> For the complete documentation index, see [llms.txt](https://axiomemu.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://axiomemu.gitbook.io/docs/data/monster/monsteraiunit.md).

# MonsterAIUnit

AI personality glue. Each Unit picks one Automata (state machine) and maps each of the 8 AI states to an Element (the action to perform). Groups and rules reference Units by `Number`.

## File Location

```
Data/Monster/MonsterAIUnit.xml
```

Loaded once at GameServer startup. Changes require a restart.

## Dependencies

| Depends On                                                       | Purpose                                                 |
| ---------------------------------------------------------------- | ------------------------------------------------------- |
| [MonsterAIAutomata.xml](/docs/data/monster/monsteraiautomata.md) | Supplies the state machine referenced by `Automata`     |
| [MonsterAIElement.xml](/docs/data/monster/monsteraielement.md)   | Supplies the per-state actions referenced by `Element*` |

| Used By                                                    | Purpose                                                            |
| ---------------------------------------------------------- | ------------------------------------------------------------------ |
| [MonsterAIGroup.xml](/docs/data/monster/monsteraigroup.md) | Assigns Units to monsters via `StartAI` / `AI01` / `AI02` / `AI03` |
| [MonsterAIRule.xml](/docs/data/monster/monsterairule.md)   | Temporarily overrides a monster class's Unit on a schedule         |

## Role in the AI Hierarchy

```
MonsterAIGroup.xml  (BasicAI per monster)
         |
         v
MonsterAIUnit.xml   <-- this file (picks Automata + maps states -> Elements)
         |
         +-> MonsterAIAutomata.xml  (state machine)
         +-> MonsterAIElement.xml   (actions)
```

## Attributes

```xml
<Unit Number="..." Name="..." DelayTime="..."
      Automata="..."
      ElementNormal="..." ElementMove="..." ElementAttack="..." ElementHeal="..."
      ElementAvoid="..." ElementHelp="..." ElementSpecial="..." ElementEvent="..." />
```

| Attribute        | Type       | Effect                                                                                                                         |
| ---------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `Number`         | int        | Unique Unit ID. Valid range 0-99. Used as the storage index, so duplicates overwrite each other                                |
| `Name`           | string     | Human-readable label. Truncated at 49 characters                                                                               |
| `DelayTime`      | ms         | Minimum delay between AI dispatcher runs for monsters using this Unit. Lower = more reactive                                   |
| `Automata`       | int        | `Number` from [MonsterAIAutomata.xml](/docs/data/monster/monsteraiautomata.md). Required - a Unit with no Automata never ticks |
| `ElementNormal`  | int or `*` | Element for state 0 (NORMAL)                                                                                                   |
| `ElementMove`    | int or `*` | Element for state 1 (MOVE)                                                                                                     |
| `ElementAttack`  | int or `*` | Element for state 2 (ATTACK)                                                                                                   |
| `ElementHeal`    | int or `*` | Element for state 3 (HEAL)                                                                                                     |
| `ElementAvoid`   | int or `*` | Element for state 4 (AVOID)                                                                                                    |
| `ElementHelp`    | int or `*` | Element for state 5 (HELP)                                                                                                     |
| `ElementSpecial` | int or `*` | Element for state 6 (SPECIAL)                                                                                                  |
| `ElementEvent`   | int or `*` | Element for state 7 (EVENT)                                                                                                    |

All Element references resolve against the `Number` attribute in [MonsterAIElement.xml](/docs/data/monster/monsteraielement.md). Using `*` or omitting an Element attribute leaves that state unwired - if the Automata transitions to that state, no action runs and the tick no-ops.

## State-to-Element Mapping

| State ID | State   | Unit attribute   |
| -------- | ------- | ---------------- |
| 0        | NORMAL  | `ElementNormal`  |
| 1        | MOVE    | `ElementMove`    |
| 2        | ATTACK  | `ElementAttack`  |
| 3        | HEAL    | `ElementHeal`    |
| 4        | AVOID   | `ElementAvoid`   |
| 5        | HELP    | `ElementHelp`    |
| 6        | SPECIAL | `ElementSpecial` |
| 7        | EVENT   | `ElementEvent`   |

Each tick the Automata picks a transition; the Element bound to that transition's next state runs. The engine does not validate that the Element's declared class matches the state - an `ElementAttack` can point at a HEAL-class Element and the engine will still execute it, just as the wrong thing.

## Tick Timing

Two delays gate every AI tick for a monster:

* The Unit's `DelayTime` (this file) caps how often the Automata is consulted.
* The Element returned by the Automata can set its own per-element delay on the monster, applied before the next Automata run.

Both are in milliseconds. Lower values increase CPU load for the class.

## Cross-File References

| Attribute  | Resolved Against                                                                                                                                                     |
| ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Number`   | [MonsterAIGroup.xml](/docs/data/monster/monsteraigroup.md) `StartAI` / `AI01` / `AI02` / `AI03`, and [MonsterAIRule.xml](/docs/data/monster/monsterairule.md) `Unit` |
| `Automata` | [MonsterAIAutomata.xml](/docs/data/monster/monsteraiautomata.md) `Number`                                                                                            |
| `Element*` | [MonsterAIElement.xml](/docs/data/monster/monsteraielement.md) `Number`                                                                                              |

## Common Issues

* Monster idle forever - `ElementNormal` is wired but the Automata never transitions to any other state, so the non-idle Elements never run.
* Wrong action in the wrong state - Element class does not match the slot. The engine executes whatever it is bound to.
* `DelayTime` too low - the dispatcher runs faster than the monster's animation or path can complete, producing jerky behaviour.
* AI change event does nothing - `ElementEvent` is missing or set to `*`; state 7 transitions fire but no action runs.
* Duplicate `Number` - the later entry overwrites the earlier one silently.
* `Number` outside 0-99 - entry is dropped silently at load.

## Related Systems

* [MonsterAIAutomata.xml](/docs/data/monster/monsteraiautomata.md) - state machine that drives transitions
* [MonsterAIElement.xml](/docs/data/monster/monsteraielement.md) - per-state action definitions
* [MonsterAIGroup.xml](/docs/data/monster/monsteraigroup.md) - assigns Units to individual monsters
* [MonsterAIRule.xml](/docs/data/monster/monsterairule.md) - time-scheduled Unit overrides
* [Monster.xml](/docs/data/monster/monster.md) - monster stats and base combat parameters
