00001
00002
00003
00004 #include <IO.H>
00005 #include <ODIR.H>
00006 #include <OSYS.H>
00007 #include <ODATE.H>
00008 #include <OMOUSE.H>
00009 #include <OMOUSECR.H>
00010 #include <OPOWER.H>
00011
00012 #include <OBOX.H>
00013 #include <OFONT.H>
00014 #include <OINFO.H>
00015 #include <OGAME.H>
00016 #include <OGAMESET.H>
00017 #include <OGFILE.H>
00018
00019
00020
00021
00022 #define MAX_BROWSE_DISP_REC 5 // max. no. of records can be displayed in the saved game browser
00023
00024 #define HALL_OF_FAME_FILE_NAME "HALLFAME.DAT"
00025
00026
00027
00028 static int sort_game_file_function( const void *a, const void *b );
00029
00030
00031
00032
00033 GameFileArray::GameFileArray() : DynArray( sizeof(GameFile), 10 ) {
00034 demo_format = 0;
00035
00036 #ifdef DEMO
00037 demo_format = 1;
00038 #endif
00039
00040 #ifdef DEMO_DESIGN
00041 demo_format = 1;
00042 #endif
00043
00044 last_file_name[0] = NULL;
00045 has_read_hall_of_fame = 0;
00046
00047 memset( hall_fame_array, 0, sizeof(HallFame)*HALL_FAME_NUM );
00048 }
00049
00050
00051
00052
00053
00054 void GameFileArray::init(char *extStr) {
00055
00056
00057 if( !has_read_hall_of_fame ) {
00058 read_hall_of_fame();
00059 has_read_hall_of_fame = 1;
00060 }
00061
00062
00063
00064 load_all_game_header(extStr,
00065 #if(GAME_VERSION>=200)
00066 stricmp(extStr,"*.SAV")==0
00067 #else
00068 0
00069 #endif
00070 );
00071 }
00072
00073
00074
00075
00076
00077 void GameFileArray::deinit() {
00078 has_read_hall_of_fame = 0;
00079 }
00080
00081
00082
00083
00092
00093 GameFile gameFile;
00094 GameFile* gameFilePtr;
00095 int addFlag=1;
00096 int gameFileRecno;
00097
00098 memset( &gameFile, 0, sizeof(GameFile) );
00099
00100 if( fileName ) {
00101
00102
00103 for( gameFileRecno=1 ; gameFileRecno<=game_file_array.size() ; gameFileRecno++ ) {
00104 gameFilePtr = game_file_array[gameFileRecno];
00105
00106
00107 if( strcmp(gameFilePtr->file_name, fileName)==0 ) {
00108 addFlag=0;
00109 break;
00110 }
00111 }
00112
00113 strcpy( gameFile.file_name, fileName );
00114 }
00115 else {
00116 gameFile.set_file_name();
00117 }
00118
00119
00120
00121 if( gameFile.save_game(fileName) ) {
00122 strcpy( last_file_name, gameFile.file_name );
00123
00124 if( addFlag ) {
00125 linkin(&gameFile);
00126
00127 quick_sort( sort_game_file_function );
00128 }
00129 else {
00130
00131 game_file_array.update(&gameFile, gameFileRecno);
00132 }
00133 }
00134 }
00135
00136
00137
00138
00140
00141 if( !box.ask( "This saved game will be deleted, proceed ?" ) )
00142 return;
00143
00144
00145
00146 unlink(game_file_array[recNo]->file_name);
00147
00148 go(recNo);
00149 linkout();
00150
00151 go(recNo-1);
00152 }
00153
00154
00155
00156
00158
00159 if( !box.ask( "This express game will be deleted, proceed ?" ) )
00160 return;
00161
00162
00163
00164 unlink(game_file_array[recNo]->file_name);
00165
00166 go(recNo);
00167 linkout();
00168
00169 go(recNo-1);
00170 }
00171
00172
00173
00174
00180
00181 void GameFileArray::load_all_game_header(char *extStr, int readAutoSave) {
00182 int i;
00183 Directory gameDir;
00184 GameFile gameFile;
00185 File file;
00186
00187 #if(GAME_VERSION>=200)
00188 if( readAutoSave ) {
00189
00190
00191
00192
00193 gameDir.read( "*.*", 1 );
00194 for( i = gameDir.size(); i > 0; --i ) {
00195 char ext[_MAX_EXT];
00196 _splitpath( gameDir[i]->name, NULL, NULL, NULL, ext );
00197
00198 if( ext[0] == '.'
00199 && ext[1] >= '0' && ext[1] <= '9'
00200 && ext[2] >= '0' && ext[2] <= '9'
00201 && ext[3] >= '0' && ext[3] <= '9'
00202 && ext[4] == '\0' ) {
00203 continue;
00204 }
00205 gameDir.linkout(i);
00206 }
00207 }
00208
00209
00210 if( extStr )
00211 gameDir.read( extStr, 1 );
00212 #else
00213
00214 gameDir.read( extStr, 1 );
00215 #endif
00216
00217
00218
00219 zap();
00220
00221 for( i=1 ; i<=gameDir.size() ; i++ ) {
00222 if( file.file_open( gameDir[i]->name, 1, 1 )
00223 && file.file_read(&gameFile, sizeof(GameFile))
00224 && gameFile.validate_header() ) {
00225
00226 strcpy( gameFile.file_name, gameDir[i]->name );
00227 gameFile.file_date = gameDir[i]->time;
00228 linkin(&gameFile);
00229 }
00230 file.file_close();
00231 }
00232 }
00233
00234
00235
00236
00238
00239 return strcmp( ((GameFile*)a)->file_name, ((GameFile*)b)->file_name );
00240 }
00241
00242
00243
00244
00246
00247 int i;
00248
00249 for( i=game_file_array.size() ; i>0 ; i-- ) {
00250 if( strcmp(game_file_array[i]->file_name, game_file_array.last_file_name)==0 )
00251 return i;
00252 }
00253
00254 return 0;
00255 }
00256
00257
00258
00259
00260
00261 GameFile* GameFileArray::operator[](int recNo) {
00262 GameFile* gameFile = (GameFile*) get(recNo);
00263
00264
00265
00266 return gameFile;
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00279
00280 int rc;
00281 File file;
00282
00283
00284 rc = file.file_create( HALL_OF_FAME_FILE_NAME, 0, 1 );
00285
00286 if( !rc )
00287 return 0;
00288
00289
00290
00291 if( rc )
00292 rc = file.file_write( hall_fame_array, sizeof(HallFame) * HALL_FAME_NUM );
00293
00294
00295
00296 if( rc )
00297 rc = file.file_write( last_file_name, MAX_PATH+1 );
00298
00299 file.file_close();
00300
00301 return rc;
00302 }
00303
00304
00305
00306
00308
00309 if( !m.is_file_exist(HALL_OF_FAME_FILE_NAME) )
00310 return 0;
00311
00312 int rc;
00313 File file;
00314
00315
00316 rc = file.file_open( HALL_OF_FAME_FILE_NAME, 0, 1 );
00317
00318 if( !rc )
00319 return 0;
00320
00321
00322
00323 if( rc )
00324 rc = file.file_read( hall_fame_array, sizeof(HallFame) * HALL_FAME_NUM );
00325
00326
00327
00328 if( rc )
00329 rc = file.file_read( last_file_name, MAX_PATH+1);
00330
00331 file.file_close();
00332
00333 return rc;
00334 }
00335
00336