Mercurial > sypikslang
diff gamelib/mission.py @ 22:296ce36fa7d9
Serialize and unserialize game state and missions
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sun, 06 May 2012 18:38:54 +0200 |
parents | 12085dfd9e69 |
children |
line wrap: on
line diff
--- a/gamelib/mission.py Sun May 06 18:34:28 2012 +0200 +++ b/gamelib/mission.py Sun May 06 18:38:54 2012 +0200 @@ -35,6 +35,13 @@ LONG_DESCRIPTION = None available = True + def __init__(self, init_data=None): + pass + + def save_data(self): + """Serialize the mission state for saving, etc.""" + return [] + def attempt(self, equipment, state): """Attempt the mission with the given equipment list. @@ -65,17 +72,22 @@ " are great, but the risks are significant. Without " \ "some serious firepower, the chances of success are small." - def __init__(self): + def __init__(self, init_data=None): # Track prior approaches to this mission self._prior_attempts = [] + if init_data: + self._prior_attempts = init_data + + def save_data(self): + return self._prior_attempts def attempt(self, equipment, state): failures = [] reputation = 0 for item in equipment: if isinstance(item, DoomsdayVirus) and \ - item not in self._prior_attempts: - self._prior_attempts.add(item) + 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")