OpenTTD
Typedefs | Functions | Variables
settings.cpp File Reference

All actions handling saving and loading of the settings/configuration goes on in this file. More...

#include "stdafx.h"
#include "currency.h"
#include "screenshot.h"
#include "network/network.h"
#include "network/network_func.h"
#include "settings_internal.h"
#include "command_func.h"
#include "console_func.h"
#include "pathfinder/pathfinder_type.h"
#include "genworld.h"
#include "train.h"
#include "news_func.h"
#include "window_func.h"
#include "sound_func.h"
#include "company_func.h"
#include "rev.h"
#include "fontcache.h"
#include "textbuf_gui.h"
#include "rail_gui.h"
#include "elrail_func.h"
#include "error.h"
#include "town.h"
#include "video/video_driver.hpp"
#include "sound/sound_driver.hpp"
#include "music/music_driver.hpp"
#include "blitter/factory.hpp"
#include "base_media_base.h"
#include "gamelog.h"
#include "settings_func.h"
#include "ini_type.h"
#include "ai/ai_config.hpp"
#include "ai/ai.hpp"
#include "game/game_config.hpp"
#include "game/game.hpp"
#include "ship.h"
#include "smallmap_gui.h"
#include "roadveh.h"
#include "fios.h"
#include "strings_func.h"
#include "void_map.h"
#include "station_base.h"
#include "table/strings.h"
#include "table/settings.h"
#include "safeguards.h"

Go to the source code of this file.

Typedefs

typedef std::list< ErrorMessageDataErrorList
 
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object)
 
typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList *list)
 

Functions

static bool IsSignedVarMemType (VarType vt)
 
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 |. More...
 
static size_t LookupManyOfMany (const char *many, const char *str)
 Find the set-integer value MANYofMANY type in a string. More...
 
static int ParseIntList (const char *p, int *items, int maxitems)
 Parse an integerlist string and set each found value. More...
 
static bool LoadIntList (const char *str, void *array, int nelems, VarType type)
 Load parsed string-values into an integer-array (intlist) More...
 
static void MakeIntList (char *buf, const char *last, const void *array, int nelems, VarType type)
 Convert an integer-array (intlist) to a string representation. More...
 
static void MakeOneOfMany (char *buf, const char *last, const char *many, int id)
 Convert a ONEofMANY structure to a string representation. More...
 
static void MakeManyOfMany (char *buf, const char *last, const char *many, uint32 x)
 Convert a MANYofMANY structure to a string representation. More...
 
static const void * StringToVal (const SettingDescBase *desc, const char *orig_str)
 Convert a string representation (external) of a setting to the internal rep. More...
 
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. More...
 
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. More...
 
