AI Task

From The DarkMod Wiki
Revision as of 14:26, 8 November 2007 by Greebo (talk | contribs) (New page: The purpose of a '''Task''' is to represent an atomic action which can be performed by a particular AI Subsystem. Once a Task is plugged into one of the AI's Subsystems, it gets '''initial...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The purpose of a Task is to represent an atomic action which can be performed by a particular AI Subsystem. Once a Task is plugged into one of the AI's Subsystems, it gets initialised once and performed multiple times, until it returns.

A Task is at the end of the command chain: The Mind delegates thinking to its State, State delegates work into the Subsystems by plugging in Tasks. Therefore a Task is supposed to work independently of other Tasks that might run in the other Subsystems (for instance: the ChaseEnemyTask (which is plugged into the movement Subsystem during Combat) only handles the AI movement, and nothing else. It does not change the AI state (in fact it is not allowed to change it) and the only way to communicate is to use data in the Memory and/or the owning idAI class.

The Task::Perform() method returns a boolean value to indicate whether this Task is finished (TRUE) or not (FALSE). Once a Task is returning TRUE, it is finished and the optional Task::OnFinish() event is triggered to give the Task the opportunity to do some cleanup. After that, the Task is removed from the Subsystem's TaskQueue and the next Task is activated.

Note: The OnFinish() method is also called when the Task is interrupted in its course (e.g. if the State is switched and the Subsystem's TaskQueue gets cleared). This ensures that the Task always gets the opportunity to perform its cleanup routine.


Things to remember:

  • Tasks are atomic actions and are highly specialised and act independently of other Subsystems.
  • Tasks may not switch States.
  • Tasks are allowed to use the Memory and the idAI methods of its owning AI class.
  • Tasks can be plugged into any of the AI's Subsystems.
  • Tasks are initialised once (Task::Init).
  • Tasks are performed often (Task::Perform), return TRUE if the Task is finished, FALSE otherwise.
  • Tasks can optionally implement an Task::OnFinish() routine to do some cleanup. This is always invoked.