# newgrf.h

Go to the documentation of this file.

    00001 /* $Id: newgrf.h 18809 2010-01-15 16:41:15Z 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 "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_END,
    00058 };
    00059
    00060 static const uint32 INVALID_GRFID = 0xFFFFFFFF;
    00061
    00062 struct GRFLabel {
    00063   byte label;
    00064   uint32 nfo_line;
    00065   size_t pos;
    00066   struct GRFLabel *next;
    00067 };
    00068
    00070 struct GRFFile {
    00071   char *filename;
    00072   bool is_ottdfile;
    00073   uint32 grfid;
    00074   uint16 sprite_offset;
    00075   byte grf_version;
    00076
    00077   /* A sprite group contains all sprites of a given vehicle (or multiple
    00078    * vehicles) when carrying given cargo. It consists of several sprite
    00079    * sets.  Group ids are refered as "cargo id"s by TTDPatch
    00080    * documentation, contributing to the global confusion.
    00081    *
    00082    * A sprite set contains all sprites of a given vehicle carrying given
    00083    * cargo at a given *stage* - that is usually its load stage. Ie. you
    00084    * can have a spriteset for an empty wagon, wagon full of coal,
    00085    * half-filled wagon etc.  Each spriteset contains eight sprites (one
    00086    * per direction) or four sprites if the vehicle is symmetric. */
    00087
    00088   SpriteID spriteset_start;
    00089   int spriteset_numsets;
    00090   int spriteset_numents;
    00091   int spriteset_feature;
    00092
    00093   int spritegroups_count;
    00094   struct SpriteGroup **spritegroups;
    00095
    00096   uint sound_offset;
    00097
    00098   StationSpec **stations;
    00099   HouseSpec **housespec;
    00100   IndustrySpec **industryspec;
    00101   IndustryTileSpec **indtspec;
    00102
    00103   uint32 param[0x80];
    00104   uint param_end;
    00105
    00106   GRFLabel *label;
    00107
    00108   uint8 cargo_max;
    00109   CargoLabel *cargo_list;
    00110   uint8 cargo_map[NUM_CARGO];
    00111
    00112   uint8 railtype_max;
    00113   RailTypeLabel *railtype_list;
    00114
    00115   int traininfo_vehicle_pitch;
    00116   int traininfo_vehicle_width;
    00117
    00118   uint32 grf_features;
    00119   PriceMultipliers price_base_multipliers;
    00120
    00122   uint32 GetParam(uint number) const
    00123   {
    00124     /* Note: We implicitly test for number < lengthof(this->param) and return 0 for invalid parameters.
    00125      *       In fact this is the more important test, as param is zeroed anyway. */
    00126     assert(this->param_end <= lengthof(this->param));
    00127     return (number < this->param_end) ? this->param[number] : 0;
    00128   }
    00129 };
    00130
    00131 enum ShoreReplacement {
    00132   SHORE_REPLACE_NONE,
    00133   SHORE_REPLACE_ACTION_5,
    00134   SHORE_REPLACE_ACTION_A,
    00135   SHORE_REPLACE_ONLY_NEW,
    00136 };
    00137
    00138 struct GRFLoadedFeatures {
    00139   bool has_2CC;
    00140   bool has_newhouses;
    00141   bool has_newindustries;
    00142   ShoreReplacement shore;
    00143 };
    00144
    00145 /* Indicates which are the newgrf features currently loaded ingame */
    00146 extern GRFLoadedFeatures _loaded_newgrf_features;
    00147
    00148 void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage);
    00149 void LoadNewGRF(uint load_index, uint file_index);
    00150 void ReloadNewGRFData(); // in saveload/afterload.cpp
    00151
    00152 void CDECL grfmsg(int severity, const char *str, ...) WARN_FORMAT(2, 3);
    00153
    00154 bool HasGrfMiscBit(GrfMiscBit bit);
    00155 bool GetGlobalVariable(byte param, uint32 *value);
    00156
    00157 StringID MapGRFStringID(uint32 grfid, StringID str);
    00158 void ShowNewGRFError();
    00159
    00160 #endif /* NEWGRF_H */