]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/route_mgr.cxx
Create a "passive" mode for the autopilot. This is analogous to running the
[flightgear.git] / src / Autopilot / route_mgr.cxx
index 0fe2d7f433957373d55930395c92f32458dc3108..f9175aa1e3e3fb89c3ca1b8e1a079d36bdfe523f 100644 (file)
@@ -68,8 +68,8 @@ FGRouteMgr::FGRouteMgr() :
 
 
 FGRouteMgr::~FGRouteMgr() {
-    delete route;
     input->removeChangeListener(listener);
+    delete route;
 }
 
 
@@ -144,7 +144,7 @@ void FGRouteMgr::update( double dt ) {
             target_altitude_ft->setDoubleValue( target_alt * SG_METER_TO_FEET );
             altitude_set = true;
 
-            if ( !on_ground() )
+            if ( !near_ground() )
                 altitude_lock->setStringValue( "altitude-hold" );
         }
 
@@ -280,14 +280,7 @@ bool FGRouteMgr::build() {
 }
 
 
-int FGRouteMgr::new_waypoint( const string& Tgt_Alt, int n ) {
-    string target = Tgt_Alt;
-
-    // make upper case
-    for (unsigned int i = 0; i < target.size(); i++)
-        if (target[i] >= 'a' && target[i] <= 'z')
-            target[i] -= 'a' - 'A';
-
+int FGRouteMgr::new_waypoint( const string& target, int n ) {
     SGWayPoint *wp = 0;
     int type = make_waypoint( &wp, target );
 
@@ -295,18 +288,24 @@ int FGRouteMgr::new_waypoint( const string& Tgt_Alt, int n ) {
         add_waypoint( *wp, n );
         delete wp;
 
-        if ( !on_ground() )
+        if ( !near_ground() )
             fgSetString( "/autopilot/locks/heading", "true-heading-hold" );
     }
     return type;
 }
 
 
-int FGRouteMgr::make_waypoint(SGWayPoint **wp, string& target) {
-    double alt = -9999.0;
+int FGRouteMgr::make_waypoint( SGWayPoint **wp, const string& tgt ) {
+    string target = tgt;
+
+    // make upper case
+    for (unsigned int i = 0; i < target.size(); i++)
+        if (target[i] >= 'a' && target[i] <= 'z')
+            target[i] -= 'a' - 'A';
 
     // extract altitude
-    unsigned int pos = target.find( '@' );
+    double alt = -9999.0;
+    size_t pos = target.find( '@' );
     if ( pos != string::npos ) {
         alt = atof( target.c_str() + pos + 1 );
         target = target.substr( 0, pos );
@@ -391,11 +390,15 @@ void FGRouteMgr::update_mirror() {
 }
 
 
-bool FGRouteMgr::on_ground() {
+bool FGRouteMgr::near_ground() {
     SGPropertyNode *gear = fgGetNode( "/gear/gear/wow", false );
     if ( !gear || gear->getType() == SGPropertyNode::NONE )
         return fgGetBool( "/sim/presets/onground", true );
 
+    if ( fgGetDouble("/position/altitude-agl-ft", 300.0)
+            < fgGetDouble("/autopilot/route-manager/min-lock-altitude-agl-ft") )
+        return true;
+
     return gear->getBoolValue();
 }