]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIScenario.cxx
fix a segmentation fault situation that is exposed at least on IRIX (but not Linux).
[flightgear.git] / src / AIModel / AIScenario.cxx
index c714f984721d0e24b8eeb6da53d63f260410c86b..e92f04da30bc766871b8c27d568f781e9e32db47 100644 (file)
@@ -1,4 +1,4 @@
-// FGAIScenario - class for loading an AI scenario
+// FGAIScenario.cxx - class for loading an AI scenario
 // Written by David Culp, started May 2004
 // - davidculp2@comcast.net
 //
@@ -17,7 +17,6 @@
 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 
-#include "AIScenario.hxx"
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/structure/exception.hxx>
 #  define exception c_exception
 #endif
 #include <simgear/props/props.hxx>
+
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 
+#include "AIScenario.hxx"
+#include "AIFlightPlan.hxx"
+
+
 
 FGAIScenario::FGAIScenario(string filename)
 {
@@ -46,16 +50,43 @@ FGAIScenario::FGAIScenario(string filename)
       return;
   }
 
-  SGPropertyNode * node = root.getNode("SCENARIO");
+  entries.clear();
+  SGPropertyNode * node = root.getNode("scenario");
   for (i = 0; i < node->nChildren(); i++) { 
      //cout << "Reading entry " << i << endl;        
-     entry* en = new entry;
+     FGAIModelEntity* en = new FGAIModelEntity;
      entries.push_back( en );
      SGPropertyNode * entry_node = node->getChild(i);
-     en->callsign       = entry_node->getStringValue("CALLSIGN", "none");
-     en->aircraft_class = entry_node->getStringValue("CLASS", "jet_transport");
-     en->model_path     = entry_node->getStringValue("MODEL", "Models/Geometry/glider.ac");
-     en->flightplan     = entry_node->getStringValue("FLIGHTPLAN", "");
+     en->callsign       = entry_node->getStringValue("callsign", "none");
+     en->m_type         = entry_node->getStringValue("type", "aircraft");
+     en->m_class        = entry_node->getStringValue("class", "jet_transport");
+     en->path           = entry_node->getStringValue("model", "Models/Geometry/glider.ac");
+     en->flightplan     = entry_node->getStringValue("flightplan", "");
+     en->repeat         = entry_node->getDoubleValue("repeat", 0.0); 
+     en->latitude       = entry_node->getDoubleValue("latitude", 0.0); 
+     en->longitude      = entry_node->getDoubleValue("longitude", 0.0); 
+     en->altitude       = entry_node->getDoubleValue("altitude", 0.0); 
+     en->speed          = entry_node->getDoubleValue("speed", 0.0); 
+     en->heading        = entry_node->getDoubleValue("heading", 0.0); 
+     en->roll           = entry_node->getDoubleValue("roll", 0.0); 
+     en->azimuth        = entry_node->getDoubleValue("azimuth", 0.0); 
+     en->elevation      = entry_node->getDoubleValue("elevation", 0.0); 
+     en->rudder         = entry_node->getDoubleValue("rudder", 0.0);
+     en->strength       = entry_node->getDoubleValue("strength-fps", 0.0);
+     en->diameter       = entry_node->getDoubleValue("diameter-ft", 0.0);
+     en->eda            = entry_node->getDoubleValue("eda", 0.007);
+     en->life           = entry_node->getDoubleValue("life", 900.0);
+     en->buoyancy       = entry_node->getDoubleValue("buoyancy", 0);
+     en->wind_from_east = entry_node->getDoubleValue("wind_from_east", 0);
+     en->wind_from_north = entry_node->getDoubleValue("wind_from_north", 0);
+     en->wind            = entry_node->getBoolValue("wind", false);
+     en->cd              = entry_node->getDoubleValue  ("cd", 0.029); 
+     en->weight          = entry_node->getDoubleValue  ("weight", 0.030); 
+
+     en->fp             = NULL;
+     if (en->flightplan != ""){
+        en->fp = new FGAIFlightPlan( en->flightplan );
+     }
    }
 
   entry_iterator = entries.begin();
@@ -69,10 +100,15 @@ FGAIScenario::~FGAIScenario()
 }
 
 
-FGAIScenario::entry*
+FGAIModelEntity*
 FGAIScenario::getNextEntry( void )
 {
-  return *entry_iterator;
+  if (entries.size() == 0) return 0;
+  if (entry_iterator != entries.end()) {
+    return *entry_iterator++;
+  } else {
+    return 0;
+  }
 }
 
 int FGAIScenario::nEntries( void )
@@ -80,4 +116,4 @@ int FGAIScenario::nEntries( void )
   return entries.size();
 }
 
-
+// end scenario.cxx