changeset 146:2587f8c34f84

Science juggling and visualization improvements.
author Jeremy Thurgood <firxen@gmail.com>
date Fri, 11 May 2012 16:20:49 +0200
parents 53277724645b
children 3d24b18d1785
files gamelib/schematics.py gamelib/visualize.py
diffstat 2 files changed, 83 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/schematics.py	Fri May 11 14:58:00 2012 +0200
+++ b/gamelib/schematics.py	Fri May 11 16:20:49 2012 +0200
@@ -17,7 +17,7 @@
     'MIND_CONTROL',
     'BEAST',
     'AQUATIC',
-    'SPY',
+    'INTELLIGENCE',
     'AI',
     )
 
@@ -34,6 +34,7 @@
     # Costs
     UPGRADE_REQUIREMENT = 1
     COST = None
+    MAX_UPGRADE = 5
 
     # Power and reliability
     PROTOTYPE_RELIABILITY = 0.4
@@ -45,7 +46,9 @@
     IMAGE_NAME = "physics"
 
     def can_spend(self, lab, spend):
-        extra = self.UPGRADE_REQUIREMENT * self.points + spend
+        if self.points + spend > self.MAX_UPGRADE:
+            return False
+        extra = self.UPGRADE_REQUIREMENT * (self.points + spend)
         return lab.meet_requirements(self, extra)
 
     def is_a(self, category):
@@ -77,15 +80,12 @@
     CATEGORIES = (cat.HAND_WEAPON,)
     STARTING_PRODUCT = True
 
+    BASE_POWER = 10
+    PRODUCTION_RELIABILITY = 1.0
+
     def __init__(self, points=0):
         self.points = 1
 
-    def spend_point(self):
-        raise NotImplementedError()
-
-    def can_spend(self, lab, spend):
-        return False
-
 
 class LightningGun(Schematic):
     NAME = "lightning gun"
@@ -95,15 +95,21 @@
         (research.Electrickery, 1),
         )
 
+    BASE_POWER = 10
+
 
 class TeslaTank(Schematic):
     NAME = "tesla tank"
-    COST = 1000
+    COST = 40000
     CATEGORIES = (cat.VEHICLE,)
     PREREQUISITES = (
-        (research.Electrickery, 3),
+        (research.Electrickery, 5),
+        (research.Robotics, 1),
         )
 
+    BASE_POWER = 100
+    POWER_INCREMENT = 10
+
 
 class DoomsdayVirus(Schematic):
     NAME = "doomsday virus"
@@ -143,41 +149,52 @@
         )
 
 
-class OrbitalLaserPlatform(Schematic):
-    NAME = "An Orbital Laser Platform"
-    COST = 10000000
-    CATEGORIES = (cat.DOOMSDAY_DEVICE,)
+class GiantRobot(Schematic):
+    NAME = "giant robot"
+    COST = 2500000
+    CATEGORIES = (cat.DOOMSDAY_DEVICE, cat.AI)
     PREREQUISITES = (
-        (research.Lasers, 5),
-        (research.Space, 2),
+        (research.Robotics, 15),
+        (research.ArtificialIntelligence, 10),
         )
 
 
-class GiantRobot(Schematic):
-    NAME = "A very large robot"
-    COST = 1000000
-    CATEGORIES = (cat.DOOMSDAY_DEVICE,)
+class ObservationDrone(Schematic):
+    NAME = "observation drone"
+    COST = 6000
+    CATEGORIES = (cat.INTELLIGENCE,)
     PREREQUISITES = (
-        (research.Robotics, 5),
-        (research.ArtificialIntelligence, 2),
+        (research.Robotics, 3),
         )
 
 
-class SpySattelite(Schematic):
-    NAME = "A small spy sattelite"
-    COST = 10000
-    CATEGORIES = (cat.SPY,)
+class SpySatellite(Schematic):
+    NAME = "spy satellite"
+    COST = 100000
+    CATEGORIES = (cat.INTELLIGENCE,)
     PREREQUISITES = (
+        (research.Rocketry, 5),
         (research.Space, 1),
         )
 
 
-class ComputerAI(Schematic):
-    NAME = "AI Assistant"
+class OrbitalLaserPlatform(Schematic):
+    NAME = "orbital laser platform"
+    COST = 10000000
+    CATEGORIES = (cat.DOOMSDAY_DEVICE,)
+    PREREQUISITES = (
+        (SpySatellite, 3),
+        (research.Lasers, 15),
+        (research.Space, 5),
+        )
+
+
+class TacticalAI(Schematic):
+    NAME = "tactical AI"
     COST = 10000
-    CATEGORIES = (cat.AI,)
+    CATEGORIES = (cat.AI, cat.INTELLIGENCE)
     PREREQUISITES = (
-        (research.ArtificialIntelligence, 1),
+        (research.ArtificialIntelligence, 3),
         )
 
 
@@ -186,5 +203,5 @@
     COST = 300
     CATEGORIES = (cat.HAND_WEAPON,)
     PREREQUISITES = (
-        (research.Lasers, 1),
+        (research.Lasers, 2),
         )
--- a/gamelib/visualize.py	Fri May 11 14:58:00 2012 +0200
+++ b/gamelib/visualize.py	Fri May 11 16:20:49 2012 +0200
@@ -3,30 +3,43 @@
 from gamelib.lab import Lab
 
 
+COLORS = {
+    'schematic': 'green',
+    'research': 'pink',
+    }
+
+
+def color(science):
+    return COLORS[science.SCIENCE_TYPE]
+
+
+def add_node(rt, science):
+    rt.add_node(science, label=science.NAME, color=color(science))
+
+
+def add_pre_node(rt, prior, science, points):
+    name = "%s%s" % (science.NAME[:3], points)
+    if name not in rt:
+        rt.add_node(name, color=color(science))
+        rt.add_edge(prior, name, color=color(science))
+    return name
+
+
+def add_prereqs(rt, science):
+    for pre, points in science.PREREQUISITES:
+        prior = pre
+        for i in range(points):
+            prior = add_pre_node(rt, prior, pre, i + 1)
+        rt.add_edge(prior, science, color=color(science))
+
+
 def construct_research_tree(lab):
     rt = networkx.DiGraph()
-    for research in lab.new_research:
-        rt.add_node(research, label=research.NAME, color='green')
-    for research in lab.new_research:
-        for prereq in research.PREREQUISITES:
-            prefix = prereq[0].NAME[0:3]
-            cur = prereq[0]
-            for i in range(1, prereq[1] + 1):
-                rt.add_node(prefix + str(i), color='green')
-                rt.add_edge(cur, prefix + str(i), color='green')
-                cur = prefix + str(i)
-            rt.add_edge(cur, research, color='green')
-    for schematic in lab.new_schematics:
-        rt.add_node(schematic, label=schematic.NAME, color='pink')
-    for schematic in lab.new_schematics:
-        for prereq in schematic.PREREQUISITES:
-            prefix = prereq[0].NAME[0:3]
-            cur = prereq[0]
-            for i in range(1, prereq[1] + 1):
-                rt.add_node(prefix + str(i), color='pink')
-                rt.add_edge(cur, prefix + str(i), color='pink')
-                cur = prefix + str(i)
-            rt.add_edge(cur, schematic, color='pink')
+    sciences = lab.new_research + lab.new_schematics
+    for science in sciences:
+        add_node(rt, science)
+    for science in sciences:
+        add_prereqs(rt, science)
     return rt