newgrf.h

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

Generated on Sun Jan 9 16:01:57 2011 for OpenTTD by  doxygen 1.6.1