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;
669 if (v->
cur_speed < speed_limit) hard_limit =
false;
681 if (!hard_limit && v->
cur_speed > speed_limit) {
771 int GetAircraftFlightLevel(T *v,
bool takeoff)
775 int aircraft_min_altitude;
776 int aircraft_max_altitude;
778 int aircraft_middle_altitude = (aircraft_min_altitude + aircraft_max_altitude) / 2;
781 assert(aircraft_min_altitude < aircraft_middle_altitude);
782 assert(aircraft_middle_altitude < aircraft_max_altitude);
785 if (z < aircraft_min_altitude ||
791 z += takeoff ? 2 : 1;
792 }
else if (!takeoff && (z > aircraft_max_altitude ||
810 template int GetAircraftFlightLevel(
Aircraft *v,
bool takeoff);
828 assert(v !=
nullptr);
829 assert(apc !=
nullptr);
846 if (
abs(delta_y) <
abs(delta_x)) {
874 uint size_x = 1, size_y = 1;
919 SoundID sfx = AircraftVehInfo(v->
engine_type)->sfx;
923 SndPlayVehicleFx(sfx, v);
936 if (v->
z_pos >= z_dest) {
1027 bool hard_limit =
true;
1035 if (count == 0)
return false;
1042 bool nudge_towards_target =
static_cast<uint
>(count) + 3 > dist;
1052 gp.x = (v->
x_pos != (x + amd.
x)) ?
1055 gp.
y = (v->
y_pos != (y + amd.
y)) ?
1065 Direction newdir = GetDirectionTowards(v, x + amd.
x, y + amd.
y);
1068 if (v->
turn_counter == 0 || newdir == v->last_direction) {
1069 if (newdir == v->last_direction) {
1109 z = GetAircraftFlightLevel(v,
true);
1114 z = GetAircraftFlightLevel(v);
1123 int airport_z = v->
z_pos;
1142 assert(airport_z <= z);
1143 int t = std::max(1U, dist - 4);
1144 int delta = z - airport_z;
1148 z -=
CeilDiv(z - airport_z, t);
1150 if (z < airport_z) z = airport_z;
1156 if (z > airport_z) {
1158 }
else if (z < airport_z) {
1165 }
while (--count != 0);
1183 if (v->
z_pos <= z) {
1195 static const DirDiff delta[] = {
1214 if (st !=
nullptr) {
1236 static const struct {
1270 void HandleMissingAircraftOrders(
Aircraft *v)
1288 if (st ==
nullptr) {
1291 cur_company.Restore();
1300 TileIndex Aircraft::GetOrderStationLocation(StationID)
1337 uint victims = v->
Crash();
1345 if (st ==
nullptr) {
1346 newsitem = STR_NEWS_PLANE_CRASH_OUT_OF_FUEL;
1349 newsitem = STR_NEWS_AIRCRAFT_CRASH;
1352 AI::NewEvent(v->
owner,
new ScriptEventVehicleCrashed(v->
index, vt, st ==
nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING, victims));
1353 Game::NewEvent(
new ScriptEventVehicleCrashed(v->
index, vt, st ==
nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING, victims));
1360 AddTileNewsItem(newsitem, newstype, vt,
nullptr, st !=
nullptr ? st->
index : INVALID_STATION);
1362 ModifyStationRatingAround(vt, v->
owner, -160, 30);
1385 if (
GB(Random(), 0, 22) > prob)
return;
1414 STR_NEWS_FIRST_AIRCRAFT_ARRIVAL,
1563 AirportMove(v, apc);
1571 AircraftEventHandler_EnterTerminal(v, apc);
1595 bool go_to_hangar =
false;
1597 case OT_GOTO_STATION:
1602 case OT_CONDITIONAL:
1609 go_to_hangar =
true;
1618 AirportMove(v, apc);
1623 FatalError(
"OK, you shouldn't be here, check your Airport Scheme!");
1628 PlayAircraftSound(v);
1657 cur_company.Restore();
1672 while (current !=
nullptr) {
1673 if (current->
heading == landingtype) {
1680 v->
state = landingtype;
1692 current = current->
next;
1708 cur_company.Restore();
1760 AircraftEventHandler_General,
1770 AircraftEventHandler_TakeOff,
1771 AircraftEventHandler_StartTakeOff,
1772 AircraftEventHandler_EndTakeOff,
1773 AircraftEventHandler_HeliTakeOff,
1774 AircraftEventHandler_Flying,
1775 AircraftEventHandler_Landing,
1776 AircraftEventHandler_EndLanding,
1777 AircraftEventHandler_HeliLanding,
1778 AircraftEventHandler_HeliEndLanding,
1794 static void AirportGoToNextPosition(
Aircraft *v)
1801 AirportClearBlock(v, apc);
1802 AirportMove(v, apc);
1810 Debug(misc, 0,
"[Ap] position {} is not valid for current airport. Max position is {}", v->
pos, apc->
nofelements-1);
1817 uint8_t prev_pos = v->
pos;
1818 uint8_t prev_state = v->
state;
1820 if (v->state !=
FLYING) v->previous_pos = prev_pos;
1825 v->previous_pos = v->pos;
1828 if (current->
next ==
nullptr) {
1846 current = current->
next;
1847 }
while (current !=
nullptr);
1849 Debug(misc, 0,
"[Ap] cannot move further on Airport! (pos {} state {}) for vehicle {}", v->pos, v->state, v->index);
1862 uint64_t airport_flags = next->
block;
1865 if (current_pos != reference && current_pos->
block != NOTHING_block) {
1866 airport_flags |= current_pos->
block;
1892 uint64_t airport_flags = next->
block;
1896 if (current == reference) current = current->
next;
1897 while (current !=
nullptr) {
1899 airport_flags |= current->
block;
1902 current = current->
next;
1916 if (next->
block != NOTHING_block) {
1958 for (; i < last_terminal; i++) {
2005 while (temp !=
nullptr) {
2015 uint group_start = 0;
2016 for (uint i = 1; i < target_group; i++) {
2020 uint group_end = group_start + apc->
terminals[target_group];
2021 if (
FreeTerminal(v, group_start, group_end))
return true;
2081 static bool AircraftEventHandler(
Aircraft *v,
int loop)
2131 for (uint i = 0; i != 2; i++) {
2133 if (!AircraftEventHandler(
this, i))
return false;
2151 if (st ==
nullptr)
return nullptr;
Base functions for all AIs.
@ VAF_HELI_DIRECT_DESCENT
The helicopter is descending directly at its destination (helipad or in front of hangar)
@ VAF_DEST_TOO_FAR
Next destination is too far away.
@ VAF_IN_MIN_HEIGHT_CORRECTION
The vehicle is currently raising its altitude because it hit the lower bound.
@ VAF_IN_MAX_HEIGHT_CORRECTION
The vehicle is currently lowering its altitude because it hit the upper bound.
static constexpr int AIRCRAFT_MIN_FLYING_ALTITUDE
Base values for flight levels above ground level for 'normal' flight and holding patterns.
static constexpr int HELICOPTER_HOLD_MAX_FLYING_ALTITUDE
holding flying altitude above tile of helicopters.
static const int ROTOR_Z_OFFSET
Z Offset between helicopter- and rotorsprite.
static constexpr int PLANE_HOLD_MAX_FLYING_ALTITUDE
holding flying altitude above tile of planes.
@ AIR_AIRCRAFT
an airplane
@ AIR_ROTOR
rotor of an helicopter
@ AIR_SHADOW
shadow of the aircraft
@ AIR_HELICOPTER
an helicopter
static constexpr int AIRCRAFT_MAX_FLYING_ALTITUDE
Maximum flying altitude above tile.
static void HandleAircraftSmoke(Aircraft *v, bool mode)
Handle smoke of broken aircraft.
static void AircraftEventHandler_InHangar(Aircraft *v, const AirportFTAClass *apc)
Handle aircraft movement/decision making in an airport hangar.
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 uint GetNumTerminals(const AirportFTAClass *apc)
Get the number of terminals at the airport.
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.
void AircraftNextAirportPos_and_Order(Aircraft *v)
set the right pos when heading to other airports after takeoff
int GetTileHeightBelowAircraft(const Vehicle *v)
Get the tile height below the aircraft.
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).
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 const MovementTerminalMapping _airport_terminal_mapping[]
A list of all valid terminals and their associated blocks.
CommandCost CmdBuildAircraft(DoCommandFlag flags, TileIndex tile, const Engine *e, Vehicle **ret)
Build an aircraft.
static bool AirportHasBlock(Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc)
returns true if the road ahead is busy, eg.
static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc)
"reserve" a block for the plane
static void AircraftLandAirplane(Aircraft *v)
Aircraft touched down at the landing strip.
int GetAircraftHoldMaxAltitude(const Aircraft *v)
Gets the maximum 'flight level' for the holding pattern of the aircraft, in pixels 'z_pos' 0,...
static bool FreeTerminal(Aircraft *v, uint8_t i, uint8_t last_terminal)
Find a free terminal or helipad, and if available, assign it.
static constexpr uint16_t SPEED_LIMIT_BROKEN
Maximum speed of an aircraft that is broken.
static void AircraftHandleDestTooFar(Aircraft *v, bool too_far)
Handle the 'dest too far' flag and the corresponding news message for aircraft.
static bool AircraftController(Aircraft *v)
Controls the movement of an aircraft.
void AircraftLeaveHangar(Aircraft *v, Direction exit_dir)
Aircraft is about to leave the hangar.
static bool AirportFindFreeHelipad(Aircraft *v, const AirportFTAClass *apc)
Find a free helipad, and assign it if available.
static constexpr uint16_t SPEED_LIMIT_NONE
No environmental speed limit. Speed limit is type dependent.
static void AircraftEntersTerminal(Aircraft *v)
Aircraft arrives at a terminal.
static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *apc)
At one of the Airport's Terminals.
void SetAircraftPosition(Aircraft *v, int x, int y, int z)
Set aircraft position.
static int UpdateAircraftSpeed(Aircraft *v, uint speed_limit=SPEED_LIMIT_NONE, bool hard_limit=true)
Sets the new speed for an aircraft.
static void MaybeCrashAirplane(Aircraft *v)
Decide whether aircraft v should crash.
static constexpr uint16_t SPEED_LIMIT_HOLD
Maximum speed of an aircraft that flies the holding pattern.
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 HandleCrashedAircraft(Aircraft *v)
Handle crashed aircraft v.
void UpdateAircraftCache(Aircraft *v, bool update_range)
Update cached values of an aircraft.
HelicopterRotorStates
Helicopter rotor animation states.
static AircraftStateHandler *const _aircraft_state_handlers[]
Array of handler functions for each target of the aircraft.
static void AircraftEventHandler_EnterHangar(Aircraft *v, const AirportFTAClass *apc)
Aircraft arrived in an airport hangar.
static bool AirportFindFreeTerminal(Aircraft *v, const AirportFTAClass *apc)
Find a free terminal, and assign it if available.
void HandleAircraftEnterHangar(Aircraft *v)
Handle Aircraft specific tasks when an Aircraft enters a hangar.
static constexpr uint16_t SPEED_LIMIT_APPROACH
Maximum speed of an aircraft on finals.
static void CrashAirplane(Aircraft *v)
Bring the aircraft in a crashed state, create the explosion animation, and create a news item about t...
static constexpr uint16_t SPEED_LIMIT_TAXI
Special velocities for aircraft.
void AircraftStateHandler(Aircraft *v, const AirportFTAClass *apc)
Signature of the aircraft handler function.
Command definitions related to aircraft.
const AirportFTAClass * GetAirport(const uint8_t airport_type)
Get the finite state machine of an airport type.
uint8_t GetVehiclePosOnBuild(TileIndex hangar_tile)
Get the vehicle position when an aircraft is build at the given tile.
AirportMovingData RotateAirportMovingData(const AirportMovingData *orig, Direction rotation, uint num_tiles_x, uint num_tiles_y)
Rotate the airport moving data to another rotation.
static const uint64_t TERM7_block
Block belonging to terminal 7.
static const uint64_t TERM4_block
Block belonging to terminal 4.
static const uint64_t TERM2_block
Block belonging to terminal 2.
static const uint64_t TERM1_block
Movement Blocks on Airports blocks (eg_airport_flags).
static const uint64_t TERM5_block
Block belonging to terminal 5.
static const uint64_t TERM3_block
Block belonging to terminal 3.
static const uint64_t TERM8_block
Block belonging to terminal 8.
static const uint MAX_TERMINALS
Some airport-related constants.
@ AT_OILRIG
Oilrig airport.
@ AMED_BRAKE
Taxiing at the airport.
@ AMED_HOLD
Holding pattern movement (above the airport).
@ AMED_SLOWTURN
Turn slowly (mostly used in the air).
@ AMED_HELI_LOWER
Helicopter landing.
@ AMED_LAND
Landing onto landing strip.
@ AMED_NOSPDCLAMP
No speed restrictions.
@ AMED_TAKEOFF
Takeoff movement.
@ AMED_EXACTPOS
Go exactly to the destination coordinates.
@ AMED_HELI_RAISE
Helicopter take-off.
static const uint64_t AIRPORT_CLOSED_block
Dummy block for indicating a closed airport.
static const uint64_t HELIPAD2_block
Block belonging to helipad 2.
static const uint64_t TERM6_block
Block belonging to terminal 6.
static const uint64_t HELIPAD3_block
Block belonging to helipad 3.
static const uint64_t HELIPAD1_block
Block belonging to helipad 1.
AirportMovementStates
Movement States on Airports (headings target)
@ HELITAKEOFF
Helicopter wants to leave the airport.
@ TERM4
Heading for terminal 4.
@ STARTTAKEOFF
Airplane has arrived at a runway for take-off.
@ HELIPAD2
Heading for helipad 2.
@ ENDTAKEOFF
Airplane has reached end-point of the take-off runway.
@ TERM5
Heading for terminal 5.
@ TERM6
Heading for terminal 6.
@ TERM3
Heading for terminal 3.
@ TERM8
Heading for terminal 8.
@ HELIPAD3
Heading for helipad 3.
@ HELIPAD1
Heading for helipad 1.
@ TERM2
Heading for terminal 2.
@ HANGAR
Heading for hangar.
@ FLYING
Vehicle is flying in the air.
@ TAKEOFF
Airplane wants to leave the airport.
@ HELILANDING
Helicopter wants to land.
@ TO_ALL
Go in this direction for every target.
@ ENDLANDING
Airplane wants to finish landing.
@ HELIENDLANDING
Helicopter wants to finish landing.
@ TERM1
Heading for terminal 1.
@ LANDING
Airplane wants to land.
@ TERM7
Heading for terminal 7.
@ TERMGROUP
Aircraft is looking for a free terminal in a terminalgroup.
Class for backupping variables and making sure they are restored later.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
#define CLRBITS(x, y)
Clears several bits in a variable.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
#define SETBITS(x, y)
Sets several bits in a variable.
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.
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
Cheats _cheats
All the cheats.
Types related to cheating.
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Common return value for all commands.
Money GetCost() const
The costs as made up to this moment.
bool Failed() const
Did this command fail?
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
uint Truncate(uint max_move=UINT_MAX, StationCargoAmountMap *cargo_per_source=nullptr)
Truncates where each destination loses roughly the same percentage of its cargo.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
static Date date
Current date in days (day counter).
static Year year
Current year, starting at 0.
static constexpr int DAYS_IN_YEAR
days per year
static Date date
Current date in days (day counter).
uint Truncate(uint max_move=UINT_MAX)
Truncates the cargo in this list to the given amount.
Functions related to commands.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
DoCommandFlag
List of flags for a command.
@ DC_EXEC
execute the given command
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
void SubtractMoneyFromCompanyFract(CompanyID company, const CommandCost &cst)
Subtract money from a company, including the money fraction.
Functions related to companies.
@ OWNER_NONE
The tile has no ownership.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta)
Applies a difference on a DiagDirection.
DiagDirDiff DiagDirDifference(DiagDirection d0, DiagDirection d1)
Calculate the difference between two DiagDirection values.
DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
Direction
Defines the 8 directions on the map.
DiagDirection
Enumeration for diagonal directions.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
DirDiff
Allow incrementing of Direction variables.
@ DIRDIFF_45LEFT
Angle of 45 degrees left.
@ DIRDIFF_REVERSE
One direction is the opposite of the other one.
@ DIRDIFF_45RIGHT
Angle of 45 degrees right.
@ DIRDIFF_SAME
Both directions faces to the same direction.
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
@ EXPENSES_AIRCRAFT_RUN
Running costs aircraft.
EffectVehicle * CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular vehicle.
Functions related to effect vehicles.
@ EV_EXPLOSION_SMALL
Various explosions.
@ EV_EXPLOSION_LARGE
Various explosions.
@ EV_BREAKDOWN_SMOKE_AIRCRAFT
Smoke of broken aircraft.
uint16_t EngineID
Unique identification number of an engine.
@ AIR_CTOL
Conventional Take Off and Landing, i.e. planes.
@ ENGINE_EXCLUSIVE_PREVIEW
This vehicle is in the exclusive preview stage, either being used or being offered to a company.
Error reporting related functions.
fluid_settings_t * settings
FluidSynth settings handle.
Types for recording game performance data.
@ PFE_GL_AIRCRAFT
Time spent processing aircraft.
Base functions for all Games.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
uint32_t PaletteID
The number of the palette.
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
Functions related to OTTD's landscape.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
NewGRF handling of airport tiles.
@ AAT_STATION_AIRPLANE_LAND
Triggered when an airplane (not a helicopter) touches down at the airport (for single tile).
Functions for NewGRF engines.
@ PROP_AIRCRAFT_RANGE
Aircraft range.
@ PROP_AIRCRAFT_RUNNING_COST_FACTOR
Yearly runningcost.
@ PROP_AIRCRAFT_SPEED
Max. speed: 1 unit = 8 mph = 12.8 km-ish/h.
@ PROP_AIRCRAFT_CARGO_AGE_PERIOD
Number of ticks before carried cargo is aged.
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event, bool force)
Checks whether a NewGRF wants to play a different vehicle sound effect.
Functions related to NewGRF provided sounds.
@ VSE_TOUCHDOWN
Whenever a plane touches down.
@ VSE_START
Vehicle starting, i.e. leaving, the station.
Functions related to news.
void DeleteVehicleNews(VehicleID vid, StringID news)
Delete a news item type about a vehicle.
void AddVehicleAdviceNewsItem(StringID string, VehicleID vehicle)
Adds a vehicle-advice news item.
void AddVehicleNewsItem(StringID string, NewsType type, VehicleID vehicle, StationID station=INVALID_STATION)
Adds a newsitem referencing a vehicle.
@ NT_ACCIDENT_OTHER
An accident or disaster has occurred.
@ NT_ARRIVAL_COMPANY
First vehicle arrived for company.
@ NT_ARRIVAL_OTHER
First vehicle arrived for competitor.
@ NT_ACCIDENT
An accident or disaster has occurred.
bool ProcessOrders(Vehicle *v)
Handle the orders of a vehicle and determine the next place to go to if needed.
void CheckOrders(const Vehicle *v)
Check the orders of a vehicle, to see if there are invalid orders and stuff.
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
@ ODATFB_NEAREST_DEPOT
Send the vehicle to the nearest depot.
@ ODTFB_PART_OF_ORDERS
This depot order is because of a regular order.
@ ODTFB_SERVICE
This depot order is because of the servicing limit.
Pseudo random number generator.
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.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
ClientSettings _settings_client
The current settings for this game.
Functions related to sound.
static const uint ORIGINAL_SAMPLE_COUNT
The number of sounds in the original sample.cat.
@ SND_18_TAKEOFF_HELICOPTER
22 == 0x16 Takeoff: helicopter
@ SND_17_SKID_PLANE
21 == 0x15 Plane landing / touching ground
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
Functions to cache sprites in memory.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Base classes/functions for stations.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
@ HVOT_AIRCRAFT
Station has seen an aircraft.
@ FACIL_AIRPORT
Station with an airport.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
uint32_t cached_max_range_sqr
Cached squared maximum range.
uint16_t cached_max_range
Cached maximum range.
Information about a aircraft vehicle.
uint16_t max_speed
Maximum speed (1 unit = 8 mph = 12.8 km-ish/h)
uint8_t mail_capacity
Mail capacity (bags).
uint8_t subtype
Type of aircraft.
uint16_t passenger_capacity
Passenger capacity (persons).
uint16_t max_range
Maximum range of this aircraft.
Aircraft, helicopters, rotors and their shadows belong to this class.
bool Tick() override
Calls the tick handler of the vehicle.
uint8_t pos
Next desired position of the aircraft.
uint8_t state
State of the airport.
uint8_t flags
Aircraft flags.
Money GetRunningCost() const override
Gets the running cost of a vehicle.
void UpdateDeltaXY() override
Updates the x and y offsets and the size of the sprite used for this vehicle.
uint8_t number_consecutive_turns
Protection to prevent the aircraft of making a lot of turns in order to reach a specific point.
void OnNewEconomyDay() override
Economy day handler.
uint Crash(bool flooded=false) override
Crash the (whole) vehicle chain.
void OnNewCalendarDay() override
Calendar day handler.
uint8_t turn_counter
Ticks between each turn to prevent > 45 degree turns.
bool IsNormalAircraft() const
Check if the aircraft type is a normal flying device; eg not a rotor or a shadow.
void MarkDirty() override
Marks the vehicles to be redrawn and updates cached variables.
uint8_t previous_pos
Previous desired position of the aircraft.
StationID targetairport
Airport to go to next.
ClosestDepot FindClosestDepot() override
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
uint16_t crashed_counter
Timer for handling crash animations.
Finite sTate mAchine (FTA) of an airport.
struct AirportFTA * layout
state machine for airport
const uint8_t num_helipads
Number of helipads on this airport. When 0 helicopters will go to normal terminals.
uint8_t delta_z
Z adjustment for helicopter pads.
const uint8_t * terminals
Array with the number of terminal groups, followed by the number of terminals in each group.
const uint8_t * entry_points
when an airplane arrives at this airport, enter it at position entry_point, index depends on directio...
uint8_t nofelements
number of positions the airport consists of
const AirportMovingData * MovingData(uint8_t position) const
Get movement data at a position.
Flags flags
Flags for this airport type.
@ AIRPLANES
Can planes land on this airport type?
@ SHORT_STRIP
This airport has a short landing strip, dangerous for fast aircraft.
Internal structure used in openttd - Finite sTate mAchine --> FTA.
AirportFTA * next
possible extra movement choices from this position
uint8_t heading
heading (current orders), guiding an airplane to its target on an airport
uint64_t block
64 bit blocks (st->airport.flags), should be enough for the most complex airports
uint8_t position
the position that an airplane is at
uint8_t next_position
next position from this position
A single location on an airport where aircraft can move to.
uint16_t flag
special flags when moving towards the destination.
int16_t x
x-coordinate of the destination.
int16_t y
y-coordinate of the destination.
Direction direction
Direction to turn the aircraft after reaching the destination.
bool HasHangar() const
Check if this airport has at least one hangar.
uint GetHangarNum(TileIndex tile) const
Get the hangar number of the hangar at a specific tile.
Direction rotation
How this airport is rotated.
uint8_t type
Type of this airport,.
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
const AirportFTAClass * GetFTA() const
Get the finite-state machine for this airport or the finite-state machine for the dummy airport in ca...
TileIndex GetHangarTile(uint hangar_num) const
Get the first tile of the given hangar.
Class to backup a specific variable and restore it later.
std::string name
Name of vehicle.
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
TileIndex xy
Base tile of the station.
Owner owner
The owner of this station.
VehicleType type
Type of vehicle.
bool value
tells if the bool cheat is active or not
Cheat no_jetcrash
no jet will crash on small airports anymore
SoundSettings sound
sound effect settings
Structure to return information about the closest depot location, and whether it could be found.
Disasters, like submarines, skyrangers and their shadows, belong to this class.
uint16_t cargo_age_period
Number of ticks before carried cargo is aged.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
uint16_t reliability_spd_dec
Speed of reliability decay between services (per day).
uint DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity=nullptr) const
Determines capacity of a given vehicle from scratch.
uint8_t original_image_index
Original vehicle image index, thus the image index of the overridden vehicle.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
TimerGameCalendar::Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
uint16_t reliability
Current reliability of the engine.
uint8_t flags
Flags of the engine.
VehicleSettings vehicle
options for vehicles
OrderSettings order
settings related to orders
Position information of a vehicle after it moved.
TileIndex new_tile
Tile of the vehicle after moving.
int y
x and y position of the vehicle after moving
TileIndex old_tile
Current tile of the vehicle.
Stores station stats for a single cargo.
StationCargoList cargo
The cargo packets of cargo waiting in this station.
uint8_t rating
Station rating for this cargo.
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Combination of aircraft state for going to a certain terminal and the airport flag for that terminal ...
uint64_t airport_flag
Bitmask in the airport flags that need to be free for this terminal.
AirportMovementStates state
Aircraft movement state when going to this terminal.
VehicleSpriteSeq sprite_seq
Vehicle appearance.
bool serviceathelipad
service helicopters at helipads automatically (no need to send to depot)
OrderDepotTypeFlags GetDepotOrderType() const
What caused us going to the depot?
DestinationID GetDestination() const
Gets the destination of this order.
bool IsType(OrderType type) const
Check whether this order is of the given type.
OrderType GetType() const
Get the type of order of this order.
void MakeDummy()
Makes this order a Dummy order.
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.
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
void Free()
'Free' the order
uint16_t w
The width of the area.
TileIndex tile
The base tile of the area.
uint16_t h
The height of the area.
Tindex index
Index of this pool item.
static Titem * Get(size_t index)
Returns Titem with given index.
Specification of a rectangle with absolute coordinates of all edges.
int Width() const
Get width of Rect.
int Height() const
Get height of Rect.
Titem value
Value of current item.
bool disaster
Play disaster and accident sounds.
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
static Station * Get(size_t index)
Gets station with given index.
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
static Aircraft * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
T * Next() const
Get next vehicle in the chain.
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
static Pool::IterateWrapper< Aircraft > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
GoodsEntry goods[NUM_CARGO]
Goods at this station.
Airport airport
Tile area the airport covers.
uint16_t cached_cargo_age_period
Number of ticks before carried cargo is aged.
uint16_t cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
uint8_t plane_crashes
number of plane crashes, 0 = none, 1 = reduced, 2 = normal
uint8_t plane_speed
divisor for speed of aircraft
Sprite sequence for a vehicle part.
bool IsValid() const
Check whether the sequence contains any sprites.
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
void CopyWithoutPalette(const VehicleSpriteSeq &src)
Copy data from another sprite sequence, while dropping all recolouring information.
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
EngineID engine_type
The type of engine used for this vehicle.
int32_t z_pos
z coordinate.
Direction direction
facing
StationIDStack GetNextStoppingStation() const
Get the next station the vehicle will stop at.
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
virtual uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
VehicleCargoList cargo
The cargo this vehicle is carrying.
uint8_t x_extent
x-extent of vehicle bounding box
TimerGameEconomy::Date date_of_last_service
Last economy date the vehicle had a service at a depot.
uint16_t cargo_cap
total capacity
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded.
uint8_t subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
uint16_t random_bits
Bits used for randomized variational spritegroups.
uint8_t day_counter
Increased by one for each 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...
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
SpriteID colourmap
NOSAVE: cached colour mapping.
uint8_t breakdown_ctr
Counter for managing breakdown events.
uint GetOldAdvanceSpeed(uint speed)
Determines the effective direction-specific vehicle movement speed.
uint8_t z_extent
z-extent of vehicle bounding box
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...
uint8_t subspeed
fractional speed
void LeaveUnbunchingDepot()
Leave an unbunching depot and calculate the next departure time for shared order vehicles.
int8_t y_offs
y offset for vehicle sprite
Vehicle * Next() const
Get the next vehicle of this vehicle.
uint8_t acceleration
used by train & aircraft
Order current_order
The current order (+ status, like: loading)
CargoID cargo_type
type of cargo this vehicle is carrying
int8_t x_offs
x offset for vehicle sprite
int32_t y_pos
y coordinate.
int32_t x_pos
x coordinate.
uint8_t y_extent
y-extent of vehicle bounding box
uint16_t refit_cap
Capacity left over from before last refit.
VehicleCache vcache
Cache of often used vehicle values.
void BeginLoading()
Prepare everything to begin the loading when arriving at a station.
uint8_t spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
uint16_t cur_speed
current speed
bool IsWaitingForUnbunching() const
Check whether a vehicle inside a depot is waiting for unbunching.
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
uint8_t breakdowns_since_last_service
Counter for the amount of breakdowns.
TimerGameCalendar::Date max_age
Maximum age.
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
uint16_t reliability
Reliability.
bool HandleBreakdown()
Handle all of the aspects of a vehicle breakdown This includes adding smoke and sounds,...
uint8_t progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
void UpdatePositionAndViewport()
Update the position of the vehicle, and update the viewport.
uint16_t reliability_spd_dec
Reliability decrease speed.
uint8_t tick_counter
Increased by one for each tick.
TileIndex tile
Current tile index.
void UpdatePosition()
Update the position of the vehicle.
StationID last_station_visited
The last station we stopped at.
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
TimerGameCalendar::Year build_year
Year the vehicle has been built.
Owner owner
Which company owns the vehicle?
bool NeedsAutomaticServicing() const
Checks if the current order should be interrupted for a service-in-depot order.
uint8_t running_ticks
Number of ticks this vehicle was not stopped this day.
int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_BASE.
static const uint TILE_SIZE
Tile size in world coordinates.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition of the game-calendar-timer.
Definition of the game-economy-timer.
void VehicleEnterDepot(Vehicle *v)
Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it,...
void VehicleServiceInDepot(Vehicle *v)
Service a vehicle and all subsequent vehicles in the consist.
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
Get position information of a vehicle when moving one pixel in the direction it is facing.
void DecreaseVehicleValue(Vehicle *v)
Decrease the value of a vehicle.
void EconomyAgeVehicle(Vehicle *v)
Update economy age of a vehicle.
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
void AgeVehicle(Vehicle *v)
Update age of a vehicle.
@ VF_BUILT_AS_PROTOTYPE
Vehicle is a prototype (accepted as exclusive preview).
@ VS_UNCLICKABLE
Vehicle is not clickable by the user (shadow vehicles).
@ VS_AIRCRAFT_BROKEN
Aircraft is broken down.
@ VS_SHADOW
Vehicle is a shadow vehicle.
@ VS_STOPPED
Vehicle is stopped by the player.
@ VS_HIDDEN
Vehicle is not visible.
@ VS_CRASHED
Vehicle is crashed.
@ VS_DEFPAL
Use default vehicle palette.
Command definitions for vehicles.
Functions related to vehicles.
EngineImageType
Visualisation contexts of vehicles and engines.
@ EIT_ON_MAP
Vehicle drawn in viewport.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ LocateHangar
Find another airport if the target one lacks a hangar.
@ Service
The vehicle will leave the depot right after arrival (service only)
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
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 SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Window functions not directly related to making/drawing windows.
@ WC_VEHICLE_DEPOT
Depot view; Window numbers:
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.