]> git.mxchange.org Git - flightgear.git/commitdiff
Make startup.nas obsolete
authorTorsten Dreyer <Torsten@t3r.de>
Wed, 10 Nov 2010 21:19:25 +0000 (22:19 +0100)
committerTorsten Dreyer <Torsten@t3r.de>
Wed, 10 Nov 2010 21:19:25 +0000 (22:19 +0100)
This is an ugly hack for automatic runway selection on startup based on
metar data. It's main intention is to make startup.nas obsolete and
to guarantee the same runway selection logic as used for AI traffic.

Calling presets-commit from startup.nas during the initialization
sequence caused occasional trouble and sometimes, the AI traffic
operated on the opposite runway.

src/Main/fg_init.cxx
src/Main/main.cxx

index 65be585e420f1d896548177fe2c1235bc10e6803..e9592c14e68467f425e015de9322048005a06bad 100644 (file)
@@ -820,7 +820,7 @@ static void fgApplyStartOffset(const SGGeod& aStartPos, double aHeading, double
 }
 
 // Set current_options lon/lat given an airport id and heading (degrees)
-static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
+bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
     if ( id.empty() )
         return false;
 
index 0113c1b18c6408a3c31a10321459e8f26f2941b6..9372f9cc915d00a03c3886d766a78eaf77079f72 100644 (file)
@@ -46,7 +46,7 @@
 #include <simgear/structure/event_mgr.hxx>
 #include <simgear/props/AtomicChangeListener.hxx>
 #include <simgear/props/props.hxx>
-#include <simgear/timing/sg_time.hxx>
+//#include <simgear/timing/sg_time.hxx>
 #include <simgear/math/sg_random.h>
 #include <simgear/io/raw_socket.hxx>
 
@@ -469,8 +469,29 @@ static void fgIdleFunction ( void ) {
                 "Subsystem initialization failed ..." );
             exit(-1);
         }
-        fgSplashProgress("setting up time & renderer");
 
+        // Torsten Dreyer:
+        // ugly hack for automatic runway selection on startup based on
+        // metar data. Makes startup.nas obsolete and guarantees the same
+        // runway selection as for AI traffic. However, this code belongs to
+        // somewhere(?) else - if I only new where...
+        if( true == fgGetBool( "/environment/metar/valid" ) ) {
+            // the realwx_ctrl fetches metar in the foreground on init,
+            // If it was able to fetch a metar or one was given on the commandline,
+            // the valid flag is set here, otherwise it is false
+            double hdg = fgGetDouble( "/environment/metar/base-wind-dir-deg", 9999.0 );
+            string apt = fgGetString( "/sim/startup/options/airport" );
+            string rwy = fgGetString( "/sim/startup/options/runway" );
+            double strthdg = fgGetDouble( "/sim/startup/options/heading-deg", 9999.0 );
+            bool onground = fgGetBool( "/sim/presets/onground", false );
+            // don't check for wind-speed < 1kt, this belongs to the runway-selection code
+            // the other logic is taken from former startup.nas
+            if( hdg < 360.0 && apt.length() > 0 && strthdg > 360.0 && rwy.length() == 0 && onground ) {
+                extern bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg );
+                fgSetPosFromAirportIDandHdg( apt, hdg );
+            }
+        }
+        fgSplashProgress("setting up time & renderer");
 
     } else if ( idle_state == 8 ) {
         idle_state = 1000;