From: Vivian Meazza Date: Wed, 8 Sep 2010 16:38:35 +0000 (+0100) Subject: Move methods "setParentNode()" etc. to make them available to all AI Objects. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c7e864cee9fadf0864266ca496872bbdc5725b10;p=flightgear.git Move methods "setParentNode()" etc. to make them available to all AI Objects. Signed-off-by: Vivian Meazza --- diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 517b91b1d..6f576078c 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -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(); } diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 4c2c591af..3d756254a 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -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; }