Skip to main content

Block state flags

LevelBlockStateFlags · 16-bit state word of LevelBlockRuntime

Block events · Events that start scripts · The engine in ten minutes

Each block of a level has a state word. Its low bits count the monsters in the block; most of the other bits switch on one block event each, so that the block's script runs only for the events it cares about.1

The remaining bits, 0x0100, 0x0200, 0x0400 and 0x8000, have no effect: the gate described below ignores them for every event the game sends, every other reader keeps only the occupancy count, and the count can never grow large enough to reach them.

typedef enum LevelBlockStateFlags {
LEVEL_BLOCK_OCCUPANCY_MASK = 0x0007, /* Three-bit field: checked, then decremented, when a monster leaves. */
LEVEL_BLOCK_PARTY_ENTER_EVENT = 0x0008, /* Enables BLOCK_EVENT_PARTY_ENTER. */
LEVEL_BLOCK_PARTY_LEAVE_EVENT = 0x0010, /* Enables BLOCK_EVENT_PARTY_LEAVE. */
LEVEL_BLOCK_ITEM_PLACED_EVENT = 0x0020, /* Enables BLOCK_EVENT_ITEM_PLACED. */
LEVEL_BLOCK_ITEM_REMOVED_EVENT = 0x0040, /* Enables BLOCK_EVENT_ITEM_REMOVED. */
LEVEL_BLOCK_FLYING_OBJECT_EVENT = 0x0080, /* Enables BLOCK_EVENT_FLYING_OBJECT. */
LEVEL_BLOCK_ITEM_USED_EVENT = 0x0800, /* Enables BLOCK_EVENT_ITEM_USED. */
LEVEL_BLOCK_MONSTER_ENTER_EVENT = 0x1000, /* Enables BLOCK_EVENT_MONSTER_ENTER. */
LEVEL_BLOCK_MONSTER_EXIT_EVENT = 0x2000, /* Enables BLOCK_EVENT_MONSTER_EXIT. */
LEVEL_BLOCK_SPELL_CAST_EVENT = 0x4000 /* Enables BLOCK_EVENT_SPELL_CAST. */
} LevelBlockStateFlags;

The gating rule​

The event flags all follow from one rule in the dispatcher: the state bit three places above an event's bit enables that event, and BLOCK_EVENT_STEP_COUNT, BLOCK_EVENT_WALL_DECORATION and BLOCK_EVENT_TIMER are always accepted. So LEVEL_BLOCK_PARTY_ENTER_EVENT enables BLOCK_EVENT_PARTY_ENTER, and so on. As a consequence:2

  • the three state bits above LEVEL_BLOCK_FLYING_OBJECT_EVENT would enable the always-accepted events, so they have no effect on gating and have no name;
  • the bit above LEVEL_BLOCK_SPELL_CAST_EVENT would enable an event bit above BLOCK_EVENT_SPELL_CAST; no event has that bit, and the keyboard activation, which has every bit set, is accepted without it.

The occupancy mask is a three-bit count, not an independent flag; see sharing a block. Placing a monster adds one to the whole word, so a count above seven carries into LEVEL_BLOCK_PARTY_ENTER_EVENT and the bits above it. This happens on [00:00], where every dead monster is placed and whose count already starts at 4 when a level is loaded; see the map header anomaly.

Use in the reference files​

Positions are written [XX:YY], column then row, for block index YY × 32 + XX.

The cell bindings of the 16 reference INF files set only the nine named event flags, from LEVEL_BLOCK_PARTY_ENTER_EVENT to LEVEL_BLOCK_SPELL_CAST_EVENT. The bindings of position [00:00], whose script receives BLOCK_EVENT_STEP_COUNT, set none.3

Sources​

Locations refer to the game executable reference.

Footnotes​

  1. Place a monster on a block and the block event dispatcher. ↩

  2. Block event dispatcher. ↩

  3. The INF loader applies the cell bindings. The statistics come from the 16 reference INF files. ↩