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);
124 StationID
index = INVALID_STATION;
128 FOR_ALL_STATIONS(st) {
147 if (distance < best || index == INVALID_STATION) {
159 if (is_custom_sprite(spritenum)) {
160 GetCustomVehicleSprite(
this, direction, image_type, result);
166 assert(IsValidImageIndex<VEH_AIRCRAFT>(spritenum));
167 result->
Set(direction + _aircraft_sprite[spritenum]);
176 GetCustomRotorSprite(v,
false, image_type, result);
181 result->
Set(SPR_ROTOR_STOPPED + w->
state);
189 if (is_custom_sprite(spritenum)) {
190 GetCustomVehicleIcon(engine,
DIR_W, image_type, result);
196 assert(IsValidImageIndex<VEH_AIRCRAFT>(spritenum));
197 result->
Set(
DIR_W + _aircraft_sprite[spritenum]);
203 GetAircraftIcon(engine, image_type, &seq);
207 preferred_x =
Clamp(preferred_x,
215 GetCustomRotorIcon(engine, image_type, &rotor_seq);
216 if (!rotor_seq.
IsValid()) rotor_seq.
Set(SPR_ROTOR_STOPPED);
233 GetAircraftIcon(engine, image_type, &seq);
238 width =
UnScaleGUI(rect.right - rect.left + 1);
239 height =
UnScaleGUI(rect.bottom - rect.top + 1);
281 u->
z_pos = GetSlopePixelZ(x, y);
315 _new_vehicle_id = v->
index;
365 w->
state = HRS_ROTOR_STOPPED;
385 if (station == INVALID_STATION)
return false;
390 if (location != NULL) *location = st->
xy;
391 if (destination != NULL) *destination = st->
index;
396 static void CheckIfAircraftNeedsService(
Aircraft *v)
437 CheckVehicleBreakdown(
this);
439 CheckIfAircraftNeedsService(
this);
454 static void HelicopterTickHandler(
Aircraft *v)
483 u->
state = HRS_ROTOR_STOPPED;
486 }
else if (tick >= spd) {
489 if (u->
state > HRS_ROTOR_MOVING_3) u->
state = HRS_ROTOR_MOVING_1;
524 u->y_pos = y - ((v->
z_pos - GetSlopePixelZ(safe_x, safe_y)) >> 3);
527 u->z_pos = GetSlopePixelZ(safe_x, safe_y);
528 u->sprite_seq.CopyWithoutPalette(v->
sprite_seq);
530 u->UpdatePositionAndViewport();
538 u->UpdatePositionAndViewport();
562 static void PlayAircraftSound(
const Vehicle *v)
565 SndPlayVehicleFx(AircraftVehInfo(v->
engine_type)->sfx, v);
579 if (max_speed != 0) {
581 max_speed = (max_speed * 128) / 10;
638 if (v->
cur_speed < speed_limit) hard_limit =
false;
650 if (!hard_limit && v->
cur_speed > speed_limit) {
743 int GetAircraftFlightLevel(T *v,
bool takeoff)
747 int aircraft_min_altitude;
748 int aircraft_max_altitude;
750 int aircraft_middle_altitude = (aircraft_min_altitude + aircraft_max_altitude) / 2;
753 assert(aircraft_min_altitude < aircraft_middle_altitude);
754 assert(aircraft_middle_altitude < aircraft_max_altitude);
757 if (z < aircraft_min_altitude ||
763 z += takeoff ? 2 : 1;
764 }
else if (!takeoff && (z > aircraft_max_altitude ||
817 if (
abs(delta_y) <
abs(delta_x)) {
847 uint size_x = 1, size_y = 1;
892 SndPlayVehicleFx(SND_18_HELICOPTER, v);
905 if (v->
z_pos >= z_dest) {
931 int z = GetSlopePixelZ(x, y) + 1 + afc->
delta_z;
984 bool hard_limit =
true;
992 if (count == 0)
return false;
1002 gp.x = (v->
x_pos != (x + amd.
x)) ?
1005 gp.
y = (v->
y_pos != (y + amd.
y)) ?
1015 Direction newdir = GetDirectionTowards(v, x + amd.
x, y + amd.
y);
1018 if (v->
turn_counter == 0 || newdir == v->last_direction) {
1019 if (newdir == v->last_direction) {
1059 z = GetAircraftFlightLevel(v,
true);
1064 z = GetAircraftFlightLevel(v);
1078 int curz = GetSlopePixelZ(x + amd.
x, y + amd.
y) + 1;
1082 int t =
max(1U, dist - 4);
1083 int delta = z - curz;
1089 if (z < curz) z = curz;
1094 int curz = GetSlopePixelZ(x, y) + 1;
1098 }
else if (z < curz) {
1105 }
while (--count != 0);
1123 if (v->
z_pos == z) {
1132 static const DirDiff delta[] = {
1173 static const struct {
1207 void HandleMissingAircraftOrders(
Aircraft *v)
1274 uint pass = v->
Crash();
1282 newsitem = STR_NEWS_PLANE_CRASH_OUT_OF_FUEL;
1285 newsitem = STR_NEWS_AIRCRAFT_CRASH;
1288 AI::NewEvent(v->
owner,
new ScriptEventVehicleCrashed(v->
index, v->
tile, st == NULL ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
1289 Game::NewEvent(
new ScriptEventVehicleCrashed(v->
index, v->
tile, st == NULL ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
1293 ModifyStationRatingAround(v->
tile, v->
owner, -160, 30);
1310 (AircraftVehInfo(v->
engine_type)->subtype & AIR_FAST) &&
1317 if (
GB(Random(), 0, 22) > prob)
return;
1346 STR_NEWS_FIRST_AIRCRAFT_ARRIVAL,
1367 SndPlayVehicleFx(SND_17_SKID_PLANE, v);
1485 AirportMove(v, apc);
1493 AircraftEventHandler_EnterTerminal(v, apc);
1516 bool go_to_hangar =
false;
1518 case OT_GOTO_STATION:
1523 case OT_CONDITIONAL:
1539 AirportMove(v, apc);
1544 error(
"OK, you shouldn't be here, check your Airport Scheme!");
1549 PlayAircraftSound(v);
1593 while (current != NULL) {
1594 if (current->
heading == landingtype) {
1601 v->
state = landingtype;
1612 current = current->
next;
1680 AircraftEventHandler_General,
1690 AircraftEventHandler_TakeOff,
1691 AircraftEventHandler_StartTakeOff,
1692 AircraftEventHandler_EndTakeOff,
1693 AircraftEventHandler_HeliTakeOff,
1694 AircraftEventHandler_Flying,
1695 AircraftEventHandler_Landing,
1696 AircraftEventHandler_EndLanding,
1697 AircraftEventHandler_HeliLanding,
1698 AircraftEventHandler_HeliEndLanding,
1714 static void AirportGoToNextPosition(
Aircraft *v)
1721 AirportClearBlock(v, apc);
1722 AirportMove(v, apc);
1730 DEBUG(misc, 0,
"[Ap] position %d is not valid for current airport. Max position is %d", v->
pos, apc->
nofelements-1);
1737 byte prev_pos = v->
pos;
1738 byte prev_state = v->
state;
1740 if (v->state !=
FLYING) v->previous_pos = prev_pos;
1748 if (current->
next == NULL) {
1766 current = current->
next;
1767 }
while (current != NULL);
1769 DEBUG(misc, 0,
"[Ap] cannot move further on Airport! (pos %d state %d) for vehicle %d", v->
pos, v->
state, v->
index);
1782 uint64 airport_flags = next->
block;
1785 if (current_pos != reference && current_pos->
block != NOTHING_block) {
1786 airport_flags |= current_pos->
block;
1812 uint64 airport_flags = next->
block;
1816 if (current == reference) current = current->
next;
1817 while (current != NULL) {
1819 airport_flags |= current->
block;
1822 current = current->
next;
1836 if (next->
block != NOTHING_block) {
1876 assert(last_terminal <=
lengthof(_airport_terminal_mapping));
1878 for (; i < last_terminal; i++) {
1881 v->
state = _airport_terminal_mapping[i].
state;
1925 while (temp != NULL) {
1935 uint group_start = 0;
1936 for (uint i = 1; i < target_group; i++) {
1940 uint group_end = group_start + apc->
terminals[target_group];
1941 if (
FreeTerminal(v, group_start, group_end))
return true;
2001 static bool AircraftEventHandler(
Aircraft *v,
int loop)
2049 for (uint i = 0; i != 2; i++) {
2051 if (!AircraftEventHandler(
this, i))
return false;
2069 if (st == NULL)
return NULL;
Flag for an invalid direction.
Functions related to OTTD's strings.
byte number_consecutive_turns
Protection to prevent the aircraft of making a lot of turns in order to reach a specific point...
VehicleSettings vehicle
options for vehicles
This vehicle is in the exclusive preview stage, either being used or being offered to a company...
uint16 reliability
Current reliability of the engine.
byte type
Type of this airport,.
uint32 PaletteID
The number of the palette.
Vehicle is stopped by the player.
First vehicle arrived for competitor.
Airplane wants to leave the airport.
This airport has a short landing strip, dangerous for fast aircraft.
void AircraftLeaveHangar(Aircraft *v, Direction exit_dir)
Aircraft is about to leave the hangar.
byte GetVehiclePosOnBuild(TileIndex hangar_tile)
Get the vehicle position when an aircraft is build at the given tile.
VehicleCargoList cargo
The cargo this vehicle is carrying.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Definition of stuff that is very close to a company, like the company struct itself.
Functions for NewGRF engines.
Airplane has reached end-point of the take-off runway.
CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret)
Build an aircraft.
void DecreaseVehicleValue(Vehicle *v)
Decrease the value of a vehicle.
static const int DAYS_IN_YEAR
days per year
Finite sTate mAchine (FTA) of an airport.
void AircraftNextAirportPos_and_Order(Aircraft *v)
set the right pos when heading to other airports after takeoff
byte nofelements
number of positions the airport consists of
StationID targetairport
Airport to go to next.
static bool HandleCrashedAircraft(Aircraft *v)
Handle crashed aircraft v.
Station * GetTargetAirportIfValid(const Aircraft *v)
Returns aircraft's target station if v->target_airport is a valid station with airport.
const AirportFTAClass * GetAirport(const byte airport_type)
Get the finite state machine of an airport type.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
byte next_position
next position from this position
Direction GetHangarExitDirection(TileIndex tile) const
Get the exit direction of the hangar at a specific tile.
DirectionByte direction
facing
Maximum speed of an aircraft that is broken.
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
static const uint64 HELIPAD1_block
Block belonging to helipad 1.
Minimum flying altitude above tile.
void CheckOrders(const Vehicle *v)
Check the orders of a vehicle, to see if there are invalid orders and stuff.
A single location on an airport where aircraft can move to.
bool HasHangar() const
Check if this airport has at least one hangar.
bool serviceathelipad
service helicopters at helipads automatically (no need to send to depot)
static Titem * Get(size_t index)
Returns Titem with given index.
bool Tick()
Calls the tick handler of the vehicle.
static const uint64 TERM6_block
Block belonging to terminal 6.
Functions related to dates.
Angle of 45 degrees left.
virtual uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
Conventional Take Off and Landing, i.e. planes.
const AirportFTAClass * GetFTA() const
Get the finite-state machine for this airport or the finite-state machine for the dummy airport in ca...
Use default vehicle palette.
Vehicle is a shadow vehicle.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Vehicle drawn in viewport.
byte pos
Next desired position of the aircraft.
uint16 cur_speed
current speed
uint16 cached_cargo_age_period
Number of ticks before carried cargo is aged.
const byte * entry_points
when an airplane arrives at this airport, enter it at position entry_point, index depends on directio...
uint Truncate(uint max_move=UINT_MAX)
Truncates the cargo in this list to the given amount.
static void AddVehicleAdviceNewsItem(StringID string, VehicleID vehicle)
Adds a vehicle-advice news item.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Depot view; Window numbers:
static const int ROTOR_Z_OFFSET
Z Offset between helicopter- and rotorsprite.
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Both directions faces to the same direction.
void UpdateAircraftCache(Aircraft *v, bool update_range)
Update cached values of an aircraft.
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...
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded...
#define SETBITS(x, y)
Sets several bits in a variable.
Station has seen an aircraft.
Functions related to vehicles.
Aircraft, helicopters, rotors and their shadows belong to this class.
uint32 current_order_time
How many ticks have passed since this order started.
void SetAircraftPosition(Aircraft *v, int x, int y, int z)
Set aircraft position.
static uint TileX(TileIndex tile)
Get the X component of a tile.
void VehicleEnterDepot(Vehicle *v)
Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it...
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
static bool AircraftController(Aircraft *v)
Controls the movement of an aircraft.
Flags flags
Flags for this airport type.
int16 y
y-coordinate of the destination.
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Tindex index
Index of this pool item.
Vehicle is flying in the air.
The vehicle is currently raising its altitude because it hit the lower bound.
Northeast, upper right on your monitor.
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
static void AircraftEventHandler_InHangar(Aircraft *v, const AirportFTAClass *apc)
Handle aircraft movement/decision making in an airport hangar.
StationID last_station_visited
The last station we stopped at.
static void AircraftEntersTerminal(Aircraft *v)
Aircraft arrives at a terminal.
uint16 reliability_spd_dec
Reliability decrease speed.
Money GetCost() const
The costs as made up to this moment.
AircraftSpeedLimits
Special velocities for aircraft.
int GetTileHeightBelowAircraft(const Vehicle *v)
Get the tile height below the aircraft.
#define CLRBITS(x, y)
Clears several bits in a variable.
static const uint64 HELIPAD3_block
Block belonging to helipad 3.
Common return value for all commands.
holding flying altitude above tile of planes.
StationCargoList cargo
The cargo packets of cargo waiting in this station.
static T max(const T a, const T b)
Returns the maximum of two values.
EngineImageType
Visualisation contexts of vehicles and engines.
byte flags
Flags of the engine.
uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
Year _cur_year
Current year, starting at 0.
Helicopter wants to land.
uint16 w
The width of the area.
static Aircraft * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
static DiagDirDiff DiagDirDifference(DiagDirection d0, DiagDirection d1)
Calculate the difference between two DiagDirection values.
uint16 cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
bool NeedsAutomaticServicing() const
Checks if the current order should be interrupted for a service-in-depot order.
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
bool IsNormalAircraft() const
Check if the aircraft type is a normal flying device; eg not a rotor or a shadow. ...
GoodsEntry goods[NUM_CARGO]
Goods at this station.
static const uint TILE_SIZE
Tile size in world coordinates.
byte VehicleRandomBits()
Get a value for a vehicle's random_bits.
Go exactly to the destination coordinates.
Find another airport if the target one lacks a hangar.
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
void UpdateDeltaXY(Direction direction)
Updates the x and y offsets and the size of the sprite used for this vehicle.
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Direction
Defines the 8 directions on the map.
Class to backup a specific variable and restore it later.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Holding pattern movement (above the airport).
Cheat no_jetcrash
no jet will crash on small airports anymore
Pseudo random number generator.
static const uint64 HELIPAD2_block
Block belonging to helipad 2.
Angle of 45 degrees right.
byte breakdown_ctr
Counter for managing breakdown events.
byte subtype
subtype (Filled with values from #EffectVehicles/#TrainSubTypes/#AircraftSubTypes) ...
static bool FreeTerminal(Aircraft *v, byte i, byte last_terminal)
Find a free terminal or helipad, and if available, assign it.
uint16 cargo_cap
total capacity
holding flying altitude above tile of helicopters.
Vehicle is a prototype (accepted as exclusive preview).
Turn slowly (mostly used in the air).
byte acceleration
used by train & aircraft
byte rating
Station rating for this cargo.
uint16 reliability_spd_dec
Speed of reliability decay between services (per day).
static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *apc)
At one of the Airport's Terminals.
Combination of aircraft state for going to a certain terminal and the airport flag for that terminal ...
Types related to cheating.
void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cst)
Subtract money from a company, including the money fraction.
static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc)
"reserve" a block for the plane
int y
x and y position of the vehicle after moving
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
byte subtype
Type of aircraft.
void AgeVehicle(Vehicle *v)
Update age of a vehicle.
bool IsValid() const
Check whether the sequence contains any sprites.
void DeleteVehicleNews(VehicleID vid, StringID news)
Delete a news item type about a vehicle.
SoundSettings sound
sound effect settings
Internal structure used in openttd - Finite sTate mAchine –> FTA.
void MakeDummy()
Makes this order a Dummy order.
int8 y_offs
y offset for vehicle sprite
bool IsType(OrderType type) const
Check whether this order is of the given type.
DoCommandFlag
List of flags for a command.
T * Next() const
Get next vehicle in the chain.
ClientSettings _settings_client
The current settings for this game.
Definition of base types and functions in a cross-platform compatible way.
const byte num_helipads
Number of helipads on this airport. When 0 helicopters will go to normal terminals.
A number of safeguards to prevent using unsafe methods.
byte x_extent
x-extent of vehicle bounding box
bool value
tells if the bool cheat is active or not
static const uint64 AIRPORT_CLOSED_block
Dummy block for indicating a closed airport.
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle) ...
bool ProcessOrders(Vehicle *v)
Handle the orders of a vehicle and determine the next place to go to if needed.
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).
DirDiff
Enumeration for the difference between two directions.
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
static void CrashAirplane(Aircraft *v)
Bring the aircraft in a crashed state, create the explosion animation, and create a news item about t...
struct AirportFTA * layout
state machine for airport
byte z_extent
z-extent of vehicle bounding box
Vehicle starting, i.e. leaving, the station.
CargoID cargo_type
type of cargo this vehicle is carrying
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Vehicle view; Window numbers:
The vehicle is currently lowering its altitude because it hit the upper bound.
static DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta)
Applies a difference on a DiagDirection.
TileIndex tile
Current tile index.
The tile has no ownership.
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...
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
static DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
static Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
int8 x_offs
x offset for vehicle sprite
StationFacilityByte facilities
The facilities that this station has.
Sprite sequence for a vehicle part.
uint64 flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
DiagDirection
Enumeration for diagonal directions.
Airplane has arrived at a runway for take-off.
#define lengthof(x)
Return the length of an fixed size array.
const AirportMovingData * MovingData(byte position) const
Get movement data at a position.
static T min(const T a, const T b)
Returns the minimum of two values.
byte previous_pos
Previous desired position of the aircraft.
static void HandleAircraftSmoke(Aircraft *v, bool mode)
Handle smoke of broken aircraft.
uint8 plane_speed
divisor for speed of aircraft
uint16 refit_cap
Capacity left over from before last refit.
byte random_bits
Bits used for determining which randomized variational spritegroups to use when drawing.
Functions related to sound.
byte breakdowns_since_last_service
Counter for the amount of breakdowns.
uint16 reliability
Reliability.
Functions to cache sprites in memory.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
bool Failed() const
Did this command fail?
byte tick_counter
Increased by one for each tick.
EffectVehicle * CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular vehicle.
static void AircraftLandAirplane(Aircraft *v)
Aircraft touched down at the landing strip.
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.
TileIndex GetHangarTile(uint hangar_num) const
Get the first tile of the given hangar.
AirportMovementStates
Movement States on Airports (headings target)
DirectionByte rotation
How this airport is rotated.
uint8 plane_crashes
number of plane crashes, 0 = none, 1 = reduced, 2 = normal
Year build_year
Year the vehicle has been built.
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event)
Checks whether a NewGRF wants to play a different vehicle sound effect.
byte state
State of the airport.
uint Truncate(uint max_move=UINT_MAX, StationCargoAmountMap *cargo_per_source=NULL)
Truncates where each destination loses roughly the same percentage of its cargo.
byte turn_counter
Ticks between each turn to prevent > 45 degree turns.
uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity=NULL) const
Determines capacity of a given vehicle from scratch.
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
#define DEBUG(name, level,...)
Output a line of debugging information.
Maximal number of cargo types in a game.
TileIndex old_tile
Current tile of the vehicle.
TileIndex tile
The base tile of the area.
OwnerByte owner
The owner of this station.
static void AircraftEventHandler_EnterHangar(Aircraft *v, const AirportFTAClass *apc)
Aircraft arrived in an airport hangar.
Maximum speed of an aircraft while taxiing.
Maximum speed of an aircraft on finals.
int GetAircraftHoldMaxAltitude(const Aircraft *v)
Gets the maximum 'flight level' for the holding pattern of the aircraft, in pixels 'z_pos' 0...
static const uint MAX_TERMINALS
Some airport-related constants.
TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
char * name
Name of vehicle.
execute the given command
static AircraftStateHandler *const _aircraft_state_handlers[]
Array of handler functions for each target of the aircraft.
The vehicle will leave the depot right after arrival (serivce only)
uint GetHangarNum(TileIndex tile) const
Get the hangar number of the hangar at a specific tile.
Functions related to companies.
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
Get position information of a vehicle when moving one pixel in the direction it is facing...
void UpdatePosition()
Update the position of the vehicle.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
void HandleAircraftEnterHangar(Aircraft *v)
Handle Aircraft specific tasks when an Aircraft enters a hangar.
Maximum flying altitude above tile.
Go in this direction for every target.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
uint16 cached_max_range
Cached maximum range.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
DestinationID GetDestination() const
Gets the destination of this order.
void VehicleServiceInDepot(Vehicle *v)
Service a vehicle and all subsequent vehicles in the consist.
static bool AirportFindFreeHelipad(Aircraft *v, const AirportFTAClass *apc)
Find a free helipad, and assign it if available.
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
byte subspeed
fractional speed
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.
bool HandleBreakdown()
Handle all of the aspects of a vehicle breakdown This includes adding smoke and sounds, and ending the breakdown when appropriate.
static const uint64 TERM7_block
Block belonging to terminal 7.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
No environmental speed limit. Speed limit is type dependent.
uint16 EngineID
Unique identification number of an engine.
CompanyByte _current_company
Company currently doing an action.
uint32 TileIndex
The index/ID of a Tile.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
void BeginLoading()
Prepare everything to begin the loading when arriving at a station.
Vehicle * Next() const
Get the next vehicle of this vehicle.
Number of ticks before carried cargo is aged.
Date date_of_last_service
Last date the vehicle had a service at a depot.
void AircraftStateHandler(Aircraft *v, const AirportFTAClass *apc)
Signature of the aircraft handler function.
Maximum speed of an aircraft that flies the holding pattern.
Information about a aircraft vehicle.
Position information of a vehicle after it moved.
OrderSettings order
settings related to orders
First vehicle arrived for company.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static const uint64 TERM1_block
Movement Blocks on Airports blocks (eg_airport_flags).
Next destination is too far away.
uint64 block
64 bit blocks (st->airport.flags), should be enough for the most complex airports ...
void Free()
'Free' the order
Disasters, like submarines, skyrangers and their shadows, belong to this class.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
OwnerByte owner
Which company owns the vehicle?
static T abs(const T a)
Returns the absolute value of (scalar) variable.
TileIndex xy
Base tile of the station.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
uint32 cached_max_range_sqr
Cached squared maximum range.
Functions related to zooming.
static const uint64 TERM8_block
Block belonging to terminal 8.
Vehicle * next
pointer to the next vehicle in the chain
int16 x
x-coordinate of the destination.
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
bool disaster
Play disaster and accident sounds.
AirportFTA * next
possible extra movement choices from this position
Functions related to OTTD's landscape.
Aircraft list; Window numbers:
Vehicle details; Window numbers:
Base functions for all Games.
static const uint64 TERM4_block
Block belonging to terminal 4.
Functions related to commands.
An accident or disaster has occurred.
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
#define FOR_ALL_AIRCRAFT(var)
Macro for iterating over all aircrafts.
static void AircraftHandleDestTooFar(Aircraft *v, bool too_far)
Handle the 'dest too far' flag and the corresponding news message for aircraft.
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Max. speed: 1 unit = 8 mph = 12.8 km-ish/h.
HelicopterRotorStates
Helicopter rotor animation states.
uint8 original_image_index
Original vehicle image index, thus the image index of the overridden vehicle.
Airport airport
Tile area the airport covers.
byte running_ticks
Number of ticks this vehicle was not stopped this day.
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...
byte y_extent
y-extent of vehicle bounding box
EngineID engine_type
The type of engine used for this vehicle.
AirportMovementStates state
Aircraft movement state when going to this terminal.
AirportMovingData RotateAirportMovingData(const AirportMovingData *orig, Direction rotation, uint num_tiles_x, uint num_tiles_y)
Rotate the airport moving data to another rotation.
Landing onto landing strip.
Helicopter wants to finish landing.
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Functions related to NewGRF provided sounds.
void Restore()
Restore the variable.
Base functions for all AIs.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
static bool AirportFindFreeTerminal(Aircraft *v, const AirportFTAClass *apc)
Find a free terminal, and assign it if available.
Whenever a plane touches down.
send a vehicle to a depot
byte progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
uint16 flag
special flags when moving towards the destination.
static const uint64 TERM3_block
Block belonging to terminal 3.
Smoke of broken aircraft.
OrderType GetType() const
Get the type of order of this order.
Specification of a rectangle with absolute coordinates of all edges.
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...
byte CargoID
Cargo slots to indicate a cargo type within a game.
static const uint64 TERM2_block
Block belonging to terminal 2.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
byte heading
heading (current orders), guiding an airplane to its target on an airport
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
DirectionByte direction
Direction to turn the aircraft after reaching the destination.
byte flags
Aircraft flags.
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
Window functions not directly related to making/drawing windows.
byte position
the position that an airplane is at
void OnNewDay()
Calls the new day handler of the vehicle.
One direction is the opposite of the other one.
uint16 crashed_counter
Timer for handling crash animations.
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
static void MaybeCrashAirplane(Aircraft *v)
Decide whether aircraft v should crash.
Functions related to news.
Base classes/functions for stations.
VehicleCache vcache
Cache of often used vehicle values.
static Station * Get(size_t index)
Gets station with given index.
Date _date
Current date in days (day counter)
void UpdateAirplanesOnNewStation(const Station *st)
Updates the status of the Aircraft heading or in the station.
uint64 airport_flag
Bitmask in the airport flags that need to be free for this terminal.
uint16 h
The height of the area.
const byte * terminals
Array with the number of terminal groups, followed by the number of terminals in each group...
static const MovementTerminalMapping _airport_terminal_mapping[]
A list of all valid terminals and their associated blocks.
TileIndex new_tile
Tile of the vehicle after moving.
static bool AirportHasBlock(Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc)
returns true if the road ahead is busy, eg.
This depot order is because of the servicing limit.
VehicleTypeByte type
Type of vehicle.
void HandleLoading(bool mode=false)
Handle the loading of the vehicle; when not it skips through dummy orders and does nothing in all oth...
Airplane wants to finish landing.
static int UpdateAircraftSpeed(Aircraft *v, uint speed_limit=SPEED_LIMIT_NONE, bool hard_limit=true)
Sets the new speed for an aircraft.
Class for backupping variables and making sure they are restored later.
Functions related to effect vehicles.
uint GetOldAdvanceSpeed(uint speed)
Determines the effective direction-specific vehicle movement speed.
static uint GetNumTerminals(const AirportFTAClass *apc)
Get the number of terminals at the airport.
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
byte day_counter
Increased by one for each day.
byte delta_z
Z adjustment for helicopter pads.
Order current_order
The current order (+ status, like: loading)
void UpdatePositionAndViewport()
Update the position of the vehicle, and update the viewport.
uint16 passenger_capacity
Passenger capacity (persons).
Money GetRunningCost() const
Gets the running cost of a vehicle.
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-...
byte mail_capacity
Mail capacity (bags).
Vehicle is not clickable by the user (shadow vehicles).
SpriteID colourmap
NOSAVE: cached colour mapping.
Cheats _cheats
All the cheats.
Aircraft()
We don't want GCC to zero our struct! It already is zeroed and has an index!
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Helicopter wants to leave the airport.
static const uint64 TERM5_block
Block belonging to terminal 5.
static void AddVehicleNewsItem(StringID string, NewsType type, VehicleID vehicle, StationID station=INVALID_STATION)
Adds a newsitem referencing a vehicle.
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.