53#include "table/strings.h"
80 static const SettingTable _generic_setting_tables[] = {
89 _news_display_settings,
90 _pathfinding_settings,
94 return _generic_setting_tables;
102 static const SettingTable _private_setting_tables[] = {
103 _network_private_settings,
105 return _private_setting_tables;
113 static const SettingTable _secrets_setting_tables[] = {
114 _network_secrets_settings,
116 return _secrets_setting_tables;
119typedef void SettingDescProc(
IniFile &ini,
const SettingTable &desc,
const char *grpname,
void *
object,
bool only_startup);
120typedef void SettingDescProcList(
IniFile &ini,
const char *grpname,
StringList &list);
122static bool IsSignedVarMemType(VarType vt)
139 inline static const IniGroupNameList list_group_names = {
143 "server_bind_addresses",
144 "server_authorized_keys",
145 "rcon_authorized_keys",
146 "admin_authorized_keys"
189 if (isdigit(*
str))
return std::strtoul(
str,
nullptr, 0);
192 for (
const auto &one :
many) {
193 if (one.size() == len && strncmp(one.c_str(),
str, len) == 0)
return idx;
208 if (strcmp(
str,
"true") == 0 || strcmp(
str,
"on") == 0 || strcmp(
str,
"1") == 0)
return true;
209 if (strcmp(
str,
"false") == 0 || strcmp(
str,
"off") == 0 || strcmp(
str,
"0") == 0)
return false;
229 while (*str ==
' ' || *str ==
'\t' || *str ==
'|') str++;
230 if (*str == 0)
break;
233 while (*s != 0 && *s !=
' ' && *s !=
'\t' && *s !=
'|') s++;
236 if (r == SIZE_MAX)
return r;
253 std::vector<uint32_t> result;
259 if (!comma)
return std::nullopt;
269 unsigned long v = std::strtoul(p, &end, 0);
270 if (p == end)
return std::nullopt;
272 result.push_back(ClampTo<uint32_t>(v));
282 if (!result.empty() && !comma)
return std::nullopt;
295static bool LoadIntList(
const char *str,
void *array,
int nelems, VarType type)
298 if (str ==
nullptr) {
299 memset(array, 0, nelems * elem_size);
304 if (!opt_items.has_value() || opt_items->size() != (
size_t)nelems)
return false;
306 char *p =
static_cast<char *
>(array);
307 for (
auto item : *opt_items) {
328 for (
size_t i = 0; i != this->
save.
length; i++) {
332 case SLE_VAR_I8: v = *(
const int8_t *)p; p += 1;
break;
333 case SLE_VAR_U8: v = *(
const uint8_t *)p; p += 1;
break;
334 case SLE_VAR_I16: v = *(
const int16_t *)p; p += 2;
break;
335 case SLE_VAR_U16: v = *(
const uint16_t *)p; p += 2;
break;
336 case SLE_VAR_I32: v = *(
const int32_t *)p; p += 4;
break;
337 case SLE_VAR_U32: v = *(
const uint32_t *)p; p += 4;
break;
338 default: NOT_REACHED();
340 if (i != 0) result +=
',';
341 result += std::to_string(v);
346std::string OneOfManySettingDesc::FormatSingleValue(uint
id)
const
348 if (
id >= this->
many.size()) {
349 return std::to_string(
id);
351 return this->
many[id];
356 uint
id = (uint)this->
Read(
object);
357 return this->FormatSingleValue(
id);
362 uint bitmask = (uint)this->
Read(
object);
369 if (!result.empty()) result +=
'|';
370 result += this->FormatSingleValue(
id);
383 size_t val = std::strtoul(
str, &end, 0);
404 if (r != SIZE_MAX)
return r;
415 if (r != SIZE_MAX)
return r;
426 if (r.has_value())
return *r;
441 return this->get_title_cb !=
nullptr ? this->get_title_cb(*
this) : this->
str;
450 return this->get_help_cb !=
nullptr ? this->get_help_cb(*
this) : this->
str_help;
459 if (this->get_value_params_cb !=
nullptr) {
460 return this->get_value_params_cb(*
this, value);
464 return {value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF, {}};
468 auto [min_val, _] = this->
GetRange();
469 return {this->
str_val - min_val + value, value};
490 return this->get_range_cb !=
nullptr ? this->get_range_cb(*
this) : std::tuple(this->
min, this->
max);
502 this->
Write(
object, val);
516 auto [min_val, max_val] = this->
GetRange();
534 val =
Clamp(val, min_val, max_val);
535 }
else if (val < min_val || val >
static_cast<int32_t
>(max_val)) {
544 uint32_t uval =
static_cast<uint32_t
>(val);
548 uval =
ClampU(uval, min_val, max_val);
549 }
else if (uval <
static_cast<uint32_t
>(min_val) || uval > max_val) {
554 val =
static_cast<int32_t
>(uval);
559 default: NOT_REACHED();
594 if (this->
max_length == 0 || str.size() < this->max_length)
return;
599 std::string stdstr(str, 0, this->
max_length - 1);
632static void IniLoadSettings(
IniFile &ini,
const SettingTable &settings_table,
const char *grpname,
void *
object,
bool only_startup)
637 for (
auto &desc : settings_table) {
640 if (sd->
startup != only_startup)
continue;
643 std::string s{ sd->
GetName() };
644 auto sc = s.find(
'.');
645 if (sc != std::string::npos) {
646 group = ini.
GetGroup(s.substr(0, sc));
647 if (group ==
nullptr) group = group_def;
648 s = s.substr(sc + 1);
654 if (group !=
nullptr) item = group->
GetItem(s);
655 if (item ==
nullptr && group != group_def && group_def !=
nullptr) {
660 if (item ==
nullptr) {
664 if (sc != std::string::npos) {
665 if (group = ini.
GetGroup(s.substr(0, sc)); group !=
nullptr) item = group->
GetItem(s.substr(sc + 1));
681 std::string str = (item ==
nullptr) ? this->
def : item->
value.value_or(
"");
683 this->
Write(
object, str);
688 const char *str = (item ==
nullptr) ? this->
def : item->
value.has_value() ? item->
value->c_str() :
nullptr;
714 IniGroup *group_def =
nullptr, *group;
716 for (
auto &desc : settings_table) {
724 std::string s{ sd->
GetName() };
725 auto sc = s.find(
'.');
726 if (sc != std::string::npos) {
728 s = s.substr(sc + 1);
734 IniItem &item = group->GetOrCreateItem(s);
746 if (IsSignedVarMemType(this->
save.
conv)) {
747 i = this->
Read(
object);
749 i = (uint32_t)this->
Read(
object);
751 return std::to_string(i);
756 bool val = this->
Read(
object) != 0;
757 return val ?
"true" :
"false";
763 int32_t object_value = this->
Read(
object);
764 return item_value == object_value;
769 int32_t object_value = this->
Read(
object);
780 const std::string &str = this->
Read(
object);
788 return fmt::format(
"\"{}\"", str);
790 default: NOT_REACHED();
800 const std::string &str = this->
Read(
object);
801 return item->
value->compare(str) == 0;
806 const std::string &str = this->
Read(
object);
807 return this->
def == str;
846 if (group ==
nullptr)
return;
851 if (!item.name.empty()) list.push_back(item.name);
869 for (
const auto &iter : list) {
908 (_game_mode == GM_NORMAL ||
958static void AILoadConfig(
const IniFile &ini,
const char *grpname)
963 for (
CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) {
968 if (group ==
nullptr)
return;
971 for (
const IniItem &item : group->items) {
974 config->
Change(item.name);
976 if (item.name !=
"none") {
977 Debug(script, 0,
"The AI by the name '{}' was no longer found, and removed from the list.", item.name);
983 if (c >= MAX_COMPANIES)
break;
987static void GameLoadConfig(
const IniFile &ini,
const char *grpname)
995 if (group ==
nullptr || group->
items.empty())
return;
1003 if (item.
name !=
"none") {
1004 Debug(script, 0,
"The GameScript by the name '{}' was no longer found, and removed from the list.", item.
name);
1018 if (
const IniItem *item = group->
GetItem(
"graphicsset"); item !=
nullptr && item->
value) BaseGraphics::ini_data.name = *item->
value;
1021 if (
const IniGroup *group = ini.
GetGroup(
"graphicsset"); group !=
nullptr) {
1023 if (
const IniItem *item = group->
GetItem(
"name"); item !=
nullptr && item->
value) BaseGraphics::ini_data.name = *item->
value;
1025 if (
const IniItem *item = group->
GetItem(
"shortname"); item !=
nullptr && item->
value && item->
value->size() == 8) {
1026 BaseGraphics::ini_data.
shortname = std::byteswap<uint32_t>(std::strtoul(item->
value->c_str(),
nullptr, 16));
1029 if (
const IniItem *item = group->
GetItem(
"extra_version"); item !=
nullptr && item->
value) BaseGraphics::ini_data.extra_version = std::strtoul(item->
value->c_str(),
nullptr, 10);
1031 if (
const IniItem *item = group->
GetItem(
"extra_params"); item !=
nullptr && item->
value) {
1033 if (params.has_value()) {
1055 if (group ==
nullptr)
return list;
1059 std::unique_ptr<GRFConfig> c{};
1061 std::array<uint8_t, 4> grfid_buf;
1063 std::string_view item_name = item.
name;
1064 bool has_md5sum =
false;
1067 auto grfid_pos = item_name.find(
"|");
1068 if (grfid_pos != std::string_view::npos) {
1069 std::string_view grfid_str = item_name.substr(0, grfid_pos);
1072 item_name = item_name.substr(grfid_pos + 1);
1074 auto md5sum_pos = item_name.find(
"|");
1075 if (md5sum_pos != std::string_view::npos) {
1076 std::string_view md5sum_str = item_name.substr(0, md5sum_pos);
1079 if (has_md5sum) item_name = item_name.substr(md5sum_pos + 1);
1082 uint32_t grfid = grfid_buf[0] | (grfid_buf[1] << 8) | (grfid_buf[2] << 16) | (grfid_buf[3] << 24);
1085 if (s !=
nullptr) c = std::make_unique<GRFConfig>(*s);
1089 if (s !=
nullptr) c = std::make_unique<GRFConfig>(*s);
1093 std::string filename = std::string(item_name);
1095 if (c ==
nullptr) c = std::make_unique<GRFConfig>(filename);
1098 if (item.
value.has_value() && !item.
value->empty()) {
1100 if (params.has_value()) {
1101 c->SetParams(params.value());
1113 reason = STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND;
1115 reason = STR_CONFIG_ERROR_INVALID_GRF_UNSAFE;
1117 reason = STR_CONFIG_ERROR_INVALID_GRF_SYSTEM;
1119 reason = STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE;
1121 reason = STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN;
1125 GetEncodedString(STR_CONFIG_ERROR_INVALID_GRF, filename.empty() ? item.
name.c_str() : filename, reason),
1131 auto found = std::ranges::find_if(list, [&c](
const auto &gc) {
return gc->ident.grfid == c->ident.grfid; });
1132 if (found != std::end(list)) {
1134 GetEncodedString(STR_CONFIG_ERROR_DUPLICATE_GRFID, c->filename, (*found)->filename),
1150 list.push_back(std::move(c));
1159 if (group ==
nullptr)
return IFV_0;
1161 auto version_number = group->
GetItem(
"ini_version");
1163 if (version_number ==
nullptr || !version_number->value.has_value())
return IFV_0;
1165 uint32_t version = 0;
1166 std::from_chars(version_number->value->data(), version_number->value->data() + version_number->value->size(), version);
1171static void AISaveConfig(
IniFile &ini,
const char *grpname)
1176 for (
CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) {
1191static void GameSaveConfig(
IniFile &ini,
const char *grpname)
1227 if (used_set ==
nullptr)
return;
1235 const GRFConfig *extra_cfg = used_set->GetExtraConfig();
1236 if (extra_cfg !=
nullptr && !extra_cfg->
param.empty()) {
1243static void GRFSaveConfig(
IniFile &ini,
const char *grpname,
const GRFConfigList &list)
1248 for (
const auto &c : list) {
1249 std::string key = fmt::format(
"{:08X}|{}|{}", std::byteswap(c->ident.grfid),
1256static void HandleSettingDescs(
IniFile &generic_ini,
IniFile &private_ini,
IniFile &secrets_ini, SettingDescProc *proc, SettingDescProcList *proc_list,
bool only_startup =
false)
1258 proc(generic_ini, _misc_settings,
"misc",
nullptr, only_startup);
1259#if defined(_WIN32) && !defined(DEDICATED)
1260 proc(generic_ini, _win32_settings,
"win32",
nullptr, only_startup);
1275 proc(generic_ini, _currency_settings,
"currency", &
GetCustomCurrency(), only_startup);
1278 if (!only_startup) {
1299 for (
auto &desc : table) {
1303 std::string s{ sd->
GetName() };
1304 auto sc = s.find(
'.');
1305 if (sc == std::string::npos)
continue;
1308 if (group ==
nullptr)
continue;
1309 s = s.substr(sc + 1);
1340 *old_item =
nullptr;
1344 if (igroup ==
nullptr)
return false;
1350 if (tmp_old_item ==
nullptr)
return false;
1356 if (new_item !=
nullptr)
return false;
1358 *old_item = tmp_old_item;
1375 IniFileVersion generic_version = LoadVersionFromConfig(generic_ini);
1398 if (network !=
nullptr) {
1399 const IniItem *use_relay_service = network->
GetItem(
"use_relay_service");
1400 if (use_relay_service !=
nullptr) {
1401 if (use_relay_service->
value ==
"never") {
1403 }
else if (use_relay_service->
value ==
"ask") {
1405 }
else if (use_relay_service->
value ==
"allow") {
1420 static std::vector<std::string> _old_autosave_interval{
"off",
"monthly",
"quarterly",
"half year",
"yearly"};
1423 switch (old_value) {
1441 AILoadConfig(generic_ini,
"ai_players");
1442 GameLoadConfig(generic_ini,
"game_scripts");
1466 IniFileVersion generic_version = LoadVersionFromConfig(generic_ini);
1472 if (
IniGroup *group = private_ini.
GetGroup(
"private"); group !=
nullptr) group->
comment =
"; This file possibly contains private information which can identify you as person.\n";
1473 if (
IniGroup *group = secrets_ini.
GetGroup(
"secrets"); group !=
nullptr) group->
comment =
"; Do not share this file with others, not even if they claim to be technical support.\n; This file contains saved passwords and other secrets that should remain private to you!\n";
1475 if (generic_version ==
IFV_0) {
1497 if (game_creation !=
nullptr) {
1498 game_creation->
RemoveItem(
"generation_seed");
1505 if (network !=
nullptr) {
1514 AISaveConfig(generic_ini,
"ai_players");
1515 GameSaveConfig(generic_ini,
"game_scripts");
1539 if (group.
name.compare(0, 7,
"preset-") == 0) {
1540 list.push_back(group.
name.substr(7));
1555 std::string section(
"preset-");
1556 section += config_name;
1559 GRFConfigList config =
GRFLoadConfig(ini, section.c_str(),
false);
1572 std::string section(
"preset-");
1573 section += config_name;
1576 GRFSaveConfig(ini, section.c_str(), config);
1586 std::string section(
"preset-");
1587 section += config_name;
1602 int32_t oldval = this->
Read(
object);
1605 if (oldval == newval)
return;
1607 this->
Write(
object, newval);
1635 if (sd->
GetName() == name)
return sd;
1639 std::string short_name_suffix = std::string{
"." }.append(name);
1643 if (sd->
GetName().ends_with(short_name_suffix))
return sd;
1659 saveloads.push_back(sd->
save);
1671 static const std::string_view company_prefix =
"company.";
1672 if (name.starts_with(company_prefix)) name.remove_prefix(company_prefix.size());
1686 if (sd !=
nullptr)
return sd;
1690 if (sd !=
nullptr)
return sd;
1694 if (sd !=
nullptr)
return sd;
1707 std::vector<const SettingDesc *> collection;
1710 for (
const auto &desc : table) {
1712 if (!func(*sd))
continue;
1714 collection.push_back(sd);
1795 if (_game_mode != GM_MENU) {
1802 if (force_newgame) {
1821 for (
auto &desc : _company_settings) {
1834 for (
auto &desc : _company_settings) {
1878 this->
Write(
object, newval);
1886void IConsoleSetSetting(
const char *name,
const char *value,
bool force_newgame)
1895 bool success =
true;
1918void IConsoleSetSetting(
const char *name,
int value)
1921 assert(sd !=
nullptr);
1946 auto [min_val, max_val] = int_setting->
GetRange();
1952static void IConsoleListSettingsTable(
const SettingTable &table,
const char *prefilter)
1954 for (
auto &desc : table) {
1957 if (prefilter !=
nullptr && sd->
GetName().find(prefilter) == std::string::npos)
continue;
1972 IConsoleListSettingsTable(table, prefilter);
1975 IConsoleListSettingsTable(table, prefilter);
1978 IConsoleListSettingsTable(table, prefilter);
AIConfig stores the configuration settings of every AI.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Common return value for all commands.
IniFile to store a configuration.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
void StartAction(GamelogActionType at)
Stores information about new action, but doesn't allocate it Action is allocated only when there is a...
void StopAction()
Stops logging of any changes.
void Setting(const std::string &name, int32_t oldval, int32_t newval)
Logs change in game settings.
@ SSS_FORCE_NEWGAME
Get the newgame Script config.
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
const std::string & GetName() const
Get the name of the Script.
void Change(std::optional< std::string > name, int version=-1, bool force_exact_match=false)
Set another Script to be loaded in this slot.
void StringToSettings(const std::string &value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
std::string SettingsToString() const
Convert the custom settings to a string that can be stored in the config file or savegames.
static constexpr int SECONDS_PER_DAY
approximate seconds per day, not for precise calculations
Functions related to commands.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
@ Execute
execute the given command
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
Configuration options of the network stuff.
static const uint NETWORK_MAX_GRF_COUNT
Maximum number of GRFs that can be sent.
void IConsolePrint(TextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.
Console functions used outside of the console code.
static const TextColour CC_HELP
Colour for help lines.
static const TextColour CC_INFO
Colour for information lines.
static const TextColour CC_DEFAULT
Default colour of the console.
static const TextColour CC_ERROR
Colour for error lines.
void ResetCurrencies(bool preserve_custom)
Will fill _currency_specs array with default values from origin_currency_specs Called only from newgr...
Functions to handle different currencies.
CurrencySpec & GetCustomCurrency()
Get the custom currency.
void DebugReconsiderSendRemoteMessages()
Reconsider whether we need to send debug messages to either NetworkAdminConsole or IConsolePrint.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Functions related to errors.
std::list< ErrorMessageData > ErrorList
Define a queue with errors.
void ScheduleErrorMessage(ErrorList &datas)
Schedule a list of errors.
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
void ShowFirstError()
Show the first error of the queue.
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, const CommandCost &cc)
Display an error message in a window.
bool FioCheckFileExists(const std::string &filename, Subdirectory subdir)
Check whether the given file exists.
Functions for Standard In/Out file operations.
@ NO_DIRECTORY
A path without any base directory.
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
Declarations for savegames operations.
fluid_settings_t * settings
FluidSynth settings handle.
GameConfig stores the configuration settings of every Game.
Gamelog _gamelog
Gamelog instance.
Functions to be called to log fundamental changes to the game.
@ GLAT_SETTING
Setting changed.
Functions related to world/map generation.
@ LG_ORIGINAL
The original landscape generator.
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
Value for custom sea level in difficulty settings.
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
Minimum percentage a user can specify for custom sea level.
Types related to reading/writing '*.ini' files.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
StringList _network_host_list
The servers we know.
bool _networking
are we in networking mode?
StringList _network_ban_list
The banned clients.
bool _network_server
network-server is active
StringList _network_bind_list
The addresses to bind on.
Basic functions/variables used all over the place.
Network functions used by other parts of OpenTTD.
GRFConfigList _grfconfig_static
First item in list of static GRF set up.
std::string GRFBuildParamList(const GRFConfig &c)
Build a string containing space separated parameter values, and terminate.
const GRFConfig * FindGRFConfig(uint32_t grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
Find a NewGRF in the scanned list.
GRFConfigList _grfconfig_newgame
First item in list of default GRF set up.
bool FillGRFDetails(GRFConfig &config, bool is_static, Subdirectory subdir)
Find the GRFID of a given grf, and calculate its md5sum.
Functions to find and configure NewGRFs.
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
@ System
GRF file is an openttd-internal system grf.
@ Static
GRF file is used statically (can be used in any MP game)
@ Unsafe
GRF file is unsafe for static usage.
@ Invalid
GRF is unusable with this version of OpenTTD.
@ FGCM_NEWEST_VALID
Find newest Grf, ignoring Grfs with GRFConfigFlag::Invalid set.
@ FGCM_EXACT
Only find Grfs matching md5sum.
void PickerSaveConfig(IniFile &ini)
Save favourites of all registered Pickers to config.
void PickerLoadConfig(const IniFile &ini)
Load favourites of all registered Pickers from config.
declaration of OTTD revision dependent variables
A number of safeguards to prevent using unsafe methods.
void WriteValue(void *ptr, VarType conv, int64_t val)
Write the value of a setting.
int64_t ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
@ SLE_VAR_NULL
useful to write zeros in savegame.
@ SLE_VAR_STR
string pointer
@ SLE_VAR_STRQ
string pointer enclosed in quotes
constexpr size_t SlVarSize(VarType type)
Return expect size in bytes of a VarType.
void * GetVariableAddress(const void *object, const SaveLoad &sld)
Get the address of the variable.
bool SlIsObjectCurrentlyValid(SaveLoadVersion version_from, SaveLoadVersion version_to)
Checks if some version from/to combination falls within the range of the active savegame version.
constexpr VarType GetVarMemType(VarType type)
Get the NumberType of a setting.
static void GraphicsSetLoadConfig(IniFile &ini)
Load BaseGraphics set selection and configuration.
void HandleOldDiffCustom(bool savegame)
Reading of the old diff_custom array and transforming it to the new format.
void SyncCompanySettings()
Sync all company settings in a multiplayer game.
static void RemoveEntriesFromIni(IniFile &ini, const SettingTable &table)
Remove all entries from a settings table from an ini-file.
StringList GetGRFPresetList()
Get the list of known NewGrf presets.
static void IniSaveSettings(IniFile &ini, const SettingTable &settings_table, const char *grpname, void *object, bool)
Save the values of settings to the inifile.
static void ValidateSettings()
Checks if any settings are set to incorrect values, and sets them to correct values in that case.
bool IsConversionNeeded(const ConfigIniFile &ini, const std::string &group, const std::string &old_var, const std::string &new_var, const IniItem **old_item)
Check whether a conversion should be done, and based on what old setting information.
static std::optional< std::vector< uint32_t > > ParseIntList(const char *p)
Parse a string into a vector of uint32s.
std::string _secrets_file
Secrets configuration file of OpenTTD.
std::string _favs_file
Picker favourites configuration file of OpenTTD.
static void IniLoadSettings(IniFile &ini, const SettingTable &settings_table, const char *grpname, void *object, bool only_startup)
Load values from a group of an IniFile structure into the internal representation.
static ErrorList _settings_error_list
Errors while loading minimal settings.
void IniLoadWindowSettings(IniFile &ini, const char *grpname, void *desc)
Load a WindowDesc from config.
static bool LoadIntList(const char *str, void *array, int nelems, VarType type)
Load parsed string-values into an integer-array (intlist)
void SetDefaultCompanySettings(CompanyID cid)
Set the company settings for a new company to their default values.
std::vector< const SettingDesc * > GetFilteredSettingCollection(std::function< bool(const SettingDesc &desc)> func)
Get a collection of settings matching a custom filter.
void LoadFromConfig(bool startup)
Load the values from the configuration files.
void SaveGRFPresetToConfig(const char *config_name, GRFConfigList &config)
Save a NewGRF configuration with a preset name.
bool SetSettingValue(const IntSettingDesc *sd, int32_t value, bool force_newgame)
Top function to save the new value of an element of the Settings struct.
void SaveToConfig()
Save the values to the configuration file.
VehicleDefaultSettings _old_vds
Used for loading default vehicles settings from old savegames.
void PrepareOldDiffCustom()
Prepare for reading and old diff_custom by zero-ing the memory.
static void IniLoadSettingList(IniFile &ini, const char *grpname, StringList &list)
Loads all items from a 'grpname' section into a list The list parameter can be a nullptr pointer,...
void GetSaveLoadFromSettingTable(SettingTable settings, std::vector< SaveLoad > &saveloads)
Get the SaveLoad for all settings in the settings table.
void IniSaveWindowSettings(IniFile &ini, const char *grpname, void *desc)
Save a WindowDesc to config.
static void IniSaveSettingList(IniFile &ini, const char *grpname, StringList &list)
Saves all items from a list into the 'grpname' section The list parameter can be a nullptr pointer,...
static void GraphicsSetSaveConfig(IniFile &ini)
Save BaseGraphics set selection and configuration.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static size_t LookupManyOfMany(const std::vector< std::string > &many, const char *str)
Find the set-integer value MANYofMANY type in a string.
CommandCost CmdChangeCompanySetting(DoCommandFlags flags, const std::string &name, int32_t value)
Change one of the per-company settings.
IniFileVersion
Ini-file versions.
@ IFV_0
0 All versions prior to introduction.
@ IFV_AUTOSAVE_RENAME
5 PR#11143 Renamed values of autosave to be in minutes.
@ IFV_LINKGRAPH_SECONDS
3 PR#10610 Store linkgraph update intervals in seconds instead of days.
@ IFV_REMOVE_GENERATION_SEED
7 PR#11927 Remove "generation_seed" from configuration.
@ IFV_MAX_VERSION
Highest possible ini-file version.
@ IFV_NETWORK_PRIVATE_SETTINGS
4 PR#10762 Move use_relay_service to private settings.
@ IFV_GAME_TYPE
2 PR#9515 Convert server_advertise to server_game_type.
@ IFV_RIGHT_CLICK_CLOSE
6 PR#10204 Add alternative right click to close windows setting.
@ IFV_PRIVATE_SECRETS
1 PR#9298 Moving of settings from openttd.cfg to private.cfg / secrets.cfg.
const uint16_t INIFILE_VERSION
Current ini-file version of OpenTTD.
static auto & SecretSettingTables()
List of all the secrets setting tables.
std::string _private_file
Private configuration file of OpenTTD.
void DeleteGRFPresetFromConfig(const char *config_name)
Delete a NewGRF configuration by preset name.
static const SettingDesc * GetSettingFromName(const std::string_view name, const SettingTable &settings)
Given a name of setting, return a setting description from the table.
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
static GRFConfigList GRFLoadConfig(const IniFile &ini, const char *grpname, bool is_static)
Load a GRF configuration.
void IConsoleGetSetting(const char *name, bool force_newgame)
Output value of a specific setting to the console.
void IConsoleListSettings(const char *prefilter)
List all settings and their value to the console.
static auto & PrivateSettingTables()
List of all the private setting tables.
static void SaveVersionInConfig(IniFile &ini)
Save the version of OpenTTD to the ini file.
std::string _config_file
Configuration file of OpenTTD.
static auto & GenericSettingTables()
List of all the generic setting tables.
GRFConfigList LoadGRFPresetFromConfig(const char *config_name)
Load a NewGRF configuration by preset-name.
static const SettingDesc * GetCompanySettingFromName(std::string_view name)
Given a name of setting, return a company setting description of it.
CommandCost CmdChangeSetting(DoCommandFlags flags, const std::string &name, int32_t value)
Network-safe changing of settings (server-only).
ClientSettings _settings_client
The current settings for this game.
Command definitions related to settings.
Functions related to setting/changing the settings.
@ NotInSave
Do not save with savegame, basically client-based.
@ Sandbox
This setting is a sandbox setting.
@ SceneditOnly
This setting can only be changed in the scenario editor.
@ PerCompany
This setting can be different for each company (saved in company struct).
@ NewgameOnly
This setting cannot be changed in a game.
@ GuiZeroIsSpecial
A value of zero is possible and has a custom string (the one after "strval").
@ NoNetwork
This setting does not apply to network games; it may not be changed during the game.
@ NotInConfig
Do not save to config file.
@ GuiDropdown
The value represents a limited number of string-options (internally integer) presented as dropdown.
@ SceneditToo
This setting can be changed in the scenario editor (only makes sense when SettingFlag::NewgameOnly is...
@ NoNetworkSync
Do not synchronize over network (but it is saved if SettingFlag::NotInSave is not set).
@ NetworkOnly
This setting only applies to network games.
SettingType
Type of settings for filtering.
@ ST_CLIENT
Client setting.
@ ST_COMPANY
Company setting.
static constexpr const SettingDesc * GetSettingDesc(const SettingVariant &desc)
Helper to convert the type of the iterated settings description to a pointer to it.
Definition of the configuration tables of the settings.
GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
Definition of base types and functions in a cross-platform compatible way.
static void StrMakeValid(T &dst, const char *str, const char *last, StringValidationSettings settings)
Copies the valid (UTF-8) characters from str up to last to the dst.
bool ConvertHexToBytes(std::string_view hex, std::span< uint8_t > bytes)
Convert a hex-string to a byte-array, while validating it was actually hex.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
Functions related to low-level strings.
@ SVS_NONE
Allow nothing and replace nothing.
std::vector< std::string > StringList
Type for a list of strings.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
std::vector< uint32_t > extra_params
parameters for the extra GRF
uint32_t shortname
unique key for base set
std::string name
The name of the base set.
uint32_t shortname
Four letter short variant of the name.
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
static std::optional< bool > ParseSingleValue(const char *str)
Find whether a string was a boolean true or a boolean false.
size_t ParseValue(const char *str) const override
Convert a string representation (external) of an integer-like setting to an integer.
All settings that are only important for the local client.
CompanySettings company
default values for per-company settings
NetworkSettings network
settings related to the network
GUISettings gui
settings related to the GUI
CompanySettings settings
settings specific for each company
uint8_t quantity_sea_lakes
the amount of seas/lakes
Information about GRF, used in the game and (part of it) in savegames.
uint32_t version
NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
std::vector< uint32_t > param
GRF parameters.
uint32_t autosave_interval
how often should we do autosaves?
RightClickClose right_click_wnd_close
close window with right click
uint8_t land_generator
the landscape generator
All settings together for the game.
DifficultySettings difficulty
settings related to the difficulty
GameCreationSettings game_creation
settings used during the creation of a game (map)
LinkGraphSettings linkgraph
settings for link graph calculations
All data of a graphics set.
Ini file that supports both loading and saving.
bool SaveToDisk(const std::string &filename)
Save the Ini file's data to the disk.
A group within an ini file.
const IniItem * GetItem(std::string_view name) const
Get the item with the given name.
std::string comment
comment for group
void Clear()
Clear all items in the group.
void RemoveItem(std::string_view name)
Remove the item with the given name.
std::string name
name of group
IniItem & CreateItem(std::string_view name)
Create an item with the given name.
IniItem & GetOrCreateItem(std::string_view name)
Get the item with the given name, and if it doesn't exist create a new item.
std::list< IniItem > items
all items in the group
A single "line" in an ini file.
std::optional< std::string > value
The value of this item.
std::string name
The name of this item.
void SetValue(std::string_view value)
Replace the current value with another value.
std::list< IniGroup > groups
all groups in the ini
void RemoveGroup(std::string_view name)
Remove the group with the given name.
void LoadFromDisk(const std::string &filename, Subdirectory subdir)
Load the Ini file's data from the disk.
const IniGroup * GetGroup(std::string_view name) const
Get the group with the given name.
IniGroup & GetOrCreateGroup(std::string_view name)
Get the group with the given name, and if it doesn't exist create a new group.
Base integer type, including boolean, settings.
StringID str_help
(Translated) string with help text; gui only.
StringID str_val
(Translated) first string describing the value.
void MakeValueValid(int32_t &value) const
Make the value valid given the limitations of this setting.
void ResetToDefault(void *object) const override
Reset the setting to its default value.
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
int32_t def
default value given when none is present
std::tuple< int32_t, uint32_t > GetRange() const
Get the min/max range for the setting.
StringID GetTitle() const
Get the title of the setting.
void ChangeValue(const void *object, int32_t newvalue) const
Handle changing a value.
uint32_t max
maximum values
GetDefaultValueCallback * get_def_cb
Callback to set the correct default value.
bool IsSameValue(const IniItem *item, void *object) const override
Check whether the value in the Ini item is the same as is saved in this setting in the object.
int32_t min
minimum values
PreChangeCheck * pre_check
Callback to check for the validity of the setting.
int32_t GetDefaultValue() const
Get the default value of the setting.
void Write(const void *object, int32_t value) const
Set the value of a setting.
StringID GetHelp() const
Get the help text of the setting.
virtual bool IsBoolSetting() const
Check whether this setting is a boolean type setting.
PostChangeCallback * post_callback
Callback when the setting has been changed.
StringID str
(translated) string with descriptive text; gui and console
void MakeValueValidAndWrite(const void *object, int32_t value) const
Make the value valid and then write it to the setting.
std::pair< StringParameter, StringParameter > GetValueParams(int32_t value) const
Get parameters for drawing the value of the setting.
virtual size_t ParseValue(const char *str) const
Convert a string representation (external) of an integer-like setting to an integer.
int32_t Read(const void *object) const
Read the integer from the the actual setting.
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
uint16_t recalc_time
time (in days) for recalculating each link graph component.
uint16_t recalc_interval
time (in days) between subsequent checks for link graphs to be calculated.
void ParseValue(const IniItem *item, void *object) const override
Parse/read the value from the Ini item into the setting associated with this object.
void ResetToDefault(void *object) const override
Reset the setting to its default value.
bool IsSameValue(const IniItem *item, void *object) const override
Check whether the value in the Ini item is the same as is saved in this setting in the object.
std::string FormatValue(const void *object) const override
Convert an integer-array (intlist) to a string representation.
const char * def
default value given when none is present
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
size_t ParseValue(const char *str) const override
Convert a string representation (external) of an integer-like setting to an integer.
NetworkAuthorizedKeys admin_authorized_keys
Public keys of clients that are authorized to use the admin network.
ServerGameType server_game_type
Server type: local / public / invite-only.
NetworkAuthorizedKeys rcon_authorized_keys
Public keys of clients that are authorized to use the rconsole (server side).
UseRelayService use_relay_service
Use relay service?
NetworkAuthorizedKeys server_authorized_keys
Public keys of clients that are authorized to connect to the game.
OnConvert * many_cnvt
callback procedure when loading value mechanism fails
size_t ParseValue(const char *str) const override
Convert a string representation (external) of an integer-like setting to an integer.
static size_t ParseSingleValue(const char *str, size_t len, const std::vector< std::string > &many)
Find the index value of a ONEofMANY type in a string separated by |.
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
std::vector< std::string > many
possible values for this type
static Titem * Get(auto index)
Returns Titem with given index.
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
uint16_t length
(Conditional) length of the variable (eg. arrays) (max array size is 65536 elements).
SaveLoadVersion version_to
Save/load the variable before this savegame version.
VarType conv
Type of the variable to be saved; this field combines both FileVarType and MemVarType.
SaveLoadVersion version_from
Save/load the variable starting from this savegame version.
Iterable ensemble of each set bit in a value.
Properties of config file settings.
virtual void ParseValue(const IniItem *item, void *object) const =0
Parse/read the value from the Ini item into the setting associated with this object.
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
SettingFlags flags
Handles how a setting would show up in the GUI (text/currency, etc.).
virtual bool IsStringSetting() const
Check whether this setting is an string type setting.
SettingType GetType() const
Return the type of the setting.
constexpr const std::string & GetName() const
Get the name of this setting.
bool startup
Setting has to be loaded directly at startup?.
virtual std::string FormatValue(const void *object) const =0
Format the value of the setting associated with this object.
const struct StringSettingDesc * AsStringSetting() const
Get the setting description of this setting as a string setting.
virtual bool IsSameValue(const IniItem *item, void *object) const =0
Check whether the value in the Ini item is the same as is saved in this setting in the object.
SaveLoad save
Internal structure (going to savegame, parts to config).
virtual bool IsIntSetting() const
Check whether this setting is an integer type setting.
const struct IntSettingDesc * AsIntSetting() const
Get the setting description of this setting as an integer setting.
const std::string & Read(const void *object) const
Read the string from the the actual setting.
std::string def
Default value given when none is present.
uint32_t max_length
Maximum length of the string, 0 means no maximum length.
PreChangeCheck * pre_check
Callback to check for the validity of the setting.
void MakeValueValid(std::string &str) const
Make the value valid given the limitations of this setting.
bool IsSameValue(const IniItem *item, void *object) const override
Check whether the value in the Ini item is the same as is saved in this setting in the object.
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
PostChangeCallback * post_callback
Callback when the setting has been changed.
void ResetToDefault(void *object) const override
Reset the setting to its default value.
void Write(const void *object, const std::string &str) const
Write a string to the actual setting.
void ChangeValue(const void *object, std::string &newval) const
Handle changing a string value.
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
void ParseValue(const IniItem *item, void *object) const override
Parse/read the value from the Ini item into the setting associated with this object.
Default settings for vehicles.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Window functions not directly related to making/drawing windows.
@ WC_ERRMSG
Error message; Window numbers:
@ WC_CHEATS
Cheat window; Window numbers:
@ WC_GAME_OPTIONS
Game options window; Window numbers: