OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
48 #include "table/strings.h"
60 typedef std::list<ErrorMessageData>
ErrorList;
84 _news_display_settings,
85 _pathfinding_settings,
89 return _generic_setting_tables;
98 _network_private_settings,
100 return _private_setting_tables;
109 _network_secrets_settings,
111 return _secrets_setting_tables;
114 typedef void SettingDescProc(
IniFile &ini,
const SettingTable &desc,
const char *grpname,
void *
object,
bool only_startup);
115 typedef void SettingDescProcList(
IniFile &ini,
const char *grpname,
StringList &list);
117 static bool IsSignedVarMemType(VarType vt)
134 inline static const char *
const list_group_names[] = {
138 "server_bind_addresses",
175 if (isdigit(*
str))
return strtoul(
str,
nullptr, 0);
178 for (
auto one :
many) {
179 if (one.size() == len && strncmp(one.c_str(),
str, len) == 0)
return idx;
201 while (*str ==
' ' || *str ==
'\t' || *str ==
'|') str++;
202 if (*str == 0)
break;
205 while (*s != 0 && *s !=
' ' && *s !=
'\t' && *s !=
'|') s++;
208 if (r == (
size_t)-1)
return r;
235 if (!comma)
return -1;
244 if (n == maxitems)
return -1;
246 unsigned long v = strtoul(p, &end, 0);
247 if (p == end)
return -1;
248 if (
sizeof(T) <
sizeof(v)) v = Clamp<unsigned long>(v, std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
259 if (n != 0 && !comma)
return -1;
272 static bool LoadIntList(
const char *str,
void *array,
int nelems, VarType type)
274 unsigned long items[64];
277 if (str ==
nullptr) {
278 memset(items, 0,
sizeof(items));
282 if (nitems != nelems)
return false;
289 for (i = 0; i != nitems; i++) ((
byte*)array)[i] = items[i];
294 for (i = 0; i != nitems; i++) ((uint16*)array)[i] = items[i];
299 for (i = 0; i != nitems; i++) ((uint32*)array)[i] = items[i];
302 default: NOT_REACHED();
325 case SLE_VAR_I8: v = *(
const int8 *)p; p += 1;
break;
326 case SLE_VAR_U8: v = *(
const uint8 *)p; p += 1;
break;
327 case SLE_VAR_I16: v = *(
const int16 *)p; p += 2;
break;
328 case SLE_VAR_U16: v = *(
const uint16 *)p; p += 2;
break;
329 case SLE_VAR_I32: v = *(
const int32 *)p; p += 4;
break;
330 case SLE_VAR_U32: v = *(
const uint32 *)p; p += 4;
break;
331 default: NOT_REACHED();
333 if (IsSignedVarMemType(this->
save.
conv)) {
334 buf +=
seprintf(buf, last, (i == 0) ?
"%d" :
",%d", v);
336 buf +=
seprintf(buf, last, (i == 0) ?
"%u" :
",%u", v);
341 char *OneOfManySettingDesc::FormatSingleValue(
char *buf,
const char *last, uint
id)
const
343 if (
id >= this->
many.size()) {
344 return buf +
seprintf(buf, last,
"%d",
id);
351 uint
id = (uint)this->
Read(
object);
352 this->FormatSingleValue(buf, last,
id);
357 uint bitmask = (uint)this->
Read(
object);
360 if (!first) buf =
strecpy(buf,
"|", last);
361 buf = this->FormatSingleValue(buf, last,
id);
374 size_t val = strtoul(
str, &end, 0);
383 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS);
396 if (r != (
size_t)-1)
return r;
408 if (r != (
size_t)-1)
return r;
418 if (strcmp(
str,
"true") == 0 || strcmp(
str,
"on") == 0 || strcmp(
str,
"1") == 0)
return true;
419 if (strcmp(
str,
"false") == 0 || strcmp(
str,
"off") == 0 || strcmp(
str,
"0") == 0)
return false;
437 this->
Write(
object, val);
469 }
else if (val < this->
min || val > (int32)this->
max) {
478 uint32 uval = (uint32)val;
483 }
else if (uval < (uint)this->
min || uval > this->
max) {
485 uval = (uint32)this->
def;
493 default: NOT_REACHED();
528 if (this->
max_length == 0 || str.size() < this->max_length)
return;
533 std::string stdstr(str, this->
max_length - 1);
571 for (
auto &desc : settings_table) {
574 if (sd->
startup != only_startup)
continue;
577 std::string s{ sd->
GetName() };
578 auto sc = s.find(
'.');
579 if (sc != std::string::npos) {
580 group = ini.
GetGroup(s.substr(0, sc));
581 s = s.substr(sc + 1);
587 if (item ==
nullptr && group != group_def) {
590 item = group_def->
GetItem(s,
false);
592 if (item ==
nullptr) {
596 if (sc != std::string::npos) item = ini.
GetGroup(s.substr(0, sc))->
GetItem(s.substr(sc + 1),
false);
605 size_t val = (item ==
nullptr) ? this->
def : this->
ParseValue(item->
value.has_value() ? item->
value->c_str() :
"");
611 std::string str = (item ==
nullptr) ? this->
def : item->
value.value_or(
"");
613 this->
Write(
object, str);
618 const char *str = (item ==
nullptr) ? this->
def : item->
value.has_value() ? item->
value->c_str() :
nullptr;
644 IniGroup *group_def =
nullptr, *group;
648 for (
auto &desc : settings_table) {
656 std::string s{ sd->
GetName() };
657 auto sc = s.find(
'.');
658 if (sc != std::string::npos) {
659 group = ini.
GetGroup(s.substr(0, sc));
660 s = s.substr(sc + 1);
662 if (group_def ==
nullptr) group_def = ini.
GetGroup(grpname);
666 item = group->GetItem(s,
true);
673 item->
value.emplace(buf);
680 uint32 i = (uint32)this->
Read(
object);
686 bool val = this->
Read(
object) != 0;
687 strecpy(buf, val ?
"true" :
"false", last);
693 int32 object_value = this->
Read(
object);
694 return item_value == object_value;
699 const std::string &str = this->
Read(
object);
707 seprintf(buf, last,
"\"%s\"", str.c_str());
711 default: NOT_REACHED();
721 const std::string &str = this->
Read(
object);
722 return item->
value->compare(str) == 0;
744 if (group ==
nullptr)
return;
748 for (
const IniItem *item = group->
item; item !=
nullptr; item = item->
next) {
749 if (!item->name.empty()) list.push_back(item->name);
766 if (group ==
nullptr)
return;
769 for (
const auto &iter : list) {
807 (_game_mode == GM_NORMAL ||
857 static void AILoadConfig(
IniFile &ini,
const char *grpname)
868 if (group ==
nullptr)
return;
871 for (item = group->
item; c < MAX_COMPANIES && item != nullptr; c++, item = item->next) {
876 if (item->
name !=
"none") {
877 Debug(script, 0,
"The AI by the name '{}' was no longer found, and removed from the list.", item->
name);
885 static void GameLoadConfig(
IniFile &ini,
const char *grpname)
894 if (group ==
nullptr)
return;
897 if (item ==
nullptr)
return;
903 if (item->
name !=
"none") {
904 Debug(script, 0,
"The GameScript by the name '{}' was no longer found, and removed from the list.", item->
name);
918 if (c >=
'0' && c <=
'9')
return c -
'0';
919 if (c >=
'A' && c <=
'F')
return c + 10 -
'A';
920 if (c >=
'a' && c <=
'f')
return c + 10 -
'a';
934 while (dest_size > 0) {
937 if (lo < 0)
return false;
938 *dest++ = (hi << 4) | lo;
958 if (group ==
nullptr)
return nullptr;
961 for (item = group->
item; item !=
nullptr; item = item->
next) {
964 uint8 grfid_buf[4], md5sum[16];
965 const char *filename = item->
name.c_str();
966 bool has_grfid =
false;
967 bool has_md5sum =
false;
972 filename += 1 + 2 *
lengthof(grfid_buf);
974 if (has_md5sum) filename += 1 + 2 *
lengthof(md5sum);
976 uint32 grfid = grfid_buf[0] | (grfid_buf[1] << 8) | (grfid_buf[2] << 16) | (grfid_buf[3] << 24);
986 if (c ==
nullptr) c =
new GRFConfig(filename);
989 if (item->
value.has_value() && !item->
value->empty()) {
1002 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
1004 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNSAFE);
1006 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_SYSTEM);
1008 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
1010 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
1020 bool duplicate =
false;
1021 for (
const GRFConfig *gc = first; gc !=
nullptr; gc = gc->
next) {
1056 auto version_number = group->
GetItem(
"ini_version",
false);
1058 if (version_number ==
nullptr || !version_number->value.has_value())
return IFV_0;
1061 std::from_chars(version_number->value->data(), version_number->value->data() + version_number->value->size(), version);
1066 static void AISaveConfig(
IniFile &ini,
const char *grpname)
1070 if (group ==
nullptr)
return;
1089 static void GameSaveConfig(
IniFile &ini,
const char *grpname)
1093 if (group ==
nullptr)
return;
1118 group->
GetItem(
"version_number",
true)->
SetValue(fmt::format(
"{:08X}", _openttd_newgrf_version));
1123 static void GRFSaveConfig(
IniFile &ini,
const char *grpname,
const GRFConfig *list)
1129 for (c = list; c !=
nullptr; c = c->
next) {
1131 char key[4 * 2 + 1 + 16 * 2 + 1 + MAX_PATH];
1143 static void HandleSettingDescs(
IniFile &generic_ini,
IniFile &private_ini,
IniFile &secrets_ini, SettingDescProc *proc, SettingDescProcList *proc_list,
bool only_startup =
false)
1145 proc(generic_ini, _misc_settings,
"misc",
nullptr, only_startup);
1146 #if defined(_WIN32) && !defined(DEDICATED)
1147 proc(generic_ini, _win32_settings,
"win32",
nullptr, only_startup);
1162 proc(generic_ini, _currency_settings,
"currency", &_custom_currency, only_startup);
1165 if (!only_startup) {
1183 for (
auto &desc : table) {
1187 std::string s{ sd->
GetName() };
1188 auto sc = s.find(
'.');
1189 if (sc == std::string::npos)
continue;
1192 s = s.substr(sc + 1);
1210 IniFileVersion generic_version = LoadVersionFromConfig(generic_ini);
1223 AILoadConfig(generic_ini,
"ai_players");
1224 GameLoadConfig(generic_ini,
"game_scripts");
1246 IniFileVersion generic_version = LoadVersionFromConfig(generic_ini);
1252 if (!private_ini.
GetGroup(
"private",
false)) private_ini.
GetGroup(
"private")->
comment =
"; This file possibly contains private information which can identify you as person.\n";
1253 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";
1255 if (generic_version ==
IFV_0) {
1278 AISaveConfig(generic_ini,
"ai_players");
1279 GameSaveConfig(generic_ini,
"game_scripts");
1300 if (group->
name.compare(0, 7,
"preset-") == 0) {
1301 list.push_back(group->
name.substr(7));
1316 size_t len = strlen(config_name) + 8;
1317 char *section = (
char*)alloca(len);
1318 seprintf(section, section + len - 1,
"preset-%s", config_name);
1334 size_t len = strlen(config_name) + 8;
1335 char *section = (
char*)alloca(len);
1336 seprintf(section, section + len - 1,
"preset-%s", config_name);
1339 GRFSaveConfig(ini, section, config);
1349 size_t len = strlen(config_name) + 8;
1350 char *section = (
char*)alloca(len);
1351 seprintf(section, section + len - 1,
"preset-%s", config_name);
1366 int32 oldval = this->
Read(
object);
1369 if (oldval == newval)
return;
1371 this->
Write(
object, newval);
1398 if (sd->
GetName() == name)
return sd;
1402 std::string short_name_suffix = std::string{
"." }.append(name);
1422 saveloads.push_back(sd->
save);
1434 static const std::string_view company_prefix =
"company.";
1435 if (
StrStartsWith(name, company_prefix)) name.remove_prefix(company_prefix.size());
1449 if (sd !=
nullptr)
return sd;
1453 if (sd !=
nullptr)
return sd;
1457 if (sd !=
nullptr)
return sd;
1541 if (_game_mode != GM_MENU) {
1548 if (force_newgame) {
1566 for (
auto &desc : _company_settings) {
1579 for (
auto &desc : _company_settings) {
1618 this->
Write(
object, newval);
1626 void IConsoleSetSetting(
const char *name,
const char *value,
bool force_newgame)
1629 if (sd ==
nullptr) {
1634 bool success =
true;
1657 void IConsoleSetSetting(
const char *name,
int value)
1660 assert(sd !=
nullptr);
1672 if (sd ==
nullptr) {
1690 static void IConsoleListSettingsTable(
const SettingTable &table,
const char *prefilter)
1692 for (
auto &desc : table) {
1695 if (prefilter !=
nullptr && sd->
GetName().find(prefilter) == std::string::npos)
continue;
1712 IConsoleListSettingsTable(table, prefilter);
1715 IConsoleListSettingsTable(table, prefilter);
1718 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.
uint32 TileIndex
The index/ID of a Tile.
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.
@ 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.
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const std::string &text, CompanyID company)
Prepare a DoCommand to be send over the network.
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.
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.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
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...
CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Network-safe changing of settings (server-only).
@ 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.
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.
CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Change one of the per-company settings.
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.
static void SaveVersionInConfig(IniFile &ini)
Save the version of OpenTTD to the ini file.
@ CMD_CHANGE_SETTING
change a setting
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.
@ CMD_CHANGE_COMPANY_SETTING
change a company setting
void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
Save a NewGRF configuration with a preset name.
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
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.