Go to the documentation of this file.
49 #include "table/strings.h"
61 typedef std::list<ErrorMessageData>
ErrorList;
85 _news_display_settings,
86 _pathfinding_settings,
90 return _generic_setting_tables;
99 _network_private_settings,
101 return _private_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 char *
const list_group_names[] = {
139 "server_bind_addresses",
177 if (isdigit(*
str))
return strtoul(
str,
nullptr, 0);
180 for (
auto one :
many) {
181 if (one.size() == len && strncmp(one.c_str(),
str, len) == 0)
return idx;
203 while (*str ==
' ' || *str ==
'\t' || *str ==
'|') str++;
204 if (*str == 0)
break;
207 while (*s != 0 && *s !=
' ' && *s !=
'\t' && *s !=
'|') s++;
210 if (r == (
size_t)-1)
return r;
237 if (!comma)
return -1;
246 if (n == maxitems)
return -1;
248 unsigned long v = strtoul(p, &end, 0);
249 if (p == end)
return -1;
250 if (
sizeof(T) <
sizeof(v)) v = Clamp<unsigned long>(v, std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
261 if (n != 0 && !comma)
return -1;
274 static bool LoadIntList(
const char *str,
void *array,
int nelems, VarType type)
276 unsigned long items[64];
279 if (str ==
nullptr) {
280 memset(items, 0,
sizeof(items));
284 if (nitems != nelems)
return false;
291 for (i = 0; i != nitems; i++) ((
byte*)array)[i] = items[i];
296 for (i = 0; i != nitems; i++) ((uint16*)array)[i] = items[i];
301 for (i = 0; i != nitems; i++) ((uint32*)array)[i] = items[i];
304 default: NOT_REACHED();
327 case SLE_VAR_I8: v = *(
const int8 *)p; p += 1;
break;
328 case SLE_VAR_U8: v = *(
const uint8 *)p; p += 1;
break;
329 case SLE_VAR_I16: v = *(
const int16 *)p; p += 2;
break;
330 case SLE_VAR_U16: v = *(
const uint16 *)p; p += 2;
break;
331 case SLE_VAR_I32: v = *(
const int32 *)p; p += 4;
break;
332 case SLE_VAR_U32: v = *(
const uint32 *)p; p += 4;
break;
333 default: NOT_REACHED();
335 if (IsSignedVarMemType(this->
save.
conv)) {
336 buf +=
seprintf(buf, last, (i == 0) ?
"%d" :
",%d", v);
338 buf +=
seprintf(buf, last, (i == 0) ?
"%u" :
",%u", v);
343 char *OneOfManySettingDesc::FormatSingleValue(
char *buf,
const char *last, uint
id)
const
345 if (
id >= this->
many.size()) {
346 return buf +
seprintf(buf, last,
"%d",
id);
353 uint
id = (uint)this->
Read(
object);
354 this->FormatSingleValue(buf, last,
id);
359 uint bitmask = (uint)this->
Read(
object);
366 if (!first) buf =
strecpy(buf,
"|", last);
367 buf = this->FormatSingleValue(buf, last,
id);
380 size_t val = strtoul(
str, &end, 0);
389 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS);
402 if (r != (
size_t)-1)
return r;
414 if (r != (
size_t)-1)
return r;
424 if (strcmp(
str,
"true") == 0 || strcmp(
str,
"on") == 0 || strcmp(
str,
"1") == 0)
return true;
425 if (strcmp(
str,
"false") == 0 || strcmp(
str,
"off") == 0 || strcmp(
str,
"0") == 0)
return false;
443 this->
Write(
object, val);
475 }
else if (val < this->
min || val > (int32)this->
max) {
484 uint32 uval = (uint32)val;
489 }
else if (uval < (uint)this->
min || uval > this->
max) {
491 uval = (uint32)this->
def;
499 default: NOT_REACHED();
534 if (this->
max_length == 0 || str.size() < this->max_length)
return;
539 std::string stdstr(str, this->
max_length - 1);
577 for (
auto &desc : settings_table) {
580 if (sd->
startup != only_startup)
continue;
583 std::string s{ sd->
GetName() };
584 auto sc = s.find(
'.');
585 if (sc != std::string::npos) {
586 group = ini.
GetGroup(s.substr(0, sc));
587 s = s.substr(sc + 1);
593 if (item ==
nullptr && group != group_def) {
596 item = group_def->
GetItem(s,
false);
598 if (item ==
nullptr) {
602 if (sc != std::string::npos) item = ini.
GetGroup(s.substr(0, sc))->
GetItem(s.substr(sc + 1),
false);
611 size_t val = (item ==
nullptr) ? this->
def : this->
ParseValue(item->
value.has_value() ? item->
value->c_str() :
"");
617 std::string str = (item ==
nullptr) ? this->
def : item->
value.value_or(
"");
619 this->
Write(
object, str);
624 const char *str = (item ==
nullptr) ? this->
def : item->
value.has_value() ? item->
value->c_str() :
nullptr;
650 IniGroup *group_def =
nullptr, *group;
654 for (
auto &desc : settings_table) {
662 std::string s{ sd->
GetName() };
663 auto sc = s.find(
'.');
664 if (sc != std::string::npos) {
665 group = ini.
GetGroup(s.substr(0, sc));
666 s = s.substr(sc + 1);
668 if (group_def ==
nullptr) group_def = ini.
GetGroup(grpname);
672 item = group->GetItem(s,
true);
679 item->
value.emplace(buf);
686 uint32 i = (uint32)this->
Read(
object);
692 bool val = this->
Read(
object) != 0;
693 strecpy(buf, val ?
"true" :
"false", last);
699 int32 object_value = this->
Read(
object);
700 return item_value == object_value;
705 const std::string &str = this->
Read(
object);
713 seprintf(buf, last,
"\"%s\"", str.c_str());
717 default: NOT_REACHED();
727 const std::string &str = this->
Read(
object);
728 return item->
value->compare(str) == 0;
750 if (group ==
nullptr)
return;
754 for (
const IniItem *item = group->
item; item !=
nullptr; item = item->
next) {
755 if (!item->name.empty()) list.push_back(item->name);
772 if (group ==
nullptr)
return;
775 for (
const auto &iter : list) {
813 (_game_mode == GM_NORMAL ||
863 static void AILoadConfig(
IniFile &ini,
const char *grpname)
874 if (group ==
nullptr)
return;
877 for (item = group->
item; c < MAX_COMPANIES && item != nullptr; c++, item = item->next) {
882 if (item->
name !=
"none") {
883 Debug(script, 0,
"The AI by the name '{}' was no longer found, and removed from the list.", item->
name);
891 static void GameLoadConfig(
IniFile &ini,
const char *grpname)
900 if (group ==
nullptr)
return;
903 if (item ==
nullptr)
return;
909 if (item->
name !=
"none") {
910 Debug(script, 0,
"The GameScript by the name '{}' was no longer found, and removed from the list.", item->
name);
924 if (c >=
'0' && c <=
'9')
return c -
'0';
925 if (c >=
'A' && c <=
'F')
return c + 10 -
'A';
926 if (c >=
'a' && c <=
'f')
return c + 10 -
'a';
940 while (dest_size > 0) {
943 if (lo < 0)
return false;
944 *dest++ = (hi << 4) | lo;
964 if (group ==
nullptr)
return nullptr;
967 for (item = group->
item; item !=
nullptr; item = item->
next) {
970 uint8 grfid_buf[4], md5sum[16];
971 const char *filename = item->
name.c_str();
972 bool has_grfid =
false;
973 bool has_md5sum =
false;
978 filename += 1 + 2 *
lengthof(grfid_buf);
980 if (has_md5sum) filename += 1 + 2 *
lengthof(md5sum);
982 uint32 grfid = grfid_buf[0] | (grfid_buf[1] << 8) | (grfid_buf[2] << 16) | (grfid_buf[3] << 24);
992 if (c ==
nullptr) c =
new GRFConfig(filename);
995 if (item->
value.has_value() && !item->
value->empty()) {
1008 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
1010 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNSAFE);
1012 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_SYSTEM);
1014 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
1016 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
1026 bool duplicate =
false;
1027 for (
const GRFConfig *gc = first; gc !=
nullptr; gc = gc->
next) {
1062 auto version_number = group->
GetItem(
"ini_version",
false);
1064 if (version_number ==
nullptr || !version_number->value.has_value())
return IFV_0;
1067 std::from_chars(version_number->value->data(), version_number->value->data() + version_number->value->size(), version);
1072 static void AISaveConfig(
IniFile &ini,
const char *grpname)
1076 if (group ==
nullptr)
return;
1095 static void GameSaveConfig(
IniFile &ini,
const char *grpname)
1099 if (group ==
nullptr)
return;
1124 group->
GetItem(
"version_number",
true)->
SetValue(fmt::format(
"{:08X}", _openttd_newgrf_version));
1129 static void GRFSaveConfig(
IniFile &ini,
const char *grpname,
const GRFConfig *list)
1135 for (c = list; c !=
nullptr; c = c->
next) {
1137 char key[4 * 2 + 1 + 16 * 2 + 1 + MAX_PATH];
1149 static void HandleSettingDescs(
IniFile &generic_ini,
IniFile &private_ini,
IniFile &secrets_ini, SettingDescProc *proc, SettingDescProcList *proc_list,
bool only_startup =
false)
1151 proc(generic_ini, _misc_settings,
"misc",
nullptr, only_startup);
1152 #if defined(_WIN32) && !defined(DEDICATED)
1153 proc(generic_ini, _win32_settings,
"win32",
nullptr, only_startup);
1168 proc(generic_ini, _currency_settings,
"currency", &_custom_currency, only_startup);
1171 if (!only_startup) {
1189 for (
auto &desc : table) {
1193 std::string s{ sd->
GetName() };
1194 auto sc = s.find(
'.');
1195 if (sc == std::string::npos)
continue;
1198 s = s.substr(sc + 1);
1216 IniFileVersion generic_version = LoadVersionFromConfig(generic_ini);
1231 if (network !=
nullptr) {
1232 IniItem *server_advertise = network->
GetItem(
"server_advertise",
false);
1233 if (server_advertise !=
nullptr && server_advertise->
value ==
"true") {
1242 AILoadConfig(generic_ini,
"ai_players");
1243 GameLoadConfig(generic_ini,
"game_scripts");
1266 IniFileVersion generic_version = LoadVersionFromConfig(generic_ini);
1272 if (!private_ini.
GetGroup(
"private",
false)) private_ini.
GetGroup(
"private")->
comment =
"; This file possibly contains private information which can identify you as person.\n";
1273 if (!secrets_ini.
GetGroup(
"secrets",
false)) secrets_ini.
GetGroup(
"secrets")->
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";
1275 if (generic_version ==
IFV_0) {
1298 if (network !=
nullptr) {
1306 AISaveConfig(generic_ini,
"ai_players");
1307 GameSaveConfig(generic_ini,
"game_scripts");
1328 if (group->
name.compare(0, 7,
"preset-") == 0) {
1329 list.push_back(group->
name.substr(7));
1344 size_t len = strlen(config_name) + 8;
1345 char *section = (
char*)alloca(len);
1346 seprintf(section, section + len - 1,
"preset-%s", config_name);
1362 size_t len = strlen(config_name) + 8;
1363 char *section = (
char*)alloca(len);
1364 seprintf(section, section + len - 1,
"preset-%s", config_name);
1367 GRFSaveConfig(ini, section, config);
1377 size_t len = strlen(config_name) + 8;
1378 char *section = (
char*)alloca(len);
1379 seprintf(section, section + len - 1,
"preset-%s", config_name);
1394 int32 oldval = this->
Read(
object);
1397 if (oldval == newval)
return;
1399 this->
Write(
object, newval);
1426 if (sd->
GetName() == name)
return sd;
1430 std::string short_name_suffix = std::string{
"." }.append(name);
1450 saveloads.push_back(sd->
save);
1462 static const std::string_view company_prefix =
"company.";
1463 if (
StrStartsWith(name, company_prefix)) name.remove_prefix(company_prefix.size());
1477 if (sd !=
nullptr)
return sd;
1481 if (sd !=
nullptr)
return sd;
1485 if (sd !=
nullptr)
return sd;
1565 if (_game_mode != GM_MENU) {
1572 if (force_newgame) {
1590 for (
auto &desc : _company_settings) {
1603 for (
auto &desc : _company_settings) {
1642 this->
Write(
object, newval);
1650 void IConsoleSetSetting(
const char *name,
const char *value,
bool force_newgame)
1653 if (sd ==
nullptr) {
1658 bool success =
true;
1681 void IConsoleSetSetting(
const char *name,
int value)
1684 assert(sd !=
nullptr);
1696 if (sd ==
nullptr) {
1714 static void IConsoleListSettingsTable(
const SettingTable &table,
const char *prefilter)
1716 for (
auto &desc : table) {
1719 if (prefilter !=
nullptr && sd->
GetName().find(prefilter) == std::string::npos)
continue;
1736 IConsoleListSettingsTable(table, prefilter);
1739 IConsoleListSettingsTable(table, prefilter);
1742 IConsoleListSettingsTable(table, prefilter);
void GamelogSetting(const std::string &name, int32 oldval, int32 newval)
Logs change in game settings.
void RemoveGroup(const char *name)
Remove the group with the given name.
void ShowFirstError()
Show the first error of the queue.
void FormatValue(char *buf, const char *last, const void *object) const override
Format the value of the setting associated with this object.
std::list< ErrorMessageData > ErrorList
Define a queue with errors.
SaveLoadVersion version_to
Save/load the variable before this savegame version.
void FormatValue(char *buf, const char *last, const void *object) const override
Format the value of the setting associated with this object.
static const TextColour CC_INFO
Colour for information lines.
void MakeValueValid(int32 &value) const
Make the value valid given the limitations of this setting.
@ SF_PER_COMPANY
This setting can be different for each company (saved in company struct).
All settings that are only important for the local client.
@ SF_NOT_IN_SAVE
Do not save with savegame, basically client-based.
@ SF_GUI_0_IS_SPECIAL
A value of zero is possible and has a custom string (the one after "strval").
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.
@ IFV_GAME_TYPE
2 PR#9515 Convert server_advertise to server_game_type.
@ SLE_VAR_STR
string pointer
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version)
Find a NewGRF in the scanned list.
void SetValue(const std::string_view value)
Replace the current value with another value.
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.
IniItem * next
The next item in this group.
static GRFConfig * GRFLoadConfig(IniFile &ini, const char *grpname, bool is_static)
Load a GRF configuration.
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 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.
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.
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
Minimum percentage a user can specify for custom sea level.
@ SF_NOT_IN_CONFIG
Do not save to config file.
void IniLoadWindowSettings(IniFile &ini, const char *grpname, void *desc)
Load a WindowDesc from config.
uint8 num_params
Number of used parameters.
void FormatValue(char *buf, const char *last, const void *object) const override
Format the value of the setting associated with this object.
bool _network_server
network-server is active
void MakeValueValidAndWrite(const void *object, int32 value) const
Make the value valid and then write it to the setting.
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.
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
A group within an ini file.
@ 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.
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
void HandleOldDiffCustom(bool savegame)
Reading of the old diff_custom array and transforming it to the new format.
virtual void FormatValue(char *buf, const char *last, const void *object) const =0
Format the value of the setting associated with this object.
DifficultySettings difficulty
settings related to the difficulty
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
void RemoveItem(const std::string &name)
Remove the item with the given name.
@ SLE_VAR_NULL
useful to write zeros in savegame.
void ChangeValue(const void *object, int32 newvalue) const
Handle changing a value.
static size_t LookupManyOfMany(const std::vector< std::string > &many, const char *str)
Find the set-integer value MANYofMANY type in a string.
@ SF_NO_NETWORK_SYNC
Do not synchronize over network (but it is saved if SF_NOT_IN_SAVE is not set).
@ ST_COMPANY
Company setting.
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
uint16 length
(Conditional) length of the variable (eg. arrays) (max array size is 65536 elements).
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
ClientSettings _settings_client
The current settings for this game.
StringList _network_bind_list
The addresses to bind on.
const std::string & Read(const void *object) const
Read the string from the the actual setting.
GRFStatus status
NOSAVE: GRFStatus, enum.
PostChangeCallback * post_callback
Callback when the setting has been changed.
SettingFlag flags
Handles how a setting would show up in the GUI (text/currency, etc.).
VarType conv
Type of the variable to be saved; this field combines both FileVarType and MemVarType.
std::string _private_file
Private configuration file of OpenTTD.
@ IFV_PRIVATE_SECRETS
1 PR#9298 Moving of settings from openttd.cfg to private.cfg / secrets.cfg.
Owner
Enum for all companies/owners.
@ GLAT_SETTING
Setting changed.
@ 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.
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
PreChangeCheck * pre_check
Callback to check for the validity of the setting.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
uint32 max_length
Maximum length of the string, 0 means no maximum length.
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.
uint32 grfid
GRF ID (defined by Action 0x08)
void Clear()
Clear all items in the group.
@ IFV_MAX_VERSION
Highest possible ini-file version.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
GameCreationSettings game_creation
settings used during the creation of a game (map)
@ GCF_INVALID
GRF is unusable with this version of OpenTTD.
static GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
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.
char * GRFBuildParamList(char *dst, const GRFConfig *c, const char *last)
Build a string containing space separated parameter values, and terminate.
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.
CommandCost CmdChangeCompanySetting(DoCommandFlag flags, const std::string &name, int32 value)
Change one of the per-company settings.
static bool DecodeHexText(const char *pos, uint8 *dest, size_t dest_size)
Parse a sequence of characters (supposedly hex digits) into a sequence of bytes.
void ChangeValue(const void *object, std::string &newval) const
Handle changing a string value.
StringList GetGRFPresetList()
Get the list of known NewGrf presets.
Common return value for all commands.
Iterable ensemble of each set bit in a value.
IniFile(const char *const *list_group_names=nullptr)
Create a new ini file with given group names.
@ SF_NETWORK_ONLY
This setting only applies to network games.
@ GCF_UNSAFE
GRF file is unsafe for static usage.
Information about GRF, used in the game and (part of it) in savegames.
static int ParseIntList(const char *p, T *items, int maxitems)
Parse an integerlist string and set each found value.
static const TextColour CC_HELP
Colour for help lines.
A trimmed down version of what std::span will be in C++20.
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.
constexpr const std::string & GetName() const
Get the name of this setting.
std::optional< std::string > value
The value of this item.
uint8 flags
NOSAVE: GCF_Flags, bitset.
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,...
const char * GetName() const
Get the name of the Script.
@ SF_NEWGAME_ONLY
This setting cannot be changed in a game.
bool SaveToDisk(const std::string &filename)
Save the Ini file's data to the disk.
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.
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.
bool StrStartsWith(const std::string_view str, const std::string_view prefix)
Check whether the given string starts with the given prefix.
CompanySettings settings
settings specific for each company
void GamelogStartAction(GamelogActionType at)
Stores information about new action, but doesn't allocate it Action is allocated only when there is a...
@ 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.
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.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
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
@ IFV_0
0 All versions prior to introduction.
void FormatValue(char *buf, const char *last, const void *object) const override
Convert an integer-array (intlist) to a string representation.
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.
The data of the error message.
Default settings for vehicles.
void ResetCurrencies(bool preserve_custom)
Will fill _currency_specs array with default values from origin_currency_specs Called only from newgr...
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 uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
void Write(const void *object, int32 value) const
Set the value of a setting.
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
GRFConfig * _grfconfig_static
First item in list of static GRF set up.
void GamelogStopAction()
Stops logging of any changes.
bool StrEndsWith(const std::string_view str, const std::string_view suffix)
Check whether the given string ends with the given suffix.
static bool SlIsObjectCurrentlyValid(SaveLoadVersion version_from, SaveLoadVersion version_to)
Checks if some version from/to combination falls within the range of the active savegame version.
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.
void WriteValue(void *ptr, VarType conv, int64 val)
Write the value of a setting.
virtual bool IsStringSetting() const
Check whether this setting is an string type setting.
std::vector< std::string > many
possible values for this type
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.
ServerGameType server_game_type
Server type: local / public / invite-only.
IniGroup * group
the first group in the ini
CompanyID _current_company
Company currently doing an action.
@ WC_GAME_OPTIONS
Game options window; Window numbers:
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
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
std::string StrMakeValid(const std::string &str, StringValidationSettings settings)
Scans the string for invalid characters and replaces then with a question mark '?' (if not ignored).
Ini file that supports both loading and saving.
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.
Properties of config file settings.
static auto & PrivateSettingTables()
List of all the private setting tables.
byte land_generator
the landscape generator
bool SetSettingValue(const IntSettingDesc *sd, int32 value, bool force_newgame)
Top function to save the new value of an element of the Settings struct.
@ NO_DIRECTORY
A path without any base directory.
static VarType GetVarMemType(VarType type)
Get the NumberType of a setting.
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.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
void ScheduleErrorMessage(const ErrorMessageData &data)
Schedule an error.
void IniSaveWindowSettings(IniFile &ini, const char *grpname, void *desc)
Save a WindowDesc to config.
static int DecodeHexNibble(char c)
Convert a character to a hex nibble value, or -1 otherwise.
const char * def
default value given when none is present
@ SSS_FORCE_NEWGAME
Get the newgame Script config.
@ SF_SCENEDIT_ONLY
This setting can only be changed in the scenario editor.
@ FGCM_NEWEST_VALID
Find newest Grf, ignoring Grfs with GCF_INVALID set.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
@ SF_GUI_DROPDOWN
The value represents a limited number of string-options (internally integer) presented as dropdown.
SaveLoadVersion version_from
Save/load the variable starting from this savegame version.
int32 Read(const void *object) const
Read the integer from the the actual setting.
static const TextColour CC_ERROR
Colour for error lines.
@ SLE_VAR_STRQ
string pointer enclosed in quotes
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::string name
The name of this item.
@ SF_SCENEDIT_TOO
This setting can be changed in the scenario editor (only makes sense when SF_NEWGAME_ONLY is set).
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
#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
static void SaveVersionInConfig(IniFile &ini)
Save the version of OpenTTD to the ini file.
IniItem * item
the first item in the group
static void * GetVariableAddress(const void *object, const SaveLoad &sld)
Get the address of the variable.
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.
void Change(const char *name, int version=-1, bool force_exact_match=false, bool is_random=false)
Set another Script to be loaded in this slot.
int64 ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
CompanySettings company
default values for per-company settings
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
const uint16 INIFILE_VERSION
Current ini-file version of OpenTTD.
@ FGCM_EXACT
Only find Grfs matching md5sum.
IniItem * GetItem(const std::string &name, bool create)
Get the item with the given name, and if it doesn't exist and create is true it creates a new item.
virtual bool IsIntSetting() const
Check whether this setting is an integer type setting.
StringList _network_host_list
The servers we know.
char * filename
Filename - either with or without full path.
void FormatValue(char *buf, const char *last, const void *object) const override
Format the value of the setting associated with this object.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
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.
void LoadFromDisk(const std::string &filename, Subdirectory subdir)
Load the Ini file's data from the disk.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
@ SF_NO_NETWORK
This setting does not apply to network games; it may not be changed during the game.
IniFileVersion
Ini-file versions.
bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir)
Find the GRFID of a given grf, and calculate its md5sum.
#define lastof(x)
Get the last element of an fixed size array.
static ErrorList _settings_error_list
Errors while loading minimal settings.
void LoadFromConfig(bool startup)
Load the values from the configuration files.
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.
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
int32 def
default value given when none is present
CommandCost CmdChangeSetting(DoCommandFlag flags, const std::string &name, int32 value)
Network-safe changing of settings (server-only).
static bool LoadIntList(const char *str, void *array, int nelems, VarType type)
Load parsed string-values into an integer-array (intlist)
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
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 |.
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
uint32 param[0x80]
GRF parameters.
GRFConfig * _grfconfig_newgame
First item in list of default GRF set up.
const struct IntSettingDesc * AsIntSetting() const
Get the setting description of this setting as an integer setting.
IniGroup * GetGroup(const std::string &name, bool create_new=true)
Get the group with the given name.
void FormatValue(char *buf, const char *last, const void *object) const override
Format the value of the setting associated with this object.
IniGroup * next
the next group within this 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.