Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
StateMachine Class Reference

#include <StateMachine.h>

Inherits MemoryPoolObject, and Snapshot.

Inherited by AIAttackMoveStateMachine, AIAttackThenIdleStateMachine, AIDockMachine, AIGuardMachine, AIGuardRetaliateMachine, AIStateMachine, AITNGuardMachine, AttackStateMachine, DeliverPayloadStateMachine, DozerActionStateMachine, DozerPrimaryStateMachine, SupplyTruckStateMachine, TurretStateMachine, and WorkerStateMachine.

Public Member Functions

 StateMachine (Object *owner, AsciiString name)
 
virtual StateReturnType updateStateMachine ()
 run one step of the machine
 
virtual void clear ()
 clear the machine's internals to a known, initialized state
 
virtual StateReturnType resetToDefaultState ()
 clear the machine's internals and set to the default state
 
virtual StateReturnType initDefaultState ()
 
virtual StateReturnType setState (StateID newStateID)
 change the current state of the machine (which may cause further state changes, due to onEnter)
 
StateID getCurrentStateID () const
 return the id of the current state of the machine
 
Bool isInIdleState () const
 
Bool isInAttackState () const
 
Bool isInForceAttackState () const
 
Bool isInGuardIdleState () const
 
Bool isInBusyState () const
 
void lock (const char *msg)
 
void unlock ()
 
Bool isLocked () const
 
ObjectgetOwner ()
 
const ObjectgetOwner () const
 
void setGoalObject (const Object *obj)
 
ObjectgetGoalObject ()
 
const ObjectgetGoalObject () const
 
void setGoalPosition (const Coord3D *pos)
 
const Coord3DgetGoalPosition () const
 
Bool isGoalObjectDestroyed () const
 Returns true if we had a goal object, but it has been destroyed.
 
virtual void halt (void)
 Stops the state machine & disables it in preparation for deleting it.
 
StateReturnType internalSetState (StateID newStateID)
 for internal use only - change the current state of the machine
 
Bool getWantsDebugOutput () const
 
AsciiString getCurrentStateName () const
 
- Public Member Functions inherited from MemoryPoolObject
void deleteInstance ()
 
- Public Member Functions inherited from Snapshot
 Snapshot (void)
 
 ~Snapshot (void)
 

Protected Member Functions

virtual void crc (Xfer *xfer)
 
virtual void xfer (Xfer *xfer)
 
virtual void loadPostProcess ()
 
void defineState (StateID id, State *state, StateID successID, StateID failureID, const StateConditionInfo *conditions=NULL)
 
StateinternalGetState (StateID id)
 
- Protected Member Functions inherited from MemoryPoolObject
virtual ~MemoryPoolObject ()
 
void * operator new (size_t s)
 
void operator delete (void *p)
 
virtual MemoryPoolgetObjectMemoryPool ()=0
 

Detailed Description

A finite state machine.

Definition at line 240 of file StateMachine.h.

Constructor & Destructor Documentation

◆ StateMachine()

StateMachine::StateMachine ( Object * owner,
AsciiString name )

All of the states used by this machine should be instantiated and defined via defineState() in the machine's constructor.

Constructor

Definition at line 267 of file StateMachine.cpp.

Member Function Documentation

◆ clear()

void StateMachine::clear ( )
virtual

clear the machine's internals to a known, initialized state

Clear the machine

Reimplemented in AIStateMachine, and TurretStateMachine.

Definition at line 351 of file StateMachine.cpp.

◆ crc()

◆ defineState()

void StateMachine::defineState ( StateID id,
State * state,
StateID successID,
StateID failureID,
const StateConditionInfo * conditions = NULL )
protected

Given a unique (to this machine) integer ID representing a state, and an instance of that state, the machine records this as a possible state, and internally maps the given integer ID to the state instance. These state id's are used to change the machine's state via setState().

Given a unique (for this machine) id number, and an instance of the State class, the machine records this as a possible state, and retains the id mapping. These state id's are used to change the machine's state via setState().

Definition at line 484 of file StateMachine.cpp.

◆ getCurrentStateID()

StateID StateMachine::getCurrentStateID ( ) const
inline

return the id of the current state of the machine

Definition at line 266 of file StateMachine.h.

◆ getCurrentStateName()

AsciiString StateMachine::getCurrentStateName ( ) const
inline

Definition at line 336 of file StateMachine.h.

◆ getGoalObject() [1/2]

Object * StateMachine::getGoalObject ( )

Definition at line 780 of file StateMachine.cpp.

◆ getGoalObject() [2/2]

