bool ReferencedBehaviorTask::onenter(Agent* pAgent) { BEHAVIAC_UNUSED_VAR(pAgent); BEHAVIAC_ASSERT(ReferencedBehavior::DynamicCast(this->m_node) != 0); ReferencedBehavior* pNode = (ReferencedBehavior*)this->m_node; BEHAVIAC_ASSERT(pNode != 0); this->m_nextStateId = -1; pNode->SetTaskParams(pAgent); this->m_subTree = Workspace::GetInstance()->CreateBehaviorTreeTask(pNode->m_referencedBehaviorPath.c_str()); { const char* pThisTree = pAgent->btgetcurrent()->GetName().c_str(); const char* pReferencedTree = pNode->m_referencedBehaviorPath.c_str(); behaviac::string msg = FormatString("%s[%d] %s", pThisTree, pNode->GetId(), pReferencedTree); LogManager::GetInstance()->Log(pAgent, msg.c_str(), EAR_none, ELM_jump); } return true; }
EBTStatus PlannerTaskReference::update(Agent* pAgent, EBTStatus childStatus) { BEHAVIAC_UNUSED_VAR(childStatus); BEHAVIAC_ASSERT(ReferencedBehavior::DynamicCast(this->m_node) != 0); //BEHAVIAC_ASSERT(this->m_node is ReferencedBehavior); ReferencedBehavior* pNode = (ReferencedBehavior*)this->m_node; //ReferencedBehavior pNode = this->m_node as ReferencedBehavior; BEHAVIAC_ASSERT(pNode != NULL); EBTStatus status = BT_RUNNING; //pNode->SetTaskParams(pAgent); if (pNode->RootTaskNode() == NULL) { status = this->m_subTree->exec(pAgent); } else { #if !BEHAVIAC_RELEASE if (!_logged) { pAgent->LogJumpTree(pNode->GetReferencedTree()); _logged = true; } #endif BEHAVIAC_ASSERT(this->m_children.size() == 1); BehaviorTask* c = this->m_children[0]; status = c->exec(pAgent); } return status; }
bool ReferencedBehaviorTask::onenter(Agent* pAgent) { BEHAVIAC_UNUSED_VAR(pAgent); BEHAVIAC_ASSERT(ReferencedBehavior::DynamicCast(this->m_node) != 0); ReferencedBehavior* pNode = (ReferencedBehavior*)this->m_node; BEHAVIAC_ASSERT(pNode != 0); this->m_nextStateId = -1; pNode->SetTaskParams(pAgent); this->m_subTree = Workspace::GetInstance()->CreateBehaviorTreeTask(pNode->m_referencedBehaviorPath.c_str()); return true; }
bool PlannerTaskReference::onenter(Agent* pAgent) { BEHAVIAC_UNUSED_VAR(pAgent); BEHAVIAC_ASSERT(ReferencedBehavior::DynamicCast(this->m_node) != 0); ReferencedBehavior* pNode = (ReferencedBehavior*)this->m_node; BEHAVIAC_UNUSED_VAR(pNode); BEHAVIAC_ASSERT(pNode != NULL); #if !BEHAVIAC_RELEASE _logged = false; #endif pNode->SetTaskParams(pAgent); this->m_subTree = Workspace::GetInstance()->CreateBehaviorTreeTask(pNode->GetReferencedTree()); return true; }
void PlannerTaskReference::onexit(Agent* pAgent, EBTStatus status) { BEHAVIAC_UNUSED_VAR(pAgent); BEHAVIAC_UNUSED_VAR(status); BEHAVIAC_ASSERT(ReferencedBehavior::DynamicCast(this->m_node) != 0); ReferencedBehavior* pNode = (ReferencedBehavior*)this->m_node; BEHAVIAC_UNUSED_VAR(pNode); BEHAVIAC_ASSERT(pNode != NULL); this->m_subTree = 0; #if !BEHAVIAC_RELEASE pAgent->LogReturnTree(pNode->GetReferencedTree()); #endif BEHAVIAC_ASSERT(this->currentState != NULL); this->currentState->Pop(); this->currentState = 0; }
bool ReferencedBehavior::decompose(BehaviorNode* node, PlannerTaskComplex* seqTask, int depth, Planner* planner) { bool bOk = false; ReferencedBehavior* taskSubTree = (ReferencedBehavior*)node;// as ReferencedBehavior; BEHAVIAC_ASSERT(taskSubTree != 0); int depth2 = planner->GetAgent()->m_variables.Depth(); BEHAVIAC_UNUSED_VAR(depth2); { AgentState::AgentStateScope scopedState(planner->GetAgent()->m_variables.Push(false)); //planner.agent.Variables.Log(planner.agent, true); taskSubTree->SetTaskParams(planner->GetAgent()); Task* task = taskSubTree->RootTaskNode(); if (task != 0) { planner->LogPlanReferenceTreeEnter(planner->GetAgent(), taskSubTree); const BehaviorNode* tree = task->GetParent(); tree->InstantiatePars(planner->GetAgent()); PlannerTask* childTask = planner->decomposeNode(task, depth); if (childTask != 0) { seqTask->AddChild(childTask); bOk = true; } tree->UnInstantiatePars(planner->GetAgent()); planner->LogPlanReferenceTreeExit(planner->GetAgent(), taskSubTree); BEHAVIAC_ASSERT(true); } } BEHAVIAC_ASSERT(planner->GetAgent()->m_variables.Depth() == depth2); return bOk; }