diff gamelib/schematics.py @ 54:168cfac9a445

Power and reliability.
author Jeremy Thurgood <firxen@gmail.com>
date Mon, 07 May 2012 22:43:54 +0200
parents 373c57ab4140
children 52913ba12988
line wrap: on
line diff
--- a/gamelib/schematics.py	Mon May 07 22:10:26 2012 +0200
+++ b/gamelib/schematics.py	Mon May 07 22:43:54 2012 +0200
@@ -1,3 +1,5 @@
+# -*- test-case-name: gamelib.tests.test_schematics -*-
+
 from gamelib import research
 from gamelib.game_base import Science
 
@@ -10,12 +12,23 @@
 
 
 class Schematic(Science):
+    # For all Schematics
+    SCIENCE_TYPE = 'schematic'
+
+    # Acquisition
+    STARTING_PRODUCT = False
     ACQUISITION_CHANCE = 0.8
-    COST = None
+    CATEGORIES = ()
+
+    # Costs
     UPGRADE_REQUIREMENT = 1
-    STARTING_PRODUCT = False
-    SCIENCE_TYPE = 'schematic'
-    CATEGORIES = ()
+    COST = None
+
+    # Power and reliability
+    PROTOTYPE_RELIABILITY = 0.4
+    PRODUCTION_RELIABILITY = 0.8
+    BASE_POWER = None
+    POWER_INCREMENT = None
 
     def can_spend(self, lab):
         extra = self.UPGRADE_REQUIREMENT * self.points + 1
@@ -24,6 +37,18 @@
     def is_a(self, category):
         return category in self.CATEGORIES
 
+    def reliability(self):
+        if self.points:
+            exp = 1 + 0.5 * (self.points - 1)
+            return 1.0 - ((1.0 - self.PRODUCTION_RELIABILITY) ** exp)
+        return self.PROTOTYPE_RELIABILITY
+
+    def power(self):
+        power = self.BASE_POWER
+        if None not in (power, self.POWER_INCREMENT):
+            power += self.POWER_INCREMENT * self.points
+        return power
+
 
 class MachineGun(Schematic):
     NAME = "Machine gun"