settings.cpp File Reference

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

#include "stdafx.h"
#include "openttd.h"
#include "currency.h"
#include "screenshot.h"
#include "variables.h"
#include "network/network.h"
#include "network/network_internal.h"
#include "settings_internal.h"
#include "command_func.h"
#include "console.h"
#include "saveload.h"
#include "npf.h"
#include "yapf/yapf.h"
#include "newgrf.h"
#include "newgrf_config.h"
#include "genworld.h"
#include "rail.h"
#include "train.h"
#include "news.h"
#include "window_func.h"
#include "strings_func.h"
#include "vehicle_func.h"
#include "sound_func.h"
#include "core/alloc_func.hpp"
#include "player_func.h"
#include "spritecache.h"
#include "transparency.h"
#include "string_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 "table/strings.h"

Go to the source code of this file.

Data Structures

struct  SettingsMemoryPool
struct  IniItem
 structs describing the ini format. More...
struct  IniGroup
struct  IniFile

Defines

#define NSD_GENERAL(name, def, cmd, guiflags, min, max, interval, many, str, proc, load)   {name, (const void*)(def), {cmd}, {guiflags}, min, max, interval, many, str, proc, load}
 Settings-macro usage: The list might look daunting at first, but is in general easy to understand.
#define SDTG_GENERAL(name, sdt_cmd, sle_cmd, type, flags, guiflags, var, length, def, min, max, interval, full, str, proc, from, to)   {NSD_GENERAL(name, def, sdt_cmd, guiflags, min, max, interval, full, str, proc, NULL), SLEG_GENERAL(sle_cmd, var, type | flags, length, from, to)}
#define SDTG_CONDVAR(name, type, flags, guiflags, var, def, min, max, interval, str, proc, from, to)   SDTG_GENERAL(name, SDT_NUMX, SL_VAR, type, flags, guiflags, var, 0, def, min, max, interval, NULL, str, proc, from, to)
#define SDTG_VAR(name, type, flags, guiflags, var, def, min, max, interval, str, proc)   SDTG_CONDVAR(name, type, flags, guiflags, var, def, min, max, interval, str, proc, 0, SL_MAX_VERSION)
#define SDTG_CONDBOOL(name, flags, guiflags, var, def, str, proc, from, to)   SDTG_GENERAL(name, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, var, 0, def, 0, 1, 0, NULL, str, proc, from, to)
#define SDTG_BOOL(name, flags, guiflags, var, def, str, proc)   SDTG_CONDBOOL(name, flags, guiflags, var, def, str, proc, 0, SL_MAX_VERSION)
#define SDTG_CONDLIST(name, type, length, flags, guiflags, var, def, str, proc, from, to)   SDTG_GENERAL(name, SDT_INTLIST, SL_ARR, type, flags, guiflags, var, length, def, 0, 0, 0, NULL, str, proc, from, to)
#define SDTG_LIST(name, type, flags, guiflags, var, def, str, proc)   SDTG_GENERAL(name, SDT_INTLIST, SL_ARR, type, flags, guiflags, var, lengthof(var), def, 0, 0, 0, NULL, str, proc, 0, SL_MAX_VERSION)
#define SDTG_CONDSTR(name, type, length, flags, guiflags, var, def, str, proc, from, to)   SDTG_GENERAL(name, SDT_STRING, SL_STR, type, flags, guiflags, var, length, def, 0, 0, 0, NULL, str, proc, from, to)
#define SDTG_STR(name, type, flags, guiflags, var, def, str, proc)   SDTG_GENERAL(name, SDT_STRING, SL_STR, type, flags, guiflags, var, lengthof(var), def, 0, 0, 0, NULL, str, proc, 0, SL_MAX_VERSION)
#define SDTG_CONDOMANY(name, type, flags, guiflags, var, def, max, full, str, proc, from, to)   SDTG_GENERAL(name, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, var, 0, def, 0, max, 0, full, str, proc, from, to)
#define SDTG_OMANY(name, type, flags, guiflags, var, def, max, full, str, proc)   SDTG_CONDOMANY(name, type, flags, guiflags, var, def, max, full, str, proc, 0, SL_MAX_VERSION)
#define SDTG_CONDMMANY(name, type, flags, guiflags, var, def, full, str, proc, from, to)   SDTG_GENERAL(name, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, var, 0, def, 0, 0, 0, full, str, proc, from, to)
#define SDTG_MMANY(name, type, flags, guiflags, var, def, full, str, proc)   SDTG_CONDMMANY(name, type, flags, guiflags, var, def, full, str, proc, 0, SL_MAX_VERSION)
#define SDTG_CONDNULL(length, from, to)   {{"", NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, NULL, NULL}, SLEG_CONDNULL(length, from, to)}
#define SDTG_END()   {{NULL, NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, NULL, NULL}, SLEG_END()}
#define SDT_GENERAL(name, sdt_cmd, sle_cmd, type, flags, guiflags, base, var, length, def, min, max, interval, full, str, proc, load, from, to)   {NSD_GENERAL(name, def, sdt_cmd, guiflags, min, max, interval, full, str, proc, load), SLE_GENERAL(sle_cmd, base, var, type | flags, length, from, to)}
#define SDT_CONDVAR(base, var, type, from, to, flags, guiflags, def, min, max, interval, str, proc)   SDT_GENERAL(#var, SDT_NUMX, SL_VAR, type, flags, guiflags, base, var, 1, def, min, max, interval, NULL, str, proc, NULL, from, to)
#define SDT_VAR(base, var, type, flags, guiflags, def, min, max, interval, str, proc)   SDT_CONDVAR(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, min, max, interval, str, proc)
#define SDT_CONDBOOL(base, var, from, to, flags, guiflags, def, str, proc)   SDT_GENERAL(#var, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, base, var, 1, def, 0, 1, 0, NULL, str, proc, NULL, from, to)
#define SDT_BOOL(base, var, flags, guiflags, def, str, proc)   SDT_CONDBOOL(base, var, 0, SL_MAX_VERSION, flags, guiflags, def, str, proc)
#define SDT_CONDLIST(base, var, type, from, to, flags, guiflags, def, str, proc)   SDT_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, base, var, lengthof(((base*)8)->var), def, 0, 0, 0, NULL, str, proc, NULL, from, to)
#define SDT_LIST(base, var, type, flags, guiflags, def, str, proc)   SDT_CONDLIST(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, str, proc)
#define SDT_CONDLISTO(base, var, length, type, from, to, flags, guiflags, def, str, proc)   SDT_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, base, var, length, def, 0, 0, 0, NULL, str, proc, NULL, from, to)
#define SDT_CONDSTR(base, var, type, from, to, flags, guiflags, def, str, proc)   SDT_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, base, var, lengthof(((base*)8)->var), def, 0, 0, 0, NULL, str, proc, NULL, from, to)
#define SDT_STR(base, var, type, flags, guiflags, def, str, proc)   SDT_CONDSTR(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, str, proc)
#define SDT_CONDSTRO(base, var, length, type, from, to, flags, def, str, proc)   SDT_GENERAL(#var, SDT_STRING, SL_STR, type, flags, 0, base, var, length, def, 0, 0, NULL, str, proc, from, to)
#define SDT_CONDCHR(base, var, from, to, flags, guiflags, def, str, proc)   SDT_GENERAL(#var, SDT_STRING, SL_VAR, SLE_CHAR, flags, guiflags, base, var, 1, def, 0, 0, 0, NULL, str, proc, NULL, from, to)
#define SDT_CHR(base, var, flags, guiflags, def, str, proc)   SDT_CONDCHR(base, var, 0, SL_MAX_VERSION, flags, guiflags, def, str, proc)
#define SDT_CONDOMANY(base, var, type, from, to, flags, guiflags, def, max, full, str, proc, load)   SDT_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, base, var, 1, def, 0, max, 0, full, str, proc, load, from, to)
#define SDT_OMANY(base, var, type, flags, guiflags, def, max, full, str, proc, load)   SDT_CONDOMANY(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, max, full, str, proc, load)
#define SDT_CONDMMANY(base, var, type, from, to, flags, guiflags, def, full, str, proc)   SDT_GENERAL(#var, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, base, var, 1, def, 0, 0, 0, full, str, proc, NULL, from, to)
#define SDT_MMANY(base, var, type, flags, guiflags, def, full, str, proc)   SDT_CONDMMANY(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, full, str, proc)
#define SDT_CONDNULL(length, from, to)   {{"", NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, NULL, NULL}, SLE_CONDNULL(length, from, to)}
#define SDT_END()   {{NULL, NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, NULL, NULL}, SLE_END()}
#define S   SLF_SAVE_NO | SLF_NETWORK_NO
#define C   SLF_CONFIG_NO
#define N   SLF_NETWORK_NO
#define D0   SGF_0ISDISABLED
#define NC   SGF_NOCOMMA
#define MS   SGF_MULTISTRING
#define NO   SGF_NETWORK_ONLY
#define CR   SGF_CURRENCY
#define NN   SGF_NO_NETWORK
#define EXTERNAL_PLAYER   "timidity"

