OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
41 #include "table/strings.h"
53 default: NOT_REACHED();
57 switch (this->
state) {
89 static const SpriteID _aircraft_sprite[] = {
90 0x0EB5, 0x0EBD, 0x0EC5, 0x0ECD,
91 0x0ED5, 0x0EDD, 0x0E9D, 0x0EA5,
92 0x0EAD, 0x0EE5, 0x0F05, 0x0F0D,
93 0x0F15, 0x0F1D, 0x0F25, 0x0F2D,
94 0x0EED, 0x0EF5, 0x0EFD, 0x0F35,
95 0x0E9D, 0x0EA5, 0x0EAD, 0x0EB5,
100 bool IsValidImageIndex<VEH_AIRCRAFT>(uint8 image_index)
102 return image_index <
lengthof(_aircraft_sprite);
123 StationID index = INVALID_STATION;
129 const Station *last_dest =
nullptr;
130 const Station *next_dest =
nullptr;
131 if (max_range != 0) {
143 if (st->owner != v->
owner || !(st->facilities &
FACIL_AIRPORT) || !st->airport.HasHangar())
continue;
154 if (max_range != 0) {
157 if (last_dist > max_range || next_dist > max_range)
continue;
162 if (distance < best || index == INVALID_STATION) {
175 GetCustomVehicleSprite(
this,
direction, image_type, result);
181 assert(IsValidImageIndex<VEH_AIRCRAFT>(
spritenum));
191 GetCustomRotorSprite(v,
false, image_type, result);
196 result->
Set(SPR_ROTOR_STOPPED + w->
state);
202 uint8 spritenum = e->u.air.image_index;
204 if (is_custom_sprite(spritenum)) {
205 GetCustomVehicleIcon(engine,
DIR_W, image_type, result);
211 assert(IsValidImageIndex<VEH_AIRCRAFT>(spritenum));
212 result->
Set(
DIR_W + _aircraft_sprite[spritenum]);
218 GetAircraftIcon(engine, image_type, &seq);
222 preferred_x =
Clamp(preferred_x,
228 if (!(AircraftVehInfo(engine)->subtype &
AIR_CTOL)) {
230 GetCustomRotorIcon(engine, image_type, &rotor_seq);
231 if (!rotor_seq.
IsValid()) rotor_seq.
Set(SPR_ROTOR_STOPPED);
248 GetAircraftIcon(engine, image_type, &seq);
253 width =
UnScaleGUI(rect.right - rect.left + 1);
254 height =
UnScaleGUI(rect.bottom - rect.top + 1);
296 u->
z_pos = GetSlopePixelZ(x, y);
330 _new_vehicle_id = v->
index;
380 w->
state = HRS_ROTOR_STOPPED;
400 if (station == INVALID_STATION)
return false;
405 if (location !=
nullptr) *location = st->
xy;
406 if (destination !=
nullptr) *destination = st->
index;
411 static void CheckIfAircraftNeedsService(
Aircraft *v)
425 assert(st !=
nullptr);
452 CheckVehicleBreakdown(
this);
454 CheckIfAircraftNeedsService(
this);
469 static void HelicopterTickHandler(
Aircraft *v)
498 u->
state = HRS_ROTOR_STOPPED;
501 }
else if (tick >= spd) {
504 if (u->
state > HRS_ROTOR_MOVING_3) u->
state = HRS_ROTOR_MOVING_1;
539 u->
y_pos = y - ((v->
z_pos - GetSlopePixelZ(safe_x, safe_y)) >> 3);
542 u->
z_pos = GetSlopePixelZ(safe_x, safe_y);
577 static void PlayAircraftSound(
const Vehicle *v)
580 SndPlayVehicleFx(AircraftVehInfo(v->
engine_type)->sfx, v);
594 if (max_speed != 0) {
596 max_speed = (max_speed * 128) / 10;
659 if (v->
cur_speed < speed_limit) hard_limit =
false;
671 if (!hard_limit && v->
cur_speed > speed_limit) {
761 int GetAircraftFlightLevel(T *v,
bool takeoff)
765 int aircraft_min_altitude;
766 int aircraft_max_altitude;
768 int aircraft_middle_altitude = (aircraft_min_altitude + aircraft_max_altitude) / 2;
771 assert(aircraft_min_altitude < aircraft_middle_altitude);
772 assert(aircraft_middle_altitude < aircraft_max_altitude);
775 if (z < aircraft_min_altitude ||
781 z += takeoff ? 2 : 1;
782 }
else if (!takeoff && (z > aircraft_max_altitude ||
800 template int GetAircraftFlightLevel(
Aircraft *v,
bool takeoff);
818 assert(v !=
nullptr);
819 assert(apc !=
nullptr);
836 if (
abs(delta_y) <
abs(delta_x)) {
864 uint size_x = 1, size_y = 1;
909 SoundID sfx = AircraftVehInfo(v->
engine_type)->sfx;
913 SndPlayVehicleFx(sfx, v);
926 if (v->
z_pos >= z_dest) {
961 int z = GetSlopePixelZ(x, y) + 1 + afc->
delta_z;
1017 bool hard_limit =
true;
1025 if (count == 0)
return false;
1032 bool nudge_towards_target =
static_cast<uint
>(count) + 3 > dist;
1042 gp.x = (v->
x_pos != (x + amd.
x)) ?
1045 gp.
y = (v->
y_pos != (y + amd.
y)) ?
1055 Direction newdir = GetDirectionTowards(v, x + amd.
x, y + amd.
y);
1058 if (v->
turn_counter == 0 || newdir == v->last_direction) {
1059 if (newdir == v->last_direction) {
1099 z = GetAircraftFlightLevel(v,
true);
1104 z = GetAircraftFlightLevel(v);
1113 int airport_z = v->
z_pos;
1132 assert(airport_z <= z);
1133 int t = std::max(1U, dist - 4);
1134 int delta = z - airport_z;
1138 z -=
CeilDiv(z - airport_z, t);
1140 if (z < airport_z) z = airport_z;
1146 if (z > airport_z) {
1148 }
else if (z < airport_z) {
1155 }
while (--count != 0);
1173 if (v->
z_pos == z) {
1182 static const DirDiff delta[] = {
1201 if (st !=
nullptr) {
1223 static const struct {
1257 void HandleMissingAircraftOrders(
Aircraft *v)
1275 if (st ==
nullptr) {
1278 cur_company.Restore();
1324 uint pass = v->
Crash();
1332 if (st ==
nullptr) {
1333 newsitem = STR_NEWS_PLANE_CRASH_OUT_OF_FUEL;
1337 newsitem = STR_NEWS_AIRCRAFT_CRASH;
1341 AI::NewEvent(v->
owner,
new ScriptEventVehicleCrashed(v->
index, vt, st ==
nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
1342 Game::NewEvent(
new ScriptEventVehicleCrashed(v->
index, vt, st ==
nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
1344 AddTileNewsItem(newsitem,
NT_ACCIDENT, vt,
nullptr, st !=
nullptr ? st->
index : INVALID_STATION);
1346 ModifyStationRatingAround(vt, v->
owner, -160, 30);
1361 (AircraftVehInfo(v->
engine_type)->subtype & AIR_FAST) &&
1369 if (
GB(Random(), 0, 22) > prob)
return;
1398 STR_NEWS_FIRST_AIRCRAFT_ARRIVAL,
1543 AirportMove(v, apc);
1551 AircraftEventHandler_EnterTerminal(v, apc);
1574 bool go_to_hangar =
false;
1576 case OT_GOTO_STATION:
1581 case OT_CONDITIONAL:
1597 AirportMove(v, apc);
1602 error(
"OK, you shouldn't be here, check your Airport Scheme!");
1607 PlayAircraftSound(v);
1636 cur_company.Restore();
1651 while (current !=
nullptr) {
1652 if (current->
heading == landingtype) {
1659 v->
state = landingtype;
1671 current = current->
next;
1687 cur_company.Restore();
1739 AircraftEventHandler_General,
1749 AircraftEventHandler_TakeOff,
1750 AircraftEventHandler_StartTakeOff,
1751 AircraftEventHandler_EndTakeOff,
1752 AircraftEventHandler_HeliTakeOff,
1753 AircraftEventHandler_Flying,
1754 AircraftEventHandler_Landing,
1755 AircraftEventHandler_EndLanding,
1756 AircraftEventHandler_HeliLanding,
1757 AircraftEventHandler_HeliEndLanding,
1773 static void AirportGoToNextPosition(
Aircraft *v)
1780 AirportClearBlock(v, apc);
1781 AirportMove(v, apc);
1789 Debug(misc, 0,
"[Ap] position {} is not valid for current airport. Max position is {}", v->
pos, apc->
nofelements-1);
1796 byte prev_pos = v->
pos;
1797 byte prev_state = v->
state;
1799 if (v->state !=
FLYING) v->previous_pos = prev_pos;
1804 v->previous_pos = v->pos;
1807 if (current->
next ==
nullptr) {
1825 current = current->
next;
1826 }
while (current !=
nullptr);
1828 Debug(misc, 0,
"[Ap] cannot move further on Airport! (pos {} state {}) for vehicle {}", v->pos, v->state, v->index);
1841 uint64 airport_flags = next->
block;
1844 if (current_pos != reference && current_pos->
block != NOTHING_block) {
1845 airport_flags |= current_pos->
block;
1871 uint64 airport_flags = next->
block;
1875 if (current == reference) current = current->
next;
1876 while (current !=
nullptr) {
1878 airport_flags |= current->
block;
1881 current = current->
next;
1895 if (next->
block != NOTHING_block) {
1937 for (; i < last_terminal; i++) {
1984 while (temp !=
nullptr) {
1994 uint group_start = 0;
1995 for (uint i = 1; i < target_group; i++) {
1999 uint group_end = group_start + apc->
terminals[target_group];
2000 if (
FreeTerminal(v, group_start, group_end))
return true;
2060 static bool AircraftEventHandler(
Aircraft *v,
int loop)
2110 for (uint i = 0; i != 2; i++) {
2112 if (!AircraftEventHandler(
this, i))
return false;
2130 if (st ==
nullptr)
return nullptr;
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ 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...
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.
byte heading
heading (current orders), guiding an airplane to its target on an airport
@ HELILANDING
Helicopter wants to land.
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event)
Checks whether a NewGRF wants to play a different vehicle sound effect.
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.
uint32 TileIndex
The index/ID of a Tile.
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.
GoodsEntry goods[NUM_CARGO]
Goods at this station.
@ DIRDIFF_REVERSE
One direction is the opposite of the other one.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
bool IsType(OrderType type) const
Check whether this order is of the given type.
static Titem * Get(size_t index)
Returns Titem with given index.
@ SND_18_TAKEOFF_HELICOPTER
22 == 0x16 Takeoff: helicopter
Direction
Defines the 8 directions on the map.
@ 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.
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.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
@ NT_ARRIVAL_OTHER
First vehicle arrived for competitor.
@ DIRDIFF_45LEFT
Angle of 45 degrees left.
static Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
byte subtype
Type of aircraft.
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.
static const uint64 HELIPAD3_block
Block belonging to helipad 3.
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.
uint16 reliability_spd_dec
Speed of reliability decay between services (per day).
Class to backup a specific variable and restore it later.
@ AMED_LAND
Landing onto landing strip.
Vehicle * Next() const
Get the next vehicle of this vehicle.
Year _cur_year
Current year, starting at 0.
@ HELIENDLANDING
Helicopter wants to finish landing.
T * Next() const
Get next vehicle in the chain.
@ DIRDIFF_SAME
Both directions faces to the same direction.
byte y_extent
y-extent of vehicle bounding box
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.
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
@ PLANE_HOLD_MAX_FLYING_ALTITUDE
holding flying altitude above tile of planes.
@ VSE_TOUCHDOWN
Whenever a plane touches down.
static void HandleAircraftSmoke(Aircraft *v, bool mode)
Handle smoke of broken aircraft.
byte random_bits
Bits used for determining which randomized variational spritegroups to use when drawing.
std::string name
Name of vehicle.
static const uint64 TERM5_block
Block belonging to terminal 5.
uint16 passenger_capacity
Passenger capacity (persons).
uint64 airport_flag
Bitmask in the airport flags that need to be free for this terminal.
@ VS_DEFPAL
Use default vehicle palette.
Tindex index
Index of this pool item.
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
@ CMD_SEND_VEHICLE_TO_DEPOT
send a vehicle to a depot
virtual uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
@ SHORT_STRIP
This airport has a short landing strip, dangerous for fast aircraft.
byte acceleration
used by train & 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.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
@ TERM1
Heading for terminal 1.
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
void AircraftStateHandler(Aircraft *v, const AirportFTAClass *apc)
Signature of the aircraft handler function.
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
@ VAF_IN_MAX_HEIGHT_CORRECTION
The vehicle is currently lowering its altitude because it hit the upper bound.
const byte num_helipads
Number of helipads on this airport. When 0 helicopters will go to normal terminals.
@ EXPENSES_AIRCRAFT_RUN
Running costs aircraft.
byte number_consecutive_turns
Protection to prevent the aircraft of making a lot of turns in order to reach a specific point.
@ ENDLANDING
Airplane wants to finish landing.
void HandleAircraftEnterHangar(Aircraft *v)
Handle Aircraft specific tasks when an Aircraft enters a hangar.
static const uint TILE_SIZE
Tile size in world coordinates.
static void AddVehicleNewsItem(StringID string, NewsType type, VehicleID vehicle, StationID station=INVALID_STATION)
Adds a newsitem referencing a vehicle.
byte running_ticks
Number of ticks this vehicle was not stopped this day.
static Station * Get(size_t index)
Gets station with given index.
@ DEPOT_LOCATE_HANGAR
Find another airport if the target one lacks a hangar.
static DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
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,...
static uint TileY(TileIndex tile)
Get the Y component of a tile.
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).
Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
@ EV_EXPLOSION_SMALL
Various explosions.
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.
uint16 cur_speed
current speed
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?
uint16 cached_cargo_age_period
Number of ticks before carried cargo is aged.
@ EV_EXPLOSION_LARGE
Various explosions.
@ DC_EXEC
execute the given command
Owner owner
The owner of this station.
@ AIR_AIRCRAFT
an airplane
static const uint64 HELIPAD2_block
Block belonging to helipad 2.
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
@ 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.
byte breakdowns_since_last_service
Counter for the amount of breakdowns.
@ AIR_SHADOW
shadow of the aircraft
#define SETBITS(x, y)
Sets several bits in a variable.
const AirportFTAClass * GetAirport(const byte airport_type)
Get the finite state machine of an airport type.
@ TERM7
Heading for terminal 7.
static uint TileX(TileIndex tile)
Get the X component of a tile.
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.
void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type=ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action=ODATF_SERVICE_ONLY, CargoID cargo=CT_NO_REFIT)
Makes this order a Go To Depot order.
OrderType GetType() const
Get the type of order of this order.
Aircraft, helicopters, rotors and their shadows belong to this class.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
StationCargoList cargo
The cargo packets of cargo waiting in this station.
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
@ ENGINE_EXCLUSIVE_PREVIEW
This vehicle is in the exclusive preview stage, either being used or being offered to a company.
OrderSettings order
settings related to orders
uint8 plane_crashes
number of plane crashes, 0 = none, 1 = reduced, 2 = normal
bool HasHangar() const
Check if this airport has at least one hangar.
void BeginLoading()
Prepare everything to begin the loading when arriving at a station.
static DiagDirDiff DiagDirDifference(DiagDirection d0, DiagDirection d1)
Calculate the difference between two DiagDirection values.
Direction rotation
How this airport is rotated.
byte breakdown_ctr
Counter for managing breakdown events.
@ VS_HIDDEN
Vehicle is not visible.
uint16 EngineID
Unique identification number of an engine.
@ SND_17_SKID_PLANE
21 == 0x15 Plane landing / touching ground
@ 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 DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
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.
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Money GetRunningCost() const
Gets the running cost of a vehicle.
Common return value for all commands.
@ VAF_HELI_DIRECT_DESCENT
The helicopter is descending directly at its destination (helipad or in front of hangar)
Date _date
Current date in days (day counter)
@ 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:
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
SoundSettings sound
sound effect settings
uint16 flag
special flags when moving towards the destination.
static DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta)
Applies a difference on a DiagDirection.
byte turn_counter
Ticks between each turn to prevent > 45 degree turns.
byte nofelements
number of positions the airport consists of
@ 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.
static byte 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.
@ EIT_ON_MAP
Vehicle drawn in viewport.
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.
CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret)
Build an aircraft.
StationID last_station_visited
The last station we stopped at.
uint16 w
The width of the area.
@ 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
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.
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
Internal structure used in openttd - Finite sTate mAchine --> FTA.
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.
TileIndex new_tile
Tile of the vehicle after moving.
uint16 reliability_spd_dec
Reliability decrease speed.
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded.
uint64 flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
Money GetCost() const
The costs as made up to this moment.
uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
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)
byte rating
Station rating for this cargo.
Finite sTate mAchine (FTA) of an airport.
bool disaster
Play disaster and accident sounds.
byte GetVehiclePosOnBuild(TileIndex hangar_tile)
Get the vehicle position when an aircraft is build at the given tile.
@ HVOT_AIRCRAFT
Station has seen an aircraft.
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
Enumeration for the difference between two directions.
DiagDirection
Enumeration for diagonal directions.
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.
static const uint64 TERM7_block
Block belonging to terminal 7.
@ TERM5
Heading for terminal 5.
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
bool value
tells if the bool cheat is active or not
@ 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.
int8 y_offs
y offset for vehicle sprite
SpriteID colourmap
NOSAVE: cached colour mapping.
void AircraftLeaveHangar(Aircraft *v, Direction exit_dir)
Aircraft is about to leave the hangar.
static const uint64 TERM1_block
Movement Blocks on Airports blocks (eg_airport_flags).
Disasters, like submarines, skyrangers and their shadows, belong to this class.
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
@ VF_BUILT_AS_PROTOTYPE
Vehicle is a prototype (accepted as exclusive preview).
Direction direction
facing
uint16 h
The height of the area.
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.
byte delta_z
Z adjustment for helicopter pads.
TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
int16 x
x-coordinate of the destination.
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.
static const uint64 AIRPORT_CLOSED_block
Dummy block for indicating a closed airport.
byte x_extent
x-extent of vehicle bounding box
static bool HandleCrashedAircraft(Aircraft *v)
Handle crashed aircraft v.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
VehicleCache vcache
Cache of often used vehicle values.
CompanyID _current_company
Company currently doing an action.
@ DEPOT_SERVICE
The vehicle will leave the depot right after arrival (service only)
uint32 cached_max_range_sqr
Cached squared maximum range.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
AirportFTA * next
possible extra movement choices from this position
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Titem value
Value of current item.
AirportMovementStates
Movement States on Airports (headings target)
byte tick_counter
Increased by one for each tick.
uint16 cargo_cap
total capacity
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
@ HELICOPTER_HOLD_MAX_FLYING_ALTITUDE
holding flying altitude above tile of helicopters.
int8 x_offs
x offset for vehicle sprite
byte subspeed
fractional speed
static Aircraft * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
@ DIRDIFF_45RIGHT
Angle of 45 degrees right.
uint16 crashed_counter
Timer for handling crash animations.
byte z_extent
z-extent of vehicle bounding box
byte VehicleRandomBits()
Get a value for a vehicle's random_bits.
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
TileIndex tile
The base tile of the area.
uint32 PaletteID
The number of the palette.
void OnNewDay()
Calls the new day handler of the vehicle.
@ 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.
uint32 current_order_time
How many ticks have passed since this order started.
static void AircraftEntersTerminal(Aircraft *v)
Aircraft arrives at a terminal.
static bool FreeTerminal(Aircraft *v, byte i, byte last_terminal)
Find a free terminal or helipad, and if available, assign it.
@ OWNER_NONE
The tile has no ownership.
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:
@ NUM_CARGO
Maximal number of cargo types in a game.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
Year build_year
Year the vehicle has been built.
byte previous_pos
Previous desired position of the aircraft.
static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *apc)
At one of the Airport's Terminals.
@ HELIPAD1
Heading for helipad 1.
void UpdateAirplanesOnNewStation(const Station *st)
Updates the status of the Aircraft heading or in the station.
@ NT_ACCIDENT
An accident or disaster has occurred.
int16 y
y-coordinate of the destination.
@ HELITAKEOFF
Helicopter wants to leave the airport.
static const int DAYS_IN_YEAR
days per year
void AircraftNextAirportPos_and_Order(Aircraft *v)
set the right pos when heading to other airports after takeoff
@ SPEED_LIMIT_NONE
No environmental speed limit. Speed limit is type dependent.
TileIndex xy
Base tile of the station.
static int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
uint16 cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
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.
byte mail_capacity
Mail capacity (bags).
static Pool::IterateWrapper< Aircraft > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
@ NT_ARRIVAL_COMPANY
First vehicle arrived for company.
uint8 original_image_index
Original vehicle image index, thus the image index of the overridden vehicle.
TileIndex old_tile
Current tile of the vehicle.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
uint64 block
64 bit blocks (st->airport.flags), should be enough for the most complex airports
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
OrderDepotTypeFlags GetDepotOrderType() const
What caused us going to the depot?
byte pos
Next desired position of the aircraft.
static void AddVehicleAdviceNewsItem(StringID string, VehicleID vehicle)
Adds a vehicle-advice news item.
@ AIR_CTOL
Conventional Take Off and Landing, i.e. planes.
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
byte day_counter
Increased by one for each day.
@ VS_UNCLICKABLE
Vehicle is not clickable by the user (shadow vehicles).
@ TERMGROUP
Aircraft is looking for a free terminal in a terminalgroup.
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
@ TO_ALL
Go in this direction for every target.
static bool AircraftController(Aircraft *v)
Controls the movement of an aircraft.
#define lengthof(x)
Return the length of an fixed size array.
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.
byte progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
const byte * terminals
Array with the number of terminal groups, followed by the number of terminals in each group.
@ 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_LVL_BASE.
uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity=nullptr) const
Determines capacity of a given vehicle from scratch.
static const uint64 TERM8_block
Block belonging to terminal 8.
byte type
Type of this airport,.
byte CargoID
Cargo slots to indicate a cargo type within a game.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
static bool Chance16R(const uint a, const uint b, uint32 &r)
Flips a coin with a given probability and saves the randomize-number in a variable.
CargoID cargo_type
type of cargo this vehicle is carrying
uint8 plane_speed
divisor for speed of aircraft
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
@ AMED_HELI_RAISE
Helicopter take-off.
uint16 cached_max_range
Cached maximum range.
@ LANDING
Airplane wants to land.
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
byte state
State of the airport.
static const uint64 TERM4_block
Block belonging to terminal 4.
byte position
the position that an airplane is at
@ TERM6
Heading for terminal 6.
VehicleSettings vehicle
options for vehicles
VehicleType type
Type of vehicle.
const byte * entry_points
when an airplane arrives at this airport, enter it at position entry_point, index depends on directio...
void UpdatePositionAndViewport()
Update the position of the vehicle, and update the viewport.
@ FACIL_AIRPORT
Station with an airport.
uint16 reliability
Reliability.
@ 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.
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...
byte flags
Flags of the engine.
static bool AirportFindFreeTerminal(Aircraft *v, const AirportFTAClass *apc)
Find a free terminal, and assign it if available.
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
bool Tick()
Calls the tick handler of the vehicle.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
@ TAKEOFF
Airplane wants to leave the airport.
Specification of a rectangle with absolute coordinates of all edges.
@ AIRPLANES
Can planes land on this airport type?
@ SPEED_LIMIT_BROKEN
Maximum speed of an aircraft that is broken.
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 UpdateDeltaXY()
Updates the x and y offsets and the size of the sprite used for this vehicle.
#define CLRBITS(x, y)
Clears several bits in a variable.
@ PROP_AIRCRAFT_RANGE
Aircraft range.
const AirportMovingData * MovingData(byte position) const
Get movement data at a position.
@ HELIPAD2
Heading for helipad 2.
static const uint64 HELIPAD1_block
Block belonging to helipad 1.
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
static const uint64 TERM3_block
Block belonging to terminal 3.
@ VS_SHADOW
Vehicle is a shadow vehicle.
byte next_position
next position from this position
byte flags
Aircraft flags.
static const uint64 TERM2_block
Block belonging to terminal 2.
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 const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
static const uint64 TERM6_block
Block belonging to terminal 6.
@ FLYING
Vehicle is flying in the air.
@ AMED_HELI_LOWER
Helicopter landing.
@ AIRCRAFT_MIN_FLYING_ALTITUDE
Minimum flying altitude above tile.
static AircraftStateHandler *const _aircraft_state_handlers[]
Array of handler functions for each target of the aircraft.
@ AT_OILRIG
Oilrig airport.
uint16 reliability
Current reliability of the engine.
uint16 refit_cap
Capacity left over from before last refit.
Date date_of_last_service
Last date the vehicle had a service at a depot.
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.
@ AMED_BRAKE
Taxiing at the airport.
@ TERM4
Heading for terminal 4.
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
@ 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.