AFSM (File Format)

The AFSM format controls AI behavior; it stands for AI Finite State Machine. AI-controlled creatures have a limited number of possible states they can be in. The AFSM file defines those states, and what triggers can cause it to transition to another state.

Header
The format first defines a list of states, then defines the triggers for each transition attached to each state. There are no state/trigger type IDs; rather, the name string itself is used as an identifier to fetch the corresponding AI function. It starts with a short header listing each state and then providing a trigger count. Note that the trigger count isn't actually used to parse the file; it's present merely because the game uses it to allocate space for each trigger ahead of time.

State Transitions
Following that, it iterates through each state, defining the transitions associated with each one. Transitions are composed of a target state index and a number of triggers; when all the triggers associated with a transition are satisfied, it advances to the targeted state. The state transitions are structured like this: