123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446 |
- /*
- * Seven Kingdoms: Ancient Adversaries
- *
- * Copyright 1997,1998 Enlight Software Ltd.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- //Filename : OGFILE2.CPP
- //Description : Object Game file, save game and restore game, part 2
- #include <OUNITRES.h>
- #include <OFIRMRES.h>
- #include <OUNIT.h>
- #include <OBULLET.h>
- #include <OSITE.h>
- #include <OTOWN.h>
- #include <ONATION.h>
- #include <OFIRM.h>
- #include <OTECHRES.h>
- #include <ORACERES.h>
- #include <OTOWNRES.h>
- #include <ORAWRES.h>
- #include <OGODRES.h>
- #include <OTALKRES.h>
- #include <OTORNADO.h>
- #include <OMONSRES.h>
- #include <OREBEL.h>
- #include <OSPY.h>
- #include <OSNOWG.h>
- #include <OSYS.h>
- #include <OREGION.h>
- #include <ONEWS.h>
- #include <OTUTOR.h>
- #include <OINFO.h>
- #include <OWEATHER.h>
- #include <OGAME.h>
- #include <OPOWER.h>
- #include <OWORLD.h>
- #include <OGFILE.h>
- #include <OROCK.h>
- // ##### begin Gilbert 2/10 #######//
- #include <OFIRMDIE.h>
- // ##### end Gilbert 2/10 #######//
- //-------- Define constant ----------//
- #define BOOK_MARK 0x1000 // book mark for validing saving data
- //----------- Game file format --------------//
- //
- // Data of the following objects will be saved :
- //
- // RaceRes race_res;
- // UnitRes unit_res;
- // FirmRes firm_res;
- // TownRes town_res;
- // TechRes tech_res;
- // TalkRes talk_res;
- // RawRes raw_res;
- // GodRes god_res;
- // MonsterRes monster_res;
- //
- // UnitArray unit_array(100); // with derived classes
- // BulletArray bullet_array(100);
- // SiteArray site_array;
- // TownArray town_array;
- // NationArray nation_array;
- // FirmArray firm_array; // with derived classes
- // TornadoArray tornado_array(10);
- // RebelArray rebel_array;
- // SpyArray spy_array;
- // SnowGroundArray snow_ground_array;
- // RegionArray region_array;
- // NewsArray news_array;
- //
- // Game game
- // Config config
- // Sys sys
- // Info info
- // Power power
- // Weather weather, weather_forecast[MAX_WEATHER_FORECAST];
- // MagicWeather magic_weather
- // News news
- // World world
- // Tutor tutor
- //### begin alex 23/9 ###//
- // SeekPath seek_path
- //#### end alex 23/9 ####//
- //
- //-------------------------------------------//
- //--------- Define static vars ---------//
- static int loaded_random_seed;
- //-------- Define static class member vars -------//
- File* GameFile::file_ptr;
- char GameFile::last_read_success_flag=0;
- //-------- Begin of function GameFile::write_file -------//
- //
- // Save a game to file
- //
- // Return : 1 - file written successfully
- // 0 - not successful
- //
- int GameFile::write_file(File* filePtr)
- {
- file_ptr = filePtr; // for write_book_mark()
- //----- check valid version first ------//
- if( game_file_array.demo_format )
- filePtr->file_put_short( -GAME_VERSION ); // negative no. means shareware version
- else
- filePtr->file_put_short( GAME_VERSION );
- //------------------------------------------------//
- //
- // The order of writing data is different between
- // the shareware and registered version.
- //
- //------------------------------------------------//
- if( game_file_array.demo_format )
- {
- if( !write_file_1(filePtr) )
- return 0;
- if( !write_file_2(filePtr) )
- return 0;
- }
- else
- {
- if( !write_file_2(filePtr) )
- return 0;
- if( !write_file_1(filePtr) )
- return 0;
- }
- if( !write_file_3(filePtr) )
- return 0;
- return 1;
- }
- //---------- End of function GameFile::write_file -------//
- //-------- Begin of function GameFile::read_file -------//
- //
- // Restore a game from file
- //
- // Return : 1 - file read successfully
- // 0 - not successful
- // -1 - incorrect game data version error
- //
- int GameFile::read_file(File* filePtr)
- {
- file_ptr = filePtr; // for read_book_mark()
- //----- check version no. first ------//
- int originalRandomSeed = m.get_random_seed();
- //### begin alex 5/3 ###//
- #ifdef AMPLUS
- // game_file_array.load_file_game_version = filePtr->file_get_short();
- game_file_array.load_file_game_version = filePtr->file_get_short();
- // compare if same demo format or not
- if( game_file_array.demo_format && game_file_array.load_file_game_version > 0
- || !game_file_array.demo_format && game_file_array.load_file_game_version < 0)
- return -1;
- // take the absolute value of game version
- game_file_array.load_file_game_version = abs(game_file_array.load_file_game_version);
- if(game_file_array.load_file_game_version > GAME_VERSION)
- return -1; // the executing program can't handle saved game in future version
- // game_file_array.same_version = (game_file_array.load_file_game_version/100==
- // (game_file_array.demo_format ? -(GAME_VERSION/100) : GAME_VERSION/100));
- game_file_array.same_version = ( game_file_array.load_file_game_version/100==GAME_VERSION/100 );
- #else
- // ###### patch begin Gilbert 20/1 ########//
- // compare major version
- //if( filePtr->file_get_short() != (game_file_array.demo_format ? -GAME_VERSION : GAME_VERSION) )
- if( filePtr->file_get_short()/100 != (game_file_array.demo_format ? -(GAME_VERSION/100) : GAME_VERSION/100) )
- return -1;
- // ###### patch end Gilbert 20/1 ########//
- #endif
- //#### end alex 5/3 ####//
- //------------------------------------------------//
- //
- // The order of writing data is different between
- // the shareware and registered version.
- //
- //------------------------------------------------//
- if( game_file_array.demo_format )
- {
- if( !read_file_1(filePtr) )
- return 0;
- if( !read_file_2(filePtr) )
- return 0;
- }
- else
- {
- if( !read_file_2(filePtr) )
- return 0;
- if( !read_file_1(filePtr) )
- return 0;
- }
- if( !read_file_3(filePtr) )
- return 0;
- //-------------------------------------//
- err_when( originalRandomSeed != m.get_random_seed() );
- m.set_random_seed(loaded_random_seed);
- return 1;
- }
- //---------- End of function GameFile::read_file -------//
- //-------- Begin of function GameFile::write_file_1 -------//
- //
- // Return : 1 - file written successfully
- // 0 - not successful
- //
- int GameFile::write_file_1(File* filePtr)
- {
- write_book_mark( BOOK_MARK+1 );
- if( !race_res.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+2 );
- if( !unit_res.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+3 );
- if( !firm_res.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+4 );
- if( !town_res.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+5 );
- if( !tech_res.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+6 );
- if( !talk_res.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+7 );
- if( !raw_res.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+8 );
- if( !god_res.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+9 );
- if( !monster_res.write_file(filePtr) )
- return 0;
- return 1;
- }
- //---------- End of function GameFile::write_file_1 -------//
- //-------- Begin of function GameFile::write_file_2 -------//
- //
- // Save a game to file
- //
- // Return : 1 - file written successfully
- // 0 - not successful
- //
- int GameFile::write_file_2(File* filePtr)
- {
- write_book_mark( BOOK_MARK+101 );
- if( !game.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+102 );
- if( !config.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+103 );
- if( !sys.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+104 );
- if( !info.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+105 );
- if( !power.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+106 );
- if( !weather.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+107 );
- if( !magic_weather.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+108 );
- if( !news_array.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+109 );
- if( !world.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+110 );
- if( !tutor.write_file(filePtr) )
- return 0;
- //### begin alex 23/9 ###//
- write_book_mark( BOOK_MARK+111 );
- if( !seek_path.write_file(filePtr) )
- return 0;
- //#### end alex 23/9 ####//
- return 1;
- }
- //---------- End of function GameFile::write_file_2 -------//
- //-------- Begin of function GameFile::write_file_3 -------//
- //
- // Return : 1 - file written successfully
- // 0 - not successful
- //
- int GameFile::write_file_3(File* filePtr)
- {
- write_book_mark( BOOK_MARK+201 );
- if( !unit_array.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+202 );
- if( !bullet_array.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+203 );
- if( !site_array.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+204 );
- if( !town_array.write_file(filePtr) ) // job will affect firm, group, item
- return 0;
- write_book_mark( BOOK_MARK+205 );
- if( !nation_array.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+206 );
- if( !firm_array.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+207 );
- if( !tornado_array.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+208 );
- if( !rebel_array.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+209 );
- if( !spy_array.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+210 );
- if( !snow_ground_array.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+211 );
- if( !region_array.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+212 );
- if( !news_array.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+213 );
- if( !rock_array.write_file(filePtr) )
- return 0;
- write_book_mark( BOOK_MARK+214 );
- if( !dirt_array.write_file(filePtr) )
- return 0;
- // ##### begin Gilbert 2/10 ######//
- write_book_mark( BOOK_MARK+215 );
- if( !firm_die_array.write_file(filePtr) )
- return 0;
- // ##### end Gilbert 2/10 ######//
- return 1;
- }
- //---------- End of function GameFile::write_file_3 -------//
- //-------- Begin of function GameFile::read_file_1 -------//
- //
- // Return : 1 - file read successfully
- // 0 - not successful
- //
- int GameFile::read_file_1(File* filePtr)
- {
- if( !read_book_mark( BOOK_MARK+1 ) )
- return 0;
- if( !race_res.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+2 ) )
- return 0;
- if( !unit_res.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+3 ) )
- return 0;
- if( !firm_res.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+4 ) )
- return 0;
- if( !town_res.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+5 ) )
- return 0;
- if( !tech_res.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+6 ) )
- return 0;
- if( !talk_res.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+7 ) )
- return 0;
- if( !raw_res.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+8 ) )
- return 0;
- if( !god_res.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+9 ) )
- return 0;
- if( !monster_res.read_file(filePtr) )
- return 0;
- return 1;
- }
- //---------- End of function GameFile::read_file_1 -------//
- //-------- Begin of function GameFile::read_file_2 -------//
- //
- // Return : 1 - file read successfully
- // 0 - not successful
- //
- int GameFile::read_file_2(File* filePtr)
- {
- if( !read_book_mark( BOOK_MARK+101 ) )
- return 0;
- if( !game.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+102 ) )
- return 0;
- if( !config.read_file(filePtr, 1) ) // 1-keep system settings
- return 0;
- if( !read_book_mark( BOOK_MARK+103 ) )
- return 0;
- if( !sys.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+104 ) )
- return 0;
- if( !info.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+105 ) )
- return 0;
- if( !power.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+106 ) )
- return 0;
- if( !weather.read_file(filePtr) )
- return 0;
- weather_forecast[0] = weather;
- weather_forecast[0].next_day();
- for(int foreDay=1; foreDay < MAX_WEATHER_FORECAST; ++foreDay)
- {
- weather_forecast[foreDay] = weather_forecast[foreDay-1];
- weather_forecast[foreDay].next_day();
- }
- if( !read_book_mark( BOOK_MARK+107 ) )
- return 0;
- if( !magic_weather.read_file(filePtr) )
- return 0;
- sprite_res.update_speed();
- if( !read_book_mark( BOOK_MARK+108 ) )
- return 0;
- if( !news_array.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+109 ) )
- return 0;
- if( !world.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+110 ) )
- return 0;
- if( !tutor.read_file(filePtr) )
- return 0;
- //### begin alex 23/9 ###//
- if( !read_book_mark( BOOK_MARK+111 ) )
- return 0;
- if( !seek_path.read_file(filePtr) )
- return 0;
- //#### end alex 23/9 ####//
- return 1;
- }
- //---------- End of function GameFile::read_file_2 -------//
- //-------- Begin of function GameFile::read_file_3 -------//
- //
- // Return : 1 - file read successfully
- // 0 - not successful
- //
- int GameFile::read_file_3(File* filePtr)
- {
- if( !read_book_mark( BOOK_MARK+201 ) )
- return 0;
- if( !unit_array.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+202 ) )
- return 0;
- if( !bullet_array.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+203 ) )
- return 0;
- if( !site_array.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+204 ) )
- return 0;
- if( !town_array.read_file(filePtr) ) // job will affect firm, group, item
- return 0;
- if( !read_book_mark( BOOK_MARK+205 ) )
- return 0;
- if( !nation_array.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+206 ) )
- return 0;
- if( !firm_array.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+207 ) )
- return 0;
- if( !tornado_array.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+208 ) )
- return 0;
- if( !rebel_array.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+209 ) )
- return 0;
- if( !spy_array.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+210 ) )
- return 0;
- if( !snow_ground_array.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+211 ) )
- return 0;
- if( !region_array.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+212 ) )
- return 0;
- if( !news_array.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+213 ) )
- return 0;
- if( !rock_array.read_file(filePtr) )
- return 0;
- if( !read_book_mark( BOOK_MARK+214 ) )
- return 0;
- if( !dirt_array.read_file(filePtr) )
- return 0;
- // ##### begin Gilbert 2/10 ######//
- if( !read_book_mark( BOOK_MARK+215 ) )
- if( !firm_die_array.read_file(filePtr) )
- return 0;
- // ##### end Gilbert 2/10 ######//
- return 1;
- }
- //---------- End of function GameFile::read_file_3 -------//
- //-------- Begin of function GameFile::write_book_mark -------//
- //
- void GameFile::write_book_mark(short bookMark)
- {
- sys.yield();
- file_ptr->file_put_short(bookMark);
- }
- //---------- End of function GameFile::write_book_mark -------//
- //-------- Begin of function GameFile::read_book_mark -------//
- //
- // Return : 1 - the book mark is matched
- // 0 - the book mark is not matched
- //
- int GameFile::read_book_mark(short bookMark)
- {
- sys.yield();
- return file_ptr->file_get_short() == bookMark;
- }
- //---------- End of function GameFile::read_book_mark -------//
- //***//
- //-------- Start of function RaceRes::write_file -------------//
- //
- int RaceRes::write_file(File* filePtr)
- {
- //------- write RaceInfo -------//
- RaceInfo* raceInfo = race_info_array;
- for( int i=1 ; i<=race_res.race_count ; i++, raceInfo++ )
- {
- filePtr->file_put_short( raceInfo->town_name_used_count );
- }
- return filePtr->file_write( name_used_array, sizeof(name_used_array[0]) * name_count );
- }
- //--------- End of function RaceRes::write_file ---------------//
- //-------- Start of function RaceRes::read_file -------------//
- //
- int RaceRes::read_file(File* filePtr)
- {
- //------- read RaceInfo -------//
- RaceInfo* raceInfo = race_info_array;
- for( int i=1 ; i<=race_res.race_count ; i++, raceInfo++ )
- {
- #ifdef AMPLUS
- raceInfo->town_name_used_count = (!game_file_array.same_version && i>VERSION_1_MAX_RACE) ?
- 0 : filePtr->file_get_short();
- #else
- raceInfo->town_name_used_count = filePtr->file_get_short();
- #endif
- }
- #ifdef AMPLUS
- if(!game_file_array.same_version)
- {
- memset(name_used_array, 0, sizeof(name_used_array[0]) * name_count);
- return filePtr->file_read( name_used_array, sizeof(name_used_array[0]) * VERSION_1_RACERES_NAME_COUNT );
- }
- else
- return filePtr->file_read( name_used_array, sizeof(name_used_array[0]) * name_count );
- #else
- return filePtr->file_read( name_used_array, sizeof(name_used_array[0]) * name_count );
- #endif
- }
- //--------- End of function RaceRes::read_file ---------------//
- //***//
- //-------- Start of function UnitRes::write_file -------------//
- //
- int UnitRes::write_file(File* filePtr)
- {
- filePtr->file_put_short(mobile_monster_count);
- UnitInfo* unitInfo = unit_info_array;
- for( int i=1 ; i<=unit_res.unit_info_count ; i++, unitInfo++ )
- {
- if( !filePtr->file_write( unitInfo->nation_tech_level_array, sizeof(unitInfo->nation_tech_level_array) ) )
- return 0;
- if( !filePtr->file_write( unitInfo->nation_unit_count_array, sizeof(unitInfo->nation_unit_count_array) ) )
- return 0;
- if( !filePtr->file_write( unitInfo->nation_general_count_array, sizeof(unitInfo->nation_general_count_array) ) )
- return 0;
- }
- return 1;
- }
- //--------- End of function UnitRes::write_file ---------------//
- //-------- Start of function UnitRes::read_file -------------//
- //
- int UnitRes::read_file(File* filePtr)
- {
- mobile_monster_count = filePtr->file_get_short();
- UnitInfo* unitInfo = unit_info_array;
- for( int i=1 ; i<=unit_res.unit_info_count ; i++, unitInfo++ )
- {
- #ifdef AMPLUS
- if(!game_file_array.same_version && i > VERSION_1_UNITRES_UNIT_INFO_COUNT)
- {
- memset(unitInfo->nation_tech_level_array, 0, sizeof(unitInfo->nation_tech_level_array));
- memset(unitInfo->nation_unit_count_array, 0, sizeof(unitInfo->nation_unit_count_array));
- memset(unitInfo->nation_general_count_array, 0, sizeof(unitInfo->nation_general_count_array));
- continue;
- }
- #endif
- if( !filePtr->file_read( unitInfo->nation_tech_level_array, sizeof(unitInfo->nation_tech_level_array) ) )
- return 0;
- if( !filePtr->file_read( unitInfo->nation_unit_count_array, sizeof(unitInfo->nation_unit_count_array) ) )
- return 0;
- if( !filePtr->file_read( unitInfo->nation_general_count_array, sizeof(unitInfo->nation_general_count_array) ) )
- return 0;
- }
- return 1;
- }
- //--------- End of function UnitRes::read_file ---------------//
- //***//
- //-------- Start of function FirmRes::write_file -------------//
- //
- int FirmRes::write_file(File* filePtr)
- {
- return filePtr->file_write( firm_info_array, firm_count * sizeof(FirmInfo) );
- }
- //--------- End of function FirmRes::write_file ---------------//
- //-------- Start of function FirmRes::read_file -------------//
- //
- int FirmRes::read_file(File* filePtr)
- {
- int arraySize = firm_count * sizeof(FirmInfo);
- //----- save the firm names, so that it won't be overwritten by the saved game file ----//
- FirmInfo* oldFirmInfoArray = (FirmInfo*) mem_add(arraySize);
- memcpy( oldFirmInfoArray, firm_info_array, arraySize );
- int rc = filePtr->file_read( firm_info_array, arraySize );
- for( int i=0 ; i<firm_count ; i++ )
- {
- memcpy( firm_info_array[i].name , oldFirmInfoArray[i].name , FirmInfo::NAME_LEN+1 );
- memcpy( firm_info_array[i].short_name , oldFirmInfoArray[i].short_name , FirmInfo::SHORT_NAME_LEN+1 );
- memcpy( firm_info_array[i].overseer_title, oldFirmInfoArray[i].overseer_title, FirmInfo::TITLE_LEN+1 );
- memcpy( firm_info_array[i].worker_title , oldFirmInfoArray[i].worker_title , FirmInfo::TITLE_LEN+1 );
- // ###### patch begin Gilbert 11/3 ########//
- firm_info_array[i].first_build_id = oldFirmInfoArray[i].first_build_id;
- firm_info_array[i].build_count = oldFirmInfoArray[i].build_count;
- // ###### patch end Gilbert 11/3 ########//
- }
- mem_del( oldFirmInfoArray );
- return rc;
- }
- //--------- End of function FirmRes::read_file ---------------//
- //***//
- //-------- Start of function TownRes::write_file -------------//
- //
- int TownRes::write_file(File* filePtr)
- {
- return filePtr->file_write( town_name_used_array, sizeof(town_name_used_array[0]) * town_name_count );
- }
- //--------- End of function TownRes::write_file ---------------//
- //-------- Start of function TownRes::read_file -------------//
- //
- int TownRes::read_file(File* filePtr)
- {
- #ifdef AMPLUS
- if(!game_file_array.same_version)
- {
- memset(town_name_used_array, 0, sizeof(town_name_used_array));
- return filePtr->file_read( town_name_used_array, sizeof(town_name_used_array[0]) * VERSION_1_TOWNRES_TOWN_NAME_COUNT );
- }
- else
- return filePtr->file_read( town_name_used_array, sizeof(town_name_used_array[0]) * town_name_count );
- #else
- return filePtr->file_read( town_name_used_array, sizeof(town_name_used_array[0]) * town_name_count );
- #endif
- }
- //--------- End of function TownRes::read_file ---------------//
- //***//
- //-------- Start of function TechRes::write_file -------------//
- //
- int TechRes::write_file(File* filePtr)
- {
- if( !filePtr->file_write( tech_class_array, tech_class_count * sizeof(TechClass) ) )
- return 0;
- if( !filePtr->file_write( tech_info_array, tech_count * sizeof(TechInfo) ) )
- return 0;
- return 1;
- }
- //--------- End of function TechRes::write_file ---------------//
- //-------- Start of function TechRes::read_file -------------//
- //
- int TechRes::read_file(File* filePtr)
- {
- if( !filePtr->file_read( tech_class_array, tech_class_count * sizeof(TechClass) ) )
- return 0;
- #ifdef AMPLUS
- if(!game_file_array.same_version)
- {
- if(!filePtr->file_read( tech_info_array, VERSION_1_TECH_COUNT * sizeof(TechInfo) ) )
- return 0;
- TechInfo *techInfoPtr = tech_info_array + VERSION_1_TECH_COUNT;
- for(int i=VERSION_1_TECH_COUNT; i<tech_count; ++i, techInfoPtr++)
- {
- memset(techInfoPtr->nation_tech_level_array, 0, sizeof(techInfoPtr->nation_tech_level_array));
- memset(techInfoPtr->nation_is_researching_array, 0, sizeof(techInfoPtr->nation_is_researching_array));
- memset(techInfoPtr->nation_research_progress_array, 0, sizeof(techInfoPtr->nation_research_progress_array));
- }
- }
- else
- {
- if( !filePtr->file_read( tech_info_array, tech_count * sizeof(TechInfo) ) )
- return 0;
- }
- #else
- if( !filePtr->file_read( tech_info_array, tech_count * sizeof(TechInfo) ) )
- return 0;
- #endif
- return 1;
- }
- //--------- End of function TechRes::read_file ---------------//
- //***//
- //-------- Start of function TalkRes::write_file -------------//
- //
- int TalkRes::write_file(File* filePtr)
- {
- if( !filePtr->file_write( this, sizeof(TalkRes) ) )
- return 0;
- if( !talk_msg_array.write_file(filePtr) )
- return 0;
- return 1;
- }
- //--------- End of function TalkRes::write_file ---------------//
- //-------- Start of function TalkRes::read_file -------------//
- //
- int TalkRes::read_file(File* filePtr)
- {
- //------ save talk_msg_array --------//
- char* tempArray = mem_add(sizeof(DynArrayB));
- memcpy( tempArray, &talk_msg_array, sizeof(DynArrayB) );
- //------ read in TalkRes --------//
- if( !filePtr->file_read( this, sizeof(TalkRes) ) )
- return 0;
- //------ restore talk_msg_array --------//
- memcpy( &talk_msg_array, tempArray, sizeof(DynArrayB) );
- mem_del(tempArray);
- //---- read in talk_msg_array ----//
- if( !talk_msg_array.read_file(filePtr) )
- return 0;
- return 1;
- }
- //--------- End of function TalkRes::read_file ---------------//
- //***//
- //-------- Start of function RawRes::write_file -------------//
- //
- int RawRes::write_file(File* filePtr)
- {
- for( int i=0 ; i<MAX_RAW ; i++ )
- {
- if( !raw_info_array[i].raw_supply_firm_array.write_file(filePtr) )
- return 0;
- if( !raw_info_array[i].product_supply_firm_array.write_file(filePtr) )
- return 0;
- }
- return 1;
- }
- //--------- End of function RawRes::write_file ---------------//
- //-------- Start of function RawRes::read_file -------------//
- //
- int RawRes::read_file(File* filePtr)
- {
- for( int i=0 ; i<MAX_RAW ; i++ )
- {
- if( !raw_info_array[i].raw_supply_firm_array.read_file(filePtr) )
- return 0;
- if( !raw_info_array[i].product_supply_firm_array.read_file(filePtr) )
- return 0;
- }
- return 1;
- }
- //--------- End of function RawRes::read_file ---------------//
- //***//
- //-------- Start of function GodRes::write_file -------------//
- //
- int GodRes::write_file(File* filePtr)
- {
- return filePtr->file_write( god_info_array, sizeof(GodInfo) * god_count );
- }
- //--------- End of function GodRes::write_file ---------------//
- //-------- Start of function GodRes::read_file -------------//
- //
- int GodRes::read_file(File* filePtr)
- {
- #ifdef AMPLUS
- if(!game_file_array.same_version)
- {
- memset(god_info_array, 0, sizeof(god_info_array));
- return filePtr->file_read( god_info_array, sizeof(GodInfo) * VERSION_1_GODRES_GOD_COUNT );
- }
- else
- return filePtr->file_read( god_info_array, sizeof(GodInfo) * god_count );
- #else
- return filePtr->file_read( god_info_array, sizeof(GodInfo) * god_count );
- #endif
- }
- //--------- End of function GodRes::read_file ---------------//
- //***//
- //-------- Start of function MonsterRes::write_file -------------//
- //
- int MonsterRes::write_file(File* filePtr)
- {
- return filePtr->file_write( active_monster_array, sizeof(active_monster_array) );
- }
- //--------- End of function MonsterRes::write_file ---------------//
- //-------- Start of function MonsterRes::read_file -------------//
- //
- int MonsterRes::read_file(File* filePtr)
- {
- return filePtr->file_read( active_monster_array, sizeof(active_monster_array) );
- }
- //--------- End of function MonsterRes::read_file ---------------//
- //***//
- //-------- Start of function Game::write_file -------------//
- //
- int Game::write_file(File* filePtr)
- {
- return filePtr->file_write( this, sizeof(Game) );
- }
- //--------- End of function Game::write_file ---------------//
- //-------- Start of function Game::read_file -------------//
- //
- int Game::read_file(File* filePtr)
- {
- return filePtr->file_read( this, sizeof(Game) );
- }
- //--------- End of function Game::read_file ---------------//
- //***//
- //-------- Start of function Config::write_file -------------//
- //
- int Config::write_file(File* filePtr)
- {
- return filePtr->file_write( this, sizeof(Config) );
- }
- //--------- End of function Config::write_file ---------------//
- //-------- Start of function Config::read_file -------------//
- //
- int Config::read_file(File* filePtr, int keepSysSettings)
- {
- //--- these settings are not game dependent -----//
- char musicFlag = music_flag;
- short cdMusicVol = cd_music_volume;
- short wavMusicVol = wav_music_volume;
- char soundEffectFlag = sound_effect_flag;
- short soundEffectVol = sound_effect_volume;
- char helpMode = help_mode;
- int rc = filePtr->file_read( this, sizeof(Config) );
- if( keepSysSettings )
- {
- music_flag = musicFlag;
- cd_music_volume = cdMusicVol;
- wav_music_volume = wavMusicVol;
- sound_effect_flag = soundEffectFlag;
- sound_effect_volume = soundEffectVol;
- help_mode = helpMode;
- }
- return rc;
- }
- //--------- End of function Config::read_file ---------------//
- //***//
- //-------- Start of function Info::write_file -------------//
- //
- int Info::write_file(File* filePtr)
- {
- int writeSize = (char*)(&last_write_offset) - (char*)(this);
- //---------- write the info data -----------//
- return filePtr->file_write( this, writeSize );
- }
- //--------- End of function Info::write_file ---------------//
- //-------- Start of function Info::read_file -------------//
- //
- int Info::read_file(File* filePtr)
- {
- int readSize = (char*)(&last_write_offset) - (char*)(this);
- //------- read the info data ----------//
- return filePtr->file_read( this, readSize );
- }
- //--------- End of function Info::read_file ---------------//
- //***//
- //-------- Start of function Power::write_file -------------//
- //
- int Power::write_file(File* filePtr)
- {
- return filePtr->file_write( this, sizeof(Power) );
- }
- //--------- End of function Power::write_file ---------------//
- //-------- Start of function Power::read_file -------------//
- //
- int Power::read_file(File* filePtr)
- {
- return filePtr->file_read( this, sizeof(Power) );
- }
- //--------- End of function Power::read_file ---------------//
- //***//
- //-------- Start of function Sys::write_file -------------//
- //
- int Sys::write_file(File* filePtr)
- {
- //---- write the current random seed first ----//
- if( !filePtr->file_put_long(m.get_random_seed()) )
- return 0;
- //---------- write some Sys data -----------//
- filePtr->file_put_long(day_frame_count);
- filePtr->file_put_long(frame_count);
- filePtr->file_put_short(view_mode);
- return 1;
- }
- //--------- End of function Sys::write_file ---------------//
- //-------- Start of function Sys::read_file -------------//
- //
- int Sys::read_file(File* filePtr)
- {
- //------- read the random seed --------//
- loaded_random_seed = filePtr->file_get_long();
- //--------- read some Sys data -----------//
- day_frame_count = filePtr->file_get_long();
- frame_count = filePtr->file_get_long();
- view_mode = (char) filePtr->file_get_short();
- return 1;
- }
- //--------- End of function Sys::read_file ---------------//
- //***//
- //-------- Start of function Weather::write_file -------------//
- //
- int Weather::write_file(File* filePtr)
- {
- return filePtr->file_write( this, sizeof(Weather) );
- }
- //--------- End of function Weather::write_file ---------------//
- //-------- Start of function Weather::read_file -------------//
- //
- int Weather::read_file(File* filePtr)
- {
- return filePtr->file_read( this, sizeof(Weather) );
- }
- //--------- End of function Weather::read_file ---------------//
- //***//
- //-------- Start of function MagicWeather::write_file -------------//
- //
- int MagicWeather::write_file(File* filePtr)
- {
- return filePtr->file_write( this, sizeof(MagicWeather) );
- }
- //--------- End of function MagicWeahter::write_file ---------------//
- //-------- Start of function MagicWeahter::read_file -------------//
- //
- int MagicWeather::read_file(File* filePtr)
- {
- return filePtr->file_read( this, sizeof(MagicWeather) );
- }
- //--------- End of function MagicWeahter::read_file ---------------//
- //***//
- //-------- Start of function World::write_file -------------//
- //
- int World::write_file(File* filePtr)
- {
- //--------- save map -------------//
- if( !filePtr->file_write(loc_matrix, max_x_loc*max_y_loc*sizeof(Location) ) )
- return 0;
- //--------- save vars -----------//
- filePtr->file_put_short(scan_fire_x);
- filePtr->file_put_short(scan_fire_y);
- filePtr->file_put_short(lightning_signal);
- // ######## begin Gilbert 18/7 #########//
- filePtr->file_put_long(plant_count);
- filePtr->file_put_long(plant_limit);
- // ######## end Gilbert 18/7 #########//
- map_matrix->last_map_mode = -1;
- filePtr->file_put_short(map_matrix->map_mode);
- filePtr->file_put_short(map_matrix->power_mode);
- filePtr->file_put_long(map_matrix->cur_x_loc);
- filePtr->file_put_long(map_matrix->cur_y_loc);
- filePtr->file_put_long(zoom_matrix->init_lightning);
- filePtr->file_put_long(zoom_matrix->vibration);
- filePtr->file_put_short(zoom_matrix->lightning_x1);
- filePtr->file_put_short(zoom_matrix->lightning_y1);
- filePtr->file_put_short(zoom_matrix->lightning_x2);
- filePtr->file_put_short(zoom_matrix->lightning_y2);
- return 1;
- }
- //--------- End of function World::write_file ---------------//
- //-------- Start of function World::read_file -------------//
- //
- int World::read_file(File* filePtr)
- {
- //-------- read in the map --------//
- loc_matrix = (Location*) mem_resize( loc_matrix, max_x_loc * max_y_loc
- * sizeof(Location) );
- if( !filePtr->file_read(loc_matrix, max_x_loc*max_y_loc*sizeof(Location) ) )
- return 0;
- assign_map();
- //--------- read in vars ----------//
- scan_fire_x = (char) filePtr->file_get_short();
- scan_fire_y = (char) filePtr->file_get_short();
- lightning_signal = (char) filePtr->file_get_short();
- // ######## begin Gilbert 18/7 #########//
- plant_count = filePtr->file_get_long();
- plant_limit = filePtr->file_get_long();
- // ######## end Gilbert 18/7 #########//
- map_matrix->last_map_mode = -1;
- map_matrix->map_mode = (char) filePtr->file_get_short();
- map_matrix->power_mode = (char) filePtr->file_get_short();
- map_matrix->cur_x_loc = filePtr->file_get_long();
- map_matrix->cur_y_loc = filePtr->file_get_long();
- zoom_matrix->top_x_loc = map_matrix->cur_x_loc;
- zoom_matrix->top_y_loc = map_matrix->cur_y_loc;
- sys.zoom_need_redraw = 1;
- zoom_matrix->init_lightning = filePtr->file_get_long();
- zoom_matrix->vibration = filePtr->file_get_long();
- zoom_matrix->lightning_x1 = filePtr->file_get_short();
- zoom_matrix->lightning_y1 = filePtr->file_get_short();
- zoom_matrix->lightning_x2 = filePtr->file_get_short();
- zoom_matrix->lightning_y2 = filePtr->file_get_short();
- return 1;
- }
- //--------- End of function World::read_file ---------------//
- //***//
- //-------- Start of function Tutor::write_file -------------//
- //
- int Tutor::write_file(File* filePtr)
- {
- filePtr->file_put_short(cur_tutor_id);
- filePtr->file_put_short(cur_text_block_id);
- return 1;
- }
- //--------- End of function Tutor::write_file ---------------//
- //-------- Start of function Tutor::read_file -------------//
- //
- int Tutor::read_file(File* filePtr)
- {
- int curTutorId = filePtr->file_get_short();
- if( curTutorId > 0 )
- tutor.load(curTutorId); // load() will reset cur_text_block_id
- cur_text_block_id = filePtr->file_get_short();
- last_text_block_id = 0;
- return 1;
- }
- //--------- End of function Tutor::read_file ---------------//
- //### begin alex 23/9 ###//
- //-------- Start of function SeekPath::write_file -------------//
- //
- int SeekPath::write_file(File* filePtr)
- {
- filePtr->file_put_short(total_node_avail);
- return 1;
- }
- //--------- End of function SeekPath::write_file ---------------//
- //-------- Start of function SeekPath::read_file -------------//
- //
- int SeekPath::read_file(File* filePtr)
- {
- total_node_avail = filePtr->file_get_short();
- return 1;
- }
- //--------- End of function SeekPath::read_file ---------------//
- //#### end alex 23/9 ####//
|