|
OpenTTD Source 20260421-master-gc2fbc6fdeb
|
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 "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 | |
| using | AircraftStateHandler = void(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) |
| Checks whether the next block the aircraft wants to travel on is busy. | |
| 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) |
| Helper to check whether an image index is valid for a particular vehicle. | |
| 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) |
| Aircraft arrives at the terminal. | |
| 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_TakeOff (Aircraft *v, const AirportFTAClass *apc) |
| Aircraft is taking off (rolling). | |
| static void | AircraftEventHandler_StartTakeOff (Aircraft *v, const AirportFTAClass *apc) |
| Aircraft is taking off (rotation). | |
| static void | AircraftEventHandler_EndTakeOff (Aircraft *v, const AirportFTAClass *apc) |
| Aircraft has taken off. | |
| static void | AircraftEventHandler_HeliTakeOff (Aircraft *v, const AirportFTAClass *apc) |
| Helicopter takes off. | |
| static void | AircraftEventHandler_Flying (Aircraft *v, const AirportFTAClass *apc) |
| Aircraft is flying around. | |
| static void | AircraftEventHandler_Landing (Aircraft *v, const AirportFTAClass *apc) |
| Aircraft is landing (touchdown). | |
| static void | AircraftEventHandler_HeliLanding (Aircraft *v, const AirportFTAClass *apc) |
| Helicopter is starting to land. | |
| static void | AircraftEventHandler_EndLanding (Aircraft *v, const AirportFTAClass *apc) |
| Aircraft is has landed. | |
| static void | AircraftEventHandler_HeliEndLanding (Aircraft *v, const AirportFTAClass *apc) |
| Helicopter has landed. | |
| 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) |
| Event handler loop for a single aircraft. | |
| 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 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. | |
This file deals with aircraft and airport movements functionalities.
Definition in file aircraft_cmd.cpp.
| using AircraftStateHandler = void(Aircraft *v, const AirportFTAClass *apc) |
Signature of the aircraft handler function.
Definition at line 1769 of file aircraft_cmd.cpp.
| enum HelicopterRotorStates : uint8_t |
Helicopter rotor animation states.
Definition at line 104 of file aircraft_cmd.cpp.
|
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 863 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, Airport::blocks, Brake, CeilDiv(), ChangeDir(), 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(), HelicopterDirectDescent, 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, PlayVehicleSound(), Aircraft::pos, Aircraft::previous_pos, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), RotateAirportMovingData(), Airport::rotation, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetAircraftPosition(), 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(), Vehicle::vehstatus, VSE_START, OrthogonalTileArea::w, AirportMovingData::x, Vehicle::x_pos, BaseStation::xy, AirportMovingData::y, GetNewVehiclePosResult::y, Vehicle::y_pos, Vehicle::z_pos, and Zeppeliner.
|
static |
Aircraft arrives at a terminal.
If it is the first aircraft, throw a party. Start loading cargo.
| v | Aircraft that arrived. |
Definition at line 1414 of file aircraft_cmd.cpp.
References _local_company, AddVehicleNewsItem(), ArrivalCompany, ArrivalOther, Vehicle::BeginLoading(), Vehicle::current_order, SpecializedStation< Station, false >::Get(), GetEncodedString(), HVOT_AIRCRAFT, Order::IsType(), Vehicle::last_station_visited, AI::NewEvent(), Game::NewEvent(), Vehicle::owner, and Aircraft::targetairport.
Referenced by AircraftEventHandler_EnterTerminal().
|
static |
Event handler loop for a single aircraft.
| v | Aircraft to process events for. |
| loop | How many times has this been called during this tick. |
true iff another loop can take place, i.e. the vehicle still exists. Definition at line 2110 of file aircraft_cmd.cpp.
References AircraftHandleDestTooFar(), Station::airport, AircraftCache::cached_max_range_sqr, Crashed, Vehicle::current_order, DestinationTooFar, DistanceSquare(), ENDTAKEOFF, Aircraft::flags, Order::GetDestination(), SpecializedStation< Station, false >::GetIfValid(), HandleAircraftSmoke(), Vehicle::HandleBreakdown(), HandleCrashedAircraft(), Vehicle::HandleLoading(), HELIENDLANDING, INVALID_TILE, Order::IsType(), ProcessOrders(), Aircraft::state, Stopped, Aircraft::targetairport, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), OrthogonalTileArea::tile, and Vehicle::vehstatus.
Referenced by Aircraft::Tick().
|
static |
At one of the Airport's Terminals.
Signature of the aircraft handler function.
Definition at line 1576 of file aircraft_cmd.cpp.
References _settings_game, AIR_HELICOPTER, AircraftEventHandler_EnterTerminal(), AirportHasBlock(), Vehicle::breakdowns_since_last_service, Vehicle::current_order, TimerGameCalendar::date, TimerGameEconomy::date, Vehicle::date_of_last_service, Vehicle::date_of_last_service_newgrf, Order::Free(), SpecializedStation< Station, false >::Get(), Order::GetDestination(), Vehicle::GetEngine(), Order::GetType(), HANGAR, HELITAKEOFF, Order::IsType(), AirportFTAClass::layout, AirportFTAClass::num_helipads, Aircraft::pos, Aircraft::previous_pos, Engine::reliability, Vehicle::reliability, SetWindowDirty(), Aircraft::state, Vehicle::subtype, TAKEOFF, Aircraft::targetairport, and WC_VEHICLE_DETAILS.
|
static |
Aircraft is has landed.
Signature of the aircraft handler function.
Definition at line 1730 of file aircraft_cmd.cpp.
References AirportFindFreeTerminal(), AirportHasBlock(), Vehicle::current_order, HANGAR, Order::IsType(), AirportFTAClass::layout, Aircraft::pos, and Aircraft::state.
|
static |
Aircraft has taken off.
Signature of the aircraft handler function.
Definition at line 1645 of file aircraft_cmd.cpp.
References AircraftNextAirportPos_and_Order(), FLYING, and Aircraft::state.
|
static |
Aircraft arrived in an airport hangar.
Signature of the aircraft handler function.
Definition at line 1520 of file aircraft_cmd.cpp.
References AirportFTAClass::layout, Aircraft::pos, Aircraft::state, and VehicleEnterDepot().
Referenced by AircraftEventHandler_InHangar().
|
static |
Aircraft arrives at the terminal.
Signature of the aircraft handler function.
Definition at line 1513 of file aircraft_cmd.cpp.
References AircraftEntersTerminal(), AirportFTAClass::layout, Aircraft::pos, and Aircraft::state.
Referenced by AircraftEventHandler_AtTerminal().
|
static |
Aircraft is flying around.
Signature of the aircraft handler function.
Definition at line 1670 of file aircraft_cmd.cpp.
References AIR_HELICOPTER, Station::airport, AirportClosed, AirportHasBlock(), Airport::blocks, CanVehicleUseStation(), Vehicle::cur_speed, Aircraft::flags, FLYING, SpecializedStation< Station, false >::Get(), AirportFTA::heading, HelicopterDirectDescent, HELILANDING, LANDING, AirportFTAClass::layout, AirportFTA::next, AirportFTA::next_position, BaseStation::owner, Vehicle::owner, OWNER_NONE, Aircraft::pos, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), Aircraft::state, Vehicle::subspeed, Vehicle::subtype, Aircraft::targetairport, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().
|
static |
Helicopter has landed.
Signature of the aircraft handler function.
Definition at line 1746 of file aircraft_cmd.cpp.
References Station::airport, AirportFindFreeHelipad(), AirportHasBlock(), Vehicle::current_order, SpecializedStation< Station, false >::Get(), HANGAR, Airport::HasHangar(), HELITAKEOFF, Order::IsType(), AirportFTAClass::layout, Aircraft::pos, Aircraft::state, and Aircraft::targetairport.
|
static |
Helicopter is starting to land.
Signature of the aircraft handler function.
Definition at line 1723 of file aircraft_cmd.cpp.
References HELIENDLANDING, Aircraft::state, and Aircraft::UpdateDeltaXY().
|
static |
Helicopter takes off.
Signature of the aircraft handler function.
Definition at line 1653 of file aircraft_cmd.cpp.
References _current_company, AircraftNextAirportPos_and_Order(), Execute, FLYING, Vehicle::NeedsAutomaticServicing(), Vehicle::owner, Backup< T >::Restore(), Service, Aircraft::state, and Aircraft::UpdateDeltaXY().
|
static |
Handle aircraft movement/decision making in an airport hangar.
Signature of the aircraft handler function.
Definition at line 1527 of file aircraft_cmd.cpp.
References AIR_HELICOPTER, AircraftEventHandler_EnterHangar(), AircraftLeaveHangar(), Station::airport, AirportFindFreeHelipad(), AirportFindFreeTerminal(), AirportHasBlock(), Vehicle::current_order, Order::Free(), BaseStation::GetByTile(), Order::GetDestination(), Airport::GetHangarExitDirection(), HELITAKEOFF, Order::IsType(), Vehicle::IsWaitingForUnbunching(), AirportFTAClass::layout, Aircraft::pos, Aircraft::previous_pos, Aircraft::state, Stopped, Vehicle::subtype, TAKEOFF, Aircraft::targetairport, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Vehicle::tile, VehicleEnterDepot(), and Vehicle::vehstatus.
|
static |
Aircraft is landing (touchdown).
Signature of the aircraft handler function.
Definition at line 1709 of file aircraft_cmd.cpp.
References _current_company, AircraftLandAirplane(), ENDLANDING, Execute, Vehicle::NeedsAutomaticServicing(), Vehicle::owner, Backup< T >::Restore(), Service, and Aircraft::state.
|
static |
Aircraft is taking off (rotation).
Signature of the aircraft handler function.
Definition at line 1638 of file aircraft_cmd.cpp.
References ENDTAKEOFF, Aircraft::state, and Aircraft::UpdateDeltaXY().
|
static |
Aircraft is taking off (rolling).
Signature of the aircraft handler function.
Definition at line 1631 of file aircraft_cmd.cpp.
References STARTTAKEOFF, and Aircraft::state.
|
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. |
| rotation | The rotation of the airport. |
Definition at line 822 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().
|
static |
Handle the 'dest too far' flag and the corresponding news message for aircraft.
| v | The aircraft. |
| too_far | True if the current destination is too far away. |
Definition at line 2081 of file aircraft_cmd.cpp.
References _local_company, AddVehicleAdviceNewsItem(), AircraftDestinationTooFar, DeleteVehicleNews(), DestinationTooFar, Aircraft::flags, GetEncodedString(), AI::NewEvent(), Vehicle::owner, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetWindowWidgetDirty(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), WC_VEHICLE_VIEW, and WID_VV_START_STOP.
Referenced by AircraftEventHandler().
|
static |
Aircraft touched down at the landing strip.
| v | Aircraft that landed. |
Definition at line 1442 of file aircraft_cmd.cpp.
References AirplaneTouchdown, SpecializedStation< Station, false >::Get(), PlayVehicleSound(), SND_17_SKID_PLANE, Aircraft::targetairport, TileVirtXY(), Aircraft::UpdateDeltaXY(), VSE_TOUCHDOWN, Vehicle::x_pos, and Vehicle::y_pos.
Referenced by AircraftEventHandler_Landing().
Aircraft is about to leave the hangar.
| v | Aircraft leaving. |
| exit_dir | The direction the vehicle leaves the hangar. |
Definition at line 1482 of file aircraft_cmd.cpp.
References Vehicle::cur_speed, Vehicle::direction, Hidden, InvalidateWindowData(), Vehicle::LeaveUnbunchingDepot(), SpecializedVehicle< T, Type >::Next(), Vehicle::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().
| void AircraftNextAirportPos_and_Order | ( | Aircraft * | v | ) |
Set the right pos when heading to other airports after takeoff.
| v | The aircraft to consider. |
Definition at line 1462 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(), AircraftEventHandler_EndTakeOff(), AircraftEventHandler_HeliTakeOff(), Aircraft::GetOrderStationLocation(), Vehicle::SendToDepot(), UpdateOldAircraft(), and UpdateOrderDest().
|
static |
Definition at line 1797 of file aircraft_cmd.cpp.
|
static |
Find a free helipad, and assign it if available.
Definition at line 2066 of file aircraft_cmd.cpp.
References AirportFindFreeTerminal(), FreeTerminal(), MAX_TERMINALS, and AirportFTAClass::num_helipads.
Referenced by AircraftEventHandler_HeliEndLanding(), and AircraftEventHandler_InHangar().
|
static |
Find a free terminal, and assign it if available.
Definition at line 2013 of file aircraft_cmd.cpp.
References Station::airport, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), Airport::blocks, AirportFTA::blocks, 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 AircraftEventHandler_EndLanding(), AircraftEventHandler_InHangar(), and AirportFindFreeHelipad().
|
static |
Definition at line 1812 of file aircraft_cmd.cpp.
|
static |
Checks whether the next block the aircraft wants to travel on is busy.
| v | The aircraft to consider. |
| current_pos | The current position in the state machine the aircraft is at. |
| apc | The airport's state machine. |
true iff the road ahead is busy, eg. you must wait before proceeding. Definition at line 1878 of file aircraft_cmd.cpp.
References Station::airport, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), Airport::blocks, AirportFTA::blocks, Vehicle::cur_speed, SpecializedStation< Station, false >::Get(), AirportFTAClass::layout, AirportFTA::next_position, Nothing, Aircraft::pos, AirportFTA::position, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), Vehicle::subspeed, and Aircraft::targetairport.
Referenced by AircraftEventHandler_AtTerminal(), AircraftEventHandler_EndLanding(), AircraftEventHandler_Flying(), AircraftEventHandler_HeliEndLanding(), and AircraftEventHandler_InHangar().
|
static |
Definition at line 1824 of file aircraft_cmd.cpp.
|
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 requested to be set |
Definition at line 1909 of file aircraft_cmd.cpp.
References Station::airport, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), Airport::blocks, AirportFTA::blocks, Vehicle::cur_speed, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Flip(), SpecializedStation< Station, false >::Get(), AirportFTA::heading, AirportFTAClass::layout, AirportFTA::next, AirportFTA::next_position, Nothing, Aircraft::pos, AirportFTA::position, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), Vehicle::subspeed, and Aircraft::targetairport.
|
static |
Definition at line 411 of file aircraft_cmd.cpp.
| CommandCost CmdBuildAircraft | ( | DoCommandFlags | flags, |
| TileIndex | tile, | ||
| const Engine * | e, | ||
| Vehicle ** | ret ) |
Build an aircraft.
| flags | type of operation. | |
| tile | tile of the depot where aircraft is built. | |
| e | the engine to build. | |
| [out] | ret | the vehicle that has been built. |
Definition at line 267 of file aircraft_cmd.cpp.
References _current_company, Vehicle::acceleration, AIR_AIRCRAFT, AIR_CTOL, AIR_HELICOPTER, AIR_ROTOR, AIR_SHADOW, Vehicle::build_year, BuiltAsPrototype, 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, BaseStation::GetByTile(), Engine::GetDefaultCargoType(), Engine::GetLifeLengthInDays(), GetSlopePixelZ(), GetStationIndex(), GetVehiclePosOnBuild(), HANGAR, Hidden, 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, Vehicle::random_bits, Vehicle::refit_cap, Engine::reliability, Vehicle::reliability, Engine::reliability_spd_dec, Vehicle::reliability_spd_dec, ROTOR_Z_OFFSET, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), VehicleSpriteSeq::Set(), 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, Vehicle::x_pos, Vehicle::y_pos, TimerGameCalendar::year, and Vehicle::z_pos.
Referenced by CmdBuildVehicle().
|
static |
Bring the aircraft in a crashed state, create the explosion animation, and create a news item about the crash.
| v | Aircraft that crashed. |
Definition at line 1347 of file aircraft_cmd.cpp.
References _local_company, _settings_client, Accident, AccidentOther, Vehicle::cargo, Aircraft::Crash(), CreateEffectVehicleRel(), EV_EXPLOSION_LARGE, GetEncodedString(), GetTargetAirportIfValid(), ModifyStationRatingAround(), AI::NewEvent(), Game::NewEvent(), SpecializedVehicle< T, Type >::Next(), Vehicle::owner, SND_12_EXPLOSION, TileVirtXYClampedToMap(), VehicleCargoList::Truncate(), Vehicle::x_pos, and Vehicle::y_pos.
Referenced by MaybeCrashAirplane().
| void DrawAircraftEngine | ( | int | left, |
| int | right, | ||
| int | preferred_x, | ||
| int | y, | ||
| EngineID | engine, | ||
| PaletteID | pal, | ||
| EngineImageType | image_type ) |
Definition at line 215 of file aircraft_cmd.cpp.
|
static |
Find the nearest hangar to v StationID::Invalid() is returned, if the company does not have any suitable airports (like helipads only).
| v | vehicle looking for a hangar |
Definition at line 118 of file aircraft_cmd.cpp.
References _cheats, AIR_CTOL, AirportFTAClass::Airplanes, Airport, Station::airport, AircraftCache::cached_max_range_sqr, Vehicle::current_order, DistanceSquare(), Vehicle::engine_type, AirportFTAClass::flags, Order::GetDepotActionType(), Order::GetDestination(), SpecializedStation< Station, false >::GetIfValid(), Vehicle::GetNextStoppingStation(), GetTargetAirportIfValid(), INVALID_TILE, Order::IsType(), SpecializedStation< Station, false >::Iterate(), Vehicle::last_station_visited, NearestDepot, Vehicle::owner, AirportFTAClass::ShortStrip, AircraftVehicleInfo::subtype, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), OrthogonalTileArea::tile, TileVirtXYClampedToMap(), Vehicle::x_pos, and Vehicle::y_pos.
Referenced by Aircraft::FindClosestDepot().
|
static |
Find a free terminal or helipad, and if available, assign it.
| v | Aircraft looking for a free terminal or helipad. |
| i | First terminal to examine. |
| last_terminal | Terminal number to stop examining. |
Definition at line 1978 of file aircraft_cmd.cpp.
References _airport_terminal_mapping, Station::airport, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), Airport::blocks, SpecializedStation< Station, false >::Get(), lengthof, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), Aircraft::state, and Aircraft::targetairport.
Referenced by AirportFindFreeHelipad(), and AirportFindFreeTerminal().
Definition at line 767 of file aircraft_cmd.cpp.
| 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.
| 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 724 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, BaseVehicle::type, Vehicle::vcache, and VEH_AIRCRAFT.
Referenced by AfterLoadGame(), AircraftController(), DisasterVehicle::DisasterVehicle(), ReleaseDisasterVehicle(), and UpdateOldAircraft().
| 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.
| v | The aircraft that may or may not need to decrease its altitude. |
Definition at line 759 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().
|
static |
Definition at line 199 of file aircraft_cmd.cpp.
| 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).
| 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.
References VehicleSpriteSeq::GetBounds(), Rect::Height(), Rect, UnScaleGUI(), and Rect::Width().
Referenced by EnginePreviewWindow::UpdateWidgetSize().
|
static |
Get the number of terminals at the airport.
| apc | Airport description. |
Definition at line 1998 of file aircraft_cmd.cpp.
References AirportFTAClass::terminals.
Referenced by AirportFindFreeTerminal().
| void GetRotorImage | ( | const Aircraft * | v, |
| EngineImageType | image_type, | ||
| VehicleSpriteSeq * | result ) |
Definition at line 185 of file aircraft_cmd.cpp.
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 2175 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().
| int GetTileHeightBelowAircraft | ( | const Vehicle * | v | ) |
Get the tile height below the aircraft.
This function is needed because aircraft can leave the mapborders.
| v | The vehicle to get the height for. |
Definition at line 707 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().
| void HandleAircraftEnterHangar | ( | Aircraft * | v | ) |
Handle Aircraft specific tasks when an Aircraft enters a hangar.
| *v | Vehicle that enters the hangar |
Definition at line 569 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().
|
static |
Handle smoke of broken aircraft.
| v | Aircraft |
| mode | Is this the non-first call for this vehicle in this tick? |
Definition at line 1248 of file aircraft_cmd.cpp.
References AircraftBroken, Vehicle::breakdown_ctr, CreateEffectVehicleRel(), Vehicle::cur_speed, Vehicle::direction, EV_BREAKDOWN_SMOKE_AIRCRAFT, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Vehicle::tick_counter, and Vehicle::vehstatus.
Referenced by AircraftEventHandler().
|
static |
Handle crashed aircraft v.
| v | Crashed aircraft. |
false iff the aircraft has been deleted. Definition at line 1187 of file aircraft_cmd.cpp.
References Station::airport, Airport::blocks, Chance16R(), ChangeDir(), Clamp(), Aircraft::crashed_counter, CreateEffectVehicleRel(), DIRDIFF_45LEFT, DIRDIFF_45RIGHT, DIRDIFF_SAME, Vehicle::direction, EV_EXPLOSION_SMALL, GB(), GetSlopePixelZ(), GetTargetAirportIfValid(), Map::MaxX(), Map::MaxY(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), RunwayIn, RunwayIn2, RunwayInOut, SetAircraftPosition(), TILE_SIZE, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.
Referenced by AircraftEventHandler().
| void HandleMissingAircraftOrders | ( | Aircraft * | v | ) |
Definition at line 1284 of file aircraft_cmd.cpp.
|
static |
Definition at line 477 of file aircraft_cmd.cpp.
| bool IsValidImageIndex< VEH_AIRCRAFT > | ( | uint8_t | image_index | ) |
Helper to check whether an image index is valid for a particular vehicle.
| T | The type of vehicle. |
| image_index | The image index to check. |
Definition at line 98 of file aircraft_cmd.cpp.
References lengthof.
|
static |
Decide whether aircraft v should crash.
| v | Aircraft to test. |
Definition at line 1383 of file aircraft_cmd.cpp.
References _cheats, _settings_game, Station::airport, GoodsEntry::GoodsEntryData::cargo, CrashAirplane(), Vehicle::engine_type, AirportFTAClass::flags, GB(), SpecializedStation< Station, false >::Get(), GoodsEntry::GetData(), Airport::GetFTA(), Station::goods, GoodsEntry::HasData(), GoodsEntry::rating, AirportFTAClass::ShortStrip, Aircraft::targetairport, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and StationCargoList::Truncate().
Referenced by AircraftController().
|
static |
Definition at line 585 of file aircraft_cmd.cpp.
| void SetAircraftPosition | ( | Aircraft * | v, |
| int | x, | ||
| int | y, | ||
| int | z ) |
Set aircraft position.
| v | Aircraft to position. |
| x | New X position. |
| y | New y position. |
| z | New z position. |
Definition at line 530 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().
| void UpdateAircraftCache | ( | Aircraft * | v, |
| bool | update_range ) |
Update cached values of an aircraft.
Currently caches callback 36 max speed.
| v | Vehicle |
| update_range | Update the aircraft range. |
Definition at line 599 of file aircraft_cmd.cpp.
References VehicleCache::cached_cargo_age_period, AircraftCache::cached_max_range, AircraftCache::cached_max_range_sqr, VehicleCache::cached_max_speed, Vehicle::engine_type, SpecializedVehicle< T, Type >::Next(), PROP_AIRCRAFT_CARGO_AGE_PERIOD, PROP_AIRCRAFT_SPEED, and Vehicle::vcache.
Referenced by AfterLoadGame(), AfterLoadVehiclesPhase2(), AircraftController(), CheckCaches(), CmdBuildAircraft(), CmdRefitVehicle(), UpdateAirplanesOnNewStation(), and UpdateOldAircraft().
|
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 |
'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 642 of file aircraft_cmd.cpp.
References _settings_game, Vehicle::acceleration, AircraftBroken, VehicleCache::cached_max_speed, Vehicle::cur_speed, Vehicle::GetOldAdvanceSpeed(), Vehicle::progress, SetWindowWidgetDirty(), SPEED_LIMIT_BROKEN, SPEED_LIMIT_NONE, Vehicle::subspeed, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Vehicle::vcache, Vehicle::vehstatus, WC_VEHICLE_VIEW, and WID_VV_START_STOP.
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 2189 of file aircraft_cmd.cpp.
References AircraftGetEntryPoint(), Station::airport, CanVehicleUseStation(), DIR_N, FLYING, Order::GetDepotOrderType(), Order::GetDestination(), Airport::GetFTA(), Airport::HasHangar(), INVALID_TILE, Order::IsType(), Order::MakeDummy(), PartOfOrders, RemoveOrderFromAllVehicles(), Airport::rotation, SetWindowWidgetDirty(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), OrthogonalTileArea::tile, UpdateAircraftCache(), WC_VEHICLE_VIEW, and WID_VV_START_STOP.
Referenced by CmdBuildAirport().
|
static |
Definition at line 86 of file aircraft_cmd.cpp.
|
static |
Array of handler functions for each target of the aircraft.
Definition at line 1772 of file aircraft_cmd.cpp.
|
static |
A list of all valid terminals and their associated blocks.
Definition at line 1957 of file aircraft_cmd.cpp.
Referenced by FreeTerminal().
|
staticconstexpr |
Maximum speed of an aircraft on finals.
Definition at line 630 of file aircraft_cmd.cpp.
Referenced by AircraftController().
|
staticconstexpr |
Maximum speed of an aircraft that is broken.
Definition at line 631 of file aircraft_cmd.cpp.
Referenced by UpdateAircraftSpeed().
|
staticconstexpr |
Maximum speed of an aircraft that flies the holding pattern.
Definition at line 632 of file aircraft_cmd.cpp.
Referenced by AircraftController().
|
staticconstexpr |
No environmental speed limit. Speed limit is type dependent.
Definition at line 633 of file aircraft_cmd.cpp.
Referenced by AircraftController(), and UpdateAircraftSpeed().
|
staticconstexpr |
Special velocities for aircraft.
Maximum speed of an aircraft while taxiing
Definition at line 629 of file aircraft_cmd.cpp.
Referenced by AircraftController().