]> git.mxchange.org Git - flightgear.git/blobdiff - src/Navaids/navrecord.cxx
commradio: improvements for atis speech
[flightgear.git] / src / Navaids / navrecord.cxx
index cb83fd02d189fbdb3794f8637ce338fdb152523a..fabc9a0d08ffe4c6ab6129e200439daf30422b0d 100644 (file)
@@ -109,6 +109,116 @@ void FGNavRecord::updateFromXML(const SGGeod& geod, double heading)
     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)