]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/submodel.cxx
warnings--
[flightgear.git] / src / AIModel / submodel.cxx
index a9992885b204eddfbc2b233ad7bef02355478e15..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;
@@ -26,6 +31,7 @@ FGSubmodelMgr::FGSubmodelMgr ()
   out[0] = out[1] = out[2] = 0;
   in[3] = out[3] = 1;
   string contents_node;
+  contrail_altitude = 30000.0;
 }
 
 FGSubmodelMgr::~FGSubmodelMgr ()
@@ -36,7 +42,7 @@ void
 FGSubmodelMgr::init ()
 {
     load();
-    _serviceable_node = fgGetNode("/sim/systems/submodels/serviceable", true);
+    _serviceable_node = fgGetNode("/sim/submodels/serviceable", true);
 
     _user_lat_node = fgGetNode("/position/latitude-deg", true);
     _user_lon_node = fgGetNode("/position/longitude-deg", true);
@@ -57,8 +63,12 @@ FGSubmodelMgr::init ()
     _user_speed_east_fps_node   = fgGetNode("/velocities/speed-east-fps",true);
     _user_speed_north_fps_node  = fgGetNode("/velocities/speed-north-fps",true);
 
-    ai = (FGAIManager*)globals->get_subsystem("ai_model");
+    _contrail_altitude_node = fgGetNode("/environment/params/contrail-altitude", true);
+    contrail_altitude = _contrail_altitude_node->getDoubleValue();
+    _contrail_trigger = fgGetNode("ai/submodels/contrails", true);
+    _contrail_trigger->setBoolValue(false);
 
+    ai = (FGAIManager*)globals->get_subsystem("ai_model");
 
 }
 
@@ -82,6 +92,9 @@ FGSubmodelMgr::update (double dt)
 {
   if (!(_serviceable_node->getBoolValue())) return;
   int i=-1;
+
+  _contrail_trigger->setBoolValue(_user_alt_node->getDoubleValue() > contrail_altitude);
+
   submodel_iterator = submodels.begin();
   while(submodel_iterator != submodels.end()) {
     i++;
@@ -100,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;
@@ -111,25 +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;
-  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)--; 
 
@@ -139,9 +155,7 @@ FGSubmodelMgr::release (submodel* sm, double dt)
 void
 FGSubmodelMgr::load ()
 {
-
-    int i;
-    SGPropertyNode *path = fgGetNode("/sim/systems/submodels/path");
+    SGPropertyNode *path = fgGetNode("/sim/submodels/path");
     SGPropertyNode root;
 
     if (path) {
@@ -158,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");
@@ -184,6 +200,7 @@ FGSubmodelMgr::load ()
      sm->first_time     = false;
      sm->cd             = entry_node->getDoubleValue("cd", 0.193);
      sm->weight         = entry_node->getDoubleValue("weight", 0.25);
+     sm->aero_stabilised = entry_node->getBoolValue  ("aero-stabilised", true);
      sm->contents_node  = fgGetNode(entry_node->getStringValue("contents", "none"), true);
 
      sm->trigger->setBoolValue(false);
@@ -191,8 +208,9 @@ FGSubmodelMgr::load ()
  
      sm->contents = sm->contents_node->getDoubleValue();
  
-     sm->prop = fgGetNode("/systems/submodels/submodel", i, true);
+     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)));