OR_RANK.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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 : OR_RANK.CPP
  21. //Description : Ranking report
  22. #include <ODATE.h>
  23. #include <OFONT.h>
  24. #include <OGAME.h>
  25. #include <OCONFIG.h>
  26. #include <OVBROWIF.h>
  27. #include <ONATION.h>
  28. #include <OINFO.h>
  29. //------------- Define coordinations -----------//
  30. enum { NATION_BROWSE_X1 = ZOOM_X1+6,
  31. NATION_BROWSE_Y1 = ZOOM_Y1+6,
  32. NATION_BROWSE_X2 = ZOOM_X2-6,
  33. NATION_BROWSE_Y2 = NATION_BROWSE_Y1+220,
  34. };
  35. enum { NATION_SCORE_X1 = ZOOM_X1+6,
  36. NATION_SCORE_Y1 = NATION_BROWSE_Y2+6,
  37. NATION_SCORE_X2 = ZOOM_X2-6,
  38. NATION_SCORE_Y2 = NATION_SCORE_Y1+150,
  39. };
  40. enum { NATION_GOAL_X1 = ZOOM_X1+6,
  41. NATION_GOAL_Y1 = NATION_SCORE_Y2+6,
  42. NATION_GOAL_X2 = ZOOM_X2-6,
  43. NATION_GOAL_Y2 = NATION_GOAL_Y1+110,
  44. };
  45. enum { PLAY_TIME_X1 = ZOOM_X1+6,
  46. PLAY_TIME_X2 = ZOOM_X2-6,
  47. };
  48. //----------- Define static variables ----------//
  49. static VBrowseIF browse_nation;
  50. static int nation_rank_data_array[MAX_RANK_TYPE][MAX_NATION];
  51. //----------- Define static functions ----------//
  52. static void put_nation_rec(int recNo, int x, int y, int refreshFlag);
  53. static int nation_filter(int recNo=0);
  54. static void disp_score();
  55. static void disp_goal();
  56. static void disp_play_time(int y1);
  57. //--------- Begin of function Info::disp_rank ---------//
  58. //
  59. void Info::disp_rank(int refreshFlag)
  60. {
  61. set_rank_data(1); // 1-only set those nations that have contact with us
  62. int x=NATION_BROWSE_X1+9;
  63. int y=NATION_BROWSE_Y1+3;
  64. vga_back.d3_panel_up(NATION_BROWSE_X1, NATION_BROWSE_Y1, NATION_BROWSE_X2, NATION_BROWSE_Y1+32 );
  65. font_san.put( x , y+7, "Kingdom" );
  66. font_san.put( x+180, y+7, "Population" );
  67. font_san.put( x+264, y+7, "Military" );
  68. font_san.put( x+332, y+7, "Economy" );
  69. font_san.put( x+406, y+7, "Reputation" );
  70. #if(defined(SPANISH))
  71. font_san.put( x+484, y , "Lucha" );
  72. font_san.put( x+484, y+13, "Fryhtan" );
  73. #else
  74. // FRENCH, German and US
  75. font_san.put( x+484, y , "Fryhtan" );
  76. font_san.put( x+484, y+13, "Battling" );
  77. #endif
  78. if( refreshFlag == INFO_REPAINT )
  79. {
  80. browse_nation.init( NATION_BROWSE_X1, NATION_BROWSE_Y1+34, NATION_BROWSE_X2, NATION_BROWSE_Y2,
  81. 0, 22, nation_filter(), put_nation_rec, 1 );
  82. browse_nation.open(browse_nation_recno);
  83. }
  84. else
  85. {
  86. browse_nation.paint();
  87. browse_nation.open(browse_nation_recno, nation_filter());
  88. }
  89. //----- display score -------//
  90. disp_score();
  91. //------ display goal -------//
  92. if( !game.game_has_ended ) // if the ending screen has already appeared once, don't display the goal
  93. {
  94. disp_goal();
  95. y = NATION_GOAL_Y2+6;
  96. }
  97. else
  98. {
  99. y = NATION_GOAL_Y1;
  100. }
  101. //----- display total playing time -----//
  102. disp_play_time(y);
  103. }
  104. //----------- End of function Info::disp_rank -----------//
  105. //--------- Begin of static function disp_score ---------//
  106. //
  107. static void disp_score()
  108. {
  109. int x=NATION_SCORE_X1+6, y=NATION_SCORE_Y1+6;
  110. static char* rankStrArray[] =
  111. { "Population Score", "Military Score", "Economic Score",
  112. "Reputation Score", "Fryhtan Battling Score" };
  113. vga.d3_panel_down( NATION_SCORE_X1, NATION_SCORE_Y1, NATION_SCORE_X2, NATION_SCORE_Y2 );
  114. //------ display individual scores ---------//
  115. int rankScore, totalScore=0;
  116. int viewNationRecno = nation_filter(browse_nation.recno());
  117. for( int i=0 ; i<MAX_RANK_TYPE ; i++, y+=16 )
  118. {
  119. rankScore = info.get_rank_score(i+1, viewNationRecno);
  120. totalScore += rankScore;
  121. font_san.put( x , y, rankStrArray[i] );
  122. font_san.put( x+300, y, rankScore, 1 );
  123. }
  124. vga_back.bar( x, y, x+340, y+1, V_BLACK );
  125. y+=4;
  126. //-------- display thte total score --------//
  127. font_san.put( x , y+2, "Total Score" );
  128. font_san.put( x+300, y+2, totalScore, 1 );
  129. y+=20;
  130. vga_back.bar( x, y, x+340, y+1, V_BLACK );
  131. y+=4;
  132. //-------- display the final score ---------//
  133. int difficultyRating = config.difficulty_rating;
  134. int finalScore = totalScore * difficultyRating / 100;
  135. String str;
  136. str = translate.process("Final Score");
  137. str += ": ";
  138. str += totalScore;
  139. str += " X ";
  140. int x2 = font_san.put( x, y+12, str ) + 5;
  141. str = difficultyRating;
  142. str += " ";
  143. str += translate.process( "(Difficulty Rating)" );
  144. font_san.center_put( x2, y+1, x2+156, y+15, str );
  145. vga_back.bar( x2 , y+16, x2+156, y+17, V_BLACK );
  146. font_san.put( x2+65, y+19, 100 );
  147. //------- if the player has cheated -------//
  148. if( nation_array[viewNationRecno]->cheat_enabled_flag )
  149. {
  150. str = "X 0 ";
  151. str += translate.process( "(Cheated)" );
  152. str += " ";
  153. finalScore = 0;
  154. }
  155. else
  156. str = "";
  157. str += "= ";
  158. str += finalScore;
  159. font_san.put( x2+170, y+12, str);
  160. y+=36;
  161. }
  162. //----------- End of static function disp_score -----------//
  163. //--------- Begin of static function disp_goal ---------//
  164. //
  165. static void disp_goal()
  166. {
  167. //----- if the ending screen has already appeared once -----//
  168. if( game.game_has_ended )
  169. return;
  170. //------------------------------------//
  171. int x=NATION_GOAL_X1+6, y=NATION_GOAL_Y1+6;
  172. int goalCount = 1 + config.goal_destroy_monster +
  173. config.goal_population_flag +
  174. config.goal_economic_score_flag +
  175. config.goal_total_score_flag;
  176. vga.d3_panel_down( NATION_GOAL_X1, NATION_GOAL_Y1, NATION_GOAL_X2, NATION_GOAL_Y2 );
  177. //------------------------------------//
  178. String str;
  179. if( goalCount > 1 )
  180. str = "GOAL: Achieve One of the Following";
  181. else
  182. str = "GOAL: Defeat All Other Kingdoms";
  183. if( config.goal_year_limit_flag )
  184. str += " Before ";
  185. str = translate.process(str);
  186. if( config.goal_year_limit_flag )
  187. str += date.date_str( info.goal_deadline );
  188. //--------------------------------------//
  189. str += ".";
  190. font_san.put( x, y, str );
  191. y+=18;
  192. if( goalCount==1 )
  193. return;
  194. //-----------------------------------//
  195. str = "Defeat All Other Kingdoms.";
  196. font_san.put( x, y, str );
  197. y+=16;
  198. //-----------------------------------//
  199. if( config.goal_destroy_monster )
  200. {
  201. str = "Destroy All Fryhtans.";
  202. font_san.put( x, y, str );
  203. y+=16;
  204. }
  205. //-----------------------------------//
  206. if( config.goal_population_flag )
  207. {
  208. #if(defined(SPANISH))
  209. str = "Alcanzar una población de ";
  210. str += config.goal_population;
  211. str += ".";
  212. #elif(defined(FRENCH))
  213. str = "Atteindre une population de ";
  214. str += config.goal_population;
  215. str += ".";
  216. #elif(defined(GERMAN))
  217. str = "Bevölkerungszahl von ";
  218. str += config.goal_population;
  219. str += " erreichen.";
  220. #else
  221. str = "Achieve a Population of ";
  222. str += config.goal_population;
  223. str += ".";
  224. #endif
  225. font_san.put( x, y, str );
  226. y+=16;
  227. }
  228. //-----------------------------------//
  229. if( config.goal_economic_score_flag )
  230. {
  231. #if(defined(SPANISH))
  232. str = "Alcanzar unos Puntos por Economía de ";
  233. str += config.goal_economic_score;
  234. str += ".";
  235. #elif(defined(FRENCH))
  236. str = "Atteindre un score économique de ";
  237. str += config.goal_economic_score;
  238. str += ".";
  239. #elif(defined(GERMAN))
  240. str = "Ökonom.-Punkte von ";
  241. str += config.goal_economic_score;
  242. str += " erreichen.";
  243. #else
  244. str = "Achieve an Economic Score of ";
  245. str += config.goal_economic_score;
  246. str += ".";
  247. #endif
  248. font_san.put( x, y, str );
  249. y+=16;
  250. }
  251. //-----------------------------------//
  252. if( config.goal_total_score_flag )
  253. {
  254. #if(defined(SPANISH))
  255. str = "Alcanzar unos Puntos Totales de ";
  256. str += config.goal_total_score;
  257. str += ".";
  258. #elif(defined(FRENCH))
  259. str = "Atteindre un score global de ";
  260. str += config.goal_total_score;
  261. str += ".";
  262. #elif(defined(GERMAN))
  263. str = "Gesamtpunkte von ";
  264. str += config.goal_total_score;
  265. str += " erreichen.";
  266. #else
  267. str = "Achieve a Total Score of ";
  268. str += config.goal_total_score;
  269. str += ".";
  270. #endif
  271. font_san.put( x, y, str );
  272. y+=16;
  273. }
  274. }
  275. //----------- End of static function disp_goal -----------//
  276. //--------- Begin of static function disp_play_time ---------//
  277. //
  278. static void disp_play_time(int y1)
  279. {
  280. vga.d3_panel_down( PLAY_TIME_X1, y1, PLAY_TIME_X2, y1+24 );
  281. String str;
  282. str = "Total Playing Time";
  283. str = translate.process(str);
  284. str += ": ";
  285. str += info.play_time_str();
  286. font_san.put( PLAY_TIME_X1+6, y1+6, str );
  287. }
  288. //----------- End of static function disp_play_time -----------//
  289. //--------- Begin of function Info::detect_rank ---------//
  290. //
  291. void Info::detect_rank()
  292. {
  293. //------- detect nation browser ------//
  294. if( browse_nation.detect() )
  295. {
  296. browse_nation_recno = browse_nation.recno();
  297. return;
  298. }
  299. }
  300. //----------- End of function Info::detect_rank -----------//
  301. //-------- Begin of static function nation_filter --------//
  302. //
  303. // This function has dual purpose :
  304. //
  305. // 1. when <int> recNo is not given :
  306. // - return the total no. of nations of this nation
  307. //
  308. // 2. when <int> recNo is given :
  309. // - return the nation recno in nation_array of the given recno.
  310. //
  311. static int nation_filter(int recNo)
  312. {
  313. int i, nationCount=0;
  314. Nation* viewingNation = NULL;
  315. if( nation_array.player_recno )
  316. viewingNation = nation_array[info.viewing_nation_recno];
  317. for( i=1 ; i<=nation_array.size() ; i++ )
  318. {
  319. if( nation_array.is_deleted(i) )
  320. continue;
  321. if( i==info.viewing_nation_recno ||
  322. !viewingNation ||
  323. viewingNation->get_relation(i)->has_contact )
  324. {
  325. nationCount++;
  326. }
  327. if( recNo && nationCount==recNo )
  328. return i;
  329. }
  330. err_when( recNo ); // the recNo is not found, it is out of range
  331. return nationCount;
  332. }
  333. //----------- End of static function nation_filter -----------//
  334. //-------- Begin of static function put_nation_rec --------//
  335. //
  336. static void put_nation_rec(int recNo, int x, int y, int refreshFlag)
  337. {
  338. int nationRecno = nation_filter(recNo);
  339. Nation* nationPtr = nation_array[nationRecno];
  340. x+=3;
  341. y+=5;
  342. nationPtr->disp_nation_color(x, y+4);
  343. font_san.put( x+20, y, nationPtr->nation_name() );
  344. font_san.put( x+210, y, info.get_rank_pos_str(1, nationRecno) );
  345. font_san.put( x+270, y, info.get_rank_pos_str(2, nationRecno) );
  346. font_san.put( x+352, y, info.get_rank_pos_str(3, nationRecno) );
  347. font_san.put( x+435, y, info.get_rank_pos_str(4, nationRecno) );
  348. font_san.put( x+500, y, info.get_rank_pos_str(5, nationRecno) );
  349. }
  350. //----------- End of static function put_nation_rec -----------//
  351. //-------- Begin of function Info::set_rank_data --------//
  352. //
  353. // <int> onlyHasContact - if this is 1, then only nations
  354. // that have contact with the viewing
  355. // nation is counted. Otherwise all nations
  356. // are counted.
  357. //
  358. void Info::set_rank_data(int onlyHasContact)
  359. {
  360. Nation* viewingNation = NULL;
  361. Nation* nationPtr;
  362. int rankPos=0;
  363. if( nation_array.player_recno && !nation_array.is_deleted(info.viewing_nation_recno) )
  364. viewingNation = nation_array[info.viewing_nation_recno];
  365. memset( nation_rank_data_array, 0, sizeof(nation_rank_data_array) );
  366. for( int i=1 ; i<=nation_array.size() ; i++ )
  367. {
  368. if( nation_array.is_deleted(i) )
  369. continue;
  370. if( onlyHasContact )
  371. {
  372. if( viewingNation && !viewingNation->get_relation(i)->has_contact )
  373. continue;
  374. }
  375. nationPtr = nation_array[i];
  376. nation_rank_data_array[0][i-1] = nationPtr->population_rating;
  377. nation_rank_data_array[1][i-1] = nationPtr->military_rating;
  378. nation_rank_data_array[2][i-1] = nationPtr->economic_rating;
  379. nation_rank_data_array[3][i-1] = (int) nationPtr->reputation;
  380. nation_rank_data_array[4][i-1] = (int) nationPtr->kill_monster_score;
  381. }
  382. }
  383. //----------- End of static function Info::set_rank_data -----------//
  384. //-------- Begin of function Info::get_rank_pos_str --------//
  385. //
  386. char* Info::get_rank_pos_str(int rankType, int nationRecno)
  387. {
  388. Nation* viewingNation = NULL;
  389. int curNationRankData = nation_rank_data_array[rankType-1][nationRecno-1];
  390. int rankPos=1;
  391. if( nation_array.player_recno && !nation_array.is_deleted(info.viewing_nation_recno) )
  392. viewingNation = nation_array[info.viewing_nation_recno];
  393. for( int i=1 ; i<=nation_array.size() ; i++ )
  394. {
  395. if( nation_array.is_deleted(i) || i == nationRecno )
  396. continue;
  397. if( viewingNation && !viewingNation->get_relation(i)->has_contact )
  398. continue;
  399. if( nation_rank_data_array[rankType-1][i-1] > curNationRankData ) // if another nation's value is higher than the given nation's value
  400. rankPos++;
  401. }
  402. return m.num_th(rankPos);
  403. }
  404. //----------- End of function Info::get_rank_pos_str -----------//
  405. //-------- Begin of function Info::get_rank_score --------//
  406. //
  407. // Get the score of the given nation in the given ranking type.
  408. //
  409. int Info::get_rank_score(int rankType, int nationRecno)
  410. {
  411. int maxValue;
  412. switch( rankType )
  413. {
  414. case 1: // population
  415. maxValue = 100;
  416. break;
  417. case 2: // military strength
  418. maxValue = 200;
  419. break;
  420. case 3: // economic strength
  421. maxValue = 6000;
  422. break;
  423. case 4: // reputation
  424. maxValue = 100; // so the maximum score of the reputation portion is 50 only
  425. break;
  426. case 5: // monsters slain score
  427. maxValue = 1000;
  428. break;
  429. }
  430. int rankScore = 100 * nation_rank_data_array[rankType-1][nationRecno-1] / maxValue;
  431. return max(0, rankScore);
  432. }
  433. //----------- End of function Info::get_rank_score -----------//
  434. //-------- Begin of function Info::get_total_score --------//
  435. //
  436. // Get the score of the given nation.
  437. //
  438. int Info::get_total_score(int nationRecno)
  439. {
  440. int totalScore=0;
  441. for( int i=0 ; i<MAX_RANK_TYPE ; i++ )
  442. {
  443. totalScore += get_rank_score(i+1, nationRecno);
  444. }
  445. return totalScore;
  446. }
  447. //----------- End of function Info::get_total_score -----------//