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

Function IConsoleSetSetting

src/settings.cpp:1926–1956  ·  view source on GitHub ↗

Those 2 functions need to be here, else we have to make some stuff non-static * and besides, it is also better to keep stuff like this at the same place */

Source from the content-addressed store, hash-verified

1924/* Those 2 functions need to be here, else we have to make some stuff non-static
1925 * and besides, it is also better to keep stuff like this at the same place */
1926void IConsoleSetSetting(std::string_view name, std::string_view value, bool force_newgame)
1927{
1928 const SettingDesc *sd = GetSettingFromName(name);
1929 /* Company settings are not in "list_settings", so don't try to modify them. */
1930 if (sd == nullptr || sd->flags.Test(SettingFlag::PerCompany)) {
1931 IConsolePrint(CC_ERROR, "'{}' is an unknown setting.", name);
1932 return;
1933 }
1934
1935 bool success = true;
1936 if (sd->IsStringSetting()) {
1937 success = SetSettingValue(sd->AsStringSetting(), value, force_newgame);
1938 } else if (sd->IsIntSetting()) {
1939 const IntSettingDesc *isd = sd->AsIntSetting();
1940 size_t val = isd->ParseValue(value);
1941 if (!_settings_error_list.empty()) {
1942 IConsolePrint(CC_ERROR, "'{}' is not a valid value for this setting.", value);
1943 _settings_error_list.clear();
1944 return;
1945 }
1946 success = SetSettingValue(isd, (int32_t)val, force_newgame);
1947 }
1948
1949 if (!success) {
1950 if (_network_server) {
1951 IConsolePrint(CC_ERROR, "This command/variable is not available during network games.");
1952 } else {
1953 IConsolePrint(CC_ERROR, "This command/variable is only available to a network server.");
1954 }
1955 }
1956}
1957
1958void IConsoleSetSetting(std::string_view name, int value)
1959{

Callers 4

OnNewGRFsScannedMethod · 0.85
ConSettingFunction · 0.85
ConSettingNewgameFunction · 0.85
OnClickMethod · 0.85

Calls 11

GetSettingFromNameFunction · 0.85
SetSettingValueFunction · 0.85
TestMethod · 0.80
AsStringSettingMethod · 0.80
AsIntSettingMethod · 0.80
IConsolePrintFunction · 0.70
IsStringSettingMethod · 0.45
IsIntSettingMethod · 0.45
ParseValueMethod · 0.45
emptyMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected