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

Function SetSettingValue

src/settings.cpp:1818–1852  ·  view source on GitHub ↗

* Top function to save the new value of an element of the Settings struct * @param index offset in the SettingDesc array of the Settings struct which * identifies the setting member we want to change * @param value new value of the setting * @param force_newgame force the newgame settings */

Source from the content-addressed store, hash-verified

1816 * @param force_newgame force the newgame settings
1817 */
1818bool SetSettingValue(const IntSettingDesc *sd, int32_t value, bool force_newgame)
1819{
1820 const IntSettingDesc *setting = sd->AsIntSetting();
1821 if (setting->flags.Test(SettingFlag::PerCompany)) {
1822 if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
1823 return Command<CMD_CHANGE_COMPANY_SETTING>::Post(setting->GetName(), value);
1824 }
1825
1826 setting->ChangeValue(&_settings_client.company, value);
1827 return true;
1828 }
1829
1830 /* If an item is company-based, we do not send it over the network
1831 * (if any) to change. Also *hack*hack* we update the _newgame version
1832 * of settings because changing a company-based setting in a game also
1833 * changes its defaults. At least that is the convention we have chosen */
1834 if (setting->flags.Test(SettingFlag::NoNetworkSync)) {
1835 if (_game_mode != GM_MENU) {
1836 setting->ChangeValue(&_settings_newgame, value);
1837 }
1838 setting->ChangeValue(&GetGameSettings(), value);
1839 return true;
1840 }
1841
1842 if (force_newgame) {
1843 setting->ChangeValue(&_settings_newgame, value);
1844 return true;
1845 }
1846
1847 /* send non-company-based settings over the network */
1848 if (!_networking || (_networking && _network_server)) {
1849 return Command<CMD_CHANGE_SETTING>::Post(setting->GetName(), value);
1850 }
1851 return false;
1852}
1853
1854/**
1855 * Set the company settings for a new company to their default values.

Callers 9

ResetAllMethod · 0.85
IConsoleSetSettingFunction · 0.85
ChangeSettingValueMethod · 0.85
OnQueryTextFinishedMethod · 0.85
OptionsPanelClickMethod · 0.85
OnQueryTextFinishedMethod · 0.85
OnDropdownSelectMethod · 0.85
CheckServerNameMethod · 0.85
OnQueryTextFinishedMethod · 0.85

Calls 6

GetVarMemTypeFunction · 0.85
AsIntSettingMethod · 0.80
TestMethod · 0.80
ChangeValueMethod · 0.80
AsStringSettingMethod · 0.80
GetNameMethod · 0.45

Tested by

no test coverage detected