OpenTTD Source: src/aircraft.h File Reference

OpenTTD Source 15.3

Data Structures | Enumerations | Functions | Variables
aircraft.h File Reference

Base for aircraft. More...

`#include "station_map.h"`
`#include "vehicle_base.h"`

Go to the source code of this file.

## Data Structures
struct | AircraftCache
| Variables that are cached to improve performance and such. More...
struct | Aircraft
| Aircraft, helicopters, rotors and their shadows belong to this class. More...

## Enumerations
enum | AircraftSubType : uint8_t { AIR_HELICOPTER = 0 , AIR_AIRCRAFT = 2 , AIR_SHADOW = 4 , AIR_ROTOR = 6 }
| An aircraft can be one of those types. More...
enum | AirVehicleFlags : uint8_t { VAF_DEST_TOO_FAR = 0 , VAF_IN_MAX_HEIGHT_CORRECTION = 1 , VAF_IN_MIN_HEIGHT_CORRECTION = 2 , VAF_HELI_DIRECT_DESCENT = 3 }
| Flags for air vehicles; shared with disaster vehicles. More...

## Functions
void | HandleAircraftEnterHangar (Aircraft *v)
| Handle Aircraft specific tasks when an Aircraft enters a hangar.
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).
void | UpdateAirplanesOnNewStation (const Station *st)
| Updates the status of the Aircraft heading or in the station.
void | UpdateAircraftCache (Aircraft *v, bool update_range=false)
| Update cached values of an aircraft.
void | AircraftLeaveHangar (Aircraft *v, Direction exit_dir)
| Aircraft is about to leave the hangar.
void | AircraftNextAirportPos_and_Order (Aircraft *v)
| set the right pos when heading to other airports after takeoff
void | SetAircraftPosition (Aircraft *v, int x, int y, int z)
| Set aircraft position.
void | GetAircraftFlightLevelBounds (const Vehicle *v, int *min, int *max)
| Get the 'flight level' bounds, in pixels from 'z_pos' 0 for a particular vehicle for normal flight situation.
template<class T >
int | GetAircraftFlightLevel (T *v, bool takeoff=false)
void | GetRotorImage (const Aircraft *v, EngineImageType image_type, VehicleSpriteSeq *result)
Station * | GetTargetAirportIfValid (const Aircraft *v)
| Returns aircraft's target station if v->target_airport is a valid station with airport.
void | HandleMissingAircraftOrders (Aircraft *v)

## Variables
static constexpr int | AIRCRAFT_MIN_FLYING_ALTITUDE = 120
| Base values for flight levels above ground level for 'normal' flight and holding patterns.
static constexpr int | AIRCRAFT_MAX_FLYING_ALTITUDE = 360
| Maximum flying altitude above tile.
static constexpr int | PLANE_HOLD_MAX_FLYING_ALTITUDE = 150
| holding flying altitude above tile of planes.
static constexpr int | HELICOPTER_HOLD_MAX_FLYING_ALTITUDE = 184
| holding flying altitude above tile of helicopters.
static const int | ROTOR_Z_OFFSET = 5
| Z Offset between helicopter- and rotorsprite.

## Detailed Description

Base for aircraft.

Definition in file aircraft.h.

## Enumeration Type Documentation

## ◆ AircraftSubType

enum AircraftSubType : uint8_t

An aircraft can be one of those types.

Enumerator
AIR_HELICOPTER | an helicopter
AIR_AIRCRAFT | an airplane
AIR_SHADOW | shadow of the aircraft
AIR_ROTOR | rotor of an helicopter

Definition at line 28 of file aircraft.h.

## ◆ AirVehicleFlags

enum AirVehicleFlags : uint8_t

Flags for air vehicles; shared with disaster vehicles.

Enumerator
VAF_DEST_TOO_FAR | Next destination is too far away.
VAF_IN_MAX_HEIGHT_CORRECTION | The vehicle is currently lowering its altitude because it hit the upper bound.
VAF_IN_MIN_HEIGHT_CORRECTION | The vehicle is currently raising its altitude because it hit the lower bound.
VAF_HELI_DIRECT_DESCENT | The helicopter is descending directly at its destination (helipad or in front of hangar)

