public override BehaviourTreeStatus Update(BlackBoard blackboard, float deltaTime)
        {
            var numSucceeded = 0;           //A counter for succeeded tasks
            var numFailed    = 0;           //A counter for failed tasks

            foreach (Task task in children) //Loop through and update each task.
            {
                var status = task.Update(blackboard, deltaTime);
                if (status == BehaviourTreeStatus.Success) //If it succeeds, increment counter
                {
                    numSucceeded++;
                }
                if (status == BehaviourTreeStatus.Failure) //If it fails, increment counter
                {
                    numFailed++;
                }

                if (numFailed >= numNeededToFail)
                {
                    return(BehaviourTreeStatus.Failure);
                }
            }

            //If either of the checks pass then we are successful!
            if (numSucceeded >= numNeededToPass)
            {
                return(BehaviourTreeStatus.Success);
            }

            //Otherwise keep running
            return(BehaviourTreeStatus.Running);
        }
示例#2
0
        private BehaviourTreeStatus RunChildTask(BlackBoard blackboard, float deltaTime)
        {
            while (true)
            {
                var childStatus = children[currIndex].Update(blackboard, deltaTime);

                //This will start the next child in our children list
                if (childStatus == BehaviourTreeStatus.Success)
                {
                    childStatus = ChildSucceeded(blackboard);
                    if (childStatus == BehaviourTreeStatus.Running)
                    {
                        continue;
                    }
                }
                else if (childStatus == BehaviourTreeStatus.Failure)
                {
                    childStatus = ChildFailed(blackboard);
                    if (childStatus == BehaviourTreeStatus.Running)
                    {
                        continue;
                    }
                }

                return(childStatus);
            }
        }
示例#3
0
        public override void Start(BlackBoard blackboard)
        {
            base.Start(blackboard);

            if (children[currIndex].Check(blackboard))
            {
                children[currIndex].Start(blackboard);
            }
            //TODO What happens here with an empty sequence?
        }
示例#4
0
 public override void End(BlackBoard blackboard)
 {
     if (currIndex < 0)
     {
         return;
     }
     for (var i = currIndex; i < children.Count; i++)
     {
         children[i].End(blackboard);
     }
 }
        public override BehaviourTreeStatus Update(BlackBoard blackboard, float deltaTime)
        {
            var status = childTask.Update(blackboard, deltaTime);

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

            return(status);
        }
示例#6
0
        public override BehaviourTreeStatus Update(BlackBoard blackboard, float deltaTime)
        {
            base.Update(blackboard, deltaTime);

            if (currIndex < 0 || currIndex >= children.Count)
            {
                return(BehaviourTreeStatus.Failure);
            }

            var childStatus = RunChildTask(blackboard, deltaTime);

            return(childStatus);
        }
 public override void Start(BlackBoard blackboard)
 {
     //base.Start(blackboard);
     //We don't call base.Start() because Parallel is special and doesn't need the typical Composite start
     currIndex = -1;
     children.ForEach(x =>
     {
         if (x.Check(blackboard))
         {
             x.Start(blackboard);
         }
     });
 }
        protected override BehaviourTreeStatus ChildSucceeded(BlackBoard blackboard)
        {
            children[currIndex].End(blackboard); //End the current child
            currIndex++;

            if (currIndex >= children.Count)         //If the index is out of the bounds of our children, return success because we're done with the sequence
            {
                return(BehaviourTreeStatus.Success); //Return success
            }
            //If the child fails the check, return with failure
            if (!children[currIndex].Check(blackboard))
            {
                return(BehaviourTreeStatus.Failure);
            }

            children[currIndex].Start(blackboard); //Start the child

            return(BehaviourTreeStatus.Running);   //Return that we are still running
        }
        public override BehaviourTreeStatus Update(BlackBoard blackboard, float deltaTime)
        {
            //If our condition returns true, then we're done with this task. Return success!
            if (_cond(blackboard))
            {
                return(BehaviourTreeStatus.Success);
            }

            //Otherwise, update the child and get it's status
            var status = childTask.Update(blackboard, deltaTime);

            //If the status is not success... simply return the status of the child
            if (status != BehaviourTreeStatus.Success && status != BehaviourTreeStatus.Failure)
            {
                return(status);
            }

            //If the child status is success or failure, we need to repeat (so reset() and start()
            childTask.Reset(blackboard);
            childTask.Start(blackboard);
            return(BehaviourTreeStatus.Running);
        }
