Example #1
0
        protected EBTStatus tickCurrentNode(Agent pAgent)
        {
            EBTStatus status = this.m_currentTask.GetStatus();

            if ((status != EBTStatus.BT_INVALID) && (status != EBTStatus.BT_RUNNING))
            {
                return(status);
            }
            BehaviorTask currentTask = this.m_currentTask;
            EBTStatus    childStatus = this.m_currentTask.exec(pAgent);

            if (childStatus != EBTStatus.BT_RUNNING)
            {
                BranchTask parent = currentTask.GetParent();
                this.SetCurrentTask(null);
                while ((parent != null) && (parent != this))
                {
                    childStatus = parent.update(pAgent, childStatus);
                    if (childStatus == EBTStatus.BT_RUNNING)
                    {
                        return(EBTStatus.BT_RUNNING);
                    }
                    parent.onexit_action(pAgent, childStatus);
                    parent.m_status = childStatus;
                    parent          = parent.GetParent();
                }
            }
            return(childStatus);
        }
        private bool oneventCurrentNode(Agent pAgent, string eventName)
        {
            Debug.Check(this.m_currentTask != null);

            EBTStatus s = this.m_currentTask.GetStatus();

            Debug.Check(s == EBTStatus.BT_RUNNING && this.m_node.HasEvents());

            bool bGoOn = this.m_currentTask.onevent(pAgent, eventName);

            //give the handling back to parents
            if (bGoOn && this.m_currentTask != null)
            {
                BranchTask parentBranch = this.m_currentTask.GetParent();

                //back track the parents until the branch
                while (parentBranch != null && parentBranch != this)
                {
                    Debug.Check(parentBranch.GetStatus() == EBTStatus.BT_RUNNING);

                    bGoOn = parentBranch.onevent(pAgent, eventName);

                    if (!bGoOn)
                    {
                        return(false);
                    }

                    parentBranch = parentBranch.GetParent();
                }
            }

            return(bGoOn);
        }
Example #3
0
        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);
        }
Example #4
0
        private bool CheckParentUpdatePreconditions(Agent pAgent)
        {
            bool bValid = true;

            if (this.m_bHasManagingParent)
            {
                bool           bHasManagingParent = false;
                const int      kMaxParentsCount   = 512;
                int            parentsCount       = 0;
                BehaviorTask[] parents            = new BehaviorTask[kMaxParentsCount];

                BranchTask parentBranch = this.GetParent();

                parents[parentsCount++] = this;

                //back track the parents until the managing branch
                while (parentBranch != null)
                {
                    Debug.Check(parentsCount < kMaxParentsCount, "weird tree!");

                    parents[parentsCount++] = parentBranch;

                    if (parentBranch.GetCurrentTask() == this)
                    {
                        //Debug.Check(parentBranch->GetNode()->IsManagingChildrenAsSubTrees());

                        bHasManagingParent = true;
                        break;
                    }

                    parentBranch = parentBranch.GetParent();
                }

                if (bHasManagingParent)
                {
                    for (int i = parentsCount - 1; i >= 0; --i)
                    {
                        BehaviorTask pb = parents[i];

                        bValid = pb.CheckPreconditions(pAgent, true);

                        if (!bValid)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                bValid = this.CheckPreconditions(pAgent, true);
            }

            return(bValid);
        }
Example #5
0
        protected EBTStatus tickCurrentNode(Agent pAgent)
        {
            Debug.Check(this.m_currentTask != null);

            EBTStatus s = this.m_currentTask.GetStatus();

            if (s == EBTStatus.BT_INVALID || s == EBTStatus.BT_RUNNING)
            {
                //this.m_currentTask could be cleared in ::tick, to remember it
                BehaviorTask currentTask = this.m_currentTask;
                EBTStatus    status      = this.m_currentTask.exec(pAgent);

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

                    BranchTask parentBranch = currentTask.GetParent();

                    this.SetCurrentTask(null);

                    //back track the parents until the branch
                    while (parentBranch != null && parentBranch != this)
                    {
                        status = parentBranch.update(pAgent, status);
                        if (status == EBTStatus.BT_RUNNING)
                        {
                            return(EBTStatus.BT_RUNNING);
                        }

                        parentBranch.onexit_action(pAgent, status);

                        parentBranch.m_status = status;

                        Debug.Check(parentBranch.m_currentTask == null);

                        parentBranch = parentBranch.GetParent();
                    }
                }

                return(status);
            }

            return(s);
        }
Example #6
0
        private bool oneventCurrentNode(Agent pAgent, string eventName)
        {
            EBTStatus status = this.m_currentTask.GetStatus();
            bool      flag   = this.m_currentTask.onevent(pAgent, eventName);

            if (flag)
            {
                BranchTask parent = this.m_currentTask.GetParent();
                while (parent != null && parent != this)
                {
                    flag = parent.onevent(pAgent, eventName);
                    if (!flag)
                    {
                        return(false);
                    }
                    parent = parent.GetParent();
                }
            }
            return(flag);
        }
Example #7
0
        private bool oneventCurrentNode(Agent pAgent, string eventName)
        {
            EBTStatus status = this.m_currentTask.GetStatus();
            bool      flag   = this.m_currentTask.onevent(pAgent, eventName);

            if (flag)
            {
                for (BranchTask task = this.m_currentTask.GetParent(); (task != null) && (task != this); task = task.GetParent())
                {
                    flag = task.onevent(pAgent, eventName);
                    if (!flag)
                    {
                        return(false);
                    }
                }
            }
            return(flag);
        }