Add support for deleted functions
[openttd/fttd.git] / src / aircraft.h
blobdbbdcf04f16ddd25663dd16cc1039bd48ee13ed6
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file aircraft.h Base for aircraft. */
12 #ifndef AIRCRAFT_H
13 #define AIRCRAFT_H
15 #include "vehicle_base.h"
16 #include "station_func.h"
18 struct Aircraft;
20 /** An aircraft can be one of those types. */
21 enum AircraftSubType {
22 AIR_HELICOPTER = 0, ///< an helicopter
23 AIR_AIRCRAFT = 2, ///< an airplane
24 AIR_SHADOW = 4, ///< shadow of the aircraft
25 AIR_ROTOR = 6, ///< rotor of an helicopter
28 /** Aircraft flags. */
29 enum VehicleAirFlags {
30 VAF_DEST_TOO_FAR = 0, ///< Next destination is too far away.
34 void HandleAircraftEnterHangar(Aircraft *v);
35 void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type);
36 void UpdateAirplanesOnNewStation(const Station *st);
37 void UpdateAircraftCache(Aircraft *v, bool update_range = false);
39 void AircraftLeaveHangar(Aircraft *v, Direction exit_dir);
40 void AircraftNextAirportPos_and_Order(Aircraft *v);
41 void SetAircraftPosition(Aircraft *v, int x, int y, int z);
42 int GetAircraftFlyingAltitude(const Aircraft *v);
44 /** Variables that are cached to improve performance and such. */
45 struct AircraftCache {
46 uint32 cached_max_range_sqr; ///< Cached squared maximum range.
47 uint16 cached_max_range; ///< Cached maximum range.
50 /**
51 * Aircraft, helicopters, rotors and their shadows belong to this class.
53 struct Aircraft FINAL : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
54 uint16 crashed_counter; ///< Timer for handling crash animations.
55 byte pos; ///< Next desired position of the aircraft.
56 byte previous_pos; ///< Previous desired position of the aircraft.
57 StationID targetairport; ///< Airport to go to next.
58 byte state; ///< State of the airport. @see AirportMovementStates
59 DirectionByte last_direction;
60 byte number_consecutive_turns; ///< Protection to prevent the aircraft of making a lot of turns in order to reach a specific point.
61 byte turn_counter; ///< Ticks between each turn to prevent > 45 degree turns.
62 byte flags; ///< Aircraft flags. @see VehicleAirFlags
64 AircraftCache acache;
66 /** We don't want GCC to zero our struct! It already is zeroed and has an index! */
67 Aircraft() : SpecializedVehicleBase() {}
68 /** We want to 'destruct' the right class. */
69 virtual ~Aircraft() { this->PreDestructor(); }
71 void MarkDirty();
72 void UpdateDeltaXY(Direction direction);
73 ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_AIRCRAFT_INC : EXPENSES_AIRCRAFT_RUN; }
74 bool IsPrimaryVehicle() const { return this->IsNormalAircraft(); }
75 SpriteID GetImage(Direction direction, EngineImageType image_type) const;
76 int GetDisplaySpeed() const { return this->cur_speed; }
77 int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed; }
78 int GetSpeedOldUnits() const { return this->vcache.cached_max_speed * 10 / 128; }
79 int GetCurrentMaxSpeed() const { return this->GetSpeedOldUnits(); }
80 Money GetRunningCost() const;
82 bool IsInDepot() const
84 assert(this->IsPrimaryVehicle());
85 return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile);
88 bool Tick();
89 void OnNewDay();
90 uint Crash(bool flooded = false);
91 TileIndex GetOrderStationLocation(StationID station);
92 bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
94 /**
95 * Check if the aircraft type is a normal flying device; eg
96 * not a rotor or a shadow
97 * @return Returns true if the aircraft is a helicopter/airplane and
98 * false if it is a shadow or a rotor
100 inline bool IsNormalAircraft() const
102 /* To be fully correct the commented out functionality is the proper one,
103 * but since value can only be 0 or 2, it is sufficient to only check <= 2
104 * return (this->subtype == AIR_HELICOPTER) || (this->subtype == AIR_AIRCRAFT); */
105 return this->subtype <= AIR_AIRCRAFT;
109 * Get the range of this aircraft.
110 * @return Range in tiles or 0 if unlimited range.
112 uint16 GetRange() const
114 return this->acache.cached_max_range;
119 * Macro for iterating over all aircrafts.
121 #define FOR_ALL_AIRCRAFT(var) FOR_ALL_VEHICLES_OF_TYPE(Aircraft, var)
123 SpriteID GetRotorImage(const Aircraft *v, EngineImageType image_type);
125 Station *GetTargetAirportIfValid(const Aircraft *v);
127 #endif /* AIRCRAFT_H */