MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CmdChangeSetting

Function CmdChangeSetting

src/settings.cpp:1770–1786  ·  view source on GitHub ↗

* Network-safe changing of settings (server-only). * @param flags operation to perform * @param name the name of the setting to change * @param value the new value for the setting * The new value is properly clamped to its minimum/maximum when setting * @return the cost of this operation or an error * @see _settings */

Source from the content-addressed store, hash-verified

1768 * @see _settings
1769 */
1770CommandCost CmdChangeSetting(DoCommandFlags flags, const std::string &name, int32_t value)
1771{
1772 if (name.empty()) return CMD_ERROR;
1773 const SettingDesc *sd = GetSettingFromName(name);
1774
1775 if (sd == nullptr) return CMD_ERROR;
1776 if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) return CMD_ERROR;
1777 if (!sd->IsIntSetting()) return CMD_ERROR;
1778
1779 if (!sd->IsEditable(true)) return CMD_ERROR;
1780
1781 if (flags.Test(DoCommandFlag::Execute)) {
1782 sd->AsIntSetting()->ChangeValue(&GetGameSettings(), value);
1783 }
1784
1785 return CommandCost();
1786}
1787
1788/**
1789 * Change one of the per-company settings.

Callers

nothing calls this directly

Calls 9

GetSettingFromNameFunction · 0.85
SlIsObjectCurrentlyValidFunction · 0.85
CommandCostClass · 0.85
TestMethod · 0.80
ChangeValueMethod · 0.80
AsIntSettingMethod · 0.80
emptyMethod · 0.45
IsIntSettingMethod · 0.45
IsEditableMethod · 0.45

Tested by

no test coverage detected