1 #file: research_screen.py
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 global research screen.
29 #cost = (money, ptime, labor)
30 #detection = (news, science, covert, person)
32 def main_research_screen():
34 g
.screen
.fill(g
.colors
["black"])
39 g
.screen
.fill(g
.colors
["white"], (xstart
, ystart
, xstart
+g
.screen_size
[1]/5,
41 g
.screen
.fill(g
.colors
["dark_blue"], (xstart
+1, ystart
+1,
42 xstart
+g
.screen_size
[1]/5-2, 48))
50 item_listbox
= listbox
.listbox(xy_loc
, (230, 300),
51 list_size
, 1, g
.colors
["dark_blue"], g
.colors
["blue"],
52 g
.colors
["white"], g
.colors
["white"], g
.font
[0][18])
54 item_scroll
= scrollbar
.scrollbar((xy_loc
[0]+230, xy_loc
[1]), 300,
55 list_size
, g
.colors
["dark_blue"], g
.colors
["blue"],
59 menu_buttons
.append(buttons
.make_norm_button((0, 0), (70, 25),
60 "BACK", 0, g
.font
[1][20]))
62 menu_buttons
.append(buttons
.make_norm_button((20, 390), (80, 25),
63 "STOP", 0, g
.font
[1][20]))
65 menu_buttons
.append(buttons
.make_norm_button((xstart
+5, ystart
+20),
66 (90, 25), "ASSIGN", 0, g
.font
[1][20]))
68 item_list
, item_display_list
, item_CPU_list
, free_CPU
= \
69 refresh_screen(menu_buttons
, list_size
)
72 # for button in menu_buttons:
73 # button.refresh_button(0)
74 refresh_research(item_list
[0], item_CPU_list
[0])
75 listbox
.refresh_list(item_listbox
, item_scroll
, list_pos
, item_display_list
)
79 for event
in pygame
.event
.get():
80 if event
.type == pygame
.QUIT
: g
.quit_game()
81 elif event
.type == pygame
.KEYDOWN
:
82 if event
.key
== pygame
.K_ESCAPE
: return -1
83 elif event
.key
== pygame
.K_DOWN
:
85 if list_pos
>= len(item_list
):
86 list_pos
= len(item_list
)-1
87 refresh_research(item_list
[list_pos
], item_CPU_list
[list_pos
])
88 listbox
.refresh_list(item_listbox
, item_scroll
,
89 list_pos
, item_display_list
)
90 elif event
.key
== pygame
.K_UP
:
94 refresh_research(item_list
[list_pos
], item_CPU_list
[list_pos
])
95 listbox
.refresh_list(item_listbox
, item_scroll
,
96 list_pos
, item_display_list
)
97 elif event
.key
== pygame
.K_q
: return -1
98 elif event
.key
== pygame
.K_RETURN
:
99 if kill_tech(item_list
[list_pos
]): return 1
100 item_list
, item_display_list
, item_CPU_list
, free_CPU
= \
101 refresh_screen(menu_buttons
, list_size
)
102 refresh_research(item_list
[list_pos
], item_CPU_list
[list_pos
])
103 listbox
.refresh_list(item_listbox
, item_scroll
,
104 list_pos
, item_display_list
)
105 elif event
.type == pygame
.MOUSEMOTION
:
106 sel_button
= buttons
.refresh_buttons(sel_button
, menu_buttons
, event
)
107 elif event
.type == pygame
.MOUSEBUTTONUP
:
108 if event
.button
== 1:
109 tmp
= item_listbox
.is_over(event
.pos
)
111 list_pos
= (list_pos
/ list_size
)*list_size
+ tmp
112 refresh_research(item_list
[list_pos
], item_CPU_list
[list_pos
])
113 listbox
.refresh_list(item_listbox
, item_scroll
,
114 list_pos
, item_display_list
)
115 if event
.button
== 4:
119 refresh_research(item_list
[list_pos
], item_CPU_list
[list_pos
])
120 listbox
.refresh_list(item_listbox
, item_scroll
,
121 list_pos
, item_display_list
)
122 if event
.button
== 5:
124 if list_pos
>= len(item_list
):
125 list_pos
= len(item_list
)-1
126 refresh_research(item_list
[list_pos
], item_CPU_list
[list_pos
])
127 listbox
.refresh_list(item_listbox
, item_scroll
,
128 list_pos
, item_display_list
)
129 for button
in menu_buttons
:
130 if button
.was_activated(event
):
131 if button
.button_id
== "BACK":
134 if button
.button_id
== "STOP":
136 #returning 1 causes the caller to refresh the list of
138 if kill_tech(item_list
[list_pos
]): return 1
139 item_list
, item_display_list
, item_CPU_list
, free_CPU
= \
140 refresh_screen(menu_buttons
, list_size
)
141 refresh_research(item_list
[list_pos
], item_CPU_list
[list_pos
])
142 listbox
.refresh_list(item_listbox
, item_scroll
,
143 list_pos
, item_display_list
)
144 if button
.button_id
== "ASSIGN":
146 if assign_tech(free_CPU
): return 1
147 item_list
, item_display_list
, item_CPU_list
, free_CPU
= \
148 refresh_screen(menu_buttons
, list_size
)
149 refresh_research(item_list
[0], item_CPU_list
[0])
150 listbox
.refresh_list(item_listbox
, item_scroll
,
151 list_pos
, item_display_list
)
153 def refresh_screen(menu_buttons
, list_size
):
155 g
.screen
.fill(g
.colors
["black"])
160 g
.screen
.fill(g
.colors
["white"], (xstart
, ystart
, xstart
+g
.screen_size
[1]/5,
162 g
.screen
.fill(g
.colors
["dark_blue"], (xstart
+1, ystart
+1,
163 xstart
+g
.screen_size
[1]/5-2, 48))
167 item_display_list
= []
170 for loc_name
in g
.bases
:
171 for base_instance
in g
.bases
[loc_name
]:
172 if base_instance
.built
!= 1: continue
173 if base_instance
.studying
== "":
174 free_CPU
+= base_instance
.processor_time()
175 elif g
.jobs
.has_key(base_instance
.studying
):
176 #Right now, jobs cannot be renamed using translations.
177 for i
in range(len(item_list
)):
178 if item_list
[i
] == base_instance
.studying
:
179 item_CPU_list
[i
] += base_instance
.processor_time()
182 item_list
.append(base_instance
.studying
)
183 item_CPU_list
.append(base_instance
.processor_time())
184 item_display_list
.append(base_instance
.studying
)
185 elif g
.techs
.has_key(base_instance
.studying
):
186 for i
in range(len(item_list
)):
187 if item_list
[i
] == base_instance
.studying
:
188 item_CPU_list
[i
] += base_instance
.processor_time()
191 item_list
.append(base_instance
.studying
)
192 item_CPU_list
.append(base_instance
.processor_time())
193 item_display_list
.append(g
.techs
[base_instance
.studying
].name
)
195 while len(item_list
) % list_size
!= 0 or len(item_list
) == 0:
197 item_display_list
.append("")
198 item_CPU_list
.append(0)
200 g
.print_string(g
.screen
, "Free CPU per day: "+str(free_CPU
),
201 g
.font
[0][16], -1, (xstart
+10, ystart
+5), g
.colors
["white"])
203 for button
in menu_buttons
:
204 button
.refresh_button(0)
206 return item_list
, item_display_list
, item_CPU_list
, free_CPU
208 def refresh_research(tech_name
, CPU_amount
):
209 xy
= (g
.screen_size
[0]-360, 5)
210 g
.screen
.fill(g
.colors
["white"], (xy
[0], xy
[1], 310, 350))
211 g
.screen
.fill(g
.colors
["dark_blue"], (xy
[0]+1, xy
[1]+1, 308, 348))
214 if tech_name
== "" or tech_name
== "Nothing":
215 g
.print_string(g
.screen
, "Nothing",
216 g
.font
[0][22], -1, (xy
[0]+5, xy
[1]+5), g
.colors
["white"])
217 string
= g
.strings
["research_nothing"]
218 g
.print_multiline(g
.screen
, string
,
219 g
.font
[0][18], 290, (xy
[0]+5, xy
[1]+35), g
.colors
["white"])
224 if g
.jobs
.has_key (tech_name
):
225 g
.print_string(g
.screen
, tech_name
,
226 g
.font
[0][22], -1, (xy
[0]+5, xy
[1]+5), g
.colors
["white"])
228 if g
.techs
["Advanced Simulacra"].known
== 1:
229 g
.print_string(g
.screen
,
230 g
.add_commas(str(int(
231 (g
.jobs
[tech_name
][0]*CPU_amount
)*1.1)))+
232 " Money per day.", g
.font
[0][22], -1, (xy
[0]+5, xy
[1]+35),
235 g
.print_string(g
.screen
,
236 g
.add_commas(str(g
.jobs
[tech_name
][0]*CPU_amount
))+
238 g
.font
[0][22], -1, (xy
[0]+5, xy
[1]+35), g
.colors
["white"])
239 g
.print_multiline(g
.screen
, g
.jobs
[tech_name
][2],
240 g
.font
[0][18], 290, (xy
[0]+5, xy
[1]+65), g
.colors
["white"])
244 g
.print_string(g
.screen
, g
.techs
[tech_name
].name
,
245 g
.font
[0][22], -1, (xy
[0]+5, xy
[1]+5), g
.colors
["white"])
248 string
= "Tech Cost:"
249 g
.print_string(g
.screen
, string
,
250 g
.font
[0][20], -1, (xy
[0]+5, xy
[1]+35), g
.colors
["white"])
252 string
= g
.add_commas(str(g
.techs
[tech_name
].cost
[0]))+" Money"
253 g
.print_string(g
.screen
, string
,
254 g
.font
[0][20], -1, (xy
[0]+5, xy
[1]+50), g
.colors
["white"])
256 string
= g
.add_commas(str(g
.techs
[tech_name
].cost
[1]))+" CPU"
257 g
.print_string(g
.screen
, string
,
258 g
.font
[0][20], -1, (xy
[0]+165, xy
[1]+50), g
.colors
["white"])
260 g
.print_string(g
.screen
, "CPU per day: "+str(CPU_amount
),
261 g
.font
[0][20], -1, (xy
[0]+105, xy
[1]+70), g
.colors
["white"])
263 g
.print_multiline(g
.screen
, g
.techs
[tech_name
].descript
,
264 g
.font
[0][18], 290, (xy
[0]+5, xy
[1]+90), g
.colors
["white"])
266 def kill_tech(tech_name
):
268 if tech_name
== "": return return_val
269 for base_loc
in g
.bases
:
270 for base
in g
.bases
[base_loc
]:
271 if base
.studying
== tech_name
:
276 def assign_tech(free_CPU
):
278 #create a temp base, in order to reuse the tech-changing code
279 tmp_base
= g
.base
.base(1, "tmp_base",
280 g
.base_type
["Reality Bubble"], 1)
281 tmp_base
.usage
[0] = g
.item
.item(g
.items
["reseach_screen_tmp_item"])
282 tmp_base
.usage
[0].item_type
.item_qual
= free_CPU
283 tmp_base
.usage
[0].built
= 1
286 base_screen
.change_tech(tmp_base
)
287 if tmp_base
.studying
== "": return False
289 for base_loc
in g
.bases
:
290 for base
in g
.bases
[base_loc
]:
291 if base
.studying
== "" and base
.allow_study(tmp_base
.studying
):
293 base
.studying
= tmp_base
.studying