+// Set current_options lon/lat given an airport id and heading (degrees)
+static bool fgSetPosFromNAV( const string& id, const double& freq ) {
+ FGNav *nav = current_navlist->findByIdentAndFreq( id.c_str(), freq );
+
+ // set initial position from runway and heading
+ if ( nav != NULL ) {
+ SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
+ << id << ":" << freq );
+
+ double lon = nav->get_lon();
+ double lat = nav->get_lat();
+
+ if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
+ {
+ double odist = fgGetDouble("/sim/presets/offset-distance")
+ * SG_NM_TO_METER;
+ double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
+ + 180.0;
+ while ( oaz >= 360.0 ) { oaz -= 360.0; }
+ double olat, olon, az2;
+ geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
+
+ lat = olat;
+ lon = olon;
+ }
+
+ // presets
+ fgSetDouble("/sim/presets/longitude-deg", lon );
+ fgSetDouble("/sim/presets/latitude-deg", lat );
+
+ // other code depends on the actual values being set ...
+ fgSetDouble("/position/longitude-deg", lon );
+ fgSetDouble("/position/latitude-deg", lat );
+ fgSetDouble("/orientation/heading-deg",
+ fgGetDouble("/sim/presets/heading-deg") );
+
+ SG_LOG( SG_GENERAL, SG_INFO,
+ "Position for " << id << ":" << freq << " is ("
+ << lon << ", "<< lat << ")" );
+
+ return true;
+ } else {
+ SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
+ << id << ":" << freq );
+ return false;
+ }
+}
+
+
+// Set current_options lon/lat given an airport id and heading (degrees)
+static bool fgSetPosFromFix( const string& id ) {
+ FGFix fix;
+
+ // set initial position from runway and heading
+ if ( current_fixlist->query( id.c_str(), &fix ) ) {
+ SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
+ << id );
+
+ double lon = fix.get_lon();
+ double lat = fix.get_lat();
+
+ if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
+ {
+ double odist = fgGetDouble("/sim/presets/offset-distance")
+ * SG_NM_TO_METER;
+ double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
+ + 180.0;
+ while ( oaz >= 360.0 ) { oaz -= 360.0; }
+ double olat, olon, az2;
+ geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
+
+ lat = olat;
+ lon = olon;
+ }
+
+ // presets
+ fgSetDouble("/sim/presets/longitude-deg", lon );
+ fgSetDouble("/sim/presets/latitude-deg", lat );
+
+ // other code depends on the actual values being set ...
+ fgSetDouble("/position/longitude-deg", lon );
+ fgSetDouble("/position/latitude-deg", lat );
+ fgSetDouble("/orientation/heading-deg",
+ fgGetDouble("/sim/presets/heading-deg") );
+
+ SG_LOG( SG_GENERAL, SG_INFO,
+ "Position for " << id << " is ("
+ << lon << ", "<< lat << ")" );
+
+ return true;
+ } else {
+ SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
+ << id );
+ return false;
+ }
+}
+
+
+/**
+ * Initialize vor/ndb/ils/fix list management and query systems (as
+ * well as simple airport db list)
+ */
+bool
+fgInitNav ()
+{
+ SG_LOG(SG_GENERAL, SG_INFO, "Loading Simple Airport List");
+ SGPath p_simple( globals->get_fg_root() );
+ p_simple.append( "Airports/basic.dat" );
+ FGAirportList *airports = new FGAirportList( p_simple.str() );
+ globals->set_airports( airports );
+
+ SG_LOG(SG_GENERAL, SG_INFO, "Loading Runway List");
+ SGPath p_runway( globals->get_fg_root() );
+ p_runway.append( "Airports/runways.dat" );
+ FGRunwayList *runways = new FGRunwayList( p_runway.str() );
+ globals->set_runways( runways );
+
+ SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
+
+ SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
+ current_navlist = new FGNavList;
+ SGPath p_nav( globals->get_fg_root() );
+ p_nav.append( "Navaids/default.nav" );
+ current_navlist->init( p_nav );
+
+ SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
+ current_beacons = new FGMarkerBeacons;
+ current_beacons->init();
+ current_ilslist = new FGILSList;
+ SGPath p_ils( globals->get_fg_root() );
+ p_ils.append( "Navaids/default.ils" );
+ current_ilslist->init( p_ils );
+
+ SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
+ current_fixlist = new FGFixList;
+ SGPath p_fix( globals->get_fg_root() );
+ p_fix.append( "Navaids/default.fix" );
+ current_fixlist->init( p_fix );
+
+ return true;
+}
+
+