]> git.mxchange.org Git - flightgear.git/blobdiff - src/Navaids/NavDataCache.cxx
Traffic improvements.
[flightgear.git] / src / Navaids / NavDataCache.cxx
index 5974aae584a5f3aaa72705510e64250564914da3..5d228c4bcf7dd4d21447884e4b9ab6969ee19bef 100644 (file)
@@ -290,7 +290,7 @@ public:
     
     try {
       execSelect(stmt);
-    } catch (sg_exception& e) {
+    } catch (sg_exception&) {
       sqlite3_finalize(stmt);
       throw; // re-throw
     }
@@ -528,6 +528,9 @@ public:
     findNavsByFreqNoPos = prepare("SELECT positioned.rowid FROM positioned, navaid WHERE "
                                   "positioned.rowid=navaid.rowid AND freq=?1 " AND_TYPED);
     
+    findNavaidForRunway = prepare("SELECT positioned.rowid FROM positioned, navaid WHERE "
+                                  "positioned.rowid=navaid.rowid AND runway=?1 AND type=?2");
+    
   // for an octree branch, return the child octree nodes which exist,
   // described as a bit-mask
     getOctreeChildren = prepare("SELECT children FROM octree WHERE rowid=?1");
@@ -596,7 +599,7 @@ public:
     reset(loadAirportStmt);
     sqlite3_bind_int64(loadAirportStmt, 1, rowId);
     execSelect1(loadAirportStmt);
-    bool hasMetar = sqlite3_column_int(loadAirportStmt, 0);
+    bool hasMetar = (sqlite3_column_int(loadAirportStmt, 0) > 0);
     return new FGAirport(rowId, id, pos, name, hasMetar, ty);
   }
   
@@ -808,7 +811,7 @@ public:
 
   sqlite3_stmt_ptr searchAirports;
   sqlite3_stmt_ptr findCommByFreq, findNavsByFreq,
-  findNavsByFreqNoPos;
+  findNavsByFreqNoPos, findNavaidForRunway;
   sqlite3_stmt_ptr getAirportItems, getAirportItemByIdent;
   sqlite3_stmt_ptr findAirportRunway,
     findILS;
@@ -1530,11 +1533,16 @@ NavDataCache::findCommByFreq(int freqKhz, const SGGeod& aPos, FGPositioned::Filt
   sqlite3_bind_double(d->findCommByFreq, 5, cartPos.y());
   sqlite3_bind_double(d->findCommByFreq, 6, cartPos.z());
   
-  if (!d->execSelect(d->findCommByFreq)) {
-    return NULL;
+  while (d->execSelect(d->findCommByFreq)) {
+    FGPositioned* p = loadById(sqlite3_column_int64(d->findCommByFreq, 0));
+    if (aFilter && !aFilter->pass(p)) {
+      continue;
+    }
+    
+    return p;
   }
   
-  return loadById(sqlite3_column_int64(d->findCommByFreq, 0));
+  return NULL;
 }
   
 PositionedIDVec
@@ -1702,6 +1710,18 @@ AirwayEdgeVec NavDataCache::airwayEdgesFrom(int network, PositionedID pos)
   }
   return result;
 }
+
+PositionedID NavDataCache::findNavaidForRunway(PositionedID runway, FGPositioned::Type ty)
+{
+  d->reset(d->findNavaidForRunway);
+  sqlite3_bind_int64(d->findNavaidForRunway, 1, runway);
+  sqlite3_bind_int(d->findNavaidForRunway, 2, ty);
+  if (!d->execSelect(d->findNavaidForRunway)) {
+    return 0;
+  }
+  
+  return sqlite3_column_int64(d->findNavaidForRunway, 0);
+}
   
 } // of namespace flightgear