Changeset - r22443:89afba6ce61a
[Not reviewed]
master
0 16 0
alberth - 8 years ago 2016-09-04 12:57:43
alberth@openttd.org
(svn r27650) -Codechange: Replace SaveOrLoadMode by FileOperation and DetailedFileType.
16 files changed with 115 insertions and 102 deletions:
0 comments (0 inline, 0 general)
src/console_cmds.cpp
Show inline comments
 
@@ -315,13 +315,13 @@ DEF_CONSOLE_CMD(ConSave)
 
	}
 

	
 
	if (argc == 2) {
 
		char *filename = str_fmt("%s.sav", argv[1]);
 
		IConsolePrint(CC_DEFAULT, "Saving map...");
 

	
 
		if (SaveOrLoad(filename, SL_SAVE, SAVE_DIR) != SL_OK) {
 
		if (SaveOrLoad(filename, FOP_SAVE, DFT_GAME_FILE, SAVE_DIR) != SL_OK) {
 
			IConsolePrint(CC_ERROR, "Saving map failed");
 
		} else {
 
			IConsolePrintF(CC_DEFAULT, "Map successfully saved to %s", filename);
 
		}
 
		free(filename);
 
		return true;
src/crashlog.cpp
Show inline comments
 
@@ -385,13 +385,13 @@ bool CrashLog::WriteSavegame(char *filen
 
	try {
 
		GamelogEmergency();
 

	
 
		seprintf(filename, filename_last, "%scrash.sav", _personal_dir);
 

	
 
		/* Don't do a threaded saveload. */
 
		return SaveOrLoad(filename, SL_SAVE, NO_DIRECTORY, false) == SL_OK;
 
		return SaveOrLoad(filename, FOP_SAVE, DFT_GAME_FILE, NO_DIRECTORY, false) == SL_OK;
 
	} catch (...) {
 
		return false;
 
	}
 
}
 

	
 
/**
src/fileio_type.h
Show inline comments
 
@@ -44,14 +44,17 @@ enum DetailedFileType {
 

	
 
	DFT_INVALID = 255, ///< Unknown or invalid file.
 
};
 

	
 
/** Operation performed on the file. */
 
enum FileOperation {
 
	FOP_LOAD, ///< File is being loaded.
 
	FOP_SAVE, ///< File is being saved.
 
	FOP_CHECK,   ///< Load file for checking and/or preview.
 
	FOP_LOAD,    ///< File is being loaded.
 
	FOP_SAVE,    ///< File is being saved.
 

	
 
	FOP_INVALID, ///< Unknown file operation.
 
};
 

	
 
/**
 
 * Construct an enum value for #FiosType as a combination of an abstract and a detailed file type.
 
 * @param abstract Abstract file type (one of #AbstractFileType).
 
 * @param detailed Detailed file type (one of #DetailedFileType).
src/fios_gui.cpp
Show inline comments
 
@@ -581,13 +581,13 @@ public:
 
						if (this->selected != file) {
 
							this->selected = file;
 
							_load_check_data.Clear();
 

	
 
							if (GetDetailedFileType(file->type) == DFT_GAME_FILE) {
 
								/* Other detailed file types cannot be checked before. */
 
								SaveOrLoad(name, SL_LOAD_CHECK, NO_DIRECTORY, false);
 
								SaveOrLoad(name, FOP_CHECK, DFT_GAME_FILE, NO_DIRECTORY, false);
 
							}
 

	
 
							this->InvalidateData(1);
 
						}
 
						if (this->fop == FOP_SAVE) {
 
							/* Copy clicked name to editbox */
 
@@ -774,10 +774,10 @@ void ShowSaveLoadDialog(AbstractFileType
 
		sld = &_save_dialog_desc;
 
	} else {
 
		/* Dialogue for loading a file. */
 
		sld = (abstract_filetype == FT_HEIGHTMAP) ? &_load_heightmap_dialog_desc : &_load_dialog_desc;
 
	}
 

	
 
	_file_to_saveload.filetype = abstract_filetype;
 
	_file_to_saveload.abstract_ftype = abstract_filetype;
 

	
 
	new SaveLoadWindow(sld, abstract_filetype, fop);
 
}
src/genworld.cpp
Show inline comments
 
@@ -201,13 +201,13 @@ static void _GenerateWorld(void *)
 
		if (_network_dedicated) DEBUG(net, 1, "Map generated, starting game");
 
		DEBUG(desync, 1, "new_map: %08x", _settings_game.game_creation.generation_seed);
 

	
 
		if (_debug_desync_level > 0) {
 
			char name[MAX_PATH];
 
			seprintf(name, lastof(name), "dmp_cmds_%08x_%08x.sav", _settings_game.game_creation.generation_seed, _date);
 
			SaveOrLoad(name, SL_SAVE, AUTOSAVE_DIR, false);
 
			SaveOrLoad(name, FOP_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);
 
		}
 
	} catch (...) {
 
		BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP, true);
 
		if (_cur_company.IsValid()) _cur_company.Restore();
 
		_generating_world = false;
 
		_modal_progress_work_mutex->EndCritical();
