Mercurial > sypikslang
annotate gamelib/mission.py @ 10:9f8def7d70d0
Rework mission objects to include reputation
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sun, 06 May 2012 13:25:28 +0200 |
parents | dd9046d0680c |
children | c0966997e0c5 |
rev | line source |
---|---|
5 | 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 | |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
15 available = True |
5 | 16 |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
17 def attempt(self, equipment, state): |
5 | 18 """Attempt the mission with the given equipment list. |
19 | |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
20 Returns a tuple (success, message). Updates the game |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
21 state with the results of the mission.""" |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
22 return False, "You can't succceed at this mission" |
5 | 23 |
24 | |
25 class RansomChina(Mission): | |
26 | |
27 NAME = "Hold China to ransom" | |
28 SHORT_DESCRIPTION = "Surely a path to riches and fame" | |
29 LONG_DESCRIPTION = "Holding China to ransom. The rewards for" \ | |
30 " successfully threatening the largest country in the world" \ | |
31 " are great, but the risks are significant. Without " \ | |
32 "some serious firepower, the chances of success are small." | |
33 | |
34 def __init__(self): | |
35 # Track prior approaches to this mission | |
36 self._prior_attempts = [] | |
37 | |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
38 def attempt(self, equipment, state): |
5 | 39 failures = [] |
40 for item in equipment: | |
41 if isinstance(item, DoomsdayVirus) and \ | |
42 item not in self._prior_attempts: | |
43 self._prior_attempts.add(item) | |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
44 state.money += 1000000 |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
45 state.reputation += 1 |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
46 return True, "Trembling at the threat of your " \ |
5 | 47 " doomsday virus, the chinese government pays the ransom" |
48 elif isinstance(item, DoomsdayVirus): | |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
49 state.reputation -= 1 |
5 | 50 failures.append("'Hah, we've developed an antidote to your" |
51 " virus, doctor'. You cannot threaten us with that" | |
52 " again'") | |
53 else: | |
54 failures.append("You fail to inspire fear with your %s" | |
55 % item.name) | |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
56 return False, "\n".join(failures) |
5 | 57 |
58 | |
59 class RobBank(Mission): | |
60 | |
61 NAME = "Rob the local bank" | |
62 SHORT_DESCRIPTION = "A trivial challenge, but easy money" | |
63 LONG_DESCRIPTION = "The security guards and local police are of minor" \ | |
64 " concern. Walk in, clean out the vault, walk out. Couldn't be" \ | |
65 " simpler." | |
66 | |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
67 def attempt(self, equipment, state): |
5 | 68 failures = [] |
69 for item in equipment: | |
70 if isinstance(item, DoomsdayVirus): | |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
71 if state.reputation < 10: |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
72 failures.append("The clerk doesn't realise the threat of" |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
73 " the vial you hold, and, although watching him" |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
74 " die in agony would be statisfying, you decide" |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
75 " it's not worth wasting this on something so" |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
76 " trivial") |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
77 else: |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
78 state.money + 1000 |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
79 return True, "Holding up a bank with only a small vial" \ |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
80 " of clear liquid. Now that is power." |
5 | 81 elif isinstance(item, MachineGun) or isinstance(item, TeslaGun): |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
82 state.money += 1000 |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
83 return True, "The threat of your weapons is enough to" \ |
5 | 84 " inspire an impressive level of cooperation" |
85 else: | |
86 failures.append("You fail to inspire fear with your %s" | |
87 % item.name) | |
88 return False, 0, "\n".join(failures) | |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
89 |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
90 |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
91 class DestroyMountRushmore(Mission): |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
92 |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
93 NAME = "Destroy Mount Rushmore" |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
94 SHORT_DESCRIPTION = "Monuments to other people? Intolerable" |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
95 LONG_DESCRIPTION = "While potentially expensive, destroying" \ |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
96 " major monument is a good way to secure your reputation." |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
97 |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
98 def attempt(self, equipment, state): |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
99 if not self.available: |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
100 return True, "You send a team to kick over the rubble." |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
101 self.available = False |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
102 state.reputation += 100 |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
103 return True, "Mount Rushmore is remarkably easy to destroy." |