OpenTTD Source 20250312-master-gcdcc6b491d
aircraft_cmd.cpp File Reference

This file deals with aircraft and airport movements functionalities. More...

#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 "error_func.h"
#include "strings_func.h"
#include "command_func.h"
#include "window_func.h"
#include "timer/timer_game_calendar.h"
#include "timer/timer_game_economy.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 "aircraft_cmd.h"
#include "vehicle_cmd.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.
 

Enumerations

enum  HelicopterRotorStates : uint8_t { HRS_ROTOR_STOPPED , HRS_ROTOR_MOVING_1 , HRS_ROTOR_MOVING_2 , HRS_ROTOR_MOVING_3 }
 Helicopter rotor animation states. 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
 
static bool AirportHasBlock (Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc)
 returns true if the road ahead is busy, eg.
 
static bool AirportFindFreeTerminal (Aircraft *v, const AirportFTAClass *apc)
 Find a free terminal, and assign it if available.
 
static bool AirportFindFreeHelipad (Aircraft *v, const AirportFTAClass *apc)
 Find a free helipad, and assign it if available.
 
static void CrashAirplane (Aircraft *v)
 Bring the aircraft in a crashed state, create the explosion animation, and create a news item about the crash.
 
template<>
bool IsValidImageIndex< VEH_AIRCRAFT > (uint8_t image_index)
 
static StationID FindNearestHangar (const Aircraft *v)
 Find the nearest hangar to v StationID::Invalid() is returned, if the company does not have any suitable airports (like helipads only)
 
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).
 
CommandCost CmdBuildAircraft (DoCommandFlags flags, TileIndex tile, const Engine *e, Vehicle **ret)
 Build an aircraft.
 
static void CheckIfAircraftNeedsService (Aircraft *v)
 
static void HelicopterTickHandler (Aircraft *v)
 
void SetAircraftPosition (Aircraft *v, int x, int y, int z)
 Set aircraft position.
 
void HandleAircraftEnterHangar (Aircraft *v)
 Handle Aircraft specific tasks when an Aircraft enters a hangar.
 
static void PlayAircraftSound (const Vehicle *v)
 
void UpdateAircraftCache (Aircraft *v, bool update_range)
 Update cached values of an aircraft.
 
static int UpdateAircraftSpeed (Aircraft *v, uint speed_limit=SPEED_LIMIT_NONE, bool hard_limit=true)
 Sets the new speed for an aircraft.
 
int GetTileHeightBelowAircraft (const Vehicle *v)
 Get the tile height below the aircraft.
 
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.
 
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.
 
template<class T >
int GetAircraftFlightLevel (T *v, bool takeoff)
 
template int GetAircraftFlightLevel (DisasterVehicle *v, bool takeoff)
 
template int GetAircraftFlightLevel (Aircraft *v, bool takeoff)
 
static uint8_t 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.
 
static void MaybeCrashAirplane (Aircraft *v)
 Decide whether aircraft v should crash.
 
static bool AircraftController (Aircraft *v)
 Controls the movement of an aircraft.
 
static bool HandleCrashedAircraft (Aircraft *v)
 Handle crashed aircraft v.
 
static void HandleAircraftSmoke (Aircraft *v, bool mode)
 Handle smoke of broken aircraft.
 
void HandleMissingAircraftOrders (Aircraft *v)
 
static void AircraftEntersTerminal (Aircraft *v)
 Aircraft arrives at a terminal.
 
static void AircraftLandAirplane (Aircraft *v)
 Aircraft touched down at the landing strip.
 
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.
 
static void AircraftEventHandler_EnterTerminal (Aircraft *v, const AirportFTAClass *apc)
 
static void AircraftEventHandler_EnterHangar (Aircraft *v, const AirportFTAClass *apc)
 Aircraft arrived in an airport hangar.
 
static void AircraftEventHandler_InHangar (Aircraft *v, const AirportFTAClass *apc)
 Handle aircraft movement/decision making in an airport hangar.
 
