#include <Airports/airport.hxx>
#include <Airports/xmlloader.hxx>
#include <Main/fg_props.hxx>
-#include <Navaids/NavDataCache.hxx>
FGNavRecord::FGNavRecord(PositionedID aGuid, Type aTy, const std::string& aIdent,
const std::string& aName, const SGGeod& aPos,
multiuse(aMultiuse),
mName(aName),
mRunway(aRunway),
+ mColocated(0),
serviceable(true)
{
}
-FGRunway* FGNavRecord::runway() const
+FGRunwayRef FGNavRecord::runway() const
{
- return (FGRunway*) flightgear::NavDataCache::instance()->loadById(mRunway);
+ return loadById<FGRunway>(mRunway);
}
double FGNavRecord::localizerWidth() const
}
+bool FGNavRecord::hasDME()
+{
+ return (mColocated > 0);
+}
+
+void FGNavRecord::setColocatedDME(PositionedID other)
+{
+ mColocated = other;
+}
+
+void FGNavRecord::updateFromXML(const SGGeod& geod, double heading)
+{
+ modifyPosition(geod);
+ multiuse = heading;
+}
+
+//------------------------------------------------------------------------------
+FGMobileNavRecord::FGMobileNavRecord( PositionedID aGuid,
+ Type type,
+ const std::string& ident,
+ const std::string& name,
+ const SGGeod& aPos,
+ int freq,
+ int range,
+ double multiuse,
+ PositionedID aRunway ):
+ FGNavRecord(aGuid, type, ident, name, aPos, freq, range, multiuse, aRunway),
+ _initial_elevation_ft(aPos.getElevationFt())
+{
+
+}
+
+//------------------------------------------------------------------------------
+const SGGeod& FGMobileNavRecord::geod() const
+{
+ const_cast<FGMobileNavRecord*>(this)->updatePos();
+ return FGNavRecord::geod();
+}
+
+//------------------------------------------------------------------------------
+const SGVec3d& FGMobileNavRecord::cart() const
+{
+ const_cast<FGMobileNavRecord*>(this)->updatePos();
+ return FGNavRecord::cart();
+}
+
+//------------------------------------------------------------------------------
+void FGMobileNavRecord::updateVehicle()
+{
+ _vehicle_node.clear();
+
+ SGPropertyNode* ai_branch = fgGetNode("ai/models");
+ if( !ai_branch )
+ {
+ SG_LOG( SG_NAVAID,
+ SG_INFO,
+ "Can not update mobile navaid position (no ai/models branch)" );
+ return;
+ }
+
+ const std::string& nav_name = name();
+
+ // Try any aircraft carriers first
+ simgear::PropertyList carrier = ai_branch->getChildren("carrier");
+ for(size_t i = 0; i < carrier.size(); ++i)
+ {
+ const std::string carrier_name = carrier[i]->getStringValue("name");
+
+ if( carrier_name.empty()
+ || nav_name.find(carrier_name) == std::string::npos )
+ continue;
+
+ _vehicle_node = carrier[i];
+ return;
+ }
+
+ // Now the tankers
+ const std::string tanker_branches[] = {
+ // AI tankers
+ "tanker",
+ // And finally mp tankers
+ "multiplayer"
+ };
+
+ for(size_t i = 0; i < sizeof(tanker_branches)/sizeof(tanker_branches[0]); ++i)
+ {
+ simgear::PropertyList tanker = ai_branch->getChildren(tanker_branches[i]);
+ for(size_t j = 0; j < tanker.size(); ++j)
+ {
+ const std::string callsign = tanker[j]->getStringValue("callsign");
+
+ if( callsign.empty()
+ || nav_name.find(callsign) == std::string::npos )
+ continue;
+
+ _vehicle_node = tanker[j];
+ return;
+ }
+ }
+}
+
+//------------------------------------------------------------------------------
+void FGMobileNavRecord::updatePos()
+{
+ SGTimeStamp now = SGTimeStamp::now();
+ if( (now - _last_vehicle_update).toSecs() > (_vehicle_node.valid() ? 5 : 2) )
+ {
+ updateVehicle();
+ _last_vehicle_update = now;
+ }
+
+ if( _vehicle_node.valid() )
+ modifyPosition(SGGeod::fromDegFt(
+ _vehicle_node->getDoubleValue("position/longitude-deg"),
+ _vehicle_node->getDoubleValue("position/latitude-deg"),
+ _vehicle_node->getNameString() == "carrier"
+ ? _initial_elevation_ft
+ : _vehicle_node->getDoubleValue("position/altitude-ft")
+ ));
+ else
+ invalidatePosition();
+
+ serviceable = _vehicle_node.valid();
+}
+
+//------------------------------------------------------------------------------
FGTACANRecord::FGTACANRecord(void) :
channel(""),
freq(0)