2009-08-21 20:21:05 +00:00
/*
* This file is part of OpenTTD .
* 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.
* 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 .
* 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/>.
*/
2007-02-23 01:48:53 +00:00
/** @file airport.h Various declarations for airports */
2004-08-09 17:04:08 +00:00
# ifndef AIRPORT_H
# define AIRPORT_H
2007-12-18 19:52:14 +00:00
# include "direction_type.h"
2010-03-18 18:38:32 +00:00
# include "tile_type.h"
2007-01-10 18:56:51 +00:00
2010-02-22 14:15:48 +00:00
/** Some airport-related constants */
2010-08-13 00:21:03 +00:00
static const uint MAX_TERMINALS = 8 ; ///< maximum number of terminals per airport
static const uint MAX_HELIPADS = 3 ; ///< maximum number of helipads per airport
2010-05-13 10:14:29 +00:00
static const uint MAX_ELEMENTS = 255 ; ///< maximum number of aircraft positions at airport
2013-10-12 16:34:59 +00:00
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.
static const uint NUM_AIRPORTTILES = 256 ; ///< Total number of airport tiles.
2010-05-13 10:14:29 +00:00
static const uint NEW_AIRPORTTILE_OFFSET = 74 ; ///< offset of first newgrf airport tile
static const uint INVALID_AIRPORTTILE = NUM_AIRPORTTILES ; ///< id for an invalid airport tile
2004-08-09 17:04:08 +00:00
2009-05-28 21:54:03 +00:00
/** Airport types */
2010-05-13 09:44:44 +00:00
enum AirportTypes {
2010-11-05 16:34:22 +00:00
AT_SMALL = 0 , ///< Small airport.
AT_LARGE = 1 , ///< Large airport.
AT_HELIPORT = 2 , ///< Heli port.
AT_METROPOLITAN = 3 , ///< Metropolitan airport.
AT_INTERNATIONAL = 4 , ///< International airport.
AT_COMMUTER = 5 , ///< Commuter airport.
AT_HELIDEPOT = 6 , ///< Heli depot.
AT_INTERCON = 7 , ///< Intercontinental airport.
AT_HELISTATION = 8 , ///< Heli station airport.
AT_OILRIG = 9 , ///< Oilrig airport.
NEW_AIRPORT_OFFSET = 10 , ///< Number of the first newgrf airport.
2013-10-12 16:34:23 +00:00
NUM_AIRPORTS_PER_GRF = 128 , ///< Maximal number of airports per NewGRF.
NUM_AIRPORTS = 128 , ///< Maximal number of airports in total.
2010-11-05 16:34:22 +00:00
AT_INVALID = 254 , ///< Invalid airport.
AT_DUMMY = 255 , ///< Dummy airport.
2004-08-09 17:04:08 +00:00
} ;
2010-11-05 16:34:22 +00:00
/** Flags for airport movement data. */
2010-05-13 09:44:44 +00:00
enum AirportMovingDataFlags {
2010-11-05 16:34:22 +00:00
AMED_NOSPDCLAMP = 1 < < 0 , ///< No speed restrictions.
AMED_TAKEOFF = 1 < < 1 , ///< Takeoff movement.
AMED_SLOWTURN = 1 < < 2 , ///< Turn slowly (mostly used in the air).
AMED_LAND = 1 < < 3 , ///< Landing onto landing strip.
AMED_EXACTPOS = 1 < < 4 , ///< Go exactly to the destination coordinates.
AMED_BRAKE = 1 < < 5 , ///< Taxiing at the airport.
AMED_HELI_RAISE = 1 < < 6 , ///< Helicopter take-off.
AMED_HELI_LOWER = 1 < < 7 , ///< Helicopter landing.
2011-12-19 17:48:04 +00:00
AMED_HOLD = 1 < < 8 , ///< Holding pattern movement (above the airport).
2006-05-01 11:27:39 +00:00
} ;
2010-11-05 16:34:22 +00:00
/** Movement States on Airports (headings target) */
2010-05-13 09:44:44 +00:00
enum AirportMovementStates {
2019-09-08 11:03:24 +00:00
TO_ALL = 0 , ///< Go in this direction for every target.
HANGAR = 1 , ///< Heading for hangar.
TERM1 = 2 , ///< Heading for terminal 1.
TERM2 = 3 , ///< Heading for terminal 2.
TERM3 = 4 , ///< Heading for terminal 3.
TERM4 = 5 , ///< Heading for terminal 4.
TERM5 = 6 , ///< Heading for terminal 5.
TERM6 = 7 , ///< Heading for terminal 6.
HELIPAD1 = 8 , ///< Heading for helipad 1.
HELIPAD2 = 9 , ///< Heading for helipad 2.
TAKEOFF = 10 , ///< Airplane wants to leave the airport.
STARTTAKEOFF = 11 , ///< Airplane has arrived at a runway for take-off.
ENDTAKEOFF = 12 , ///< Airplane has reached end-point of the take-off runway.
HELITAKEOFF = 13 , ///< Helicopter wants to leave the airport.
FLYING = 14 , ///< %Vehicle is flying in the air.
LANDING = 15 , ///< Airplane wants to land.
ENDLANDING = 16 , ///< Airplane wants to finish landing.
HELILANDING = 17 , ///< Helicopter wants to land.
HELIENDLANDING = 18 , ///< Helicopter wants to finish landing.
TERM7 = 19 , ///< Heading for terminal 7.
TERM8 = 20 , ///< Heading for terminal 8.
HELIPAD3 = 21 , ///< Heading for helipad 3.
MAX_HEADINGS = 21 , ///< Last valid target to head for.
TERMGROUP = 255 , ///< Aircraft is looking for a free terminal in a terminalgroup.
2006-05-01 11:27:39 +00:00
} ;
2010-11-05 16:34:22 +00:00
/** Movement Blocks on Airports blocks (eg_airport_flags). */
2007-02-13 12:34:54 +00:00
static const uint64
2010-11-05 16:34:22 +00:00
TERM1_block = 1ULL < < 0 , ///< Block belonging to terminal 1.
TERM2_block = 1ULL < < 1 , ///< Block belonging to terminal 2.
TERM3_block = 1ULL < < 2 , ///< Block belonging to terminal 3.
TERM4_block = 1ULL < < 3 , ///< Block belonging to terminal 4.
TERM5_block = 1ULL < < 4 , ///< Block belonging to terminal 5.
TERM6_block = 1ULL < < 5 , ///< Block belonging to terminal 6.
HELIPAD1_block = 1ULL < < 6 , ///< Block belonging to helipad 1.
HELIPAD2_block = 1ULL < < 7 , ///< Block belonging to helipad 2.
2007-07-03 23:23:38 +00:00
RUNWAY_IN_OUT_block = 1ULL < < 8 ,
RUNWAY_IN_block = 1ULL < < 8 ,
AIRPORT_BUSY_block = 1ULL < < 8 ,
RUNWAY_OUT_block = 1ULL < < 9 ,
TAXIWAY_BUSY_block = 1ULL < < 10 ,
OUT_WAY_block = 1ULL < < 11 ,
IN_WAY_block = 1ULL < < 12 ,
AIRPORT_ENTRANCE_block = 1ULL < < 13 ,
TERM_GROUP1_block = 1ULL < < 14 ,
TERM_GROUP2_block = 1ULL < < 15 ,
HANGAR2_AREA_block = 1ULL < < 16 ,
TERM_GROUP2_ENTER1_block = 1ULL < < 17 ,
TERM_GROUP2_ENTER2_block = 1ULL < < 18 ,
TERM_GROUP2_EXIT1_block = 1ULL < < 19 ,
TERM_GROUP2_EXIT2_block = 1ULL < < 20 ,
PRE_HELIPAD_block = 1ULL < < 21 ,
2006-06-23 22:05:40 +00:00
2009-06-21 20:57:01 +00:00
/* blocks for new airports */
2010-11-05 16:34:22 +00:00
TERM7_block = 1ULL < < 22 , ///< Block belonging to terminal 7.
TERM8_block = 1ULL < < 23 , ///< Block belonging to terminal 8.
HELIPAD3_block = 1ULL < < 24 , ///< Block belonging to helipad 3.
2007-07-03 23:23:38 +00:00
HANGAR1_AREA_block = 1ULL < < 26 ,
OUT_WAY2_block = 1ULL < < 27 ,
IN_WAY2_block = 1ULL < < 28 ,
RUNWAY_IN2_block = 1ULL < < 29 ,
2010-11-05 16:34:22 +00:00
RUNWAY_OUT2_block = 1ULL < < 10 , ///< @note re-uses #TAXIWAY_BUSY_block
HELIPAD_GROUP_block = 1ULL < < 13 , ///< @note re-uses #AIRPORT_ENTRANCE_block
2007-07-03 23:23:38 +00:00
OUT_WAY_block2 = 1ULL < < 31 ,
2009-06-21 20:57:01 +00:00
/* end of new blocks */
2006-06-23 22:05:40 +00:00
2012-04-17 19:43:18 +00:00
NOTHING_block = 1ULL < < 30 ,
AIRPORT_CLOSED_block = 1ULL < < 63 ; ///< Dummy block for indicating a closed airport.
2006-05-01 11:27:39 +00:00
2010-08-02 23:09:38 +00:00
/** A single location on an airport where aircraft can move to. */
2007-03-07 12:11:48 +00:00
struct AirportMovingData {
2019-04-22 07:11:28 +00:00
int16 x ; ///< x-coordinate of the destination.
int16 y ; ///< y-coordinate of the destination.
uint16 flag ; ///< special flags when moving towards the destination.
Direction direction ; ///< Direction to turn the aircraft after reaching the destination.
2007-03-07 12:11:48 +00:00
} ;
2006-05-01 11:27:39 +00:00
2010-08-05 12:03:06 +00:00
AirportMovingData RotateAirportMovingData ( const AirportMovingData * orig , Direction rotation , uint num_tiles_x , uint num_tiles_y ) ;
2007-02-04 10:25:57 +00:00
struct AirportFTAbuildup ;
2010-11-05 16:34:22 +00:00
/** Finite sTate mAchine (FTA) of an airport. */
2007-03-07 12:11:48 +00:00
struct AirportFTAClass {
2009-06-21 21:05:06 +00:00
public :
2010-08-02 23:09:38 +00:00
/** Bitmask of airport flags. */
2009-06-21 21:05:06 +00:00
enum Flags {
2010-08-02 23:09:38 +00:00
AIRPLANES = 0x1 , ///< Can planes land on this airport type?
HELICOPTERS = 0x2 , ///< Can helicopters land on this airport type?
ALL = AIRPLANES | HELICOPTERS , ///< Mask to check for both planes and helicopters.
2011-12-19 17:48:04 +00:00
SHORT_STRIP = 0x4 , ///< This airport has a short landing strip, dangerous for fast aircraft.
2009-06-21 21:05:06 +00:00
} ;
AirportFTAClass (
const AirportMovingData * moving_data ,
const byte * terminals ,
2010-08-13 00:36:12 +00:00
const byte num_helipads ,
2009-06-21 21:05:06 +00:00
const byte * entry_points ,
Flags flags ,
const AirportFTAbuildup * apFA ,
2010-01-15 12:08:08 +00:00
byte delta_z
2009-06-21 21:05:06 +00:00
) ;
2007-02-04 10:25:57 +00:00
2009-06-21 20:57:01 +00:00
~ AirportFTAClass ( ) ;
2007-02-04 10:25:57 +00:00
2010-11-05 16:34:22 +00:00
/**
* Get movement data at a position .
* @ param position Element number to get movement data about .
* @ return Pointer to the movement data .
*/
2009-06-21 20:57:01 +00:00
const AirportMovingData * MovingData ( byte position ) const
{
assert ( position < nofelements ) ;
return & moving_data [ position ] ;
}
2007-02-03 13:03:11 +00:00
2010-11-05 16:34:22 +00:00
const AirportMovingData * moving_data ; ///< Movement data.
2008-04-11 18:00:51 +00:00
struct AirportFTA * layout ; ///< state machine for airport
2012-01-01 17:22:32 +00:00
const byte * terminals ; ///< %Array with the number of terminal groups, followed by the number of terminals in each group.
2010-08-13 00:36:12 +00:00
const byte num_helipads ; ///< Number of helipads on this airport. When 0 helicopters will go to normal terminals.
2010-11-05 16:34:22 +00:00
Flags flags ; ///< Flags for this airport type.
2008-04-11 18:00:51 +00:00
byte nofelements ; ///< number of positions the airport consists of
2007-02-16 12:10:19 +00:00
const byte * entry_points ; ///< when an airplane arrives at this airport, enter it at position entry_point, index depends on direction
2008-04-11 18:00:51 +00:00
byte delta_z ; ///< Z adjustment for helicopter pads
2007-03-07 12:11:48 +00:00
} ;
2004-08-09 17:04:08 +00:00
2007-02-15 20:35:45 +00:00
DECLARE_ENUM_AS_BIT_SET ( AirportFTAClass : : Flags )
2009-06-21 21:05:06 +00:00
/** Internal structure used in openttd - Finite sTate mAchine --> FTA */
2007-03-07 12:11:48 +00:00
struct AirportFTA {
2008-04-11 18:00:51 +00:00
AirportFTA * next ; ///< possible extra movement choices from this position
2010-03-18 21:02:20 +00:00
uint64 block ; ///< 64 bit blocks (st->airport.flags), should be enough for the most complex airports
2008-04-11 18:00:51 +00:00
byte position ; ///< the position that an airplane is at
byte next_position ; ///< next position from this position
byte heading ; ///< heading (current orders), guiding an airplane to its target on an airport
2007-03-07 12:11:48 +00:00
} ;
2004-08-09 17:04:08 +00:00
2006-07-26 03:33:12 +00:00
const AirportFTAClass * GetAirport ( const byte airport_type ) ;
2010-03-18 18:38:32 +00:00
byte GetVehiclePosOnBuild ( TileIndex hangar_tile ) ;
2004-08-09 17:04:08 +00:00
# endif /* AIRPORT_H */