static void AircraftEventHandler_AtTerminal (Aircraft *v, const AirportFTAClass *apc)
 At one of the Airport's Terminals.
 
static void AircraftEventHandler_General (Aircraft *, const AirportFTAClass *)
 
static void AircraftEventHandler_TakeOff (Aircraft *v, const AirportFTAClass *)
 
static void AircraftEventHandler_StartTakeOff (Aircraft *v, const AirportFTAClass *)
 
static void AircraftEventHandler_EndTakeOff (Aircraft *v, const AirportFTAClass *)
 
static void AircraftEventHandler_HeliTakeOff (Aircraft *v, const AirportFTAClass *)
 
static void AircraftEventHandler_Flying (Aircraft *v, const AirportFTAClass *apc)
 
static void AircraftEventHandler_Landing (Aircraft *v, const AirportFTAClass *)
 
static void AircraftEventHandler_HeliLanding (Aircraft *v, const AirportFTAClass *)
 
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, uint8_t i, uint8_t last_terminal)
 Find a free terminal or helipad, and if available, assign it.
 
static uint GetNumTerminals (const AirportFTAClass *apc)
 Get the number of terminals at the airport.
 
static void AircraftHandleDestTooFar (Aircraft *v, bool too_far)
 Handle the 'dest too far' flag and the corresponding news message for aircraft.
 
static bool AircraftEventHandler (Aircraft *v, int loop)
 
StationGetTargetAirportIfValid (const Aircraft *v)
 Returns aircraft's target station if v->target_airport is a valid station with airport.
 
void UpdateAirplanesOnNewStation (const Station *st)
 Updates the status of the Aircraft heading or in the station.
 

Variables

static const SpriteID _aircraft_sprite []
 
static constexpr uint16_t SPEED_LIMIT_TAXI = 50
 Special velocities for aircraft.
 
static constexpr uint16_t SPEED_LIMIT_APPROACH = 230
 Maximum speed of an aircraft on finals.
 
static constexpr uint16_t SPEED_LIMIT_BROKEN = 320
 Maximum speed of an aircraft that is broken.
 
static constexpr uint16_t SPEED_LIMIT_HOLD = 425
 Maximum speed of an aircraft that flies the holding pattern.
 
static constexpr uint16_t SPEED_LIMIT_NONE = UINT16_MAX
 No environmental speed limit. Speed limit is type dependent.
 
static AircraftStateHandler *const _aircraft_state_handlers []
 Array of handler functions for each target of the aircraft.
 
static const MovementTerminalMapping _airport_terminal_mapping []
 A list of all valid terminals and their associated blocks.
 

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
vAircraft to handle.
apcAirport state machine.

Definition at line 1755 of file aircraft_cmd.cpp.

Enumeration Type Documentation

◆ HelicopterRotorStates

enum HelicopterRotorStates : uint8_t

Helicopter rotor animation states.

Definition at line 110 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
vThe 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 867 of file aircraft_cmd.cpp.

