forked from videogamepreservation/7kaa
/
OF_RESE.cpp
556 lines (426 loc) · 13.7 KB
/
OF_RESE.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
/*
* Seven Kingdoms: Ancient Adversaries
*
* Copyright 1997,1998 Enlight Software Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
//Filename : OF_RESE.CPP
//Description : Firm Magic Tower
#include <OINFO.h>
#include <OVGA.h>
#include <ODATE.h>
#include <OSTR.h>
#include <ONEWS.h>
#include <OFONT.h>
#include <OCONFIG.h>
#include <OBUTT3D.h>
#include <OMOUSE.h>
#include <OSYS.h>
#include <OPOWER.h>
#include <OUNIT.h>
#include <OGAME.h>
#include <ONATION.h>
#include <OTECHRES.h>
#include <OF_RESE.h>
#include <OREMOTE.h>
#include <OSE.h>
#include <OSERES.h>
#include <OBUTTCUS.h>
//------------- Define constant ------------//
#define MAX_RESEARCH_OPTION 6
#define RESEARCH_OPTION_HEIGHT 48
//---------- Define constant ------------//
enum { RESEARCH_MENU_MAIN,
RESEARCH_MENU_RESEARCH,
};
//----------- Define static vars -------------//
static Button3D button_select_research;
static char research_menu_mode;
static char disable_refresh=0;
static ButtonCustom button_research_array[MAX_RESEARCH_OPTION];
// ######## begin Gilbert 16/8 ######//
static ButtonCustom button_cancel;
// ######## end Gilbert 16/8 ######//
static int added_count; // no. of buttons in button_research_array
//---------- Declare static functions ---------//
static void i_disp_research_button(ButtonCustom *, int);
//--------- Begin of function FirmResearch::FirmResearch ---------//
//
FirmResearch::FirmResearch()
{
firm_skill_id = SKILL_RESEARCH;
}
//----------- End of function FirmResearch::FirmResearch -----------//
//--------- Begin of function FirmResearch::~FirmResearch ---------//
//
FirmResearch::~FirmResearch()
{
terminate_research();
}
//----------- End of function FirmResearch::~FirmResearch -----------//
//--------- Begin of function FirmResearch::init_derived ---------//
//
void FirmResearch::init_derived()
{
tech_id = 0; // the id. of the tech this firm is currently researching
complete_percent = (float) 0; // percent completed on researching the current technology
}
//----------- End of function FirmResearch::init_derived -----------//
//--------- Begin of function FirmResearch::put_info ---------//
//
void FirmResearch::put_info(int refreshFlag)
{
if( refreshFlag==INFO_REPAINT && !disable_refresh )
research_menu_mode = RESEARCH_MENU_MAIN;
switch( research_menu_mode )
{
case RESEARCH_MENU_MAIN:
disp_main_menu(refreshFlag);
break;
case RESEARCH_MENU_RESEARCH:
disp_research_menu(refreshFlag);
break;
}
}
//----------- End of function FirmResearch::put_info -----------//
//--------- Begin of function FirmResearch::detect_info ---------//
//
void FirmResearch::detect_info()
{
switch( research_menu_mode )
{
case RESEARCH_MENU_MAIN:
detect_main_menu();
break;
case RESEARCH_MENU_RESEARCH:
detect_research_menu();
break;
}
}
//----------- End of function FirmResearch::detect_info -----------//
//--------- Begin of function FirmResearch::disp_main_menu ---------//
//
void FirmResearch::disp_main_menu(int refreshFlag)
{
disp_basic_info(INFO_Y1, refreshFlag);
if( !should_show_info() )
return;
disp_research_info(INFO_Y1+54, refreshFlag);
disp_worker_list(INFO_Y1+107, refreshFlag);
disp_worker_info(INFO_Y1+171, refreshFlag);
if( own_firm() )
{
if( refreshFlag==INFO_REPAINT )
button_select_research.paint( INFO_X1, INFO_Y1+235, 'A', "RESEARCH" );
}
disp_spy_button( INFO_X1+BUTTON_ACTION_WIDTH, INFO_Y1+235, refreshFlag );
}
//----------- End of function FirmResearch::disp_main_menu -----------//
//--------- Begin of function FirmResearch::detect_main_menu ---------//
//
void FirmResearch::detect_main_menu()
{
//-------- detect basic info -----------//
if( detect_basic_info() )
return;
//----------- detect worker -----------//
if( detect_worker_list() )
{
disp_research_info(INFO_Y1+54, INFO_UPDATE);
disp_worker_info(INFO_Y1+171, INFO_UPDATE);
}
//-------- detect spy button ----------//
detect_spy_button();
if( !own_firm() )
return;
//------ detect the select research button -------//
if( button_select_research.detect() )
{
research_menu_mode = RESEARCH_MENU_RESEARCH;
disable_refresh = 1; // static var for disp_info() only
info.disp();
disable_refresh = 0;
}
}
//----------- End of function FirmResearch::detect_main_menu -----------//
//--------- Begin of function FirmResearch::disp_research_menu ---------//
//
void FirmResearch::disp_research_menu(int refreshFlag)
{
if( refreshFlag != INFO_REPAINT )
return;
int techId, y=INFO_Y1;
added_count=0;
for( techId=1 ; techId<=tech_res.tech_count ; techId++ )
{
if( !tech_res[techId]->can_research(nation_recno) )
continue;
if( added_count < MAX_RESEARCH_OPTION )
{
button_research_array[added_count].paint(INFO_X1, y, INFO_X2, y+RESEARCH_OPTION_HEIGHT-2,
i_disp_research_button, ButtonCustomPara(this, techId) );
added_count++;
y += RESEARCH_OPTION_HEIGHT;
}
}
// ###### begin Gilbert 16/8 ######//
// button_cancel.paint(INFO_X1, y, "CANCEL1", "CANCEL1D" );
button_cancel.paint(INFO_X1, y, INFO_X2, y+RESEARCH_OPTION_HEIGHT*3/4,
ButtonCustom::disp_text_button_func, ButtonCustomPara((void*)"Cancel",0) );
// ###### end Gilbert 16/8 ######//
}
//----------- End of function FirmResearch::disp_research_menu -----------//
//--------- Begin of function FirmResearch::detect_research_menu ---------//
//
void FirmResearch::detect_research_menu()
{
int i;
for( i = 0; i < added_count; ++i )
{
if(button_research_array[i].detect() )
{
int techId = button_research_array[i].custom_para.value;
if( tech_res[techId]->can_research(nation_recno) )
{
start_research(techId, COMMAND_PLAYER);
// ##### begin Gilbert 25/9 ######//
se_ctrl.immediate_sound("TURN_ON");
// ##### end Gilbert 25/9 ######//
research_menu_mode = RESEARCH_MENU_MAIN;
info.disp();
}
else
{
// ##### begin Gilbert 25/9 ######//
se_ctrl.immediate_sound("TURN_OFF");
// ##### end Gilbert 25/9 ######//
}
break;
}
}
//------ detect the cancel button --------//
if( i >= added_count ) // no research button has been pressed
{
if( button_cancel.detect() )
{
// ##### begin Gilbert 25/9 ######//
se_ctrl.immediate_sound("TURN_OFF");
// ##### end Gilbert 25/9 ######//
research_menu_mode = RESEARCH_MENU_MAIN;
info.disp();
}
}
}
//----------- End of function FirmResearch::detect_research_menu -----------//
//-------- Begin of static function i_disp_research_button --------//
//
void i_disp_research_button(ButtonCustom *button, int repaintBody)
{
int x1 = button->x1;
int y1 = button->y1;
int x2 = button->x2;
int y2 = button->y2;
if( button->pushed_flag )
{
vga.d3_panel2_down(x1, y1, x2, y2);
x1++;
y1++;
}
else
{
vga.d3_panel2_up(x1, y1, x2, y2);
x2--;
y2--;
}
//--------------------------------------------//
TechInfo* techInfo = tech_res[button->custom_para.value];
// Vga::active_buf->d3_panel_down(x1+2, y1+2, x1+TECH_LARGE_ICON_WIDTH+7, y1+TECH_LARGE_ICON_HEIGHT+7, 2, 0 );
Vga::active_buf->put_bitmap(x1+4, y1+4, techInfo->tech_large_icon() );
//------ display research description -------//
String str;
str = techInfo->tech_des();
Firm *firmPtr = (Firm *) button->custom_para.ptr;
int researchVersion = techInfo->get_nation_tech_level(firmPtr->nation_recno)+1; // research the next non-researched version
if( researchVersion > 1 )
{
str += " ";
str += m.roman_number(researchVersion);
}
font_bible.put( x1+TECH_LARGE_ICON_WIDTH+12, y1+14, str );
}
//--------- End of static function i_disp_research_button ---------//
//--------- Begin of function FirmResearch::disp_research_info ---------//
//
void FirmResearch::disp_research_info(int dispY1, int refreshFlag)
{
static short lastTechId=0;
if( refreshFlag==INFO_UPDATE && lastTechId != tech_id )
{
lastTechId = tech_id;
info.disp();
}
//---------------- paint the panel --------------//
if( refreshFlag == INFO_REPAINT )
vga.d3_panel_up( INFO_X1, dispY1, INFO_X2, dispY1+50 );
if( !tech_id )
return;
int x=INFO_X1+4, y=dispY1+4;
//-------- display the icon of the researching item ---------//
TechInfo* techInfo = tech_res[tech_id];
if( refreshFlag == INFO_REPAINT )
{
vga.d3_panel_down( x, y, x+TECH_LARGE_ICON_WIDTH+3, y+TECH_LARGE_ICON_HEIGHT+3, 2 );
vga_front.put_bitmap( x+2, y+2, techInfo->tech_large_icon() );
//----------- display text ------------//
x += TECH_LARGE_ICON_WIDTH+10;
String str;
str = techInfo->tech_des();
int researchVersion = techInfo->get_nation_tech_level(nation_recno)+1; // research the next non-researched version
if( researchVersion > 1 )
{
str += " ";
str += m.roman_number(researchVersion);
}
font_san.put( x, y+4, str);
}
else
{
x += TECH_LARGE_ICON_WIDTH+10;
}
vga_front.indicator( 0, x-2, y+21, techInfo->get_progress(nation_recno), (float)100, VGA_GRAY );
}
//----------- End of function FirmResearch::disp_research_info -----------//
//--------- Begin of function FirmResearch::next_day ---------//
//
void FirmResearch::next_day()
{
//----- call next_day() of the base class -----//
Firm::next_day();
//----------- update population -------------//
recruit_worker();
//-------- train up the skill ------------//
update_worker();
//--------- calculate productivity ----------//
calc_productivity();
//--------- process research ----------//
process_research();
}
//----------- End of function FirmResearch::next_day -----------//
//------- Begin of function FirmResearch::change_nation ---------//
//
void FirmResearch::change_nation(int newNationRecno)
{
terminate_research();
//-------- change the nation of this firm now ----------//
Firm::change_nation(newNationRecno);
}
//-------- End of function FirmResearch::change_nation ---------//
//--------- Begin of function FirmResearch::start_research --------//
//
// Start researching on the specific technology.
//
// <int> techId - id. of the technology to research.
//
void FirmResearch::start_research(int techId, char remoteAction)
{
TechInfo* techInfo = tech_res[techId];
err_when( !techInfo->can_research(nation_recno) );
if( !remoteAction && remote.is_enable())
{
// packet structure : <firm recno> <tech Id>
short *shortPtr = (short *)remote.new_send_queue_msg(MSG_F_RESEARCH_START, 2*sizeof(short) );
shortPtr[0] = firm_recno;
shortPtr[1] = (short) techId;
return;
}
//---- if the firm currently is already researching something ---//
if( tech_id )
terminate_research();
//-------- set self parameters ---------//
tech_id = techId;
//------- set TechRes parameters -------//
techInfo->inc_nation_is_researching(nation_recno);
}
//----------- End of function FirmResearch::start_research ---------//
//--------- Begin of function FirmResearch::process_research --------//
//
// Process the current research.
//
void FirmResearch::process_research()
{
if( !tech_id )
return;
//------- make a progress with the research ------//
TechInfo* techInfo = tech_res[tech_id];
float progressPoint;
if( config.fast_build && nation_recno==nation_array.player_recno )
progressPoint = (float) productivity / 100 + (float) 0.5;
else
progressPoint = (float) productivity / 300;
int newLevel = techInfo->get_nation_tech_level(nation_recno)+1;
float levelDivider = ((float)(newLevel+1)/2); // from 1.0 to 2.0
progressPoint = progressPoint * (float) 30
/ techInfo->complex_level
/ levelDivider; // more complex and higher level technology will take longer to research
int techId = tech_id; // techInfo->progress() will reset tech_id if the current research level is the max tech level, so we have to save it now
if( techInfo->progress(nation_recno, progressPoint) )
{
if( tech_id ) // TechRes::progress() may have called terminate_research() if the tech level reaches the maximum
{
int techId = tech_id;
research_complete();
//----- research next level technology automatically -----//
if( !firm_ai ) // for player's firm only
{
if( techInfo->get_nation_tech_level(nation_recno) < techInfo->max_tech_level )
{
start_research( techId, COMMAND_AUTO );
if( firm_recno == firm_array.selected_recno )
info.disp();
}
}
}
//--------- add news ---------//
if( own_firm() )
{
news_array.tech_researched( techId, tech_res[techId]->get_nation_tech_level(nation_recno) );
se_res.far_sound(center_x, center_y, 1, 'F', firm_id, "FINS",
'S', unit_res[tech_res[techId]->unit_id]->sprite_id);
}
}
}
//----------- End of function FirmResearch::process_research ---------//
//--------- Begin of function FirmResearch::research_complete --------//
//
void FirmResearch::research_complete()
{
short techId = tech_id; // backup tech_id
tech_res[tech_id]->dec_nation_is_researching(nation_recno);
tech_id = 0; // reset parameters
complete_percent = (float) 0;
}
//----------- End of function FirmResearch::research_complete ---------//
//--------- Begin of function FirmResearch::terminate_research --------//
//
void FirmResearch::terminate_research()
{
if( !tech_id )
return;
tech_res[tech_id]->dec_nation_is_researching(nation_recno);
tech_id = 0; // reset parameters
complete_percent = (float) 0;
}
//----------- End of function FirmResearch::terminate_research ---------//