]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/submodel.cxx
warnings--
[flightgear.git] / src / AIModel / submodel.cxx
index 0e2dd42999687889055e5a1ea78b6407343d8d39..a4959e27bb34f584ca38bc92e7f025048dc735c8 100644 (file)
@@ -3,6 +3,10 @@
 //
 // This file is in the Public Domain and comes with no warranty.
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include "submodel.hxx"
 
 #include <simgear/structure/exception.hxx>
@@ -11,6 +15,7 @@
 #include <Main/fg_props.hxx>
 #include <Main/util.hxx>
 #include <AIModel/AIManager.hxx>
+#include <AIModel/AIBallistic.hxx>
 
 
 const double FGSubmodelMgr::lbs_to_slugs = 0.031080950172;
@@ -88,9 +93,7 @@ FGSubmodelMgr::update (double dt)
   if (!(_serviceable_node->getBoolValue())) return;
   int i=-1;
 
-  if (_user_alt_node->getDoubleValue() > contrail_altitude) {
-     _contrail_trigger->setBoolValue(true);
-  }   
+  _contrail_trigger->setBoolValue(_user_alt_node->getDoubleValue() > contrail_altitude);
 
   submodel_iterator = submodels.begin();
   while(submodel_iterator != submodels.end()) {
@@ -110,6 +113,9 @@ FGSubmodelMgr::update (double dt)
 bool
 FGSubmodelMgr::release (submodel* sm, double dt)
 {
+  // only run if first time or repeat is set to true
+  if (!sm->first_time && !sm->repeat) return false;
+
   sm->timer += dt;
   if (sm->timer < sm->delay) return false;
   sm->timer = 0.0;
@@ -121,26 +127,25 @@ FGSubmodelMgr::release (submodel* sm, double dt)
 
   transform(sm);  // calculate submodel's initial conditions in world-coordinates
 
-  FGAIModelEntity entity;
-
-  entity.path = sm->model.c_str();
-  entity.latitude = IC.lat;
-  entity.longitude = IC.lon;
-  entity.altitude = IC.alt;
-  entity.azimuth = IC.azimuth;
-  entity.elevation = IC.elevation;
-  entity.roll = IC.roll;
-  entity.speed = IC.speed;
-  entity.eda = sm->drag_area;
-  entity.life = sm->life;
-  entity.buoyancy = sm->buoyancy;
-  entity.wind_from_east = IC.wind_from_east;
-  entity.wind_from_north = IC.wind_from_north;
-  entity.wind = sm->wind;
-  entity.cd = sm->cd;
-  entity.mass = IC.mass;
-  entity.aero_stabilised = sm->aero_stabilised;
-  ai->createBallistic( &entity );
+  FGAIBallistic* ballist = new FGAIBallistic;
+  ballist->setPath(sm->model.c_str());
+  ballist->setLatitude(IC.lat);
+  ballist->setLongitude(IC.lon);
+  ballist->setAltitude(IC.alt);
+  ballist->setAzimuth(IC.azimuth);
+  ballist->setElevation(IC.elevation);
+  ballist->setRoll(IC.roll);
+  ballist->setSpeed(IC.speed);
+  ballist->setDragArea(sm->drag_area);
+  ballist->setLife(sm->life);
+  ballist->setBuoyancy(sm->buoyancy);
+  ballist->setWind_from_east(IC.wind_from_east);
+  ballist->setWind_from_north(IC.wind_from_north);
+  ballist->setWind(sm->wind);
+  ballist->setCd(sm->cd);
+  ballist->setMass(IC.mass);
+  ballist->setStabilisation(sm->aero_stabilised);
+  ai->attach(ballist);
  
   if (sm->count > 0) (sm->count)--; 
 
@@ -150,8 +155,6 @@ FGSubmodelMgr::release (submodel* sm, double dt)
 void
 FGSubmodelMgr::load ()
 {
-
-    int i;
     SGPropertyNode *path = fgGetNode("/sim/submodels/path");
     SGPropertyNode root;
 
@@ -169,12 +172,14 @@ FGSubmodelMgr::load ()
       }
     }
 
-   int count = root.nChildren();
-   for (i = 0; i < count; i++) { 
-     // cout << "Reading submodel " << i << endl;        
-     SGPropertyNode *prop;
+   vector<SGPropertyNode_ptr> children = root.getChildren("submodel");
+   vector<SGPropertyNode_ptr>::iterator it = children.begin();
+   vector<SGPropertyNode_ptr>::iterator end = children.end();
+   for (int i = 0; it != end; ++it, i++) {
+
+     // cout << "Reading submodel " << (*it)->getPath() << endl;
      submodel* sm = new submodel;
-     SGPropertyNode * entry_node = root.getChild(i);
+     SGPropertyNode * entry_node = *it;
      sm->trigger        = fgGetNode(entry_node->getStringValue("trigger", "none"), true);
      sm->name           = entry_node->getStringValue("name", "none_defined");
      sm->model          = entry_node->getStringValue("model", "Models/Geometry/rocket.ac");
@@ -205,6 +210,7 @@ FGSubmodelMgr::load ()
  
      sm->prop = fgGetNode("/ai/submodels/submodel", i, true);
      sm->prop->tie("count", SGRawValuePointer<int>(&(sm->count)));
+     sm->prop->tie("repeat", SGRawValuePointer<bool>(&(sm->repeat)));
 
 //   sm->prop->tie("contents", SGRawValuePointer<double>(&(sm->contents)));
 //   sm->prop->tie("contents path", SGRawValuePointer<const char *>(&(sm->contents_node)));