예제 #1
0
        public EBTStatus ParallelUpdate(Agent pAgent, List <BehaviorTask> children)
        {
            bool sawSuccess    = false;
            bool sawFail       = false;
            bool sawRunning    = false;
            bool sawAllFails   = true;
            bool sawAllSuccess = true;

            bool bLoop = (this.m_childFinishPolicy == CHILDFINISH_POLICY.CHILDFINISH_LOOP);

            // go through all m_children
            for (int i = 0; i < children.Count; ++i)
            {
                BehaviorTask pChild = children[i];

                EBTStatus treeStatus = pChild.GetStatus();

                if (bLoop || (treeStatus == EBTStatus.BT_RUNNING || treeStatus == EBTStatus.BT_INVALID))
                {
                    EBTStatus status = pChild.exec(pAgent);

                    if (status == EBTStatus.BT_FAILURE)
                    {
                        sawFail       = true;
                        sawAllSuccess = false;
                    }
                    else if (status == EBTStatus.BT_SUCCESS)
                    {
                        sawSuccess  = true;
                        sawAllFails = false;
                    }
                    else if (status == EBTStatus.BT_RUNNING)
                    {
                        sawRunning    = true;
                        sawAllFails   = false;
                        sawAllSuccess = false;
                    }
                }
                else if (treeStatus == EBTStatus.BT_SUCCESS)
                {
                    sawSuccess  = true;
                    sawAllFails = false;
                }
                else
                {
                    Debug.Check(treeStatus == EBTStatus.BT_FAILURE);

                    sawFail       = true;
                    sawAllSuccess = false;
                }
            }

            EBTStatus result = sawRunning ? EBTStatus.BT_RUNNING : EBTStatus.BT_FAILURE;

            if ((this.m_failPolicy == FAILURE_POLICY.FAIL_ON_ALL && sawAllFails) ||
                (this.m_failPolicy == FAILURE_POLICY.FAIL_ON_ONE && sawFail))
            {
                result = EBTStatus.BT_FAILURE;
            }
            else if ((this.m_succeedPolicy == SUCCESS_POLICY.SUCCEED_ON_ALL && sawAllSuccess) ||
                     (this.m_succeedPolicy == SUCCESS_POLICY.SUCCEED_ON_ONE && sawSuccess))
            {
                result = EBTStatus.BT_SUCCESS;
            }

            //else if (m_failPolicy == FAIL_ON_ALL && m_succeedPolicy == SUCCEED_ON_ALL && sawRunning)
            //{
            //  return EBTStatus.BT_RUNNING;
            //}

            if (this.m_exitPolicy == EXIT_POLICY.EXIT_ABORT_RUNNINGSIBLINGS && (result == EBTStatus.BT_FAILURE || result == EBTStatus.BT_SUCCESS))
            {
                for (int i = 0; i < children.Count; ++i)
                {
                    BehaviorTask pChild = children[i];
                    //Debug.Check(BehaviorTreeTask.DynamicCast(pChild));
                    EBTStatus treeStatus = pChild.GetStatus();

                    if (treeStatus == EBTStatus.BT_RUNNING)
                    {
                        pChild.abort(pAgent);
                    }
                }
            }

            return(result);
        }
