Package com.csse3200.game.ai.tasks
Class AITaskComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.ai.tasks.AITaskComponent
- All Implemented Interfaces:
TaskRunner
Task-based AI component. Given a list of tasks with priorities, the AI component will run the
highest priority task each frame. Tasks can be made up of smaller sub-tasks. A negative priority
indicates that the task should not be run.
This is a simple implementation of Goal-Oriented Action Planning (GOAP), a common AI decision algorithm in games that's more powerful than Finite State Machines (FSMs) (State pattern).
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddTask
(PriorityTask task) Add a priority task to the list of tasks.void
changeTask
(PriorityTask desiredTask) void
dispose()
Called when the component is disposed.void
Empties the priorityTasks List.<T extends PriorityTask>
TGet a task from the list of tasks.void
restore()
Restores the priorityTasks List.void
update()
On update, run the current highest priority task.Methods inherited from class com.csse3200.game.components.Component
create, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.csse3200.game.ai.tasks.TaskRunner
getEntity
-
Constructor Details
-
AITaskComponent
public AITaskComponent()
-
-
Method Details
-
addTask
Add a priority task to the list of tasks. This task will be run only when it has the highest priority, and can be stopped to run a higher priority task.- Parameters:
task
- Task to add- Returns:
- self
-
getTask
Get a task from the list of tasks. This can be used to get a reference to a task to modify it. This is inspired from Entity.getComponent().- Type Parameters:
T
- The type of task to get- Parameters:
task
- The task to get- Returns:
- A reference to a task with the given class
-
update
public void update()On update, run the current highest priority task. If it's a different one, stop the old one and start the new one. If the highest priority task has negative priority, no task will be run. -
dispose
public void dispose()Description copied from class:Component
Called when the component is disposed. Dispose of any internal resources here. -
disposeAll
public void disposeAll()Empties the priorityTasks List. Disposes all of the entity's tasks. -
restore
public void restore()Restores the priorityTasks List. Adds all of the entity's disposed tasks back into priorityTasks. -
getHighestPriorityTask
-
changeTask
-