Change level or load monster resources
SCRIPT_LOAD_LEVEL_OR_MONSTERS · opcode 0xec · 7 or 17 bytes
Script virtual machine · Opcode list · Scripted level and resource loading
Sends the party to another level or, in a second form, loads monster
resources. The byte after the opcode, a
ScriptLoadTarget, selects the form.
Level transition
Encoding
Offsets count from the opcode byte. Words are little-endian.
| Offset | Type | Field | Meaning |
|---|---|---|---|
| 0 | u8 | opcode | 0xec |
| 1 | u8 | target | 0xe5, SCRIPT_LOAD_LEVEL. |
| 2 | s8 | level | Level to load. |
| 3 | s8 | sublevel | Sublevel to load. |
| 4 | u16le | block | Arrival block, stored as the party's block. |
| 6 | s8 | direction | New facing, or SCRIPT_LEVEL_KEEP_DIRECTION (0xff) from ScriptLevelDirection. |
Example (constructed, not from a level): ec e5 05 00 ab 00 ff loads level 5,
sublevel 0, with the party at block 171, keeping its facing. Block 171 is
position [11:05], with block = YY × 32 + XX.
Behavior
- The inventory panel and the spell book are closed.
- The party's block and, unless
directionisSCRIPT_LEVEL_KEEP_DIRECTION, its facing are set. - The current level is settled — flying objects land, doors finish — and
its state is saved, then the level loader loads
levelandsublevel. The thrown items of the old level land, and their blocks receive their item-placed event, after the party's block has been set to the arrival block (anomaly).sublevelselects a record of the level's INF file and is not range-checked; see sublevels. - The party is placed on the arrival block. Since the party's block already holds the arrival block, that block receives the party-leave event and then the party-enter event; no arrival block of the original levels accepts the leave event. The portraits are redrawn, the run's stop flag and the level-loading flag are set, a scene update is requested and the return-stack depth is cleared.1
The handler reports a length of zero, but the interpreter loop stops because of the stop flag: the instruction still occupies seven bytes, and the bytes after it are not executed. In the reference files, 112 instructions of this kind are directly followed by bytes that are never reached.
ANOMALY-155 — The handler stores the arrival block before it settles the old
level. The scripts of the old level that a landing item starts therefore read
a party block that belongs to another map, while the save routines, the other
callers of the settling, leave the party's block as it is. Such a script can
also change level itself, since nothing guards against it. The landing item's
flight record is cleared only after its event returns, so the inner level
change settles the same item and sends the same event again: unless the
script has changed its own condition, this repeats until the stack runs out
(inferred). Otherwise the inner level is loaded and its arrival script runs;
the outer handler then writes that level's record and loads its own target.
This is latent: no item-placed path of the 223 bindings that accept the event
reaches a level change, and the plate scripts that read the party's block on
this path compare it with no arrival block of their level. A faithful
reimplementation sets the party's block first and clears the flight record
after the event.1
Monster-resource loading
Encoding
Any target other than SCRIPT_LOAD_LEVEL selects this form; this routing
does not establish which values are valid.
| Offset | Type | Field | Meaning |
|---|---|---|---|
| 0 | u8 | opcode | 0xec |
| 1 | u8 | target | Any value other than SCRIPT_LOAD_LEVEL; it only selects this form and is not used further. |
| 2 | s8 | loader_index | Monster image loader, 0 to 2: which of three shape layouts cuts the image. |
| 3 | s8 | slot_group | Graphics bank to replace, 0 or 1, the bank a monster's graphics_index selects. |
| 4 | 13 bytes | resource_name_raw | Name of the monster image and of its decoration file. Preserve all 13 bytes. |
Behavior
This form replaces the images of one of the two monster graphics banks of the level, as the level's own monster graphics records do when it is loaded:2
- The 18 monster shapes of bank
slot_group, from entryslot_group × 18, and their decorations are released. - The loader chosen by
loader_index— the same three loaders as the INF monster graphics records — loads the imageresource_name_raw, cuts six body shapes into entriesslot_group × 18toslot_group × 18 + 5with its own layout, builds their colour variants and, since the handler always asks for them, reads the decoration file of the same name. See monster images.
Monsters whose graphics_index selects that bank are drawn with the new
shapes from then on. The inventory panel and the spell book are closed
first, and the play screen is then rebuilt: wall graphics, view and
portraits. The script continues after the 17 bytes. No reference script uses this form.
Edge cases and unknowns
- Valid levels, sublevels and arrival blocks, and the behavior when loading fails, are not established.
- In the second form, the name is read up to its first zero byte, which may lie beyond the 13 bytes; the instruction always takes 17. A missing decoration file is skipped.
Observed use
The reference scripts contain 143 instructions of this kind, all with
SCRIPT_LOAD_LEVEL: stairs, pits, portals, teleporters, a switch in place
and a few scenes, 11 of them selecting a second sublevel. They are the only
way the party changes level during play; see
level changes in the original levels.
They name 91 distinct pairs of level and arrival block. Ten of these blocks
have a script: eight accept LEVEL_BLOCK_PARTY_ENTER_EVENT only, the one at
[23:03] on level 2 accepts LEVEL_BLOCK_ITEM_USED_EVENT only, and the one at
[16:05] on level 1 has no event flag
(LevelBlockStateFlags). None has
LEVEL_BLOCK_PARTY_LEAVE_EVENT, so the leave event sent on arrival never runs
a script.