2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file aircraft.h Base for aircraft. */
|
2007-02-23 01:48:53 +00:00
|
|
|
|
2006-06-09 06:34:28 +00:00
|
|
|
#ifndef AIRCRAFT_H
|
|
|
|
#define AIRCRAFT_H
|
|
|
|
|
2006-06-05 12:43:41 +00:00
|
|
|
#include "station_map.h"
|
2007-12-27 13:35:39 +00:00
|
|
|
#include "vehicle_base.h"
|
2006-06-05 12:43:41 +00:00
|
|
|
|
2014-09-21 06:35:34 +00:00
|
|
|
/**
|
|
|
|
* Base values for flight levels above ground level for 'normal' flight and holding patterns.
|
|
|
|
* Due to speed and direction, the actual flight level may be higher.
|
|
|
|
*/
|
|
|
|
enum AircraftFlyingAltitude {
|
|
|
|
AIRCRAFT_MIN_FLYING_ALTITUDE = 120, ///< Minimum flying altitude above tile.
|
|
|
|
AIRCRAFT_MAX_FLYING_ALTITUDE = 360, ///< Maximum flying altitude above tile.
|
|
|
|
PLANE_HOLD_MAX_FLYING_ALTITUDE = 150, ///< holding flying altitude above tile of planes.
|
|
|
|
HELICOPTER_HOLD_MAX_FLYING_ALTITUDE = 184 ///< holding flying altitude above tile of helicopters.
|
|
|
|
};
|
|
|
|
|
2009-05-22 20:03:26 +00:00
|
|
|
struct Aircraft;
|
|
|
|
|
2010-11-05 16:34:22 +00:00
|
|
|
/** An aircraft can be one of those types. */
|
2007-03-07 12:11:48 +00:00
|
|
|
enum AircraftSubType {
|
2007-04-02 14:20:31 +00:00
|
|
|
AIR_HELICOPTER = 0, ///< an helicopter
|
2007-04-02 15:08:36 +00:00
|
|
|
AIR_AIRCRAFT = 2, ///< an airplane
|
2007-04-02 14:20:31 +00:00
|
|
|
AIR_SHADOW = 4, ///< shadow of the aircraft
|
2011-12-19 17:48:04 +00:00
|
|
|
AIR_ROTOR = 6, ///< rotor of an helicopter
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2007-01-27 12:29:55 +00:00
|
|
|
|
2014-09-21 06:35:34 +00:00
|
|
|
/** Flags for air vehicles; shared with disaster vehicles. */
|
|
|
|
enum AirVehicleFlags {
|
|
|
|
VAF_DEST_TOO_FAR = 0, ///< Next destination is too far away.
|
|
|
|
|
|
|
|
/* The next two flags are to prevent stair climbing of the aircraft. The idea is that the aircraft
|
|
|
|
* will ascend or descend multiple flight levels at a time instead of following the contours of the
|
|
|
|
* landscape at a fixed altitude. This only has effect when there are more than 15 height levels. */
|
|
|
|
VAF_IN_MAX_HEIGHT_CORRECTION = 1, ///< The vehicle is currently lowering its altitude because it hit the upper bound.
|
|
|
|
VAF_IN_MIN_HEIGHT_CORRECTION = 2, ///< The vehicle is currently raising its altitude because it hit the lower bound.
|
2018-11-03 12:24:36 +00:00
|
|
|
|
|
|
|
VAF_HELI_DIRECT_DESCENT = 3, ///< The helicopter is descending directly at its destination (helipad or in front of hangar)
|
2011-12-13 00:43:35 +00:00
|
|
|
};
|
|
|
|
|
2014-09-20 15:46:44 +00:00
|
|
|
static const int ROTOR_Z_OFFSET = 5; ///< Z Offset between helicopter- and rotorsprite.
|
2007-01-27 12:29:55 +00:00
|
|
|
|
2009-05-22 20:03:26 +00:00
|
|
|
void HandleAircraftEnterHangar(Aircraft *v);
|
2012-12-23 01:00:25 +00:00
|
|
|
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type);
|
2007-02-20 06:39:09 +00:00
|
|
|
void UpdateAirplanesOnNewStation(const Station *st);
|
2011-12-13 00:43:35 +00:00
|
|
|
void UpdateAircraftCache(Aircraft *v, bool update_range = false);
|
2007-04-18 18:37:40 +00:00
|
|
|
|
2011-09-09 21:27:57 +00:00
|
|
|
void AircraftLeaveHangar(Aircraft *v, Direction exit_dir);
|
2009-05-22 20:03:26 +00:00
|
|
|
void AircraftNextAirportPos_and_Order(Aircraft *v);
|
|
|
|
void SetAircraftPosition(Aircraft *v, int x, int y, int z);
|
2015-08-02 21:58:41 +00:00
|
|
|
void FindBreakdownDestination(Aircraft *v);
|
2014-09-21 06:35:34 +00:00
|
|
|
|
|
|
|
void GetAircraftFlightLevelBounds(const Vehicle *v, int *min, int *max);
|
|
|
|
template <class T>
|
|
|
|
int GetAircraftFlightLevel(T *v, bool takeoff = false);
|
2009-01-04 15:32:25 +00:00
|
|
|
|
2011-12-13 00:43:35 +00:00
|
|
|
/** Variables that are cached to improve performance and such. */
|
|
|
|
struct AircraftCache {
|
2024-01-07 16:41:53 +00:00
|
|
|
uint32_t cached_max_range_sqr; ///< Cached squared maximum range.
|
|
|
|
uint16_t cached_max_range; ///< Cached maximum range.
|
2020-08-25 00:26:44 +00:00
|
|
|
byte image_movement_state; ///< Cached image aircraft movement state
|
2011-12-13 00:43:35 +00:00
|
|
|
};
|
|
|
|
|
2007-04-29 21:24:08 +00:00
|
|
|
/**
|
2009-05-26 23:24:34 +00:00
|
|
|
* Aircraft, helicopters, rotors and their shadows belong to this class.
|
2007-04-29 21:24:08 +00:00
|
|
|
*/
|
2024-01-31 20:03:17 +00:00
|
|
|
struct Aircraft final : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
|
2024-01-07 16:41:53 +00:00
|
|
|
uint16_t crashed_counter; ///< Timer for handling crash animations.
|
2010-11-05 16:34:22 +00:00
|
|
|
byte pos; ///< Next desired position of the aircraft.
|
|
|
|
byte previous_pos; ///< Previous desired position of the aircraft.
|
|
|
|
StationID targetairport; ///< Airport to go to next.
|
|
|
|
byte state; ///< State of the airport. @see AirportMovementStates
|
2019-04-22 07:11:28 +00:00
|
|
|
Direction last_direction;
|
2010-11-05 16:34:22 +00:00
|
|
|
byte number_consecutive_turns; ///< Protection to prevent the aircraft of making a lot of turns in order to reach a specific point.
|
|
|
|
byte turn_counter; ///< Ticks between each turn to prevent > 45 degree turns.
|
2014-09-21 06:35:34 +00:00
|
|
|
byte flags; ///< Aircraft flags. @see AirVehicleFlags
|
2011-12-13 00:43:35 +00:00
|
|
|
|
|
|
|
AircraftCache acache;
|
2010-01-09 14:43:08 +00:00
|
|
|
|
2009-06-02 19:12:28 +00:00
|
|
|
/** We don't want GCC to zero our struct! It already is zeroed and has an index! */
|
2011-01-21 14:43:38 +00:00
|
|
|
Aircraft() : SpecializedVehicleBase() {}
|
2007-04-29 21:24:08 +00:00
|
|
|
/** We want to 'destruct' the right class. */
|
2007-08-05 17:43:04 +00:00
|
|
|
virtual ~Aircraft() { this->PreDestructor(); }
|
2007-04-29 21:24:08 +00:00
|
|
|
|
2023-04-13 06:23:18 +00:00
|
|
|
void MarkDirty() override;
|
|
|
|
void UpdateDeltaXY() override;
|
|
|
|
ExpensesType GetExpenseType(bool income) const override { return income ? EXPENSES_AIRCRAFT_REVENUE : EXPENSES_AIRCRAFT_RUN; }
|
|
|
|
bool IsPrimaryVehicle() const override { return this->IsNormalAircraft(); }
|
|
|
|
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const override;
|
2021-10-12 19:19:53 +00:00
|
|
|
Direction GetMapImageDirection() const { return this->First()->direction; }
|
2023-04-13 06:23:18 +00:00
|
|
|
int GetDisplaySpeed() const override { return this->cur_speed; }
|
|
|
|
int GetDisplayMaxSpeed() const override { return this->vcache.cached_max_speed; }
|
|
|
|
int GetSpeedOldUnits() const { return this->vcache.cached_max_speed * 10 / 128; }
|
|
|
|
int GetCurrentMaxSpeed() const override { return this->GetSpeedOldUnits(); }
|
|
|
|
Money GetRunningCost() const override;
|
2012-07-07 15:39:46 +00:00
|
|
|
|
2023-04-13 06:23:18 +00:00
|
|
|
bool IsInDepot() const override
|
2012-07-07 15:39:46 +00:00
|
|
|
{
|
|
|
|
assert(this->IsPrimaryVehicle());
|
|
|
|
return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile);
|
|
|
|
}
|
|
|
|
|
2023-04-13 06:23:18 +00:00
|
|
|
bool Tick() override;
|
|
|
|
void OnNewDay() override;
|
2023-11-20 22:26:57 +00:00
|
|
|
void OnPeriodic() override;
|
2023-04-13 06:23:18 +00:00
|
|
|
uint Crash(bool flooded = false) override;
|
|
|
|
TileIndex GetOrderStationLocation(StationID station) override;
|
|
|
|
ClosestDepot FindClosestDepot() override;
|
2009-07-13 16:37:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the aircraft type is a normal flying device; eg
|
|
|
|
* not a rotor or a shadow
|
|
|
|
* @return Returns true if the aircraft is a helicopter/airplane and
|
|
|
|
* false if it is a shadow or a rotor
|
|
|
|
*/
|
2011-12-20 17:57:56 +00:00
|
|
|
inline bool IsNormalAircraft() const
|
2009-07-13 16:37:27 +00:00
|
|
|
{
|
|
|
|
/* To be fully correct the commented out functionality is the proper one,
|
|
|
|
* but since value can only be 0 or 2, it is sufficient to only check <= 2
|
|
|
|
* return (this->subtype == AIR_HELICOPTER) || (this->subtype == AIR_AIRCRAFT); */
|
|
|
|
return this->subtype <= AIR_AIRCRAFT;
|
|
|
|
}
|
2011-12-13 00:43:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the range of this aircraft.
|
|
|
|
* @return Range in tiles or 0 if unlimited range.
|
|
|
|
*/
|
2024-01-07 16:41:53 +00:00
|
|
|
uint16_t GetRange() const
|
2011-12-13 00:43:35 +00:00
|
|
|
{
|
|
|
|
return this->acache.cached_max_range;
|
|
|
|
}
|
2007-04-29 21:24:08 +00:00
|
|
|
};
|
|
|
|
|
2016-10-16 14:57:56 +00:00
|
|
|
void GetRotorImage(const Aircraft *v, EngineImageType image_type, VehicleSpriteSeq *result);
|
2009-05-22 20:03:26 +00:00
|
|
|
|
|
|
|
Station *GetTargetAirportIfValid(const Aircraft *v);
|
2023-01-29 08:28:24 +00:00
|
|
|
void HandleMissingAircraftOrders(Aircraft *v);
|
2008-09-16 15:15:41 +00:00
|
|
|
|
2023-03-22 20:58:13 +00:00
|
|
|
const char *AirportMovementStateToString(byte state);
|
|
|
|
|
2006-06-09 06:34:28 +00:00
|
|
|
#endif /* AIRCRAFT_H */
|