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",
176 if (isdigit(*
str))
return strtoul(
str,
nullptr, 0);
179 for (
auto one :
many) {
180 if (one.size() == len && strncmp(one.c_str(),
str, len) == 0)
return idx;
202 while (*str ==
' ' || *str ==
'\t' || *str ==
'|') str++;
203 if (*str == 0)
break;
206 while (*s != 0 && *s !=
' ' && *s !=
'\t' && *s !=
'|') s++;
209 if (r == (
size_t)-1)
return r;
236 if (!comma)
return -1;
245 if (n == maxitems)
return -1;
247 unsigned long v = strtoul(p, &end, 0);
248 if (p == end)
return -1;
249 if (
sizeof(T) <
sizeof(v)) v = Clamp<unsigned long>(v, std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
260 if (n != 0 && !comma)
return -1;
273 static bool LoadIntList(
const char *str,
void *array,
int nelems, VarType type)
275 unsigned long items[64];
278 if (str ==
nullptr) {
279 memset(items, 0,
sizeof(items));
283 if (nitems != nelems)
return false;
290 for (i = 0; i != nitems; i++) ((
byte*)array)[i] = items[i];
295 for (i = 0; i != nitems; i++) ((uint16*)array)[i] = items[i];
300 for (i = 0; i != nitems; i++) ((uint32*)array)[i] = items[i];
303 default: NOT_REACHED();
326 case SLE_VAR_I8: v = *(
const int8 *)p; p += 1;
break;
327 case SLE_VAR_U8: v = *(
const uint8 *)p; p += 1;
break;
328 case SLE_VAR_I16: v = *(
const int16 *)p; p += 2;
break;
329 case SLE_VAR_U16: v = *(
const uint16 *)p; p += 2;
break;
330 case SLE_VAR_I32: v = *(
const int32 *)p; p += 4;
break;
331 case SLE_VAR_U32: v = *(
const uint32 *)p; p += 4;
break;
332 default: NOT_REACHED();
334 if (IsSignedVarMemType(this->
save.
conv)) {
335 buf +=
seprintf(buf, last, (i == 0) ?
"%d" :
",%d", v);
337 buf +=
seprintf(buf, last, (i == 0) ?
"%u" :
",%u", v);
342 char *OneOfManySettingDesc::FormatSingleValue(
char *buf,
const char *last, uint
id)
const
344 if (
id >= this->
many.size()) {
345 return buf +
seprintf(buf, last,
"%d",
id);
352 uint
id = (uint)this->
Read(
object);
353 this->FormatSingleValue(buf, last,
id);
358 uint bitmask = (uint)this->
Read(
object);
365 if (!first) buf =
strecpy(buf,
"|", last);
366 buf = this->FormatSingleValue(buf, last,
id);
379 size_t val = strtoul(
str, &end, 0);
388 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS);
401 if (r != (
size_t)-1)
return r;
413 if (r != (
size_t)-1)
return r;
423 if (strcmp(
str,
"true") == 0 || strcmp(
str,
"on") == 0 || strcmp(
str,
"1") == 0)
return true;
424 if (strcmp(
str,
"false") == 0 || strcmp(
str,
"off") == 0 || strcmp(
str,
"0") == 0)
return false;
442 this->
Write(
object, val);
474 }
else if (val < this->
min || val > (int32)this->
max) {
483 uint32 uval = (uint32)val;
488 }
else if (uval < (uint)this->
min || uval > this->
max) {
490 uval = (uint32)this->
def;
498 default: NOT_REACHED();
533 if (this->
max_length == 0 || str.size() < this->max_length)
return;
538 std::string stdstr(str, this->
max_length - 1);
576 for (
auto &desc : settings_table) {
579 if (sd->
startup != only_startup)
continue;
582 std::string s{ sd->
GetName() };
583 auto sc = s.find(
'.');
584 if (sc != std::string::npos) {
585 group = ini.
GetGroup(s.substr(0, sc));
586 s = s.substr(sc + 1);
592 if (item ==
nullptr && group != group_def) {
595 item = group_def->
GetItem(s,
false);
597 if (item ==
nullptr) {
601 if (sc != std::string::npos) item = ini.
GetGroup(s.substr(0, sc))->
GetItem(s.substr(sc + 1),
false);
610 size_t val = (item ==
nullptr) ? this->
def : this->
ParseValue(item->
value.has_value() ? item->
value->c_str() :
"");
616 std::string str = (item ==
nullptr) ? this->
def : item->
value.value_or(
"");
618 this->
Write(
object, str);
623 const char *str = (item ==
nullptr) ? this->
def : item->
value.has_value() ? item->
value->c_str() :
nullptr;
649 IniGroup *group_def =
nullptr, *group;
653 for (
auto &desc : settings_table) {
661 std::string s{ sd->
GetName() };
662 auto sc = s.find(
'.');
663 if (sc != std::string::npos) {
664 group = ini.
GetGroup(s.substr(0, sc));
665 s = s.substr(sc + 1);
667 if (group_def ==
nullptr) group_def = ini.
GetGroup(grpname);
671 item = group->GetItem(s,
true);
678 item->
value.emplace(buf);
685 uint32 i = (uint32)this->
Read(
object);
691 bool val = this->
Read(
object) != 0;
692 strecpy(buf, val ?
"true" :
"false", last);
698 int32 object_value = this->
Read(
object);
699 return item_value == object_value;
704 const std::string &str = this->
Read(
object);
712 seprintf(buf, last,
"\"%s\"", str.c_str());
716 default: NOT_REACHED();
726 const std::string &str = this->
Read(
object);
727 return item->
value->compare(str) == 0;
749 if (group ==
nullptr)
return;
753 for (
const IniItem *item = group->
item; item !=
nullptr; item = item->
next) {
754 if (!item->name.empty()) list.push_back(item->name);
771 if (group ==
nullptr)
return;
774 for (
const auto &iter : list) {
812 (_game_mode == GM_NORMAL ||
862 static void AILoadConfig(
IniFile &ini,
const char *grpname)
873 if (group ==
nullptr)
return;
876 for (item = group->
item; c < MAX_COMPANIES && item != nullptr; c++, item = item->next) {
881 if (item->
name !=
"none") {
882 Debug(script, 0,
"The AI by the name '{}' was no longer found, and removed from the list.", item->
name);
890 static void GameLoadConfig(
IniFile &ini,
const char *grpname)
899 if (group ==
nullptr)
return;
902 if (item ==
nullptr)
return;
908 if (item->
name !=
"none") {
909 Debug(script, 0,
"The GameScript by the name '{}' was no longer found, and removed from the list.", item->
name);
923 if (c >=
'0' && c <=
'9')
return c -
'0';
924 if (c >=
'A' && c <=
'F')
return c + 10 -
'A';
925 if (c >=
'a' && c <=
'f')
return c + 10 -
'a';
939 while (dest_size > 0) {
942 if (lo < 0)
return false;
943 *dest++ = (hi << 4) | lo;
963 if (group ==
nullptr)
return nullptr;
966 for (item = group->
item; item !=
nullptr; item = item->
next) {
969 uint8 grfid_buf[4], md5sum[16];
970 const char *filename = item->
name.c_str();
971 bool has_grfid =
false;
972 bool has_md5sum =
false;
977 filename += 1 + 2 *
lengthof(grfid_buf);
979 if (has_md5sum) filename += 1 + 2 *
lengthof(md5sum);
981 uint32 grfid = grfid_buf[0] | (grfid_buf[1] << 8) | (grfid_buf[2] << 16) | (grfid_buf[3] << 24);
991 if (c ==
nullptr) c =
new GRFConfig(filename);
994 if (item->
value.has_value() && !item->
value->empty()) {
1007 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
1009 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNSAFE);
1011 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_SYSTEM);
1013 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
1015 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
1025 bool duplicate =
false;
1026 for (
const GRFConfig *gc = first; gc !=
nullptr; gc = gc->
next) {
1061 auto version_number = group->
GetItem(
"ini_version",
false);
1063 if (version_number ==
nullptr || !version_number->value.has_value())
return IFV_0;
1066 std::from_chars(version_number->value->data(), version_number->value->data() + version_number->value->size(), version);
1071 static void AISaveConfig(
IniFile &ini,
const char *grpname)
1075 if (group ==
nullptr)
return;
1094 static void GameSaveConfig(
IniFile &ini,
const char *grpname)
1098 if (group ==
nullptr)
return;
1123 group->
GetItem(
"version_number",
true)->
SetValue(fmt::format(
"{:08X}", _openttd_newgrf_version));
1128 static void GRFSaveConfig(
IniFile &ini,
const char *grpname,
const GRFConfig *list)
1134 for (c = list; c !=
nullptr; c = c->
next) {
1136 char key[4 * 2 + 1 + 16 * 2 + 1 + MAX_PATH];
1148 static void HandleSettingDescs(
IniFile &generic_ini,
IniFile &private_ini,
IniFile &secrets_ini, SettingDescProc *proc, SettingDescProcList *proc_list,
bool only_startup =
false)
1150 proc(generic_ini, _misc_settings,
"misc",
nullptr, only_startup);
1151 #if defined(_WIN32) && !defined(DEDICATED)
1152 proc(generic_ini, _win32_settings,
"win32",
nullptr, only_startup);
1167 proc(generic_ini, _currency_settings,
"currency", &_custom_currency, only_startup);
1170 if (!only_startup) {
1188 for (
auto &desc : table) {
1192 std::string s{ sd->
GetName() };
1193 auto sc = s.find(
'.');
1194 if (sc == std::string::npos)
continue;
1197 s = s.substr(sc + 1);
1215 IniFileVersion generic_version = LoadVersionFromConfig(generic_ini);
1230 if (network !=
nullptr) {
1231 IniItem *server_advertise = network->
GetItem(
"server_advertise",
false);
1232 if (server_advertise !=
nullptr && server_advertise->
value ==
"true") {
1241 AILoadConfig(generic_ini,
"ai_players");
1242 GameLoadConfig(generic_ini,
"game_scripts");
1265 IniFileVersion generic_version = LoadVersionFromConfig(generic_ini);
1271 if (!private_ini.
GetGroup(
"private",
false)) private_ini.
GetGroup(
"private")->
comment =
"; This file possibly contains private information which can identify you as person.\n";
1272 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";
1274 if (generic_version ==
IFV_0) {
1297 if (network !=
nullptr) {
1305 AISaveConfig(generic_ini,
"ai_players");
1306 GameSaveConfig(generic_ini,
"game_scripts");
1327 if (group->
name.compare(0, 7,
"preset-") == 0) {
1328 list.push_back(group->
name.substr(7));
1343 size_t len = strlen(config_name) + 8;
1344 char *section = (
char*)alloca(len);
1345 seprintf(section, section + len - 1,
"preset-%s", config_name);
1361 size_t len = strlen(config_name) + 8;
1362 char *section = (
char*)alloca(len);
1363 seprintf(section, section + len - 1,
"preset-%s", config_name);
1366 GRFSaveConfig(ini, section, config);
1376 size_t len = strlen(config_name) + 8;
1377 char *section = (
char*)alloca(len);
1378 seprintf(section, section + len - 1,
"preset-%s", config_name);
1393 int32 oldval = this->
Read(
object);
1396 if (oldval == newval)
return;
1398 this->
Write(
object, newval);
1425 if (sd->
GetName() == name)
return sd;
1429 std::string short_name_suffix = std::string{
"." }.append(name);
1449 saveloads.push_back(sd->
save);
1461 static const std::string_view company_prefix =
"company.";
1462 if (
StrStartsWith(name, company_prefix)) name.remove_prefix(company_prefix.size());
1476 if (sd !=
nullptr)
return sd;
1480 if (sd !=
nullptr)
return sd;
1484 if (sd !=
nullptr)
return sd;
1568 if (_game_mode != GM_MENU) {
1575 if (force_newgame) {
1593 for (
auto &desc : _company_settings) {
1606 for (
auto &desc : _company_settings) {
1645 this->
Write(
object, newval);
1653 void IConsoleSetSetting(
const char *name,
const char *value,
bool force_newgame)
1656 if (sd ==
nullptr) {
1661 bool success =
true;
1684 void IConsoleSetSetting(
const char *name,
int value)
1687 assert(sd !=
nullptr);
1699 if (sd ==
nullptr) {
1717 static void IConsoleListSettingsTable(
const SettingTable &table,
const char *prefilter)
1719 for (
auto &desc : table) {
1722 if (prefilter !=
nullptr && sd->
GetName().find(prefilter) == std::string::npos)
continue;
1739 IConsoleListSettingsTable(table, prefilter);
1742 IConsoleListSettingsTable(table, prefilter);
1745 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.
@ 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.
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.
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.
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.
NetworkSettings network
settings related to the network
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 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
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.