| 1 | /* |
| 2 | * SPDX-FileName: AIBallistic.hxx |
| 3 | * SPDX-FileComment: AIBase derived class creates an AI ballistic object |
| 4 | * SPDX-FileCopyrightText: Copyright (C) 2003 David P. Culp - [email protected] |
| 5 | * SPDX-FileContributor: With major additions by Vivian Meazza, Feb 2008 |
| 6 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include <cmath> |
| 12 | #include <string_view> |
| 13 | #include <vector> |
| 14 | |
| 15 | #include <simgear/scene/material/mat.hxx> |
| 16 | #include <simgear/structure/SGSharedPtr.hxx> |
| 17 | |
| 18 | #include "AIBase.hxx" |
| 19 | #include "AIManager.hxx" |
| 20 | |
| 21 | |
| 22 | class FGAIBallistic : public FGAIBase |
| 23 | { |
| 24 | public: |
| 25 | explicit FGAIBallistic(object_type ot = object_type::otBallistic); |
| 26 | virtual ~FGAIBallistic() = default; |
| 27 | |
| 28 | std::string_view getTypeString(void) const override { return "ballistic"; } |
| 29 | void readFromScenario(SGPropertyNode* scFileNode) override; |
| 30 | |
| 31 | bool init(ModelSearchOrder searchOrder) override; |
| 32 | void bind() override; |
| 33 | void reinit() override; |
| 34 | void update(double dt) override; |
| 35 | |
| 36 | void Run(double dt); |
| 37 | |
| 38 | void setAzimuth(double az); |
| 39 | void setElevation(double el); |
| 40 | void setAzimuthRandomError(double error); |
| 41 | void setElevationRandomError(double error); |
| 42 | void setRoll(double rl); |
| 43 | void setStabilisation(bool val); |
| 44 | void setDragArea(double a); |
| 45 | void setLife(double seconds); |
| 46 | void setBuoyancy(double fpss); |
| 47 | void setWind_from_east(double fps); |
| 48 | void setWind_from_north(double fps); |
| 49 | void setWind(bool val); |
| 50 | void setCd(double cd); |
| 51 | void setCdRandomness(double randomness); |
| 52 | void setMass(double m); |
| 53 | void setWeight(double w); |
| 54 | void setNoRoll(bool nr); |
| 55 | void setRandom(bool r); |
| 56 | void setLifeRandomness(double randomness); |
| 57 | void setCollision(bool c); |
| 58 | void setExpiry(bool e); |
| 59 | void setImpact(bool i); |
| 60 | void setImpactReportNode(const std::string&); |
| 61 | void setContentsNode(const SGPropertyNode_ptr); |
| 62 | void setFuseRange(double f); |
| 63 | void setSMPath(const std::string&); |
| 64 | void setSubID(int i); |
| 65 | void setSubmodel(const std::string&); |
| 66 | void setExternalForce(bool f); |
| 67 | void setForcePath(const std::string&); |
| 68 | void setContentsPath(const std::string&); |
| 69 | void setForceStabilisation(bool val); |
| 70 | void setGroundOffset(double g); |
| 71 | void setLoadOffset(double l); |
| 72 | void setSlaved(bool s); |
| 73 | void setSlavedLoad(bool s); |
| 74 | void setPch(double e, double dt, double c); |
| 75 | int setHdg(double az, double dt, double c); |
| 76 | void setBnk(double r, double dt, double c); |
| 77 | void setHt(double h, double dt, double c); |
| 78 | void setSpd(double s, double dt, double c); |
| 79 | void setParentNodes(const SGPropertyNode_ptr); |
| 80 | void setParentPos(); |
| 81 | void setOffsetPos(SGGeod pos, double heading, double pitch, double roll); |
| 82 | void setOffsetVelocity(double dt, SGGeod pos); |
| 83 | void setTime(double sec); |
| 84 | |
| 85 | double _getTime() const; |
| 86 | double getRelBrgHitchToUser() const; |
| 87 | double getElevHitchToUser() const; |
| 88 | double getLoadOffset() const; |
| 89 | double getContents(); |
| 90 | double getDistanceToHitch() const; |
| 91 | double getElevToHitch() const; |
| 92 | double getBearingToHitch() const; |
| 93 | |
| 94 | SGVec3d getCartHitchPos() const; |
| 95 | |
| 96 | bool getHtAGL(double start); |
| 97 | bool getSlaved() const; |
| 98 | bool getSlavedLoad() const; |
| 99 | |
| 100 | FGAIBallistic* ballistic = nullptr; |
| 101 | |
| 102 | static const double slugs_to_kgs; //conversion factor |
| 103 | static const double slugs_to_lbs; //conversion factor |
| 104 | |
| 105 | SGPropertyNode_ptr _force_node; |
| 106 | SGPropertyNode_ptr _force_azimuth_node; |
| 107 | SGPropertyNode_ptr _force_elevation_node; |
| 108 | |
| 109 | // Node for parent model |
| 110 | SGPropertyNode_ptr _pnode; |
| 111 | |
| 112 | // Nodes for parent parameters |
| 113 | SGPropertyNode_ptr _p_pos_node; |
| 114 | SGPropertyNode_ptr _p_lat_node; |
| 115 | SGPropertyNode_ptr _p_lon_node; |
| 116 | SGPropertyNode_ptr _p_alt_node; |
| 117 | SGPropertyNode_ptr _p_agl_node; |
| 118 | SGPropertyNode_ptr _p_ori_node; |
| 119 | SGPropertyNode_ptr _p_pch_node; |
| 120 | SGPropertyNode_ptr _p_rll_node; |
| 121 | SGPropertyNode_ptr _p_hdg_node; |
| 122 | SGPropertyNode_ptr _p_vel_node; |
| 123 | SGPropertyNode_ptr _p_spd_node; |
| 124 | |
| 125 | double _height; |
| 126 | double _speed; |
| 127 | double _ht_agl_ft; // height above ground level |
| 128 | double _azimuth; // degrees true |
| 129 | double _elevation; // degrees |
| 130 | double _rotation; // degrees |
| 131 | double _speed_north_fps = 0.0; |
| 132 | double _speed_east_fps = 0.0; |
| 133 | double _wind_from_east = 0.0; // fps |
| 134 | double _wind_from_north = 0.0; // fps |
| 135 | |
| 136 | double hs; |
| 137 | |
| 138 | void setTgtXOffset(double x); |
| 139 | void setTgtYOffset(double y); |
| 140 | void setTgtZOffset(double z); |
| 141 | void setTgtOffsets(double dt, double c); |
| 142 | |
| 143 | double getTgtXOffset() const; |
| 144 | double getTgtYOffset() const; |
| 145 | double getTgtZOffset() const; |
| 146 | |
| 147 | double _tgt_x_offset = 0.0; |
| 148 | double _tgt_y_offset = 0.0; |
| 149 | double _tgt_z_offset = 0.0; |
| 150 | double _elapsed_time; |
| 151 | |
| 152 | SGGeod _parentpos; |
| 153 | SGGeod _oldpos; |
| 154 | SGGeod _offsetpos; |
| 155 | SGGeod _oldoffsetpos; |
| 156 | |
| 157 | private: |
| 158 | double _az_random_error; // maximum azimuth error in degrees |
| 159 | double _el_random_error; // maximum elevation error in degrees |
| 160 | bool _aero_stabilised; // if true, object will align with trajectory |
| 161 | double _drag_area; // equivalent drag area in ft2 |
| 162 | double _cd; // current drag coefficient |
| 163 | double _init_cd; // initial drag coefficient |
| 164 | double _cd_randomness; // randomness of Cd. 1.0 means +- 100%, 0.0 means no randomness |
| 165 | double _buoyancy; // fps^2 |
| 166 | double _life_timer; // seconds |
| 167 | bool _wind; // if true, local wind will be applied to object |
| 168 | double _mass; // slugs |
| 169 | bool _random; // modifier for Cd, life, az |
| 170 | double _life_randomness; // dimension for _random, only applies to life at present |
| 171 | double _load_resistance; // ground load resistance N/m^2 |
| 172 | double _frictionFactor = 0.0; // dimensionless modifier for Coefficient of Friction |
| 173 | bool _solid; // if true ground is solid for FDMs |
| 174 | // double _elevation_m = 0.0; // ground elevation in meters |
| 175 | bool _force_stabilised; // if true, object will align to external force |
| 176 | bool _slave_to_ac; // if true, object will be slaved to the parent ac pos and orientation |
| 177 | bool _slave_load_to_ac; // if true, object will be slaved to the parent ac pos |
| 178 | double _contents_lb; // contents of the object |
| 179 | double _weight_lb = 0.0; // weight of the object (no contents if appropriate) (lbs) |
| 180 | std::string _mat_name; |
| 181 | |
| 182 | bool _report_collision; // if true a collision point with AI Objects is calculated |
| 183 | bool _report_impact; // if true an impact point on the terrain is calculated |
| 184 | bool _external_force; // if true then apply external force |
| 185 | bool _report_expiry; |
| 186 | |
| 187 | SGPropertyNode_ptr _impact_report_node; // report node for impact and collision |
| 188 | SGPropertyNode_ptr _contents_node; // node for droptank etc. contents |
| 189 | |
| 190 | double _fuse_range = 0.0; |
| 191 | |
| 192 | std::string _force_path; |
| 193 | std::string _contents_path; |
| 194 | |
| 195 | void handleEndOfLife(double); |
| 196 | void handle_collision(); |
| 197 | void handle_expiry(); |
| 198 | void handle_impact(); |
| 199 | void report_impact(double elevation, const FGAIBase* target = 0); |
| 200 | void slaveToAC(double dt); |
| 201 | void setContents(double c); |
| 202 | void calcVSHS(); |
| 203 | void calcNE(); |
| 204 | |
| 205 | SGVec3d getCartOffsetPos(SGGeod pos, double heading, double pitch, double roll) const; |
| 206 | |
| 207 | double getRecip(double az); |
| 208 | double getMass() const; |
| 209 | |
| 210 | double _ground_offset = 0.0; |
| 211 | double _load_offset = 0.0; |
| 212 | |
| 213 | SGVec3d _oldcartoffsetPos; |
| 214 | SGVec3d _oldcartPos; |
| 215 | }; |