]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIManager.cxx
commradio: improvements for atis speech
[flightgear.git] / src / AIModel / AIManager.cxx
index b7ec95a8472b89555c3957be3775dbd21fe0e57d..27582d9ca708a2fb52a236acce96d99989006886 100644 (file)
@@ -85,6 +85,9 @@ public:
         }
         
         FGNasalSys* nasalSys = (FGNasalSys*) globals->get_subsystem("nasal");
+        if (!nasalSys)
+            return;
+        
         std::string moduleName = "scenario_" + _internalName;
         if (!_unloadScript.empty()) {
             nasalSys->createModule(moduleName.c_str(), moduleName.c_str(),
@@ -131,6 +134,7 @@ FGAIManager::init() {
     
     globals->get_commands()->addCommand("load-scenario", this, &FGAIManager::loadScenarioCommand);
     globals->get_commands()->addCommand("unload-scenario", this, &FGAIManager::unloadScenarioCommand);
+    _environmentVisiblity = fgGetNode("/environment/visibility-m");
 }
 
 void
@@ -181,6 +185,10 @@ FGAIManager::shutdown()
     }
     
     ai_list.clear();
+    _environmentVisiblity.clear();
+    
+    globals->get_commands()->removeCommand("load-scenario");
+    globals->get_commands()->removeCommand("unload-scenario");
 }
 
 void
@@ -292,6 +300,12 @@ FGAIManager::attach(FGAIBase *model)
     p->setBoolValue("valid", true);
 }
 
+bool FGAIManager::isVisible(const SGGeod& pos) const
+{
+  double visibility_meters = _environmentVisiblity->getDoubleValue();
+  return ( dist(globals->get_view_position_cart(), SGVec3d::fromGeod(pos)) ) <= visibility_meters;
+}
+
 int
 FGAIManager::getNumAiObjects() const
 {