tron@3963: /* $Id$ */ tron@3963: rubidium@10429: /** @file aircraft.h Base for aircraft. */ belugas@6443: peter1138@3987: #ifndef AIRCRAFT_H peter1138@3987: #define AIRCRAFT_H peter1138@3987: tron@3963: #include "station_map.h" rubidium@9281: #include "station_base.h" rubidium@8640: #include "vehicle_base.h" rubidium@9282: #include "engine_func.h" peter1138@10382: #include "engine_base.h" tron@3963: belugas@6911: /** An aircraft can be one ot those types */ rubidium@6574: enum AircraftSubType { belugas@6905: AIR_HELICOPTER = 0, ///< an helicopter rubidium@6906: AIR_AIRCRAFT = 2, ///< an airplane belugas@6905: AIR_SHADOW = 4, ///< shadow of the aircraft belugas@6905: 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 Darkvater@6105: * return (v->subtype == AIR_HELICOPTER) || (v->subtype == AIR_AIRCRAFT); */ Darkvater@6105: return v->subtype <= AIR_AIRCRAFT; Darkvater@6105: } Darkvater@6105: glx@8179: /** Checks if an aircraft can use the station in question bjarni@6563: * @param engine The engine to test glx@8179: * @param st The station glx@8179: * @return true if the aircraft can use the station bjarni@6563: */ glx@8179: static inline bool CanAircraftUseStation(EngineID engine, const Station *st) bjarni@6563: { bjarni@6563: const AirportFTAClass *apc = st->Airport(); bjarni@6563: const AircraftVehicleInfo *avi = AircraftVehInfo(engine); bjarni@6563: glx@6571: return (apc->flags & (avi->subtype & AIR_CTOL ? AirportFTAClass::AIRPLANES : AirportFTAClass::HELICOPTERS)) != 0; bjarni@6563: } bjarni@6563: glx@8179: /** Checks if an aircraft can use the station at the tile in question glx@8179: * @param engine The engine to test glx@8179: * @param tile The tile where the station is glx@8179: * @return true if the aircraft can use the station glx@8179: */ glx@8179: static inline bool CanAircraftUseStation(EngineID engine, TileIndex tile) glx@8179: { glx@8179: return CanAircraftUseStation(engine, GetStationByTile(tile)); glx@8179: } glx@8179: belugas@6905: /** belugas@6905: * Calculates cargo capacity based on an aircraft's passenger belugas@6905: * and mail capacities. belugas@6905: * @param cid Which cargo type to calculate a capacity for. belugas@6905: * @param avi Which engine to find a cargo capacity for. belugas@6905: * @return New cargo capacity value. belugas@6905: */ rubidium@6906: uint16 AircraftDefaultCargoCapacity(CargoID cid, const AircraftVehicleInfo *avi); peter1138@3987: belugas@6911: /** belugas@6911: * This is the Callback method after the construction attempt of an aircraft belugas@6911: * @param success indicates completion (or not) of the operation belugas@6911: * @param tile of depot where aircraft is built belugas@6911: * @param p1 unused belugas@6911: * @param p2 unused belugas@6911: */ bjarni@6031: void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2); belugas@6911: belugas@6905: /** Handle Aircraft specific tasks when a an Aircraft enters a hangar belugas@6905: * @param *v Vehicle that enters the hangar belugas@6905: */ belugas@4732: void HandleAircraftEnterHangar(Vehicle *v); belugas@6905: belugas@6905: /** Get the size of the sprite of an aircraft sprite heading west (used for lists) belugas@6905: * @param engine The engine to get the sprite from belugas@6905: * @param width The width of the sprite belugas@6905: * @param height The height of the sprite belugas@6905: */ bjarni@6223: void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height); bjarni@4653: belugas@6911: /** belugas@6911: * Updates the status of the Aircraft heading or in the station belugas@6911: * @param st Station been updated belugas@6911: */ tron@6413: void UpdateAirplanesOnNewStation(const Station *st); tron@6413: peter1138@6986: /** Update cached values of an aircraft. peter1138@6986: * Currently caches callback 36 max speed. peter1138@6986: * @param v Vehicle peter1138@6986: */ peter1138@6986: void UpdateAircraftCache(Vehicle *v); peter1138@6986: rubidium@7048: /** rubidium@7048: * This class 'wraps' Vehicle; you do not actually instantiate this class. rubidium@7048: * You create a Vehicle using AllocateVehicle, so it is added to the pool rubidium@7048: * and you reinitialize that to a Train using: rubidium@7048: * v = new (v) Aircraft(); rubidium@7048: * rubidium@7048: * As side-effect the vehicle type is set correctly. rubidium@7048: */ rubidium@7048: struct Aircraft : public Vehicle { rubidium@7048: /** Initializes the Vehicle to an aircraft */ rubidium@7048: Aircraft() { this->type = VEH_AIRCRAFT; } rubidium@7048: rubidium@7048: /** We want to 'destruct' the right class. */ rubidium@7908: virtual ~Aircraft() { this->PreDestructor(); } rubidium@7048: rubidium@7059: const char *GetTypeString() const { return "aircraft"; } rubidium@7049: void MarkDirty(); rubidium@7054: void UpdateDeltaXY(Direction direction); rubidium@7059: ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_AIRCRAFT_INC : EXPENSES_AIRCRAFT_RUN; } maedhros@7269: bool IsPrimaryVehicle() const { return IsNormalAircraft(this); } peter1138@10293: SpriteID GetImage(Direction direction) const; rubidium@7973: int GetDisplaySpeed() const { return this->cur_speed * 10 / 16; } rubidium@7980: int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 16; } rubidium@7984: Money GetRunningCost() const { return AircraftVehInfo(this->engine_type)->running_cost * _price.aircraft_running; } rubidium@7986: bool IsInDepot() const { return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile); } rubidium@7631: void Tick(); glx@8963: void OnNewDay(); rubidium@9326: TileIndex GetOrderStationLocation(StationID station); rubidium@10126: bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse); rubidium@7048: }; rubidium@7048: peter1138@3987: #endif /* AIRCRAFT_H */