コード例 #1
0
        /// <summary>
        /// Push a new node on the call stack, and execute the callstack.
        /// </summary>
        /// <param name="node"></param>
        public void Call(AINode node)
        {
            //Push the new node on the callstack, and fetch the top of the callstack.
            Push(node);
            node = callstack.Peek();

            //Initalize this node, and follow through depending on status.
            var status = node.Init(this, dataContext);

            switch (status)
            {
            case AINode.BehaviourStatus.Success:     //Call the node.
                Call(AINode.BehaviourStatus.Call);
                break;

            case AINode.BehaviourStatus.Failure:     //Pop the node off the callstack, and return execution to it's parent.
                Pop();
                Call(AINode.BehaviourStatus.Failure);
                break;

            case AINode.BehaviourStatus.Running:     //These status should be impossible durring Initialization.
            case AINode.BehaviourStatus.Call:
                throw new InvalidOperationException(callstack.Peek().GetType().ToString() + ": Node cannot reutrn Call or Running from Init");
            }
        }
コード例 #2
0
 /// <summary>
 /// Set a new root for the tree, and clear the callstack.
 /// </summary>
 /// <param name="node"></param>
 public void SetRoot(AINode node)
 {
     callstack = new Stack <AINode>();
     Push(node);
     node = callstack.Peek();
     node.Init(this, dataContext);
 }