Exemple #1
0
        protected EBTStatus resume_branch(Agent pAgent, EBTStatus status)
        {
            Debug.Check(this.m_currentTask != null);
            Debug.Check(status == EBTStatus.BT_SUCCESS || status == EBTStatus.BT_FAILURE);

            BranchTask parent = null;

            if (this.m_currentTask.GetNode().IsManagingChildrenAsSubTrees())
            {
                parent = (BranchTask)this.m_currentTask;
            }
            else
            {
                parent = this.m_currentTask.GetParent();
            }

            //clear it as it ends and the next exec might need to set it
            this.m_currentTask = null;

            if (parent != null)
            {
                EBTStatus s = parent.exec(pAgent, status);

                return(s);
            }

            return(EBTStatus.BT_INVALID);
        }
        private EBTStatus execCurrentTask(Agent pAgent)
        {
            Debug.Check(this.m_currentTask != null && this.m_currentTask.GetStatus() == EBTStatus.BT_RUNNING);

            //this.m_currentTask could be cleared in ::tick, to remember it
            EBTStatus status = this.m_currentTask.exec(pAgent);

            //give the handling back to parents
            if (status != EBTStatus.BT_RUNNING)
            {
                Debug.Check(status == EBTStatus.BT_SUCCESS || status == EBTStatus.BT_FAILURE);
                Debug.Check(this.m_currentTask.m_status == status);

                BranchTask parentBranch = this.m_currentTask.GetParent();

                this.m_currentTask = null;

                //back track the parents until the branch
                while (parentBranch != null && parentBranch != this)
                {
                    status = parentBranch.exec(pAgent, status);

                    if (status == EBTStatus.BT_RUNNING)
                    {
                        return(EBTStatus.BT_RUNNING);
                    }

                    Debug.Check(parentBranch.m_status == status);

                    parentBranch = parentBranch.GetParent();
                }
            }

            return(status);
        }