tron@3963: /* $Id$ */ tron@3963: celestar@6447: /** @file aircraft.h */ belugas@6443: peter1138@3987: #ifndef AIRCRAFT_H peter1138@3987: #define AIRCRAFT_H peter1138@3987: tron@3963: #include "station_map.h" rubidium@6872: #include "vehicle_base.h" rubidium@6868: #include "engine.h" tron@3963: richk@6719: /** An aircraft can be one ot those types */ rubidium@6574: enum AircraftSubType { richk@6719: AIR_HELICOPTER = 0, ///< an helicopter richk@6719: AIR_AIRCRAFT = 2, ///< an airplane richk@6719: AIR_SHADOW = 4, ///< shadow of the aircraft richk@6719: AIR_ROTOR = 6 ///< rotor of an helicopter rubidium@6574: }; Darkvater@6105: Darkvater@6105: Darkvater@6105: /** Check if the aircraft type is a normal flying device; eg Darkvater@6105: * not a rotor or a shadow Darkvater@6105: * @param v vehicle to check Darkvater@6105: * @return Returns true if the aircraft is a helicopter/airplane and Darkvater@6105: * false if it is a shadow or a rotor) */ Darkvater@6105: static inline bool IsNormalAircraft(const Vehicle *v) Darkvater@6105: { rubidium@6585: assert(v->type == VEH_AIRCRAFT); Darkvater@6105: /* To be fully correct the commented out functionality is the proper one, Darkvater@6105: * but since value can only be 0 or 2, it is sufficient to only check <= 2 richk@6862: * return (v->subtype == AIR_HELICOPTER) || (v->subtype == AIR_AIRCRAFT); richk@6862: * limited to lower 3 bits so that seaplanes are still regarded as normal aircraft */ richk@6862: return (v->subtype & 0x07) <= AIR_AIRCRAFT; Darkvater@6105: } Darkvater@6105: rubidium@6870: /** Checks if an aircraft can use the station in question bjarni@6563: * @param engine The engine to test rubidium@6870: * @param st The station rubidium@6870: * @return true if the aircraft can use the station bjarni@6563: */ rubidium@6870: static inline bool CanAircraftUseStation(EngineID engine, const Station *st) bjarni@6563: { richk@6738: const AirportFTAClass *apc = st->Airport(); bjarni@6563: const AircraftVehicleInfo *avi = AircraftVehInfo(engine); bjarni@6563: richk@6862: if ((apc->flags & AirportFTAClass::SEAPLANES) && ((avi->subtype & AirportFTAClass::SEAPLANES) == 0)) return false; glx@6571: return (apc->flags & (avi->subtype & AIR_CTOL ? AirportFTAClass::AIRPLANES : AirportFTAClass::HELICOPTERS)) != 0; bjarni@6563: } bjarni@6563: rubidium@6870: /** Checks if an aircraft can use the station at the tile in question rubidium@6870: * @param engine The engine to test rubidium@6870: * @param tile The tile where the station is rubidium@6870: * @return true if the aircraft can use the station rubidium@6870: */ rubidium@6870: static inline bool CanAircraftUseStation(EngineID engine, TileIndex tile) rubidium@6870: { rubidium@6870: return CanAircraftUseStation(engine, GetStationByTile(tile)); rubidium@6870: } rubidium@6870: richk@6719: /** richk@6719: * Calculates cargo capacity based on an aircraft's passenger richk@6719: * and mail capacities. richk@6719: * @param cid Which cargo type to calculate a capacity for. richk@6719: * @param avi Which engine to find a cargo capacity for. richk@6719: * @return New cargo capacity value. richk@6719: */ richk@6719: uint16 AircraftDefaultCargoCapacity(CargoID cid, const AircraftVehicleInfo *avi); peter1138@3987: richk@6719: /** richk@6719: * This is the Callback method after the construction attempt of an aircraft richk@6719: * @param success indicates completion (or not) of the operation richk@6719: * @param tile of depot where aircraft is built richk@6719: * @param p1 unused richk@6719: * @param p2 unused richk@6719: */ bjarni@6031: void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2); richk@6719: richk@6719: /** Handle Aircraft specific tasks when a an Aircraft enters a hangar richk@6719: * @param *v Vehicle that enters the hangar richk@6719: */ belugas@4732: void HandleAircraftEnterHangar(Vehicle *v); richk@6719: richk@6719: /** Get the size of the sprite of an aircraft sprite heading west (used for lists) richk@6719: * @param engine The engine to get the sprite from richk@6719: * @param width The width of the sprite richk@6719: * @param height The height of the sprite richk@6719: */ bjarni@6223: void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height); bjarni@4653: richk@6719: /** richk@6719: * Updates the status of the Aircraft heading or in the station richk@6719: * @param st Station been updated richk@6719: */ tron@6413: void UpdateAirplanesOnNewStation(const Station *st); tron@6413: richk@6719: /** Update cached values of an aircraft. richk@6719: * Currently caches callback 36 max speed. richk@6719: * @param v Vehicle richk@6719: */ richk@6719: void UpdateAircraftCache(Vehicle *v); richk@6719: richk@6719: /** richk@6719: * This class 'wraps' Vehicle; you do not actually instantiate this class. richk@6719: * You create a Vehicle using AllocateVehicle, so it is added to the pool richk@6719: * and you reinitialize that to a Train using: richk@6719: * v = new (v) Aircraft(); richk@6719: * richk@6719: * As side-effect the vehicle type is set correctly. richk@6719: */ richk@6719: struct Aircraft : public Vehicle { richk@6719: /** Initializes the Vehicle to an aircraft */ richk@6719: Aircraft() { this->type = VEH_AIRCRAFT; } richk@6719: richk@6719: /** We want to 'destruct' the right class. */ rubidium@6800: virtual ~Aircraft() { this->PreDestructor(); } richk@6719: richk@6719: const char *GetTypeString() const { return "aircraft"; } richk@6719: void MarkDirty(); richk@6719: void UpdateDeltaXY(Direction direction); richk@6719: ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_AIRCRAFT_INC : EXPENSES_AIRCRAFT_RUN; } richk@6719: WindowClass GetVehicleListWindowClass() const { return WC_AIRCRAFT_LIST; } richk@6719: bool IsPrimaryVehicle() const { return IsNormalAircraft(this); } richk@6720: int GetImage(Direction direction) const; rubidium@6868: int GetDisplaySpeed() const { return this->cur_speed * 10 / 16; } rubidium@6868: int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 16; } rubidium@6868: Money GetRunningCost() const { return AircraftVehInfo(this->engine_type)->running_cost * _price.aircraft_running; } rubidium@6868: bool IsInDepot() const { return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile); } richk@6720: void Tick(); richk@6719: }; richk@6719: peter1138@3987: #endif /* AIRCRAFT_H */