]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/submodel.cxx
Stuart Buchanan:
[flightgear.git] / src / AIModel / submodel.cxx
index d08ceeafba57fa1e8de7c8042b1b987495a462b7..7b946f0b8e4ae01c707f4318dda4242a21248ba7 100644 (file)
@@ -1,4 +1,4 @@
-// submodel.cxx - models a releasable submodel.
+//// submodel.cxx - models a releasable submodel.
 // Written by Dave Culp, started Aug 2004
 // With major additions by Vivian Meaaza 2004 - 2007
 //
@@ -13,6 +13,7 @@
 #include <simgear/structure/exception.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/math/sg_geodesy.hxx>
+#include <simgear/props/props_io.hxx>
 
 #include <Main/fg_props.hxx>
 #include <Main/util.hxx>
@@ -33,7 +34,6 @@ FGSubmodelMgr::FGSubmodelMgr()
     yaw_offset = 0.0;
 
     out[0] = out[1] = out[2] = 0;
-    in[3] = out[3] = 1;
     string contents_node;
     contrail_altitude = 30000;
     _count = 0;
@@ -116,18 +116,19 @@ void FGSubmodelMgr::update(double dt)
         _impact = (*sm_list_itr)->_getImpactData();
         _hit = (*sm_list_itr)->_getCollisionData();
         int parent_subID = (*sm_list_itr)->_getSubID();
