Translations update
[openttd/fttd.git] / src / aircraft.h
bloba8a69040d4cbf4cbd07163c68be20f96f4389a5c
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 /** Flags for air vehicles; shared with disaster vehicles. */
29 enum AirVehicleFlags {
30 VAF_DEST_TOO_FAR = 0, ///< Next destination is too far away.
32 /* The next two flags are to prevent stair climbing of the aircraft. The idea is that the aircraft
33 * will ascend or descend multiple flight levels at a time instead of following the contours of the
34 * landscape at a fixed altitude. This only has effect when there are more than 15 height levels. */
35 VAF_IN_MAX_HEIGHT_CORRECTION = 1, ///< The vehicle is currently lowering its altitude because it hit the upper bound.
36 VAF_IN_MIN_HEIGHT_CORRECTION = 2, ///< The vehicle is currently raising its altitude because it hit the lower bound.
39 static const int ROTOR_Z_OFFSET = 5; ///< Z Offset between helicopter- and rotorsprite.
41 void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type);
42 void UpdateAirplanesOnNewStation(const Station *st);
43 void UpdateAircraftCache(Aircraft *v, bool update_range = false);
45 void AircraftLeaveHangar(Aircraft *v, Direction exit_dir);
46 void AircraftNextAirportPos_and_Order(Aircraft *v);
47 void SetAircraftPosition(Aircraft *v, int x, int y, int z);
49 int GetAircraftBaseFlightLevel (const Vehicle *v);
50 int GetAircraftFlightLevel (const Vehicle *v, byte *flags, bool takeoff);
52 template <class T>
53 static inline int GetAircraftFlightLevel (T *v, bool takeoff = false)
55 return GetAircraftFlightLevel (v, &v->flags, takeoff);
58 /** Variables that are cached to improve performance and such. */
59 struct AircraftCache {
60 uint32 cached_max_range_sqr; ///< Cached squared maximum range.
61 uint16 cached_max_range; ///< Cached maximum range.
64 /**
65 * Aircraft, helicopters, rotors and their shadows belong to this class.
67 struct Aircraft FINAL : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
68 uint16 crashed_counter; ///< Timer for handling crash animations.
69 byte pos; ///< Next desired position of the aircraft.
70 byte previous_pos; ///< Previous desired position of the aircraft.
71 StationID targetairport; ///< Airport to go to next.
72 byte state; ///< State of the airport. @see AirportMovementStates
73 DirectionByte last_direction;
74 byte number_consecutive_turns; ///< Protection to prevent the aircraft of making a lot of turns in order to reach a specific point.
75 byte turn_counter; ///< Ticks between each turn to prevent > 45 degree turns.
76 byte flags; ///< Aircraft flags. @see AirVehicleFlags
78 AircraftCache acache;
80 /** We don't want GCC to zero our struct! It already is zeroed and has an index! */
81 Aircraft() : SpecializedVehicleBase() {}
82 /** We want to 'destruct' the right class. */
83 virtual ~Aircraft() { this->PreDestructor(); }
85 void MarkDirty();
86 void UpdateDeltaXY(Direction direction);
87 ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_AIRCRAFT_INC : EXPENSES_AIRCRAFT_RUN; }
88 bool IsPrimaryVehicle() const { return this->IsNormalAircraft(); }
89 void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const;
90 int GetDisplaySpeed() const { return this->cur_speed; }
91 int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed; }
92 int GetSpeedOldUnits() const { return this->vcache.cached_max_speed * 10 / 128; }
93 int GetCurrentMaxSpeed() const { return this->GetSpeedOldUnits(); }
94 Money GetRunningCost() const;
96 bool IsInDepot() const
98 assert(this->IsPrimaryVehicle());
99 return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile);
102 bool Tick();
103 void OnNewDay();
104 uint Crash(bool flooded = false);
105 TileIndex GetOrderStationLocation(StationID station);
106 bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
109 * Check if the aircraft type is a normal flying device; eg
110 * not a rotor or a shadow
111 * @return Returns true if the aircraft is a helicopter/airplane and
112 * false if it is a shadow or a rotor
114 inline bool IsNormalAircraft() const
116 /* To be fully correct the commented out functionality is the proper one,
117 * but since value can only be 0 or 2, it is sufficient to only check <= 2
118 * return (this->subtype == AIR_HELICOPTER) || (this->subtype == AIR_AIRCRAFT); */
119 return this->subtype <= AIR_AIRCRAFT;
123 * Get the range of this aircraft.
124 * @return Range in tiles or 0 if unlimited range.
126 uint16 GetRange() const
128 return this->acache.cached_max_range;
133 * Macro for iterating over all aircrafts.
135 #define FOR_ALL_AIRCRAFT(var) FOR_ALL_VEHICLES_OF_TYPE(Aircraft, var)
137 void GetRotorImage(const Aircraft *v, EngineImageType image_type, VehicleSpriteSeq *result);
139 Station *GetTargetAirportIfValid(const Aircraft *v);
141 #endif /* AIRCRAFT_H */