public class StateMachine
extends java.lang.Object
This is the agent's main behavioural state machine and implements the state design pattern.
It contains the states the agent may be in.
One state is assigned as the current state. Only the current state's implementation of processModel() is ever called by clients.
The state may be changed to a new state by calling changeState with a next state to change to.
Modifier and Type | Field and Description |
---|---|
static AttackingState |
ATTACKING_STATE |
static DefendingState |
DEFENDING_STATE |
static PassiveState |
PASSIVE_STATE |
static SupportState |
SUPPORT_STATE |
Constructor and Description |
---|
StateMachine(CommandPlayer context)
Create a state machine for a particular agent.
|
Modifier and Type | Method and Description |
---|---|
void |
changeState(State nextState,
EnvironmentModel model)
Change to a new state.
|
CommandPlayer |
getContext()
Return the context agent of this state machine.
|
void |
processModel(EnvironmentModel model)
Process the model in the current state.
|
public static final PassiveState PASSIVE_STATE
public static final DefendingState DEFENDING_STATE
public static final AttackingState ATTACKING_STATE
public static final SupportState SUPPORT_STATE
public StateMachine(CommandPlayer context)
context
- The agent to which this state machine belongs.public void changeState(State nextState, EnvironmentModel model)
nextState
- The state which should become the new currentState.model
- The current model which should be used to validate the new state.public void processModel(EnvironmentModel model)
model
- The model to be processed in the current state.public CommandPlayer getContext()