コード例 #1
0
            protected override EBTStatus update(Agent pAgent, EBTStatus childStatus)
            {
                int num = -1;

                for (int i = 0; i < base.m_children.Count; i++)
                {
                    WithPreconditionTask task = (WithPreconditionTask)base.m_children[i];
                    if (task.PreconditionNode().exec(pAgent) == EBTStatus.BT_SUCCESS)
                    {
                        num = i;
                        break;
                    }
                }
                if (num != -1)
                {
                    if (base.m_activeChildIndex != -1)
                    {
                        WithPreconditionTask task3 = (WithPreconditionTask)base.m_children[base.m_activeChildIndex];
                        BehaviorTask         task4 = task3.Action();
                        BehaviorTask         task6 = ((WithPreconditionTask)base.m_children[num]).Action();
                        if (task4 != task6)
                        {
                            task4.abort(pAgent);
                            task3.abort(pAgent);
                            base.m_activeChildIndex = num;
                        }
                    }
                    for (int j = 0; j < base.m_children.Count; j++)
                    {
                        WithPreconditionTask task7   = (WithPreconditionTask)base.m_children[j];
                        EBTStatus            status2 = task7.exec(pAgent);
                        if ((j >= num) && ((j <= num) || (task7.PreconditionNode().exec(pAgent) == EBTStatus.BT_SUCCESS)))
                        {
                            EBTStatus status4 = task7.Action().exec(pAgent);
                            switch (status4)
                            {
                            case EBTStatus.BT_RUNNING:
                                base.m_activeChildIndex = num;
                                return(status4);

                            case EBTStatus.BT_FAILURE:
                            case EBTStatus.BT_INVALID:
                            {
                                continue;
                            }
                            }
                            return(status4);
                        }
                    }
                }
                return(EBTStatus.BT_FAILURE);
            }
コード例 #2
0
ファイル: Parallel.cs プロジェクト: TonyDongGuaPi/joework
            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
ファイル: Parallel.cs プロジェクト: q3640850400/Dream1
        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);
        }
コード例 #4
0
ファイル: Selectorloop.cs プロジェクト: raptoravis/behaviac1
            protected override EBTStatus update(Agent pAgent, EBTStatus childStatus)
            {
                int idx = -1;

                for (int i = 0; i < this.m_children.Count; ++i)
                {
                    WithPreconditionTask pSubTree = (WithPreconditionTask)this.m_children[i];
                    Debug.Check(pSubTree is WithPreconditionTask);

                    EBTStatus returnStatus = pSubTree.GetReturnStatus();
                    if (returnStatus != EBTStatus.BT_INVALID)
                    {
                        pSubTree.SetReturnStatus(EBTStatus.BT_INVALID);

                        if (returnStatus == EBTStatus.BT_SUCCESS)
                        {
                            return(EBTStatus.BT_SUCCESS);
                        }
                        else if (returnStatus == EBTStatus.BT_FAILURE)
                        {
                            idx = i;
                            break;
                        }
                    }
                }

                //checking the preconditions and take the first action tree
                int index = (int)-1;

                for (int i = (idx + 1); i < this.m_children.Count; ++i)
                {
                    WithPreconditionTask pSubTree = (WithPreconditionTask)this.m_children[i];
                    Debug.Check(pSubTree is WithPreconditionTask);

                    BehaviorTask pPrecondTree = pSubTree.PreconditionNode();

                    EBTStatus status = pPrecondTree.exec(pAgent);

                    if (status == EBTStatus.BT_SUCCESS)
                    {
                        index = i;
                        break;
                    }
                }

                //clean up the current ticking action tree
                if (index != (int)-1)
                {
                    if (this.m_activeChildIndex != CompositeTask.InvalidChildIndex && this.m_activeChildIndex != index)
                    {
                        WithPreconditionTask pCurrentSubTree = (WithPreconditionTask)this.m_children[this.m_activeChildIndex];
                        Debug.Check(pCurrentSubTree is WithPreconditionTask);
                        BehaviorTask pCurrentActionTree = pCurrentSubTree.Action();

                        WithPreconditionTask pSubTree = (WithPreconditionTask)this.m_children[index];
                        Debug.Check(pSubTree is WithPreconditionTask);

                        BehaviorTask pActionTree = pSubTree.Action();

                        Debug.Check(pCurrentActionTree != pActionTree);

                        pCurrentActionTree.abort(pAgent);

                        pCurrentSubTree.abort(pAgent);

                        this.m_activeChildIndex = index;
                    }

                    for (int i = index; i < this.m_children.Count; ++i)
                    {
                        WithPreconditionTask pSubTree = (WithPreconditionTask)this.m_children[i];
                        Debug.Check(pSubTree is WithPreconditionTask);

                        if (i > index)
                        {
                            BehaviorTask pPreconditionTree = pSubTree.PreconditionNode();

                            EBTStatus status = pPreconditionTree.exec(pAgent);

                            //to search for the first one whose precondition is success
                            if (status != EBTStatus.BT_SUCCESS)
                            {
                                continue;
                            }
                        }

                        BehaviorTask pActionTree = pSubTree.Action();

                        EBTStatus s = pActionTree.exec(pAgent);

                        if (s == EBTStatus.BT_RUNNING)
                        {
                            this.m_activeChildIndex = index;
                        }
                        else
                        {
                            pActionTree.reset(pAgent);

                            if (s == EBTStatus.BT_FAILURE || s == EBTStatus.BT_INVALID)
                            {
                                //THE ACTION failed, to try the next one
                                continue;
                            }
                        }

                        Debug.Check(s == EBTStatus.BT_RUNNING || s == EBTStatus.BT_SUCCESS);

                        return(s);
                    }
                }

                return(EBTStatus.BT_FAILURE);
            }
