]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATCDCL/ATCmgr.cxx
Expose a radio function (receiveBeacon) to the Nasal subsystem
[flightgear.git] / src / ATCDCL / ATCmgr.cxx
index 7a3da5969f6caf00a8c7090371d214e01c2b0437..69a0b117959643a6462f84b52da84c413482807b 100644 (file)
@@ -48,9 +48,11 @@ FGATCMgr::FGATCMgr() :
     voice(false),
 #endif
 {
+    globals->set_ATC_mgr(this);
 }
 
 FGATCMgr::~FGATCMgr() {
+    globals->set_ATC_mgr(NULL);
     delete v1;
 }
 
@@ -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;
     };