overview wiki api reference download
 All Classes Functions Variables Typedefs Enumerations Enumerator
Public Member Functions
gameplay::AIStateMachine Class Reference

#include <AIStateMachine.h>

List of all members.

Public Member Functions

AIAgentgetAgent () const
AIStateaddState (const char *id)
void addState (AIState *state)
void removeState (AIState *state)
AIStategetState (const char *id) const
AIStategetActiveState () const
AIStatesetState (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

Creates and adds a new state to the state machine.

Parameters:
idID of the new state.
Returns:
The newly created and added 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:
stateThe state to add.

Returns the active state for this state machine.

Returns:
The active state for this state machine.

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:
idThe ID of the state to return.
Returns:
The state with the given ID, or NULL if no such state exists.

Removes a state from the state machine.

Parameters:
stateThe state to remove.

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:
idThe ID of the new state.
Returns:
The new state, or NULL if no matching state could be found.

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:
stateThe new state.
Returns:
true if the state is successfully changed, false otherwise.
 All Classes Functions Variables Typedefs Enumerations Enumerator