From 22dc45738d2a3a9634693e43dbbf95d948142b83 Mon Sep 17 00:00:00 2001 From: frosch Date: Wed, 5 Dec 2012 19:35:09 +0000 Subject: (svn r24787) -Fix: Unify checks for editability of settings. --- src/settings.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/settings.cpp') diff --git a/src/settings.cpp b/src/settings.cpp index 36b15cd89..46360a2d1 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -732,6 +732,22 @@ static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList *li } } +/** + * Check whether the setting is editable in the current gamemode. + * @param do_command true if this is about checking a command from the server. + * @return true if editable. + */ +bool SettingDesc::IsEditable(bool do_command) const +{ + if (!do_command && !(this->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(this->desc.flags & SGF_PER_COMPANY)) return false; + if ((this->desc.flags & SGF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return false; + if ((this->desc.flags & SGF_NO_NETWORK) && _networking) return false; + if ((this->desc.flags & SGF_NEWGAME_ONLY) && + (_game_mode == GM_NORMAL || + (_game_mode == GM_EDITOR && !(this->desc.flags & SGF_SCENEDIT_TOO)))) return false; + return true; +} + /* Begin - Callback Functions for the various settings. */ /** Reposition the main toolbar as the setting changed. */ @@ -1782,13 +1798,7 @@ CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uin if (sd == NULL) return CMD_ERROR; if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) return CMD_ERROR; - if ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return CMD_ERROR; - if ((sd->desc.flags & SGF_NO_NETWORK) && _networking) return CMD_ERROR; - if ((sd->desc.flags & SGF_NEWGAME_ONLY) && - (_game_mode == GM_NORMAL || - (_game_mode == GM_EDITOR && (sd->desc.flags & SGF_SCENEDIT_TOO) == 0))) { - return CMD_ERROR; - } + if (!sd->IsEditable(true)) return CMD_ERROR; if (flags & DC_EXEC) { void *var = GetVariableAddress(&GetGameSettings(), &sd->save); -- cgit v1.2.3-54-g00ecf