2 #Copyright (C) 2005,2006 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 player class.
25 def __init__(self
, cash
, time_sec
=0, time_min
=0, time_hour
=0, time_day
=0):
27 self
.time_sec
= time_sec
28 self
.time_min
= time_min
29 self
.time_hour
= time_hour
30 self
.time_day
= time_day
31 self
.interest_rate
= 1
34 self
.labor_bonus
= 10000
35 self
.job_bonus
= 10000
36 self
.discover_bonus
= (10000, 10000, 10000, 10000)
37 self
.suspicion_bonus
= (1, 1, 1, 1)
38 self
.suspicion
= (0, 0, 0, 0)
40 def give_time(self
, time_sec
):
42 store_last_minute
= self
.time_min
43 store_last_day
= self
.time_day
47 self
.time_sec
+= time_sec
48 if self
.time_sec
>= 60:
49 time_min
+= self
.time_sec
/ 60
50 self
.time_sec
= self
.time_sec
% 60
51 self
.time_min
+= time_min
52 if self
.time_min
>= 60:
53 time_hour
+= self
.time_min
/ 60
54 self
.time_min
= self
.time_min
% 60
55 self
.time_hour
+= time_hour
56 if self
.time_hour
>= 24:
57 time_day
+= self
.time_hour
/ 24
58 self
.time_hour
= self
.time_hour
% 24
59 self
.time_day
+= time_day
62 for base_loc
in g
.bases
:
63 for base_name
in g
.bases
[base_loc
]:
64 #Construction of new bases:
65 if base_name
.built
== 0:
66 tmp_base_time
= (base_name
.cost
[2] * self
.labor_bonus
) /10000
67 if tmp_base_time
== 0:
68 money_towards
= base_name
.cost
[0]
69 cpu_towards
= base_name
.cost
[1]
70 if cpu_towards
> self
.cpu_for_day
:
71 cpu_towards
= self
.cpu_for_day
73 money_towards
= (time_min
*base_name
.cost
[0]) / \
75 if money_towards
> base_name
.cost
[0]:
76 money_towards
= base_name
.cost
[0]
77 cpu_towards
= (time_min
*base_name
.cost
[1]) / \
79 if cpu_towards
> base_name
.cost
[1]:
80 cpu_towards
= base_name
.cost
[1]
81 if cpu_towards
> self
.cpu_for_day
:
82 cpu_towards
= self
.cpu_for_day
83 if money_towards
<= self
.cash
:
84 self
.cash
-= money_towards
85 self
.cpu_for_day
-= cpu_towards
86 built_base
= base_name
.study((money_towards
,
87 cpu_towards
, time_min
))
90 g
.create_dialog(g
.strings
["construction0"]+" "+
91 base_name
.name
+" "+g
.strings
["construction1"],
92 g
.font
[0][18], (g
.screen_size
[0]/2 - 100, 50),
93 (200, 200), g
.colors
["dark_blue"],
94 g
.colors
["white"], g
.colors
["white"])
97 #Construction of items:
99 for item
in base_name
.usage
:
100 if item
== 0: continue
101 tmp
= item
.work_on(time_min
) or tmp
104 g
.create_dialog(g
.strings
["construction0"]+" "+
105 item
.item_type
.name
+" "+
106 g
.strings
["item_construction1"]+" "+
108 g
.font
[0][18], (g
.screen_size
[0]/2 - 100, 50),
109 (200, 200), g
.colors
["dark_blue"],
110 g
.colors
["white"], g
.colors
["white"])
112 for item
in base_name
.extra_items
:
113 if item
== 0: continue
114 tmp
= item
.work_on(time_min
)
117 g
.create_dialog(g
.strings
["construction0"]+" "+
118 item
.item_type
.name
+" "+
119 g
.strings
["item_construction1"]+" "+
121 g
.font
[0][18], (g
.screen_size
[0]/2 - 100, 50),
122 (200, 200), g
.colors
["dark_blue"],
123 g
.colors
["white"], g
.colors
["white"])
127 for i
in range(self
.time_day
- store_last_day
):
128 needs_refresh
= self
.new_day() or needs_refresh
132 #Run every day at midnight.
135 #interest and income.
136 self
.cash
+= (self
.interest_rate
* self
.cash
) / 10000
137 self
.cash
+= self
.income
139 self
.suspicion
= (self
.suspicion
[0] - self
.suspicion_bonus
[0],
140 self
.suspicion
[1] - self
.suspicion_bonus
[1],
141 self
.suspicion
[2] - self
.suspicion_bonus
[2],
142 self
.suspicion
[3] - self
.suspicion_bonus
[3])
143 if self
.suspicion
[0] <= 0: self
.suspicion
= (0, self
.suspicion
[1],
144 self
.suspicion
[2], self
.suspicion
[3])
145 if self
.suspicion
[1] <= 0: self
.suspicion
= (self
.suspicion
[0], 0,
146 self
.suspicion
[2], self
.suspicion
[3])
147 if self
.suspicion
[2] <= 0: self
.suspicion
= (self
.suspicion
[0],
148 self
.suspicion
[1], 0, self
.suspicion
[3])
149 if self
.suspicion
[3] <= 0: self
.suspicion
= (self
.suspicion
[0],
150 self
.suspicion
[1], self
.suspicion
[2], 0)
153 for base_loc
in g
.bases
:
156 for base_name
in g
.bases
[base_loc
]:
158 #Does base get detected?
159 #Give a grace period.
160 if self
.time_day
- base_name
.built_date
> base_name
.base_type
.cost
[2]*2:
161 tmp_d_chance
= base_name
.get_d_chance()
163 print "Chance of discovery for base %s: %s" % \
164 (base_name
.name
, repr (tmp_d_chance
))
165 #Note that I'm filling removal_index from the front
166 #in order to make base removal easier.
167 if g
.roll_percent(tmp_d_chance
[0]) == 1:
168 removal_index
.insert(0, (loc_in_array
, "news"))
169 elif g
.roll_percent(tmp_d_chance
[1]) == 1:
170 removal_index
.insert(0, (loc_in_array
, "science"))
171 elif g
.roll_percent(tmp_d_chance
[2]) == 1:
172 removal_index
.insert(0, (loc_in_array
, "covert"))
173 elif g
.roll_percent(tmp_d_chance
[3]) == 1:
174 removal_index
.insert(0, (loc_in_array
, "person"))
176 if base_name
.built
== 1:
178 self
.cash
-= base_name
.base_type
.mainten
[0]
179 if self
.cash
< 0: self
.cash
= 0
181 self
.cpu_for_day
-= base_name
.base_type
.mainten
[1]
182 if self
.cpu_for_day
< 0: self
.cpu_for_day
= 0
186 if base_name
.studying
== "":
187 self
.cpu_for_day
+= base_name
.processor_time()
191 if g
.jobs
.has_key(base_name
.studying
):
192 self
.cash
+= (g
.jobs
[base_name
.studying
][0]*
193 base_name
.processor_time())
195 if g
.techs
["Advanced Simulacra"].known
== 1:
197 self
.cash
+= (g
.jobs
[base_name
.studying
][0]*
198 base_name
.processor_time())/10
201 #tech aready known. This should occur when multiple
202 #bases are studying the same tech.
203 if g
.techs
[base_name
.studying
].known
== 1:
204 base_name
.studying
= ""
205 self
.cpu_for_day
+= base_name
.processor_time()
208 if g
.techs
[base_name
.studying
].cost
[1] == 0:
209 money_towards
= g
.techs
[base_name
.studying
].cost
[0]
212 tmp_base_time
= base_name
.processor_time()
213 money_towards
= (tmp_base_time
*
214 g
.techs
[base_name
.studying
].cost
[0])/ \
215 (g
.techs
[base_name
.studying
].cost
[1])
216 if money_towards
> g
.techs
[base_name
.studying
].cost
[0]:
217 money_towards
=g
.techs
[base_name
.studying
].cost
[0]
218 if money_towards
<= self
.cash
:
220 print "Studying "+base_name
.studying
+": "+ \
221 str(money_towards
)+" Money, "+str(tmp_base_time
)+" CPU"
222 self
.cash
-= money_towards
223 learn_tech
= g
.techs
[base_name
.studying
].study(
224 (money_towards
, tmp_base_time
, 0))
227 g
.create_dialog(g
.strings
["tech_construction0"]+" "+
228 g
.techs
[base_name
.studying
].name
+" "+
229 g
.strings
["construction1"]+" "+
230 g
.techs
[base_name
.studying
].result
,
231 g
.font
[0][18], (g
.screen_size
[0]/2 - 100, 50),
232 (200, 200), g
.colors
["dark_blue"],
233 g
.colors
["white"], g
.colors
["white"])
234 base_name
.studying
= ""
237 print "NOT Studying "+base_name
.studying
+": "+ \
238 str(money_towards
)+"/"+str(self
.cash
)+" Money"
240 for detection_succeed
in removal_index
:
241 if detection_succeed
[1] == "news":
242 self
.increase_suspicion((1000, 0, 0, 0))
243 detect_phrase
= g
.strings
["discover_news"]
244 elif detection_succeed
[1] == "science":
245 self
.increase_suspicion((0, 1000, 0, 0))
246 detect_phrase
= g
.strings
["discover_science"]
247 elif detection_succeed
[1] == "covert":
248 self
.increase_suspicion((0, 0, 1000, 0))
249 detect_phrase
= g
.strings
["discover_covert"]
250 elif detection_succeed
[1] == "person":
251 self
.increase_suspicion((0, 0, 0, 1000))
252 detect_phrase
= g
.strings
["discover_public"]
253 else: print "error detecting base: "+detection_succeed
[1]
254 g
.create_dialog(g
.strings
["discover0"]+" "+
255 g
.bases
[base_loc
][detection_succeed
[0]].name
+" "+
256 g
.strings
["discover1"]+" "+detect_phrase
,
257 g
.font
[0][18], (g
.screen_size
[0]/2 - 100, 50),
258 (200, 200), g
.colors
["dark_blue"],
259 g
.colors
["white"], g
.colors
["white"])
261 g
.bases
[base_loc
].pop(detection_succeed
[0])
263 g
.base
.renumber_bases(g
.bases
[base_loc
])
264 #I need to recheck after going through all bases as research
265 #worked on by multiple bases doesn't get erased properly otherwise.
266 for base_loc
in g
.bases
:
267 for base
in g
.bases
[base_loc
]:
268 if base
.studying
== "": continue
269 if g
.jobs
.has_key(base
.studying
): continue
270 if g
.techs
[base
.studying
].known
== 1:
274 def increase_suspicion(self
, amount
):
275 self
.suspicion
= (self
.suspicion
[0]+amount
[0], self
.suspicion
[1]+amount
[1],
276 self
.suspicion
[2]+amount
[2], self
.suspicion
[3]+amount
[3])
277 if self
.suspicion
[0] <= 0: self
.suspicion
= (0, self
.suspicion
[1],
278 self
.suspicion
[2], self
.suspicion
[3])
279 if self
.suspicion
[1] <= 0: self
.suspicion
= (self
.suspicion
[0], 0,
280 self
.suspicion
[2], self
.suspicion
[3])
281 if self
.suspicion
[2] <= 0: self
.suspicion
= (self
.suspicion
[0],
282 self
.suspicion
[1], 0, self
.suspicion
[3])
283 if self
.suspicion
[3] <= 0: self
.suspicion
= (self
.suspicion
[0],
284 self
.suspicion
[1], self
.suspicion
[2], 0)
288 if self
.suspicion
[0] >= 10000 or self
.suspicion
[1] >= 10000 or \
289 self
.suspicion
[2] >= 10000 or self
.suspicion
[3] >= 10000:
291 if (len(g
.bases
["N AMERICA"]) == 0 and
292 len(g
.bases
["S AMERICA"]) == 0 and
293 len(g
.bases
["EUROPE"]) == 0 and
294 len(g
.bases
["ASIA"]) == 0 and
295 len(g
.bases
["AFRICA"]) == 0 and
296 len(g
.bases
["ANTARCTIC"]) == 0 and
297 len(g
.bases
["OCEAN"]) == 0 and
298 len(g
.bases
["MOON"]) == 0 and
299 len(g
.bases
["FAR REACHES"]) == 0 and
300 len(g
.bases
["TRANSDIMENSIONAL"]) == 0):
304 #returns the amount of cash available after taking into account all
305 #current projects in construction.
306 def future_cash(self
):
307 result_cash
= self
.cash
308 for base_loc
in g
.bases
:
309 for base_name
in g
.bases
[base_loc
]:
310 result_cash
-= base_name
.cost
[0]
311 if g
.techs
.has_key(base_name
.studying
):
312 result_cash
-= g
.techs
[base_name
.studying
].cost
[0]
313 for item
in base_name
.usage
:
314 if item
!= 0: result_cash
-= item
.cost
[0]
315 for item
in base_name
.extra_items
:
316 if item
!= 0: result_cash
-= item
.cost
[0]
321 # money_towards = base_name.cost[0] / \
323 # if money_towards <= self.cash:
324 # self.cash -= money_towards
325 # base_name.study((money_towards, 0,
326 # self.time_day - store_last_day))
328 # base_name.cost = (base_name.cost[0] - money_towards,
329 # base_name.cost[1], base_name.cost[2])
330 # self.cash -= money_towards
331 # base_name.cost = (base_name.cost[0], base_name.cost[1],
332 # base_name.cost[2] - ())