# HG changeset patch # User Jeremy Thurgood # Date 1336333213 -7200 # Node ID 20ed2843adec17bdd335df9d1553b2e8d8f7924a # Parent 12c33aac76848b4c7ea511d13e455cbc0c2f4384 More categories. diff -r 12c33aac7684 -r 20ed2843adec gamelib/missions.py --- a/gamelib/missions.py Sun May 06 21:27:33 2012 +0200 +++ b/gamelib/missions.py Sun May 06 21:40:13 2012 +0200 @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4 -from products import DoomsdayVirus, HAND_WEAPON +from products import HAND_WEAPON, PATHOGEN, DOOMSDAY_DEVICE MAJOR_SETBACK, FAILURE, SUCCESS, MAJOR_SUCCESS, GAME_WIN = range(5) @@ -78,9 +78,9 @@ def __init__(self, init_data=None): # Track prior approaches to this mission - self._prior_attempts = [] + self._prior_attempts = set() if init_data: - self._prior_attempts = init_data + self._prior_attempts = set(init_data) def save_data(self): return self._prior_attempts @@ -89,20 +89,26 @@ failures = [] reputation = 0 for item in equipment: - if isinstance(item, DoomsdayVirus) and \ - item.NAME not in self._prior_attempts: - self._prior_attempts.add(item.NAME) - return Result(SUCCESS, 1000000, 1, "Trembling at the threat of" - " your doomsday virus, the chinese government pays the" - " ransom") - elif isinstance(item, DoomsdayVirus): - reputation = -1 - failures.append("'Hah, we've developed an antidote to your" - " virus, doctor'. You cannot threaten us with that" - " again'") + if item.is_a(DOOMSDAY_DEVICE): + if item.NAME not in self._prior_attempts: + self._prior_attempts.add(item.NAME) + return Result(SUCCESS, 1000000, 1, ( + "Trembling at the threat of your doomsday virus," + " the chinese government pays the ransom.")) + elif item.is_a(PATHOGEN): + reputation = -1 + failures.append( + "'Hah, we've developed an antidote to your" + " pathogen, doctor. You cannot threaten us with that" + " again.'") + else: + reputation = -1 + failures.append( + "'Hah, we know how to deal with that particular" + " threat, doctor.'") else: failures.append("You fail to inspire fear with your %s" - % item.name) + % item.NAME) return Result(FAILURE, 0, reputation, "\n".join(failures)) @@ -121,7 +127,7 @@ " barehanded is unsuccessful. Fortunately, everyone is" " too stunned to impede your escape.") for item in equipment: - if isinstance(item, DoomsdayVirus): + if item.is_a(PATHOGEN): if state.reputation < 10: failures.append("The clerk doesn't realise the threat of" " the vial you hold, and, although watching him" @@ -132,7 +138,7 @@ return Result(SUCCESS, 1000, 0, "Holding up a bank with" " only a small vial of clear liquid. Now that" " is power.") - elif HAND_WEAPON in item.CATEGORIES: + elif item.is_a(HAND_WEAPON): return Result(SUCCESS, 1000, 0, "The threat of your weapons is" " enough to inspire an impressive level of cooperation") else: diff -r 12c33aac7684 -r 20ed2843adec gamelib/products.py --- a/gamelib/products.py Sun May 06 21:27:33 2012 +0200 +++ b/gamelib/products.py Sun May 06 21:40:13 2012 +0200 @@ -28,6 +28,9 @@ extra = self.UPGRADE_REQUIREMENT * self.points + 1 return lab.meet_requirements(self, extra) + def is_a(self, category): + return category in self.CATEGORIES + class MachineGun(Product): NAME = "Machine gun"