References _settings_game, abs(), AIR_AIRCRAFT, AircraftGetEntryPoint(), AircraftNextAirportPos_and_Order(), Station::airport, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::All(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), AT_DUMMY, AT_OILRIG, Brake, CeilDiv(), ChangeDir(), ClrBit(), Crashed, Vehicle::cur_speed, Vehicle::current_order, AirportFTAClass::delta_z, DIR_N, DIRDIFF_45LEFT, DIRDIFF_45RIGHT, DIRDIFF_REVERSE, DIRDIFF_SAME, DirDifference(), AirportMovingData::direction, Vehicle::direction, Vehicle::engine_type, ExactPosition, Aircraft::flags, AirportMovingData::flags, FLYING, GetAircraftFlightLevelBounds(), GetAircraftHoldMaxAltitude(), GetAirport(), Order::GetDestination(), Airport::GetFTA(), Airport::GetHangarTile(), SpecializedStation< Station, false >::GetIfValid(), GetNewVehiclePos(), GetSlopePixelZ(), GetTileMaxPixelZ(), OrthogonalTileArea::h, Airport::HasHangar(), HeliLower, HeliRaise, Hold, INVALID_TILE, Land, MaybeCrashAirplane(), AirportFTAClass::MovingData(), GetNewVehiclePosResult::new_tile, SpecializedVehicle< T, Type >::Next(), AirportFTAClass::nofelements, NoSpeedClamp, Aircraft::number_consecutive_turns, GetNewVehiclePosResult::old_tile, ORIGINAL_SAMPLE_COUNT, VehicleSettings::plane_speed, PlayVehicleSound(), Aircraft::pos, Aircraft::previous_pos, RotateAirportMovingData(), Airport::rotation, SetAircraftPosition(), SetBit(), SlowTurn, SND_18_TAKEOFF_HELICOPTER, SPEED_LIMIT_APPROACH, SPEED_LIMIT_HOLD, SPEED_LIMIT_NONE, SPEED_LIMIT_TAXI, Aircraft::state, Vehicle::subtype, Takeoff, Aircraft::targetairport, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), OrthogonalTileArea::tile, Vehicle::tile, TILE_SIZE, TileVirtXY(), TileX(), TileY(), Aircraft::turn_counter, Airport::type, UpdateAircraftCache(), UpdateAircraftSpeed(), VAF_HELI_DIRECT_DESCENT, GameSettings::vehicle, Vehicle::vehstatus, VSE_START, OrthogonalTileArea::w, AirportMovingData::x, Vehicle::x_pos, BaseStation::xy, AirportMovingData::y, GetNewVehiclePosResult::y, Vehicle::y_pos, and Vehicle::z_pos.

◆ AircraftEntersTerminal()

◆ AircraftEventHandler()

static bool AircraftEventHandler ( Aircraft v,
int  loop 
)
static

Definition at line 2078 of file aircraft_cmd.cpp.

◆ AircraftEventHandler_AtTerminal()

◆ AircraftEventHandler_EndLanding()

static void AircraftEventHandler_EndLanding ( Aircraft v,
const AirportFTAClass apc 
)
static

Definition at line 1716 of file aircraft_cmd.cpp.

◆ AircraftEventHandler_EndTakeOff()

static void AircraftEventHandler_EndTakeOff ( Aircraft v,
const AirportFTAClass  
)
static

Definition at line 1636 of file aircraft_cmd.cpp.

◆ AircraftEventHandler_EnterHangar()

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

Aircraft arrived in an airport hangar.

Parameters
vAircraft in the hangar.
apcAirport description containing the hangar.

Definition at line 1505 of file aircraft_cmd.cpp.

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

Referenced by AircraftEventHandler_InHangar().

◆ AircraftEventHandler_EnterTerminal()

static void AircraftEventHandler_EnterTerminal ( Aircraft v,
const AirportFTAClass apc 
)
static

Definition at line 1494 of file aircraft_cmd.cpp.

◆ AircraftEventHandler_Flying()

static void AircraftEventHandler_Flying ( Aircraft v,
const AirportFTAClass apc 
)
static

Definition at line 1659 of file aircraft_cmd.cpp.

◆ AircraftEventHandler_General()

static void AircraftEventHandler_General ( Aircraft ,
const AirportFTAClass  
)
static

Definition at line 1619 of file aircraft_cmd.cpp.

◆ AircraftEventHandler_HeliEndLanding()

static void AircraftEventHandler_HeliEndLanding ( Aircraft v,
const AirportFTAClass apc 
)
static

Definition at line 1732 of file aircraft_cmd.cpp.

◆ AircraftEventHandler_HeliLanding()

static void AircraftEventHandler_HeliLanding ( Aircraft v,
const AirportFTAClass  
)
static

Definition at line 1710 of file aircraft_cmd.cpp.

◆ AircraftEventHandler_HeliTakeOff()

