}
-// 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
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 "
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() );