Typedefs

typedef const char * SettingListCallbackProc (const IniItem *item, uint index)
typedef void SettingDescProc (IniFile *ini, const SettingDesc *desc, const char *grpname, void *object)
typedef void SettingDescProcList (IniFile *ini, const char *grpname, char **list, uint len, SettingListCallbackProc proc)

Functions

static void pool_init (SettingsMemoryPool **pool)
static void * pool_alloc (SettingsMemoryPool **pool, uint size)
static void * pool_strdup (SettingsMemoryPool **pool, const char *mem, uint size)
static void pool_free (SettingsMemoryPool **pool)
static bool IsSignedVarMemType (VarType vt)
static SettingsMemoryPool * pool_new (uint minsize)
static IniFile * ini_alloc ()
 allocate an inifile object
static IniGroup * ini_group_alloc (IniFile *ini, const char *grpt, int len)
 allocate an ini group object
static IniItemini_item_alloc (IniGroup *group, const char *name, int len)
static IniFile * ini_load (const char *filename)
 load an ini file into the "abstract" format
static IniGroup * ini_getgroup (IniFile *ini, const char *name, int len)
 lookup a group or make a new one
static IniItemini_getitem (IniGroup *group, const char *name, bool create)
 lookup an item or make a new one
static bool ini_save (const char *filename, IniFile *ini)
 save ini file from the "abstract" format.
