Beispiel #1
0
        public Parallel(int childrenTickInterval, params BTNode[] children)
        {
            this.childrenTickInterval = childrenTickInterval;
            this.children             = children;

            lastStatus = BTStatus.Failed;             /* allow tasks to initialize */
        }
Beispiel #2
0
    public override BTStatus Execute()
    {
        BTStatus rv = BTStatus.FAILURE;


        for (int i = CurrentChildIndex; i < children.Count; i++) //Current childindex is the table
        {
            rv = children[i].Execute();                          //Selector
            CurrentChildIndex = i;                               //Updating the current child index.
            if (rv == BTStatus.FAILURE)                          // if it fails it returns to the top
            {
                return(rv);
            }
            if (rv == BTStatus.RUNNING) //if it runs it returns to the top
            {
                return(rv);
            }
            if (rv == BTStatus.SUCCESS) //if we are good it resets
            {
                Reset();

                return(rv);
            }
            if (rv == BTStatus.FAILURE && (CurrentChildIndex + 1) == children.Count) //it fals on the last child node, it resets and returns failure
            {
                Reset();

                return(rv);
            }
        }
        return(rv);
    }
Beispiel #3
0
        public override BTStatus Execute()
        {
            for (int i = 0; i < children.Length; i++)
            {
                if (!children[i].CanExecute())
                {
                    continue;
                }

                if (lastRunningChildIndex != null && i != lastRunningChildIndex)
                {
                    children[lastRunningChildIndex.Value].ResetState();
                }

                BTStatus status = children[i].Execute();


                if (status == BTStatus.Success)
                {
                    lastRunningChildIndex = null;
                    return(status);
                }
                else if (status == BTStatus.Running)
                {
                    lastRunningChildIndex = i;
                    return(status);
                }
            }

            lastRunningChildIndex = null;
            return(BTStatus.Failed);
        }
Beispiel #4
0
    public override BTStatus Execute()
    {
        BTStatus rv = BTStatus.FAILURE;

        for (int i = CurrentChildIndex; i < children.Count; i++) //Current childindex is the table
        {
            rv = children[i].Execute();                          //Selector
            CurrentChildIndex = i;                               //Updating the current child index.

            if (rv == BTStatus.FAILURE)
            {
                Reset();

                return(rv);
            }
            if (rv == BTStatus.RUNNING) //if it runs it returns to the top
            {
                return(rv);
            }
            if (rv == BTStatus.SUCCESS && (CurrentChildIndex + 1) == children.Count) //if all nodes succed, return success.
            {
                Reset();
            }

            return(rv);
        }
        return(rv);
    }
Beispiel #5
0
    public override BTStatus Execute()
    {
        BTStatus rv = BTStatus.SUCCESS;

        Debug.Log("Zombie Biting");
        return(rv);
    }
Beispiel #6
0
 public sealed override BTStatus Step()
 {
     m_Result = BTStatus.Success;
     if (m_Status == BTStatus.Initial)
     {
         bool checkCondition = Enter();
         m_Status = checkCondition ? BTStatus.Running : BTStatus.Failure;
     }
     if (m_Status == BTStatus.Running)
     {
         bool success = Prepare();
         if (success)
         {
             m_Result = Execute();
             if (m_Result != BTStatus.Running)
             {
                 Exit();
                 m_Status    = BTStatus.Initial;
                 m_IsRunning = false;
             }
             else
             {
                 m_IsRunning = true;
             }
         }
         else
         {
             m_IsRunning = true;
             return(BTStatus.Running);
         }
     }
     return(m_Result);
 }
Beispiel #7
0
        protected override BTResult OnTick(ref BTInput _input)
        {
            BTResult result = BTResult.Success;

            if (mStatus == BTStatus.Ready)
            {
                OnEnter(_input);
                mNeedExit = true;
                mStatus   = BTStatus.Running;
            }
            if (mStatus == BTStatus.Running)
            {
                result = OnExecute(ref _input);
                if (result == BTResult.Success || result == BTResult.Failed)
                {
                    mStatus = BTStatus.Finish;
                }
            }
            if (mStatus == BTStatus.Finish)
            {
                if (mNeedExit)
                {
                    OnExit(_input, result);
                }
                mStatus   = BTStatus.Ready;
                mNeedExit = false;
            }
            return(result);
        }