src/genworld_gui.cpp
Show inline comments
 
@@ -830,13 +830,13 @@ static void _ShowGenerateLandscape(Gener
 

	
 
	/* Generate a new seed when opening the window */
 
	_settings_newgame.game_creation.generation_seed = InteractiveRandom();
 

	
 
	if (mode == GLWM_HEIGHTMAP) {
 
		/* If the function returns negative, it means there was a problem loading the heightmap */
 
		if (!GetHeightmapDimensions(_file_to_saveload.name, &x, &y)) return;
 
		if (!GetHeightmapDimensions(_file_to_saveload.detail_ftype, _file_to_saveload.name, &x, &y)) return;
 
	}
 

	
 
	WindowDesc *desc = (mode == GLWM_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc;
 
	GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow>(desc, mode, true);
 

	
 
	if (mode == GLWM_HEIGHTMAP) {
src/heightmap.cpp
Show inline comments
 
@@ -99,13 +99,13 @@ static void ReadHeightmapPNGImageData(by
 

	
 
/**
 
 * Reads the heightmap and/or size of the heightmap from a PNG file.
 
 * If map == NULL only the size of the PNG is read, otherwise a map
 
 * with grayscale pixels is allocated and assigned to *map.
 
 */
 
static bool ReadHeightmapPNG(char *filename, uint *x, uint *y, byte **map)
 
static bool ReadHeightmapPNG(const char *filename, uint *x, uint *y, byte **map)
 
{
 
	FILE *fp;
 
	png_structp png_ptr = NULL;
 
	png_infop info_ptr  = NULL;
 

	
 
	fp = FioFOpenFile(filename, "rb", HEIGHTMAP_DIR);
 
@@ -229,13 +229,13 @@ static void ReadHeightmapBMPImageData(by
 

	
 
/**
 
 * Reads the heightmap and/or size of the heightmap from a BMP file.
 
 * If map == NULL only the size of the BMP is read, otherwise a map
 
 * with grayscale pixels is allocated and assigned to *map.
 
 */
 
static bool ReadHeightmapBMP(char *filename, uint *x, uint *y, byte **map)
 
static bool ReadHeightmapBMP(const char *filename, uint *x, uint *y, byte **map)
 
{
 
	FILE *f;
 
	BmpInfo info;
 
	BmpData data;
 
	BmpBuffer buffer;
 

	
 
@@ -441,51 +441,62 @@ void FixSlopes()
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * Reads the heightmap with the correct file reader
 
 * Reads the heightmap with the correct file reader.
 
 * @param dft Type of image file.
 
 * @param filename Name of the file to load.
 
 * @param [out] x Length of the image.
 
 * @param [out] y Height of the image.
 
 * @param [inout] map If not \c NULL, destination to store the loaded block of image data.
 
 * @return Whether loading was successful.
 
 */
 
static bool ReadHeightMap(char *filename, uint *x, uint *y, byte **map)
 
static bool ReadHeightMap(DetailedFileType dft, const char *filename, uint *x, uint *y, byte **map)
 
{
 
	switch (_file_to_saveload.mode) {
 
		default: NOT_REACHED();
 
	switch (dft) {
 
		default:
 
			NOT_REACHED();
 

	
 
#ifdef WITH_PNG
 
		case SL_PNG:
 
		case DFT_HEIGHTMAP_PNG:
 
			return ReadHeightmapPNG(filename, x, y, map);
 
#endif /* WITH_PNG */
 
		case SL_BMP:
 

	
 
		case DFT_HEIGHTMAP_BMP:
 
			return ReadHeightmapBMP(filename, x, y, map);
 
	}
 
}
 

	
 
/**
 
 * Get the dimensions of a heightmap.
 
 * @param dft Type of image file.
 
 * @param filename to query
 
 * @param x dimension x
 
 * @param y dimension y
 
 * @return Returns false if loading of the image failed.
 
 */
 
bool GetHeightmapDimensions(char *filename, uint *x, uint *y)
 
bool GetHeightmapDimensions(DetailedFileType dft, const char *filename, uint *x, uint *y)
 
{
 
	return ReadHeightMap(filename, x, y, NULL);
 
	return ReadHeightMap(dft, filename, x, y, NULL);
 
}
 

	
 
/**
 
 * Load a heightmap from file and change the map in his current dimensions
 
 *  to a landscape representing the heightmap.
 
 * It converts pixels to height. The brighter, the higher.
 
 * @param dft Type of image file.
 
 * @param filename of the heightmap file to be imported
 
 */
 
void LoadHeightmap(char *filename)
 
void LoadHeightmap(DetailedFileType dft, const char *filename)
 
{
 
	uint x, y;
 
	byte *map = NULL;
 

	
 
	if (!ReadHeightMap(filename, &x, &y, &map)) {
 
	if (!ReadHeightMap(dft, filename, &x, &y, &map)) {
 
		free(map);
 
		return;
 
	}
 

	
 
	GrayscaleToMapHeights(x, y, map);
 
	free(map);
src/heightmap.h
Show inline comments
 
@@ -9,21 +9,23 @@
 

	
 
/** @file heightmap.h Functions related to creating heightmaps from files. */
 

	
 
#ifndef HEIGHTMAP_H
 
#define HEIGHTMAP_H
 

	
 
#include "fileio_type.h"
 

	
 
/**
 
 * Order of these enums has to be the same as in lang/english.txt
 
 * Otherwise you will get inconsistent behaviour.
 
 */
 
enum HeightmapRotation {
 
	HM_COUNTER_CLOCKWISE, ///< Rotate the map counter clockwise 45 degrees
 
	HM_CLOCKWISE,         ///< Rotate the map clockwise 45 degrees
 
};
 

	
 
bool GetHeightmapDimensions(char *filename, uint *x, uint *y);
 
void LoadHeightmap(char *filename);
 
bool GetHeightmapDimensions(DetailedFileType dft, const char *filename, uint *x, uint *y);
 
void LoadHeightmap(DetailedFileType dft, const char *filename);
 
void FlatEmptyWorld(byte tile_height);
 
void FixSlopes();
 

	
 
#endif /* HEIGHTMAP_H */
src/landscape.cpp
Show inline comments
 
@@ -1219,13 +1219,13 @@ void GenerateLandscape(byte mode)
 
		GLS_OTHER        =  0, ///< Extra steps for other landscapes
 
	};
 
	uint steps = (_settings_game.game_creation.landscape == LT_TROPIC) ? GLS_TROPIC : GLS_OTHER;
 

	
 
	if (mode == GWM_HEIGHTMAP) {
 
		SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_HEIGHTMAP);
 
		LoadHeightmap(_file_to_saveload.name);
 
		LoadHeightmap(_file_to_saveload.detail_ftype, _file_to_saveload.name);
 
		IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
 
	} else if (_settings_game.game_creation.land_generator == LG_TERRAGENESIS) {
 
		SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_TERRAGENESIS);
 
		GenerateTerrainPerlin();
 
	} else {
 
		SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_ORIGINAL);
src/network/network_client.cpp
Show inline comments
 
@@ -517,13 +517,13 @@ bool ClientNetworkGameSocketHandler::IsC
 

	
 
/***********
 
 * Receiving functions
 
 *   DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p
 
 ************/
 

	
 
extern bool SafeLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL);
 
extern bool SafeLoad(const char *filename, FileOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL);
 

	
 
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p)
 
{
 
	/* We try to join a server which is full */
 
	ShowErrorMessage(STR_NETWORK_ERROR_SERVER_FULL, INVALID_STRING_ID, WL_CRITICAL);
 
	DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
 
@@ -833,13 +833,13 @@ NetworkRecvStatus ClientNetworkGameSocke
 
	LoadFilter *lf = this->savegame;
 
	this->savegame = NULL;
 
	lf->Reset();
 

	
 
	/* The map is done downloading, load it */
 
	ClearErrorMessages();
 
	bool load_success = SafeLoad(NULL, SL_LOAD, GM_NORMAL, NO_DIRECTORY, lf);
 
	bool load_success = SafeLoad(NULL, FOP_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, lf);
 

	
 
	/* Long savegame loads shouldn't affect the lag calculation! */
 
	this->last_packet = _realtime_tick;
 

	
 
	if (!load_success) {
 
		DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
src/openttd.cpp
Show inline comments
 
@@ -325,13 +325,13 @@ static void LoadIntroGame(bool load_newg
 

	
 
	/* Setup main window */
 
	ResetWindowSystem();
 
	SetupColoursAndInitialWindow();
 

	
 
	/* Load the default opening screen savegame */
 
	if (SaveOrLoad("opntitle.dat", SL_LOAD, BASESET_DIR) != SL_OK) {
 
	if (SaveOrLoad("opntitle.dat", FOP_LOAD, DFT_GAME_FILE, BASESET_DIR) != SL_OK) {
 
		GenerateWorld(GWM_EMPTY, 64, 64); // if failed loading, make empty world.
 
		WaitTillGeneratedWorld();
 
		SetLocalCompany(COMPANY_SPECTATOR);
 
	} else {
 
		SetLocalCompany(COMPANY_FIRST);
 
	}
 
@@ -616,14 +616,15 @@ int openttd_main(int argc, char *argv[])
 
				break;
 
			}
 
		case 'e': _switch_mode = (_switch_mode == SM_LOAD_GAME || _switch_mode == SM_LOAD_SCENARIO ? SM_LOAD_SCENARIO : SM_EDITOR); break;
 
		case 'g':
 
			if (mgo.opt != NULL) {
 
				strecpy(_file_to_saveload.name, mgo.opt, lastof(_file_to_saveload.name));
 
				_switch_mode = (_switch_mode == SM_EDITOR || _switch_mode == SM_LOAD_SCENARIO ? SM_LOAD_SCENARIO : SM_LOAD_GAME);
 
				_file_to_saveload.mode = SL_LOAD;
 
				bool is_scenario = _switch_mode == SM_EDITOR || _switch_mode == SM_LOAD_SCENARIO;
 
				_switch_mode = is_scenario ? SM_LOAD_SCENARIO : SM_LOAD_GAME;
 
				_file_to_saveload.SetMode(FOP_LOAD, is_scenario ? FT_SCENARIO : FT_SAVEGAME, DFT_GAME_FILE);
 

	
 
				/* if the file doesn't exist or it is not a valid savegame, let the saveload code show an error */
 
				const char *t = strrchr(_file_to_saveload.name, '.');
 
				if (t != NULL) {
 
					FiosType ft = FiosGetSavegameListCallback(FOP_LOAD, _file_to_saveload.name, t, NULL, NULL);
 
					if (ft != FIOS_TYPE_INVALID) _file_to_saveload.SetMode(ft);
 
@@ -647,13 +648,13 @@ int openttd_main(int argc, char *argv[])
 

	
 
			char title[80];
 
			title[0] = '\0';
 
			FiosGetSavegameListCallback(FOP_LOAD, mgo.opt, strrchr(mgo.opt, '.'), title, lastof(title));
 

	
 
			_load_check_data.Clear();
 
			SaveOrLoadResult res = SaveOrLoad(mgo.opt, SL_LOAD_CHECK, SAVE_DIR, false);
 
			SaveOrLoadResult res = SaveOrLoad(mgo.opt, FOP_CHECK, DFT_GAME_FILE, SAVE_DIR, false);
 
			if (res != SL_OK || _load_check_data.HasErrors()) {
 
				fprintf(stderr, "Failed to open savegame\n");
 
				if (_load_check_data.HasErrors()) {
 
					char buf[256];
 
					SetDParamStr(0, _load_check_data.error_data);
 
					GetString(buf, _load_check_data.error, lastof(buf));
 
@@ -994,20 +995,21 @@ static void MakeNewEditorWorld()
 
 * @param mode mode of loading, either SL_LOAD or SL_OLD_LOAD
 
 * @param newgm switch to this mode of loading fails due to some unknown error
 
 * @param filename file to be loaded
 
 * @param subdir default directory to look for filename, set to 0 if not needed
 
 * @param lf Load filter to use, if NULL: use filename + subdir.
 
 */
 
bool SafeLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL)
 
bool SafeLoad(const char *filename, FileOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL)
 
{
 
	assert(mode == SL_LOAD || (lf == NULL && mode == SL_OLD_LOAD));
 
	assert(fop == FOP_LOAD);
 
	assert(dft == DFT_GAME_FILE || (lf == NULL && dft == DFT_OLD_GAME_FILE));
 
	GameMode ogm = _game_mode;
 

	
 
	_game_mode = newgm;
 

	
 
	switch (lf == NULL ? SaveOrLoad(filename, mode, subdir) : LoadWithFilter(lf)) {
 
	switch (lf == NULL ? SaveOrLoad(filename, fop, dft, subdir) : LoadWithFilter(lf)) {
 
		case SL_OK: return true;
 

	
 
		case SL_REINIT:
 
#ifdef ENABLE_NETWORK
 
			if (_network_dedicated) {
 
				/*
 
@@ -1090,17 +1092,17 @@ void SwitchToMode(SwitchMode new_mode)
 
			break;
 

	
 
		case SM_LOAD_GAME: { // Load game, Play Scenario
 
			ResetGRFConfig(true);
 
			ResetWindowSystem();
 

	
 
			if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, NO_DIRECTORY)) {
 
			if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_NORMAL, NO_DIRECTORY)) {
 
				SetDParamStr(0, GetSaveLoadErrorString());
 
				ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
 
			} else {
 
				if (_file_to_saveload.filetype == FT_SCENARIO) {
 
				if (_file_to_saveload.abstract_ftype == FT_SCENARIO) {
 
					/* Reset engine pool to simplify changing engine NewGRFs in scenario editor. */
 
					EngineOverrideManager::ResetToCurrentNewGRFConfig();
 
				}
 
				/* Update the local company for a loaded game. It is either always
 
				 * company #1 (eg 0) or in the case of a dedicated server a spectator */
 
				SetLocalCompany(_network_dedicated ? COMPANY_SPECTATOR : COMPANY_FIRST);
 
@@ -1131,13 +1133,13 @@ void SwitchToMode(SwitchMode new_mode)
 

	
 
			GenerateWorld(GWM_HEIGHTMAP, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
 
			MarkWholeScreenDirty();
 
			break;
 

	
 
		case SM_LOAD_SCENARIO: { // Load scenario from scenario editor
 
			if (SafeLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) {
 
			if (SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_EDITOR, NO_DIRECTORY)) {
 
				SetLocalCompany(OWNER_NONE);
 
				_settings_newgame.game_creation.starting_year = _cur_year;
 
				/* Cancel the saveload pausing */
 
				DoCommandP(0, PM_PAUSED_SAVELOAD, 0, CMD_PAUSE);
 
			} else {
 
				SetDParamStr(0, GetSaveLoadErrorString());
 
@@ -1153,13 +1155,13 @@ void SwitchToMode(SwitchMode new_mode)
 
				BaseSounds::ini_set = stredup(BaseSounds::GetUsedSet()->name);
 
			}
 
			break;
 

	
 
		case SM_SAVE_GAME: // Save game.
 
			/* Make network saved games on pause compatible to singleplayer */
 
			if (SaveOrLoad(_file_to_saveload.name, SL_SAVE, NO_DIRECTORY) != SL_OK) {
 
			if (SaveOrLoad(_file_to_saveload.name, FOP_SAVE, DFT_GAME_FILE, NO_DIRECTORY) != SL_OK) {
 
				SetDParamStr(0, GetSaveLoadErrorString());
 
				ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
 
			} else {
 
				DeleteWindowById(WC_SAVELOAD, 0);
 
			}
 
			break;
 
@@ -1364,13 +1366,13 @@ void StateGameLoop()
 
		NewsLoop();
 
	} else {
 
		if (_debug_desync_level > 2 && _date_fract == 0 && (_date & 0x1F) == 0) {
 
			/* Save the desync savegame if needed. */
 
			char name[MAX_PATH];
 
			seprintf(name, lastof(name), "dmp_cmds_%08x_%08x.sav", _settings_game.game_creation.generation_seed, _date);
 
			SaveOrLoad(name, SL_SAVE, AUTOSAVE_DIR, false);
 
			SaveOrLoad(name, FOP_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);
 
		}
 

	
 
		CheckCaches();
 

	
 
		/* All these actions has to be done from OWNER_NONE
 
		 *  for multiplayer compatibility */
 
@@ -1421,13 +1423,13 @@ static void DoAutosave()
 
		seprintf(buf, lastof(buf), "autosave%d.sav", _autosave_ctr);
 

	
 
		if (++_autosave_ctr >= _settings_client.gui.max_num_autosaves) _autosave_ctr = 0;
 
	}
 

	
 
	DEBUG(sl, 2, "Autosaving to '%s'", buf);
 
	if (SaveOrLoad(buf, SL_SAVE, AUTOSAVE_DIR) != SL_OK) {
 
	if (SaveOrLoad(buf, FOP_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR) != SL_OK) {
 
		ShowErrorMessage(STR_ERROR_AUTOSAVE_FAILED, INVALID_STRING_ID, WL_ERROR);
 
	}
 
}
 

	
 
void GameLoop()
 
{
src/saveload/afterload.cpp
Show inline comments
 
@@ -245,13 +245,13 @@ static void InitializeWindowsAndCaches()
 

	
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
		/* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it
 
		 * accordingly if it is not the case.  No need to set it on companies that are not been used already,
 
		 * thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */
 
		if (_file_to_saveload.filetype == FT_SCENARIO && c->inaugurated_year != MIN_YEAR) {
 
		if (_file_to_saveload.abstract_ftype == FT_SCENARIO && c->inaugurated_year != MIN_YEAR) {
 
			c->inaugurated_year = _cur_year;
 
		}
 
	}
 

	
 
	/* Count number of objects per type */
 
	Object *o;
src/saveload/saveload.cpp
Show inline comments
 
@@ -2775,25 +2775,25 @@ SaveOrLoadResult LoadWithFilter(LoadFilt
 
 * @param filename The name of the savegame being created/loaded
 
 * @param mode Save or load mode. Load can also be a TTD(Patch) game. Use #SL_LOAD, #SL_OLD_LOAD, #SL_LOAD_CHECK, or #SL_SAVE.
 
 * @param sb The sub directory to save the savegame in
 
 * @param threaded True when threaded saving is allowed
 
 * @return Return the result of the action. #SL_OK, #SL_ERROR, or #SL_REINIT ("unload" the game)
 
 */
 
SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, bool threaded)
 
SaveOrLoadResult SaveOrLoad(const char *filename, FileOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded)
 
{
 
	/* An instance of saving is already active, so don't go saving again */
 
	if (_sl.saveinprogress && mode == SL_SAVE && threaded) {
 
	if (_sl.saveinprogress && fop == FOP_SAVE && dft == DFT_GAME_FILE && threaded) {
 
		/* if not an autosave, but a user action, show error message */
 
		if (!_do_autosave) ShowErrorMessage(STR_ERROR_SAVE_STILL_IN_PROGRESS, INVALID_STRING_ID, WL_ERROR);
 
		return SL_OK;
 
	}
 
	WaitTillSaved();
 

	
 
	try {
 
		/* Load a TTDLX or TTDPatch game */
 
		if (mode == SL_OLD_LOAD) {
 
		if (fop == FOP_LOAD && dft == DFT_OLD_GAME_FILE) {
 
			InitializeGame(256, 256, true, true); // set a mapsize of 256x256 for TTDPatch games or it might get confused
 

	
 
			/* TTD/TTO savegames have no NewGRFs, TTDP savegame have them
 
			 * and if so a new NewGRF list will be made in LoadOldSaveGame.
 
			 * Note: this is done here because AfterLoadGame is also called
 
			 * for OTTD savegames which have their own NewGRF logic. */
 
@@ -2808,56 +2808,67 @@ SaveOrLoadResult SaveOrLoad(const char *
 
				return SL_REINIT;
 
			}
 
			GamelogStopAction();
 
			return SL_OK;
 
		}
 

	
 
		switch (mode) {
 
			case SL_LOAD_CHECK: _sl.action = SLA_LOAD_CHECK; break;
 
			case SL_LOAD: _sl.action = SLA_LOAD; break;
 
			case SL_SAVE: _sl.action = SLA_SAVE; break;
 
		assert(dft == DFT_GAME_FILE);
 
		switch (dft) {
 
			case FOP_CHECK:
 
				_sl.action = SLA_LOAD_CHECK;
 
				break;
 

	
 
			case FOP_LOAD:
 
				_sl.action = SLA_LOAD;
 
				break;
 

	
 
			case FOP_SAVE:
 
				_sl.action = SLA_SAVE;
 
				break;
 

	
 
			default: NOT_REACHED();
 
		}
 

	
 
		FILE *fh = (mode == SL_SAVE) ? FioFOpenFile(filename, "wb", sb) : FioFOpenFile(filename, "rb", sb);
 
		FILE *fh = (fop == FOP_SAVE) ? FioFOpenFile(filename, "wb", sb) : FioFOpenFile(filename, "rb", sb);
 

	
 
		/* Make it a little easier to load savegames from the console */
 
		if (fh == NULL && mode != SL_SAVE) fh = FioFOpenFile(filename, "rb", SAVE_DIR);
 
		if (fh == NULL && mode != SL_SAVE) fh = FioFOpenFile(filename, "rb", BASE_DIR);
 
		if (fh == NULL && mode != SL_SAVE) fh = FioFOpenFile(filename, "rb", SCENARIO_DIR);
 
		if (fh == NULL && fop != FOP_SAVE) fh = FioFOpenFile(filename, "rb", SAVE_DIR);
 
		if (fh == NULL && fop != FOP_SAVE) fh = FioFOpenFile(filename, "rb", BASE_DIR);
 
		if (fh == NULL && fop != FOP_SAVE) fh = FioFOpenFile(filename, "rb", SCENARIO_DIR);
 

	
 
		if (fh == NULL) {
 
			SlError(mode == SL_SAVE ? STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE : STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
 
			SlError(fop == FOP_SAVE ? STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE : STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
 
		}
 

	
 
		if (mode == SL_SAVE) { // SAVE game
 
		if (fop == FOP_SAVE) { // SAVE game
 
			DEBUG(desync, 1, "save: %08x; %02x; %s", _date, _date_fract, filename);
 
			if (_network_server || !_settings_client.gui.threaded_saves) threaded = false;
 

	
 
			return DoSave(new FileWriter(fh), threaded);
 
		}
 

	
 
		/* LOAD game */
 
		assert(mode == SL_LOAD || mode == SL_LOAD_CHECK);
 
		assert(fop == FOP_LOAD || fop == FOP_CHECK);
 
		DEBUG(desync, 1, "load: %s", filename);
 
		return DoLoad(new FileReader(fh), mode == SL_LOAD_CHECK);
 
		return DoLoad(new FileReader(fh), fop == FOP_CHECK);
 
	} catch (...) {
 
		/* This code may be executed both for old and new save games. */
 
		ClearSaveLoadState();
 

	
 
		/* Skip the "colour" character */
 
		if (mode != SL_LOAD_CHECK) DEBUG(sl, 0, "%s", GetSaveLoadErrorString() + 3);
 
		if (fop != FOP_CHECK) DEBUG(sl, 0, "%s", GetSaveLoadErrorString() + 3);
 

	
 
		/* A saver/loader exception!! reinitialize all variables to prevent crash! */
 
		return (mode == SL_LOAD || mode == SL_OLD_LOAD) ? SL_REINIT : SL_ERROR;
 
		return (fop == FOP_LOAD) ? SL_REINIT : SL_ERROR;
 
	}
 
}
 

	
 
/** Do a save when exiting the game (_settings_client.gui.autosave_on_exit) */
 
void DoExitSave()
 
{
 
	SaveOrLoad("exit.sav", SL_SAVE, AUTOSAVE_DIR);
 
	SaveOrLoad("exit.sav", FOP_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR);
 
}
 

	
 
/**
 
 * Fill the buffer with the default name for a savegame *or* screenshot.
 
 * @param buf the buffer to write to.
 
 * @param last the last element in the buffer.
 
@@ -2895,40 +2906,33 @@ void GenerateDefaultSaveName(char *buf, 
 
/**
 
 * Set the mode and file type of the file to save or load based on the type of file entry at the file system.
 
 * @param ft Type of file entry of the file system.
 
 */
 
void FileToSaveLoad::SetMode(FiosType ft)
 
{
 
	switch (ft) {
 
		case FIOS_TYPE_FILE:
 
		case FIOS_TYPE_SCENARIO:
 
			this->mode = SL_LOAD;
 
			break;
 

	
 
		case FIOS_TYPE_OLDFILE:
 
		case FIOS_TYPE_OLD_SCENARIO:
 
			this->mode = SL_OLD_LOAD;
 
			break;
 

	
 
#ifdef WITH_PNG
 
		case FIOS_TYPE_PNG:
 
			this->mode = SL_PNG;
 
			break;
 
#endif /* WITH_PNG */
 

	
 
		case FIOS_TYPE_BMP:
 
			this->mode = SL_BMP;
 
			break;
 

	
 
		default:
 
			this->mode = SL_INVALID;
 
			break;
 
	this->SetMode(FOP_LOAD, GetAbstractFileType(ft), GetDetailedFileType(ft));
 
}
 

	
 
/**
 
 * Set the mode and file type of the file to save or load.
 
 * @param fop File operation being performed.
 
 * @param aft Abstract file type.
 
 * @param dft Detailed file type.
 
 */
 
void FileToSaveLoad::SetMode(FileOperation fop, AbstractFileType aft, DetailedFileType dft)
 
{
 
	if (aft == FT_INVALID || aft == FT_NONE) {
 
		this->file_op = FOP_INVALID;
 
		this->detail_ftype = DFT_INVALID;
 
		this->abstract_ftype = FT_INVALID;
 
		return;
 
	}
 

	
 
	this->filetype = GetAbstractFileType(ft);
 
	if (this->filetype == FT_NONE) this->filetype = FT_INVALID;
 
	this->file_op = fop;
 
	this->detail_ftype = dft;
 
	this->abstract_ftype = aft;
 
}
 

	
 
#if 0
 
/**
 
 * Function to get the type of the savegame by looking at the file header.
 
 * NOTICE: Not used right now, but could be used if extensions of savegames are garbled
src/saveload/saveload.h
Show inline comments
 
@@ -19,31 +19,22 @@
 
enum SaveOrLoadResult {
 
	SL_OK     = 0, ///< completed successfully
 
	SL_ERROR  = 1, ///< error that was caught before internal structures were modified
 
	SL_REINIT = 2, ///< error that was caught in the middle of updating game state, need to clear it. (can only happen during load)
 
};
 

	
 
/** Save or load mode. @see SaveOrLoad */
 
enum SaveOrLoadMode {
 
	SL_INVALID    = -1, ///< Invalid mode.
 
	SL_LOAD       =  0, ///< Load game.
 
	SL_SAVE       =  1, ///< Save game.
 
	SL_OLD_LOAD   =  2, ///< Load old game.
 
	SL_PNG        =  3, ///< Load PNG file (height map).
 
	SL_BMP        =  4, ///< Load BMP file (height map).
 
	SL_LOAD_CHECK =  5, ///< Load for game preview.
 
};
 

	
 
/** Deals with the type of the savegame, independent of extension */
 
struct FileToSaveLoad {
 
	SaveOrLoadMode mode;       ///< savegame/scenario type (old, new)
 
	AbstractFileType filetype; ///< what type of file are we dealing with
 
	char name[MAX_PATH];       ///< name
 
	char title[255];           ///< internal name of the game
 
	FileOperation file_op;           ///< File operation to perform.
 
	DetailedFileType detail_ftype;   ///< Concrete file type (PNG, BMP, old save, etc).
 
	AbstractFileType abstract_ftype; ///< Abstract type of file (scenario, heightmap, etc).
 
	char name[MAX_PATH];             ///< Name of the file.
 
	char title[255];                 ///< Internal name of the game.
 

	
 
	void SetMode(FiosType ft);
 
	void SetMode(FileOperation fop, AbstractFileType aft, DetailedFileType dft);
 
};
 

	
 
/** Types of save games. */
 
enum SavegameType {
 
	SGT_TTD,    ///< TTD  savegame (can be detected incorrectly)
 
	SGT_TTDP1,  ///< TTDP savegame ( -//- ) (data at NW border)
 
@@ -55,13 +46,13 @@ enum SavegameType {
 

	
 
extern FileToSaveLoad _file_to_saveload;
 

	
 
void GenerateDefaultSaveName(char *buf, const char *last);
 
void SetSaveLoadError(uint16 str);
 
const char *GetSaveLoadErrorString();
 
SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, bool threaded = true);
 
SaveOrLoadResult SaveOrLoad(const char *filename, FileOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded = true);
 
void WaitTillSaved();
 
void ProcessAsyncSaveFinish();
 
void DoExitSave();
 

	
 
SaveOrLoadResult SaveWithFilter(struct SaveFilter *writer, bool threaded);
 
SaveOrLoadResult LoadWithFilter(struct LoadFilter *reader);
src/saveload/signs_sl.cpp
Show inline comments
 
@@ -57,13 +57,13 @@ static void Load_SIGN()
 
		 *  - so set owner to OWNER_NONE if needed (signs from pre-version 6.1 would be lost) */
 
		if (IsSavegameVersionBefore(6, 1) || (IsSavegameVersionBefore(83) && si->owner == INVALID_OWNER)) {
 
			si->owner = OWNER_NONE;
 
		}
 

	
 
		/* Signs placed in scenario editor shall now be OWNER_DEITY */
 
		if (IsSavegameVersionBefore(171) && si->owner == OWNER_NONE && _file_to_saveload.filetype == FT_SCENARIO) {
 
		if (IsSavegameVersionBefore(171) && si->owner == OWNER_NONE && _file_to_saveload.abstract_ftype == FT_SCENARIO) {
 
			si->owner = OWNER_DEITY;
 
		}
 
	}
 
}
 

	
 
/** Chunk handlers related to signs. */
src/video/dedicated_v.cpp
Show inline comments
 
@@ -139,13 +139,13 @@ static void CloseWindowsConsoleThread()
 

	
 
static void *_dedicated_video_mem;
 

	
 
/* Whether a fork has been done. */
 
bool _dedicated_forks;
 

	
 
extern bool SafeLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL);
 
extern bool SafeLoad(const char *filename, FileOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL);
 

	
 
static FVideoDriver_Dedicated iFVideoDriver_Dedicated;
 

	
 

	
 
const char *VideoDriver_Dedicated::Start(const char * const *parm)
 
{
 
@@ -283,13 +283,13 @@ void VideoDriver_Dedicated::MainLoop()
 
		SwitchToMode(_switch_mode);
 
		_switch_mode = SM_NONE;
 
	} else {
 
		_switch_mode = SM_NONE;
 
		/* First we need to test if the savegame can be loaded, else we will end up playing the
 
		 *  intro game... */
 
		if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, BASE_DIR)) {
 
		if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_NORMAL, BASE_DIR)) {
 
			/* Loading failed, pop out.. */
 
			DEBUG(net, 0, "Loading requested map failed, aborting");
 
			_networking = false;
 
		} else {
 
			/* We can load this game, so go ahead */
 
			SwitchToMode(SM_LOAD_GAME);
0 comments (0 inline, 0 general)