Exemplo n.º 1
0
        /// <summary>
        /// Test if the aborter may abort the node.
        /// Make sure that the node orders are pre-computed before calling this function.
        /// This method is mainly used by the editor.
        /// </summary>
        /// <param name="aborter">The node to perform the abort.</param>
        /// <param name="node">The node that gets aborted.</param>
        /// <returns></returns>
        public static bool IsAbortable(ConditionalAbort aborter, BehaviourNode node)
        {
            // This makes sure that dangling nodes do not show that they can abort nodes under main tree.
            if (aborter.preOrderIndex == kInvalidOrder)
            {
                return(false);
            }

            // Parallel subtrees cannot abort each other.
            if (aborter.Parent && aborter.Parent is Parallel)
            {
                return(false);
            }

            switch (aborter.abortType)
            {
            case AbortType.LowerPriority:
                return
                    (!BehaviourTree.IsUnderSubtree(aborter, node) &&
                     BehaviourTree.IsUnderSubtree(aborter.Parent, node) &&
                     aborter.Priority() > GetSubtree(aborter.Parent, node).Priority());

            // Self aborts always interrupt, regardless of the condition.
            case AbortType.Self:
                return(BehaviourTree.IsUnderSubtree(aborter, node));

            case AbortType.Both:
                return
                    (BehaviourTree.IsUnderSubtree(aborter, node) ||
                     (BehaviourTree.IsUnderSubtree(aborter.Parent, node) &&
                      aborter.Priority() > GetSubtree(aborter.Parent, node).Priority()));
            }

            return(false);
        }
Exemplo n.º 2
0
        public bool IsAbortSatisfied()
        {
            // Aborts need to be enabled in order to test them.
            if (abortType == AbortType.None)
            {
                return(false);
            }

            // The main node we wish to abort from if possible.
            // Aborts only occur within the same parent subtree of the aborter.
            BehaviourNode active = Tree.allNodes[_iterator.CurrentIndex];

            // The abort type dictates the final criteria to check
            // if the abort is satisfied and if the condition check changed state.
            switch (abortType)
            {
            case AbortType.LowerPriority:
                return
                    (!BehaviourTree.IsUnderSubtree(this, active) &&
                     BehaviourTree.IsUnderSubtree(Parent, active) &&
                     this.Priority() > _iterator.GetRunningSubtree(Parent).Priority() &&
                     Reevaluate());

            // Self aborts always interrupt, regardless of the condition.
            case AbortType.Self:
                return(BehaviourTree.IsUnderSubtree(this, active) && Reevaluate());

            case AbortType.Both:
                return
                    ((BehaviourTree.IsUnderSubtree(this, active) ||
                      (BehaviourTree.IsUnderSubtree(Parent, active) &&
                       this.Priority() > _iterator.GetRunningSubtree(Parent).Priority())) &&
                     Reevaluate());
            }

            return(false);
        }