view gamelib/mission.py @ 5:dd9046d0680c

Sketch in mission objects
author Neil Muller <drnlmuller@gmail.com>
date Sun, 06 May 2012 12:36:34 +0200
parents
children 9f8def7d70d0
line wrap: on
line source

# -*- 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)