OR_TRADE.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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 <OSTR.h>
  24. #include <OFONT.h>
  25. #include <OIMGRES.h>
  26. #include <OVBROWIF.h>
  27. #include <OBUTTON.h>
  28. #include <ORACERES.h>
  29. #include <OFIRM.h>
  30. #include <OWORLD.h>
  31. #include <ONATION.h>
  32. #include <OU_CARA.h>
  33. #include <OU_MARI.h>
  34. #include <OINFO.h>
  35. //------------- Define coordinations -----------//
  36. enum { CARAVAN_BROWSE_X1 = ZOOM_X1+6,
  37. CARAVAN_BROWSE_Y1 = ZOOM_Y1+6,
  38. CARAVAN_BROWSE_X2 = ZOOM_X2-6,
  39. CARAVAN_BROWSE_Y2 = CARAVAN_BROWSE_Y1+260
  40. };
  41. enum { SHIP_BROWSE_X1 = ZOOM_X1+6,
  42. SHIP_BROWSE_Y1 = CARAVAN_BROWSE_Y2+6,
  43. SHIP_BROWSE_X2 = ZOOM_X2-6,
  44. SHIP_BROWSE_Y2 = ZOOM_Y2-6,
  45. };
  46. //----------- Define static variables ----------//
  47. static VBrowseIF browse_caravan, browse_ship;
  48. //----------- Define static functions ----------//
  49. static void create_caravan_list();
  50. static void create_ship_list();
  51. static void put_caravan_rec(int recNo, int x, int y, int refreshFlag);
  52. static void put_ship_rec(int recNo, int x, int y, int refreshFlag);
  53. static void disp_total();
  54. static void put_stop_info(int x, int y, TradeStop* tradeStop);
  55. static int sort_unit( const void *a, const void *b );
  56. //--------- Begin of function Info::disp_trade ---------//
  57. //
  58. void Info::disp_trade(int refreshFlag)
  59. {
  60. create_caravan_list();
  61. create_ship_list();
  62. //-------- display the caravan browser --------//
  63. int x=CARAVAN_BROWSE_X1+9;
  64. int y=CARAVAN_BROWSE_Y1+4;
  65. vga_back.d3_panel_up(CARAVAN_BROWSE_X1, CARAVAN_BROWSE_Y1, CARAVAN_BROWSE_X2, CARAVAN_BROWSE_Y1+20 );
  66. font_san.put( x , y, "Caravan" );
  67. #if(defined(FRENCH))
  68. font_san.put( x+75 , y, "Hit Points" );
  69. #else
  70. font_san.put( x+90 , y, "Hit Points" );
  71. #endif
  72. font_san.put( x+160, y, "Stop 1" );
  73. font_san.put( x+220, y, "Stop 2" );
  74. font_san.put( x+280, y, "Stop 3" );
  75. font_san.put( x+340, y, "Goods Carried" );
  76. if( refreshFlag == INFO_REPAINT )
  77. {
  78. browse_caravan.init( CARAVAN_BROWSE_X1, CARAVAN_BROWSE_Y1+22, CARAVAN_BROWSE_X2, CARAVAN_BROWSE_Y2-20,
  79. 0, 16, report_array.size(), put_caravan_rec, 1 );
  80. browse_caravan.open(browse_caravan_recno);
  81. }
  82. else
  83. {
  84. browse_caravan.paint();
  85. browse_caravan.open(browse_caravan_recno, report_array.size());
  86. }
  87. //-------- display the ship browser ---------//
  88. x=SHIP_BROWSE_X1+9;
  89. y=SHIP_BROWSE_Y1+4;
  90. vga_back.d3_panel_up(SHIP_BROWSE_X1, SHIP_BROWSE_Y1, SHIP_BROWSE_X2, SHIP_BROWSE_Y1+20 );
  91. font_san.put( x , y, "Ship" );
  92. #if(defined(FRENCH))
  93. font_san.put( x+75 , y, "Hit Points" );
  94. #else
  95. font_san.put( x+90 , y, "Hit Points" );
  96. #endif
  97. #if(defined(FRENCH))
  98. font_san.put( x+160, y, "Escale 1" );
  99. font_san.put( x+220, y, "Escale 2" );
  100. font_san.put( x+280, y, "Escale 3" );
  101. #else
  102. font_san.put( x+160, y, "Stop 1" );
  103. font_san.put( x+220, y, "Stop 2" );
  104. font_san.put( x+280, y, "Stop 3" );
  105. #endif
  106. font_san.put( x+340, y, "Goods Carried" );
  107. if( refreshFlag == INFO_REPAINT )
  108. {
  109. browse_ship.init( SHIP_BROWSE_X1, SHIP_BROWSE_Y1+22, SHIP_BROWSE_X2, SHIP_BROWSE_Y2-20,
  110. 0, 16, report_array2.size(), put_ship_rec, 1 );
  111. browse_ship.open(browse_ship_recno);
  112. }
  113. else
  114. {
  115. browse_ship.paint();
  116. browse_ship.open(browse_ship_recno, report_array2.size());
  117. }
  118. //------------ display total -------------//
  119. disp_total();
  120. }
  121. //----------- End of function Info::disp_trade -----------//
  122. //--------- Begin of function Info::detect_trade ---------//
  123. //
  124. void Info::detect_trade()
  125. {
  126. //-------- detect the caravan browser ---------//
  127. if( browse_caravan.detect() )
  128. {
  129. browse_caravan_recno = browse_caravan.recno();
  130. if( browse_caravan.double_click )
  131. {
  132. Unit* unitPtr = unit_array[ get_report_data(browse_caravan_recno) ];
  133. world.go_loc(unitPtr->next_x_loc(), unitPtr->next_y_loc(), 1);
  134. }
  135. }
  136. //-------- detect the ship browser ---------//
  137. if( browse_ship.detect() )
  138. {
  139. browse_ship_recno = browse_ship.recno();
  140. if( browse_ship.double_click )
  141. {
  142. Unit* unitPtr = unit_array[ get_report_data2(browse_ship_recno) ];
  143. world.go_loc(unitPtr->next_x_loc(), unitPtr->next_y_loc(), 1);
  144. }
  145. }
  146. }
  147. //----------- End of function Info::detect_trade -----------//
  148. //-------- Begin of static function disp_total --------//
  149. static void disp_total()
  150. {
  151. //------- display caravan total --------//
  152. int x=CARAVAN_BROWSE_X1+9;
  153. int y=CARAVAN_BROWSE_Y2-16;
  154. vga_back.d3_panel_up(CARAVAN_BROWSE_X1, CARAVAN_BROWSE_Y2-18, CARAVAN_BROWSE_X2, CARAVAN_BROWSE_Y2 );
  155. String str;
  156. if( info.report_array.size() > 1 )
  157. str = "Total Caravans";
  158. else
  159. str = "Total Caravan";
  160. str = translate.process(str);
  161. str += ": ";
  162. str += info.report_array.size();
  163. font_san.put( x, y, str );
  164. //-------- display ship total --------//
  165. x=SHIP_BROWSE_X1+9;
  166. y=SHIP_BROWSE_Y2-16;
  167. vga_back.d3_panel_up(SHIP_BROWSE_X1, SHIP_BROWSE_Y2-18, SHIP_BROWSE_X2, SHIP_BROWSE_Y2 );
  168. if( info.report_array2.size() > 1 )
  169. str = "Total Ships";
  170. else
  171. str = "Total Ship";
  172. str = translate.process(str);
  173. str += ": ";
  174. str += info.report_array2.size();
  175. font_san.put( x, y, str );
  176. }
  177. //----------- End of static function disp_total -----------//
  178. //-------- Begin of static function create_caravan_list --------//
  179. //
  180. static void create_caravan_list()
  181. {
  182. int totalUnit = unit_array.size();
  183. Unit* unitPtr;
  184. info.report_array.zap();
  185. for( short unitRecno=1 ; unitRecno<=totalUnit ; unitRecno++ )
  186. {
  187. if( unit_array.is_deleted(unitRecno) )
  188. continue;
  189. unitPtr = unit_array[unitRecno];
  190. if( unitPtr->nation_recno == info.viewing_nation_recno &&
  191. unitPtr->unit_id == UNIT_CARAVAN )
  192. {
  193. info.report_array.linkin(&unitRecno);
  194. }
  195. }
  196. info.report_array.quick_sort(sort_unit);
  197. }
  198. //----------- End of static function create_caravan_list -----------//
  199. //-------- Begin of static function create_ship_list --------//
  200. //
  201. static void create_ship_list()
  202. {
  203. int totalUnit = unit_array.size();
  204. Unit* unitPtr;
  205. info.report_array2.zap();
  206. for( short unitRecno=1 ; unitRecno<=totalUnit ; unitRecno++ )
  207. {
  208. if( unit_array.is_deleted(unitRecno) )
  209. continue;
  210. unitPtr = unit_array[unitRecno];
  211. if( unitPtr->nation_recno == info.viewing_nation_recno &&
  212. unit_res[unitPtr->unit_id]->carry_goods_capacity > 0 )
  213. {
  214. info.report_array2.linkin(&unitRecno);
  215. }
  216. }
  217. info.report_array2.quick_sort(sort_unit);
  218. }
  219. //----------- End of static function create_ship_list -----------//
  220. //-------- Begin of static function put_caravan_rec --------//
  221. //
  222. static void put_caravan_rec(int recNo, int x, int y, int refreshFlag)
  223. {
  224. int unitRecno = info.get_report_data(recNo);
  225. UnitCaravan* unitPtr = (UnitCaravan*) unit_array[unitRecno];
  226. int x2 = x+browse_caravan.rec_width-3;
  227. //---------- display info ----------//
  228. x+=3;
  229. y+=3;
  230. String str;
  231. str = (int) unitPtr->hit_points;
  232. str += "/";
  233. str += unitPtr->max_hit_points;
  234. font_san.put( x , y, unitPtr->unit_name() );
  235. font_san.put( x+90 , y, str );
  236. //------- display pick up type of each stop -------//
  237. if( unitPtr->stop_defined_num >= 1 )
  238. put_stop_info( x+160, y, unitPtr->stop_array );
  239. if( unitPtr->stop_defined_num >= 2 )
  240. put_stop_info( x+220, y, unitPtr->stop_array+1 );
  241. if( unitPtr->stop_defined_num >= 3 )
  242. put_stop_info( x+280, y, unitPtr->stop_array+2 );
  243. //------- display goods carried -------//
  244. x += 340;
  245. char *bitmapPtr;
  246. int i;
  247. for(i=0; i<MAX_RAW; i++)
  248. {
  249. if( unitPtr->raw_qty_array[i]==0 )
  250. continue;
  251. bitmapPtr = raw_res.small_raw_icon(i+1);
  252. vga_back.put_bitmap( x, y, bitmapPtr );
  253. font_san.disp( x+14, y-1, unitPtr->raw_qty_array[i], 1, x+45 );
  254. x+=36;
  255. if( x+36 > x2 )
  256. return;
  257. }
  258. for( i=0; i<MAX_PRODUCT; i++)
  259. {
  260. if( unitPtr->product_raw_qty_array[i]==0 )
  261. continue;
  262. bitmapPtr = raw_res.small_product_icon(i+1);
  263. vga_back.put_bitmap( x, y, bitmapPtr );
  264. font_san.disp( x+14, y-1, unitPtr->product_raw_qty_array[i], 1, x+45 );
  265. x+=36;
  266. if( x+36 > x2 )
  267. return;
  268. }
  269. }
  270. //----------- End of static function put_caravan_rec -----------//
  271. //-------- Begin of static function put_ship_rec --------//
  272. //
  273. static void put_ship_rec(int recNo, int x, int y, int refreshFlag)
  274. {
  275. int unitRecno = info.get_report_data2(recNo);
  276. UnitMarine* unitPtr = (UnitMarine*) unit_array[unitRecno];
  277. int x2 = x+browse_ship.rec_width-3;
  278. //---------- display info ----------//
  279. x+=3;
  280. y+=3;
  281. String str;
  282. str = (int) unitPtr->hit_points;
  283. str += "/";
  284. str += unitPtr->max_hit_points;
  285. font_san.put( x , y, unitPtr->unit_name() );
  286. font_san.put( x+90 , y, str );
  287. //------- display pick up type of each stop -------//
  288. if( unitPtr->stop_defined_num >= 1 )
  289. put_stop_info( x+160, y, unitPtr->stop_array );
  290. if( unitPtr->stop_defined_num >= 2 )
  291. put_stop_info( x+220, y, unitPtr->stop_array+1 );
  292. if( unitPtr->stop_defined_num >= 3 )
  293. put_stop_info( x+280, y, unitPtr->stop_array+2 );
  294. //------- display goods carried -------//
  295. x += 340;
  296. char *bitmapPtr;
  297. int i;
  298. for(i=0; i<MAX_RAW; i++)
  299. {
  300. if( unitPtr->raw_qty_array[i]==0 )
  301. continue;
  302. bitmapPtr = raw_res.small_raw_icon(i+1);
  303. vga_back.put_bitmap( x, y, bitmapPtr );
  304. font_san.disp( x+14, y-1, unitPtr->raw_qty_array[i], 1, x+45 );
  305. x+=36;
  306. if( x+36 > x2 )
  307. return;
  308. }
  309. for( i=0; i<MAX_PRODUCT; i++)
  310. {
  311. if( unitPtr->product_raw_qty_array[i]==0 )
  312. continue;
  313. bitmapPtr = raw_res.small_product_icon(i+1);
  314. vga_back.put_bitmap( x, y, bitmapPtr );
  315. font_san.disp( x+14, y-1, unitPtr->product_raw_qty_array[i], 1, x+45 );
  316. x+=36;
  317. if( x+36 > x2 )
  318. return;
  319. }
  320. }
  321. //----------- End of static function put_ship_rec -----------//
  322. //-------- Begin of static function put_stop_info --------//
  323. //
  324. static void put_stop_info(int x, int y, TradeStop* tradeStop)
  325. {
  326. int x2=x+58;
  327. //----- display the color of the stop ----//
  328. if( firm_array.is_deleted(tradeStop->firm_recno) )
  329. return;
  330. Firm* firmPtr = firm_array[tradeStop->firm_recno];
  331. nation_array[firmPtr->nation_recno]->disp_nation_color( x, y );
  332. x+=15;
  333. //------ display pick up type icon ------//
  334. int i, pickUpType = tradeStop->pick_up_type;
  335. switch( pickUpType )
  336. {
  337. case AUTO_PICK_UP:
  338. vga_back.put_bitmap( x, y, image_icon.get_ptr("AUTOPICK") );
  339. break;
  340. case NO_PICK_UP:
  341. vga_back.put_bitmap( x, y, image_icon.get_ptr("NOPICK") );
  342. break;
  343. default:
  344. for( i=PICK_UP_RAW_FIRST ; i<=PICK_UP_RAW_LAST ; i++ )
  345. {
  346. if( tradeStop->pick_up_array[i-1] )
  347. {
  348. vga_back.put_bitmap( x, y, raw_res.small_raw_icon(i-PICK_UP_RAW_FIRST+1) );
  349. x+=10;
  350. if( x+10 > x2 )
  351. return;
  352. }
  353. }
  354. for( i=PICK_UP_PRODUCT_FIRST ; i<=PICK_UP_PRODUCT_LAST ; i++ )
  355. {
  356. if( tradeStop->pick_up_array[i-1] )
  357. {
  358. vga_back.put_bitmap( x, y, raw_res.small_product_icon(i-PICK_UP_PRODUCT_FIRST+1) );
  359. x+=12;
  360. if( x+10 > x2 )
  361. return;
  362. }
  363. }
  364. }
  365. }
  366. //----------- End of static function put_stop_info -----------//
  367. //------ Begin of function sort_unit ------//
  368. //
  369. static int sort_unit( const void *a, const void *b )
  370. {
  371. Unit* unitPtr1 = (Unit*) unit_array[*((short*)a)];
  372. Unit* unitPtr2 = (Unit*) unit_array[*((short*)b)];
  373. return unitPtr1->name_id - unitPtr2->name_id;
  374. }
  375. //------- End of function sort_unit ------//