OpenTTD Source: src/aircraft_cmd.cpp File Reference

OpenTTD Source 12.2

Data Structures | Typedefs | Enumerations | Functions | Variables
aircraft_cmd.cpp File Reference
`#include "stdafx.h"`
`#include "aircraft.h"`
`#include "landscape.h"`
`#include "news_func.h"`
`#include "newgrf_engine.h"`
`#include "newgrf_sound.h"`
`#include "spritecache.h"`
`#include "strings_func.h"`
`#include "command_func.h"`
`#include "window_func.h"`
`#include "date_func.h"`
`#include "vehicle_func.h"`
`#include "sound_func.h"`
`#include "cheat_type.h"`
`#include "company_base.h"`
`#include "ai/ai.hpp"`
`#include "game/game.hpp"`
`#include "company_func.h"`
`#include "effectvehicle_func.h"`
`#include "station_base.h"`
`#include "engine_base.h"`
`#include "core/random_func.hpp"`
`#include "core/backup_type.hpp"`
`#include "zoom_func.h"`
`#include "disaster_vehicle.h"`
`#include "newgrf_airporttiles.h"`
`#include "framerate_type.h"`
`#include "table/strings.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | MovementTerminalMapping
| Combination of aircraft state for going to a certain terminal and the airport flag for that terminal block. More...

## Typedefs
typedef void | AircraftStateHandler(Aircraft *v, const AirportFTAClass *apc)
| Signature of the aircraft handler function. More...

## Enumerations
enum | HelicopterRotorStates { HRS_ROTOR_STOPPED, HRS_ROTOR_MOVING_1, HRS_ROTOR_MOVING_2, HRS_ROTOR_MOVING_3 }
| Helicopter rotor animation states.
enum | AircraftSpeedLimits { SPEED_LIMIT_TAXI = 50, SPEED_LIMIT_APPROACH = 230, SPEED_LIMIT_BROKEN = 320, SPEED_LIMIT_HOLD = 425, SPEED_LIMIT_NONE = 0xFFFF }
| Special velocities for aircraft. More...

## Functions
static bool | AirportMove (Aircraft *v, const AirportFTAClass *apc)
static bool | AirportSetBlocks (Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc)
| "reserve" a block for the plane More...
static bool | AirportHasBlock (Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc)
| returns true if the road ahead is busy, eg. More...
static bool | AirportFindFreeTerminal (Aircraft *v, const AirportFTAClass *apc)
| Find a free terminal, and assign it if available. More...
static bool | AirportFindFreeHelipad (Aircraft *v, const AirportFTAClass *apc)
| Find a free helipad, and assign it if available. More...
static void | CrashAirplane (Aircraft *v)
| Bring the aircraft in a crashed state, create the explosion animation, and create a news item about the crash. More...
template<>
bool | IsValidImageIndex< VEH_AIRCRAFT > (uint8 image_index)
static StationID | FindNearestHangar (const Aircraft *v)
| Find the nearest hangar to v INVALID_STATION is returned, if the company does not have any suitable airports (like helipads only) More...
void | GetRotorImage (const Aircraft *v, EngineImageType image_type, VehicleSpriteSeq *result)
static void | GetAircraftIcon (EngineID engine, EngineImageType image_type, VehicleSpriteSeq *result)
void | DrawAircraftEngine (int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
void | GetAircraftSpriteSize (EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
| Get the size of the sprite of an aircraft sprite heading west (used for lists). More...
CommandCost | CmdBuildAircraft (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret)
| Build an aircraft. More...
static void | CheckIfAircraftNeedsService (Aircraft *v)
static void | HelicopterTickHandler (Aircraft *v)
void | SetAircraftPosition (Aircraft *v, int x, int y, int z)
| Set aircraft position. More...
void | HandleAircraftEnterHangar (Aircraft *v)
| Handle Aircraft specific tasks when an Aircraft enters a hangar. More...
static void | PlayAircraftSound (const Vehicle *v)
void | UpdateAircraftCache (Aircraft *v, bool update_range)
| Update cached values of an aircraft. More...
static int | UpdateAircraftSpeed (Aircraft *v, uint speed_limit=SPEED_LIMIT_NONE, bool hard_limit=true)
| Sets the new speed for an aircraft. More...
int | GetTileHeightBelowAircraft (const Vehicle *v)
| Get the tile height below the aircraft. More...
void | GetAircraftFlightLevelBounds (const Vehicle *v, int *min_level, int *max_level)
| Get the 'flight level' bounds, in pixels from 'z_pos' 0 for a particular vehicle for normal flight situation. More...
int | GetAircraftHoldMaxAltitude (const Aircraft *v)
| Gets the maximum 'flight level' for the holding pattern of the aircraft, in pixels 'z_pos' 0, depending on terrain below. More...
template<class T >
int | GetAircraftFlightLevel (T *v, bool takeoff)
template int | GetAircraftFlightLevel (DisasterVehicle *v, bool takeoff)
template int | GetAircraftFlightLevel (Aircraft *v, bool takeoff)
static byte | AircraftGetEntryPoint (const Aircraft *v, const AirportFTAClass *apc, Direction rotation)
| Find the entry point to an airport depending on direction which the airport is being approached from. More...
static void | MaybeCrashAirplane (Aircraft *v)
| Decide whether aircraft v should crash. More...
static bool | AircraftController (Aircraft *v)
| Controls the movement of an aircraft. More...
static bool | HandleCrashedAircraft (Aircraft *v)
| Handle crashed aircraft v. More...
static void | HandleAircraftSmoke (Aircraft *v, bool mode)
| Handle smoke of broken aircraft. More...
void | HandleMissingAircraftOrders (Aircraft *v)
static void | AircraftEntersTerminal (Aircraft *v)
| Aircraft arrives at a terminal. More...
static void | AircraftLandAirplane (Aircraft *v)
| Aircraft touched down at the landing strip. More...
void | AircraftNextAirportPos_and_Order (Aircraft *v)
| set the right pos when heading to other airports after takeoff
void | AircraftLeaveHangar (Aircraft *v, Direction exit_dir)
| Aircraft is about to leave the hangar. More...
static void | AircraftEventHandler_EnterTerminal (Aircraft *v, const AirportFTAClass *apc)
static void | AircraftEventHandler_EnterHangar (Aircraft *v, const AirportFTAClass *apc)
| Aircraft arrived in an airport hangar. More...
static void | AircraftEventHandler_InHangar (Aircraft *v, const AirportFTAClass *apc)
| Handle aircraft movement/decision making in an airport hangar. More...
static void | AircraftEventHandler_AtTerminal (Aircraft *v, const AirportFTAClass *apc)
| At one of the Airport's Terminals.
static void | AircraftEventHandler_General (Aircraft *v, const AirportFTAClass *apc)
static void | AircraftEventHandler_TakeOff (Aircraft *v, const AirportFTAClass *apc)
static void | AircraftEventHandler_StartTakeOff (Aircraft *v, const AirportFTAClass *apc)
static void | AircraftEventHandler_EndTakeOff (Aircraft *v, const AirportFTAClass *apc)
static void | AircraftEventHandler_HeliTakeOff (Aircraft *v, const AirportFTAClass *apc)
static void | AircraftEventHandler_Flying (Aircraft *v, const AirportFTAClass *apc)
static void | AircraftEventHandler_Landing (Aircraft *v, const AirportFTAClass *apc)
static void | AircraftEventHandler_HeliLanding (Aircraft *v, const AirportFTAClass *apc)
static void | AircraftEventHandler_EndLanding (Aircraft *v, const AirportFTAClass *apc)
static void | AircraftEventHandler_HeliEndLanding (Aircraft *v, const AirportFTAClass *apc)
static void | AirportClearBlock (const Aircraft *v, const AirportFTAClass *apc)
static void | AirportGoToNextPosition (Aircraft *v)
static bool | FreeTerminal (Aircraft *v, byte i, byte last_terminal)
| Find a free terminal or helipad, and if available, assign it. More...
static uint | GetNumTerminals (const AirportFTAClass *apc)
| Get the number of terminals at the airport. More...
static void | AircraftHandleDestTooFar (Aircraft *v, bool too_far)
| Handle the 'dest too far' flag and the corresponding news message for aircraft. More...
static bool | AircraftEventHandler (Aircraft *v, int loop)
Station * | GetTargetAirportIfValid (const Aircraft *v)
| Returns aircraft's target station if v->target_airport is a valid station with airport. More...
void | UpdateAirplanesOnNewStation (const Station *st)
| Updates the status of the Aircraft heading or in the station. More...

## Variables
static const SpriteID | _aircraft_sprite []
static AircraftStateHandler *const | _aircraft_state_handlers []
| Array of handler functions for each target of the aircraft. More...
static const MovementTerminalMapping | _airport_terminal_mapping []
| A list of all valid terminals and their associated blocks. More...

## Detailed Description

This file deals with aircraft and airport movements functionalities

Definition in file aircraft_cmd.cpp.

## Typedef Documentation

## ◆ AircraftStateHandler

typedef void AircraftStateHandler(Aircraft *v, const AirportFTAClass *apc)

Signature of the aircraft handler function.

Parameters

  v | Aircraft to handle.
  apc | Airport state machine.

Definition at line 1736 of file aircraft_cmd.cpp.

## Enumeration Type Documentation

## ◆ AircraftSpeedLimits

enum AircraftSpeedLimits

Special velocities for aircraft.

Enumerator
SPEED_LIMIT_TAXI | Maximum speed of an aircraft while taxiing.
SPEED_LIMIT_APPROACH | Maximum speed of an aircraft on finals.
SPEED_LIMIT_BROKEN | Maximum speed of an aircraft that is broken.
SPEED_LIMIT_HOLD | Maximum speed of an aircraft that flies the holding pattern.
SPEED_LIMIT_NONE | No environmental speed limit. Speed limit is type dependent.

Definition at line 621 of file aircraft_cmd.cpp.

## Function Documentation

## ◆ AircraftController()

static bool AircraftController | ( | Aircraft * | v | ) |
| static

Controls the movement of an aircraft.

This function actually moves the vehicle on the map and takes care of minor things like sound playback.

Todo:
  De-mystify the cur_speed values for helicopter rotors.

Parameters

  v | The vehicle that is moved. Must be the first vehicle of the chain

Returns
  Whether the position requested by the State Machine has been reached

Definition at line 857 of file aircraft_cmd.cpp.

References AircraftGetEntryPoint(), AircraftNextAirportPos_and_Order(), Station::airport, AT_DUMMY, Vehicle::current_order, DIR_N, FLYING, GetAirport(), Order::GetDestination(), Airport::GetFTA(), SpecializedStation< Station, false >::GetIfValid(), OrthogonalTileArea::h, INVALID_TILE, AirportFTAClass::nofelements, Aircraft::pos, Aircraft::previous_pos, Airport::rotation, SetAircraftPosition(), Aircraft::state, Aircraft::targetairport, OrthogonalTileArea::tile, UpdateAircraftCache(), OrthogonalTileArea::w, Vehicle::x_pos, BaseStation::xy, and Vehicle::y_pos.

## ◆ AircraftEntersTerminal()

static void AircraftEntersTerminal | ( | Aircraft * | v | ) |
| static

Aircraft arrives at a terminal.

If it is the first aircraft, throw a party. Start loading cargo.

Parameters

  v | Aircraft that arrived.

Definition at line 1385 of file aircraft_cmd.cpp.

References Vehicle::current_order, and Order::IsType().

## ◆ AircraftEventHandler_EnterHangar()

static void AircraftEventHandler_EnterHangar | ( | Aircraft * | v,
|  | const AirportFTAClass * | apc
| ) |  |
| static

Aircraft arrived in an airport hangar.

Parameters

  v | Aircraft in the hangar.
  apc | Airport description containing the hangar.

Definition at line 1490 of file aircraft_cmd.cpp.

References AirportFTA::heading, AirportFTAClass::layout, Aircraft::pos, Aircraft::state, and VehicleEnterDepot().

Referenced by AircraftEventHandler_InHangar().

## ◆ AircraftEventHandler_InHangar()

static void AircraftEventHandler_InHangar | ( | Aircraft * | v,
|  | const AirportFTAClass * | apc
| ) |  |
| static

Handle aircraft movement/decision making in an airport hangar.

Parameters

  v | Aircraft in the hangar.
  apc | Airport description containing the hangar.

Definition at line 1501 of file aircraft_cmd.cpp.

References AircraftEventHandler_EnterHangar(), Vehicle::current_order, Order::IsType(), Aircraft::pos, and Aircraft::previous_pos.

## ◆ AircraftGetEntryPoint()

static byte AircraftGetEntryPoint | ( | const Aircraft * | v,
|  | const AirportFTAClass * | apc,
|  | Direction | rotation
| ) |  |
| static

Find the entry point to an airport depending on direction which the airport is being approached from.

Each airport can have up to four entry points for its approach system so that approaching aircraft do not fly through each other or are forced to do 180 degree turns during the approach. The arrivals are grouped into four sectors dependent on the DiagDirection from which the airport is approached.

Parameters

  v | The vehicle that is approaching the airport
  apc | The Airport Class being approached.
  rotation | The rotation of the airport.

Returns
  The index of the entry point

Definition at line 816 of file aircraft_cmd.cpp.

References abs(), Station::airport, ChangeDiagDir(), DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, DiagDirDifference(), DirToDiagDir(), AirportFTAClass::entry_points, SpecializedStation< Station, false >::GetIfValid(), INVALID_TILE, Aircraft::targetairport, OrthogonalTileArea::tile, TILE_SIZE, TileX(), TileY(), Vehicle::x_pos, BaseStation::xy, and Vehicle::y_pos.

Referenced by AircraftController().

## ◆ AircraftHandleDestTooFar()

static void AircraftHandleDestTooFar | ( | Aircraft * | v,
|  | bool | too_far
| ) |  |
| static

Handle the 'dest too far' flag and the corresponding news message for aircraft.

Parameters

  v | The aircraft.
  too_far | True if the current destination is too far away.

Definition at line 2036 of file aircraft_cmd.cpp.

References _local_company, AddVehicleAdviceNewsItem(), ClrBit(), DeleteVehicleNews(), Aircraft::flags, HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, AI::NewEvent(), Vehicle::owner, SetBit(), SetDParam(), SetWindowWidgetDirty(), VAF_DEST_TOO_FAR, WC_VEHICLE_VIEW, and WID_VV_START_STOP.

## ◆ AircraftLandAirplane()

static void AircraftLandAirplane | ( | Aircraft * | v | ) |
| static

Aircraft touched down at the landing strip.

Parameters

  v | Aircraft that landed.

Definition at line 1414 of file aircraft_cmd.cpp.

References SpecializedStation< Station, false >::Get(), Aircraft::targetairport, TileVirtXY(), Aircraft::UpdateDeltaXY(), Vehicle::x_pos, and Vehicle::y_pos.

## ◆ AircraftLeaveHangar()

void AircraftLeaveHangar | ( | Aircraft * | v,
|  | Direction | exit_dir
| ) |  |

Aircraft is about to leave the hangar.

Parameters

  v | Aircraft leaving.
  exit_dir | The direction the vehicle leaves the hangar.

Note
  This function is called in AfterLoadGame for old savegames, so don't rely on any data to be valid, especially don't rely on the fact that the vehicle is actually on the ground inside a depot.

Definition at line 1451 of file aircraft_cmd.cpp.

References Vehicle::cur_speed, Vehicle::direction, InvalidateWindowData(), Vehicle::Next(), SpecializedVehicle< T, Type >::Next(), Vehicle::progress, SetAircraftPosition(), SetWindowClassesDirty(), Vehicle::subspeed, Vehicle::tile, VehicleServiceInDepot(), Vehicle::vehstatus, VS_HIDDEN, WC_AIRCRAFT_LIST, WC_VEHICLE_DEPOT, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by UpdateOldAircraft().

## ◆ AirportFindFreeHelipad()

static bool AirportFindFreeHelipad | ( | Aircraft * | v,
|  | const AirportFTAClass * | apc
| ) |  |
| static

Find a free helipad, and assign it if available.

Parameters

  v | Aircraft to handle.
  apc | Airport state machine.

Returns
  Found a free helipad and assigned it.

Definition at line 2021 of file aircraft_cmd.cpp.

References AirportFindFreeTerminal(), FreeTerminal(), MAX_TERMINALS, and AirportFTAClass::num_helipads.

## ◆ AirportFindFreeTerminal()

static bool AirportFindFreeTerminal | ( | Aircraft * | v,
|  | const AirportFTAClass * | apc
| ) |  |
| static

Find a free terminal, and assign it if available.

Parameters

  v | Aircraft to handle.
  apc | Airport state machine.

Returns
  Found a free terminal and assigned it.

Definition at line 1968 of file aircraft_cmd.cpp.

References Station::airport, AirportFTA::block, Airport::flags, FreeTerminal(), SpecializedStation< Station, false >::Get(), GetNumTerminals(), AirportFTA::heading, AirportFTAClass::layout, AirportFTA::next, AirportFTA::next_position, Aircraft::pos, Aircraft::targetairport, TERMGROUP, and AirportFTAClass::terminals.

Referenced by AirportFindFreeHelipad().

## ◆ AirportHasBlock()

static bool AirportHasBlock | ( | Aircraft * | v,
|  | const AirportFTA * | current_pos,
|  | const AirportFTAClass * | apc
| ) |  |
| static

returns true if the road ahead is busy, eg.

you must wait before proceeding.

Definition at line 1833 of file aircraft_cmd.cpp.

References AirportFTA::block, SpecializedStation< Station, false >::Get(), AirportFTAClass::layout, AirportFTA::next_position, Aircraft::pos, AirportFTA::position, and Aircraft::targetairport.

## ◆ AirportSetBlocks()

static bool AirportSetBlocks | ( | Aircraft * | v,
|  | const AirportFTA * | current_pos,
|  | const AirportFTAClass * | apc
| ) |  |
| static

"reserve" a block for the plane

Parameters

  v | airplane that requires the operation
  current_pos | of the vehicle in the list of blocks
  apc | airport on which block is requested to be set

Returns
  true on success. Eg, next block was free and we have occupied it

Definition at line 1864 of file aircraft_cmd.cpp.

References Station::airport, AirportFTA::block, Vehicle::cur_speed, Airport::flags, SpecializedStation< Station, false >::Get(), AirportFTA::heading, AirportFTAClass::layout, AirportFTA::next, AirportFTA::next_position, Aircraft::pos, AirportFTA::position, Vehicle::subspeed, and Aircraft::targetairport.

## ◆ CmdBuildAircraft()

CommandCost CmdBuildAircraft | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | const Engine * | e,
|  | uint16 | data,
|  | Vehicle ** | ret
| ) |  |

Build an aircraft.

Parameters

  | tile | tile of the depot where aircraft is built.
  | flags | type of operation.
  | e | the engine to build.
  | data | unused.
  [out] | ret | the vehicle that has been built.

Returns
  the cost of this operation or an error.

Definition at line 268 of file aircraft_cmd.cpp.

References _current_company, Station::airport, CanVehicleUseStation(), CMD_ERROR, DC_EXEC, DIR_SE, Vehicle::direction, SpecializedStation< Station, false >::GetByTile(), Airport::GetHangarNum(), Airport::GetHangarTile(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::owner, and Vehicle::tile.

## ◆ CrashAirplane()

static void CrashAirplane | ( | Aircraft * | v | ) |
| static

Bring the aircraft in a crashed state, create the explosion animation, and create a news item about the crash.

Parameters

  v | Aircraft that crashed.

Definition at line 1320 of file aircraft_cmd.cpp.

References Vehicle::cargo, Aircraft::Crash(), CreateEffectVehicleRel(), EV_EXPLOSION_LARGE, GetTargetAirportIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Game::NewEvent(), AI::NewEvent(), SpecializedVehicle< T, Type >::Next(), Vehicle::owner, SetDParam(), Vehicle::tile, TileVirtXY(), VehicleCargoList::Truncate(), Vehicle::x_pos, and Vehicle::y_pos.

## ◆ FindNearestHangar()

static StationID FindNearestHangar | ( | const Aircraft * | v | ) |
| static

Find the nearest hangar to v INVALID_STATION is returned, if the company does not have any suitable airports (like helipads only)

Parameters

  v | vehicle looking for a hangar

Returns
  the StationID if one is found, otherwise, INVALID_STATION

Definition at line 120 of file aircraft_cmd.cpp.

Referenced by Aircraft::FindClosestDepot().

## ◆ FreeTerminal()

static bool FreeTerminal | ( | Aircraft * | v,
|  | byte | i,
|  | byte | last_terminal
| ) |  |
| static

Find a free terminal or helipad, and if available, assign it.

Parameters

  v | Aircraft looking for a free terminal or helipad.
  i | First terminal to examine.
  last_terminal | Terminal number to stop examining.

Returns
  A terminal or helipad has been found, and has been assigned to the aircraft.

Definition at line 1933 of file aircraft_cmd.cpp.

References _airport_terminal_mapping, Station::airport, MovementTerminalMapping::airport_flag, Airport::flags, SpecializedStation< Station, false >::Get(), lengthof, SETBITS, Aircraft::state, MovementTerminalMapping::state, and Aircraft::targetairport.

Referenced by AirportFindFreeHelipad(), and AirportFindFreeTerminal().

## ◆ GetAircraftFlightLevelBounds()

void GetAircraftFlightLevelBounds | ( | const Vehicle * | v,
|  | int * | min_level,
|  | int * | max_level
| ) |  |

Get the 'flight level' bounds, in pixels from 'z_pos' 0 for a particular vehicle for normal flight situation.

When the maximum is reached the vehicle should consider descending. When the minimum is reached the vehicle should consider ascending.

Parameters

  | v | The vehicle to get the flight levels for.
  [out] | min_level | The minimum bounds for flight level.
  [out] | max_level | The maximum bounds for flight level.

Definition at line 718 of file aircraft_cmd.cpp.

References AIR_HELICOPTER, AIRCRAFT_MAX_FLYING_ALTITUDE, AIRCRAFT_MIN_FLYING_ALTITUDE, VehicleCache::cached_max_speed, DIR_E, DIR_N, DIR_NE, DIR_SE, Vehicle::direction, SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), GetTileHeightBelowAircraft(), HELICOPTER_HOLD_MAX_FLYING_ALTITUDE, PLANE_HOLD_MAX_FLYING_ALTITUDE, Vehicle::subtype, BaseVehicle::type, Vehicle::vcache, and VEH_AIRCRAFT.

Referenced by ReleaseDisastersTargetingVehicle().

## ◆ GetAircraftHoldMaxAltitude()

int GetAircraftHoldMaxAltitude | ( | const Aircraft * | v | ) |

Gets the maximum 'flight level' for the holding pattern of the aircraft, in pixels 'z_pos' 0, depending on terrain below.

Parameters

  v | The aircraft that may or may not need to decrease its altitude.

Returns
  Maximal aircraft holding altitude, while in normal flight, in pixels.

Definition at line 753 of file aircraft_cmd.cpp.

References AIR_HELICOPTER, GetTileHeightBelowAircraft(), HELICOPTER_HOLD_MAX_FLYING_ALTITUDE, PLANE_HOLD_MAX_FLYING_ALTITUDE, and Vehicle::subtype.

## ◆ GetAircraftSpriteSize()

void GetAircraftSpriteSize | ( | EngineID | engine,
|  | uint & | width,
|  | uint & | height,
|  | int & | xoffs,
|  | int & | yoffs,
|  | EngineImageType | image_type
| ) |  |

Get the size of the sprite of an aircraft sprite heading west (used for lists).

Parameters

  | engine | The engine to get the sprite from.
  [out] | width | The width of the sprite.
  [out] | height | The height of the sprite.
  [out] | xoffs | Number of pixels to shift the sprite to the right.
  [out] | yoffs | Number of pixels to shift the sprite downwards.
  | image_type | Context the sprite is used in.

Definition at line 245 of file aircraft_cmd.cpp.

## ◆ GetNumTerminals()

static uint GetNumTerminals | ( | const AirportFTAClass * | apc | ) |
| static

Get the number of terminals at the airport.

Parameters

  apc | Airport description.

Returns
  Number of terminals.

Definition at line 1953 of file aircraft_cmd.cpp.

References AirportFTAClass::terminals.

Referenced by AirportFindFreeTerminal().

## ◆ GetTargetAirportIfValid()

Station* GetTargetAirportIfValid | ( | const Aircraft * | v | ) |

Returns aircraft's target station if v->target_airport is a valid station with airport.

Parameters

  v | vehicle to get target airport for

Returns
  pointer to target station, nullptr if invalid

Definition at line 2125 of file aircraft_cmd.cpp.

References Station::airport, SpecializedStation< Station, false >::GetIfValid(), INVALID_TILE, Aircraft::targetairport, OrthogonalTileArea::tile, BaseVehicle::type, and VEH_AIRCRAFT.

Referenced by CrashAirplane(), Aircraft::FindClosestDepot(), HandleCrashedAircraft(), and MapAircraftMovementState().

## ◆ GetTileHeightBelowAircraft()

int GetTileHeightBelowAircraft | ( | const Vehicle * | v | ) |

Get the tile height below the aircraft.

This function is needed because aircraft can leave the mapborders.

Parameters

  v | The vehicle to get the height for.

Returns
  The height in pixels from 'z_pos' 0.

Definition at line 701 of file aircraft_cmd.cpp.

References Clamp(), MapMaxX(), MapMaxY(), TILE_HEIGHT, TILE_SIZE, TileHeight(), TileVirtXY(), Vehicle::x_pos, and Vehicle::y_pos.

Referenced by GetAircraftFlightLevelBounds(), and GetAircraftHoldMaxAltitude().

## ◆ HandleAircraftEnterHangar()

void HandleAircraftEnterHangar | ( | Aircraft * | v | ) |

Handle Aircraft specific tasks when an Aircraft enters a hangar.

Parameters

  *v | Vehicle that enters the hangar

Definition at line 561 of file aircraft_cmd.cpp.

References Vehicle::cur_speed, SpecializedVehicle< T, Type >::Next(), Vehicle::progress, SetAircraftPosition(), Vehicle::subspeed, Vehicle::vehstatus, VS_HIDDEN, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by VehicleEnterDepot().

## ◆ HandleAircraftSmoke()

static void HandleAircraftSmoke | ( | Aircraft * | v,
|  | bool | mode
| ) |  |
| static

Handle smoke of broken aircraft.

Parameters

  v | Aircraft
  mode | Is this the non-first call for this vehicle in this tick?

Definition at line 1221 of file aircraft_cmd.cpp.

## ◆ HandleCrashedAircraft()

static bool HandleCrashedAircraft | ( | Aircraft * | v | ) |
| static

Handle crashed aircraft v.

Parameters

  v | Crashed aircraft.

Definition at line 1163 of file aircraft_cmd.cpp.

References Aircraft::crashed_counter, and GetTargetAirportIfValid().

## ◆ MaybeCrashAirplane()

static void MaybeCrashAirplane | ( | Aircraft * | v | ) |
| static

Decide whether aircraft v should crash.

Parameters

  v | Aircraft to test.

Definition at line 1354 of file aircraft_cmd.cpp.

References Station::airport, AirportFTAClass::flags, SpecializedStation< Station, false >::Get(), Airport::GetFTA(), AirportFTAClass::SHORT_STRIP, and Aircraft::targetairport.

## ◆ SetAircraftPosition()

void SetAircraftPosition | ( | Aircraft * | v,
|  | int | x,
|  | int | y,
|  | int | z
| ) |  |

Set aircraft position.

Parameters

  v | Aircraft to position.
  x | New X position.
  y | New y position.
  z | New z position.

Definition at line 522 of file aircraft_cmd.cpp.

Referenced by AircraftController(), AircraftLeaveHangar(), and HandleAircraftEnterHangar().

## ◆ UpdateAircraftCache()

void UpdateAircraftCache | ( | Aircraft * | v,
|  | bool | update_range
| ) |  |

Update cached values of an aircraft.

Currently caches callback 36 max speed.

Parameters

  v | Vehicle
  update_range | Update the aircraft range.

Definition at line 591 of file aircraft_cmd.cpp.

Referenced by AircraftController(), and UpdateOldAircraft().

## ◆ UpdateAircraftSpeed()

static int UpdateAircraftSpeed | ( | Aircraft * | v,
|  | uint | speed_limit = `SPEED_LIMIT_NONE`,
|  | bool | hard_limit = `true`
| ) |  |
| static

Sets the new speed for an aircraft.

Parameters

  v | The vehicle for which the speed should be obtained
  speed_limit | The maximum speed the vehicle may have.
  hard_limit | If true, the limit is directly enforced, otherwise the plane is slowed down gradually

Returns
  The number of position updates needed within the tick

'acceleration' has the unit 3/8 mph/tick. This function is called twice per tick. So the speed amount we need to accelerate is: acceleration * 3 / 16 mph = acceleration * 3 / 16 * 16 / 10 km-ish/h = acceleration * 3 / 10 * 256 * (km-ish/h / 256) ~ acceleration * 77 (km-ish/h / 256)

Definition at line 636 of file aircraft_cmd.cpp.

References _settings_game, Vehicle::acceleration, VehicleCache::cached_max_speed, Vehicle::cur_speed, Vehicle::GetOldAdvanceSpeed(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, VehicleSettings::plane_speed, Vehicle::progress, SetWindowWidgetDirty(), SPEED_LIMIT_BROKEN, Vehicle::subspeed, Vehicle::vcache, GameSettings::vehicle, Vehicle::vehstatus, VS_AIRCRAFT_BROKEN, WC_VEHICLE_VIEW, and WID_VV_START_STOP.

## ◆ UpdateAirplanesOnNewStation()

void UpdateAirplanesOnNewStation | ( | const Station * | st | ) |

Updates the status of the Aircraft heading or in the station.

Parameters

  st | Station been updated

Definition at line 2139 of file aircraft_cmd.cpp.

References Station::airport, Vehicle::current_order, DIR_N, FLYING, Airport::GetFTA(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_TILE, Aircraft::IsNormalAircraft(), Order::IsType(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::Iterate(), Airport::rotation, Aircraft::state, Aircraft::targetairport, and OrthogonalTileArea::tile.

## Variable Documentation

## ◆ _aircraft_sprite

const SpriteID _aircraft_sprite[]
| static

Initial value:
= {
0x0EB5, 0x0EBD, 0x0EC5, 0x0ECD,
0x0ED5, 0x0EDD, 0x0E9D, 0x0EA5,
0x0EAD, 0x0EE5, 0x0F05, 0x0F0D,
0x0F15, 0x0F1D, 0x0F25, 0x0F2D,
0x0EED, 0x0EF5, 0x0EFD, 0x0F35,
0x0E9D, 0x0EA5, 0x0EAD, 0x0EB5,
0x0EBD, 0x0EC5
}

Definition at line 89 of file aircraft_cmd.cpp.

## ◆ _aircraft_state_handlers

AircraftStateHandler* const _aircraft_state_handlers[]
| static

Initial value:
= {
AircraftEventHandler_General,
AircraftEventHandler_InHangar,
AircraftEventHandler_AtTerminal,
AircraftEventHandler_AtTerminal,
AircraftEventHandler_AtTerminal,
AircraftEventHandler_AtTerminal,
AircraftEventHandler_AtTerminal,
AircraftEventHandler_AtTerminal,
AircraftEventHandler_AtTerminal,
AircraftEventHandler_AtTerminal,
AircraftEventHandler_TakeOff,
AircraftEventHandler_StartTakeOff,
AircraftEventHandler_EndTakeOff,
AircraftEventHandler_HeliTakeOff,
AircraftEventHandler_Flying,
AircraftEventHandler_Landing,
AircraftEventHandler_EndLanding,
AircraftEventHandler_HeliLanding,
AircraftEventHandler_HeliEndLanding,
AircraftEventHandler_AtTerminal,
AircraftEventHandler_AtTerminal,
AircraftEventHandler_AtTerminal,
}

Array of handler functions for each target of the aircraft.

Definition at line 1738 of file aircraft_cmd.cpp.

## ◆ _airport_terminal_mapping

const MovementTerminalMapping _airport_terminal_mapping[]
| static

Initial value:
= {
{TERM1, TERM1_block},
{TERM2, TERM2_block},
{TERM3, TERM3_block},
{TERM4, TERM4_block},
{TERM5, TERM5_block},
{TERM6, TERM6_block},
{TERM7, TERM7_block},
{TERM8, TERM8_block},
{HELIPAD1, HELIPAD1_block},
{HELIPAD2, HELIPAD2_block},
{HELIPAD3, HELIPAD3_block},
}

A list of all valid terminals and their associated blocks.

Definition at line 1912 of file aircraft_cmd.cpp.

Referenced by FreeTerminal().

HELIPAD3_block
static const uint64 HELIPAD3_block
Block belonging to helipad 3.
Definition: airport.h:117
TERM5_block
static const uint64 TERM5_block
Block belonging to terminal 5.
Definition: airport.h:93
TERM1
@ TERM1
Heading for terminal 1.
Definition: airport.h:63
HELIPAD2_block
static const uint64 HELIPAD2_block
Block belonging to helipad 2.
Definition: airport.h:96
TERM7
@ TERM7
Heading for terminal 7.
Definition: airport.h:80
TERM3
@ TERM3
Heading for terminal 3.
Definition: airport.h:65
AircraftEventHandler_InHangar
static void AircraftEventHandler_InHangar(Aircraft *v, const AirportFTAClass *apc)
Handle aircraft movement/decision making in an airport hangar.
Definition: aircraft_cmd.cpp:1501
TERM7_block
static const uint64 TERM7_block
Block belonging to terminal 7.
Definition: airport.h:115
TERM5
@ TERM5
Heading for terminal 5.
Definition: airport.h:67
HELIPAD3
@ HELIPAD3
Heading for helipad 3.
Definition: airport.h:82
TERM1_block
static const uint64 TERM1_block
Movement Blocks on Airports blocks (eg_airport_flags).
Definition: airport.h:89
TERM2
@ TERM2
Heading for terminal 2.
Definition: airport.h:64
AircraftEventHandler_AtTerminal
static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *apc)
At one of the Airport's Terminals.
Definition: aircraft_cmd.cpp:1547
HELIPAD1
@ HELIPAD1
Heading for helipad 1.
Definition: airport.h:69
TERM8_block
static const uint64 TERM8_block
Block belonging to terminal 8.
Definition: airport.h:116
TERM4_block
static const uint64 TERM4_block
Block belonging to terminal 4.
Definition: airport.h:92
TERM6
@ TERM6
Heading for terminal 6.
Definition: airport.h:68
TERM8
@ TERM8
Heading for terminal 8.
Definition: airport.h:81
HELIPAD2
@ HELIPAD2
Heading for helipad 2.
Definition: airport.h:70
HELIPAD1_block
static const uint64 HELIPAD1_block
Block belonging to helipad 1.
Definition: airport.h:95
TERM3_block
static const uint64 TERM3_block
Block belonging to terminal 3.
Definition: airport.h:91
TERM2_block
static const uint64 TERM2_block
Block belonging to terminal 2.
Definition: airport.h:90
TERM6_block
static const uint64 TERM6_block
Block belonging to terminal 6.
Definition: airport.h:94
TERM4
@ TERM4
Heading for terminal 4.
Definition: airport.h:66