예제 #2
0
            protected override EBTStatus update(Agent pAgent, EBTStatus childStatus)
            {
                Parallel parallel = (Parallel)base.GetNode();
                bool     flag     = false;
                bool     flag2    = false;
                bool     flag3    = false;
                bool     flag4    = true;
                bool     flag5    = true;
                bool     flag6    = parallel.m_childFinishPolicy == CHILDFINISH_POLICY.CHILDFINISH_LOOP;

                for (int i = 0; i < this.m_children.get_Count(); i++)
                {
                    BehaviorTask behaviorTask = this.m_children.get_Item(i);
                    EBTStatus    status       = behaviorTask.GetStatus();
                    if (flag6 || status == EBTStatus.BT_RUNNING || status == EBTStatus.BT_INVALID)
                    {
                        EBTStatus eBTStatus = behaviorTask.exec(pAgent);
                        if (eBTStatus == EBTStatus.BT_FAILURE)
                        {
                            flag2 = true;
                            flag5 = false;
                        }
                        else if (eBTStatus == EBTStatus.BT_SUCCESS)
                        {
                            flag  = true;
                            flag4 = false;
                        }
                        else if (eBTStatus == EBTStatus.BT_RUNNING)
                        {
                            flag3 = true;
                            flag4 = false;
                            flag5 = false;
                        }
                    }
                    else if (status == EBTStatus.BT_SUCCESS)
                    {
                        flag  = true;
                        flag4 = false;
                    }
                    else
                    {
                        flag2 = true;
                        flag5 = false;
                    }
                }
                EBTStatus eBTStatus2 = (!flag3) ? EBTStatus.BT_FAILURE : EBTStatus.BT_RUNNING;

                if ((parallel.m_failPolicy == FAILURE_POLICY.FAIL_ON_ALL && flag4) || (parallel.m_failPolicy == FAILURE_POLICY.FAIL_ON_ONE && flag2))
                {
                    eBTStatus2 = EBTStatus.BT_FAILURE;
                }
                else if ((parallel.m_succeedPolicy == SUCCESS_POLICY.SUCCEED_ON_ALL && flag5) || (parallel.m_succeedPolicy == SUCCESS_POLICY.SUCCEED_ON_ONE && flag))
                {
                    eBTStatus2 = EBTStatus.BT_SUCCESS;
                }
                if (parallel.m_exitPolicy == EXIT_POLICY.EXIT_ABORT_RUNNINGSIBLINGS && (eBTStatus2 == EBTStatus.BT_FAILURE || eBTStatus2 == EBTStatus.BT_SUCCESS))
                {
                    for (int j = 0; j < this.m_children.get_Count(); j++)
                    {
                        BehaviorTask behaviorTask2 = this.m_children.get_Item(j);
                        EBTStatus    status2       = behaviorTask2.GetStatus();
                        if (status2 == EBTStatus.BT_RUNNING)
                        {
                            behaviorTask2.abort(pAgent);
                        }
                    }
                }
                return(eBTStatus2);
            }
예제 #3
0
            protected override EBTStatus update(Agent pAgent, EBTStatus childStatus)
            {
                Parallel node  = (Parallel)base.GetNode();
                bool     flag  = false;
                bool     flag2 = false;
                bool     flag3 = false;
                bool     flag4 = true;
                bool     flag5 = true;
                bool     flag6 = node.m_childFinishPolicy == CHILDFINISH_POLICY.CHILDFINISH_LOOP;

                for (int i = 0; i < base.m_children.Count; i++)
                {
                    BehaviorTask task   = base.m_children[i];
                    EBTStatus    status = task.GetStatus();
                    if ((flag6 || (status == EBTStatus.BT_RUNNING)) || (status == EBTStatus.BT_INVALID))
                    {
                        EBTStatus status2 = task.exec(pAgent);
                        switch (status2)
                        {
                        case EBTStatus.BT_FAILURE:
                        {
                            flag2 = true;
                            flag5 = false;
                            continue;
                        }

                        case EBTStatus.BT_SUCCESS:
                        {
                            flag  = true;
                            flag4 = false;
                            continue;
                        }
                        }
                        if (status2 == EBTStatus.BT_RUNNING)
                        {
                            flag3 = true;
                            flag4 = false;
                            flag5 = false;
                        }
                    }
                    else if (status == EBTStatus.BT_SUCCESS)
                    {
                        flag  = true;
                        flag4 = false;
                    }
                    else
                    {
                        flag2 = true;
                        flag5 = false;
                    }
                }
                EBTStatus status3 = !flag3 ? EBTStatus.BT_FAILURE : EBTStatus.BT_RUNNING;

                if (((node.m_failPolicy == FAILURE_POLICY.FAIL_ON_ALL) && flag4) || ((node.m_failPolicy == FAILURE_POLICY.FAIL_ON_ONE) && flag2))
                {
                    status3 = EBTStatus.BT_FAILURE;
                }
                else if (((node.m_succeedPolicy == SUCCESS_POLICY.SUCCEED_ON_ALL) && flag5) || ((node.m_succeedPolicy == SUCCESS_POLICY.SUCCEED_ON_ONE) && flag))
                {
                    status3 = EBTStatus.BT_SUCCESS;
                }
                if ((node.m_exitPolicy == EXIT_POLICY.EXIT_ABORT_RUNNINGSIBLINGS) && ((status3 == EBTStatus.BT_FAILURE) || (status3 == EBTStatus.BT_SUCCESS)))
                {
                    for (int j = 0; j < base.m_children.Count; j++)
                    {
                        BehaviorTask task2 = base.m_children[j];
                        if (task2.GetStatus() == EBTStatus.BT_RUNNING)
                        {
                            task2.abort(pAgent);
                        }
                    }
                }
                return(status3);
            }