newgrf.h

Go to the documentation of this file.
00001 /* $Id: newgrf.h 26364 2014-02-22 21:12:28Z 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 NEWGRF_H
00013 #define NEWGRF_H
00014 
00015 #include "cargotype.h"
00016 #include "rail_type.h"
00017 #include "fileio_type.h"
00018 #include "core/bitmath_func.hpp"
00019 #include "core/alloc_type.hpp"
00020 #include "core/smallvec_type.hpp"
00021 
00026 enum CanalFeature {
00027   CF_WATERSLOPE,
00028   CF_LOCKS,
00029   CF_DIKES,
00030   CF_ICON,
00031   CF_DOCKS,
00032   CF_RIVER_SLOPE,
00033   CF_RIVER_EDGE,
00034   CF_RIVER_GUI,
00035   CF_BUOY,
00036   CF_END,
00037 };
00038 
00040 struct CanalProperties {
00041   uint8 callback_mask;  
00042   uint8 flags;          
00043 };
00044 
00045 enum GrfLoadingStage {
00046   GLS_FILESCAN,
00047   GLS_SAFETYSCAN,
00048   GLS_LABELSCAN,
00049   GLS_INIT,
00050   GLS_RESERVE,
00051   GLS_ACTIVATION,
00052   GLS_END,
00053 };
00054 
00055 DECLARE_POSTFIX_INCREMENT(GrfLoadingStage)
00056 
00057 enum GrfMiscBit {
00058   GMB_DESERT_TREES_FIELDS    = 0, // Unsupported.
00059   GMB_DESERT_PAVED_ROADS     = 1,
00060   GMB_FIELD_BOUNDING_BOX     = 2, // Unsupported.
00061   GMB_TRAIN_WIDTH_32_PIXELS  = 3, 
00062   GMB_AMBIENT_SOUND_CALLBACK = 4,
00063   GMB_CATENARY_ON_3RD_TRACK  = 5, // Unsupported.
00064 };
00065 
00066 enum GrfSpecFeature {
00067   GSF_TRAINS,
00068   GSF_ROADVEHICLES,
00069   GSF_SHIPS,
00070   GSF_AIRCRAFT,
00071   GSF_STATIONS,
00072   GSF_CANALS,
00073   GSF_BRIDGES,
00074   GSF_HOUSES,
00075   GSF_GLOBALVAR,
00076   GSF_INDUSTRYTILES,
00077   GSF_INDUSTRIES,
00078   GSF_CARGOES,
00079   GSF_SOUNDFX,
00080   GSF_AIRPORTS,
00081   GSF_SIGNALS,
00082   GSF_OBJECTS,
00083   GSF_RAILTYPES,
00084   GSF_AIRPORTTILES,
00085   GSF_END,
00086 
00087   GSF_FAKE_TOWNS = GSF_END, 
00088   GSF_FAKE_END,             
00089 
00090   GSF_INVALID = 0xFF,       
00091 };
00092 
00093 static const uint32 INVALID_GRFID = 0xFFFFFFFF;
00094 
00095 struct GRFLabel {
00096   byte label;
00097   uint32 nfo_line;
00098   size_t pos;
00099   struct GRFLabel *next;
00100 };
00101 
00103 struct GRFFile : ZeroedMemoryAllocator {
00104   char *filename;
00105   bool is_ottdfile;
00106   uint32 grfid;
00107   byte grf_version;
00108 
00109   uint sound_offset;
00110   uint16 num_sounds;
00111 
00112   struct StationSpec **stations;
00113   struct HouseSpec **housespec;
00114   struct IndustrySpec **industryspec;
00115   struct IndustryTileSpec **indtspec;
00116   struct ObjectSpec **objectspec;
00117   struct AirportSpec **airportspec;
00118   struct AirportTileSpec **airtspec;
00119 
00120   uint32 param[0x80];
00121   uint param_end;  
00122 
00123   GRFLabel *label; 
00124 
00125   SmallVector<CargoLabel, 4> cargo_list;          
00126   uint8 cargo_map[NUM_CARGO];                     
00127 
00128   SmallVector<RailTypeLabel, 4> railtype_list;    
00129   RailTypeByte railtype_map[RAILTYPE_END];
00130 
00131   CanalProperties canal_local_properties[CF_END]; 
00132 
00133   struct LanguageMap *language_map; 
00134 
00135   int traininfo_vehicle_pitch;  
00136   uint traininfo_vehicle_width; 
00137 
00138   uint32 grf_features;                     
00139   PriceMultipliers price_base_multipliers; 
00140 
00141   GRFFile(const struct GRFConfig *config);
00142   ~GRFFile();
00143 
00145   uint32 GetParam(uint number) const
00146   {
00147     /* Note: We implicitly test for number < lengthof(this->param) and return 0 for invalid parameters.
00148      *       In fact this is the more important test, as param is zeroed anyway. */
00149     assert(this->param_end <= lengthof(this->param));
00150     return (number < this->param_end) ? this->param[number] : 0;
00151   }
00152 };
00153 
00154 enum ShoreReplacement {
00155   SHORE_REPLACE_NONE,       
00156   SHORE_REPLACE_ACTION_5,   
00157   SHORE_REPLACE_ACTION_A,   
00158   SHORE_REPLACE_ONLY_NEW,   
00159 };
00160 
00161 struct GRFLoadedFeatures {
00162   bool has_2CC;             
00163   uint64 used_liveries;     
00164   bool has_newhouses;       
00165   bool has_newindustries;   
00166   ShoreReplacement shore;   
00167 };
00168 
00174 static inline bool HasGrfMiscBit(GrfMiscBit bit)
00175 {
00176   extern byte _misc_grf_features;
00177   return HasBit(_misc_grf_features, bit);
00178 }
00179 
00180 /* Indicates which are the newgrf features currently loaded ingame */
00181 extern GRFLoadedFeatures _loaded_newgrf_features;
00182 
00183 byte GetGRFContainerVersion();
00184 
00185 void LoadNewGRFFile(struct GRFConfig *config, uint file_index, GrfLoadingStage stage, Subdirectory subdir);
00186 void LoadNewGRF(uint load_index, uint file_index);
00187 void ReloadNewGRFData(); // in saveload/afterload.cpp
00188 void ResetNewGRFData();
00189 void ResetPersistentNewGRFData();
00190 
00191 void CDECL grfmsg(int severity, const char *str, ...) WARN_FORMAT(2, 3);
00192 
00193 bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile);
00194 
00195 StringID MapGRFStringID(uint32 grfid, StringID str);
00196 void ShowNewGRFError();
00197 
00198 #endif /* NEWGRF_H */