# HG changeset patch # User Rizmari Versfeld # Date 1336688606 -7200 # Node ID 8fbd0abb7744e797695d65a1dbbdf6ff33b78fa1 # Parent abbceec3cc8ba9efa2f6ce2bc4ebec32b518c0b3# Parent 07be37129447068459271a21b20a6ae5e9d840dd merge diff -r abbceec3cc8b -r 8fbd0abb7744 gamelib/constants.py --- a/gamelib/constants.py Fri May 11 00:23:01 2012 +0200 +++ b/gamelib/constants.py Fri May 11 00:23:26 2012 +0200 @@ -12,8 +12,7 @@ BUFFER = 1024 # Result codes for UI hints -(MAJOR_SETBACK, FAILURE, SUCCESS, MAJOR_SUCCESS, GAME_WIN, NEW_SCIENCE, - NEW_SCHEMATIC, NEW_MILESTONE) = range(8) +(MAJOR_SETBACK, FAILURE, SUCCESS, MAJOR_SUCCESS, GAME_WIN, INFO) = range(6) # Planning to take over the: MILESTONES = ("basement", "neighbourhood", "city", "world") diff -r abbceec3cc8b -r 8fbd0abb7744 gamelib/gamegui.py --- a/gamelib/gamegui.py Fri May 11 00:23:01 2012 +0200 +++ b/gamelib/gamegui.py Fri May 11 00:23:26 2012 +0200 @@ -17,8 +17,7 @@ font_medium, font_large) from gamelib.gui import BigButton, ImageDrawable from gamelib.engine import PopWindow, AddWindow, GameOver -from gamelib.constants import (WIDTH, HEIGHT, FAILURE, SUCCESS, NEW_SCIENCE, - NEW_SCHEMATIC, GAME_WIN) +from gamelib.constants import WIDTH, HEIGHT, FAILURE, SUCCESS, GAME_WIN, INFO from gamelib.gamestate import Game @@ -309,6 +308,11 @@ class ResultsWindow(Window): + message_colours = { + INFO: (60, 60, 255), + FAILURE: (255, 60, 60), + SUCCESS: (60, 255, 60), + } def __init__(self, screen, messages, turn): super(ResultsWindow, self).__init__(screen) @@ -325,26 +329,30 @@ self.add_child(results) else: y = 200 - for msg_type, msg in messages: + for msg_type, msg, loot in messages: # FIXME: Better widgets - if msg_type in [NEW_SCHEMATIC, NEW_SCIENCE]: - text = TextBox((50, y, 750, 25), - msg, font_medium, (60, 60, 255)) - elif msg_type == FAILURE: - text = TextBox((50, y, 750, 25), - msg, font_medium, (255, 60, 60)) - elif msg_type == SUCCESS: - text = TextBox((50, y, 750, 25), - msg, font_medium, (60, 255, 60)) - elif msg_type == GAME_WIN: + if msg_type == GAME_WIN: self._make_win_screen(turn, msg) self.is_game_over = True break - else: - text = TextBox((50, y, 750, 25), - msg, font_medium, (255, 255, 0)) - y += text.rect.height + 10 - self.add_child(text) + colour = self.message_colours.get(msg_type, (255, 255, 255)) + y = self.display_message(y, msg, loot, colour) + + def display_message(self, y, msg, loot, colour, font=font_medium): + text = TextBox((50, y, 700, 25), msg, font, colour) + y += text.rect.height + 5 + self.add_child(text) + for kind, value in loot.items(): + y += self.display_loot_item(y, kind, value) + return y + 5 + + def display_loot_item(self, y, kind, value): + if hasattr(value, 'NAME'): + value = value.NAME + msg = "* %s: %s" % (kind, value) + text = TextBox((80, y, 670, 25), msg, font_medium, (255, 255, 60)) + self.add_child(text) + return text.rect.height + 5 def _make_win_screen(self, turn, msg): # Clear existing widgets, and turn this into a won screen diff -r abbceec3cc8b -r 8fbd0abb7744 gamelib/gamestate.py --- a/gamelib/gamestate.py Fri May 11 00:23:01 2012 +0200 +++ b/gamelib/gamestate.py Fri May 11 00:23:26 2012 +0200 @@ -5,8 +5,7 @@ from gamelib import missions, lab from gamelib.game_base import get_subclasses -from gamelib.constants import (NEW_SCIENCE, NEW_SCHEMATIC, M_VALS, MILESTONES, - NEW_MILESTONE) +from gamelib.constants import M_VALS, INFO class Game(object): @@ -61,6 +60,10 @@ def get_available_points(self): return self.points - len(self.cur_allocation) + def apply_mission_special(self, new_milestone=None): + if new_milestone: + self.milestone = new_milestone + def end_turn(self): # Attempt the missions mission_results = [] @@ -80,18 +83,11 @@ messages = [] for result in mission_results: result.apply(self) - messages.append((result.outcome, result.text)) - if result.outcome == NEW_MILESTONE: - self.milestone = MILESTONES[M_VALS[self.milestone] + 1] + messages.append((result.outcome, result.text, result.loot)) for science in new_stuff: # FIXME: Update UI better. - if science.SCIENCE_TYPE == 'research': - messages.append((NEW_SCIENCE, - "You've started a new line of research in %s" - % science.NAME)) - else: - messages.append((NEW_SCHEMATIC, - "You've developed blueprints for a %s" % science.NAME)) + messages.append((INFO, "SCIENCE breakthrough!", { + science.SCIENCE_TYPE: science})) return messages def save_data(self): diff -r abbceec3cc8b -r 8fbd0abb7744 gamelib/lab.py --- a/gamelib/lab.py Fri May 11 00:23:01 2012 +0200 +++ b/gamelib/lab.py Fri May 11 00:23:26 2012 +0200 @@ -128,7 +128,7 @@ return breakthroughs def apply_basic_research(self, basic_research): - if basic_research <= 1: + if basic_research <= 0: return [] options = self.find_new_research() diff -r abbceec3cc8b -r 8fbd0abb7744 gamelib/missions.py --- a/gamelib/missions.py Fri May 11 00:23:01 2012 +0200 +++ b/gamelib/missions.py Fri May 11 00:23:26 2012 +0200 @@ -3,7 +3,7 @@ from random import randint -from gamelib.constants import SUCCESS, FAILURE, GAME_WIN, NEW_MILESTONE, M_VALS +from gamelib.constants import SUCCESS, FAILURE, GAME_WIN, M_VALS from gamelib.schematics import cat @@ -13,17 +13,30 @@ This is an exception so we can throw it from inside helper methods. """ - def __init__(self, outcome, msg, money=0, rep=0): + def __init__(self, outcome, msg, money=0, rep=0, **special): self.outcome = outcome self.money = money self.reputation = rep self.text = msg + self.special = special self.applied = False + @property + def loot(self): + loot = {} + if self.money != 0: + loot['money'] = self.money + if self.reputation != 0: + loot['rep'] = self.reputation + loot.update(self.special) + loot.pop('new_milestone', None) # This one's special. + return loot + def apply(self, state): if not self.applied: state.money += self.money state.reputation += self.reputation + state.apply_mission_special(self.special) self.applied = True else: raise RuntimeError('attempted to apply result twice') @@ -92,15 +105,15 @@ return False return True - def fail(self, msg=None, money=0, rep=0): + def fail(self, msg=None, money=0, rep=0, **special): if msg is None: msg = self.GENERIC_FAILURE - raise Result(FAILURE, msg, money=money, rep=rep) + raise Result(FAILURE, msg, money=money, rep=rep, **special) - def succeed(self, msg=None, money=0, rep=0): + def succeed(self, msg=None, money=0, rep=0, **special): if msg is None: msg = self.GENERIC_SUCCESS - raise Result(SUCCESS, msg, money=money, rep=rep) + raise Result(SUCCESS, msg, money=money, rep=rep, **special) def categorise_equipment(self, equipment): # Categorise equipment for easier decision-making. @@ -385,11 +398,12 @@ def attempt_with(self, categorised, state): if all(c in categorised for c in (cat.MIND_CONTROL, cat.HAND_WEAPON)): self.data['completed'] = True - raise Result(NEW_MILESTONE, "Guns and persuasion, that's" - " all you need. It's early days still, but you're" - " finally out of that pokey basement and have some" - " elbow room to work with. Next step: the city!", - money=randint(1000, 2000), rep=randint(5, 15)) + self.succeed( + "Guns and persuasion, that's all you need. It's early days" + " still, but you're finally out of that pokey basement and" + " have some elbow room to work with. Next step: the city!", + money=randint(1000, 2000), rep=randint(5, 15), + new_milestone="neighbourhood") if cat.HAND_WEAPON in categorised: self.succeed(