AI for Games 1.1.1
Loading...
Searching...
No Matches
game2dai.fsm.FiniteStateMachine Class Reference

Public Member Functions

 FiniteStateMachine (BaseEntity owner)
 
 FiniteStateMachine (BaseEntity owner, State currentState, State previousState, State globalState)
 
void setCurrentState (State s)
 
void setGlobalState (State s)
 
void setPreviousState (State s)
 
void update (double deltaTime, World world)
 
boolean onMessage (Telegram msg)
 
void changeState (State newState)
 
void revertToPreviousState ()
 
boolean isGlobalState (State state)
 
boolean isPreviousState (State state)
 
boolean isCurrentState (State state)
 
boolean isUsingState (State st)
 
State getCurrentState ()
 
State getGlobalState ()
 
State getPreviousState ()
 
String getNameOfCurrentState ()
 

Protected Attributes

BaseEntity owner
 
State currentState
 
State previousState
 
State globalState
 

Private Member Functions

 FiniteStateMachine ()
 

Detailed Description

Author
Peter Lager

Constructor & Destructor Documentation

◆ FiniteStateMachine() [1/3]

game2dai.fsm.FiniteStateMachine.FiniteStateMachine ( )
private

Prevent use of default constructor

◆ FiniteStateMachine() [2/3]

game2dai.fsm.FiniteStateMachine.FiniteStateMachine ( BaseEntity  owner)

A FSM belongs to an entity (it cannot be shared by other entities)

Parameters
owner

◆ FiniteStateMachine() [3/3]

game2dai.fsm.FiniteStateMachine.FiniteStateMachine ( BaseEntity  owner,
State  currentState,
State  previousState,
State  globalState 
)
Parameters
owner
currentState
previousState
globalState

Member Function Documentation

◆ changeState()

void game2dai.fsm.FiniteStateMachine.changeState ( State  newState)

Change the current state of the entity.
Before changing the entity's state, the current state will be saved as the previous state. This method will also call the exit() method of the old state and the enter() method of the new state.

Parameters
newStatethe new current state

◆ getCurrentState()

State game2dai.fsm.FiniteStateMachine.getCurrentState ( )

Get the current state

◆ getGlobalState()

State game2dai.fsm.FiniteStateMachine.getGlobalState ( )

Get the global state

◆ isCurrentState()

boolean game2dai.fsm.FiniteStateMachine.isCurrentState ( State  state)

Sees if the current state is of the same type (class) as the parameter.

Parameters
statethe state we want to compare with.
Returns
true if it is the same class as the current state.

◆ isGlobalState()

boolean game2dai.fsm.FiniteStateMachine.isGlobalState ( State  state)

Sees if the global state is of the same type (class) as the parameter.

Parameters
statethe state we want to compare with.
Returns
true if it is the same class as the global state.

◆ isPreviousState()

boolean game2dai.fsm.FiniteStateMachine.isPreviousState ( State  state)

Sees if the previous state is of the same type (class) as the parameter.

Parameters
statethe state we want to compare with.
Returns
true if it is the same class as the previous state.

◆ isUsingState()

boolean game2dai.fsm.FiniteStateMachine.isUsingState ( State  st)

Use this method if using the singleton objects for each state. If in doubt use the other is????State methods.

Parameters
stthe current state object
Returns
true if the parameter is the same object as this

◆ onMessage()

boolean game2dai.fsm.FiniteStateMachine.onMessage ( Telegram  msg)

This method is called when a telegram for the owning entity is received.
It first passes it to the current state and if it is not processed by that state it is passed to the global state.

Parameters
msgthe telegram
Returns
true if this method processed the telegram

◆ revertToPreviousState()

void game2dai.fsm.FiniteStateMachine.revertToPreviousState ( )

Performs the same actions as the changeState() method but the new state will be the previous state.

◆ setCurrentState()

void game2dai.fsm.FiniteStateMachine.setCurrentState ( State  s)

Use this to set the current state.
This will leave the previous state value unchanged.

Parameters
sthe state to use

◆ setGlobalState()

void game2dai.fsm.FiniteStateMachine.setGlobalState ( State  s)

Use this to set the global state.

Parameters
sthe state to use

◆ setPreviousState()

void game2dai.fsm.FiniteStateMachine.setPreviousState ( State  s)

Use this to set the previous state.

Parameters
sthe state to use

◆ update()

void game2dai.fsm.FiniteStateMachine.update ( double  deltaTime,
World  world 
)

This method is called by the world update method and should not be caled directly.

Parameters
deltaTime
world

The documentation for this class was generated from the following file: