OR_MIL.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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 : OINFOMIL.CPP
  21. //Description : Economy information screen
  22. #include <OVGA.h>
  23. #include <OFONT.h>
  24. #include <OSPY.h>
  25. #include <OIMGRES.h>
  26. #include <OUNITRES.h>
  27. #include <ORACERES.h>
  28. #include <OVBROWIF.h>
  29. #include <OBUTTON.h>
  30. #include <OF_CAMP.h>
  31. #include <ONATION.h>
  32. #include <OUNIT.h>
  33. #include <OINFO.h>
  34. //------------- Define coordinations -----------//
  35. enum { TROOP_BROWSE_X1 = ZOOM_X1+6,
  36. TROOP_BROWSE_Y1 = ZOOM_Y1+6,
  37. TROOP_BROWSE_X2 = ZOOM_X2-6,
  38. TROOP_BROWSE_Y2 = TROOP_BROWSE_Y1+240
  39. };
  40. enum { UNIT_BROWSE_X1 = ZOOM_X1+6,
  41. UNIT_BROWSE_Y1 = TROOP_BROWSE_Y2+6,
  42. UNIT_BROWSE_X2 = ZOOM_X2-6,
  43. UNIT_BROWSE_Y2 = ZOOM_Y2-6,
  44. };
  45. //----------- Define static variables ----------//
  46. static VBrowseIF browse_troop;
  47. static VBrowseIF browse_unit;
  48. //----------- Define static functions ----------//
  49. static void put_troop_rec(int recNo, int x, int y, int refreshFlag);
  50. static void put_unit_rec(int recNo, int x, int y, int refreshFlag);
  51. static int troop_filter(int recNo=0);
  52. static int unit_filter(int recNo=0);
  53. static void disp_troop_total();
  54. static void disp_unit_total();
  55. //--------- Begin of function Info::disp_military ---------//
  56. //
  57. void Info::disp_military(int refreshFlag)
  58. {
  59. //------- Display the Troop report -------//
  60. int x=TROOP_BROWSE_X1+9;
  61. int y=TROOP_BROWSE_Y1+4;
  62. vga_back.d3_panel_up(TROOP_BROWSE_X1, TROOP_BROWSE_Y1, TROOP_BROWSE_X2, TROOP_BROWSE_Y1+33 );
  63. #if(defined(FRENCH))
  64. font_san.put( x , y+7 , "Commander" );
  65. font_san.put( x+170, y+7, "Leadership" );
  66. font_san.put( x+275, y+7, "Loyalty" );
  67. font_san.put( x+350, y, "Points" );
  68. font_san.put( x+350, y+13, "de vie" );
  69. font_san.put( x+410, y+7, "Garnison" );
  70. font_san.put( x+480, y+7, "Status" );
  71. #elif(defined(GERMAN))
  72. font_san.put( x , y+7 , "Commander" );
  73. font_san.put( x+210, y+7 , "Leadership" );
  74. font_san.put( x+275, y+7 , "Loyalty" );
  75. font_san.put( x+342, y+7 , "Hit Points" );
  76. font_san.put( x+406, y , "Commanded" );
  77. font_san.put( x+415, y+13, "Soldiers" );
  78. font_san.put( x+485, y+7 , "Status" );
  79. #else
  80. font_san.put( x , y+7 , "Commander" );
  81. font_san.put( x+200, y+7 , "Leadership" );
  82. font_san.put( x+285, y+7 , "Loyalty" );
  83. font_san.put( x+342, y+7 , "Hit Points" );
  84. font_san.put( x+406, y , "Commanded" );
  85. font_san.put( x+423, y+13, "Soldiers" );
  86. font_san.put( x+490, y+7 , "Status" );
  87. #endif
  88. if( refreshFlag == INFO_REPAINT )
  89. {
  90. browse_troop.init( TROOP_BROWSE_X1, TROOP_BROWSE_Y1+35, TROOP_BROWSE_X2, TROOP_BROWSE_Y2-20,
  91. 0, 22, troop_filter(), put_troop_rec, 1 );
  92. browse_troop.open(browse_troop_recno);
  93. }
  94. else
  95. {
  96. browse_troop.paint();
  97. browse_troop.open(browse_troop_recno, troop_filter());
  98. }
  99. disp_troop_total();
  100. //------- Display the unit report -------//
  101. x=UNIT_BROWSE_X1+9;
  102. y=UNIT_BROWSE_Y1+4;
  103. vga_back.d3_panel_up(UNIT_BROWSE_X1, UNIT_BROWSE_Y1, UNIT_BROWSE_X2, UNIT_BROWSE_Y1+20 );
  104. font_san.put( x , y, "Unit Type" );
  105. font_san.put( x+300, y, "No. of Units" );
  106. if( refreshFlag == INFO_REPAINT )
  107. {
  108. browse_unit.init( UNIT_BROWSE_X1, UNIT_BROWSE_Y1+22, UNIT_BROWSE_X2, UNIT_BROWSE_Y2-20,
  109. 0, 16, unit_filter(), put_unit_rec, 1 );
  110. browse_unit.open(browse_unit_recno);
  111. }
  112. else
  113. {
  114. browse_unit.paint();
  115. browse_unit.open(browse_unit_recno, unit_filter());
  116. }
  117. disp_unit_total();
  118. }
  119. //----------- End of function Info::disp_military -----------//
  120. //--------- Begin of function Info::detect_military ---------//
  121. //
  122. void Info::detect_military()
  123. {
  124. //------- detect the troop report -------//
  125. if( browse_troop.detect() )
  126. {
  127. browse_troop_recno = browse_troop.recno();
  128. if( browse_troop.double_click )
  129. {
  130. Unit* unitPtr = unit_array[ troop_filter(browse_troop_recno) ];
  131. short xLoc, yLoc;
  132. if( unitPtr->get_cur_loc(xLoc, yLoc) )
  133. {
  134. world.go_loc(xLoc, yLoc, 1);
  135. }
  136. }
  137. }
  138. //------- detect the unit report -------//
  139. if( browse_unit.detect() )
  140. {
  141. browse_unit_recno = browse_unit.recno();
  142. }
  143. }
  144. //----------- End of function Info::detect_military -----------//
  145. //-------- Begin of static function disp_troop_total --------//
  146. static void disp_troop_total()
  147. {
  148. //---- count the total no. of soldiers ----//
  149. Unit* unitPtr;
  150. int totalSoldier=0, totalCommandedSoldier=0;
  151. int i;
  152. for( i=unit_array.size() ; i>0 ; i-- )
  153. {
  154. if( unit_array.is_deleted(i) )
  155. continue;
  156. unitPtr = unit_array[i];
  157. if( unitPtr->nation_recno != info.viewing_nation_recno )
  158. continue;
  159. if( unitPtr->rank_id == RANK_SOLDIER )
  160. totalSoldier++;
  161. else
  162. totalCommandedSoldier += unitPtr->commanded_soldier_count();
  163. }
  164. Nation* viewingNation = nation_array[info.viewing_nation_recno];
  165. for( i=viewingNation->ai_camp_count-1 ; i>=0 ; i-- )
  166. {
  167. totalSoldier += firm_array[ viewingNation->ai_camp_array[i] ]->worker_count;
  168. }
  169. //--------- paint the area ----------//
  170. int x=TROOP_BROWSE_X1+9;
  171. int y=TROOP_BROWSE_Y2-16;
  172. vga_back.d3_panel_up(TROOP_BROWSE_X1, TROOP_BROWSE_Y2-18, TROOP_BROWSE_X2, TROOP_BROWSE_Y2 );
  173. //------ display commander count ------//
  174. String str;
  175. if( browse_troop.total_rec() > 1 )
  176. str = "Total Commanders";
  177. else
  178. str = "Total Commander";
  179. str = translate.process(str);
  180. str += ": ";
  181. str += browse_troop.total_rec();
  182. font_san.put( x, y, str );
  183. //------ display soldiers under command count ------//
  184. if( totalCommandedSoldier > 1 )
  185. str = "Total Soldiers Under Command";
  186. else
  187. str = "Total Soldier Under Command";
  188. str = translate.process(str);
  189. str += ": ";
  190. str += totalCommandedSoldier;
  191. font_san.put( x+160, y, str );
  192. //------ display soldiers count ------//
  193. if( totalSoldier > 1 )
  194. str = "Total Soldiers";
  195. else
  196. str = "Total Soldier";
  197. str = translate.process(str);
  198. str += ": ";
  199. str += totalSoldier;
  200. #if(defined(FRENCH))
  201. font_san.put( x+396, y, str );
  202. #else
  203. font_san.put( x+410, y, str );
  204. #endif
  205. }
  206. //----------- End of static function disp_troop_total -----------//
  207. //-------- Begin of static function disp_unit_total --------//
  208. static void disp_unit_total()
  209. {
  210. int totalUnitCount=0, totalUnitCost=0;
  211. UnitInfo* unitInfo;
  212. for( int unitId=1 ; unitId<=MAX_UNIT_TYPE ; unitId++ )
  213. {
  214. unitInfo = unit_res[unitId];
  215. int unitCount = unitInfo->nation_unit_count_array[info.viewing_nation_recno-1];
  216. int generalCount = unitInfo->nation_general_count_array[info.viewing_nation_recno-1];
  217. totalUnitCount += unitCount;
  218. if( unitInfo->race_id )
  219. {
  220. totalUnitCost += generalCount * GENERAL_YEAR_SALARY;
  221. totalUnitCost += (unitCount-generalCount) * SOLDIER_YEAR_SALARY;
  222. }
  223. else
  224. totalUnitCost += unitCount * unitInfo->year_cost;
  225. }
  226. //--------- paint the area ----------//
  227. int x=UNIT_BROWSE_X1+9;
  228. int y=UNIT_BROWSE_Y2-16;
  229. vga_back.d3_panel_up(UNIT_BROWSE_X1, UNIT_BROWSE_Y2-18, UNIT_BROWSE_X2, UNIT_BROWSE_Y2 );
  230. String str;
  231. str = "Total Units";
  232. str = translate.process(str);
  233. str += ": ";
  234. str += totalUnitCount;
  235. font_san.put( x, y, str );
  236. }
  237. //----------- End of static function disp_unit_total -----------//
  238. //-------- Begin of static function troop_filter --------//
  239. //
  240. // This function has dual purpose :
  241. //
  242. // 1. when <int> recNo is not given :
  243. // - return the total no. of firms of this nation
  244. //
  245. // 2. when <int> recNo is given :
  246. // - return the firm recno in firm_array of the given recno.
  247. //
  248. static int troop_filter(int recNo)
  249. {
  250. int i, unitCount=0, totalUnit=unit_array.size();
  251. Unit* unitPtr;
  252. for( i=1 ; i<=totalUnit ; i++ )
  253. {
  254. if( unit_array.is_deleted(i) )
  255. continue;
  256. unitPtr = unit_array[i];
  257. if( unitPtr->nation_recno == info.viewing_nation_recno &&
  258. (unitPtr->rank_id==RANK_GENERAL || unitPtr->rank_id==RANK_KING) )
  259. {
  260. unitCount++;
  261. }
  262. if( recNo && unitCount==recNo )
  263. return i;
  264. }
  265. err_when( recNo ); // the recNo is not found, it is out of range
  266. return unitCount;
  267. }
  268. //----------- End of static function troop_filter -----------//
  269. //-------- Begin of static function put_troop_rec --------//
  270. //
  271. static void put_troop_rec(int recNo, int x, int y, int refreshFlag)
  272. {
  273. int unitRecno = troop_filter(recNo);
  274. Unit* unitPtr = unit_array[unitRecno];
  275. //---------- display bitmap ----------//
  276. x+=3;
  277. y+=3;
  278. vga_back.put_bitmap( x, y-2, unit_res[unitPtr->unit_id]->get_small_icon_ptr(unitPtr->rank_id) );
  279. //-------- display name & team size -------//
  280. y+=2;
  281. font_san.put( x+28 , y, unitPtr->unit_name(), 0, 238 );
  282. font_san.put( x+240, y, unitPtr->skill.get_skill(SKILL_LEADING) );
  283. if( unitPtr->rank_id != RANK_KING )
  284. font_san.put( x+295, y, unitPtr->loyalty );
  285. //--------- display hit points -----------//
  286. String str;
  287. str = (int) unitPtr->hit_points;
  288. str += "/";
  289. str += unitPtr->max_hit_points;
  290. font_san.put( x+352, y, str );
  291. //---- display the no. of soldiers led by this general ---//
  292. font_san.put( x+445, y, unitPtr->commanded_soldier_count() );
  293. //---- display the status of the general ----//
  294. char* statusStr;
  295. if( unitPtr->unit_mode == UNIT_MODE_OVERSEE )
  296. {
  297. int firmId = firm_array[ unitPtr->unit_mode_para ]->firm_id;
  298. if( firmId == FIRM_CAMP )
  299. statusStr = "In Fort";
  300. else if( firmId == FIRM_BASE )
  301. statusStr = "In Seat";
  302. else
  303. err_here();
  304. }
  305. else if( unitPtr->unit_mode == UNIT_MODE_ON_SHIP )
  306. {
  307. statusStr = "On Ship";
  308. }
  309. else
  310. {
  311. statusStr = "Mobile";
  312. }
  313. #if(defined(FRENCH))
  314. font_san.put( x+470, y, statusStr );
  315. #else
  316. // German and US
  317. font_san.put( x+486, y, statusStr );
  318. #endif
  319. }
  320. //----------- End of static function put_troop_rec -----------//
  321. //-------- Begin of static function unit_filter --------//
  322. //
  323. // This function has dual purpose :
  324. //
  325. // 1. when <int> recNo is not given :
  326. // - return the total no. of firms of this nation
  327. //
  328. // 2. when <int> recNo is given :
  329. // - return the firm recno in firm_array of the given recno.
  330. //
  331. static int unit_filter(int recNo)
  332. {
  333. int unitTypeCount=0;
  334. UnitInfo* unitInfo;
  335. //------- count human units -------//
  336. Nation* nationPtr = nation_array[info.viewing_nation_recno];
  337. unitTypeCount++;
  338. if( recNo && unitTypeCount==recNo )
  339. return -1;
  340. //------- count non-human unit types -------//
  341. for( int unitId=1 ; unitId<=MAX_UNIT_TYPE ; unitId++ )
  342. {
  343. unitInfo = unit_res[unitId];
  344. //---- if this is not a human unit -----//
  345. if( !unitInfo->race_id &&
  346. unitInfo->nation_unit_count_array[info.viewing_nation_recno-1] > 0 )
  347. {
  348. unitTypeCount++;
  349. }
  350. if( recNo && unitTypeCount==recNo )
  351. return unitId;
  352. }
  353. err_when( recNo ); // the recNo is not found, it is out of range
  354. return unitTypeCount;
  355. }
  356. //----------- End of static function unit_filter -----------//
  357. //-------- Begin of static function put_unit_rec --------//
  358. //
  359. static void put_unit_rec(int recNo, int x, int y, int refreshFlag)
  360. {
  361. int unitId = unit_filter(recNo);
  362. int unitCount;
  363. char* str;
  364. UnitInfo* unitInfo;
  365. Nation* nationPtr = nation_array[info.viewing_nation_recno];
  366. int rc = unit_filter(recNo);
  367. switch( rc )
  368. {
  369. //------- count human units -------//
  370. case -1:
  371. str = "Human General";
  372. unitCount = nationPtr->total_general_count;
  373. break;
  374. default:
  375. unitInfo = unit_res[rc];
  376. str = unitInfo->name;
  377. unitCount = unitInfo->nation_unit_count_array[ info.viewing_nation_recno-1 ];
  378. }
  379. //---------- display info --------//
  380. x+=3;
  381. y+=3;
  382. font_san.put( x , y, str );
  383. font_san.put( x+320, y, m.format(unitCount,1) );
  384. }
  385. //----------- End of static function put_unit_rec -----------//