From 2a5a8f395c0c71146259433a1a4abe7807d2f8ac Mon Sep 17 00:00:00 2001 From: yexo Date: Tue, 26 May 2009 13:29:01 +0000 Subject: (svn r16433) -Codechange: Remove most of CmdSetAutoreplace and replace it with calls to CmdChangeCompanySetting --- src/settings.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/settings.cpp') diff --git a/src/settings.cpp b/src/settings.cpp index c59a4bd8e..d73e17161 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1425,6 +1425,7 @@ CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uin */ CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { + DEBUG(misc, 0, "Change company setting: %u into %u", p1, p2); if (p1 >= lengthof(_company_settings)) return CMD_ERROR; const SettingDesc *sd = &_company_settings[p1]; @@ -1501,6 +1502,35 @@ void SetCompanySetting(uint index, int32 value) } } +/** + * Sync all company settings in a multiplayer game. + */ +void SyncCompanySettings() +{ + const SettingDesc *sd; + uint i = 0; + for (sd = _company_settings; sd->save.cmd != SL_END; sd++, i++) { + const void *old_var = GetVariableAddress(&Company::Get(_current_company)->settings, &sd->save); + const void *new_var = GetVariableAddress(&_settings_client.company, &sd->save); + uint32 old_value = (uint32)ReadValue(old_var, sd->save.conv); + uint32 new_value = (uint32)ReadValue(new_var, sd->save.conv); + if (old_value != new_value) NetworkSend_Command(0, i, new_value, CMD_CHANGE_COMPANY_SETTING, NULL, NULL); + } +} + +/** + * Get the index in the _company_settings array of a setting + * @param name The name of the setting + * @return The index in the _company_settings array + */ +uint GetCompanySettingIndex(const char *name) +{ + uint i; + const SettingDesc *sd = GetSettingFromName(name, &i); + assert(sd != NULL && (sd->desc.flags & SGF_PER_COMPANY) != 0); + return i; +} + /** * Set a setting value with a string. * @param index the settings index. -- cgit v1.2.3-70-g09d2