Skip to main content

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.

OffsetTypeFieldMeaning
0u8opcode0xec
1u8target0xe5, SCRIPT_LOAD_LEVEL.
2s8levelLevel to load.
3s8sublevelSublevel to load.
4u16leblockArrival block, stored as the party's block.
6s8directionNew 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​

  1. The inventory panel and the spell book are closed.
  2. The party's block and, unless direction is SCRIPT_LEVEL_KEEP_DIRECTION, its facing are set.
  3. The current level is settled — flying objects land, doors finish — and its state is saved, then the level loader loads level and sublevel. 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). sublevel selects a record of the level's INF file and is not range-checked; see sublevels.
  4. 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

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.

OffsetTypeFieldMeaning
0u8opcode0xec
1u8targetAny value other than SCRIPT_LOAD_LEVEL; it only selects this form and is not used further.
2s8loader_indexMonster image loader, 0 to 2: which of three shape layouts cuts the image.
3s8slot_groupGraphics bank to replace, 0 or 1, the bank a monster's graphics_index selects.
413 bytesresource_name_rawName 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

  1. The 18 monster shapes of bank slot_group, from entry slot_group × 18, and their decorations are released.
  2. The loader chosen by loader_index — the same three loaders as the INF monster graphics records — loads the image resource_name_raw, cuts six body shapes into entries slot_group × 18 to slot_group × 18 + 5 with 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.

Sources​

Footnotes​

  1. Handler for 0xec, which calls the overlay routines settle the level, save the level state and load the INF file; the party block, the party direction, the stop flag and the level-loading flag. Comparative source: EoBInfProcessor::oeob_loadNewLevelOrMonsters in REF-SCUMM-003. Statistics come from decoding the scripts reachable in the 16 reference INF files. ↩ ↩2

  2. Handler for 0xec, second branch, the loader table, the release of monster shapes, the monster image loaders and the monster shapes. Comparative source: EoBInfProcessor::oeob_loadNewLevelOrMonsters in REF-SCUMM-003. ↩