comparison 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
comparison
equal deleted inserted replaced
4:5e21bf2b6853 5:dd9046d0680c
1 # -*- coding: utf-8 -*-
2 # vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4
3
4 from product import DoomsdayVirus, MachineGun, TeslaGun
5
6
7 class Mission(object):
8 """Base class for the mission objects.
9 Missions have a name, short description (for list displays) and
10 long description (which may contain clues about approaches)"""
11
12 NAME = "Generic Mission"
13 SHORT_DESCRIPTION = None
14 LONG_DESCRIPTION = None
15
16 def attempt(self, equipment):
17 """Attempt the mission with the given equipment list.
18
19 Returns a tuple (success, money, message)"""
20 return False, 0, "You can't succceed at this mission"
21
22
23 class RansomChina(Mission):
24
25 NAME = "Hold China to ransom"
26 SHORT_DESCRIPTION = "Surely a path to riches and fame"
27 LONG_DESCRIPTION = "Holding China to ransom. The rewards for" \
28 " successfully threatening the largest country in the world" \
29 " are great, but the risks are significant. Without " \
30 "some serious firepower, the chances of success are small."
31
32 def __init__(self):
33 # Track prior approaches to this mission
34 self._prior_attempts = []
35
36 def attempt(self, equipment):
37 failures = []
38 for item in equipment:
39 if isinstance(item, DoomsdayVirus) and \
40 item not in self._prior_attempts:
41 self._prior_attempts.add(item)
42 return True, 1000000, "Trembling at the threat of your " \
43 " doomsday virus, the chinese government pays the ransom"
44 elif isinstance(item, DoomsdayVirus):
45 failures.append("'Hah, we've developed an antidote to your"
46 " virus, doctor'. You cannot threaten us with that"
47 " again'")
48 else:
49 failures.append("You fail to inspire fear with your %s"
50 % item.name)
51 return False, 0, "\n".join(failures)
52
53
54 class RobBank(Mission):
55
56 NAME = "Rob the local bank"
57 SHORT_DESCRIPTION = "A trivial challenge, but easy money"
58 LONG_DESCRIPTION = "The security guards and local police are of minor" \
59 " concern. Walk in, clean out the vault, walk out. Couldn't be" \
60 " simpler."
61
62 def attempt(self, equipment):
63 failures = []
64 for item in equipment:
65 if isinstance(item, DoomsdayVirus):
66 failures.append("The clerk doesn't realise the threat of the"
67 " vial you hold, and, although watching him die in"
68 " agony would be statisfying, you decide it's not"
69 " worth wasting this on something so trivial")
70 elif isinstance(item, MachineGun) or isinstance(item, TeslaGun):
71 return True, 1000, "The threat of your weapons is enough to" \
72 " inspire an impressive level of cooperation"
73 else:
74 failures.append("You fail to inspire fear with your %s"
75 % item.name)
76 return False, 0, "\n".join(failures)