OpenTTD Source: src/airport.h Source File

OpenTTD Source 15.0-RC2

airport.h
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef AIRPORT_H
11#define AIRPORT_H
12
13#include "direction_type.h"
14#include "tile_type.h"
15
17 static const uint MAX_TERMINALS = 8;
18 static const uint MAX_HELIPADS = 3;
19 static const uint MAX_ELEMENTS = 255;
20
21 static const uint NUM_AIRPORTTILES_PER_GRF = 255;
22
23 static const uint NUM_AIRPORTTILES = 256;
24 static const uint NEW_AIRPORTTILE_OFFSET = 74;
25 static const uint INVALID_AIRPORTTILE = NUM_AIRPORTTILES;
26
28 enum AirportTypes : uint8_t {
29 AT_SMALL = 0,
30 AT_LARGE = 1,
31 AT_HELIPORT = 2,
32 AT_METROPOLITAN = 3,
33 AT_INTERNATIONAL = 4,
34 AT_COMMUTER = 5,
35 AT_HELIDEPOT = 6,
36 AT_INTERCON = 7,
37 AT_HELISTATION = 8,
38 AT_OILRIG = 9,
39 NEW_AIRPORT_OFFSET = 10,
40 NUM_AIRPORTS_PER_GRF = 128,
41 NUM_AIRPORTS = 128,
42 AT_INVALID = 254,
43 AT_DUMMY = 255,
44};
45
47 enum class AirportMovingDataFlag : uint8_t {
48 NoSpeedClamp,
49 Takeoff,
50 SlowTurn,
51 Land,
52 ExactPosition,
53 Brake,
54 HeliRaise,
55 HeliLower,
56 Hold,
57};
58
59using AirportMovingDataFlags = EnumBitSet<AirportMovingDataFlag, uint16_t>;
60
62 enum AirportMovementStates : uint8_t {
63 TO_ALL = 0,
64 HANGAR = 1,
65 TERM1 = 2,
66 TERM2 = 3,
67 TERM3 = 4,
68 TERM4 = 5,
69 TERM5 = 6,
70 TERM6 = 7,
71 HELIPAD1 = 8,
72 HELIPAD2 = 9,
73 TAKEOFF = 10,
74 STARTTAKEOFF = 11,
75 ENDTAKEOFF = 12,
76 HELITAKEOFF = 13,
77 FLYING = 14,
78 LANDING = 15,
79 ENDLANDING = 16,
80 HELILANDING = 17,
81 HELIENDLANDING = 18,
82 TERM7 = 19,
83 TERM8 = 20,
84 HELIPAD3 = 21,
85 MAX_HEADINGS = 21,
86 TERMGROUP = 255,
87};
88
90 enum class AirportBlock : uint8_t {
91 Term1 = 0,
92 Term2 = 1,
93 Term3 = 2,
94 Term4 = 3,
95 Term5 = 4,
96 Term6 = 5,
97 Helipad1 = 6,
98 Helipad2 = 7,
99 RunwayInOut = 8,
100 RunwayIn = 8,
101 AirportBusy = 8,
102 RunwayOut = 9,
103 TaxiwayBusy = 10,
104 OutWay = 11,
105 InWay = 12,
106 AirportEntrance = 13,
107 TermGroup1 = 14,
108 TermGroup2 = 15,
109 Hangar2Area = 16,
110 TermGroup2Enter1 = 17,
111 TermGroup2Enter2 = 18,
112 TermGroup2Exit1 = 19,
113 TermGroup2Exit2 = 20,
114 PreHelipad = 21,
115
116 /* blocks for new airports */
117 Term7 = 22,
118 Term8 = 23,
119 Helipad3 = 24,
120 Hangar1Area = 26,
121 OutWay2 = 27,
122 InWay2 = 28,
123 RunwayIn2 = 29,
124 RunwayOut2 = 10,
125 HelipadGroup = 13,
126 OutWay3 = 31,
127 /* end of new blocks */
128
129 Nothing = 30,
130 Zeppeliner = 62,
131 AirportClosed = 63,
132};
133using AirportBlocks = EnumBitSet<AirportBlock, uint64_t>;
134
136 struct AirportMovingData {
137 int16_t x;
138 int16_t y;
139 AirportMovingDataFlags flags;
140 Direction direction;
141};
142
143 AirportMovingData RotateAirportMovingData(const AirportMovingData *orig, Direction rotation, uint num_tiles_x, uint num_tiles_y);
144
145struct AirportFTAbuildup;
146
148 struct AirportFTA {
149 AirportFTA(const AirportFTAbuildup&);
150
151 std::unique_ptr<AirportFTA> next;
152 AirportBlocks blocks;
153 uint8_t position;
154 uint8_t next_position;
155 uint8_t heading;
156};
157
159 struct AirportFTAClass {
160public:
162 enum class Flag : uint8_t {
163 Airplanes = 0,
164 Helicopters = 1,
165 ShortStrip = 2,
166 };
167 using Flags = EnumBitSet<Flag, uint8_t>;
168
169 AirportFTAClass(
170 const AirportMovingData *moving_data,
171 const uint8_t *terminals,
172 const uint8_t num_helipads,
173 const uint8_t *entry_points,
174 Flags flags,
175 const AirportFTAbuildup *apFA,
176 uint8_t delta_z
177 );
178
184 const AirportMovingData *MovingData(uint8_t position) const
185 {
186 assert(position < nofelements);
187 return &moving_data[position];
188 }
189
190 const AirportMovingData *moving_data;
191 std::vector<AirportFTA> layout;
192 const uint8_t *terminals;
193 const uint8_t num_helipads;
194 Flags flags;
195 uint8_t nofelements;
196 const uint8_t *entry_points;
197 uint8_t delta_z;
198};
199
200
201const AirportFTAClass *GetAirport(const uint8_t airport_type);
202uint8_t GetVehiclePosOnBuild(TileIndex hangar_tile);
203
204#endif /* AIRPORT_H */
MAX_HELIPADS
static const uint MAX_HELIPADS
maximum number of helipads per airport
Definition airport.h:18
MAX_ELEMENTS
static const uint MAX_ELEMENTS
maximum number of aircraft positions at airport
Definition airport.h:19
INVALID_AIRPORTTILE
static const uint INVALID_AIRPORTTILE
id for an invalid airport tile
Definition airport.h:25
MAX_TERMINALS
static const uint MAX_TERMINALS
Some airport-related constants.
Definition airport.h:17
NEW_AIRPORTTILE_OFFSET
static const uint NEW_AIRPORTTILE_OFFSET
offset of first newgrf airport tile
Definition airport.h:24
AirportBlock
AirportBlock
Movement Blocks on Airports blocks (eg_airport_flags).
Definition airport.h:90
AirportBlock::Zeppeliner
@ Zeppeliner
Block for the zeppeliner disaster vehicle.
AirportBlock::Term2
@ Term2
Block belonging to terminal 2.
AirportBlock::AirportClosed
@ AirportClosed
Dummy block for indicating a closed airport.
AirportBlock::Term5
@ Term5
Block belonging to terminal 5.
AirportBlock::Term6
@ Term6
Block belonging to terminal 6.
AirportBlock::Term4
@ Term4
Block belonging to terminal 4.
AirportBlock::Helipad3
@ Helipad3
Block belonging to helipad 3.
AirportBlock::Term7
@ Term7
Block belonging to terminal 7.
AirportBlock::Helipad1
@ Helipad1
Block belonging to helipad 1.
AirportBlock::Term3
@ Term3
Block belonging to terminal 3.
AirportBlock::Term1
@ Term1
Block belonging to terminal 1.
AirportBlock::HelipadGroup
@ HelipadGroup
AirportBlock::Helipad2
@ Helipad2
Block belonging to helipad 2.
AirportBlock::Term8
@ Term8
Block belonging to terminal 8.
AirportBlock::RunwayOut2
@ RunwayOut2
GetVehiclePosOnBuild
uint8_t GetVehiclePosOnBuild(TileIndex hangar_tile)
Get the vehicle position when an aircraft is build at the given tile.
Definition airport.cpp:197
NUM_AIRPORTTILES_PER_GRF
static const uint NUM_AIRPORTTILES_PER_GRF
Number of airport tiles per NewGRF; limited to 255 to allow extending Action3 with an extended byte l...
Definition airport.h:21
GetAirport
const AirportFTAClass * GetAirport(const uint8_t airport_type)
Get the finite state machine of an airport type.
Definition airport.cpp:186
AirportMovingDataFlag
AirportMovingDataFlag
Flags for airport movement data.
Definition airport.h:47
AirportMovingDataFlag::HeliRaise
@ HeliRaise
Helicopter take-off.
AirportMovingDataFlag::HeliLower
@ HeliLower
Helicopter landing.
AirportMovingDataFlag::Land
@ Land
Landing onto landing strip.
AirportMovingDataFlag::Takeoff
@ Takeoff
Takeoff movement.
AirportMovingDataFlag::SlowTurn
@ SlowTurn
Turn slowly (mostly used in the air).
AirportMovingDataFlag::Brake
@ Brake
Taxiing at the airport.
AirportMovingDataFlag::NoSpeedClamp
@ NoSpeedClamp
No speed restrictions.
AirportMovingDataFlag::Hold
@ Hold
Holding pattern movement (above the airport).
AirportMovingDataFlag::ExactPosition
@ ExactPosition
Go exactly to the destination coordinates.
RotateAirportMovingData
AirportMovingData RotateAirportMovingData(const AirportMovingData *orig, Direction rotation, uint num_tiles_x, uint num_tiles_y)
Rotate the airport moving data to another rotation.
Definition airport.cpp:81
NUM_AIRPORTTILES
static const uint NUM_AIRPORTTILES
Total number of airport tiles.
Definition airport.h:23
AirportMovementStates
AirportMovementStates
Movement States on Airports (headings target)
Definition airport.h:62
HELITAKEOFF
@ HELITAKEOFF
Helicopter wants to leave the airport.
Definition airport.h:76
TERM4
@ TERM4
Heading for terminal 4.
Definition airport.h:68
STARTTAKEOFF
@ STARTTAKEOFF
Airplane has arrived at a runway for take-off.
Definition airport.h:74
HELIPAD2
@ HELIPAD2
Heading for helipad 2.
Definition airport.h:72
ENDTAKEOFF
@ ENDTAKEOFF
Airplane has reached end-point of the take-off runway.
Definition airport.h:75
TERM5
@ TERM5
Heading for terminal 5.
Definition airport.h:69
TERM6
@ TERM6
Heading for terminal 6.
Definition airport.h:70
TERM3
@ TERM3
Heading for terminal 3.
Definition airport.h:67
TERM8
@ TERM8
Heading for terminal 8.
Definition airport.h:83
HELIPAD3
@ HELIPAD3
Heading for helipad 3.
Definition airport.h:84
HELIPAD1
@ HELIPAD1
Heading for helipad 1.
Definition airport.h:71
TERM2
@ TERM2
Heading for terminal 2.
Definition airport.h:66
HANGAR
@ HANGAR
Heading for hangar.
Definition airport.h:64
FLYING
@ FLYING
Vehicle is flying in the air.
Definition airport.h:77
TAKEOFF
@ TAKEOFF
Airplane wants to leave the airport.
Definition airport.h:73
HELILANDING
@ HELILANDING
Helicopter wants to land.
Definition airport.h:80
TO_ALL
@ TO_ALL
Go in this direction for every target.
Definition airport.h:63
ENDLANDING
@ ENDLANDING
Airplane wants to finish landing.
Definition airport.h:79
HELIENDLANDING
@ HELIENDLANDING
Helicopter wants to finish landing.
Definition airport.h:81
MAX_HEADINGS
@ MAX_HEADINGS
Last valid target to head for.
Definition airport.h:85
TERM1
@ TERM1
Heading for terminal 1.
Definition airport.h:65
LANDING
@ LANDING
Airplane wants to land.
Definition airport.h:78
TERM7
@ TERM7
Heading for terminal 7.
Definition airport.h:82
TERMGROUP
@ TERMGROUP
Aircraft is looking for a free terminal in a terminalgroup.
Definition airport.h:86
AirportTypes
AirportTypes
Airport types.
Definition airport.h:28
AT_SMALL
@ AT_SMALL
Small airport.
Definition airport.h:29
AT_HELIDEPOT
@ AT_HELIDEPOT
Heli depot.
Definition airport.h:35
AT_INVALID
@ AT_INVALID
Invalid airport.
Definition airport.h:42
AT_METROPOLITAN
@ AT_METROPOLITAN
Metropolitan airport.
Definition airport.h:32
NUM_AIRPORTS
@ NUM_AIRPORTS
Maximal number of airports in total.
Definition airport.h:41
AT_LARGE
@ AT_LARGE
Large airport.
Definition airport.h:30
AT_HELISTATION
@ AT_HELISTATION
Heli station airport.
Definition airport.h:37
AT_DUMMY
@ AT_DUMMY
Dummy airport.
Definition airport.h:43
AT_HELIPORT
@ AT_HELIPORT
Heli port.
Definition airport.h:31
NEW_AIRPORT_OFFSET
@ NEW_AIRPORT_OFFSET
Number of the first newgrf airport.
Definition airport.h:39
NUM_AIRPORTS_PER_GRF
@ NUM_AIRPORTS_PER_GRF
Maximal number of airports per NewGRF.
Definition airport.h:40
AT_INTERCON
@ AT_INTERCON
Intercontinental airport.
Definition airport.h:36
AT_INTERNATIONAL
@ AT_INTERNATIONAL
International airport.
Definition airport.h:33
AT_COMMUTER
@ AT_COMMUTER
Commuter airport.
Definition airport.h:34
AT_OILRIG
@ AT_OILRIG
Oilrig airport.
Definition airport.h:38
EnumBitSet< AirportMovingDataFlag, uint16_t >
direction_type.h
Different types to 'show' directions.
Direction
Direction
Defines the 8 directions on the map.
Definition direction_type.h:24
AirportFTAClass
Finite sTate mAchine (FTA) of an airport.
Definition airport.h:159
AirportFTAClass::num_helipads
const uint8_t num_helipads
Number of helipads on this airport. When 0 helicopters will go to normal terminals.
Definition airport.h:193
AirportFTAClass::MovingData
const AirportMovingData * MovingData(uint8_t position) const
Get movement data at a position.
Definition airport.h:184
AirportFTAClass::Flag
Flag
Bitmask of airport flags.
Definition airport.h:162
AirportFTAClass::Flag::Airplanes
@ Airplanes
Can planes land on this airport type?
AirportFTAClass::Flag::ShortStrip
@ ShortStrip
This airport has a short landing strip, dangerous for fast aircraft.
AirportFTAClass::Flag::Helicopters
@ Helicopters
Can helicopters land on this airport type?
AirportFTAClass::delta_z
uint8_t delta_z
Z adjustment for helicopter pads.
Definition airport.h:197
AirportFTAClass::layout
std::vector< AirportFTA > layout
state machine for airport
Definition airport.h:191
AirportFTAClass::terminals
const uint8_t * terminals
Array with the number of terminal groups, followed by the number of terminals in each group.
Definition airport.h:192
AirportFTAClass::entry_points
const uint8_t * entry_points
when an airplane arrives at this airport, enter it at position entry_point, index depends on directio...
Definition airport.h:196
AirportFTAClass::nofelements
uint8_t nofelements
number of positions the airport consists of
Definition airport.h:195
AirportFTAClass::flags
Flags flags
Flags for this airport type.
Definition airport.h:194
AirportFTAClass::moving_data
const AirportMovingData * moving_data
Movement data.
Definition airport.h:190
AirportFTA
Internal structure used in openttd - Finite sTate mAchine --> FTA.
Definition airport.h:148
AirportFTA::next
std::unique_ptr< AirportFTA > next
possible extra movement choices from this position
Definition airport.h:151
AirportFTA::heading
uint8_t heading
heading (current orders), guiding an airplane to its target on an airport
Definition airport.h:155
AirportFTA::blocks
AirportBlocks blocks
bitmap of blocks that could be reserved
Definition airport.h:152
AirportFTA::position
uint8_t position
the position that an airplane is at
Definition airport.h:153
AirportFTA::next_position
uint8_t next_position
next position from this position
Definition airport.h:154
AirportFTAbuildup
State machine input struct (from external file, etc.) Finite sTate mAchine --> FTA.
Definition airport_movement.h:20
AirportMovingData
A single location on an airport where aircraft can move to.
Definition airport.h:136
AirportMovingData::x
int16_t x
x-coordinate of the destination.
Definition airport.h:137
AirportMovingData::flags
AirportMovingDataFlags flags
special flags when moving towards the destination.
Definition airport.h:139
AirportMovingData::y
int16_t y
y-coordinate of the destination.
Definition airport.h:138
AirportMovingData::direction
Direction direction
Direction to turn the aircraft after reaching the destination.
Definition airport.h:140
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
tile_type.h
Types related to tiles.