-
+        //SG_LOG(SG_GENERAL, SG_DEBUG, "Submodel: Impact " << _impact << " hit! "
+        //        << _hit <<" parent_subID " << parent_subID);
         if ( parent_subID == 0) // this entry in the list has no associated submodel
             continue;           // so we can continue
 
         if (_impact || _hit) {
-            SG_LOG(SG_GENERAL, SG_ALERT, "Submodel: Impact " << _impact << " hit! " << _hit );
+            //SG_LOG(SG_GENERAL, SG_DEBUG, "Submodel: Impact " << _impact << " hit! " << _hit );
 
             submodel_iterator = submodels.begin();
 
             while (submodel_iterator != submodels.end()) {
                 int child_ID = (*submodel_iterator)->id;
-                cout << "Impact: parent SubID " << parent_subID << " child_ID " << child_ID << endl;
+                //cout << "Impact: parent SubID " << parent_subID << " child_ID " << child_ID << endl;
 
                 if ( parent_subID == child_ID ) {
                     _parent_lat = (*sm_list_itr)->_getImpactLat();
@@ -160,11 +161,10 @@ void FGSubmodelMgr::update(double dt)
         i++;
         in_range = true;
 
-        SG_LOG(SG_GENERAL, SG_DEBUG,
-            "Submodels:  " << (*submodel_iterator)->id
-            << " name " << (*submodel_iterator)->name
-            << " in range " << in_range
-            );
+        /*SG_LOG(SG_GENERAL, SG_DEBUG,
+                "Submodels:  " << (*submodel_iterator)->id
+                << " name " << (*submodel_iterator)->name
+                << " in range " << in_range);*/
 
         if ((*submodel_iterator)->trigger_node != 0) {
             _trigger_node = (*submodel_iterator)->trigger_node;
@@ -185,11 +185,11 @@ void FGSubmodelMgr::update(double dt)
             sm_list_iterator end = sm_list.end();
 
             while (sm_list_itr != end) {
+                in_range = true;
 
                 if (id == 0) {
-                    SG_LOG(SG_GENERAL, SG_DEBUG,
-                        "Submodels: continuing: " << id << " name " << name );
-                    in_range = true;
+                    //SG_LOG(SG_GENERAL, SG_DEBUG,
+                    //        "Submodels: continuing: " << id << " name " << name );
                     ++sm_list_itr;
                     continue;
                 }
@@ -199,29 +199,28 @@ void FGSubmodelMgr::update(double dt)
                 if (parent_id == id) {
                     double parent_lat = (*sm_list_itr)->_getLatitude();
                     double parent_lon = (*sm_list_itr)->_getLongitude();
+                    string parent_name = (*sm_list_itr)->_getName();
                     double own_lat    = _user_lat_node->getDoubleValue();
                     double own_lon    = _user_lon_node->getDoubleValue();
                     double range_nm   = getRange(parent_lat, parent_lon, own_lat, own_lon);
-                    // cout << "parent " << parent_id << ", "<< parent_lat << ", " << parent_lon << endl;
-                    //cout << "own " << own_lat << ", " << own_lon << " range " << range_nm << endl;
+                    //cout << "parent name " << parent_name << ", "<< parent_id << ", "<< parent_lat << ", " << parent_lon << endl;
+                    //cout << "own name " << own_lat << ", " << own_lon << " range " << range_nm << endl;
 
                     if (range_nm > 15) {
-                        SG_LOG(SG_GENERAL, SG_DEBUG,
-                            "Submodels: skipping release: " << id);
+                        //SG_LOG(SG_GENERAL, SG_DEBUG,
+                        //    "Submodels: skipping release, out of range: " << id);
                         in_range = false;
                     }
-
                 }
 
                 ++sm_list_itr;
             } // end while
 
-            SG_LOG(SG_GENERAL, SG_DEBUG,
-                "Submodels end:  " << (*submodel_iterator)->id
-                << " name " << (*submodel_iterator)->name
-                << " count " << (*submodel_iterator)->count
-                << " in range " << in_range
-                );
+            /*SG_LOG(SG_GENERAL, SG_DEBUG,
+                    "Submodels end:  " << (*submodel_iterator)->id
+                    << " name " << (*submodel_iterator)->name
+                    << " count " << (*submodel_iterator)->count
+                    << " in range " << in_range);*/
 
             if ((*submodel_iterator)->count != 0 && in_range)
                 release(*submodel_iterator, dt);
@@ -236,7 +235,7 @@ void FGSubmodelMgr::update(double dt)
 bool FGSubmodelMgr::release(submodel *sm, double dt)
 {
     //cout << "release id " << sm->id << " name " << sm->name
-    //<< " first time " << sm->first_time  << " repeat " << (*sm)->repeat  <<
+    //<< " first time " << sm->first_time  << " repeat " << sm->repeat  <<
     //    endl;
 
     // only run if first time or repeat is set to true
@@ -287,6 +286,9 @@ bool FGSubmodelMgr::release(submodel *sm, double dt)
     ballist->setFuseRange(sm->fuse_range);
     ballist->setSubmodel(sm->submodel.c_str());
     ballist->setSubID(sm->sub_id);
+    ballist->setForceStabilisation(sm->force_stabilised);
+    ballist->setExternalForce(sm->ext_force);
+    ballist->setForcePath(sm->force_path.c_str());
     ai->attach(ballist);
 
     if (sm->count > 0)
@@ -312,11 +314,16 @@ void FGSubmodelMgr::transform(submodel *sm)
     // set initial conditions
     if (sm->contents_node != 0) {
         // get the weight of the contents (lbs) and convert to mass (slugs)
-        sm->contents = sm->contents_node->getDoubleValue();
+        sm->contents = sm->contents_node->getChild("level-lbs",0,1)->getDoubleValue();
+        //cout << "transform: contents " << sm->contents << endl;
         IC.mass = (sm->weight + sm->contents) * lbs_to_slugs;
+        //cout << "mass inc contents"  << IC.mass << endl;
 
         // set contents to 0 in the parent
-        sm->contents_node->setDoubleValue(0);
+        sm->contents_node->getChild("level-gal_us",0,1)->setDoubleValue(0);
+        /*cout << "contents " << sm->contents_node->getChild("level-gal_us")->getDoubleValue()
+        << " " << sm->contents_node->getChild("level-lbs",0,1)->getDoubleValue()
+        << endl;*/
     } else
         IC.mass = sm->weight * lbs_to_slugs;
 
@@ -463,22 +470,22 @@ void FGSubmodelMgr::transform(submodel *sm)
 
     // calculate the total speed north
     IC.total_speed_north = sm->speed * cos(IC.elevation * SG_DEGREES_TO_RADIANS)
-        * cos(IC.azimuth * SG_DEGREES_TO_RADIANS) + IC.speed_north_fps;
+            * cos(IC.azimuth * SG_DEGREES_TO_RADIANS) + IC.speed_north_fps;
 
     // calculate the total speed east
     IC.total_speed_east = sm->speed * cos(IC.elevation * SG_DEGREES_TO_RADIANS)
-        * sin(IC.azimuth * SG_DEGREES_TO_RADIANS) + IC.speed_east_fps;
+            * sin(IC.azimuth * SG_DEGREES_TO_RADIANS) + IC.speed_east_fps;
 
     // calculate the total speed down
     IC.total_speed_down = sm->speed * -sin(IC.elevation * SG_DEGREES_TO_RADIANS)
-        + IC.speed_down_fps;
+            + IC.speed_down_fps;
 
     // re-calculate speed, elevation and azimuth
     IC.speed = sqrt(IC.total_speed_north * IC.total_speed_north
-        + IC.total_speed_east * IC.total_speed_east
-        + IC.total_speed_down * IC.total_speed_down);
+            + IC.total_speed_east * IC.total_speed_east
+            + IC.total_speed_down * IC.total_speed_down);
 
-    // if speeds are low these calculations can become unreliable
+    // if speeds are low this calculation can become unreliable
     if (IC.speed > 1) {
         IC.azimuth = atan2(IC.total_speed_east , IC.total_speed_north) * SG_RADIANS_TO_DEGREES;
         //        cout << "azimuth1 " << IC.azimuth<<endl;
@@ -488,12 +495,11 @@ void FGSubmodelMgr::transform(submodel *sm)
             IC.azimuth += 360;
         else if (IC.azimuth >= 360)
             IC.azimuth -= 360;
+        // cout << "azimuth2 " << IC.azimuth<<endl;
 
-    // cout << "azimuth2 " << IC.azimuth<<endl;
-
-    IC.elevation = -atan(IC.total_speed_down / sqrt(IC.total_speed_north
-        * IC.total_speed_north + IC.total_speed_east * IC.total_speed_east))
-        * SG_RADIANS_TO_DEGREES;
+        IC.elevation = -atan(IC.total_speed_down / sqrt(IC.total_speed_north
+            * IC.total_speed_north + IC.total_speed_east * IC.total_speed_east))
+            * SG_RADIANS_TO_DEGREES;
     }
 }
 
@@ -518,7 +524,7 @@ void FGSubmodelMgr::loadAI()
     sm_list_iterator end = sm_list.end();
 
     while (sm_list_itr != end) {
-        string path = (*sm_list_itr)->_getPath();
+        string path = (*sm_list_itr)->_getSMPath();
 
         if (path.empty()) {
             ++sm_list_itr;
@@ -550,15 +556,13 @@ void FGSubmodelMgr::setData(int id, string& path, bool serviceable)
     SGPath config(globals->get_fg_root());
     config.append(path);
     SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: path " << path);
-
     try {
         SG_LOG(SG_GENERAL, SG_DEBUG,
-            "Submodels: Trying to read AI submodels file: " << config.str());
+                "Submodels: Trying to read AI submodels file: " << config.str());
         readProperties(config.str(), &root);
-
-    } catch (const sg_exception &e) {
+    } catch (const sg_exception &) {
         SG_LOG(SG_GENERAL, SG_DEBUG,
-            "Submodels: Unable to read AI submodels file: " << config.str());
+                "Submodels: Unable to read AI submodels file: " << config.str());
         return;
     }
 
@@ -597,7 +601,9 @@ void FGSubmodelMgr::setData(int id, string& path, bool serviceable)
         sm->contents_node   = fgGetNode(entry_node->getStringValue("contents", "none"), false);
         sm->speed_node      = fgGetNode(entry_node->getStringValue("speed-node", "none"), false);
         sm->submodel        = entry_node->getStringValue("submodel-path", "");
-
+        sm->force_stabilised= entry_node->getBoolValue("force-stabilised", false);
+        sm->ext_force       = entry_node->getBoolValue("external-force", false);
+        sm->force_path      = entry_node->getStringValue("force-path", "");
         //cout <<  "sm->contents_node " << sm->contents_node << endl;
         if (sm->contents_node != 0)
             sm->contents = sm->contents_node->getDoubleValue();
@@ -624,7 +630,6 @@ void FGSubmodelMgr::setData(int id, string& path, bool serviceable)
         sm->prop->tie("repeat", SGRawValuePointer<bool>(&(sm->repeat)));
         sm->prop->tie("id", SGRawValuePointer<int>(&(sm->id)));
         sm->prop->tie("sub-id", SGRawValuePointer<int>(&(sm->sub_id)));
-
         sm->prop->tie("serviceable", SGRawValuePointer<bool>(&(sm->serviceable)));
         string name = sm->name;
         sm->prop->setStringValue("name", name.c_str());
@@ -633,6 +638,10 @@ void FGSubmodelMgr::setData(int id, string& path, bool serviceable)
         sm->prop->setStringValue("submodel", submodel.c_str());
         //cout << " set submodel path " << submodel << endl;
 
+        string force_path = sm->force_path;
+        sm->prop->setStringValue("force_path", force_path.c_str());
+        //cout << "set force_path " << force_path << endl;
+
         if (sm->contents_node != 0)
             sm->prop->tie("contents-lbs", SGRawValuePointer<double>(&(sm->contents)));
 
@@ -651,12 +660,12 @@ void FGSubmodelMgr::setSubData(int id, string& path, bool serviceable)
         "Submodels: path " << path);
     try {
         SG_LOG(SG_GENERAL, SG_DEBUG,
-            "Submodels: Trying to read AI submodels file: " << config.str());
+                "Submodels: Trying to read AI submodels file: " << config.str());
         readProperties(config.str(), &root);
 
-    } catch (const sg_exception &e) {
+    } catch (const sg_exception &) {
         SG_LOG(SG_GENERAL, SG_DEBUG,
-            "Submodels: Unable to read AI submodels file: " << config.str());
+                "Submodels: Unable to read AI submodels file: " << config.str());
         return;
     }
 
