OFIRMRES.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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 : OFIRMRES.CPP
  21. //Description : Firm material resource object
  22. #include <OSYS.h>
  23. #include <OGAMESET.h>
  24. #include <OWORLD.h>
  25. #include <OUNIT.h>
  26. #include <ONATION.h>
  27. #include <OFIRMRES.h>
  28. #if(defined(GERMAN) || defined(FRENCH) || defined(SPANISH))
  29. #include <OTRANSL.h>
  30. #endif
  31. //---------- #define constant ------------//
  32. #define FIRM_DB "FIRM"
  33. #define FIRM_BUILD_DB "FBUILD"
  34. #define FIRM_FRAME_DB "FFRAME"
  35. #define FIRM_BITMAP_DB "FBITMAP"
  36. //------- Begin of function FirmRes::FirmRes -----------//
  37. FirmRes::FirmRes()
  38. {
  39. init_flag=0;
  40. }
  41. //--------- End of function FirmRes::FirmRes -----------//
  42. //---------- Begin of function FirmRes::init -----------//
  43. //
  44. // This function must be called after a map is generated.
  45. //
  46. void FirmRes::init()
  47. {
  48. deinit();
  49. //----- open firm material bitmap resource file -------//
  50. String str;
  51. str = DIR_RES;
  52. str += "I_FIRM.RES";
  53. res_bitmap.init_imported(str,1); // 1-read all into buffer
  54. //------- load database information --------//
  55. load_firm_bitmap(); // call load_firm_bitmap() first as load_firm_info() will need info loaded by load_firm_bitmap()
  56. load_firm_build();
  57. load_firm_info();
  58. //------------ set firm skill ------------//
  59. firm_res[FIRM_BASE]->firm_skill_id = SKILL_LEADING;
  60. firm_res[FIRM_CAMP]->firm_skill_id = SKILL_LEADING;
  61. firm_res[FIRM_MINE]->firm_skill_id = SKILL_MINING;
  62. firm_res[FIRM_FACTORY]->firm_skill_id = SKILL_MFT;
  63. firm_res[FIRM_RESEARCH]->firm_skill_id = SKILL_RESEARCH;
  64. firm_res[FIRM_WAR_FACTORY]->firm_skill_id = SKILL_MFT;
  65. //----------------------------------------//
  66. init_flag=1;
  67. }
  68. //---------- End of function FirmRes::init -----------//
  69. //---------- Begin of function FirmRes::deinit -----------//
  70. void FirmRes::deinit()
  71. {
  72. if( init_flag )
  73. {
  74. mem_del(firm_info_array);
  75. mem_del(firm_build_array);
  76. mem_del(firm_bitmap_array);
  77. res_bitmap.deinit();
  78. init_flag=0;
  79. }
  80. }
  81. //---------- End of function FirmRes::deinit -----------//
  82. //------- Begin of function FirmRes::load_firm_bitmap -------//
  83. //
  84. // Read in information of FBITMAP.DBF into memory array
  85. //
  86. void FirmRes::load_firm_bitmap()
  87. {
  88. FirmBitmapRec *firmBitmapRec;
  89. FirmBitmap *firmBitmap;
  90. int i;
  91. long bitmapOffset;
  92. Database *dbFirmBitmap = game_set.open_db(FIRM_BITMAP_DB);
  93. firm_bitmap_count = (short) dbFirmBitmap->rec_count();
  94. firm_bitmap_array = (FirmBitmap*) mem_add( sizeof(FirmBitmap)*firm_bitmap_count );
  95. //------ read in firm bitmap info array -------//
  96. memset( firm_bitmap_array, 0, sizeof(FirmBitmap) * firm_bitmap_count );
  97. for( i=0 ; i<firm_bitmap_count ; i++ )
  98. {
  99. firmBitmapRec = (FirmBitmapRec*) dbFirmBitmap->read(i+1);
  100. firmBitmap = firm_bitmap_array+i;
  101. memcpy( &bitmapOffset, firmBitmapRec->bitmap_ptr, sizeof(long) );
  102. firmBitmap->bitmap_ptr = res_bitmap.read_imported(bitmapOffset);
  103. firmBitmap->width = *((short*)firmBitmap->bitmap_ptr);
  104. firmBitmap->height = *(((short*)firmBitmap->bitmap_ptr)+1);
  105. firmBitmap->offset_x = m.atoi( firmBitmapRec->offset_x, firmBitmapRec->OFFSET_LEN );
  106. firmBitmap->offset_y = m.atoi( firmBitmapRec->offset_y, firmBitmapRec->OFFSET_LEN );
  107. firmBitmap->loc_width = m.atoi( firmBitmapRec->loc_width , firmBitmapRec->LOC_LEN );
  108. firmBitmap->loc_height = m.atoi( firmBitmapRec->loc_height, firmBitmapRec->LOC_LEN );
  109. firmBitmap->display_layer = firmBitmapRec->layer - '0';
  110. }
  111. }
  112. //--------- End of function FirmRes::load_firm_bitmap ---------//
  113. //------- Begin of function FirmRes::load_firm_build -------//
  114. //
  115. // Read in information of FIRM.DBF into memory array
  116. //
  117. void FirmRes::load_firm_build()
  118. {
  119. FirmBuildRec *firmBuildRec;
  120. FirmFrameRec *firmFrameRec;
  121. FirmBuild *firmBuild;
  122. FirmBitmap *firmBitmap;
  123. int i, j, k, frameRecno, bitmapRecno;
  124. short *firstFrameArray;
  125. //---- read in firm count and initialize firm info array ----//
  126. Database *dbFirmBuild = game_set.open_db(FIRM_BUILD_DB); // only one database can be opened at a time, so we read FIRM.DBF first
  127. firm_build_count = (short) dbFirmBuild->rec_count();
  128. firm_build_array = (FirmBuild*) mem_add( sizeof(FirmBuild)*firm_build_count );
  129. memset( firm_build_array, 0, sizeof(FirmBuild) * firm_build_count );
  130. //------ allocate an array for storing firstFrameRecno -----//
  131. firstFrameArray = (short*) mem_add( sizeof(short) * firm_build_count );
  132. //---------- read in FBUILD.DBF ---------//
  133. for( i=0 ; i<firm_build_count ; i++ )
  134. {
  135. firmBuildRec = (FirmBuildRec*) dbFirmBuild->read(i+1);
  136. firmBuild = firm_build_array+i;
  137. m.rtrim_fld( firmBuild->build_code, firmBuildRec->race_code, firmBuild->BUILD_CODE_LEN );
  138. firmBuild->animate_full_size = firmBuildRec->animate_full_size=='1';
  139. firmBuild->race_id = m.atoi( firmBuildRec->race_id , firmBuildRec->RACE_ID_LEN );
  140. firmBuild->frame_count = m.atoi( firmBuildRec->frame_count, firmBuildRec->FRAME_COUNT_LEN );
  141. firmBuild->under_construction_bitmap_recno = m.atoi(firmBuildRec->under_construction_bitmap_recno, firmBuildRec->BITMAP_RECNO_LEN);
  142. // ##### begin Gilbert 18/10 ########//
  143. firmBuild->under_construction_bitmap_count =
  144. m.atoi(firmBuildRec->under_construction_bitmap_count, firmBuildRec->FRAME_COUNT_LEN);
  145. // ##### end Gilbert 18/10 ########//
  146. firmBuild->idle_bitmap_recno = m.atoi(firmBuildRec->idle_bitmap_recno, firmBuildRec->BITMAP_RECNO_LEN);
  147. firmBuild->ground_bitmap_recno = m.atoi(firmBuildRec->ground_bitmap_recno, firmBuildRec->BITMAP_RECNO_LEN);
  148. err_when( firmBuild->frame_count > MAX_FIRM_FRAME );
  149. firstFrameArray[i] = m.atoi( firmBuildRec->first_frame, firmBuildRec->FIRST_FRAME_LEN );
  150. }
  151. //-------- read in FFRAME.DBF --------//
  152. Database *dbFirmFrame = game_set.open_db(FIRM_FRAME_DB);
  153. int minOffsetX, minOffsetY;
  154. int maxX2, maxY2;
  155. for( i=0 ; i<firm_build_count ; i++ )
  156. {
  157. firmBuild = firm_build_array+i;
  158. frameRecno = firstFrameArray[i];
  159. minOffsetX = minOffsetY = 0xFFFF;
  160. maxX2 = maxY2 = 0;
  161. for( j=0 ; j<firmBuild->frame_count ; j++, frameRecno++ )
  162. {
  163. firmFrameRec = (FirmFrameRec*) dbFirmFrame->read(frameRecno);
  164. //------ following animation frames, bitmap sections -----//
  165. firmBuild->first_bitmap_array[j] = m.atoi( firmFrameRec->first_bitmap, firmFrameRec->FIRST_BITMAP_LEN );
  166. firmBuild->bitmap_count_array[j] = m.atoi( firmFrameRec->bitmap_count, firmFrameRec->BITMAP_COUNT_LEN );
  167. firmBuild->frame_delay_array[j] = m.atoi( firmFrameRec->delay, firmFrameRec->DELAY_LEN );
  168. //---- get the min offset_x, offset_y and max width, height ----//
  169. //
  170. // So we can get the largest area of all the frames in this building
  171. // and this will serve as a normal size setting for this building,
  172. // with variation from frame to frame
  173. //
  174. //--------------------------------------------------------------//
  175. firmBitmap = firm_bitmap_array + firmBuild->first_bitmap_array[j] - 1;
  176. for( k=firmBuild->bitmap_count_array[j] ; k>0 ; k--, firmBitmap++ )
  177. {
  178. if( firmBitmap->offset_x < minOffsetX )
  179. minOffsetX = firmBitmap->offset_x;
  180. if( firmBitmap->offset_y < minOffsetY )
  181. minOffsetY = firmBitmap->offset_y;
  182. if( firmBitmap->offset_x + firmBitmap->width > maxX2 )
  183. maxX2 = firmBitmap->offset_x + firmBitmap->width;
  184. if( firmBitmap->offset_y + firmBitmap->height > maxY2 )
  185. maxY2 = firmBitmap->offset_y + firmBitmap->height;
  186. }
  187. }
  188. //------- set FirmBuild Info -------//
  189. bitmapRecno = firmBuild->first_bitmap_array[0];
  190. //----- get the info of the first frame bitmap ----//
  191. firmBitmap = firm_bitmap_array + bitmapRecno - 1;
  192. firmBuild->loc_width = firmBitmap->loc_width;
  193. firmBuild->loc_height = firmBitmap->loc_height;
  194. firmBuild->min_offset_x = minOffsetX;
  195. firmBuild->min_offset_y = minOffsetY;
  196. firmBuild->max_bitmap_width = maxX2 - minOffsetX;
  197. firmBuild->max_bitmap_height = maxY2 - minOffsetY;
  198. //------ set firmBuild's under construction and idle bitmap recno -----//
  199. // ####### begin Gilbert 18/10 #######//
  200. if( firmBuild->under_construction_bitmap_recno==0 )
  201. {
  202. firmBuild->under_construction_bitmap_recno = bitmapRecno;
  203. firmBuild->under_construction_bitmap_count = 1;
  204. }
  205. err_when(firmBuild->under_construction_bitmap_count == 0);
  206. // ####### end Gilbert 18/10 #######//
  207. if( firmBuild->idle_bitmap_recno==0 )
  208. firmBuild->idle_bitmap_recno = bitmapRecno;
  209. }
  210. //------ free up the temporary array -------//
  211. mem_del( firstFrameArray );
  212. }
  213. //--------- End of function FirmRes::load_firm_build ---------//
  214. //------- Begin of function FirmRes::load_firm_info -------//
  215. //
  216. // Read in information of FIRM.DBF into memory array
  217. //
  218. void FirmRes::load_firm_info()
  219. {
  220. FirmRec *firmRec;
  221. FirmInfo *firmInfo;
  222. FirmBuild *firmBuild;
  223. int i;
  224. //---- read in firm count and initialize firm info array ----//
  225. Database *dbFirm = game_set.open_db(FIRM_DB); // only one database can be opened at a time, so we read FIRM.DBF first
  226. firm_count = (short) dbFirm->rec_count();
  227. firm_info_array = (FirmInfo*) mem_add( sizeof(FirmInfo)*firm_count );
  228. memset( firm_info_array, 0, sizeof(FirmInfo) * firm_count );
  229. //---------- read in FIRM.DBF ---------//
  230. for( i=0 ; i<firm_count ; i++ )
  231. {
  232. firmRec = (FirmRec*) dbFirm->read(i+1);
  233. firmInfo = firm_info_array+i;
  234. m.rtrim_fld( firmInfo->name, firmRec->name, firmRec->NAME_LEN );
  235. m.rtrim_fld( firmInfo->short_name, firmRec->short_name, firmRec->SHORT_NAME_LEN );
  236. m.rtrim_fld( firmInfo->overseer_title, firmRec->overseer_title, firmRec->TITLE_LEN );
  237. m.rtrim_fld( firmInfo->worker_title , firmRec->worker_title , firmRec->TITLE_LEN );
  238. #if(defined(GERMAN) || defined(FRENCH) || defined(SPANISH))
  239. translate.multi_to_win(firmInfo->name, firmInfo->NAME_LEN);
  240. translate.multi_to_win(firmInfo->short_name, firmInfo->SHORT_NAME_LEN);
  241. translate.multi_to_win(firmInfo->overseer_title, firmInfo->TITLE_LEN);
  242. translate.multi_to_win(firmInfo->worker_title, firmInfo->TITLE_LEN);
  243. #endif
  244. firmInfo->firm_id = i+1;
  245. firmInfo->tera_type = firmRec->tera_type-'0';
  246. firmInfo->live_in_town = firmRec->live_in_town=='1';
  247. firmInfo->max_hit_points = m.atoi( firmRec->hit_points, firmRec->HIT_POINTS_LEN );
  248. firmInfo->first_build_id = m.atoi( firmRec->first_build, firmRec->FIRST_BUILD_LEN );
  249. firmInfo->build_count = m.atoi( firmRec->build_count, firmRec->BUILD_COUNT_LEN );
  250. firmInfo->need_overseer = firmInfo->overseer_title[0] && firmInfo->overseer_title[0] != ' ';
  251. firmInfo->need_worker = firmInfo->worker_title[0] && firmInfo->worker_title[0] != ' ';
  252. firmInfo->is_linkable_to_town = firmRec->is_linkable_to_town=='1';
  253. firmInfo->setup_cost = m.atoi( firmRec->setup_cost, firmRec->COST_LEN );
  254. firmInfo->year_cost = m.atoi( firmRec->year_cost, firmRec->COST_LEN );
  255. firmInfo->buildable = firmInfo->setup_cost > 0;
  256. if( firmRec->all_know=='1' )
  257. memset( firmInfo->nation_tech_level_array, 1, sizeof(firmInfo->nation_tech_level_array) );
  258. //------- set loc_width & loc_height in FirmInfo --------//
  259. firmBuild = firm_build_array+firmInfo->first_build_id-1;
  260. firmInfo->loc_width = firmBuild->loc_width;
  261. firmInfo->loc_height = firmBuild->loc_height;
  262. //------------- set firm_race_id --------------//
  263. if( firmInfo->build_count==1 ) // if only one building style for this firm, take the race id. of the building as the race of the firm
  264. firmInfo->firm_race_id = (char) firmBuild->race_id;
  265. }
  266. }
  267. //--------- End of function FirmRes::load_firm_info ---------//
  268. //---------- Begin of function FirmRes::operator[] -----------//
  269. FirmInfo* FirmRes::operator[](int firmId)
  270. {
  271. err_if( firmId<1 || firmId>firm_count )
  272. err_now( "FirmRes::operator[]" );
  273. return firm_info_array+firmId-1;
  274. }
  275. //------------ End of function FirmRes::operator[] -----------//
  276. //-------- Start of function FirmInfo::can_build -------------//
  277. //
  278. // Whether unit of this race can build this firm or not.
  279. //
  280. // <int> unitRecno - check whether this unit knows how to build
  281. // this firm.
  282. //
  283. int FirmInfo::can_build(int unitRecno)
  284. {
  285. if( !buildable )
  286. return 0;
  287. Unit* unitPtr = unit_array[unitRecno];
  288. if( !unitPtr->nation_recno )
  289. return 0;
  290. if( !(get_nation_tech_level(unitPtr->nation_recno) > 0) )
  291. return 0;
  292. //------ fortress of power ------//
  293. if( firm_id == FIRM_BASE ) // only if the nation has acquired the myth to build it
  294. {
  295. if( unitPtr->rank_id == RANK_GENERAL ||
  296. unitPtr->rank_id == RANK_KING ||
  297. unitPtr->skill.skill_id == SKILL_PRAYING ||
  298. unitPtr->skill.skill_id == SKILL_CONSTRUCTION )
  299. {
  300. //----- each nation can only build one seat of power -----//
  301. if( unitPtr->nation_recno > 0 &&
  302. unitPtr->race_id > 0 &&
  303. nation_array[unitPtr->nation_recno]->base_count_array[unitPtr->race_id-1] == 0 )
  304. {
  305. //--- if this nation has acquired the needed scroll of power ---//
  306. return nation_array[unitPtr->nation_recno]->know_base_array[unitPtr->race_id-1];
  307. }
  308. }
  309. return 0;
  310. }
  311. //------ a king or a unit with construction skill knows how to build all buildings -----//
  312. if( firm_race_id == 0 )
  313. {
  314. if( unitPtr->rank_id == RANK_KING || unitPtr->skill.skill_id == SKILL_CONSTRUCTION )
  315. return 1;
  316. }
  317. //----- if the firm is race specific, if the unit is right race, return true ----//
  318. if( firm_race_id == unitPtr->race_id )
  319. return 1;
  320. //---- if the unit has the skill needed by the firm or the unit has general construction skill ----//
  321. if( firm_skill_id && firm_skill_id == unitPtr->skill.skill_id )
  322. return 1;
  323. return 0;
  324. }
  325. //--------- End of function FirmInfo::can_build ---------------//
  326. //-------- Start of function FirmInfo::is_linkable_to_firm -------------//
  327. //
  328. int FirmInfo::is_linkable_to_firm(int linkFirmId)
  329. {
  330. switch(firm_id)
  331. {
  332. case FIRM_FACTORY:
  333. return linkFirmId==FIRM_MINE || linkFirmId==FIRM_MARKET || linkFirmId==FIRM_HARBOR;
  334. case FIRM_MINE:
  335. return linkFirmId==FIRM_FACTORY || linkFirmId==FIRM_MARKET || linkFirmId==FIRM_HARBOR;
  336. case FIRM_MARKET:
  337. return linkFirmId==FIRM_MINE || linkFirmId==FIRM_FACTORY || linkFirmId==FIRM_HARBOR;
  338. case FIRM_INN: // for an inn to scan for neighbor inns quickly, the link line is not displayed
  339. return linkFirmId==FIRM_INN;
  340. case FIRM_HARBOR:
  341. return linkFirmId==FIRM_MARKET || linkFirmId==FIRM_MINE || linkFirmId==FIRM_FACTORY;
  342. default:
  343. return 0;
  344. }
  345. }
  346. //--------- End of function FirmInfo::is_linkable_to_firm ---------------//
  347. //------ Start of function FirmInfo::default_link_status --------//
  348. //
  349. // return: <int> 1 - the default status is <enable>
  350. // 0 - the default status is <disable>
  351. //
  352. int FirmInfo::default_link_status(int linkFirmId)
  353. {
  354. int rc;
  355. switch(firm_id)
  356. {
  357. case FIRM_MINE:
  358. rc = (linkFirmId!=FIRM_MARKET);
  359. break;
  360. case FIRM_FACTORY:
  361. rc = (linkFirmId==FIRM_MARKET) || (linkFirmId==FIRM_MINE);
  362. break;
  363. case FIRM_MARKET:
  364. rc = (linkFirmId==FIRM_FACTORY) || (linkFirmId==FIRM_HARBOR);
  365. break;
  366. case FIRM_HARBOR:
  367. rc = (linkFirmId==FIRM_MARKET) || (linkFirmId==FIRM_MINE) ||
  368. (linkFirmId==FIRM_FACTORY);
  369. break;
  370. default:
  371. rc = 1;
  372. }
  373. if( rc )
  374. return LINK_EE;
  375. else
  376. return LINK_DD;
  377. }
  378. //------- End of function FirmInfo::default_link_status -------//
  379. //-------- Start of function FirmInfo::get_build_id -------------//
  380. //
  381. // Give the build code and return the build id.
  382. //
  383. // <char*> buildCode - the build code
  384. //
  385. int FirmInfo::get_build_id(char* buildCode)
  386. {
  387. err_when( build_count<1 );
  388. if( build_count==1 ) // if this firm has only one building type
  389. return first_build_id;
  390. int firmBuildId = first_build_id;
  391. for( int i=0 ; i<build_count ; i++, firmBuildId++ ) // if this firm has one graphics for each race
  392. {
  393. if( strcmp(buildCode, firm_res.get_build(firmBuildId)->build_code)==0 )
  394. return firmBuildId;
  395. }
  396. err_here();
  397. return 0;
  398. }
  399. //--------- End of function FirmInfo::get_build_id ---------------//
  400. //---- Begin of function FirmInfo::inc_nation_firm_count ----//
  401. void FirmInfo::inc_nation_firm_count(int nationRecno)
  402. {
  403. err_when( nationRecno<1 || nationRecno>nation_array.size() );
  404. nation_firm_count_array[nationRecno-1]++;
  405. nation_array[nationRecno]->total_firm_count++;
  406. }
  407. //----- End of function FirmInfo::inc_nation_firm_count -----//
  408. //---- Begin of function FirmInfo::dec_nation_firm_count ----//
  409. void FirmInfo::dec_nation_firm_count(int nationRecno)
  410. {
  411. nation_firm_count_array[nationRecno-1]--;
  412. nation_array[nationRecno]->total_firm_count--;
  413. err_when( nation_firm_count_array[nationRecno-1] < 0 );
  414. if( nation_firm_count_array[nationRecno-1] < 0 ) // run-time bug fixing
  415. nation_firm_count_array[nationRecno-1] = 0;
  416. }
  417. //----- End of function FirmInfo::dec_nation_firm_count -----//
  418. //--------- begin of function FirmBitmap::draw_at ---------//
  419. void FirmBitmap::draw_at(int absX, int absY, char *colorRemapTable, int displayLayer)
  420. {
  421. // -------- skip if display layer is not correct --------//
  422. if( !(displayLayer & display_layer))
  423. return;
  424. //-------- check if the firm is within the view area --------//
  425. int x1 = absX + offset_x - World::view_top_x;
  426. int x2 = x1 + width -1;
  427. if( x1 >= ZOOM_WIDTH || x2 < 0)
  428. return;
  429. int y1 = absY + offset_y - World::view_top_y;
  430. int y2 = y1 + height -1;
  431. if( y1 >= ZOOM_HEIGHT || y2 < 0)
  432. return;
  433. //---- only portion of the sprite is inside the view area ------//
  434. if( x1 < 0 || x2 >= ZOOM_WIDTH || y1 < 0 || y2 >= ZOOM_HEIGHT )
  435. {
  436. int srcX1 = x1<0 ? -x1 : 0;
  437. int srcY1 = y1<0 ? -y1 : 0;
  438. int srcX2 = x2>=ZOOM_WIDTH ? ZOOM_WIDTH-1-x1 : width-1;
  439. int srcY2 = y2>=ZOOM_HEIGHT ? ZOOM_HEIGHT-1-y1 : height-1;
  440. if( colorRemapTable )
  441. {
  442. vga_back.put_bitmap_area_trans_remap_decompress( x1+ZOOM_X1, y1+ZOOM_Y1,
  443. bitmap_ptr, srcX1, srcY1, srcX2, srcY2, colorRemapTable );
  444. }
  445. else
  446. {
  447. vga_back.put_bitmap_area_trans_decompress( x1+ZOOM_X1, y1+ZOOM_Y1,
  448. bitmap_ptr, srcX1, srcY1, srcX2, srcY2 );
  449. }
  450. }
  451. //---- the whole sprite is inside the view area ------//
  452. else
  453. {
  454. if( colorRemapTable )
  455. {
  456. vga_back.put_bitmap_trans_remap_decompress( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, colorRemapTable );
  457. }
  458. else
  459. {
  460. vga_back.put_bitmap_trans_decompress( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr );
  461. }
  462. }
  463. }
  464. // --------- end of function FirmBitmap::draw_at ---------//