OF_WAR.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  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 : OF_WAR.CPP
  21. //Description : Firm War Factory
  22. #include <OINFO.h>
  23. #include <OVGA.h>
  24. #include <ODATE.h>
  25. #include <OSTR.h>
  26. #include <OCONFIG.h>
  27. #include <OFONT.h>
  28. #include <OMOUSE.h>
  29. #include <OBUTT3D.h>
  30. #include <OPOWER.h>
  31. #include <OUNIT.h>
  32. #include <OGAME.h>
  33. #include <OSYS.h>
  34. #include <ONATION.h>
  35. #include <OF_WAR.h>
  36. #include <OREMOTE.h>
  37. #include <OIMGRES.h>
  38. #include <OSE.h>
  39. #include <OSERES.h>
  40. #include <OBUTTCUS.h>
  41. //------------- Define constant ------------//
  42. #ifdef AMPLUS
  43. #define BUILD_BUTTON_WIDTH 201
  44. #define BUILD_BUTTON_HEIGHT 46
  45. #define COUNT_BUTTON_OFFSET_X 156
  46. #define COUNT_BUTTON_OFFSET_Y 7
  47. #define COUNT_BUTTON_WIDTH 32
  48. #define COUNT_BUTTON_HEIGHT 30
  49. #define BUILD_UNIT_ICON_OFFSET_X 6
  50. #define BUILD_UNIT_ICON_OFFSET_Y 4
  51. #define BUILD_UNIT_NAME_OFFSET_X 60
  52. #define BUILD_UNIT_NAME_OFFSET_Y 12
  53. #else
  54. #define BUILD_BUTTON_WIDTH 201
  55. #define BUILD_BUTTON_HEIGHT 56
  56. #define COUNT_BUTTON_OFFSET_X 156
  57. #define COUNT_BUTTON_OFFSET_Y 12
  58. #define COUNT_BUTTON_WIDTH 32
  59. #define COUNT_BUTTON_HEIGHT 32
  60. #define BUILD_UNIT_ICON_OFFSET_X 6
  61. #define BUILD_UNIT_ICON_OFFSET_Y 8
  62. #define BUILD_UNIT_NAME_OFFSET_X 60
  63. #define BUILD_UNIT_NAME_OFFSET_Y 18
  64. #endif
  65. //---------- Define constant ------------//
  66. enum { WAR_MENU_MAIN,
  67. WAR_MENU_BUILD,
  68. };
  69. //--------- define static variables ----------//
  70. static Button3D button_select_build;
  71. static Button3D button_cancel_build;
  72. static char war_menu_mode;
  73. static char disable_refresh=0;
  74. static short added_count;
  75. // ###### begin Gilbert 10/9 #######//
  76. // static short button_unit_id[MAX_WEAPON_TYPE];
  77. static ButtonCustom button_weapon[MAX_WEAPON_TYPE];
  78. static ButtonCustom button_queue_weapon[MAX_WEAPON_TYPE];
  79. // ###### end Gilbert 10/9 #######//
  80. static ButtonCustom button_cancel;
  81. // --------- declare static function ----------//
  82. static void i_disp_build_button(ButtonCustom *button, int);
  83. static void i_disp_queue_button(ButtonCustom *button, int);
  84. //--------- Begin of function FirmWar::FirmWar ---------//
  85. //
  86. FirmWar::FirmWar()
  87. {
  88. firm_skill_id = SKILL_MFT;
  89. build_unit_id = 0;
  90. build_queue_count = 0;
  91. }
  92. //----------- End of function FirmWar::FirmWar -----------//
  93. //--------- Begin of function FirmWar::~FirmWar ---------//
  94. //
  95. FirmWar::~FirmWar()
  96. {
  97. }
  98. //----------- End of function FirmWar::~FirmWar -----------//
  99. //--------- Begin of function FirmWar::put_info ---------//
  100. //
  101. void FirmWar::put_info(int refreshFlag)
  102. {
  103. if( refreshFlag==INFO_REPAINT && !disable_refresh )
  104. war_menu_mode = WAR_MENU_MAIN;
  105. switch( war_menu_mode )
  106. {
  107. case WAR_MENU_MAIN:
  108. disp_main_menu(refreshFlag);
  109. break;
  110. case WAR_MENU_BUILD:
  111. disp_build_menu(refreshFlag);
  112. break;
  113. }
  114. }
  115. //----------- End of function FirmWar::put_info -----------//
  116. //--------- Begin of function FirmWar::detect_info ---------//
  117. //
  118. void FirmWar::detect_info()
  119. {
  120. switch( war_menu_mode )
  121. {
  122. case WAR_MENU_MAIN:
  123. detect_main_menu();
  124. break;
  125. case WAR_MENU_BUILD:
  126. detect_build_menu();
  127. break;
  128. }
  129. }
  130. //----------- End of function FirmWar::detect_info -----------//
  131. //--------- Begin of function FirmWar::disp_main_menu ---------//
  132. //
  133. void FirmWar::disp_main_menu(int refreshFlag)
  134. {
  135. disp_basic_info(INFO_Y1, refreshFlag);
  136. if( !should_show_info() )
  137. return;
  138. disp_war_info(INFO_Y1+54, refreshFlag);
  139. disp_worker_list(INFO_Y1+107, refreshFlag);
  140. disp_worker_info(INFO_Y1+171, refreshFlag);
  141. if( own_firm() )
  142. {
  143. if( refreshFlag==INFO_REPAINT )
  144. button_select_build.paint( INFO_X1, INFO_Y1+235, 'A', "MAKEWEAP" );
  145. }
  146. disp_spy_button( INFO_X1+BUTTON_ACTION_WIDTH, INFO_Y1+235, refreshFlag );
  147. }
  148. //----------- End of function FirmWar::disp_main_menu -----------//
  149. //--------- Begin of function FirmWar::detect_main_menu ---------//
  150. //
  151. void FirmWar::detect_main_menu()
  152. {
  153. //-------- detect basic info -----------//
  154. if( detect_basic_info() )
  155. return;
  156. //---------- detect cancel build ------------//
  157. if(build_unit_id)
  158. {
  159. if(button_cancel_build.detect())
  160. {
  161. if( !remote.is_enable() )
  162. cancel_build_unit();
  163. else
  164. {
  165. short *shortPtr = (short *)remote.new_send_queue_msg(MSG_F_WAR_SKIP_WEAPON, sizeof(short) );
  166. shortPtr[0] = firm_recno;
  167. }
  168. }
  169. }
  170. //----------- detect worker -----------//
  171. if( detect_worker_list() )
  172. {
  173. disp_war_info(INFO_Y1+54, INFO_UPDATE);
  174. disp_worker_info(INFO_Y1+171, INFO_UPDATE);
  175. }
  176. //-------- detect spy button ----------//
  177. detect_spy_button();
  178. if( !own_firm() )
  179. return;
  180. //------ detect the select research button -------//
  181. if( button_select_build.detect() )
  182. {
  183. war_menu_mode = WAR_MENU_BUILD;
  184. disable_refresh = 1; // static var for disp_info() only
  185. info.disp();
  186. disable_refresh = 0;
  187. }
  188. }
  189. //----------- End of function FirmWar::detect_main_menu -----------//
  190. //--------- Begin of function FirmWar::disp_build_menu ---------//
  191. //
  192. void FirmWar::disp_build_menu(int refreshFlag)
  193. {
  194. // ###### begin Gilbert 10/9 ########//
  195. if( refreshFlag == INFO_UPDATE )
  196. {
  197. for( int b=0; b<added_count; ++b )
  198. {
  199. button_weapon[b].paint(-1, 0);
  200. // button_queue_weapon[b] is called by button_weapon[b].paint();
  201. }
  202. }
  203. else if( refreshFlag == INFO_REPAINT )
  204. {
  205. added_count=0;
  206. int unitId, x=INFO_X1+2, y=INFO_Y1;
  207. UnitInfo* unitInfo;
  208. for( unitId=1; unitId<=MAX_UNIT_TYPE ; unitId++ )
  209. {
  210. unitInfo = unit_res[unitId];
  211. if( unitInfo->unit_class == UNIT_CLASS_WEAPON &&
  212. unitInfo->get_nation_tech_level(nation_recno) > 0 )
  213. {
  214. // disp_build_button( y, unitId, 1);
  215. button_queue_weapon[added_count].create(x+COUNT_BUTTON_OFFSET_X, y+COUNT_BUTTON_OFFSET_Y,
  216. x+COUNT_BUTTON_OFFSET_X+COUNT_BUTTON_WIDTH-1, y+COUNT_BUTTON_OFFSET_Y+COUNT_BUTTON_HEIGHT-1,
  217. i_disp_queue_button, ButtonCustomPara(this, unitId) );
  218. button_weapon[added_count].paint(x, y, x+BUILD_BUTTON_WIDTH-1, y+BUILD_BUTTON_HEIGHT-1,
  219. i_disp_build_button, ButtonCustomPara(&button_queue_weapon[added_count], unitId) );
  220. err_when(added_count >= MAX_UNIT_TYPE);
  221. //button_unit_id[added_count++] = unitId;
  222. added_count++;
  223. y += BUILD_BUTTON_HEIGHT;
  224. }
  225. }
  226. button_cancel.paint(x, y, x+BUILD_BUTTON_WIDTH-1, y+BUILD_BUTTON_HEIGHT*3/4,
  227. ButtonCustom::disp_text_button_func, ButtonCustomPara((void*)"Done",0) );
  228. }
  229. // ###### end Gilbert 10/9 ########//
  230. }
  231. //----------- End of function FirmWar::disp_build_menu -----------//
  232. //--------- Begin of function FirmWar::detect_build_menu ---------//
  233. //
  234. void FirmWar::detect_build_menu()
  235. {
  236. int unitId, x=INFO_X1+2, y=INFO_Y1, rc, quitFlag;
  237. UnitInfo* unitInfo;
  238. for( int b = 0; b < added_count; ++b)
  239. {
  240. // ##### begin Gilbert 10/9 ######//
  241. unitId = button_weapon[b].custom_para.value;
  242. // ##### end Gilbert 10/9 ######//
  243. unitInfo = unit_res[unitId];
  244. //------ detect pressing on the small queue count button -------//
  245. // ######## begin Gilbert 10/9 #########//
  246. rc = 0;
  247. if( (rc = button_queue_weapon[b].detect(0,0,2)) != 0 ) // both button
  248. {
  249. quitFlag = 0; // don't quit the menu right after pressing the button
  250. }
  251. //------ detect pressing on the big button -------//
  252. else if( (rc = button_weapon[b].detect(0,0,2)) != 0 )
  253. {
  254. quitFlag = 1; // quit the menu right after pressing the button
  255. }
  256. // ######## end Gilbert 10/9 #########//
  257. //------- process the action --------//
  258. if( rc > 0 )
  259. {
  260. if( rc==1 ) // left button
  261. {
  262. if( remote.is_enable() )
  263. {
  264. // packet structure : <firm recno> <unit Id>
  265. short *shortPtr = (short *)remote.new_send_queue_msg(MSG_F_WAR_BUILD_WEAPON, 2*sizeof(short) );
  266. shortPtr[0] = firm_recno;
  267. shortPtr[1] = unitId;
  268. }
  269. else
  270. add_queue(unitId);
  271. // ##### begin Gilbert 25/9 ######//
  272. se_ctrl.immediate_sound("TURN_ON");
  273. // ##### end Gilbert 25/9 ######//
  274. }
  275. else // right button - remove queue
  276. {
  277. if( remote.is_enable() )
  278. {
  279. // packet structure : <firm recno> <unit Id>
  280. short *shortPtr = (short *)remote.new_send_queue_msg(MSG_F_WAR_CANCEL_WEAPON, 2*sizeof(short) );
  281. shortPtr[0] = firm_recno;
  282. shortPtr[1] = unitId;
  283. }
  284. else
  285. remove_queue(unitId);
  286. // ##### begin Gilbert 25/9 ######//
  287. se_ctrl.immediate_sound("TURN_OFF");
  288. // ##### end Gilbert 25/9 ######//
  289. }
  290. if( quitFlag )
  291. info.disp(); // info.disp() will call put_info() which will switch mode back to the main menu mode
  292. // ###### begin Gilbert 10/9 ########//
  293. else
  294. //disp_queue_button(y+COUNT_BUTTON_OFFSET_Y, unitId, 1);
  295. info.update();
  296. // ###### end Gilbert 10/9 ########//
  297. return;
  298. }
  299. y += BUILD_BUTTON_HEIGHT;
  300. }
  301. //------ detect the cancel button --------//
  302. if( button_cancel.detect() )
  303. {
  304. // ##### begin Gilbert 25/9 ######//
  305. se_ctrl.immediate_sound("TURN_OFF");
  306. // ##### end Gilbert 25/9 ######//
  307. war_menu_mode = WAR_MENU_MAIN;
  308. info.disp();
  309. }
  310. }
  311. //----------- End of function FirmWar::detect_build_menu -----------//
  312. // ####### begin Gilbert 10/9 ########//
  313. /*
  314. //-------- Begin of function FirmWar::disp_build_button --------//
  315. //
  316. void FirmWar::disp_build_button(int y, int unitId, int buttonUp)
  317. {
  318. int x;
  319. int y0 = y;
  320. if( buttonUp )
  321. {
  322. vga.d3_panel_up( INFO_X1, y, INFO_X2-1, y+BUILD_BUTTON_HEIGHT-2 );
  323. x = INFO_X1;
  324. }
  325. else
  326. {
  327. vga.d3_panel_down( INFO_X1, y, INFO_X2-1, y+BUILD_BUTTON_HEIGHT-2 );
  328. x = INFO_X1+1;
  329. y++;
  330. }
  331. // display unit large icon
  332. UnitInfo* unitInfo = unit_res[unitId];
  333. vga_front.put_bitmap(x+6, y+8, unitInfo->get_large_icon_ptr(0));
  334. //-------- display unit name --------//
  335. String str;
  336. str = unitInfo->name;
  337. if( unitInfo->unit_class == UNIT_CLASS_WEAPON ) // add version no.
  338. {
  339. int techLevel = unitInfo->get_nation_tech_level(nation_recno);
  340. if( techLevel > 1 )
  341. {
  342. str += " ";
  343. str += m.roman_number(techLevel);
  344. }
  345. }
  346. font_bible.put( x+60, y+18, str );
  347. disp_queue_button(y0+COUNT_BUTTON_OFFSET_Y, unitId, 1);
  348. }
  349. //--------- End of function FirmWar::disp_build_button ---------//
  350. */
  351. //-------- Begin of function i_disp_build_button --------//
  352. //
  353. static void i_disp_build_button(ButtonCustom *button, int repaintBody)
  354. {
  355. int x1 = button->x1;
  356. int y1 = button->y1;
  357. int x2 = button->x2;
  358. int y2 = button->y2;
  359. if( !button->pushed_flag )
  360. {
  361. if( repaintBody )
  362. {
  363. vga.blt_buf(x1, y1, x2, y2, 0);
  364. vga.d3_panel2_up( x1, y1, x2, y2, 1 );
  365. }
  366. x2--;
  367. y2--;
  368. }
  369. else
  370. {
  371. if( repaintBody )
  372. {
  373. vga.blt_buf(x1, y1, x2, y2, 0);
  374. vga.d3_panel2_down( x1, y1, x2, y2, 1 );
  375. }
  376. x1++;
  377. y1++;
  378. }
  379. ButtonCustom *queueButton = (ButtonCustom *)button->custom_para.ptr;
  380. if( repaintBody)
  381. {
  382. // display unit large icon
  383. short unitId = button->custom_para.value;
  384. UnitInfo* unitInfo = unit_res[unitId];
  385. vga_front.put_bitmap(x1+BUILD_UNIT_ICON_OFFSET_X, y1+BUILD_UNIT_ICON_OFFSET_Y,
  386. unitInfo->get_large_icon_ptr(0));
  387. err_when( button->custom_para.value != queueButton->custom_para.value);
  388. //-------- display unit name --------//
  389. String str;
  390. str = unitInfo->name;
  391. if( unitInfo->unit_class == UNIT_CLASS_WEAPON ) // add version no.
  392. {
  393. FirmWar *warFactory = (FirmWar *)queueButton->custom_para.ptr;
  394. int techLevel = unitInfo->get_nation_tech_level(warFactory->nation_recno);
  395. if( techLevel > 1 )
  396. {
  397. str += " ";
  398. str += m.roman_number(techLevel);
  399. }
  400. }
  401. font_bible.put( x1+BUILD_UNIT_NAME_OFFSET_X, y1+BUILD_UNIT_NAME_OFFSET_Y, str );
  402. }
  403. // display small button
  404. queueButton->paint(-1, repaintBody);
  405. }
  406. //--------- End of static function i_disp_build_button ---------//
  407. /*
  408. //-------- Begin of function FirmWar::disp_queue_button --------//
  409. //
  410. void FirmWar::disp_queue_button(int y, int unitId, int buttonUp)
  411. {
  412. //----- count the no. of units queued for this weapon ------//
  413. int x=INFO_X1+2+COUNT_BUTTON_OFFSET_X;
  414. int queuedCount=0;
  415. for( int i=0 ; i<build_queue_count ; i++ )
  416. {
  417. if( build_queue_array[i] == unitId )
  418. queuedCount++;
  419. }
  420. if(build_unit_id==unitId)
  421. queuedCount++;
  422. if( buttonUp )
  423. {
  424. vga.d3_panel_up( x, y, x+COUNT_BUTTON_WIDTH-1, y+COUNT_BUTTON_HEIGHT-1);
  425. }
  426. else
  427. {
  428. vga.d3_panel_down( x, y, x+COUNT_BUTTON_WIDTH-1, y+COUNT_BUTTON_HEIGHT-1);
  429. x++;
  430. y++;
  431. }
  432. font_san.center_put( x, y, x+COUNT_BUTTON_WIDTH-1 , y+COUNT_BUTTON_HEIGHT-1, m.format(queuedCount) );
  433. }
  434. //--------- End of function FirmWar::disp_queue_button ---------//
  435. */
  436. //-------- Begin of static function i_disp_queue_button --------//
  437. //
  438. static void i_disp_queue_button(ButtonCustom *button, int repaintBody)
  439. {
  440. FirmWar *warFactory = (FirmWar *)button->custom_para.ptr;
  441. int x1 = button->x1;
  442. int y1 = button->y1;
  443. int x2 = button->x2;
  444. int y2 = button->y2;
  445. if( !button->pushed_flag )
  446. {
  447. if( repaintBody )
  448. {
  449. vga.blt_buf(x1, y1, x2, y2, 0);
  450. vga.d3_panel2_up( x1, y1, x2, y2, 1, 1);
  451. }
  452. x2--;
  453. y2--;
  454. }
  455. else
  456. {
  457. if( repaintBody )
  458. {
  459. vga.blt_buf(x1, y1, x2, y2, 0);
  460. vga.d3_panel2_down( x1, y1, x2, y2, 1, 1);
  461. }
  462. x1++;
  463. y1++;
  464. }
  465. //----- count the no. of units queued for this weapon ------//
  466. short unitId = button->custom_para.value;
  467. int queuedCount=0;
  468. for( int i=0 ; i<warFactory->build_queue_count ; i++ )
  469. {
  470. if( warFactory->build_queue_array[i] == unitId )
  471. queuedCount++;
  472. }
  473. if( warFactory->build_unit_id == unitId)
  474. queuedCount++;
  475. font_mid.center_put( x1+3, y1+3, x2-3, y2-3, m.format(queuedCount), 1);
  476. }
  477. //--------- End of static function i_disp_queue_button ---------//
  478. // ####### end Gilbert 10/9 ########//
  479. //--------- Begin of function FirmWar::add_queue ---------//
  480. //
  481. void FirmWar::add_queue(int unitId)
  482. {
  483. if( build_queue_count+(build_unit_id>0)==MAX_BUILD_QUEUE )
  484. return;
  485. build_queue_array[build_queue_count++] = unitId;
  486. }
  487. //----------- End of function FirmWar::add_queue -----------//
  488. //--------- Begin of function FirmWar::remove_queue ---------//
  489. //
  490. void FirmWar::remove_queue(int unitId)
  491. {
  492. for( int i=build_queue_count-1 ; i>=0 ; i-- )
  493. {
  494. if( build_queue_array[i] == unitId )
  495. {
  496. err_when( build_queue_count > MAX_BUILD_QUEUE );
  497. m.del_array_rec( build_queue_array, build_queue_count, sizeof(build_queue_array[0]), i+1 );
  498. build_queue_count--;
  499. return;
  500. }
  501. }
  502. if(build_unit_id==unitId)
  503. cancel_build_unit();
  504. }
  505. //----------- End of function FirmWar::remove_queue -----------//
  506. //--------- Begin of function FirmWar::disp_war_info ---------//
  507. //
  508. void FirmWar::disp_war_info(int dispY1, int refreshFlag)
  509. {
  510. static short lastUnitId=0;
  511. if( refreshFlag==INFO_UPDATE && lastUnitId != build_unit_id )
  512. {
  513. lastUnitId = build_unit_id;
  514. info.disp();
  515. }
  516. //---------------- paint the panel --------------//
  517. if( refreshFlag == INFO_REPAINT )
  518. vga.d3_panel_up( INFO_X1, dispY1, INFO_X2, dispY1+50 );
  519. if( !build_unit_id )
  520. return;
  521. int x=INFO_X1+4, y=dispY1+4;
  522. //-------- display the icon of the researching item ---------//
  523. UnitInfo* unitInfo = unit_res[build_unit_id];
  524. if( refreshFlag == INFO_REPAINT )
  525. {
  526. vga.d3_panel_down( x, y, x+UNIT_LARGE_ICON_WIDTH+3, y+UNIT_LARGE_ICON_HEIGHT+3, 2 );
  527. vga_front.put_bitmap( x+2, y+2, unitInfo->get_large_icon_ptr(0) );
  528. //----------- display text ------------//
  529. x += UNIT_LARGE_ICON_WIDTH+10;
  530. String str(unitInfo->name);
  531. if( unitInfo->unit_class == UNIT_CLASS_WEAPON ) // add version no.
  532. {
  533. int techLevel = unitInfo->get_nation_tech_level(nation_recno);
  534. if( techLevel > 1 )
  535. {
  536. str += " ";
  537. str += m.roman_number(techLevel);
  538. }
  539. }
  540. font_san.put( x, y+4, str );
  541. }
  542. else
  543. {
  544. x += UNIT_LARGE_ICON_WIDTH+10;
  545. }
  546. //-- unitInfo->build_days is the no. of days take to build the firm when productivity is 100, the actually no. of days will be longer if productivity is less than 100 --//
  547. float buildProgressDays = build_progress_days
  548. + (float) (sys.frame_count-last_process_build_frame_no) / FRAMES_PER_DAY
  549. * (float) (worker_count*6+productivity/2) / 100;
  550. vga_front.indicator( 0, x-2, y+21, buildProgressDays, unitInfo->build_days, VGA_GRAY );
  551. button_cancel_build.paint(MSG_X2-27, dispY1, "V_X-U", "V_X-D");
  552. button_cancel_build.set_help_code( "CANCELWP" );
  553. }
  554. //----------- End of function FirmWar::disp_war_info -----------//
  555. //--------- Begin of function FirmWar::next_day ---------//
  556. //
  557. void FirmWar::next_day()
  558. {
  559. //----- call next_day() of the base class -----//
  560. Firm::next_day();
  561. //----------- update population -------------//
  562. recruit_worker();
  563. //-------- train up the skill ------------//
  564. update_worker();
  565. //--------- calculate productivity ----------//
  566. calc_productivity();
  567. //--------- process building weapon -------//
  568. if( build_unit_id )
  569. process_build();
  570. else
  571. process_queue();
  572. }
  573. //----------- End of function FirmWar::next_day -----------//
  574. //--------- Begin of function FirmWar::process_queue ---------//
  575. //
  576. void FirmWar::process_queue()
  577. {
  578. if( build_queue_count==0 )
  579. return;
  580. //--- first check if the nation has enough money to build the weapon ---//
  581. Nation* nationPtr = nation_array[nation_recno];
  582. build_unit_id = build_queue_array[0];
  583. if( nationPtr->cash < unit_res[build_unit_id]->build_cost )
  584. {
  585. build_unit_id = 0;
  586. return;
  587. }
  588. nationPtr->add_expense( EXPENSE_WEAPON, unit_res[build_unit_id]->build_cost, 1);
  589. err_when( build_queue_count > MAX_BUILD_QUEUE );
  590. m.del_array_rec( build_queue_array, build_queue_count, sizeof(build_queue_array[0]), 1 );
  591. build_queue_count--;
  592. //------- set building parameters -------//
  593. last_process_build_frame_no = sys.frame_count;
  594. build_progress_days = (float) 0;
  595. if( firm_array.selected_recno == firm_recno )
  596. {
  597. disable_refresh = 1;
  598. info.disp();
  599. disable_refresh = 0;
  600. }
  601. }
  602. //----------- End of function FirmWar::process_queue -----------//
  603. //--------- Begin of function FirmWar::process_build ---------//
  604. //
  605. void FirmWar::process_build()
  606. {
  607. err_when( !build_unit_id );
  608. UnitInfo* unitInfo = unit_res[build_unit_id];
  609. int totalBuildDays = unitInfo->build_days;
  610. build_progress_days += (float) (worker_count*6+productivity/2) / 100;
  611. last_process_build_frame_no = sys.frame_count;
  612. if( config.fast_build && nation_recno==nation_array.player_recno )
  613. build_progress_days += (float) 2;
  614. if( build_progress_days > totalBuildDays )
  615. {
  616. SpriteInfo* spriteInfo = sprite_res[ unitInfo->sprite_id ];
  617. int xLoc=loc_x1; // xLoc & yLoc are used for returning results
  618. int yLoc=loc_y1;
  619. if( !world.locate_space(xLoc, yLoc, loc_x2, loc_y2,
  620. spriteInfo->loc_width, spriteInfo->loc_height, unitInfo->mobile_type) )
  621. {
  622. build_progress_days = (float)(totalBuildDays + 1);
  623. return;
  624. }
  625. unit_array.add_unit( build_unit_id, nation_recno, 0, 0, xLoc, yLoc );
  626. if( firm_array.selected_recno == firm_recno )
  627. {
  628. disable_refresh = 1;
  629. info.disp();
  630. disable_refresh = 0;
  631. }
  632. if( own_firm() )
  633. se_res.far_sound(center_x, center_y, 1, 'F', firm_id, "FINS", 'S', unit_res[build_unit_id]->sprite_id);
  634. build_unit_id = 0;
  635. }
  636. }
  637. //----------- End of function FirmWar::process_build -----------//
  638. //--------- Begin of function FirmWar::cancel_build_unit ---------//
  639. void FirmWar::cancel_build_unit()
  640. {
  641. build_unit_id = 0;
  642. if( firm_array.selected_recno == firm_recno )
  643. {
  644. disable_refresh = 1;
  645. info.disp();
  646. disable_refresh = 0;
  647. }
  648. }
  649. //----------- End of function FirmWar::cancel_build_unitpt -----------//