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 is used to display the World Map.
31 import research_screen
34 def display_pause_menu():
35 xy_loc
= (g
.screen_size
[0]/2 - 100, 50)
38 g
.screen
.fill(g
.colors
["white"], (xy_loc
[0], xy_loc
[1], 200, 350))
39 g
.screen
.fill(g
.colors
["black"], (xy_loc
[0]+1, xy_loc
[1]+1, 198, 348))
41 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0]+10, xy_loc
[1]+10), (180, 50),
42 "NEW GAME", 0, g
.font
[1][30]))
43 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0]+10, xy_loc
[1]+80), (180, 50),
44 "SAVE GAME", 0, g
.font
[1][30]))
45 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0]+10, xy_loc
[1]+150), (180, 50),
46 "LOAD GAME", 0, g
.font
[1][30]))
47 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0]+10, xy_loc
[1]+220), (180, 50),
48 "QUIT", 0, g
.font
[1][30]))
49 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0]+10, xy_loc
[1]+290), (180, 50),
50 "RESUME", 0, g
.font
[1][30]))
52 for button
in menu_buttons
:
53 button
.refresh_button(0)
59 for event
in pygame
.event
.get():
60 if event
.type == pygame
.QUIT
: g
.quit_game()
61 elif event
.type == pygame
.KEYDOWN
:
62 if event
.key
== pygame
.K_ESCAPE
: return 0
63 elif event
.type == pygame
.MOUSEMOTION
:
64 sel_button
= buttons
.refresh_buttons(sel_button
, menu_buttons
, event
)
65 for button
in menu_buttons
:
66 if button
.was_activated(event
):
67 if button
.button_id
== "RESUME":
70 if button
.button_id
== "SAVE GAME":
73 if button
.button_id
== "NEW GAME":
76 elif button
.button_id
== "LOAD GAME":
79 if button
.button_id
== "QUIT":
83 def display_cheat_list(menu_buttons
):
84 if g
.cheater
== 0: return
85 xy_loc
= (g
.screen_size
[0]/2 - 100, 50)
88 g
.screen
.fill(g
.colors
["white"], (xy_loc
[0], xy_loc
[1], 200, 420))
89 g
.screen
.fill(g
.colors
["black"], (xy_loc
[0]+1, xy_loc
[1]+1, 198, 418))
91 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0]+10, xy_loc
[1]+10), (180, 50),
92 "GIVE MONEY", 5, g
.font
[1][30]))
93 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0]+10, xy_loc
[1]+80), (180, 50),
94 "GIVE TECH", 5, g
.font
[1][30]))
95 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0]+10, xy_loc
[1]+150), (180, 50),
96 "END CONSTR.", 0, g
.font
[1][30]))
97 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0]+10, xy_loc
[1]+220), (180, 50),
98 "SUPERSPEED", 0, g
.font
[1][30]))
99 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0]+10, xy_loc
[1]+290), (180, 50),
100 "KILL SUSP.", 0, g
.font
[1][30]))
101 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0]+10, xy_loc
[1]+360), (180, 50),
102 "RESUME", 0, g
.font
[1][30]))
104 for button
in menu_buttons
:
105 button
.refresh_button(0)
106 pygame
.display
.flip()
111 for event
in pygame
.event
.get():
112 if event
.type == pygame
.QUIT
: g
.quit_game()
113 elif event
.type == pygame
.KEYDOWN
:
114 if event
.key
== pygame
.K_ESCAPE
: return 0
115 elif event
.type == pygame
.MOUSEMOTION
:
116 sel_button
= buttons
.refresh_buttons(sel_button
, menu_buttons
, event
)
117 for button
in menu_buttons
:
118 if button
.was_activated(event
):
119 if button
.button_id
== "RESUME":
121 elif button
.button_id
== "SUPERSPEED":
122 g
.curr_speed
= 864000
124 elif button
.button_id
== "END CONSTR.":
125 for base_loc
in g
.bases
:
126 for base_name
in g
.bases
[base_loc
]:
127 if base_name
.built
== 0:
128 base_name
.study((999999999, 999999999,
131 elif button
.button_id
== "GIVE TECH":
132 #create a temp base, in order to reuse the tech-changing code
133 tmp_base
= g
.base
.base(1, "tmp_base",
134 g
.base_type
["Reality Bubble"], 1)
135 base_screen
.change_tech(tmp_base
)
136 if g
.techs
.has_key(tmp_base
.studying
):
137 g
.techs
[tmp_base
.studying
].gain_tech()
139 elif button
.button_id
== "GIVE MONEY":
140 cash_amount
= g
.create_textbox("How much cash?",
142 (g
.screen_size
[0]/2-100, 100), (200, 100), 25,
143 g
.colors
["dark_blue"], g
.colors
["white"],
144 g
.colors
["white"], g
.colors
["light_blue"])
145 if cash_amount
.isdigit() == False: return
146 g
.pl
.cash
+= int(cash_amount
)
148 elif button
.button_id
== "KILL SUSP.":
149 g
.pl
.suspicion
= (0, 0, 0, 0)
154 #Note that this must be element 0 in menu_buttons
156 if g
.screen_size
[0] == 640: tmp_font_size
= 16
157 menu_buttons
.append(buttons
.button((100, -1), (200, 26),
158 "DAY 0000, 00:00:00", -1, g
.colors
["black"], g
.colors
["dark_blue"],
159 g
.colors
["black"], g
.colors
["white"], g
.font
[1][tmp_font_size
]))
160 menu_buttons
.append(buttons
.make_norm_button((0, 0), (100, 25),
161 "OPTIONS", 0, g
.font
[1][20]))
162 menu_buttons
.append(buttons
.make_norm_button((300, 0), (25, 25),
163 "ii", -1, g
.font
[1][20]))
164 if g
.curr_speed
== 0: menu_buttons
[2].stay_selected
= 1
165 menu_buttons
[2].activate_key
= "0"
166 menu_buttons
.append(buttons
.make_norm_button((324, 0), (25, 25),
167 ">", -1, g
.font
[1][20]))
168 if g
.curr_speed
== 1: menu_buttons
[3].stay_selected
= 1
169 menu_buttons
[3].activate_key
= "1"
170 menu_buttons
.append(buttons
.make_norm_button((348, 0), (25, 25),
171 ">>", -1, g
.font
[1][20]))
172 if g
.curr_speed
== 60: menu_buttons
[4].stay_selected
= 1
173 menu_buttons
[4].activate_key
= "2"
174 menu_buttons
.append(buttons
.make_norm_button((372, 0), (28, 25),
175 ">>>", -1, g
.font
[1][20]))
176 if g
.curr_speed
== 7200: menu_buttons
[5].stay_selected
= 1
177 menu_buttons
[5].activate_key
= "3"
178 menu_buttons
.append(buttons
.make_norm_button((399, 0), (36, 25),
179 ">>>>", -1, g
.font
[1][20]))
180 if g
.curr_speed
== 432000: menu_buttons
[6].stay_selected
= 1
181 menu_buttons
[6].activate_key
= "4"
182 #Note that this must be element 7 in menu_buttons
183 menu_buttons
.append(buttons
.button((435, -1), (g
.screen_size
[0]-435, 26),
184 "CASH", -1, g
.colors
["black"], g
.colors
["dark_blue"],
185 g
.colors
["black"], g
.colors
["white"], g
.font
[1][tmp_font_size
]))
186 #Note that this must be element 8 in menu_buttons
187 menu_buttons
.append(buttons
.button((0, g
.screen_size
[1]-25),
188 (g
.screen_size
[0], 26),
189 "SUSPICION", -1, g
.colors
["black"], g
.colors
["dark_blue"],
190 g
.colors
["black"], g
.colors
["white"], g
.font
[1][tmp_font_size
-2]))
191 menu_buttons
.append(buttons
.make_norm_button((0, g
.screen_size
[1]-50), (120, 25),
192 "RESEARCH", 0, g
.font
[1][20]))
193 menu_buttons
.append(buttons
.make_norm_button((g
.screen_size
[0]-120,
194 g
.screen_size
[1]-50), (120, 25),
195 "FINANCE", 6, g
.font
[1][20]))
197 menu_buttons
.append(buttons
.make_norm_button((
198 g
.screen_size
[0]*15/100, g
.screen_size
[1]*25/100), -1,
199 "N AMERICA", 0, g
.font
[1][25]))
200 menu_buttons
.append(buttons
.make_norm_button((
201 g
.screen_size
[0]*20/100, g
.screen_size
[1]*50/100), -1,
202 "S AMERICA", 0, g
.font
[1][25]))
203 menu_buttons
.append(buttons
.make_norm_button((
204 g
.screen_size
[0]*45/100, g
.screen_size
[1]*30/100), -1,
205 "EUROPE", 1, g
.font
[1][25]))
206 menu_buttons
.append(buttons
.make_norm_button((
207 g
.screen_size
[0]*80/100, g
.screen_size
[1]*30/100), -1,
208 "ASIA", 0, g
.font
[1][25]))
209 menu_buttons
.append(buttons
.make_norm_button((
210 g
.screen_size
[0]*55/100, g
.screen_size
[1]*45/100), -1,
211 "AFRICA", 3, g
.font
[1][25]))
212 menu_buttons
.append(buttons
.make_norm_button((
213 g
.screen_size
[0]*50/100, g
.screen_size
[1]*75/100), -1,
214 "ANTARCTIC", 2, g
.font
[1][25]))
215 menu_buttons
.append(buttons
.make_norm_button((
216 g
.screen_size
[0]*70/100, g
.screen_size
[1]*60/100), -1,
217 "OCEAN", 1, g
.font
[1][25]))
218 menu_buttons
.append(buttons
.make_norm_button((
219 g
.screen_size
[0]*82/100, g
.screen_size
[1]*10/100), -1,
220 "MOON", 0, g
.font
[1][25]))
221 # menu_buttons.append(buttons.make_norm_button((
222 # g.screen_size[0]*15/100, g.screen_size[1]*10/100), -1,
223 # "ORBIT", 2, g.font[1][25]))
224 menu_buttons
.append(buttons
.make_norm_button((
225 g
.screen_size
[0]*3/100, g
.screen_size
[1]*10/100), -1,
226 "FAR REACHES", 0, g
.font
[1][25]))
227 menu_buttons
.append(buttons
.make_norm_button((
228 g
.screen_size
[0]*35/100, g
.screen_size
[1]*10/100), -1,
229 "TRANSDIMENSIONAL", 5, g
.font
[1][25]))
232 refresh_map(menu_buttons
)
234 #I set this to 1000 to force an immediate refresh.
238 milli_clock
+= g
.old_clock
.tick(60) * g
.curr_speed
239 if milli_clock
>= 1000:
240 need_refresh
= g
.pl
.give_time(milli_clock
/1000)
241 if need_refresh
== 1: refresh_map(menu_buttons
)
242 tmp
= g
.pl
.lost_game()
244 g
.create_dialog(g
.strings
["lost_nobases"],
245 g
.font
[0][18], (g
.screen_size
[0]/2 - 100, 50),
246 (200, 200), g
.colors
["dark_blue"],
247 g
.colors
["white"], g
.colors
["white"])
250 g
.create_dialog(g
.strings
["lost_sus"],
251 g
.font
[0][18], (g
.screen_size
[0]/2 - 100, 50),
252 (200, 200), g
.colors
["dark_blue"],
253 g
.colors
["white"], g
.colors
["white"])
255 milli_clock
= milli_clock
% 1000
257 tmp_day
= str(g
.pl
.time_day
)
258 if len(tmp_day
) < 4: tmp_day
= "0"*(4-len(tmp_day
))+tmp_day
259 tmp_sec
= str(g
.pl
.time_sec
)
260 if len(tmp_sec
) == 1: tmp_sec
= "0"+tmp_sec
261 tmp_hour
= str(g
.pl
.time_hour
)
262 if len(tmp_hour
) == 1: tmp_hour
= "0"+tmp_hour
263 tmp_sec
= str(g
.pl
.time_sec
)
264 if len(tmp_sec
) == 1: tmp_sec
= "0"+tmp_sec
265 tmp_min
= str(g
.pl
.time_min
)
266 if len(tmp_min
) == 1: tmp_min
= "0"+tmp_min
268 menu_buttons
[0].text
= \
269 "DAY "+tmp_day
+", "+tmp_hour
+":"+tmp_min
+":"+tmp_sec
270 menu_buttons
[0].remake_button()
271 menu_buttons
[0].refresh_button(0)
273 result_cash
= str(g
.pl
.future_cash())
274 menu_buttons
[7].text
= "CASH: "+str(g
.pl
.cash
)+" ("+result_cash
+")"
275 menu_buttons
[7].remake_button()
276 menu_buttons
[7].refresh_button(0)
278 menu_buttons
[8].text
= ("SUSPICION: NEWS: "+
279 g
.to_percent(g
.pl
.suspicion
[0], 1)+" SCIENCE: "+
280 g
.to_percent(g
.pl
.suspicion
[1], 1)+" COVERT: "+
281 g
.to_percent(g
.pl
.suspicion
[2], 1)+" PUBLIC: "+
282 g
.to_percent(g
.pl
.suspicion
[3], 1)+".")
283 menu_buttons
[8].remake_button()
284 menu_buttons
[8].refresh_button(0)
285 pygame
.display
.flip()
286 for event
in pygame
.event
.get():
287 if event
.type == pygame
.QUIT
: g
.quit_game()
288 elif event
.type == pygame
.KEYDOWN
:
289 if event
.key
== pygame
.K_ESCAPE
:
290 tmp
= display_pause_menu()
291 tmp
= handle_pause_menu(tmp
, menu_buttons
)
292 if tmp
!= -1: return tmp
293 elif event
.key
== pygame
.K_BACKQUOTE
:
294 display_cheat_list(menu_buttons
)
295 refresh_map(menu_buttons
)
297 elif event
.type == pygame
.MOUSEMOTION
:
298 sel_button
= buttons
.refresh_buttons(sel_button
, menu_buttons
, event
)
299 for button
in menu_buttons
:
300 if button
.was_activated(event
):
301 if button
.button_id
== "OPTIONS":
303 tmp
= display_pause_menu()
304 tmp
= handle_pause_menu(tmp
, menu_buttons
)
305 if tmp
!= -1: return tmp
306 elif button
.button_id
== "RESEARCH":
308 while research_screen
.main_research_screen() == 1:
310 refresh_map(menu_buttons
)
311 elif button
.button_id
== "FINANCE":
313 finance_screen
.main_finance_screen()
314 refresh_map(menu_buttons
)
315 elif button
.button_id
== "ii":
318 for button2
in menu_buttons
:
319 button2
.stay_selected
= 0
320 button2
.refresh_button(0)
321 button
.stay_selected
= 1
322 button
.refresh_button(1)
323 elif button
.button_id
== ">":
326 for button2
in menu_buttons
:
327 button2
.stay_selected
= 0
328 button2
.refresh_button(0)
329 button
.stay_selected
= 1
330 button
.refresh_button(1)
331 elif button
.button_id
== ">>":
334 for button2
in menu_buttons
:
335 button2
.stay_selected
= 0
336 button2
.refresh_button(0)
337 button
.stay_selected
= 1
338 button
.refresh_button(1)
339 elif button
.button_id
== ">>>":
342 for button2
in menu_buttons
:
343 button2
.stay_selected
= 0
344 button2
.refresh_button(0)
345 button
.stay_selected
= 1
346 button
.refresh_button(1)
347 elif button
.button_id
== ">>>>":
349 g
.curr_speed
= 432000
350 for button2
in menu_buttons
:
351 button2
.stay_selected
= 0
352 button2
.refresh_button(0)
353 button
.stay_selected
= 1
354 button
.refresh_button(1)
355 elif button
.button_id
== "SUSPICION": pass
356 elif button
.xy
[1] != -1: #ignore the timer
358 display_base_list(button
.button_id
, menu_buttons
)
359 pygame
.display
.flip()
362 def handle_pause_menu(tmp
, menu_buttons
):
363 if tmp
== 0: refresh_map(menu_buttons
)
365 possible_name
= g
.create_textbox(g
.strings
["save_text"],
366 g
.default_savegame_name
, g
.font
[0][18],
367 (g
.screen_size
[0]/2-100, 100), (200, 100), 25,
368 g
.colors
["dark_blue"], g
.colors
["white"], g
.colors
["white"],
369 g
.colors
["light_blue"])
370 if possible_name
== "":
371 refresh_map(menu_buttons
)
373 g
.save_game(possible_name
)
374 refresh_map(menu_buttons
)
375 elif tmp
== 2: return 0
377 load_return
= main_menu
.display_load_menu()
378 if load_return
== -1 or load_return
== "":
379 refresh_map(menu_buttons
)
381 g
.load_game(load_return
)
383 # refresh_map(menu_buttons)
385 elif tmp
== 4: g
.quit_game()
388 def refresh_map(menu_buttons
):
389 g
.screen
.fill(g
.colors
["black"])
390 g
.screen
.blit(pygame
.transform
.scale(g
.picts
["earth.jpg"],
391 (g
.screen_size
[0], g
.screen_size
[0]/2)),
392 (0, g
.screen_size
[1]/2-g
.screen_size
[0]/4))
393 for button
in menu_buttons
:
394 button
.stay_selected
= 0
395 if g
.bases
.has_key(button
.button_id
):
396 #determine if building in a location is possible. If so, show the
398 if g
.base
.allow_entry_to_loc(button
.button_id
) == 1:
400 else: button
.visible
= 0
402 button
.text
= button
.button_id
+ " ("
403 button
.text
+= str(len(g
.bases
[button
.button_id
]))+")"
404 button
.remake_button()
405 elif ((button
.button_id
== "ii" and g
.curr_speed
== 0) or
406 (button
.button_id
== ">" and g
.curr_speed
== 1) or
407 (button
.button_id
== ">>" and g
.curr_speed
== 60) or
408 (button
.button_id
== ">>>" and g
.curr_speed
== 7200) or
409 (button
.button_id
== ">>>>" and g
.curr_speed
== 432000)):
410 button
.stay_selected
= 1
411 button
.refresh_button(0)
412 pygame
.display
.flip()
414 significant_numbers
= [
419 '19', # From the Dark Tower.
423 '16', # Four of the Lost numbers. The other two are '23' and '42'.
424 '13', # Lucky or unlucky?
426 '2012', # Mayan calendar ending.
427 '2038', # End of UNIX 32-bit time.
428 '1969', # Man lands on the moon.
429 '2043', # No meaning--confusion! :)
430 '2029', # Predicted date of AI passing a Turing Test by Kurzweil.
431 '3141', # ... if you don't know what this is, you should go away.
432 '1618', # Golden ratio.
436 ## Generates a name for a base, given a particular location.
437 def generate_base_name(location
, base_type
):
438 # First, decide whether we're going to try significant values or just
439 # choose one randomly.
440 if random
.random() < 0.3: # 30% chance.
443 while (done
== 0) and (attempts
< 5):
444 name
= random
.choice(g
.city_list
[location
])[0] + \
445 " " + random
.choice(base_type
.flavor
) + " " \
446 + random
.choice(significant_numbers
)
448 for base
in g
.bases
[location
]:
449 if base
.name
== name
:
457 # This is both the else case and the general case.
458 name
= random
.choice(g
.city_list
[location
])[0] + " " + \
459 random
.choice(base_type
.flavor
) + " " + \
460 str (random
.randint(0, 32767))
464 def display_base_list(location
, menu_buttons
):
465 if g
.base
.allow_entry_to_loc(location
) == 0: return
467 tmp
= display_base_list_inner(location
)
468 refresh_map(menu_buttons
)
469 pygame
.display
.flip()
471 tmp
= build_new_base_window(location
)
472 if tmp
!= "" and tmp
!= -1:
473 base_to_add
= g
.base_type
[tmp
]
474 possible_name
= g
.create_textbox(g
.strings
["new_base_text"],
475 generate_base_name(location
, g
.base_type
[tmp
]),
477 (g
.screen_size
[0]/2-150, 100), (300, 100), 25,
478 g
.colors
["dark_blue"], g
.colors
["white"], g
.colors
["white"],
479 g
.colors
["light_blue"])
480 if possible_name
== "":
481 refresh_map(menu_buttons
)
483 base_to_add
.count
+= 1
484 # while got_valid_name == 0:
485 # g.screen.fill(g.colors["white"], (250, 200, 350, 175))
486 # g.screen.fill(g.colors["light_blue"], (251, 201, 348, 173))
487 # g.screen.fill(g.colors["white"], (300, 250, 250, 25))
488 # g.screen.fill(g.colors["dark_blue"], (301, 251, 248, 23))
489 # g.print_multiline(g.screen, "Enter a name for the base.", g.font[0][18],
490 # 200, (305, 255), g.colors["white"])
492 g
.bases
[location
].append(g
.base
.base(len(g
.bases
[location
]),
493 tmp
, g
.base_type
[tmp
], 0))
494 g
.bases
[location
][-1].name
= possible_name
495 # refresh_map(menu_buttons)
496 # pygame.display.flip()
497 elif tmp
!= -1 and tmp
!= "":
498 if g
.bases
[location
][tmp
].built
== 0:
499 string
= "Under Construction. \\n Completion in "
500 string
+= g
.to_time(g
.bases
[location
][tmp
].cost
[2]) + ". \\n "
501 string
+= "Remaining cost: "+g
.add_commas(
502 str(g
.bases
[location
][tmp
].cost
[0]))
503 string
+=" money, and "+g
.add_commas(
504 str(g
.bases
[location
][tmp
].cost
[1]))
505 string
+=" processor time."
506 if g
.create_yesno(string
, g
.font
[0][18], (g
.screen_size
[0]/2 - 100, 50),
507 (200, 200), g
.colors
["dark_blue"], g
.colors
["white"],
508 g
.colors
["white"], ("DESTROY", "OK")):
509 if g
.create_yesno("Destroy this base? This will waste "+
510 g
.add_commas(str(g
.bases
[location
][tmp
].base_type
.cost
[0]-
511 g
.bases
[location
][tmp
].cost
[0]))
513 g
.add_commas(str(g
.bases
[location
][tmp
].base_type
.cost
[1]-
514 g
.bases
[location
][tmp
].cost
[1]))
515 +" processor time.", g
.font
[0][18],
516 (g
.screen_size
[0]/2 - 100, 50),
517 (200, 200), g
.colors
["dark_blue"], g
.colors
["white"],
519 g
.base
.destroy_base(location
, tmp
)
522 while next_prev
!= 0:
523 next_prev
= base_screen
.show_base(g
.bases
[location
][tmp
])
525 g
.base
.destroy_base(location
, tmp
)
528 if tmp
< 0: tmp
= len(g
.bases
[location
]) -1
529 if tmp
>= len(g
.bases
[location
]): tmp
= 0
530 while g
.bases
[location
][tmp
].built
!= 1:
532 if tmp
< 0: tmp
= len(g
.bases
[location
]) -1
533 if tmp
>= len(g
.bases
[location
]): tmp
= 0
537 refresh_map(menu_buttons
)
538 pygame
.display
.flip()
541 #Display the list of bases.
542 def display_base_list_inner(location
):
547 for base
in g
.bases
[location
]:
548 tmp_study
= base
.studying
549 if tmp_study
== "": tmp_study
= "Nothing"
550 elif g
.techs
.has_key(tmp_study
): tmp_study
= g
.techs
[tmp_study
].name
551 temp_base_list
.append(base
.name
+" ("+tmp_study
+")")
552 base_id_list
.append(base
.ID
)
554 xy_loc
= (g
.screen_size
[0]/2 - 259, 50)
556 while len(temp_base_list
) % base_list_size
!= 0 or len(temp_base_list
) == 0:
557 temp_base_list
.append("")
558 base_id_list
.append("")
562 bases_list
= listbox
.listbox(xy_loc
, (500, 350),
563 base_list_size
, 1, g
.colors
["dark_blue"], g
.colors
["blue"],
564 g
.colors
["white"], g
.colors
["white"], g
.font
[0][18])
566 bases_scroll
= scrollbar
.scrollbar((xy_loc
[0]+500, xy_loc
[1]), 350,
567 base_list_size
, g
.colors
["dark_blue"], g
.colors
["blue"],
571 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0], xy_loc
[1]+367), (100, 50),
572 "OPEN", 0, g
.font
[1][30]))
573 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0]+105, xy_loc
[1]+367), (100, 50),
574 "BACK", 0, g
.font
[1][30]))
575 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0]+210, xy_loc
[1]+367), (100, 50),
576 "NEW", 0, g
.font
[1][30]))
577 for button
in menu_buttons
:
578 button
.refresh_button(0)
579 listbox
.refresh_list(bases_list
, bases_scroll
, base_pos
, temp_base_list
)
584 for event
in pygame
.event
.get():
585 if event
.type == pygame
.QUIT
: g
.quit_game()
586 elif event
.type == pygame
.KEYDOWN
:
587 if event
.key
== pygame
.K_ESCAPE
: return -1
588 elif event
.key
== pygame
.K_DOWN
:
590 if base_pos
>= len(temp_base_list
):
591 base_pos
= len(temp_base_list
)-1
592 listbox
.refresh_list(bases_list
, bases_scroll
,
593 base_pos
, temp_base_list
)
594 elif event
.key
== pygame
.K_UP
:
598 listbox
.refresh_list(bases_list
, bases_scroll
,
599 base_pos
, temp_base_list
)
600 elif event
.key
== pygame
.K_q
: return -1
601 elif event
.key
== pygame
.K_RETURN
:
602 return base_id_list
[base_pos
]
603 elif event
.type == pygame
.MOUSEBUTTONUP
:
604 if event
.button
== 1:
605 tmp
= bases_list
.is_over(event
.pos
)
607 base_pos
= (base_pos
/base_list_size
)*base_list_size
+ tmp
608 listbox
.refresh_list(bases_list
, bases_scroll
,
609 base_pos
, temp_base_list
)
610 if event
.button
== 4:
614 listbox
.refresh_list(bases_list
, bases_scroll
,
615 base_pos
, temp_base_list
)
616 if event
.button
== 5:
618 if base_pos
>= len(temp_base_list
):
619 base_pos
= len(temp_base_list
)-1
620 listbox
.refresh_list(bases_list
, bases_scroll
,
621 base_pos
, temp_base_list
)
622 elif event
.type == pygame
.MOUSEMOTION
:
623 sel_button
= buttons
.refresh_buttons(sel_button
, menu_buttons
, event
)
624 for button
in menu_buttons
:
625 if button
.was_activated(event
):
626 if button
.button_id
== "OPEN":
628 return base_id_list
[base_pos
]
629 elif button
.button_id
== "NEW":
632 if button
.button_id
== "BACK":
635 tmp
= bases_scroll
.adjust_pos(event
, base_pos
, temp_base_list
)
638 listbox
.refresh_list(bases_list
, bases_scroll
,
639 base_pos
, temp_base_list
)
642 def build_new_base_window(location
):
646 temp_base_display_list
= []
647 for base_name
in g
.base_type
:
648 for region
in g
.base_type
[base_name
].regions
:
649 if g
.base_type
[base_name
].prereq
== "" or \
650 g
.techs
[g
.base_type
[base_name
].prereq
].known
== 1:
651 if region
== location
:
652 temp_base_list
.append(base_name
)
653 temp_base_display_list
.append(g
.base_type
[base_name
].base_name
)
655 xy_loc
= (g
.screen_size
[0]/2 - 289, 50)
657 while len(temp_base_list
) % base_list_size
!= 0 or len(temp_base_list
) == 0:
658 temp_base_list
.append("")
659 temp_base_display_list
.append("")
663 bases_list
= listbox
.listbox(xy_loc
, (230, 350),
664 base_list_size
, 1, g
.colors
["dark_blue"], g
.colors
["blue"],
665 g
.colors
["white"], g
.colors
["white"], g
.font
[0][18])
668 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0], xy_loc
[1]+367), (100, 50),
669 "BUILD", 1, g
.font
[1][30]))
670 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0]+103, xy_loc
[1]+367), (100, 50),
671 "BACK", 0, g
.font
[1][30]))
672 for button
in menu_buttons
:
673 button
.refresh_button(0)
677 refresh_new_base(temp_base_list
[base_pos
], xy_loc
)
679 listbox
.refresh_list(bases_list
, 0, base_pos
, temp_base_display_list
)
684 for event
in pygame
.event
.get():
685 if event
.type == pygame
.QUIT
: g
.quit_game()
686 elif event
.type == pygame
.KEYDOWN
:
687 if event
.key
== pygame
.K_ESCAPE
: return -1
688 elif event
.key
== pygame
.K_DOWN
:
690 if base_pos
>= len(temp_base_list
):
691 base_pos
= len(temp_base_list
)-1
692 refresh_new_base(temp_base_list
[base_pos
], xy_loc
)
693 listbox
.refresh_list(bases_list
, 0,
694 base_pos
, temp_base_display_list
)
695 elif event
.key
== pygame
.K_UP
:
699 refresh_new_base(temp_base_list
[base_pos
], xy_loc
)
700 listbox
.refresh_list(bases_list
, 0,
701 base_pos
, temp_base_display_list
)
702 elif event
.key
== pygame
.K_q
: return -1
703 elif event
.key
== pygame
.K_RETURN
:
704 return temp_base_list
[base_pos
]
705 elif event
.type == pygame
.MOUSEBUTTONUP
:
706 if event
.button
== 1:
707 tmp
= bases_list
.is_over(event
.pos
)
709 base_pos
= (base_pos
/base_list_size
)*base_list_size
+ tmp
710 refresh_new_base(temp_base_list
[base_pos
], xy_loc
)
711 listbox
.refresh_list(bases_list
, 0,
712 base_pos
, temp_base_display_list
)
713 if event
.button
== 4:
717 refresh_new_base(temp_base_list
[base_pos
], xy_loc
)
718 listbox
.refresh_list(bases_list
, 0,
719 base_pos
, temp_base_display_list
)
720 if event
.button
== 5:
722 if base_pos
>= len(temp_base_list
):
723 base_pos
= len(temp_base_list
)-1
724 refresh_new_base(temp_base_list
[base_pos
], xy_loc
)
725 listbox
.refresh_list(bases_list
, 0,
726 base_pos
, temp_base_display_list
)
727 elif event
.type == pygame
.MOUSEMOTION
:
728 sel_button
= buttons
.refresh_buttons(sel_button
, menu_buttons
, event
)
729 for button
in menu_buttons
:
730 if button
.was_activated(event
):
731 if button
.button_id
== "BUILD":
733 return temp_base_list
[base_pos
]
734 if button
.button_id
== "BACK":
738 def refresh_new_base(base_name
, xy
):
739 xy
= (xy
[0]+80, xy
[1])
740 g
.screen
.fill(g
.colors
["white"], (xy
[0]+155, xy
[1], 300, 350))
741 g
.screen
.fill(g
.colors
["dark_blue"], (xy
[0]+156, xy
[1]+1, 298, 348))
742 if base_name
== "": return
743 g
.print_string(g
.screen
, g
.base_type
[base_name
].base_name
,
744 g
.font
[0][22], -1, (xy
[0]+160, xy
[1]+5), g
.colors
["white"])
747 string
= "Building Cost:"
748 g
.print_string(g
.screen
, string
,
749 g
.font
[0][18], -1, (xy
[0]+160, xy
[1]+30), g
.colors
["white"])
751 string
= g
.add_commas(str(g
.base_type
[base_name
].cost
[0]))+" Money"
752 g
.print_string(g
.screen
, string
,
753 g
.font
[0][16], -1, (xy
[0]+160, xy
[1]+50), g
.colors
["white"])
755 string
= g
.add_commas(str(g
.base_type
[base_name
].cost
[1])) + " CPU"
756 g
.print_string(g
.screen
, string
,
757 g
.font
[0][16], -1, (xy
[0]+160, xy
[1]+70), g
.colors
["white"])
759 string
= g
.add_commas(str(g
.base_type
[base_name
].cost
[2])) + " Days"
760 g
.print_string(g
.screen
, string
,
761 g
.font
[0][16], -1, (xy
[0]+160, xy
[1]+90), g
.colors
["white"])
764 string
= "Maintenance Cost:"
765 g
.print_string(g
.screen
, string
,
766 g
.font
[0][18], -1, (xy
[0]+290, xy
[1]+30), g
.colors
["white"])
768 string
= g
.add_commas(str(g
.base_type
[base_name
].mainten
[0])) + " Money"
769 g
.print_string(g
.screen
, string
,
770 g
.font
[0][16], -1, (xy
[0]+290, xy
[1]+50), g
.colors
["white"])
772 string
= g
.add_commas(str(g
.base_type
[base_name
].mainten
[1])) + " CPU"
773 g
.print_string(g
.screen
, string
,
774 g
.font
[0][16], -1, (xy
[0]+290, xy
[1]+70), g
.colors
["white"])
776 # string = g.add_commas(str(g.base_type[base_name].mainten[2])) + " Time"
777 # g.print_string(g.screen, string,
778 # g.font[0][16], -1, (xy[0]+290, xy[1]+90), g.colors["white"])
781 string
= "Size: "+str(g
.base_type
[base_name
].size
)
782 g
.print_string(g
.screen
, string
,
783 g
.font
[0][20], -1, (xy
[0]+160, xy
[1]+110), g
.colors
["white"])
786 string
= "Detection chance:"
787 g
.print_string(g
.screen
, string
,
788 g
.font
[0][22], -1, (xy
[0]+160, xy
[1]+130), g
.colors
["white"])
790 string
= "News: " + g
.to_percent(g
.base_type
[base_name
].d_chance
[0])
791 g
.print_string(g
.screen
, string
,
792 g
.font
[0][16], -1, (xy
[0]+160, xy
[1]+150), g
.colors
["white"])
793 string
= "Science: " + g
.to_percent(g
.base_type
[base_name
].d_chance
[1])
794 g
.print_string(g
.screen
, string
,
795 g
.font
[0][16], -1, (xy
[0]+290, xy
[1]+150), g
.colors
["white"])
796 string
= "Covert: " + g
.to_percent(g
.base_type
[base_name
].d_chance
[2])
797 g
.print_string(g
.screen
, string
,
798 g
.font
[0][16], -1, (xy
[0]+160, xy
[1]+170), g
.colors
["white"])
799 string
= "Public: " + g
.to_percent(g
.base_type
[base_name
].d_chance
[3])
800 g
.print_string(g
.screen
, string
,
801 g
.font
[0][16], -1, (xy
[0]+290, xy
[1]+170), g
.colors
["white"])
803 g
.print_multiline(g
.screen
, g
.base_type
[base_name
].descript
,
804 g
.font
[0][18], 290, (xy
[0]+160, xy
[1]+190), g
.colors
["white"])