tron@3963: /* $Id$ */ tron@3963: rubidium@9111: /** @file aircraft.h Base for aircraft. */ belugas@6117: peter1138@3987: #ifndef AIRCRAFT_H peter1138@3987: #define AIRCRAFT_H peter1138@3987: tron@3963: #include "station_map.h" rubidium@8785: #include "station_base.h" rubidium@8144: #include "vehicle_base.h" rubidium@8786: #include "engine_func.h" peter1138@9070: #include "engine_base.h" tron@3963: belugas@6415: /** An aircraft can be one ot those types */ rubidium@6248: enum AircraftSubType { belugas@6409: AIR_HELICOPTER = 0, ///< an helicopter rubidium@6410: AIR_AIRCRAFT = 2, ///< an airplane belugas@6409: AIR_SHADOW = 4, ///< shadow of the aircraft belugas@6409: AIR_ROTOR = 6 ///< rotor of an helicopter rubidium@6248: }; Darkvater@5854: Darkvater@5854: Darkvater@5854: /** Check if the aircraft type is a normal flying device; eg Darkvater@5854: * not a rotor or a shadow Darkvater@5854: * @param v vehicle to check Darkvater@5854: * @return Returns true if the aircraft is a helicopter/airplane and Darkvater@5854: * false if it is a shadow or a rotor) */ Darkvater@5854: static inline bool IsNormalAircraft(const Vehicle *v) Darkvater@5854: { rubidium@6259: assert(v->type == VEH_AIRCRAFT); Darkvater@5854: /* To be fully correct the commented out functionality is the proper one, Darkvater@5854: * but since value can only be 0 or 2, it is sufficient to only check <= 2 Darkvater@5854: * return (v->subtype == AIR_HELICOPTER) || (v->subtype == AIR_AIRCRAFT); */ Darkvater@5854: return v->subtype <= AIR_AIRCRAFT; Darkvater@5854: } Darkvater@5854: glx@7683: /** Checks if an aircraft can use the station in question bjarni@6237: * @param engine The engine to test glx@7683: * @param st The station glx@7683: * @return true if the aircraft can use the station bjarni@6237: */ glx@7683: static inline bool CanAircraftUseStation(EngineID engine, const Station *st) bjarni@6237: { bjarni@6237: const AirportFTAClass *apc = st->Airport(); bjarni@6237: const AircraftVehicleInfo *avi = AircraftVehInfo(engine); bjarni@6237: glx@6245: return (apc->flags & (avi->subtype & AIR_CTOL ? AirportFTAClass::AIRPLANES : AirportFTAClass::HELICOPTERS)) != 0; bjarni@6237: } bjarni@6237: glx@7683: /** Checks if an aircraft can use the station at the tile in question glx@7683: * @param engine The engine to test glx@7683: * @param tile The tile where the station is glx@7683: * @return true if the aircraft can use the station glx@7683: */ glx@7683: static inline bool CanAircraftUseStation(EngineID engine, TileIndex tile) glx@7683: { glx@7683: return CanAircraftUseStation(engine, GetStationByTile(tile)); glx@7683: } glx@7683: belugas@6409: /** belugas@6409: * Calculates cargo capacity based on an aircraft's passenger belugas@6409: * and mail capacities. belugas@6409: * @param cid Which cargo type to calculate a capacity for. belugas@6409: * @param avi Which engine to find a cargo capacity for. belugas@6409: * @return New cargo capacity value. belugas@6409: */ rubidium@6410: uint16 AircraftDefaultCargoCapacity(CargoID cid, const AircraftVehicleInfo *avi); peter1138@3987: belugas@6415: /** belugas@6415: * This is the Callback method after the construction attempt of an aircraft belugas@6415: * @param success indicates completion (or not) of the operation belugas@6415: * @param tile of depot where aircraft is built belugas@6415: * @param p1 unused belugas@6415: * @param p2 unused belugas@6415: */ bjarni@5780: void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2); belugas@6415: belugas@6409: /** Handle Aircraft specific tasks when a an Aircraft enters a hangar belugas@6409: * @param *v Vehicle that enters the hangar belugas@6409: */ belugas@4732: void HandleAircraftEnterHangar(Vehicle *v); belugas@6409: belugas@6409: /** Get the size of the sprite of an aircraft sprite heading west (used for lists) belugas@6409: * @param engine The engine to get the sprite from belugas@6409: * @param width The width of the sprite belugas@6409: * @param height The height of the sprite belugas@6409: */ bjarni@5972: void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height); bjarni@4653: belugas@6415: /** belugas@6415: * Updates the status of the Aircraft heading or in the station belugas@6415: * @param st Station been updated belugas@6415: */ tron@6087: void UpdateAirplanesOnNewStation(const Station *st); tron@6087: peter1138@6490: /** Update cached values of an aircraft. peter1138@6490: * Currently caches callback 36 max speed. peter1138@6490: * @param v Vehicle peter1138@6490: */ peter1138@6490: void UpdateAircraftCache(Vehicle *v); peter1138@6490: rubidium@6552: /** rubidium@6552: * This class 'wraps' Vehicle; you do not actually instantiate this class. rubidium@6552: * You create a Vehicle using AllocateVehicle, so it is added to the pool rubidium@6552: * and you reinitialize that to a Train using: rubidium@6552: * v = new (v) Aircraft(); rubidium@6552: * rubidium@6552: * As side-effect the vehicle type is set correctly. rubidium@6552: */ rubidium@6552: struct Aircraft : public Vehicle { rubidium@6552: /** Initializes the Vehicle to an aircraft */ rubidium@6552: Aircraft() { this->type = VEH_AIRCRAFT; } rubidium@6552: rubidium@6552: /** We want to 'destruct' the right class. */ rubidium@7412: virtual ~Aircraft() { this->PreDestructor(); } rubidium@6552: rubidium@6563: const char *GetTypeString() const { return "aircraft"; } rubidium@6553: void MarkDirty(); rubidium@6558: void UpdateDeltaXY(Direction direction); rubidium@6563: ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_AIRCRAFT_INC : EXPENSES_AIRCRAFT_RUN; } maedhros@6773: bool IsPrimaryVehicle() const { return IsNormalAircraft(this); } peter1138@9022: SpriteID GetImage(Direction direction) const; rubidium@7477: int GetDisplaySpeed() const { return this->cur_speed * 10 / 16; } rubidium@7484: int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 16; } rubidium@7488: Money GetRunningCost() const { return AircraftVehInfo(this->engine_type)->running_cost * _price.aircraft_running; } rubidium@7490: bool IsInDepot() const { return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile); } rubidium@7135: void Tick(); glx@8467: void OnNewDay(); rubidium@8830: TileIndex GetOrderStationLocation(StationID station); rubidium@8890: bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse); rubidium@6552: }; rubidium@6552: smatz@10154: Station *GetTargetAirportIfValid(const Vehicle *v); smatz@10154: peter1138@3987: #endif /* AIRCRAFT_H */