Beispiel #8
0
    public BTStatus Tick(float time, T context)
    {
        BTStatus result = BTStatus.Running;
        int      count  = 0;

        foreach (INode <T> node in _nodes)
        {
            BTStatus status = node.Tick(time, context);
            switch (status)
            {
            case BTStatus.Success:
                count++;
                break;

            case BTStatus.Failed:
                result = BTStatus.Failed;
                break;

            default:
                break;
            }
        }

        return(result);
    }
Beispiel #9
0
        public override BTStatus Tick()
        {
            BTStatus status = ChildrenNodes[NowChild].Tick();

            switch (status)
            {
            case BTStatus.Fail:
                NowChild = 0;
                return(BTStatus.Fail);

            case BTStatus.Running:
                return(BTStatus.Running);

            case BTStatus.Success:
                NowChild++;
                if (NowChild == ChildrenNodes.Count)
                {
                    NowChild = 0;
                    return(BTStatus.Success);
                }
                return(BTStatus.Running);

            case BTStatus.Exit:
                NowChild = 0;
                return(BTStatus.Exit);
            }
            throw new System.Exception("no node, but try get it");
        }
Beispiel #10
0
 public BTNode OpenBranch(BTNode _node, BTStatus _decorator, BTStatus falseStatus)
 {
     ChildNode       = _node;
     DecoratorStatus = _decorator;
     FalseStatus     = falseStatus;
     return(this);
 }
Beispiel #11
0
    public override BTStatus Execute()
    {
        BTStatus RV      = BTStatus.FAILURE;
        bool     failure = false;

        for (int i = 0; i < children.Count; i++) //Iterate through children and continue until a success is found.
        {
            RV = children[i].Execute();
            if (RV == BTStatus.SUCCESS)
            {
                return(RV);
            }
            else if (RV == BTStatus.RUNNING)
            {
                CurrentChildIndex = i;
                return(BTStatus.RUNNING);
            }
            else if (RV == BTStatus.FAILURE)
            {
                failure = true;
            }
        }
        //If a success is not found, return a failure
        //CurrentChildIndex = 0;
        if (failure == true)
        {
            return(BTStatus.FAILURE);
        }
        else
        {
            return(BTStatus.SUCCESS);
        }
    }
Beispiel #12
0
        public override BTStatus Tick()
        {
            RandomNodes();
            BTStatus status = ChildrenNodes[NowChild].Tick();

            switch (status)
            {
            case BTStatus.Fail:
                NowChild++;
                if (NowChild >= ChildrenNodes.Count)
                {
                    NowChild = 0;
                }
                return(BTStatus.Fail);

            case BTStatus.Running:
                return(BTStatus.Running);

            case BTStatus.Success:
                NowChild = 0;
                return(BTStatus.Success);

            case BTStatus.Exit:
                NowChild = 0;
                return(BTStatus.Exit);
            }

            throw new System.NotImplementedException();
        }
Beispiel #13
0
        public override BTStatus Step()
        {
            BTStatus pStatus = base.Step();

            switch (pStatus)
            {
            case BTStatus.Success:
            {
                Count++;
                base.Clear();
                break;
            }

            case BTStatus.Running:
            {
                break;
            }

            case BTStatus.Failure:
            {
                return(BTStatus.Failure);
            }
            }
            return(Count >= Times ? BTStatus.Success : BTStatus.Running);
        }
