2 # 20,000 Light Years Into Space
3 # This game is licensed under GPL v2, and copyright (C) Jack Whitham 2006-07.
6 # A model for the movement of steam within the system.
9 from primitives
import *
13 # Don't understand steam? Confused by the thought of
14 # boiling water being used as a source of energy?
15 # Why not just assume that it's electricity.
17 def __init__(self
,node
):
19 self
.capacitance
= 1.0
24 self
.capacity
= INITIAL_NODE_CAPACITY
30 def Source(self
, current
):
31 dq
= current
* self
.TIME_CONSTANT
35 def Think(self
, neighbour_list
):
36 self
.voltage
= self
.charge
/ self
.capacitance
39 for (neighbour
, resist
, max_intensity
) in neighbour_list
:
41 # Potential difference:
42 dv
= self
.voltage
- neighbour
.voltage
43 if ( dv
>= self
.NEGLIGIBLE
):
50 dq
= i
* self
.TIME_CONSTANT
53 if (adq
>1): dq
/=math
.sqrt(adq
) # Limit accurracy problems
54 # Apply Intensity Limit
55 if (dq
>max_intensity
*self
.TIME_CONSTANT
):
56 dq
=max_intensity
*self
.TIME_CONSTANT
58 if (dq
<-max_intensity
*self
.TIME_CONSTANT
):
59 dq
=-max_intensity
*self
.TIME_CONSTANT
61 if ( self
.charge
-dq
> self
.capacity
):
62 dq
=self
.charge
-self
.capacity
63 if ( neighbour
.charge
+dq
> neighbour
.capacity
):
64 dq
=neighbour
.capacity
-neighbour
.charge
66 i
= dq
/ self
.TIME_CONSTANT
70 neighbour
.charge
+= dq
78 original_charge
=self
.charge
79 if ( self
.charge
< 0 ):
81 elif ( self
.charge
> self
.capacity
):
82 self
.charge
= self
.capacity
# vent
84 diff_charge
=original_charge
-self
.charge
86 if len(self
.node
.pipes
)>0:
87 diff_charge
/=len(self
.node
.pipes
)
89 for pipe
in self
.node
.pipes
:
90 if pipe
.n1
==self
.node
: dest
=pipe
.n2
91 if pipe
.n2
==self
.node
: dest
=pipe
.n1
92 dest
.steam
.charge
+=diff_charge
96 def Get_Pressure(self
):
99 def Get_Capacity(self
):
102 def Capacity_Upgrade(self
):
103 self
.capacity
+= CAPACITY_UPGRADE
105 class Steam_Model(Voltage_Model
):