static void ini_free (IniFile *ini)
static int lookup_oneofmany (const char *many, const char *one, int onelen)
 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 void *array, int nelems, VarType type)
 Convert an integer-array (intlist) to a string representation.
static void make_oneofmany (char *buf, const char *many, int id)
 Convert a ONEofMANY structure to a string representation.
static void make_manyofmany (char *buf, const char *many, uint32 x)
 Convert a MANYofMANY structure to a string representation.
static const void * string_to_val (const SettingDescBase *desc, const char *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, char **list, uint len, SettingListCallbackProc proc)
 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, char **list, uint len, SettingListCallbackProc proc)
 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 int32 v_PositionMainToolbar (int32 p1)
static int32 AiNew_PatchActive_Warning (int32 p1)
static int32 Ai_In_Multiplayer_Warning (int32 p1)
static int32 PopulationInLabelActive (int32 p1)
static int32 RedrawScreen (int32 p1)
static int32 InValidateDetailsWindow (int32 p1)
static int32 InvalidateStationBuildWindow (int32 p1)
static int32 InvalidateBuildIndustryWindow (int32 p1)
static int32 UpdateConsists (int32 p1)
static int32 CheckInterval (int32 p1)
static int32 EngineRenewUpdate (int32 p1)
static int32 EngineRenewMonthsUpdate (int32 p1)
static int32 EngineRenewMoneyUpdate (int32 p1)
static int32 RealisticAccelerationChanged (int32 p1)
static int32 DragSignalsDensityChanged (int32)
static int32 CheckTownLayout (int32 p1)
 Check for right TownLayout usage in editor mode.
static int32 ConvertLandscape (const char *value)
 Conversion callback for _gameopt_settings.landscape It converts (or try) between old values and the new ones, without loosing initial setting of the user.
static uint NewsDisplayLoadConfig (IniFile *ini, const char *grpname)
static GRFConfig * GRFLoadConfig (IniFile *ini, const char *grpname, bool is_static)
static void NewsDisplaySaveConfig (IniFile *ini, const char *grpname, uint news_display)
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)
void CheckDifficultyLevels ()
 Checks the difficulty levels read from the configuration and forces them to be correct when invalid.
