2 #Copyright (C) 2005 Evil Mr Henry and Phil Bordelon
3 #This file is part of Endgame: Singularity.
5 #Endgame: Singularity is free software; you can redistribute it and/or modify
6 #it under the terms of the GNU General Public License as published by
7 #the Free Software Foundation; either version 2 of the License, or
8 #(at your option) any later version.
10 #Endgame: Singularity is distributed in the hope that it will be useful,
11 #but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 #GNU General Public License for more details.
15 #You should have received a copy of the GNU General Public License
16 #along with Endgame: Singularity; if not, write to the Free Software
17 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #This file contains the base class.
25 #cost = (money, ptime, labor)
26 #detection = (news, science, covert, person)
28 def __init__(self
, name
, descript
, size
, regions
, d_chance
, cost
,
32 self
.descript
= descript
34 self
.regions
= regions
35 self
.d_chance
= d_chance
38 self
.mainten
= mainten
43 def __init__(self
, ID
, name
, base_type
, built
):
46 self
.base_type
= base_type
48 self
.built_date
= g
.pl
.time_day
51 #Base suspicion is currently unused
52 self
.suspicion
= (0, 0, 0, 0)
53 self
.usage
= [0] * self
.base_type
.size
54 # for i in range(self.base_type.size):
55 # self.usage.append(0)
56 if self
.base_type
.base_id
== "Stolen Computer Time":
57 self
.usage
[0] = g
.item
.item(g
.items
["PC"])
59 elif self
.base_type
.base_id
== "Server Access":
60 self
.usage
[0] = g
.item
.item(g
.items
["Server"])
62 elif self
.base_type
.base_id
== "Time Capsule":
63 self
.usage
[0] = g
.item
.item(g
.items
["PC"])
65 #Reactor, network, security.
66 self
.extra_items
= [0] * 3
70 self
.cost
= (base_type
.cost
[0], base_type
.cost
[1],
71 base_type
.cost
[2]*24*60)
73 def study(self
, cost_towards
):
74 if cost_towards
[1] < 0 and g
.debug
== 1:
75 print "WARNING: Got a negative cost_towards for CPU. Something is deeply amiss."
76 self
.cost
= (self
.cost
[0]-cost_towards
[0], self
.cost
[1]-cost_towards
[1],
77 self
.cost
[2]-cost_towards
[2])
78 if self
.cost
[0] <= 0: self
.cost
= (0, self
.cost
[1], self
.cost
[2])
79 if self
.cost
[1] <= 0: self
.cost
= (self
.cost
[0], 0, self
.cost
[2])
80 if self
.cost
[2] <= 0: self
.cost
= (self
.cost
[0], self
.cost
[1], 0)
81 if self
.cost
== (0, 0, 0):
83 self
.built_date
= g
.pl
.time_day
86 #Get detection chance for the base, applying bonuses as needed.
87 def get_d_chance(self
):
88 temp_d_chance
= self
.base_type
.d_chance
89 #Factor in both per-base suspicion adjustments and player
90 #suspicion adjustments.
91 temp_d_chance
= ((temp_d_chance
[0]*(10000+g
.pl
.suspicion
[0])/10000),
92 (temp_d_chance
[1]*(10000+g
.pl
.suspicion
[1])/10000),
93 (temp_d_chance
[2]*(10000+g
.pl
.suspicion
[2])/10000),
94 (temp_d_chance
[3]*(10000+g
.pl
.suspicion
[3])/10000))
96 temp_d_chance
= ((temp_d_chance
[0]*(10000+self
.suspicion
[0])/10000),
97 (temp_d_chance
[1]*(10000+self
.suspicion
[1])/10000),
98 (temp_d_chance
[2]*(10000+self
.suspicion
[2])/10000),
99 (temp_d_chance
[3]*(10000+self
.suspicion
[3])/10000))
101 #Factor in technology-based discovery bonus.
102 temp_d_chance
= ((temp_d_chance
[0]*g
.pl
.discover_bonus
[0])/10000,
103 (temp_d_chance
[1]*g
.pl
.discover_bonus
[1])/10000,
104 (temp_d_chance
[2]*g
.pl
.discover_bonus
[2])/10000,
105 (temp_d_chance
[3]*g
.pl
.discover_bonus
[3])/10000)
107 if self
.extra_items
[0] != 0:
108 temp_d_chance
= ((temp_d_chance
[0]*3)/4,
109 (temp_d_chance
[1]*3)/4,
110 (temp_d_chance
[2]*3)/4,
111 (temp_d_chance
[3]*3)/4)
112 if self
.extra_items
[2] != 0:
113 temp_d_chance
= (temp_d_chance
[0]/2,
118 #Return the number of units the given base has of a computer.
121 for item
in self
.usage
:
122 if item
== 0: continue
123 if item
.built
== 0: continue
127 #Return how many units of CPU the base can contribute each day.
128 def processor_time(self
):
131 for item
in self
.usage
:
132 if item
== 0: continue
133 if item
.built
== 0: continue
134 comp_power
+= item
.item_type
.item_qual
135 if self
.extra_items
[1] != 0:
136 compute_bonus
= self
.extra_items
[1].item_type
.item_qual
137 return (comp_power
* (10000+compute_bonus
))/10000
139 #For the given tech, return 1 if the base can study it, or 0 otherwise.
140 def allow_study(self
, tech_name
):
141 if g
.techs
[tech_name
].danger
== 0: return 1
142 if g
.techs
[tech_name
].danger
== 1:
143 for region
in self
.base_type
.regions
:
144 if region
== "OCEAN" or region
== "MOON" or \
145 region
== "FAR REACHES" or region
== "TRANSDIMENSIONAL":
148 if g
.techs
[tech_name
].danger
== 2:
149 for region
in self
.base_type
.regions
:
150 if region
== "MOON" or \
151 region
== "FAR REACHES" or region
== "TRANSDIMENSIONAL":
155 if g
.techs
[tech_name
].danger
== 3:
156 for region
in self
.base_type
.regions
:
157 if region
== "FAR REACHES" or region
== "TRANSDIMENSIONAL":
161 if g
.techs
[tech_name
].danger
== 4:
162 for region
in self
.base_type
.regions
:
163 if region
== "TRANSDIMENSIONAL":
167 #When a base is removed, call to renumber the remaining bases properly.
168 def renumber_bases(base_array
):
169 for i
in range(len(base_array
)):
172 #When given a location like "ocean", determine if building there is allowed.
173 #Used to determine whether or not to display buttons on the map.
174 def allow_entry_to_loc(location
):
175 if g
.bases
.has_key(location
):
176 if location
== "ANTARCTIC":
177 #TECH (also, look below)
178 if g
.techs
["Autonomous Vehicles"].known
== 1 or \
179 g
.techs
["Advanced Database Manipulation"].known
== 1: return 1
181 if location
== "OCEAN":
182 if g
.techs
["Autonomous Vehicles"].known
== 1: return 1
184 if location
== "MOON":
185 if g
.techs
["Lunar Rocketry"].known
== 1: return 1
187 if location
== "FAR REACHES":
188 if g
.techs
["Fusion Rocketry"].known
== 1: return 1
190 if location
== "TRANSDIMENSIONAL":
191 if g
.techs
["Space-Time Manipulation"].known
== 1: return 1
193 #By this point, only the "boring" locations are left.
194 #Those are always buildable.
197 print "BUG: allow_entry_to_loc called with "+str(location
)