newgrf_config.h

Go to the documentation of this file.
00001 /* $Id: newgrf_config.h 23640 2011-12-20 17:57:56Z truebrain $ */
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 NEWGRF_CONFIG_H
00013 #define NEWGRF_CONFIG_H
00014 
00015 #include "strings_type.h"
00016 #include "core/alloc_type.hpp"
00017 #include "core/smallmap_type.hpp"
00018 #include "misc/countedptr.hpp"
00019 #include "fileio_type.h"
00020 
00022 enum GCF_Flags {
00023   GCF_SYSTEM,     
00024   GCF_UNSAFE,     
00025   GCF_STATIC,     
00026   GCF_COMPATIBLE, 
00027   GCF_COPY,       
00028   GCF_INIT_ONLY,  
00029   GCF_RESERVED,   
00030   GCF_INVALID,    
00031 };
00032 
00034 enum GRFStatus {
00035   GCS_UNKNOWN,      
00036   GCS_DISABLED,     
00037   GCS_NOT_FOUND,    
00038   GCS_INITIALISED,  
00039   GCS_ACTIVATED,    
00040 };
00041 
00043 enum GRFBugs {
00044   GBUG_VEH_LENGTH,        
00045   GBUG_VEH_REFIT,         
00046   GBUG_VEH_POWERED_WAGON, 
00047   GBUG_UNKNOWN_CB_RESULT, 
00048 };
00049 
00051 enum GRFListCompatibility {
00052   GLC_ALL_GOOD,   
00053   GLC_COMPATIBLE, 
00054   GLC_NOT_FOUND,  
00055 };
00056 
00058 enum GRFPalette {
00059   GRFP_USE_BIT     = 0,   
00060   GRFP_GRF_OFFSET  = 2,   
00061   GRFP_GRF_SIZE    = 2,   
00062   GRFP_BLT_OFFSET  = 4,   
00063   GRFP_BLT_SIZE    = 1,   
00064 
00065   GRFP_USE_DOS     = 0x0, 
00066   GRFP_USE_WINDOWS = 0x1, 
00067   GRFP_USE_MASK    = 0x1, 
00068 
00069   GRFP_GRF_UNSET   = 0x0 << GRFP_GRF_OFFSET,          
00070   GRFP_GRF_DOS     = 0x1 << GRFP_GRF_OFFSET,          
00071   GRFP_GRF_WINDOWS = 0x2 << GRFP_GRF_OFFSET,          
00072   GRFP_GRF_ANY     = GRFP_GRF_DOS | GRFP_GRF_WINDOWS, 
00073   GRFP_GRF_MASK    = GRFP_GRF_ANY,                    
00074 
00075   GRFP_BLT_UNSET   = 0x0 << GRFP_BLT_OFFSET,          
00076   GRFP_BLT_32BPP   = 0x1 << GRFP_BLT_OFFSET,          
00077   GRFP_BLT_MASK    = GRFP_BLT_32BPP,                  
00078 };
00079 
00080 
00082 struct GRFIdentifier {
00083   uint32 grfid;     
00084   uint8 md5sum[16]; 
00085 
00092   inline bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
00093   {
00094     if (this->grfid != grfid) return false;
00095     if (md5sum == NULL) return true;
00096     return memcmp(md5sum, this->md5sum, sizeof(this->md5sum)) == 0;
00097   }
00098 };
00099 
00101 struct GRFError : ZeroedMemoryAllocator {
00102   GRFError(StringID severity, StringID message = 0);
00103   GRFError(const GRFError &error);
00104   ~GRFError();
00105 
00106   char *custom_message;  
00107   char *data;            
00108   StringID message;      
00109   StringID severity;     
00110   uint8 num_params;      
00111   uint32 param_value[2]; 
00112 };
00113 
00115 enum GRFParameterType {
00116   PTYPE_UINT_ENUM, 
00117   PTYPE_BOOL,      
00118   PTYPE_END,       
00119 };
00120 
00122 struct GRFParameterInfo {
00123   GRFParameterInfo(uint nr);
00124   GRFParameterInfo(GRFParameterInfo &info);
00125   ~GRFParameterInfo();
00126   struct GRFText *name;  
00127   struct GRFText *desc;  
00128   GRFParameterType type; 
00129   uint32 min_value;      
00130   uint32 max_value;      
00131   uint32 def_value;      
00132   byte param_nr;         
00133   byte first_bit;        
00134   byte num_bit;          
00135   SmallMap<uint32, struct GRFText *, 8> value_names; 
00136 
00137   uint32 GetValue(struct GRFConfig *config) const;
00138   void SetValue(struct GRFConfig *config, uint32 value);
00139 };
00140 
00142 struct GRFTextWrapper : public SimpleCountedObject {
00143   struct GRFText *text; 
00144 
00145   GRFTextWrapper();
00146   ~GRFTextWrapper();
00147 };
00148 
00150 enum TextfileType {
00151   TFT_BEGIN,
00152 
00153   TFT_README = TFT_BEGIN,  
00154   TFT_CHANGELOG,           
00155   TFT_LICENSE,             
00156 
00157   TFT_END,
00158 };
00159 DECLARE_POSTFIX_INCREMENT(TextfileType)
00160 
00161 
00162 struct GRFConfig : ZeroedMemoryAllocator {
00163   GRFConfig(const char *filename = NULL);
00164   GRFConfig(const GRFConfig &config);
00165   ~GRFConfig();
00166 
00167   GRFIdentifier ident;                           
00168   uint8 original_md5sum[16];                     
00169   char *filename;                                
00170   GRFTextWrapper *name;                          
00171   GRFTextWrapper *info;                          
00172   GRFTextWrapper *url;                           
00173   GRFError *error;                               
00174 
00175   uint32 version;                                
00176   uint32 min_loadable_version;                   
00177   uint8 flags;                                   
00178   GRFStatus status;                              
00179   uint32 grf_bugs;                               
00180   uint32 param[0x80];                            
00181   uint8 num_params;                              
00182   uint8 num_valid_params;                        
00183   uint8 palette;                                 
00184   SmallVector<GRFParameterInfo *, 4> param_info; 
00185   bool has_param_defaults;                       
00186 
00187   struct GRFConfig *next;                        
00188 
00189   bool IsOpenTTDBaseGRF() const;
00190 
00191   const char *GetTextfile(TextfileType type) const;
00192   const char *GetName() const;
00193   const char *GetDescription() const;
00194   const char *GetURL() const;
00195 
00196   void SetParameterDefaults();
00197   void SetSuitablePalette();
00198 };
00199 
00201 enum FindGRFConfigMode {
00202   FGCM_EXACT,       
00203   FGCM_COMPATIBLE,  
00204   FGCM_NEWEST,      
00205   FGCM_NEWEST_VALID,
00206   FGCM_ANY,         
00207 };
00208 
00209 extern GRFConfig *_all_grfs;          
00210 extern GRFConfig *_grfconfig;         
00211 extern GRFConfig *_grfconfig_newgame; 
00212 extern GRFConfig *_grfconfig_static;  
00213 
00215 struct NewGRFScanCallback {
00217   virtual ~NewGRFScanCallback() {}
00219   virtual void OnNewGRFsScanned() = 0;
00220 };
00221 
00222 void ScanNewGRFFiles(NewGRFScanCallback *callback);
00223 void CheckForMissingSprites();
00224 const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum = NULL, uint32 desired_version = 0);
00225 GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
00226 GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
00227 void AppendStaticGRFConfigs(GRFConfig **dst);
00228 void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
00229 void ClearGRFConfigList(GRFConfig **config);
00230 void ResetGRFConfig(bool defaults);
00231 GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig);
00232 bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR);
00233 char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
00234 
00235 /* In newgrf_gui.cpp */
00236 void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
00237 
00238 #ifdef ENABLE_NETWORK
00239 
00240 #define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
00241 GRFTextWrapper *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
00242 #endif /* ENABLE_NETWORK */
00243 
00244 void UpdateNewGRFScanStatus(uint num, const char *name);
00245 bool UpdateNewGRFConfigPalette(int32 p1 = 0);
00246 
00247 #endif /* NEWGRF_CONFIG_H */