newgrf.h

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