From 9242f3a083ac53486053cb41fe36f08c3370e02b Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Wed, 10 Nov 2010 22:19:25 +0100 Subject: [PATCH] Make startup.nas obsolete 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 | 2 +- src/Main/main.cxx | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) 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; -- 2.39.5