|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
50 #include "table/strings.h"
76 static const SettingTable _generic_setting_tables[] = {
85 _news_display_settings,
86 _pathfinding_settings,
90 return _generic_setting_tables;
98 static const SettingTable _private_setting_tables[] = {
99 _network_private_settings,
101 return _private_setting_tables;
109 static const SettingTable _secrets_setting_tables[] = {
110 _network_secrets_settings,
112 return _secrets_setting_tables;
115 typedef void SettingDescProc(
IniFile &ini,
const SettingTable &desc,
const char *grpname,
void *
object,
bool only_startup);
116 typedef void SettingDescProcList(
IniFile &ini,
const char *grpname,
StringList &list);
118 static bool IsSignedVarMemType(VarType vt)
135 inline static const IniGroupNameList list_group_names = {
139 "server_bind_addresses",
182 if (isdigit(*
str))
return std::strtoul(
str,
nullptr, 0);
185 for (
auto one :
many) {
186 if (one.size() == len && strncmp(one.c_str(),
str, len) == 0)
return idx;
201 if (strcmp(
str,
"true") == 0 || strcmp(
str,
"on") == 0 || strcmp(
str,
"1") == 0)
return true;
202 if (strcmp(
str,
"false") == 0 || strcmp(
str,
"off") == 0 || strcmp(
str,
"0") == 0)
return false;
222 while (*str ==
' ' || *str ==
'\t' || *str ==
'|') str++;
223 if (*str == 0)
break;
226 while (*s != 0 && *s !=
' ' && *s !=
'\t' && *s !=
'|') s++;
229 if (r == (
size_t)-1)
return r;
256 if (!comma)
return -1;
265 if (n == maxitems)
return -1;
267 unsigned long v = std::strtoul(p, &end, 0);
268 if (p == end)
return -1;
269 if (
sizeof(T) <
sizeof(v)) v = Clamp<unsigned long>(v, std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
280 if (n != 0 && !comma)
return -1;
282 return ClampTo<int>(n);
293 static bool LoadIntList(
const char *str,
void *array,
int nelems, VarType type)
295 unsigned long items[64];
298 if (str ==
nullptr) {
299 memset(items, 0,
sizeof(items));
303 if (nitems != nelems)
return false;
310 for (i = 0; i != nitems; i++) ((
byte*)array)[i] = items[i];
315 for (i = 0; i != nitems; i++) ((uint16_t*)array)[i] = items[i];
320 for (i = 0; i != nitems; i++) ((uint32_t*)array)[i] = items[i];
323 default: NOT_REACHED();
343 for (
size_t i = 0; i != this->
save.
length; i++) {
347 case SLE_VAR_I8: v = *(
const int8_t *)p; p += 1;
break;
348 case SLE_VAR_U8: v = *(
const uint8_t *)p; p += 1;
break;
349 case SLE_VAR_I16: v = *(
const int16_t *)p; p += 2;
break;
350 case SLE_VAR_U16: v = *(
const uint16_t *)p; p += 2;
break;
351 case SLE_VAR_I32: v = *(
const int32_t *)p; p += 4;
break;
352 case SLE_VAR_U32: v = *(
const uint32_t *)p; p += 4;
break;
353 default: NOT_REACHED();
355 if (i != 0) result +=
',';
356 result += std::to_string(v);
361 std::string OneOfManySettingDesc::FormatSingleValue(uint
id)
const
363 if (
id >= this->
many.size()) {
364 return std::to_string(
id);
366 return this->
many[id];
371 uint
id = (uint)this->
Read(
object);
372 return this->FormatSingleValue(
id);
377 uint bitmask = (uint)this->
Read(
object);
384 if (!result.empty()) result +=
'|';
385 result += this->FormatSingleValue(
id);
398 size_t val = std::strtoul(
str, &end, 0);
407 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS);
420 if (r != (
size_t)-1)
return r;
432 if (r != (
size_t)-1)
return r;
443 if (r.has_value())
return *r;
459 return this->get_title_cb !=
nullptr ? this->get_title_cb(*
this) : this->
str;
468 return this->get_help_cb !=
nullptr ? this->get_help_cb(*
this) : this->
str_help;
478 if (this->set_value_dparams_cb !=
nullptr) {
479 this->set_value_dparams_cb(*
this, first_param, value);
481 SetDParam(first_param++, value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
501 this->
Write(
object, val);
533 }
else if (val < this->
min || val > (int32_t)this->
max) {
542 uint32_t uval = (uint32_t)val;
547 }
else if (uval < (uint)this->
min || uval > this->
max) {
549 uval = (uint32_t)this->
def;
557 default: NOT_REACHED();
592 if (this->
max_length == 0 || str.size() < this->max_length)
return;
597 std::string stdstr(str, this->
max_length - 1);
630 static void IniLoadSettings(
IniFile &ini,
const SettingTable &settings_table,
const char *grpname,
void *
object,
bool only_startup)
635 for (
auto &desc : settings_table) {
638 if (sd->
startup != only_startup)
continue;
641 std::string s{ sd->
GetName() };
642 auto sc = s.find(
'.');
643 if (sc != std::string::npos) {
644 group = ini.
GetGroup(s.substr(0, sc));
645 if (group ==
nullptr) group = group_def;
646 s = s.substr(sc + 1);
652 if (group !=
nullptr) item = group->
GetItem(s);
653 if (item ==
nullptr && group != group_def && group_def !=
nullptr) {
658 if (item ==
nullptr) {
662 if (sc != std::string::npos) {
663 if (group = ini.
GetGroup(s.substr(0, sc)); group !=
nullptr) item = group->
GetItem(s.substr(sc + 1));
673 size_t val = (item ==
nullptr) ? this->
def : this->
ParseValue(item->
value.has_value() ? item->
value->c_str() :
"");
679 std::string str = (item ==
nullptr) ? this->
def : item->
value.value_or(
"");
681 this->
Write(
object, str);
686 const char *str = (item ==
nullptr) ? this->
def : item->
value.has_value() ? item->
value->c_str() :
nullptr;
712 IniGroup *group_def =
nullptr, *group;
714 for (
auto &desc : settings_table) {
722 std::string s{ sd->
GetName() };
723 auto sc = s.find(
'.');
724 if (sc != std::string::npos) {
726 s = s.substr(sc + 1);
732 IniItem &item = group->GetOrCreateItem(s);
744 if (IsSignedVarMemType(this->
save.
conv)) {
745 i = this->
Read(
object);
747 i = (uint32_t)this->
Read(
object);
749 return std::to_string(i);
754 bool val = this->
Read(
object) != 0;
755 return val ?
"true" :
"false";
761 int32_t object_value = this->
Read(
object);
762 return item_value == object_value;
767 int32_t object_value = this->
Read(
object);
768 return this->
def == object_value;
773 const std::string &str = this->
Read(
object);
781 return fmt::format(
"\"{}\"", str);
783 default: NOT_REACHED();
793 const std::string &str = this->
Read(
object);
794 return item->
value->compare(str) == 0;
799 const std::string &str = this->
Read(
object);
800 return this->
def == str;
828 if (group ==
nullptr)
return;
833 if (!item.
name.empty()) list.push_back(item.
name);
851 for (
const auto &iter : list) {
886 if (do_command && (this->
flags & SF_NO_NETWORK_SYNC))
return false;
890 (_game_mode == GM_NORMAL ||
940 static void AILoadConfig(
const IniFile &ini,
const char *grpname)
950 if (group ==
nullptr)
return;
958 if (item.
name !=
"none") {
959 Debug(script, 0,
"The AI by the name '{}' was no longer found, and removed from the list.", item.
name);
969 static void GameLoadConfig(
const IniFile &ini,
const char *grpname)
977 if (group ==
nullptr || group->
items.empty())
return;
985 if (item.
name !=
"none") {
986 Debug(script, 0,
"The GameScript by the name '{}' was no longer found, and removed from the list.", item.
name);
1000 if (
const IniItem *item = group->
GetItem(
"graphicsset"); item !=
nullptr && item->
value) BaseGraphics::ini_data.name = *item->
value;
1003 if (
const IniGroup *group = ini.
GetGroup(
"graphicsset"); group !=
nullptr) {
1005 if (
const IniItem *item = group->
GetItem(
"name"); item !=
nullptr && item->
value) BaseGraphics::ini_data.name = *item->
value;
1007 if (
const IniItem *item = group->
GetItem(
"shortname"); item !=
nullptr && item->
value && item->
value->size() == 8) {
1013 if (
const IniItem *item = group->
GetItem(
"extra_params"); item !=
nullptr && item->
value) {
1014 auto &extra_params = BaseGraphics::ini_data.
extra_params;
1016 int count =
ParseIntList(item->
value->c_str(), &extra_params.front(), extra_params.size());
1022 extra_params.resize(count);
1039 if (group ==
nullptr)
return nullptr;
1045 std::array<uint8_t, 4> grfid_buf;
1047 std::string_view item_name = item.
name;
1048 bool has_md5sum =
false;
1051 auto grfid_pos = item_name.find(
"|");
1052 if (grfid_pos != std::string_view::npos) {
1053 std::string_view grfid_str = item_name.substr(0, grfid_pos);
1056 item_name = item_name.substr(grfid_pos + 1);
1058 auto md5sum_pos = item_name.find(
"|");
1059 if (md5sum_pos != std::string_view::npos) {
1060 std::string_view md5sum_str = item_name.substr(0, md5sum_pos);
1063 if (has_md5sum) item_name = item_name.substr(md5sum_pos + 1);
1066 uint32_t grfid = grfid_buf[0] | (grfid_buf[1] << 8) | (grfid_buf[2] << 16) | (grfid_buf[3] << 24);
1069 if (s !=
nullptr) c =
new GRFConfig(*s);
1073 if (s !=
nullptr) c =
new GRFConfig(*s);
1077 std::string filename = std::string(item_name);
1079 if (c ==
nullptr) c =
new GRFConfig(filename);
1082 if (item.
value.has_value() && !item.
value->empty()) {
1095 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
1097 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNSAFE);
1099 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_SYSTEM);
1101 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
1103 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
1113 bool duplicate =
false;
1114 for (
const GRFConfig *gc = first; gc !=
nullptr; gc = gc->
next) {
1148 if (group ==
nullptr)
return IFV_0;
1150 auto version_number = group->
GetItem(
"ini_version");
1152 if (version_number ==
nullptr || !version_number->value.has_value())
return IFV_0;
1154 uint32_t version = 0;
1155 std::from_chars(version_number->value->data(), version_number->value->data() + version_number->value->size(), version);
1160 static void AISaveConfig(
IniFile &ini,
const char *grpname)
1180 static void GameSaveConfig(
IniFile &ini,
const char *grpname)
1216 if (used_set ==
nullptr)
return;
1224 const GRFConfig *extra_cfg = used_set->GetExtraConfig();
1225 if (extra_cfg !=
nullptr && extra_cfg->
num_params > 0) {
1232 static void GRFSaveConfig(
IniFile &ini,
const char *grpname,
const GRFConfig *list)
1238 for (c = list; c !=
nullptr; c = c->
next) {
1246 static void HandleSettingDescs(
IniFile &generic_ini,
IniFile &private_ini,
IniFile &secrets_ini, SettingDescProc *proc, SettingDescProcList *proc_list,
bool only_startup =
false)
1248 proc(generic_ini, _misc_settings,
"misc",
nullptr, only_startup);
1249 #if defined(_WIN32) && !defined(DEDICATED)
1250 proc(generic_ini, _win32_settings,
"win32",
nullptr, only_startup);
1265 proc(generic_ini, _currency_settings,
"currency", &_custom_currency, only_startup);
1268 if (!only_startup) {
1286 for (
auto &desc : table) {
1290 std::string s{ sd->
GetName() };
1291 auto sc = s.find(
'.');
1292 if (sc == std::string::npos)
continue;
1295 if (group ==
nullptr)
continue;
1296 s = s.substr(sc + 1);
1327 *old_item =
nullptr;
1331 if (igroup ==
nullptr)
return false;
1337 if (tmp_old_item ==
nullptr)
return false;
1343 if (new_item !=
nullptr)
return false;
1345 *old_item = tmp_old_item;
1361 IniFileVersion generic_version = LoadVersionFromConfig(generic_ini);
1384 if (network !=
nullptr) {
1385 const IniItem *no_http_content_downloads = network->
GetItem(
"no_http_content_downloads");
1386 if (no_http_content_downloads !=
nullptr) {
1387 if (no_http_content_downloads->
value ==
"true") {
1389 }
else if (no_http_content_downloads->
value ==
"false") {
1394 const IniItem *use_relay_service = network->
GetItem(
"use_relay_service");
1395 if (use_relay_service !=
nullptr) {
1396 if (use_relay_service->
value ==
"never") {
1398 }
else if (use_relay_service->
value ==
"ask") {
1400 }
else if (use_relay_service->
value ==
"allow") {
1415 static std::vector<std::string> _old_autosave_interval{
"off",
"monthly",
"quarterly",
"half year",
"yearly"};
1418 switch (old_value) {
1436 AILoadConfig(generic_ini,
"ai_players");
1437 GameLoadConfig(generic_ini,
"game_scripts");
1459 IniFileVersion generic_version = LoadVersionFromConfig(generic_ini);
1465 if (
IniGroup *group = private_ini.
GetGroup(
"private"); group !=
nullptr) group->
comment =
"; This file possibly contains private information which can identify you as person.\n";
1466 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";
1468 if (generic_version ==
IFV_0) {
1490 if (game_creation !=
nullptr) {
1491 game_creation->
RemoveItem(
"generation_seed");
1498 if (network !=
nullptr) {
1499 network->
RemoveItem(
"no_http_content_downloads");
1508 AISaveConfig(generic_ini,
"ai_players");
1509 GameSaveConfig(generic_ini,
"game_scripts");
1530 if (group.
name.compare(0, 7,
"preset-") == 0) {
1531 list.push_back(group.
name.substr(7));
1546 std::string section(
"preset-");
1547 section += config_name;
1563 std::string section(
"preset-");
1564 section += config_name;
1567 GRFSaveConfig(ini, section.c_str(), config);
1577 std::string section(
"preset-");
1578 section += config_name;
1593 int32_t oldval = this->
Read(
object);
1596 if (oldval == newval)
return;
1598 this->
Write(
object, newval);
1625 if (sd->
GetName() == name)
return sd;
1629 std::string short_name_suffix = std::string{
"." }.append(name);
1633 if (sd->
GetName().ends_with(short_name_suffix))
return sd;
1649 saveloads.push_back(sd->
save);
1661 static const std::string_view company_prefix =
"company.";
1662 if (name.starts_with(company_prefix)) name.remove_prefix(company_prefix.size());
1676 if (sd !=
nullptr)
return sd;
1680 if (sd !=
nullptr)
return sd;
1684 if (sd !=
nullptr)
return sd;
1764 if (_game_mode != GM_MENU) {
1771 if (force_newgame) {
1789 for (
auto &desc : _company_settings) {
1802 for (
auto &desc : _company_settings) {
1841 this->
Write(
object, newval);
1849 void IConsoleSetSetting(
const char *name,
const char *value,
bool force_newgame)
1852 if (sd ==
nullptr) {
1857 bool success =
true;
1880 void IConsoleSetSetting(
const char *name,
int value)
1883 assert(sd !=
nullptr);
1895 if (sd ==
nullptr) {
1912 static void IConsoleListSettingsTable(
const SettingTable &table,
const char *prefilter)
1914 for (
auto &desc : table) {
1917 if (prefilter !=
nullptr && sd->
GetName().find(prefilter) == std::string::npos)
continue;
1932 IConsoleListSettingsTable(table, prefilter);
1935 IConsoleListSettingsTable(table, prefilter);
1938 IConsoleListSettingsTable(table, prefilter);
@ IFV_NETWORK_PRIVATE_SETTINGS
4 PR#10762 Move no_http_content_downloads / use_relay_service to private settings.
void ShowFirstError()
Show the first error of the queue.
SaveLoadVersion version_to
Save/load the variable before this savegame version.
IniFileVersion
Ini-file versions.
static const TextColour CC_INFO
Colour for information lines.
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.
std::string FormatArrayAsHex(std::span< const byte > data)
Format a byte array into a continuous hex string.
All settings that are only important for the local client.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
static Titem * Get(size_t index)
Returns Titem with given index.
void MakeValueValid(std::string &str) const
Make the value valid given the limitations of this setting.
static void RemoveEntriesFromIni(IniFile &ini, const SettingTable &table)
Remove all entries from a settings table from an ini-file.
@ SLE_VAR_STR
string pointer
@ SF_SCENEDIT_TOO
This setting can be changed in the scenario editor (only makes sense when SF_NEWGAME_ONLY is set).
void SetValue(const std::string_view value)
Replace the current value with another value.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
PreChangeCheck * pre_check
Callback to check for the validity of the setting.
void SetDParamStr(uint n, const char *str)
Set a rawstring parameter.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
static const SettingDesc * GetSettingFromName(const std::string_view name, const SettingTable &settings)
Given a name of setting, return a setting description from the table.
static void GraphicsSetLoadConfig(IniFile &ini)
Load BaseGraphics set selection and configuration.
void ScheduleErrorMessage(ErrorList &datas)
Schedule a list of errors.
static void ValidateSettings()
Checks if any settings are set to incorrect values, and sets them to correct values in that case.
void SetDefaultCompanySettings(CompanyID cid)
Set the company settings for a new company to their default values.
CommandCost CmdChangeSetting(DoCommandFlag flags, const std::string &name, int32_t value)
Network-safe changing of settings (server-only).
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.
uint32_t shortname
Four letter short variant of the name.
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
Minimum percentage a user can specify for custom sea level.
void IniLoadWindowSettings(IniFile &ini, const char *grpname, void *desc)
Load a WindowDesc from config.
uint32_t shortname
unique key for base set
Gamelog _gamelog
Gamelog instance.
static GRFConfig * GRFLoadConfig(const IniFile &ini, const char *grpname, bool is_static)
Load a GRF configuration.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
bool _network_server
network-server is active
std::string name
The name of the base set.
A single "line" in an ini file.
SaveLoad save
Internal structure (going to savegame, parts to config).
SettingType GetType() const
Return the type of the setting.
void SaveToConfig()
Save the values to the configuration file.
void PrepareOldDiffCustom()
Prepare for reading and old diff_custom by zero-ing the memory.
VehicleDefaultSettings _old_vds
Used for loading default vehicles settings from old savegames.
const IniItem * GetItem(const std::string &name) const
Get the item with the given name.
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
A group within an ini file.
@ SF_SCENEDIT_ONLY
This setting can only be changed in the scenario editor.
@ ST_CLIENT
Client setting.
@ LG_ORIGINAL
The original landscape generator.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
void HandleOldDiffCustom(bool savegame)
Reading of the old diff_custom array and transforming it to the new format.
DifficultySettings difficulty
settings related to the difficulty
std::list< ErrorMessageData > ErrorList
Define a queue with errors.
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.
std::string filename
Filename - either with or without full path.
void RemoveItem(const std::string &name)
Remove the item with the given name.
@ SLE_VAR_NULL
useful to write zeros in savegame.
static size_t LookupManyOfMany(const std::vector< std::string > &many, const char *str)
Find the set-integer value MANYofMANY type in a string.
@ ST_COMPANY
Company setting.
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
ClientSettings _settings_client
The current settings for this game.
StringList _network_bind_list
The addresses to bind on.
IniGroup & GetOrCreateGroup(const std::string &name)
Get the group with the given name, and if it doesn't exist create a new group.
const std::string & Read(const void *object) const
Read the string from the the actual setting.
GRFStatus status
NOSAVE: GRFStatus, enum.
std::list< IniItem > items
all items in the group
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
PostChangeCallback * post_callback
Callback when the setting has been changed.
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.
SettingFlag flags
Handles how a setting would show up in the GUI (text/currency, etc.).
@ IFV_GAME_TYPE
2 PR#9515 Convert server_advertise to server_game_type.
VarType conv
Type of the variable to be saved; this field combines both FileVarType and MemVarType.
UseRelayService use_relay_service
Use relay service?
std::string _private_file
Private configuration file of OpenTTD.
Owner
Enum for all companies/owners.
@ DC_EXEC
execute the given command
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.
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
PreChangeCheck * pre_check
Callback to check for the validity of the setting.
DoCommandFlag
List of flags for a command.
const struct StringSettingDesc * AsStringSetting() const
Get the setting description of this setting as a string setting.
static const TextColour CC_DEFAULT
Default colour of the console.
size_t ParseValue(const char *str) const override
Convert a string representation (external) of an integer-like setting to an integer.
IniFile to store a configuration.
void Clear()
Clear all items in the group.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
GameCreationSettings game_creation
settings used during the creation of a game (map)
@ GCF_INVALID
GRF is unusable with this version of OpenTTD.
uint16_t recalc_interval
time (in days) between subsequent checks for link graphs to be calculated.
bool no_http_content_downloads
do not do content downloads over HTTP
int64_t ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
static void IniSaveSettings(IniFile &ini, const SettingTable &settings_table, const char *grpname, void *object, bool)
Save the values of settings to the inifile.
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.
void ParseValue(const IniItem *item, void *object) const override
Parse/read the value from the Ini item into the setting associated with this object.
@ COMPANY_FIRST
First company, same as owner.
SettingType
Type of settings for filtering.
static const uint NETWORK_MAX_GRF_COUNT
Maximum number of GRFs that can be sent.
void RemoveGroup(const std::string &name)
Remove the group with the given name.
void ChangeValue(const void *object, std::string &newval) const
Handle changing a string value.
StringList GetGRFPresetList()
Get the list of known NewGrf presets.
uint32_t version
NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
constexpr VarType GetVarMemType(VarType type)
Get the NumberType of a setting.
@ SF_GUI_0_IS_SPECIAL
A value of zero is possible and has a custom string (the one after "strval").
@ GLAT_SETTING
Setting changed.
@ IFV_0
0 All versions prior to introduction.
void Setting(const std::string &name, int32_t oldval, int32_t newval)
Logs change in game settings.
StringID str_val
(Translated) first string describing the value.
void MakeValueValidAndWrite(const void *object, int32_t value) const
Make the value valid and then write it to the setting.
Common return value for all commands.
static uint32_t BSWAP32(uint32_t x)
Perform a 32 bits endianness bitswap on x.
Iterable ensemble of each set bit in a value.
@ GCF_UNSAFE
GRF file is unsafe for static usage.
Information about GRF, used in the game and (part of it) in savegames.
static const TextColour CC_HELP
Colour for help lines.
void MakeValueValid(int32_t &value) const
Make the value valid given the limitations of this setting.
std::vector< uint32_t > extra_params
parameters for the extra GRF
bool startup
Setting has to be loaded directly at startup?.
@ GCF_SYSTEM
GRF file is an openttd-internal system grf.
Base integer type, including boolean, settings.
IniItem & GetOrCreateItem(const std::string &name)
Get the item with the given name, and if it doesn't exist create a new item.
constexpr const std::string & GetName() const
Get the name of this setting.
std::optional< std::string > value
The value of this item.
@ IFV_LINKGRAPH_SECONDS
3 PR#10610 Store linkgraph update intervals in seconds instead of days.
MD5Hash md5sum
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
@ SF_NETWORK_ONLY
This setting only applies to network games.
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,...
bool SaveToDisk(const std::string &filename)
Save the Ini file's data to the disk.
virtual std::string FormatValue(const void *object) const =0
Format the value of the setting associated with this object.
int32_t def
default value given when none is present
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
static auto & SecretSettingTables()
List of all the secrets setting tables.
CommandCost CmdChangeCompanySetting(DoCommandFlag flags, const std::string &name, int32_t value)
Change one of the per-company settings.
void ParseValue(const IniItem *item, void *object) const override
Parse/read the value from the Ini item into the setting associated with this object.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
CompanySettings settings
settings specific for each company
void * GetVariableAddress(const void *object, const SaveLoad &sld)
Get the address of the variable.
int32_t min
minimum values
@ MAX_COMPANIES
Maximum number of companies.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
std::vector< std::string > StringList
Type for a list of strings.
void SyncCompanySettings()
Sync all company settings in a multiplayer game.
void Write(const void *object, int32_t value) const
Set the value of a setting.
@ SF_NO_NETWORK_SYNC
Do not synchronize over network (but it is saved if SF_NOT_IN_SAVE is not set).
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.
void StringToSettings(const std::string &value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
byte quantity_sea_lakes
the amount of seas/lakes
fluid_settings_t * settings
FluidSynth settings handle.
All settings together for the game.
bool _networking
are we in networking mode?
OnConvert * many_cnvt
callback procedure when loading value mechanism fails
static constexpr const SettingDesc * GetSettingDesc(const SettingVariant &desc)
Helper to convert the type of the iterated settings description to a pointer to it.
void DeleteGRFPresetFromConfig(const char *config_name)
Delete a NewGRF configuration by preset name.
const IniGroup * GetGroup(const std::string &name) const
Get the group with the given name.
The data of the error message.
Default settings for vehicles.
void ChangeValue(const void *object, int32_t newvalue) const
Handle changing a value.
LinkGraphSettings linkgraph
settings for link graph calculations
@ IFV_AUTOSAVE_RENAME
5 PR#11143 Renamed values of autosave to be in minutes.
void ResetCurrencies(bool preserve_custom)
Will fill _currency_specs array with default values from origin_currency_specs Called only from newgr...
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
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,...
StringID GetHelp() const
Get the help text of the setting.
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
GRFConfig * _grfconfig_static
First item in list of static GRF set up.
static int ParseIntList(const char *p, T *items, size_t maxitems)
Parse an integerlist string and set each found value.
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
void Change(std::optional< const std::string > name, int version=-1, bool force_exact_match=false, bool is_random=false)
Set another Script to be loaded in this slot.
GRFConfig * LoadGRFPresetFromConfig(const char *config_name)
Load a NewGRF configuration by preset-name.
size_t ParseValue(const char *str) const override
Convert a string representation (external) of an integer-like setting to an integer.
virtual bool IsStringSetting() const
Check whether this setting is an string type setting.
std::vector< std::string > many
possible values for this type
bool SlIsObjectCurrentlyValid(SaveLoadVersion version_from, SaveLoadVersion version_to)
Checks if some version from/to combination falls within the range of the active savegame version.
std::string _secrets_file
Secrets configuration file of OpenTTD.
static auto & GenericSettingTables()
List of all the generic setting tables.
size_t ParseValue(const char *str) const override
Convert a string representation (external) of an integer-like setting to an integer.
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.
static std::optional< bool > ParseSingleValue(const char *str)
Find whether a string was a boolean true or a boolean false.
StringID str_help
(Translated) string with help text; gui only.
ServerGameType server_game_type
Server type: local / public / invite-only.
CompanyID _current_company
Company currently doing an action.
@ WC_GAME_OPTIONS
Game options window; Window numbers:
uint8_t flags
NOSAVE: GCF_Flags, bitset.
StringID GetTitle() const
Get the title of the setting.
void IConsoleListSettings(const char *prefilter)
List all settings and their value to the console.
std::string comment
comment for group
bool FioCheckFileExists(const std::string &filename, Subdirectory subdir)
Check whether the given file exists.
std::string name
name of group
Ini file that supports both loading and saving.
std::array< uint32_t, 0x80 > param
GRF parameters.
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.
@ SF_NO_NETWORK
This setting does not apply to network games; it may not be changed during the game.
Properties of config file settings.
uint32_t extra_version
version of the extra GRF
static auto & PrivateSettingTables()
List of all the private setting tables.
byte land_generator
the landscape generator
std::string GRFBuildParamList(const GRFConfig *c)
Build a string containing space separated parameter values, and terminate.
@ NO_DIRECTORY
A path without any base directory.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
uint32_t autosave_interval
how often should we do autosaves?
static void GraphicsSetSaveConfig(IniFile &ini)
Save BaseGraphics set selection and configuration.
uint32_t max
maximum values
@ SF_NEWGAME_ONLY
This setting cannot be changed in a game.
std::string SettingsToString() const
Convert the custom settings to a string that can be stored in the config file or savegames.
StringID str
(translated) string with descriptive text; gui and console
struct GRFConfig * next
NOSAVE: Next item in the linked list.
IniItem & CreateItem(const std::string &name)
Create an item with the given name.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
int32_t Read(const void *object) const
Read the integer from the the actual setting.
void IniSaveWindowSettings(IniFile &ini, const char *grpname, void *desc)
Save a WindowDesc to config.
const char * def
default value given when none is present
@ SSS_FORCE_NEWGAME
Get the newgame Script config.
@ FGCM_NEWEST_VALID
Find newest Grf, ignoring Grfs with GCF_INVALID set.
virtual bool IsBoolSetting() const
Check whether this setting is a boolean type setting.
@ IFV_REMOVE_GENERATION_SEED
7 PR#11927 Remove "generation_seed" from configuration.
IniFile(const IniGroupNameList &list_group_names={})
Create a new ini file with given group names.
uint32_t max_length
Maximum length of the string, 0 means no maximum length.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
SaveLoadVersion version_from
Save/load the variable starting from this savegame version.
void SetValueDParams(uint first_param, int32_t value) const
Set the DParams for drawing the value of the setting.
static const TextColour CC_ERROR
Colour for error lines.
@ SLE_VAR_STRQ
string pointer enclosed in quotes
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
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.
@ SVS_NONE
Allow nothing and replace nothing.
virtual size_t ParseValue(const char *str) const
Convert a string representation (external) of an integer-like setting to an integer.
void Write(const void *object, const std::string &str) const
Write a string to the actual setting.
void IConsoleGetSetting(const char *name, bool force_newgame)
Output value of a specific setting to the console.
std::list< IniGroup > groups
all groups in the ini
std::string name
The name of this item.
#define lengthof(x)
Return the length of an fixed size array.
std::string def
Default value given when none is present.
StringList _network_ban_list
The banned clients.
NetworkSettings network
settings related to the network
uint32_t grfid
GRF ID (defined by Action 0x08)
static void SaveVersionInConfig(IniFile &ini)
Save the version of OpenTTD to the ini file.
@ SF_NOT_IN_SAVE
Do not save with savegame, basically client-based.
uint8_t num_params
Number of used parameters.
std::string FormatValue(const void *object) const override
Convert an integer-array (intlist) to a string representation.
PostChangeCallback * post_callback
Callback when the setting has been changed.
static const SettingDesc * GetCompanySettingFromName(std::string_view name)
Given a name of setting, return a company setting description of it.
static constexpr int SECONDS_PER_DAY
approximate seconds per day, not for precise calculations
uint16_t recalc_time
time (in days) for recalculating each link graph component.
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
CompanySettings company
default values for per-company settings
static bool IsValidID(size_t 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).
@ FGCM_EXACT
Only find Grfs matching md5sum.
@ SF_GUI_DROPDOWN
The value represents a limited number of string-options (internally integer) presented as dropdown.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
virtual bool IsIntSetting() const
Check whether this setting is an integer type setting.
StringList _network_host_list
The servers we know.
@ IFV_RIGHT_CLICK_CLOSE
6 PR#10204 Add alternative right click to close windows setting.
std::string _config_file
Configuration file of OpenTTD.
@ WC_ERRMSG
Error message; Window numbers:
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
Value for custom sea level in difficulty settings.
@ SF_PER_COMPANY
This setting can be different for each company (saved in company struct).
void LoadFromDisk(const std::string &filename, Subdirectory subdir)
Load the Ini file's data from the disk.
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
@ IFV_PRIVATE_SECRETS
1 PR#9298 Moving of settings from openttd.cfg to private.cfg / secrets.cfg.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
const GRFConfig * FindGRFConfig(uint32_t grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
Find a NewGRF in the scanned list.
bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir)
Find the GRFID of a given grf, and calculate its md5sum.
static ErrorList _settings_error_list
Errors while loading minimal settings.
void LoadFromConfig(bool startup)
Load the values from the configuration files.
All data of a graphics set.
void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
Save a NewGRF configuration with a preset name.
void DebugReconsiderSendRemoteMessages()
Reconsider whether we need to send debug messages to either NetworkAdminConsole or IConsolePrint.
void GetSaveLoadFromSettingTable(SettingTable settings, std::vector< SaveLoad > &saveloads)
Get the SaveLoad for all settings in the settings table.
const uint16_t INIFILE_VERSION
Current ini-file version of OpenTTD.
RightClickClose right_click_wnd_close
close window with right click
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
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 bool LoadIntList(const char *str, void *array, int nelems, VarType type)
Load parsed string-values into an integer-array (intlist)
void WriteValue(void *ptr, VarType conv, int64_t val)
Write the value of a setting.
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
@ GCF_STATIC
GRF file is used statically (can be used in any MP game)
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 |.
GUISettings gui
settings related to the GUI
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
GRFConfig * _grfconfig_newgame
First item in list of default GRF set up.
@ IFV_MAX_VERSION
Highest possible ini-file version.
const struct IntSettingDesc * AsIntSetting() const
Get the setting description of this setting as an integer setting.
const std::string & GetName() const
Get the name of the Script.
@ SF_NOT_IN_CONFIG
Do not save to config file.
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.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.