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 airport.h Various declarations for airports */ 9 10 #ifndef AIRPORT_H 11 #define AIRPORT_H 12 13 #include "direction_type.h" 14 #include "tile_type.h" 15 16 /** Some airport-related constants */ 17 static const uint MAX_TERMINALS = 8; ///< maximum number of terminals per airport 18 static const uint MAX_HELIPADS = 3; ///< maximum number of helipads per airport 19 static const uint MAX_ELEMENTS = 255; ///< maximum number of aircraft positions at airport 20 21 static const uint NUM_AIRPORTTILES_PER_GRF = 255; ///< Number of airport tiles per NewGRF; limited to 255 to allow extending Action3 with an extended byte later on. 22 23 static const uint NUM_AIRPORTTILES = 256; ///< Total number of airport tiles. 24 static const uint NEW_AIRPORTTILE_OFFSET = 74; ///< offset of first newgrf airport tile 25 static const uint INVALID_AIRPORTTILE = NUM_AIRPORTTILES; ///< id for an invalid airport tile 26 27 /** Airport types */ 28 enum AirportTypes { 29 AT_SMALL = 0, ///< Small airport. 30 AT_LARGE = 1, ///< Large airport. 31 AT_HELIPORT = 2, ///< Heli port. 32 AT_METROPOLITAN = 3, ///< Metropolitan airport. 33 AT_INTERNATIONAL = 4, ///< International airport. 34 AT_COMMUTER = 5, ///< Commuter airport. 35 AT_HELIDEPOT = 6, ///< Heli depot. 36 AT_INTERCON = 7, ///< Intercontinental airport. 37 AT_HELISTATION = 8, ///< Heli station airport. 38 AT_OILRIG = 9, ///< Oilrig airport. 39 NEW_AIRPORT_OFFSET = 10, ///< Number of the first newgrf airport. 40 NUM_AIRPORTS_PER_GRF = 128, ///< Maximal number of airports per NewGRF. 41 NUM_AIRPORTS = 128, ///< Maximal number of airports in total. 42 AT_INVALID = 254, ///< Invalid airport. 43 AT_DUMMY = 255, ///< Dummy airport. 44 }; 45 46 /** Flags for airport movement data. */ 47 enum AirportMovingDataFlags { 48 AMED_NOSPDCLAMP = 1 << 0, ///< No speed restrictions. 49 AMED_TAKEOFF = 1 << 1, ///< Takeoff movement. 50 AMED_SLOWTURN = 1 << 2, ///< Turn slowly (mostly used in the air). 51 AMED_LAND = 1 << 3, ///< Landing onto landing strip. 52 AMED_EXACTPOS = 1 << 4, ///< Go exactly to the destination coordinates. 53 AMED_BRAKE = 1 << 5, ///< Taxiing at the airport. 54 AMED_HELI_RAISE = 1 << 6, ///< Helicopter take-off. 55 AMED_HELI_LOWER = 1 << 7, ///< Helicopter landing. 56 AMED_HOLD = 1 << 8, ///< Holding pattern movement (above the airport). 57 }; 58 59 /** Movement States on Airports (headings target) */ 60 enum AirportMovementStates { 61 TO_ALL = 0, ///< Go in this direction for every target. 62 HANGAR = 1, ///< Heading for hangar. 63 TERM1 = 2, ///< Heading for terminal 1. 64 TERM2 = 3, ///< Heading for terminal 2. 65 TERM3 = 4, ///< Heading for terminal 3. 66 TERM4 = 5, ///< Heading for terminal 4. 67 TERM5 = 6, ///< Heading for terminal 5. 68 TERM6 = 7, ///< Heading for terminal 6. 69 HELIPAD1 = 8, ///< Heading for helipad 1. 70 HELIPAD2 = 9, ///< Heading for helipad 2. 71 TAKEOFF = 10, ///< Airplane wants to leave the airport. 72 STARTTAKEOFF = 11, ///< Airplane has arrived at a runway for take-off. 73 ENDTAKEOFF = 12, ///< Airplane has reached end-point of the take-off runway. 74 HELITAKEOFF = 13, ///< Helicopter wants to leave the airport. 75 FLYING = 14, ///< %Vehicle is flying in the air. 76 LANDING = 15, ///< Airplane wants to land. 77 ENDLANDING = 16, ///< Airplane wants to finish landing. 78 HELILANDING = 17, ///< Helicopter wants to land. 79 HELIENDLANDING = 18, ///< Helicopter wants to finish landing. 80 TERM7 = 19, ///< Heading for terminal 7. 81 TERM8 = 20, ///< Heading for terminal 8. 82 HELIPAD3 = 21, ///< Heading for helipad 3. 83 MAX_HEADINGS = 21, ///< Last valid target to head for. 84 TERMGROUP = 255, ///< Aircraft is looking for a free terminal in a terminalgroup. 85 }; 86 87 /** Movement Blocks on Airports blocks (eg_airport_flags). */ 88 static const uint64 89 TERM1_block = 1ULL << 0, ///< Block belonging to terminal 1. 90 TERM2_block = 1ULL << 1, ///< Block belonging to terminal 2. 91 TERM3_block = 1ULL << 2, ///< Block belonging to terminal 3. 92 TERM4_block = 1ULL << 3, ///< Block belonging to terminal 4. 93 TERM5_block = 1ULL << 4, ///< Block belonging to terminal 5. 94 TERM6_block = 1ULL << 5, ///< Block belonging to terminal 6. 95 HELIPAD1_block = 1ULL << 6, ///< Block belonging to helipad 1. 96 HELIPAD2_block = 1ULL << 7, ///< Block belonging to helipad 2. 97 RUNWAY_IN_OUT_block = 1ULL << 8, 98 RUNWAY_IN_block = 1ULL << 8, 99 AIRPORT_BUSY_block = 1ULL << 8, 100 RUNWAY_OUT_block = 1ULL << 9, 101 TAXIWAY_BUSY_block = 1ULL << 10, 102 OUT_WAY_block = 1ULL << 11, 103 IN_WAY_block = 1ULL << 12, 104 AIRPORT_ENTRANCE_block = 1ULL << 13, 105 TERM_GROUP1_block = 1ULL << 14, 106 TERM_GROUP2_block = 1ULL << 15, 107 HANGAR2_AREA_block = 1ULL << 16, 108 TERM_GROUP2_ENTER1_block = 1ULL << 17, 109 TERM_GROUP2_ENTER2_block = 1ULL << 18, 110 TERM_GROUP2_EXIT1_block = 1ULL << 19, 111 TERM_GROUP2_EXIT2_block = 1ULL << 20, 112 PRE_HELIPAD_block = 1ULL << 21, 113 114 /* blocks for new airports */ 115 TERM7_block = 1ULL << 22, ///< Block belonging to terminal 7. 116 TERM8_block = 1ULL << 23, ///< Block belonging to terminal 8. 117 HELIPAD3_block = 1ULL << 24, ///< Block belonging to helipad 3. 118 HANGAR1_AREA_block = 1ULL << 26, 119 OUT_WAY2_block = 1ULL << 27, 120 IN_WAY2_block = 1ULL << 28, 121 RUNWAY_IN2_block = 1ULL << 29, 122 RUNWAY_OUT2_block = 1ULL << 10, ///< @note re-uses #TAXIWAY_BUSY_block 123 HELIPAD_GROUP_block = 1ULL << 13, ///< @note re-uses #AIRPORT_ENTRANCE_block 124 OUT_WAY_block2 = 1ULL << 31, 125 /* end of new blocks */ 126 127 NOTHING_block = 1ULL << 30, 128 AIRPORT_CLOSED_block = 1ULL << 63; ///< Dummy block for indicating a closed airport. 129 130 /** A single location on an airport where aircraft can move to. */ 131 struct AirportMovingData { 132 int16 x; ///< x-coordinate of the destination. 133 int16 y; ///< y-coordinate of the destination. 134 uint16 flag; ///< special flags when moving towards the destination. 135 Direction direction; ///< Direction to turn the aircraft after reaching the destination. 136 }; 137 138 AirportMovingData RotateAirportMovingData(const AirportMovingData *orig, Direction rotation, uint num_tiles_x, uint num_tiles_y); 139 140 struct AirportFTAbuildup; 141 142 /** Finite sTate mAchine (FTA) of an airport. */ 143 struct AirportFTAClass { 144 public: 145 /** Bitmask of airport flags. */ 146 enum Flags { 147 AIRPLANES = 0x1, ///< Can planes land on this airport type? 148 HELICOPTERS = 0x2, ///< Can helicopters land on this airport type? 149 ALL = AIRPLANES | HELICOPTERS, ///< Mask to check for both planes and helicopters. 150 SHORT_STRIP = 0x4, ///< This airport has a short landing strip, dangerous for fast aircraft. 151 }; 152 153 AirportFTAClass( 154 const AirportMovingData *moving_data, 155 const byte *terminals, 156 const byte num_helipads, 157 const byte *entry_points, 158 Flags flags, 159 const AirportFTAbuildup *apFA, 160 byte delta_z 161 ); 162 163 ~AirportFTAClass(); 164 165 /** 166 * Get movement data at a position. 167 * @param position Element number to get movement data about. 168 * @return Pointer to the movement data. 169 */ MovingDataAirportFTAClass170 const AirportMovingData *MovingData(byte position) const 171 { 172 assert(position < nofelements); 173 return &moving_data[position]; 174 } 175 176 const AirportMovingData *moving_data; ///< Movement data. 177 struct AirportFTA *layout; ///< state machine for airport 178 const byte *terminals; ///< %Array with the number of terminal groups, followed by the number of terminals in each group. 179 const byte num_helipads; ///< Number of helipads on this airport. When 0 helicopters will go to normal terminals. 180 Flags flags; ///< Flags for this airport type. 181 byte nofelements; ///< number of positions the airport consists of 182 const byte *entry_points; ///< when an airplane arrives at this airport, enter it at position entry_point, index depends on direction 183 byte delta_z; ///< Z adjustment for helicopter pads 184 }; 185 186 DECLARE_ENUM_AS_BIT_SET(AirportFTAClass::Flags) 187 188 189 /** Internal structure used in openttd - Finite sTate mAchine --> FTA */ 190 struct AirportFTA { 191 AirportFTA *next; ///< possible extra movement choices from this position 192 uint64 block; ///< 64 bit blocks (st->airport.flags), should be enough for the most complex airports 193 byte position; ///< the position that an airplane is at 194 byte next_position; ///< next position from this position 195 byte heading; ///< heading (current orders), guiding an airplane to its target on an airport 196 }; 197 198 const AirportFTAClass *GetAirport(const byte airport_type); 199 byte GetVehiclePosOnBuild(TileIndex hangar_tile); 200 201 #endif /* AIRPORT_H */ 202