]> git.mxchange.org Git - flightgear.git/commitdiff
Move methods "setParentNode()" etc. to make them available to all AI Objects.
authorVivian Meazza <vivian.meazza@lineone.net>
Wed, 8 Sep 2010 16:38:35 +0000 (17:38 +0100)
committerAnders Gidenstam <anders@gidenstam.org>
Fri, 17 Sep 2010 19:06:35 +0000 (21:06 +0200)
Signed-off-by: Vivian Meazza <vivian.meazza@lineone.net>
src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx

index 517b91b1d31732f47063bd22f19c389b9201242b..6f576078cac6cc7087d60ae7a45c71d5847ed784 100644 (file)
@@ -68,7 +68,8 @@ FGAIBase::FGAIBase(object_type ot) :
 
     _refID( _newAIModelID() ),
     _otype(ot),
-    _initialized(false)
+    _initialized(false),
+    _parent("")
 {
     tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 0.0;
     tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0;
@@ -226,17 +227,22 @@ bool FGAIBase::init(bool search_in_AI_path) {
 
 void FGAIBase::initModel(osg::Node *node)
 {
-    if (model.valid()) {
+    if (model.valid()) { 
+
         if( _path != ""){
             props->setStringValue("submodels/path", _path.c_str());
             SG_LOG(SG_INPUT, SG_DEBUG, "AIBase: submodels/path " << _path);
         }
+
+        if( _parent!= ""){
+            props->setStringValue("parent-name", _parent.c_str());
+        }
+
         fgSetString("/ai/models/model-added", props->getPath().c_str());
     } else if (!model_path.empty()) {
         SG_LOG(SG_INPUT, SG_WARN, "AIBase: Could not load model " << model_path);
     }
 
-    //props->setStringValue("submodels/path", _path.c_str()); 
     setDie(false);
 }
 
@@ -527,6 +533,46 @@ void FGAIBase::_setSubID( int s ) {
     _subID = s;
 }
 
+void FGAIBase::setParentNode() {
+//    cout << "AIBase: setParentNode " << _parent << endl;
+
+    const SGPropertyNode_ptr ai = fgGetNode("/ai/models", true);
+
+    for (int i = ai->nChildren() - 1; i >= -1; i--) {
+        SGPropertyNode_ptr model;
+
+        if (i < 0) { // last iteration: selected model
+            model = _selected_ac;
+        } else {
+            model = ai->getChild(i);
+            string path = ai->getPath();
+            const string name = model->getStringValue("name");
+
+            if (!model->nChildren()){
+                continue;
+            }
+            if (name == _parent) {
+                _selected_ac = model;  // save selected model for last iteration
+                break;
+            }
+
+        }
+        if (!model)
+            continue;
+
+    }// end for loop
+
+    if (_selected_ac != 0){
+        const string name = _selected_ac->getStringValue("name");
+        //setParent();
+
+    } else {
+        SG_LOG(SG_GENERAL, SG_ALERT, "AIEscort: " << _name
+            << " parent not found: dying ");
+        setDie(true);
+    }
+
+}
 double FGAIBase::_getLongitude() const {
     return pos.getLongitudeDeg();
 }
index 4c2c591af19594e9457c14e5e0dbc660de6542b7..3d756254a21767244afb99f4f3715aaf929cd836 100644 (file)
@@ -85,6 +85,8 @@ public:
     void setImpactLat( double lat );
     void setImpactLon( double lon );
     void setImpactElev( double e );
+    void setParentName(const string& p);
+    void setParentNode();
 
     int getID() const;
     int _getSubID() const;
@@ -113,12 +115,14 @@ public:
     string _callsign;
     string _submodel;
     string _name;
+    string _parent;
 
     SGGeod userpos;
 
 
 protected:
 
+    SGPropertyNode_ptr _selected_ac;
     SGPropertyNode_ptr props;
     SGPropertyNode_ptr trigger_node;
     SGPropertyNode_ptr model_removed; // where to report model removal
@@ -357,6 +361,10 @@ inline void FGAIBase::setYawoffset(double y) {
     _yaw_offset = y;
 }
 
+inline void FGAIBase::setParentName(const string& p) {
+    _parent = p;
+}
+
 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
 
 inline bool FGAIBase::getDie() { return delete_me; }