|  | overview |  | wiki |  | api reference |  | download

- Main Page
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Functions Variables Typedefs Enumerations Enumerator
Public Member Functions
gameplay::AIStateMachine Class Reference

`#include <AIStateMachine.h>`

List of all members.

## 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)

## Detailed Description

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.

## Member Function Documentation

AIState* gameplay::AIStateMachine::addState | ( | const char * | id | ) |

Creates and adds a new state to the state machine.

Parameters:

  id | ID of the new state.

Returns:
  The newly created and added 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.

Parameters:

  state | The state to add.

AIState* gameplay::AIStateMachine::getActiveState | ( |  | ) | const

Returns the active state for this state machine.

Returns:
  The active state for this state machine.

AIAgent* gameplay::AIStateMachine::getAgent | ( |  | ) | const

Returns the AIAgent that owns this state machine.

Returns:
  The AIAgent that owns this state machine.

AIState* gameplay::AIStateMachine::getState | ( | const char * | id | ) | const

Returns a state registered with this state machine.

Parameters:

  id | The ID of the state to return.

Returns:
  The state with the given ID, or NULL if no such state exists.

void gameplay::AIStateMachine::removeState | ( | AIState * | state | ) |

Removes a state from the state machine.

Parameters:

  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.

Parameters:

  id | The ID of the new state.

Returns:
  The new state, or NULL if no matching state could be found.

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.

Parameters:

  state | The new state.

Returns:
  true if the state is successfully changed, false otherwise.

All Classes Functions Variables Typedefs Enumerations Enumerator