Directions
Direction · 2 bits of value; stored as a word for the party, a byte for
monsters and script operands
Blocks, directions and positions ·
LevelBlockRuntime ·
MonsterRuntime
The game numbers the four compass directions clockwise from north. The same values give the party's facing, a monster's facing, the step to a neighboring block and the side of a block that a wall reference belongs to. Turning adds or subtracts one, modulo 4.
/* A compass direction (values 0–3; arithmetic is done modulo 4). */
typedef enum Direction {
DIRECTION_NORTH = 0, /* Neighbor: row − 1, block index − 32. */
DIRECTION_EAST = 1, /* Neighbor: column + 1, block index + 1. */
DIRECTION_SOUTH = 2, /* Neighbor: row + 1, block index + 32. */
DIRECTION_WEST = 3 /* Neighbor: column − 1, block index − 1. */
} Direction;
Row 00 is the northern edge of a level and column 00 its western edge, so
[00:00] is the north-west corner. Positions are written [XX:YY], column
then row; block index = YY × 32 + XX.
Relative directions
For a facing d:
| Relative direction | Value | Example, facing DIRECTION_NORTH |
|---|---|---|
| Ahead | d | DIRECTION_NORTH |
| Right | (d + 1) & 3 | DIRECTION_EAST |
| Behind | (d + 2) & 3 | DIRECTION_SOUTH |
| Left | (d + 3) & 3 | DIRECTION_WEST |
The party's "turn left" and "step left" buttons use d − 1, the right ones
d + 1. When the party looks at the block ahead, it sees that block's
(d + 2) & 3 side, the side turned towards it.
Where it is used
- the party's direction, a word;
- the
directionbyte of each monster slot, which the patrol and wander modes pass to the same neighbor routine; - the index of
wall_referencesin a level block: sidesis the face turned towards directions; - script operands such as the facing after a
level change and the turns of
SCRIPT_CHANGE_DIRECTION.
Edge case
The neighbor routine wraps the block index to 0–1,023 without checking the row: stepping east from column 31 leads to column 0 of the next row, and stepping north from row 0 to row 31. A level whose edges are not closed by walls would therefore connect its opposite sides this way.
Sources
Locations refer to the game executable reference; comparative sources are listed in the technical references.
The neighbor routine and its
direction steps; the
compass shapes and
compass drawing; the
visible blocks and the
view setup; the
movement buttons; the monster
patrol modes. Comparative source:
generateBlockDrawingBuffer in REF-SCUMM-016.