Modes and provocation
Monsters · MonsterMode · MonsterRuntimeFlags
In brief
A monster's behavior is its mode: pursuing, wandering, waiting, patrolling, delayed, peaceful or paralyzed. The level data or a script gives the first mode; during play, noticing the party, being provoked, the end of a counter and some spells change it. A monster attacked by a character is provoked for good: whenever it stops pursuing, it sets off again toward the party, wherever the party is.
Reacting to damage
When a character attacks a monster — hit or miss — or a monster is damaged
and survives, it is marked MONSTER_RUNTIME_PROVOKED; if it is damaged
within distance 3 of the party, it also records the party's block as its
destination.1
On its next update, a provoked monster switches to MONSTER_MODE_PURSUE and
records the party's block, unless it is paralyzed. A provoked peaceful
monster wakes every peaceful monster at once: they all switch to pursuit.
See provoked monsters.
The flag is never cleared, so this happens again at every update in which
the monster is in another mode; see
what a monster's state changes.1
Changing mode
A monster's mode comes from the level's INF data or
from SCRIPT_SPAWN_MONSTER,
together with a counter; only these give MONSTER_MODE_DELAYED,
MONSTER_MODE_PEACEFUL or MONSTER_MODE_UNKNOWN_9. During play, the mode
changes only in these cases:2
| Cause | Modes affected | New mode | Destination |
|---|---|---|---|
| The monster notices the party | 0 to 6 | MONSTER_MODE_PURSUE | The party's block |
| It is provoked, at its next update | 1 to 9, except peaceful and paralyzed | MONSTER_MODE_PURSUE | The party's block |
| A peaceful monster is provoked or dies | Every MONSTER_MODE_PEACEFUL monster | MONSTER_MODE_PURSUE | The party's block |
A script sets a flag of the monster (SCRIPT_FLAG_TARGET_MONSTER) | Any | MONSTER_MODE_PURSUE | Unchanged |
| In pursuit, the block ahead is the destination and the party is not there | MONSTER_MODE_PURSUE | MONSTER_MODE_WANDER_LEFT or _RIGHT, at random | Unchanged |
| Its counter reaches zero | Delayed, paralyzed | MONSTER_MODE_PURSUE | Unchanged |
| Hold Person, Hold Monster, Power Word Stun | Any | MONSTER_MODE_PARALYZED, counter 15 | Unchanged |
| Fear | All but delayed, peaceful, paralyzed | MONSTER_MODE_PURSUE, fleeing, counter 20 | Unchanged |
| Turn undead succeeds | Any | MONSTER_MODE_PURSUE, fleeing, counter 40 | Unchanged |
The conditions of each spell — the monster types it affects, immunities and
saving throws — are in the attack spells.
Counters count the updates of the monster's own group, so a hold lasts 15
times the level's update interval. A monster that leaves a counted mode,
flees or is provoked by a script keeps whatever destination it had: the
block where it last noticed the party, or [00:00] if it never did.
A monster killed to free its slot for
SCRIPT_SPAWN_MONSTER dies
like any other, so a peaceful one wakes the others. A peaceful monster that
is held, turned or provoked by a script leaves the peaceful mode alone,
without waking the others: only its provocation by an attack or its death
wakes the whole group.2
ANOMALY-147 — The routine that wakes peaceful monsters keeps a pointer to the last one it
woke and, after its loop, reads that monster's type to set a
global script flag. It does not test that it
woke any: with no monster in MONSTER_MODE_PEACEFUL, the pointer is
whatever the stack holds, and the byte it reads could set the flag
(inferred). The case is latent: both callers run the routine only for a
monster that is itself peaceful, so the loop always wakes at least one. A
faithful reimplementation keeps that guard and has nothing else to
reproduce.2
What a monster's state changes
Besides its mode, a monster's decisions depend on a few fields of its
MonsterRuntime slot and on its
state flags:3
| State | Set by | Effect | Ends |
|---|---|---|---|
| No hit points | Death | Never updated, never notices the party. | A new monster in the slot |
MONSTER_RUNTIME_PROVOKED | A character's hit roll against it, hit or miss; damage; a script | Each update outside pursuit, peaceful and paralyzed modes sends it back to pursuit, toward the party's current block. | Never |
MONSTER_RUNTIME_AVOID_CLOSER_BLOCK | Fear, Turn undead | It flees: moves away from its destination and refuses any block closer to the party. | Damage, or its counter running out |
MONSTER_RUNTIME_MELEE_ALTERNATE | Each melee opportunity toggles it | It attacks only when the toggle leaves it set: every second opportunity. | Toggled again |
MONSTER_RUNTIME_TURNED_TO_STONE | Flesh to Stone | Never updated or animated; any melee attack hits it and destroys it, with experience. | Never |
MONSTER_RUNTIME_TURN_UNDEAD_TRIED | A Turn undead attempt on it | No later Turn undead affects it, whatever the result of the first. | Never |
| Skip-update byte | A class-1 monster on its block turning it | It misses its next update. | That update |
| Counter | Level data, spawn, spells | Delayed and paralyzed: updates left. Fleeing: steps left. | Zero |
Provocation lasts. Nothing clears MONSTER_RUNTIME_PROVOKED. A provoked
monster that loses the party in pursuit switches to a wander mode as usual,
but its next update sends it back to pursuit with the party's current
block as destination, at any distance and through walls. Once attacked, a
monster therefore keeps finding the party; only death, a hold or the
peaceful mode stops it.
Fleeing. While MONSTER_RUNTIME_AVOID_CLOSER_BLOCK is set, each step
toward the destination goes the opposite way and lowers the counter. When
the counter reaches zero the flag is cleared and the monster moves normally
again; damage clears the flag at once. Attacks are still tried before
moving, as in any pursuit.
Turned to stone. The monster keeps its block, hit points and mode, so it still occupies its block, stands in the way of ranged attacks and keeps the party from resting nearby. No code turns it back.
Standing still. After the mode routine, the walking frame alternates at
every update unless the monster is then waiting, delayed or peaceful. A
paralyzed monster and a MONSTER_MODE_UNKNOWN_9 monster therefore keep
alternating their walking frames while they stand in place.
Sources
Locations refer to the game executable reference; comparative sources are listed in the technical references.