]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIManager.cxx
Interim windows build fix
[flightgear.git] / src / AIModel / AIManager.cxx
index c0d8a78a7fe24ce757f34ae9ac3427a21bbf83a1..4faf23e591e5887ffb0937ad15f276d40028e67c 100644 (file)
@@ -32,6 +32,7 @@
 #include <boost/foreach.hpp>
 
 #include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
 #include <Airports/airport.hxx>
 #include <Scripting/NasalSys.hxx>
 
@@ -85,6 +86,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 +135,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 +186,7 @@ FGAIManager::shutdown()
     }
     
     ai_list.clear();
+    _environmentVisiblity.clear();
     
     globals->get_commands()->removeCommand("load-scenario");
     globals->get_commands()->removeCommand("unload-scenario");
@@ -295,6 +301,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
 {
@@ -397,7 +409,14 @@ FGAIBasePtr FGAIManager::addObject(const SGPropertyNode* definition)
     }
 
     ai->readFromScenario(const_cast<SGPropertyNode*>(definition));
-    attach(ai);
+       if((ai->isValid())){
+               attach(ai);
+        SG_LOG(SG_AI, SG_DEBUG, "attached scenario " << ai->_getName());
+       }
+       else{
+               ai->setDie(true);
+               SG_LOG(SG_AI, SG_ALERT, "killed invalid scenario "  << ai->_getName());
+       }
     return ai;
 }