@@ -695,6 +704,8 @@ void FGSubmodelMgr::setSubData(int id, string& path, bool serviceable)
         sm->contents_node   = fgGetNode(entry_node->getStringValue("contents", "none"), false);
         sm->speed_node      = fgGetNode(entry_node->getStringValue("speed-node", "none"), false);
         sm->submodel        = entry_node->getStringValue("submodel-path", "");
+        sm->ext_force       = entry_node->getBoolValue("external-force", false);
+        sm->force_path      = entry_node->getStringValue("force-path", "");
 
         //cout <<  "sm->contents_node " << sm->contents_node << endl;
         if (sm->contents_node != 0)
@@ -730,6 +741,10 @@ void FGSubmodelMgr::setSubData(int id, string& path, bool serviceable)
         sm->prop->setStringValue("submodel", submodel.c_str());
         // cout << " set submodel path " << submodel<< endl;
 
+        string force_path = sm->force_path;
+        sm->prop->setStringValue("force_path", force_path.c_str());
+        //cout << "set force_path " << force_path << endl;
+
         if (sm->contents_node != 0)
             sm->prop->tie("contents-lbs", SGRawValuePointer<double>(&(sm->contents)));
 
@@ -749,10 +764,10 @@ void FGSubmodelMgr::loadSubmodels()
         if (!submodel.empty()) {
             //int id = (*submodel_iterator)->id;
             bool serviceable = true;
-            SG_LOG(SG_GENERAL, SG_ALERT, "found path sub sub "
-                << submodel
-                << " index " << index
-                << "name " << (*submodel_iterator)->name);
+            //SG_LOG(SG_GENERAL, SG_DEBUG, "found path sub sub "
+            //        << submodel
+            //        << " index " << index
+            //        << "name " << (*submodel_iterator)->name);
 
             (*submodel_iterator)->sub_id = index;
             setSubData(index, submodel, serviceable);
@@ -768,17 +783,17 @@ void FGSubmodelMgr::loadSubmodels()
         ++subsubmodel_iterator;
     }
 
-    submodel_iterator = submodels.begin();
+    //submodel_iterator = submodels.begin();
 
-    while (submodel_iterator != submodels.end()) {
-        int id = (*submodel_iterator)->id;
-        SG_LOG(SG_GENERAL, SG_DEBUG,"after pusback "
-            << " id " << id
-            << " name " << (*submodel_iterator)->name
-            << " sub id " << (*submodel_iterator)->sub_id);
+    //while (submodel_iterator != submodels.end()) {
+        //int id = (*submodel_iterator)->id;
+        //SG_LOG(SG_GENERAL, SG_DEBUG,"after pushback "
+        //        << " id " << id
+        //        << " name " << (*submodel_iterator)->name
+        //        << " sub id " << (*submodel_iterator)->sub_id);
 
-        ++submodel_iterator;
-    }
+        //++submodel_iterator;
+    //}
 }
 
 // end of submodel.cxx