Mercurial > sypikslang
annotate gamelib/schematics.py @ 130:8f717b2b3378
Advance milestone
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Thu, 10 May 2012 16:46:18 +0200 |
parents | a8a46c14d467 |
children | 8e64bbd561bd |
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', | |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
20 ) |
32 | 21 |
22 | |
49 | 23 class Schematic(Science): |
54 | 24 # For all Schematics |
25 SCIENCE_TYPE = 'schematic' | |
26 | |
27 # Acquisition | |
28 STARTING_PRODUCT = False | |
6
826b44731323
Start of basic lab implementation.
Jeremy Thurgood <firxen@gmail.com>
parents:
3
diff
changeset
|
29 ACQUISITION_CHANCE = 0.8 |
54 | 30 CATEGORIES = () |
31 | |
32 # Costs | |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
33 UPGRADE_REQUIREMENT = 1 |
54 | 34 COST = None |
35 | |
36 # Power and reliability | |
37 PROTOTYPE_RELIABILITY = 0.4 | |
38 PRODUCTION_RELIABILITY = 0.8 | |
39 BASE_POWER = None | |
40 POWER_INCREMENT = None | |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
41 |
58
52913ba12988
Check for multiple points in can_spend
Neil Muller <drnlmuller@gmail.com>
parents:
54
diff
changeset
|
42 def can_spend(self, lab, spend): |
52913ba12988
Check for multiple points in can_spend
Neil Muller <drnlmuller@gmail.com>
parents:
54
diff
changeset
|
43 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
|
44 return lab.meet_requirements(self, extra) |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
45 |
34 | 46 def is_a(self, category): |
47 return category in self.CATEGORIES | |
48 | |
54 | 49 def reliability(self): |
50 if self.points: | |
51 exp = 1 + 0.5 * (self.points - 1) | |
52 return 1.0 - ((1.0 - self.PRODUCTION_RELIABILITY) ** exp) | |
53 return self.PROTOTYPE_RELIABILITY | |
54 | |
55 def power(self): | |
56 power = self.BASE_POWER | |
57 if None not in (power, self.POWER_INCREMENT): | |
58 power += self.POWER_INCREMENT * self.points | |
59 return power | |
60 | |
94
245ef50de84d
Sanity-check research, schematic and mission classes. (Ironic, no?)
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
61 @classmethod |
245ef50de84d
Sanity-check research, schematic and mission classes. (Ironic, no?)
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
62 def sanity_check(cls): |
245ef50de84d
Sanity-check research, schematic and mission classes. (Ironic, no?)
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
63 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
|
64 assert issubclass(science, Science) |
245ef50de84d
Sanity-check research, schematic and mission classes. (Ironic, no?)
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
65 assert isinstance(points, int) |
245ef50de84d
Sanity-check research, schematic and mission classes. (Ironic, no?)
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
66 assert isinstance(cls.CATEGORIES, tuple) |
245ef50de84d
Sanity-check research, schematic and mission classes. (Ironic, no?)
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
67 |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
68 |
49 | 69 class MachineGun(Schematic): |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
70 NAME = "machine gun" |
15 | 71 COST = 100 |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
72 CATEGORIES = (cat.HAND_WEAPON,) |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
73 STARTING_PRODUCT = True |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
74 |
20 | 75 def __init__(self, points=0): |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
76 self.points = 1 |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
77 |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
78 def spend_point(self): |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
79 raise NotImplementedError() |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
80 |
58
52913ba12988
Check for multiple points in can_spend
Neil Muller <drnlmuller@gmail.com>
parents:
54
diff
changeset
|
81 def can_spend(self, lab, spend): |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
82 return False |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
83 |
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
84 |
49 | 85 class LightningGun(Schematic): |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
86 NAME = "lightning gun" |
32 | 87 COST = 300 |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
88 CATEGORIES = (cat.HAND_WEAPON,) |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
89 PREREQUISITES = ( |
115 | 90 (research.Electrickery, 1), |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
91 ) |
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
92 |
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
93 |
49 | 94 class TeslaTank(Schematic): |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
95 NAME = "tesla tank" |
32 | 96 COST = 1000 |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
97 CATEGORIES = (cat.VEHICLE,) |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
98 PREREQUISITES = ( |
115 | 99 (research.Electrickery, 3), |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
100 ) |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
101 |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
102 |
49 | 103 class DoomsdayVirus(Schematic): |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
104 NAME = "doomsday virus" |
32 | 105 COST = 100000 |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
106 CATEGORIES = (cat.DOOMSDAY_DEVICE, cat.PATHOGEN) |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
107 PREREQUISITES = ( |
14 | 108 (research.Biogenetics, 5), |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
109 ) |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
110 |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
111 |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
112 class PropagandaMachine(Schematic): |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
113 NAME = "propaganda machine" |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
114 COST = 1000 |
91
c57b5b46d3e0
Better mission data management.
Jeremy Thurgood <firxen@gmail.com>
parents:
85
diff
changeset
|
115 CATEGORIES = (cat.MIND_CONTROL,) |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
116 PREREQUISITES = ( |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
117 (research.Psychology, 2), |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
118 ) |
116 | 119 |
120 | |
121 class GiantSquid(Schematic): | |
122 NAME = "giant squid" | |
123 COST = 50000 | |
124 CATEGORIES = (cat.BEAST, cat.AQUATIC) | |
125 PREREQUISITES = ( | |
126 (research.MarineBiology, 20), | |
127 (research.Biogenetics, 15), | |
128 ) | |
129 | |
130 | |
131 class SharksWithFrickinLasers(Schematic): | |
132 NAME = "sharks with frickin' lasers" | |
133 COST = 20000 | |
134 CATEGORIES = (cat.BEAST, cat.AQUATIC) | |
135 PREREQUISITES = ( | |
136 (research.MarineBiology, 10), | |
137 (research.Lasers, 7), | |
138 ) |