]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/submodel.cxx
Make traffic take-off roll look a little better.
[flightgear.git] / src / AIModel / submodel.cxx
index 8963be7191fa96449ec9bb25be3e0c624c66c06e..e4746bfc8d3cc37bd65d319b81d2b7e2595b9249 100644 (file)
@@ -43,6 +43,11 @@ FGSubmodelMgr::~FGSubmodelMgr()
 {
 }
 
+FGAIManager* FGSubmodelMgr::aiManager()
+{
+   return (FGAIManager*)globals->get_subsystem("ai-model");
+}
+
 void FGSubmodelMgr::init()
 {
     index = 0;
@@ -74,13 +79,8 @@ void FGSubmodelMgr::init()
     _contrail_trigger       = fgGetNode("ai/submodels/contrails", true);
     _contrail_trigger->setBoolValue(false);
 
-    ai = (FGAIManager*)globals->get_subsystem("ai_model");
-
     load();
 
-    //_model_added_node = fgGetNode("ai/models/model-added", true);
-    //_model_added_node->addChangeListener(this, false);
-
 }
 
 void FGSubmodelMgr::postinit() {
@@ -119,9 +119,9 @@ void FGSubmodelMgr::update(double dt)
     _expiry = false;
 
     // check if the submodel hit an object or terrain
-    sm_list = ai->get_ai_list();
-    sm_list_iterator sm_list_itr = sm_list.begin();
-    sm_list_iterator end = sm_list.end();
+    FGAIManager::ai_list_type sm_list(aiManager()->get_ai_list());
+    FGAIManager::ai_list_iterator sm_list_itr = sm_list.begin(),
+      end = sm_list.end();
 
     for (; sm_list_itr != end; ++sm_list_itr) {
         FGAIBase::object_type object_type =(*sm_list_itr)->getType();
@@ -136,19 +136,19 @@ void FGSubmodelMgr::update(double dt)
         if ( parent_subID == 0 || id == -1) // this entry in the list has no associated submodel
             continue;                       // or is invalid so we can continue
 
-        //SG_LOG(SG_GENERAL, SG_DEBUG, "Submodel: Impact " << _impact << " hit! "
+        //SG_LOG(SG_AI, SG_DEBUG, "Submodel: Impact " << _impact << " hit! "
         //        << _hit <<" parent_subID " << parent_subID);
 
         _hit = (*sm_list_itr)->_getCollisionData();
         _impact = (*sm_list_itr)->_getImpactData();
         _expiry = (*sm_list_itr)->_getExpiryData();
 
-        //SG_LOG(SG_GENERAL, SG_ALERT, "Submodel: " << (*sm_list_itr)->_getName()
+        //SG_LOG(SG_AI, SG_ALERT, "Submodel: " << (*sm_list_itr)->_getName()
         //    << " Impact " << _impact << " hit! " << _hit
         //    << " exipiry :-( " << _expiry );
 
         if (_impact || _hit || _expiry) {
-    //        SG_LOG(SG_GENERAL, SG_ALERT, "Submodel: Impact " << _impact << " hit! " << _hit 
+    //        SG_LOG(SG_AI, SG_ALERT, "Submodel: Impact " << _impact << " hit! " << _hit
                 //<< " exipiry :-( " << _expiry );
 
             submodel_iterator = submodels.begin();
@@ -191,7 +191,7 @@ void FGSubmodelMgr::update(double dt)
     while (submodel_iterator != submodels.end())  {
         i++;
 
-        /*SG_LOG(SG_GENERAL, SG_DEBUG,
+        /*SG_LOG(SG_AI, SG_DEBUG,
                 "Submodels:  " << (*submodel_iterator)->id
                 << " name " << (*submodel_iterator)->name
                 );*/
@@ -207,10 +207,10 @@ void FGSubmodelMgr::update(double dt)
 
         if (trigger && (*submodel_iterator)->count != 0) {
 
-            int id = (*submodel_iterator)->id;
+            //int id = (*submodel_iterator)->id;
             string name = (*submodel_iterator)->name;
             
-            SG_LOG(SG_GENERAL, SG_DEBUG,
+            SG_LOG(SG_AI, SG_DEBUG,
             "Submodels release:  " << (*submodel_iterator)->id
             << " name " << (*submodel_iterator)->name
             << " count " << (*submodel_iterator)->count
@@ -300,10 +300,11 @@ bool FGSubmodelMgr::release(submodel *sm, double dt)
     ballist->setZoffset(sm->z_offset);
     ballist->setPitchoffset(sm->pitch_offset);
     ballist->setYawoffset(sm->yaw_offset);
-    ballist->setParentNode(_selected_ac);
+    ballist->setParentNodes(_selected_ac);
     ballist->setContentsNode(sm->contents_node);
     ballist->setWeight(sm->weight);
-    ai->attach(ballist);
+    
+    aiManager()->attach(ballist);
 
     if (sm->count > 0)
         sm->count--;
@@ -341,7 +342,7 @@ void FGSubmodelMgr::transform(submodel *sm)
         IC.mass = sm->weight * lbs_to_slugs;
 
     int id = sm->id;
-    int sub_id = sm->sub_id;
+    //int sub_id = sm->sub_id;
     string name = sm->name;
 
 
@@ -386,8 +387,6 @@ void FGSubmodelMgr::transform(submodel *sm)
     } else {
         // set the data for a submodel tied to an AI Object
         //cout << " set the data for a submodel tied to an AI Object " << id << endl;
-        sm_list_iterator sm_list_itr = sm_list.begin();
-        sm_list_iterator end = sm_list.end();
         setParentNode(id);
     }
 
@@ -478,17 +477,17 @@ void FGSubmodelMgr::updatelat(double lat)
 
 void FGSubmodelMgr::loadAI()
 {
-    SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: Loading AI submodels ");
+    SG_LOG(SG_AI, SG_DEBUG, "Submodels: Loading AI submodels ");
 
-    sm_list = ai->get_ai_list();
+    FGAIManager::ai_list_type sm_list(aiManager()->get_ai_list());
 
     if (sm_list.empty()) {
-        SG_LOG(SG_GENERAL, SG_ALERT, "Submodels: Unable to read AI submodel list");
+        SG_LOG(SG_AI, SG_ALERT, "Submodels: Unable to read AI submodel list");
         return;
     }
 
-    sm_list_iterator sm_list_itr = sm_list.begin();
-    sm_list_iterator end = sm_list.end();
+    FGAIManager::ai_list_iterator sm_list_itr = sm_list.begin(),
+      end = sm_list.end();
 
     while (sm_list_itr != end) {
         string path = (*sm_list_itr)->_getSMPath();
@@ -517,11 +516,11 @@ void FGSubmodelMgr::setData(int id, string& path, bool serviceable)
 
     SGPath config = globals->resolve_aircraft_path(path);
     try {
-        SG_LOG(SG_GENERAL, SG_DEBUG,
+        SG_LOG(SG_AI, SG_DEBUG,
                 "Submodels: Trying to read AI submodels file: " << config.str());
         readProperties(config.str(), &root);
     } catch (const sg_exception &) {
-        SG_LOG(SG_GENERAL, SG_ALERT,
+        SG_LOG(SG_AI, SG_ALERT,
                 "Submodels: Unable to read AI submodels file: " << config.str());
         return;
     }
@@ -621,12 +620,12 @@ void FGSubmodelMgr::setSubData(int id, string& path, bool serviceable)
     SGPath config = globals->resolve_aircraft_path(path);
 
     try {
-        SG_LOG(SG_GENERAL, SG_DEBUG,
+        SG_LOG(SG_AI, SG_DEBUG,
                 "Submodels: Trying to read AI submodels file: " << config.str());
         readProperties(config.str(), &root);
 
     } catch (const sg_exception &) {
-        SG_LOG(SG_GENERAL, SG_ALERT,
+        SG_LOG(SG_AI, SG_ALERT,
                 "Submodels: Unable to read AI submodels file: " << config.str());
         return;
     }
@@ -723,7 +722,7 @@ void FGSubmodelMgr::setSubData(int id, string& path, bool serviceable)
 
 void FGSubmodelMgr::loadSubmodels()
 {
-    SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: Loading sub submodels");
+    SG_LOG(SG_AI, SG_DEBUG, "Submodels: Loading sub submodels");
 
     _found_sub = false;
 
@@ -734,7 +733,7 @@ void FGSubmodelMgr::loadSubmodels()
         if (!submodel.empty()) {
             //int id = (*submodel_iterator)->id;
             bool serviceable = true;
-            SG_LOG(SG_GENERAL, SG_DEBUG, "found path sub sub "
+            SG_LOG(SG_AI, SG_DEBUG, "found path sub sub "
                     << submodel
                     << " index " << index
                     << " name " << (*submodel_iterator)->name);
@@ -767,7 +766,7 @@ void FGSubmodelMgr::loadSubmodels()
     //    int id = (*submodel_iterator)->id;
     //    subcount++;
 
-    //    SG_LOG(SG_GENERAL, SG_ALERT,"after pushback "
+    //    SG_LOG(SG_AI, SG_ALERT,"after pushback "
     //            << " parent id " << id
     //            << " name " << (*submodel_iterator)->name
     //            << " sub id " << (*submodel_iterator)->sub_id
@@ -821,48 +820,35 @@ void FGSubmodelMgr::setOffsetPos(){
 
 void FGSubmodelMgr::valueChanged(SGPropertyNode *prop)
 {
-//    cout << "LISTENER: " << endl;
+    return; // this isn't working atm
 
     const char* _model_added = _model_added_node->getStringValue();
 
     basic_string <char>::size_type indexCh2b;
 
     string str2 = _model_added;
-    const char *cstr2b = "ballistic";
+    const char *cstr2b = "multiplayer";
     indexCh2b = str2.find( cstr2b, 0 );
 
-//    cout << "model added - " << str2 <<" now do something "<< endl;
-
     if (indexCh2b != string::npos ){        // we will ignore Ballistic Objects - there are potentially too many 
-        return;
-    } else {
-       
-        SGPropertyNode *a_node = fgGetNode(_model_added, true );
-        SGPropertyNode *sub_node = a_node->getChild("submodels", 0, true);
+
+        //cout << "Submodels: model added - " << str2 <<" read path "<< endl;
+        //return;
+        SGPropertyNode *a_node = fgGetNode(_model_added, true);
+        SGPropertyNode *sub_node = a_node->getChild("sim", 0, true);
         SGPropertyNode_ptr path_node = sub_node->getChild("path", 0, true);
+        SGPropertyNode_ptr callsign_node = a_node->getChild("callsign", 0, true);
 
-        string path = path_node->getStringValue();
+        string callsign = callsign_node->getStringValue();
 
-        if (path.empty()){
-            // nothing to do - return
-            //cout << "subpath empty - return"  << endl << endl;
+        //cout << "Submodels: model added - " << callsign <<" read callsign "<< endl;
             return;
-        } else {
-            //cout << "subpath found - loading"  << endl << endl;
-            SGPropertyNode_ptr ident_node = a_node->getChild("id", 0, true);
-            int id = ident_node->getIntValue();
-
-            setData(id, path, true);
-
-            _found_sub = true;
-
-            while (_found_sub)
-                loadSubmodels();
 
+        } else {
+            cout << "model added - " << str2 <<" returning "<< endl;
+        return;
         }
 
-    }
-
 }
 
 void FGSubmodelMgr::setParentNode(int id) {
@@ -912,7 +898,7 @@ void FGSubmodelMgr::setParentNode(int id) {
         //cout << name << " IC.speed " << IC.speed << endl;
 
     } else {
-        SG_LOG(SG_GENERAL, SG_ALERT, "AISubmodel: parent node not found ");
+        SG_LOG(SG_AI, SG_ALERT, "AISubmodel: parent node not found ");
     }
 
 }