コード例 #5
0
            protected override EBTStatus update(Agent pAgent, EBTStatus childStatus)
            {
                int idx = -1;

                if (childStatus != EBTStatus.BT_RUNNING)
                {
                    Debug.Check(this.m_activeChildIndex != CompositeTask.InvalidChildIndex);

                    if (childStatus == EBTStatus.BT_SUCCESS)
                    {
                        return(EBTStatus.BT_SUCCESS);
                    }
                    else if (childStatus == EBTStatus.BT_FAILURE)
                    {
                        //the next for starts from (idx + 1), so that it starts from next one after this failed one
                        idx = this.m_activeChildIndex;
                    }
                    else
                    {
                        Debug.Check(false);
                    }
                }

                //checking the preconditions and take the first action tree
                int index = (int)-1;

                for (int i = (idx + 1); i < this.m_children.Count; ++i)
                {
                    Debug.Check(this.m_children[i] is WithPreconditionTask);
                    WithPreconditionTask pSubTree = (WithPreconditionTask)this.m_children[i];

                    BehaviorTask pre = pSubTree.PreconditionNode;

                    EBTStatus status = pre.exec(pAgent);

                    if (status == EBTStatus.BT_SUCCESS)
                    {
                        index = i;
                        break;
                    }
                }

                //clean up the current ticking action tree
                if (index != (int)-1)
                {
                    if (this.m_activeChildIndex != CompositeTask.InvalidChildIndex &&
                        this.m_activeChildIndex != index)
                    {
                        WithPreconditionTask pCurrentSubTree = (WithPreconditionTask)this.m_children[this.m_activeChildIndex];
                        BehaviorTask         action          = pCurrentSubTree.ActionNode;
                        action.abort(pAgent);

                        //don't set it here
                        //this.m_activeChildIndex = index;
                    }

                    for (int i = index; i < this.m_children.Count; ++i)
                    {
                        WithPreconditionTask pSubTree = (WithPreconditionTask)this.m_children[i];

                        if (i > index)
                        {
                            BehaviorTask pre    = pSubTree.PreconditionNode;
                            EBTStatus    status = pre.exec(pAgent);

                            //to search for the first one whose precondition is success
                            if (status != EBTStatus.BT_SUCCESS)
                            {
                                continue;
                            }
                        }

                        BehaviorTask action = pSubTree.ActionNode;
                        EBTStatus    s      = action.exec(pAgent);

                        if (s == EBTStatus.BT_RUNNING)
                        {
                            this.m_activeChildIndex = i;
                        }
                        else
                        {
                            if (s == EBTStatus.BT_FAILURE)
                            {
                                //THE ACTION failed, to try the next one
                                continue;
                            }
                        }

                        Debug.Check(s == EBTStatus.BT_RUNNING || s == EBTStatus.BT_SUCCESS);

                        return(s);
                    }
                }

                return(EBTStatus.BT_FAILURE);
            }
コード例 #6
0
ファイル: SelectorLoop.cs プロジェクト: TonyDongGuaPi/joework
            protected override EBTStatus update(Agent pAgent, EBTStatus childStatus)
            {
                int num = -1;

                for (int i = 0; i < this.m_children.get_Count(); i++)
                {
                    WithPreconditionTask withPreconditionTask = (WithPreconditionTask)this.m_children.get_Item(i);
                    BehaviorTask         behaviorTask         = withPreconditionTask.PreconditionNode();
                    EBTStatus            eBTStatus            = behaviorTask.exec(pAgent);
                    if (eBTStatus == EBTStatus.BT_SUCCESS)
                    {
                        num = i;
                        break;
                    }
                }
                if (num != -1)
                {
                    if (this.m_activeChildIndex != -1)
                    {
                        WithPreconditionTask withPreconditionTask2 = (WithPreconditionTask)this.m_children.get_Item(this.m_activeChildIndex);
                        BehaviorTask         behaviorTask2         = withPreconditionTask2.Action();
                        WithPreconditionTask withPreconditionTask3 = (WithPreconditionTask)this.m_children.get_Item(num);
                        BehaviorTask         behaviorTask3         = withPreconditionTask3.Action();
                        if (behaviorTask2 != behaviorTask3)
                        {
                            behaviorTask2.abort(pAgent);
                            withPreconditionTask2.abort(pAgent);
                            this.m_activeChildIndex = num;
                        }
                    }
                    for (int j = 0; j < this.m_children.get_Count(); j++)
                    {
                        WithPreconditionTask withPreconditionTask4 = (WithPreconditionTask)this.m_children.get_Item(j);
                        EBTStatus            eBTStatus2            = withPreconditionTask4.exec(pAgent);
                        if (j >= num)
                        {
                            if (j > num)
                            {
                                BehaviorTask behaviorTask4 = withPreconditionTask4.PreconditionNode();
                                EBTStatus    eBTStatus3    = behaviorTask4.exec(pAgent);
                                if (eBTStatus3 != EBTStatus.BT_SUCCESS)
                                {
                                    goto IL_158;
                                }
                            }
                            BehaviorTask behaviorTask5 = withPreconditionTask4.Action();
                            EBTStatus    eBTStatus4    = behaviorTask5.exec(pAgent);
                            if (eBTStatus4 == EBTStatus.BT_RUNNING)
                            {
                                this.m_activeChildIndex = num;
                            }
                            else if (eBTStatus4 == EBTStatus.BT_FAILURE || eBTStatus4 == EBTStatus.BT_INVALID)
                            {
                                goto IL_158;
                            }
                            return(eBTStatus4);
                        }
                        IL_158 :;
                    }
                }
                return(EBTStatus.BT_FAILURE);
            }
コード例 #7
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);
            }