settings_internal.h

Go to the documentation of this file.
00001 /* $Id: settings_internal.h 17644 2009-09-26 17:43:06Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef SETTINGS_INTERNAL_H
00013 #define SETTINGS_INTERNAL_H
00014 
00015 #include "saveload/saveload.h"
00016 #include "settings_type.h"
00017 
00022 enum SettingDescTypeLong {
00023   /* 4 bytes allocated a maximum of 16 types for GenericType */
00024   SDT_BEGIN       = 0,
00025   SDT_NUMX        = 0, 
00026   SDT_BOOLX       = 1, 
00027   SDT_ONEOFMANY   = 2, 
00028   SDT_MANYOFMANY  = 3, 
00029   SDT_INTLIST     = 4, 
00030   SDT_STRING      = 5, 
00031   SDT_END,
00032   /* 10 more possible primitives */
00033 };
00034 typedef SimpleTinyEnumT<SettingDescTypeLong, byte> SettingDescType;
00035 
00036 
00037 enum SettingGuiFlagLong {
00038   /* 1 byte allocated for a maximum of 8 flags
00039    * Flags directing saving/loading of a variable */
00040   SGF_NONE = 0,
00041   SGF_0ISDISABLED  = 1 << 0, 
00042   SGF_NOCOMMA      = 1 << 1, 
00043   SGF_MULTISTRING  = 1 << 2, 
00044   SGF_NETWORK_ONLY = 1 << 3, 
00045   SGF_CURRENCY     = 1 << 4, 
00046   SGF_NO_NETWORK   = 1 << 5, 
00047   SGF_NEWGAME_ONLY = 1 << 6, 
00048   SGF_SCENEDIT_TOO = 1 << 7, 
00049   SGF_PER_COMPANY  = 1 << 8, 
00050 };
00051 DECLARE_ENUM_AS_BIT_SET(SettingGuiFlagLong);
00052 typedef SimpleTinyEnumT<SettingGuiFlagLong, uint16> SettingGuiFlag;
00053 
00054 
00055 typedef bool OnChange(int32 var);           
00056 typedef int32 OnConvert(const char *value); 
00057 
00058 struct SettingDescBase {
00059   const char *name;       
00060   const void *def;        
00061   SettingDescType cmd;    
00062   SettingGuiFlag flags;   
00063   int32 min;              
00064   uint32 max;             
00065   int32 interval;         
00066   const char *many;       
00067   StringID str;           
00068   OnChange *proc;         
00069   OnConvert *proc_cnvt;   
00070 };
00071 
00072 struct SettingDesc {
00073   SettingDescBase desc;   
00074   SaveLoad save;          
00075 };
00076 
00077 /* NOTE: The only difference between SettingDesc and SettingDescGlob is
00078  * that one uses global variables as a source and the other offsets
00079  * in a struct which are bound to a certain variable during runtime.
00080  * The only way to differentiate between these two is to check if an object
00081  * has been passed to the function or not. If not, then it is a global variable
00082  * and save->variable has its address, otherwise save->variable only holds the
00083  * offset in a certain struct */
00084 typedef SettingDesc SettingDescGlobVarList;
00085 
00086 const SettingDesc *GetSettingFromName(const char *name, uint *i);
00087 bool SetSettingValue(uint index, int32 value);
00088 bool SetSettingValue(uint index, const char *value);
00089 void SetCompanySetting(uint index, int32 value);
00090 
00091 extern VehicleDefaultSettings _old_vds;
00092 
00093 #endif /* SETTINGS_H */

Generated on Wed Dec 23 23:27:54 2009 for OpenTTD by  doxygen 1.5.6