src/settings_internal.h
author rubidium
Tue, 22 Jan 2008 21:00:30 +0000
branchNewGRF_ports
changeset 6872 1c4a4a609f85
child 10731 67db0d431d5e
permissions -rw-r--r--
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
     1
/* $Id$ */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
     2
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
     3
/** @file settings_internal.h Functions and types used internally for the settings configurations. */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
     4
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
     5
#ifndef SETTINGS_INTERNAL_H
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
     6
#define SETTINGS_INTERNAL_H
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
     7
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
     8
#include "saveload.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
     9
#include "settings_type.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    10
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    11
/** Convention/Type of settings. This is then further specified if necessary
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    12
 * with the SLE_ (SLE_VAR/SLE_FILE) enums in saveload.h
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    13
 * @see VarTypes
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    14
 * @see SettingDescBase */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    15
enum SettingDescTypeLong {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    16
	/* 4 bytes allocated a maximum of 16 types for GenericType */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    17
	SDT_BEGIN       = 0,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    18
	SDT_NUMX        = 0, ///< any number-type
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    19
	SDT_BOOLX       = 1, ///< a boolean number
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    20
	SDT_ONEOFMANY   = 2, ///< bitmasked number where only ONE bit may be set
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    21
	SDT_MANYOFMANY  = 3, ///< bitmasked number where MULTIPLE bits may be set
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    22
	SDT_INTLIST     = 4, ///< list of integers seperated by a comma ','
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    23
	SDT_STRING      = 5, ///< string with a pre-allocated buffer
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    24
	SDT_END,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    25
	/* 10 more possible primitives */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    26
};
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    27
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    28
template <> struct EnumPropsT<SettingDescTypeLong> : MakeEnumPropsT<SettingDescTypeLong, byte, SDT_BEGIN, SDT_END, SDT_END> {};
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    29
typedef TinyEnumT<SettingDescTypeLong> SettingDescType;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    30
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    31
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    32
enum SettingGuiFlagLong {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    33
	/* 8 bytes allocated for a maximum of 8 flags
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    34
	 * Flags directing saving/loading of a variable */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    35
	SGF_NONE = 0,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    36
	SGF_0ISDISABLED  = 1 << 0, ///< a value of zero means the feature is disabled
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    37
	SGF_NOCOMMA      = 1 << 1, ///< number without any thousand seperators (no formatting)
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    38
	SGF_MULTISTRING  = 1 << 2, ///< the value represents a limited number of string-options (internally integer)
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    39
	SGF_NETWORK_ONLY = 1 << 3, ///< this setting only applies to network games
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    40
	SGF_CURRENCY     = 1 << 4, ///< the number represents money, so when reading value multiply by exchange rate
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    41
	SGF_NO_NETWORK   = 1 << 5, ///< this setting does not apply to network games; it may not be changed during the game
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    42
	SGF_END          = 1 << 6,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    43
	/* 3 more possible flags */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    44
};
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    45
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    46
DECLARE_ENUM_AS_BIT_SET(SettingGuiFlagLong);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    47
template <> struct EnumPropsT<SettingGuiFlagLong> : MakeEnumPropsT<SettingGuiFlagLong, byte, SGF_NONE, SGF_END, SGF_END> {};
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    48
typedef TinyEnumT<SettingGuiFlagLong> SettingGuiFlag;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    49
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    50
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    51
typedef int32 OnChange(int32 var);          ///< callback prototype on data modification
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    52
typedef int32 OnConvert(const char *value); ///< callback prototype for convertion error
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    53
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    54
struct SettingDescBase {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    55
	const char *name;       ///< name of the setting. Used in configuration file and for console
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    56
	const void *def;        ///< default value given when none is present
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    57
	SettingDescType cmd;    ///< various flags for the variable
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    58
	SettingGuiFlag flags;   ///< handles how a setting would show up in the GUI (text/currency, etc.)
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    59
	int32 min, max;         ///< minimum and maximum values
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    60
	int32 interval;         ///< the interval to use between settings in the 'patches' window. If interval is '0' the interval is dynamically determined
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    61
	const char *many;       ///< ONE/MANY_OF_MANY: string of possible values for this type
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    62
	StringID str;           ///< (translated) string with descriptive text; gui and console
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    63
	OnChange *proc;         ///< callback procedure for when the value is changed
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    64
	OnConvert *proc_cnvt;   ///< callback procedure when loading value mechanism fails
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    65
};
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    66
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    67
struct SettingDesc {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    68
	SettingDescBase desc;   ///< Settings structure (going to configuration file)
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    69
	SaveLoad save;          ///< Internal structure (going to savegame, parts to config)
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    70
};
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    71
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    72
/* NOTE: The only difference between SettingDesc and SettingDescGlob is
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    73
 * that one uses global variables as a source and the other offsets
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    74
 * in a struct which are bound to a certain variable during runtime.
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    75
 * The only way to differentiate between these two is to check if an object
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    76
 * has been passed to the function or not. If not, then it is a global variable
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    77
 * and save->variable has its address, otherwise save->variable only holds the
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    78
 * offset in a certain struct */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    79
typedef SettingDesc SettingDescGlobVarList;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    80
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    81
enum IniGroupType {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    82
	IGT_VARIABLES = 0, ///< values of the form "landscape = hilly"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    83
	IGT_LIST      = 1, ///< a list of values, seperated by \n and terminated by the next group block
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    84
};
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    85
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    86
const SettingDesc *GetPatchFromName(const char *name, uint *i);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    87
bool SetPatchValue(uint index, const Patches *object, int32 value);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    88
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
diff changeset
    89
#endif /* SETTINGS_H */