Definition at line 36 of file aircraft.h.

## Function Documentation

## ◆ 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 1480 of file aircraft_cmd.cpp.

References Vehicle::cur_speed, Vehicle::direction, Hidden, InvalidateWindowData(), Vehicle::LeaveUnbunchingDepot(), Vehicle::Next(), SpecializedVehicle< T, Type >::Next(), Vehicle::progress, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), SetAircraftPosition(), SetWindowClassesDirty(), Vehicle::subspeed, Vehicle::tile, VehicleServiceInDepot(), Vehicle::vehstatus, WC_AIRCRAFT_LIST, WC_VEHICLE_DEPOT, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by AircraftEventHandler_InHangar(), and UpdateOldAircraft().

## ◆ AircraftNextAirportPos_and_Order()

void AircraftNextAirportPos_and_Order | ( | Aircraft * | v | ) |

set the right pos when heading to other airports after takeoff

Definition at line 1460 of file aircraft_cmd.cpp.

References AircraftGetEntryPoint(), Station::airport, AT_DUMMY, Vehicle::current_order, DIR_N, GetAirport(), Order::GetDestination(), Airport::GetFTA(), GetTargetAirportIfValid(), Order::IsType(), Aircraft::pos, Aircraft::previous_pos, Airport::rotation, and Aircraft::targetairport.

Referenced by AfterLoadGame(), AircraftController(), Aircraft::GetOrderStationLocation(), Vehicle::SendToDepot(), UpdateOldAircraft(), and UpdateOrderDest().

## ◆ GetAircraftFlightLevel()

template<class T >

int GetAircraftFlightLevel | ( | T * | v,
|  | bool | takeoff = `false`
| ) |  |

Definition at line 769 of file aircraft_cmd.cpp.

## ◆ 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 726 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 AfterLoadGame(), AircraftController(), DisasterVehicle::DisasterVehicle(), ReleaseDisasterVehicle(), and UpdateOldAircraft().

## ◆ 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 247 of file aircraft_cmd.cpp.

References VehicleSpriteSeq::GetBounds(), Rect::Height(), UnScaleGUI(), and Rect::Width().

Referenced by EnginePreviewWindow::UpdateWidgetSize().

## ◆ GetRotorImage()

void GetRotorImage | ( | const Aircraft * | v,
|  | EngineImageType | image_type,
|  | VehicleSpriteSeq * | result
| ) |  |

Definition at line 187 of file aircraft_cmd.cpp.

## ◆ 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 2163 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 AfterLoadGame(), AircraftNextAirportPos_and_Order(), CrashAirplane(), Aircraft::FindClosestDepot(), FindNearestHangar(), HandleCrashedAircraft(), MapAircraftMovementState(), and Vehicle::PreDestructor().

## ◆ 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 571 of file aircraft_cmd.cpp.

References Vehicle::cur_speed, Hidden, SpecializedVehicle< T, Type >::Next(), Vehicle::progress, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetAircraftPosition(), Vehicle::subspeed, Vehicle::vehstatus, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by VehicleEnterDepot().

## ◆ HandleMissingAircraftOrders()

void HandleMissingAircraftOrders | ( | Aircraft * | v | ) |

Definition at line 1285 of file aircraft_cmd.cpp.

## ◆ 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 532 of file aircraft_cmd.cpp.

References AIR_HELICOPTER, Clamp(), VehicleSpriteSeq::CopyWithoutPalette(), EIT_ON_MAP, GetSlopePixelZ(), Map::MaxX(), Map::MaxY(), SpecializedVehicle< T, Type >::Next(), ROTOR_Z_OFFSET, Vehicle::sprite_cache, MutableSpriteCache::sprite_seq, Vehicle::subtype, TILE_SIZE, Vehicle::UpdatePosition(), Vehicle::UpdatePositionAndViewport(), SpecializedVehicle< T, Type >::UpdateViewport(), Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by AfterLoadGame(), AircraftController(), AircraftLeaveHangar(), HandleAircraftEnterHangar(), HandleCrashedAircraft(), and UpdateOldAircraft().

