2006-06-05 14:43:41 +02:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 22:21:05 +02: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 17:11:33 +02:00
|
|
|
/** @file aircraft.h Base for aircraft. */
|
2007-02-23 02:48:53 +01:00
|
|
|
|
2006-06-09 08:34:28 +02:00
|
|
|
#ifndef AIRCRAFT_H
|
|
|
|
#define AIRCRAFT_H
|
|
|
|
|
2006-06-05 14:43:41 +02:00
|
|
|
#include "station_map.h"
|
2007-12-27 14:35:39 +01:00
|
|
|
#include "vehicle_base.h"
|
2006-06-05 14:43:41 +02:00
|
|
|
|
2009-05-22 22:03:26 +02:00
|
|
|
struct Aircraft;
|
|
|
|
|
2010-11-05 17:34:22 +01:00
|
|
|
/** An aircraft can be one of those types. */
|
2007-03-07 13:11:48 +01:00
|
|
|
enum AircraftSubType {
|
2007-04-02 16:20:31 +02:00
|
|
|
AIR_HELICOPTER = 0, ///< an helicopter
|
2007-04-02 17:08:36 +02:00
|
|
|
AIR_AIRCRAFT = 2, ///< an airplane
|
2007-04-02 16:20:31 +02:00
|
|
|
AIR_SHADOW = 4, ///< shadow of the aircraft
|
2011-12-19 18:48:04 +01:00
|
|
|
AIR_ROTOR = 6, ///< rotor of an helicopter
|
2007-03-07 13:11:48 +01:00
|
|
|
};
|
2007-01-27 13:29:55 +01:00
|
|
|
|
2011-12-13 01:43:35 +01:00
|
|
|
/** Aircraft flags. */
|
|
|
|
enum VehicleAirFlags {
|
|
|
|
VAF_DEST_TOO_FAR = 0, ///< Next destination is too far away.
|
|
|
|
};
|
|
|
|
|
2007-01-27 13:29:55 +01:00
|
|
|
|
2009-05-22 22:03:26 +02:00
|
|
|
void HandleAircraftEnterHangar(Aircraft *v);
|
2011-11-01 17:51:47 +01:00
|
|
|
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height, EngineImageType image_type);
|
2007-02-20 07:39:09 +01:00
|
|
|
void UpdateAirplanesOnNewStation(const Station *st);
|
2011-12-13 01:43:35 +01:00
|
|
|
void UpdateAircraftCache(Aircraft *v, bool update_range = false);
|
2007-04-18 20:37:40 +02:00
|
|
|
|
2011-09-09 23:27:57 +02:00
|
|
|
void AircraftLeaveHangar(Aircraft *v, Direction exit_dir);
|
2009-05-22 22:03:26 +02:00
|
|
|
void AircraftNextAirportPos_and_Order(Aircraft *v);
|
|
|
|
void SetAircraftPosition(Aircraft *v, int x, int y, int z);
|
2011-11-04 14:40:59 +01:00
|
|
|
int GetAircraftFlyingAltitude(const Aircraft *v);
|
2009-01-04 16:32:25 +01:00
|
|
|
|
2011-12-13 01:43:35 +01: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 23:24:08 +02:00
|
|
|
/**
|
2009-05-27 01:24:34 +02:00
|
|
|
* Aircraft, helicopters, rotors and their shadows belong to this class.
|
2007-04-29 23:24:08 +02:00
|
|
|
*/
|
2011-12-18 18:17:18 +01:00
|
|
|
struct Aircraft FINAL : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
|
2010-11-05 17:34:22 +01: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 14:11:31 +02:00
|
|
|
DirectionByte last_direction;
|
2010-11-05 17:34:22 +01: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.
|
2011-12-13 01:43:35 +01:00
|
|
|
byte flags; ///< Aircraft flags. @see VehicleAirFlags
|
|
|
|
|
|
|
|
AircraftCache acache;
|
2010-01-09 15:43:08 +01:00
|
|
|
|
2009-06-02 21:12:28 +02:00
|
|
|
/** We don't want GCC to zero our struct! It already is zeroed and has an index! */
|
2011-01-21 15:43:38 +01:00
|
|
|
Aircraft() : SpecializedVehicleBase() {}
|
2007-04-29 23:24:08 +02:00
|
|
|
/** We want to 'destruct' the right class. */
|
2007-08-05 19:43:04 +02:00
|
|
|
virtual ~Aircraft() { this->PreDestructor(); }
|
2007-04-29 23:24:08 +02:00
|
|
|
|
2007-04-30 00:33:51 +02:00
|
|
|
void MarkDirty();
|
2007-05-01 18:35:14 +02:00
|
|
|
void UpdateDeltaXY(Direction direction);
|
2007-05-02 11:39:11 +02:00
|
|
|
ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_AIRCRAFT_INC : EXPENSES_AIRCRAFT_RUN; }
|
2010-11-06 13:42:04 +01:00
|
|
|
bool IsPrimaryVehicle() const { return this->IsNormalAircraft(); }
|
2011-11-01 17:51:47 +01:00
|
|
|
SpriteID GetImage(Direction direction, EngineImageType image_type) const;
|
2010-11-06 13:42:04 +01:00
|
|
|
int GetDisplaySpeed() const { return this->cur_speed; }
|
2010-11-06 13:53:31 +01:00
|
|
|
int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed; }
|
|
|
|
int GetSpeedOldUnits() const { return this->vcache.cached_max_speed * 10 / 128; }
|
2012-05-14 21:56:49 +02:00
|
|
|
int GetCurrentMaxSpeed() const { return this->GetSpeedOldUnits(); }
|
2009-01-22 22:33:08 +01:00
|
|
|
Money GetRunningCost() const;
|
2012-07-07 17:39:46 +02:00
|
|
|
|
|
|
|
bool IsInDepot() const
|
|
|
|
{
|
|
|
|
assert(this->IsPrimaryVehicle());
|
|
|
|
return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile);
|
|
|
|
}
|
|
|
|
|
2009-05-22 15:53:14 +02:00
|
|
|
bool Tick();
|
2008-02-01 23:02:14 +01:00
|
|
|
void OnNewDay();
|
2009-12-04 21:29:46 +01:00
|
|
|
uint Crash(bool flooded = false);
|
2008-04-05 14:01:34 +02:00
|
|
|
TileIndex GetOrderStationLocation(StationID station);
|
2008-04-11 10:14:43 +02:00
|
|
|
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
|
2009-07-13 18:37:27 +02: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 18:57:56 +01:00
|
|
|
inline bool IsNormalAircraft() const
|
2009-07-13 18:37:27 +02: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 01:43:35 +01: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 23:24:08 +02:00
|
|
|
};
|
|
|
|
|
2010-11-05 17:34:22 +01:00
|
|
|
/**
|
|
|
|
* Macro for iterating over all aircrafts.
|
|
|
|
*/
|
2009-05-27 00:10:13 +02:00
|
|
|
#define FOR_ALL_AIRCRAFT(var) FOR_ALL_VEHICLES_OF_TYPE(Aircraft, var)
|
|
|
|
|
2011-11-01 17:51:47 +01:00
|
|
|
SpriteID GetRotorImage(const Aircraft *v, EngineImageType image_type);
|
2009-05-22 22:03:26 +02:00
|
|
|
|
|
|
|
Station *GetTargetAirportIfValid(const Aircraft *v);
|
2008-09-16 17:15:41 +02:00
|
|
|
|
2006-06-09 08:34:28 +02:00
|
|
|
#endif /* AIRCRAFT_H */
|