static void IniSaveSettings (IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
 Save the values of settings to the inifile. More...
 
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, in this case nothing will be saved and a callback function should be defined that will take over the list-handling and store the data itself somewhere. More...
 
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, in this case a callback function should be defined that will provide the source data to be saved. More...
 
void IniLoadWindowSettings (IniFile *ini, const char *grpname, void *desc)
 Load a WindowDesc from config. More...
 
void IniSaveWindowSettings (IniFile *ini, const char *grpname, void *desc)
 Save a WindowDesc to config. More...
 
static bool v_PositionMainToolbar (int32 p1)
 Reposition the main toolbar as the setting changed. More...
 
static bool v_PositionStatusbar (int32 p1)
 Reposition the statusbar as the setting changed. More...
 
static bool PopulationInLabelActive (int32 p1)
 
static bool RedrawScreen (int32 p1)
 
static bool RedrawSmallmap (int32 p1)
 Redraw the smallmap after a colour scheme change. More...
 
static bool InvalidateDetailsWindow (int32 p1)
 
static bool StationSpreadChanged (int32 p1)
 
static bool InvalidateBuildIndustryWindow (int32 p1)
 
static bool CloseSignalGUI (int32 p1)
 
static bool InvalidateTownViewWindow (int32 p1)
 
static bool DeleteSelectStationWindow (int32 p1)
 
static bool UpdateConsists (int32 p1)
 
static bool CheckInterval (int32 p1)
 
static bool UpdateInterval (VehicleType type, int32 p1)
 
static bool UpdateIntervalTrains (int32 p1)
 
static bool UpdateIntervalRoadVeh (int32 p1)
 
static bool UpdateIntervalShips (int32 p1)
 
static bool UpdateIntervalAircraft (int32 p1)
 
static bool TrainAccelerationModelChanged (int32 p1)
 
static bool TrainSlopeSteepnessChanged (int32 p1)
 This function updates the train acceleration cache after a steepness change. More...
 
static bool RoadVehAccelerationModelChanged (int32 p1)
 This function updates realistic acceleration caches when the setting "Road vehicle acceleration model" is set. More...
 
static bool RoadVehSlopeSteepnessChanged (int32 p1)
 This function updates the road vehicle acceleration cache after a steepness change. More...
 
static bool DragSignalsDensityChanged (int32)
 
static bool TownFoundingChanged (int32 p1)
 
static bool InvalidateVehTimetableWindow (int32 p1)
 
static bool ZoomMinMaxChanged (int32 p1)
 
static bool InvalidateNewGRFChangeWindows (int32 p1)
 Update any possible saveload window and delete any newgrf dialogue as its widget parts might change. More...
 
static bool InvalidateCompanyLiveryWindow (int32 p1)
 
static bool InvalidateIndustryViewWindow (int32 p1)
 
static bool InvalidateAISettingsWindow (int32 p1)
 
static bool RedrawTownAuthority (int32 p1)
 Update the town authority window after a town authority setting change. More...
 
static bool InvalidateCompanyInfrastructureWindow (int32 p1)
 Invalidate the company infrastructure details window after a infrastructure maintenance setting change. More...
 
static bool InvalidateCompanyWindow (int32 p1)
 Invalidate the company details window after the shares setting changed. More...
 
static void ValidateSettings ()
 Checks if any settings are set to incorrect values, and sets them to correct values in that case. More...
 
static bool DifficultyNoiseChange (int32 i)
 
static bool MaxNoAIsChange (int32 i)
 
static bool CheckRoadSide (int p1)
 Check whether the road side may be changed. More...
 
static size_t ConvertLandscape (const char *value)
 Conversion callback for _gameopt_settings_game.landscape It converts (or try) between old values and the new ones, without losing initial setting of the user. More...
 
static bool CheckFreeformEdges (int32 p1)
 
static bool ChangeDynamicEngines (int32 p1)
 Changing the setting "allow multiple NewGRF sets" is not allowed if there are vehicles.
 
static bool ChangeMaxHeightLevel (int32 p1)
 
static bool StationCatchmentChanged (int32 p1)
 
static bool MaxVehiclesChanged (int32 p1)
 
static bool UpdateClientName (int32 p1)
 
static bool UpdateServerPassword (int32 p1)
 
static bool UpdateRconPassword (int32 p1)
 
static bool UpdateClientConfigValues (int32 p1)
 
static void PrepareOldDiffCustom ()
 Prepare for reading and old diff_custom by zero-ing the memory.
 
static void HandleOldDiffCustom (bool savegame)
 Reading of the old diff_custom array and transforming it to the new format. More...
 
static void AILoadConfig (IniFile *ini, const char *grpname)
 
static void GameLoadConfig (IniFile *ini, const char *grpname)
 
static int DecodeHexNibble (char c)
 Convert a character to a hex nibble value, or -1 otherwise. More...
 
static bool DecodeHexText (char *pos, uint8 *dest, size_t dest_size)
 Parse a sequence of characters (supposedly hex digits) into a sequence of bytes. More...
 
static GRFConfigGRFLoadConfig (IniFile *ini, const char *grpname, bool is_static)
 Load a GRF configuration. More...
 
static void AISaveConfig (IniFile *ini, const char *grpname)
 
static void GameSaveConfig (IniFile *ini, const char *grpname)
 
static void SaveVersionInConfig (IniFile *ini)
 Save the version of OpenTTD to the ini file. More...
 
static void GRFSaveConfig (IniFile *ini, const char *grpname, const GRFConfig *list)
 
static void HandleSettingDescs (IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list, bool basic_settings=true, bool other_settings=true)
 
static IniFileIniLoadConfig ()
 
void LoadFromConfig (bool minimal)
 Load the values from the configuration files. More...
 
void SaveToConfig ()
 Save the values to the configuration file.
 
void GetGRFPresetList (GRFPresetList *list)
 Get the list of known NewGrf presets. More...
 
GRFConfigLoadGRFPresetFromConfig (const char *config_name)
 Load a NewGRF configuration by preset-name. More...
 
void SaveGRFPresetToConfig (const char *config_name, GRFConfig *config)
 Save a NewGRF configuration with a preset name. More...
 
void DeleteGRFPresetFromConfig (const char *config_name)
 Delete a NewGRF configuration by preset name. More...
 
const SettingDescGetSettingDescription (uint index)
 
CommandCost CmdChangeSetting (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Network-safe changing of settings (server-only). More...
 
CommandCost CmdChangeCompanySetting (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Change one of the per-company settings. More...
 
bool SetSettingValue (uint index, int32 value, bool force_newgame)
 Top function to save the new value of an element of the Settings struct. More...
 
void SetCompanySetting (uint index, int32 value)
 Top function to save the new value of an element of the Settings struct. More...
 
void SetDefaultCompanySettings (CompanyID cid)
 Set the company settings for a new company to their default values.
 
void SyncCompanySettings ()
 Sync all company settings in a multiplayer game.
 
uint GetCompanySettingIndex (const char *name)
 Get the index in the _company_settings array of a setting. More...
 
bool SetSettingValue (uint index, const char *value, bool force_newgame)
 Set a setting value with a string. More...
 
const SettingDescGetSettingFromName (const char *name, uint *i)
 Given a name of setting, return a setting description of it. More...
 
void IConsoleSetSetting (const char *name, const char *value, bool force_newgame)
 
void IConsoleSetSetting (const char *name, int value)
 
void IConsoleGetSetting (const char *name, bool force_newgame)
 Output value of a specific setting to the console. More...
 
void IConsoleListSettings (const char *prefilter)
 List all settings and their value to the console. More...
 
static void LoadSettings (const SettingDesc *osd, void *object)
 Save and load handler for settings. More...
 
static void SaveSettings (const SettingDesc *sd, void *object)
 Save and load handler for settings. More...
 
static void Load_OPTS ()
 
static void Load_PATS ()
 
static void Check_PATS ()
 
static void Save_PATS ()
 
void CheckConfig ()
 

Variables

ClientSettings _settings_client
 The current settings for this game. More...
 
GameSettings _settings_game
 Game settings of a running game or the scenario editor. More...
 
GameSettings _settings_newgame
 Game settings for new games (updated from the intro screen). More...
 
VehicleDefaultSettings _old_vds
 Used for loading default vehicles settings from old savegames. More...
 
char * _config_file
 Configuration file of OpenTTD.
 
static ErrorList _settings_error_list
 Errors while loading minimal settings.
 
static const char *const _list_group_names []
 Groups in openttd.cfg that are actually lists. More...
 
const ChunkHandler _setting_chunk_handlers []
 

Detailed Description

All actions handling saving and loading of the settings/configuration goes on in this file.

The file consists of three parts:

  1. Parsing the configuration file (openttd.cfg). This is achieved with the ini_ functions which handle various types, such as normal 'key = value' pairs, lists and value combinations of lists, strings, integers, 'bit'-masks and element selections.
  2. Handle reading and writing to the setting-structures from inside the game either from the console for example or through the gui with CMD_ functions.
  3. Handle saving/loading of the PATS chunk inside the savegame.
See also
SettingDesc
SaveLoad

Definition in file settings.cpp.

Function Documentation

◆ CheckRoadSide()

static bool CheckRoadSide ( int  p1)
static

Check whether the road side may be changed.

Parameters
p1unused
Returns
true if the road side may be changed.

Definition at line 1185 of file settings.cpp.

References RoadVehiclesAreBuilt().

◆ CmdChangeCompanySetting()

CommandCost CmdChangeCompanySetting ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Change one of the per-company settings.

Parameters
tileunused
flagsoperation to perform
p1the index of the setting in the _company_settings array which identifies it
p2the new value for the setting The new value is properly clamped to its minimum/maximum when setting
textunused
Returns
the cost of this operation or an error

Definition at line 1885 of file settings.cpp.

References _current_company, CMD_ERROR, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), GetVariableAddress(), lengthof, and SettingDesc::save.

◆ CmdChangeSetting()

CommandCost CmdChangeSetting ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Network-safe changing of settings (server-only).

Parameters
tileunused
flagsoperation to perform
p1the index of the setting in the SettingDesc array which identifies it
p2the new value for the setting The new value is properly clamped to its minimum/maximum when setting
textunused
Returns
the cost of this operation or an error
See also
_settings

Definition at line 1838 of file settings.cpp.

◆ ConvertLandscape()

static size_t ConvertLandscape ( const char *  value)
static

Conversion callback for _gameopt_settings_game.landscape It converts (or try) between old values and the new ones, without losing initial setting of the user.

Parameters
valuethat was read from config file
Returns
the "hopefully" converted value

Definition at line 1198 of file settings.cpp.

References LookupOneOfMany().

◆ DecodeHexNibble()

static int DecodeHexNibble ( char  c)
static

Convert a character to a hex nibble value, or -1 otherwise.

Parameters
cCharacter to convert.
Returns
Hex value of the character, or -1 if not a hex digit.

Definition at line 1450 of file settings.cpp.

Referenced by DecodeHexText().

◆ DecodeHexText()

static bool DecodeHexText ( char *  pos,
uint8 *  dest,
size_t  dest_size 
)
static

Parse a sequence of characters (supposedly hex digits) into a sequence of bytes.

After the hex number should be a '|' character.

Parameters
posFirst character to convert.
dest[out] Output byte array to write the bytes.
dest_sizeNumber of bytes in dest.
Returns
Whether reading was successful.

Definition at line 1466 of file settings.cpp.

References DecodeHexNibble().

Referenced by GRFLoadConfig().

◆ DeleteGRFPresetFromConfig()

void DeleteGRFPresetFromConfig ( const char *  config_name)

Delete a NewGRF configuration by preset name.

Parameters
config_nameName of the preset.

Definition at line 1809 of file settings.cpp.

References seprintf().

◆ GetCompanySettingIndex()

uint GetCompanySettingIndex ( const char *  name)

Get the index in the _company_settings array of a setting.

Parameters
nameThe name of the setting
Returns
The index in the _company_settings array

Definition at line 2008 of file settings.cpp.

References GetSettingFromName().

Referenced by ReplaceVehicleWindow::OnClick().

◆ GetGRFPresetList()

void GetGRFPresetList ( GRFPresetList list)

Get the list of known NewGrf presets.

Parameters
list[inout]Pointer to list for storing the preset names.

Definition at line 1753 of file settings.cpp.

References AutoFreeSmallVector< T, S >::Clear().

Referenced by NewGRFWindow::OnQueryTextFinished(), and SavePresetWindow::SavePresetWindow().

◆ GetSettingFromName()

const SettingDesc* GetSettingFromName ( const char *  name,
uint *  i 
)

Given a name of setting, return a setting description of it.

Parameters
nameName of the setting to return a setting description of
iPointer to an integer that will contain the index of the setting after the call, if it is successful.
Returns
Pointer to the setting description of setting name if it can be found, NULL indicates failure to obtain the description

Definition at line 2048 of file settings.cpp.

References SaveLoad::cmd, and SettingDesc::save.

Referenced by GetCompanySettingIndex(), NewsTypeData::GetDisplay(), IConsoleGetSetting(), SettingEntry::Init(), and GameOptionsWindow::OnDropdownSelect().

◆ GRFLoadConfig()

static GRFConfig* GRFLoadConfig ( IniFile ini,
const char *  grpname,
bool  is_static 
)
static

◆ HandleOldDiffCustom()

static void HandleOldDiffCustom ( bool  savegame)
static

Reading of the old diff_custom array and transforming it to the new format.

Parameters
savegameis it read from the config or savegame. In the latter case we are sure there is an array; in the former case we have to check that.

Definition at line 1368 of file settings.cpp.

References GetVariableAddress(), IsSavegameVersionBefore(), SettingDesc::save, SlIsObjectCurrentlyValid(), SaveLoad::version_from, SaveLoad::version_to, and Write_ValidateSetting().

◆ IConsoleGetSetting()

void IConsoleGetSetting ( const char *  name,
bool  force_newgame 
)

Output value of a specific setting to the console.

Parameters
nameName of the setting to output its value
force_newgameforce the newgame settings

Definition at line 2127 of file settings.cpp.

References CC_WARNING, GetSettingFromName(), GetVariableAddress(), and IConsolePrintF().

◆ IConsoleListSettings()

void IConsoleListSettings ( const char *  prefilter)

List all settings and their value to the console.

Parameters
prefilterIf not NULL, only list settings with names that begin with prefilter prefix

Definition at line 2160 of file settings.cpp.

References CC_WARNING, SaveLoad::cmd, IConsolePrintF(), and SettingDesc::save.

◆ IniLoadSettingList()

static void IniLoadSettingList ( IniFile ini,
const char *  grpname,
StringList list 
)
static

Loads all items from a 'grpname' section into a list The list parameter can be a NULL pointer, in this case nothing will be saved and a callback function should be defined that will take over the list-handling and store the data itself somewhere.

Parameters
iniIniFile handle to the ini file with the source data
grpnamecharacter string identifying the section-header of the ini file that will be parsed
listnew list with entries of the given section

Definition at line 704 of file settings.cpp.

References SmallVector< T, S >::Append(), AutoFreeSmallVector< T, S >::Clear(), IniLoadFile::GetGroup(), IniGroup::item, IniItem::next, and stredup().

◆ IniLoadSettings()

static void IniLoadSettings ( IniFile ini,
const SettingDesc sd,
const char *  grpname,
void *  object 
)
static

Load values from a group of an IniFile structure into the internal representation.

Parameters
inipointer to IniFile structure that holds administrative information
sdpointer to SettingDesc structure whose internally pointed variables will be given values
grpnamethe group of the IniFile to search in for the new values
objectpointer to the object been loaded

Definition at line 477 of file settings.cpp.

References SaveLoad::cmd, IniLoadFile::GetGroup(), and SettingDesc::save.

Referenced by IniLoadWindowSettings().

◆ IniLoadWindowSettings()

void IniLoadWindowSettings ( IniFile ini,
const char *  grpname,
void *  desc 
)

Load a WindowDesc from config.

Parameters
iniIniFile handle to the ini file with the source data
grpnamecharacter string identifying the section-header of the ini file that will be parsed
descDestination WindowDesc

Definition at line 744 of file settings.cpp.

References IniLoadSettings().

Referenced by WindowDesc::LoadFromConfig().

◆ IniSaveSettingList()

static void IniSaveSettingList ( IniFile ini,
const char *  grpname,
StringList list 
)
static

Saves all items from a list into the 'grpname' section The list parameter can be a NULL pointer, in this case a callback function should be defined that will provide the source data to be saved.

Parameters
iniIniFile handle to the ini file where the destination data is saved
grpnamecharacter string identifying the section-header of the ini file
listpointer to an string(pointer) array that will be used as the source to be saved into the relevant ini section

Definition at line 726 of file settings.cpp.

References SmallVector< T, S >::Begin(), IniGroup::Clear(), SmallVector< T, S >::End(), IniLoadFile::GetGroup(), IniGroup::GetItem(), and IniItem::SetValue().

◆ IniSaveSettings()

static void IniSaveSettings ( IniFile ini,
const SettingDesc sd,
const char *  grpname,
void *  object 
)
static

Save the values of settings to the inifile.

Parameters
inipointer to IniFile structure
sdread-only SettingDesc structure which contains the unmodified, loaded values of the configuration file and various information about it
grpnameholds the name of the group (eg. [network]) where these will be saved
objectpointer to the object been saved The function works as follows: for each item in the SettingDesc structure we have a look if the value has changed since we started the game (the original values are reloaded when saving). If settings indeed have changed, we get these and save them.

Definition at line 575 of file settings.cpp.

References SaveLoad::cmd, and SettingDesc::save.

Referenced by IniSaveWindowSettings().

◆ IniSaveWindowSettings()

void IniSaveWindowSettings ( IniFile ini,
const char *  grpname,
void *  desc 
)

Save a WindowDesc to config.

Parameters
iniIniFile handle to the ini file where the destination data is saved
grpnamecharacter string identifying the section-header of the ini file
descSource WindowDesc

Definition at line 755 of file settings.cpp.

References IniSaveSettings().

Referenced by WindowDesc::SaveToConfig().

◆ InvalidateCompanyInfrastructureWindow()

static bool InvalidateCompanyInfrastructureWindow ( int32  p1)
static

Invalidate the company infrastructure details window after a infrastructure maintenance setting change.

Parameters
p1Unused.
Returns
Always true.

Definition at line 1130 of file settings.cpp.

References InvalidateWindowClassesData(), and WC_COMPANY_INFRASTRUCTURE.

◆ InvalidateCompanyWindow()

static bool InvalidateCompanyWindow ( int32  p1)
static

Invalidate the company details window after the shares setting changed.

Parameters
p1Unused.
Returns
Always true.

Definition at line 1141 of file settings.cpp.

References InvalidateWindowClassesData(), and WC_COMPANY.

◆ InvalidateNewGRFChangeWindows()

static bool InvalidateNewGRFChangeWindows ( int32  p1)
static

Update any possible saveload window and delete any newgrf dialogue as its widget parts might change.

Reinit all windows as it allows access to the newgrf debug button.

Parameters
p1unused.
Returns
Always true.

Definition at line 1088 of file settings.cpp.

References DeleteWindowByClass(), InvalidateWindowClassesData(), ReInitAllWindows(), WC_GAME_OPTIONS, and WC_SAVELOAD.

◆ LoadFromConfig()

void LoadFromConfig ( bool  minimal)

Load the values from the configuration files.

Parameters
minimalLoad the minimal amount of the configuration to "bootstrap" the blitter and such.

Definition at line 1700 of file settings.cpp.

Referenced by AfterNewGRFScan::OnNewGRFsScanned().

◆ LoadGRFPresetFromConfig()

GRFConfig* LoadGRFPresetFromConfig ( const char *  config_name)

Load a NewGRF configuration by preset-name.

Parameters
config_nameName of the preset.
Returns
NewGRF configuration.
See also
GetGRFPresetList

Definition at line 1774 of file settings.cpp.

References seprintf().

Referenced by NewGRFWindow::OnDropdownSelect().

◆ LoadIntList()

static bool LoadIntList ( const char *  str,
void *  array,
int  nelems,
VarType  type 
)
static

Load parsed string-values into an integer-array (intlist)

Parameters
strthe string that contains the values (and will be parsed)
arraypointer to the integer-arrays that will be filled
nelemsthe number of elements the array holds. Maximum is 64 elements
typethe type of elements the array holds (eg INT8, UINT16, etc.)
Returns
return true on success and false on error

Definition at line 216 of file settings.cpp.

References lengthof, and ParseIntList().

◆ LoadSettings()

static void LoadSettings ( const SettingDesc osd,
void *  object 
)
static

Save and load handler for settings.

Parameters
osdSettingDesc struct containing all information
objectcan be either NULL in which case we load global variables or a pointer to a struct which is getting saved

Definition at line 2189 of file settings.cpp.

References SaveLoad::cmd, and SettingDesc::save.

◆ LookupManyOfMany()

static size_t LookupManyOfMany ( const char *  many,
const char *  str 
)
static

Find the set-integer value MANYofMANY type in a string.

Parameters
manyfull domain of values the MANYofMANY setting can have
strthe current string value of the setting, each individual of separated by a whitespace,tab or | character
Returns
the 'fully' set integer, or -1 if a set is not found

Definition at line 138 of file settings.cpp.

References LookupOneOfMany(), and SetBit().

Referenced by StringToVal().

◆ LookupOneOfMany()

static size_t LookupOneOfMany ( const char *  many,
const char *  one,
size_t  onelen = 0 
)
static

Find the index value of a ONEofMANY type in a string separated by |.

Parameters
manyfull domain of values the ONEofMANY setting can have
onethe current value of the setting for which a value needs found
onelenforce calculation of the *one parameter
Returns
the integer index of the full-list, or -1 if not found

Definition at line 109 of file settings.cpp.

Referenced by ConvertLandscape(), LookupManyOfMany(), and StringToVal().

◆ MakeIntList()

static void MakeIntList ( char *  buf,
const char *  last,
const void *  array,
int  nelems,
VarType  type 
)
static

Convert an integer-array (intlist) to a string representation.

Each value is separated by a comma or a space character

Parameters
bufoutput buffer where the string-representation will be stored
lastlast item to write to in the output buffer
arraypointer to the integer-arrays that is read from
nelemsthe number of elements the array holds.
typethe type of elements the array holds (eg INT8, UINT16, etc.)

Definition at line 261 of file settings.cpp.

◆ MakeManyOfMany()

static void MakeManyOfMany ( char *  buf,
const char *  last,
const char *  many,
uint32  x 
)
static

Convert a MANYofMANY structure to a string representation.

Parameters
bufoutput buffer where the string-representation will be stored
lastlast item to write to in the output buffer
manythe full-domain string of possible values
xthe value of the variable and whose string-representation must be found in the bitmasked many string

Definition at line 316 of file settings.cpp.

◆ MakeOneOfMany()

static void MakeOneOfMany ( char *  buf,
const char *  last,
const char *  many,
int  id 
)
static

Convert a ONEofMANY structure to a string representation.

Parameters
bufoutput buffer where the string-representation will be stored
lastlast item to write to in the output buffer
manythe full-domain string of possible values
idthe value of the variable and whose string-representation must be found

Definition at line 288 of file settings.cpp.

References seprintf().

◆ ParseIntList()

static int ParseIntList ( const char *  p,
int *  items,
int  maxitems 
)
static

Parse an integerlist string and set each found value.

Parameters
pthe string to be parsed. Each element in the list is separated by a comma or a space character
itemspointer to the integerlist-array that will be filled with values
maxitemsthe maximum number of elements the integerlist-array has
Returns
returns the number of items found, or -1 on an error

Definition at line 170 of file settings.cpp.

References ClampToI32().

Referenced by GRFLoadConfig(), and LoadIntList().

◆ RedrawSmallmap()

static bool RedrawSmallmap ( int32  p1)
static

Redraw the smallmap after a colour scheme change.

Parameters
p1Callback parameter.
Returns
Always true.

Definition at line 823 of file settings.cpp.

References BuildLandLegend(), BuildOwnerLegend(), SetWindowClassesDirty(), and WC_SMALLMAP.

◆ RedrawTownAuthority()

static bool RedrawTownAuthority ( int32  p1)
static

Update the town authority window after a town authority setting change.

Parameters
p1Unused.
Returns
Always true.

Definition at line 1119 of file settings.cpp.

References SetWindowClassesDirty(), and WC_TOWN_AUTHORITY.

◆ RoadVehAccelerationModelChanged()

static bool RoadVehAccelerationModelChanged ( int32  p1)
static

This function updates realistic acceleration caches when the setting "Road vehicle acceleration model" is set.

Parameters
p1Callback parameter
Returns
Always true

Definition at line 1010 of file settings.cpp.

References VehicleSettings::roadveh_acceleration_model, and GameSettings::vehicle.

◆ RoadVehSlopeSteepnessChanged()

static bool RoadVehSlopeSteepnessChanged ( int32  p1)
static

This function updates the road vehicle acceleration cache after a steepness change.

Parameters
p1Callback parameter.
Returns
Always true.

Definition at line 1034 of file settings.cpp.

◆ SaveGRFPresetToConfig()

void SaveGRFPresetToConfig ( const char *  config_name,
GRFConfig config 
)

Save a NewGRF configuration with a preset name.

Parameters
config_nameName of the preset.
configNewGRF configuration to save.
See also
GetGRFPresetList

Definition at line 1793 of file settings.cpp.

References seprintf().

Referenced by NewGRFWindow::OnQueryTextFinished().

◆ SaveSettings()

static void SaveSettings ( const SettingDesc sd,
void *  object 
)
static

Save and load handler for settings.

Parameters
sdSettingDesc struct containing all information
objectcan be either NULL in which case we load global variables or a pointer to a struct which is getting saved

Definition at line 2206 of file settings.cpp.

References SaveLoad::cmd, and SettingDesc::save.

◆ SaveVersionInConfig()

static void SaveVersionInConfig ( IniFile ini)
static

Save the version of OpenTTD to the ini file.

Parameters
inithe ini to write to

Definition at line 1629 of file settings.cpp.

References IniLoadFile::GetGroup(), lastof, and seprintf().

◆ SetCompanySetting()

void SetCompanySetting ( uint  index,
int32  value 
)

Top function to save the new value of an element of the Settings struct.

Parameters
indexoffset in the SettingDesc array of the CompanySettings struct which identifies the setting member we want to change
valuenew value of the setting

Definition at line 1960 of file settings.cpp.

References _local_company, and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID().

◆ SetSettingValue() [1/2]

bool SetSettingValue ( uint  index,
int32  value,
bool  force_newgame 
)

Top function to save the new value of an element of the Settings struct.

Parameters
indexoffset in the SettingDesc array of the Settings struct which identifies the setting member we want to change
valuenew value of the setting
force_newgameforce the newgame settings

Definition at line 1919 of file settings.cpp.

References SaveLoad::conv, GetGameSettings(), GetVariableAddress(), SettingDesc::save, SLF_NO_NETWORK_SYNC, and Write_ValidateSetting().

◆ SetSettingValue() [2/2]

bool SetSettingValue ( uint  index,
const char *  value,
bool  force_newgame 
)

Set a setting value with a string.

Parameters
indexthe settings index.
valuethe value to write
force_newgameforce the newgame settings
Note
Strings WILL NOT be synced over the network

Definition at line 2023 of file settings.cpp.

◆ StringToVal()

static const void* StringToVal ( const SettingDescBase desc,
const char *  orig_str 
)
static

Convert a string representation (external) of a setting to the internal rep.

Parameters
descSettingDesc struct that holds all information about the variable
orig_strinput string that will be parsed based on the type of desc
Returns
return the parsed value of the setting

Definition at line 349 of file settings.cpp.

References _settings_error_list, SettingDescBase::cmd, SettingDescBase::def, LookupManyOfMany(), LookupOneOfMany(), SettingDescBase::many, SettingDescBase::name, SettingDescBase::proc_cnvt, SDT_BOOLX, SDT_INTLIST, SDT_MANYOFMANY, SDT_NUMX, SDT_ONEOFMANY, SDT_STRING, and ErrorMessageData::SetDParamStr().

◆ TrainSlopeSteepnessChanged()

static bool TrainSlopeSteepnessChanged ( int32  p1)
static

This function updates the train acceleration cache after a steepness change.

Parameters
p1Callback parameter.
Returns
Always true.

Definition at line 995 of file settings.cpp.

◆ v_PositionMainToolbar()

static bool v_PositionMainToolbar ( int32  p1)
static

Reposition the main toolbar as the setting changed.

Definition at line 789 of file settings.cpp.

◆ v_PositionStatusbar()

static bool v_PositionStatusbar ( int32  p1)
static

Reposition the statusbar as the setting changed.

Definition at line 796 of file settings.cpp.

◆ ValidateSettings()

static void ValidateSettings ( )
static

Checks if any settings are set to incorrect values, and sets them to correct values in that case.

Definition at line 1148 of file settings.cpp.

References CUSTOM_SEA_LEVEL_MIN_PERCENTAGE, CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY, GameSettings::difficulty, GameSettings::game_creation, GameCreationSettings::land_generator, LG_ORIGINAL, and DifficultySettings::quantity_sea_lakes.

◆ Write_ValidateSetting()

static void Write_ValidateSetting ( void *  ptr,
const SettingDesc sd,
int32  val 
)
static

Set the value of a setting and if needed clamp the value to the preset minimum and maximum.

Parameters
ptrthe variable itself
sdpointer to the 'information'-database of the variable
valsigned long version of the new value
Precondition
SettingDesc is of type SDT_BOOLX, SDT_NUMX, SDT_ONEOFMANY or SDT_MANYOFMANY. Other types are not supported as of now

Definition at line 424 of file settings.cpp.

References SettingDescBase::cmd, SaveLoad::conv, SettingDesc::desc, GetVarMemType(), SettingDesc::save, SDT_BOOLX, SDT_MANYOFMANY, SDT_NUMX, SDT_ONEOFMANY, and SLE_VAR_NULL.

Referenced by HandleOldDiffCustom(), and SetSettingValue().

Variable Documentation

◆ _list_group_names

const char* const _list_group_names[]
static
Initial value:
= {
"bans",
"newgrf",
"servers",
"server_bind_addresses",
NULL
}

Groups in openttd.cfg that are actually lists.

Definition at line 94 of file settings.cpp.

◆ _old_vds

Used for loading default vehicles settings from old savegames.

Old vehicle settings, which were game settings before, and are company settings now.

Definition at line 79 of file settings.cpp.

◆ _setting_chunk_handlers

const ChunkHandler _setting_chunk_handlers[]
Initial value:
= {
{ 'OPTS', NULL, Load_OPTS, NULL, NULL, CH_RIFF},
{ 'PATS', Save_PATS, Load_PATS, NULL, Check_PATS, CH_RIFF | CH_LAST},
}
Last chunk in this array.
Definition: saveload.h:104

◆ _settings_client

ClientSettings _settings_client

The current settings for this game.

Definition at line 76 of file settings.cpp.

Referenced by AIDebugWindow::AIDebugWindow(), ServerNetworkAdminSocketHandler::AllowConnection(), ServerNetworkGameSocketHandler::AllowConnection(), BuildAirportWindow::BuildAirportClassDropDown(), BuildLandLegend(), BuildOwnerLegend(), BuildRailClick_Remove(), CcBuildBridge(), CcBuildRailTunnel(), CcBuildRoadTunnel(), CcRoadStop(), AnimationBase< IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback >::ChangeAnimationFrame(), CheckMinActiveClients(), CheckOrders(), CheckPauseOnJoin(), BuildRailStationWindow::CheckSelectedSize(), CheckSoftLimit(), ClearPathReservation(), CompanyServiceInterval(), Order::ConvertFromOldSavegame(), DEF_CONSOLE_HOOK(), GRFFileScanner::DoScan(), ClientNetworkContentSocketHandler::DownloadSelectedContent(), NetworkStartServerWindow::DrawWidget(), FloodVehicle(), GetLogPrefix(), GetOrderCmdFromTile(), GetSmallMapContoursPixels(), GetSmallMapIndustriesPixels(), GetSmallMapVehiclesPixels(), Vehicle::HandlePathfindingResult(), HandlePlacePushButton(), HandleViewportScroll(), HandleZoomMessage(), IConsoleDebug(), IConsoleWarning(), InitializeMusic(), MaybeBarCrossingWithSound(), MaybeStartNewCompany(), NetworkAutoCleanCompanies(), NetworkCheckRestartMap(), NetworkClientPreferTeamChat(), NetworkDisconnect(), NetworkInitChatMessage(), NetworkMaxCompaniesReached(), NetworkServer_Tick(), NetworkServerSetCompanyPassword(), NetworkStartUp(), NetworkUDPAdvertise(), NetworkUDPAdvertiseThread(), NetworkUDPRemoveAdvertiseThread(), NetworkUpdateClientName(), TransparenciesWindow::OnClick(), SmallMapWindow::OnClick(), BuildDocksStationWindow::OnClick(), BuildAirportWindow::OnClick(), NetworkGameWindow::OnClick(), BuildRailStationWindow::OnClick(), BuildRailDepotWindow::OnClick(), BuildRailWaypointWindow::OnClick(), IndustryCargoesWindow::OnClick(), NetworkGameWindow::OnDropdownSelect(), NetworkStartServerWindow::OnDropdownSelect(), GameSettingsWindow::OnDropdownSelect(), NetworkGameWindow::OnEditboxChanged(), NetworkStartServerWindow::OnEditboxChanged(), MusicTrackSelectionWindow::OnInvalidateData(), MusicWindow::OnInvalidateData(), BuildSignalWindow::OnInvalidateData(), ExtraViewportWindow::OnMouseWheel(), SmallMapWindow::OnMouseWheel(), MainWindow::OnMouseWheel(), AfterNewGRFScan::OnNewGRFsScanned(), OnNewMonth(), CompanyFinancesWindow::OnPaint(), BuildDocksStationWindow::OnPaint(), BuildRoadStationWindow::OnPaint(), BuildRailStationWindow::OnPaint(), TimetableWindow::OnQueryTextFinished(), NetworkStartServerWindow::OnQueryTextFinished(), OrdersWindow::OrderClick_NearestDepot(), PlayVehicleSound(), PopupMainToolbMenu(), PositionMainToolbar(), PositionNetworkChatWindow(), PositionNewsMessage(), PositionStatusbar(), AISettingsWindow::RebuildVisibleSettings(), ServerNetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(), MasterNetworkUDPSocketHandler::Receive_MASTER_ACK_REGISTER(), ScriptScanner::RegisterScript(), ResetSignalVariant(), StationViewWindow::SelectGroupBy(), StationViewWindow::SelectSortBy(), StationViewWindow::SelectSortOrder(), ServerNetworkGameSocketHandler::SendConfigUpdate(), ServerNetworkGameSocketHandler::SendNeedCompanyPassword(), ServerNetworkGameSocketHandler::SendWelcome(), ServerNetworkAdminSocketHandler::SendWelcome(), ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(), MusicTrackSelectionWindow::SetStringParameters(), NetworkGameWindow::SetStringParameters(), NetworkStartServerWindow::SetStringParameters(), BuildSignalWindow::SetStringParameters(), GRFConfig::SetSuitablePalette(), SetTimetableParams(), SetupScreenshotViewport(), ShowNewspaper(), ShowSelectBaseStationIfNeeded(), ShowTicker(), SndPlayScreenCoordFx(), NewGRFWindow::TagNameFilter(), IConsoleLine::Truncate(), OrdersWindow::UpdateAutoRefitState(), TimetableWindow::UpdateSelectionStates(), CompanyFinancesWindow::UpdateWidgetSize(), and VpSelectTilesWithMethod().

◆ _settings_game

GameSettings _settings_game

Game settings of a running game or the scenario editor.

The current settings for this game.

Definition at line 77 of file settings.cpp.

Referenced by AddInflation(), AffectSpeedByZChange(), AutoslopeEnabled(), BuildLandLegend(), BuildTownHouse(), CalcEngineReliability(), CanFollowRoad(), AI::CanStartNew(), CheckBridgeAvailability(), CheckBuildableTile(), CheckforTownRating(), CheckIfAuthorityAllowsNewStation(), CheckIfCanLevelIndustryPlatform(), CheckIfTrainNeedsService(), CheckIndustryCloseDownProtection(), CheckNewIndustry_Farm(), CheckNewIndustry_Forest(), CheckNewTrain(), CheckNextTrainTile(), CheckRailSlope(), CheckRoadSlope(), CheckSwitchToEuro(), CheckTrainAttachment(), CheckTrainStayInDepot(), ClampXYToMap(), ClickChangeMaxHlCheat(), CmdBuildRoadDepot(), CmdBuildTrainDepot(), CmdConvertRail(), CmdFoundTown(), CmdGiveMoney(), CmdLevelLand(), CompaniesMonthlyLoop(), Company::Company(), ConvertDisplaySpeedToKmhishSpeed(), ConvertDisplaySpeedToSpeed(), ConvertKmhishSpeedToDisplaySpeed(), ConvertSpeedToDisplaySpeed(), CreateRivers(), DeleteStaleLinks(), DisplayVehicleSortDropDown(), DistanceFromEdgeDir(), DoTrainPathfind(), LinkGraphOverlay::DrawContent(), StationViewWindow::DrawEntries(), DrawRoadAsSnowDesert(), ScenarioEditorToolbarWindow::DrawWidget(), ExtendTrainReservation(), FindSafePosition(), FindSpring(), FindStationsAroundTiles(), FindTownForIndustry(), FlatEmptyWorld(), FormatNumber(), FreightWagonMult(), AI::GameLoop(), ScriptInstance::GameLoop(), GenerateLandscape(), GenerateTerrainPerlin(), GenerateTownName(), GenerateTrees(), GetAirportNoiseLevelForTown(), GetAmplitude(), Station::GetCatchmentRadius(), RoadVehicle::GetCurrentMaxSpeed(), Train::GetCurrentMaxSpeed(), GetDriveableTrackdirBits(), GetFreeUnitNumber(), GetGlobalVariable(), GetIndustryGamePlayProbability(), Engine::GetLifeLengthInDays(), GetLoadAmount(), GetMaskOfTownActions(), GetOtherAqueductEnd(), GetRandomTreeType(), GetScaledIndustryGenerationProbability(), RoadVehicle::GetSlopeSteepness(), Train::GetSlopeSteepness(), GetSnowLine(), GetTerrainType(), TownScopeResolver::GetVariable(), GfxLoadSprites(), GUIPlaceProcDragXY(), HasRailCatenaryDrawn(), HeightMapCoastLines(), HeightMapNormalize(), HeightMapSineTransform(), HighestSnowLine(), IndustryCargoesWindow::HousesCanAccept(), InitializeGRFSpecial(), AirportSpec::IsAvailable(), Engine::IsEnabled(), ObjectSpec::IsEverAvailable(), IsRoadAllowedHere(), IsVehicleTypeDisabled(), LoadNewGRF(), LoadSpriteTables(), LowestSnowLine(), Town::MaxTownNoise(), MaybeCrashAirplane(), MayCompanyTakeOver(), IndustryBuildData::MonthlyLoop(), Vehicle::NeedsServicing(), NetworkServerSetCompanyPassword(), NPFFindSafeTile(), NPFSaveTargetData(), LandInfoWindow::OnInit(), BuildIndustryWindow::OnInvalidateData(), BuildVehicleWindow::OnInvalidateData(), CompanyWindow::OnInvalidateData(), BuildAirportWindow::OnPaint(), BuildDocksStationWindow::OnPaint(), BuildRoadStationWindow::OnPaint(), ScenarioEditorToolbarWindow::OnPaint(), CreateScenarioWindow::OnQueryTextFinished(), OnTick_LinkGraph(), ScriptInstance::Pause(), SmallMapWindow::RebuildColourIndexIfNecessary(), ServerNetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(), RecomputePrices(), AI::ResetConfig(), RoadFindPathToDest(), ServerNetworkGameSocketHandler::SendNeedCompanyPassword(), ServerNetworkGameSocketHandler::SendWelcome(), SetStartingYear(), SetupScreenshotViewport(), StationViewWindow::ShowCargo(), StationJoinerNeeded(), TestAutoslopeOnRailTile(), TGPGetMaxHeight(), ToolbarScenDatePanel(), TownLayoutAllows2x2HouseHere(), TownLayoutAllowsHouseHere(), TrainCheckIfLineEnds(), TryReserveSafeTrack(), AI::Uninitialize(), UpdateAircraftSpeed(), RoadVehicle::UpdateSpeed(), Train::UpdateSpeed(), UpdateTownGrowRate(), IndustrySpec::UsesSmoothEconomy(), YapfRoadVehicleChooseTrack(), YapfRoadVehicleFindNearestDepot(), YapfShipCheckReverse(), YapfShipChooseTrack(), YapfTrainCheckReverse(), YapfTrainChooseTrack(), YapfTrainFindNearestDepot(), YapfTrainFindNearestSafeTile(), and LinkGraphJob::~LinkGraphJob().

◆ _settings_newgame

GameSettings _settings_newgame