From: Torsten Dreyer Date: Fri, 8 Jul 2011 08:56:18 +0000 (+0200) Subject: Fix #369: ATIS receiver has excessive range X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5303d15aa32b14c42784bc65e88a090f3b7f0f6a;p=flightgear.git Fix #369: ATIS receiver has excessive range Add a range filter when searching for CommStations, searching by frequency is not enough. --- diff --git a/src/ATCDCL/ATCmgr.cxx b/src/ATCDCL/ATCmgr.cxx index 8d8a6fc58..0b93d6a20 100644 --- a/src/ATCDCL/ATCmgr.cxx +++ b/src/ATCDCL/ATCmgr.cxx @@ -250,8 +250,25 @@ 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(), _pos(pos) {} + virtual bool pass(FGPositioned* aPos) const { + flightgear::CommStation * stn = dynamic_cast(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 ); + } + private: + 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;