const Object * StateMachine::getGoalObject ( ) const

Definition at line 786 of file StateMachine.cpp.

◆ getGoalPosition()

const Coord3D * StateMachine::getGoalPosition ( ) const
inline

Definition at line 314 of file StateMachine.h.

◆ getOwner() [1/2]

Object * StateMachine::getOwner ( )
inline

Get the object that "owns" this machine. There need not be an object with a machine, but it is so common that it is useful to have this method in the generic state machine.

Definition at line 306 of file StateMachine.h.

◆ getOwner() [2/2]

const Object * StateMachine::getOwner ( ) const
inline

Definition at line 307 of file StateMachine.h.

◆ getWantsDebugOutput()

Bool StateMachine::getWantsDebugOutput ( ) const
inline

Definition at line 335 of file StateMachine.h.

◆ halt()

void StateMachine::halt ( void )
virtual

Stops the state machine & disables it in preparation for deleting it.

Reimplemented in AIDockMachine.

Definition at line 755 of file StateMachine.cpp.

◆ initDefaultState()

StateReturnType StateMachine::initDefaultState ( )
virtual

must be called to jump the StateMachine into the default state... this may fail (return a failure code), so it can't be done via the ctor. you MUST call this before using the state machine.

Define the default state of the machine, and set the machine's state to it.

Definition at line 665 of file StateMachine.cpp.

◆ internalGetState()

State * StateMachine::internalGetState ( StateID id)
protected

Given a state ID, return the state instance

Definition at line 513 of file StateMachine.cpp.

◆ internalSetState()

StateReturnType StateMachine::internalSetState ( StateID newStateID)

for internal use only - change the current state of the machine

Change the current state of the machine. This causes the old state's onExit() method to be invoked, and the new state's onEnter() method to be invoked.

Todo
It might be useful to pass the old state in... (MSB)

Definition at line 563 of file StateMachine.cpp.

◆ isGoalObjectDestroyed()

Bool StateMachine::isGoalObjectDestroyed ( ) const

Returns true if we had a goal object, but it has been destroyed.

Definition at line 745 of file StateMachine.cpp.

◆ isInAttackState()

Bool StateMachine::isInAttackState ( ) const
inline

Definition at line 268 of file StateMachine.h.

◆ isInBusyState()

Bool StateMachine::isInBusyState ( ) const
inline

Definition at line 273 of file StateMachine.h.

◆ isInForceAttackState()

Bool StateMachine::isInForceAttackState ( ) const
inline

Definition at line 269 of file StateMachine.h.

◆ isInGuardIdleState()

Bool StateMachine::isInGuardIdleState ( ) const
inline

Definition at line 270 of file StateMachine.h.

◆ isInIdleState()

Bool StateMachine::isInIdleState ( ) const
inline

Definition at line 267 of file StateMachine.h.

◆ isLocked()

Bool StateMachine::isLocked ( ) const
inline

Definition at line 299 of file StateMachine.h.

◆ loadPostProcess()

◆ lock()

void StateMachine::lock ( const char * msg)
inline

Lock/unlock this state machine. If a machine is locked, it cannot be reset, or given external setStates(), etc.

Definition at line 283 of file StateMachine.h.

◆ resetToDefaultState()

StateReturnType StateMachine::resetToDefaultState ( )
virtual

clear the machine's internals and set to the default state

Reset the machine to its default state

Reimplemented in AIStateMachine, and TurretStateMachine.

Definition at line 376 of file StateMachine.cpp.

◆ setGoalObject()

void StateMachine::setGoalObject ( const Object * obj)

Definition at line 736 of file StateMachine.cpp.

◆ setGoalPosition()

void StateMachine::setGoalPosition ( const Coord3D * pos)

Definition at line 792 of file StateMachine.cpp.

◆ setState()

StateReturnType StateMachine::setState ( StateID newStateID)
virtual

change the current state of the machine (which may cause further state changes, due to onEnter)

Change the current state of the machine. This causes the old state's onExit() method to be invoked, and the new state's onEnter() method to be invoked.

Reimplemented in AIStateMachine, and TurretStateMachine.

Definition at line 542 of file StateMachine.cpp.

◆ unlock()

void StateMachine::unlock ( )
inline

Definition at line 291 of file StateMachine.h.

◆ updateStateMachine()

StateReturnType StateMachine::updateStateMachine ( )
virtual

run one step of the machine

Run one step of the machine

Reimplemented in AIStateMachine.

Definition at line 419 of file StateMachine.cpp.

◆ xfer()


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