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

Function IConsoleGetSetting

src/settings.cpp:1970–1991  ·  view source on GitHub ↗

* Output value of a specific setting to the console * @param name Name of the setting to output its value * @param force_newgame force the newgame settings */

Source from the content-addressed store, hash-verified

1968 * @param force_newgame force the newgame settings
1969 */
1970void IConsoleGetSetting(std::string_view name, bool force_newgame)
1971{
1972 const SettingDesc *sd = GetSettingFromName(name);
1973 /* Company settings are not in "list_settings", so don't try to read them. */
1974 if (sd == nullptr || sd->flags.Test(SettingFlag::PerCompany)) {
1975 IConsolePrint(CC_ERROR, "'{}' is an unknown setting.", name);
1976 return;
1977 }
1978
1979 const void *object = (_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game;
1980
1981 if (sd->IsStringSetting()) {
1982 IConsolePrint(CC_INFO, "Current value for '{}' is '{}'.", sd->GetName(), sd->AsStringSetting()->Read(object));
1983 } else if (sd->IsIntSetting()) {
1984 std::string value = sd->FormatValue(object);
1985 const IntSettingDesc *int_setting = sd->AsIntSetting();
1986 auto [min_val, max_val] = int_setting->GetRange();
1987 auto def_val = int_setting->GetDefaultValue();
1988 IConsolePrint(CC_INFO, "Current value for '{}' is '{}' (min: {}{}, max: {}, def: {}).",
1989 sd->GetName(), value, sd->flags.Test(SettingFlag::GuiZeroIsSpecial) ? "(0) " : "", min_val, max_val, def_val);
1990 }
1991}
1992
1993static void IConsoleListSettingsTable(const SettingTable &table, std::string_view prefilter)
1994{

Callers 2

ConSettingFunction · 0.85
ConSettingNewgameFunction · 0.85

Calls 12

GetSettingFromNameFunction · 0.85
TestMethod · 0.80
AsStringSettingMethod · 0.80
AsIntSettingMethod · 0.80
GetDefaultValueMethod · 0.80
IConsolePrintFunction · 0.70
IsStringSettingMethod · 0.45
GetNameMethod · 0.45
ReadMethod · 0.45
IsIntSettingMethod · 0.45
FormatValueMethod · 0.45
GetRangeMethod · 0.45

Tested by

no test coverage detected