From 81b266aa4a583942a2c11365baa6e44aac6a3af1 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 21 Jul 2000 22:54:14 +0000 Subject: [PATCH] Try to set initial position in a bit more intelligent way (and earlier in the process so time initialization can have a chance to work.) --- src/Main/fg_init.cxx | 45 ++++++++++++++++++++++++++++++-------------- src/Main/fg_init.hxx | 4 ++++ src/Main/main.cxx | 5 +++++ 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 6235493ff..5fb58c971 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -136,14 +136,11 @@ bool fgInitConfig ( int argc, char **argv ) { } -// Set initial position and orientation -bool fgInitPosition( void ) { - string id; - FGInterface *f; - - f = current_aircraft.fdm_state; +// Set current_options lon/lat given an airport id +bool fgSetPosFromAirportID( const string& id ) { + FGAirport a; + double lon, lat; - id = current_options.get_airport_id(); if ( id.length() ) { // set initial position from airport id @@ -151,7 +148,6 @@ bool fgInitPosition( void ) { path.append( "Airports" ); path.append( "simple.mk4" ); FGAirports airports( path.c_str() ); - FGAirport a; FG_LOG( FG_GENERAL, FG_INFO, "Attempting to set starting position from airport code " @@ -170,18 +166,39 @@ bool fgInitPosition( void ) { if ( ! airports.search( id, &a ) ) { FG_LOG( FG_GENERAL, FG_ALERT, "Failed to find " << id << " in database." ); - exit(-1); + return false; } else { - f->set_Longitude( a.longitude * DEG_TO_RAD ); - f->set_Latitude( a.latitude * DEG_TO_RAD ); + current_options.set_lon( a.longitude ); + current_options.set_lat( a.latitude ); } } else { - // set initial position from default or command line coordinates + return false; + } + + FG_LOG( FG_GENERAL, FG_INFO, + "Position for " << id << " is (" + << a.longitude << ", " + << a.latitude << ")" ); - f->set_Longitude( current_options.get_lon() * DEG_TO_RAD ); - f->set_Latitude( current_options.get_lat() * DEG_TO_RAD ); + return true; +} + +// Set initial position and orientation +bool fgInitPosition( void ) { + FGInterface *f = current_aircraft.fdm_state; + string id = current_options.get_airport_id(); + + if ( id.length() ) { + // set initial position from airport id + if ( ! fgSetPosFromAirportID( id ) ) { + exit(-1); + } } + // set initial position from default or command line coordinates + f->set_Longitude( current_options.get_lon() * DEG_TO_RAD ); + f->set_Latitude( current_options.get_lat() * DEG_TO_RAD ); + FG_LOG( FG_GENERAL, FG_INFO, "starting altitude is = " << current_options.get_altitude() ); diff --git a/src/Main/fg_init.hxx b/src/Main/fg_init.hxx index 2f4399e4b..182f78ac4 100644 --- a/src/Main/fg_init.hxx +++ b/src/Main/fg_init.hxx @@ -49,6 +49,10 @@ bool fgInitSubsystems( void ); void fgReInitSubsystems( void ); +// Set current_options lon/lat given an airport id +bool fgSetPosFromAirportID( const string& id ); + + #endif // _FG_INIT_H diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 003dbd1c9..6837c403b 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -1312,6 +1312,11 @@ int main( int argc, char **argv ) { // fonts !!! guiInit(); + // set current_options lon/lat if an airport id is specified + if ( current_options.get_airport_id().length() ) { + fgSetPosFromAirportID( current_options.get_airport_id() ); + } + // Initialize time FGPath zone( current_options.get_fg_root() ); zone.append( "Timezone" ); -- 2.39.5