]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIWingman.cxx
commradio: improvements for atis speech
[flightgear.git] / src / AIModel / AIWingman.cxx
index 6c93f395568124ef1e658ff57974d5f9565fc19d..7c14789971ae5079450a561e306e0f2180eee8a7 100644 (file)
 #endif
 
 #include <simgear/sg_inlines.h>
-#include <simgear/math/SGMath.hxx>
 
 
 #include "AIWingman.hxx"
 
 FGAIWingman::FGAIWingman() : FGAIBallistic(otWingman),
 _formate_to_ac(true),
-_break_angle(-90),
 _break(false),
 _join(false),
+_break_angle(-90),
 _coeff_hdg(5.0),
 _coeff_pch(5.0),
 _coeff_bnk(5.0),
@@ -81,129 +80,91 @@ void FGAIWingman::bind() {
 
     props->untie("controls/slave-to-ac");
 
-    props->tie("id", SGRawValueMethods<FGAIBase,int>(*this,
+    tie("id", SGRawValueMethods<FGAIBase,int>(*this,
         &FGAIBase::getID));
-    props->tie("subID", SGRawValueMethods<FGAIBase,int>(*this,
+    tie("subID", SGRawValueMethods<FGAIBase,int>(*this,
         &FGAIBase::_getSubID));
-    props->tie("position/altitude-ft",
+    tie("position/altitude-ft",
         SGRawValueMethods<FGAIBase,double>(*this,
         &FGAIBase::_getElevationFt,
         &FGAIBase::_setAltitude));
-    props->tie("position/latitude-deg",
+    tie("position/latitude-deg",
         SGRawValueMethods<FGAIBase,double>(*this,
         &FGAIBase::_getLatitude,
         &FGAIBase::_setLatitude));
-    props->tie("position/longitude-deg",
+    tie("position/longitude-deg",
         SGRawValueMethods<FGAIBase,double>(*this,
         &FGAIBase::_getLongitude,
         &FGAIBase::_setLongitude));
 
-    props->tie("controls/break", SGRawValuePointer<bool>(&_break));
-    props->tie("controls/join", SGRawValuePointer<bool>(&_join));
+    tie("controls/break", SGRawValuePointer<bool>(&_break));
+    tie("controls/join", SGRawValuePointer<bool>(&_join));
 
-    props->tie("controls/formate-to-ac",
+    tie("controls/formate-to-ac",
         SGRawValueMethods<FGAIWingman,bool>
         (*this, &FGAIWingman::getFormate, &FGAIWingman::setFormate));
-    props->tie("controls/tgt-heading-deg",
+    tie("controls/tgt-heading-deg",
         SGRawValueMethods<FGAIWingman,double>
         (*this, &FGAIWingman::getTgtHdg, &FGAIWingman::setTgtHdg));
-    props->tie("controls/tgt-speed-kt",
+    tie("controls/tgt-speed-kt",
         SGRawValueMethods<FGAIWingman,double>
         (*this, &FGAIWingman::getTgtSpd, &FGAIWingman::setTgtSpd));
-    props->tie("controls/break-deg-rel",
+    tie("controls/break-deg-rel",
         SGRawValueMethods<FGAIWingman,double>
         (*this, &FGAIWingman::getBrkAng, &FGAIWingman::setBrkAng));
-    props->tie("controls/coefficients/heading",
+    tie("controls/coefficients/heading",
         SGRawValuePointer<double>(&_coeff_hdg));
-    props->tie("controls/coefficients/pitch",
+    tie("controls/coefficients/pitch",
         SGRawValuePointer<double>(&_coeff_pch));
-    props->tie("controls/coefficients/bank",
+    tie("controls/coefficients/bank",
         SGRawValuePointer<double>(&_coeff_bnk));
-    props->tie("controls/coefficients/speed",
+    tie("controls/coefficients/speed",
         SGRawValuePointer<double>(&_coeff_spd));
 
-    props->tie("orientation/pitch-deg",   SGRawValuePointer<double>(&pitch));
-    props->tie("orientation/roll-deg",    SGRawValuePointer<double>(&roll));
-    props->tie("orientation/true-heading-deg", SGRawValuePointer<double>(&hdg));
+    tie("orientation/pitch-deg",   SGRawValuePointer<double>(&pitch));
+    tie("orientation/roll-deg",    SGRawValuePointer<double>(&roll));
+    tie("orientation/true-heading-deg", SGRawValuePointer<double>(&hdg));
 
-    props->tie("submodels/serviceable", SGRawValuePointer<bool>(&serviceable));
+    tie("submodels/serviceable", SGRawValuePointer<bool>(&serviceable));
 
-    props->tie("load/rel-brg-to-user-deg",
+    tie("load/rel-brg-to-user-deg",
         SGRawValueMethods<FGAIBallistic,double>
         (*this, &FGAIBallistic::getRelBrgHitchToUser));
-    props->tie("load/elev-to-user-deg",
+    tie("load/elev-to-user-deg",
         SGRawValueMethods<FGAIBallistic,double>
         (*this, &FGAIBallistic::getElevHitchToUser));
 
-    props->tie("velocities/vertical-speed-fps",
+    tie("velocities/vertical-speed-fps",
         SGRawValuePointer<double>(&vs));
-    props->tie("velocities/true-airspeed-kt",
+    tie("velocities/true-airspeed-kt",
         SGRawValuePointer<double>(&speed));
-    props->tie("velocities/speed-east-fps",
+    tie("velocities/speed-east-fps",
         SGRawValuePointer<double>(&_speed_east_fps));
-    props->tie("velocities/speed-north-fps",
+    tie("velocities/speed-north-fps",
         SGRawValuePointer<double>(&_speed_north_fps));
 
-    props->tie("position/x-offset", 
+    tie("position/x-offset",
         SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getXOffset, &FGAIBase::setXoffset));
-    props->tie("position/y-offset", 
+    tie("position/y-offset",
         SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getYOffset, &FGAIBase::setYoffset));
-    props->tie("position/z-offset", 
+    tie("position/z-offset",
         SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getZOffset, &FGAIBase::setZoffset));
-    props->tie("position/tgt-x-offset", 
+    tie("position/tgt-x-offset",
         SGRawValueMethods<FGAIBallistic,double>(*this, &FGAIBallistic::getTgtXOffset, &FGAIBallistic::setTgtXOffset));
-    props->tie("position/tgt-y-offset", 
+    tie("position/tgt-y-offset",
         SGRawValueMethods<FGAIBallistic,double>(*this, &FGAIBallistic::getTgtYOffset, &FGAIBallistic::setTgtYOffset));
-    props->tie("position/tgt-z-offset", 
+    tie("position/tgt-z-offset",
         SGRawValueMethods<FGAIBallistic,double>(*this, &FGAIBallistic::getTgtZOffset, &FGAIBallistic::setTgtZOffset));
 }
 
-void FGAIWingman::unbind() {
-    FGAIBallistic::unbind();
-
-    props->untie("id");
-    props->untie("SubID");
-
-    props->untie("orientation/pitch-deg");
-    props->untie("orientation/roll-deg");
-    props->untie("orientation/true-heading-deg");
-
-    props->untie("controls/formate-to-ac");
-    props->untie("controls/break");
-    props->untie("controls/join");
-    props->untie("controls/tgt-heading-deg");
-    props->untie("controls/tgt-speed-kt");
-    props->untie("controls/break-deg-rel");
-    props->untie("controls/coefficients/heading");
-    props->untie("controls/coefficients/pitch");
-    props->untie("controls/coefficients/bank");
-    props->untie("controls/coefficients/speed");
-
-    props->untie("submodels/serviceable");
-
-    props->untie("velocities/true-airspeed-kt");
-    props->untie("velocities/vertical-speed-fps");
-    props->untie("velocities/speed_east_fps");
-    props->untie("velocities/speed_north_fps");
-
-    props->untie("load/rel-brg-to-user-deg");
-    props->untie("load/elev-to-user-deg");
-
-    props->untie("position/altitude-ft");
-    props->untie("position/latitude-deg");
-    props->untie("position/longitude-deg");
-    props->untie("position/x-offset");
-    props->untie("position/y-offset");
-    props->untie("position/z-offset");
-    props->untie("position/tgt-x-offset");
-    props->untie("position/tgt-y-offset");
-    props->untie("position/tgt-z-offset");
-}
-
 bool FGAIWingman::init(bool search_in_AI_path) {
     if (!FGAIBallistic::init(search_in_AI_path))
         return false;
+    reinit();
+    return true;
+}
 
+void FGAIWingman::reinit() {
     invisible = false;
 
     _tgt_x_offset = _x_offset;
@@ -215,14 +176,16 @@ bool FGAIWingman::init(bool search_in_AI_path) {
     roll = _rotation;
     _ht_agl_ft = 1e10;
 
-    props->setStringValue("submodels/path", _path.c_str());
-
     if(_parent != ""){
         setParentNode();
     }
 
     setParentNodes(_selected_ac);
-    return true;
+
+    props->setStringValue("submodels/path", _path.c_str());
+    user_WoW_node      = fgGetNode("gear/gear[1]/wow", true);
+
+    FGAIBallistic::reinit();
 }
 
 void FGAIWingman::update(double dt) {
@@ -277,7 +240,7 @@ double FGAIWingman::calcAngle(double range, SGGeod pos1, SGGeod pos2){
 
 void FGAIWingman::formateToAC(double dt){
 
-    double p_hdg, p_pch, p_rll, p_agl, p_ht = 0;
+    double p_hdg, p_pch, p_rll, p_agl, p_ht, p_wow = 0;
 
     setTgtOffsets(dt, 25);
 
@@ -290,12 +253,11 @@ void FGAIWingman::formateToAC(double dt){
         setOffsetPos(_parentpos, p_hdg, p_pch, p_rll);
         setSpeed(_p_spd_node->getDoubleValue());
     }else {
-        _setUserPos();
         p_hdg = manager->get_user_heading();
         p_pch = manager->get_user_pitch();
         p_rll = manager->get_user_roll();
-        p_ht  = manager->get_user_altitude();
-        setOffsetPos(userpos, p_hdg,p_pch, p_rll);
+        p_ht  = globals->get_aircraft_position().getElevationFt();
+        setOffsetPos(globals->get_aircraft_position(), p_hdg,p_pch, p_rll);
         setSpeed(manager->get_user_speed());
     }
 
@@ -312,8 +274,9 @@ void FGAIWingman::formateToAC(double dt){
     double h_feet  = 3 * factor;
 
     p_agl = manager->get_user_agl();
+    p_wow = user_WoW_node->getDoubleValue();
 
-    if(p_agl <= 10) {
+    if(p_agl <= 10 || p_wow == 1) {
         _height = p_ht;
         //cout << "ht case1 " ;
     } else if (p_agl > 10 && p_agl <= 150 ) {
@@ -332,7 +295,8 @@ void FGAIWingman::formateToAC(double dt){
     pos.setLongitudeDeg(_offsetpos.getLongitudeDeg());
 
     // these calculations are unreliable at slow speeds
-    if(speed >= 10) {
+    // and we don't want random movement on the ground
+    if(speed >= 10 && p_wow != 1) {
         setHdg(p_hdg + h_angle, dt, 0.9);
         setPch(p_pch + p_angle + _pitch_offset, dt, 0.9);
 
@@ -372,7 +336,7 @@ void FGAIWingman::Break(double dt) {
 void FGAIWingman::Join(double dt) {
 
     double range, bearing, az2;
-    double parent_hdg, parent_spd, parent_ht= 0;
+    double parent_hdg, parent_spd = 0;
     double p_hdg, p_pch, p_rll = 0;
 
     setTgtOffsets(dt, 25);
@@ -386,11 +350,10 @@ void FGAIWingman::Join(double dt) {
         parent_hdg = _p_hdg_node->getDoubleValue();
         parent_spd = _p_spd_node->getDoubleValue();
     }else {
-        _setUserPos();
         p_hdg = manager->get_user_heading();
         p_pch = manager->get_user_pitch();
         p_rll = manager->get_user_roll();
-        setOffsetPos(userpos, p_hdg, p_pch, p_rll);
+        setOffsetPos(globals->get_aircraft_position(), p_hdg, p_pch, p_rll);
         parent_hdg = manager->get_user_heading();
         parent_spd = manager->get_user_speed();
     }
@@ -411,7 +374,7 @@ void FGAIWingman::Join(double dt) {
             _formate_to_ac = true;
             _join = false;
 
-            SG_LOG(SG_GENERAL, SG_ALERT, _name << " joined " << " RANGE " << distance
+            SG_LOG(SG_AI, SG_ALERT, _name << " joined " << " RANGE " << distance
             << " SPEED " << speed );
 
             return;
@@ -422,10 +385,10 @@ void FGAIWingman::Join(double dt) {
     double rel_brg   = calcRelBearingDeg(bearing, hdg);
     double recip_brg = calcRecipBearingDeg(bearing);
     double angle = calcAngle(distance,_offsetpos, pos);
-    double approx_angle = atan2(daltM, range);
+    //double approx_angle = atan2(daltM, range);
     double frm_spd = 50; // formation speed
     double join_rnge = 1000.0;
-    double recip_parent_hdg = calcRecipBearingDeg(parent_hdg);
+//    double recip_parent_hdg = calcRecipBearingDeg(parent_hdg);
     int turn = SGMiscd::sign(rel_brg);// turn direction: 1 = right, -1 = left
 
     if (range <= join_rnge && (hdg >= hdg_l_lim || hdg <= hdg_r_lim)){