1 /* 2 * This file is part of OpenTTD. 3 * 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. 4 * 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. 5 * 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/>. 6 */ 7 8 /** @file newgrf_airport.h NewGRF handling of airports. */ 9 10 #ifndef NEWGRF_AIRPORT_H 11 #define NEWGRF_AIRPORT_H 12 13 #include "airport.h" 14 #include "date_type.h" 15 #include "newgrf_class.h" 16 #include "newgrf_commons.h" 17 #include "tilearea_type.h" 18 19 /** Copy from station_map.h */ 20 typedef byte StationGfx; 21 22 /** Tile-offset / AirportTileID pair. */ 23 struct AirportTileTable { 24 TileIndexDiffC ti; ///< Tile offset from the top-most airport tile. 25 StationGfx gfx; ///< AirportTile to use for this tile. 26 }; 27 28 /** Iterator to iterate over all tiles belonging to an airport spec. */ 29 class AirportTileTableIterator : public TileIterator { 30 private: 31 const AirportTileTable *att; ///< The offsets. 32 TileIndex base_tile; ///< The tile we base the offsets off. 33 34 public: 35 /** 36 * Construct the iterator. 37 * @param att The TileTable we want to iterate over. 38 * @param base_tile The basetile for all offsets. 39 */ AirportTileTableIterator(const AirportTileTable * att,TileIndex base_tile)40 AirportTileTableIterator(const AirportTileTable *att, TileIndex base_tile) : TileIterator(base_tile + ToTileIndexDiff(att->ti)), att(att), base_tile(base_tile) 41 { 42 } 43 44 inline TileIterator& operator ++() 45 { 46 this->att++; 47 if (this->att->ti.x == -0x80) { 48 this->tile = INVALID_TILE; 49 } else { 50 this->tile = this->base_tile + ToTileIndexDiff(this->att->ti); 51 } 52 return *this; 53 } 54 55 /** Get the StationGfx for the current tile. */ GetStationGfx()56 StationGfx GetStationGfx() const 57 { 58 return this->att->gfx; 59 } 60 Clone()61 virtual AirportTileTableIterator *Clone() const 62 { 63 return new AirportTileTableIterator(*this); 64 } 65 }; 66 67 /** List of default airport classes. */ 68 enum AirportClassID { 69 APC_BEGIN = 0, ///< Lowest valid airport class id 70 APC_SMALL = 0, ///< id for small airports class 71 APC_LARGE, ///< id for large airports class 72 APC_HUB, ///< id for hub airports class 73 APC_HELIPORT, ///< id for heliports 74 APC_MAX = 16, ///< maximum number of airport classes 75 }; 76 77 /** Allow incrementing of AirportClassID variables */ 78 DECLARE_POSTFIX_INCREMENT(AirportClassID) 79 80 /** TTDP airport types. Used to map our types to TTDPatch's */ 81 enum TTDPAirportType { 82 ATP_TTDP_SMALL, ///< Same as AT_SMALL 83 ATP_TTDP_LARGE, ///< Same as AT_LARGE 84 ATP_TTDP_HELIPORT, ///< Same as AT_HELIPORT 85 ATP_TTDP_OILRIG, ///< Same as AT_OILRIG 86 }; 87 88 /** A list of all hangar tiles in an airport */ 89 struct HangarTileTable { 90 TileIndexDiffC ti; ///< Tile offset from the top-most airport tile. 91 Direction dir; ///< Direction of the exit. 92 byte hangar_num; ///< The hangar to which this tile belongs. 93 }; 94 95 /** 96 * Defines the data structure for an airport. 97 */ 98 struct AirportSpec { 99 const struct AirportFTAClass *fsm; ///< the finite statemachine for the default airports 100 const AirportTileTable * const *table; ///< list of the tiles composing the airport 101 const Direction *rotation; ///< the rotation of each tiletable 102 byte num_table; ///< number of elements in the table 103 const HangarTileTable *depot_table; ///< gives the position of the depots on the airports 104 byte nof_depots; ///< the number of hangar tiles in this airport 105 byte size_x; ///< size of airport in x direction 106 byte size_y; ///< size of airport in y direction 107 byte noise_level; ///< noise that this airport generates 108 byte catchment; ///< catchment area of this airport 109 Year min_year; ///< first year the airport is available 110 Year max_year; ///< last year the airport is available 111 StringID name; ///< name of this airport 112 TTDPAirportType ttd_airport_type; ///< ttdpatch airport type (Small/Large/Helipad/Oilrig) 113 AirportClassID cls_id; ///< the class to which this airport type belongs 114 SpriteID preview_sprite; ///< preview sprite for this airport 115 uint16 maintenance_cost; ///< maintenance cost multiplier 116 /* Newgrf data */ 117 bool enabled; ///< Entity still available (by default true). Newgrf can disable it, though. 118 struct GRFFileProps grf_prop; ///< Properties related to the grf file. 119 120 static const AirportSpec *Get(byte type); 121 static AirportSpec *GetWithoutOverride(byte type); 122 123 bool IsAvailable() const; 124 bool IsWithinMapBounds(byte table, TileIndex index) const; 125 126 static void ResetAirports(); 127 128 /** Get the index of this spec. */ GetIndexAirportSpec129 byte GetIndex() const 130 { 131 assert(this >= specs && this < endof(specs)); 132 return (byte)(this - specs); 133 } 134 135 static const AirportSpec dummy; ///< The dummy airport. 136 137 private: 138 static AirportSpec specs[NUM_AIRPORTS]; ///< Specs of the airports. 139 }; 140 141 /** Information related to airport classes. */ 142 typedef NewGRFClass<AirportSpec, AirportClassID, APC_MAX> AirportClass; 143 144 void BindAirportSpecs(); 145 146 StringID GetAirportTextCallback(const AirportSpec *as, byte layout, uint16 callback); 147 148 #endif /* NEWGRF_AIRPORT_H */ 149