Go to the documentation of this file.
41 #if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
70 #if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
71 #define HAS_TRUETYPE_FONT
74 #include "table/strings.h"
75 #include "table/settings.h"
85 typedef std::list<ErrorMessageData>
ErrorList;
89 typedef void SettingDescProc(
IniFile *ini,
const SettingDesc *desc,
const char *grpname,
void *
object,
bool only_startup);
90 typedef void SettingDescProcList(
IniFile *ini,
const char *grpname,
StringList &list);
92 static bool IsSignedVarMemType(VarType vt);
101 "server_bind_addresses",
117 if (onelen == 0) onelen = strlen(one);
120 if (*one >=
'0' && *one <=
'9')
return strtoul(one,
nullptr, 0);
126 while (*s !=
'|' && *s != 0) s++;
127 if ((
size_t)(s - many) == onelen && !memcmp(one, many, onelen))
return idx;
128 if (*s == 0)
return (
size_t)-1;
149 while (*str ==
' ' || *str ==
'\t' || *str ==
'|') str++;
150 if (*str == 0)
break;
153 while (*s != 0 && *s !=
' ' && *s !=
'\t' && *s !=
'|') s++;
156 if (r == (
size_t)-1)
return r;
183 if (!comma)
return -1;
192 if (n == maxitems)
return -1;
194 unsigned long v = strtoul(p, &end, 0);
195 if (p == end)
return -1;
196 if (
sizeof(T) <
sizeof(v)) v = Clamp<unsigned long>(v, std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
207 if (n != 0 && !comma)
return -1;
220 static bool LoadIntList(
const char *str,
void *array,
int nelems, VarType type)
222 unsigned long items[64];
225 if (str ==
nullptr) {
226 memset(items, 0,
sizeof(items));
230 if (nitems != nelems)
return false;
237 for (i = 0; i != nitems; i++) ((
byte*)array)[i] = items[i];
242 for (i = 0; i != nitems; i++) ((uint16*)array)[i] = items[i];
247 for (i = 0; i != nitems; i++) ((uint32*)array)[i] = items[i];
250 default: NOT_REACHED();
265 static void MakeIntList(
char *buf,
const char *last,
const void *array,
int nelems, VarType type)
268 const byte *p = (
const byte *)array;
270 for (i = 0; i != nelems; i++) {
273 case SLE_VAR_I8: v = *(
const int8 *)p; p += 1;
break;
274 case SLE_VAR_U8: v = *(
const uint8 *)p; p += 1;
break;
275 case SLE_VAR_I16: v = *(
const int16 *)p; p += 2;
break;
276 case SLE_VAR_U16: v = *(
const uint16 *)p; p += 2;
break;
277 case SLE_VAR_I32: v = *(
const int32 *)p; p += 4;
break;
278 case SLE_VAR_U32: v = *(
const uint32 *)p; p += 4;
break;
279 default: NOT_REACHED();
281 if (IsSignedVarMemType(type)) {
282 buf +=
seprintf(buf, last, (i == 0) ?
"%d" :
",%d", v);
284 buf +=
seprintf(buf, last, (i == 0) ?
"0x%X" :
",0x%X", v);
286 buf +=
seprintf(buf, last, (i == 0) ?
"%u" :
",%u", v);
298 static void MakeOneOfMany(
char *buf,
const char *last,
const char *many,
int id)
304 for (; *many !=
'|'; many++) {
314 while (*many !=
'\0' && *many !=
'|' && buf < last) *buf++ = *many++;
326 static void MakeManyOfMany(
char *buf,
const char *last,
const char *many, uint32 x)
332 for (; x != 0; x >>= 1, i++) {
334 while (*many != 0 && *many !=
'|') many++;
337 if (!init) buf +=
seprintf(buf, last,
"|");
340 buf +=
seprintf(buf, last,
"%d", i);
342 memcpy(buf, start, many - start);
347 if (*many ==
'|') many++;
361 const char *str = orig_str ==
nullptr ?
"" : orig_str;
366 size_t val = strtoul(str, &end, 0);
375 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS);
387 if (r != (
size_t)-1)
return (
void*)r;
398 if (r != (
size_t)-1)
return (
void*)r;
407 if (strcmp(str,
"true") == 0 || strcmp(str,
"on") == 0 || strcmp(str,
"1") == 0)
return (
void*)
true;
408 if (strcmp(str,
"false") == 0 || strcmp(str,
"off") == 0 || strcmp(str,
"0") == 0)
return (
void*)
false;
466 }
else if (val < sdb->min || val > (int32)sdb->
max) {
468 val = (int32)(
size_t)sdb->
def;
475 uint32 uval = (uint32)val;
480 }
else if (uval < (uint)sdb->
min || uval > sdb->
max) {
482 uval = (uint32)(
size_t)sdb->
def;
490 default: NOT_REACHED();
511 for (; sd->
save.
cmd != SL_END; sd++) {
519 std::string s{ sdb->
name };
520 auto sc = s.find(
'.');
521 if (sc != std::string::npos) {
522 group = ini->
GetGroup(s.substr(0, sc));
523 s = s.substr(sc + 1);
529 if (item ==
nullptr && group != group_def) {
532 item = group_def->
GetItem(s,
false);
534 if (item ==
nullptr) {
538 if (sc != std::string::npos) item = ini->
GetGroup(s.substr(0, sc))->
GetItem(s.substr(sc + 1),
false);
541 const void *p = (item ==
nullptr) ? sdb->
def :
StringToVal(sdb, item->
value.has_value() ? item->
value->c_str() :
nullptr);
556 if (p !=
nullptr)
strecpy((
char*)ptr, (
const char*)p, (
char*)ptr + sld->
length - 1);
562 *(
char**)ptr = p ==
nullptr ?
nullptr :
stredup((
const char*)p);
565 case SLE_VAR_CHAR:
if (p !=
nullptr) *(
char *)ptr = *(
const char *)p;
break;
567 default: NOT_REACHED();
576 reinterpret_cast<std::string *
>(ptr)->assign((
const char *)p);
578 reinterpret_cast<std::string *
>(ptr)->clear();
582 default: NOT_REACHED();
600 default: NOT_REACHED();
619 IniGroup *group_def =
nullptr, *group;
624 for (; sd->
save.
cmd != SL_END; sd++) {
634 std::string s{ sdb->
name };
635 auto sc = s.find(
'.');
636 if (sc != std::string::npos) {
637 group = ini->
GetGroup(s.substr(0, sc));
638 s = s.substr(sc + 1);
640 if (group_def ==
nullptr) group_def = ini->
GetGroup(grpname);
644 item = group->GetItem(s,
true);
647 if (item->
value.has_value()) {
660 if (*(
bool*)ptr == (p !=
nullptr))
continue;
665 if (*(
byte*)ptr == (
byte)(
size_t)p)
continue;
670 if (*(uint16*)ptr == (uint16)(
size_t)p)
continue;
675 if (*(uint32*)ptr == (uint32)(
size_t)p)
continue;
678 default: NOT_REACHED();
699 default: NOT_REACHED();
711 if (*(
char**)ptr ==
nullptr) {
718 case SLE_VAR_CHAR: buf[0] = *(
char*)ptr; buf[1] =
'\0';
break;
719 default: NOT_REACHED();
728 if (
reinterpret_cast<std::string *
>(ptr)->empty()) {
731 seprintf(buf,
lastof(buf),
"\"%s\"",
reinterpret_cast<std::string *
>(ptr)->c_str());
735 default: NOT_REACHED();
743 default: NOT_REACHED();
747 item->
value.emplace(buf);
764 if (group ==
nullptr)
return;
768 for (
const IniItem *item = group->
item; item !=
nullptr; item = item->
next) {
769 if (!item->name.empty()) list.push_back(item->name);
786 if (group ==
nullptr)
return;
789 for (
const auto &iter : list) {
827 (_game_mode == GM_NORMAL ||
828 (_game_mode == GM_EDITOR && !(this->desc.flags &
SGF_SCENEDIT_TOO))))
return false;
855 if (_game_mode != GM_MENU) {
863 static bool PopulationInLabelActive(int32 p1)
869 static bool RedrawScreen(int32 p1)
888 static bool InvalidateDetailsWindow(int32 p1)
894 static bool StationSpreadChanged(int32 p1)
901 static bool InvalidateBuildIndustryWindow(int32 p1)
907 static bool CloseSignalGUI(int32 p1)
915 static bool InvalidateTownViewWindow(int32 p1)
921 static bool DeleteSelectStationWindow(int32 p1)
927 static bool UpdateConsists(int32 p1)
931 if (t->IsFrontEngine() || t->IsFreeWagon()) t->ConsistChanged(
CCF_TRACK);
938 static bool CheckInterval(int32 p1)
940 bool update_vehicles;
944 update_vehicles =
false;
947 update_vehicles =
true;
962 if (update_vehicles) {
965 if (v->owner ==
_current_company && v->IsPrimaryVehicle() && !v->ServiceIntervalIsCustom()) {
967 v->SetServiceIntervalIsPercent(p1 != 0);
972 InvalidateDetailsWindow(0);
977 static bool UpdateInterval(
VehicleType type, int32 p1)
979 bool update_vehicles;
983 update_vehicles =
false;
986 update_vehicles =
true;
991 if (interval != p1)
return false;
993 if (update_vehicles) {
995 if (v->owner ==
_current_company && v->type == type && v->IsPrimaryVehicle() && !v->ServiceIntervalIsCustom()) {
996 v->SetServiceInterval(p1);
1001 InvalidateDetailsWindow(0);
1006 static bool UpdateIntervalTrains(int32 p1)
1011 static bool UpdateIntervalRoadVeh(int32 p1)
1013 return UpdateInterval(
VEH_ROAD, p1);
1016 static bool UpdateIntervalShips(int32 p1)
1018 return UpdateInterval(
VEH_SHIP, p1);
1021 static bool UpdateIntervalAircraft(int32 p1)
1026 static bool TrainAccelerationModelChanged(int32 p1)
1029 if (t->IsFrontEngine()) {
1030 t->tcache.cached_max_curve_speed = t->GetCurveSpeedLimit();
1031 t->UpdateAcceleration();
1051 if (t->IsFrontEngine()) t->CargoChanged();
1066 if (rv->IsFrontEngine()) {
1088 if (rv->IsFrontEngine()) rv->CargoChanged();
1094 static bool DragSignalsDensityChanged(int32)
1101 static bool TownFoundingChanged(int32 p1)
1111 static bool InvalidateVehTimetableWindow(int32 p1)
1117 static bool ZoomMinMaxChanged(int32 p1)
1119 extern void ConstrainAllViewportsZoom();
1120 ConstrainAllViewportsZoom();
1131 static bool SpriteZoomMinChanged(int32 p1) {
1153 static bool InvalidateCompanyLiveryWindow(int32 p1)
1156 return RedrawScreen(p1);
1159 static bool InvalidateIndustryViewWindow(int32 p1)
1165 static bool InvalidateAISettingsWindow(int32 p1)
1214 static bool DifficultyNoiseChange(int32 i)
1216 if (_game_mode == GM_NORMAL) {
1226 static bool MaxNoAIsChange(int32 i)
1262 static bool CheckFreeformEdges(int32 p1)
1264 if (_game_mode == GM_MENU)
return true;
1268 if (
TileX(s->tile) == 0 ||
TileY(s->tile) == 0) {
1275 if (st->IsInUse() && (
TileX(st->xy) == 0 ||
TileY(st->xy) == 0)) {
1283 for (uint i = 0; i <
MapMaxX(); i++) {
1289 for (uint i = 1; i <
MapMaxX(); i++) {
1295 for (uint i = 0; i <
MapMaxY(); i++) {
1301 for (uint i = 1; i <
MapMaxY(); i++) {
1308 for (uint i = 0; i <
MapMaxX(); i++) {
1312 for (uint i = 0; i <
MapMaxY(); i++) {
1327 if (_game_mode == GM_MENU)
return true;
1337 static bool ChangeMaxHeightLevel(int32 p1)
1339 if (_game_mode == GM_NORMAL)
return false;
1340 if (_game_mode != GM_EDITOR)
return true;
1358 static bool StationCatchmentChanged(int32 p1)
1365 static bool MaxVehiclesChanged(int32 p1)
1372 static bool InvalidateShipPathCache(int32 p1)
1380 static bool UpdateClientName(int32 p1)
1386 static bool UpdateServerPassword(int32 p1)
1395 static bool UpdateRconPassword(int32 p1)
1404 static bool UpdateClientConfigValues(int32 p1)
1418 memset(_old_diff_custom, 0,
sizeof(_old_diff_custom));
1433 bool old_diff_custom_used =
false;
1434 for (uint i = 0; i < options_to_load && !old_diff_custom_used; i++) {
1435 old_diff_custom_used = (_old_diff_custom[i] != 0);
1438 if (!old_diff_custom_used)
return;
1441 for (uint i = 0; i < options_to_load; i++) {
1450 static void AILoadConfig(
IniFile *ini,
const char *grpname)
1461 if (group ==
nullptr)
return;
1464 for (item = group->
item; c < MAX_COMPANIES && item != nullptr; c++, item = item->next) {
1469 if (item->
name !=
"none") {
1470 DEBUG(script, 0,
"The AI by the name '%s' was no longer found, and removed from the list.", item->
name.c_str());
1478 static void GameLoadConfig(
IniFile *ini,
const char *grpname)
1487 if (group ==
nullptr)
return;
1490 if (item ==
nullptr)
return;
1496 if (item->
name !=
"none") {
1497 DEBUG(script, 0,
"The GameScript by the name '%s' was no longer found, and removed from the list.", item->
name.c_str());
1511 if (c >=
'0' && c <=
'9')
return c -
'0';
1512 if (c >=
'A' && c <=
'F')
return c + 10 -
'A';
1513 if (c >=
'a' && c <=
'f')
return c + 10 -
'a';
1527 while (dest_size > 0) {
1530 if (lo < 0)
return false;
1531 *dest++ = (hi << 4) | lo;
1551 if (group ==
nullptr)
return nullptr;
1553 for (item = group->
item; item !=
nullptr; item = item->
next) {
1556 uint8 grfid_buf[4], md5sum[16];
1557 const char *filename = item->
name.c_str();
1558 bool has_grfid =
false;
1559 bool has_md5sum =
false;
1564 filename += 1 + 2 *
lengthof(grfid_buf);
1566 if (has_md5sum) filename += 1 + 2 *
lengthof(md5sum);
1568 uint32 grfid = grfid_buf[0] | (grfid_buf[1] << 8) | (grfid_buf[2] << 16) | (grfid_buf[3] << 24);
1571 if (s !=
nullptr) c =
new GRFConfig(*s);
1575 if (s !=
nullptr) c =
new GRFConfig(*s);
1578 if (c ==
nullptr) c =
new GRFConfig(filename);
1581 if (item->
value.has_value() && !item->
value->empty()) {
1594 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
1596 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNSAFE);
1598 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_SYSTEM);
1600 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
1602 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
1612 bool duplicate =
false;
1613 for (
const GRFConfig *gc = first; gc !=
nullptr; gc = gc->
next) {
1638 static void AISaveConfig(
IniFile *ini,
const char *grpname)
1642 if (group ==
nullptr)
return;
1662 static void GameSaveConfig(
IniFile *ini,
const char *grpname)
1666 if (group ==
nullptr)
return;
1693 seprintf(version,
lastof(version),
"%08X", _openttd_newgrf_version);
1695 const char *
const versions[][2] = {
1696 {
"version_string", _openttd_revision },
1697 {
"version_number", version }
1700 for (uint i = 0; i <
lengthof(versions); i++) {
1706 static void GRFSaveConfig(
IniFile *ini,
const char *grpname,
const GRFConfig *list)
1712 for (c = list; c !=
nullptr; c = c->
next) {
1714 char key[4 * 2 + 1 + 16 * 2 + 1 + MAX_PATH];
1726 static void HandleSettingDescs(
IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list,
bool only_startup =
false)
1728 proc(ini, (
const SettingDesc*)_misc_settings,
"misc",
nullptr, only_startup);
1729 #if defined(_WIN32) && !defined(DEDICATED)
1730 proc(ini, (
const SettingDesc*)_win32_settings,
"win32",
nullptr, only_startup);
1734 proc(ini, _currency_settings,
"currency", &_custom_currency, only_startup);
1737 if (!only_startup) {
1744 static IniFile *IniLoadConfig()
1757 IniFile *ini = IniLoadConfig();
1766 AILoadConfig(ini,
"ai_players");
1767 GameLoadConfig(ini,
"game_scripts");
1787 IniFile *ini = IniLoadConfig();
1797 AISaveConfig(ini,
"ai_players");
1798 GameSaveConfig(ini,
"game_scripts");
1812 std::unique_ptr<IniFile> ini(IniLoadConfig());
1813 for (
IniGroup *group = ini->group; group !=
nullptr; group = group->
next) {
1814 if (group->
name.compare(0, 7,
"preset-") == 0) {
1815 list.push_back(group->
name.substr(7));
1830 size_t len = strlen(config_name) + 8;
1831 char *section = (
char*)alloca(len);
1832 seprintf(section, section + len - 1,
"preset-%s", config_name);
1834 IniFile *ini = IniLoadConfig();
1849 size_t len = strlen(config_name) + 8;
1850 char *section = (
char*)alloca(len);
1851 seprintf(section, section + len - 1,
"preset-%s", config_name);
1853 IniFile *ini = IniLoadConfig();
1854 GRFSaveConfig(ini, section, config);
1865 size_t len = strlen(config_name) + 8;
1866 char *section = (
char*)alloca(len);
1867 seprintf(section, section + len - 1,
"preset-%s", config_name);
1869 IniFile *ini = IniLoadConfig();
1875 const SettingDesc *GetSettingDescription(uint index)
1877 if (index >=
lengthof(_settings))
return nullptr;
1878 return &_settings[index];
1894 const SettingDesc *sd = GetSettingDescription(p1);
1905 int32 newval = (int32)p2;
1950 int32 newval = (int32)p2;
1986 if (_game_mode != GM_MENU) {
1998 if (force_newgame) {
2021 const SettingDesc *sd = &_company_settings[index];
2038 for (sd = _company_settings; sd->
save.
cmd != SL_END; sd++) {
2051 for (sd = _company_settings; sd->
save.
cmd != SL_END; sd++, i++) {
2089 *var = strcmp(value,
"(null)") == 0 ? nullptr :
stredup(value);
2112 for (*i = 0, sd = _settings; sd->
save.
cmd != SL_END; sd++, (*i)++) {
2114 if (strcmp(sd->
desc.
name, name) == 0)
return sd;
2118 for (*i = 0, sd = _settings; sd->
save.
cmd != SL_END; sd++, (*i)++) {
2120 const char *short_name = strchr(sd->
desc.
name,
'.');
2121 if (short_name !=
nullptr) {
2123 if (strcmp(short_name, name) == 0)
return sd;
2127 if (strncmp(name,
"company.", 8) == 0) name += 8;
2129 for (*i = 0, sd = _company_settings; sd->
save.
cmd != SL_END; sd++, (*i)++) {
2131 if (strcmp(sd->
desc.
name, name) == 0)
return sd;
2139 void IConsoleSetSetting(
const char *name,
const char *value,
bool force_newgame)
2144 if (sd ==
nullptr) {
2166 IConsoleError(
"This command/variable is not available during network games.");
2168 IConsoleError(
"This command/variable is only available to a network server.");
2173 void IConsoleSetSetting(
const char *name,
int value)
2178 assert(sd !=
nullptr);
2194 if (sd ==
nullptr) {
2205 seprintf(value,
lastof(value), (*(
const bool*)ptr != 0) ?
"on" :
"off");
2226 if (prefilter !=
nullptr && strstr(sd->
desc.
name, prefilter) ==
nullptr)
continue;
2231 seprintf(value,
lastof(value), (*(
const bool *)ptr != 0) ?
"on" :
"off");
2251 for (; osd->
save.
cmd != SL_END; osd++) {
2255 if (!SlObjectMember(ptr, sld))
continue;
2272 for (i = sd; i->
save.
cmd != SL_END; i++) {
2273 length += SlCalcObjMemberLength(
object, &i->
save);
2277 for (i = sd; i->
save.
cmd != SL_END; i++) {
2279 SlObjectMember(ptr, &i->
save);
2283 static void Load_OPTS()
2293 static void Load_PATS()
2301 static void Check_PATS()
2306 static void Save_PATS()
2311 extern const ChunkHandler _setting_chunk_handlers[] = {
2312 {
'OPTS',
nullptr, Load_OPTS,
nullptr,
nullptr, CH_RIFF},
2313 {
'PATS', Save_PATS, Load_PATS,
nullptr, Check_PATS, CH_RIFF |
CH_LAST},
2316 static bool IsSignedVarMemType(VarType vt)
@ VEH_AIRCRAFT
Aircraft vehicle type.
void StringToSettings(const char *value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
void RemoveGroup(const char *name)
Remove the group with the given name.
void LoadStringWidthTable(bool monospace)
Initialize _stringwidth_table cache.
void ShowFirstError()
Show the first error of the queue.
Buses, trucks and trams belong to this class.
@ WC_SAVELOAD
Saveload window; Window numbers:
char rcon_password[NETWORK_PASSWORD_LENGTH]
password for rconsole (server side)
std::list< ErrorMessageData > ErrorList
Define a queue with errors.
SaveLoadVersion version_to
save/load the variable until this savegame version
void BuildOwnerLegend()
Completes the array for the owned property legend.
uint32 TileIndex
The index/ID of a Tile.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
@ SDT_STRING
string with a pre-allocated buffer
All settings that are only important for the local client.
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
void ReInitAllWindows()
Re-initialize all windows.
static Titem * Get(size_t index)
Returns Titem with given index.
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
void SettingsToString(char *string, const char *last) const
Convert the custom settings to a string that can be stored in the config file or savegames.
@ SLF_NOT_IN_SAVE
do not save with savegame, basically client-based
uint16 GetServiceIntervalClamped(uint interval, bool ispercent)
Clamp the service interval to the correct min/max.
@ 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.
static bool InvalidateCompanyWindow(int32 p1)
Invalidate the company details window after the shares setting changed.
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.
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
IniItem * next
The next item in this group.
static const char *const _list_group_names[]
Groups in openttd.cfg that are actually lists.
static bool TrainSlopeSteepnessChanged(int32 p1)
This function updates the train acceleration cache after a steepness change.
static void SaveSettings(const SettingDesc *sd, void *object)
Save and load handler for settings.
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.
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
Minimum percentage a user can specify for custom sea level.
@ WC_COMPANY_COLOUR
Company colour selection; Window numbers:
@ WC_FOUND_TOWN
Found a town; Window numbers:
@ SGF_PER_COMPANY
this setting can be different for each company (saved in company struct)
uint8 num_params
Number of used parameters.
bool _network_server
network-server is active
A single "line" in an ini file.
@ WC_ENGINE_PREVIEW
Engine preview window; Window numbers:
SaveLoad save
Internal structure (going to savegame, parts to config)
SettingType GetType() const
Return the type of the setting.
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
void SaveToConfig()
Save the values to the configuration file.
static const void * StringToVal(const SettingDescBase *desc, const char *orig_str)
Convert a string representation (external) of a setting to the internal rep.
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
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.
static bool RedrawSmallmap(int32 p1)
Redraw the smallmap after a colour scheme change.
A group within an ini file.
@ SDT_BOOLX
a boolean number
@ 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.
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.
@ SLE_VAR_STRBQ
string enclosed in quotes (with pre-allocated buffer)
VehicleDefaultSettings vehicle
default settings for vehicles
@ SGF_NEWGAME_ONLY
this setting cannot be changed in a game
@ SLE_VAR_NULL
useful to write zeros in savegame.
@ CH_LAST
Last chunk in this array.
void NetworkUpdateClientName()
Send the server our name.
@ WC_BUILD_INDUSTRY
Build industry; Window numbers:
@ 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.
GRFStatus status
NOSAVE: GRFStatus, enum.
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
const char * many
ONE/MANY_OF_MANY: string of possible values for this type.
@ WC_COMPANY
Company view; Window numbers:
@ WC_BUILD_STATION
Build station; Window numbers:
@ SDT_NUMX
any number-type
@ VEH_ROAD
Road vehicle type.
Handlers and description of chunk.
VarType conv
type of the variable to be saved, int
ZoomLevel _gui_zoom
GUI Zoom level.
uint16 servint_ships
service interval for ships
@ SLF_NO_NETWORK_SYNC
do not synchronize over network (but it is saved if SLF_NOT_IN_SAVE is not set)
Owner
Enum for all companies/owners.
@ DC_EXEC
execute the given command
void IniSaveWindowSettings(IniFile *ini, const char *grpname, void *desc)
Save a WindowDesc to config.
@ SLF_HEX
print numbers as hex in the config file (only useful for unsigned)
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
DoCommandFlag
List of flags for a command.
void SlSetLength(size_t length)
Sets the length of either a RIFF object or the number of items in an array.
static const TextColour CC_DEFAULT
Default colour of the console.
bool startup
setting has to be loaded directly at startup?
uint32 grfid
GRF ID (defined by Action 0x08)
void Clear()
Clear all items in the group.
@ SDT_STDSTRING
std::string
static uint TileX(TileIndex tile)
Get the X component of a tile.
static void Write_ValidateSetting(void *ptr, const SettingDesc *sd, int32 val)
Set the value of a setting and if needed clamp the value to the preset minimum and maximum.
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.
void UpdateCursorSize()
Update cursor dimension.
static GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
static uint MapSizeX()
Get the size of the map along the X.
char * GRFBuildParamList(char *dst, const GRFConfig *c, const char *last)
Build a string containing space separated parameter values, and terminate.
static void LoadSettings(const SettingDesc *osd, void *object)
Save and load handler for settings.
@ SLE_VAR_STRB
string (with pre-allocated buffer)
static bool IsNumericType(VarType conv)
Check if the given saveload type is a numeric type.
@ COMPANY_FIRST
First company, same as owner.
SettingType
Type of settings for filtering.
int PositionStatusbar(Window *w)
(Re)position statusbar window at the screen.
bool RoadVehiclesAreBuilt()
Verify whether a road vehicle is available.
SettingDescType cmd
various flags for the variable
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 UpdateAllTownVirtCoords()
Update the virtual coords needed to draw the town sign for all towns.
StringList GetGRFPresetList()
Get the list of known NewGrf presets.
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
bool station_noise_level
build new airports when the town noise level is still within accepted limits
static uint MapSize()
Get the size of the map.
char server_password[NETWORK_PASSWORD_LENGTH]
password for joining this server
Common return value for all commands.
Properties of config file settings.
static bool InvalidateCompanyInfrastructureWindow(int32 p1)
Invalidate the company infrastructure details window after a infrastructure maintenance setting chang...
static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList &list)
Saves all items from a list into the 'grpname' section The list parameter can be a nullptr pointer,...
static void MakeIntList(char *buf, const char *last, const void *array, int nelems, VarType type)
Convert an integer-array (intlist) to a string representation.
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
@ 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.
@ WC_TOWN_AUTHORITY
Town authority; Window numbers:
void GfxClearSpriteCache()
Remove all encoded sprites from the sprite cache without discarding sprite location information.
@ SGF_NETWORK_ONLY
this setting only applies to network games
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
@ GCF_SYSTEM
GRF file is an openttd-internal system grf.
#define DEBUG(name, level,...)
Output a line of debugging information.
static void PrepareOldDiffCustom()
Prepare for reading and old diff_custom by zero-ing the memory.
std::optional< std::string > value
The value of this item.
uint8 flags
NOSAVE: GCF_Flags, bitset.
@ SDT_MANYOFMANY
bitmasked number where MULTIPLE bits may be set
const char * GetName() const
Get the name of the Script.
uint GetCompanySettingIndex(const char *name)
Get the index in the _company_settings array of a setting.
void UpdateAirportsNoise()
Recalculate the noise generated by the airports of each town.
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.
void IConsoleError(const char *string)
It is possible to print error information to the console.
static void MakeVoid(TileIndex t)
Make a nice void tile ;)
@ SDT_ONEOFMANY
bitmasked number where only ONE bit may be set
static bool v_PositionStatusbar(int32 p1)
Reposition the statusbar as the setting changed.
SaveLoadType cmd
the action to take with the saved/loaded type, All types need different action
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void GamelogStartAction(GamelogActionType at)
Stores information about new action, but doesn't allocate it Action is allocated only when there is a...
bool GetArgumentInteger(uint32 *value, const char *arg)
Change a string into its number representation.
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
EconomySettings economy
settings to change the economy
@ 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.
const void * def
default value given when none is present
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
'Train' is either a loco or a wagon.
static void HandleOldDiffCustom(bool savegame)
Reading of the old diff_custom array and transforming it to the new format.
void SetCompanySetting(uint index, int32 value)
Top function to save the new value of an element of the Settings struct.
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.
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
All settings together for the game.
const SettingDesc * GetSettingFromName(const char *name, uint *i)
Given a name of setting, return a setting description of it.
bool _networking
are we in networking mode?
static bool InvalidateNewGRFChangeWindows(int32 p1)
Update any possible saveload window and delete any newgrf dialogue as its widget parts might change.
void DeleteGRFPresetFromConfig(const char *config_name)
Delete a NewGRF configuration by preset name.
The data of the error message.
Default settings for vehicles.
TownFounding found_town
town founding.
static uint MapSizeY()
Get the size of the map along the Y.
void ResetCurrencies(bool preserve_custom)
Will fill _currency_specs array with default values from origin_currency_specs Called only from newgr...
@ SDT_INTLIST
list of integers separated by a comma ','
static size_t LookupOneOfMany(const char *many, const char *one, size_t onelen=0)
Find the index value of a ONEofMANY type in a string separated by |.
VehicleType
Available vehicle types.
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
static bool RedrawTownAuthority(int32 p1)
Update the town authority window after a town authority setting change.
static void SetTileHeight(TileIndex tile, uint height)
Sets the height of a tile.
static void MakeOneOfMany(char *buf, const char *last, const char *many, int id)
Convert a ONEofMANY structure to a string representation.
GRFConfig * _grfconfig_static
First item in list of static GRF set up.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
void GamelogSetting(const char *name, int32 oldval, int32 newval)
Logs change in game settings.
void GamelogStopAction()
Stops logging of any changes.
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.
SettingGuiFlag flags
handles how a setting would show up in the GUI (text/currency, etc.)
void WriteValue(void *ptr, VarType conv, int64 val)
Write the value of a setting.
ZoomLevel zoom_min
minimum zoom out level
static size_t LookupManyOfMany(const char *many, const char *str)
Find the set-integer value MANYofMANY type in a string.
All ships have this type.
@ SGF_MULTISTRING
the value represents a limited number of string-options (internally integer)
CompanyID _current_company
Company currently doing an action.
static bool CheckRoadSide(int p1)
Check whether the road side may be changed.
@ SGF_0ISDISABLED
a value of zero means the feature is disabled
@ WC_GAME_OPTIONS
Game options window; Window numbers:
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
void IConsoleListSettings(const char *prefilter)
List all settings and their value to the console.
static size_t ConvertLandscape(const char *value)
Conversion callback for _gameopt_settings_game.landscape It converts (or try) between old values and ...
bool FioCheckFileExists(const std::string &filename, Subdirectory subdir)
Check whether the given file exists.
std::string name
name of group
Ini file that supports both loading and saving.
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
void NetworkServerSendConfigUpdate()
Send Config Update.
uint16 servint_trains
service interval for trains
@ SGF_NO_NETWORK
this setting does not apply to network games; it may not be changed during the game
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
@ GLAT_SETTING
Setting changed.
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company)
Prepare a DoCommand to be send over the network.
byte land_generator
the landscape generator
@ NO_DIRECTORY
A path without any base directory.
static VarType GetVarMemType(VarType type)
Get the NumberType of a setting.
static void MakeManyOfMany(char *buf, const char *last, const char *many, uint32 x)
Convert a MANYofMANY structure to a string representation.
int CompanyServiceInterval(const Company *c, VehicleType type)
Get the service interval for the given company and vehicle type.
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
struct GRFConfig * next
NOSAVE: Next item in the linked list.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
@ WC_AI_SETTINGS
AI settings; Window numbers:
void ScheduleErrorMessage(const ErrorMessageData &data)
Schedule an error.
static void SaveVersionInConfig(IniFile *ini)
Save the version of OpenTTD to the ini file.
static int DecodeHexNibble(char c)
Convert a character to a hex nibble value, or -1 otherwise.
@ SSS_FORCE_NEWGAME
Get the newgame Script config.
@ WC_COMPANY_INFRASTRUCTURE
Company infrastructure overview; Window numbers:
uint16 servint_aircraft
service interval for aircraft
@ FGCM_NEWEST_VALID
Find newest Grf, ignoring Grfs with GCF_INVALID set.
static bool ChangeDynamicEngines(int32 p1)
Changing the setting "allow multiple NewGRF sets" is not allowed if there are vehicles.
@ SLF_NOT_IN_CONFIG
do not save to config file
static bool RoadVehSlopeSteepnessChanged(int32 p1)
This function updates the road vehicle acceleration cache after a steepness change.
SettingDescBase desc
Settings structure (going to configuration file)
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
SaveLoadVersion version_from
save/load the variable starting from this savegame version
void SetValue(const char *value)
Replace the current value with another value.
Base class for all station-ish types.
static const TextColour CC_ERROR
Colour for error lines.
@ WL_ERROR
Errors (eg. saving/loading failed)
@ SLE_VAR_STRQ
string pointer enclosed in quotes
static Pool::IterateWrapper< Train > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change one of the per-company settings.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
void IConsoleGetSetting(const char *name, bool force_newgame)
Output value of a specific setting to the console.
bool servint_ispercent
service intervals are in percents
std::string name
The name of this item.
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.
StringList _network_ban_list
The banned clients.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
NetworkSettings network
settings related to the network
static bool v_PositionMainToolbar(int32 p1)
Reposition the main toolbar as the setting changed.
@ CMD_CHANGE_SETTING
change a setting
IniItem * item
the first item in the group
CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Network-safe changing of settings (server-only).
uint16 servint_roadveh
service interval for road vehicles
const char * name
name of the setting. Used in configuration file and for console
OnChange * proc
callback procedure for when the value is changed
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.
@ WC_TOWN_VIEW
Town view; Window numbers:
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
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
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,...
@ CCF_TRACK
Valid changes while vehicle is driving, and possibly changing tracks.
VehicleSettings vehicle
options for vehicles
@ WC_BUILD_SIGNAL
Build signal toolbar; Window numbers:
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
bool SetSettingValue(uint index, int32 value, bool force_newgame)
Top function to save the new value of an element of the Settings struct.
@ VEH_TRAIN
Train vehicle type.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
OnConvert * proc_cnvt
callback procedure when loading value mechanism fails
@ 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.
static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object, bool)
Save the values of settings to the inifile.
StringList _network_host_list
The servers we know.
char * filename
Filename - either with or without full path.
@ VIWD_MODIFY_ORDERS
Other order modifications.
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 TextColour CC_WARNING
Colour for warning lines.
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
Value for custom sea level in difficulty settings.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
@ SLV_4
4.0 1 4.1 122 0.3.3, 0.3.4 4.2 1222 0.3.5 4.3 1417 4.4 1426
void LoadFromDisk(const std::string &filename, Subdirectory subdir)
Load the Ini file's data from the disk.
@ VEH_SHIP
Ship vehicle type.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object, bool only_startup)
Load values from a group of an IniFile structure into the internal representation.
@ SGF_SCENEDIT_TOO
this setting can be changed in the scenario editor (only makes sense when SGF_NEWGAME_ONLY is set)
bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir)
Find the GRFID of a given grf, and calculate its md5sum.
static void * GetVariableAddress(const void *object, const SaveLoad *sld)
Get the address of the variable.
#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.
CompanySettings settings
settings specific for each company
@ CMD_CHANGE_COMPANY_SETTING
change a company setting
void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
Save a NewGRF configuration with a preset name.
@ WC_SMALLMAP
Small map; Window numbers:
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
void CDECL IConsolePrintF(TextColour colour_code, const char *format,...)
Handle the printing of text entered into the console or redirected there by any other means.
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).
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
@ GCF_STATIC
GRF file is used statically (can be used in any MP game)
GUISettings gui
settings related to the GUI
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
@ SGF_SCENEDIT_ONLY
this setting can only be changed in the scenario editor
uint32 param[0x80]
GRF parameters.
static bool RoadVehAccelerationModelChanged(int32 p1)
This function updates realistic acceleration caches when the setting "Road vehicle acceleration model...
GRFConfig * _grfconfig_newgame
First item in list of default GRF set up.
static GRFConfig * GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static)
Load a GRF configuration.
void BuildLandLegend()
(Re)build the colour tables for the legends.
IniGroup * GetGroup(const std::string &name, bool create_new=true)
Get the group with the given name.
IniGroup * next
the next group within this file
void IniLoadWindowSettings(IniFile *ini, const char *grpname, void *desc)
Load a WindowDesc from config.