Mercurial > sypikslang
annotate gamelib/schematics.py @ 135:8d1cf98e39b5
Reputation decays over time
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Thu, 10 May 2012 17:07:06 +0200 |
parents | 8e64bbd561bd |
children | 53277724645b |
rev | line source |
---|---|
54 | 1 # -*- test-case-name: gamelib.tests.test_schematics -*- |
2 | |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
3 from gamelib import research |
45
1e8f7e694f0c
Refactor missions and sciences a bit to reduce duplication.
Jeremy Thurgood <firxen@gmail.com>
parents:
34
diff
changeset
|
4 from gamelib.game_base import Science |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
5 |
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
6 |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
7 class SchematicCategorySet(object): |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
8 def __init__(self, *categories): |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
9 for cat in categories: |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
10 setattr(self, cat, cat.lower().replace('_', ' ')) |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
11 |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
12 cat = SchematicCategorySet( |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
13 'HAND_WEAPON', |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
14 'VEHICLE', |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
15 'DOOMSDAY_DEVICE', |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
16 'PATHOGEN', |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
17 'MIND_CONTROL', |
116 | 18 'BEAST', |
19 'AQUATIC', | |
132 | 20 'SPY', |
21 'AI', | |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
22 ) |
32 | 23 |
24 | |
49 | 25 class Schematic(Science): |
54 | 26 # For all Schematics |
27 SCIENCE_TYPE = 'schematic' | |
28 | |
29 # Acquisition | |
30 STARTING_PRODUCT = False | |
6
826b44731323
Start of basic lab implementation.
Jeremy Thurgood <firxen@gmail.com>
parents:
3
diff
changeset
|
31 ACQUISITION_CHANCE = 0.8 |
54 | 32 CATEGORIES = () |
33 | |
34 # Costs | |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
35 UPGRADE_REQUIREMENT = 1 |
54 | 36 COST = None |
37 | |
38 # Power and reliability | |
39 PROTOTYPE_RELIABILITY = 0.4 | |
40 PRODUCTION_RELIABILITY = 0.8 | |
41 BASE_POWER = None | |
42 POWER_INCREMENT = None | |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
43 |
58
52913ba12988
Check for multiple points in can_spend
Neil Muller <drnlmuller@gmail.com>
parents:
54
diff
changeset
|
44 def can_spend(self, lab, spend): |
52913ba12988
Check for multiple points in can_spend
Neil Muller <drnlmuller@gmail.com>
parents:
54
diff
changeset
|
45 extra = self.UPGRADE_REQUIREMENT * self.points + spend |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
46 return lab.meet_requirements(self, extra) |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
47 |
34 | 48 def is_a(self, category): |
49 return category in self.CATEGORIES | |
50 | |
54 | 51 def reliability(self): |
52 if self.points: | |
53 exp = 1 + 0.5 * (self.points - 1) | |
54 return 1.0 - ((1.0 - self.PRODUCTION_RELIABILITY) ** exp) | |
55 return self.PROTOTYPE_RELIABILITY | |
56 | |
57 def power(self): | |
58 power = self.BASE_POWER | |
59 if None not in (power, self.POWER_INCREMENT): | |
60 power += self.POWER_INCREMENT * self.points | |
61 return power | |
62 | |
94
245ef50de84d
Sanity-check research, schematic and mission classes. (Ironic, no?)
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
63 @classmethod |
245ef50de84d
Sanity-check research, schematic and mission classes. (Ironic, no?)
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
64 def sanity_check(cls): |
245ef50de84d
Sanity-check research, schematic and mission classes. (Ironic, no?)
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
65 for science, points in cls.PREREQUISITES: |
245ef50de84d
Sanity-check research, schematic and mission classes. (Ironic, no?)
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
66 assert issubclass(science, Science) |
245ef50de84d
Sanity-check research, schematic and mission classes. (Ironic, no?)
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
67 assert isinstance(points, int) |
245ef50de84d
Sanity-check research, schematic and mission classes. (Ironic, no?)
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
68 assert isinstance(cls.CATEGORIES, tuple) |
245ef50de84d
Sanity-check research, schematic and mission classes. (Ironic, no?)
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
69 |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
70 |
49 | 71 class MachineGun(Schematic): |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
72 NAME = "machine gun" |
15 | 73 COST = 100 |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
74 CATEGORIES = (cat.HAND_WEAPON,) |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
75 STARTING_PRODUCT = True |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
76 |
20 | 77 def __init__(self, points=0): |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
78 self.points = 1 |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
79 |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
80 def spend_point(self): |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
81 raise NotImplementedError() |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
82 |
58
52913ba12988
Check for multiple points in can_spend
Neil Muller <drnlmuller@gmail.com>
parents:
54
diff
changeset
|
83 def can_spend(self, lab, spend): |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
84 return False |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
85 |
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
86 |
49 | 87 class LightningGun(Schematic): |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
88 NAME = "lightning gun" |
32 | 89 COST = 300 |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
90 CATEGORIES = (cat.HAND_WEAPON,) |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
91 PREREQUISITES = ( |
115 | 92 (research.Electrickery, 1), |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
93 ) |
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
94 |
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
95 |
49 | 96 class TeslaTank(Schematic): |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
97 NAME = "tesla tank" |
32 | 98 COST = 1000 |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
99 CATEGORIES = (cat.VEHICLE,) |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
100 PREREQUISITES = ( |
115 | 101 (research.Electrickery, 3), |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
102 ) |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
103 |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
104 |
49 | 105 class DoomsdayVirus(Schematic): |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
106 NAME = "doomsday virus" |
32 | 107 COST = 100000 |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
108 CATEGORIES = (cat.DOOMSDAY_DEVICE, cat.PATHOGEN) |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
109 PREREQUISITES = ( |
14 | 110 (research.Biogenetics, 5), |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
111 ) |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
112 |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
113 |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
114 class PropagandaMachine(Schematic): |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
115 NAME = "propaganda machine" |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
116 COST = 1000 |
91
c57b5b46d3e0
Better mission data management.
Jeremy Thurgood <firxen@gmail.com>
parents:
85
diff
changeset
|
117 CATEGORIES = (cat.MIND_CONTROL,) |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
118 PREREQUISITES = ( |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
119 (research.Psychology, 2), |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
120 ) |
116 | 121 |
122 | |
123 class GiantSquid(Schematic): | |
124 NAME = "giant squid" | |
125 COST = 50000 | |
126 CATEGORIES = (cat.BEAST, cat.AQUATIC) | |
127 PREREQUISITES = ( | |
128 (research.MarineBiology, 20), | |
129 (research.Biogenetics, 15), | |
130 ) | |
131 | |
132 | |
133 class SharksWithFrickinLasers(Schematic): | |
134 NAME = "sharks with frickin' lasers" | |
135 COST = 20000 | |
136 CATEGORIES = (cat.BEAST, cat.AQUATIC) | |
137 PREREQUISITES = ( | |
138 (research.MarineBiology, 10), | |
139 (research.Lasers, 7), | |
140 ) | |
132 | 141 |
142 | |
143 class OrbitalLaserPlatform(Schematic): | |
144 NAME = "An Orbital Laser Platform" | |
145 COST = 10000000 | |
146 CATEGORIES = (cat.DOOMSDAY_DEVICE,) | |
147 PREREQUISITES = ( | |
148 (research.Lasers, 5), | |
149 (research.Space, 2), | |
150 ) | |
151 | |
152 | |
153 class GiantRobot(Schematic): | |
154 NAME = "A very large robot" | |
155 COST = 1000000 | |
156 CATEGORIES = (cat.DOOMSDAY_DEVICE,) | |
157 PREREQUISITES = ( | |
158 (research.Robotics, 5), | |
159 (research.ArtificialIntelligence, 2), | |
160 ) | |
161 | |
162 | |
163 class SpySattelite(Schematic): | |
164 NAME = "A small spy sattelite" | |
165 COST = 10000 | |
166 CATEGORIES = (cat.SPY,) | |
167 PREREQUISITES = ( | |
168 (research.Space, 1), | |
169 ) | |
170 | |
171 | |
172 class ComputerAI(Schematic): | |
173 NAME = "AI Assistant" | |
174 COST = 10000 | |
175 CATEGORIES = (cat.AI,) | |
176 PREREQUISITES = ( | |
177 (research.ArtificialIntelligence, 1), | |
178 ) | |
179 | |
180 | |
181 class LaserGun(Schematic): | |
182 NAME = "Laser Gun" | |
183 COST = 300 | |
184 CATEGORIES = (cat.HAND_WEAPON,) | |
185 PREREQUISITES = ( | |
186 (research.Lasers, 1), | |
187 ) |