2006-06-05 12:43:41 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
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.
|
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);
|
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 {
|
|
|
|
uint32 cached_max_range_sqr; ///< Cached squared maximum range.
|
|
|
|
uint16 cached_max_range; ///< Cached maximum range.
|
|
|
|
};
|
|
|
|
|
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
|
|
|
*/
|
2011-12-18 17:17:18 +00:00
|
|
|
struct Aircraft FINAL : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
|
2010-11-05 16:34:22 +00:00
|
|
|
uint16 crashed_counter; ///< Timer for handling crash animations.
|
|
|
|
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
|
2009-09-03 12:11:31 +00:00
|
|
|
DirectionByte 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
|
|
|
|
2007-04-29 22:33:51 +00:00
|
|
|
void MarkDirty();
|
2007-05-01 16:35:14 +00:00
|
|
|
void UpdateDeltaXY(Direction direction);
|
2007-05-02 09:39:11 +00:00
|
|
|
ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_AIRCRAFT_INC : EXPENSES_AIRCRAFT_RUN; }
|
2010-11-06 12:42:04 +00:00
|
|
|
bool IsPrimaryVehicle() const { return this->IsNormalAircraft(); }
|
2011-11-01 16:51:47 +00:00
|
|
|
SpriteID GetImage(Direction direction, EngineImageType image_type) const;
|
2010-11-06 12:42:04 +00:00
|
|
|
int GetDisplaySpeed() const { return this->cur_speed; }
|
2010-11-06 12:53:31 +00:00
|
|
|
int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed; }
|
|
|
|
int GetSpeedOldUnits() const { return this->vcache.cached_max_speed * 10 / 128; }
|
2012-05-14 19:56:49 +00:00
|
|
|
int GetCurrentMaxSpeed() const { return this->GetSpeedOldUnits(); }
|
2009-01-22 21:33:08 +00:00
|
|
|
Money GetRunningCost() const;
|
2012-07-07 15:39:46 +00:00
|
|
|
|
|
|
|
bool IsInDepot() const
|
|
|
|
{
|
|
|
|
assert(this->IsPrimaryVehicle());
|
|
|
|
return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile);
|
|
|
|
}
|
|
|
|
|
2009-05-22 13:53:14 +00:00
|
|
|
bool Tick();
|
2008-02-01 22:02:14 +00:00
|
|
|
void OnNewDay();
|
2009-12-04 20:29:46 +00:00
|
|
|
uint Crash(bool flooded = false);
|
2008-04-05 12:01:34 +00:00
|
|
|
TileIndex GetOrderStationLocation(StationID station);
|
2008-04-11 08:14:43 +00:00
|
|
|
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
|
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.
|
|
|
|
*/
|
|
|
|
uint16 GetRange() const
|
|
|
|
{
|
|
|
|
return this->acache.cached_max_range;
|
|
|
|
}
|
2007-04-29 21:24:08 +00:00
|
|
|
};
|
|
|
|
|
2010-11-05 16:34:22 +00:00
|
|
|
/**
|
|
|
|
* Macro for iterating over all aircrafts.
|
|
|
|
*/
|
2009-05-26 22:10:13 +00:00
|
|
|
#define FOR_ALL_AIRCRAFT(var) FOR_ALL_VEHICLES_OF_TYPE(Aircraft, var)
|
|
|
|
|
2011-11-01 16:51:47 +00:00
|
|
|
SpriteID GetRotorImage(const Aircraft *v, EngineImageType image_type);
|
2009-05-22 20:03:26 +00:00
|
|
|
|
|
|
|
Station *GetTargetAirportIfValid(const Aircraft *v);
|
2008-09-16 15:15:41 +00:00
|
|
|
|
2006-06-09 06:34:28 +00:00
|
|
|
#endif /* AIRCRAFT_H */
|