OGFILE3.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545
  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 : OGFILE3.CPP
  21. //Description : Object Game file, save game and restore game, part 3
  22. #include <OUNIT.h>
  23. #include <OBULLET.h>
  24. #include <OU_MARI.h>
  25. #include <OB_PROJ.h>
  26. #include <OSITE.h>
  27. #include <OTOWN.h>
  28. #include <ONATION.h>
  29. #include <OFIRM.h>
  30. #include <OTORNADO.h>
  31. #include <OREBEL.h>
  32. #include <OSPY.h>
  33. #include <OSNOWG.h>
  34. #include <OREGION.h>
  35. #include <OREGIONS.h>
  36. #include <ONEWS.h>
  37. #include <OGFILE.h>
  38. #include <OGF_V1.h>
  39. //------- declare static functions -------//
  40. static char* create_monster_func();
  41. static char* create_rebel_func();
  42. static void write_ai_info(File* filePtr, short* aiInfoArray, short aiInfoCount, short aiInfoSize);
  43. static void read_ai_info(File* filePtr, short** aiInfoArrayPtr, short& aiInfoCount, short& aiInfoSize);
  44. //-------- Start of function UnitArray::write_file -------------//
  45. //
  46. int UnitArray::write_file(File* filePtr)
  47. {
  48. int i;
  49. Unit *unitPtr;
  50. filePtr->file_put_short(restart_recno); // variable in SpriteArray
  51. filePtr->file_put_short( size() ); // no. of units in unit_array
  52. filePtr->file_put_short( selected_recno );
  53. filePtr->file_put_short( selected_count );
  54. filePtr->file_put_long ( cur_group_id );
  55. filePtr->file_put_long ( cur_team_id );
  56. filePtr->file_put_short(idle_blocked_unit_reset_count);
  57. filePtr->file_put_long (unit_search_tries);
  58. filePtr->file_put_short(unit_search_tries_flag);
  59. filePtr->file_put_short(visible_unit_count);
  60. filePtr->file_put_short(mp_first_frame_to_select_caravan);
  61. filePtr->file_put_short(mp_first_frame_to_select_ship);
  62. filePtr->file_put_short(mp_pre_selected_caravan_recno);
  63. filePtr->file_put_short(mp_pre_selected_ship_recno);
  64. for( i=1; i<=size() ; i++ )
  65. {
  66. unitPtr = (Unit*) get_ptr(i);
  67. //----- write unitId or 0 if the unit is deleted -----//
  68. if( !unitPtr ) // the unit is deleted
  69. {
  70. filePtr->file_put_short(0);
  71. }
  72. else
  73. {
  74. //--------- write unit_id -------------//
  75. filePtr->file_put_short(unitPtr->unit_id);
  76. //------ write data in the base class ------//
  77. if( !unitPtr->write_file(filePtr) )
  78. return 0;
  79. //------ write data in the derived class ------//
  80. if( !unitPtr->write_derived_file(filePtr) )
  81. return 0;
  82. }
  83. }
  84. //------- write empty room array --------//
  85. write_empty_room(filePtr);
  86. return 1;
  87. }
  88. //--------- End of function UnitArray::write_file ---------------//
  89. //-------- Start of function UnitArray::read_file -------------//
  90. //
  91. int UnitArray::read_file(File* filePtr)
  92. {
  93. Unit* unitPtr;
  94. int i, unitId, emptyRoomCount=0;
  95. restart_recno = filePtr->file_get_short();
  96. int unitCount = filePtr->file_get_short(); // get no. of units from file
  97. selected_recno = filePtr->file_get_short();
  98. selected_count = filePtr->file_get_short();
  99. cur_group_id = filePtr->file_get_long();
  100. cur_team_id = filePtr->file_get_long();
  101. idle_blocked_unit_reset_count = filePtr->file_get_short();
  102. unit_search_tries = filePtr->file_get_long ();
  103. unit_search_tries_flag = (char) filePtr->file_get_short();
  104. visible_unit_count = filePtr->file_get_short();
  105. mp_first_frame_to_select_caravan = (char) filePtr->file_get_short();
  106. mp_first_frame_to_select_ship = (char) filePtr->file_get_short();
  107. mp_pre_selected_caravan_recno = filePtr->file_get_short();
  108. mp_pre_selected_ship_recno = filePtr->file_get_short();
  109. for( i=1 ; i<=unitCount ; i++ )
  110. {
  111. unitId = filePtr->file_get_short();
  112. if( unitId==0 ) // the unit has been deleted
  113. {
  114. add_blank(1); // it's a DynArrayB function
  115. emptyRoomCount++;
  116. }
  117. else
  118. {
  119. //----- create unit object -----------//
  120. unitPtr = create_unit( unitId );
  121. unitPtr->unit_id = unitId;
  122. //---- read data in base class -----//
  123. if( !unitPtr->read_file( filePtr ) )
  124. return 0;
  125. //----- read data in derived class -----//
  126. if( !unitPtr->read_derived_file( filePtr ) )
  127. return 0;
  128. }
  129. }
  130. //-------- linkout() those record added by add_blank() ----------//
  131. //-- So they will be marked deleted in DynArrayB and can be -----//
  132. //-- undeleted and used when a new record is going to be added --//
  133. for( i=size() ; i>0 ; i-- )
  134. {
  135. DynArrayB::go(i); // since UnitArray has its own go() which will call GroupArray::go()
  136. if( get_ptr() == NULL ) // add_blank() record
  137. linkout();
  138. }
  139. //------- read empty room array --------//
  140. read_empty_room(filePtr);
  141. //------- verify the empty_room_array loading -----//
  142. #ifdef DEBUG
  143. err_when( empty_room_count != emptyRoomCount );
  144. for( i=0 ; i<empty_room_count ; i++ )
  145. {
  146. if( !is_deleted( empty_room_array[i].recno ) )
  147. err_here();
  148. }
  149. #endif
  150. return 1;
  151. }
  152. //--------- End of function UnitArray::read_file ---------------//
  153. //--------- Begin of function Unit::write_file ---------//
  154. //
  155. // Write data in derived class.
  156. //
  157. // If the derived Unit don't have any special data,
  158. // just use Unit::write_file(), otherwise make its own derived copy of write_file()
  159. //
  160. int Unit::write_file(File* filePtr)
  161. {
  162. if( !filePtr->file_write( this, sizeof(Unit) ) )
  163. return 0;
  164. //--------------- write memory data ----------------//
  165. if( result_node_array )
  166. {
  167. if( !filePtr->file_write( result_node_array, sizeof(ResultNode) * result_node_count ) )
  168. return 0;
  169. }
  170. //### begin alex 15/10 ###//
  171. if(way_point_array)
  172. {
  173. err_when(way_point_array_size==0 || way_point_array_size<way_point_count);
  174. if(!filePtr->file_write(way_point_array, sizeof(ResultNode)*way_point_array_size))
  175. return 0;
  176. }
  177. //#### end alex 15/10 ####//
  178. if( team_info )
  179. {
  180. if( !filePtr->file_write( team_info, sizeof(TeamInfo) ) )
  181. return 0;
  182. }
  183. return 1;
  184. }
  185. //----------- End of function Unit::write_file ---------//
  186. //--------- Begin of function Unit::read_file ---------//
  187. //
  188. int Unit::read_file(File* filePtr)
  189. {
  190. char* vfPtr = *((char**)this); // save the virtual function table pointer
  191. if( !filePtr->file_read( this, sizeof(Unit) ) )
  192. return 0;
  193. *((char**)this) = vfPtr;
  194. //--------------- read in memory data ----------------//
  195. if( result_node_array )
  196. {
  197. result_node_array = (ResultNode*) mem_add( sizeof(ResultNode) * result_node_count );
  198. if( !filePtr->file_read( result_node_array, sizeof(ResultNode) * result_node_count ) )
  199. return 0;
  200. }
  201. //### begin alex 15/10 ###//
  202. if(way_point_array)
  203. {
  204. way_point_array = (ResultNode*) mem_add(sizeof(ResultNode) * way_point_array_size);
  205. if(!filePtr->file_read(way_point_array, sizeof(ResultNode)*way_point_array_size))
  206. return 0;
  207. }
  208. //#### end alex 15/10 ####//
  209. if( team_info )
  210. {
  211. team_info = (TeamInfo*) mem_add( sizeof(TeamInfo) );
  212. if( !filePtr->file_read( team_info, sizeof(TeamInfo) ) )
  213. return 0;
  214. }
  215. //----------- post-process the data read ----------//
  216. // attack_info_array = unit_res.attack_info_array+unit_res[unit_id]->first_attack-1;
  217. sprite_info = sprite_res[sprite_id];
  218. sprite_info->load_bitmap_res();
  219. //--------- special process of UNIT_MARINE --------//
  220. // move to read_derived_file
  221. //if( unit_res[unit_id]->unit_class == UNIT_CLASS_SHIP )
  222. //{
  223. // ((UnitMarine*)this)->splash.sprite_info = sprite_res[sprite_id];
  224. // ((UnitMarine*)this)->splash.sprite_info->load_bitmap_res();
  225. //}
  226. return 1;
  227. }
  228. //----------- End of function Unit::read_file ---------//
  229. //--------- Begin of function Unit::write_derived_file ---------//
  230. //
  231. int Unit::write_derived_file(File* filePtr)
  232. {
  233. //--- write data in derived class -----//
  234. int writeSize = unit_array.unit_class_size(unit_id)-sizeof(Unit);
  235. if( writeSize > 0 )
  236. {
  237. if( !filePtr->file_write( (char*) this + sizeof(Unit), writeSize ) )
  238. return 0;
  239. }
  240. return 1;
  241. }
  242. //----------- End of function Unit::write_derived_file ---------//
  243. //--------- Begin of function Unit::read_derived_file ---------//
  244. //
  245. int Unit::read_derived_file(File* filePtr)
  246. {
  247. //--- read data in derived class -----//
  248. int readSize = unit_array.unit_class_size(unit_id) - sizeof(Unit);
  249. if( readSize > 0 )
  250. {
  251. if( !filePtr->file_read( (char*) this + sizeof(Unit), readSize ) )
  252. return 0;
  253. }
  254. // ###### begin Gilbert 13/8 #######//
  255. fix_attack_info();
  256. // ###### end Gilbert 13/8 #######//
  257. return 1;
  258. }
  259. //----------- End of function Unit::read_derived_file ---------//
  260. //--------- Begin of function UnitMarine::read_derived_file ---------//
  261. int UnitMarine::read_derived_file(File* filePtr)
  262. {
  263. //---- backup virtual functions table pointer of splash ----//
  264. char* splashVfPtr = *((char **)&splash);
  265. //--------- read file --------//
  266. if( !Unit::read_derived_file(filePtr) )
  267. return 0;
  268. // -------- restore virtual function table pointer -------//
  269. *((char **)&splash) = splashVfPtr ;
  270. // ------- post-process the data read --------//
  271. splash.sprite_info = sprite_res[splash.sprite_id];
  272. splash.sprite_info->load_bitmap_res();
  273. return 1;
  274. }
  275. //--------- End of function UnitMarine::read_derived_file ---------//
  276. //*****//
  277. //-------- Start of function BulletArray::write_file -------------//
  278. //
  279. int BulletArray::write_file(File* filePtr)
  280. {
  281. filePtr->file_put_short(restart_recno); // variable in SpriteArray
  282. int i, emptyRoomCount=0;;
  283. Bullet *bulletPtr;
  284. filePtr->file_put_short( size() ); // no. of bullets in bullet_array
  285. for( i=1; i<=size() ; i++ )
  286. {
  287. bulletPtr = (Bullet*) get_ptr(i);
  288. //----- write bulletId or 0 if the bullet is deleted -----//
  289. if( !bulletPtr ) // the bullet is deleted
  290. {
  291. filePtr->file_put_short(0);
  292. emptyRoomCount++;
  293. }
  294. else
  295. {
  296. filePtr->file_put_short(bulletPtr->sprite_id); // there is a bullet in this record
  297. //------ write data in the base class ------//
  298. if( !bulletPtr->write_file(filePtr) )
  299. return 0;
  300. //------ write data in the derived class -------//
  301. if( !bulletPtr->write_derived_file(filePtr) )
  302. return 0;
  303. }
  304. }
  305. //------- write empty room array --------//
  306. write_empty_room(filePtr);
  307. //------- verify the empty_room_array loading -----//
  308. #ifdef DEBUG
  309. err_when( empty_room_count != emptyRoomCount );
  310. for( i=0 ; i<empty_room_count ; i++ )
  311. {
  312. if( !is_deleted( empty_room_array[i].recno ) )
  313. err_here();
  314. }
  315. #endif
  316. return 1;
  317. }
  318. //--------- End of function BulletArray::write_file -------------//
  319. //-------- Start of function BulletArray::read_file -------------//
  320. //
  321. int BulletArray::read_file(File* filePtr)
  322. {
  323. restart_recno = filePtr->file_get_short();
  324. int i, bulletRecno, bulletCount, emptyRoomCount=0, spriteId;
  325. Bullet* bulletPtr;
  326. bulletCount = filePtr->file_get_short(); // get no. of bullets from file
  327. for( i=1 ; i<=bulletCount ; i++ )
  328. {
  329. spriteId = filePtr->file_get_short();
  330. if( spriteId == 0 )
  331. {
  332. add_blank(1); // it's a DynArrayB function
  333. emptyRoomCount++;
  334. }
  335. else
  336. {
  337. //----- create bullet object -----------//
  338. bulletRecno = create_bullet(spriteId);
  339. bulletPtr = bullet_array[bulletRecno];
  340. //----- read data in base class --------//
  341. if( !bulletPtr->read_file( filePtr ) )
  342. return 0;
  343. //----- read data in derived class -----//
  344. if( !bulletPtr->read_derived_file( filePtr ) )
  345. return 0;
  346. }
  347. }
  348. //-------- linkout() those record added by add_blank() ----------//
  349. //-- So they will be marked deleted in DynArrayB and can be -----//
  350. //-- undeleted and used when a new record is going to be added --//
  351. for( i=1 ; i<=size() ; i++ )
  352. {
  353. DynArrayB::go(i); // since BulletArray has its own go() which will call GroupArray::go()
  354. if( get_ptr() == NULL ) // add_blank() record
  355. linkout();
  356. }
  357. //------- read empty room array --------//
  358. read_empty_room(filePtr);
  359. //------- verify the empty_room_array loading -----//
  360. #ifdef DEBUG
  361. err_when( empty_room_count != emptyRoomCount );
  362. for( i=0 ; i<empty_room_count ; i++ )
  363. {
  364. if( !is_deleted( empty_room_array[i].recno ) )
  365. err_here();
  366. }
  367. #endif
  368. return 1;
  369. }
  370. //--------- End of function BulletArray::read_file ---------------//
  371. //--------- Begin of function Bullet::write_file ---------//
  372. //
  373. int Bullet::write_file(File* filePtr)
  374. {
  375. if( !filePtr->file_write( this, sizeof(Bullet) ) )
  376. return 0;
  377. return 1;
  378. }
  379. //----------- End of function Bullet::write_file ---------//
  380. //--------- Begin of function Bullet::read_file ---------//
  381. //
  382. int Bullet::read_file(File* filePtr)
  383. {
  384. char* vfPtr = *((char**)this); // save the virtual function table pointer
  385. if( !filePtr->file_read( this, sizeof(Bullet) ) )
  386. return 0;
  387. *((char**)this) = vfPtr;
  388. //------------ post-process the data read ----------//
  389. sprite_info = sprite_res[sprite_id];
  390. sprite_info->load_bitmap_res();
  391. return 1;
  392. }
  393. //----------- End of function Bullet::read_file ---------//
  394. //----------- Begin of function Bullet::write_derived_file ---------//
  395. int Bullet::write_derived_file(File *filePtr)
  396. {
  397. //--- write data in derived class -----//
  398. int writeSize = bullet_array.bullet_class_size(sprite_id)-sizeof(Bullet);
  399. if( writeSize > 0 )
  400. {
  401. if( !filePtr->file_write( (char*) this + sizeof(Bullet), writeSize ) )
  402. return 0;
  403. }
  404. return 1;
  405. }
  406. //----------- End of function Bullet::write_derived_file ---------//
  407. //----------- Begin of function Bullet::read_derived_file ---------//
  408. int Bullet::read_derived_file(File *filePtr)
  409. {
  410. //--- read data in derived class -----//
  411. int readSize = bullet_array.bullet_class_size(sprite_id) - sizeof(Bullet);
  412. if( readSize > 0 )
  413. {
  414. if( !filePtr->file_read( (char*) this + sizeof(Bullet), readSize ) )
  415. return 0;
  416. }
  417. return 1;
  418. }
  419. //----------- End of function Bullet::read_derived_file ---------//
  420. //----------- Begin of function Projectile::read_derived_file ---------//
  421. int Projectile::read_derived_file(File *filePtr)
  422. {
  423. //--- backup virtual function table pointer of act_bullet and bullet_shadow ---//
  424. char* actBulletVfPtr = *((char**)&act_bullet);
  425. char* bulletShadowVfPtr = *((char**)&bullet_shadow);
  426. //---------- read file ----------//
  427. if( !Bullet::read_derived_file(filePtr) )
  428. return 0;
  429. //------ restore virtual function table pointer --------//
  430. *((char**)&act_bullet) = actBulletVfPtr;
  431. *((char**)&bullet_shadow) = bulletShadowVfPtr;
  432. //----------- post-process the data read ----------//
  433. act_bullet.sprite_info = sprite_res[act_bullet.sprite_id];
  434. act_bullet.sprite_info->load_bitmap_res();
  435. bullet_shadow.sprite_info = sprite_res[bullet_shadow.sprite_id];
  436. bullet_shadow.sprite_info->load_bitmap_res();
  437. return 1;
  438. }
  439. //----------- End of function Projectile::read_derived_file ---------//
  440. //*****//
  441. //-------- Start of function FirmArray::write_file -------------//
  442. //
  443. int FirmArray::write_file(File* filePtr)
  444. {
  445. int i;
  446. Firm *firmPtr;
  447. filePtr->file_put_short( size() ); // no. of firms in firm_array
  448. filePtr->file_put_short( process_recno );
  449. filePtr->file_put_short( selected_recno );
  450. filePtr->file_put_short( Firm::firm_menu_mode );
  451. filePtr->file_put_short( Firm::action_spy_recno );
  452. filePtr->file_put_short( Firm::bribe_result );
  453. filePtr->file_put_short( Firm::assassinate_result );
  454. for( i=1; i<=size() ; i++ )
  455. {
  456. firmPtr = (Firm*) get_ptr(i);
  457. //----- write firmId or 0 if the firm is deleted -----//
  458. if( !firmPtr ) // the firm is deleted
  459. {
  460. filePtr->file_put_short(0);
  461. }
  462. else
  463. {
  464. //--------- write firm_id -------------//
  465. filePtr->file_put_short(firmPtr->firm_id);
  466. //------ write data in base class --------//
  467. if( !filePtr->file_write( firmPtr, sizeof(Firm) ) )
  468. return 0;
  469. //--------- write worker_array ---------//
  470. if( firmPtr->worker_array )
  471. {
  472. if( !filePtr->file_write( firmPtr->worker_array, MAX_WORKER*sizeof(Worker) ) )
  473. return 0;
  474. }
  475. //------ write data in derived class ------//
  476. if( !firmPtr->write_derived_file(filePtr) )
  477. return 0;
  478. }
  479. }
  480. //------- write empty room array --------//
  481. write_empty_room(filePtr);
  482. return 1;
  483. }
  484. //--------- End of function FirmArray::write_file ---------------//
  485. //-------- Start of function FirmArray::read_file -------------//
  486. //
  487. int FirmArray::read_file(File* filePtr)
  488. {
  489. Firm* firmPtr;
  490. char* vfPtr;
  491. int i, firmId, firmRecno;
  492. int firmCount = filePtr->file_get_short(); // get no. of firms from file
  493. process_recno = filePtr->file_get_short();
  494. selected_recno = filePtr->file_get_short();
  495. Firm::firm_menu_mode = (char) filePtr->file_get_short();
  496. Firm::action_spy_recno = filePtr->file_get_short();
  497. Firm::bribe_result = (char) filePtr->file_get_short();
  498. Firm::assassinate_result = (char) filePtr->file_get_short();
  499. for( i=1 ; i<=firmCount ; i++ )
  500. {
  501. firmId = filePtr->file_get_short();
  502. if( firmId==0 ) // the firm has been deleted
  503. {
  504. add_blank(1); // it's a DynArrayB function
  505. }
  506. else
  507. {
  508. //----- create firm object -----------//
  509. firmRecno = create_firm( firmId );
  510. firmPtr = firm_array[firmRecno];
  511. //---- read data in base class -----//
  512. vfPtr = *((char**)firmPtr); // save the virtual function table pointer
  513. if( !filePtr->file_read( firmPtr, sizeof(Firm) ) )
  514. return 0;
  515. #ifdef AMPLUS
  516. if(!game_file_array.same_version && firmPtr->firm_id > FIRM_BASE)
  517. firmPtr->firm_build_id += MAX_RACE - VERSION_1_MAX_RACE;
  518. #endif
  519. *((char**)firmPtr) = vfPtr;
  520. //--------- read worker_array ---------//
  521. if( firm_res[firmId]->need_worker )
  522. {
  523. firmPtr->worker_array = (Worker*) mem_add( MAX_WORKER*sizeof(Worker) );
  524. if( !filePtr->file_read( firmPtr->worker_array, MAX_WORKER*sizeof(Worker) ) )
  525. return 0;
  526. }
  527. //----- read data in derived class -----//
  528. if( !firmPtr->read_derived_file( filePtr ) )
  529. return 0;
  530. }
  531. }
  532. //-------- linkout() those record added by add_blank() ----------//
  533. //-- So they will be marked deleted in DynArrayB and can be -----//
  534. //-- undeleted and used when a new record is going to be added --//
  535. for( i=size() ; i>0 ; i-- )
  536. {
  537. DynArrayB::go(i); // since FirmArray has its own go() which will call GroupArray::go()
  538. if( get_ptr() == NULL ) // add_blank() record
  539. linkout();
  540. }
  541. //------- read empty room array --------//
  542. read_empty_room(filePtr);
  543. return 1;
  544. }
  545. //--------- End of function FirmArray::read_file ---------------//
  546. //--------- Begin of function Firm::write_derived_file ---------//
  547. //
  548. // Write data in derived class.
  549. //
  550. // If the derived Firm don't have any special data,
  551. // just use Firm::write_file(), otherwise make its own derived copy of write_file()
  552. //
  553. int Firm::write_derived_file(File* filePtr)
  554. {
  555. //--- write data in derived class -----//
  556. int writeSize = firm_array.firm_class_size(firm_id)-sizeof(Firm);
  557. if( writeSize > 0 )
  558. {
  559. if( !filePtr->file_write( (char*) this + sizeof(Firm), writeSize ) )
  560. return 0;
  561. }
  562. return 1;
  563. }
  564. //----------- End of function Firm::write_derived_file ---------//
  565. //--------- Begin of function Firm::read_derived_file ---------//
  566. //
  567. // Read data in derived class.
  568. //
  569. // If the derived Firm don't have any special data,
  570. // just use Firm::read_file(), otherwise make its own derived copy of read_file()
  571. //
  572. int Firm::read_derived_file(File* filePtr)
  573. {
  574. //--- read data in derived class -----//
  575. int readSize = firm_array.firm_class_size(firm_id)-sizeof(Firm);
  576. if( readSize > 0 )
  577. {
  578. if( !filePtr->file_read( (char*) this + sizeof(Firm), readSize ) )
  579. return 0;
  580. }
  581. return 1;
  582. }
  583. //----------- End of function Firm::read_derived_file ---------//
  584. //*****//
  585. //-------- Start of function SiteArray::write_file -------------//
  586. //
  587. int SiteArray::write_file(File* filePtr)
  588. {
  589. filePtr->file_put_short(selected_recno);
  590. filePtr->file_put_short(untapped_raw_count);
  591. filePtr->file_put_short(scroll_count);
  592. filePtr->file_put_short(gold_coin_count);
  593. filePtr->file_put_short(std_raw_site_count);
  594. return DynArrayB::write_file( filePtr );
  595. }
  596. //--------- End of function SiteArray::write_file ---------------//
  597. //-------- Start of function SiteArray::read_file -------------//
  598. //
  599. int SiteArray::read_file(File* filePtr)
  600. {
  601. selected_recno = filePtr->file_get_short();
  602. untapped_raw_count = filePtr->file_get_short();
  603. scroll_count = filePtr->file_get_short();
  604. gold_coin_count = filePtr->file_get_short();
  605. std_raw_site_count = filePtr->file_get_short();
  606. return DynArrayB::read_file( filePtr );
  607. }
  608. //--------- End of function SiteArray::read_file ---------------//
  609. //*****//
  610. //-------- Start of function TownArray::write_file -------------//
  611. //
  612. int TownArray::write_file(File* filePtr)
  613. {
  614. int i;
  615. Town *townPtr;
  616. filePtr->file_put_short( size() ); // no. of towns in town_array
  617. filePtr->file_put_short( selected_recno );
  618. filePtr->file_write( race_wander_pop_array, sizeof(race_wander_pop_array) );
  619. filePtr->file_put_short( Town::if_town_recno );
  620. //-----------------------------------------//
  621. for( i=1; i<=size() ; i++ )
  622. {
  623. townPtr = (Town*) get_ptr(i);
  624. //----- write townId or 0 if the town is deleted -----//
  625. if( !townPtr ) // the town is deleted
  626. {
  627. filePtr->file_put_short(0);
  628. }
  629. else
  630. {
  631. #ifdef DEBUG
  632. townPtr->verify_slot_object_id_array(); // for debugging only
  633. #endif
  634. filePtr->file_put_short(1); // the town exists
  635. if( !filePtr->file_write( townPtr, sizeof(Town) ) )
  636. return 0;
  637. }
  638. }
  639. //------- write empty room array --------//
  640. write_empty_room(filePtr);
  641. return 1;
  642. }
  643. //--------- End of function TownArray::write_file ---------------//
  644. //-------- Start of function TownArray::read_file -------------//
  645. //
  646. int TownArray::read_file(File* filePtr)
  647. {
  648. Town* townPtr;
  649. int i;
  650. int townCount = filePtr->file_get_short(); // get no. of towns from file
  651. selected_recno = filePtr->file_get_short();
  652. #ifdef AMPLUS
  653. if(!game_file_array.same_version)
  654. {
  655. memset(race_wander_pop_array, 0, sizeof(race_wander_pop_array));
  656. filePtr->file_read( race_wander_pop_array, sizeof(race_wander_pop_array[0])*VERSION_1_MAX_RACE );
  657. }
  658. else
  659. filePtr->file_read( race_wander_pop_array, sizeof(race_wander_pop_array) );
  660. #else
  661. filePtr->file_read( race_wander_pop_array, sizeof(race_wander_pop_array) );
  662. #endif
  663. Town::if_town_recno = filePtr->file_get_short();
  664. //------------------------------------------//
  665. for( i=1 ; i<=townCount ; i++ )
  666. {
  667. if( filePtr->file_get_short()==0 ) // the town has been deleted
  668. {
  669. add_blank(1); // it's a DynArrayB function
  670. }
  671. else
  672. {
  673. townPtr = town_array.create_town();
  674. #ifdef AMPLUS
  675. if(!game_file_array.same_version)
  676. {
  677. Version_1_Town *oldTown = (Version_1_Town*) mem_add(sizeof(Version_1_Town));
  678. if(!filePtr->file_read(oldTown, sizeof(Version_1_Town)))
  679. {
  680. mem_del(oldTown);
  681. return 0;
  682. }
  683. oldTown->convert_to_version_2(townPtr);
  684. mem_del(oldTown);
  685. }
  686. else
  687. {
  688. if( !filePtr->file_read( townPtr, sizeof(Town) ) )
  689. return 0;
  690. }
  691. #else
  692. if( !filePtr->file_read( townPtr, sizeof(Town) ) )
  693. return 0;
  694. #endif
  695. #ifdef DEBUG
  696. townPtr->verify_slot_object_id_array(); // for debugging only
  697. #endif
  698. }
  699. }
  700. //-------- linkout() those record added by add_blank() ----------//
  701. //-- So they will be marked deleted in DynArrayB and can be -----//
  702. //-- undeleted and used when a new record is going to be added --//
  703. for( i=size() ; i>0 ; i-- )
  704. {
  705. DynArrayB::go(i); // since TownArray has its own go() which will call GroupArray::go()
  706. if( get_ptr() == NULL ) // add_blank() record
  707. linkout();
  708. }
  709. //------- read empty room array --------//
  710. read_empty_room(filePtr);
  711. return 1;
  712. }
  713. //--------- End of function TownArray::read_file ---------------//
  714. //*****//
  715. //-------- Start of function NationArray::write_file -------------//
  716. //
  717. int NationArray::write_file(File* filePtr)
  718. {
  719. //------ write info in NationArray ------//
  720. if( !filePtr->file_write( (char*) this + sizeof(DynArrayB), sizeof(NationArray)-sizeof(DynArrayB) ) )
  721. return 0;
  722. //---------- write Nations --------------//
  723. int i;
  724. Nation *nationPtr;
  725. filePtr->file_put_short( size() ); // no. of nations in nation_array
  726. for( i=1; i<=size() ; i++ )
  727. {
  728. nationPtr = (Nation*) get_ptr(i);
  729. //----- write nationId or 0 if the nation is deleted -----//
  730. if( !nationPtr ) // the nation is deleted
  731. {
  732. filePtr->file_put_short(0);
  733. }
  734. else
  735. {
  736. filePtr->file_put_short(1); // there is a nation in this record
  737. //------ write data in the base class ------//
  738. if( !nationPtr->write_file(filePtr) )
  739. return 0;
  740. }
  741. }
  742. //------- write empty room array --------//
  743. write_empty_room(filePtr);
  744. return 1;
  745. }
  746. //--------- End of function NationArray::write_file -------------//
  747. //-------- Start of function NationArray::read_file -------------//
  748. //
  749. int NationArray::read_file(File* filePtr)
  750. {
  751. //------ read info in NationArray ------//
  752. #ifdef AMPLUS
  753. if(!game_file_array.same_version)
  754. {
  755. Version_1_NationArray *oldNationArrayPtr = (Version_1_NationArray*) mem_add(sizeof(Version_1_NationArray));
  756. //if( !filePtr->file_read( (char*) oldNationArrayPtr + sizeof(DynArrayB), sizeof(Version_1_NationArray)-sizeof(DynArrayB) ) )
  757. if( !filePtr->file_read( (char*) oldNationArrayPtr, sizeof(Version_1_NationArray) ) )
  758. {
  759. mem_del(oldNationArrayPtr);
  760. return 0;
  761. }
  762. oldNationArrayPtr->convert_to_version_2(this);
  763. mem_del(oldNationArrayPtr);
  764. }
  765. else
  766. {
  767. if( !filePtr->file_read( (char*) this + sizeof(DynArrayB), sizeof(NationArray)-sizeof(DynArrayB) ) )
  768. return 0;
  769. }
  770. #else
  771. if( !filePtr->file_read( (char*) this + sizeof(DynArrayB), sizeof(NationArray)-sizeof(DynArrayB) ) )
  772. return 0;
  773. #endif
  774. //---------- read Nations --------------//
  775. int i, nationRecno, nationCount;
  776. Nation* nationPtr;
  777. nationCount = filePtr->file_get_short(); // get no. of nations from file
  778. for( i=1 ; i<=nationCount ; i++ )
  779. {
  780. if( filePtr->file_get_short() == 0 )
  781. {
  782. add_blank(1); // it's a DynArrayB function
  783. }
  784. else
  785. {
  786. //----- create nation object -----------//
  787. nationRecno = create_nation();
  788. nationPtr = nation_array[nationRecno];
  789. //----- read data in base class --------//
  790. if( !nationPtr->read_file( filePtr ) )
  791. return 0;
  792. }
  793. }
  794. //-------- linkout() those record added by add_blank() ----------//
  795. //-- So they will be marked deleted in DynArrayB and can be -----//
  796. //-- undeleted and used when a new record is going to be added --//
  797. for( i=size() ; i>0 ; i-- )
  798. {
  799. DynArrayB::go(i); // since NationArray has its own go() which will call GroupArray::go()
  800. if( get_ptr() == NULL ) // add_blank() record
  801. linkout();
  802. }
  803. //-------- set NationArray::player_ptr -----------//
  804. player_ptr = nation_array[player_recno];
  805. //------- read empty room array --------//
  806. read_empty_room(filePtr);
  807. return 1;
  808. }
  809. //--------- End of function NationArray::read_file ---------------//
  810. //--------- Begin of function Nation::write_file ---------//
  811. //
  812. int Nation::write_file(File* filePtr)
  813. {
  814. if( !filePtr->file_write( this, sizeof(Nation) ) )
  815. return 0;
  816. //----------- write AI Action Array ------------//
  817. action_array.write_file(filePtr);
  818. //------ write AI info array ---------//
  819. write_ai_info(filePtr, ai_town_array, ai_town_count, ai_town_size);
  820. write_ai_info(filePtr, ai_base_array, ai_base_count, ai_base_size);
  821. write_ai_info(filePtr, ai_mine_array, ai_mine_count, ai_mine_size);
  822. write_ai_info(filePtr, ai_factory_array, ai_factory_count, ai_factory_size);
  823. write_ai_info(filePtr, ai_market_array, ai_market_count, ai_market_size);
  824. write_ai_info(filePtr, ai_inn_array, ai_inn_count, ai_inn_size);
  825. write_ai_info(filePtr, ai_camp_array, ai_camp_count, ai_camp_size);
  826. write_ai_info(filePtr, ai_research_array, ai_research_count, ai_research_size);
  827. write_ai_info(filePtr, ai_war_array, ai_war_count, ai_war_size);
  828. write_ai_info(filePtr, ai_harbor_array, ai_harbor_count, ai_harbor_size);
  829. write_ai_info(filePtr, ai_caravan_array, ai_caravan_count, ai_caravan_size);
  830. write_ai_info(filePtr, ai_ship_array, ai_ship_count, ai_ship_size);
  831. write_ai_info(filePtr, ai_general_array, ai_general_count, ai_general_size);
  832. return 1;
  833. }
  834. //----------- End of function Nation::write_file ---------//
  835. //--------- Begin of static function write_ai_info ---------//
  836. //
  837. static void write_ai_info(File* filePtr, short* aiInfoArray, short aiInfoCount, short aiInfoSize)
  838. {
  839. filePtr->file_put_short( aiInfoCount );
  840. filePtr->file_put_short( aiInfoSize );
  841. filePtr->file_write( aiInfoArray, sizeof(short) * aiInfoCount );
  842. }
  843. //----------- End of static function write_ai_info ---------//
  844. //--------- Begin of function Nation::read_file ---------//
  845. //
  846. int Nation::read_file(File* filePtr)
  847. {
  848. char* vfPtr = *((char**)this); // save the virtual function table pointer
  849. //---- save the action_array first before loading in the whole Nation class ----//
  850. char* saveActionArray = (char*) mem_add( sizeof(DynArray) );
  851. memcpy( saveActionArray, &action_array, sizeof(DynArray) );
  852. //--------------------------------------------------//
  853. #ifdef AMPLUS
  854. if(!game_file_array.same_version)
  855. {
  856. Version_1_Nation *oldNationPtr = (Version_1_Nation*) mem_add(sizeof(Version_1_Nation));
  857. if(!filePtr->file_read(oldNationPtr, sizeof(Version_1_Nation)))
  858. {
  859. mem_del(oldNationPtr);
  860. return 0;
  861. }
  862. oldNationPtr->convert_to_version_2(this);
  863. mem_del(oldNationPtr);
  864. }
  865. else
  866. {
  867. if( !filePtr->file_read( this, sizeof(Nation) ) )
  868. return 0;
  869. }
  870. #else
  871. if( !filePtr->file_read( this, sizeof(Nation) ) )
  872. return 0;
  873. #endif
  874. *((char**)this) = vfPtr;
  875. //---------- restore action_array ------------//
  876. memcpy( &action_array, saveActionArray, sizeof(DynArray) );
  877. mem_del( saveActionArray );
  878. //-------------- read AI Action Array --------------//
  879. action_array.read_file(filePtr);
  880. //------ write AI info array ---------//
  881. read_ai_info(filePtr, &ai_town_array, ai_town_count, ai_town_size);
  882. read_ai_info(filePtr, &ai_base_array, ai_base_count, ai_base_size);
  883. read_ai_info(filePtr, &ai_mine_array, ai_mine_count, ai_mine_size);
  884. read_ai_info(filePtr, &ai_factory_array, ai_factory_count, ai_factory_size);
  885. read_ai_info(filePtr, &ai_market_array, ai_market_count, ai_market_size);
  886. read_ai_info(filePtr, &ai_inn_array, ai_inn_count, ai_inn_size);
  887. read_ai_info(filePtr, &ai_camp_array, ai_camp_count, ai_camp_size);
  888. read_ai_info(filePtr, &ai_research_array, ai_research_count, ai_research_size);
  889. read_ai_info(filePtr, &ai_war_array, ai_war_count, ai_war_size);
  890. read_ai_info(filePtr, &ai_harbor_array, ai_harbor_count, ai_harbor_size);
  891. read_ai_info(filePtr, &ai_caravan_array, ai_caravan_count, ai_caravan_size);
  892. read_ai_info(filePtr, &ai_ship_array, ai_ship_count, ai_ship_size);
  893. read_ai_info(filePtr, &ai_general_array, ai_general_count, ai_general_size);
  894. return 1;
  895. }
  896. //----------- End of function Nation::read_file ---------//
  897. //--------- Begin of static function read_ai_info ---------//
  898. //
  899. static void read_ai_info(File* filePtr, short** aiInfoArrayPtr, short& aiInfoCount, short& aiInfoSize)
  900. {
  901. aiInfoCount = filePtr->file_get_short();
  902. aiInfoSize = filePtr->file_get_short();
  903. *aiInfoArrayPtr = (short*) mem_add( aiInfoSize * sizeof(short) );
  904. filePtr->file_read( *aiInfoArrayPtr, sizeof(short) * aiInfoCount );
  905. }
  906. //----------- End of static function read_ai_info ---------//
  907. //*****//
  908. //-------- Start of function TornadoArray::write_file -------------//
  909. //
  910. int TornadoArray::write_file(File* filePtr)
  911. {
  912. filePtr->file_put_short(restart_recno); // variable in SpriteArray
  913. int i;
  914. Tornado *tornadoPtr;
  915. filePtr->file_put_short( size() ); // no. of tornados in tornado_array
  916. for( i=1; i<=size() ; i++ )
  917. {
  918. tornadoPtr = (Tornado*) get_ptr(i);
  919. //----- write tornadoId or 0 if the tornado is deleted -----//
  920. if( !tornadoPtr ) // the tornado is deleted
  921. {
  922. filePtr->file_put_short(0);
  923. }
  924. else
  925. {
  926. filePtr->file_put_short(1); // there is a tornado in this record
  927. //------ write data in the base class ------//
  928. if( !tornadoPtr->write_file(filePtr) )
  929. return 0;
  930. }
  931. }
  932. //------- write empty room array --------//
  933. write_empty_room(filePtr);
  934. return 1;
  935. }
  936. //--------- End of function TornadoArray::write_file -------------//
  937. //-------- Start of function TornadoArray::read_file -------------//
  938. //
  939. int TornadoArray::read_file(File* filePtr)
  940. {
  941. restart_recno = filePtr->file_get_short();
  942. int i, tornadoRecno, tornadoCount;
  943. Tornado* tornadoPtr;
  944. tornadoCount = filePtr->file_get_short(); // get no. of tornados from file
  945. for( i=1 ; i<=tornadoCount ; i++ )
  946. {
  947. if( filePtr->file_get_short() == 0 )
  948. {
  949. add_blank(1); // it's a DynArrayB function
  950. }
  951. else
  952. {
  953. //----- create tornado object -----------//
  954. tornadoRecno = tornado_array.create_tornado();
  955. tornadoPtr = tornado_array[tornadoRecno];
  956. //----- read data in base class --------//
  957. if( !tornadoPtr->read_file( filePtr ) )
  958. return 0;
  959. }
  960. }
  961. //-------- linkout() those record added by add_blank() ----------//
  962. //-- So they will be marked deleted in DynArrayB and can be -----//
  963. //-- undeleted and used when a new record is going to be added --//
  964. for( i=size() ; i>0 ; i-- )
  965. {
  966. DynArrayB::go(i); // since TornadoArray has its own go() which will call GroupArray::go()
  967. if( get_ptr() == NULL ) // add_blank() record
  968. linkout();
  969. }
  970. //------- read empty room array --------//
  971. read_empty_room(filePtr);
  972. return 1;
  973. }
  974. //--------- End of function TornadoArray::read_file ---------------//
  975. //--------- Begin of function Tornado::write_file ---------//
  976. //
  977. int Tornado::write_file(File* filePtr)
  978. {
  979. if( !filePtr->file_write( this, sizeof(Tornado) ) )
  980. return 0;
  981. return 1;
  982. }
  983. //----------- End of function Tornado::write_file ---------//
  984. //--------- Begin of function Tornado::read_file ---------//
  985. //
  986. int Tornado::read_file(File* filePtr)
  987. {
  988. char* vfPtr = *((char**)this); // save the virtual function table pointer
  989. if( !filePtr->file_read( this, sizeof(Tornado) ) )
  990. return 0;
  991. *((char**)this) = vfPtr;
  992. //------------ post-process the data read ----------//
  993. sprite_info = sprite_res[sprite_id];
  994. sprite_info->load_bitmap_res();
  995. return 1;
  996. }
  997. //----------- End of function Tornado::read_file ---------//
  998. //*****//
  999. //-------- Start of function RebelArray::write_file -------------//
  1000. //
  1001. int RebelArray::write_file(File* filePtr)
  1002. {
  1003. return write_ptr_array(filePtr, sizeof(Rebel));
  1004. }
  1005. //--------- End of function RebelArray::write_file ---------------//
  1006. //-------- Start of function RebelArray::read_file -------------//
  1007. //
  1008. int RebelArray::read_file(File* filePtr)
  1009. {
  1010. return read_ptr_array(filePtr, sizeof(Rebel), create_rebel_func);
  1011. }
  1012. //--------- End of function RebelArray::read_file ---------------//
  1013. //-------- Start of static function create_rebel_func ---------//
  1014. //
  1015. static char* create_rebel_func()
  1016. {
  1017. Rebel *rebelPtr = new Rebel;
  1018. rebel_array.linkin(&rebelPtr);
  1019. return (char*) rebelPtr;
  1020. }
  1021. //--------- End of static function create_rebel_func ----------//
  1022. //*****//
  1023. //-------- Start of function SpyArray::write_file -------------//
  1024. //
  1025. int SpyArray::write_file(File* filePtr)
  1026. {
  1027. return DynArrayB::write_file( filePtr );
  1028. }
  1029. //--------- End of function SpyArray::write_file ---------------//
  1030. //-------- Start of function SpyArray::read_file -------------//
  1031. //
  1032. int SpyArray::read_file(File* filePtr)
  1033. {
  1034. return DynArrayB::read_file( filePtr );
  1035. }
  1036. //--------- End of function SpyArray::read_file ---------------//
  1037. //*****//
  1038. //-------- Start of function SnowGroundArray::write_file -------------//
  1039. //
  1040. int SnowGroundArray::write_file(File* filePtr)
  1041. {
  1042. if( !filePtr->file_write( this, sizeof(SnowGroundArray)) )
  1043. return 0;
  1044. return 1;
  1045. }
  1046. //--------- End of function SnowGroundArray::write_file ---------------//
  1047. //-------- Start of function SnowGroundArray::read_file -------------//
  1048. //
  1049. int SnowGroundArray::read_file(File* filePtr)
  1050. {
  1051. if( !filePtr->file_read( this, sizeof(SnowGroundArray)) )
  1052. return 0;
  1053. return 1;
  1054. }
  1055. //--------- End of function SnowGroundArray::read_file ---------------//
  1056. //*****//
  1057. //-------- Start of function RegionArray::write_file -------------//
  1058. //
  1059. int RegionArray::write_file(File* filePtr)
  1060. {
  1061. if( !filePtr->file_write( this, sizeof(RegionArray)) )
  1062. return 0;
  1063. if( !filePtr->file_write( region_info_array, sizeof(RegionInfo)*region_info_count ) )
  1064. return 0;
  1065. //-------- write RegionStat ----------//
  1066. filePtr->file_put_short( region_stat_count );
  1067. if( !filePtr->file_write( region_stat_array, sizeof(RegionStat)*region_stat_count ) )
  1068. return 0;
  1069. //--------- write connection bits ----------//
  1070. int connectBit = (region_info_count -1) * (region_info_count) /2;
  1071. int connectByte = (connectBit +7) /8;
  1072. if( connectByte > 0)
  1073. {
  1074. if( !filePtr->file_write(connect_bits, connectByte) )
  1075. return 0;
  1076. }
  1077. return 1;
  1078. }
  1079. //--------- End of function RegionArray::write_file ---------------//
  1080. //-------- Start of function RegionArray::read_file -------------//
  1081. //
  1082. int RegionArray::read_file(File* filePtr)
  1083. {
  1084. if( !filePtr->file_read( this, sizeof(RegionArray)) )
  1085. return 0;
  1086. if( region_info_count > 0 )
  1087. region_info_array = (RegionInfo *) mem_add(sizeof(RegionInfo)*region_info_count);
  1088. else
  1089. region_info_array = NULL;
  1090. if( !filePtr->file_read( region_info_array, sizeof(RegionInfo)*region_info_count))
  1091. return 0;
  1092. //-------- read RegionStat ----------//
  1093. region_stat_count = filePtr->file_get_short();
  1094. region_stat_array = (RegionStat*) mem_add( region_stat_count * sizeof(RegionStat) );
  1095. if( !filePtr->file_read( region_stat_array, sizeof(RegionStat)*region_stat_count ) )
  1096. return 0;
  1097. //--------- read connection bits ----------//
  1098. int connectBit = (region_info_count -1) * (region_info_count) /2;
  1099. int connectByte = (connectBit +7) /8;
  1100. if( connectByte > 0)
  1101. {
  1102. connect_bits = (unsigned char *)mem_add(connectByte);
  1103. if( !filePtr->file_read(connect_bits, connectByte) )
  1104. return 0;
  1105. }
  1106. else
  1107. {
  1108. connect_bits = NULL;
  1109. }
  1110. return 1;
  1111. }
  1112. //--------- End of function RegionArray::read_file ---------------//
  1113. //*****//
  1114. //-------- Start of function NewsArray::write_file -------------//
  1115. //
  1116. int NewsArray::write_file(File* filePtr)
  1117. {
  1118. //----- save news_array parameters -----//
  1119. filePtr->file_write( news_type_option, sizeof(news_type_option) );
  1120. filePtr->file_put_short(news_who_option);
  1121. filePtr->file_put_long (last_clear_recno);
  1122. //---------- save news data -----------//
  1123. return DynArray::write_file(filePtr);
  1124. }
  1125. //--------- End of function NewsArray::write_file ---------------//
  1126. //-------- Start of function NewsArray::read_file -------------//
  1127. //
  1128. int NewsArray::read_file(File* filePtr)
  1129. {
  1130. //----- read news_array parameters -----//
  1131. filePtr->file_read( news_type_option, sizeof(news_type_option) );
  1132. news_who_option = (char) filePtr->file_get_short();
  1133. last_clear_recno = filePtr->file_get_long();
  1134. //---------- read news data -----------//
  1135. return DynArray::read_file(filePtr);
  1136. }
  1137. //--------- End of function NewsArray::read_file ---------------//