diff options
author | Stephan <5377412+Taschi120@users.noreply.github.com> | 2021-07-09 21:44:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-09 21:44:02 +0200 |
commit | a70aa5df4938a6a4459690c4666a5c39a3f5bf98 (patch) | |
tree | b5296b3077a2268dda8394bfc0745dac81d3345a /src/saveload/saveload.cpp | |
parent | ce813ce644c58bbf07509eb8c409ec60512deaf0 (diff) | |
download | openttd-a70aa5df4938a6a4459690c4666a5c39a3f5bf98.tar.xz |
Add #9188: netsave now keeps multiple version around, similar to autosave (#9395)
Diffstat (limited to 'src/saveload/saveload.cpp')
-rw-r--r-- | src/saveload/saveload.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 74978c4db..d771bf526 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -3323,6 +3323,40 @@ SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, } } +/** + * Create an autosave or netsave. + * @param counter A reference to the counter variable to be used for rotating the file name. + * @param netsave Indicates if this is a regular autosave or a netsave. + */ +void DoAutoOrNetsave(int &counter, bool netsave) +{ + char buf[MAX_PATH]; + + if (_settings_client.gui.keep_all_autosave) { + GenerateDefaultSaveName(buf, lastof(buf)); + if (!netsave) { + strecat(buf, ".sav", lastof(buf)); + } else { + strecat(buf, "-netsave.sav", lastof(buf)); + } + } else { + /* Generate a savegame name and number according to _settings_client.gui.max_num_autosaves. */ + if (!netsave) { + seprintf(buf, lastof(buf), "autosave%d.sav", counter); + } else { + seprintf(buf, lastof(buf), "netsave%d.sav", counter); + } + + if (++counter >= _settings_client.gui.max_num_autosaves) counter = 0; + } + + Debug(sl, 2, "Autosaving to '{}'", buf); + if (SaveOrLoad(buf, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR) != SL_OK) { + ShowErrorMessage(STR_ERROR_AUTOSAVE_FAILED, INVALID_STRING_ID, WL_ERROR); + } +} + + /** Do a save when exiting the game (_settings_client.gui.autosave_on_exit) */ void DoExitSave() { |