//------------------------------------------------------
        protected override bool OnEvaluate(/*in*/ BTWorkingData wData)
        {
            var thisContext = (BTCActionParallel *)wData.GetContext(_uniqueKey);

            thisContext->evaluationStatus.Init(false);
            bool finalResult = false;

            for (int i = 0; i < GetChildCount(); ++i)
            {
                BTAction node = GetChild <BTAction>(i);
                bool     ret  = node.Evaluate(wData);
                //early break
                if (_evaluationRelationship == ECHILDREN_RELATIONSHIP.AND && ret == false)
                {
                    finalResult = false;
                    break;
                }

                if (ret == true)
                {
                    finalResult = true;
                }

                thisContext->evaluationStatus[i] = ret;
            }

            return(finalResult);
        }
示例#2
0
        //------------------------------------------------------
        protected override bool OnEvaluate(/*in*/ BTWorkingData wData)
        {
            var thisContext      = (BTCActionSequence *)wData.GetContext(_uniqueKey);
            int checkedNodeIndex = -1;

            if (IsIndexValid(thisContext->currentSelectedIndex))
            {
                checkedNodeIndex = thisContext->currentSelectedIndex;
            }
            else
            {
                checkedNodeIndex = 0;
            }

            if (IsIndexValid(checkedNodeIndex))
            {
                BTAction node = GetChild <BTAction>(checkedNodeIndex);
                if (node.Evaluate(wData))
                {
                    thisContext->currentSelectedIndex = checkedNodeIndex;
                    return(true);
                }
            }

            return(false);
        }
        protected override int OnUpdate(BTWorkingData wData)
        {
            var thisContext  = (BTCActionPrioritizedSelector *)wData.GetContext(_uniqueKey);
            int runningState = BTRunningStatus.FINISHED;

            if (thisContext->currentSelectedIndex != thisContext->lastSelectedIndex)
            {
                if (IsIndexValid(thisContext->lastSelectedIndex))
                {
                    BTAction node = GetChild <BTAction>(thisContext->lastSelectedIndex);
                    node.Transition(wData);
                }

                thisContext->lastSelectedIndex = thisContext->currentSelectedIndex;
            }

            if (IsIndexValid(thisContext->lastSelectedIndex))
            {
                BTAction node = GetChild <BTAction>(thisContext->lastSelectedIndex);
                runningState = node.Update(wData);
                if (BTRunningStatus.IsFinished(runningState))
                {
                    thisContext->lastSelectedIndex = -1;
                }
            }

            return(runningState);
        }
示例#4
0
        protected override int OnUpdate(BTWorkingData wData)
        {
            var      thisContext   = (BTCActionSequence *)wData.GetContext(_uniqueKey);
            int      runningStatus = BTRunningStatus.FINISHED;
            BTAction node          = GetChild <BTAction>(thisContext->currentSelectedIndex);

            runningStatus = node.Update(wData);
            if (_continueIfErrorOccors == false && BTRunningStatus.IsError(runningStatus))
            {
                thisContext->currentSelectedIndex = -1;
                return(runningStatus);
            }

            if (BTRunningStatus.IsFinished(runningStatus))
            {
                thisContext->currentSelectedIndex++;
                if (IsIndexValid(thisContext->currentSelectedIndex))
                {
                    runningStatus = BTRunningStatus.EXECUTING;
                }
                else
                {
                    thisContext->currentSelectedIndex = -1;
                }
            }

            return(runningStatus);
        }
示例#5
0
        protected override void OnTransition(BTWorkingData wData)
        {
            var thisContext = (BTActionLoopContext *)wData.GetContext(_uniqueKey);

            if (IsIndexValid(0))
            {
                BTAction node = GetChild <BTAction>(0);
                node.Transition(wData);
            }
            thisContext->currentCount = 0;
        }
        protected override void OnTransition(BTWorkingData wData)
        {
            var      thisContext = (BTCActionPrioritizedSelector *)wData.GetContext(_uniqueKey);
            BTAction node        = GetChild <BTAction>(thisContext->lastSelectedIndex);

            if (node != null)
            {
                node.Transition(wData);
            }

            thisContext->lastSelectedIndex = -1;
        }
