4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file newgrf_airport.h NewGRF handling of airports. */
12 #ifndef NEWGRF_AIRPORT_H
13 #define NEWGRF_AIRPORT_H
16 #include "date_type.h"
17 #include "newgrf_class.h"
18 #include "newgrf_commons.h"
19 #include "map/tilearea.h"
21 /** Copy from tile/station.h */
22 typedef byte StationGfx
;
24 /** Tile-offset / AirportTileID pair. */
25 struct AirportTileTable
{
26 CoordDiff ti
; ///< Tile offset from the top-most airport tile.
27 StationGfx gfx
; ///< AirportTile to use for this tile.
28 byte rotation
; ///< Rotation of this layout (first tile only).
31 /* The rotation field of struct AirportTileTable is only used in the
32 * first tile of a layout; make sure that this does not increase memory
33 * requirements for the struct, as most tiles will not be using it. */
34 assert_compile (sizeof(AirportTileTable
) == sizeof(CoordDiff
) + 2);
35 assert_compile (sizeof(AirportTileTable
) % 2 == 0);
37 /** Iterator to iterate over all tiles belonging to an airport spec. */
38 class AirportTileTableIterator
: public TileIterator
{
40 const AirportTileTable
*att
; ///< The offsets.
41 TileIndex base_tile
; ///< The tile we base the offsets off.
44 inline void Next() OVERRIDE
47 if (this->att
->ti
.x
== -0x80) {
48 this->tile
= INVALID_TILE
;
50 this->tile
= this->base_tile
+ ToTileIndexDiff(this->att
->ti
);
56 * Construct the iterator.
57 * @param att The TileTable we want to iterate over.
58 * @param base_tile The basetile for all offsets.
60 AirportTileTableIterator(const AirportTileTable
*att
, TileIndex base_tile
) : TileIterator(base_tile
+ ToTileIndexDiff(att
->ti
)), att(att
), base_tile(base_tile
)
64 /** Get the StationGfx for the current tile. */
65 StationGfx
GetStationGfx() const
67 return this->att
->gfx
;
71 /** List of default airport classes. */
73 APC_BEGIN
= 0, ///< Lowest valid airport class id
74 APC_SMALL
= 0, ///< id for small airports class
75 APC_LARGE
, ///< id for large airports class
76 APC_HUB
, ///< id for hub airports class
77 APC_HELIPORT
, ///< id for heliports
78 APC_MAX
= 16, ///< maximum number of airport classes
81 /** Allow incrementing of AirportClassID variables */
82 DECLARE_POSTFIX_INCREMENT(AirportClassID
)
84 /** TTDP airport types. Used to map our types to TTDPatch's */
85 enum TTDPAirportType
{
86 ATP_TTDP_SMALL
, ///< Same as AT_SMALL
87 ATP_TTDP_LARGE
, ///< Same as AT_LARGE
88 ATP_TTDP_HELIPORT
, ///< Same as AT_HELIPORT
89 ATP_TTDP_OILRIG
, ///< Same as AT_OILRIG
93 * Defines the data structure for an airport.
96 const struct AirportFTA
*fsm
; ///< the finite statemachine for the default airports
97 const AirportTileTable
* const *table
; ///< list of the tiles composing the airport
98 byte num_table
; ///< number of elements in the table
99 byte size_x
; ///< size of airport in x direction
100 byte size_y
; ///< size of airport in y direction
101 byte noise_level
; ///< noise that this airport generates
102 byte catchment
; ///< catchment area of this airport
103 Year min_year
; ///< first year the airport is available
104 Year max_year
; ///< last year the airport is available
105 StringID name
; ///< name of this airport
106 TTDPAirportType ttd_airport_type
; ///< ttdpatch airport type (Small/Large/Helipad/Oilrig)
107 AirportClassID cls_id
; ///< the class to which this airport type belongs
108 SpriteID preview_sprite
; ///< preview sprite for this airport
109 uint16 maintenance_cost
; ///< maintenance cost multiplier
111 bool enabled
; ///< Entity still available (by default true). Newgrf can disable it, though.
112 struct GRFFileProps grf_prop
; ///< Properties related to the grf file.
114 static const AirportSpec
*Get(byte type
);
115 static AirportSpec
*GetWithoutOverride(byte type
);
117 bool IsAvailable() const;
119 static void ResetAirports();
121 /** Get the index of this spec. */
122 byte
GetIndex() const
124 assert(this >= specs
&& this < endof(specs
));
125 return (byte
)(this - specs
);
129 static AirportSpec specs
[NUM_AIRPORTS
]; ///< Specs of the airports.
132 /** Information related to airport classes. */
133 typedef NewGRFClass
<AirportSpec
, AirportClassID
, APC_MAX
> AirportClass
;
135 void BindAirportSpecs();
137 StringID
GetAirportTextCallback(const AirportSpec
*as
, byte layout
, uint16 callback
);
139 #endif /* NEWGRF_AIRPORT_H */