# newgrf.h

Go to the documentation of this file.

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