示例#7
0
        public static BTInfo CreateBtInfo(BTAction bt)
        {
            var offsets = bt.GetTotalOffsets();
            var memSize = bt.GetTotalMemSize();

            return(new BTInfo()
            {
                MemSize = memSize,
                Offsets = offsets,
                RootNode = bt,
            });
        }
        protected override void OnTransition(BTWorkingData wData)
        {
            var thisContext = (BTCActionParallel *)wData.GetContext(_uniqueKey);

            for (int i = 0; i < GetChildCount(); ++i)
            {
                BTAction node = GetChild <BTAction>(i);
                node.Transition(wData);
            }

            //clear running status
            thisContext->StatusRunning.Init((byte)(int)BTRunningStatus.EXECUTING);
        }
        protected override bool OnEvaluate(/*in*/ BTWorkingData wData)
        {
            var thisContext = (BTCActionNonPrioritizedSelector *)wData.GetContext(_uniqueKey);

            //check last node first
            if (IsIndexValid(thisContext->currentSelectedIndex))
            {
                BTAction node = GetChild <BTAction>(thisContext->currentSelectedIndex);
                if (node.Evaluate(wData))
                {
                    return(true);
                }
            }

            return(base.OnEvaluate(wData));
        }
示例#10
0
        //-------------------------------------------------------
        protected override bool OnEvaluate(/*in*/ BTWorkingData wData)
        {
            var  thisContext    = (BTActionLoopContext *)wData.GetContext(_uniqueKey);
            bool checkLoopCount = (_loopCount == INFINITY || thisContext->currentCount < _loopCount);

            if (checkLoopCount == false)
            {
                return(false);
            }
            if (IsIndexValid(0))
            {
                BTAction node = GetChild <BTAction>(0);
                return(node.Evaluate(wData));
            }
            return(false);
        }
        protected override int OnUpdate(BTWorkingData wData)
        {
            var thisContext = (BTCActionParallel *)wData.GetContext(_uniqueKey);
            //first time initialization

            bool hasFinished  = false;
            bool hasExecuting = false;

            for (int i = 0; i < GetChildCount(); ++i)
            {
                if (thisContext->evaluationStatus[i] == false)
                {
                    continue;
                }

                if (BTRunningStatus.IsFinished(thisContext->StatusRunning[i]))
                {
                    hasFinished = true;
                    continue;
                }

                BTAction node          = GetChild <BTAction>(i);
                int      runningStatus = node.Update(wData);
                if (BTRunningStatus.IsFinished(runningStatus))
                {
                    hasFinished = true;
                }
                else
                {
                    hasExecuting = true;
                }

                thisContext->StatusRunning[i] = (byte)runningStatus;
            }

            if (_runningStatusRelationship == ECHILDREN_RELATIONSHIP.OR && hasFinished ||
                _runningStatusRelationship == ECHILDREN_RELATIONSHIP.AND && hasExecuting == false)
            {
                thisContext->StatusRunning.Init((byte)(int)BTRunningStatus.EXECUTING);
                return(BTRunningStatus.FINISHED);
            }

            return(BTRunningStatus.EXECUTING);
        }
        protected override bool OnEvaluate(/*in*/ BTWorkingData wData)
        {
            var thisContext = (BTCActionPrioritizedSelector *)wData.GetContext(_uniqueKey);

            thisContext->currentSelectedIndex = -1;
            int childCount = GetChildCount();

            for (int i = 0; i < childCount; ++i)
            {
                BTAction node = GetChild <BTAction>(i);
                if (node.Evaluate(wData))
                {
                    thisContext->currentSelectedIndex = i;
                    return(true);
                }
            }

            return(false);
        }
示例#13
0
        protected override int OnUpdate(BTWorkingData wData)
        {
            var thisContext   = (BTActionLoopContext *)wData.GetContext(_uniqueKey);
            int runningStatus = BTRunningStatus.FINISHED;

            if (IsIndexValid(0))
            {
                BTAction node = GetChild <BTAction>(0);
                runningStatus = node.Update(wData);
                if (BTRunningStatus.IsFinished(runningStatus))
                {
                    thisContext->currentCount++;
                    if (thisContext->currentCount < _loopCount || _loopCount == INFINITY)
                    {
                        runningStatus = BTRunningStatus.EXECUTING;
                    }
                }
            }
            return(runningStatus);
        }