#include <AIStateMachine.h>
Public Member Functions | |
AIAgent * | getAgent () const |
AIState * | addState (const char *id) |
void | addState (AIState *state) |
void | removeState (AIState *state) |
AIState * | getState (const char *id) const |
AIState * | getActiveState () const |
AIState * | setState (const char *id) |
bool | setState (AIState *state) |
Defines a simple AI state machine that can be used to program logic for an AIAgent in a game.
A state machine uses AIState objects to represent different states of an object in the game. The state machine provides access to the current state of an AI agent and it controls state changes as well. When a new state is set, the stateExited event will be called for the previous state, the stateEntered event will be called for the new state and then the stateUpdate event will begin to be called each frame while the new state is active.
Communication of state changes is facilitated through the AIMessage class. Messages are dispatched by the AIController and can be used for purposes other than state changes as well. Messages may be sent to the state machines of any other agents in a game and can contain any arbitrary information. This mechanism provides a simple, flexible and easily debuggable method for communicating between AI objects in a game.
AIState* gameplay::AIStateMachine::addState | ( | const char * | id | ) |
Creates and adds a new state to the state machine.
id | ID of the new state. |
void gameplay::AIStateMachine::addState | ( | AIState * | state | ) |
Adds a state to the state machine.
The specified state may be shared by other state machines. Its reference count is increased while it is held by this state machine.
state | The state to add. |
AIState* gameplay::AIStateMachine::getActiveState | ( | ) | const |
Returns the active state for this state machine.
AIAgent* gameplay::AIStateMachine::getAgent | ( | ) | const |
AIState* gameplay::AIStateMachine::getState | ( | const char * | id | ) | const |
Returns a state registered with this state machine.
id | The ID of the state to return. |
void gameplay::AIStateMachine::removeState | ( | AIState * | state | ) |
Removes a state from the state machine.
state | The state to remove. |
AIState* gameplay::AIStateMachine::setState | ( | const char * | id | ) |
Changes the state of this state machine to the given state.
If no state with the given ID exists within this state machine, this method does nothing.
id | The ID of the new state. |
bool gameplay::AIStateMachine::setState | ( | AIState * | state | ) |
Changes the state of this state machine to the given state.
If the given state is not registered with this state machine, this method does nothing.
state | The new state. |