## ◆ 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 601 of file aircraft_cmd.cpp.

References VehicleCache::cached_cargo_age_period, AircraftCache::cached_max_range, AircraftCache::cached_max_range_sqr, VehicleCache::cached_max_speed, EngineInfo::cargo_age_period, Vehicle::engine_type, AircraftVehicleInfo::max_range, AircraftVehicleInfo::max_speed, SpecializedVehicle< T, Type >::Next(), PROP_AIRCRAFT_CARGO_AGE_PERIOD, PROP_AIRCRAFT_RANGE, PROP_AIRCRAFT_SPEED, and Vehicle::vcache.

Referenced by AfterLoadGame(), AfterLoadVehiclesPhase2(), AircraftController(), CheckCaches(), CmdBuildAircraft(), CmdRefitVehicle(), UpdateAirplanesOnNewStation(), and UpdateOldAircraft().

## ◆ 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 2177 of file aircraft_cmd.cpp.

References AircraftGetEntryPoint(), Station::airport, CanVehicleUseStation(), Vehicle::current_order, DIR_N, FLYING, Order::GetDepotOrderType(), Order::GetDestination(), Airport::GetFTA(), Airport::HasHangar(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, INVALID_TILE, Aircraft::IsNormalAircraft(), Order::IsType(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate(), Order::MakeDummy(), PartOfOrders, Aircraft::pos, Aircraft::previous_pos, RemoveOrderFromAllVehicles(), Airport::rotation, SetWindowWidgetDirty(), Aircraft::state, Aircraft::targetairport, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), OrthogonalTileArea::tile, UpdateAircraftCache(), WC_VEHICLE_VIEW, and WID_VV_START_STOP.

Referenced by CmdBuildAirport().

## Variable Documentation

## ◆ AIRCRAFT_MAX_FLYING_ALTITUDE

constexpr int AIRCRAFT_MAX_FLYING_ALTITUDE = 360
| staticconstexpr

Maximum flying altitude above tile.

Definition at line 21 of file aircraft.h.

Referenced by GetAircraftFlightLevelBounds().

## ◆ AIRCRAFT_MIN_FLYING_ALTITUDE

constexpr int AIRCRAFT_MIN_FLYING_ALTITUDE = 120
| staticconstexpr

Base values for flight levels above ground level for 'normal' flight and holding patterns.

Due to speed and direction, the actual flight level may be higher. Minimum flying altitude above tile.

Definition at line 20 of file aircraft.h.

Referenced by GetAircraftFlightLevelBounds().

## ◆ HELICOPTER_HOLD_MAX_FLYING_ALTITUDE

constexpr int HELICOPTER_HOLD_MAX_FLYING_ALTITUDE = 184
| staticconstexpr

holding flying altitude above tile of helicopters.

Definition at line 23 of file aircraft.h.

Referenced by GetAircraftFlightLevelBounds(), and GetAircraftHoldMaxAltitude().

## ◆ PLANE_HOLD_MAX_FLYING_ALTITUDE

constexpr int PLANE_HOLD_MAX_FLYING_ALTITUDE = 150
| staticconstexpr

holding flying altitude above tile of planes.

Definition at line 22 of file aircraft.h.

Referenced by GetAircraftFlightLevelBounds(), and GetAircraftHoldMaxAltitude().

## ◆ ROTOR_Z_OFFSET

const int ROTOR_Z_OFFSET = 5
| static

Z Offset between helicopter- and rotorsprite.

Definition at line 48 of file aircraft.h.

Referenced by CmdBuildAircraft(), DisasterVehicle::DisasterVehicle(), SetAircraftPosition(), and DisasterVehicle::UpdatePosition().