summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/afterload.cpp2
-rw-r--r--src/saveload/saveload.cpp90
-rw-r--r--src/saveload/saveload.h23
-rw-r--r--src/saveload/signs_sl.cpp2
4 files changed, 56 insertions, 61 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 969048115..de3f7ccff 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -248,7 +248,7 @@ static void InitializeWindowsAndCaches()
/* 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;
}
}
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index b5fdda27a..4dd8a4c7b 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -2778,10 +2778,10 @@ SaveOrLoadResult LoadWithFilter(LoadFilter *reader)
* @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;
@@ -2790,7 +2790,7 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo
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
@@ -2811,25 +2811,35 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo
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;
@@ -2837,24 +2847,25 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo
}
/* 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);
}
/**
@@ -2898,34 +2909,27 @@ void GenerateDefaultSaveName(char *buf, const char *last)
*/
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;
+ this->SetMode(FOP_LOAD, GetAbstractFileType(ft), GetDetailedFileType(ft));
+}
- default:
- this->mode = SL_INVALID;
- break;
+/**
+ * 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
diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h
index 43b9d5d3c..7b0ae8f48 100644
--- a/src/saveload/saveload.h
+++ b/src/saveload/saveload.h
@@ -22,25 +22,16 @@ enum SaveOrLoadResult {
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. */
@@ -58,7 +49,7 @@ 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();
diff --git a/src/saveload/signs_sl.cpp b/src/saveload/signs_sl.cpp
index 077d34501..132ac181e 100644
--- a/src/saveload/signs_sl.cpp
+++ b/src/saveload/signs_sl.cpp
@@ -60,7 +60,7 @@ static void Load_SIGN()
}
/* 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;
}
}