static void AircraftEventHandler_HeliTakeOff ( Aircraft v,
const AirportFTAClass  
)
static

Definition at line 1643 of file aircraft_cmd.cpp.

◆ AircraftEventHandler_InHangar()

◆ AircraftEventHandler_Landing()

static void AircraftEventHandler_Landing ( Aircraft v,
const AirportFTAClass  
)
static

Definition at line 1697 of file aircraft_cmd.cpp.

◆ AircraftEventHandler_StartTakeOff()

static void AircraftEventHandler_StartTakeOff ( Aircraft v,
const AirportFTAClass  
)
static

Definition at line 1630 of file aircraft_cmd.cpp.

◆ AircraftEventHandler_TakeOff()

static void AircraftEventHandler_TakeOff ( Aircraft v,
const AirportFTAClass  
)
static

Definition at line 1624 of file aircraft_cmd.cpp.

◆ AircraftGetEntryPoint()

static uint8_t 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
vThe vehicle that is approaching the airport
apcThe Airport Class being approached.
rotationThe rotation of the airport.
Returns
The index of the entry point

Definition at line 826 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(), AircraftNextAirportPos_and_Order(), and UpdateAirplanesOnNewStation().

◆ AircraftHandleDestTooFar()

static void AircraftHandleDestTooFar ( Aircraft v,
bool  too_far 
)
static

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

Parameters
vThe aircraft.
too_farTrue if the current destination is too far away.

Definition at line 2055 of file aircraft_cmd.cpp.

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

◆ AircraftLandAirplane()

static void AircraftLandAirplane ( Aircraft v)
static

◆ AircraftLeaveHangar()

void AircraftLeaveHangar ( Aircraft v,
Direction  exit_dir 
)

Aircraft is about to leave the hangar.

Parameters
vAircraft leaving.
exit_dirThe 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 1465 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()

◆ AirportClearBlock()

static void AirportClearBlock ( const Aircraft v,
const AirportFTAClass apc 
)
static

Definition at line 1782 of file aircraft_cmd.cpp.

◆ AirportFindFreeHelipad()

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

Find a free helipad, and assign it if available.

Parameters
vAircraft to handle.
apcAirport state machine.
Returns
Found a free helipad and assigned it.

Definition at line 2040 of file aircraft_cmd.cpp.

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

Referenced by AircraftEventHandler_InHangar().

◆ AirportFindFreeTerminal()

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

◆ AirportGoToNextPosition()

static void AirportGoToNextPosition ( Aircraft v)
static

Definition at line 1792 of file aircraft_cmd.cpp.

◆ AirportHasBlock()

◆ AirportMove()

static bool AirportMove ( Aircraft v,
const AirportFTAClass apc 
)
static

Definition at line 1804 of file aircraft_cmd.cpp.

◆ AirportSetBlocks()

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

"reserve" a block for the plane

Parameters
vairplane that requires the operation
current_posof the vehicle in the list of blocks
apcairport 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 1883 of file aircraft_cmd.cpp.

References Station::airport, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), AirportFTA::blocks, Airport::blocks, Vehicle::cur_speed, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Flip(), SpecializedStation< Station, false >::Get(), AirportFTA::heading, AirportFTAClass::layout, AirportFTA::next, AirportFTA::next_position, Aircraft::pos, AirportFTA::position, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), Vehicle::subspeed, and Aircraft::targetairport.

◆ CheckIfAircraftNeedsService()

static void CheckIfAircraftNeedsService ( Aircraft v)
static

Definition at line 415 of file aircraft_cmd.cpp.

◆ CmdBuildAircraft()

CommandCost CmdBuildAircraft ( DoCommandFlags  flags,
TileIndex  tile,
const Engine e,
Vehicle **  ret 
)

Build an aircraft.

Parameters
flagstype of operation.
tiletile of the depot where aircraft is built.
ethe engine to build.
[out]retthe vehicle that has been built.
Returns
the cost of this operation or an error.

