#include <simgear/sg_inlines.h>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/math/sg_random.h>
+#include <simgear/sound/sample_group.hxx>
#include <Main/fg_props.hxx>
#include <Navaids/navlist.hxx>
return range_nm + (range_nm * rand * rand);
}
+namespace {
+
+ class DMEFilter : public FGNavList::TypeFilter
+ {
+ public:
+ DMEFilter() :
+ TypeFilter(FGPositioned::DME),
+ _locEnabled(fgGetBool("/sim/realism/dme-fallback-to-loc", true))
+ {
+ if (_locEnabled) {
+ _mintype = FGPositioned::ILS;
+ }
+ }
+
+ virtual bool pass(FGPositioned* pos) const
+ {
+ switch (pos->type()) {
+ case FGPositioned::DME: return true;
+ case FGPositioned::ILS:
+ case FGPositioned::LOC: return _locEnabled;
+ default: return false;
+ }
+ }
+
+ private:
+ const bool _locEnabled;
+ };
+
+} // of anonymous namespace
+
DME::DME ( SGPropertyNode *node )
: _last_distance_nm(0),
void
DME::init ()
{
- string branch;
+ std::string branch;
branch = "/instrumentation/" + _name;
SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
if( NULL == _audioIdent )
_audioIdent = new DMEAudioIdent( temp.str() );
_audioIdent->init();
+
+ reinit();
+}
+
+void
+DME::reinit ()
+{
+ _time_before_search_sec = 0;
}
void
// Figure out the source
const char * source = _source_node->getStringValue();
if (source[0] == '\0') {
- string branch;
+ std::string branch;
branch = "/instrumentation/" + _name + "/frequencies/selected-mhz";
_source_node->setStringValue(branch.c_str());
source = _source_node->getStringValue();
if (_time_before_search_sec < 0) {
_time_before_search_sec = 1.0;
- if( fgGetBool( "/sim/realism/dme-fallback-to-loc", true ) ) {
- if( NULL == (_navrecord = globals->get_loclist()->findByFreq( frequency_mhz,
- globals->get_aircraft_position())) ) {
-
- _navrecord = globals->get_dmelist()->findByFreq( frequency_mhz,
- globals->get_aircraft_position());
- }
- } else {
- _navrecord = globals->get_dmelist()->findByFreq( frequency_mhz,
- globals->get_aircraft_position());
- }
+ SGGeod pos(globals->get_aircraft_position());
+ DMEFilter filter;
+ _navrecord = FGNavList::findByFreq(frequency_mhz, pos, &filter);
}
// If it's off, don't bother.