//-------- Begin of function GameFileArray::save_new_game -----// // // Save current game to a new saved game file immediately without // prompting menu. // // Called by GameFileArray::process_action() and error handler. // // [char*] fileName - file name of the saved game // // return : <int> 1 - saved successfully. // 0 - not saved. // int GameFileArray::save_new_game(const char* fileName) { GameFile gameFile; GameFile* gameFilePtr; int addFlag=1; int gameFileRecno; memset( &gameFile, 0, sizeof(GameFile) ); if( fileName ) { //----- check for overwriting an existing file ----// for( gameFileRecno=1 ; gameFileRecno<=game_file_array.size() ; gameFileRecno++ ) { gameFilePtr = game_file_array[gameFileRecno]; if( strcmp(gameFilePtr->file_name, fileName)==0 ) // if this file name already exist { addFlag=0; break; } } strcpy( gameFile.file_name, fileName ); } else { gameFile.set_file_name(); // give it a new game_file_name based on current group name } //----------- save game now ------------// if( gameFile.save_game(fileName) ) { strcpy( last_file_name, gameFile.file_name ); if( addFlag ) { linkin(&gameFile); quick_sort( sort_game_file_function ); } else { game_file_array.update(&gameFile, gameFileRecno); } return 1; } return 0; }
//-------- Begin of function GameFileArray::save_new_game -----// // // Save current game to a new saved game file immediately without // prompting menu. // // Called by GameFileArray::process_action() and error handler. // // <char*> fileName - file name of the saved game // // return 1 - success // 0 - cancel // -1 - fail // // ###### begin Gilbert 20/1 ########// int GameFileArray::save_new_game(const char* fileName) { GameFile gameFile; GameFile* gameFilePtr; int addFlag=1; int gameFileRecno; memset( &gameFile, 0, sizeof(GameFile) ); if( fileName ) // has a filename before extension { load_all_game_header( save_default_dir, save_default_ext ); // ### begin Gilbert 26/5 #####// // fileName = player_profile.save_game_path(fileName); // ### end Gilbert 26/5 #####// if( save_default_dir[0] != '\0' ) { strcpy( gameFile.file_name, save_default_dir ); strcat( gameFile.file_name, "/" ); strcat( gameFile.file_name, fileName ); } else { strcpy( gameFile.file_name, fileName ); } // if fileName without extension append if( !strchr(fileName, '.' ) ) { strcat(gameFile.file_name, strchr( save_default_ext, '.') ); // remove '*' of "*.SAV" } //----- check for overwriting an existing file ----// for( gameFileRecno=1 ; gameFileRecno<=game_file_array.size() ; gameFileRecno++ ) { gameFilePtr = game_file_array[gameFileRecno]; // ###### begin Gilbert 31/10 ######// if( strcasecmp(gameFilePtr->file_name, gameFile.file_name)==0 ) // if this file name already exist // ###### end Gilbert 31/10 ######// { addFlag=0; break; } } // strcpy( gameFile.file_name, fileName ); // now use gameFile.file_name instead } else { load_all_game_header( save_default_dir, save_default_ext ); // find the extension begin with '.' err_when( !strchr(save_default_ext, '.') ); gameFile.set_file_name(save_default_dir, strchr(save_default_ext, '.') ); // give it a new game_file_name based on current group name } // --------- ask description -------// if( !gameFile.ask_desc() ) return 0; //----------- save game now ------------// if( gameFile.save_game(save_default_dir, NULL, NULL) ) // use gameFile.file_name { strcpy( last_file_name, gameFile.file_name ); if( addFlag ) { linkin(&gameFile); quick_sort( sort_game_file_function ); } else { // #### begin Gilbert 31/10 ######// update(&gameFile, gameFileRecno); // #### end Gilbert 31/10 ######// } return 1; } return -1; // ###### end Gilbert 20/1 ########// }