Definition at line 271 of file aircraft_cmd.cpp.

References _current_company, Vehicle::acceleration, AIR_AIRCRAFT, AIR_CTOL, AIR_HELICOPTER, AIR_ROTOR, AIR_SHADOW, Station::airport, Vehicle::build_year, CanVehicleUseStation(), Vehicle::cargo_cap, Vehicle::cargo_type, CMD_ERROR, TimerGameCalendar::date, TimerGameEconomy::date, Vehicle::date_of_last_service, Vehicle::date_of_last_service_newgrf, DefaultPalette, Engine::DetermineCapacity(), DIR_N, DIR_SE, Vehicle::direction, Vehicle::engine_type, ExclusivePreview, Execute, Engine::flags, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), BaseStation::GetByTile(), Engine::GetDefaultCargoType(), Airport::GetHangarNum(), Airport::GetHangarTile(), Engine::GetLifeLengthInDays(), GetSlopePixelZ(), GetStationIndex(), GetVehiclePosOnBuild(), HANGAR, Hidden, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Vehicle::InvalidateNewGRFCacheOfChain(), IsValidCargoType(), Vehicle::last_loading_station, Vehicle::last_station_visited, AircraftVehicleInfo::mail_capacity, Vehicle::max_age, BaseConsist::name, Vehicle::owner, AircraftVehicleInfo::passenger_capacity, Aircraft::pos, Aircraft::previous_pos, Random, Vehicle::random_bits, Vehicle::refit_cap, Engine::reliability, Vehicle::reliability, Engine::reliability_spd_dec, Vehicle::reliability_spd_dec, ROTOR_Z_OFFSET, VehicleSpriteSeq::Set(), SetBit(), Vehicle::SetNext(), settings, Shadow, Vehicle::sprite_cache, MutableSpriteCache::sprite_seq, Vehicle::spritenum, Aircraft::state, Stopped, AircraftVehicleInfo::subtype, Vehicle::subtype, Aircraft::targetairport, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Vehicle::tile, TILE_SIZE, TileX(), TileY(), Unclickable, UpdateAircraftCache(), Aircraft::UpdateDeltaXY(), Vehicle::UpdatePosition(), BaseConsist::vehicle_flags, Vehicle::vehstatus, VF_BUILT_AS_PROTOTYPE, Vehicle::x_pos, Vehicle::y_pos, TimerGameCalendar::year, and Vehicle::z_pos.

Referenced by CmdBuildVehicle().

◆ CrashAirplane()

◆ DrawAircraftEngine()

void DrawAircraftEngine ( int  left,
int  right,
int  preferred_x,
int  y,
EngineID  engine,
PaletteID  pal,
EngineImageType  image_type 
)

Definition at line 219 of file aircraft_cmd.cpp.

◆ FindNearestHangar()

◆ FreeTerminal()

static bool FreeTerminal ( Aircraft v,
uint8_t  i,
uint8_t  last_terminal 
)
static

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

Parameters
vAircraft looking for a free terminal or helipad.
iFirst terminal to examine.
last_terminalTerminal number to stop examining.
Returns
A terminal or helipad has been found, and has been assigned to the aircraft.

Definition at line 1952 of file aircraft_cmd.cpp.

References _airport_terminal_mapping, Station::airport, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), MovementTerminalMapping::blocks, Airport::blocks, SpecializedStation< Station, false >::Get(), lengthof, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), Aircraft::state, MovementTerminalMapping::state, and Aircraft::targetairport.

Referenced by AirportFindFreeHelipad(), and AirportFindFreeTerminal().

◆ GetAircraftFlightLevel()

template<class T >
int GetAircraftFlightLevel ( T *  v,
bool  takeoff 
)

Definition at line 771 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
vThe vehicle to get the flight levels for.
[out]min_levelThe minimum bounds for flight level.
[out]max_levelThe maximum bounds for flight level.

Definition at line 728 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().

