]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATCDCL/ATCmgr.cxx
Fix file access mode for newnavradio.[ch]xx
[flightgear.git] / src / ATCDCL / ATCmgr.cxx
index 8d8a6fc5815987df5026e478eafa9053fca57b3b..334523fd451d2dda3dc6ee52a7ff7730f5eb261b 100644 (file)
@@ -31,7 +31,7 @@
 #include <Main/fg_props.hxx>
 
 #include "ATCmgr.hxx"
-#include "ATCDialog.hxx"
+#include "ATCDialogOld.hxx"
 #include "ATCutils.hxx"
 #include "atis.hxx"
 
@@ -48,9 +48,11 @@ FGATCMgr::FGATCMgr() :
     voice(false),
 #endif
 {
+    globals->set_ATC_mgr(this);
 }
 
 FGATCMgr::~FGATCMgr() {
+    globals->set_ATC_mgr(NULL);
     delete v1;
 }
 
@@ -153,7 +155,7 @@ void FGATCMgr::ZapOtherService(const string ncunit, const string svc_name){
         //cout << "Eradicating service: '" << svc->first << "'" << endl;
         svc->second->SetNoDisplay();
         svc->second->Update(0);     // one last update
-        SG_LOG(SG_GENERAL, SG_INFO, "would have erased ATC service:" << svc->second->get_name()<< "/"
+        SG_LOG(SG_ATC, SG_INFO, "would have erased ATC service:" << svc->second->get_name()<< "/"
           << svc->second->get_ident());
         // delete svc->second;
         atc_list->erase(svc);
@@ -250,8 +252,35 @@ void FGATCMgr::FreqSearch(const string navcomm, const int unit) {
     
     _aircraftPos = SGGeod::fromDegFt(lon_node->getDoubleValue(),
         lat_node->getDoubleValue(), elev_node->getDoubleValue());
+
+    class RangeFilter : public CommStation::Filter {
+    public:
+        RangeFilter( const SGGeod & pos ) : 
+          CommStation::Filter(), 
+          _cart(SGVec3d::fromGeod(pos)),
+          _pos(pos)
+        {}
+      
+        virtual bool pass(FGPositioned* aPos) const
+        {
+            flightgear::CommStation * stn = dynamic_cast<flightgear::CommStation*>(aPos);
+            if( NULL == stn ) return false;
+          // do the range check in cartesian space, since the distances are potentially
+          // large enough that the geodetic functions become unstable
+          // (eg, station on opposite side of the planet)
+            double rangeM = SGMiscd::max( stn->rangeNm(), 10.0 ) * SG_NM_TO_METER;
+            double d2 = distSqr( aPos->cart(), _cart);
+          
+            return d2 <= (rangeM * rangeM);
+        }
+    private:
+        SGVec3d _cart;
+        SGGeod _pos;
+    };
+
+    RangeFilter rangeFilter(_aircraftPos );
     
-    CommStation* sta = CommStation::findByFreq(freqKhz, _aircraftPos);
+    CommStation* sta = CommStation::findByFreq(freqKhz, _aircraftPos, &rangeFilter );
     if (!sta) {
         ZapOtherService(ncunit, "x x x");
         return;