summaryrefslogtreecommitdiff
path: root/src/settings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/settings.cpp')
-rw-r--r--src/settings.cpp30
1 files changed, 30 insertions, 0 deletions
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];
@@ -1502,6 +1503,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.
* @param value the value to write