OGAMHALL.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 : OGAMHALL.CPP
  21. //Description : Hall of Fame
  22. #include <OVGA.h>
  23. #include <OVGALOCK.h>
  24. #include <ODATE.h>
  25. #include <OSTR.h>
  26. #include <OSYS.h>
  27. #include <OFONT.h>
  28. #include <OMOUSE.h>
  29. #include <OIMGRES.h>
  30. #include <ORACERES.h>
  31. #include <OGAME.h>
  32. #include <ONATION.h>
  33. #include <OGFILE.h>
  34. //------ Begin of function GameFileArray::disp_hall_of_fame -----//
  35. //
  36. // Display the Hall of Fame
  37. //
  38. void GameFileArray::disp_hall_of_fame()
  39. {
  40. vga.disp_image_file("HALLFAME");
  41. //---------- display hall of fame records ------------//
  42. int i;
  43. int x=120, y=116;
  44. for( i=0 ; i<HALL_FAME_NUM ; i++, y+=76 )
  45. {
  46. hall_fame_array[i].disp_info( x, y, i+1 );
  47. }
  48. mouse.wait_press(60); // 60 seconds to time out
  49. vga.finish_disp_image_file();
  50. }
  51. //------- End of function GameFileArray::disp_hall_of_fame -----//
  52. //------ Begin of function HallFame::disp_info -------//
  53. //
  54. // Display a Hall of Fame record
  55. //
  56. // <int> x, y = the location of the information
  57. // <int> pos = the position of the record.
  58. //
  59. void HallFame::disp_info(int x, int y, int pos)
  60. {
  61. if( !start_year ) // no information
  62. return;
  63. //------------------------------------------------------//
  64. //
  65. // e.g. 1. [Image] King Trevor Chan
  66. // [ ] Score : 150 Population : 1000 Period : 1001-1030
  67. //
  68. //------------------------------------------------------//
  69. Font* fontPtr;
  70. #if( defined(GERMAN) || defined(FRENCH) || defined(SPANISH) )
  71. fontPtr = &font_hall;
  72. #else
  73. fontPtr = &font_std;
  74. #endif
  75. String str;
  76. int y2 = y+17;
  77. //----------------------------------------//
  78. str = pos;
  79. str += ".";
  80. fontPtr->put( x, y, str );
  81. x += 16;
  82. //----------------------------------------//
  83. str = translate.process("King ");
  84. str += player_name;
  85. fontPtr->put( x, y, str );
  86. //----------------------------------------//
  87. str = translate.process("Score : ");
  88. str += score;
  89. fontPtr->put( x, y2, str );
  90. //----------------------------------------//
  91. str = translate.process("Population : ");
  92. str += population;
  93. fontPtr->put( x+110, y2, str );
  94. //----------------------------------------//
  95. #if( defined(GERMAN) || defined(FRENCH) || defined(SPANISH) )
  96. x-=10; // position adjustment for the German version
  97. #endif
  98. str = translate.process("Period : ");
  99. str += m.num_to_str(start_year); // without adding comma separators
  100. str += "-";
  101. str += m.num_to_str(end_year);
  102. fontPtr->put( x+260, y2, str );
  103. //----------------------------------------//
  104. str = translate.process("Difficulty : ");
  105. str += difficulty_rating;
  106. fontPtr->put( x+420, y2, str );
  107. }
  108. //------- End of function HallFame::disp_info -------//
  109. //------ Begin of function GameFileArray::add_hall_of_fame -----//
  110. //
  111. // Add current game into the hall of hame
  112. //
  113. // <int> totalScore of the player.
  114. //
  115. // return : <int> 1-hall of fame updated
  116. // 0-not updated
  117. //
  118. int GameFileArray::add_hall_of_fame(int totalScore)
  119. {
  120. //-------- insert the record -----------//
  121. int i;
  122. for( i=0 ; i<HALL_FAME_NUM ; i++ )
  123. {
  124. if( totalScore > hall_fame_array[i].score )
  125. {
  126. //---------- move and insert the data --------//
  127. if( i < HALL_FAME_NUM-1 ) // it is not the last record
  128. {
  129. memmove( hall_fame_array+i+1, hall_fame_array+i,
  130. sizeof(HallFame) * (HALL_FAME_NUM-i-1) );
  131. }
  132. //-------- record the hall of fame rcord ------//
  133. hall_fame_array[i].record_data(totalScore);
  134. //--------- display the hall of fame ----------//
  135. write_hall_of_fame(); // must write hall of fame, because it also write the last saved game slot no.
  136. disp_hall_of_fame();
  137. return 1;
  138. }
  139. }
  140. return 0;
  141. }
  142. //------- End of function GameFileArray::add_hall_of_fame -----//
  143. //--------- Begin of function HallFame::record_data --------//
  144. //
  145. // Record the hall of fame record_data
  146. //
  147. void HallFame::record_data(int totalScore)
  148. {
  149. Nation* playerNation = ~nation_array;
  150. strncpy( player_name, playerNation->king_name(), NationArray::HUMAN_NAME_LEN );
  151. player_name[NationArray::HUMAN_NAME_LEN] = NULL;
  152. race_id = playerNation->race_id;
  153. start_year = date.year(info.game_start_date);
  154. end_year = info.game_year;
  155. score = totalScore;
  156. population = playerNation->all_population();
  157. difficulty_rating = config.difficulty_rating;
  158. }
  159. //----------- End of function HallFame::record_data ---------//