]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
Exposed the fg_commands though the httpd interface.
[flightgear.git] / src / Main / fg_init.cxx
index ac84226de9be0ce3002e1c382c7901ebae9d2751..ec7e640e12191ba1fba5018d89d01a23a411bb02 100644 (file)
@@ -576,6 +576,22 @@ bool fgFindAirportID( const string& id, FGAirport *a ) {
 }
 
 
+// get airport elevation
+static double fgGetAirportElev( const string& id ) {
+    FGAirport a;
+    // double lon, lat;
+
+    SG_LOG( SG_GENERAL, SG_INFO,
+            "Finding elevation for airport: " << id );
+
+    if ( fgFindAirportID( id, &a ) ) {
+        return a.elevation;
+    } else {
+        return -9999.0;
+    }
+}
+
+
 // Preset lon/lat given an airport id
 static bool fgSetPosFromAirportID( const string& id ) {
     FGAirport a;
@@ -602,11 +618,9 @@ static bool fgSetPosFromAirportID( const string& id ) {
     } else {
         return false;
     }
-
 }
 
 
-
 // Set current tower position lon/lat given an airport id
 static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
     FGAirport a;
@@ -752,6 +766,7 @@ static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) {
     FGRunway found_r;
     double heading = 0.0;
     string runway;
+    bool match = false;
 
     // standardize input number
     string tmp = rwy.substr(1, 1);
@@ -785,6 +800,7 @@ static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) {
             if ( r.rwy_no == runway ) {
                 found_r = r;
                 heading = r.heading;
+                match = true;
                 SG_LOG( SG_GENERAL, SG_INFO,
                         "Runway " << r.rwy_no << " heading = " << heading );
             }
@@ -827,6 +843,7 @@ static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) {
                 found_r = r;
                 heading = r.heading + 180;
                 while ( heading > 360.0 ) { heading -= 360; }
+                match = true;
                 SG_LOG( SG_GENERAL, SG_INFO,
                         "Runway " << r.rwy_no << " heading = " << heading );
             }
@@ -837,68 +854,87 @@ static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) {
         return false;
     }
 
-    double lat2, lon2, az2;
-    double azimuth = heading + 180.0;
-    while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
+    if ( match ) {
+        double lat2, lon2, az2;
+        double azimuth = heading + 180.0;
+        while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
 
-    SG_LOG( SG_GENERAL, SG_INFO,
-            "runway =  " << found_r.lon << ", " << found_r.lat
-            << " length = " << found_r.length * SG_FEET_TO_METER * 0.5 
-            << " heading = " << azimuth );
+        SG_LOG( SG_GENERAL, SG_INFO,
+                "runway =  " << found_r.lon << ", " << found_r.lat
+                << " length = " << found_r.length * SG_FEET_TO_METER * 0.5 
+                << " heading = " << azimuth );
     
-    geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon, 
-                        azimuth, found_r.length * SG_FEET_TO_METER * 0.5 - 5.0,
-                        &lat2, &lon2, &az2 );
+        geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon, 
+                            azimuth,
+                            found_r.length * SG_FEET_TO_METER * 0.5 - 5.0,
+                            &lat2, &lon2, &az2 );
 
-    if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON ) {
-        double olat, olon;
-        double odist = fgGetDouble("/sim/presets/offset-distance");
-        odist *= SG_NM_TO_METER;
-        double oaz = azimuth;
-        if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON ) {
-            oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
+        if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
+        {
+            double olat, olon;
+            double odist = fgGetDouble("/sim/presets/offset-distance");
+            odist *= SG_NM_TO_METER;
+            double oaz = azimuth;
+            if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON )
+            {
+                oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
+            }
+            while ( oaz >= 360.0 ) { oaz -= 360.0; }
+            geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
+            lat2=olat;
+            lon2=olon;
         }
-        while ( oaz >= 360.0 ) { oaz -= 360.0; }
-        geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
-        lat2=olat;
-        lon2=olon;
-    }
 
-    // presets
-    fgSetDouble("/sim/presets/longitude-deg",  lon2 );
-    fgSetDouble("/sim/presets/latitude-deg",  lat2 );
-    fgSetDouble("/sim/presets/heading-deg", heading );
+        // presets
+        fgSetDouble("/sim/presets/longitude-deg",  lon2 );
+        fgSetDouble("/sim/presets/latitude-deg",  lat2 );
+        fgSetDouble("/sim/presets/heading-deg", heading );
 
