| 1 | /* |
| 2 | * SPDX-FileName: AICarrier.hxx |
| 3 | * SPDX-FileComment: AIShip-derived class creates an AI aircraft carrier |
| 4 | * SPDX-FileCopyrightText: Copyright (C) 2004 David P. Culp - [email protected] |
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 6 | */ |
| 7 | |
| 8 | #pragma once |
| 9 | |
| 10 | #include <list> |
| 11 | #include <string> |
| 12 | #include <string_view> |
| 13 | |
| 14 | #include <simgear/compiler.h> |
| 15 | #include <simgear/emesary/Emesary.hxx> |
| 16 | |
| 17 | #include "AIShip.hxx" |
| 18 | #include "AIBase.hxx" |
| 19 | #include "AIManager.hxx" |
| 20 | |
| 21 | |
| 22 | class FGAIManager; |
| 23 | class FGAICarrier; |
| 24 | |
| 25 | class FGAICarrier : public FGAIShip, simgear::Emesary::IReceiver |
| 26 | { |
| 27 | public: |
| 28 | FGAICarrier(); |
| 29 | virtual ~FGAICarrier(); |
| 30 | |
| 31 | std::string_view getTypeString(void) const override { return "carrier"; } |
| 32 | void readFromScenario(SGPropertyNode* scFileNode) override; |
| 33 | |
| 34 | void setSign(const std::string&); |
| 35 | void setDeckAltitudeFt(const double altitude_feet); |
| 36 | void setTACANChannelID(const std::string&); |
| 37 | double getDefaultModelRadius() override { return 350.0; } |
| 38 | |
| 39 | void bind() override; |
| 40 | void UpdateWind(double dt); |
| 41 | void setWind_from_east(double fps); |
| 42 | void setWind_from_north(double fps); |
| 43 | void setMaxLat(double deg); |
| 44 | void setMinLat(double deg); |
| 45 | void setMaxLong(double deg); |
| 46 | void setMinLong(double deg); |
| 47 | void setMPControl(bool c); |
| 48 | void setAIControl(bool c); |
| 49 | void TurnToLaunch(); |
| 50 | void TurnToRecover(); |
| 51 | void TurnToBase(); |
| 52 | void ReturnToBox(); |
| 53 | bool OutsideBox(); |
| 54 | |
| 55 | bool init(ModelSearchOrder searchOrder) override; |
| 56 | |
| 57 | bool getParkPosition(const std::string& id, SGGeod& geodPos, double& hdng, SGVec3d& uvw); |
| 58 | |
| 59 | /** |
| 60 | * @brief type-safe wrapper around AIManager::getObjectFromProperty |
| 61 | */ |
| 62 | static SGSharedPtr<FGAICarrier> findCarrierByNameOrPennant(const std::string& namePennant); |
| 63 | |
| 64 | static std::pair<bool, SGGeod> initialPositionForCarrier(const std::string& namePennant); |
| 65 | |
| 66 | /** |
| 67 | * for a given scenario node, check for carriers within, and write nodes with |
| 68 | * names, pennants and initial position into the second argument. |
| 69 | * This is used to support 'start on a carrier', since we can quickly find |
| 70 | * the corresponding scenario file to be loaded. |
| 71 | */ |
| 72 | static void extractCarriersFromScenario(SGPropertyNode_ptr xmlNode, SGPropertyNode_ptr scenario); |
| 73 | |
| 74 | bool getFLOLSPositionHeading(SGGeod& pos, double& heading) const; |
| 75 | |
| 76 | double getFLOLFSGlidepathAngleDeg() const; |
| 77 | double getDeckAltitudeFt() const { return _deck_altitude_ft; } |
| 78 | virtual simgear::Emesary::ReceiptStatus Receive(simgear::Emesary::INotificationPtr n) override; |
| 79 | |
| 80 | private: |
| 81 | /// Is sufficient to be private, stores a possible position to place an |
| 82 | /// aircraft on start |
| 83 | struct ParkPosition { |
| 84 | explicit ParkPosition(const ParkPosition& pp) |
| 85 | : name(pp.name), offset(pp.offset), heading_deg(pp.heading_deg) |
| 86 | { |
| 87 | } |
| 88 | ParkPosition(const std::string& n, const SGVec3d& off = SGVec3d(), double heading = 0) |
| 89 | : name(n), offset(off), heading_deg(heading) |
| 90 | { |
| 91 | } |
| 92 | |
| 93 | std::string name; |
| 94 | SGVec3d offset; |
| 95 | double heading_deg; |
| 96 | }; |
| 97 | |
| 98 | void update(double dt) override; |
| 99 | bool InToWind(); // set if the carrier is in to wind |
| 100 | void UpdateElevator(double dt); |
| 101 | void UpdateJBD(double dt); |
| 102 | |
| 103 | bool _AIControl = false; // under AI control. Either this or MPControl will be true |
| 104 | SGPropertyNode_ptr _ai_latch_node; |
| 105 | SGPropertyNode_ptr _altitude_node; |
| 106 | double _angled_deck_degrees = -8.55; // angled deck offset from carrier heading. usually negative |
| 107 | double _base_course = 0; |
| 108 | double _base_speed = 0; |
| 109 | double _deck_altitude_ft = 65.0065; |
| 110 | double _elevator_pos_norm = 0; |
| 111 | double _elevator_pos_norm_raw = 0; |
| 112 | double _elevator_time_constant = 0; |
| 113 | double _elevator_transition_time = 0; |
| 114 | bool _elevators = false; |
| 115 | double _flols_angle = 0; |
| 116 | double _flols_dist = 0; // the distance of the eyepoint from the flols |
| 117 | int _flols_visible_light = 0; // the flols light which is visible at the moment |
| 118 | SGPropertyNode_ptr _flols_x_node; |
| 119 | SGPropertyNode_ptr _flols_y_node; |
| 120 | SGPropertyNode_ptr _flols_z_node; |
| 121 | double _flolsApproachAngle = 3.0; ///< glidepath angle for the FLOLS |
| 122 | double _flolsHeadingOffsetDeg = 0.0; /// angle in degrees offset from the carrier centerline |
| 123 | SGVec3d _flolsPosOffset; |
| 124 | SGVec3d _flolsTouchdownPosition; |
| 125 | SGPropertyNode_ptr _heading_node; |
| 126 | bool _in_to_wind = false; |
| 127 | bool _jbd = false; |
| 128 | double _jbd_elevator_pos_norm = 0; |
| 129 | double _jbd_elevator_pos_norm_raw = 0; |
| 130 | double _jbd_time_constant = 0; |
| 131 | double _jbd_transition_time = 0; |
| 132 | SGPropertyNode_ptr _latitude_node; |
| 133 | SGPropertyNode_ptr _launchbar_state_node; |
| 134 | double _lineup = 0; // lineup angle deviation from carrier; |
| 135 | SGPropertyNode_ptr _longitude_node; |
| 136 | SGVec3d _lsoPosition; /// LSO position |
| 137 | double _max_lat = 0; |
| 138 | double _max_lon = 0; |
| 139 | double _min_lat = 0; |
| 140 | double _min_lon = 0; |
| 141 | SGGeod _mOpBoxPos; // operational box limit for carrier. |
| 142 | bool _MPControl = false; // being controlled by MP. Either this or AIControl will be true |
| 143 | SGPropertyNode_ptr _pitch_node; |
| 144 | std::list<ParkPosition> _ppositions; // List of positions where an aircraft can start. |
| 145 | double _rel_wind = 0; |
| 146 | double _rel_wind_from_deg = 0; |
| 147 | double _rel_wind_speed_kts = 0; |
| 148 | bool _returning = false; // set if the carrier is returning to an operating box |
| 149 | SGPropertyNode_ptr _roll_node; |
| 150 | std::string _sign; // The sign (pennant) of this carrier; e.g. CVN-68 |
| 151 | SGPropertyNode_ptr _surface_wind_from_deg_node; |
| 152 | SGPropertyNode_ptr _surface_wind_speed_node; |
| 153 | std::string _TACAN_channel_id; |
| 154 | SGVec3d _towerPosition; |
| 155 | bool _turn_to_base_course = true; |
| 156 | bool _turn_to_launch_hdg = true; |
| 157 | bool _turn_to_recovery_hdg = true; |
| 158 | int _view_index = 0; |
| 159 | SGPropertyNode_ptr _view_position_alt_ft_node; |
| 160 | SGPropertyNode_ptr _view_position_lat_deg_node; |
| 161 | SGPropertyNode_ptr _view_position_lon_deg_node; |
| 162 | bool _wave_off_lights_demand = false; // when waveoff requested. |
| 163 | double _wind_from_deg = 0; //true wind direction |
| 164 | double _wind_from_east = 0; // fps |
| 165 | double _wind_from_north = 0; // fps |
| 166 | double _wind_speed_kts = 0; //true wind speed |
| 167 | SGPropertyNode_ptr _is_user_craft; |
| 168 | }; |