◆ 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
vThe 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 763 of file aircraft_cmd.cpp.

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

Referenced by AircraftController().

◆ GetAircraftIcon()

static void GetAircraftIcon ( EngineID  engine,
EngineImageType  image_type,
VehicleSpriteSeq result 
)
static

Definition at line 203 of file aircraft_cmd.cpp.

◆ 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
engineThe engine to get the sprite from.
[out]widthThe width of the sprite.
[out]heightThe height of the sprite.
[out]xoffsNumber of pixels to shift the sprite to the right.
[out]yoffsNumber of pixels to shift the sprite downwards.
image_typeContext the sprite is used in.

Definition at line 249 of file aircraft_cmd.cpp.

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

Referenced by EnginePreviewWindow::UpdateWidgetSize().

◆ GetNumTerminals()

static uint GetNumTerminals ( const AirportFTAClass apc)
static

Get the number of terminals at the airport.

Parameters
apcAirport description.
Returns
Number of terminals.

Definition at line 1972 of file aircraft_cmd.cpp.

References AirportFTAClass::terminals.

Referenced by AirportFindFreeTerminal().

◆ GetRotorImage()

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

Definition at line 189 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
vvehicle to get target airport for
Returns
pointer to target station, nullptr if invalid

Definition at line 2143 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().

◆ GetTileHeightBelowAircraft()

int GetTileHeightBelowAircraft ( const Vehicle v)

Get the tile height below the aircraft.

This function is needed because aircraft can leave the mapborders.

Parameters
vThe vehicle to get the height for.
Returns
The height in pixels from 'z_pos' 0.

Definition at line 711 of file aircraft_cmd.cpp.

References Clamp(), Map::MaxX(), Map::MaxY(), TILE_HEIGHT, TILE_SIZE, TileHeight(), TileVirtXY(), Vehicle::x_pos, and Vehicle::y_pos.

Referenced by GetAircraftFlightLevelBounds(), and GetAircraftHoldMaxAltitude().

◆ HandleAircraftEnterHangar()

void HandleAircraftEnterHangar ( Aircraft v)

◆ HandleAircraftSmoke()

static void HandleAircraftSmoke ( Aircraft v,
bool  mode 
)
static

◆ HandleCrashedAircraft()

◆ HandleMissingAircraftOrders()

void HandleMissingAircraftOrders ( Aircraft v)

Definition at line 1270 of file aircraft_cmd.cpp.

◆ HelicopterTickHandler()

static void HelicopterTickHandler ( Aircraft v)
static

Definition at line 481 of file aircraft_cmd.cpp.

◆ IsValidImageIndex< VEH_AIRCRAFT >()

template<>
bool IsValidImageIndex< VEH_AIRCRAFT > ( uint8_t  image_index)

Definition at line 104 of file aircraft_cmd.cpp.

◆ MaybeCrashAirplane()

◆ PlayAircraftSound()

static void PlayAircraftSound ( const Vehicle v)
static

Definition at line 589 of file aircraft_cmd.cpp.

◆ SetAircraftPosition()

◆ UpdateAircraftCache()

◆ 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
vThe vehicle for which the speed should be obtained
speed_limitThe maximum speed the vehicle may have.
hard_limitIf 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 646 of file aircraft_cmd.cpp.

