mirror of https://github.com/OpenTTD/OpenTTD.git
This commit is contained in:
parent
ce813ce644
commit
a70aa5df49
|
@ -132,12 +132,8 @@ struct PacketReader : LoadFilter {
|
|||
*/
|
||||
void ClientNetworkEmergencySave()
|
||||
{
|
||||
if (!_settings_client.gui.autosave_on_network_disconnect) return;
|
||||
if (!_networking) return;
|
||||
|
||||
const char *filename = "netsave.sav";
|
||||
Debug(net, 3, "Performing emergency save: {}", filename);
|
||||
SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);
|
||||
static int _netsave_ctr = 0;
|
||||
DoAutoOrNetsave(_netsave_ctr, true);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1392,24 +1392,8 @@ void StateGameLoop()
|
|||
*/
|
||||
static void DoAutosave()
|
||||
{
|
||||
char buf[MAX_PATH];
|
||||
|
||||
if (_settings_client.gui.keep_all_autosave) {
|
||||
GenerateDefaultSaveName(buf, lastof(buf));
|
||||
strecat(buf, ".sav", lastof(buf));
|
||||
} else {
|
||||
static int _autosave_ctr = 0;
|
||||
|
||||
/* generate a savegame name and number according to _settings_client.gui.max_num_autosaves */
|
||||
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 '{}'", buf);
|
||||
if (SaveOrLoad(buf, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR) != SL_OK) {
|
||||
ShowErrorMessage(STR_ERROR_AUTOSAVE_FAILED, INVALID_STRING_ID, WL_ERROR);
|
||||
}
|
||||
static int _autosave_ctr = 0;
|
||||
DoAutoOrNetsave(_autosave_ctr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -381,6 +381,8 @@ void WaitTillSaved();
|
|||
void ProcessAsyncSaveFinish();
|
||||
void DoExitSave();
|
||||
|
||||
void DoAutoOrNetsave(int &counter, bool netsave = false);
|
||||
|
||||
SaveOrLoadResult SaveWithFilter(struct SaveFilter *writer, bool threaded);
|
||||
SaveOrLoadResult LoadWithFilter(struct LoadFilter *reader);
|
||||
|
||||
|
|
Loading…
Reference in New Issue