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); }
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); } }
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? }
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); }
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); }
public CompositeTask(List <Task> tasks, BlackBoard blackBoard) : base(blackBoard) { _tasks = tasks; }
public CompositeTask(BlackBoard blackBoard) : base(blackBoard) { }
public override bool Check(BlackBoard blackboard) { return(currIndex < children.Count); }
public SimpleParallelTask(List <Task> tasks, BlackBoard blackBoard) : base(tasks, blackBoard) { }
public override void End(BlackBoard blackboard) { childTask.End(blackboard); }
/// <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)); }
public override void Reset(BlackBoard blackboard) { childTask.Reset(blackboard); }
/// <summary> /// Called when the task is reset for reuse. /// </summary> public virtual void Reset(BlackBoard blackboard) { }
public override BehaviourTreeStatus Update(BlackBoard blackboard, float deltaTime) { return(childTask.Update(blackboard, deltaTime)); }
/// <summary> /// Called when the Task completes (either Success or Failure) /// </summary> public virtual void End(BlackBoard blackboard) { }
/// <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); }
/// <summary> /// Used to initialize anything like variables for use in the Update() method /// </summary> public virtual void Start(BlackBoard blackboard) { }
/// <summary> /// Called when the current child succeeds /// </summary> protected abstract BehaviourTreeStatus ChildSucceeded(BlackBoard blackboard);
public SequencesTask(List <Task> tasks, BlackBoard blackBoard) : base(tasks, blackBoard) { }
/// <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)); }
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(); }
public override BehaviourTreeStatus Update(BlackBoard blackboard, float deltaTime) { return(_cond(blackboard) ? base.Update(blackboard, deltaTime) : BehaviourTreeStatus.Failure); }
public RandomSelectorTask(List<Task> tasks, BlackBoard blackBoard) : base(tasks, blackBoard) { }