Mercurial > sypikslang
annotate gamelib/mission.py @ 19:12085dfd9e69
Add rescue mission for the out of money case
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sun, 06 May 2012 17:39:38 +0200 |
parents | 0849ab5304cf |
children | 296ce36fa7d9 |
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 | |
18
0849ab5304cf
Add more mission result codes
Neil Muller <drnlmuller@gmail.com>
parents:
13
diff
changeset
|
6 MAJOR_SETBACK, FAILURE, SUCCESS, MAJOR_SUCCESS, GAME_WIN = range(5) |
0849ab5304cf
Add more mission result codes
Neil Muller <drnlmuller@gmail.com>
parents:
13
diff
changeset
|
7 |
5 | 8 |
13
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
9 class Result(object): |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
10 """Results of a mission""" |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
11 |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
12 def __init__(self, outcome, money, reputation, msg): |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
13 self.outcome = outcome |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
14 self.money = money |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
15 self.reputation = reputation |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
16 self.message = msg |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
17 self.applied = False |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
18 |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
19 def apply(self, state): |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
20 if not self.applied: |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
21 state.money += self.money |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
22 state.reputation += self.reputation |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
23 self.applied = True |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
24 else: |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
25 raise RuntimeError('attempted to apply result twice') |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
26 |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
27 |
5 | 28 class Mission(object): |
29 """Base class for the mission objects. | |
30 Missions have a name, short description (for list displays) and | |
31 long description (which may contain clues about approaches)""" | |
32 | |
33 NAME = "Generic Mission" | |
34 SHORT_DESCRIPTION = None | |
35 LONG_DESCRIPTION = None | |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
36 available = True |
5 | 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 """Attempt the mission with the given equipment list. |
40 | |
13
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
41 Returns a result object with the results of the mission.""" |
18
0849ab5304cf
Add more mission result codes
Neil Muller <drnlmuller@gmail.com>
parents:
13
diff
changeset
|
42 return Result(FAILURE, 0, 0, "You can't succceed at this mission") |
5 | 43 |
44 | |
19
12085dfd9e69
Add rescue mission for the out of money case
Neil Muller <drnlmuller@gmail.com>
parents:
18
diff
changeset
|
45 class PlaygroundBully(Mission): |
12085dfd9e69
Add rescue mission for the out of money case
Neil Muller <drnlmuller@gmail.com>
parents:
18
diff
changeset
|
46 |
12085dfd9e69
Add rescue mission for the out of money case
Neil Muller <drnlmuller@gmail.com>
parents:
18
diff
changeset
|
47 NAME = "Rob kids in the playground" |
12085dfd9e69
Add rescue mission for the out of money case
Neil Muller <drnlmuller@gmail.com>
parents:
18
diff
changeset
|
48 SHORT_DESCRIPTION = "Steal from those significantly weaker than yourself" |
12085dfd9e69
Add rescue mission for the out of money case
Neil Muller <drnlmuller@gmail.com>
parents:
18
diff
changeset
|
49 LONG_DESCRIPTION = ("It's not menancing, or lucrative, but when the bills" |
12085dfd9e69
Add rescue mission for the out of money case
Neil Muller <drnlmuller@gmail.com>
parents:
18
diff
changeset
|
50 " are due, no one cares how you earn the money") |
12085dfd9e69
Add rescue mission for the out of money case
Neil Muller <drnlmuller@gmail.com>
parents:
18
diff
changeset
|
51 |
12085dfd9e69
Add rescue mission for the out of money case
Neil Muller <drnlmuller@gmail.com>
parents:
18
diff
changeset
|
52 def attempt(sefl, equipment, state): |
12085dfd9e69
Add rescue mission for the out of money case
Neil Muller <drnlmuller@gmail.com>
parents:
18
diff
changeset
|
53 return Result(SUCCESS, 100, -1, "You devote your resources to" |
12085dfd9e69
Add rescue mission for the out of money case
Neil Muller <drnlmuller@gmail.com>
parents:
18
diff
changeset
|
54 " robbing kids in a playpark. It's not the finest moment" |
12085dfd9e69
Add rescue mission for the out of money case
Neil Muller <drnlmuller@gmail.com>
parents:
18
diff
changeset
|
55 " in your reign of terror, but at least you walked away" |
12085dfd9e69
Add rescue mission for the out of money case
Neil Muller <drnlmuller@gmail.com>
parents:
18
diff
changeset
|
56 " with a surprising amount of small change.") |
12085dfd9e69
Add rescue mission for the out of money case
Neil Muller <drnlmuller@gmail.com>
parents:
18
diff
changeset
|
57 |
12085dfd9e69
Add rescue mission for the out of money case
Neil Muller <drnlmuller@gmail.com>
parents:
18
diff
changeset
|
58 |
5 | 59 class RansomChina(Mission): |
60 | |
61 NAME = "Hold China to ransom" | |
62 SHORT_DESCRIPTION = "Surely a path to riches and fame" | |
63 LONG_DESCRIPTION = "Holding China to ransom. The rewards for" \ | |
64 " successfully threatening the largest country in the world" \ | |
65 " are great, but the risks are significant. Without " \ | |
66 "some serious firepower, the chances of success are small." | |
67 | |
68 def __init__(self): | |
69 # Track prior approaches to this mission | |
70 self._prior_attempts = [] | |
71 | |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
72 def attempt(self, equipment, state): |
5 | 73 failures = [] |
13
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
74 reputation = 0 |
5 | 75 for item in equipment: |
76 if isinstance(item, DoomsdayVirus) and \ | |
77 item not in self._prior_attempts: | |
78 self._prior_attempts.add(item) | |
18
0849ab5304cf
Add more mission result codes
Neil Muller <drnlmuller@gmail.com>
parents:
13
diff
changeset
|
79 return Result(SUCCESS, 1000000, 1, "Trembling at the threat of" |
13
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
80 " your doomsday virus, the chinese government pays the" |
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
81 " ransom") |
5 | 82 elif isinstance(item, DoomsdayVirus): |
13
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
83 reputation = -1 |
5 | 84 failures.append("'Hah, we've developed an antidote to your" |
85 " virus, doctor'. You cannot threaten us with that" | |
86 " again'") | |
87 else: | |
88 failures.append("You fail to inspire fear with your %s" | |
89 % item.name) | |
18
0849ab5304cf
Add more mission result codes
Neil Muller <drnlmuller@gmail.com>
parents:
13
diff
changeset
|
90 return Result(FAILURE, 0, reputation, "\n".join(failures)) |
5 | 91 |
92 | |
93 class RobBank(Mission): | |
94 | |
95 NAME = "Rob the local bank" | |
96 SHORT_DESCRIPTION = "A trivial challenge, but easy money" | |
97 LONG_DESCRIPTION = "The security guards and local police are of minor" \ | |
98 " concern. Walk in, clean out the vault, walk out. Couldn't be" \ | |
99 " simpler." | |
100 | |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
101 def attempt(self, equipment, state): |
5 | 102 failures = [] |
103 for item in equipment: | |
104 if isinstance(item, DoomsdayVirus): | |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
105 if state.reputation < 10: |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
106 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
|
107 " the vial you hold, and, although watching him" |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
108 " die in agony would be statisfying, you decide" |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
109 " 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
|
110 " trivial") |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
111 else: |
18
0849ab5304cf
Add more mission result codes
Neil Muller <drnlmuller@gmail.com>
parents:
13
diff
changeset
|
112 return Result(SUCCESS, 1000, 0, "Holding up a bank with" |
0849ab5304cf
Add more mission result codes
Neil Muller <drnlmuller@gmail.com>
parents:
13
diff
changeset
|
113 " only a small vial of clear liquid. Now that" |
0849ab5304cf
Add more mission result codes
Neil Muller <drnlmuller@gmail.com>
parents:
13
diff
changeset
|
114 " is power.") |
5 | 115 elif isinstance(item, MachineGun) or isinstance(item, TeslaGun): |
18
0849ab5304cf
Add more mission result codes
Neil Muller <drnlmuller@gmail.com>
parents:
13
diff
changeset
|
116 return Result(SUCCESS, 1000, 0, "The threat of your weapons is" |
13
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
117 " enough to inspire an impressive level of cooperation") |
5 | 118 else: |
119 failures.append("You fail to inspire fear with your %s" | |
120 % item.name) | |
18
0849ab5304cf
Add more mission result codes
Neil Muller <drnlmuller@gmail.com>
parents:
13
diff
changeset
|
121 return Result(FAILURE, 0, 0, "\n".join(failures)) |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
122 |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
123 |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
124 class DestroyMountRushmore(Mission): |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
125 |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
126 NAME = "Destroy Mount Rushmore" |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
127 SHORT_DESCRIPTION = "Monuments to other people? Intolerable" |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
128 LONG_DESCRIPTION = "While potentially expensive, destroying" \ |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
129 " 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
|
130 |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
131 def attempt(self, equipment, state): |
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
132 if not self.available: |
13
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
133 raise RuntimeError('Cannot attempt an unavailable mission') |
10
9f8def7d70d0
Rework mission objects to include reputation
Neil Muller <drnlmuller@gmail.com>
parents:
5
diff
changeset
|
134 self.available = False |
18
0849ab5304cf
Add more mission result codes
Neil Muller <drnlmuller@gmail.com>
parents:
13
diff
changeset
|
135 return Result(SUCCESS, 0, 100, |
13
c0966997e0c5
Use a results object instead of tuple (will hopefully make changign stuff easier later)
Neil Muller <drnlmuller@gmail.com>
parents:
10
diff
changeset
|
136 "Mount Rushmore is remarkably easy to destroy.") |