#include "stdafx.h"
#include "openttd.h"
#include "aircraft.h"
#include "debug.h"
#include "landscape.h"
#include "station_map.h"
#include "timetable.h"
#include "depot.h"
#include "engine.h"
#include "station.h"
#include "news.h"
#include "airport.h"
#include "vehicle_gui.h"
#include "newgrf_engine.h"
#include "newgrf_callbacks.h"
#include "newgrf_text.h"
#include "newgrf_sound.h"
#include "spritecache.h"
#include "cargotype.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 "functions.h"
#include "variables.h"
#include "autoreplace_func.h"
#include "autoreplace_gui.h"
#include "gfx_func.h"
#include "player_func.h"
#include "settings_type.h"
#include "table/strings.h"
#include "table/sprites.h"
Go to the source code of this file.
Defines | |
#define | MKIT(a, b, c, d) ((a & 0xFF) << 24) | ((b & 0xFF) << 16) | ((c & 0xFF) << 8) | ((d & 0xFF) << 0) |
Typedefs | |
typedef void | AircraftStateHandler (Vehicle *v, const AirportFTAClass *apc) |
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 (Vehicle *v, const AirportFTAClass *apc) |
static bool | AirportSetBlocks (Vehicle *v, const AirportFTA *current_pos, const AirportFTAClass *apc) |
"reserve" a block for the plane | |
static bool | AirportHasBlock (Vehicle *v, const AirportFTA *current_pos, const AirportFTAClass *apc) |
static bool | AirportFindFreeTerminal (Vehicle *v, const AirportFTAClass *apc) |
static bool | AirportFindFreeHelipad (Vehicle *v, const AirportFTAClass *apc) |
static void | CrashAirplane (Vehicle *v) |
static void | AircraftNextAirportPos_and_Order (Vehicle *v) |
set the right pos when heading to other airports after takeoff | |
static byte | GetAircraftFlyingAltitude (const Vehicle *v) |
Gets the cruise altitude of an aircraft. | |
static StationID | FindNearestHangar (const Vehicle *v) |
Find the nearest hangar to v INVALID_STATION is returned, if the player does not have any suitable airports (like helipads only). | |
SpriteID | GetRotorImage (const Vehicle *v) |
void | DrawAircraftEngine (int x, int y, EngineID engine, SpriteID pal) |
void | GetAircraftSpriteSize (EngineID engine, uint &width, uint &height) |
Get the size of the sprite of an aircraft sprite heading west (used for lists). | |
static CommandCost | EstimateAircraftCost (EngineID engine, const AircraftVehicleInfo *avi) |
uint16 | AircraftDefaultCargoCapacity (CargoID cid, const AircraftVehicleInfo *avi) |
Calculates cargo capacity based on an aircraft's passenger and mail capacities. | |
CommandCost | CmdBuildAircraft (TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
Build an aircraft. | |
static void | DoDeleteAircraft (Vehicle *v) |
CommandCost | CmdSellAircraft (TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
Sell an aircraft. | |
CommandCost | CmdStartStopAircraft (TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
Start/Stop an aircraft. | |
CommandCost | CmdSendAircraftToHangar (TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
Send an aircraft to the hangar. | |
CommandCost | CmdRefitAircraft (TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
Refits an aircraft to the specified cargo type. | |
static void | CheckIfAircraftNeedsService (Vehicle *v) |
void | AircraftYearlyLoop () |
static void | AgeAircraftCargo (Vehicle *v) |
static void | HelicopterTickHandler (Vehicle *v) |
static void | SetAircraftPosition (Vehicle *v, int x, int y, int z) |
void | HandleAircraftEnterHangar (Vehicle *v) |
Handle Aircraft specific tasks when a an Aircraft enters a hangar. | |
static void | PlayAircraftSound (const Vehicle *v) |
void | UpdateAircraftCache (Vehicle *v) |
Update cached values of an aircraft. | |
static int | UpdateAircraftSpeed (Vehicle *v, uint speed_limit=SPEED_LIMIT_NONE, bool hard_limit=true) |
Sets the new speed for an aircraft. | |
static byte | AircraftGetEntryPoint (const Vehicle *v, const AirportFTAClass *apc) |
Find the entry point to an airport depending on direction which the airport is being approached from. | |
static bool | AircraftController (Vehicle *v) |
Controls the movement of an aircraft. | |
static void | HandleCrashedAircraft (Vehicle *v) |
static void | HandleBrokenAircraft (Vehicle *v) |
static void | HandleAircraftSmoke (Vehicle *v) |
static void | ProcessAircraftOrder (Vehicle *v) |
static void | MaybeCrashAirplane (Vehicle *v) |
static void | AircraftEntersTerminal (Vehicle *v) |
we've landed and just arrived at a terminal | |
static void | AircraftLandAirplane (Vehicle *v) |
static void | AircraftLeaveHangar (Vehicle *v) |
static bool | CheckSendAircraftToHangarForReplacement (const Vehicle *v) |
Checks if an aircraft should head towards a hangar because it needs replacement. | |
static void | AircraftEventHandler_EnterTerminal (Vehicle *v, const AirportFTAClass *apc) |
static void | AircraftEventHandler_EnterHangar (Vehicle *v, const AirportFTAClass *apc) |
static void | AircraftEventHandler_InHangar (Vehicle *v, const AirportFTAClass *apc) |
In an Airport Hangar. | |
static void | AircraftEventHandler_AtTerminal (Vehicle *v, const AirportFTAClass *apc) |
At one of the Airport's Terminals. | |
static void | AircraftEventHandler_General (Vehicle *v, const AirportFTAClass *apc) |
static void | AircraftEventHandler_TakeOff (Vehicle *v, const AirportFTAClass *apc) |
static void | AircraftEventHandler_StartTakeOff (Vehicle *v, const AirportFTAClass *apc) |
static void | AircraftEventHandler_EndTakeOff (Vehicle *v, const AirportFTAClass *apc) |
static void | AircraftEventHandler_HeliTakeOff (Vehicle *v, const AirportFTAClass *apc) |
static void | AircraftEventHandler_Flying (Vehicle *v, const AirportFTAClass *apc) |
static void | AircraftEventHandler_Landing (Vehicle *v, const AirportFTAClass *apc) |
static void | AircraftEventHandler_HeliLanding (Vehicle *v, const AirportFTAClass *apc) |
static void | AircraftEventHandler_EndLanding (Vehicle *v, const AirportFTAClass *apc) |
static void | AircraftEventHandler_HeliEndLanding (Vehicle *v, const AirportFTAClass *apc) |
static void | AirportClearBlock (const Vehicle *v, const AirportFTAClass *apc) |
static void | AirportGoToNextPosition (Vehicle *v) |
static bool | FreeTerminal (Vehicle *v, byte i, byte last_terminal) |
static uint | GetNumTerminals (const AirportFTAClass *apc) |
static uint | GetNumHelipads (const AirportFTAClass *apc) |
static void | AircraftEventHandler (Vehicle *v, int loop) |
Station * | GetTargetAirportIfValid (const Vehicle *v) |
Returns aircraft's target station if v->u.air.target_airport is a valid station with airport. | |
void | UpdateOldAircraft () |
need to be called to load aircraft from old version | |
void | UpdateAirplanesOnNewStation (const Station *st) |
Updates the status of the Aircraft heading or in the station. | |
Variables | |
static const byte | _airport_terminal_state [] = {2, 3, 4, 5, 6, 7, 19, 20, 0, 0, 8, 9, 21, 22} |
this maps the terminal to its corresponding state and block flag currently set for 10 terms, 4 helipads | |
static const byte | _airport_terminal_flag [] = {0, 1, 2, 3, 4, 5, 22, 23, 0, 0, 6, 7, 24, 25} |
static const SpriteID | _aircraft_sprite [] |
static AircraftStateHandler *const | _aircraft_state_handlers [] |
Definition in file aircraft_cmd.cpp.
enum AircraftSpeedLimits |
Special velocities for aircraft.
Definition at line 909 of file aircraft_cmd.cpp.
static bool AircraftController | ( | Vehicle * | 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.
v | The vehicle that is moved. Must be the first vehicle of the chain |
Definition at line 1058 of file aircraft_cmd.cpp.
References abs(), AircraftGetEntryPoint(), AircraftNextAirportPos_and_Order(), ChangeDir(), DIRDIFF_45LEFT, DIRDIFF_45RIGHT, DIRDIFF_REVERSE, DIRDIFF_SAME, DirDifference(), GetAircraftFlyingAltitude(), max(), min(), SPEED_LIMIT_APPROACH, SPEED_LIMIT_HOLD, SPEED_LIMIT_NONE, SPEED_LIMIT_TAXI, TILE_SIZE, TileX(), TileY(), UpdateAircraftCache(), and UpdateAircraftSpeed().
uint16 AircraftDefaultCargoCapacity | ( | CargoID | cid, | |
const AircraftVehicleInfo * | avi | |||
) |
Calculates cargo capacity based on an aircraft's passenger and mail capacities.
cid | Which cargo type to calculate a capacity for. | |
avi | Which engine to find a cargo capacity for. |
Definition at line 252 of file aircraft_cmd.cpp.
Referenced by CmdBuildAircraft(), and CmdRefitAircraft().
static byte AircraftGetEntryPoint | ( | const Vehicle * | v, | |
const AirportFTAClass * | apc | |||
) | [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.
v | The vehicle that is approaching the airport | |
apc | The Airport Class being approached. |
Definition at line 1021 of file aircraft_cmd.cpp.
References abs(), DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, TILE_SIZE, TileX(), and TileY().
Referenced by AircraftController(), AircraftNextAirportPos_and_Order(), and UpdateAirplanesOnNewStation().
static bool AirportSetBlocks | ( | Vehicle * | v, | |
const AirportFTA * | current_pos, | |||
const AirportFTAClass * | apc | |||
) | [static] |
"reserve" a block for the plane
v | airplane that requires the operation | |
current_pos | of the vehicle in the list of blocks | |
apc | airport on which block is requsted to be set |
Definition at line 1991 of file aircraft_cmd.cpp.
static bool CheckSendAircraftToHangarForReplacement | ( | const Vehicle * | v | ) | [inline, static] |
Checks if an aircraft should head towards a hangar because it needs replacement.
*v | the vehicle to test |
Definition at line 1591 of file aircraft_cmd.cpp.
References CMD_BUILD_AIRCRAFT, DC_QUERY_COST, DoCommand(), EngineReplacementForPlayer(), HasBit(), and VehicleHasDepotOrders().
CommandCost CmdBuildAircraft | ( | TileIndex | tile, | |
uint32 | flags, | |||
uint32 | p1, | |||
uint32 | p2 | |||
) |
Build an aircraft.
tile | tile of depot where aircraft is built | |
flags | for command | |
p1 | aircraft type being built (engine) | |
p2 | unused return result of operation. Could be cost, error |
Definition at line 277 of file aircraft_cmd.cpp.
References AIR_AIRCRAFT, AIR_CTOL, AIR_HELICOPTER, AIR_ROTOR, AIR_SHADOW, Aircraft::Aircraft(), AircraftDefaultCargoCapacity(), CALLBACK_FAILED, CanAircraftUseStation(), CBID_VEHICLE_REFIT_CAPACITY, CBM_VEHICLE_REFIT_CAPACITY, CMD_ERROR, DC_AUTOREPLACE, DC_EXEC, DC_QUERY_COST, DIR_N, DIR_SE, ENGINE_EXCLUSIVE_PREVIEW, FindFirstRefittableCargo(), CommandCost::GetCost(), GetVehicleCallback(), HasBit(), INVALID_DIR, InvalidateAutoreplaceWindow(), IsEngineBuildable(), IsTileOwner(), return_cmd_error, SetBit(), TILE_SIZE, TileX(), TileY(), ToTileIndexDiff(), UpdateAircraftCache(), and VehicleRandomBits().
CommandCost CmdRefitAircraft | ( | TileIndex | tile, | |
uint32 | flags, | |||
uint32 | p1, | |||
uint32 | p2 | |||
) |
Refits an aircraft to the specified cargo type.
tile | unused | |
flags | for command type | |
p1 | vehicle ID of the aircraft to refit | |
p2 | various bitstuffed elements
|
Definition at line 639 of file aircraft_cmd.cpp.
References AircraftDefaultCargoCapacity(), CALLBACK_FAILED, CanRefitTo(), CBID_VEHICLE_REFIT_CAPACITY, CBM_VEHICLE_REFIT_CAPACITY, CC_PASSENGERS, CMD_ERROR, DC_EXEC, GB(), GetRefitCost(), GetVehicleCallback(), HasBit(), IsValidVehicleID(), and return_cmd_error.
CommandCost CmdSellAircraft | ( | TileIndex | tile, | |
uint32 | flags, | |||
uint32 | p1, | |||
uint32 | p2 | |||
) |
Sell an aircraft.
tile | unused | |
flags | for command type | |
p1 | vehicle ID to be sold | |
p2 | unused |
Definition at line 488 of file aircraft_cmd.cpp.
References CMD_ERROR, DC_EXEC, HASBITS, IsValidVehicleID(), and return_cmd_error.
CommandCost CmdSendAircraftToHangar | ( | TileIndex | tile, | |
uint32 | flags, | |||
uint32 | p1, | |||
uint32 | p2 | |||
) |
Send an aircraft to the hangar.
tile | unused | |
flags | for command type | |
p1 | vehicle ID to send to the hangar | |
p2 | various bitmasked elements
|
Definition at line 561 of file aircraft_cmd.cpp.
References AircraftNextAirportPos_and_Order(), ClrBit(), CMD_ERROR, DC_EXEC, FindNearestHangar(), GetTargetAirportIfValid(), HasBit(), IsValidVehicleID(), OFB_NON_STOP, OFB_UNLOAD, SendAllVehiclesToDepot(), SetBit(), and ToggleBit().
CommandCost CmdStartStopAircraft | ( | TileIndex | tile, | |
uint32 | flags, | |||
uint32 | p1, | |||
uint32 | p2 | |||
) |
Start/Stop an aircraft.
tile | unused | |
flags | for command type | |
p1 | aircraft ID to start/stop | |
p2 | unused |
Definition at line 517 of file aircraft_cmd.cpp.
References CALLBACK_FAILED, CBID_VEHICLE_START_STOP_CHECK, CMD_ERROR, DC_EXEC, DeleteVehicleNews(), error, GB(), GetEngineGRFID(), GetGRFStringID(), GetVehicleCallback(), IsValidVehicleID(), and return_cmd_error.
static StationID FindNearestHangar | ( | const Vehicle * | v | ) | [static] |
Find the nearest hangar to v INVALID_STATION is returned, if the player does not have any suitable airports (like helipads only).
v | vehicle looking for a hangar |
Definition at line 111 of file aircraft_cmd.cpp.
References DistanceSquare(), and PoolItem< T, Tid, Tpool >::index.
Referenced by CmdSendAircraftToHangar().
static byte GetAircraftFlyingAltitude | ( | const Vehicle * | v | ) | [static] |
Gets the cruise altitude of an aircraft.
The cruise altitude is determined by the velocity of the vehicle and the direction it is moving
v | The vehicle. Should be an aircraft |
Definition at line 981 of file aircraft_cmd.cpp.
References DIR_E, DIR_N, DIR_NE, DIR_SE, and min().
Referenced by AircraftController(), UpdateAirplanesOnNewStation(), and UpdateOldAircraft().
void GetAircraftSpriteSize | ( | EngineID | engine, | |
uint & | width, | |||
uint & | height | |||
) |
Get the size of the sprite of an aircraft sprite heading west (used for lists).
engine | The engine to get the sprite from | |
width | The width of the sprite | |
height | The height of the sprite |
Definition at line 219 of file aircraft_cmd.cpp.
References DIR_W.
Station* GetTargetAirportIfValid | ( | const Vehicle * | v | ) |
Returns aircraft's target station if v->u.air.target_airport is a valid station with airport.
v | vehicle to get target airport for |
Definition at line 2207 of file aircraft_cmd.cpp.
Referenced by AircraftNextAirportPos_and_Order(), CmdSendAircraftToHangar(), and MapAircraftMovementState().
void HandleAircraftEnterHangar | ( | Vehicle * | v | ) |
Handle Aircraft specific tasks when a an Aircraft enters a hangar.
*v | Vehicle that enters the hangar |
Definition at line 868 of file aircraft_cmd.cpp.
void UpdateAircraftCache | ( | Vehicle * | v | ) |
Update cached values of an aircraft.
Currently caches callback 36 max speed.
v | Vehicle |
Definition at line 892 of file aircraft_cmd.cpp.
Referenced by AfterLoadVehicles(), AircraftController(), CmdBuildAircraft(), and UpdateAirplanesOnNewStation().
static int UpdateAircraftSpeed | ( | Vehicle * | v, | |
uint | speed_limit = SPEED_LIMIT_NONE , |
|||
bool | hard_limit = true | |||
) | [static] |
Sets the new speed for an aircraft.
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 |
Definition at line 924 of file aircraft_cmd.cpp.
References max(), min(), and SPEED_LIMIT_BROKEN.
Referenced by AircraftController().
void UpdateAirplanesOnNewStation | ( | const Station * | st | ) |
Updates the status of the Aircraft heading or in the station.
st | Station been updated |
Definition at line 2260 of file aircraft_cmd.cpp.
References AIR_HELICOPTER, AircraftGetEntryPoint(), GetAircraftFlyingAltitude(), IsNormalAircraft(), and UpdateAircraftCache().
Referenced by CmdBuildAirport().
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 87 of file aircraft_cmd.cpp.
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, AircraftEventHandler_AtTerminal, }
Definition at line 1863 of file aircraft_cmd.cpp.