71 #include "table/strings.h" 72 #include "table/settings.h" 82 typedef std::list<ErrorMessageData>
ErrorList;
86 typedef void SettingDescProc(
IniFile *ini,
const SettingDesc *desc,
const char *grpname,
void *
object);
87 typedef void SettingDescProcList(
IniFile *ini,
const char *grpname,
StringList *list);
89 static bool IsSignedVarMemType(VarType vt);
98 "server_bind_addresses",
114 if (onelen == 0) onelen = strlen(one);
117 if (*one >=
'0' && *one <=
'9')
return strtoul(one, NULL, 0);
123 while (*s !=
'|' && *s != 0) s++;
124 if ((
size_t)(s - many) == onelen && !memcmp(one, many, onelen))
return idx;
125 if (*s == 0)
return (
size_t)-1;
146 while (*str ==
' ' || *str ==
'\t' || *str ==
'|') str++;
147 if (*str == 0)
break;
150 while (*s != 0 && *s !=
' ' && *s !=
'\t' && *s !=
'|') s++;
153 if (r == (
size_t)-1)
return r;
179 if (!comma)
return -1;
188 if (n == maxitems)
return -1;
190 long v = strtol(p, &end, 0);
191 if (p == end)
return -1;
192 if (
sizeof(
int) <
sizeof(
long)) v =
ClampToI32(v);
203 if (n != 0 && !comma)
return -1;
216 static bool LoadIntList(
const char *str,
void *array,
int nelems, VarType type)
222 memset(items, 0,
sizeof(items));
226 if (nitems != nelems)
return false;
233 for (i = 0; i != nitems; i++) ((byte*)array)[i] = items[i];
238 for (i = 0; i != nitems; i++) ((uint16*)array)[i] = items[i];
243 for (i = 0; i != nitems; i++) ((uint32*)array)[i] = items[i];
246 default: NOT_REACHED();
261 static void MakeIntList(
char *buf,
const char *last,
const void *array,
int nelems, VarType type)
264 const byte *p = (
const byte *)array;
266 for (i = 0; i != nelems; i++) {
269 case SLE_VAR_I8: v = *(
const int8 *)p; p += 1;
break;
270 case SLE_VAR_U8: v = *(
const uint8 *)p; p += 1;
break;
271 case SLE_VAR_I16: v = *(
const int16 *)p; p += 2;
break;
272 case SLE_VAR_U16: v = *(
const uint16 *)p; p += 2;
break;
273 case SLE_VAR_I32: v = *(
const int32 *)p; p += 4;
break;
274 case SLE_VAR_U32: v = *(
const uint32 *)p; p += 4;
break;
275 default: NOT_REACHED();
277 buf +=
seprintf(buf, last, (i == 0) ?
"%d" :
",%d", v);
288 static void MakeOneOfMany(
char *buf,
const char *last,
const char *many,
int id)
294 for (; *many !=
'|'; many++) {
304 while (*many !=
'\0' && *many !=
'|' && buf < last) *buf++ = *many++;
316 static void MakeManyOfMany(
char *buf,
const char *last,
const char *many, uint32 x)
322 for (; x != 0; x >>= 1, i++) {
324 while (*many != 0 && *many !=
'|') many++;
327 if (!init) buf +=
seprintf(buf, last,
"|");
330 buf +=
seprintf(buf, last,
"%d", i);
332 memcpy(buf, start, many - start);
337 if (*many ==
'|') many++;
351 const char *str = orig_str == NULL ?
"" : orig_str;
356 size_t val = strtoul(str, &end, 0);
365 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS);
377 if (r != (
size_t)-1)
return (
void*)r;
388 if (r != (
size_t)-1)
return (
void*)r;
397 if (strcmp(str,
"true") == 0 || strcmp(str,
"on") == 0 || strcmp(str,
"1") == 0)
return (
void*)
true;
398 if (strcmp(str,
"false") == 0 || strcmp(str,
"off") == 0 || strcmp(str,
"0") == 0)
return (
void*)
false;
462 default: NOT_REACHED();
486 for (; sd->
save.
cmd != SL_END; sd++) {
493 s = strchr(sdb->
name,
'.');
502 item = group->
GetItem(s,
false);
503 if (item == NULL && group != group_def) {
506 item = group_def->
GetItem(s,
false);
511 const char *sc = strchr(s,
'.');
512 if (sc != NULL) item = ini->
GetGroup(s, sc - s)->
GetItem(sc + 1,
false);
530 if (p != NULL)
strecpy((
char*)ptr, (
const char*)p, (
char*)ptr + sld->
length - 1);
536 *(
char**)ptr = p == NULL ? NULL :
stredup((
const char*)p);
539 case SLE_VAR_CHAR:
if (p != NULL) *(
char *)ptr = *(
const char *)p;
break;
541 default: NOT_REACHED();
558 default: NOT_REACHED();
583 for (; sd->
save.
cmd != SL_END; sd++) {
593 s = strchr(sdb->
name,
'.');
598 if (group_def == NULL) group_def = ini->
GetGroup(grpname);
603 item = group->GetItem(s,
true);
606 if (item->
value != NULL) {
619 if (*(
bool*)ptr == (p != NULL))
continue;
624 if (*(byte*)ptr == (byte)(
size_t)p)
continue;
629 if (*(uint16*)ptr == (uint16)(
size_t)p)
continue;
634 if (*(uint32*)ptr == (uint32)(
size_t)p)
continue;
637 default: NOT_REACHED();
658 default: NOT_REACHED();
670 if (*(
char**)ptr == NULL) {
677 case SLE_VAR_CHAR: buf[0] = *(
char*)ptr; buf[1] =
'\0';
break;
678 default: NOT_REACHED();
686 default: NOT_REACHED();
708 if (group == NULL || list == NULL)
return;
712 for (
const IniItem *item = group->
item; item != NULL; item = item->
next) {
713 if (item->name != NULL) *list->
Append() =
stredup(item->name);
730 if (group == NULL || list == NULL)
return;
733 for (
char **iter = list->
Begin(); iter != list->
End(); iter++) {
771 (_game_mode == GM_NORMAL ||
772 (_game_mode == GM_EDITOR && !(this->desc.flags &
SGF_SCENEDIT_TOO))))
return false;
798 if (_game_mode != GM_MENU) {
806 static bool PopulationInLabelActive(int32 p1)
812 static bool RedrawScreen(int32 p1)
831 static bool InvalidateDetailsWindow(int32 p1)
837 static bool StationSpreadChanged(int32 p1)
844 static bool InvalidateBuildIndustryWindow(int32 p1)
850 static bool CloseSignalGUI(int32 p1)
858 static bool InvalidateTownViewWindow(int32 p1)
864 static bool DeleteSelectStationWindow(int32 p1)
870 static bool UpdateConsists(int32 p1)
882 static bool CheckInterval(int32 p1)
884 bool update_vehicles;
888 update_vehicles =
false;
891 update_vehicles =
true;
906 if (update_vehicles) {
912 v->SetServiceIntervalIsPercent(p1 != 0);
917 InvalidateDetailsWindow(0);
922 static bool UpdateInterval(
VehicleType type, int32 p1)
924 bool update_vehicles;
928 update_vehicles =
false;
931 update_vehicles =
true;
936 if (interval != p1)
return false;
938 if (update_vehicles) {
942 v->SetServiceInterval(p1);
947 InvalidateDetailsWindow(0);
952 static bool UpdateIntervalTrains(int32 p1)
957 static bool UpdateIntervalRoadVeh(int32 p1)
959 return UpdateInterval(
VEH_ROAD, p1);
962 static bool UpdateIntervalShips(int32 p1)
964 return UpdateInterval(
VEH_SHIP, p1);
967 static bool UpdateIntervalAircraft(int32 p1)
972 static bool TrainAccelerationModelChanged(int32 p1)
1014 FOR_ALL_ROADVEHICLES(rv) {
1037 FOR_ALL_ROADVEHICLES(rv) {
1044 static bool DragSignalsDensityChanged(int32)
1051 static bool TownFoundingChanged(int32 p1)
1061 static bool InvalidateVehTimetableWindow(int32 p1)
1067 static bool ZoomMinMaxChanged(int32 p1)
1069 extern void ConstrainAllViewportsZoom();
1070 ConstrainAllViewportsZoom();
1096 static bool InvalidateCompanyLiveryWindow(int32 p1)
1099 return RedrawScreen(p1);
1102 static bool InvalidateIndustryViewWindow(int32 p1)
1108 static bool InvalidateAISettingsWindow(int32 p1)
1157 static bool DifficultyNoiseChange(int32 i)
1159 if (_game_mode == GM_NORMAL) {
1169 static bool MaxNoAIsChange(int32 i)
1204 static bool CheckFreeformEdges(int32 p1)
1206 if (_game_mode == GM_MENU)
return true;
1217 FOR_ALL_BASE_STATIONS(st) {
1227 for (uint i = 0; i <
MapMaxX(); i++) {
1233 for (uint i = 1; i <
MapMaxX(); i++) {
1239 for (uint i = 0; i <
MapMaxY(); i++) {
1245 for (uint i = 1; i <
MapMaxY(); i++) {
1252 for (uint i = 0; i <
MapMaxX(); i++) {
1256 for (uint i = 0; i <
MapMaxY(); i++) {
1271 if (_game_mode == GM_MENU)
return true;
1281 static bool ChangeMaxHeightLevel(int32 p1)
1283 if (_game_mode == GM_NORMAL)
return false;
1284 if (_game_mode != GM_EDITOR)
return true;
1302 static bool StationCatchmentChanged(int32 p1)
1308 static bool MaxVehiclesChanged(int32 p1)
1316 #ifdef ENABLE_NETWORK 1318 static bool UpdateClientName(int32 p1)
1324 static bool UpdateServerPassword(int32 p1)
1333 static bool UpdateRconPassword(int32 p1)
1342 static bool UpdateClientConfigValues(int32 p1)
1359 memset(_old_diff_custom, 0,
sizeof(_old_diff_custom));
1374 bool old_diff_custom_used =
false;
1375 for (uint i = 0; i < options_to_load && !old_diff_custom_used; i++) {
1376 old_diff_custom_used = (_old_diff_custom[i] != 0);
1379 if (!old_diff_custom_used)
return;
1382 for (uint i = 0; i < options_to_load; i++) {
1391 static void AILoadConfig(
IniFile *ini,
const char *grpname)
1402 if (group == NULL)
return;
1405 for (item = group->
item; c < MAX_COMPANIES && item != NULL; c++, item = item->next) {
1410 if (strcmp(item->
name,
"none") != 0) {
1411 DEBUG(script, 0,
"The AI by the name '%s' was no longer found, and removed from the list.", item->
name);
1419 static void GameLoadConfig(
IniFile *ini,
const char *grpname)
1428 if (group == NULL)
return;
1431 if (item == NULL)
return;
1437 if (strcmp(item->
name,
"none") != 0) {
1438 DEBUG(script, 0,
"The GameScript by the name '%s' was no longer found, and removed from the list.", item->
name);
1452 if (c >=
'0' && c <=
'9')
return c -
'0';
1453 if (c >=
'A' && c <=
'F')
return c + 10 -
'A';
1454 if (c >=
'a' && c <=
'f')
return c + 10 -
'a';
1468 while (dest_size > 0) {
1471 if (lo < 0)
return false;
1472 *dest++ = (hi << 4) | lo;
1492 if (group == NULL)
return NULL;
1494 for (item = group->
item; item != NULL; item = item->
next) {
1497 uint8 grfid_buf[4], md5sum[16];
1498 char *filename = item->
name;
1499 bool has_grfid =
false;
1500 bool has_md5sum =
false;
1505 filename += 1 + 2 *
lengthof(grfid_buf);
1507 if (has_md5sum) filename += 1 + 2 *
lengthof(md5sum);
1509 uint32 grfid = grfid_buf[0] | (grfid_buf[1] << 8) | (grfid_buf[2] << 16) | (grfid_buf[3] << 24);
1519 if (c == NULL) c =
new GRFConfig(filename);
1535 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
1537 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNSAFE);
1539 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_SYSTEM);
1541 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
1543 SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
1553 bool duplicate =
false;
1554 for (
const GRFConfig *gc = first; gc != NULL; gc = gc->
next) {
1579 static void AISaveConfig(
IniFile *ini,
const char *grpname)
1583 if (group == NULL)
return;
1603 static void GameSaveConfig(
IniFile *ini,
const char *grpname)
1607 if (group == NULL)
return;
1634 seprintf(version,
lastof(version),
"%08X", _openttd_newgrf_version);
1636 const char *
const versions[][2] = {
1637 {
"version_string", _openttd_revision },
1638 {
"version_number", version }
1641 for (uint i = 0; i <
lengthof(versions); i++) {
1647 static void GRFSaveConfig(
IniFile *ini,
const char *grpname,
const GRFConfig *list)
1653 for (c = list; c != NULL; c = c->
next) {
1655 char key[4 * 2 + 1 + 16 * 2 + 1 + MAX_PATH];
1667 static void HandleSettingDescs(
IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list,
bool basic_settings =
true,
bool other_settings =
true)
1669 if (basic_settings) {
1670 proc(ini, (
const SettingDesc*)_misc_settings,
"misc", NULL);
1671 #if defined(WIN32) && !defined(DEDICATED) 1672 proc(ini, (
const SettingDesc*)_win32_settings,
"win32", NULL);
1676 if (other_settings) {
1677 proc(ini, _settings,
"patches", &_settings_newgame);
1678 proc(ini, _currency_settings,
"currency", &_custom_currency);
1679 proc(ini, _company_settings,
"company", &_settings_client.
company);
1681 #ifdef ENABLE_NETWORK 1689 static IniFile *IniLoadConfig()
1702 IniFile *ini = IniLoadConfig();
1711 AILoadConfig(ini,
"ai_players");
1712 GameLoadConfig(ini,
"game_scripts");
1715 IniLoadSettings(ini, _gameopt_settings,
"gameopt", &_settings_newgame);
1732 IniFile *ini = IniLoadConfig();
1742 AISaveConfig(ini,
"ai_players");
1743 GameSaveConfig(ini,
"game_scripts");
1757 IniFile *ini = IniLoadConfig();
1759 for (group = ini->
group; group != NULL; group = group->
next) {
1760 if (strncmp(group->
name,
"preset-", 7) == 0) {
1776 size_t len = strlen(config_name) + 8;
1777 char *section = (
char*)alloca(len);
1778 seprintf(section, section + len - 1,
"preset-%s", config_name);
1780 IniFile *ini = IniLoadConfig();
1795 size_t len = strlen(config_name) + 8;
1796 char *section = (
char*)alloca(len);
1797 seprintf(section, section + len - 1,
"preset-%s", config_name);
1799 IniFile *ini = IniLoadConfig();
1800 GRFSaveConfig(ini, section, config);
1811 size_t len = strlen(config_name) + 8;
1812 char *section = (
char*)alloca(len);
1813 seprintf(section, section + len - 1,
"preset-%s", config_name);
1815 IniFile *ini = IniLoadConfig();
1821 const SettingDesc *GetSettingDescription(uint index)
1823 if (index >=
lengthof(_settings))
return NULL;
1824 return &_settings[index];
1840 const SettingDesc *sd = GetSettingDescription(p1);
1851 int32 newval = (int32)p2;
1894 int32 newval = (int32)p2;
1930 if (_game_mode != GM_MENU) {
1941 if (force_newgame) {
1962 const SettingDesc *sd = &_company_settings[index];
1979 for (sd = _company_settings; sd->
save.
cmd != SL_END; sd++) {
1985 #if defined(ENABLE_NETWORK) 1993 for (sd = _company_settings; sd->
save.
cmd != SL_END; sd++, i++) {
2031 *var = strcmp(value,
"(null)") == 0 ? NULL :
stredup(value);
2053 for (*i = 0, sd = _settings; sd->
save.
cmd != SL_END; sd++, (*i)++) {
2055 if (strcmp(sd->
desc.
name, name) == 0)
return sd;
2059 for (*i = 0, sd = _settings; sd->
save.
cmd != SL_END; sd++, (*i)++) {
2061 const char *short_name = strchr(sd->
desc.
name,
'.');
2062 if (short_name != NULL) {
2064 if (strcmp(short_name, name) == 0)
return sd;
2068 if (strncmp(name,
"company.", 8) == 0) name += 8;
2070 for (*i = 0, sd = _company_settings; sd->
save.
cmd != SL_END; sd++, (*i)++) {
2072 if (strcmp(sd->
desc.
name, name) == 0)
return sd;
2080 void IConsoleSetSetting(
const char *name,
const char *value,
bool force_newgame)
2107 IConsoleError(
"This command/variable is not available during network games.");
2109 IConsoleError(
"This command/variable is only available to a network server.");
2114 void IConsoleSetSetting(
const char *name,
int value)
2139 ptr =
GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->
save);
2145 seprintf(value,
lastof(value), (*(
const bool*)ptr != 0) ?
"on" :
"off");
2166 if (prefilter != NULL && strstr(sd->desc.name, prefilter) == NULL)
continue;
2171 seprintf(value,
lastof(value), (*(
const bool *)ptr != 0) ?
"on" :
"off");
2191 for (; osd->
save.
cmd != SL_END; osd++) {
2195 if (!SlObjectMember(ptr, sld))
continue;
2212 for (i = sd; i->
save.
cmd != SL_END; i++) {
2213 length += SlCalcObjMemberLength(
object, &i->
save);
2217 for (i = sd; i->
save.
cmd != SL_END; i++) {
2219 SlObjectMember(ptr, &i->
save);
2223 static void Load_OPTS()
2233 static void Load_PATS()
2241 static void Check_PATS()
2246 static void Save_PATS()
2263 extern const ChunkHandler _setting_chunk_handlers[] = {
2264 {
'OPTS', NULL, Load_OPTS, NULL, NULL, CH_RIFF},
2265 {
'PATS', Save_PATS, Load_PATS, NULL, Check_PATS, CH_RIFF |
CH_LAST},
2268 static bool IsSignedVarMemType(VarType vt)
Functions related to OTTD's strings.
VehicleSettings vehicle
options for vehicles
static void ValidateSettings()
Checks if any settings are set to incorrect values, and sets them to correct values in that case...
this setting can be changed in the scenario editor (only makes sense when SGF_NEWGAME_ONLY is set) ...
int CompanyServiceInterval(const Company *c, VehicleType type)
Get the service interval for the given company and vehicle type.
static uint MapSizeX()
Get the size of the map along the X.
A group within an ini file.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void IConsoleGetSetting(const char *name, bool force_newgame)
Output value of a specific setting to the console.
bool _networking
are we in networking mode?
const void * def
default value given when none is present
Base of all video drivers.
Default settings for vehicles.
uint GetCompanySettingIndex(const char *name)
Get the index in the _company_settings array of a setting.
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
Select station (when joining stations); Window numbers:
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.
static uint MapSizeY()
Get the size of the map along the Y.
static void MakeVoid(TileIndex t)
Make a nice void tile ;)
bitmasked number where MULTIPLE bits may be set
void ResetCurrencies(bool preserve_custom)
Will fill _currency_specs array with default values from origin_currency_specs Called only from newgr...
void SetDParamStr(uint n, const char *str)
Set a rawstring parameter.
static bool DecodeHexText(char *pos, uint8 *dest, size_t dest_size)
Parse a sequence of characters (supposedly hex digits) into a sequence of bytes.
void BuildOwnerLegend()
Completes the array for the owned property legend.
this setting can be different for each company (saved in company struct)
byte land_generator
the landscape generator
uint16 GetServiceIntervalClamped(uint interval, bool ispercent)
Clamp the service interval to the correct min/max.
Saveload window; Window numbers:
GameConfig stores the configuration settings of every Game.
static GRFConfig * GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static)
Load a GRF configuration.
TownFoundingByte found_town
town founding,
this setting cannot be changed in a game
EconomySettings economy
settings to change the economy
void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
Save a NewGRF configuration with a preset name.
GRFConfig * _grfconfig_newgame
First item in list of default GRF set up.
static void HandleOldDiffCustom(bool savegame)
Reading of the old diff_custom array and transforming it to the new format.
byte pf_maxdepth
maximum recursion depth when searching for a train route for new pathfinder
All settings together for the game.
static Titem * Get(size_t index)
Returns Titem with given index.
string (with pre-allocated buffer)
Functions to handle different currencies.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Base for the train class.
Other order modifications.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
General types related to pathfinders.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
SettingGuiFlag flags
handles how a setting would show up in the GUI (text/currency, etc.)
do not synchronize over network (but it is saved if SLF_NOT_IN_SAVE is not set)
Functions to be called to log possibly unsafe game events.
static bool InvalidateCompanyWindow(int32 p1)
Invalidate the company details window after the shares setting changed.
static void PrepareOldDiffCustom()
Prepare for reading and old diff_custom by zero-ing the memory.
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
Value for custom sea level in difficulty settings.
bool IsInUse() const
Check whether the base station currently is in use; in use means that it is not scheduled for deletio...
void GamelogStartAction(GamelogActionType at)
Stores information about new action, but doesn't allocate it Action is allocated only when there is a...
static void MakeManyOfMany(char *buf, const char *last, const char *many, uint32 x)
Convert a MANYofMANY structure to a string representation.
IniItem * item
the first item in the group
GRFConfig * LoadGRFPresetFromConfig(const char *config_name)
Load a NewGRF configuration by preset-name.
static bool ChangeDynamicEngines(int32 p1)
Changing the setting "allow multiple NewGRF sets" is not allowed if there are vehicles.
GRFStatus status
NOSAVE: GRFStatus, enum.
static bool RedrawTownAuthority(int32 p1)
Update the town authority window after a town authority setting change.
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
static bool InvalidateCompanyInfrastructureWindow(int32 p1)
Invalidate the company infrastructure details window after a infrastructure maintenance setting chang...
void IConsoleListSettings(const char *prefilter)
List all settings and their value to the console.
Base for all sound drivers.
list of integers separated by a comma ','
static uint TileX(TileIndex tile)
Get the X component of a tile.
PathfinderSettings pf
settings for all pathfinders
Build vehicle; Window numbers:
void UpdateAllTownVirtCoords()
Update the virtual coords needed to draw the town sign for all towns.
GRF file is used statically (can be used in any MP game)
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.
const T * Begin() const
Get the pointer to the first item (const)
DifficultySettings difficulty
settings related to the difficulty
void RemoveGroup(const char *name)
Remove the group with the given name.
Properties of config file settings.
do not save to config file
#define lastof(x)
Get the last element of an fixed size array.
ZoomLevelByte _gui_zoom
GUI Zoom level.
static const TextColour CC_DEFAULT
Default colour of the console.
IniGroup * GetGroup(const char *name, size_t len=0, bool create_new=true)
Get the group with the given name.
GRF file was not found in the local cache.
Functions related to world/map generation.
Stuff related to the text buffer GUI.
Functions to make screenshots.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version)
Find a NewGRF in the scanned list.
void CargoChanged()
Recalculates the cached weight of a vehicle and its parts.
Common return value for all commands.
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
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.
IniItem * next
The next item in this group.
CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Network-safe changing of settings (server-only).
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...
this setting only applies to network games
const char * name
name of the setting. Used in configuration file and for console
OnChange * proc
callback procedure for when the value is changed
CompanySettings settings
settings specific for each company
const T * End() const
Get the pointer behind the last valid item (const)
uint16 pf_maxlength
maximum length when searching for a train route for new pathfinder
struct GRFConfig * next
NOSAVE: Next item in the linked list.
A single "line" in an ini file.
const char * GetName() const
Get the name of the Script.
GRFConfig * _grfconfig_static
First item in list of static GRF set up.
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
uint16 servint_ships
service interval for ships
T * Append(uint to_add=1)
Append an item and return it.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
static bool RedrawSmallmap(int32 p1)
Redraw the smallmap after a colour scheme change.
static bool LoadIntList(const char *str, void *array, int nelems, VarType type)
Load parsed string-values into an integer-array (intlist)
static void SetTileHeight(TileIndex tile, uint height)
Sets the height of a tile.
bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir)
Find the GRFID of a given grf, and calculate its md5sum.
uint16 length
(conditional) length of the variable (eg. arrays) (max array size is 65536 elements) ...
Functions to read fonts from files and cache them.
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...
Buses, trucks and trams belong to this class.
int PositionStatusbar(Window *w)
(Re)position statusbar window at the screen.
Critical errors, the MessageBox is shown in all cases.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=NULL, uint textref_stack_size=0, const uint32 *textref_stack=NULL)
Display an error message in a window.
char * _config_file
Configuration file of OpenTTD.
void UpdateAirportsNoise()
Recalculate the noise generated by the airports of each town.
SaveLoad save
Internal structure (going to savegame, parts to config)
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
NetworkSettings network
settings related to the network
void GamelogSetting(const char *name, int32 oldval, int32 newval)
Logs change in game settings.
void SetDefaultCompanySettings(CompanyID cid)
Set the company settings for a new company to their default values.
Engine preview window; Window numbers:
uint8 num_params
Number of used parameters.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
VarType conv
type of the variable to be saved, int
IniGroup * group
the first group in the ini
static void SaveVersionInConfig(IniFile *ini)
Save the version of OpenTTD to the ini file.
Functions related to errors.
static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
Save the values of settings to the inifile.
Error message; Window numbers:
GRF file is an openttd-internal system grf.
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
CompanySettings company
default values for per-company settings
Information about GRF, used in the game and (part of it) in savegames.
do not save with savegame, basically client-based
void ConsistChanged(ConsistChangeFlags allowed_changes)
Recalculates the cached stuff of a train.
void IniLoadWindowSettings(IniFile *ini, const char *grpname, void *desc)
Load a WindowDesc from config.
VehicleDefaultSettings vehicle
default settings for vehicles
OnConvert * proc_cnvt
callback procedure when loading value mechanism fails
VehicleType
Available vehicle types.
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
Small map; Window numbers:
bool SaveToDisk(const char *filename)
Save the Ini file's data to the disk.
void SyncCompanySettings()
Sync all company settings in a multiplayer game.
DoCommandFlag
List of flags for a command.
this setting does not apply to network games; it may not be changed during the game ...
Functions related to setting/changing the settings.
char * GRFBuildParamList(char *dst, const GRFConfig *c, const char *last)
Build a string containing space separated parameter values, and terminate.
void SetValue(const char *value)
Replace the current value with another value.
ClientSettings _settings_client
The current settings for this game.
static const char *const _list_group_names[]
Groups in openttd.cfg that are actually lists.
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...
void LoadFromDisk(const char *filename, Subdirectory subdir)
Load the Ini file's data from the disk.
A path without any base directory.
Base for all music playback.
Definition of base types and functions in a cross-platform compatible way.
void LoadStringWidthTable(bool monospace)
Initialize _stringwidth_table cache.
static size_t LookupManyOfMany(const char *many, const char *str)
Find the set-integer value MANYofMANY type in a string.
A number of safeguards to prevent using unsafe methods.
void NetworkUpdateClientName()
Send the server our name.
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
First company, same as owner.
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
const SettingDesc * GetSettingFromName(const char *name, uint *i)
Given a name of setting, return a setting description of it.
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
uint8 flags
NOSAVE: GCF_Flags, bitset.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
void LoadFromConfig(bool minimal)
Load the values from the configuration files.
Console functions used outside of the console code.
GRF is unusable with this version of OpenTTD.
void ScheduleErrorMessage(const ErrorMessageData &data)
Schedule an error.
Company colour selection; Window numbers:
char * value
The value of this item.
bool IsFrontEngine() const
Check if the vehicle is a front engine.
TileIndex tile
Current tile index.
Find newest Grf, ignoring Grfs with GCF_INVALID set.
static ErrorList _settings_error_list
Errors while loading minimal settings.
static bool RoadVehSlopeSteepnessChanged(int32 p1)
This function updates the road vehicle acceleration cache after a steepness change.
Vehicle timetable; Window numbers:
Found a town; Window numbers:
uint16 version_to
save/load the variable until this savegame version
Basic functions/variables used all over the place.
Build station; Window numbers:
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Industry view; Window numbers:
static bool IsSavegameVersionBefore(uint16 major, byte minor=0)
Checks whether the savegame is below major.
#define lengthof(x)
Return the length of an fixed size array.
bool RoadVehiclesAreBuilt()
Verify whether a road vehicle is available.
void GfxClearSpriteCache()
Remove all encoded sprites from the sprite cache without discarding sprite location information...
static T min(const T a, const T b)
Returns the minimum of two values.
char rcon_password[NETWORK_PASSWORD_LENGTH]
password for rconsole (server side)
Types related to reading/writing '*.ini' files.
void Clear()
Clear all items in the group.
static int ParseIntList(const char *p, int *items, int maxitems)
Parse an integerlist string and set each found value.
bool FioCheckFileExists(const char *filename, Subdirectory subdir)
Check whether the given file exists.
Functions related to sound.
static bool SlIsObjectCurrentlyValid(uint16 version_from, uint16 version_to)
Checks if some version from/to combination falls within the range of the active savegame version...
static size_t ConvertLandscape(const char *value)
Conversion callback for _gameopt_settings_game.landscape It converts (or try) between old values and ...
static VarType GetVarMemType(VarType type)
Get the NumberType of a setting.
static void LoadSettings(const SettingDesc *osd, void *object)
Save and load handler for settings.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
static bool IsNumericType(VarType conv)
Check if the given saveload type is a numeric type.
string with a pre-allocated buffer
Maximum number of companies.
All ships have this type.
OPFSettings opf
pathfinder settings for the old pathfinder
Handlers and description of chunk.
void SetCompanySetting(uint index, int32 value)
Top function to save the new value of an element of the Settings struct.
Subdirectory for all NewGRFs.
#define FOR_ALL_SHIPS(var)
Iterate over all ships.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
void GamelogStopAction()
Stops logging of any changes.
Build industry; Window numbers:
Build toolbar; Window numbers:
void DeleteGRFPresetFromConfig(const char *config_name)
Delete a NewGRF configuration by preset name.
#define DEBUG(name, level,...)
Output a line of debugging information.
'Train' is either a loco or a wagon.
Build signal toolbar; Window numbers:
string enclosed in quotes (with pre-allocated buffer)
static bool CheckRoadSide(int p1)
Check whether the road side may be changed.
StringList _network_host_list
The servers we know.
static bool v_PositionStatusbar(int32 p1)
Reposition the statusbar as the setting changed.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
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 NULL pointer...
static int DecodeHexNibble(char c)
Convert a character to a hex nibble value, or -1 otherwise.
void BuildLandLegend()
(Re)build the colour tables for the legends.
ZoomLevelByte zoom_min
minimum zoom out level
byte quantity_sea_lakes
the amount of seas/lakes
static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
Load values from a group of an IniFile structure into the internal representation.
execute the given command
Company infrastructure overview; Window numbers:
static void * GetVariableAddress(const void *object, const SaveLoad *sld)
Get the address of the variable.
static int32 ClampToI32(const int64 a)
Reduce a signed 64-bit int to a signed 32-bit one.
Functions related to companies.
static uint MapSize()
Get the size of the map.
static void MakeIntList(char *buf, const char *last, const void *array, int nelems, VarType type)
Convert an integer-array (intlist) to a string representation.
void ReInitAllWindows()
Re-initialize all windows.
The data of the error message.
Ini file that supports both loading and saving.
static bool RoadVehAccelerationModelChanged(int32 p1)
This function updates realistic acceleration caches when the setting "Road vehicle acceleration model...
void NetworkServerSendConfigUpdate()
Send Config Update.
Town authority; Window numbers:
GUISettings gui
settings related to the GUI
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
bool station_noise_level
build new airports when the town noise level is still within accepted limits
int cached_max_curve_speed
max consist speed limited by curves
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
a value of zero means the feature is disabled
void UpdateCursorSize()
Update cursor dimension.
Declarations for savegames operations.
CompanyByte _current_company
Company currently doing an action.
uint32 TileIndex
The index/ID of a Tile.
uint16 servint_trains
service interval for trains
char * name
The name of this item.
static void MakeOneOfMany(char *buf, const char *last, const char *many, int id)
Convert a ONEofMANY structure to a string representation.
Map accessors for void tiles.
useful to write zeros in savegame.
string pointer enclosed in quotes
static GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
GRF file is unsafe for static usage.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
bitmasked number where only ONE bit may be set
bool servint_ispercent
service intervals are in percents
OwnerByte owner
Which company owns the vehicle?
bool SetSettingValue(uint index, int32 value, bool force_newgame)
Top function to save the new value of an element of the Settings struct.
TileIndex xy
Base tile of the station.
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
Minimum percentage a user can specify for custom sea level.
void IConsoleError(const char *string)
It is possible to print error information to the console.
IniItem * GetItem(const char *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...
SaveLoadType cmd
the action to take with the saved/loaded type, All types need different action
void GetGRFPresetList(GRFPresetList *list)
Get the list of known NewGrf presets.
Functions and types used internally for the settings configurations.
Get the newgame Script config.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Town view; Window numbers:
char * filename
Filename - either with or without full path.
VehicleDefaultSettings _old_vds
Used for loading default vehicles settings from old savegames.
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
StringList _network_ban_list
The banned clients.
int GetCurveSpeedLimit() const
Computes train speed limit caused by curves.
uint16 servint_aircraft
service interval for aircraft
SettingType GetType() const
Return the type of the setting.
SettingDescType cmd
various flags for the variable
static void RecomputeIndustriesNearForAll()
Recomputes Station::industries_near for all stations.
const char * many
ONE/MANY_OF_MANY: string of possible values for this type.
Vehicle details; Window numbers:
Base functions for all Games.
Functions related to commands.
Network functions used by other parts of OpenTTD.
bool _network_server
network-server is active
void Clear()
Remove all items from the list.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
header file for electrified rail specific functions
static const TextColour CC_ERROR
Colour for error lines.
The original landscape generator.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
AI settings; Window numbers:
uint32 grfid
GRF ID (defined by Action 0x08)
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
bool IsFreeWagon() const
Check if the vehicle is a free wagon (got no engine in front of it).
IniGroup * next
the next group within this file
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
declaration of OTTD revision dependent variables
uint32 param[0x80]
GRF parameters.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Base functions for all AIs.
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
void SlSetLength(size_t length)
Sets the length of either a RIFF object or the number of items in an array.
static bool TrainSlopeSteepnessChanged(int32 p1)
This function updates the train acceleration cache after a steepness change.
GameCreationSettings game_creation
settings used during the creation of a game (map)
uint16 servint_roadveh
service interval for road vehicles
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 |.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
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 NULL pointer...
StringList _network_bind_list
The addresses to bind on.
AIConfig stores the configuration settings of every AI.
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
Owner
Enum for all companies/owners.
Window functions not directly related to making/drawing windows.
SettingType
Type of settings for filtering.
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF) ...
Only find Grfs matching md5sum.
void StringToSettings(const char *value)
Convert a string which is stored in the config file or savegames to custom settings of this Script...
CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change one of the per-company settings.
char server_password[NETWORK_PASSWORD_LENGTH]
password for joining this server
uint16 version_from
save/load the variable starting from this savegame version
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.
void IniSaveWindowSettings(IniFile *ini, const char *grpname, void *desc)
Save a WindowDesc to config.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Functions related to news.
Base classes/functions for stations.
Errors (eg. saving/loading failed)
std::list< ErrorMessageData > ErrorList
Define a queue with errors.
Company view; Window numbers:
static const TextColour CC_WARNING
Colour for warning lines.
VehicleTypeByte type
Type of vehicle.
void WriteValue(void *ptr, VarType conv, int64 val)
Write the value of a setting.
SettingDescBase desc
Settings structure (going to configuration file)
Valid changes while vehicle is driving, and possibly changing tracks.
static bool v_PositionMainToolbar(int32 p1)
Reposition the main toolbar as the setting changed.
static bool InvalidateNewGRFChangeWindows(int32 p1)
Update any possible saveload window and delete any newgrf dialogue as its widget parts might change...
Base class for all station-ish types.
Factory to 'query' all available blitters.
Game options window; Window numbers:
bool GetArgumentInteger(uint32 *value, const char *arg)
Change a string into its number representation.
All settings that are only important for the local client.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
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-...
void UpdateAcceleration()
Update acceleration of the train from the cached power and weight.
Last chunk in this array.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
static void SaveSettings(const SettingDesc *sd, void *object)
Save and load handler for settings.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
void ShowFirstError()
Show the first error of the queue.