diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 65be585e4..e9592c14e 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -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; diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 0113c1b18..9372f9cc9 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -46,7 +46,7 @@ #include #include #include -#include +//#include #include #include @@ -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;