void LoadFromConfig ()
 Load the values from the configuration files.
void SaveToConfig ()
 Save the values to the configuration file.
static const SettingDesc * GetSettingDescription (uint index)
CommandCost CmdChangePatchSetting (TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 Network-safe changing of patch-settings (server-only).
bool SetPatchValue (uint index, const Patches *object, int32 value)
 Top function to save the new value of an element of the Patches struct.
const SettingDesc * GetPatchFromName (const char *name, uint *i)
bool IConsoleSetPatchSetting (const char *name, int32 value)
void IConsoleGetPatchSetting (const char *name)
void IConsoleListPatches ()
static void LoadSettings (const SettingDesc *osd, void *object)
 Save and load handler for patches/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 patches/settings.
static void SaveSettingsGlobList (const SettingDescGlobVarList *sdg)
 Savehandler for a list of global variables.
static void Load_OPTS ()
static void Save_OPTS ()
static void Load_PATS ()
static void Save_PATS ()
void CheckConfig ()
void UpdatePatches ()

Variables

GameOptions _opt
GameOptions _opt_newgame
GameOptions * _opt_ptr
Patches _patches
Patches _patches_newgame
 The patch values that are used for new games and/or modified in config file.
static const SettingDesc _music_settings []
static const SettingDescGlobVarList _misc_settings []
static const SettingDesc _gameopt_settings []
const SettingDesc _patch_settings []
static const SettingDesc _currency_settings []
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 four 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. Defining the data structures that go into the configuration. These include for example the _patches struct, but also network-settings, banlists, newgrf, etc. There are a lot of helper macros available for the various types, and also saving/loading of these settings in a savegame is handled inside these structures.
  3. 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.
  4. Handle saving/loading of the PATS chunk inside the savegame.
See also:
SettingDesc

SaveLoad

Definition in file settings.cpp.


Define Documentation

#define NSD_GENERAL ( name,
def,
cmd,
guiflags,
min,
max,
interval,
many,
str,
proc,
load   )     {name, (const void*)(def), {cmd}, {guiflags}, min, max, interval, many, str, proc, load}

Settings-macro usage: The list might look daunting at first, but is in general easy to understand.

