# newgrf.h

Go to the documentation of this file.

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