src/settings_internal.h
author terom@frrb.lan
Fri, 19 Dec 2008 01:38:09 +0200
changeset 10439 50f056aa3024
parent 9996 fceaf224b2f0
permissions -rw-r--r--
industries, unmoveables... everything but the landscape
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 1739
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 1739
diff changeset
     2
8208
3d0590aa2124 (svn r11771) -Codechange: split settings.h into better separated headers.
rubidium
parents: 8131
diff changeset
     3
/** @file settings_internal.h Functions and types used internally for the settings configurations. */
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6355
diff changeset
     4
8208
3d0590aa2124 (svn r11771) -Codechange: split settings.h into better separated headers.
rubidium
parents: 8131
diff changeset
     5
#ifndef SETTINGS_INTERNAL_H
3d0590aa2124 (svn r11771) -Codechange: split settings.h into better separated headers.
rubidium
parents: 8131
diff changeset
     6
#define SETTINGS_INTERNAL_H
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     7
3115
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
     8
#include "saveload.h"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8208
diff changeset
     9
#include "settings_type.h"
3115
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    10
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    11
/** Convention/Type of settings. This is then further specified if necessary
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    12
 * with the SLE_ (SLE_VAR/SLE_FILE) enums in saveload.h
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    13
 * @see VarTypes
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    14
 * @see SettingDescBase */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    15
enum SettingDescTypeLong {
2972
1eacb2fc37ae (svn r3547) - [Patches]: do some general cleanup, commentarization before starting actual work. This patch contains no functional changes (I hope). It might break GPMI-builds though when trying to join a trunk/ network game or vice versa. To solve, you can change the order of the first 8 enums in SettingDescType. I think that'll work.
Darkvater
parents: 2307
diff changeset
    16
	/* 4 bytes allocated a maximum of 16 types for GenericType */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    17
	SDT_BEGIN       = 0,
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6355
diff changeset
    18
	SDT_NUMX        = 0, ///< any number-type
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6355
diff changeset
    19
	SDT_BOOLX       = 1, ///< a boolean number
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6355
diff changeset
    20
	SDT_ONEOFMANY   = 2, ///< bitmasked number where only ONE bit may be set
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6355
diff changeset
    21
	SDT_MANYOFMANY  = 3, ///< bitmasked number where MULTIPLE bits may be set
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6355
diff changeset
    22
	SDT_INTLIST     = 4, ///< list of integers seperated by a comma ','
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6355
diff changeset
    23
	SDT_STRING      = 5, ///< string with a pre-allocated buffer
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    24
	SDT_END,
3115
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    25
	/* 10 more possible primitives */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    26
};
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    27
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    28
template <> struct EnumPropsT<SettingDescTypeLong> : MakeEnumPropsT<SettingDescTypeLong, byte, SDT_BEGIN, SDT_END, SDT_END> {};
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    29
typedef TinyEnumT<SettingDescTypeLong> SettingDescType;
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    30
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    31
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    32
enum SettingGuiFlagLong {
3115
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    33
	/* 8 bytes allocated for a maximum of 8 flags
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    34
	 * Flags directing saving/loading of a variable */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    35
	SGF_NONE = 0,
3115
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    36
	SGF_0ISDISABLED  = 1 << 0, ///< a value of zero means the feature is disabled
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    37
	SGF_NOCOMMA      = 1 << 1, ///< number without any thousand seperators (no formatting)
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    38
	SGF_MULTISTRING  = 1 << 2, ///< the value represents a limited number of string-options (internally integer)
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    39
	SGF_NETWORK_ONLY = 1 << 3, ///< this setting only applies to network games
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    40
	SGF_CURRENCY     = 1 << 4, ///< the number represents money, so when reading value multiply by exchange rate
7901
6e8ab6c5473d (svn r11452) -Change: do not allow configuration changes, that NewGRFs can directly use to change their behaviour, during network games as this can cause desyncs.
rubidium
parents: 6429
diff changeset
    41
	SGF_NO_NETWORK   = 1 << 5, ///< this setting does not apply to network games; it may not be changed during the game
9359
3a8554ac1cb8 (svn r13256) -Codechange: merge the OPTS and PATS chuncks.
rubidium
parents: 9354
diff changeset
    42
	SGF_NEWGAME_ONLY = 1 << 6, ///< this setting cannot be changed in inside a game
3a8554ac1cb8 (svn r13256) -Codechange: merge the OPTS and PATS chuncks.
rubidium
parents: 9354
diff changeset
    43
	SGF_END          = 1 << 7,
3115
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    44
};
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    45
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    46
DECLARE_ENUM_AS_BIT_SET(SettingGuiFlagLong);
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    47
template <> struct EnumPropsT<SettingGuiFlagLong> : MakeEnumPropsT<SettingGuiFlagLong, byte, SGF_NONE, SGF_END, SGF_END> {};
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    48
typedef TinyEnumT<SettingGuiFlagLong> SettingGuiFlag;
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    49
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    50
6355
d1232b85d407 (svn r9398) -Feature: Allow for a conversion callback system while reading configuration file, in case of wrong value.
belugas
parents: 6248
diff changeset
    51
