# 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 "variables.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 "strings_func.h"`
`#include "vehicle_func.h"`
`#include "sound_func.h"`
`#include "company_func.h"`
`#include "rev.h"`
`#include "textbuf_gui.h"`
`#include "rail_gui.h"`
`#include "elrail_func.h"`
`#include "gui.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.hpp"`
`#include "ai/ai_config.hpp"`
`#include "newgrf.h"`
`#include "ship.h"`
`#include "void_map.h"`
`#include "station_base.h"`
`#include "table/strings.h"`
`#include "table/settings.h"`

Go to the source code of this file.

## Typedefs
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 int | lookup_oneofmany (const char *many, const char *one, size_t onelen=0)
| Find the index value of a ONEofMANY type in a string seperated by |.
static uint32 | lookup_manyofmany (const char *many, const char *str)
| Find the set-integer value MANYofMANY type in a string.
static int | parse_intlist (const char *p, int *items, int maxitems)
| Parse an integerlist string and set each found value.
static bool | load_intlist (const char *str, void *array, int nelems, VarType type)
| Load parsed string-values into an integer-array (intlist).
static void | make_intlist (char *buf, const char *last, const void *array, int nelems, VarType type)
| Convert an integer-array (intlist) to a string representation.
static void | make_oneofmany (char *buf, const char *last, const char *many, int id)
| Convert a ONEofMANY structure to a string representation.
static void | make_manyofmany (char *buf, const char *last, const char *many, uint32 x)
| Convert a MANYofMANY structure to a string representation.
static const void * | string_to_val (const SettingDescBase *desc, const char *orig_str)
| Convert a string representation (external) of a setting to the internal rep.
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.
static void | ini_load_settings (IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
| Load values from a group of an IniFile structure into the internal representation.
static void | ini_save_settings (IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
| Save the values of settings to the inifile.
static void | ini_load_setting_list (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.
static void | ini_save_setting_list (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.
static bool | v_PositionMainToolbar (int32 p1)
static bool | PopulationInLabelActive (int32 p1)
static bool | RedrawScreen (int32 p1)
static bool | InvalidateDetailsWindow (int32 p1)
static bool | InvalidateStationBuildWindow (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 | TrainAccelerationModelChanged (int32 p1)
static bool | DragSignalsDensityChanged (int32)
static bool | TownFoundingChanged (int32 p1)
static bool | InvalidateVehTimetableWindow (int32 p1)
void | SetDifficultyLevel (int mode, DifficultySettings *gm_opt)
static void | CheckDifficultyLevels ()
| Checks the difficulty levels read from the configuration and forces them to be correct when invalid.
static bool | DifficultyReset (int32 level)
static bool | DifficultyChange (int32)
static bool | DifficultyNoiseChange (int32 i)
static bool | CheckRoadSide (int p1)
| Check whether the road side may be changed.
static int32 | 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.
static int32 | CheckNoiseToleranceLevel (const char *value)
| Check for decent values been supplied by the user for the noise tolerance setting.
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 | StationCatchmentChanged (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.
static bool | ConvertOldNewsSetting (const char *name, const char *value)
| tries to convert newly introduced news settings based on old ones
static void | NewsDisplayLoadConfig (IniFile *ini, const char *grpname)
static void | AILoadConfig (IniFile *ini, const char *grpname)
static GRFConfig * | GRFLoadConfig (IniFile *ini, const char *grpname, bool is_static)
static void | NewsDisplaySaveConfig (IniFile *ini, const char *grpname)
static void | AISaveConfig (IniFile *ini, const char *grpname)
static void | SaveVersionInConfig (IniFile *ini)
| Save the version of OpenTTD to the ini file.
static void | GRFSaveConfig (IniFile *ini, const char *grpname, const GRFConfig *list)
static void | HandleSettingDescs (IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list)
static IniFile * | IniLoadConfig ()
void | LoadFromConfig ()
| Load the values from the configuration files.
void | SaveToConfig ()
| Save the values to the configuration file.
void | GetGRFPresetList (GRFPresetList *list)
GRFConfig * | LoadGRFPresetFromConfig (const char *config_name)
void | SaveGRFPresetToConfig (const char *config_name, GRFConfig *config)
void | DeleteGRFPresetFromConfig (const char *config_name)
static const SettingDesc * | GetSettingDescription (uint index)
CommandCost | CmdChangeSetting (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Network-safe changing of settings (server-only).
CommandCost | CmdChangeCompanySetting (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Change one of the per-company settings.
bool | SetSettingValue (uint index, int32 value)
| Top function to save the new value of an element of the Settings struct.
void | SetCompanySetting (uint index, int32 value)
| Top function to save the new value of an element of the Settings struct.
void | SetDefaultCompanySettings (CompanyID cid)
| Set the company settings for a new company to their default values.
uint | GetCompanySettingIndex (const char *name)
| Get the index in the _company_settings array of a setting.
bool | SetSettingValue (uint index, const char *value)
| Set a setting value with a string.
const SettingDesc * | GetSettingFromName (const char *name, uint *i)
| Given a name of setting, return a setting description of it.
void | IConsoleSetSetting (const char *name, const char *value)
void | IConsoleSetSetting (const char *name, int value)
void | IConsoleGetSetting (const char *name)
| Output value of a specific setting to the console.
void | IConsoleListSettings (const char *prefilter)
| List all settings and their value to the console.
static void | LoadSettings (const SettingDesc *osd, void *object)
| Save and load handler for settings.
static void | LoadSettingsGlobList (const SettingDescGlobVarList *sdg)
| Loadhandler for a list of global variables.
static void | SaveSettings (const SettingDesc *sd, void *object)
| Save and load handler for settings.
static void | SaveSettingsGlobList (const SettingDescGlobVarList *sdg)
| Savehandler for a list of global variables.
static void | Load_OPTS ()
static void | Load_PATS ()
static void | Save_PATS ()
void | CheckConfig ()
## Variables
ClientSettings | _settings_client
| The current settings for this game.
GameSettings | _settings_game
| The current settings for this game.
GameSettings | _settings_newgame
| The settings values that are used for new games and/or modified in config file.
VehicleDefaultSettings | _old_vds
| Used for loading default vehicles settings from old savegames.
static const char *const | _list_group_names []
| Groups in openttd.cfg that are actually lists.
static const DifficultySettings | _default_game_diff [3]
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

static int32 CheckNoiseToleranceLevel | ( | const char * | value | ) | `[static]`

Check for decent values been supplied by the user for the noise tolerance setting.

The primary idea is to avoid division by zero in game mode. The secondary idea is to make it so the values will be somewhat sane and that towns will not be overcrowed with airports. It would be easy to abuse such a feature So basically, 200, 400, 800 are the lowest allowed values

Definition at line 889 of file settings.cpp.

References GameSettings::economy, lengthof, max(), and EconomySettings::town_noise_population.

static bool CheckRoadSide | ( | int | p1 | ) | `[static]`

Check whether the road side may be changed.

Parameters:

  | p1 | unused

Returns:
  true if the road side may be changed.

Definition at line 865 of file settings.cpp.

References RoadVehiclesAreBuilt().

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

Change one of the per-company settings.

Parameters:

  | tile | unused
  | flags | operation to perform
  | p1 | the index of the setting in the _company_settings array which identifies it
  | p2 | the new value for the setting The new value is properly clamped to its minimum/maximum when setting
  | text | unused

Returns:
  the cost of this operation or an error

Definition at line 1480 of file settings.cpp.

References CMD_ERROR, DC_EXEC, GetVariableAddress(), lengthof, ReadValue(), SetWindowDirty(), Write_ValidateSetting(), and WriteValue().

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

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

Parameters:

  | tile | unused
  | flags | operation to perform
  | p1 | the index of the setting in the SettingDesc array which identifies it
  | p2 | the new value for the setting The new value is properly clamped to its minimum/maximum when setting
  | text | unused

Returns:
  the cost of this operation or an error

See also:
  _settings

Definition at line 1427 of file settings.cpp.

References CMD_ERROR, DC_EXEC, GamelogSetting(), GamelogStartAction(), GamelogStopAction(), GetVariableAddress(), GLAT_SETTING, ReadValue(), SetWindowDirty(), SGF_NETWORK_ONLY, SGF_NEWGAME_ONLY, SGF_NO_NETWORK, SGF_SCENEDIT_TOO, SlIsObjectCurrentlyValid(), Write_ValidateSetting(), and WriteValue().

static int32 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:

  | value | that was read from config file

Returns:
  the "hopefully" converted value

Definition at line 877 of file settings.cpp.

References lookup_oneofmany().

static bool ConvertOldNewsSetting | ( | const char * | name,
|  | const char * | value |
| ) |  |  | `[static]`

tries to convert newly introduced news settings based on old ones

Parameters:

  | name | pointer to the string defining name of the old news config
  | value | pointer to the string defining value of the old news config

Returns:
  true if conversion could have been made

Definition at line 1065 of file settings.cpp.

References _news_type_data, NewsTypeData::display, ND_FULL, ND_OFF, ND_SUMMARY, NT_INDUSTRY_CLOSE, and NT_INDUSTRY_OPEN.

uint GetCompanySettingIndex | ( | const char * | name | ) |

Get the index in the _company_settings array of a setting.

Parameters:

  | name | The name of the setting

Returns:
  The index in the _company_settings array

Definition at line 1592 of file settings.cpp.

References GetSettingFromName(), and SGF_PER_COMPANY.

Referenced by AIGroup::EnableWagonRemoval(), ReplaceVehicleWindow::OnClick(), AICompany::SetAutoRenewMoney(), AICompany::SetAutoRenewMonths(), and AICompany::SetAutoRenewStatus().

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

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

Parameters:

  | name | Name of the setting to return a setting description of
  | i | Pointer 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 1625 of file settings.cpp.

References SlIsObjectCurrentlyValid().

Referenced by GetCompanySettingIndex(), AIGameSettings::GetValue(), IConsoleGetSetting(), SettingEntry::Init(), and AIGameSettings::IsValid().

static void HandleOldDiffCustom | ( | bool | savegame | ) | `[static]`

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

Parameters:

  | savegame | is 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 1038 of file settings.cpp.

References CheckSavegameVersion(), GetVariableAddress(), SlIsObjectCurrentlyValid(), and Write_ValidateSetting().

Referenced by LoadFromConfig().

void IConsoleGetSetting | ( | const char * | name | ) |

Output value of a specific setting to the console.

Parameters:

  | name | Name of the setting to output its value

Definition at line 1703 of file settings.cpp.

References GetSettingFromName(), GetVariableAddress(), IConsolePrintF(), ReadValue(), SDT_BOOLX, SDT_STRING, and SGF_0ISDISABLED.

void IConsoleListSettings | ( | const char * | prefilter | ) |

List all settings and their value to the console.

Parameters:

  | prefilter | If not `NULL`, only list settings with names that begin with prefilter prefix

Definition at line 1736 of file settings.cpp.

References GetVariableAddress(), IConsolePrintF(), lengthof, min(), ReadValue(), SDT_BOOLX, SDT_STRING, and SlIsObjectCurrentlyValid().

static void ini_load_setting_list | ( | 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:

  | ini | IniFile handle to the ini file with the source data
  | grpname | character string identifying the section-header of the ini file that will be parsed
  | list | new list with entries of the given section

Definition at line 606 of file settings.cpp.

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

Referenced by LoadFromConfig().

static void ini_load_settings | ( | 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:

  | ini | pointer to IniFile structure that holds administrative information
  | sd | pointer to SettingDesc structure whose internally pointed variables will be given values
  | grpname | the group of the IniFile to search in for the new values
  | object | pointer to the object been loaded

Definition at line 399 of file settings.cpp.

References SaveLoad::conv, IniFile::GetGroup(), IniGroup::GetItem(), GetVariableAddress(), SaveLoad::length, load_intlist(), IniGroup::name, SDT_BOOLX, SDT_INTLIST, SDT_MANYOFMANY, SDT_NUMX, SDT_ONEOFMANY, SDT_STRING, ShowInfoF(), SLE_VAR_STR, SLE_VAR_STRB, SLE_VAR_STRBQ, SLE_VAR_STRQ, SlIsObjectCurrentlyValid(), string_to_val(), ttd_strlcpy(), IniItem::value, SaveLoad::version_from, SaveLoad::version_to, and Write_ValidateSetting().

Referenced by LoadFromConfig().

static void ini_save_setting_list | ( | 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:

  | ini | IniFile handle to the ini file where the destination data is saved
  | grpname | character string identifying the section-header of the ini file
  | list | pointer to an string(pointer) array that will be used as the source to be saved into the relevant ini section

Definition at line 627 of file settings.cpp.

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

Referenced by SaveToConfig().

static void ini_save_settings | ( | IniFile * | ini,
|  | const SettingDesc * | sd,
|  | const char * | grpname,
|  | void * | object |
| ) |  |  | `[static]`

Save the values of settings to the inifile.

Parameters:

  | ini | pointer to IniFile structure
  | sd | read-only SettingDesc structure which contains the unmodified, loaded values of the configuration file and various information about it
  | grpname | holds the name of the group (eg. [network]) where these will be saved
  | object | pointer 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 487 of file settings.cpp.

References SaveLoad::conv, IniFile::GetGroup(), GetVariableAddress(), lastof, SaveLoad::length, make_intlist(), make_manyofmany(), make_oneofmany(), IniGroup::name, ReadValue(), SDT_BOOLX, SDT_INTLIST, SDT_MANYOFMANY, SDT_NUMX, SDT_ONEOFMANY, SDT_STRING, seprintf(), SLE_VAR_STR, SLE_VAR_STRB, SLE_VAR_STRBQ, SLE_VAR_STRQ, SLF_CONFIG_NO, SlIsObjectCurrentlyValid(), strecpy(), string_to_val(), IniItem::value, SaveLoad::version_from, and SaveLoad::version_to.

Referenced by SaveToConfig().

static bool load_intlist | ( | const char * | str,
|  | void * | array,
|  | int | nelems,
|  | VarType | type |
| ) |  |  | `[static]`

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

Parameters:

  | str | the string that contains the values (and will be parsed)
  | array | pointer to the integer-arrays that will be filled
  | nelems | the number of elements the array holds. Maximum is 64 elements
  | type | the type of elements the array holds (eg INT8, UINT16, etc.)

Returns:
  return true on success and false on error

Definition at line 179 of file settings.cpp.

References lengthof, and parse_intlist().

Referenced by ini_load_settings().

static void LoadSettings | ( | const SettingDesc * | osd,
|  | void * | object |
| ) |  |  | `[static]`

Save and load handler for settings.

Parameters:

  | osd | SettingDesc struct containing all information
  | object | can be either NULL in which case we load global variables or a pointer to a struct which is getting saved

Definition at line 1765 of file settings.cpp.

References GetVariableAddress().

Referenced by LoadSettingsGlobList().

static void LoadSettingsGlobList | ( | const SettingDescGlobVarList * | sdg | ) | `[inline, static]`

Loadhandler for a list of global variables.

Parameters:

  | sdg | pointer for the global variable list SettingDescGlobVarList

Note:
  this is actually a stub for LoadSettings with the object pointer set to NULL

Definition at line 1779 of file settings.cpp.

References LoadSettings().

static uint32 lookup_manyofmany | ( | const char * | many,
|  | const char * | str |
| ) |  |  | `[static]`

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

Parameters:

  | many | full domain of values the MANYofMANY setting can have
  | str | the current string value of the setting, each individual of seperated by a whitespace,tab or | character

Returns:
  the 'fully' set integer, or -1 if a set is not found

Definition at line 125 of file settings.cpp.

References lookup_oneofmany(), and SetBit().

Referenced by string_to_val().

static int lookup_oneofmany | ( | const char * | many,
|  | const char * | one,
|  | size_t | onelen = `0` |
| ) |  |  | `[static]`

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

Parameters:

  | many | full domain of values the ONEofMANY setting can have
  | one | the current value of the setting for which a value needs found
  | onelen | force calculation of the *one parameter

Returns:
  the integer index of the full-list, or -1 if not found

Definition at line 97 of file settings.cpp.

Referenced by ConvertLandscape(), lookup_manyofmany(), and string_to_val().

static void make_intlist | ( | 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 seperated by a comma or a space character

Parameters:

  | buf | output buffer where the string-representation will be stored
  | last | last item to write to in the output buffer
  | array | pointer to the integer-arrays that is read from
  | nelems | the number of elements the array holds.
  | type | the type of elements the array holds (eg INT8, UINT16, etc.)

Definition at line 219 of file settings.cpp.

References seprintf().

Referenced by ini_save_settings().

static void make_manyofmany | ( | char * | buf,
|  | const char * | last,
|  | const char * | many,
|  | uint32 | x |
| ) |  |  | `[static]`

Convert a MANYofMANY structure to a string representation.

Parameters:

  | buf | output buffer where the string-representation will be stored
  | last | last item to write to in the output buffer
  | many | the full-domain string of possible values
  | x | the value of the variable and whose string-representation must be found in the bitmasked many string

Definition at line 270 of file settings.cpp.

References HasBit(), and seprintf().

Referenced by ini_save_settings().

static void make_oneofmany | ( | char * | buf,
|  | const char * | last,
|  | const char * | many,
|  | int | id |
| ) |  |  | `[static]`

Convert a ONEofMANY structure to a string representation.

Parameters:

  | buf | output buffer where the string-representation will be stored
  | last | last item to write to in the output buffer
  | many | the full-domain string of possible values
  | id | the value of the variable and whose string-representation must be found

Definition at line 244 of file settings.cpp.

References seprintf().

Referenced by ini_save_settings().

static int parse_intlist | ( | const char * | p,
|  | int * | items,
|  | int | maxitems |
| ) |  |  | `[static]`

Parse an integerlist string and set each found value.

Parameters:

  | p | the string to be parsed. Each element in the list is seperated by a comma or a space character
  | items | pointer to the integerlist-array that will be filled with values
  | maxitems | the maximum number of elements the integerlist-array has

Returns:
  returns the number of items found, or -1 on an error

Definition at line 155 of file settings.cpp.

static void SaveSettings | ( | const SettingDesc * | sd,
|  | void * | object |
| ) |  |  | `[static]`

Save and load handler for settings.

Parameters:

  | sd | SettingDesc struct containing all information
  | object | can be either NULL in which case we load global variables or a pointer to a struct which is getting saved

Definition at line 1788 of file settings.cpp.

References GetVariableAddress(), and SlSetLength().

Referenced by SaveSettingsGlobList().

static void SaveSettingsGlobList | ( | const SettingDescGlobVarList * | sdg | ) | `[inline, static]`

Savehandler for a list of global variables.

Note:
  this is actually a stub for SaveSettings with the object pointer set to NULL

Definition at line 1808 of file settings.cpp.

References SaveSettings().

static void SaveVersionInConfig | ( | IniFile * | ini | ) | `[static]`

Save the version of OpenTTD to the ini file.

Parameters:

  | ini | the ini to write to

Definition at line 1263 of file settings.cpp.

References IniFile::GetGroup(), IniGroup::GetItem(), lengthof, and IniItem::SetValue().

Referenced by SaveToConfig().

void SetCompanySetting | ( | uint | index,
|  | int32 | value |
| ) |  |  |

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

Parameters:

  | index | offset in the SettingDesc array of the CompanySettings struct which identifies the setting member we want to change
  | value | new value of the setting

Definition at line 1544 of file settings.cpp.

References CMD_CHANGE_COMPANY_SETTING, ClientSettings::company, DoCommandP(), GetVariableAddress(), ReadValue(), and Write_ValidateSetting().

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

Set a setting value with a string.

Parameters:

  | index | the settings index.
  | value | the value to write

Note:
  CANNOT BE SAVED IN THE SAVEGAME.

Definition at line 1606 of file settings.cpp.

References GetVariableAddress(), SLF_NETWORK_NO, and ttd_strlcpy().

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

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

Parameters:

  | index | offset in the SettingDesc array of the Settings struct which identifies the setting member we want to change
  | value | new value of the setting

Definition at line 1512 of file settings.cpp.

References CMD_CHANGE_SETTING, DoCommandP(), GetVariableAddress(), ReadValue(), SetWindowDirty(), SLF_NETWORK_NO, and Write_ValidateSetting().

static const void* string_to_val | ( | const SettingDescBase * | desc,
|  | const char * | orig_str |
| ) |  |  | `[static]`

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

Parameters:

  | desc | SettingDesc struct that holds all information about the variable
  | orig_str | input string that will be parsed based on the type of desc

Returns:
  return the parsed value of the setting

Definition at line 301 of file settings.cpp.

References lookup_manyofmany(), lookup_oneofmany(), SDT_BOOLX, SDT_INTLIST, SDT_MANYOFMANY, SDT_NUMX, SDT_ONEOFMANY, SDT_STRING, and ShowInfoF().

Referenced by ini_load_settings(), and ini_save_settings().

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:

  | ptr | the variable itself
  | sd | pointer to the 'information'-database of the variable
  | val | signed 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 349 of file settings.cpp.

References Clamp(), ClampU(), min(), SDT_BOOLX, SDT_MANYOFMANY, SDT_NUMX, SDT_ONEOFMANY, SGF_0ISDISABLED, SLE_VAR_NULL, and WriteValue().

Referenced by CmdChangeCompanySetting(), CmdChangeSetting(), HandleOldDiffCustom(), ini_load_settings(), SetCompanySetting(), SetDefaultCompanySettings(), and SetSettingValue().

## Variable Documentation

const DifficultySettings _default_game_diff[3]`[static]`

Initial value:

     {
      {2, 2, 4, 300000, 2, 0, 2, 1, 2, 0, 1, 0, 0, 0, 0, 0, 0},
      {4, 2, 3, 150000, 3, 1, 3, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1},
      {7, 3, 3, 100000, 4, 1, 3, 2, 0, 2, 3, 2, 1, 1, 1, 2, 2},
    }

Definition at line 791 of file settings.cpp.

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 84 of file settings.cpp.

const ChunkHandler _setting_chunk_handlers[]

Initial value:

     {
      { 'OPTS', NULL,      Load_OPTS, NULL, CH_RIFF},
      { 'PATS', Save_PATS, Load_PATS, NULL, CH_RIFF | CH_LAST},
    }

ClientSettings _settings_client

The current settings for this game.

Definition at line 71 of file settings.cpp.

Referenced by _GenerateWorld(), AddNewsItem(), BuildRailClick_AutoSignals(), BuildRailClick_Remove(), CalcRaildirsDrawstyle(), CanBuildVehicleInfrastructure(), CcBuildRailTunnel(), CheckOrders(), CheckSoftLimit(), ClearPathReservation(), CmdCompanyCtrl(), DoAutosave(), DrawCategories(), DrawTile_Road(), DrawTile_TunnelBridge(), DrawTrackBits(), VehicleViewWindow::DrawWidget(), DrawYearColumn(), GenerateDefaultSaveName(), GenericPlaceSignals(), GetEngineLivery(), GetLogPrefix(), HandleAutoscroll(), HandleAutoSignalPlacement(), InitializeRailGUI(), LoadUnloadVehicle(), OnNewMonth(), OnNewYear(), CompanyFinancesWindow::OnPaint(), BuildRailToolbarWindow::OnPlaceMouseUp(), OrdersWindow::OnPlaceObject(), BuildIndustryWindow::OnPlaceObject(), OrdersWindow::OrderClick_NearestDepot(), PositionMainToolbar(), ResetSignalVariant(), SaveOrLoad(), SetDefaultRailGui(), SetTimetableParams(), ShowErrorMessage(), ShowMeasurementTooltips(), ShowSelectBaseStationIfNeeded(), StartScenario(), IConsoleLine::Truncate(), TryPathReserve(), TryReserveRailTrack(), UnreserveRailTrack(), UpdateAircraftSpeed(), UpdateViewportPosition(), CompanyFinancesWindow::UpdateWidgetSize(), and VpSelectTilesWithMethod().

GameSettings _settings_game

The current settings for this game.

Definition at line 72 of file settings.cpp.

Referenced by _GenerateWorld(), AddInflation(), AffectSpeedByZChange(), AircraftController(), AircraftEventHandler_AtTerminal(), AITileList_IndustryAccepting::AITileList_IndustryAccepting(), AITileList_IndustryProducing::AITileList_IndustryProducing(), AlwaysDrawUnpavedRoads(), AutoslopeEnabled(), Subsidy::AwardTo(), BuildRailClick_Remove(), BuildTownHouse(), AIRoad::CanBuildConnectedRoadParts(), AIIndustryType::CanBuildIndustry(), CanBuildVehicleInfrastructure(), CanExpandRailStation(), AIIndustryType::CanProspectIndustry(), ChangeIndustryProduction(), CheckAllowRemoveRoad(), CheckFlatLandBelow(), CheckIfAuthorityAllowsNewStation(), CheckIndustryCloseDownProtection(), CheckNewTrain(), CheckNextTrainTile(), CheckRailSlope(), CheckRoadSlope(), CheckSwitchToEuro(), CheckTrainAttachment(), ChooseShipTrack(), ClickChangeClimateCheat(), CmdAutofillTimetable(), CmdBuildAircraft(), CmdBuildAirport(), CmdBuildBridge(), CmdBuildDock(), CmdBuildIndustry(), CmdBuildRailStation(), CmdBuildRailVehicle(), CmdBuildRailWaypoint(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildRoadStop(), CmdBuildRoadVeh(), CmdBuildShip(), CmdBuildTrainDepot(), CmdBuyShareInCompany(), CmdChangeTimetable(), CmdConvertRail(), CmdFoundTown(), CmdGiveMoney(), CmdInsertOrder(), CmdPlantTree(), CmdReverseTrainDirection(), CmdSellShareInCompany(), CmdSetTimetableStart(), CmdSetVehicleOnTime(), ConvertDisplaySpeedToSpeed(), ConvertSpeedToDisplaySpeed(), CreateNewIndustryHelper(), DeliverGoods(), DoCreateTown(), DoTrainPathfind(), SmallMapWindow::DrawSmallMapStuff(), DrawTrainDetails(), VehicleDetailsWindow::DrawWidget(), ExpandTown(), ExtendTrainReservation(), FindClosestTrainDepot(), FindJoiningBaseStation(), FindSafePosition(), FindStationsAroundTiles(), FindStationsNearby(), FlatEmptyWorld(), FloodVehicles(), FollowTrainReservation(), FormatBytes(), FreightWagonMult(), GamelogMode(), GamelogTestMode(), GenerateIndustries(), GenerateTerrainPerlin(), GenerateTownName(), GenerateTowns(), GenerateTrees(), GenerateWorld(), AIAirport::GetAirportCoverageRadius(), GetAirportNoiseLevelForTown(), AITown::GetAllowedNoise(), AITile::GetCargoAcceptance(), AITile::GetCargoProduction(), Station::GetCatchmentRadius(), GetClosestWaterDistance(), GetCompanyRailtypes(), GetCompanyRoadtypes(), IndustrySpec::GetConstructionCost(), AIIndustryType::GetConstructionCost(), AIStation::GetCoverageRadius(), GetDriveableTrackdirBits(), GetGlobalVariable(), GetMaskOfTownActions(), AIBridge::GetMaxLength(), AIEventEnginePreview::GetMaxSpeed(), AIEngine::GetMaxSpeed(), GetNewEngine(), AIAirport::GetNoiseLevelIncrease(), GetRandomTreeType(), GetSnowLine(), GetTerrainType(), GetTileSlope(), GetTrainCurveSpeedLimit(), AIGameSettings::GetValue(), GrayscaleToMapHeights(), GrowTown(), GrowTownInTile(), GUIPlaceProcDragXY(), HasCatenaryDrawn(), HeightMapCoastLines(), HeightMapGenerate(), HeightMapNormalize(), HeightMapSineTransform(), HighestSnowLine(), InitLoading(), int_noise(), AirportFTAClass::IsAvailable(), AIGameSettings::IsDisabledVehicleType(), IsRoadAllowedHere(), IsValidTileForWaypoint(), LoadUnloadVehicle(), LowestSnowLine(), MaybeNewIndustry(), NPFFindSafeTile(), NPFSaveTargetData(), BuildIndustryWindow::OnClick(), BuildTreesWindow::OnInvalidateData(), BuildIndustryWindow::OnInvalidateData(), OnNewMonth(), CompanyWindow::OnPaint(), PlaceInitialIndustry(), PlaceTreesRandomly(), AIIndustryType::ProductionCanIncrease(), RecomputePrices(), RemoveAirport(), RemoveFromRailBaseStation(), RemoveRailStation(), RemoveRailWaypoint(), RemoveRoad(), ResetIndustries(), ResetNewGRFData(), RestoreVehicleOrders(), RoadFindPathToDest(), SaveHighScoreValue(), BuildIndustryWindow::SetStringParameters(), SetTileType(), StartScenario(), StationJoinerNeeded(), TerraformTileHeight(), TestAutoslopeOnRailTile(), TgenSetTileHeight(), TownGetVariable(), TownHouseChangeInfo(), TownLayoutAllows2x2HouseHere(), TownLayoutAllowsHouseHere(), TrainCheckIfLineEnds(), TrainConsistChanged(), TrainDetailsCapacityTab(), TrainDetailsCargoTab(), TranslateXYToTileCoord(), TryPathReserve(), TryReserveSafeTrack(), UpdateAircraftSpeed(), UpdateTownGrowRate(), UpdateTrainSpeed(), OrdersWindow::UpdateWidgetSize(), YapfRoadVehicleChooseTrack(), YapfRoadVehicleFindNearestDepot(), YapfShipChooseTrack(), YapfTrainCheckReverse(), YapfTrainChooseTrack(), YapfTrainFindNearestDepot(), and YapfTrainFindNearestSafeTile().

GameSettings _settings_newgame

The settings values that are used for new games and/or modified in config file.

Definition at line 73 of file settings.cpp.

Referenced by _GenerateWorld(), AIConfigWindow::DrawWidget(), AIConfigWindow::OnClick(), AISettingsWindow::OnClick(), AIConfigWindow::OnInvalidateData(), AIConfigWindow::SetStringParameters(), and StartScenario().