Mercurial > hg > openttd
changeset 14386:a992c2cc9b03 draft
(svn r18943) -Feature [FS#2885]: make it possible to change newgame settings from within a game via the console (use setting_newgame instead of setting)
author | yexo <yexo@openttd.org> |
---|---|
date | Thu, 28 Jan 2010 23:17:28 +0000 |
parents | 5539b78ca7a4 |
children | 564d4bfbb911 |
files | src/console_cmds.cpp src/settings.cpp src/settings_func.h src/settings_internal.h |
diffstat | 4 files changed, 37 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -1713,6 +1713,25 @@ return true; } +DEF_CONSOLE_CMD(ConSettingNewgame) +{ + if (argc == 0) { + IConsoleHelp("Change setting for the next game. Usage: 'setting_newgame <name> [<value>]'"); + IConsoleHelp("Omitting <value> will print out the current value of the setting."); + return true; + } + + if (argc == 1 || argc > 3) return false; + + if (argc == 2) { + IConsoleGetSetting(argv[1], true); + } else { + IConsoleSetSetting(argv[1], argv[2], true); + } + + return true; +} + DEF_CONSOLE_CMD(ConListSettings) { if (argc == 0) { @@ -1818,6 +1837,7 @@ IConsoleCmdRegister("pwd", ConPrintWorkingDirectory); IConsoleCmdRegister("clear", ConClearBuffer); IConsoleCmdRegister("setting", ConSetting); + IConsoleCmdRegister("setting_newgame", ConSettingNewgame); IConsoleCmdRegister("list_settings",ConListSettings); IConsoleCmdRegister("gamelog", ConGamelogPrint); @@ -1828,6 +1848,7 @@ IConsoleAliasRegister("new_game", "newgame"); IConsoleAliasRegister("patch", "setting %+"); IConsoleAliasRegister("set", "setting %+"); + IConsoleAliasRegister("set_newgame", "setting_newgame %+"); IConsoleAliasRegister("list_patches", "list_settings %+");
--- a/src/settings.cpp +++ b/src/settings.cpp @@ -1515,8 +1515,9 @@ * @param index offset in the SettingDesc array of the Settings struct which * identifies the setting member we want to change * @param value new value of the setting + * @param force_newgame force the newgame settings */ -bool SetSettingValue(uint index, int32 value) +bool SetSettingValue(uint index, int32 value, bool force_newgame) { const SettingDesc *sd = &_settings[index]; /* If an item is company-based, we do not send it over the network @@ -1536,6 +1537,12 @@ return true; } + if (force_newgame) { + void *var2 = GetVariableAddress(&_settings_newgame, &sd->save); + Write_ValidateSetting(var2, sd, value); + return true; + } + /* send non-company-based settings over the network */ if (!_networking || (_networking && _network_server)) { return DoCommandP(0, index, value, CMD_CHANGE_SETTING); @@ -1661,7 +1668,7 @@ /* Those 2 functions need to be here, else we have to make some stuff non-static * and besides, it is also better to keep stuff like this at the same place */ -void IConsoleSetSetting(const char *name, const char *value) +void IConsoleSetSetting(const char *name, const char *value, bool force_newgame) { uint index; const SettingDesc *sd = GetSettingFromName(name, &index); @@ -1683,7 +1690,7 @@ return; } - success = SetSettingValue(index, val); + success = SetSettingValue(index, val, force_newgame); } if (!success) { @@ -1706,8 +1713,9 @@ /** * Output value of a specific setting to the console * @param name Name of the setting to output its value + * @param force_newgame force the newgame settings */ -void IConsoleGetSetting(const char *name) +void IConsoleGetSetting(const char *name, bool force_newgame) { char value[20]; uint index; @@ -1719,7 +1727,7 @@ return; } - ptr = GetVariableAddress((_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game, &sd->save); + ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save); if (sd->desc.cmd == SDT_STRING) { IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, (const char *)ptr);
--- a/src/settings_func.h +++ b/src/settings_func.h @@ -15,9 +15,9 @@ #include "core/smallvec_type.hpp" #include "company_type.h" -void IConsoleSetSetting(const char *name, const char *value); +void IConsoleSetSetting(const char *name, const char *value, bool force_newgame = false); void IConsoleSetSetting(const char *name, int32 value); -void IConsoleGetSetting(const char *name); +void IConsoleGetSetting(const char *name, bool force_newgame = false); void IConsoleListSettings(const char *prefilter); void LoadFromConfig();
--- a/src/settings_internal.h +++ b/src/settings_internal.h @@ -85,7 +85,7 @@ typedef SettingDesc SettingDescGlobVarList; const SettingDesc *GetSettingFromName(const char *name, uint *i); -bool SetSettingValue(uint index, int32 value); +bool SetSettingValue(uint index, int32 value, bool force_newgame = false); bool SetSettingValue(uint index, const char *value); void SetCompanySetting(uint index, int32 value);