Mercurial > sypikslang
annotate gamelib/schematics.py @ 87:d93e1ea2bd0d
Fix method name assumption bug
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Wed, 09 May 2012 20:06:44 +0200 |
parents | 182fce9f70b6 |
children | c57b5b46d3e0 |
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', |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
18 ) |
32 | 19 |
20 | |
49 | 21 class Schematic(Science): |
54 | 22 # For all Schematics |
23 SCIENCE_TYPE = 'schematic' | |
24 | |
25 # Acquisition | |
26 STARTING_PRODUCT = False | |
6
826b44731323
Start of basic lab implementation.
Jeremy Thurgood <firxen@gmail.com>
parents:
3
diff
changeset
|
27 ACQUISITION_CHANCE = 0.8 |
54 | 28 CATEGORIES = () |
29 | |
30 # Costs | |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
31 UPGRADE_REQUIREMENT = 1 |
54 | 32 COST = None |
33 | |
34 # Power and reliability | |
35 PROTOTYPE_RELIABILITY = 0.4 | |
36 PRODUCTION_RELIABILITY = 0.8 | |
37 BASE_POWER = None | |
38 POWER_INCREMENT = None | |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
39 |
58
52913ba12988
Check for multiple points in can_spend
Neil Muller <drnlmuller@gmail.com>
parents:
54
diff
changeset
|
40 def can_spend(self, lab, spend): |
52913ba12988
Check for multiple points in can_spend
Neil Muller <drnlmuller@gmail.com>
parents:
54
diff
changeset
|
41 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
|
42 return lab.meet_requirements(self, extra) |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
43 |
34 | 44 def is_a(self, category): |
45 return category in self.CATEGORIES | |
46 | |
54 | 47 def reliability(self): |
48 if self.points: | |
49 exp = 1 + 0.5 * (self.points - 1) | |
50 return 1.0 - ((1.0 - self.PRODUCTION_RELIABILITY) ** exp) | |
51 return self.PROTOTYPE_RELIABILITY | |
52 | |
53 def power(self): | |
54 power = self.BASE_POWER | |
55 if None not in (power, self.POWER_INCREMENT): | |
56 power += self.POWER_INCREMENT * self.points | |
57 return power | |
58 | |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
59 |
49 | 60 class MachineGun(Schematic): |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
61 NAME = "machine gun" |
15 | 62 COST = 100 |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
63 CATEGORIES = (cat.HAND_WEAPON,) |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
64 STARTING_PRODUCT = True |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
65 |
20 | 66 def __init__(self, points=0): |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
67 self.points = 1 |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
68 |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
69 def spend_point(self): |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
70 raise NotImplementedError() |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
71 |
58
52913ba12988
Check for multiple points in can_spend
Neil Muller <drnlmuller@gmail.com>
parents:
54
diff
changeset
|
72 def can_spend(self, lab, spend): |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
73 return False |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
74 |
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
75 |
49 | 76 class LightningGun(Schematic): |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
77 NAME = "lightning gun" |
32 | 78 COST = 300 |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
79 CATEGORIES = (cat.HAND_WEAPON,) |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
80 PREREQUISITES = ( |
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
81 (research.Tesla, 1), |
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
82 ) |
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 TeslaTank(Schematic): |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
86 NAME = "tesla tank" |
32 | 87 COST = 1000 |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
88 CATEGORIES = (cat.VEHICLE,) |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
89 PREREQUISITES = ( |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
90 (research.Tesla, 3), |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
91 ) |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
92 |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
15
diff
changeset
|
93 |
49 | 94 class DoomsdayVirus(Schematic): |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
95 NAME = "doomsday virus" |
32 | 96 COST = 100000 |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
97 CATEGORIES = (cat.DOOMSDAY_DEVICE, cat.PATHOGEN) |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
98 PREREQUISITES = ( |
14 | 99 (research.Biogenetics, 5), |
3
6ab4f1ab9eab
Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff
changeset
|
100 ) |
85
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
101 |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
102 |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
103 class PropagandaMachine(Schematic): |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
104 NAME = "propaganda machine" |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
105 COST = 1000 |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
106 CATEGORIES = (cat.MIND_CONTROL) |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
107 PREREQUISITES = ( |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
108 (research.Psychology, 2), |
182fce9f70b6
Propaganda! Also, a fix to blueprint breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
109 ) |