OR_TOWN.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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_TOWN.CPP
  21. //Description : Town Report
  22. #include <OVGA.h>
  23. #include <OFONT.h>
  24. #include <OIMGRES.h>
  25. #include <OVBROWIF.h>
  26. #include <OBUTTON.h>
  27. #include <ORACERES.h>
  28. #include <OFIRM.h>
  29. #include <OFIRM.h>
  30. #include <OWORLD.h>
  31. #include <ONATION.h>
  32. #include <OUNIT.h>
  33. #include <OINFO.h>
  34. //------------- Define coordinations -----------//
  35. enum { TOWN_BROWSE_X1 = ZOOM_X1+6,
  36. TOWN_BROWSE_Y1 = ZOOM_Y1+6,
  37. TOWN_BROWSE_X2 = ZOOM_X2-6,
  38. TOWN_BROWSE_Y2 = TOWN_BROWSE_Y1+280
  39. };
  40. enum { POP_TOTAL_X1 = ZOOM_X1+6,
  41. POP_TOTAL_Y1 = TOWN_BROWSE_Y2+2,
  42. POP_TOTAL_X2 = ZOOM_X2-6,
  43. POP_TOTAL_Y2 = POP_TOTAL_Y1+18,
  44. };
  45. enum { FIRM_BROWSE_X1 = ZOOM_X1+6,
  46. FIRM_BROWSE_Y1 = POP_TOTAL_Y2+6,
  47. FIRM_BROWSE_X2 = ZOOM_X2-6,
  48. FIRM_BROWSE_Y2 = ZOOM_Y2-6,
  49. };
  50. //----------- Define static variables ----------//
  51. static VBrowseIF browse_town, browse_firm;
  52. static int total_population, total_peasant;
  53. static int firm_income_array[MAX_FIRM_TYPE];
  54. static int total_firm_cost, total_firm_income, total_firm_count;
  55. static float total_expense;
  56. //----------- Define static functions ----------//
  57. static void put_town_rec(int recNo, int x, int y, int refreshFlag);
  58. static void put_firm_rec(int recNo, int x, int y, int refreshFlag);
  59. static int town_filter(int recNo=0);
  60. static int firm_filter(int recNo=0);
  61. static void disp_total();
  62. static void calc_firm_total();
  63. //--------- Begin of function Info::disp_town ---------//
  64. //
  65. void Info::disp_town(int refreshFlag)
  66. {
  67. int x=TOWN_BROWSE_X1+9;
  68. int y=TOWN_BROWSE_Y1+4;
  69. vga_back.d3_panel_up(TOWN_BROWSE_X1, TOWN_BROWSE_Y1, TOWN_BROWSE_X2, TOWN_BROWSE_Y1+20 );
  70. font_san.put( x , y, "Village" );
  71. font_san.put( x+150, y, "Villagers" );
  72. font_san.put( x+225, y, "Peasants" );
  73. font_san.put( x+295, y, "Loyalty" );
  74. font_san.put( x+355, y, "Races" );
  75. if( refreshFlag == INFO_REPAINT )
  76. {
  77. browse_town.init( TOWN_BROWSE_X1, TOWN_BROWSE_Y1+22, TOWN_BROWSE_X2, TOWN_BROWSE_Y2-20,
  78. 0, 21, town_filter(), put_town_rec, 1 );
  79. browse_town.open(browse_town_recno);
  80. }
  81. else
  82. {
  83. browse_town.paint();
  84. browse_town.open(browse_town_recno, town_filter());
  85. }
  86. //------- Display the firm report -------//
  87. calc_firm_total();
  88. x=FIRM_BROWSE_X1+9;
  89. y=FIRM_BROWSE_Y1+4;
  90. vga_back.d3_panel_up(FIRM_BROWSE_X1, FIRM_BROWSE_Y1, FIRM_BROWSE_X2, FIRM_BROWSE_Y1+20 );
  91. font_san.put( x , y, "Structure" );
  92. font_san.put( x+140, y, "Unit Cost" );
  93. #if(defined(FRENCH))
  94. font_san.put( x+237, y, "No. of Structures" );
  95. #else
  96. font_san.put( x+217, y, "No. of Structures" );
  97. #endif
  98. font_san.put( x+340, y, "Yearly Expense" );
  99. font_san.put( x+450, y, "Yearly Income" );
  100. if( refreshFlag == INFO_REPAINT )
  101. {
  102. browse_firm.init( FIRM_BROWSE_X1, FIRM_BROWSE_Y1+22, FIRM_BROWSE_X2, FIRM_BROWSE_Y2-20,
  103. 0, 16, firm_filter(), put_firm_rec, 1 );
  104. browse_firm.open(browse_firm_recno);
  105. }
  106. else
  107. {
  108. browse_firm.paint();
  109. browse_firm.open(browse_firm_recno, firm_filter());
  110. }
  111. //--------- Display total ------------//
  112. disp_total();
  113. }
  114. //----------- End of function Info::disp_town -----------//
  115. //--------- Begin of function Info::detect_town ---------//
  116. //
  117. void Info::detect_town()
  118. {
  119. //------- detect the town browser -------//
  120. if( browse_town.detect() )
  121. {
  122. browse_town_recno = browse_town.recno();
  123. if( browse_town.double_click )
  124. {
  125. Town* townPtr = town_array[ town_filter(browse_town_recno) ];
  126. world.go_loc(townPtr->center_x, townPtr->center_y, 1);
  127. }
  128. }
  129. //------- detect the firm browser -------//
  130. if( browse_firm.detect() )
  131. browse_firm_recno = browse_firm.recno();
  132. }
  133. //----------- End of function Info::detect_town -----------//
  134. //-------- Begin of static function disp_total --------//
  135. static void disp_total()
  136. {
  137. //------- calculate total --------//
  138. total_population = 0;
  139. total_peasant = 0;
  140. Town* townPtr;
  141. for( int i=town_array.size() ; i>0 ; i-- )
  142. {
  143. if( town_array.is_deleted(i) )
  144. continue;
  145. townPtr = town_array[i];
  146. if( townPtr->nation_recno==info.viewing_nation_recno )
  147. {
  148. total_population += townPtr->population;
  149. total_peasant += townPtr->jobless_population;
  150. }
  151. }
  152. //-------- display town total --------//
  153. int x=TOWN_BROWSE_X1+9;
  154. int y=TOWN_BROWSE_Y2-16;
  155. vga_back.d3_panel_up(TOWN_BROWSE_X1, TOWN_BROWSE_Y2-18, TOWN_BROWSE_X2, TOWN_BROWSE_Y2 );
  156. String str;
  157. if( browse_town.total_rec() > 1 )
  158. str = "Total Villages";
  159. else
  160. str = "Total Village";
  161. str = translate.process(str);
  162. str += ": ";
  163. str += browse_town.total_rec();
  164. font_san.put( x, y, str );
  165. //-------------------------------//
  166. str = "Total Villagers";
  167. str = translate.process(str);
  168. str += ": ";
  169. str += total_population;
  170. font_san.put( x+180, y, str );
  171. //-------------------------------//
  172. if( total_peasant > 1 )
  173. str = "Total Peasants";
  174. else
  175. str = "Total Peasant";
  176. str = translate.process(str);
  177. str += ": ";
  178. str += total_peasant;
  179. font_san.put( x+360, y, str );
  180. //------- display other totals --------//
  181. Nation* viewNation = nation_array[info.viewing_nation_recno];
  182. x=POP_TOTAL_X1+9;
  183. y=POP_TOTAL_Y1+2;
  184. vga_back.d3_panel_up(POP_TOTAL_X1, POP_TOTAL_Y1, POP_TOTAL_X2, POP_TOTAL_Y2 );
  185. str = "Total Other Human Units";
  186. str = translate.process(str);
  187. str += ": ";
  188. str += viewNation->total_human_count;
  189. font_san.put( x, y, str );
  190. str = "Total Population";
  191. str = translate.process(str);
  192. str += ": ";
  193. str += viewNation->total_population + viewNation->total_human_count;
  194. font_san.put( x+360, y, str );
  195. //-------- display firm total ---------//
  196. x=FIRM_BROWSE_X1+9;
  197. y=FIRM_BROWSE_Y2-16;
  198. vga_back.d3_panel_up(FIRM_BROWSE_X1, FIRM_BROWSE_Y2-18, FIRM_BROWSE_X2, FIRM_BROWSE_Y2 );
  199. font_san.put( x , y, "Total" );
  200. font_san.put( x+265, y, total_firm_count );
  201. font_san.put( x+370, y, m.format(total_firm_cost,2) );
  202. font_san.put( x+470, y, m.format(total_firm_income,2) );
  203. }
  204. //----------- End of static function disp_total -----------//
  205. //-------- Begin of static function calc_firm_total --------//
  206. static void calc_firm_total()
  207. {
  208. //-------- calculate firm incomes --------//
  209. total_firm_income = 0;
  210. memset( firm_income_array, 0, sizeof(firm_income_array) );
  211. int thisIncome;
  212. Firm* firmPtr;
  213. int i;
  214. for( i=firm_array.size() ; i>0 ; i-- )
  215. {
  216. if( firm_array.is_deleted(i) )
  217. continue;
  218. firmPtr = firm_array[i];
  219. if( firmPtr->nation_recno == info.viewing_nation_recno )
  220. {
  221. thisIncome = (int) firmPtr->income_365days();
  222. if( thisIncome > 0 )
  223. {
  224. firm_income_array[firmPtr->firm_id-1] += thisIncome;
  225. total_firm_income += thisIncome;
  226. }
  227. }
  228. }
  229. //------ calculate total firm cost --------//
  230. total_firm_count = 0;
  231. total_firm_cost = 0;
  232. FirmInfo* firmInfo;
  233. for( i=1 ; i<=MAX_FIRM_TYPE ; i++ )
  234. {
  235. firmInfo = firm_res[i];
  236. total_firm_cost += firmInfo->year_cost *
  237. firmInfo->nation_firm_count_array[info.viewing_nation_recno-1];
  238. total_firm_count += firmInfo->nation_firm_count_array[info.viewing_nation_recno-1];
  239. }
  240. }
  241. //----------- End of static function calc_firm_total -----------//
  242. //-------- Begin of static function town_filter --------//
  243. //
  244. // This function has dual purpose :
  245. //
  246. // 1. when <int> recNo is not given :
  247. // - return the total no. of firms of this nation
  248. //
  249. // 2. when <int> recNo is given :
  250. // - return the firm recno in firm_array of the given recno.
  251. //
  252. static int town_filter(int recNo)
  253. {
  254. int totalTown = town_array.size();
  255. int townCount=0;
  256. Town* townPtr;
  257. for( int townRecno=1 ; townRecno<=totalTown ; townRecno++ )
  258. {
  259. if( town_array.is_deleted(townRecno) )
  260. continue;
  261. townPtr = town_array[townRecno];
  262. if( townPtr->nation_recno==info.viewing_nation_recno )
  263. townCount++;
  264. if( recNo && townCount==recNo )
  265. return townRecno;
  266. }
  267. err_when( recNo ); // the recNo is not found, it is out of range
  268. return townCount;
  269. }
  270. //----------- End of static function town_filter -----------//
  271. //-------- Begin of static function put_town_rec --------//
  272. //
  273. static void put_town_rec(int recNo, int x, int y, int refreshFlag)
  274. {
  275. int townRecno = town_filter(recNo);
  276. Town* townPtr = town_array[townRecno];
  277. //---------- display info ----------//
  278. x+=3;
  279. y+=3;
  280. font_san.put( x , y, townPtr->town_name() );
  281. font_san.put( x+175, y, townPtr->population );
  282. font_san.put( x+241, y, townPtr->jobless_population );
  283. font_san.put( x+309, y, townPtr->average_loyalty() );
  284. //------- display race icons -------//
  285. x += 350;
  286. int i;
  287. int iconSpacing = RACE_ICON_WIDTH+2;
  288. #if(MAX_RACE > 7)
  289. int raceCount = 0;
  290. for( i=0 ; i<MAX_RACE ; i++ )
  291. {
  292. if( townPtr->race_pop_array[i] > 0 )
  293. {
  294. ++raceCount;
  295. }
  296. }
  297. if( raceCount > 7 )
  298. {
  299. iconSpacing = 7 * iconSpacing / raceCount;
  300. }
  301. #endif
  302. for( i=0 ; i<MAX_RACE ; i++ )
  303. {
  304. if( townPtr->race_pop_array[i] > 0 )
  305. {
  306. vga_back.put_bitmap( x, y-2, race_res[i+1]->icon_bitmap_ptr );
  307. x += iconSpacing;
  308. }
  309. }
  310. }
  311. //----------- End of static function put_town_rec -----------//
  312. //-------- Begin of static function firm_filter --------//
  313. //
  314. // This function has dual purpose :
  315. //
  316. // 1. when <int> recNo is not given :
  317. // - return the total no. of firms of this nation
  318. //
  319. // 2. when <int> recNo is given :
  320. // - return the firm recno in firm_array of the given recno.
  321. //
  322. static int firm_filter(int recNo)
  323. {
  324. int firmTypeCount=0;
  325. FirmInfo* firmInfo;
  326. for( int firmId=1 ; firmId<=MAX_FIRM_TYPE ; firmId++ )
  327. {
  328. firmInfo = firm_res[firmId];
  329. if( firmInfo->nation_firm_count_array[info.viewing_nation_recno-1] )
  330. firmTypeCount++;
  331. if( recNo && firmTypeCount==recNo )
  332. return firmId;
  333. }
  334. err_when( recNo ); // the recNo is not found, it is out of range
  335. return firmTypeCount;
  336. }
  337. //----------- End of static function firm_filter -----------//
  338. //----------- Begin of static function put_firm_rec -----------//
  339. //
  340. static void put_firm_rec(int recNo, int x, int y, int refreshFlag)
  341. {
  342. int firmId = firm_filter(recNo);
  343. FirmInfo* firmInfo = firm_res[firmId];
  344. x+=3;
  345. y+=3;
  346. int firmCount = firmInfo->nation_firm_count_array[info.viewing_nation_recno-1];
  347. font_san.put( x , y, firmInfo->name );
  348. font_san.put( x+155, y, m.format(firmInfo->year_cost,2) );
  349. font_san.put( x+265, y, firmCount );
  350. font_san.put( x+370, y, m.format(firmInfo->year_cost*firmCount,2) );
  351. font_san.put( x+470, y, m.format(firm_income_array[firmId-1], 2) );
  352. }
  353. //----------- End of static function put_firm_rec -----------//