OpenTTD

newgrf_airport.h
Go to the documentation of this file.
1 /* $Id: newgrf_airport.h 27908 2017-08-31 06:55:38Z adf88 $ */
2
3 /*
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/>.
8 */
9
12 #ifndef NEWGRF_AIRPORT_H
13 #define NEWGRF_AIRPORT_H
14
15 #include "airport.h"
16 #include "date_type.h"
17 #include "newgrf_class.h"
18 #include "newgrf_commons.h"
19 #include "tilearea_type.h"
20
22 typedef byte StationGfx;
23
25 struct AirportTileTable {
26 TileIndexDiffC ti;
27 StationGfx gfx;
28 };
29
31 class AirportTileTableIterator : public TileIterator {
32 private:
33 const AirportTileTable *att;
34 TileIndex base_tile;
35
36 public:
42 AirportTileTableIterator(const AirportTileTable *att, TileIndex base_tile) : TileIterator(base_tile + ToTileIndexDiff(att->ti)), att(att), base_tile(base_tile)
43 {
44 }
45
46 inline TileIterator& operator ++()
47 {
48 this->att++;
49 if (this->att->ti.x == -0x80) {
50 this->tile = INVALID_TILE;
51 } else {
52 this->tile = this->base_tile + ToTileIndexDiff(this->att->ti);
53 }
54 return *this;
55 }
56
58 StationGfx GetStationGfx() const
59 {
60 return this->att->gfx;
61 }
62
63 virtual AirportTileTableIterator *Clone() const
64 {
65 return new AirportTileTableIterator(*this);
66 }
67 };
68
70 enum AirportClassID {
71 APC_BEGIN = 0,
72 APC_SMALL = 0,
73 APC_LARGE,
74 APC_HUB,
75 APC_HELIPORT,
76 APC_MAX = 16,
77 };
78
80 DECLARE_POSTFIX_INCREMENT(AirportClassID)
81
82
83 enum TTDPAirportType {
84 ATP_TTDP_SMALL,
85 ATP_TTDP_LARGE,
86 ATP_TTDP_HELIPORT,
87 ATP_TTDP_OILRIG,
88 };
89
91 struct HangarTileTable {
92 TileIndexDiffC ti;
93 Direction dir;
94 byte hangar_num;
95 };
96
100 struct AirportSpec {
101 const struct AirportFTAClass *fsm;
102 const AirportTileTable * const *table;
103 const Direction *rotation;
104 byte num_table;
105 const HangarTileTable *depot_table;
106 byte nof_depots;
107 byte size_x;
108 byte size_y;
109 byte noise_level;
110 byte catchment;
111 Year min_year;
112 Year max_year;
113 StringID name;
114 TTDPAirportType ttd_airport_type;
115 AirportClassID cls_id;
116 SpriteID preview_sprite;
117 uint16 maintenance_cost;
118 /* Newgrf data */
119 bool enabled;
120 struct GRFFileProps grf_prop;
121
122 static const AirportSpec *Get(byte type);
123 static AirportSpec *GetWithoutOverride(byte type);
124
125 bool IsAvailable() const;
126
127 static void ResetAirports();
128
130 byte GetIndex() const
131 {
132 assert(this >= specs && this < endof(specs));
133 return (byte)(this - specs);
134 }
135
136 static const AirportSpec dummy;
137
138 private:
139 static AirportSpec specs[NUM_AIRPORTS];
140 };
141
143 typedef NewGRFClass<AirportSpec, AirportClassID, APC_MAX> AirportClass;
144
145 void BindAirportSpecs();
146
147 StringID GetAirportTextCallback(const AirportSpec *as, byte layout, uint16 callback);
148
149 #endif /* NEWGRF_AIRPORT_H */
APC_SMALL
id for small airports class
Definition: newgrf_airport.h:72
AirportSpec::ttd_airport_type
TTDPAirportType ttd_airport_type
ttdpatch airport type (Small/Large/Helipad/Oilrig)
Definition: newgrf_airport.h:114
AirportFTAClass
Finite sTate mAchine (FTA) of an airport.
Definition: airport.h:144
AirportClassID
AirportClassID
List of default airport classes.
Definition: newgrf_airport.h:70
AirportTileTable::ti
TileIndexDiffC ti
Tile offset from the top-most airport tile.
Definition: newgrf_airport.h:26
AirportSpec::size_y
byte size_y
size of airport in y direction
Definition: newgrf_airport.h:108
HangarTileTable::hangar_num
byte hangar_num
The hangar to which this tile belongs.
Definition: newgrf_airport.h:94
BindAirportSpecs
void BindAirportSpecs()
Tie all airportspecs to their class.
Definition: newgrf_airport.cpp:147
AirportSpec::depot_table
const HangarTileTable * depot_table
gives the position of the depots on the airports
Definition: newgrf_airport.h:105
AirportSpec::GetIndex
byte GetIndex() const
Get the index of this spec.
Definition: newgrf_airport.h:130
AirportTileTableIterator
Iterator to iterate over all tiles belonging to an airport spec.
Definition: newgrf_airport.h:31
AirportSpec::dummy
static const AirportSpec dummy
The dummy airport.
Definition: newgrf_airport.h:136
HangarTileTable
A list of all hangar tiles in an airport.
Definition: newgrf_airport.h:91
APC_BEGIN
Lowest valid airport class id.
Definition: newgrf_airport.h:71
Year
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:20
AirportSpec::fsm
const struct AirportFTAClass * fsm
the finite statemachine for the default airports
Definition: newgrf_airport.h:101
AirportSpec::min_year
Year min_year
first year the airport is available
Definition: newgrf_airport.h:111
AirportSpec::nof_depots
byte nof_depots
the number of hangar tiles in this airport
Definition: newgrf_airport.h:106
AirportSpec::maintenance_cost
uint16 maintenance_cost
maintenance cost multiplier
Definition: newgrf_airport.h:117
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:26
AirportSpec::table
const AirportTileTable *const * table
list of the tiles composing the airport
Definition: newgrf_airport.h:102
airport.h
Various declarations for airports.
AirportSpec::catchment
byte catchment
catchment area of this airport
Definition: newgrf_airport.h:110
NUM_AIRPORTS
Maximal number of airports in total.
Definition: airport.h:43
AirportSpec::noise_level
byte noise_level
noise that this airport generates
Definition: newgrf_airport.h:109
NewGRFClass
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:21
AirportSpec::cls_id
AirportClassID cls_id
the class to which this airport type belongs
Definition: newgrf_airport.h:115
AirportClass
NewGRFClass< AirportSpec, AirportClassID, APC_MAX > AirportClass
Information related to airport classes.
Definition: newgrf_airport.h:143
AirportSpec::rotation
const Direction * rotation
the rotation of each tiletable
Definition: newgrf_airport.h:103
GRFFileProps
Data related to the handling of grf files.
Definition: newgrf_commons.h:325
APC_MAX
maximum number of airport classes
Definition: newgrf_airport.h:76
AirportTileTableIterator::att
const AirportTileTable * att
The offsets.
Definition: newgrf_airport.h:33
TileIndexDiffC::x
int16 x
The x value of the coordinate.
Definition: map_type.h:59
ATP_TTDP_OILRIG
Same as AT_OILRIG.
Definition: newgrf_airport.h:87
AirportSpec::num_table
byte num_table
number of elements in the table
Definition: newgrf_airport.h:104
TileIterator
Base class for tile iterators.
Definition: tilearea_type.h:99
AirportTileTable::gfx
StationGfx gfx
AirportTile to use for this tile.
Definition: newgrf_airport.h:27
AirportTileTableIterator::Clone
virtual AirportTileTableIterator * Clone() const
Allocate a new iterator that is a copy of this one.
Definition: newgrf_airport.h:63
APC_HELIPORT
id for heliports
Definition: newgrf_airport.h:75
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
AirportTileTableIterator::base_tile
TileIndex base_tile
The tile we base the offsets off.
Definition: newgrf_airport.h:34
HangarTileTable::ti
TileIndexDiffC ti
Tile offset from the top-most airport tile.
Definition: newgrf_airport.h:92
AirportTileTableIterator::GetStationGfx
StationGfx GetStationGfx() const
Get the StationGfx for the current tile.
Definition: newgrf_airport.h:58
TileIndexDiffC
A pair-construct of a TileIndexDiff.
Definition: map_type.h:58
ToTileIndexDiff
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between to tiles from a TileIndexDiffC struct.
Definition: map_func.h:232
StationGfx
byte StationGfx
Copy from station_map.h.
Definition: newgrf_airport.h:22
newgrf_class.h
Header file for classes to be used by e.g.
ATP_TTDP_HELIPORT
Same as AT_HELIPORT.
Definition: newgrf_airport.h:86
HangarTileTable::dir
Direction dir
Direction of the exit.
Definition: newgrf_airport.h:93
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
AirportSpec::name
StringID name
name of this airport
Definition: newgrf_airport.h:113
GetAirportTextCallback
StringID GetAirportTextCallback(const AirportSpec *as, byte layout, uint16 callback)
Get a custom text for the airport.
Definition: newgrf_airport.cpp:278
AirportTileTableIterator::AirportTileTableIterator
AirportTileTableIterator(const AirportTileTable *att, TileIndex base_tile)
Construct the iterator.
Definition: newgrf_airport.h:42
AirportSpec::size_x
byte size_x
size of airport in x direction
Definition: newgrf_airport.h:107
AirportTileTable
Tile-offset / AirportTileID pair.
Definition: newgrf_airport.h:25
endof
#define endof(x)
Get the end element of an fixed size array.
Definition: stdafx.h:427
APC_HUB
id for hub airports class
Definition: newgrf_airport.h:74
ATP_TTDP_LARGE
Same as AT_LARGE.
Definition: newgrf_airport.h:85
tilearea_type.h
Type for storing the &#39;area&#39; of something uses on the map.
date_type.h
Types related to the dates in OpenTTD.
newgrf_commons.h
This file simplyfies and embeds a common mechanism of loading/saving and mapping of grf entities...
AirportSpec::enabled
bool enabled
Entity still available (by default true). Newgrf can disable it, though.
Definition: newgrf_airport.h:119
ATP_TTDP_SMALL
Same as AT_SMALL.
Definition: newgrf_airport.h:84
AirportSpec::preview_sprite
SpriteID preview_sprite
preview sprite for this airport
Definition: newgrf_airport.h:116
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
AirportSpec
Defines the data structure for an airport.
Definition: newgrf_airport.h:100
DECLARE_POSTFIX_INCREMENT
#define DECLARE_POSTFIX_INCREMENT(type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:16
TTDPAirportType
TTDPAirportType
Allow incrementing of AirportClassID variables.
Definition: newgrf_airport.h:83
AirportSpec::max_year
Year max_year
last year the airport is available
Definition: newgrf_airport.h:112
APC_LARGE
id for large airports class
Definition: newgrf_airport.h:73