diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 862c78f80..12214e4db 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -83,15 +83,8 @@ FGAIBase::~FGAIBase() { if (props) { SGPropertyNode* parent = props->getParent(); - if (parent) { + if (parent) model_removed->setStringValue(props->getPath()); - parent->removeChild(props->getName(), props->getIndex(), false); - } - - // so that radar does not have to do extra checks - props->setBoolValue("radar/in-range", false); - props->removeChild("id", 0); - } delete fp; fp = 0; @@ -507,6 +500,10 @@ bool FGAIBase::_getServiceable() const { return serviceable; } +SGPropertyNode* FGAIBase::_getProps() const { + return props; +} + void FGAIBase::_setAltitude( double _alt ) { setAltitude( _alt ); } diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 2d68fa94d..0d99103d1 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -184,6 +184,7 @@ public: double _get_speed_north_fps() const; bool _getServiceable() const; + SGPropertyNode* _getProps() const; const char* _getPath(); const char* _getCallsign(); diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index 0351e8342..e1dce1a04 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -122,7 +122,19 @@ void FGAIManager::update(double dt) { tmgr->release((*ai_list_itr)->getID()); --mNumAiModels; --(mNumAiTypeModels[(*ai_list_itr)->getType()]); - (*ai_list_itr)->unbind(); + FGAIBase *base = *ai_list_itr; + SGPropertyNode *props = base->_getProps(); + + props->setBoolValue("valid", false); + base->unbind(); + + // for backward compatibility reset properties, so that aircraft, + // which don't know the property, keep working + // TODO: remove after a while + props->setIntValue("id", -1); + props->setBoolValue("radar/in-range", false); + props->setIntValue("refuel/tanker", false); + ai_list_itr = ai_list.erase(ai_list_itr); } else { fetchUserState(); @@ -150,11 +162,10 @@ FGAIManager::attach(SGSharedPtr model) //more than 10000 mp-aircrafts in the property tree we should optimize the mp-server { p = root->getNode(typeString, i, false); - if (!p) break; - if (p->getIntValue("id",-1)==model->getID()) - { + if (!p || !p->getBoolValue("valid", false)) + break; + if (p->getIntValue("id",-1)==model->getID()) { p->setStringValue("callsign","***invalid node***"); //debug only, should never set! - } } p = root->getNode(typeString, i, true); @@ -166,6 +177,7 @@ FGAIManager::attach(SGSharedPtr model) || model->getType()==FGAIBase::otMultiplayer || model->getType()==FGAIBase::otStatic); model->bind(); + p->setBoolValue("valid", true); }