# HG changeset patch # User Neil Muller # Date 1336300594 -7200 # Node ID dd9046d0680c748525f81bf477c749be4d23bed6 # Parent 5e21bf2b68531fe2035d628400ca65410948e51d Sketch in mission objects diff -r 5e21bf2b6853 -r dd9046d0680c gamelib/mission.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gamelib/mission.py Sun May 06 12:36:34 2012 +0200 @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- +# vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4 + +from product import DoomsdayVirus, MachineGun, TeslaGun + + +class Mission(object): + """Base class for the mission objects. + Missions have a name, short description (for list displays) and + long description (which may contain clues about approaches)""" + + NAME = "Generic Mission" + SHORT_DESCRIPTION = None + LONG_DESCRIPTION = None + + def attempt(self, equipment): + """Attempt the mission with the given equipment list. + + Returns a tuple (success, money, message)""" + return False, 0, "You can't succceed at this mission" + + +class RansomChina(Mission): + + NAME = "Hold China to ransom" + SHORT_DESCRIPTION = "Surely a path to riches and fame" + LONG_DESCRIPTION = "Holding China to ransom. The rewards for" \ + " successfully threatening the largest country in the world" \ + " are great, but the risks are significant. Without " \ + "some serious firepower, the chances of success are small." + + def __init__(self): + # Track prior approaches to this mission + self._prior_attempts = [] + + def attempt(self, equipment): + failures = [] + for item in equipment: + if isinstance(item, DoomsdayVirus) and \ + item not in self._prior_attempts: + self._prior_attempts.add(item) + return True, 1000000, "Trembling at the threat of your " \ + " doomsday virus, the chinese government pays the ransom" + elif isinstance(item, DoomsdayVirus): + failures.append("'Hah, we've developed an antidote to your" + " virus, doctor'. You cannot threaten us with that" + " again'") + else: + failures.append("You fail to inspire fear with your %s" + % item.name) + return False, 0, "\n".join(failures) + + +class RobBank(Mission): + + NAME = "Rob the local bank" + SHORT_DESCRIPTION = "A trivial challenge, but easy money" + LONG_DESCRIPTION = "The security guards and local police are of minor" \ + " concern. Walk in, clean out the vault, walk out. Couldn't be" \ + " simpler." + + def attempt(self, equipment): + failures = [] + for item in equipment: + if isinstance(item, DoomsdayVirus): + failures.append("The clerk doesn't realise the threat of the" + " vial you hold, and, although watching him die in" + " agony would be statisfying, you decide it's not" + " worth wasting this on something so trivial") + elif isinstance(item, MachineGun) or isinstance(item, TeslaGun): + return True, 1000, "The threat of your weapons is enough to" \ + " inspire an impressive level of cooperation" + else: + failures.append("You fail to inspire fear with your %s" + % item.name) + return False, 0, "\n".join(failures)