]> git.mxchange.org Git - flightgear.git/blobdiff - src/Navaids/navdb.cxx
commradio: improvements for atis speech
[flightgear.git] / src / Navaids / navdb.cxx
index 1a3613c15ad2ab0b6df1e34a46a8ec6812e05293..4b01c3ad6ff29688d9616d6c0aeceabbce191556 100644 (file)
@@ -118,15 +118,22 @@ static double defaultNavRange(const string& ident, FGPositioned::Type type)
     case FGPositioned::GS:
       return FG_LOC_DEFAULT_RANGE;
       
-    case FGPositioned::DME: return FG_DME_DEFAULT_RANGE;
-    default: return FG_LOC_DEFAULT_RANGE;
+    case FGPositioned::DME:
+      return FG_DME_DEFAULT_RANGE;
+
+    case FGPositioned::TACAN:
+    case FGPositioned::MOBILE_TACAN:
+      return FG_TACAN_DEFAULT_RANGE;
+
+    default:
+      return FG_LOC_DEFAULT_RANGE;
   }
 }
 
 
 namespace flightgear
 {
-  
+
 static PositionedID readNavFromStream(std::istream& aStream,
                                         FGPositioned::Type type = FGPositioned::INVALID)
 {
@@ -134,9 +141,8 @@ static PositionedID readNavFromStream(std::istream& aStream,
   
   int rawType;
   aStream >> rawType;
-  if (aStream.eof() || (rawType == 99)) {
+  if( aStream.eof() || (rawType == 99) || (rawType == 0) )
     return 0; // happens with, eg, carrier_nav.dat
-  }
   
   double lat, lon, elev_ft, multiuse;
   int freq, range;
@@ -146,7 +152,7 @@ static PositionedID readNavFromStream(std::istream& aStream,
   
   SGGeod pos(SGGeod::fromDegFt(lon, lat, elev_ft));
   name = simgear::strutils::strip(name);
-  
+
 // the type can be forced by our caller, but normally we use th value
 // supplied in the .dat file
   if (type == FGPositioned::INVALID) {
@@ -169,15 +175,42 @@ static PositionedID readNavFromStream(std::istream& aStream,
                                arp.first, arp.second);
   }
   
-  if (range < 0.01) {
+  if (range < 1) {
     range = defaultNavRange(ident, type);
   }
   
   AirportRunwayPair arp;
   FGRunway* runway = NULL;
-  
-  // FIXME - also relate DMEs, but only ILS/LOC DMEs - need a heuristic
-  // on the DME naming string
+  PositionedID navaid_dme = 0;
+
+  if (type == FGPositioned::DME) {
+    FGPositioned::TypeFilter f(FGPositioned::INVALID);
+    if ( name.find("VOR-DME") != std::string::npos ) {
+      f.addType(FGPositioned::VOR);
+    } else if ( name.find("DME-ILS") != std::string::npos ) {
+      f.addType(FGPositioned::ILS);
+      f.addType(FGPositioned::LOC);
+    } else if ( name.find("VORTAC") != std::string::npos ) {
+      f.addType(FGPositioned::VOR);
+    } else if ( name.find("NDB-DME") != std::string::npos ) {
+      f.addType(FGPositioned::NDB);
+    } else if ( name.find("TACAN") != std::string::npos ) {
+      f.addType(FGPositioned::VOR);
+    }
+
+    if (f.maxType() > 0) {
+      FGPositionedRef ref = FGPositioned::findClosestWithIdent(ident, pos, &f);
+      if (ref.valid()) {
+        string_list dme_part = simgear::strutils::split(name , 0 ,1);
+        string_list navaid_part = simgear::strutils::split(ref.get()->name(), 0 ,1);
+
+        if ( simgear::strutils::uppercase(navaid_part[0]) == simgear::strutils::uppercase(dme_part[0]) ) {
+          navaid_dme = ref.get()->guid();
+        }
+      }
+    }
+  }
+
   if ((type >= FGPositioned::ILS) && (type <= FGPositioned::GS)) {
     arp = cache->findAirportRunway(name);
     if (arp.second) {
@@ -211,6 +244,10 @@ static PositionedID readNavFromStream(std::istream& aStream,
   if (isLoc) {
     cache->setRunwayILS(arp.second, r);
   }
+
+  if (navaid_dme) {
+    cache->setNavaidColocated(navaid_dme, r);
+  }
   
   return r;
 }
@@ -251,9 +288,10 @@ bool loadCarrierNav(const SGPath& path)
     }
     
     while ( ! incarrier.eof() ) {
+      incarrier >> skipcomment;
       // force the type to be MOBILE_TACAN
       readNavFromStream(incarrier, FGPositioned::MOBILE_TACAN);
-    } // end while
+    }
 
   return true;
 }