Beispiel #14
0
        public void Step()
        {
            for (int i = 0; i < m_BTTrees.Count; i++)
            {
                BTTree   tree    = m_BTTrees[i];
                BTStatus pStatus = tree.Step();

                switch (pStatus)
                {
                case BTStatus.Initial:
                    break;

                case BTStatus.Running:
                    break;

                case BTStatus.Success:
                case BTStatus.Failure:
                {
                    m_DeleteList.Add(tree);
                }
                break;
                }
            }

            for (int i = 0; i < m_DeleteList.Count; i++)
            {
                BTTree tree = m_DeleteList[i];
                m_BTTrees.Remove(tree);
                tree.Clear();
            }
            m_DeleteList.Clear();
        }
Beispiel #15
0
 public override void Clear()
 {
     base.Clear();
     if (m_Status != BTStatus.Initial)
     {
         Exit();
         m_Status = BTStatus.Initial;
     }
 }
Beispiel #16
0
 protected override void OnTransition(BTInput _input)
 {
     if (mNeedExit)
     {
         OnExit(_input, BTResult.Failed);
     }
     mStatus   = BTStatus.Ready;
     mNeedExit = false;
 }
Beispiel #17
0
    // Update is called once per frame
    void Update()
    {
        BTStatus status = rootNode.Tick(Time.deltaTime, bb);

        Debug.Log(status + "passedTime: " + bb.passedTime);
        if (status == BTStatus.Success)
        {
            bb.passedTime = 0.0f;
        }
    }
Beispiel #18
0
    public override BTStatus Execute()
    {
        BTStatus rv = BTStatus.RUNNING;

        if ((zombieRef.transform.position - zBB.MoveToLocation).magnitude <= 1.0f)
        {
            Debug.Log("Reached target");
            rv = BTStatus.SUCCESS;
        }
        return(rv);
    }
Beispiel #19
0
    public override BTStatus Execute()
    {
        BTStatus rv = BTStatus.FAILURE;

        if (CheckStatus())
        {
            rv = WrappedNode.Execute();
        }

        return(rv);
    }
Beispiel #20
0
    public BTStatus Tick(float time, T context)
    {
        foreach (INode <T> node in _nodes)
        {
            BTStatus status = node.Tick(time, context);
            if (status != BTStatus.Success)
            {
                return(status);
            }
        }

        return(BTStatus.Success);
    }
Beispiel #21
0
        public override BTStatus Tick()
        {
            BTStatus status = ChildNode.Tick();

            // 子节点匹配装饰节点
            if (status == DecoratorStatus)
            {
                return(DecoratorStatus);
            }
            // 不匹配装饰节点
            else
            {
                return(FalseStatus);
            }
        }
Beispiel #22
0
    public override BTStatus Execute()
    {
        BTStatus rv = WrappedNode.Execute();

        if (rv == BTStatus.FAILURE)
        {
            rv = BTStatus.SUCCESS;
        }
        else if (rv == BTStatus.SUCCESS)
        {
            rv = BTStatus.FAILURE;
        }

        return(rv);
    }
Beispiel #23
0
        public override BTStatus Execute()
        {
            BTStatus rv = BTStatus.RUNNING;


            if (Vector3.Distance(mBB.FleeTarget.transform.position, MinerRef.transform.position) > mBB.FleeProximity - 1)
            {
                rv = BTStatus.SUCCESS;
                MinerRef.SB.EvadeOff();
                MinerRef.SB.FleeOff();
                MinerRef.SB.Stop();
                mBB.fleeing = false;
            }

            return(rv);
        }
Beispiel #24
0
    public BTStatus Tick(float time, T context)
    {
        BTStatus status = _node.Tick(time, context);

        switch (status)
        {
        case BTStatus.Success:
            return(BTStatus.Failed);

        case BTStatus.Failed:
            return(BTStatus.Success);

        default:
            return(status);
        }
    }
