diff --git a/Makefile b/Makefile index 8036237c21..8165839de7 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,9 @@ # WITH_DIRECTMUSIC: enable DirectMusic MIDI support # WITH_NETWORK: enable networking # DEDICATED: allows compilation on UNIX without SDL. Useful for dedicated servers +# MAX_NUM_AUTOSAVES: sets the number of autosaves the games will make before starting +# to overwrite the old ones. If not set, the game will use 16. +# NOTE: assign a number, not a string of a number # # Paths: # INSTALL: If not set, the game uses the directory of the binary to @@ -118,7 +121,7 @@ # Makefile version tag # it checks if the version tag in Makefile.config is the same and force update outdated config files -MAKEFILE_VERSION:=7 +MAKEFILE_VERSION:=8 # CONFIG_WRITER has to be found even for manual configuration CONFIG_WRITER=makefiledir/Makefile.config_writer @@ -512,6 +515,10 @@ CDEFS += -DMIDI_ARG=\"$(MIDI_ARG)\" endif endif +ifdef MAX_NUM_AUTOSAVES +CDEFS += -DMAX_NUM_AUTOSAVES=$(MAX_NUM_AUTOSAVES) +endif + ifdef WITH_NETWORK CDEFS += -DENABLE_NETWORK ifdef QNX diff --git a/makefiledir/Makefile.config_writer b/makefiledir/Makefile.config_writer index 0544bdb5a6..f74197edd9 100644 --- a/makefiledir/Makefile.config_writer +++ b/makefiledir/Makefile.config_writer @@ -19,6 +19,7 @@ $(MAKE_CONFIG): $(call CONFIG_LINE,\# SUPRESS_LANG_ERRORS: supresses output about missing and mismatched strings) $(call CONFIG_LINE,\# WITH_NETWORK: makes OpenTTD able to play multiplayer using TCP and UDP) $(call CONFIG_LINE,\# DEDICATED: compiles a dedicated server. This one can only host using a CLI, but do not need SDL) + $(call CONFIG_LINE,\# MAX_NUM_AUTOSAVES: sets the max number of autosaves the game keeps before overwriting old ones) $(call CONFIG_LINE,STATIC:=$(STATIC)) $(call CONFIG_LINE,TRANSLATOR:=$(TRANSLATOR)) $(call CONFIG_LINE,DISPLAY_WARNINGS:=$(DISPLAY_WARNINGS)) @@ -30,6 +31,7 @@ $(MAKE_CONFIG): $(call CONFIG_LINE,WITH_DIRECTMUSIC:=$(WITH_DIRECTMUSIC)) $(call CONFIG_LINE,WITH_NETWORK:=$(WITH_NETWORK)) $(call CONFIG_LINE,DEDICATED:=$(DEDICATED)) + $(call CONFIG_LINE,MAX_NUM_AUTOSAVES:=$(MAX_NUM_AUTOSAVES)) $(call CONFIG_LINE,GPMI:=$(GPMI)) $(call CONFIG_LINE,) diff --git a/openttd.c b/openttd.c index e63685382b..cc4732df72 100644 --- a/openttd.c +++ b/openttd.c @@ -888,10 +888,14 @@ static void DoAutosave(void) SetDParam(2, _date); s = GetString(buf + strlen(_path.autosave_dir) + strlen(PATHSEP), STR_4004); strcpy(s, ".sav"); - } else { /* Save a maximum of 15 autosaves */ - int n = _autosave_ctr; - _autosave_ctr = (_autosave_ctr + 1) & 15; - sprintf(buf, "%s%sautosave%d.sav", _path.autosave_dir, PATHSEP, n); + } else { /* generate a savegame name and number according to _patches.max_num_autosaves */ + sprintf(buf, "%s%sautosave%d.sav", _path.autosave_dir, PATHSEP, _autosave_ctr); + + _autosave_ctr++; + if (_autosave_ctr >= _patches.max_num_autosaves) { + // we reached the limit for numbers of autosaves. We will start over + _autosave_ctr = 0; + } } DEBUG(misc, 2) ("Autosaving to %s", buf); diff --git a/settings.c b/settings.c index 6a92e948a5..4456c09887 100644 --- a/settings.c +++ b/settings.c @@ -818,6 +818,11 @@ static const SettingDesc gameopt_settings[] = { {NULL, 0, NULL, NULL, NULL} }; +#if !defined(MAX_NUM_AUTOSAVES) +// no custom default max number of autosaves have been set in the makefile, so we will set the default max to 16 +#define MAX_NUM_AUTOSAVES 16 +#endif + // The player-based settings (are not send over the network) // Not everything can just be added to this list. For example, service_interval // can not be done, because every client assigns the service_interval value to the @@ -841,6 +846,7 @@ static const SettingDesc patch_player_settings[] = { {"toolbar_pos", SDT_UINT8, (void*)0, &_patches.toolbar_pos, NULL}, {"keep_all_autosave", SDT_BOOL, (void*)false, &_patches.keep_all_autosave, NULL}, {"autosave_on_exit", SDT_BOOL, (void*)false, &_patches.autosave_on_exit, NULL}, + {"max_autosave_num", SDT_UINT8, (void*)MAX_NUM_AUTOSAVES, &_patches.max_num_autosaves, NULL}, {"bridge_pillars", SDT_BOOL, (void*)true, &_patches.bridge_pillars, NULL}, {"invisible_trees", SDT_BOOL, (void*)false, &_patches.invisible_trees, NULL}, diff --git a/variables.h b/variables.h index ae1c3b61fd..1e9bb99eb6 100644 --- a/variables.h +++ b/variables.h @@ -155,6 +155,7 @@ typedef struct Patches { bool keep_all_autosave; // name the autosave in a different way. bool autosave_on_exit; // save an autosave when you quit the game, but do not ask "Do you really want to quit?" + byte max_num_autosaves; // controls how many autosavegames are made before the game starts to overwrite (names them 0 to max_num_autosaves - 1) bool extra_dynamite; // extra dynamite bool never_expire_vehicles; // never expire vehicles