OGAMEND.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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 : OGAMEND.CPP
  21. //Description : Game ending screen
  22. #include <OVGA.h>
  23. #include <OVGALOCK.h>
  24. #include <ODATE.h>
  25. #include <OREMOTE.h>
  26. #include <OBOX.h>
  27. #include <OCONFIG.h>
  28. #include <OSTR.h>
  29. #include <OSYS.h>
  30. #include <OFONT.h>
  31. #include <OMOUSE.h>
  32. #include <OIMGRES.h>
  33. #include <ORACERES.h>
  34. #include <OGAME.h>
  35. #include <OGFILE.h>
  36. #include <ONATION.h>
  37. #include <OMOUSECR.h>
  38. #include <OMUSIC.h>
  39. #include <OOPTMENU.h>
  40. #include <OINGMENU.h>
  41. // ####### begin Gilbert 29/10 ########//
  42. #include <OPOWER.h>
  43. // ####### end Gilbert 29/10 ########//
  44. //-------- Declare static vars & functions ---------//
  45. static int disp_score(int winFlag);
  46. static void disp_goal_str(int winNationRecno);
  47. static void disp_losing_str(int surrenderToNationRecno);
  48. static void disp_retire_str();
  49. static void disp_ranking();
  50. static void disp_stat();
  51. static void put_stat(int y, char* desStr, char* dispStr);
  52. static void put_stat(int y, char* desStr, int dispValue);
  53. static void put_ranking(int y, int nationRecno);
  54. //---------- Begin of function Game::game_end --------//
  55. //
  56. // <int> winNationRecno - the recno of the nation that won the game.
  57. // 0 - if you are just defeated or surrender
  58. // to another kingdom, and no other kingdom
  59. // has won yet.
  60. // [int] playerDestroyed - whether the player's nation has been destroyed or not.
  61. // (default: 0)
  62. // [int] surrenderToNationRecno - the nation your surrender to.
  63. // [int] retireFlag - 1 if the player retires
  64. //
  65. void Game::game_end(int winNationRecno, int playerDestroyed, int surrenderToNationRecno, int retireFlag)
  66. {
  67. //--- if the player has already won/lost the game and is just staying/observing the game ---//
  68. if( game_has_ended && !retireFlag ) // don't repeat displaying the winning/losing screen
  69. return;
  70. // ------ quit any menu mode ------//
  71. if( option_menu.is_active() )
  72. {
  73. option_menu.abort();
  74. }
  75. if( ::in_game_menu.is_active() )
  76. {
  77. ::in_game_menu.abort();
  78. }
  79. //------ set the quit siginal -------//
  80. sys.signal_exit_flag = 2; // set it first to disable Power::mouse.handler()
  81. mouse_cursor.set_frame(0);
  82. // ####### begin Gilbert 29/10 #######//
  83. mouse_cursor.set_icon(CURSOR_NORMAL);
  84. // ####### end Gilbert 29/10 #######//
  85. info.save_game_scr();
  86. int useBackBuf = vga.use_back_buf;
  87. vga.use_front();
  88. //------- display the winning/losing picture -------//
  89. int songId = 10;
  90. int winFlag = 0;
  91. if( !retireFlag ) // don't display this when retire
  92. {
  93. char* fileName;
  94. if( winNationRecno && (winNationRecno == nation_array.player_recno) )
  95. {
  96. fileName = race_res[(~nation_array)->race_id]->code;
  97. songId = 9;
  98. winFlag = 1;
  99. }
  100. else
  101. fileName = "LOSEGAME";
  102. vga.disp_image_file(fileName);
  103. music.play(songId, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0);
  104. mouse.wait_press(60); // 60 seconds to time out
  105. }
  106. else
  107. {
  108. music.play(songId, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0);
  109. }
  110. //------- display the statistic -------//
  111. vga.disp_image_file("RESULTS");
  112. if( winNationRecno )
  113. {
  114. disp_goal_str(winNationRecno);
  115. }
  116. else if( retireFlag )
  117. {
  118. disp_retire_str();
  119. }
  120. else
  121. {
  122. disp_losing_str(surrenderToNationRecno);
  123. }
  124. disp_stat();
  125. mouse.wait_press(60); // 60 seconds to time out
  126. //-------- display ranking and score ----------//
  127. vga.disp_image_file("RESULTS");
  128. info.set_rank_data(0); // count all nations, not only those that have contact with the player
  129. disp_ranking();
  130. int totalScore = disp_score(winFlag);
  131. mouse.wait_press(60); // 60 seconds to time out
  132. //--- if the player has managed to get into the hall of fame ---//
  133. if( !game_has_ended )
  134. {
  135. if( !game_file_array.add_hall_of_fame(totalScore) )
  136. vga.finish_disp_image_file(); // if add_hall_of_fame() has displayed the bitmap, it should have called vga.finish_disp_image_file() already
  137. }
  138. else
  139. {
  140. vga.finish_disp_image_file();
  141. }
  142. //--------- set game_has_ended to 1 --------//
  143. music.stop();
  144. game_has_ended = 1;
  145. //----------- reset all goals -----------//
  146. config.goal_destroy_monster = 0;
  147. config.goal_population_flag = 0;
  148. config.goal_economic_score_flag = 0;
  149. config.goal_total_score_flag = 0;
  150. config.goal_year_limit_flag = 0;
  151. //--- otherwise, ask if the player wants to stay in the game ---//
  152. #ifndef DEMO // cannot continue to stay in the game in the demo version
  153. if( !retireFlag && !remote.is_enable() ) // can't stay in the game in a multiplayer game
  154. {
  155. vga_front.bar( 0, 0, VGA_WIDTH-1, VGA_HEIGHT-1, V_BLACK ); // clear the screen
  156. // ###### begin Gilbert 29/10 ######//
  157. char powerWinFlag = power.win_opened;
  158. power.win_opened = 1;
  159. if( box.ask( "Do you want to continue to stay in the game?", "Yes", "No" ) )
  160. sys.signal_exit_flag = 0;
  161. power.win_opened = powerWinFlag;
  162. // ###### end Gilbert 29/10 ######//
  163. }
  164. #endif
  165. //-------- if it quits now ----------//
  166. if( sys.signal_exit_flag )
  167. {
  168. info.free_game_scr();
  169. vga.use_back_buf = useBackBuf;
  170. }
  171. else
  172. {
  173. //---- otherwise restore the screen and continue to play ----//
  174. info.rest_game_scr();
  175. vga.use_back_buf = useBackBuf;
  176. //---- reveal the whole world for staying in the game after being destroyed ----//
  177. if( playerDestroyed && !retireFlag )
  178. {
  179. world.unveil(0, 0, MAX_WORLD_X_LOC-1, MAX_WORLD_Y_LOC-1);
  180. world.visit(0, 0, MAX_WORLD_X_LOC-1, MAX_WORLD_Y_LOC-1, 0, 0);
  181. config.blacken_map = 0;
  182. config.fog_of_war = 0;
  183. }
  184. }
  185. }
  186. //----------- End of function Game::game_end ---------//
  187. //----------- Begin of static function disp_goal_str -----------//
  188. static void disp_goal_str(int winNationRecno)
  189. {
  190. Nation* winNation = nation_array[winNationRecno];
  191. String str, str2;
  192. if( winNationRecno == nation_array.player_recno )
  193. str = translate.process("Your Kingdom");
  194. else
  195. str = nation_array[winNationRecno]->nation_name();
  196. str2 = "";
  197. //---- if the player has achieved one of its goals ----//
  198. if( winNation->goal_destroy_monster_achieved() )
  199. {
  200. str2 = str;
  201. str = translate.process("All Fryhtans have been Destroyed !");
  202. str2 += translate.process(" has Achieved the Highest Fryhtan Battling Score !");
  203. }
  204. //-----------------------------------//
  205. else if( winNation->goal_population_achieved() )
  206. {
  207. str += translate.process( " has Reached" );
  208. str2 = translate.process( "its Population Goal of " );
  209. str2 += config.goal_population;
  210. str2 += " !";
  211. }
  212. //-----------------------------------//
  213. else if( winNation->goal_economic_score_achieved() )
  214. {
  215. str += translate.process( " has Reached" );
  216. str2 = translate.process( "its Economic Score Goal of " );
  217. str2 += config.goal_economic_score;
  218. str2 += " !";
  219. }
  220. //-----------------------------------//
  221. else if( winNation->goal_total_score_achieved() )
  222. {
  223. str += translate.process( " has Reached" );
  224. str2 = translate.process( "its Total Score Goal of " );
  225. str2 += config.goal_total_score;
  226. str2 += " !";
  227. }
  228. //-----------------------------------//
  229. else // ( winNation->goal_destroy_nation_achieved() )
  230. {
  231. str += translate.process( " has Defeated All Other Kingdoms !" );
  232. }
  233. //-----------------------------------//
  234. int y=40;
  235. if( winNationRecno != nation_array.player_recno )
  236. {
  237. font_bible.center_put(0, 30, VGA_WIDTH-1, 60, "You Have Lost the Game !" );
  238. y=60;
  239. }
  240. font_bible.center_put(0, y , VGA_WIDTH-1, y+30, str );
  241. font_bible.center_put(0, y+30, VGA_WIDTH-1, y+60, str2 );
  242. }
  243. //----------- End of static function disp_goal_str -----------//
  244. //----------- Begin of static function disp_losing_str -----------//
  245. static void disp_losing_str(int surrenderToNationRecno)
  246. {
  247. String str;
  248. if( surrenderToNationRecno ) // you surrender to another kingdom
  249. {
  250. str = translate.process( "You Surrendered to " );
  251. str += nation_array[surrenderToNationRecno]->nation_name();
  252. str += " ";
  253. str += translate.process( "on ");
  254. str += date.date_str(info.game_date);
  255. str += ".";
  256. }
  257. // You failed to achieve the goal within the time limit
  258. else if( config.goal_year_limit_flag && info.game_date >= info.goal_deadline )
  259. {
  260. str = "Your Kingdom has Failed to Achieve its Goal Within the Time Limit.";
  261. }
  262. else // you're defeated by another kingdom
  263. {
  264. str = "Your Kingdom has Gone Down to Ignominious Defeat !";
  265. }
  266. font_bible.center_put(0, 0, VGA_WIDTH-1, 139, str );
  267. }
  268. //----------- End of static function disp_losing_str -----------//
  269. //----------- Begin of static function disp_retire_str -----------//
  270. static void disp_retire_str()
  271. {
  272. String str;
  273. #if(defined(SPANISH))
  274. str = "Te has retirado el ";
  275. str += date.date_str( info.game_date );
  276. str += ".";
  277. #elif(defined(FRENCH))
  278. str = "Vous avez abandonné le ";
  279. str += date.date_str( info.game_date );
  280. str += ".";
  281. #elif(defined(GERMAN))
  282. str = "Sie haben am ";
  283. str += date.date_str( info.game_date );
  284. str += " aufgegeben.";
  285. #else
  286. str = "You Retired on ";
  287. str += date.date_str( info.game_date );
  288. str += ".";
  289. #endif
  290. font_bible.center_put(0, 0, VGA_WIDTH-1, 139, str );
  291. }
  292. //----------- End of static function disp_retire_str -----------//
  293. //-------- Begin of static function disp_stat --------//
  294. //
  295. static void disp_stat()
  296. {
  297. int y=140;
  298. Nation* nationPtr = ~nation_array;
  299. put_stat( y , "Duration of Your Rule", info.game_duration_str() );
  300. put_stat( y+=20, "Total Gaming Time", info.play_time_str() );
  301. put_stat( y+=30, "Final Population", nationPtr->all_population() );
  302. put_stat( y+=20, "Final Treasure" , m.format((int)nationPtr->cash,2) );
  303. put_stat( y+=30, "Enemy Soldiers Dispatched", nationPtr->enemy_soldier_killed );
  304. put_stat( y+=20, "King's Soldiers Martyred" , nationPtr->own_soldier_killed );
  305. put_stat( y+=30, "Enemy Weapons Destroyed" , nationPtr->enemy_weapon_destroyed );
  306. put_stat( y+=20, "King's Weapons Rendered Obsolete", nationPtr->own_weapon_destroyed );
  307. put_stat( y+=30, "Enemy Ships Sunk" , nationPtr->enemy_ship_destroyed );
  308. put_stat( y+=20, "King's Ships Missing", nationPtr->own_ship_destroyed );
  309. put_stat( y+=30, "Enemy Buildings Destroyed" , nationPtr->enemy_firm_destroyed );
  310. put_stat( y+=20, "King's Buildings Cleared", nationPtr->own_firm_destroyed );
  311. put_stat( y+=30, "Enemy Civilians Collaterally Damaged", nationPtr->enemy_civilian_killed );
  312. put_stat( y+=20, "King's Civilians Cruelly Murdered" , nationPtr->own_civilian_killed );
  313. }
  314. //----------- End of static function disp_stat -----------//
  315. //-------- Begin of static function put_stat --------//
  316. //
  317. static void put_stat(int y, char* desStr, char* dispStr)
  318. {
  319. font_bible.put( 140, y, desStr );
  320. font_bible.put( 570, y, dispStr );
  321. }
  322. //----------- End of static function put_stat -----------//
  323. //-------- Begin of static function put_stat --------//
  324. //
  325. static void put_stat(int y, char* desStr, int dispValue)
  326. {
  327. font_bible.put( 140, y, desStr );
  328. font_bible.put( 570, y, m.format(dispValue) );
  329. }
  330. //----------- End of static function put_stat -----------//
  331. //-------- Begin of static function disp_ranking --------//
  332. //
  333. static void disp_ranking()
  334. {
  335. //--------- display descriptions ---------//
  336. int x=20, y=76;
  337. font_bible.put( x+20 , y+7, "Kingdom" );
  338. font_bible.put( x+260, y+7, "Population" );
  339. font_bible.put( x+370, y+7, "Military" );
  340. font_bible.put( x+470, y+7, "Economy" );
  341. font_bible.put( x+562, y+7, "Reputation" );
  342. #if(defined(SPANISH))
  343. font_bible.put( x+670, y , "Lucha" );
  344. font_bible.put( x+670, y+14, "Fryhtan" );
  345. #else
  346. font_bible.put( x+670, y , "Fryhtan" );
  347. font_bible.put( x+670, y+14, "Battling" );
  348. #endif
  349. //--------- display rankings -----------//
  350. put_ranking(y+=36, nation_array.player_recno);
  351. for( int i=1 ; i<=nation_array.size() ; i++ )
  352. {
  353. if( nation_array.is_deleted(i) || i==nation_array.player_recno )
  354. continue;
  355. put_ranking( y+=30, i );
  356. }
  357. }
  358. //----------- End of static function disp_ranking -----------//
  359. //-------- Begin of static function put_ranking --------//
  360. //
  361. static void put_ranking(int y, int nationRecno)
  362. {
  363. Nation* nationPtr = nation_array[nationRecno];
  364. int x=20;
  365. nationPtr->disp_nation_color(x, y+5);
  366. font_bible.put( x+20, y, nationPtr->nation_name() );
  367. int y2 = y+font_bible.height()-1;
  368. font_bible.center_put( x+260, y, x+340, y2, info.get_rank_pos_str(1, nationRecno) );
  369. font_bible.center_put( x+370, y, x+435, y2, info.get_rank_pos_str(2, nationRecno) );
  370. font_bible.center_put( x+470, y, x+540, y2, info.get_rank_pos_str(3, nationRecno) );
  371. font_bible.center_put( x+562, y, x+640, y2, info.get_rank_pos_str(4, nationRecno) );
  372. font_bible.center_put( x+670, y, x+730, y2, info.get_rank_pos_str(5, nationRecno) );
  373. }
  374. //----------- End of static function put_ranking -----------//
  375. //--------- Begin of static function disp_score ---------//
  376. //
  377. static int disp_score(int winFlag)
  378. {
  379. int x=200, y=360;
  380. static char* rankStrArray[] =
  381. { "Population Score", "Military Score", "Economic Score",
  382. "Reputation Score", "Fryhtan Battling Score" };
  383. //------ display individual scores ---------//
  384. int rankScore, totalScore=0;
  385. int viewNationRecno = nation_array.player_recno;
  386. for( int i=0 ; i<MAX_RANK_TYPE ; i++, y+=22 )
  387. {
  388. rankScore = info.get_rank_score(i+1, viewNationRecno);
  389. totalScore += rankScore;
  390. font_bible.put( x , y, rankStrArray[i] );
  391. font_bible.put( x+300, y, rankScore );
  392. }
  393. vga_front.bar( x, y, x+340, y+1, V_BLACK );
  394. y+=7;
  395. //-------- display thte total score --------//
  396. font_bible.put( x , y+2, "Total Score" );
  397. font_bible.put( x+300, y+2, totalScore );
  398. y+=28;
  399. vga_front.bar( x, y, x+340, y+1, V_BLACK );
  400. y+=4;
  401. //-------- display the final score ---------//
  402. int difficultyRating = config.difficulty_rating;
  403. int finalScore = totalScore * difficultyRating / 100;
  404. String str;
  405. str = translate.process("Final Score");
  406. str += ": ";
  407. str += totalScore;
  408. str += " X ";
  409. x = font_bible.put( x, y+20, str )+5;
  410. str = difficultyRating;
  411. str += " ";
  412. str += translate.process( "(Difficulty Rating)" );
  413. font_bible.center_put( x, y+4, x+170, y+1+font_bible.height(), str );
  414. vga_front.bar( x, y+27, x+170, y+28, V_BLACK );
  415. font_bible.put( x+70, y+30, 100 );
  416. //---- if this is a scenario and there are score bonus ----//
  417. str = "";
  418. if( info.goal_score_bonus && winFlag &&
  419. !nation_array[viewNationRecno]->cheat_enabled_flag ) // if cheated, don't display bonus score, as there is no space for displaying both
  420. {
  421. str += "+ ";
  422. str += info.goal_score_bonus;
  423. str += " (Bonus) ";
  424. finalScore += info.goal_score_bonus;
  425. }
  426. //------- if the player has cheated -------//
  427. if( nation_array[viewNationRecno]->cheat_enabled_flag )
  428. {
  429. str = "X 0 ";
  430. str += translate.process( "(Cheated)" );
  431. str += " ";
  432. finalScore = 0;
  433. }
  434. str += "= ";
  435. str += finalScore;
  436. font_bible.put( x+180, y+18, str);
  437. return finalScore;
  438. }
  439. //----------- End of static function disp_score -----------//