]> 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 0b93d6a206fb633c001fad16164ee0f2374c97e4..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);
@@ -253,16 +255,26 @@ void FGATCMgr::FreqSearch(const string navcomm, const int unit) {
 
     class RangeFilter : public CommStation::Filter {
     public:
-        RangeFilter( const SGGeod & pos ) : CommStation::Filter(), _pos(pos) {}
-        virtual bool pass(FGPositioned* aPos) const {
+        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;
-            double dist = SGGeodesy::distanceNm( stn->geod(), _pos );
-            // if range is not configured, assume at least 10NM range
-            // TODO: maybe ramp down range with proximity to ground?
-            return dist <= SGMiscd::max( stn->rangeNm(), 10.0 );
+          // 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;
     };