newgrf.h

Go to the documentation of this file.
00001 /* $Id: newgrf.h 22995 2011-10-04 20:22:46Z 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 
00022 enum CanalFeature {
00023   CF_WATERSLOPE,
00024   CF_LOCKS,
00025   CF_DIKES,
00026   CF_ICON,
00027   CF_DOCKS,
00028   CF_RIVER_SLOPE,
00029   CF_RIVER_EDGE,
00030   CF_RIVER_GUI,
00031   CF_BUOY,
00032   CF_END,
00033 };
00034 
00036 struct CanalProperties {
00037   uint8 callback_mask;  
00038   uint8 flags;          
00039 };
00040 
00041 enum GrfLoadingStage {
00042   GLS_FILESCAN,
00043   GLS_SAFETYSCAN,
00044   GLS_LABELSCAN,
00045   GLS_INIT,
00046   GLS_RESERVE,
00047   GLS_ACTIVATION,
00048   GLS_END,
00049 };
00050 
00051 DECLARE_POSTFIX_INCREMENT(GrfLoadingStage)
00052 
00053 enum GrfMiscBit {
00054   GMB_DESERT_TREES_FIELDS    = 0, // Unsupported.
00055   GMB_DESERT_PAVED_ROADS     = 1,
00056   GMB_FIELD_BOUNDING_BOX     = 2, // Unsupported.
00057   GMB_TRAIN_WIDTH_32_PIXELS  = 3, 
00058   GMB_AMBIENT_SOUND_CALLBACK = 4, // Unsupported.
00059   GMB_CATENARY_ON_3RD_TRACK  = 5, // Unsupported.
00060 };
00061 
00062 enum GrfSpecFeature {
00063   GSF_TRAINS,
00064   GSF_ROADVEHICLES,
00065   GSF_SHIPS,
00066   GSF_AIRCRAFT,
00067   GSF_STATIONS,
00068   GSF_CANALS,
00069   GSF_BRIDGES,
00070   GSF_HOUSES,
00071   GSF_GLOBALVAR,
00072   GSF_INDUSTRYTILES,
00073   GSF_INDUSTRIES,
00074   GSF_CARGOS,
00075   GSF_SOUNDFX,
00076   GSF_AIRPORTS,
00077   GSF_SIGNALS,
00078   GSF_OBJECTS,
00079   GSF_RAILTYPES,
00080   GSF_AIRPORTTILES,
00081   GSF_END,
00082 
00083   GSF_FAKE_TOWNS = GSF_END, 
00084   GSF_FAKE_END,             
00085 
00086   GSF_INVALID = 0xFF        
00087 };
00088 
00089 static const uint32 INVALID_GRFID = 0xFFFFFFFF;
00090 
00091 struct GRFLabel {
00092   byte label;
00093   uint32 nfo_line;
00094   size_t pos;
00095   struct GRFLabel *next;
00096 };
00097 
00099 struct GRFFile {
00100   char *filename;
00101   bool is_ottdfile;
00102   uint32 grfid;
00103   uint16 sprite_offset;
00104   byte grf_version;
00105 
00106   /* A sprite group contains all sprites of a given vehicle (or multiple
00107    * vehicles) when carrying given cargo. It consists of several sprite
00108    * sets.  Group ids are refered as "cargo id"s by TTDPatch
00109    * documentation, contributing to the global confusion.
00110    *
00111    * A sprite set contains all sprites of a given vehicle carrying given
00112    * cargo at a given *stage* - that is usually its load stage. Ie. you
00113    * can have a spriteset for an empty wagon, wagon full of coal,
00114    * half-filled wagon etc.  Each spriteset contains eight sprites (one
00115    * per direction) or four sprites if the vehicle is symmetric. */
00116 
00117   SpriteID spriteset_start;
00118   int spriteset_numsets;
00119   int spriteset_numents;
00120   int spriteset_feature;
00121 
00122   int spritegroups_count;
00123   struct SpriteGroup **spritegroups;
00124 
00125   uint sound_offset;
00126   uint16 num_sounds;
00127 
00128   struct StationSpec **stations;
00129   struct HouseSpec **housespec;
00130   struct IndustrySpec **industryspec;
00131   struct IndustryTileSpec **indtspec;
00132   struct ObjectSpec **objectspec;
00133   struct AirportSpec **airportspec;
00134   struct AirportTileSpec **airtspec;
00135 
00136   uint32 param[0x80];
00137   uint param_end;  
00138 
00139   GRFLabel *label; 
00140 
00141   uint8 cargo_max;
00142   CargoLabel *cargo_list;
00143   uint8 cargo_map[NUM_CARGO];
00144 
00145   uint8 railtype_max;
00146   RailTypeLabel *railtype_list;
00147   RailType railtype_map[RAILTYPE_END];
00148 
00149   CanalProperties canal_local_properties[CF_END]; 
00150 
00151   struct LanguageMap *language_map; 
00152 
00153   int traininfo_vehicle_pitch;  
00154   uint traininfo_vehicle_width; 
00155 
00156   uint32 grf_features;                     
00157   PriceMultipliers price_base_multipliers; 
00158 
00160   uint32 GetParam(uint number) const
00161   {
00162     /* Note: We implicitly test for number < lengthof(this->param) and return 0 for invalid parameters.
00163      *       In fact this is the more important test, as param is zeroed anyway. */
00164     assert(this->param_end <= lengthof(this->param));
00165     return (number < this->param_end) ? this->param[number] : 0;
00166   }
00167 };
00168 
00169 enum ShoreReplacement {
00170   SHORE_REPLACE_NONE,       
00171   SHORE_REPLACE_ACTION_5,   
00172   SHORE_REPLACE_ACTION_A,   
00173   SHORE_REPLACE_ONLY_NEW,   
00174 };
00175 
00176 struct GRFLoadedFeatures {
00177   bool has_2CC;             
00178   uint64 used_liveries;     
00179   bool has_newhouses;       
00180   bool has_newindustries;   
00181   ShoreReplacement shore;   
00182 };
00183 
00184 /* Indicates which are the newgrf features currently loaded ingame */
00185 extern GRFLoadedFeatures _loaded_newgrf_features;
00186 
00187 void LoadNewGRFFile(struct GRFConfig *config, uint file_index, GrfLoadingStage stage);
00188 void LoadNewGRF(uint load_index, uint file_index);
00189 void ReloadNewGRFData(); // in saveload/afterload.cpp
00190 void ResetNewGRFData();
00191 void ResetPersistentNewGRFData();
00192 
00193 void CDECL grfmsg(int severity, const char *str, ...) WARN_FORMAT(2, 3);
00194 
00195 bool HasGrfMiscBit(GrfMiscBit bit);
00196 bool GetGlobalVariable(byte param, uint32 *value);
00197 
00198 StringID MapGRFStringID(uint32 grfid, StringID str);
00199 void ShowNewGRFError();
00200 
00201 #endif /* NEWGRF_H */