+bool FGAIBase::setParentNode() {
+
+ if (_parent == ""){
+ SG_LOG(SG_GENERAL, SG_ALERT, "AIBase: " << _name
+ << " parent not set ");
+ return false;
+ }
+
+ 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");
+ return true;
+ } else {
+ SG_LOG(SG_GENERAL, SG_ALERT, "AIBase: " << _name
+ << " parent not found: dying ");
+ setDie(true);
+ return false;
+ }
+
+}
+