Skip to main content

Monster state flags

MonsterRuntimeFlags · 1 byte, flags at offset +0x16 of MonsterRuntime

Monsters · Monster behavior modes · The engine in ten minutes

Each monster has a byte of combinable state flags. They record that it has been provoked, that it is fleeing, that it is turned to stone, that it was already a target of Turn undead, which of two melee opportunities is its turn, that it was placed by the level, and that its drawing must flash.

No code was found that sets or tests bit 0x80.

typedef enum MonsterRuntimeFlags {
MONSTER_RUNTIME_PROVOKED = 0x01, /* Attacked, damaged, or turned on the party by a script; never cleared. */
MONSTER_RUNTIME_REVEALED = 0x02, /* Drawn even if its type has MONSTER_CAP_HIDDEN; set when damaged in view, cleared once its flash is drawn. */
MONSTER_RUNTIME_MELEE_ALTERNATE = 0x04, /* Toggled at each melee opportunity; the monster attacks when it is set. */
MONSTER_RUNTIME_AVOID_CLOSER_BLOCK = 0x08, /* Fleeing after Fear or Turn undead: moves away, refuses closer blocks. */
MONSTER_RUNTIME_TURN_UNDEAD_TRIED = 0x10, /* Already a target of Turn undead; later casts skip it. Never cleared. */
MONSTER_RUNTIME_TURNED_TO_STONE = 0x20, /* Flesh to Stone: no longer updated; melee destroys it. Never cleared. */
MONSTER_RUNTIME_KEEP_SLOT = 0x40 /* Placed by the level's INF data: SCRIPT_SPAWN_MONSTER never reuses the slot while it lives. */
} MonsterRuntimeFlags;

Provoked monsters​

Every hit roll a character makes against a monster — a melee attack, a projectile that rolls to hit, a Cause Wounds spell — sets MONSTER_RUNTIME_PROVOKED whatever its result, so a miss provokes too; damage sets it as well and clears MONSTER_RUNTIME_AVOID_CLOSER_BLOCK. A script sets the same bit with Set a flag and SCRIPT_FLAG_TARGET_MONSTER, which also switches the monster to MONSTER_MODE_PURSUE at once. Nothing clears the bit; see where the destination comes from.1

At each of its updates, a provoked monster that is not pursuing switches to MONSTER_MODE_PURSUE with the party's block as destination, unless it is peaceful (MONSTER_MODE_PEACEFUL) or paralyzed (MONSTER_MODE_PARALYZED). Since the bit stays, a provoked monster that loses the party and starts wandering is sent after the party's current block at its next update, wherever the party is.1

A provoked peaceful monster turns every peaceful monster of the level: each switches to MONSTER_MODE_PURSUE with the party's block as destination. The peaceful mode therefore ends for the whole level as soon as one of its monsters is attacked; this is how the clerics of level 5 react to an attack.1

In the same step, if the last such monster in slot order has type index 7, the game sets SCRIPT_GLOBAL_FLAG_18_UNKNOWN; for type index 12, it sets SCRIPT_GLOBAL_FLAG_27_UNKNOWN. The reference files never reach these two branches through the known paths: no level declares type index 12, the only monsters of type index 7 (on level 1) start in another mode, scripts never place a monster in the peaceful mode, and no script reads either bit.2

Avoiding the party​

A monster with MONSTER_RUNTIME_AVOID_CLOSER_BLOCK refuses to move into a block closer to the party than its current one; see walls and doors.3

Two spell effects set the bit, each time together with MONSTER_MODE_PURSUE and a counter:

  • Turn undead. An affected monster gets a counter of 40 and turns to face away from the party.
  • Fear, through spell effect 6. The monster gets a counter of 20 and tries one move away from the party. A delayed, peaceful or paralyzed monster is not affected.

While the bit is set, each move of the pursuing monster toward its destination goes the opposite way and lowers the counter by one; when the counter reaches zero, the bit is cleared and the monster moves normally; see moving toward the destination. Damage clears the bit at once. The bit is also cleared when the counter was already zero.4

Alternating melee attacks​

MONSTER_RUNTIME_MELEE_ALTERNATE is flipped each time the monster stands in position for a melee attack, and the attack happens only when the flip leaves it set; see melee attacks.5

Turned to stone​

Flesh to Stone sets MONSTER_RUNTIME_TURNED_TO_STONE. Such a monster is skipped by the monster update and the idle animation; it is drawn in a single colour (colour 13), and, standing in the centre of its block, it stays there when another monster enters; a character's hit roll against it always hits, and a melee attack destroys it at once ("The monster crumbles to dust!"), with experience. It keeps its block, hit points and mode, so it still occupies its block and can keep the party from resting; see the resting anomaly. Other damage, from spells or missiles, applies normally. No code was found that clears the bit.5

Placed by the level​

The level loader sets MONSTER_RUNTIME_KEEP_SLOT on every monster it places from the INF data. When SCRIPT_SPAWN_MONSTER finds no free slot, it kills the living monster farthest from the party among those without the bit, so only spawned monsters are replaced.6

Sources​

Locations refer to the game executable reference.

Footnotes​

  1. Damage a monster, a character's hit roll, react to provocation, wake peaceful monsters and the set flags handler. Comparative sources: characterAttackHitTest, updateMonsterAttackMode and turnFriendlyMonstersHostile in REF-SCUMM-008 and REF-SCUMM-020. ↩ ↩2 ↩3

  2. The wake routine writes the global flags. The statement about the reference files comes from the monster types, initial monsters and decoded scripts of the 16 reference INF files, and from a byte scan of the executable for literal writes of the peaceful mode; other addressing forms are not excluded. ↩

  3. Check a candidate move. ↩

  4. Turn undead, spell effects on a monster and move toward a destination; damage in damage a monster. Comparative sources: turnUndeadHit and magicObjectStatusHit in REF-SCUMM-013, and walkMonster in REF-SCUMM-020. ↩

  5. Close-range action, spell effects on a monster, monster update, the idle animation, a character's hit roll and melee attack. Comparative source: characterAttackHitTest and closeDistanceAttack in REF-SCUMM-020. ↩ ↩2

  6. The INF monster-state reader and spawn a monster. Comparative source: DarkMoonEngine::replaceMonster in REF-SCUMM-020. ↩