Skip to main content

Run a special event

SCRIPT_SPECIAL_EVENT · opcode 0xe2 · 3 bytes

Script virtual machine · Opcode list · Special events

Runs one of seven fixed routines for effects that the other instructions cannot express: a lightning effect, the choice of a party member, a level gain, a resurrection, the recruitment of a character, the removal of two quest items and the reloading of the wall graphics.

Encoding​

Offsets count from the opcode byte. Words are little-endian.

OffsetTypeFieldMeaning
0u8opcode0xe2
1u16leeventA ScriptSpecialEvent value.

Example: e2 03 00 runs the resurrection event.

Behavior​

Values above 6 run nothing. Two events write the run variable read by SCRIPT_EXPR_RUN_VARIABLE; the others leave it unchanged.1

Lightning (event 0)​

SCRIPT_SPECIAL_EVENT_LIGHTNING

The scene is redrawn first. Then a 32 × 120 pixel column of the scene view, starting at x = 72, is saved and, four times, overdrawn with lightning, shown on the screen and removed from the work page, each time waiting for the next tick of the game counter. Each frame stays on the screen until the next replaces it, and the last until the next scene redraw. Finally a scene update is requested. The event changes no game state.

Each lightning frame stacks one 32 × 64 pixel shape six times down the column, every 64 pixels, alternating between a normal and a mirrored copy, from a random start. The shape is cut from DECORATE.CPS, at x 144, y 88, when that picture is loaded. In the reference scripts this event always comes just before Damage characters: it is the visual part of lightning traps.2

Choose a party member (event 1)​

SCRIPT_SPECIAL_EVENT_SELECT_CHARACTER

A menu lists the names of the party members that are present and not dead (CHARACTER_ELIGIBLE_PRESENT and CHARACTER_ELIGIBLE_NOT_DEAD of CharacterEligibilityMask), followed by an ABORT entry. The run variable receives the chosen member's party slot, 0 to 5, or 99 for ABORT.3

Level gain (event 2)​

SCRIPT_SPECIAL_EVENT_LEVEL_GAIN

The event aims to give the character in the party slot given by the run variable, normally set by event 1, one level in each of its classes. For each class in turn, it reads the threshold of the next level, skips the class when there is none, and awards the missing experience plus one through the character's normal experience path. The run variable is not checked: 99 would index outside the party.4

A single-class character gains exactly one level.

Anomaly

The normal experience path divides every award by the number of classes and adds the share to each of them. A multi-class character therefore receives only part of what each class lacks, and usually gains no level. A fighter/mage at 0 and 0 experience receives 2001 points, that is 1000 per class, then 2500 − 1000 + 1 = 1501, that is 750 per class: it ends at 1750 in each class, below both thresholds of 2000 and 2500. A faithful reimplementation keeps the division.

Resurrection (event 3)​

SCRIPT_SPECIAL_EVENT_RESURRECTION

The player chooses from a list of:

  • the party members that are present and whose hit points are −10, the value that marks death;
  • every item of type 33 in the 27 inventory slots of every party member that is present, and the item held in the hand when the mouse-hand mode is active; the item names of the reference ITEM.DAT identify these as sets of bones. An item of value v is listed under the name of character preset v − 1;
  • an ABORT entry.

The run variable is set to 1 before the choice. Choosing ABORT sets it to 0. Choosing a dead member sets that member's hit points to 1. Choosing a set of bones with value v runs the recruitment described under event 4, with type 33 and value v, then adds character preset v − 1 to the party. When recruitment is refused, the run variable stays 1, so a script that counts uses, such as the level 5 altar, counts the attempt. The value is not checked against the six presets; see the anomaly. A set of bones of value 0 is taken for party slot 0: choosing it sets slot 0's hit points to 1.

Anomaly

ANOMALY-134 — The list is built in a fixed space of 20 entries with no limit. With exactly 20 entries before ABORT, the ABORT entry overwrites the first entry's name and the entry count, and the menu shows 23 lines, of which the first and the last two are not entries. With 21 or more, the count takes a value in the thousands, and ABORT and the later entries are written far outside the list (inferred: into game data, and the game crashes). The original data holds at most 12 entries.5

Recruit a character (event 4)​

SCRIPT_SPECIAL_EVENT_RECRUIT_NPC_4

Recruitment with type 33 and value 5, then, if it succeeds, character preset 4 joins the party. Recruitment works as follows: when all six party slots are occupied, the player chooses a member to remove, or CANCEL, which cancels; then every item of the given type and value is deleted from the party's inventories and hand, and the chosen member, if any, is removed. The new member takes the first free slot, copied from the preset table.6

Remove two quest items (event 5)​

SCRIPT_SPECIAL_EVENT_REMOVE_QUEST_ITEMS

Deletes from the inventories of all eligible members, and from the hand, every item of type ITEM_TYPE_QUEST_ITEM with value 5, then every one with value 6. In the reference ITEM.DAT, the only such items are two objects placed on level 15. Level 15 runs this event after checking that the party holds one of them.7

Reload the wall graphics (event 6)​

SCRIPT_SPECIAL_EVENT_RELOAD_WALL_GRAPHICS

Calls the level loader's VCN routine without a file name, so the routine uses the name of the last wall-graphics file loaded, the current level's, and loads that .VCN wall-graphics file again. The reference scripts of levels 9 and 14 run it during dialogues that end with a scene redraw.8

Observed use​

The 36 reachable instructions of the 16 reference INF files use event 0 27 times (26 on level 7, once on level 12), event 6 four times (levels 9 and 14) and events 1 to 5 once each (1 and 2 on level 11, 3 on level 5, 4 on level 7, 5 on level 15). Level 11 runs event 1, tests for 99 and later runs event 2.

Sources​

Footnotes​

  1. Handler for 0xe2. Comparative source: oeob_specialEvent in REF-SCUMM-012 (script/script_eob.cpp, lines 1592–1650). Statistics come from decoding the scripts reachable in the 16 reference INF files. ↩

  2. Overlay routines for the scene redraw, the lightning column and the DECORATE loading; the two drawing routines, the lightning shape and the shared counter. Comparative source: drawLightningColumn (engine/darkmoon.cpp, lines 722–731) and encodeShape(18, 88, 4, 64) (engine/eobcommon.cpp, line 937) in REF-SCUMM-012. ↩

  3. Overlay character pick and the eligibility test. Comparative source: charSelectDialogue in REF-SCUMM-012. ↩

  4. Handler for 0xe2, event 2; the next-level routine, the experience routine, the class level counts and CharacterRuntime. Comparative source: characterLevelGain in REF-SCUMM-012. ↩

  5. Overlay resurrection menu. Comparative source: resurrectionSelectDialogue in REF-SCUMM-012. ↩

  6. Overlay routines for making room and character setup; resident item deletion and character removal. Comparative source: prepareForNewPartyMember and initNpc in REF-SCUMM-012. ↩

  7. Handler for 0xe2, event 5, and the item deletion; the reference ITEM.DAT records 424 and 425 (type 46, values 5 and 6, level 15). ↩

  8. Overlay VCN loading and the stored VCN name. Comparative source: loadVcnData(0, 0) in REF-SCUMM-012. ↩