示例#10
0
 public CompositeTask(List <Task> tasks, BlackBoard blackBoard) : base(blackBoard)
 {
     _tasks = tasks;
 }
示例#11
0
 public CompositeTask(BlackBoard blackBoard) : base(blackBoard)
 {
 }
示例#12
0
 public override bool Check(BlackBoard blackboard)
 {
     return(currIndex < children.Count);
 }
示例#13
0
 public SimpleParallelTask(List <Task> tasks, BlackBoard blackBoard) : base(tasks, blackBoard)
 {
 }
示例#14
0
 public override void End(BlackBoard blackboard)
 {
     childTask.End(blackboard);
 }
示例#15
0
 /// <summary>
 /// Used to check any special conditions before Start() is called.
 /// </summary>
 /// <returns>True if the task is ready to be started, false otherwise</returns>
 public virtual bool Check(BlackBoard blackboard)
 {
     return(true);
 }
 public override BehaviourTreeStatus Update(BlackBoard blackboard, float delta)
 {
     return(fn(blackboard, delta));
 }
示例#17
0
 public override void Reset(BlackBoard blackboard)
 {
     childTask.Reset(blackboard);
 }
示例#18
0
 /// <summary>
 /// Called when the task is reset for reuse.
 /// </summary>
 public virtual void Reset(BlackBoard blackboard)
 {
 }
示例#19
0
 public override BehaviourTreeStatus Update(BlackBoard blackboard, float deltaTime)
 {
     return(childTask.Update(blackboard, deltaTime));
 }
示例#20
0
 /// <summary>
 /// Called when the Task completes (either Success or Failure)
 /// </summary>
 public virtual void End(BlackBoard blackboard)
 {
 }
示例#21
0
 /// <summary>
 /// The update method of the Task. Called to execute the behaviour.
 /// </summary>
 /// <param name="blackboard">The BlackBoard to use for data.</param>
 /// <returns>The status of the Task. Success, Running, or Failure.</returns>
 public virtual BehaviourTreeStatus Update(BlackBoard blackboard, float delta)
 {
     return(BehaviourTreeStatus.Success);
 }
示例#22
0
 /// <summary>
 /// Used to initialize anything like variables for use in the Update() method
 /// </summary>
 public virtual void Start(BlackBoard blackboard)
 {
 }
示例#23
0
 /// <summary>
 /// Called when the current child succeeds
 /// </summary>
 protected abstract BehaviourTreeStatus ChildSucceeded(BlackBoard blackboard);
示例#24
0
 public SequencesTask(List <Task> tasks, BlackBoard blackBoard) : base(tasks, blackBoard)
 {
 }
示例#25
0
 /// <summary>
 /// Called when the current child fails
 /// </summary>
 protected abstract BehaviourTreeStatus ChildFailed(BlackBoard blackboard);
 public override void End(BlackBoard blackboard)
 {
     base.End(blackboard);
     children.ForEach(task => task.End(blackboard));
 }
示例#27
0
 public override void Reset(BlackBoard blackboard)
 {
     base.Reset(blackboard);
     children.ForEach(x => x.Reset(blackboard));
     currIndex = 0;
 }
 protected override BehaviourTreeStatus ChildSucceeded(BlackBoard blackboard)
 {
     throw new NotImplementedException();
 }
示例#29
0
 public override BehaviourTreeStatus Update(BlackBoard blackboard, float deltaTime)
 {
     return(_cond(blackboard) ? base.Update(blackboard, deltaTime) : BehaviourTreeStatus.Failure);
 }
示例#30
0
 public RandomSelectorTask(List<Task> tasks, BlackBoard blackBoard) : base(tasks, blackBoard)
 {
 }