#include "stdafx.h"
#include "aircraft.h"
#include "debug.h"
#include "landscape.h"
#include "news_func.h"
#include "vehicle_gui.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 "functions.h"
#include "cheat_type.h"
#include "autoreplace_func.h"
#include "autoreplace_gui.h"
#include "gfx_func.h"
#include "ai/ai.hpp"
#include "company_func.h"
#include "effectvehicle_func.h"
#include "station_base.h"
#include "cargotype.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 (Aircraft *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 (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) |
static bool | AirportFindFreeTerminal (Aircraft *v, const AirportFTAClass *apc) |
static bool | AirportFindFreeHelipad (Aircraft *v, const AirportFTAClass *apc) |
static void | CrashAirplane (Aircraft *v) |
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). | |
SpriteID | GetRotorImage (const Aircraft *v) |
static SpriteID | GetAircraftIcon (EngineID engine) |
void | DrawAircraftEngine (int left, int right, int preferred_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). | |
CommandCost | CmdBuildAircraft (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Build an aircraft. | |
CommandCost | CmdSellAircraft (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Sell an aircraft. | |
CommandCost | CmdSendAircraftToHangar (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Send an aircraft to the hangar. | |
CommandCost | CmdRefitAircraft (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Refits an aircraft to the specified cargo type. | |
static void | CheckIfAircraftNeedsService (Aircraft *v) |
static void | HelicopterTickHandler (Aircraft *v) |
void | SetAircraftPosition (Aircraft *v, int x, int y, int z) |
void | HandleAircraftEnterHangar (Aircraft *v) |
Handle Aircraft specific tasks when a an Aircraft enters a hangar. | |
static void | PlayAircraftSound (const Vehicle *v) |
void | UpdateAircraftCache (Aircraft *v) |
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. | |
byte | GetAircraftFlyingAltitude (const Aircraft *v) |
Gets the cruise altitude of an aircraft. | |
static byte | AircraftGetEntryPoint (const Aircraft *v, const AirportFTAClass *apc) |
Find the entry point to an airport depending on direction which the airport is being approached from. | |
static bool | AircraftController (Aircraft *v) |
Controls the movement of an aircraft. | |
static bool | HandleCrashedAircraft (Aircraft *v) |
static void | HandleBrokenAircraft (Aircraft *v) |
static void | HandleAircraftSmoke (Aircraft *v) |
void | HandleMissingAircraftOrders (Aircraft *v) |
static void | MaybeCrashAirplane (Aircraft *v) |
static void | AircraftEntersTerminal (Aircraft *v) |
we've landed and just arrived at a terminal | |
static void | AircraftLandAirplane (Aircraft *v) |
void | AircraftNextAirportPos_and_Order (Aircraft *v) |
set the right pos when heading to other airports after takeoff | |
void | AircraftLeaveHangar (Aircraft *v) |
static void | AircraftEventHandler_EnterTerminal (Aircraft *v, const AirportFTAClass *apc) |
static void | AircraftEventHandler_EnterHangar (Aircraft *v, const AirportFTAClass *apc) |
static void | AircraftEventHandler_InHangar (Aircraft *v, const AirportFTAClass *apc) |
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 *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) |
static uint | GetNumTerminals (const AirportFTAClass *apc) |
static uint | GetNumHelipads (const AirportFTAClass *apc) |
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. | |
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 698 of file aircraft_cmd.cpp.
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.
v | The vehicle that is moved. Must be the first vehicle of the chain |
Definition at line 847 of file aircraft_cmd.cpp.
References _settings_game, abs(), AIR_AIRCRAFT, AircraftGetEntryPoint(), AircraftNextAirportPos_and_Order(), Station::Airport(), Station::airport_tile, Station::airport_type, ChangeDir(), AirportFTAClass::delta_z, DIRDIFF_45LEFT, DIRDIFF_45RIGHT, DIRDIFF_REVERSE, DIRDIFF_SAME, DirDifference(), GetAircraftFlyingAltitude(), SpecializedStation< Station, false >::GetIfValid(), GetNewVehiclePos(), INVALID_TILE, Aircraft::last_direction, max(), min(), AirportFTAClass::MovingData(), GetNewVehiclePosResult::new_tile, SpecializedVehicle< T, Type >::Next(), AirportFTAClass::nofelements, Aircraft::number_consecutive_turns, GetNewVehiclePosResult::old_tile, VehicleSettings::plane_speed, Aircraft::pos, Aircraft::previous_pos, SPEED_LIMIT_APPROACH, SPEED_LIMIT_HOLD, SPEED_LIMIT_NONE, SPEED_LIMIT_TAXI, Aircraft::state, Aircraft::targetairport, TILE_SIZE, TileX(), TileY(), UpdateAircraftCache(), UpdateAircraftSpeed(), GameSettings::vehicle, GetNewVehiclePosResult::x, BaseStation::xy, and GetNewVehiclePosResult::y.
static byte AircraftGetEntryPoint | ( | const Aircraft * | 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 810 of file aircraft_cmd.cpp.
References abs(), Station::airport_tile, DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, AirportFTAClass::entry_points, SpecializedStation< Station, false >::GetIfValid(), INVALID_TILE, Aircraft::targetairport, TILE_SIZE, TileX(), TileY(), and BaseStation::xy.
Referenced by AircraftController(), AircraftNextAirportPos_and_Order(), and UpdateAirplanesOnNewStation().
static bool AirportSetBlocks | ( | Aircraft * | 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 1749 of file aircraft_cmd.cpp.
References Station::airport_flags, AirportFTA::block, SpecializedStation< Station, false >::Get(), AirportFTA::heading, AirportFTAClass::layout, AirportFTA::next, AirportFTA::next_position, Aircraft::pos, AirportFTA::position, SETBITS, and Aircraft::targetairport.
CommandCost CmdBuildAircraft | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Build an aircraft.
tile | tile of depot where aircraft is built | |
flags | for command | |
p1 | aircraft type being built (engine) | |
p2 | unused | |
text | unused |
Definition at line 236 of file aircraft_cmd.cpp.
References _cur_year, _date, _settings_game, AIR_AIRCRAFT, AIR_HELICOPTER, AIR_ROTOR, AIR_SHADOW, Aircraft::Aircraft(), Station::Airport(), AirportFTAClass::airport_depots, Station::airport_tile, CanVehicleUseStation(), CMD_ERROR, CT_INVALID, DC_AUTOREPLACE, DC_EXEC, DC_QUERY_COST, DIR_N, DIR_SE, ENGINE_EXCLUSIVE_PREVIEW, SpecializedStation< Station, false >::GetByTile(), GetStationIndex(), GetVehicleCapacity(), AirportFTA::heading, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_DIR, InvalidateAutoreplaceWindow(), InvalidateWindowClassesData(), InvalidateWindowData(), IsEngineBuildable(), IsTileOwner(), AirportFTAClass::layout, VehicleSettings::max_aircraft, AirportFTAClass::nof_depots, Aircraft::pos, AirportFTA::position, Aircraft::previous_pos, return_cmd_error, SetBit(), SetWindowDirty(), Aircraft::state, Aircraft::targetairport, TILE_SIZE, TileX(), TileY(), ToTileIndexDiff(), UpdateAircraftCache(), Aircraft::UpdateDeltaXY(), VEH_AIRCRAFT, GameSettings::vehicle, VehicleMove(), and VehicleRandomBits().
CommandCost CmdRefitAircraft | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
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
| |
text | unused |
Definition at line 490 of file aircraft_cmd.cpp.
References CMD_ERROR, DC_EXEC, GB(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateWindowClassesData(), NUM_CARGO, RefitVehicle(), return_cmd_error, and SetWindowDirty().
CommandCost CmdSellAircraft | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Sell an aircraft.
tile | unused | |
flags | for command type | |
p1 | vehicle ID to be sold | |
p2 | unused | |
text | unused |
Definition at line 417 of file aircraft_cmd.cpp.
References CMD_ERROR, DC_EXEC, SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::GetIfValid(), and return_cmd_error.
CommandCost CmdSendAircraftToHangar | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Send an aircraft to the hangar.
tile | unused | |
flags | for command type | |
p1 | vehicle ID to send to the hangar | |
p2 | various bitmasked elements
| |
text | unused |
Definition at line 464 of file aircraft_cmd.cpp.
References CMD_ERROR, DEPOT_MASS_SEND, DEPOT_SERVICE, SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::GetIfValid(), SendAllVehiclesToDepot(), and VEH_AIRCRAFT.
Find the nearest hangar to v INVALID_STATION is returned, if the company does not have any suitable airports (like helipads only).
v | vehicle looking for a hangar |
Definition at line 107 of file aircraft_cmd.cpp.
References Station::Airport(), Station::airport_tile, DistanceSquare(), FACIL_AIRPORT, BaseStation::facilities, AirportFTAClass::flags, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Cheats::no_jetcrash, AirportFTAClass::nof_depots, BaseStation::owner, and Cheat::value.
byte GetAircraftFlyingAltitude | ( | const Aircraft * | v | ) |
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 770 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 220 of file aircraft_cmd.cpp.
References Sprite::height, ST_NORMAL, and Sprite::width.
Returns aircraft's target station if v->target_airport is a valid station with airport.
v | vehicle to get target airport for |
Definition at line 1965 of file aircraft_cmd.cpp.
References Station::airport_tile, SpecializedStation< Station, false >::GetIfValid(), INVALID_TILE, Aircraft::targetairport, and VEH_AIRCRAFT.
Referenced by AircraftNextAirportPos_and_Order(), and MapAircraftMovementState().
void HandleAircraftEnterHangar | ( | Aircraft * | v | ) |
Handle Aircraft specific tasks when a an Aircraft enters a hangar.
*v | Vehicle that enters the hangar |
Definition at line 657 of file aircraft_cmd.cpp.
References SpecializedVehicle< T, Type >::Next().
void UpdateAircraftCache | ( | Aircraft * | v | ) |
Update cached values of an aircraft.
Currently caches callback 36 max speed.
v | Vehicle |
Definition at line 681 of file aircraft_cmd.cpp.
References Aircraft::acache, AircraftCache::cached_max_speed, and PROP_AIRCRAFT_SPEED.
Referenced by AfterLoadVehicles(), AircraftController(), CmdBuildAircraft(), StateGameLoop(), and UpdateAirplanesOnNewStation().
static int UpdateAircraftSpeed | ( | Aircraft * | 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 713 of file aircraft_cmd.cpp.
References _settings_client, _settings_game, Aircraft::acache, AircraftCache::cached_max_speed, ClientSettings::gui, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, max(), min(), VehicleSettings::plane_speed, SetWindowWidgetDirty(), SPEED_LIMIT_BROKEN, GameSettings::vehicle, and GUISettings::vehicle_speed.
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 1979 of file aircraft_cmd.cpp.
References AIR_HELICOPTER, AircraftGetEntryPoint(), Station::Airport(), GetAircraftFlyingAltitude(), GetNewVehiclePos(), AirportFTA::heading, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Aircraft::IsNormalAircraft(), AirportFTAClass::layout, AirportFTAClass::nofelements, Aircraft::pos, AirportFTA::position, Aircraft::previous_pos, Aircraft::state, Aircraft::targetairport, UpdateAircraftCache(), GetNewVehiclePosResult::x, and GetNewVehiclePosResult::y.
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 83 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 1622 of file aircraft_cmd.cpp.