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 advance to another state.
|
This file format is almost completely documented We should have a list of possible states and trigger conditions and a short explanation of what they generally do on this page somewhere. Also, the float settings on conditions is unknown.
|
Format
The format first defines a list of states, then defines each trigger 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.
Type
|
Count
|
Description
|
long
|
1
|
State count (SC)
|
string
|
SC
|
State names (each zero-terminated)
|
long
|
1
|
Trigger count
|
State Triggers
Following that, it iterates through each state, defining the triggers associated with each one. Triggers are composed of a target state index and a number of conditions; when all the conditions associated with a trigger are satisfied, it advances to the targeted state. The state trigger definitions are structured like this:
Type
|
Count
|
Description
|
long
|
1
|
Trigger count (TC)
|
Trigger
|
TC
|
Triggers
|
Trigger
Type
|
Count
|
Description
|
long
|
1
|
Condition count (CC)
|
Trigger condition
|
CC
|
Conditions
|
Condition
Type
|
Count
|
Description
|
string
|
1
|
Condition name
|
float
|
1
|
Unknown (possibly AI function parameter)
|
long
|
1
|
Target state index (note: this is ONLY present on the first condition for each trigger!)
|