]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
Merge branch 'next' into durk-atc
[flightgear.git] / src / Main / fg_init.cxx
index d573383181eabde0633ee20acb8c63608af61b6d..52a88efdfc1da92b03ab2b25490ea038d805a6e0 100644 (file)
@@ -59,6 +59,7 @@
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/misc/sg_dir.hxx>
 #include <simgear/misc/sgstream.hxx>
+#include <simgear/misc/strutils.hxx>
 
 #include <simgear/misc/interpolator.hxx>
 #include <simgear/scene/material/matlib.hxx>
@@ -997,18 +998,37 @@ static void fgSetDistOrAltFromGlideSlope() {
 
 
 // Set current_options lon/lat given an airport id and heading (degrees)
-static bool fgSetPosFromNAV( const string& id, const double& freq ) {
-    FGNavRecord *nav
-        = globals->get_navlist()->findByIdentAndFreq( id.c_str(), freq );
+static bool fgSetPosFromNAV( const string& id, const double& freq, FGPositioned::Type type ) {
 
-  if (!nav) {
-    SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
-                << id << ":" << freq );
-    return false;
-  }
-  
-  fgApplyStartOffset(nav->geod(), fgGetDouble("/sim/presets/heading-deg"));
-  return true;
+    const nav_list_type navlist
+        = globals->get_navlist()->findByIdentAndFreq( id.c_str(), freq, type );
+
+    if (navlist.size() == 0 ) {
+        SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
+            << id << ":" << freq );
+        return false;
+    }
+
+    if( navlist.size() > 1 ) {
+        ostringstream buf;
+        buf << "Ambigous NAV-ID: '" << id << "'. Specify id and frequency. Available stations:" << endl;
+        for( nav_list_type::const_iterator it = navlist.begin(); it != navlist.end(); ++it ) {
+            // NDB stored in kHz, VOR stored in MHz * 100 :-P
+            double factor = (*it)->type() == FGPositioned::NDB ? 1.0 : 1/100.0;
+            string unit = (*it)->type() == FGPositioned::NDB ? "kHz" : "MHz";
+            buf << (*it)->ident() << " "
+                << setprecision(5) << (double)((*it)->get_freq() * factor) << " "
+                << (*it)->get_lat() << "/" << (*it)->get_lon()
+                << endl;
+        }
+
+        SG_LOG( SG_GENERAL, SG_ALERT, buf.str() );
+        return false;
+    }
+
+    FGNavRecord *nav = navlist[0];
+    fgApplyStartOffset(nav->geod(), fgGetDouble("/sim/presets/heading-deg"));
+    return true;
 }
 
 // Set current_options lon/lat given an aircraft carrier id
@@ -1220,14 +1240,14 @@ bool fgInitPosition() {
 
     if ( !set_pos && !vor.empty() ) {
         // a VOR is requested
-        if ( fgSetPosFromNAV( vor, vor_freq ) ) {
+        if ( fgSetPosFromNAV( vor, vor_freq, FGPositioned::VOR ) ) {
             set_pos = true;
         }
     }
 
     if ( !set_pos && !ndb.empty() ) {
         // an NDB is requested
-        if ( fgSetPosFromNAV( ndb, ndb_freq ) ) {
+        if ( fgSetPosFromNAV( ndb, ndb_freq, FGPositioned::NDB ) ) {
             set_pos = true;
         }
     }