tron@2186: /* $Id$ */ tron@2186: truelight@543: #ifndef SETTINGS_H truelight@543: #define SETTINGS_H truelight@543: Darkvater@3115: #include "saveload.h" Darkvater@3115: Darkvater@3115: /** Convention/Type of settings. This is then further specified if necessary Darkvater@3115: * with the SLE_ (SLE_VAR/SLE_FILE) enums in saveload.h Darkvater@3115: * @see VarTypes Darkvater@3115: * @see SettingDescBase */ truelight@543: enum SettingDescType { Darkvater@2972: /* 4 bytes allocated a maximum of 16 types for GenericType */ Darkvater@3115: SDT_NUMX = 0, // any number-type Darkvater@3115: SDT_BOOLX = 1, // a boolean number Darkvater@3115: SDT_ONEOFMANY = 2, // bitmasked number where only ONE bit may be set Darkvater@3115: SDT_MANYOFMANY = 3, // bitmasked number where MULTIPLE bits may be set Darkvater@3115: SDT_INTLIST = 4, // list of integers seperated by a comma ',' Darkvater@3115: SDT_STRING = 5, // string with a pre-allocated buffer Darkvater@3115: /* 10 more possible primitives */ truelight@543: }; truelight@543: Darkvater@3115: enum SettingGuiFlag { Darkvater@3115: /* 8 bytes allocated for a maximum of 8 flags Darkvater@3115: * Flags directing saving/loading of a variable */ Darkvater@3115: SGF_0ISDISABLED = 1 << 0, ///< a value of zero means the feature is disabled Darkvater@3115: SGF_NOCOMMA = 1 << 1, ///< number without any thousand seperators (no formatting) Darkvater@3115: SGF_MULTISTRING = 1 << 2, ///< the value represents a limited number of string-options (internally integer) Darkvater@3115: SGF_NETWORK_ONLY = 1 << 3, ///< this setting only applies to network games Darkvater@3115: SGF_CURRENCY = 1 << 4, ///< the number represents money, so when reading value multiply by exchange rate Darkvater@3115: /* 3 more possible flags */ Darkvater@3115: }; Darkvater@3115: Darkvater@3115: typedef int32 OnChange(int32 var); Darkvater@3115: typedef byte SettingDescType; Darkvater@3115: typedef byte SettingGuiFlag; Darkvater@3115: Darkvater@3115: typedef struct SettingDescBase { Darkvater@3115: const char *name; ///< name of the setting. Used in configuration file and for console Darkvater@3115: const void *def; ///< default value given when none is present Darkvater@3115: SettingDescType cmd; ///< various flags for the variable Darkvater@3115: SettingGuiFlag flags; ///< handles how a setting would show up in the GUI (text/currency, etc.) Darkvater@3115: int32 min, max; ///< minimum and maximum values Darkvater@3115: const char *many; ///< ONE/MANY_OF_MANY: string of possible values for this type Darkvater@3115: StringID str; ///< (translated) string with descriptive text; gui and console Darkvater@3115: OnChange *proc; ///< callback procedure for when the value is changed Darkvater@3115: } SettingDescBase; dominik@705: truelight@543: typedef struct SettingDesc { Darkvater@3116: SettingDescBase desc; ///< Settings structure (going to configuration file) Darkvater@3115: SaveLoad save; ///< Internal structure (going to savegame, parts to config) truelight@543: } SettingDesc; truelight@543: Darkvater@3115: /* NOTE: The only difference between SettingDesc and SettingDescGlob is Darkvater@3115: * that one uses global variables as a source and the other offsets Darkvater@3115: * in a struct which are bound to a certain variable during runtime. Darkvater@3115: * The only way to differentiate between these two is to check if an object Darkvater@3115: * has been passed to the function or not. If not, then it is a global variable Darkvater@3115: * and save->variable has its address, otherwise save->variable only holds the Darkvater@3115: * offset in a certain struct */ Darkvater@3115: typedef SettingDesc SettingDescGlobVarList; Darkvater@3115: Darkvater@3115: typedef enum { Darkvater@3115: IGT_VARIABLES = 0, ///< values of the form "landscape = hilly" Darkvater@3115: IGT_LIST = 1, ///< a list of values, seperated by \n and terminated by the next group block Darkvater@3115: } IniGroupType; Darkvater@3115: Darkvater@3115: /** Get the address of the variable. Which one to pick depends on the object Darkvater@3115: * pointer. If it is NULL we are dealing with global variables so the address Darkvater@3115: * is taken. If non-null only the offset is stored in the union and we need Darkvater@3115: * to add this to the address of the object */ Darkvater@3115: static inline void *ini_get_variable(const SaveLoad *sld, const void *object) Darkvater@3115: { KUDr@3584: return (object == NULL) ? sld->address : (byte*)object + (ptrdiff_t)sld->address; Darkvater@3115: } Darkvater@3115: Darkvater@1739: void IConsoleSetPatchSetting(const char *name, const char *value); Darkvater@1739: void IConsoleGetPatchSetting(const char *name); Darkvater@3247: const SettingDesc *GetPatchFromName(const char *name, uint *i); Darkvater@3118: void SetPatchValue(uint index, const Patches *object, int32 value); Darkvater@1739: truelight@543: #endif /* SETTINGS_H */