forked from mirror/OpenTTD
(svn r3726) - [6/6] Finalize conversion, finally save the patches struct.
- Remove the temporary synchronisation in during the map-transfer as this is no longer needed - The saved patches work just like the saved gameoptions. You have a _patches and a _patches_newgame struct. The _patches_newgame struct contains the values from the configuration file and thus the defaults for new games. When a new game is started or an older game is loaded, the default values are copied over to _patches to be used. When you load a game that has PATS saved, the default values are also loaded, but immediately overwritten by the values from the savegame. This ensures that player-based values are always taken from your personal preferences. - The current implementation also changes the default values if you change player-based settings in the game. For example changing window_snap_radius in a certain game will also change it for all next OpenTTD sessions. - The savegame version has been increased to 22. - The last 6 orso patches close the following reports: [ 1366446 ] different names for patches: all patch settings have the same name as in the configuration file and are reachable from the console. [ 1288024 ] Strange string on OTTD initial screen: configuration (and this includes patches) inputs are validated and clamped to their minimum/maximum values. [ 1423198 ] Make "Signals on Drive side" player, not server, based: this is only visual so current setting is to save it with the savegame but not synchronise in multiplayer. [ 1208070 ] Patches and New GRF options saved: apart from newgrf this is done
This commit is contained in:
47
settings.c
47
settings.c
@@ -15,6 +15,9 @@
|
||||
#include "console.h"
|
||||
#include "saveload.h"
|
||||
|
||||
/** The patch values that are used for new games and/or modified in config file */
|
||||
Patches _patches_newgame;
|
||||
|
||||
typedef struct IniFile IniFile;
|
||||
typedef struct IniItem IniItem;
|
||||
typedef struct IniGroup IniGroup;
|
||||
@@ -1229,7 +1232,7 @@ static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescP
|
||||
#endif /* WIN32 */
|
||||
|
||||
proc(ini, _gameopt_settings, "gameopt", &_opt_newgame);
|
||||
proc(ini, _patch_settings, "patches", &_patches);
|
||||
proc(ini, _patch_settings, "patches", &_patches_newgame);
|
||||
proc(ini, _currency_settings,"currency", &_custom_currency);
|
||||
|
||||
#ifdef ENABLE_NETWORK
|
||||
@@ -1276,7 +1279,7 @@ int32 CmdChangePatchSetting(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
if (sd == NULL) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
Patches *patches_ptr = &_patches;
|
||||
Patches *patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches;
|
||||
void *var = ini_get_variable(&sd->save, patches_ptr);
|
||||
Write_ValidateSetting(var, sd, (int32)p2);
|
||||
|
||||
@@ -1303,6 +1306,11 @@ void SetPatchValue(uint index, const Patches *object, int32 value)
|
||||
if (sd->save.conv & SLF_NETWORK_NO) {
|
||||
void *var = ini_get_variable(&sd->save, object);
|
||||
Write_ValidateSetting(var, sd, value);
|
||||
|
||||
if (_game_mode != GM_MENU) {
|
||||
void *var2 = ini_get_variable(&sd->save, &_patches_newgame);
|
||||
Write_ValidateSetting(var2, sd, value);
|
||||
}
|
||||
} else {
|
||||
DoCommandP(0, index, value, NULL, CMD_CHANGE_PATCH_SETTING);
|
||||
}
|
||||
@@ -1336,7 +1344,7 @@ void IConsoleSetPatchSetting(const char *name, const char *value)
|
||||
}
|
||||
|
||||
sscanf(value, "%d", &val);
|
||||
patches_ptr = &_patches;
|
||||
patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches;
|
||||
ptr = ini_get_variable(&sd->save, patches_ptr);
|
||||
|
||||
SetPatchValue(index, patches_ptr, val);
|
||||
@@ -1362,7 +1370,7 @@ void IConsoleGetPatchSetting(const char *name)
|
||||
return;
|
||||
}
|
||||
|
||||
ptr = ini_get_variable(&sd->save, &_patches);
|
||||
ptr = ini_get_variable(&sd->save, (_game_mode == GM_MENU) ? &_patches_newgame : &_patches);
|
||||
|
||||
if (sd->desc.cmd == SDT_BOOLX) {
|
||||
snprintf(value, sizeof(value), (*(bool*)ptr == 1) ? "on" : "off");
|
||||
@@ -1439,6 +1447,20 @@ static void Save_OPTS(void)
|
||||
SaveSettings(_gameopt_settings, &_opt);
|
||||
}
|
||||
|
||||
static void Load_PATS(void)
|
||||
{
|
||||
/* Copy over default setting since some might not get loaded in
|
||||
* a networking environment. This ensures for example that the local
|
||||
* signal_side stays when joining a network-server */
|
||||
_patches = _patches_newgame;
|
||||
LoadSettings(_patch_settings, &_patches);
|
||||
}
|
||||
|
||||
static void Save_PATS(void)
|
||||
{
|
||||
SaveSettings(_patch_settings, &_patches);
|
||||
}
|
||||
|
||||
void CheckConfig(void)
|
||||
{
|
||||
// fix up news_display_opt from old to new
|
||||
@@ -1453,12 +1475,21 @@ void CheckConfig(void)
|
||||
|
||||
// Increase old default values for pf_maxdepth and pf_maxlength
|
||||
// to support big networks.
|
||||
if (_patches.pf_maxdepth == 16 && _patches.pf_maxlength == 512) {
|
||||
_patches.pf_maxdepth = 48;
|
||||
_patches.pf_maxlength = 4096;
|
||||
if (_patches_newgame.pf_maxdepth == 16 && _patches_newgame.pf_maxlength == 512) {
|
||||
_patches_newgame.pf_maxdepth = 48;
|
||||
_patches_newgame.pf_maxlength = 4096;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdatePatches(void)
|
||||
{
|
||||
/* Since old(er) savegames don't have any patches saved, we initialise
|
||||
* them with the default values just as it was in the old days.
|
||||
* Also new games need this copying-over */
|
||||
_patches = _patches_newgame; /* backwards compatibility */
|
||||
}
|
||||
|
||||
const ChunkHandler _setting_chunk_handlers[] = {
|
||||
{ 'OPTS', Save_OPTS, Load_OPTS, CH_RIFF | CH_LAST}
|
||||
{ 'OPTS', Save_OPTS, Load_OPTS, CH_RIFF},
|
||||
{ 'PATS', Save_PATS, Load_PATS, CH_RIFF | CH_LAST},
|
||||
};
|
||||
|
Reference in New Issue
Block a user