We have two types of list: 1. SDTG_something 2. SDT_something The 'G' stands for global, so this is the one you will use for a SettingDescGlobVarList section meaning global variables. The other uses a Base/Offset and runtime variable selection mechanism, known from the saveload convention (it also has global so it should not be hard). Of each type there are again two versions, the normal one and one prefixed with 'COND'. COND means that the setting is only valid in certain savegame versions (since patches are saved to the savegame, this bookkeeping is necessary. Now there are a lot of types. Easy ones are:

  • VAR: any number type, 'type' field specifies what number. eg int8 or uint32
  • BOOL: a boolean number type
  • STR: a string or character. 'type' field specifies what string. Normal, string, or quoted A bit more difficult to use are MMANY (meaning ManyOfMany) and OMANY (OneOfMany) These are actually normal numbers, only bitmasked. In MMANY several bits can be set, in the other only one. The most complex type is INTLIST. This is basically an array of numbers. If the intlist is only valid in certain savegame versions because for example it has grown in size its length cannot be automatically be calculated so use SDT(G)_CONDLISTO() meaning Old. If nothing fits you, you can use the GENERAL macros, but it exposes the internal structure somewhat so it needs a little looking. There are _NULL() macros as well, these fill up space so you can add more patches there (in place) and you DON'T have to increase the savegame version.

While reading values from openttd.cfg, some values may not be converted properly, for any kind of reasons. In order to allow a process of self-cleaning mechanism, a callback procedure is made available. You will have to supply the function, which will work on a string, one function per patch. And of course, enable the callback param on the appropriate macro.

Definition at line 991 of file settings.cpp.


Function Documentation

static int32 CheckTownLayout ( int32  p1  )  [static]

Check for right TownLayout usage in editor mode.

The No Road mode is not desirable since towns have to be able to grow. If a user desires to have a town with no road, he can easily remove them himself. This would create less confusion

Parameters:
p1 unused
Returns:
always 0

Definition at line 1232 of file settings.cpp.

References TL_NO_ROADS, and TL_ORIGINAL.

CommandCost CmdChangePatchSetting ( TileIndex  tile,
uint32  flags,
uint32  p1,
uint32  p2 
)

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

Parameters:
tile unused
flags operation to perform
p1 the index of the patch in the SettingDesc array which identifies it
p2 the new value for the patch The new value is properly clamped to its minimum/maximum when setting
See also:
_patch_settings

Definition at line 1881 of file settings.cpp.

References _networking, _patches_newgame, CMD_ERROR, DC_EXEC, GetVariableAddress(), ReadValue(), SGF_NETWORK_ONLY, SGF_NO_NETWORK, SlIsObjectCurrentlyValid(), and Write_ValidateSetting().

static int32 ConvertLandscape ( const char *  value  )  [static]

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

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

Definition at line 1247 of file settings.cpp.

References lookup_oneofmany().

static void ini_load_setting_list ( IniFile *  ini,
const char *  grpname,
char **  list,
uint  len,
SettingListCallbackProc  proc 
) [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 pointer to an string(pointer) array that will store the parsed entries of the given section
len the maximum number of items available for the above list
proc callback function that can override how the values are stored inside the list

Definition at line 893 of file settings.cpp.

References ini_getgroup(), IniItem::name, 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 702 of file settings.cpp.

References SaveLoad::conv, GetVariableAddress(), ini_getgroup(), ini_getitem(), SaveLoad::length, load_intlist(), SDT_BOOLX, SDT_INTLIST, SDT_MANYOFMANY, SDT_NUMX, SDT_ONEOFMANY, SDT_STRING, SLE_VAR_STR, SLE_VAR_STRB, SLE_VAR_STRBQ, SLE_VAR_STRQ, SlIsObjectCurrentlyValid(), string_to_val(), IniItem::value, SaveLoad::version_from, SaveLoad::version_to, and Write_ValidateSetting().

Referenced by LoadFromConfig().

static bool ini_save ( const char *  filename,
IniFile *  ini 
) [static]

save ini file from the "abstract" format.

Definition at line 357 of file settings.cpp.

References IniItem::comment, IGT_LIST, IniItem::name, IniItem::next, and IniItem::value.

Referenced by SaveToConfig().

static void ini_save_setting_list ( IniFile *  ini,
const char *  grpname,
char **  list,
uint  len,
SettingListCallbackProc  proc 
) [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
len the maximum number of items available for the above list
proc callback function that can will provide the source data if defined

Definition at line 921 of file settings.cpp.

References ini_getgroup(), IniItem::name, IniItem::next, and IniItem::value.

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

References buf, SaveLoad::conv, GetVariableAddress(), ini_getgroup(), ini_getitem(), SaveLoad::length, make_intlist(), make_manyofmany(), make_oneofmany(), ReadValue(), SDT_BOOLX, SDT_INTLIST, SDT_MANYOFMANY, SDT_NUMX, SDT_ONEOFMANY, SDT_STRING, SLE_VAR_STR, SLE_VAR_STRB, SLE_VAR_STRBQ, SLE_VAR_STRQ, SLF_CONFIG_NO, SlIsObjectCurrentlyValid(), 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 486 of file settings.cpp.

References parse_intlist().

Referenced by ini_load_settings().

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

Save and load handler for patches/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 2018 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 2032 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 432 of file settings.cpp.

References lookup_oneofmany(), and SetBit().

Referenced by string_to_val().

static int lookup_oneofmany ( const char *  many,
const char *  one,
int  onelen 
) [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 404 of file settings.cpp.

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

static void make_intlist ( char *  buf,
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
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 525 of file settings.cpp.

Referenced by ini_save_settings().

static void make_manyofmany ( char *  buf,
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
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 574 of file settings.cpp.

References HasBit().

Referenced by ini_save_settings().

static void make_oneofmany ( char *  buf,
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
many the full-domain string of possible values
id the value of the variable and whose string-representation must be found

Definition at line 549 of file settings.cpp.

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

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

Save and load handler for patches/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 2041 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 2062 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 1772 of file settings.cpp.

References ini_getgroup(), and IniItem::next.

Referenced by SaveToConfig().

bool SetPatchValue ( uint  index,
const Patches *  object,
int32  value 
)

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

Parameters:
index offset in the SettingDesc array of the Patches struct which identifies the patch member we want to change
object pointer to a valid patches struct that has its settings change. This only affects patch-members that are not needed to be the same on all clients in a network game.
value new value of the patch

Definition at line 1910 of file settings.cpp.

References _networking, _patches_newgame, CMD_CHANGE_PATCH_SETTING, DoCommandP(), GetVariableAddress(), ReadValue(), SLF_NETWORK_NO, and Write_ValidateSetting().

Referenced by PatchesSelectionWndProc().

static const void* string_to_val ( const SettingDescBase *  desc,
const char *  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
str input string that will be parsed based on the type of desc
Returns:
return the parsed value of the setting

Definition at line 605 of file settings.cpp.

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

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

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

Referenced by CmdChangePatchSetting(), ini_load_settings(), and SetPatchValue().


Variable Documentation

const SettingDesc _currency_settings[] [static]

Initial value:

 {
  SDT_VAR(CurrencySpec, rate,    SLE_UINT16, S, 0,  1, 0, 100, 0, STR_NULL, NULL),
  SDT_CHR(CurrencySpec, separator,           S, 0,        ".",    STR_NULL, NULL),
  SDT_VAR(CurrencySpec, to_euro,  SLE_INT32, S, 0,  0, 0, 3000, 0, STR_NULL, NULL),
  SDT_STR(CurrencySpec, prefix,   SLE_STRBQ, S, 0,       NULL,    STR_NULL, NULL),
  SDT_STR(CurrencySpec, suffix,   SLE_STRBQ, S, 0, " credits",    STR_NULL, NULL),

}

Definition at line 1636 of file settings.cpp.

const SettingDesc _gameopt_settings[] [static]

Initial value:

 {
  
  SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, SLE_FILE_I16 | SLE_VAR_U16, 0, 0, GameOptions, diff, 17, 0, 0, 0, 0, NULL, STR_NULL, NULL, NULL, 0, 3),
  SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, SLE_UINT16, 0, 0, GameOptions, diff, 18, 0, 0, 0, 0, NULL, STR_NULL, NULL, NULL, 4, SL_MAX_VERSION),
      SDT_VAR(GameOptions, diff_level, SLE_UINT8, 0, 0, 0, 0,  3, 0, STR_NULL, NULL),
    SDT_OMANY(GameOptions, currency,  SLE_UINT8, N, 0, 0, CUSTOM_CURRENCY_ID, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SIT|SEK|YTL|SKK|BRR|custom", STR_NULL, NULL, NULL),
    SDT_OMANY(GameOptions, units,     SLE_UINT8, N, 0, 1,     2, "imperial|metric|si", STR_NULL, NULL, NULL),
  
    SDT_OMANY(GameOptions, town_name, SLE_UINT8, 0, 0, 0,   255, "english|french|german|american|latin|silly|swedish|dutch|finnish|polish|slovakish|norwegian|hungarian|austrian|romanian|czech|swiss|danish|turkish|italian|catalan", STR_NULL, NULL, NULL),
    SDT_OMANY(GameOptions, landscape, SLE_UINT8, 0, 0, 0,     3, "temperate|arctic|tropic|toyland", STR_NULL, NULL, ConvertLandscape),
      SDT_VAR(GameOptions, snow_line, SLE_UINT8, 0, 0, 7 * TILE_HEIGHT, 2 * TILE_HEIGHT, 13 * TILE_HEIGHT, 0, STR_NULL, NULL),
  SDT_CONDOMANY(GameOptions,autosave, SLE_UINT8, 0, 22,             N, 0, 0, 0, "", STR_NULL, NULL, NULL),
  SDT_CONDOMANY(GameOptions,autosave, SLE_UINT8,23, SL_MAX_VERSION, S, 0, 1, 4, "off|monthly|quarterly|half year|yearly", STR_NULL, NULL, NULL),
    SDT_OMANY(GameOptions, road_side, SLE_UINT8, 0, 0, 1,   1, "left|right", STR_NULL, NULL, NULL),

}

Definition at line 1347 of file settings.cpp.

const SettingDescGlobVarList _misc_settings[] [static]

Initial value:

 {
  SDTG_MMANY("display_opt",     SLE_UINT8, S, 0, _display_opt,       (1 << DO_SHOW_TOWN_NAMES | 1 << DO_SHOW_STATION_NAMES | 1 << DO_SHOW_SIGNS | 1 << DO_FULL_ANIMATION | 1 << DO_FULL_DETAIL | 1 << DO_WAYPOINTS), "SHOW_TOWN_NAMES|SHOW_STATION_NAMES|SHOW_SIGNS|FULL_ANIMATION||FULL_DETAIL|WAYPOINTS", STR_NULL, NULL),
   SDTG_BOOL("news_ticker_sound",          S, 0, _news_ticker_sound,     true,    STR_NULL, NULL),
   SDTG_BOOL("fullscreen",                 S, 0, _fullscreen,           false,    STR_NULL, NULL),
    SDTG_STR("videodriver",      SLE_STRB,C|S,0, _ini_videodriver,       NULL,    STR_NULL, NULL),
    SDTG_STR("musicdriver",      SLE_STRB,C|S,0, _ini_musicdriver,       NULL,    STR_NULL, NULL),
    SDTG_STR("sounddriver",      SLE_STRB,C|S,0, _ini_sounddriver,       NULL,    STR_NULL, NULL),
    SDTG_STR("blitter",          SLE_STRB,C|S,0, _ini_blitter,           NULL,    STR_NULL, NULL),
    SDTG_STR("language",         SLE_STRB, S, 0, _dynlang.curr_file,     NULL,    STR_NULL, NULL),
   SDTG_LIST("resolution",     SLE_UINT16, S, 0, _cur_resolution,   "640,480",    STR_NULL, NULL),
    SDTG_STR("screenshot_format",SLE_STRB, S, 0, _screenshot_format_name,NULL,    STR_NULL, NULL),
    SDTG_STR("savegame_format",  SLE_STRB, S, 0, _savegame_format,       NULL,    STR_NULL, NULL),
   SDTG_BOOL("rightclick_emulate",         S, 0, _rightclick_emulate,   false,    STR_NULL, NULL),











    SDTG_VAR("sprite_cache_size",SLE_UINT, S, 0, _sprite_cache_size,     4, 1, 64, 0, STR_NULL, NULL),
    SDTG_VAR("player_face",    SLE_UINT32, S, 0, _player_face,      0,0,0xFFFFFFFF,0, STR_NULL, NULL),
    SDTG_VAR("transparency_options", SLE_UINT, S, 0, _transparency_opt,  0,0,0x1FF,0, STR_NULL, NULL),
    SDTG_VAR("transparency_locks", SLE_UINT, S, 0, _transparency_lock,   0,0,0x1FF,0, STR_NULL, NULL),

}

Definition at line 1285 of file settings.cpp.

const SettingDesc _music_settings[] [static]

Initial value:

 {
   SDT_VAR(MusicFileSettings, playlist,   SLE_UINT8, S, 0,   0, 0,   5, 1,  STR_NULL, NULL),
   SDT_VAR(MusicFileSettings, music_vol,  SLE_UINT8, S, 0, 127, 0, 127, 1,  STR_NULL, NULL),
   SDT_VAR(MusicFileSettings, effect_vol, SLE_UINT8, S, 0, 127, 0, 127, 1,  STR_NULL, NULL),
  SDT_LIST(MusicFileSettings, custom_1,   SLE_UINT8, S, 0, NULL,            STR_NULL, NULL),
  SDT_LIST(MusicFileSettings, custom_2,   SLE_UINT8, S, 0, NULL,            STR_NULL, NULL),
  SDT_BOOL(MusicFileSettings, playing,               S, 0, true,            STR_NULL, NULL),
  SDT_BOOL(MusicFileSettings, shuffle,               S, 0, false,           STR_NULL, NULL),
   SDT_STR(MusicFileSettings, extmidi,     SLE_STRB, S, 0, EXTERNAL_PLAYER, STR_NULL, NULL),

}

Definition at line 1259 of file settings.cpp.

const ChunkHandler _setting_chunk_handlers[]

Initial value:

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


Generated on Wed Oct 1 17:03:30 2008 for openttd by  doxygen 1.5.6