E
- type of the blackboard object that tasks use to read or modify game state@TaskConstraint public abstract class Task<E> extends Object
Task
of a behavior tree has a status, one control and a list of children.Modifier and Type | Class and Description |
---|---|
static class |
Task.Status |
Modifier and Type | Field and Description |
---|---|
protected Task<E> |
control
The parent of this task.
|
protected Task.Status |
status |
protected BehaviorTree<E> |
tree
The behavior tree this task belongs to.
|
Constructor and Description |
---|
Task() |
Modifier and Type | Method and Description |
---|---|
int |
addChild(Task<E> child)
This method will add a child to the list of this task's children
|
protected abstract int |
addChildToTask(Task<E> child)
This method will add a child to the list of this task's children
|
void |
cancel()
Terminates this task and all its running children.
|
protected void |
cancelRunningChildren(int startIndex)
Terminates the running children of this task starting from the specified index up to the end.
|
boolean |
checkGuard(Task<E> control)
Checks the guard of this task.
|
abstract void |
childFail(Task<E> task)
This method will be called when one of the children of this task fails.
|
abstract void |
childRunning(Task<E> runningTask,
Task<E> reporter)
This method will be called when one of the ancestors of this task needs to run again.
|
abstract void |
childSuccess(Task<E> task)
This method will be called when one of the children of this task succeeds.
|
Task<E> |
cloneTask()
Clones this task to a new one.
|
protected abstract Task<E> |
copyTo(Task<E> task)
Copies this task to the given task.
|
void |
end()
This method will be called by
success() , fail() or cancel() , meaning that this task's status has
just been set to Task.Status.SUCCEEDED , Task.Status.FAILED or Task.Status.CANCELLED respectively. |
void |
fail()
This method will be called in
run() to inform control that this task has finished running with a failure result. |
abstract Task<E> |
getChild(int i) |
abstract int |
getChildCount() |
E |
getEntity()
Returns the blackboard object of the behavior tree this task belongs to.
|
Task<E> |
getGuard() |
Task.Status |
getStatus() |
void |
reset()
Resets this task to make it restart from scratch on next run.
|
abstract void |
run()
This method contains the update logic of this task.
|
void |
running()
This method will be called in
run() to inform control that this task needs to run again. |
void |
setControl(Task<E> control)
This method will set a task as this task's control (parent).
|
void |
setGuard(Task<E> guard)
Sets the guard of this task.
|
void |
start()
This method will be called once before this task's first run.
|
void |
success()
This method will be called in
run() to inform control that this task has finished running with a success result. |
protected Task.Status status
protected BehaviorTree<E> tree
public final int addChild(Task<E> child)
child
- the child task which will be addedIllegalStateException
- if the child cannot be added for whatever reasonprotected abstract int addChildToTask(Task<E> child)
child
- the child task which will be addedIllegalStateException
- if the child cannot be added for whatever reasonpublic abstract int getChildCount()
public E getEntity()
IllegalStateException
- if this task has never runpublic void setGuard(Task<E> guard)
guard
- the guardpublic final Task.Status getStatus()
public final void setControl(Task<E> control)
control
- the parent taskpublic boolean checkGuard(Task<E> control)
control
- the parent tasktrue
if guard evaluation succeeds or there's no guard; false
otherwise.IllegalStateException
- if guard evaluation returns any status other than Task.Status.SUCCEEDED
and
Task.Status.FAILED
.public void start()
public void end()
success()
, fail()
or cancel()
, meaning that this task's status has
just been set to Task.Status.SUCCEEDED
, Task.Status.FAILED
or Task.Status.CANCELLED
respectively.public abstract void run()
public final void running()
run()
to inform control that this task needs to run again.public final void success()
run()
to inform control that this task has finished running with a success result.public final void fail()
run()
to inform control that this task has finished running with a failure result.public abstract void childSuccess(Task<E> task)
task
- the task that succeededpublic abstract void childFail(Task<E> task)
task
- the task that failedpublic abstract void childRunning(Task<E> runningTask, Task<E> reporter)
runningTask
- the task that needs to run againreporter
- the task that reports, usually one of this task's childrenpublic final void cancel()
protected void cancelRunningChildren(int startIndex)
startIndex
- the start indexpublic void reset()
public Task<E> cloneTask()
copyTo(Task)
is invoked.TaskCloneException
- if the task cannot be successfully cloned.protected abstract Task<E> copyTo(Task<E> task)
task
- the task to be filledTaskCloneException
- if the task cannot be successfully copied.Copyright © 2018. All rights reserved.