typedef int32 OnChange(int32 var);          ///< callback prototype on data modification
d1232b85d407 (svn r9398) -Feature: Allow for a conversion callback system while reading configuration file, in case of wrong value.
belugas
parents: 6248
diff changeset
    52
typedef int32 OnConvert(const char *value); ///< callback prototype for convertion error
3115
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    53
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 5587
diff changeset
    54
struct SettingDescBase {
3115
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    55
	const char *name;       ///< name of the setting. Used in configuration file and for console
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    56
	const void *def;        ///< default value given when none is present
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    57
	SettingDescType cmd;    ///< various flags for the variable
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    58
	SettingGuiFlag flags;   ///< handles how a setting would show up in the GUI (text/currency, etc.)
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    59
	int32 min, max;         ///< minimum and maximum values
4431
7ecf73508c31 (svn r6186) -Fix [FS#309]: add an override system to the dynamically determined size of steps for numeric patch settings in the 'Configure patches' GUI.
rubidium
parents: 4344
diff changeset
    60
	int32 interval;         ///< the interval to use between settings in the 'patches' window. If interval is '0' the interval is dynamically determined
3115
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    61
	const char *many;       ///< ONE/MANY_OF_MANY: string of possible values for this type
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    62
	StringID str;           ///< (translated) string with descriptive text; gui and console
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    63
	OnChange *proc;         ///< callback procedure for when the value is changed
6355
d1232b85d407 (svn r9398) -Feature: Allow for a conversion callback system while reading configuration file, in case of wrong value.
belugas
parents: 6248
diff changeset
    64
	OnConvert *proc_cnvt;   ///< callback procedure when loading value mechanism fails
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 5587
diff changeset
    65
};
705
71cf9f0d7e7f (svn r1157) Enhanced the config file (openttd.cfg) to use another section type. "List sections" as opposed to "variable sections" contain a list of values, separated by a new line. This is now used for the [newgrf] group. You have to edit each line in this section from e.g. "0 = firstset.grf" to only "firstset.grf".
dominik
parents: 543
diff changeset
    66
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 5587
diff changeset
    67
struct SettingDesc {
3116
b125bf75b4b0 (svn r3720) - [2/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This second part gets rid of the old SettingDesc structures and updates them with the unified types. These new settings are heavily macro'd, which should make it easy to add/edit entries within sections.
Darkvater
parents: 3115
diff changeset
    68
	SettingDescBase desc;   ///< Settings structure (going to configuration file)
3115
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    69
	SaveLoad save;          ///< Internal structure (going to savegame, parts to config)
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 5587
diff changeset
    70
};
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    71
3115
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    72
/* NOTE: The only difference between SettingDesc and SettingDescGlob is
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    73
 * that one uses global variables as a source and the other offsets
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    74
 * in a struct which are bound to a certain variable during runtime.
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    75
 * The only way to differentiate between these two is to check if an object
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    76
 * has been passed to the function or not. If not, then it is a global variable
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    77
 * and save->variable has its address, otherwise save->variable only holds the
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    78
 * offset in a certain struct */
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    79
typedef SettingDesc SettingDescGlobVarList;
24c7e92baa31 (svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
Darkvater
parents: 3020
diff changeset
    80
3247
ede7a53941b2 (svn r3930) - [Patches] Change the GUI-patch options from indeces to string representations. Not only makes this the part more humanly readable, but saves us from rewriting the whole index when a patch is added/removed/changed
Darkvater
parents: 3118
diff changeset
    81
const SettingDesc *GetPatchFromName(const char *name, uint *i);
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9359
diff changeset
    82
bool SetPatchValue(uint index, int32 value);
9426
a77c8a4abcf5 (svn r13341) -Codechange: make most of the network settings configurable via the patch command.
rubidium
parents: 9413
diff changeset
    83
bool SetPatchValue(uint index, const char *value);
1739
4c8fb3905cbd (svn r2243) -Fix: Rework of console. Use 'help command|variable' to get help about it. You can assign variables with =, ++, --, or just new value. Console parser is now lenient towards typed spaces, and more robust in general (at least readable). Removed the 'set' command, instead implemented all such variables as 'variables'.
Darkvater
parents: 759
diff changeset
    84
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    85
#endif /* SETTINGS_H */