Пример #1
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 : <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;
}
Пример #2
0
//------- Begin of function GameFileArray::process_action ------//
//
// [int] saveNew - save on a new game file
//                 (default : 0)
//
// return : <int> 1 - process ok
//                0 - process cancelled
//               -1 - save/load failed
//
int GameFileArray::process_action(int saveNew)
{
	//------------ save game --------------//

	if( action_mode == 1 )
	{
		if( saveNew || browse_recno==0 )   // save on empty slot
		{
			if ( !save_new_game())
				return -1;
		}
		else           // save on existing slot
		{
			if( !box.ask( _("It will overwrite the existing saved game, proceed ?") ) )
				return 0;

			GameFile* gameFile = game_file_array[browse_recno];

			if( !gameFile->save_game())
				return -1;

			strcpy( last_file_name, gameFile->file_name );
		}

		return 1;
	}

	//----------- load game -------------//

	else
	{
		GameFile* gameFile = game_file_array[browse_recno];

		int rc = gameFile->load_game((const char*)sys.dir_config, NULL);
		if( rc > 0 )
			strcpy( last_file_name, gameFile->file_name );
		return rc;
	}

	return 0;
}
Пример #3
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 ########//
}
Пример #4
0
//------- Begin of function GameFileArray::process_action ------//
//
// [int] saveNew - save on a new game file
//                 (default : 0)
//
// return : <int> 1 - process ok
//                0 - process cancelled
//               -1 - save/load failed
//
int GameFileArray::process_action(int saveNew)
{
	//------------ save game --------------//

	if( action_mode == 1 )
	{
		if( saveNew || browse_recno==0 )   // save on empty slot
		{
			// #### begin Gilbert 20/1 ######//
			return save_new_game(NULL);
			// #### end Gilbert 20/1 ######//
		}
		else           // save on existing slot
		{
			if( !box.ask(text_game_menu.str_ask_overwrite()) )// "It will overwrite the existing saved game, proceed ?" ) )
				return 0;

			GameFile* gameFile = game_file_array[browse_recno];

			// ###### begin Gilbert 20/1 ########//
			if( !gameFile->ask_desc() )
				return 0;
			// ###### end Gilbert 20/1 ########//

			if( !gameFile->save_game(save_default_dir, NULL, NULL))
				return -1;

			strcpy( last_file_name, gameFile->file_name );
		}

		return 1;
	}

	//----------- load game -------------//

	else
	{
		GameFile* gameFile = game_file_array[browse_recno];

		// check gameFile->campaign_id. Campaign save game can be loaded
		// if and only if in campaign mode

		if( !sys.debug_session && gameFile->scenario_cheat_flag < sys.scenario_cheat_flag )
		{
			box.msg( text_game_menu.str_editor_cant_load() );// "Cannot load in scenario editor" );
			return 0;
		}

		// ###### begin Gilbert 9/4 ########//

		if( !pre_game && (game.is_campaign_mode() || gameFile->campaign_id) )
		{
			game.set_load_game_in_main_menu(gameFile->file_name);
			sys.signal_exit_flag = 2;		// quit to main menu and it will load game automatically
			return 1;
		}
		// ###### end Gilbert 9/4 ########//

		int rc = gameFile->load_game(save_default_dir, NULL);
		if( rc > 0 )
			strcpy( last_file_name, gameFile->file_name );
		return rc;
	}

	return 0;
}