-    // other code depends on the actual values being set ...
-    fgSetDouble("/position/longitude-deg",  lon2 );
-    fgSetDouble("/position/latitude-deg",  lat2 );
-    fgSetDouble("/orientation/heading-deg", heading );
+        // other code depends on the actual values being set ...
+        fgSetDouble("/position/longitude-deg",  lon2 );
+        fgSetDouble("/position/latitude-deg",  lat2 );
+        fgSetDouble("/orientation/heading-deg", heading );
 
-    SG_LOG( SG_GENERAL, SG_INFO,
-            "Position for " << id << " is ("
-            << lon2 << ", "
-            << lat2 << ") new heading is "
-            << heading );
+        SG_LOG( SG_GENERAL, SG_INFO,
+                "Position for " << id << " is ("
+                << lon2 << ", "
+                << lat2 << ") new heading is "
+                << heading );
 
-    return true;
+        return true;
+    } else {
+        return false;
+    }
 }
 
 
 static void fgSetDistOrAltFromGlideSlope() {
-    double gs = fgGetDouble("/sim/presets/glideslope");
+    string apt_id = fgGetString("/sim/presets/airport-id");
+    double gs = fgGetDouble("/sim/presets/glideslope-deg")
+        * SG_DEGREES_TO_RADIANS ;
     double od = fgGetDouble("/sim/presets/offset-distance");
     double alt = fgGetDouble("/sim/presets/altitude-ft");
-    
+
+    double apt_elev = 0.0;
+    if ( ! apt_id.empty() ) {
+        apt_elev = fgGetAirportElev( apt_id );
+        if ( apt_elev < -9990.0 ) {
+            apt_elev = 0.0;
+        }
+    } else {
+        apt_elev = 0.0;
+    }
+
     if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
         // set altitude from glideslope and offset-distance
         od *= SG_NM_TO_METER * SG_METER_TO_FEET;
-        alt = fabs(od*tan(gs));
+        alt = fabs(od*tan(gs)) + apt_elev;
         fgSetDouble("/sim/presets/altitude-ft", alt);
         fgSetBool("/sim/presets/onground", false);
         SG_LOG(SG_GENERAL,SG_INFO, "Calculated altitude as: " << alt  << " ft");
     } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
         // set offset-distance from glideslope and altitude
-        od  = alt/tan(gs);
+        od  = (alt - apt_elev) / tan(gs);
         od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
         fgSetDouble("/sim/presets/offset-distance", od);
         SG_LOG(SG_GENERAL, SG_INFO, "Calculated offset distance as: " 
@@ -907,7 +943,8 @@ static void fgSetDistOrAltFromGlideSlope() {
         SG_LOG( SG_GENERAL, SG_ALERT,
                 "Glideslope given but not altitude or offset-distance." );
         SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
-        fgSetDouble("/sim/presets/glideslope", 0);
+        fgSetDouble("/sim/presets/glideslope-deg", 0);
+        fgSetBool("/sim/presets/onground", true);
     }                              
 }                       
 
@@ -1186,7 +1223,7 @@ SGTime *fgInitTime() {
 // initialization routines.  If you are adding a subsystem to flight
 // gear, its initialization call should located in this routine.
 // Returns non-zero if a problem encountered.
-bool fgInitSubsystems( void ) {
+bool fgInitSubsystems() {
     static const SGPropertyNode *longitude
         = fgGetNode("/sim/presets/longitude-deg");
     static const SGPropertyNode *latitude
@@ -1231,9 +1268,7 @@ bool fgInitSubsystems( void ) {
         // Load the local scenery data
         double visibility_meters = fgGetDouble("/environment/visibility-m");
                 
-        global_tile_mgr.update( longitude->getDoubleValue(),
-                                latitude->getDoubleValue(),
-                                visibility_meters );
+        global_tile_mgr.update( visibility_meters );
     } else {
         SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
         exit(-1);
@@ -1601,7 +1636,7 @@ bool fgInitSubsystems( void ) {
 }
 
 
-void fgReInitSubsystems( void )
+void fgReInitSubsystems()
 {
     static const SGPropertyNode *longitude
         = fgGetNode("/sim/presets/longitude-deg");
@@ -1620,12 +1655,8 @@ void fgReInitSubsystems( void )
     if ( !freeze ) {
         fgSetBool("/sim/freeze/master", true);
     }
-    
-    // Initialize the Scenery Management subsystem
-    // FIXME, what really needs to get initialized here, at the time
-    // this was commented out, scenery.init() was a noop
-    // scenery.init();
 
+    // Initialize the FDM
     fgInitFDM();
     
     // allocates structures so must happen before any of the flight