annotate gamelib/schematics.py @ 85:182fce9f70b6

Propaganda! Also, a fix to blueprint breakthroughs.
author Jeremy Thurgood <firxen@gmail.com>
date Wed, 09 May 2012 20:02:28 +0200
parents 52913ba12988
children c57b5b46d3e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
54
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
1 # -*- test-case-name: gamelib.tests.test_schematics -*-
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
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
00aff02bc6fc Product categories.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
19
00aff02bc6fc Product categories.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
20
49
373c57ab4140 Product -> Schematic.
Jeremy Thurgood <firxen@gmail.com>
parents: 45
diff changeset
21 class Schematic(Science):
54
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
22 # For all Schematics
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
23 SCIENCE_TYPE = 'schematic'
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
24
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
25 # Acquisition
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
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
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
28 CATEGORIES = ()
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
29
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
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
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
32 COST = None
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
33
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
34 # Power and reliability
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
35 PROTOTYPE_RELIABILITY = 0.4
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
36 PRODUCTION_RELIABILITY = 0.8
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
37 BASE_POWER = None
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
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
20ed2843adec More categories.
Jeremy Thurgood <firxen@gmail.com>
parents: 32
diff changeset
44 def is_a(self, category):
20ed2843adec More categories.
Jeremy Thurgood <firxen@gmail.com>
parents: 32
diff changeset
45 return category in self.CATEGORIES
20ed2843adec More categories.
Jeremy Thurgood <firxen@gmail.com>
parents: 32
diff changeset
46
54
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
47 def reliability(self):
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
48 if self.points:
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
49 exp = 1 + 0.5 * (self.points - 1)
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
50 return 1.0 - ((1.0 - self.PRODUCTION_RELIABILITY) ** exp)
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
51 return self.PROTOTYPE_RELIABILITY
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
52
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
53 def power(self):
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
54 power = self.BASE_POWER
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
55 if None not in (power, self.POWER_INCREMENT):
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
56 power += self.POWER_INCREMENT * self.points
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
57 return power
168cfac9a445 Power and reliability.
Jeremy Thurgood <firxen@gmail.com>
parents: 49
diff changeset
58
3
6ab4f1ab9eab Very basics of research and products.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
59
49
373c57ab4140 Product -> Schematic.
Jeremy Thurgood <firxen@gmail.com>
parents: 45
diff changeset
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
8865ba0c9c38 Add cost to products
Neil Muller <drnlmuller@gmail.com>
parents: 14
diff changeset
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
718d1ec382f7 Deserialise lab data.
Jeremy Thurgood <firxen@gmail.com>
parents: 17
diff changeset
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
373c57ab4140 Product -> Schematic.
Jeremy Thurgood <firxen@gmail.com>
parents: 45
diff changeset
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
00aff02bc6fc Product categories.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
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
373c57ab4140 Product -> Schematic.
Jeremy Thurgood <firxen@gmail.com>
parents: 45
diff changeset
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
00aff02bc6fc Product categories.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
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
373c57ab4140 Product -> Schematic.
Jeremy Thurgood <firxen@gmail.com>
parents: 45
diff changeset
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
00aff02bc6fc Product categories.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
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
9d61abb3cfaf Better subclass handling.
Jeremy Thurgood <firxen@gmail.com>
parents: 6
diff changeset
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 )