bool PlannerTaskIterator::onenter(Agent* pAgent) { bool bOk = PlannerTaskComplex::onenter(pAgent); DecoratorIterator* pNode = (DecoratorIterator*)this->m_node; int count = 0; bOk = pNode->IterateIt(pAgent, this->m_index, count); return bOk; }
bool DecoratorIterator::decompose(BehaviorNode* node, PlannerTaskComplex* seqTask, int depth, Planner* planner) { bool bOk = false; DecoratorIterator* pForEach = (DecoratorIterator*)node; int childCount = pForEach->GetChildrenCount(); BEHAVIAC_ASSERT(childCount == 1); BEHAVIAC_UNUSED_VAR(childCount); BehaviorNode* childNode = (BehaviorNode*)pForEach->GetChild(0); bool bGoOn = true; int count = 0; int index = 0; while (bGoOn) { int depth2 = planner->GetAgent()->m_variables.Depth(); BEHAVIAC_UNUSED_VAR(depth2); { AgentState::AgentStateScope scopedState(planner->GetAgent()->m_variables.Push(false)); bGoOn = pForEach->IterateIt(planner->GetAgent(), index, count); if (bGoOn) { planner->LogPlanForEachBegin(planner->GetAgent(), pForEach, index, count); PlannerTask* childTask = planner->decomposeNode(childNode, depth); planner->LogPlanForEachEnd(planner->GetAgent(), pForEach, index, count, childTask != NULL ? "success" : "failure"); if (childTask != NULL) { BEHAVIAC_ASSERT(PlannerTaskIterator::DynamicCast(seqTask) != 0); PlannerTaskIterator* pForEachTask = (PlannerTaskIterator*)seqTask; pForEachTask->SetIndex(index); seqTask->AddChild(childTask); bOk = true; break; } index++; } BEHAVIAC_ASSERT(planner->GetAgent()->m_variables.Depth() == depth2); } } return bOk; }