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
|
|
|
|
2009-05-22 20:03:26 +00:00
|
|
|
struct Aircraft;
|
|
|
|
|
2007-04-03 16:12:28 +00:00
|
|
|
/** An aircraft can be one ot 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
|
|
|
|
AIR_ROTOR = 6 ///< rotor of an helicopter
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2007-01-27 12:29:55 +00:00
|
|
|
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Handle Aircraft specific tasks when a an Aircraft enters a hangar
|
2007-04-02 14:20:31 +00:00
|
|
|
* @param *v Vehicle that enters the hangar
|
|
|
|
*/
|
2009-05-22 20:03:26 +00:00
|
|
|
void HandleAircraftEnterHangar(Aircraft *v);
|
2007-04-02 14:20:31 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Get the size of the sprite of an aircraft sprite heading west (used for lists)
|
2007-04-02 14:20:31 +00:00
|
|
|
* @param engine The engine to get the sprite from
|
|
|
|
* @param width The width of the sprite
|
|
|
|
* @param height The height of the sprite
|
|
|
|
*/
|
2007-02-10 13:37:32 +00:00
|
|
|
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height);
|
2006-09-27 15:40:55 +00:00
|
|
|
|
2007-04-03 16:12:28 +00:00
|
|
|
/**
|
|
|
|
* Updates the status of the Aircraft heading or in the station
|
|
|
|
* @param st Station been updated
|
|
|
|
*/
|
2007-02-20 06:39:09 +00:00
|
|
|
void UpdateAirplanesOnNewStation(const Station *st);
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Update cached values of an aircraft.
|
2007-04-18 18:37:40 +00:00
|
|
|
* Currently caches callback 36 max speed.
|
|
|
|
* @param v Vehicle
|
|
|
|
*/
|
2009-05-22 20:03:26 +00:00
|
|
|
void UpdateAircraftCache(Aircraft *v);
|
2007-04-18 18:37:40 +00:00
|
|
|
|
2009-05-22 20:03:26 +00:00
|
|
|
void AircraftLeaveHangar(Aircraft *v);
|
|
|
|
void AircraftNextAirportPos_and_Order(Aircraft *v);
|
|
|
|
void SetAircraftPosition(Aircraft *v, int x, int y, int z);
|
|
|
|
byte GetAircraftFlyingAltitude(const Aircraft *v);
|
2009-01-04 15:32:25 +00:00
|
|
|
|
2009-05-23 09:10:56 +00:00
|
|
|
/** Cached oftenly queried (NewGRF) values */
|
|
|
|
struct AircraftCache {
|
|
|
|
uint16 cached_max_speed; ///< Cached maximum speed of the aircraft.
|
|
|
|
};
|
|
|
|
|
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
|
|
|
*/
|
2009-05-26 22:10:13 +00:00
|
|
|
struct Aircraft : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
|
2009-05-23 09:10:56 +00:00
|
|
|
AircraftCache acache; ///< Cache of often used calculated values
|
|
|
|
|
2009-05-22 20:07:26 +00:00
|
|
|
uint16 crashed_counter;
|
|
|
|
byte pos;
|
|
|
|
byte previous_pos;
|
|
|
|
StationID targetairport;
|
|
|
|
byte state;
|
2009-09-03 12:11:31 +00:00
|
|
|
DirectionByte last_direction;
|
2009-09-09 00:03:35 +00:00
|
|
|
byte number_consecutive_turns;
|
2009-05-22 20:07:26 +00:00
|
|
|
|
2010-01-09 14:43:08 +00:00
|
|
|
/** Ticks between each turn to prevent > 45 degree turns. */
|
|
|
|
byte turn_counter;
|
|
|
|
|
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! */
|
|
|
|
Aircraft() : SpecializedVehicle<Aircraft, VEH_AIRCRAFT>() {}
|
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-05-02 09:39:11 +00:00
|
|
|
const char *GetTypeString() const { return "aircraft"; }
|
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; }
|
2009-07-13 16:37:27 +00:00
|
|
|
bool IsPrimaryVehicle() const { return this->IsNormalAircraft(); }
|
2008-04-21 20:50:58 +00:00
|
|
|
SpriteID GetImage(Direction direction) const;
|
2009-02-01 17:14:39 +00:00
|
|
|
int GetDisplaySpeed() const { return this->cur_speed; }
|
|
|
|
int GetDisplayMaxSpeed() const { return this->max_speed; }
|
2009-01-22 21:33:08 +00:00
|
|
|
Money GetRunningCost() const;
|
2007-08-29 21:49:08 +00:00
|
|
|
bool IsInDepot() const { 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
|
|
|
|
*/
|
|
|
|
FORCEINLINE bool IsNormalAircraft() const
|
|
|
|
{
|
|
|
|
/* 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;
|
|
|
|
}
|
2007-04-29 21:24:08 +00:00
|
|
|
};
|
|
|
|
|
2009-05-26 22:10:13 +00:00
|
|
|
#define FOR_ALL_AIRCRAFT(var) FOR_ALL_VEHICLES_OF_TYPE(Aircraft, var)
|
|
|
|
|
2009-05-22 20:03:26 +00:00
|
|
|
SpriteID GetRotorImage(const Aircraft *v);
|
|
|
|
|
|
|
|
Station *GetTargetAirportIfValid(const Aircraft *v);
|
2008-09-16 15:15:41 +00:00
|
|
|
|
2006-06-09 06:34:28 +00:00
|
|
|
#endif /* AIRCRAFT_H */
|