newgrf_config.h

Go to the documentation of this file.
00001 /* $Id: newgrf_config.h 26317 2014-02-07 23:48:56Z frosch $ */
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   GBUG_VEH_CAPACITY,      
00050 };
00051 
00053 enum GRFListCompatibility {
00054   GLC_ALL_GOOD,   
00055   GLC_COMPATIBLE, 
00056   GLC_NOT_FOUND,  
00057 };
00058 
00060 enum GRFPalette {
00061   GRFP_USE_BIT     = 0,   
00062   GRFP_GRF_OFFSET  = 2,   
00063   GRFP_GRF_SIZE    = 2,   
00064   GRFP_BLT_OFFSET  = 4,   
00065   GRFP_BLT_SIZE    = 1,   
00066 
00067   GRFP_USE_DOS     = 0x0, 
00068   GRFP_USE_WINDOWS = 0x1, 
00069   GRFP_USE_MASK    = 0x1, 
00070 
00071   GRFP_GRF_UNSET   = 0x0 << GRFP_GRF_OFFSET,          
00072   GRFP_GRF_DOS     = 0x1 << GRFP_GRF_OFFSET,          
00073   GRFP_GRF_WINDOWS = 0x2 << GRFP_GRF_OFFSET,          
00074   GRFP_GRF_ANY     = GRFP_GRF_DOS | GRFP_GRF_WINDOWS, 
00075   GRFP_GRF_MASK    = GRFP_GRF_ANY,                    
00076 
00077   GRFP_BLT_UNSET   = 0x0 << GRFP_BLT_OFFSET,          
00078   GRFP_BLT_32BPP   = 0x1 << GRFP_BLT_OFFSET,          
00079   GRFP_BLT_MASK    = GRFP_BLT_32BPP,                  
00080 };
00081 
00082 
00084 struct GRFIdentifier {
00085   uint32 grfid;     
00086   uint8 md5sum[16]; 
00087 
00094   inline bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
00095   {
00096     if (this->grfid != grfid) return false;
00097     if (md5sum == NULL) return true;
00098     return memcmp(md5sum, this->md5sum, sizeof(this->md5sum)) == 0;
00099   }
00100 };
00101 
00103 struct GRFError : ZeroedMemoryAllocator {
00104   GRFError(StringID severity, StringID message = 0);
00105   GRFError(const GRFError &error);
00106   ~GRFError();
00107 
00108   char *custom_message;  
00109   char *data;            
00110   StringID message;      
00111   StringID severity;     
00112   uint32 param_value[2]; 
00113 };
00114 
00116 enum GRFParameterType {
00117   PTYPE_UINT_ENUM, 
00118   PTYPE_BOOL,      
00119   PTYPE_END,       
00120 };
00121 
00123 struct GRFParameterInfo {
00124   GRFParameterInfo(uint nr);
00125   GRFParameterInfo(GRFParameterInfo &info);
00126   ~GRFParameterInfo();
00127   struct GRFText *name;  
00128   struct GRFText *desc;  
00129   GRFParameterType type; 
00130   uint32 min_value;      
00131   uint32 max_value;      
00132   uint32 def_value;      
00133   byte param_nr;         
00134   byte first_bit;        
00135   byte num_bit;          
00136   SmallMap<uint32, struct GRFText *, 8> value_names; 
00137   bool complete_labels;  
00138 
00139   uint32 GetValue(struct GRFConfig *config) const;
00140   void SetValue(struct GRFConfig *config, uint32 value);
00141   void Finalize();
00142 };
00143 
00145 struct GRFTextWrapper : public SimpleCountedObject {
00146   struct GRFText *text; 
00147 
00148   GRFTextWrapper();
00149   ~GRFTextWrapper();
00150 };
00151 
00153 struct GRFConfig : ZeroedMemoryAllocator {
00154   GRFConfig(const char *filename = NULL);
00155   GRFConfig(const GRFConfig &config);
00156   ~GRFConfig();
00157 
00158   GRFIdentifier ident;                           
00159   uint8 original_md5sum[16];                     
00160   char *filename;                                
00161   GRFTextWrapper *name;                          
00162   GRFTextWrapper *info;                          
00163   GRFTextWrapper *url;                           
00164   GRFError *error;                               
00165 
00166   uint32 version;                                
00167   uint32 min_loadable_version;                   
00168   uint8 flags;                                   
00169   GRFStatus status;                              
00170   uint32 grf_bugs;                               
00171   uint32 param[0x80];                            
00172   uint8 num_params;                              
00173   uint8 num_valid_params;                        
00174   uint8 palette;                                 
00175   SmallVector<GRFParameterInfo *, 4> param_info; 
00176   bool has_param_defaults;                       
00177 
00178   struct GRFConfig *next;                        
00179 
00180   bool IsOpenTTDBaseGRF() const;
00181 
00182   const char *GetTextfile(TextfileType type) const;
00183   const char *GetName() const;
00184   const char *GetDescription() const;
00185   const char *GetURL() const;
00186 
00187   void SetParameterDefaults();
00188   void SetSuitablePalette();
00189   void FinalizeParameterInfo();
00190 };
00191 
00193 enum FindGRFConfigMode {
00194   FGCM_EXACT,       
00195   FGCM_COMPATIBLE,  
00196   FGCM_NEWEST,      
00197   FGCM_NEWEST_VALID,
00198   FGCM_ANY,         
00199 };
00200 
00201 extern GRFConfig *_all_grfs;          
00202 extern GRFConfig *_grfconfig;         
00203 extern GRFConfig *_grfconfig_newgame; 
00204 extern GRFConfig *_grfconfig_static;  
00205 
00207 struct NewGRFScanCallback {
00209   virtual ~NewGRFScanCallback() {}
00211   virtual void OnNewGRFsScanned() = 0;
00212 };
00213 
00214 size_t GRFGetSizeOfDataSection(FILE *f);
00215 
00216 void ScanNewGRFFiles(NewGRFScanCallback *callback);
00217 void CheckForMissingSprites();
00218 const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum = NULL, uint32 desired_version = 0);
00219 GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
00220 GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
00221 void AppendStaticGRFConfigs(GRFConfig **dst);
00222 void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
00223 void ClearGRFConfigList(GRFConfig **config);
00224 void ResetGRFConfig(bool defaults);
00225 GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig);
00226 bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR);
00227 char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
00228 
00229 /* In newgrf_gui.cpp */
00230 void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
00231 
00232 #ifdef ENABLE_NETWORK
00233 
00234 #define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
00235 GRFTextWrapper *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
00236 #endif /* ENABLE_NETWORK */
00237 
00238 void UpdateNewGRFScanStatus(uint num, const char *name);
00239 bool UpdateNewGRFConfigPalette(int32 p1 = 0);
00240 
00241 #endif /* NEWGRF_CONFIG_H */