OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
45 #include "table/strings.h"
57 default: NOT_REACHED();
61 switch (this->
state) {
93 static const SpriteID _aircraft_sprite[] = {
94 0x0EB5, 0x0EBD, 0x0EC5, 0x0ECD,
95 0x0ED5, 0x0EDD, 0x0E9D, 0x0EA5,
96 0x0EAD, 0x0EE5, 0x0F05, 0x0F0D,
97 0x0F15, 0x0F1D, 0x0F25, 0x0F2D,
98 0x0EED, 0x0EF5, 0x0EFD, 0x0F35,
99 0x0E9D, 0x0EA5, 0x0EAD, 0x0EB5,
104 bool IsValidImageIndex<VEH_AIRCRAFT>(uint8_t image_index)
106 return image_index <
lengthof(_aircraft_sprite);
127 StationID index = INVALID_STATION;
133 const Station *last_dest =
nullptr;
134 const Station *next_dest =
nullptr;
135 if (max_range != 0) {
147 if (st->owner != v->
owner || !(st->facilities &
FACIL_AIRPORT) || !st->airport.HasHangar())
continue;
158 if (max_range != 0) {
161 if (last_dist > max_range || next_dist > max_range)
continue;
166 if (distance < best || index == INVALID_STATION) {
179 GetCustomVehicleSprite(
this,
direction, image_type, result);
180 if (result->IsValid())
return;
185 assert(IsValidImageIndex<VEH_AIRCRAFT>(
spritenum));
195 GetCustomRotorSprite(v, image_type, result);
196 if (result->IsValid())
return;
200 result->Set(SPR_ROTOR_STOPPED + w->
state);
206 uint8_t spritenum = e->u.air.image_index;
208 if (is_custom_sprite(spritenum)) {
209 GetCustomVehicleIcon(engine,
DIR_W, image_type, result);
210 if (result->IsValid())
return;
215 assert(IsValidImageIndex<VEH_AIRCRAFT>(spritenum));
216 result->Set(
DIR_W + _aircraft_sprite[spritenum]);
222 GetAircraftIcon(engine, image_type, &seq);
226 preferred_x =
Clamp(preferred_x,
232 if (!(AircraftVehInfo(engine)->subtype &
AIR_CTOL)) {
234 GetCustomRotorIcon(engine, image_type, &rotor_seq);
235 if (!rotor_seq.
IsValid()) rotor_seq.
Set(SPR_ROTOR_STOPPED);
252 GetAircraftIcon(engine, image_type, &seq);
314 CargoID mail = GetCargoIDByLabel(CT_MAIL);
387 w->
state = HRS_ROTOR_STOPPED;
415 static void CheckIfAircraftNeedsService(
Aircraft *v)
429 assert(st !=
nullptr);
465 CheckVehicleBreakdown(
this);
466 CheckIfAircraftNeedsService(
this);
481 static void HelicopterTickHandler(
Aircraft *v)
510 u->
state = HRS_ROTOR_STOPPED;
513 }
else if (tick >= spd) {
516 if (u->
state > HRS_ROTOR_MOVING_3) u->
state = HRS_ROTOR_MOVING_1;
589 static void PlayAircraftSound(
const Vehicle *v)
592 SndPlayVehicleFx(AircraftVehInfo(v->
engine_type)->sfx, v);
606 if (max_speed != 0) {
608 max_speed = (max_speed * 128) / 10;
671 if (v->
cur_speed < speed_limit) hard_limit =
false;
683 if (!hard_limit && v->
cur_speed > speed_limit) {
773 int GetAircraftFlightLevel(T *v,
bool takeoff)
777 int aircraft_min_altitude;
778 int aircraft_max_altitude;
780 int aircraft_middle_altitude = (aircraft_min_altitude + aircraft_max_altitude) / 2;
783 assert(aircraft_min_altitude < aircraft_middle_altitude);
784 assert(aircraft_middle_altitude < aircraft_max_altitude);
787 if (z < aircraft_min_altitude ||
793 z += takeoff ? 2 : 1;
794 }
else if (!takeoff && (z > aircraft_max_altitude ||
812 template int GetAircraftFlightLevel(
Aircraft *v,
bool takeoff);
830 assert(v !=
nullptr);
831 assert(apc !=
nullptr);
848 if (
abs(delta_y) <
abs(delta_x)) {
876 uint size_x = 1, size_y = 1;
921 SoundID sfx = AircraftVehInfo(v->
engine_type)->sfx;
925 SndPlayVehicleFx(sfx, v);
938 if (v->
z_pos >= z_dest) {
1029 bool hard_limit =
true;
1037 if (count == 0)
return false;
1044 bool nudge_towards_target =
static_cast<uint
>(count) + 3 > dist;
1054 gp.x = (v->
x_pos != (x + amd.
x)) ?
1057 gp.
y = (v->
y_pos != (y + amd.
y)) ?
1067 Direction newdir = GetDirectionTowards(v, x + amd.
x, y + amd.
y);
1070 if (v->
turn_counter == 0 || newdir == v->last_direction) {
1071 if (newdir == v->last_direction) {
1111 z = GetAircraftFlightLevel(v,
true);
1116 z = GetAircraftFlightLevel(v);
1125 int airport_z = v->
z_pos;
1144 assert(airport_z <= z);
1145 int t = std::max(1U, dist - 4);
1146 int delta = z - airport_z;
1150 z -=
CeilDiv(z - airport_z, t);
1152 if (z < airport_z) z = airport_z;
1158 if (z > airport_z) {
1160 }
else if (z < airport_z) {
1167 }
while (--count != 0);
1185 if (v->
z_pos <= z) {
1197 static const DirDiff delta[] = {
1216 if (st !=
nullptr) {
1238 static const struct {
1272 void HandleMissingAircraftOrders(
Aircraft *v)
1290 if (st ==
nullptr) {
1293 cur_company.Restore();
1302 TileIndex Aircraft::GetOrderStationLocation(StationID)
1339 uint victims = v->
Crash();
1347 if (st ==
nullptr) {
1348 newsitem = STR_NEWS_PLANE_CRASH_OUT_OF_FUEL;
1351 newsitem = STR_NEWS_AIRCRAFT_CRASH;
1354 AI::NewEvent(v->
owner,
new ScriptEventVehicleCrashed(v->
index, vt, st ==
nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING, victims));
1355 Game::NewEvent(
new ScriptEventVehicleCrashed(v->
index, vt, st ==
nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING, victims));
1362 AddTileNewsItem(newsitem, newstype, vt,
nullptr, st !=
nullptr ? st->
index : INVALID_STATION);
1364 ModifyStationRatingAround(vt, v->
owner, -160, 30);
1387 if (
GB(Random(), 0, 22) > prob)
return;
1416 STR_NEWS_FIRST_AIRCRAFT_ARRIVAL,
1565 AirportMove(v, apc);
1573 AircraftEventHandler_EnterTerminal(v, apc);
1597 bool go_to_hangar =
false;
1599 case OT_GOTO_STATION:
1604 case OT_CONDITIONAL:
1611 go_to_hangar =
true;
1620 AirportMove(v, apc);
1625 FatalError(
"OK, you shouldn't be here, check your Airport Scheme!");
1630 PlayAircraftSound(v);
1659 cur_company.Restore();
1674 while (current !=
nullptr) {
1675 if (current->
heading == landingtype) {
1682 v->
state = landingtype;
1694 current = current->
next;
1710 cur_company.Restore();
1762 AircraftEventHandler_General,
1772 AircraftEventHandler_TakeOff,
1773 AircraftEventHandler_StartTakeOff,
1774 AircraftEventHandler_EndTakeOff,
1775 AircraftEventHandler_HeliTakeOff,
1776 AircraftEventHandler_Flying,
1777 AircraftEventHandler_Landing,
1778 AircraftEventHandler_EndLanding,
1779 AircraftEventHandler_HeliLanding,
1780 AircraftEventHandler_HeliEndLanding,
1796 static void AirportGoToNextPosition(
Aircraft *v)
1803 AirportClearBlock(v, apc);
1804 AirportMove(v, apc);
1812 Debug(misc, 0,
"[Ap] position {} is not valid for current airport. Max position is {}", v->
pos, apc->
nofelements-1);
1819 uint8_t prev_pos = v->
pos;
1820 uint8_t prev_state = v->
state;
1822 if (v->state !=
FLYING) v->previous_pos = prev_pos;
1827 v->previous_pos = v->pos;
1830 if (current->
next ==
nullptr) {
1848 current = current->
next;
1849 }
while (current !=
nullptr);
1851 Debug(misc, 0,
"[Ap] cannot move further on Airport! (pos {} state {}) for vehicle {}", v->pos, v->state, v->index);
1864 uint64_t airport_flags = next->
block;
1867 if (current_pos != reference && current_pos->
block != NOTHING_block) {
1868 airport_flags |= current_pos->
block;
1894 uint64_t airport_flags = next->
block;
1898 if (current == reference) current = current->
next;
1899 while (current !=
nullptr) {
1901 airport_flags |= current->
block;
1904 current = current->
next;
1918 if (next->
block != NOTHING_block) {
1960 for (; i < last_terminal; i++) {
2007 while (temp !=
nullptr) {
2017 uint group_start = 0;
2018 for (uint i = 1; i < target_group; i++) {
2022 uint group_end = group_start + apc->
terminals[target_group];
2023 if (
FreeTerminal(v, group_start, group_end))
return true;
2083 static bool AircraftEventHandler(
Aircraft *v,
int loop)
2133 for (uint i = 0; i != 2; i++) {
2135 if (!AircraftEventHandler(
this, i))
return false;
2153 if (st ==
nullptr)
return nullptr;
@ VSE_START
Vehicle starting, i.e. leaving, the station.
static void CrashAirplane(Aircraft *v)
Bring the aircraft in a crashed state, create the explosion animation, and create a news item about t...
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
StationID targetairport
Airport to go to next.
static void AircraftEventHandler_EnterHangar(Aircraft *v, const AirportFTAClass *apc)
Aircraft arrived in an airport hangar.
@ HELILANDING
Helicopter wants to land.
static void AircraftHandleDestTooFar(Aircraft *v, bool too_far)
Handle the 'dest too far' flag and the corresponding news message for aircraft.
Cheat no_jetcrash
no jet will crash on small airports anymore
static int UpdateAircraftSpeed(Aircraft *v, uint speed_limit=SPEED_LIMIT_NONE, bool hard_limit=true)
Sets the new speed for an aircraft.
static const uint64_t AIRPORT_CLOSED_block
Dummy block for indicating a closed airport.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
void MakeDummy()
Makes this order a Dummy order.
Direction GetHangarExitDirection(TileIndex tile) const
Get the exit direction of the hangar at a specific tile.
uint64_t flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
GoodsEntry goods[NUM_CARGO]
Goods at this station.
@ DIRDIFF_REVERSE
One direction is the opposite of the other one.
uint16_t cached_cargo_age_period
Number of ticks before carried cargo is aged.
uint8_t rating
Station rating for this cargo.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
bool IsType(OrderType type) const
Check whether this order is of the given type.
int Height() const
Get height of Rect.
static Titem * Get(size_t index)
Returns Titem with given index.
@ SND_18_TAKEOFF_HELICOPTER
22 == 0x16 Takeoff: helicopter
uint16_t max_range
Maximum range of this aircraft.
@ ENDTAKEOFF
Airplane has reached end-point of the take-off runway.
uint GetHangarNum(TileIndex tile) const
Get the hangar number of the hangar at a specific tile.
uint16_t max_speed
Maximum speed (1 unit = 8 mph = 12.8 km-ish/h)
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
VehicleSpriteSeq sprite_seq
Vehicle appearance.
void CopyWithoutPalette(const VehicleSpriteSeq &src)
Copy data from another sprite sequence, while dropping all recolouring information.
A single location on an airport where aircraft can move to.
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
uint16_t reliability_spd_dec
Reliability decrease speed.
@ DIRDIFF_45LEFT
Angle of 45 degrees left.
int GetAircraftHoldMaxAltitude(const Aircraft *v)
Gets the maximum 'flight level' for the holding pattern of the aircraft, in pixels 'z_pos' 0,...
AirportMovingData RotateAirportMovingData(const AirportMovingData *orig, Direction rotation, uint num_tiles_x, uint num_tiles_y)
Rotate the airport moving data to another rotation.
@ ODTFB_SERVICE
This depot order is because of the servicing limit.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
int GetTileHeightBelowAircraft(const Vehicle *v)
Get the tile height below the aircraft.
uint16_t cargo_cap
total capacity
static const MovementTerminalMapping _airport_terminal_mapping[]
A list of all valid terminals and their associated blocks.
void CheckOrders(const Vehicle *v)
Check the orders of a vehicle, to see if there are invalid orders and stuff.
Class to backup a specific variable and restore it later.
bool Chance16R(const uint32_t a, const uint32_t b, uint32_t &r, const std::source_location location=std::source_location::current())
Flips a coin with a given probability and saves the randomize-number in a variable.
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
@ AMED_LAND
Landing onto landing strip.
uint16_t reliability_spd_dec
Speed of reliability decay between services (per day).
Vehicle * Next() const
Get the next vehicle of this vehicle.
@ HELIENDLANDING
Helicopter wants to finish landing.
T * Next() const
Get next vehicle in the chain.
const AirportFTAClass * GetAirport(const uint8_t airport_type)
Get the finite state machine of an airport type.
@ DIRDIFF_SAME
Both directions faces to the same direction.
DestinationID GetDestination() const
Gets the destination of this order.
bool NeedsAutomaticServicing() const
Checks if the current order should be interrupted for a service-in-depot order.
TimerGameCalendar::Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
@ NT_ACCIDENT
An accident or disaster has occurred.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
uint8_t breakdowns_since_last_service
Counter for the amount of breakdowns.
@ PLANE_HOLD_MAX_FLYING_ALTITUDE
holding flying altitude above tile of planes.
@ HVOT_AIRCRAFT
Station has seen an aircraft.
uint16_t cached_max_range
Cached maximum range.
@ VSE_TOUCHDOWN
Whenever a plane touches down.
static void HandleAircraftSmoke(Aircraft *v, bool mode)
Handle smoke of broken aircraft.
uint8_t spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
uint8_t y_extent
y-extent of vehicle bounding box
static const uint64_t HELIPAD1_block
Block belonging to helipad 1.
std::string name
Name of vehicle.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
uint8_t GetVehiclePosOnBuild(TileIndex hangar_tile)
Get the vehicle position when an aircraft is build at the given tile.
@ VS_DEFPAL
Use default vehicle palette.
Tindex index
Index of this pool item.
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
void AddVehicleAdviceNewsItem(StringID string, VehicleID vehicle)
Adds a vehicle-advice news item.
virtual uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
@ SHORT_STRIP
This airport has a short landing strip, dangerous for fast aircraft.
@ AMED_TAKEOFF
Takeoff movement.
@ PROP_AIRCRAFT_RUNNING_COST_FACTOR
Yearly runningcost.
void Free()
'Free' the order
void DeleteVehicleNews(VehicleID vid, StringID news)
Delete a news item type about a vehicle.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ TERM1
Heading for terminal 1.
void AircraftStateHandler(Aircraft *v, const AirportFTAClass *apc)
Signature of the aircraft handler function.
uint8_t plane_crashes
number of plane crashes, 0 = none, 1 = reduced, 2 = normal
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
@ VAF_IN_MAX_HEIGHT_CORRECTION
The vehicle is currently lowering its altitude because it hit the upper bound.
@ ENDLANDING
Airplane wants to finish landing.
void HandleAircraftEnterHangar(Aircraft *v)
Handle Aircraft specific tasks when an Aircraft enters a hangar.
uint8_t heading
heading (current orders), guiding an airplane to its target on an airport
static const uint TILE_SIZE
Tile size in world coordinates.
uint64_t airport_flag
Bitmask in the airport flags that need to be free for this terminal.
DiagDirection
Enumeration for diagonal directions.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
static Station * Get(size_t index)
Gets station with given index.
ClosestDepot FindClosestDepot() override
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
ClientSettings _settings_client
The current settings for this game.
void VehicleEnterDepot(Vehicle *v)
Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it,...
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
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).
@ EV_EXPLOSION_SMALL
Various explosions.
Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
EngineImageType
Visualisation contexts of vehicles and engines.
Station * GetTargetAirportIfValid(const Aircraft *v)
Returns aircraft's target station if v->target_airport is a valid station with airport.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
Owner owner
Which company owns the vehicle?
@ EV_EXPLOSION_LARGE
Various explosions.
@ DC_EXEC
execute the given command
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
uint32_t PaletteID
The number of the palette.
Owner owner
The owner of this station.
@ AIR_AIRCRAFT
an airplane
uint8_t position
the position that an airplane is at
@ VS_AIRCRAFT_BROKEN
Aircraft is broken down.
@ HANGAR
Heading for hangar.
DoCommandFlag
List of flags for a command.
void VehicleServiceInDepot(Vehicle *v)
Service a vehicle and all subsequent vehicles in the consist.
@ SPEED_LIMIT_APPROACH
Maximum speed of an aircraft on finals.
uint16_t h
The height of the area.
@ AIR_SHADOW
shadow of the aircraft
#define SETBITS(x, y)
Sets several bits in a variable.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
uint8_t subspeed
fractional speed
@ TERM7
Heading for terminal 7.
@ NT_ACCIDENT_OTHER
An accident or disaster has occurred.
int32_t x_pos
x coordinate.
int16_t x
x-coordinate of the destination.
Direction direction
Direction to turn the aircraft after reaching the destination.
@ TERM3
Heading for terminal 3.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
@ AMED_EXACTPOS
Go exactly to the destination coordinates.
const AirportFTAClass * GetFTA() const
Get the finite-state machine for this airport or the finite-state machine for the dummy airport in ca...
static void AircraftEventHandler_InHangar(Aircraft *v, const AirportFTAClass *apc)
Handle aircraft movement/decision making in an airport hangar.
OrderType GetType() const
Get the type of order of this order.
Money GetRunningCost() const override
Gets the running cost of a vehicle.
uint8_t flags
Flags of the engine.
Aircraft, helicopters, rotors and their shadows belong to this class.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
StationCargoList cargo
The cargo packets of cargo waiting in this station.
const uint8_t num_helipads
Number of helipads on this airport. When 0 helicopters will go to normal terminals.
TimerGameEconomy::Date date_of_last_service
Last economy date the vehicle had a service at a depot.
@ ENGINE_EXCLUSIVE_PREVIEW
This vehicle is in the exclusive preview stage, either being used or being offered to a company.
uint16_t cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
uint DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity=nullptr) const
Determines capacity of a given vehicle from scratch.
OrderSettings order
settings related to orders
bool HasHangar() const
Check if this airport has at least one hangar.
uint16_t crashed_counter
Timer for handling crash animations.
void BeginLoading()
Prepare everything to begin the loading when arriving at a station.
int16_t y
y-coordinate of the destination.
Direction rotation
How this airport is rotated.
@ VS_HIDDEN
Vehicle is not visible.
@ SND_17_SKID_PLANE
21 == 0x15 Plane landing / touching ground
DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
@ AAT_STATION_AIRPLANE_LAND
Triggered when an airplane (not a helicopter) touches down at the airport (for single tile).
bool IsValid() const
Check whether the sequence contains any sprites.
static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc)
"reserve" a block for the plane
@ AIRCRAFT_MAX_FLYING_ALTITUDE
Maximum flying altitude above tile.
uint8_t subtype
Type of aircraft.
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Common return value for all commands.
@ VAF_HELI_DIRECT_DESCENT
The helicopter is descending directly at its destination (helipad or in front of hangar)
uint8_t flags
Aircraft flags.
@ PROP_AIRCRAFT_CARGO_AGE_PERIOD
Number of ticks before carried cargo is aged.
uint Truncate(uint max_move=UINT_MAX)
Truncates the cargo in this list to the given amount.
@ AMED_SLOWTURN
Turn slowly (mostly used in the air).
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
SoundSettings sound
sound effect settings
DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta)
Applies a difference on a DiagDirection.
bool IsWaitingForUnbunching() const
Check whether a vehicle inside a depot is waiting for unbunching.
@ OWNER_NONE
The tile has no ownership.
@ NT_ARRIVAL_COMPANY
First vehicle arrived for company.
@ EV_BREAKDOWN_SMOKE_AIRCRAFT
Smoke of broken aircraft.
void SubtractMoneyFromCompanyFract(CompanyID company, const CommandCost &cst)
Subtract money from a company, including the money fraction.
TileIndex tile
Current tile index.
@ EXPENSES_AIRCRAFT_RUN
Running costs aircraft.
uint8_t pos
Next desired position of the aircraft.
@ EIT_ON_MAP
Vehicle drawn in viewport.
DiagDirDiff DiagDirDifference(DiagDirection d0, DiagDirection d1)
Calculate the difference between two DiagDirection values.
uint16_t random_bits
Bits used for randomized variational spritegroups.
EngineID engine_type
The type of engine used for this vehicle.
@ VS_CRASHED
Vehicle is crashed.
Cheats _cheats
All the cheats.
Sprite sequence for a vehicle part.
@ LocateHangar
Find another airport if the target one lacks a hangar.
StationID last_station_visited
The last station we stopped at.
uint8_t next_position
next position from this position
@ AMED_HOLD
Holding pattern movement (above the airport).
VehicleCargoList cargo
The cargo this vehicle is carrying.
uint GetOldAdvanceSpeed(uint speed)
Determines the effective direction-specific vehicle movement speed.
bool Failed() const
Did this command fail?
@ SPEED_LIMIT_TAXI
Maximum speed of an aircraft while taxiing.
Order current_order
The current order (+ status, like: loading)
TileIndex GetHangarTile(uint hangar_num) const
Get the first tile of the given hangar.
static bool AirportFindFreeHelipad(Aircraft *v, const AirportFTAClass *apc)
Find a free helipad, and assign it if available.
Airport airport
Tile area the airport covers.
HelicopterRotorStates
Helicopter rotor animation states.
struct AirportFTA * layout
state machine for airport
uint16_t cur_speed
current speed
Flags flags
Flags for this airport type.
@ ODATFB_NEAREST_DEPOT
Send the vehicle to the nearest depot.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
TimerGameCalendar::Year build_year
Year the vehicle has been built.
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
Internal structure used in openttd - Finite sTate mAchine --> FTA.
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 NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
@ VS_STOPPED
Vehicle is stopped by the player.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
uint8_t mail_capacity
Mail capacity (bags).
TileIndex new_tile
Tile of the vehicle after moving.
#define lengthof(array)
Return the length of an fixed size array.
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded.
Money GetCost() const
The costs as made up to this moment.
static const uint64_t TERM2_block
Block belonging to terminal 2.
DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
uint64_t block
64 bit blocks (st->airport.flags), should be enough for the most complex airports
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
static const uint64_t TERM1_block
Movement Blocks on Airports blocks (eg_airport_flags).
AircraftSpeedLimits
Special velocities for aircraft.
@ ODTFB_PART_OF_ORDERS
This depot order is because of a regular order.
fluid_settings_t * settings
FluidSynth settings handle.
@ SPEED_LIMIT_HOLD
Maximum speed of an aircraft that flies the holding pattern.
@ VAF_IN_MIN_HEIGHT_CORRECTION
The vehicle is currently raising its altitude because it hit the lower bound.
Combination of aircraft state for going to a certain terminal and the airport flag for that terminal ...
bool serviceathelipad
service helicopters at helipads automatically (no need to send to depot)
Finite sTate mAchine (FTA) of an airport.
bool disaster
Play disaster and accident sounds.
static void MaybeCrashAirplane(Aircraft *v)
Decide whether aircraft v should crash.
static uint GetNumTerminals(const AirportFTAClass *apc)
Get the number of terminals at the airport.
DirDiff
Allow incrementing of Direction variables.
uint8_t running_ticks
Number of ticks this vehicle was not stopped this day.
void HandleLoading(bool mode=false)
Handle the loading of the vehicle; when not it skips through dummy orders and does nothing in all oth...
@ PFE_GL_AIRCRAFT
Time spent processing aircraft.
EffectVehicle * CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular vehicle.
uint8_t previous_pos
Previous desired position of the aircraft.
@ NT_ARRIVAL_OTHER
First vehicle arrived for competitor.
@ TERM5
Heading for terminal 5.
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
void AddVehicleNewsItem(StringID string, NewsType type, VehicleID vehicle, StationID station=INVALID_STATION)
Adds a newsitem referencing a vehicle.
bool value
tells if the bool cheat is active or not
uint16_t reliability
Current reliability of the engine.
uint8_t progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
@ HELIPAD3
Heading for helipad 3.
static bool AirportHasBlock(Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc)
returns true if the road ahead is busy, eg.
static const uint64_t HELIPAD3_block
Block belonging to helipad 3.
SpriteID colourmap
NOSAVE: cached colour mapping.
void OnNewCalendarDay() override
Calendar day handler.
void AircraftLeaveHangar(Aircraft *v, Direction exit_dir)
Aircraft is about to leave the hangar.
uint8_t plane_speed
divisor for speed of aircraft
uint8_t number_consecutive_turns
Protection to prevent the aircraft of making a lot of turns in order to reach a specific point.
Disasters, like submarines, skyrangers and their shadows, belong to this class.
int32_t z_pos
z coordinate.
@ VF_BUILT_AS_PROTOTYPE
Vehicle is a prototype (accepted as exclusive preview).
Direction direction
facing
static const uint64_t TERM8_block
Block belonging to terminal 8.
static const uint MAX_TERMINALS
Some airport-related constants.
@ TERM2
Heading for terminal 2.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
uint8_t tick_counter
Increased by one for each tick.
uint8_t nofelements
number of positions the airport consists of
static const uint64_t TERM7_block
Block belonging to terminal 7.
uint8_t subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
bool ProcessOrders(Vehicle *v)
Handle the orders of a vehicle and determine the next place to go to if needed.
@ VAF_DEST_TOO_FAR
Next destination is too far away.
uint8_t acceleration
used by train & aircraft
static bool HandleCrashedAircraft(Aircraft *v)
Handle crashed aircraft v.
VehicleCache vcache
Cache of often used vehicle values.
Stores station stats for a single cargo.
CompanyID _current_company
Company currently doing an action.
AirportFTA * next
possible extra movement choices from this position
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Titem value
Value of current item.
uint8_t day_counter
Increased by one for each day.
AirportMovementStates
Movement States on Airports (headings target)
TimerGameCalendar::Date max_age
Maximum age.
@ HELICOPTER_HOLD_MAX_FLYING_ALTITUDE
holding flying altitude above tile of helicopters.
uint32_t cached_max_range_sqr
Cached squared maximum range.
uint8_t state
State of the airport.
static Aircraft * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
int8_t x_offs
x offset for vehicle sprite
@ DIRDIFF_45RIGHT
Angle of 45 degrees right.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
TimerGameCalendar::Date date_of_last_service_newgrf
Last calendar date the vehicle had a service at a depot, unchanged by the date cheat to protect again...
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
static const uint64_t TERM6_block
Block belonging to terminal 6.
TileIndex tile
The base tile of the area.
@ AIR_HELICOPTER
an helicopter
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
bool IsNormalAircraft() const
Check if the aircraft type is a normal flying device; eg not a rotor or a shadow.
void OnNewEconomyDay() override
Economy day handler.
static void AircraftEntersTerminal(Aircraft *v)
Aircraft arrives at a terminal.
uint16_t reliability
Reliability.
void UpdateAircraftCache(Aircraft *v, bool update_range)
Update cached values of an aircraft.
Position information of a vehicle after it moved.
@ WC_VEHICLE_DEPOT
Depot view; Window numbers:
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
const AirportMovingData * MovingData(uint8_t position) const
Get movement data at a position.
static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *apc)
At one of the Airport's Terminals.
@ HELIPAD1
Heading for helipad 1.
uint8_t turn_counter
Ticks between each turn to prevent > 45 degree turns.
void UpdateAirplanesOnNewStation(const Station *st)
Updates the status of the Aircraft heading or in the station.
uint16_t cargo_age_period
Number of ticks before carried cargo is aged.
@ HELITAKEOFF
Helicopter wants to leave the airport.
static const uint64_t HELIPAD2_block
Block belonging to helipad 2.
uint8_t delta_z
Z adjustment for helicopter pads.
void AircraftNextAirportPos_and_Order(Aircraft *v)
set the right pos when heading to other airports after takeoff
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
@ SPEED_LIMIT_NONE
No environmental speed limit. Speed limit is type dependent.
Direction
Defines the 8 directions on the map.
TileIndex xy
Base tile of the station.
static StationID FindNearestHangar(const Aircraft *v)
Find the nearest hangar to v INVALID_STATION is returned, if the company does not have any suitable a...
static const uint ORIGINAL_SAMPLE_COUNT
The number of sounds in the original sample.cat.
static const uint64_t TERM4_block
Block belonging to terminal 4.
static Pool::IterateWrapper< Aircraft > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
TileIndex old_tile
Current tile of the vehicle.
int32_t y_pos
y coordinate.
Structure to return information about the closest depot location, and whether it could be found.
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event, bool force)
Checks whether a NewGRF wants to play a different vehicle sound effect.
uint16_t w
The width of the area.
OrderDepotTypeFlags GetDepotOrderType() const
What caused us going to the depot?
@ AIR_CTOL
Conventional Take Off and Landing, i.e. planes.
int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
@ VS_UNCLICKABLE
Vehicle is not clickable by the user (shadow vehicles).
@ TERMGROUP
Aircraft is looking for a free terminal in a terminalgroup.
@ TO_ALL
Go in this direction for every target.
static bool AircraftController(Aircraft *v)
Controls the movement of an aircraft.
int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
uint16_t passenger_capacity
Passenger capacity (persons).
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
void AgeVehicle(Vehicle *v)
Update age of a vehicle.
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
@ STARTTAKEOFF
Airplane has arrived at a runway for take-off.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_BASE.
@ Service
The vehicle will leave the depot right after arrival (service only)
const uint8_t * terminals
Array with the number of terminal groups, followed by the number of terminals in each group.
static bool FreeTerminal(Aircraft *v, uint8_t i, uint8_t last_terminal)
Find a free terminal or helipad, and if available, assign it.
@ VEH_AIRCRAFT
Aircraft vehicle type.
uint8_t x_extent
x-extent of vehicle bounding box
CargoID cargo_type
type of cargo this vehicle is carrying
uint8_t original_image_index
Original vehicle image index, thus the image index of the overridden vehicle.
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
uint Crash(bool flooded=false) override
Crash the (whole) vehicle chain.
@ AMED_HELI_RAISE
Helicopter take-off.
@ LANDING
Airplane wants to land.
static Date date
Current date in days (day counter).
@ TERM6
Heading for terminal 6.
VehicleSettings vehicle
options for vehicles
uint16_t EngineID
Unique identification number of an engine.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
VehicleType type
Type of vehicle.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
void UpdatePositionAndViewport()
Update the position of the vehicle, and update the viewport.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
@ PROP_AIRCRAFT_SPEED
Max. speed: 1 unit = 8 mph = 12.8 km-ish/h.
AirportMovementStates state
Aircraft movement state when going to this terminal.
@ TERM8
Heading for terminal 8.
static const uint64_t TERM3_block
Block belonging to terminal 3.
void UpdatePosition()
Update the position of the vehicle.
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 si...
static bool AirportFindFreeTerminal(Aircraft *v, const AirportFTAClass *apc)
Find a free terminal, and assign it if available.
int Width() const
Get width of Rect.
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
static void AircraftLandAirplane(Aircraft *v)
Aircraft touched down at the landing strip.
bool HandleBreakdown()
Handle all of the aspects of a vehicle breakdown This includes adding smoke and sounds,...
Information about a aircraft vehicle.
void DecreaseVehicleValue(Vehicle *v)
Decrease the value of a vehicle.
int y
x and y position of the vehicle after moving
void EconomyAgeVehicle(Vehicle *v)
Update economy age of a vehicle.
bool Tick() override
Calls the tick handler of the vehicle.
@ TAKEOFF
Airplane wants to leave the airport.
static const uint64_t TERM5_block
Block belonging to terminal 5.
Specification of a rectangle with absolute coordinates of all edges.
@ AIRPLANES
Can planes land on this airport type?
uint8_t type
Type of this airport,.
static constexpr int DAYS_IN_YEAR
days per year
@ SPEED_LIMIT_BROKEN
Maximum speed of an aircraft that is broken.
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type=ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action=ODATF_SERVICE_ONLY, CargoID cargo=CARGO_NO_REFIT)
Makes this order a Go To Depot order.
const uint8_t * entry_points
when an airplane arrives at this airport, enter it at position entry_point, index depends on directio...
#define CLRBITS(x, y)
Clears several bits in a variable.
@ PROP_AIRCRAFT_RANGE
Aircraft range.
@ HELIPAD2
Heading for helipad 2.
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
@ VS_SHADOW
Vehicle is a shadow vehicle.
void UpdateDeltaXY() override
Updates the x and y offsets and the size of the sprite used for this vehicle.
void LeaveUnbunchingDepot()
Leave an unbunching depot and calculate the next departure time for shared order vehicles.
uint Truncate(uint max_move=UINT_MAX, StationCargoAmountMap *cargo_per_source=nullptr)
Truncates where each destination loses roughly the same percentage of its cargo.
void MarkDirty() override
Marks the vehicles to be redrawn and updates cached variables.
@ FLYING
Vehicle is flying in the air.
@ AMED_HELI_LOWER
Helicopter landing.
@ AIRCRAFT_MIN_FLYING_ALTITUDE
Minimum flying altitude above tile.
CommandCost CmdBuildAircraft(DoCommandFlag flags, TileIndex tile, const Engine *e, Vehicle **ret)
Build an aircraft.
static AircraftStateHandler *const _aircraft_state_handlers[]
Array of handler functions for each target of the aircraft.
int8_t y_offs
y offset for vehicle sprite
@ AT_OILRIG
Oilrig airport.
uint16_t flag
special flags when moving towards the destination.
uint16_t refit_cap
Capacity left over from before last refit.
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
Get position information of a vehicle when moving one pixel in the direction it is facing.
void SetAircraftPosition(Aircraft *v, int x, int y, int z)
Set aircraft position.
uint8_t z_extent
z-extent of vehicle bounding box
@ AMED_BRAKE
Taxiing at the airport.
@ TERM4
Heading for terminal 4.
@ AIR_ROTOR
rotor of an helicopter
StationIDStack GetNextStoppingStation() const
Get the next station the vehicle will stop at.
@ AMED_NOSPDCLAMP
No speed restrictions.
static const int ROTOR_Z_OFFSET
Z Offset between helicopter- and rotorsprite.
static Year year
Current year, starting at 0.
@ FACIL_AIRPORT
Station with an airport.
static Date date
Current date in days (day counter).
uint8_t breakdown_ctr
Counter for managing breakdown events.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.