summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorLoïc Guilloux <glx22@users.noreply.github.com>2021-07-17 12:48:35 +0200
committerGitHub <noreply@github.com>2021-07-17 12:48:35 +0200
commit460991ecf4fbeca2c0f8c39874b39a0885d6f67d (patch)
treebb4df8e1fba39293c8db4772c9b553a88a6fa58c /src/saveload
parent16abdd52546eb3cfa9d51d674c41711c2c170029 (diff)
downloadopenttd-460991ecf4fbeca2c0f8c39874b39a0885d6f67d.tar.xz
Feature: Persistant rotation of numbered auto/netsave after restart (#9397)
It was always starting from 0 on openttd restart. Now the most recent auto/netsave number will be used as a base to generate the next filename.
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/saveload.cpp17
-rw-r--r--src/saveload/saveload.h3
2 files changed, 5 insertions, 15 deletions
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index d771bf526..c8a1a0d29 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -3328,26 +3328,15 @@ SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop,
* @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)
+void DoAutoOrNetsave(FiosNumberedSaveName &counter)
{
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));
- }
+ strecat(buf, counter.Extension().c_str(), 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;
+ strecpy(buf, counter.Filename().c_str(), lastof(buf));
}
Debug(sl, 2, "Autosaving to '{}'", buf);
diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h
index d79bc1416..3047cbfd8 100644
--- a/src/saveload/saveload.h
+++ b/src/saveload/saveload.h
@@ -11,6 +11,7 @@
#define SAVELOAD_H
#include "../fileio_type.h"
+#include "../fios.h"
#include "../strings_type.h"
#include "../core/span_type.hpp"
#include <optional>
@@ -381,7 +382,7 @@ void WaitTillSaved();
void ProcessAsyncSaveFinish();
void DoExitSave();
-void DoAutoOrNetsave(int &counter, bool netsave = false);
+void DoAutoOrNetsave(FiosNumberedSaveName &counter);
SaveOrLoadResult SaveWithFilter(struct SaveFilter *writer, bool threaded);
SaveOrLoadResult LoadWithFilter(struct LoadFilter *reader);