Beispiel #25
0
        public override BTStatus Step()
        {
            for (int i = 0; i < m_Children.Count; i++)
            {
                BTNode   pNode   = m_Children[i];
                BTStatus pStatus = pNode.Step();
                switch (pStatus)
                {
                case BTStatus.Running:
                {
                    if (m_ActiveIndex != i && m_ActiveIndex != -1)
                    {
                        m_Children[m_ActiveIndex].Clear();
                    }
                    m_ActiveIndex = i;
                    m_PreviaIndex = -1;
                    m_IsRunning   = true;
                    return(BTStatus.Running);
                }

                case BTStatus.Success:
                {
                    if (m_ActiveIndex != i && m_ActiveIndex != -1)
                    {
                        m_Children[m_ActiveIndex].Clear();
                    }
                    pNode.Clear();
                    m_ActiveIndex = -1;
                    m_PreviaIndex = i;
                    m_IsRunning   = false;
                    return(BTStatus.Success);
                }

                case BTStatus.Failure:
                {
                    pNode.Clear();
                    return(BTStatus.Failure);
                }
                }
            }

            m_IsRunning = false;
            return(BTStatus.Failure);
        }
Beispiel #26
0
        public override BTStatus Step()
        {
            if (m_ActiveIndex == -1)
            {
                m_ActiveIndex = UnityEngine.Random.Range(0, m_Children.Count);
            }

            if (m_Children.Count > 0)
            {
                BTNode   pNode   = m_Children[m_ActiveIndex];
                BTStatus pStatus = pNode.Step();
                switch (pStatus)
                {
                case BTStatus.Running:
                {
                    m_IsRunning = true;
                    return(BTStatus.Running);
                }

                case BTStatus.Success:
                {
                    pNode.Clear();
                    m_ActiveIndex = -1;
                    m_PreviaIndex = m_ActiveIndex;
                    m_IsRunning   = false;
                    return(BTStatus.Success);
                }

                case BTStatus.Failure:
                {
                    pNode.Clear();
                    m_ActiveIndex = -1;
                    m_PreviaIndex = -1;
                    m_IsRunning   = false;
                    return(BTStatus.Failure);
                }
                }
            }
            m_ActiveIndex = -1;
            m_PreviaIndex = -1;
            m_IsRunning   = false;
            return(BTStatus.Failure);
        }
Beispiel #27
0
    public override BTStatus Execute()
    {
        BTStatus rv = BTStatus.RUNNING;

        if (!Started &&
            !DelayFinished)
        {
            Started = true;
            regulator.Start();
        }
        else if (DelayFinished)
        {
            DelayFinished = false;
            Started       = false;
            rv            = BTStatus.SUCCESS;
        }

        return(rv);
    }
Beispiel #28
0
        public override BTStatus Execute()
        {
            for (int i = currentChildIndex; i < children.Length; i++)
            {
                if (!alwaysLoop)
                {
                    currentChildIndex = i;
                }

                BTStatus status = children[i].Execute();

                if (status != BTStatus.Success)
                {
                    return(status);
                }
            }

            currentChildIndex = 0;
            return(BTStatus.Success);
        }
Beispiel #29
0
    public override BTStatus Execute()
    {
        if (FirstRun)
        {
            FirstRun = false;
            Debug.Log("Moving to player");
            // perhaps the BTNode should have some "start" function that
            // can be overridden in child classes so we don't have to do this?
        }
        BTStatus rv = BTStatus.RUNNING;

        zombieRef.ZombieMoveTo(zBB.PlayerLocation);
        if ((zombieRef.transform.position - zBB.PlayerLocation).magnitude <= 1.0f)
        {
            Debug.Log("Reached the player");
            rv       = BTStatus.SUCCESS;
            FirstRun = true;
        }
        return(rv);
    }
Beispiel #30
0
    public override BTStatus Execute()
    {
        BTStatus RV = BTStatus.FAILURE;

        for (int i = 0; i < children.Count; i++) //Iterate through all children UNTIL a failure occurs.
        {
            RV = children[i].Execute();
            if (RV == BTStatus.FAILURE)
            {
                return(RV);
            }
            else if (RV == BTStatus.RUNNING)
            {
                CurrentChildIndex = i;
                return(BTStatus.RUNNING);
            }
        }
        //CurrentChildIndex = 0;
        return(BTStatus.SUCCESS); //If no failure occurs, return a success
    }