Deavid: Improvements to prevent steam lossmaster
authorDavid Martínez Martí <[email protected]>
Fri, 27 Jun 2008 13:45:10 +0000 (27 15:45 +0200)
committerDavid Martínez Martí <[email protected]>
Fri, 27 Jun 2008 13:45:10 +0000 (27 15:45 +0200)
 ** map_items.py **

 - Well Nodes now calculate hoy many units will produce.

 ** steam_model.py **

 - Nodes now will return the excedent pressure into the system.

code/map_items.py
code/steam_model.py

index aae87b3..409c03a 100644 (file)
@@ -202,7 +202,7 @@ class Node(Building):
         self.pos = (x,y)
         self.max_health = NODE_HEALTH_UNITS * HEALTH_UNIT
         self.base_colour = (255,192,0)
-        self.steam = Steam_Model()
+        self.steam = Steam_Model(self)
         self.draw_obj_finished = draw_obj.Draw_Obj("node.png", 1)
         self.draw_obj_incomplete = draw_obj.Draw_Obj("node_u.png", 1)
         self.draw_obj = self.draw_obj_incomplete
@@ -415,6 +415,18 @@ class Well_Node(Node):
         if ( not self.Needs_Work() ):
             self.production = (DIFFICULTY.BASIC_STEAM_PRODUCTION + (self.tech_level *
                     DIFFICULTY.STEAM_PRODUCTION_PER_LEVEL))
+            max_P=self.steam.capacity
+            min_P=self.steam.charge
+
+            for pipe in self.pipes:
+                if pipe.n1==self: dest=pipe.n2
+                if pipe.n2==self: dest=pipe.n1
+                if dest.steam.charge<min_P:
+                    min_P=dest.steam.charge
+
+            mult = (max_P - min_P) / max_P
+
+            self.production*=mult
             self.steam.Source(self.production)
         else:
             self.production = 0
index 2cca590..4d854dd 100644 (file)
@@ -14,7 +14,7 @@ class Voltage_Model:
     # boiling water being used as a source of energy?
     # Why not just assume that it's electricity.
 
-    def __init__(self):
+    def __init__(self,node):
         # Invariant:
         self.capacitance = 1.0
         # May change:
@@ -22,6 +22,7 @@ class Voltage_Model:
         self.voltage = 0.0
         # Changed by upgrades
         self.capacity = INITIAL_NODE_CAPACITY
+        self.node = node
 
     NEGLIGIBLE = 0.05
     TIME_CONSTANT = 0.1
@@ -74,11 +75,24 @@ class Voltage_Model:
         return currents
 
     def __Bound(self):
+        original_charge=self.charge
         if ( self.charge < 0 ):
             self.charge = 0
         elif ( self.charge > self.capacity ):
             self.charge = self.capacity # vent
 
+        diff_charge=original_charge-self.charge
+
+        if len(self.node.pipes)>0:
+            diff_charge/=len(self.node.pipes)
+
+            for pipe in self.node.pipes:
+                if pipe.n1==self.node: dest=pipe.n2
+                if pipe.n2==self.node: dest=pipe.n1
+                dest.steam.charge+=diff_charge
+
+
+
     def Get_Pressure(self):
         return self.charge