OR_SPY.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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_SPY.CPP
  21. //Description : Spy Report
  22. #include <OVGA.h>
  23. #include <OFONT.h>
  24. #include <OFIRMRES.h>
  25. #include <ONATION.h>
  26. #include <ORACERES.h>
  27. #include <OIMGRES.h>
  28. #include <OVBROWIF.h>
  29. #include <OSPY.h>
  30. #include <OINFO.h>
  31. //------------- Define coordinations -----------//
  32. enum { SPY_BROWSE_X1 = ZOOM_X1+6,
  33. SPY_BROWSE_Y1 = ZOOM_Y1+6,
  34. SPY_BROWSE_X2 = ZOOM_X2-6,
  35. SPY_BROWSE_Y2 = ZOOM_Y2-6,
  36. };
  37. //----------- Define static variables ----------//
  38. static VBrowseIF browse_spy;
  39. //----------- Define static functions ----------//
  40. static void put_spy_rec(int recNo, int x, int y, int refreshFlag);
  41. static int spy_filter(int recNo=0);
  42. static void disp_total();
  43. //--------- Begin of function Info::disp_spy ---------//
  44. //
  45. void Info::disp_spy(int refreshFlag)
  46. {
  47. //------- Display the spy report -------//
  48. int x=SPY_BROWSE_X1+9;
  49. int y=SPY_BROWSE_Y1+4;
  50. vga_back.d3_panel_up(SPY_BROWSE_X1, SPY_BROWSE_Y1, SPY_BROWSE_X2, SPY_BROWSE_Y1+20 );
  51. #if(defined(FRENCH))
  52. font_san.put( x , y, "Spy Name" );
  53. font_san.put( x+155, y, "Cloak" );
  54. font_san.put( x+205, y, "Location" );
  55. font_san.put( x+320, y, "Skill" );
  56. font_san.put( x+384, y, "Loyalty" );
  57. font_san.put( x+448, y, "Action" );
  58. #else
  59. // German and US
  60. font_san.put( x , y, "Spy Name" );
  61. font_san.put( x+155, y, "Cloak" );
  62. font_san.put( x+205, y, "Location" );
  63. font_san.put( x+330, y, "Skill" );
  64. font_san.put( x+370, y, "Loyalty" );
  65. font_san.put( x+435, y, "Action" );
  66. #endif
  67. if( refreshFlag == INFO_REPAINT )
  68. {
  69. browse_spy.init( SPY_BROWSE_X1, SPY_BROWSE_Y1+22, SPY_BROWSE_X2, SPY_BROWSE_Y2-20,
  70. 0, 21, spy_filter(), put_spy_rec, 1 );
  71. browse_spy.open(browse_spy_recno);
  72. }
  73. else
  74. {
  75. browse_spy.paint();
  76. browse_spy.open(browse_spy_recno, spy_filter());
  77. }
  78. //--------- Display total ------------//
  79. disp_total();
  80. }
  81. //----------- End of function Info::disp_spy -----------//
  82. //--------- Begin of function Info::detect_spy ---------//
  83. //
  84. void Info::detect_spy()
  85. {
  86. //------- detect the spy browser -------//
  87. if( browse_spy.detect() )
  88. {
  89. browse_spy_recno = browse_spy.recno();
  90. if( browse_spy.double_click )
  91. {
  92. Spy* spyPtr = spy_array[ spy_filter(browse_spy_recno) ];
  93. int xLoc, yLoc;
  94. if( spyPtr->get_loc(xLoc, yLoc) )
  95. world.go_loc( xLoc, yLoc, 1 );
  96. }
  97. }
  98. }
  99. //----------- End of function Info::detect_spy -----------//
  100. //-------- Begin of static function disp_total --------//
  101. static void disp_total()
  102. {
  103. int x = SPY_BROWSE_X1+9;
  104. int y = SPY_BROWSE_Y2-16;
  105. vga_back.d3_panel_up(SPY_BROWSE_X1, SPY_BROWSE_Y2-18, SPY_BROWSE_X2, SPY_BROWSE_Y2 );
  106. String str;
  107. if( browse_spy.total_rec() > 1 )
  108. str = "Total Spies";
  109. else
  110. str = "Total Spy";
  111. str = translate.process(str);
  112. str += ": ";
  113. str += browse_spy.total_rec();
  114. font_san.put( x, y, str );
  115. }
  116. //----------- End of static function disp_total -----------//
  117. //-------- Begin of static function spy_filter --------//
  118. //
  119. // This function has dual purpose :
  120. //
  121. // 1. when <int> recNo is not given :
  122. // - return the total no. of firms of this nation
  123. //
  124. // 2. when <int> recNo is given :
  125. // - return the firm recno in firm_array of the given recno.
  126. //
  127. static int spy_filter(int recNo)
  128. {
  129. int totalSpy = spy_array.size();
  130. int spyCount=0;
  131. Spy* spyPtr;
  132. for( int spyRecno=1 ; spyRecno<=totalSpy ; spyRecno++ )
  133. {
  134. if( spy_array.is_deleted(spyRecno) )
  135. continue;
  136. spyPtr = spy_array[spyRecno];
  137. if( spyPtr->true_nation_recno==info.viewing_nation_recno )
  138. spyCount++;
  139. if( recNo && spyCount==recNo )
  140. return spyRecno;
  141. }
  142. err_when( recNo ); // the recNo is not found, it is out of range
  143. return spyCount;
  144. }
  145. //----------- End of static function spy_filter -----------//
  146. //-------- Begin of static function put_spy_rec --------//
  147. //
  148. static void put_spy_rec(int recNo, int x, int y, int refreshFlag)
  149. {
  150. int spyRecno = spy_filter(recNo);
  151. Spy* spyPtr = spy_array[spyRecno];
  152. x+=3;
  153. y+=5;
  154. //------ display rank/skill icon -------//
  155. int cloakedRankId = spyPtr->cloaked_rank_id();
  156. int cloakedSkillId = spyPtr->cloaked_skill_id();
  157. String str;
  158. switch( cloakedRankId )
  159. {
  160. case RANK_KING:
  161. str = "U_KING";
  162. break;
  163. case RANK_GENERAL:
  164. str = "U_GENE";
  165. break;
  166. case RANK_SOLDIER:
  167. if( cloakedSkillId )
  168. {
  169. str = "U_";
  170. str += Skill::skill_code_array[cloakedSkillId-1];
  171. }
  172. else
  173. {
  174. str = "";
  175. }
  176. break;
  177. }
  178. if( str.len() > 0 )
  179. image_icon.put_back(x, y+1, str);
  180. //------ display race icon -------------//
  181. vga_back.put_bitmap( x+13, y-4, race_res[spyPtr->race_id]->icon_bitmap_ptr );
  182. //----------- display name -----------//
  183. font_san.put( x+39, y, race_res[spyPtr->race_id]->get_name(spyPtr->name_id), 0, 185 );
  184. //------- display cloaked nation color ------//
  185. int tx = x+170;
  186. if( spyPtr->cloaked_nation_recno==0 ) // independent nation
  187. {
  188. vga_back.bar( tx, y, tx+12, y+12, V_WHITE );
  189. vga_back.rect( tx, y, tx+12, y+12, 1, VGA_GRAY+8 );
  190. }
  191. else
  192. {
  193. nation_array[spyPtr->cloaked_nation_recno]->disp_nation_color(tx, y+2);
  194. }
  195. //---------- display other info ----------//
  196. switch( spyPtr->spy_place )
  197. {
  198. case SPY_FIRM:
  199. str = firm_res[firm_array[spyPtr->spy_place_para]->firm_id]->name;
  200. break;
  201. case SPY_TOWN:
  202. str = town_array[spyPtr->spy_place_para]->town_name();
  203. break;
  204. case SPY_MOBILE:
  205. {
  206. Unit* unitPtr = unit_array[spyPtr->spy_place_para];
  207. switch( unitPtr->unit_mode )
  208. {
  209. case UNIT_MODE_CONSTRUCT:
  210. str = firm_res[firm_array[unitPtr->unit_mode_para]->firm_id]->name;
  211. break;
  212. case UNIT_MODE_ON_SHIP:
  213. str = "On Ship";
  214. break;
  215. default:
  216. str = "Mobile";
  217. }
  218. break;
  219. }
  220. default:
  221. str = "";
  222. }
  223. font_san.put( x+205, y, str );
  224. font_san.put( x+335, y, spyPtr->spy_skill );
  225. font_san.put( x+385, y, spyPtr->spy_loyalty );
  226. font_san.put( x+435, y, spyPtr->action_str() );
  227. }
  228. //----------- End of static function put_spy_rec -----------//