References _settings_game, Vehicle::acceleration, AircraftBroken, VehicleCache::cached_max_speed, Vehicle::cur_speed, Vehicle::GetOldAdvanceSpeed(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, VehicleSettings::plane_speed, Vehicle::progress, SetWindowWidgetDirty(), SPEED_LIMIT_BROKEN, Vehicle::subspeed, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Vehicle::vcache, GameSettings::vehicle, Vehicle::vehstatus, WC_VEHICLE_VIEW, and WID_VV_START_STOP.

Referenced by AircraftController().

◆ UpdateAirplanesOnNewStation()

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 93 of file aircraft_cmd.cpp.

◆ _aircraft_state_handlers

AircraftStateHandler* const _aircraft_state_handlers[]
static
Initial value:
= {
AircraftEventHandler_General,
AircraftEventHandler_TakeOff,
AircraftEventHandler_StartTakeOff,
AircraftEventHandler_EndTakeOff,
AircraftEventHandler_HeliTakeOff,
AircraftEventHandler_Flying,
AircraftEventHandler_Landing,
AircraftEventHandler_EndLanding,
AircraftEventHandler_HeliLanding,
AircraftEventHandler_HeliEndLanding,
}
static void AircraftEventHandler_InHangar(Aircraft *v, const AirportFTAClass *apc)
Handle aircraft movement/decision making in an airport hangar.
static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *apc)
At one of the Airport's Terminals.

Array of handler functions for each target of the aircraft.

Definition at line 1757 of file aircraft_cmd.cpp.

◆ _airport_terminal_mapping

const MovementTerminalMapping _airport_terminal_mapping[]
static
Initial value:
= {
}
@ Term2
Block belonging to terminal 2.
@ Term5
Block belonging to terminal 5.
@ Term6
Block belonging to terminal 6.
@ Term4
Block belonging to terminal 4.
@ Helipad3
Block belonging to helipad 3.
@ Term7
Block belonging to terminal 7.
@ Helipad1
Block belonging to helipad 1.
@ Term3
Block belonging to terminal 3.
@ Term1
Block belonging to terminal 1.
@ Helipad2
Block belonging to helipad 2.
@ Term8
Block belonging to terminal 8.
@ TERM4
Heading for terminal 4.
Definition airport.h:68
@ HELIPAD2
Heading for helipad 2.
Definition airport.h:72
@ TERM5
Heading for terminal 5.
Definition airport.h:69
@ TERM6
Heading for terminal 6.
Definition airport.h:70
@ TERM3
Heading for terminal 3.
Definition airport.h:67
@ TERM8
Heading for terminal 8.
Definition airport.h:83
@ HELIPAD3
Heading for helipad 3.
Definition airport.h:84
@ HELIPAD1
Heading for helipad 1.
Definition airport.h:71
@ TERM2
Heading for terminal 2.
Definition airport.h:66
@ TERM1
Heading for terminal 1.
Definition airport.h:65
@ TERM7
Heading for terminal 7.
Definition airport.h:82

A list of all valid terminals and their associated blocks.

Definition at line 1931 of file aircraft_cmd.cpp.

Referenced by FreeTerminal().

◆ SPEED_LIMIT_APPROACH

constexpr uint16_t SPEED_LIMIT_APPROACH = 230
staticconstexpr

Maximum speed of an aircraft on finals.

Definition at line 634 of file aircraft_cmd.cpp.

Referenced by AircraftController().

◆ SPEED_LIMIT_BROKEN

constexpr uint16_t SPEED_LIMIT_BROKEN = 320
staticconstexpr

Maximum speed of an aircraft that is broken.

Definition at line 635 of file aircraft_cmd.cpp.

Referenced by UpdateAircraftSpeed().

◆ SPEED_LIMIT_HOLD

constexpr uint16_t SPEED_LIMIT_HOLD = 425
staticconstexpr

Maximum speed of an aircraft that flies the holding pattern.

Definition at line 636 of file aircraft_cmd.cpp.

Referenced by AircraftController().

◆ SPEED_LIMIT_NONE

constexpr uint16_t SPEED_LIMIT_NONE = UINT16_MAX
staticconstexpr

No environmental speed limit. Speed limit is type dependent.

Definition at line 637 of file aircraft_cmd.cpp.

Referenced by AircraftController().

◆ SPEED_LIMIT_TAXI

constexpr uint16_t SPEED_LIMIT_TAXI = 50
staticconstexpr

Special velocities for aircraft.

Maximum speed of an aircraft while taxiing

Definition at line 633 of file aircraft_cmd.cpp.

Referenced by AircraftController().