Rage against the state machine
A finite state machine (FSM) is made up of states, event, transitions and actions. There are a limited (finite) number of states it can be in and it is always in one of these state, called the current state. It can change from one state to another by responding to an event and the change is called a transition. Finally there is actions that is happening when the state machine is in a state or when using a transition.
The object that is the FSM. It needs to have a list of all it's states and what state is the current one. It also needs to know what state should be used as the start state.
onEvent(name) Send a event to the FSM for it to handle.
OnUpdate() Update the FSM.
FSMState* _current The current state
A state contains the actions that will happen when the state is the current one. It can also have a actions for when the state gets current or stops being current.
onEnter() Called when state is made the current.
onUpdate() Called each update when the state is current
onExit() Called when state stops being current.
A event as string that tells the FSM that something happens. For example a NoticeSound event can be sent to the FSM each time the agent hear a sound. The idle states then respond on that event by going to the Investigate state but the combat states ignore that event. Only the current state get to respond to the events so a global event list can also be used in the FSM for common events. If a global event list is used one can setup a Start event and simply send the Start event to the FSM when it is created to get it into the correct state.
When the FSM changes the current state it is called a transition. Mostly they do nothing but one could add the possibility of running actions when they take place.
The things that get done by the FSM are actions. They can be seperate objects that can be added to the states onEnter, onUpdate or onExit lists. Another options is to write them directly in the in functions of each state.
Stack-Based State Machines
Hierarchical Finite State Machine
Fuzzy State Machines
Finite State Machines with Ash entity system framework - 2012
Implementing a State Machine Language, AIGPW1 p314-320. - 2002.
Enhancing a State Machine Language through Messaging, AIGPW1 p321-329. - 2002.
The Ultimate Guide to FSMs in Games, AIGPW2 p283-302 - 2004.
Stack-Based Finite-State Machines, AIGPW2 p303-306. - 2004.
Implementing a Data-Driven Finite-State Machine, AIGPW2 p307-317 - 2004.
Finite-State Machine Scripting Language for Designers, AIGPW2 p319-325. - 2004.
Finite-State Machines. AIGEP p241-279 - 2004