Mercurial > sypikslang
comparison gamelib/gamestate.py @ 138:14917385a0fd
Better handling of mission results and turn-end messages.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Thu, 10 May 2012 22:33:26 +0200 |
parents | fb8037bc22f1 |
children | f4601492020b |
comparison
equal
deleted
inserted
replaced
137:fb8037bc22f1 | 138:14917385a0fd |
---|---|
3 | 3 |
4 """The actual game state object""" | 4 """The actual game state object""" |
5 | 5 |
6 from gamelib import missions, lab | 6 from gamelib import missions, lab |
7 from gamelib.game_base import get_subclasses | 7 from gamelib.game_base import get_subclasses |
8 from gamelib.constants import (NEW_SCIENCE, NEW_SCHEMATIC, M_VALS, MILESTONES, | 8 from gamelib.constants import M_VALS, INFO |
9 NEW_MILESTONE) | |
10 | 9 |
11 | 10 |
12 class Game(object): | 11 class Game(object): |
13 | 12 |
14 def __init__(self, init_data=None): | 13 def __init__(self, init_data=None): |
59 return available | 58 return available |
60 | 59 |
61 def get_available_points(self): | 60 def get_available_points(self): |
62 return self.points - len(self.cur_allocation) | 61 return self.points - len(self.cur_allocation) |
63 | 62 |
63 def apply_mission_special(self, new_milestone=None): | |
64 if new_milestone: | |
65 self.milestone = new_milestone | |
66 | |
64 def end_turn(self): | 67 def end_turn(self): |
65 # Attempt the missions | 68 # Attempt the missions |
66 mission_results = [] | 69 mission_results = [] |
67 for mission, equipment in self.cur_missions: | 70 for mission, equipment in self.cur_missions: |
68 mission_results.append(mission.attempt_mission(equipment, self)) | 71 mission_results.append(mission.attempt_mission(equipment, self)) |
78 self.minions = 0 | 81 self.minions = 0 |
79 # Process mission results | 82 # Process mission results |
80 messages = [] | 83 messages = [] |
81 for result in mission_results: | 84 for result in mission_results: |
82 result.apply(self) | 85 result.apply(self) |
83 messages.append((result.outcome, result.text)) | 86 messages.append((result.outcome, result.text, result.loot)) |
84 if result.outcome == NEW_MILESTONE: | |
85 self.milestone = MILESTONES[M_VALS[self.milestone] + 1] | |
86 for science in new_stuff: | 87 for science in new_stuff: |
87 # FIXME: Update UI better. | 88 # FIXME: Update UI better. |
88 if science.SCIENCE_TYPE == 'research': | 89 messages.append((INFO, "SCIENCE breakthrough!", { |
89 messages.append((NEW_SCIENCE, | 90 science.SCIENCE_TYPE: science})) |
90 "You've started a new line of research in %s" | |
91 % science.NAME)) | |
92 else: | |
93 messages.append((NEW_SCHEMATIC, | |
94 "You've developed blueprints for a %s" % science.NAME)) | |
95 return messages | 91 return messages |
96 | 92 |
97 def save_data(self): | 93 def save_data(self): |
98 """Serialize the game state into a dict""" | 94 """Serialize the game state into a dict""" |
99 data = {} | 95 data = {} |