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

Function CmdChangeCompanySetting

src/settings.cpp:1796–1809  ·  view source on GitHub ↗

* Change one of the per-company settings. * @param flags operation to perform * @param name the name of the company 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 */

Source from the content-addressed store, hash-verified

1794 * @return the cost of this operation or an error
1795 */
1796CommandCost CmdChangeCompanySetting(DoCommandFlags flags, const std::string &name, int32_t value)
1797{
1798 if (name.empty()) return CMD_ERROR;
1799 const SettingDesc *sd = GetCompanySettingFromName(name);
1800
1801 if (sd == nullptr) return CMD_ERROR;
1802 if (!sd->IsIntSetting()) return CMD_ERROR;
1803
1804 if (flags.Test(DoCommandFlag::Execute)) {
1805 sd->AsIntSetting()->ChangeValue(&Company::Get(_current_company)->settings, value);
1806 }
1807
1808 return CommandCost();
1809}
1810
1811/**
1812 * Top function to save the new value of an element of the Settings struct

Callers

nothing calls this directly

Calls 7

CommandCostClass · 0.85
TestMethod · 0.80
ChangeValueMethod · 0.80
AsIntSettingMethod · 0.80
emptyMethod · 0.45
IsIntSettingMethod · 0.45

Tested by

no test coverage detected