newgrf_config.h

Go to the documentation of this file.
00001 /* $Id: newgrf_config.h 24900 2013-01-08 22:46:42Z planetmaker $ */
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 #include "textfile_type.h"
00021 
00023 enum GCF_Flags {
00024   GCF_SYSTEM,     
00025   GCF_UNSAFE,     
00026   GCF_STATIC,     
00027   GCF_COMPATIBLE, 
00028   GCF_COPY,       
00029   GCF_INIT_ONLY,  
00030   GCF_RESERVED,   
00031   GCF_INVALID,    
00032 };
00033 
00035 enum GRFStatus {
00036   GCS_UNKNOWN,      
00037   GCS_DISABLED,     
00038   GCS_NOT_FOUND,    
00039   GCS_INITIALISED,  
00040   GCS_ACTIVATED,    
00041 };
00042 
00044 enum GRFBugs {
00045   GBUG_VEH_LENGTH,        
00046   GBUG_VEH_REFIT,         
00047   GBUG_VEH_POWERED_WAGON, 
00048   GBUG_UNKNOWN_CB_RESULT, 
00049 };
00050 
00052 enum GRFListCompatibility {
00053   GLC_ALL_GOOD,   
00054   GLC_COMPATIBLE, 
00055   GLC_NOT_FOUND,  
00056 };
00057 
00059 enum GRFPalette {
00060   GRFP_USE_BIT     = 0,   
00061   GRFP_GRF_OFFSET  = 2,   
00062   GRFP_GRF_SIZE    = 2,   
00063   GRFP_BLT_OFFSET  = 4,   
00064   GRFP_BLT_SIZE    = 1,   
00065 
00066   GRFP_USE_DOS     = 0x0, 
00067   GRFP_USE_WINDOWS = 0x1, 
00068   GRFP_USE_MASK    = 0x1, 
00069 
00070   GRFP_GRF_UNSET   = 0x0 << GRFP_GRF_OFFSET,          
00071   GRFP_GRF_DOS     = 0x1 << GRFP_GRF_OFFSET,          
00072   GRFP_GRF_WINDOWS = 0x2 << GRFP_GRF_OFFSET,          
00073   GRFP_GRF_ANY     = GRFP_GRF_DOS | GRFP_GRF_WINDOWS, 
00074   GRFP_GRF_MASK    = GRFP_GRF_ANY,                    
00075 
00076   GRFP_BLT_UNSET   = 0x0 << GRFP_BLT_OFFSET,          
00077   GRFP_BLT_32BPP   = 0x1 << GRFP_BLT_OFFSET,          
00078   GRFP_BLT_MASK    = GRFP_BLT_32BPP,                  
00079 };
00080 
00081 
00083 struct GRFIdentifier {
00084   uint32 grfid;     
00085   uint8 md5sum[16]; 
00086 
00093   inline bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
00094   {
00095     if (this->grfid != grfid) return false;
00096     if (md5sum == NULL) return true;
00097     return memcmp(md5sum, this->md5sum, sizeof(this->md5sum)) == 0;
00098   }
00099 };
00100 
00102 struct GRFError : ZeroedMemoryAllocator {
00103   GRFError(StringID severity, StringID message = 0);
00104   GRFError(const GRFError &error);
00105   ~GRFError();
00106 
00107   char *custom_message;  
00108   char *data;            
00109   StringID message;      
00110   StringID severity;     
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   bool complete_labels;  
00137 
00138   uint32 GetValue(struct GRFConfig *config) const;
00139   void SetValue(struct GRFConfig *config, uint32 value);
00140   void Finalize();
00141 };
00142 
00144 struct GRFTextWrapper : public SimpleCountedObject {
00145   struct GRFText *text; 
00146 
00147   GRFTextWrapper();
00148   ~GRFTextWrapper();
00149 };
00150 
00152 struct GRFConfig : ZeroedMemoryAllocator {
00153   GRFConfig(const char *filename = NULL);
00154   GRFConfig(const GRFConfig &config);
00155   ~GRFConfig();
00156 
00157   GRFIdentifier ident;                           
00158   uint8 original_md5sum[16];                     
00159   char *filename;                                
00160   GRFTextWrapper *name;                          
00161   GRFTextWrapper *info;                          
00162   GRFTextWrapper *url;                           
00163   GRFError *error;                               
00164 
00165   uint32 version;                                
00166   uint32 min_loadable_version;                   
00167   uint8 flags;                                   
00168   GRFStatus status;                              
00169   uint32 grf_bugs;                               
00170   uint32 param[0x80];                            
00171   uint8 num_params;                              
00172   uint8 num_valid_params;                        
00173   uint8 palette;                                 
00174   SmallVector<GRFParameterInfo *, 4> param_info; 
00175   bool has_param_defaults;                       
00176 
00177   struct GRFConfig *next;                        
00178 
00179   bool IsOpenTTDBaseGRF() const;
00180 
00181   const char *GetTextfile(TextfileType type) const;
00182   const char *GetName() const;
00183   const char *GetDescription() const;
00184   const char *GetURL() const;
00185 
00186   void SetParameterDefaults();
00187   void SetSuitablePalette();
00188   void FinalizeParameterInfo();
00189 };
00190 
00192 enum FindGRFConfigMode {
00193   FGCM_EXACT,       
00194   FGCM_COMPATIBLE,  
00195   FGCM_NEWEST,      
00196   FGCM_NEWEST_VALID,
00197   FGCM_ANY,         
00198 };
00199 
00200 extern GRFConfig *_all_grfs;          
00201 extern GRFConfig *_grfconfig;         
00202 extern GRFConfig *_grfconfig_newgame; 
00203 extern GRFConfig *_grfconfig_static;  
00204 
00206 struct NewGRFScanCallback {
00208   virtual ~NewGRFScanCallback() {}
00210   virtual void OnNewGRFsScanned() = 0;
00211 };
00212 
00213 size_t GRFGetSizeOfDataSection(FILE *f);
00214 
00215 void ScanNewGRFFiles(NewGRFScanCallback *callback);
00216 void CheckForMissingSprites();
00217 const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum = NULL, uint32 desired_version = 0);
00218 GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
00219 GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
00220 void AppendStaticGRFConfigs(GRFConfig **dst);
00221 void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
00222 void ClearGRFConfigList(GRFConfig **config);
00223 void ResetGRFConfig(bool defaults);
00224 GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig);
00225 bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR);
00226 char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
00227 
00228 /* In newgrf_gui.cpp */
00229 void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
00230 
00231 #ifdef ENABLE_NETWORK
00232 
00233 #define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
00234 GRFTextWrapper *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
00235 #endif /* ENABLE_NETWORK */
00236 
00237 void UpdateNewGRFScanStatus(uint num, const char *name);
00238 bool UpdateNewGRFConfigPalette(int32 p1 = 0);
00239 
00240 #endif /* NEWGRF_CONFIG_H */