]> git.mxchange.org Git - flightgear.git/commitdiff
Try to set initial position in a bit more intelligent way (and earlier in
authorcurt <curt>
Fri, 21 Jul 2000 22:54:14 +0000 (22:54 +0000)
committercurt <curt>
Fri, 21 Jul 2000 22:54:14 +0000 (22:54 +0000)
the process so time initialization can have a chance to work.)

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

index 6235493ff4d6d28d6a56d4bc68fabd111263ae84..5fb58c971fc62de85a42a2e3100d548e93902d21 100644 (file)
@@ -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() );
 
index 2f4399e4b6204416f1d096638951c5f0b459b47a..182f78ac432a89baf3b817f427e0104093a5bb9e 100644 (file)
@@ -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
 
 
index 003dbd1c9a2fd6cd383927b49fbc563293d9a72c..6837c403b12fff28b3189699355bb082a38c7559 100644 (file)
@@ -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" );