OFIRMDRW.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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 : OFIRMDRW.CPP
  21. //Description : Firm drawing routines
  22. #include <COLCODE.h>
  23. #include <OSYS.h>
  24. #include <OVGA.h>
  25. #include <ONATION.h>
  26. #include <OSPRITE.h>
  27. #include <OINFO.h>
  28. #include <ORAWRES.h>
  29. #include <OPOWER.h>
  30. #include <OGAME.h>
  31. #include <OANLINE.h>
  32. #include <OIMGRES.h>
  33. #include <OWORLD.h>
  34. #include <OF_BASE.h>
  35. #include <OSE.h>
  36. #include <OREMOTE.h>
  37. //------- define static vars -------//
  38. struct Point
  39. {
  40. short x;
  41. short y;
  42. };
  43. static Point slot_point_array[] =
  44. {
  45. { 1, 86 },
  46. { 8, 84 },
  47. { 15, 86 },
  48. { 1, 79 },
  49. { 8, 77 },
  50. { 15, 79 },
  51. { 1, 72 },
  52. { 8, 70 },
  53. { 15, 72 },
  54. };
  55. //------- Begin of function Firm::draw -----------//
  56. //
  57. // Draw the firm on the map
  58. //
  59. // [int] displayLayer : 1 = same layer with units (default : 1)
  60. // : 2 = layer above units
  61. // : 4 = layer below units
  62. //
  63. void Firm::draw(int displayLayer)
  64. {
  65. FirmBuild* firmBuild = firm_res.get_build(firm_build_id);
  66. // if in construction, don't draw ground unless the last construction frame
  67. if( firmBuild->ground_bitmap_recno &&
  68. (!under_construction || construction_frame() >= firmBuild->under_construction_bitmap_count-1))
  69. {
  70. firm_res.get_bitmap(firmBuild->ground_bitmap_recno)
  71. ->draw_at(loc_x1*ZOOM_LOC_WIDTH, loc_y1*ZOOM_LOC_HEIGHT, NULL, displayLayer);
  72. }
  73. if( firmBuild->animate_full_size )
  74. {
  75. draw_full_size(displayLayer);
  76. }
  77. else
  78. {
  79. if( under_construction )
  80. {
  81. draw_full_size(displayLayer);
  82. }
  83. else if( !is_operating() )
  84. {
  85. FirmBuild* firmBuild = firm_res.get_build(firm_build_id);
  86. if( firm_res.get_bitmap(firmBuild->idle_bitmap_recno) )
  87. draw_full_size(displayLayer);
  88. else
  89. {
  90. draw_frame(1, displayLayer);
  91. draw_frame(2, displayLayer);
  92. }
  93. }
  94. else
  95. {
  96. draw_frame(1, displayLayer); // the first frame is the common frame for multi-segment bitmaps
  97. draw_frame(cur_frame, displayLayer);
  98. }
  99. }
  100. }
  101. //--------- End of function Firm::draw -----------//
  102. //------- Begin of function Firm::draw_full_size -----------//
  103. //
  104. // Draw the firm on the map
  105. //
  106. void Firm::draw_full_size(int displayLayer)
  107. {
  108. FirmBuild* firmBuild = firm_res.get_build(firm_build_id);
  109. //-------- check if the firm is within the view area --------//
  110. int x1 = abs_x1 - World::view_top_x;
  111. if( x1 <= -firmBuild->max_bitmap_width || x1 >= ZOOM_WIDTH ) // out of the view area, not even a slight part of it appears in the view area
  112. return;
  113. int y1 = abs_y1 - World::view_top_y;
  114. if( y1 <= -firmBuild->max_bitmap_height || y1 >= ZOOM_HEIGHT )
  115. return;
  116. //------- get the color remap table for this bitmap ------//
  117. char* colorRemapTable = game.get_color_remap_table(nation_recno, firm_array.selected_recno == firm_recno);
  118. // ######## begin Gilbert 29/10 #######//
  119. // ------ draw flags behind the building -------//
  120. if( under_construction )
  121. {
  122. #define FLAG_WIDTH 9
  123. #define FLAG_HEIGHT 25
  124. char *flagBitmapPtr = image_spict.get_ptr("FLAG-S0");
  125. int drawX = loc_x1 * ZOOM_LOC_WIDTH - world.view_top_x + ZOOM_X1;
  126. int drawY = loc_y1 * ZOOM_LOC_HEIGHT - world.view_top_y + ZOOM_Y1;
  127. world.zoom_matrix->put_bitmap_remap_clip(drawX, drawY, flagBitmapPtr, colorRemapTable, 1); // 1-the bitmap is compressed
  128. drawX = (loc_x2+1)*ZOOM_LOC_WIDTH - FLAG_WIDTH - world.view_top_x + ZOOM_X1;
  129. world.zoom_matrix->put_bitmap_remap_clip(drawX, drawY, flagBitmapPtr, colorRemapTable, 1); // 1-the bitmap is compressed
  130. }
  131. // ######## end Gilbert 29/10 #######//
  132. //---------- get the bitmap pointer ----------//
  133. FirmBitmap* firmBitmap = NULL;
  134. if( under_construction )
  135. {
  136. int buildFraction = construction_frame();
  137. firmBitmap = firm_res.get_bitmap(firmBuild->under_construction_bitmap_recno
  138. + buildFraction);
  139. }
  140. else if( !is_operating() ) // is_operating() is a virtual function
  141. firmBitmap = firm_res.get_bitmap(firmBuild->idle_bitmap_recno);
  142. else
  143. firmBitmap = firm_res.get_bitmap(firmBuild->first_bitmap(cur_frame));
  144. // ------ check if the display layer is correct ---------//
  145. if( !firmBitmap || !(firmBitmap->display_layer & displayLayer) )
  146. return;
  147. //-------- check if the firm is within the view area --------//
  148. x1 = loc_x1 * ZOOM_LOC_WIDTH - World::view_top_x + firmBitmap->offset_x;
  149. if( x1 <= -firmBitmap->width || x1 >= ZOOM_WIDTH ) // out of the view area, not even a slight part of it appears in the view area
  150. return;
  151. y1 = loc_y1 * ZOOM_LOC_HEIGHT - World::view_top_y + firmBitmap->offset_y;
  152. if( y1 <= -firmBitmap->height || y1 >= ZOOM_HEIGHT )
  153. return;
  154. //------- decide which approach to use for displaying -----//
  155. int x2 = x1 + firmBitmap->width - 1;
  156. int y2 = y1 + firmBitmap->height - 1;
  157. //------- if the firm is under construction ------//
  158. if( 0 && under_construction )
  159. {
  160. err_when( (abs_x2-abs_x1+1) * (abs_y2-abs_y1+1) > COMMON_DATA_BUF_SIZE );
  161. //---------- decompress the image ---------//
  162. IMGremapDecompress(sys.common_data_buf, firmBitmap->bitmap_ptr, colorRemapTable);
  163. //---------- pixelize the image -----------//
  164. char* pixelPtr = sys.common_data_buf + sizeof(short) * 2;
  165. int y, bitmapWidth=abs_x2-abs_x1+1, bitmapHeight=abs_y2-abs_y1+1;
  166. int lineCount;
  167. int solidLineCount = bitmapHeight / 2 * (int) hit_points / (int) max_hit_points;
  168. int solidLinePixel = bitmapHeight / 2 * bitmapWidth * (int) hit_points / (int) max_hit_points -
  169. solidLineCount * bitmapWidth;
  170. int hitPerPixel = (int) max_hit_points / bitmapWidth / bitmapHeight / 2;
  171. for( lineCount=1, y=bitmapHeight-2 ; y>=0 ; y-=2, lineCount++ )
  172. {
  173. if( lineCount > solidLineCount )
  174. memset( pixelPtr+y*bitmapWidth, TRANSPARENT_CODE, bitmapWidth );
  175. if( lineCount==solidLineCount+1 ) // the current progressing line
  176. memset( pixelPtr+y*bitmapWidth, TRANSPARENT_CODE, solidLinePixel );
  177. }
  178. //---- only portion of the sprite is inside the view area ------//
  179. if( x1 < 0 || x2 >= ZOOM_WIDTH || y1 < 0 || y2 >= ZOOM_HEIGHT )
  180. {
  181. vga_back.put_bitmap_area_trans( x1+ZOOM_X1, y1+ZOOM_Y1, sys.common_data_buf,
  182. max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1 );
  183. }
  184. //---- the whole sprite is inside the view area ------//
  185. else
  186. {
  187. vga_back.put_bitmap_trans( x1+ZOOM_X1, y1+ZOOM_Y1, sys.common_data_buf );
  188. }
  189. }
  190. else //----- display the normal image (not under construction) ----//
  191. {
  192. //---- only portion of the sprite is inside the view area ------//
  193. if( x1 < 0 || x2 >= ZOOM_WIDTH || y1 < 0 || y2 >= ZOOM_HEIGHT )
  194. {
  195. vga_back.put_bitmap_area_trans_remap_decompress( x1+ZOOM_X1, y1+ZOOM_Y1, firmBitmap->bitmap_ptr,
  196. max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1, colorRemapTable );
  197. }
  198. //---- the whole sprite is inside the view area ------//
  199. else
  200. {
  201. vga_back.put_bitmap_trans_remap_decompress( x1+ZOOM_X1, y1+ZOOM_Y1, firmBitmap->bitmap_ptr, colorRemapTable );
  202. }
  203. }
  204. // ######## begin Gilbert 29/10 #######//
  205. // ------ draw flags in front of the building -------//
  206. if( under_construction )
  207. {
  208. char *flagBitmapPtr = image_spict.get_ptr("FLAG-S0");
  209. int drawX = loc_x1 * ZOOM_LOC_WIDTH - world.view_top_x + ZOOM_X1;
  210. int drawY = (loc_y2+1) * ZOOM_LOC_HEIGHT - FLAG_HEIGHT - world.view_top_y + ZOOM_Y1;
  211. world.zoom_matrix->put_bitmap_remap_clip(drawX, drawY, flagBitmapPtr, colorRemapTable, 1); // 1-the bitmap is compressed
  212. drawX = (loc_x2+1)*ZOOM_LOC_WIDTH - FLAG_WIDTH - world.view_top_x + ZOOM_X1;
  213. world.zoom_matrix->put_bitmap_remap_clip(drawX, drawY, flagBitmapPtr, colorRemapTable, 1); // 1-the bitmap is compressed
  214. }
  215. // ######## end Gilbert 29/10 #######//
  216. }
  217. //--------- End of function Firm::draw_full_size -----------//
  218. //------- Begin of function Firm::draw_frame -----------//
  219. //
  220. // Draw a specific frame of the firm.
  221. //
  222. void Firm::draw_frame(int frameId, int displayLayer)
  223. {
  224. //---------- draw animation now ------------//
  225. FirmBuild* firmBuild = firm_res.get_build(firm_build_id);
  226. FirmBitmap* firmBitmap;
  227. int bitmapRecno, i;
  228. int firstBitmap = firmBuild->first_bitmap(frameId);
  229. int bitmapCount = firmBuild->bitmap_count(frameId);
  230. char* colorRemapTable = game.get_color_remap_table(nation_recno, firm_array.selected_recno==firm_recno);
  231. for( i=0, bitmapRecno=firstBitmap ; i<bitmapCount ; i++, bitmapRecno++ )
  232. {
  233. firmBitmap = firm_res.get_bitmap(bitmapRecno);
  234. if( firmBitmap )
  235. firmBitmap->draw_at(loc_x1*ZOOM_LOC_WIDTH, loc_y1*ZOOM_LOC_HEIGHT, colorRemapTable, displayLayer);
  236. }
  237. }
  238. //--------- End of function Firm::draw_frame -----------//
  239. //------- Begin of function Firm::draw_detect_link_line ---------//
  240. //
  241. // [int] actionDetect - 0 - this is a draw action
  242. // 1 - this is a detect action
  243. // (default: 0)
  244. //
  245. // return: <int> 1 - detected
  246. // 0 - not detected
  247. //
  248. int Firm::draw_detect_link_line(int actionDetect)
  249. {
  250. if( firm_id == FIRM_INN ) // FirmInn's link is only for scan for neighbor inns quickly, the link line is not displayed
  251. return 0;
  252. //--------------------------------------//
  253. int i, firmX, firmY, townX, townY;
  254. Firm* firmPtr;
  255. Town* townPtr;
  256. FirmInfo* firmInfo = firm_res[firm_id];
  257. //-------- set source points ----------//
  258. int srcX = ( ZOOM_X1 + (loc_x1-world.zoom_matrix->top_x_loc) * ZOOM_LOC_WIDTH
  259. + ZOOM_X1 + (loc_x2-world.zoom_matrix->top_x_loc+1) * ZOOM_LOC_WIDTH ) / 2;
  260. int srcY = ( ZOOM_Y1 + (loc_y1-world.zoom_matrix->top_y_loc) * ZOOM_LOC_HEIGHT
  261. + ZOOM_Y1 + (loc_y2-world.zoom_matrix->top_y_loc+1) * ZOOM_LOC_HEIGHT ) / 2;
  262. //------ draw lines to linked firms ---------//
  263. int lineType;
  264. char* bitmapPtr;
  265. for( i=0 ; i<linked_firm_count ; i++ )
  266. {
  267. firmPtr = firm_array[linked_firm_array[i]];
  268. firmX = ( ZOOM_X1 + (firmPtr->loc_x1-world.zoom_matrix->top_x_loc) * ZOOM_LOC_WIDTH
  269. + ZOOM_X1 + (firmPtr->loc_x2-world.zoom_matrix->top_x_loc+1) * ZOOM_LOC_WIDTH ) / 2;
  270. firmY = ( ZOOM_Y1 + (firmPtr->loc_y1-world.zoom_matrix->top_y_loc) * ZOOM_LOC_HEIGHT
  271. + ZOOM_Y1 + (firmPtr->loc_y2-world.zoom_matrix->top_y_loc+1) * ZOOM_LOC_HEIGHT ) / 2;
  272. anim_line.draw_line(&vga_back, srcX, srcY, firmX, firmY, linked_firm_enable_array[i]==LINK_EE );
  273. //----- check if this firm can toggle link or not -----//
  274. if( !can_toggle_firm_link(firmPtr->firm_recno) )
  275. continue;
  276. //------ if the link is switchable -------//
  277. bitmapPtr = power.get_link_icon( linked_firm_enable_array[i], nation_recno==firmPtr->nation_recno );
  278. if( actionDetect )
  279. {
  280. if( own_firm() && world.zoom_matrix->detect_bitmap_clip( firmX-11, firmY-11, bitmapPtr ) )
  281. {
  282. if( linked_firm_enable_array[i] & LINK_ED )
  283. {
  284. toggle_firm_link( i+1, 0, COMMAND_PLAYER );
  285. se_ctrl.immediate_sound("TURN_OFF");
  286. }
  287. else
  288. {
  289. toggle_firm_link( i+1, 1, COMMAND_PLAYER );
  290. se_ctrl.immediate_sound("TURN_ON");
  291. }
  292. return 1;
  293. }
  294. }
  295. else
  296. {
  297. if( nation_recno == nation_array.player_recno )
  298. world.zoom_matrix->put_bitmap_clip( firmX-11, firmY-11, bitmapPtr );
  299. }
  300. }
  301. //------ draw lines to linked towns ---------//
  302. for( i=0 ; i<linked_town_count ; i++ )
  303. {
  304. townPtr = town_array[linked_town_array[i]];
  305. townX = ( ZOOM_X1 + (townPtr->loc_x1-world.zoom_matrix->top_x_loc) * ZOOM_LOC_WIDTH
  306. + ZOOM_X1 + (townPtr->loc_x2-world.zoom_matrix->top_x_loc+1) * ZOOM_LOC_WIDTH ) / 2;
  307. townY = ( ZOOM_Y1 + (townPtr->loc_y1-world.zoom_matrix->top_y_loc) * ZOOM_LOC_HEIGHT
  308. + ZOOM_Y1 + (townPtr->loc_y2-world.zoom_matrix->top_y_loc+1) * ZOOM_LOC_HEIGHT ) / 2;
  309. if( worker_array && selected_worker_id &&
  310. worker_array[selected_worker_id-1].town_recno == townPtr->town_recno )
  311. {
  312. lineType = -1;
  313. anim_line.thick_line(&vga_back, srcX, srcY, townX, townY, linked_town_enable_array[i]==LINK_EE, lineType );
  314. }
  315. else
  316. {
  317. lineType = 0;
  318. anim_line.draw_line(&vga_back, srcX, srcY, townX, townY, linked_town_enable_array[i]==LINK_EE, lineType );
  319. }
  320. //----- check if this firm can toggle link or not -----//
  321. if( !can_toggle_town_link() )
  322. continue;
  323. //--------- draw link symbol -----------//
  324. bitmapPtr = power.get_link_icon( linked_town_enable_array[i], nation_recno==townPtr->nation_recno );
  325. if( actionDetect )
  326. {
  327. int rc = world.zoom_matrix->detect_bitmap_clip( townX-11, townY-11, bitmapPtr );
  328. //------ left clicking to toggle link -------//
  329. if( rc==1 && own_firm() )
  330. {
  331. if( linked_town_enable_array[i] & LINK_ED )
  332. {
  333. toggle_town_link( i+1, 0, COMMAND_PLAYER );
  334. se_ctrl.immediate_sound("TURN_OFF");
  335. }
  336. else
  337. {
  338. toggle_town_link( i+1, 1, COMMAND_PLAYER );
  339. se_ctrl.immediate_sound("TURN_ON");
  340. }
  341. //
  342. // update RemoteMsg::firm_toggle_link_town()
  343. //
  344. if( firm_id == FIRM_CAMP && !remote.is_enable())
  345. {
  346. if( townPtr->nation_recno )
  347. townPtr->update_target_loyalty();
  348. else
  349. townPtr->update_target_resistance();
  350. townPtr->update_camp_link();
  351. }
  352. return 1;
  353. }
  354. //------ right clicking to move workers ------//
  355. else if( rc==2 && selected_worker_id > 0 )
  356. {
  357. //--- only when this worker is ours ----//
  358. if( firm_res[firm_id]->live_in_town &&
  359. worker_array[selected_worker_id-1].is_nation(firm_recno, nation_array.player_recno) )
  360. {
  361. if(townPtr->population>=MAX_TOWN_POPULATION)
  362. return 0;
  363. set_worker_home_town(townPtr->town_recno, COMMAND_PLAYER);
  364. se_ctrl.immediate_sound("PULL_MAN");
  365. return 1;
  366. }
  367. }
  368. }
  369. else
  370. {
  371. if( nation_recno == nation_array.player_recno )
  372. world.zoom_matrix->put_bitmap_clip( townX-11, townY-11, bitmapPtr );
  373. }
  374. }
  375. return 0;
  376. }
  377. //------- End of function Firm::draw_detect_link_line ---------//
  378. //------- Begin of function Firm::is_in_zoom_win -----------//
  379. //
  380. // Whether the firm is in the current zoom window.
  381. //
  382. int Firm::is_in_zoom_win()
  383. {
  384. FirmBuild* firmBuild = firm_res.get_build(firm_build_id);
  385. //-------- check if the firm is within the view area --------//
  386. int x1 = abs_x1 - World::view_top_x;
  387. if( x1 <= -firmBuild->max_bitmap_width || x1 >= ZOOM_WIDTH ) // out of the view area, not even a slight part of it appears in the view area
  388. return 0;
  389. int y1 = abs_y1 - World::view_top_y;
  390. if( y1 <= -firmBuild->max_bitmap_height || y1 >= ZOOM_HEIGHT )
  391. return 0;
  392. return 1;
  393. }
  394. //--------- End of function Firm::is_in_zoom_win -----------//
  395. //------- Begin of function Firm::draw_selected -----------//
  396. //
  397. // Draw a square around the firm on the map.
  398. //
  399. void Firm::draw_selected()
  400. {
  401. /*
  402. //------ calculate frame coordinations ---------//
  403. FirmBuild* firmBuild = firm_res.get_build(firm_build_id);
  404. int x1 = loc_x1 * ZOOM_LOC_WIDTH;
  405. int y1 = loc_y1 * ZOOM_LOC_HEIGHT;
  406. int x2 = (loc_x1+firmBuild->loc_width) * ZOOM_LOC_WIDTH - 1;
  407. int y2 = (loc_y1+firmBuild->loc_height) * ZOOM_LOC_HEIGHT - 1;
  408. x1 = x1 - World::view_top_x + ZOOM_X1;
  409. y1 = y1 - World::view_top_y + ZOOM_Y1;
  410. x2 = x2 - World::view_top_x + ZOOM_X1;
  411. y2 = y2 - World::view_top_y + ZOOM_Y1;
  412. //------------- set frame color -------------//
  413. char frameColor;
  414. if( nation_recno == nation_array.player_recno )
  415. frameColor = OWN_SELECT_FRAME_COLOR;
  416. else
  417. frameColor = ENEMY_SELECT_FRAME_COLOR;
  418. //------------ draw the square frame now ------------//
  419. if( m.is_touch( x1, y1, x2, y2, ZOOM_X1, ZOOM_Y1, ZOOM_X2, ZOOM_Y2 ) )
  420. {
  421. //------- Only draw_selected the portion within the zoom window area ----//
  422. if( y1 >= ZOOM_Y1 ) // square top
  423. vga_back.bar( max(x1,ZOOM_X1), y1, min(x2,ZOOM_X2), y1, frameColor );
  424. if( y2 <= ZOOM_Y2 ) // square bottom
  425. vga_back.bar( max(x1,ZOOM_X1), y2, min(x2,ZOOM_X2), y2, frameColor );
  426. if( x1 >= ZOOM_X1 ) // square left
  427. vga_back.bar( x1, max(y1,ZOOM_Y1), x1, min(y2,ZOOM_Y2), frameColor );
  428. if( y1 <= ZOOM_X2 ) // square left
  429. vga_back.bar( x2, max(y1,ZOOM_Y1), x2, min(y2,ZOOM_Y2), frameColor );
  430. //------------ display hit point bar -----------//
  431. if( firm_res[firm_id]->buildable )
  432. {
  433. x1 = x1+1;
  434. y1 = max( y2-4, ZOOM_Y1 );
  435. x2 = x2-1;
  436. y2 = min( y2-1, ZOOM_Y2 );
  437. if( x1<=ZOOM_X2 && x2>=ZOOM_X1 && y1<=ZOOM_Y2 && y2>=ZOOM_Y1 )
  438. {
  439. int barWidth = (x2-x1+1) * hit_points / max_hit_points;
  440. if( hit_points > 0 && x1+barWidth-1 >= ZOOM_X1)
  441. {
  442. vga_back.bar( max(x1,ZOOM_X1), y1 , min(x1+barWidth-1,ZOOM_X2), y1, frameColor );
  443. vga_back.bar( max(x1,ZOOM_X1), y1+1, min(x1+barWidth-1,ZOOM_X2), y2, V_GREEN );
  444. }
  445. }
  446. }
  447. }
  448. */
  449. //------- draw lines connected to town ---------//
  450. draw_detect_link_line(0);
  451. }
  452. //--------- End of function Firm::draw_selected -----------//
  453. //------- Begin of function Firm::draw_cargo -----------//
  454. //
  455. // Draw cargos of stock.
  456. //
  457. // <int> cargoCount - the no. of cargos to be drawn
  458. // <char*> cargoBitmapPtr - bitmap ptr to the cargo
  459. //
  460. void Firm::draw_cargo(int cargoCount, char* cargoBitmapPtr)
  461. {
  462. //-------- check if the firm is within the view area --------//
  463. if( loc_x1 < world.zoom_matrix->top_x_loc || loc_x2 >= world.zoom_matrix->top_x_loc+ZOOM_WIDTH )
  464. return;
  465. if( loc_y1 < world.zoom_matrix->top_y_loc || loc_y2 >= world.zoom_matrix->top_y_loc+ZOOM_HEIGHT )
  466. return;
  467. //------ display a pile of raw materials ------//
  468. int x = ZOOM_X1 + (loc_x1-world.zoom_matrix->top_x_loc) * ZOOM_LOC_WIDTH;
  469. int y = ZOOM_Y1 + (loc_y1-world.zoom_matrix->top_y_loc) * ZOOM_LOC_HEIGHT;
  470. for( int i=0 ; i<cargoCount ; i++ )
  471. {
  472. world.zoom_matrix->put_bitmap_clip( x+slot_point_array[i].x,
  473. y+slot_point_array[i].y, cargoBitmapPtr);
  474. }
  475. }
  476. //--------- End of function Firm::draw_cargo -----------//
  477. //------- Begin of function Firm::can_toggle_town_link ---------//
  478. //
  479. int Firm::can_toggle_town_link()
  480. {
  481. return firm_id != FIRM_MARKET; // only a market cannot toggle its link as it is
  482. }
  483. //------- Begin of function Firm::can_toggle_town_link ---------//
  484. //------- Begin of function Firm::can_toggle_firm_link ---------//
  485. //
  486. int Firm::can_toggle_firm_link(int firmRecno)
  487. {
  488. Firm* firmPtr = firm_array[firmRecno];
  489. //--- market to harbor link is determined by trade treaty ---//
  490. if( ( firm_id == FIRM_MARKET && firmPtr->firm_id == FIRM_HARBOR ) ||
  491. ( firm_id == FIRM_HARBOR && firmPtr->firm_id == FIRM_MARKET ) )
  492. {
  493. return 0;
  494. }
  495. return firm_res[firm_id]->is_linkable_to_firm(firmPtr->firm_id);
  496. }
  497. //------- End of function Firm::can_toggle_firm_link ---------//
  498. //------- Begin of function Firm::construction_frame ---------//
  499. //
  500. // return 0 to hitfirmBuild->under_construction_bitmap_count-1
  501. // according to hit_points and max_hitpoints
  502. //
  503. int Firm::construction_frame()
  504. {
  505. err_when(!under_construction);
  506. FirmBuild* firmBuild = firm_res.get_build(firm_build_id);
  507. int r = int( hit_points * firmBuild->under_construction_bitmap_count / max_hit_points);
  508. err_when( r < 0);
  509. if( r >= firmBuild->under_construction_bitmap_count )
  510. r = firmBuild->under_construction_bitmap_count-1;
  511. return r;
  512. }
  513. //------- End of function Firm::construction_frame ---------//