16
|
1 # -*- coding: utf-8 -*-
|
|
2 # vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4
|
|
3
|
|
4 """The actual game state object"""
|
|
5
|
|
6 from gamelib import missions, lab, products
|
|
7
|
|
8
|
|
9 class Game(object):
|
|
10
|
|
11 def __init__(self):
|
|
12 self.lab = lab.Lab()
|
|
13 # FIXME: Generate the initial tech set
|
|
14 self.money = 1000
|
|
15 # Will be updated on the next turn
|
|
16 self.points = 0
|
|
17 self.reputation = 0
|
|
18 # instantiate the available missions
|
|
19 self.missions = [cls() for cls in missions.Mission.__subclasses__()]
|
|
20 # Missions being attempted
|
|
21 self.cur_missions = []
|
|
22 # Science allocation for the current turn
|
|
23 self.cur_allocation = []
|
|
24
|
|
25 def start_turn(self):
|
|
26 # Make more flexible?
|
|
27 self.points += 3
|
|
28 self.cur_missions = []
|
|
29 self.cur_allocation = []
|
|
30
|
|
31 def get_available_equipment(self):
|
|
32 """Return a list of equipment we can produce and afford"""
|
|
33 available = [x for x in lab.science
|
|
34 if isinstance(x, products.Product) and x.COST <= self.money]
|
|
35 return available
|
|
36
|
|
37 def end_turn(self):
|
|
38 # Attempt the missions
|
|
39 mission_results = []
|
|
40 for mission, equipment in self.cur_missions:
|
|
41 mission_results.appned(mission.attempt(equipment, self))
|
|
42 # Do the science
|
|
43 self.points -= len(self.cur_allocation)
|
|
44 if self.points < 0:
|
|
45 raise RuntimeError('Spent too many points')
|
|
46 new_stuff = self.lab.spend_points(self.cur_allocation, self.points)
|
|
47 # Process mission results
|
|
48 for result in mission_results:
|
|
49 result.apply(self)
|
|
50 # Update the science state with result of spend_points
|
|
51 for science in new_stuff:
|
|
52 self.lab.science.append(science)
|
|
53 # FIXME: Update UI
|