OSYS2.cpp 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. //Filename : OSYS2.CPP
  21. //Description : System resource management object
  22. #include <OVGA.h>
  23. #include <OMOUSE.h>
  24. #include <OFONT.h>
  25. #include <OBUTT3D.h>
  26. #include <OVBROWSE.h>
  27. #include <ONATION.h>
  28. #include <OFIRM.h>
  29. #include <OTOWN.h>
  30. #include <OSITE.h>
  31. #include <OUNIT.h>
  32. #include <OHELP.h>
  33. #include <OTUTOR.h>
  34. #include <ONEWS.h>
  35. #include <OBULLET.h>
  36. #include <OREBEL.h>
  37. #include <OREMOTE.h>
  38. #include <OSPY.h>
  39. #include <OINFO.h>
  40. #include <OGAME.h>
  41. #include <OWORLD.h>
  42. #include <OSYS.h>
  43. #include <ORAWRES.h>
  44. #include <OTALKRES.h>
  45. #include <OWEATHER.h>
  46. #include <OANLINE.h>
  47. #include <OTORNADO.h>
  48. #include <OSE.h>
  49. #include <OSNOWG.h>
  50. #include <OROCK.h>
  51. #include <OEFFECT.h>
  52. #include <OLOG.h>
  53. #include <OCONFIG.h>
  54. #include <OPOWER.h>
  55. #include <OSERES.h>
  56. #include <OIMGRES.h>
  57. #include <OWARPT.h>
  58. #include <OMOUSECR.h>
  59. #include <OFIRMDIE.h>
  60. #include <OOPTMENU.h>
  61. #include <OINGMENU.h>
  62. //---------- define static variables ----------//
  63. static int report_disp_frame_no;
  64. static Button3D button_menu;
  65. //-------- Begin of function Sys::detect --------//
  66. //
  67. void Sys::detect()
  68. {
  69. //--- only detect at the even frames when in report mode ---//
  70. if( view_mode != MODE_NORMAL &&
  71. // ###### begin Gilbert 5/11 ######//
  72. !report_disp_frame_no )
  73. // ###### end Gilbert 5/11 ######//
  74. {
  75. return;
  76. }
  77. //--------------------------------------//
  78. mouse.get_event();
  79. if( option_menu.is_active() )
  80. {
  81. option_menu.detect();
  82. return;
  83. }
  84. if( in_game_menu.is_active() )
  85. {
  86. in_game_menu.detect();
  87. return;
  88. }
  89. if( VBrowse::press_record ) // if the user is pulling the records of the browser up and down, calling detect() routines of other controls will confuse it
  90. {
  91. VBrowse::press_vbrowse_ptr->detect();
  92. }
  93. if( mouse.is_key_event() )
  94. {
  95. process_key(mouse.scan_code, mouse.event_skey_state);
  96. }
  97. detect_button(); // detect main buttons on the screen
  98. detect_view();
  99. }
  100. //--------- End of function Sys::detect ---------//
  101. //-------- Begin of function Sys::process --------//
  102. //
  103. void Sys::process()
  104. {
  105. //---- if any of the DirectDraw buffers is lost, restore it ----//
  106. if( vga_front.is_buf_lost() || vga_back.is_buf_lost() )
  107. {
  108. if (!restore())
  109. pause();
  110. }
  111. //------- update frame count and is_sync_frame --------//
  112. frame_count++;
  113. is_sync_frame = frame_count%3==0; // check if sychronization should take place at this frame (for handling one sync per n frames)
  114. //------- play sound effect ------//
  115. se_ctrl.flush();
  116. //--------- process objects -----------//
  117. LOG_MSG(m.get_random_seed());
  118. LOG_MSG("begin unit_array.process()");
  119. unit_array.process();
  120. seek_path.reset_total_node_avail(); // reset node for seek_path
  121. LOG_MSG("end unit_array.process()");
  122. LOG_MSG(m.get_random_seed());
  123. LOG_MSG("begin firm_array.process()");
  124. firm_array.process();
  125. LOG_MSG("end firm_array.process()");
  126. LOG_MSG(m.get_random_seed());
  127. LOG_MSG("begin town_array.process()");
  128. town_array.process();
  129. LOG_MSG("end town_array.process()");
  130. LOG_MSG(m.get_random_seed());
  131. LOG_MSG("begin nation_array.process()");
  132. nation_array.process();
  133. LOG_MSG("end nation_array.process()");
  134. LOG_MSG(m.get_random_seed());
  135. LOG_MSG("begin bullet_array.process()");
  136. bullet_array.process();
  137. LOG_MSG("end bullet_array.process()");
  138. LOG_MSG(m.get_random_seed());
  139. LOG_MSG("begin world.process()");
  140. world.process();
  141. LOG_MSG("end world.process()");
  142. LOG_MSG(m.get_random_seed());
  143. #ifndef AMPLUS
  144. // AMPLUS version moved to disp_frame
  145. LOG_MSG("begin anim_line.inc_phase()");
  146. anim_line.inc_phase();
  147. LOG_MSG("end anim_line.inc_phase()");
  148. LOG_MSG(m.get_random_seed());
  149. #endif
  150. LOG_MSG("begin tornado_array.process()");
  151. tornado_array.process();
  152. LOG_MSG("begin tornado_array.process()");
  153. LOG_MSG(m.get_random_seed());
  154. LOG_MSG("begin snow_ground_array.process()");
  155. snow_ground_array.process();
  156. LOG_MSG("end snow_ground_array.process()");
  157. LOG_MSG(m.get_random_seed());
  158. LOG_MSG("begin rock_array.process()");
  159. rock_array.process();
  160. LOG_MSG("end rock_array.process()");
  161. LOG_MSG(m.get_random_seed());
  162. LOG_MSG("begin dirt_array.process()");
  163. dirt_array.process();
  164. LOG_MSG("end dirt_array.process()");
  165. LOG_MSG(m.get_random_seed());
  166. LOG_MSG("begin effect_array.process()");
  167. effect_array.process();
  168. LOG_MSG("end effect_array.process()");
  169. LOG_MSG(m.get_random_seed());
  170. LOG_MSG("begin war_point_array.process()");
  171. war_point_array.process();
  172. LOG_MSG("end war_point_array.process()");
  173. LOG_MSG("begin firm_die.process()");
  174. firm_die_array.process();
  175. LOG_MSG("end firm_die.process()");
  176. //------ check if it's time for the next day ------//
  177. if( ++day_frame_count > FRAMES_PER_DAY )
  178. {
  179. LOG_MSG("begin info.next_day()");
  180. info.next_day();
  181. LOG_MSG("end info.next_day()");
  182. LOG_MSG(m.get_random_seed());
  183. LOG_MSG("begin world.next_day()");
  184. world.next_day();
  185. LOG_MSG("end world.next_day()");
  186. LOG_MSG(m.get_random_seed());
  187. LOG_MSG("begin site_array.next_day()");
  188. site_array.next_day();
  189. LOG_MSG("end site_array.next_day()");
  190. LOG_MSG(m.get_random_seed());
  191. LOG_MSG("begin rebel_array.next_day()");
  192. rebel_array.next_day();
  193. LOG_MSG("end rebel_array.next_day()");
  194. LOG_MSG(m.get_random_seed());
  195. LOG_MSG("begin spy_array.next_day()");
  196. spy_array.next_day();
  197. LOG_MSG("end spy_array.next_day()");
  198. LOG_MSG(m.get_random_seed());
  199. LOG_MSG("begin sprite_res.update_speed()");
  200. if( config.weather_effect)
  201. sprite_res.update_speed();
  202. LOG_MSG("end sprite_res.update_speed()");
  203. LOG_MSG(m.get_random_seed());
  204. LOG_MSG("begin raw_res.next_day()");
  205. raw_res.next_day();
  206. LOG_MSG("end raw_res.next_day()");
  207. LOG_MSG(m.get_random_seed());
  208. LOG_MSG("begin talk_res.next_day()");
  209. talk_res.next_day();
  210. LOG_MSG("end talk_res.next_day()");
  211. LOG_MSG(m.get_random_seed());
  212. LOG_MSG("begin region_array.next_day()");
  213. region_array.next_day();
  214. LOG_MSG("end region_array.next_day()");
  215. LOG_MSG(m.get_random_seed());
  216. day_frame_count = 0;
  217. }
  218. //### begin alex 12/9 ###//
  219. //---------- update data structure of selected trading unit ------------//
  220. unit_array.update_selected_trade_unit_info();
  221. //#### end alex 12/9 ####//
  222. //------ display the current frame ------//
  223. LOG_MSG("begin sys.disp_frame");
  224. m.lock_seed();
  225. disp_frame();
  226. m.unlock_seed();
  227. LOG_MSG("end sys.disp_frame");
  228. LOG_MSG(m.get_random_seed() );
  229. //### begin alex 12/9 ###//
  230. //--------- send message for selected trading unit in multiplayer game -------//
  231. unit_array.mp_mark_selected_caravan();
  232. unit_array.mp_mark_selected_ship();
  233. //#### end alex 12/9 ####//
  234. //-----------------------------------------//
  235. /*
  236. #ifdef DEBUG
  237. //------- debug codes used to count town's defender number -------//
  238. Unit *unitPtr;
  239. Town *townPtr;
  240. for(int i=unit_array.size(); i>0; i--)
  241. {
  242. if(unit_array.SpriteArray::is_deleted(i))
  243. continue;
  244. unitPtr = unit_array[i];
  245. if(unitPtr->unit_mode==UNIT_MODE_DEFEND_TOWN)
  246. {
  247. if(town_array.is_deleted(unitPtr->unit_mode_para))
  248. continue;
  249. townPtr = town_array[unitPtr->unit_mode_para];
  250. if(townPtr->nation_recno==unitPtr->nation_recno)
  251. townPtr->debug_defender_count++;
  252. }
  253. }
  254. for(i=town_array.size(); i>0; i--)
  255. {
  256. if(town_array.is_deleted(i))
  257. continue;
  258. townPtr = town_array[i];
  259. err_when(townPtr->debug_defender_count != townPtr->town_defender_count);
  260. townPtr->debug_defender_count = 0;
  261. }
  262. #endif
  263. */
  264. //-*********** simulate aat ************-//
  265. #ifdef DEBUG
  266. if(debug_sim_game_type==2)
  267. {
  268. //if(m.random(20)==0)
  269. if(m.random(50)==0)
  270. {
  271. #define MAX_ATTACKER 30
  272. int arraySize = unit_array.size();
  273. int i, j, i2, j2;
  274. short nationRecno;
  275. Unit *unitPtr, *targetPtr;
  276. short attackerArray[MAX_ATTACKER];
  277. short attackerCount = 0;
  278. //----------- select attackers -----------//
  279. //for(i=m.random(arraySize)+1, j=1; j<=arraySize; j++, i++)
  280. for(i=int(m.get_random_seed()%arraySize)+1, j=1; j<=arraySize; j++, i++)
  281. {
  282. if(i>arraySize)
  283. i = 1;
  284. if(unit_array.is_deleted(i))
  285. continue;
  286. unitPtr = (Unit*) unit_array[i];
  287. if(!unitPtr->is_visible())
  288. continue;
  289. if(attackerCount)
  290. {
  291. if(unitPtr->nation_recno!=nationRecno)
  292. continue;
  293. }
  294. else
  295. nationRecno = unitPtr->nation_recno;
  296. err_when(i!=unitPtr->sprite_recno);
  297. err_when(i>arraySize);
  298. if(m.random(4)==0)
  299. attackerArray[attackerCount++] = i;
  300. if(attackerCount>=MAX_ATTACKER/2)
  301. break; // array full
  302. }
  303. //--------- selecet victim ----------//
  304. //if(day_frame_count==9 && frame_count==6082)
  305. // int debug =0;
  306. if(m.random(10))
  307. {
  308. //for(i2=m.random(arraySize)+1, j2=1; j2<=arraySize; j2++, i2++)
  309. for(i2=int(m.get_random_seed()%arraySize)+1, j2=1; j2<=arraySize; j2++, i2++)
  310. {
  311. if(i2>arraySize)
  312. i2 = 1;
  313. if(unit_array.is_deleted(i2))
  314. continue;
  315. targetPtr = (Unit*) unit_array[i2];
  316. if(!targetPtr->is_visible())
  317. continue;
  318. if(targetPtr->nation_recno==unitPtr->nation_recno)
  319. continue;
  320. err_when(i2>arraySize);
  321. unit_array.attack(targetPtr->next_x_loc(), targetPtr->next_y_loc(), 0, attackerArray, attackerCount, 0, 0);
  322. break;
  323. }
  324. }
  325. else
  326. unit_array.move_to(m.random(MAX_WORLD_X_LOC), m.random(MAX_WORLD_Y_LOC), 0, attackerArray, attackerCount, 1);
  327. }
  328. }
  329. #endif
  330. //-*********** simulate aat ************-//
  331. }
  332. //--------- End of function Sys::process ---------//
  333. //-------- Begin of function Sys::disp_button --------//
  334. //
  335. void Sys::disp_button()
  336. {
  337. vga.use_back();
  338. button_menu.paint( 720, 6, "MENU-U", "MENU-D" );
  339. button_menu.set_help_code( "GAMEMENU" );
  340. vga.use_front();
  341. }
  342. //--------- End of function Sys::disp_button ---------//
  343. //-------- Begin of function Sys::detect_button --------//
  344. //
  345. void Sys::detect_button()
  346. {
  347. //--------- detect menu button -------//
  348. if( button_menu.detect() )
  349. {
  350. // ##### begin Gilbert 5/11 #######//
  351. // game.in_game_menu();
  352. in_game_menu.enter(!remote.is_enable());
  353. // ##### end Gilbert 5/11 #######//
  354. return;
  355. }
  356. //------- detect view mode buttons -----//
  357. #define VIEW_MODE_BUTTON_WIDTH 58
  358. #define VIEW_MODE_BUTTON_HEIGHT 16
  359. #define VIEW_MODE_BUTTON_X_SPACE 5
  360. int i, x=6, y=8;
  361. static char viewModeArray[] =
  362. {
  363. MODE_NATION, MODE_TOWN, MODE_ECONOMY, MODE_TRADE, MODE_MILITARY, MODE_TECH, MODE_SPY, MODE_RANK
  364. };
  365. for( i=0 ; i<8 ; i++, x+=VIEW_MODE_BUTTON_WIDTH+VIEW_MODE_BUTTON_X_SPACE )
  366. {
  367. if( i==4 ) // the second row
  368. {
  369. x=12;
  370. y=29;
  371. }
  372. if( nation_array.player_recno==0 && i<7 ) // when the player has lost the game, the only report available is ranking report only
  373. continue;
  374. if( mouse.single_click( x, y, x+VIEW_MODE_BUTTON_WIDTH-1, y+VIEW_MODE_BUTTON_HEIGHT-1 ) )
  375. {
  376. int newMode = viewModeArray[i];
  377. if( view_mode == newMode ) // when click on the same mode again, go to the normal mode
  378. set_view_mode(MODE_NORMAL);
  379. else
  380. set_view_mode(newMode);
  381. break;
  382. }
  383. }
  384. }
  385. //--------- End of function Sys::detect_button ---------//
  386. //-------- Begin of function Sys::set_view_mode --------//
  387. //
  388. // <int> viewMode - id. of the view mode.
  389. // [int] viewingNationRecno - which nation the player is viewing at with the reports.
  390. // (default: the player nation)
  391. // [int] viewingSpyRecno - >0 if the spy is viewing secret reports of other nations
  392. //
  393. void Sys::set_view_mode(int viewMode, int viewingNationRecno, int viewingSpyRecno)
  394. {
  395. if( view_mode == viewMode )
  396. return;
  397. //---- if the player's kingdom has been destroyed ----//
  398. err_when( viewingNationRecno && nation_array.is_deleted(viewingNationRecno) );
  399. if( nation_array.is_deleted(info.default_viewing_nation_recno) )
  400. {
  401. if( viewMode != MODE_NORMAL && viewMode != MODE_RANK ) // other reports are not available except the normal and rank report
  402. return;
  403. }
  404. //---- a spy is exposed when he has finished viewing the secrets ----//
  405. if( info.viewing_spy_recno )
  406. {
  407. if( !spy_array.is_deleted(info.viewing_spy_recno) )
  408. {
  409. Spy* spyPtr = spy_array[info.viewing_spy_recno];
  410. int needViewSecretSkill = spy_array.needed_view_secret_skill(info.viewing_spy_recno);
  411. int escapeChance = spyPtr->spy_skill - needViewSecretSkill;
  412. int killFlag = 0;
  413. if( escapeChance > 0 )
  414. {
  415. if( m2.random( escapeChance/15 )==0 ) // use m2 instead of m to maintain mulitplayer sync
  416. killFlag = 1;
  417. }
  418. if( killFlag )
  419. spyPtr->set_exposed(COMMAND_PLAYER);
  420. }
  421. info.viewing_spy_recno = 0;
  422. }
  423. //----------------------------------------------------//
  424. if( viewMode == MODE_NORMAL )
  425. {
  426. info.viewing_nation_recno = info.default_viewing_nation_recno;
  427. }
  428. else
  429. {
  430. if( viewingNationRecno )
  431. info.viewing_nation_recno = viewingNationRecno;
  432. else
  433. info.viewing_nation_recno = info.default_viewing_nation_recno;
  434. info.viewing_spy_recno = viewingSpyRecno;
  435. }
  436. view_mode = viewMode;
  437. disp_view_mode();
  438. disp_view();
  439. }
  440. //--------- End of function Sys::set_view_mode ---------//
  441. //-------- Begin of function Sys::disp_frame --------//
  442. void Sys::disp_frame()
  443. {
  444. if( sys.signal_exit_flag )
  445. return;
  446. if( option_menu.is_active() )
  447. {
  448. // ##### begin Gilbert 3/11 ######//
  449. option_menu.disp(need_redraw_flag);
  450. // ##### end Gilbert 3/11 ######//
  451. blt_virtual_buf();
  452. }
  453. else
  454. {
  455. // -------- re-draw the whole screen if needed, such as after task switching ---------//
  456. if( need_redraw_flag )
  457. {
  458. info.disp_panel();
  459. world.paint();
  460. disp_button();
  461. world.refresh();
  462. disp_view();
  463. if( in_game_menu.is_active() )
  464. {
  465. vga.use_back();
  466. in_game_menu.disp();
  467. vga.use_front();
  468. }
  469. vga.blt_buf(0,0, VGA_WIDTH-1, VGA_HEIGHT-1, 0);
  470. // ###### begin Gilbert 4/11 ######//
  471. disp_view_mode();
  472. // ###### end Gilbert 4/11 ######//
  473. info.disp();
  474. }
  475. else
  476. {
  477. update_view();
  478. info.update();
  479. }
  480. //--------- display the map and info area --------//
  481. disp_map();
  482. blt_virtual_buf();
  483. //---------- display help ----------//
  484. if( !remote.is_enable() ) // help is only available in a single player game as it has to pause the game
  485. help.disp();
  486. }
  487. // ####### end Glbert 24/10 #######//
  488. #ifdef AMPLUS
  489. anim_line.inc_phase(); // originally in Sys::process()
  490. #endif
  491. need_redraw_flag = 0;
  492. }
  493. //-------- End of function Sys::disp_frame --------//
  494. //-------- Begin of function Sys::disp_view --------//
  495. //
  496. // Display the view area.
  497. //
  498. void Sys::disp_view()
  499. {
  500. disp_zoom();
  501. // ###### begin Gilbert 5/11 ########//
  502. report_disp_frame_no = 0; // 0 - mean report can be drawn, clear after disp_zoom, set after display report
  503. // ###### end Gilbert 5/11 ########//
  504. //---- if in report mode, convert the view to gray scale ----//
  505. if( view_mode!=MODE_NORMAL )
  506. {
  507. // ###### begin Gilbert 5/11 ########//
  508. // report_disp_frame_no = frame_count; // the frame no which this report is first displayed
  509. // ###### end Gilbert 5/11 ########//
  510. //------- blt the zoom area to the front screen --------//
  511. vga.use_back();
  512. Vga::opaque_flag = config.opaque_report;
  513. switch( view_mode )
  514. {
  515. case MODE_TRADE:
  516. info.disp_trade(INFO_REPAINT);
  517. break;
  518. case MODE_MILITARY:
  519. info.disp_military(INFO_REPAINT);
  520. break;
  521. case MODE_ECONOMY:
  522. info.disp_economy(INFO_REPAINT);
  523. break;
  524. case MODE_TOWN:
  525. info.disp_town(INFO_REPAINT);
  526. break;
  527. case MODE_NATION:
  528. info.disp_nation(INFO_REPAINT);
  529. break;
  530. case MODE_TECH:
  531. info.disp_tech(INFO_REPAINT);
  532. break;
  533. case MODE_SPY:
  534. info.disp_spy(INFO_REPAINT);
  535. break;
  536. case MODE_RANK:
  537. info.disp_rank(INFO_REPAINT);
  538. break;
  539. case MODE_NEWS_LOG:
  540. info.disp_news_log(INFO_REPAINT);
  541. break;
  542. case MODE_AI_ACTION:
  543. info.disp_ai_action(INFO_REPAINT);
  544. break;
  545. }
  546. vga.use_front();
  547. Vga::opaque_flag = 0;
  548. // ###### begin Gilbert 5/11 ########//
  549. report_disp_frame_no = 1;
  550. // ###### end Gilbert 5/11 ########//
  551. }
  552. }
  553. //-------- End of function Sys::disp_view --------//
  554. //-------- Begin of function Sys::update_view --------//
  555. //
  556. // Display the view area.
  557. //
  558. void Sys::update_view()
  559. {
  560. if( view_mode==MODE_NORMAL )
  561. {
  562. disp_zoom();
  563. // ####### begin Gilbert 5/11 #######//
  564. report_disp_frame_no = 0;
  565. // ####### end Gilbert 5/11 #######//
  566. //------ display tutorial text -------//
  567. if( game.game_mode == GAME_TUTORIAL )
  568. tutor.disp();
  569. //----------- draw profile information -----------//
  570. if( config.show_ai_info )
  571. {
  572. vga.use_back();
  573. /*
  574. char* germanStr = "d ü ä ß ö Ä Ü Ö";
  575. vga_back.bar( ZOOM_X1, ZOOM_Y1, ZOOM_X1+300, ZOOM_Y1+150, VGA_LIGHT_GREEN );
  576. font_san.put( ZOOM_X1+10, ZOOM_Y1+30, germanStr );
  577. font_news.put( ZOOM_X1+10, ZOOM_Y1+50, germanStr );
  578. font_bible.put( ZOOM_X1+10, ZOOM_Y1+70, germanStr );
  579. */
  580. nation_array.draw_profile();
  581. firm_array.draw_profile();
  582. town_array.draw_profile();
  583. unit_array.draw_profile();
  584. vga.use_front();
  585. }
  586. if( in_game_menu.is_active() )
  587. {
  588. vga.use_back();
  589. in_game_menu.disp();
  590. vga.use_front();
  591. }
  592. //------------------------------------//
  593. vga.blt_buf(ZOOM_X1, ZOOM_Y1, ZOOM_X2, ZOOM_Y2);
  594. }
  595. else
  596. {
  597. //-------------------------------------------//
  598. //
  599. // In report mode, display the background view in odd
  600. // number frames and the report in even number frames.
  601. //
  602. //-------------------------------------------//
  603. // ####### begin Gilbert 5/11 #######//
  604. if( report_disp_frame_no )
  605. {
  606. disp_zoom();
  607. report_disp_frame_no = 0;
  608. }
  609. else
  610. {
  611. vga.use_back();
  612. Vga::opaque_flag = config.opaque_report;
  613. switch( view_mode )
  614. {
  615. case MODE_TRADE:
  616. info.disp_trade(INFO_UPDATE);
  617. break;
  618. case MODE_MILITARY:
  619. info.disp_military(INFO_UPDATE);
  620. break;
  621. case MODE_ECONOMY:
  622. info.disp_economy(INFO_UPDATE);
  623. break;
  624. case MODE_TOWN:
  625. info.disp_town(INFO_UPDATE);
  626. break;
  627. case MODE_NATION:
  628. info.disp_nation(INFO_UPDATE);
  629. break;
  630. case MODE_TECH:
  631. info.disp_tech(INFO_UPDATE);
  632. break;
  633. case MODE_SPY:
  634. info.disp_spy(INFO_UPDATE);
  635. break;
  636. case MODE_RANK:
  637. info.disp_rank(INFO_UPDATE);
  638. break;
  639. case MODE_NEWS_LOG:
  640. info.disp_news_log(INFO_UPDATE);
  641. break;
  642. case MODE_AI_ACTION:
  643. info.disp_ai_action(INFO_UPDATE);
  644. break;
  645. }
  646. if( in_game_menu.is_active() )
  647. {
  648. in_game_menu.disp();
  649. }
  650. vga.use_front();
  651. Vga::opaque_flag = 0;
  652. vga.blt_buf(ZOOM_X1, ZOOM_Y1, ZOOM_X2, ZOOM_Y2);
  653. // ###### begin Gilbert 5/11 #######//
  654. report_disp_frame_no = 1;
  655. // ###### end Gilbert 5/11 #######//
  656. }
  657. }
  658. }
  659. //-------- End of function Sys::update_view --------//
  660. //-------- Begin of function Sys::detect_view --------//
  661. //
  662. void Sys::detect_view()
  663. {
  664. int enableAction; // some action is not enabled, when paused.
  665. #ifdef AMPLUS
  666. enableAction = config.frame_speed > 0 || !remote.is_enable(); // AMPLUS allows action when paused in single player
  667. #else
  668. enableAction = config.frame_speed > 0;
  669. #endif
  670. if( enableAction )
  671. info.detect();
  672. vga.use_back();
  673. switch( view_mode )
  674. {
  675. case MODE_TRADE:
  676. info.detect_trade();
  677. break;
  678. case MODE_MILITARY:
  679. info.detect_military();
  680. break;
  681. case MODE_ECONOMY:
  682. info.detect_economy();
  683. break;
  684. case MODE_TOWN:
  685. info.detect_town();
  686. break;
  687. case MODE_NATION:
  688. info.detect_nation();
  689. break;
  690. case MODE_TECH:
  691. info.detect_tech();
  692. break;
  693. case MODE_SPY:
  694. info.detect_spy();
  695. break;
  696. case MODE_RANK:
  697. info.detect_rank();
  698. break;
  699. case MODE_NEWS_LOG:
  700. info.detect_news_log();
  701. break;
  702. case MODE_AI_ACTION:
  703. info.detect_ai_action();
  704. break;
  705. }
  706. vga.use_front();
  707. //------ detect tutorial controls -------//
  708. if( view_mode==MODE_NORMAL && game.game_mode==GAME_TUTORIAL ) // tutorial text is only displayed in non-report mode
  709. {
  710. if( tutor.detect() )
  711. return;
  712. }
  713. //---- no normal news when the game is displaying the news log ----//
  714. // ##### patch begin Gilbert 31/3 #####//
  715. if( news_array.detect() )
  716. return;
  717. // ##### patch end Gilbert 31/3 #####//
  718. //---- pressing right button in command mode -> cancel command mode ----//
  719. if( mouse.any_click(RIGHT_BUTTON) && power.command_id )
  720. {
  721. power.command_id = 0;
  722. mouse.reset_click();
  723. info.disp();
  724. return;
  725. }
  726. //------ detect selecting objects and laying tracks ------//
  727. //-------- detect world ----------//
  728. if( world.detect() )
  729. return;
  730. if( view_mode == MODE_NORMAL )
  731. {
  732. if( world.detect_firm_town() )
  733. return;
  734. //------ detect selecting objects and laying tracks ------//
  735. if( power.detect_frame() )
  736. return;
  737. }
  738. else
  739. {
  740. mouse_cursor.set_frame(0);
  741. }
  742. //----------- detect action ------------//
  743. if( enableAction && power.detect_action() )
  744. {
  745. if(unit_array.selected_recno && se_res.mark_command_time() )
  746. {
  747. Unit *unitPtr = unit_array[unit_array.selected_recno];
  748. se_res.far_sound( unitPtr->cur_x_loc(), unitPtr->cur_y_loc(), 1, 'S',
  749. unitPtr->sprite_id, "ACK");
  750. }
  751. return;
  752. }
  753. //----- detect right mouse button to select defined unit groups -----//
  754. if( !(mouse.event_skey_state & SHIFT_KEY_MASK) &&
  755. mouse.any_click(ZOOM_X1, ZOOM_Y1, ZOOM_X2, ZOOM_Y2, RIGHT_BUTTON) &&
  756. power.detect_select(mouse.click_x(RIGHT_BUTTON), mouse.click_y(RIGHT_BUTTON),
  757. mouse.click_x(RIGHT_BUTTON),mouse.click_y(RIGHT_BUTTON), 1, 0) ) // 1 - recall group
  758. {
  759. return;
  760. }
  761. //-------- detect world ----------//
  762. // world.detect();
  763. }
  764. //-------- End of function Sys::detect_view --------//
  765. //-------- Begin of function Sys::disp_map --------//
  766. void Sys::disp_map()
  767. {
  768. //------ draw and display the map -------//
  769. if( map_need_redraw ) // requested by other modules to redraw the pre-drawn map background
  770. {
  771. world.map_matrix->draw();
  772. map_need_redraw = 0;
  773. }
  774. world.map_matrix->disp();
  775. //-------- draw dots on the map ---------//
  776. firm_array.draw_dot();
  777. town_array.draw_dot();
  778. site_array.draw_dot();
  779. unit_array.draw_dot();
  780. war_point_array.draw_dot();
  781. tornado_array.draw_dot();
  782. world.map_matrix->draw_square(); // draw a square on the map for current zoomed area
  783. //------- blt the map area to the front screen --------//
  784. vga.blt_buf( MAP_X1, MAP_Y1 , MAP_X2 , MAP_Y2);
  785. }
  786. //-------- End of function Sys::disp_map --------//
  787. //-------- Begin of function Sys::disp_zoom --------//
  788. void Sys::disp_zoom()
  789. {
  790. //--------- set zoom window ----------//
  791. ZoomMatrix* zoomMatrix = world.zoom_matrix;
  792. err_when(zoomMatrix->top_x_loc<0 || zoomMatrix->top_x_loc>=MAX_WORLD_X_LOC);
  793. err_when(zoomMatrix->top_y_loc<0 || zoomMatrix->top_y_loc>=MAX_WORLD_Y_LOC);
  794. World::view_top_x = zoomMatrix->top_x_loc * ZOOM_LOC_WIDTH;
  795. World::view_top_y = zoomMatrix->top_y_loc * ZOOM_LOC_HEIGHT;
  796. //--------- draw map area ---------//
  797. if( zoom_need_redraw ) // requested by other modules to redraw the pre-drawn zoom background
  798. {
  799. long backupSeed = m.get_random_seed();
  800. world.zoom_matrix->draw();
  801. zoom_need_redraw = 0;
  802. }
  803. //-------- disp zoom area --------//
  804. world.zoom_matrix->disp();
  805. //---- draw sprite white sites if in debug mode ----//
  806. #ifdef DEBUG
  807. if(debug2_enable_flag)
  808. world.zoom_matrix->draw_white_site();
  809. #endif
  810. //------- draw foreground objects --------//
  811. world.zoom_matrix->draw_frame();
  812. //----- draw the frame of the selected firm/town -----//
  813. info.draw_selected();
  814. //-------- display news messages ---------//
  815. news_array.disp();
  816. //----- next frame, increase the frame counter -----//
  817. sys.frames_in_this_second++; // no. of frames displayed in this second
  818. if( view_mode==MODE_NORMAL )
  819. disp_frames_per_second();
  820. }
  821. //-------- End of function Sys::disp_zoom --------//
  822. //-------- Begin of function Sys::blt_virtual_buf --------//
  823. //
  824. void Sys::blt_virtual_buf()
  825. {
  826. if( !sys.debug_session )
  827. return;
  828. //--- in a debug sesion, vga_front is not the true front buffer, now copy it to the true one ---//
  829. int frontLocked=0;
  830. if( vga_front.buf_locked )
  831. {
  832. vga_front.unlock_buf();
  833. frontLocked=1;
  834. }
  835. RECT bltRect;
  836. bltRect.left = 0;
  837. bltRect.top = 0;
  838. bltRect.right = VGA_WIDTH-1;
  839. bltRect.bottom = VGA_HEIGHT-1;
  840. int rc = vga_true_front.dd_buf->BltFast(
  841. 0, 0,
  842. vga_front.dd_buf, // src surface
  843. &bltRect, // src rect (all of it)
  844. DDBLTFAST_WAIT );
  845. if( frontLocked )
  846. vga_front.lock_buf();
  847. }
  848. //--------- End of function Sys::blt_virtual_buf ---------//
  849. //-------- Begin of function Sys::disp_frames_per_second --------//
  850. //
  851. void Sys::disp_frames_per_second()
  852. {
  853. if( !config.show_ai_info ) // only display this in a debug session
  854. return;
  855. if( game.game_mode == GAME_TUTORIAL ) // don't display in tutorial mode as it overlaps with the tutorial text
  856. return;
  857. //------- get the curren system time ---------//
  858. DWORD curTime = m.get_time(); // in millisecond
  859. //----------- first time calling -------------//
  860. if( last_second_time==0 )
  861. {
  862. last_second_time = curTime;
  863. frames_in_this_second = 0; // no. of frames displayed in this second
  864. return;
  865. }
  866. //------ when passes to the next second -----//
  867. if( curTime >= last_second_time+1000 ) // 1 second = 1000 millisecond
  868. {
  869. frames_per_second = frames_in_this_second;
  870. //------ update var and reset counter -----//
  871. last_second_time += 1000;
  872. frames_in_this_second = 0;
  873. }
  874. //---------- display frame count -----------//
  875. String str;
  876. str = "Frames per second: ";
  877. str += frames_per_second;
  878. vga.use_back();
  879. font_news.disp( ZOOM_X1+10, ZOOM_Y1+10, str, MAP_X2);
  880. vga.use_front();
  881. }
  882. //--------- End of function Sys::disp_frames_per_second ---------//
  883. //--------- Begin of funtion Sys::disp_view_mode ---------//
  884. // <int> observeMode - force observe mode display (darken view mode 1 - 7)
  885. // needed in Game::game_end, nation_array.player_recno has not yet set to 0
  886. void Sys::disp_view_mode(int observeMode)
  887. {
  888. // ------- display highlight ----------//
  889. const int MIN_MODE_TO_DISPLAY = 1;
  890. const int MAX_MODE_TO_DISPLAY = 8;
  891. const int MODE_TO_DISPLAY_COUNT = MAX_MODE_TO_DISPLAY - MIN_MODE_TO_DISPLAY + 1;
  892. static short highLightX[MODE_TO_DISPLAY_COUNT] = { 0, 62, 124, 186, 7, 68, 129, 192};
  893. static short highLightY[MODE_TO_DISPLAY_COUNT] = { 0, 0, 0, 0, 19, 19, 19, 19};
  894. static short darkenX[MODE_TO_DISPLAY_COUNT] = { 7, 69, 132, 195, 13, 75, 139, 201};
  895. static short darkenY[MODE_TO_DISPLAY_COUNT] = { 8, 8, 8, 8, 29, 29, 29, 29};
  896. const int darkenWidth = 58;
  897. const int darkenHeight = 16;
  898. char scrollName[] = "SCROLL-0";
  899. // disable highlight of the mode before
  900. scrollName[7] = 'B';
  901. image_button.put_front( 0,0, scrollName);
  902. // highlight of the mode after
  903. if( view_mode >= MIN_MODE_TO_DISPLAY && view_mode <= MAX_MODE_TO_DISPLAY )
  904. {
  905. // find the size of that scroll
  906. scrollName[7] = '0' + view_mode;
  907. image_button.put_front( highLightX[view_mode-MIN_MODE_TO_DISPLAY],
  908. highLightY[view_mode-MIN_MODE_TO_DISPLAY], scrollName);
  909. }
  910. // darken buttons of view mode 1-7 if nation_array.player_recno == 0
  911. if( observeMode || !nation_array.player_recno )
  912. {
  913. for( int j = 1; j <= 7; ++j )
  914. {
  915. //if( j == view_mode)
  916. // continue;
  917. vga_front.adjust_brightness(
  918. darkenX[j-MIN_MODE_TO_DISPLAY], darkenY[j-MIN_MODE_TO_DISPLAY],
  919. darkenX[j-MIN_MODE_TO_DISPLAY]+darkenWidth-1,
  920. darkenY[j-MIN_MODE_TO_DISPLAY]+darkenHeight-1, -8 );
  921. }
  922. }
  923. }
  924. //--------- End of funtion Sys::disp_view_mode ---------//