Scripted walls and doors
Scripts · Walls and doors · SCRIPT_TOGGLE
In brief
Scripts set or toggle the wall references of a block, one side or all four, and ask doors to open, close or toggle. A door request records a slot and makes a first step at once; the door update then moves the door one reference every six ticks or more, while the script goes on. Three slots exist; without a free one the door jumps to its endpoint.
Walls
Setting walls. SCRIPT_SET assigns
wall references in a LevelBlockRuntime;
its target is a ScriptSetTarget:1
| Target | Effect |
|---|---|
SCRIPT_SET_BLOCK_WALLS | Give all four sides of a block the same wall reference. |
SCRIPT_SET_BLOCK_SIDE | Give one side of a block a wall reference. |
SCRIPT_SET_DIRECTION | Set the party's facing. |
Toggling walls. SCRIPT_TOGGLE
switches a wall between two references, with SCRIPT_TOGGLE_BLOCK_WALLS for
all four sides or SCRIPT_TOGGLE_BLOCK_SIDE for one (
ScriptToggleTarget):2
if current_reference == first_reference:
new_reference = second_reference
else:
new_reference = first_reference
For all four sides, the first side alone decides, even if the others differ, and a wall holding neither reference becomes the first one.
Only the block named is changed: its neighbor's matching face is not. After either change, the game checks whether the block is one of the 15 blocks in view ahead of the party and, if so, marks the view for redrawing. The changed walls are kept in the level's record when the party leaves the level, and in saved games; see level records.
Side s is the face turned towards direction s (0 north, 1 east, 2 south,
3 west; see Direction).
Doors
SCRIPT_OPEN_DOOR and
SCRIPT_CLOSE_DOOR ask for the door
of a block to open or close. A close request is ignored while monsters or the
party are in that block; an open request has no such check.
SCRIPT_TOGGLE_DOOR (ScriptToggleTarget)
has the same restriction as closing: if the block has a door operation
recorded, it requests the opposite direction; otherwise it chooses the
direction from the current wall's properties.3
All three commands go through a shared door routine. It works on two
opposite faces of the block: the north and south faces when the north face is
a door (WALL_RUNTIME_DOOR of WallRuntimeFlags),
the east and west faces otherwise. The north or east face, the leading
face, alone decides where the door stands.
- Already there. If the leading face already carries the endpoint of
the request,
WALL_RUNTIME_DOOR_OPEN_ENDPOINTfor opening orWALL_RUNTIME_DOOR_CLOSED_ENDPOINTfor closing, nothing happens. - Slot. The routine takes the slot already recorded for the block, or else the first of three free slots, and stores the block and the direction. A request for a moving door therefore reverses or confirms it.
- First step. A door at the other endpoint — closed and asked to open, or open and asked to close — moves one reference at once on both faces, with sound 3 when opening and 4 when closing.
- Further steps. The door update of the timed updates moves both faces one reference at a time until the leading face reaches either endpoint, which frees the slot.
Each face moves from its own reference. A door whose faces belong to two groups, such as reference 7 on one side and 12 on the other, keeps each face in its group: closed, it shows 3 and 8. When the three slots are all held by other blocks, the routine instead completes the request at once, with no sound (anomaly). The script does not wait for the door: the next instructions run while it moves, and nothing tells the script whether the request had an effect.
Timing. The door update runs at most once per pass of the game loop, once the shared counter has passed its deadline, and then sets the deadline 5 ticks ahead. Every request that records a slot also moves that deadline to 5 ticks ahead, which delays all doors in motion. Steps are thus at least 6 ticks apart, about a third of a second, and none happens while a script waits. Opening a closed door goes from reference 3 to 4 at once, then to 5, 6 and 7, with sound 3 at each step. Closing an open door goes from 7 to 6 at once, then to 5 and 4 with sound 4, and to 3 with sound 5. All door sounds are played from the party's block, whatever the distance to the door. A step to the endpoint marks the view for redrawing when the door is in view; the first step does not (anomaly).
A close request, and a toggle in either direction, is checked only when it
is made: nothing checks the block again while the door moves. Writing new
references to the faces of a moving door, with
SCRIPT_SET or
SCRIPT_TOGGLE, does not stop it:
the next steps start from the written references.4
ANOMALY-127 — When all three door slots are held by other blocks, a door
request walks the leading face to its endpoint at once and writes that same
reference to the opposite face as well. Everywhere else — the first step,
the timed steps and the completion on a level change — each face moves from
its own reference. A door whose faces belong to different groups therefore
changes group on its second face: closed this way, the door of level 3 at
[27:03] would leave reference 3, a door with a switch, on its south face,
where the usual path leaves 8. 20 door instructions
of the reference scripts act on such doors. That this happens in play is
inferred: it requires three other doors in motion at the time of the
request. A faithful reimplementation copies the leading face in this
case.4
All 153 door instructions of the reference scripts (104 open, 27 close and 22 toggle) name blocks whose two faces are door references on the level's original map. The 20 that act on a door with faces in different groups, 3 and 8 or 7 and 12, are 13 open and 7 close requests; every toggle acts on a door with both faces in one group:5
| Level | Blocks, with the number of instructions when there are several |
|---|---|
| 1 | [13:08] (2), [17:17] (2) |
| 2 | [02:03], [10:07] |
| 3 | [27:03] |
| 8 | [15:14] (3) |
| 11 | [18:06] |
| 12 | [03:29] (4), [03:25] |
| 13 | [21:11], [07:10], [07:08] |
| 16 | [28:08] |
ANOMALY-128 — The first step, made at once when the request finds the
door at its other endpoint, changes both faces without the in-view check
that marks the view for redrawing; the timed steps and the no-slot path make
that check. The intermediate reference is shown only if something else
requests a redraw before the next step. A wall interaction always does, so
a door switch is unaffected. The visible effect is inferred.4
ANOMALY-148 — A free door slot is marked by block number 0, and the slot
scan compares each slot's block with the requested one before it tests for a
free slot. A request on block 0, [00:00], therefore takes the first free slot
as the block's own: it stores the direction and makes the first step, but the
door update and the completion on a level change skip slots whose block is 0.
The door stops at the reference of that first step, and the slot still counts
as free. With all three slots held by other blocks, the request takes the
no-slot path as for any other block. This is latent: [00:00] is a border
block, no original map has a door there and no reference script names it in a
door instruction. A faithful reimplementation keeps 0 as the mark of a free
slot.4
Sources
Locations refer to the game executable reference; comparative sources are listed in the technical references. Statements about the original levels come from decoding the scripts of the 16 reference INF files listed in the file inventory.