Skip to main content

Level 4: reference tables

Level 4 · The levels · Level data (INF)

In brief​

The details of level 4: the data of the level, how to read the script details, every scripted place and encounter as the scripts run it, the cell bindings, the level flags and the monster types, with its sublevel records when it has two. Its story page tells the same places and encounters in a few sentences each.

Level data​

The level has one sublevel record. It uses the maze LEVEL4.MAZ and the forest graphics, sets a step threshold of 22 for BLOCK_EVENT_STEP_COUNT, defines one script timer and starts with five monsters. Its only monster graphics resource is wolf; the three monster types that its scripts place are all drawn with it.1

This page covers every reachable script of the reference file: 16 cell bindings, 18 script entry points including two shared subroutines, and 184 instructions. The decoding leaves no unreached script byte and no unknown operand layout. Message colors are palette colors (Print a message).2

Reading this page​

  • Coordinates. A position [XX:YY] gives the column XX and the row YY, counting from 00. The block index used by the files and the instructions is YY × 32 + XX, as in INF and MAZ.
  • Directions. 0 = north (decreasing row), 1 = east, 2 = south and 3 = west; see Direction.
  • Script offsets count from the start of the INF script_data field, which becomes the runtime script buffer; in the reference file it begins at decoded payload offset 681. Cell bindings store these offsets.
  • Messages and texts. Message numbers index the level's 17 strings; text numbers index TEXT.DAT (see SCRIPT_DIALOGUE). They are summarized here, not quoted.
  • Speakers. A message containing a character name is attributed to the character found by the last SCRIPT_EXPR_FIND_CHARACTER_* test, or else to a randomly chosen eligible character.3
  • Level flags are bits of this level's flag word (SCRIPT_FLAG_TARGET_LEVEL); their names below are descriptive.

Wolves​

Where they appear​

Two scripts place monsters with SCRIPT_SPAWN_MONSTER, whose checks can refuse a placement. Because every type of this level has occupancy class 1, a placement succeeds only on a block that holds no monster and is not the party's block. When all 30 monster slots are alive, a placement replaces the living monster farthest from the party.2

  • Every 23rd move ([00:00], offset 288): the step-triggered script runs when the party's move counter exceeds 22. It places a monster of type 0 at position 0 of [10:11], then one of type 1 at position 1 of the same block. The second placement never succeeds: after the first one the block is occupied, and when the first one is refused the second is refused for the same reason. Each event therefore adds at most one monster, of type 0.
  • On the timer ([21:13], offset 319): a monster of type 2 at [21:11], one of type 2 at [21:12] and one of type 1 at [21:13], all at position 4. Each is placed only if its block holds no monster and is not the party's block, so each event adds up to three monsters, and none while all three blocks are occupied.

The five monsters present at the start are all of type 1, at [14:07], [13:08], [13:10], [16:15] and [18:15].1

How often the timer fires​

The level's only timed block script sends BLOCK_EVENT_TIMER to [21:13] with an interval of 180, that is 180 × 18 = 3 240 ticks of the game clock, about 178 seconds: just under three minutes of game time. In detail:4

  • The count starts when level 4 is loaded: at a new game, at each arrival from level 1 or level 5, and when a saved game on this level is loaded. Leaving the level stops it; returning starts a full period again.
  • The event is sent at the first check after the deadline has passed, and the next deadline counts from that moment, so a late check never makes it fire twice. The check runs once per pass of the game loop, never while a script is running, such as during a dialogue.
  • Time does not count during pauses: while the camp menu is open, while a level loads and during a few animations. A rest moves the clock forward by its hours, so the timer is overdue when the camp closes and fires once.
  • No script changes or stops the timer: as long as the party is on level 4, it keeps firing at this period.

The old woman​

Entering [19:10] or [12:11] calls the dialogue at offset 2, but only while level flag 0 is clear; the script sets it first, so the encounter happens once. The dialogue:2

  1. Opens the dialogue screen, fades in the upper-left region of SOUT1 with SCRIPT_DIALOGUE_BITMAP_TRANSITION, plays sound 52 and shows text 14: an old woman appears and offers help. The player chooses between three answers (messages 0–2: inquire, attack, leave).
  2. Leave (answer 3): a party member greets her (message 3); the screen closes after a prompt.
  3. Attack (answer 2): text 21 says that she is easily killed and carried a scroll. SCRIPT_CREATE_ITEM copies the parchment template 28, with value 14, into the current block (SCRIPT_ITEM_DESTINATION_CURRENT_BLOCK). Reading a parchment of value 14 shows TEXT.DAT text 15: an order to send travelers to Darkmoon, paid in silver, with a promise that the bearer's family will be returned. No dialogue of the level shows that text. Without the new value, the copy would keep the template's value −1, which shows a part of the map instead.5
  4. Inquire (answer 1): text 16, where the party asks about a lost friend, and a second question with two answers (messages 5 and 6).
    • Accept her guidance: the screen closes and the party is moved to [15:14], turned to direction 0, then moved northwards through [15:13], [15:12] and [15:11], with a redraw and a delay of 15 after each move. The dialogue screen then reopens, level flag 6 is set, text 17 says that this is the temple and that she leaves, and the party is moved to the entrance at [15:10].
    • Decline: text 19, a farewell, then the screen closes.

Because moving the party dispatches block events, the last move runs the entrance script inside this dialogue, and the walk through [15:11] sets the south-approach flags.

Temple entrance​

[15:11] (south of the entrance) and [16:10] (east of it) record the approach when the party enters them: [15:11] sets level flag 5 and global bit 28; [16:10] clears both.2

The entrance [15:10] reacts to three events:

  • Party enters. The script opens the dialogue screen unless level flag 6 says it is already open, clears flag 6, draws the full-width DARKMOON picture, plays sound 54 and asks with text 18 whether to enter.
    • Yes: message 12 announces the temple, and SCRIPT_LOAD_LEVEL_OR_MONSTERS loads level 5, sublevel 0, position [14:09], direction 3.
    • No: the party is moved back to [15:11] if flag 5 is set (clearing it), or to [16:10] otherwise, and the screen closes.
  • Item placed or flying object. Every item at [15:10] is moved to level 5 [14:09], with SCRIPT_MOVE_ITEMS: items dropped or thrown into the entrance follow into the temple.

The global bit serves the way back. The level 5 front-door scripts at offsets 120 and 168 test it: when it is set, they return the party to level 4 [15:11] facing 2, or send items there; otherwise they use [16:10], facing 1.6

Hidden stairway​

On entering [17:15], a party member remarks that the bushes to the south look strange (message 13, sound 79). The script tests two candidates in turn and gives the remark once (level flag 1): a character whose race_and_sex shifted right once equals 1, then a CHARACTER_CLASS_THIEF (CharacterClassMask). The first test selects an elf: race_and_sex is 2 × race + sex, and race 1 is the elf (CharacterRace).2

[17:16], the bushes south of it, reacts to three events:

  • Party enters. The dialogue screen shows the lower-left region of SOUT1, plays sound 53 and asks with text 13 whether to take the stairway found behind the bushes. Yes loads level 1, sublevel 0, position [29:15], direction 3; no moves the party back to [17:15] and closes the screen.
  • Item placed or flying object. Every item at [17:16] is moved to level 1 [29:15].

Graves​

The graves at [17:04], [19:04], [16:06], [21:06] and [20:07] have wall reference 60 on all four sides. This level maps references 60 and 61 to graves with INF_WALL_SPECIAL_DECORATION_SCRIPT (InfWallSpecialType), so activating a grave dispatches BLOCK_EVENT_WALL_DECORATION to that block's script. All five scripts follow the same pattern:7

  1. If side 2 of the block already holds reference 61, show message 14: a desecrated grave. Nothing else happens.
  2. Otherwise call the digging question at offset 201. It clears level flag 7, plays sound 55 and asks whether to dig (message 8, yes or no). Yes sets flag 7. Then, if the party has a CHARACTER_CLASS_CLERIC or a CHARACTER_CLASS_PALADIN, that character protests (message 11) and the question is asked again; answering no this time clears flag 7.
  3. If flag 7 is set, SCRIPT_SET_BLOCK_WALLS changes all four sides to reference 61 and bones are created in the block; then flag 7 is cleared.
GraveItems created (template, position)
[17:04]femur 33 at 1, skull 32 at 0
[19:04]femur 33 at 0, femur 33 at 0, skull 32 at 1
[16:06]femur 33 at 3, femur 33 at 3, skull 32 at 2
[21:06]femur 33 at 1, femur 33 at 3
[20:07]femur 33 at 2

Two positions near the graves trigger a one-time remark by a member of a given class, with sound 79: [16:05], a CHARACTER_CLASS_CLERIC (message 15, level flag 2), and [20:06], a CHARACTER_CLASS_FIGHTER (message 16, level flag 3).

Sounds​

A sound number selects an entry of the sound-effect table, which comes from the level's sound file: FOREST.ADL with sound driver 1, FOREST.SND with drivers 2 and 3. The entries used by this level's scripts:8

SoundPlayed by this levelFOREST.ADLFOREST.SNDAlso played by the game itself
52The old woman appears10316—
53The stairway behind the bushes11016At the start of the conversation with Calandra
54The temple entrance11316In the dream sequence that can replace a rest on level 3
55The digging question12116At the start of the conversation with Shorn
79The party members' remarks2916With the warnings of spells, and when Aid is cast on a character who already has it

With driver 1, the five numbers select five different programs of the ADL file. Programs 103, 110, 113 and 121 are tunes of six, two, seven and four voices, lasting 27.5, 0.8, 5.0 and 1.7 seconds; program 29 is a single note of 0.9 seconds (measured by running the driver's code, ADL). With drivers 2 and 3, the five numbers all start program 16 of the SND file: ten short notes falling from about 4,187 Hz to 1,329 Hz and back, 0.1 second in all. On the PC speaker it plays once; on the Tandy sound chip it is echoed twice, more quietly, 0.12 and 0.24 second later. The old woman, the stairway, the temple entrance, the digging question and the party's remarks therefore all sound alike with these drivers.9

Bindings​

The bindings give each scripted block its enabled events and script. Blocks whose flags are zero can still receive the events that need no enabling bit: the step event ([00:00]), the timer event (its target) and BLOCK_EVENT_WALL_DECORATION (activated walls).1

PositionEnabled eventsScriptPurpose
[00:00]none (BLOCK_EVENT_STEP_COUNT)288Wolves, every 23rd move
[21:13]none (BLOCK_EVENT_TIMER)319Wolves, on the timer
[19:10]BLOCK_EVENT_PARTY_ENTER508The old woman
[12:11]BLOCK_EVENT_PARTY_ENTER525The old woman
[15:10]BLOCK_EVENT_PARTY_ENTER, BLOCK_EVENT_ITEM_PLACED, BLOCK_EVENT_FLYING_OBJECT379Temple entrance
[16:10]BLOCK_EVENT_PARTY_ENTER372Temple entrance, east approach
[15:11]BLOCK_EVENT_PARTY_ENTER365Temple entrance, south approach
[17:15]BLOCK_EVENT_PARTY_ENTER542Hidden stairway, hint
[17:16]BLOCK_EVENT_PARTY_ENTER, BLOCK_EVENT_ITEM_PLACED, BLOCK_EVENT_FLYING_OBJECT611Hidden stairway
[17:04]none (BLOCK_EVENT_WALL_DECORATION)698Graves
[19:04]none (BLOCK_EVENT_WALL_DECORATION)817Graves
[16:06]none (BLOCK_EVENT_WALL_DECORATION)754Graves
[21:06]none (BLOCK_EVENT_WALL_DECORATION)880Graves
[20:07]none (BLOCK_EVENT_WALL_DECORATION)936Graves
[16:05]BLOCK_EVENT_PARTY_ENTER985Graves, hint
[20:06]BLOCK_EVENT_PARTY_ENTER1015Graves, hint

Two subroutines are reached only by SCRIPT_CALL: the old woman's dialogue at offset 2 and the grave-digging question at offset 201.

Level flags​

BitSet byCleared byMeaning (descriptive)
0[19:10], [12:11]—The old woman has appeared.
1[17:15]—The stairway hint has been given.
2[16:05]—The cleric's graveyard remark has been made.
3[20:06]—The fighter's graveyard remark has been made.
5[15:11][16:10]; refusing to enter after coming from the southThe party last approached the entrance from the south.
6The old woman's guidanceThe entrance scriptThe dialogue screen is already open on arrival.
7A confirmed grave diggingThe grave scripts, after useTemporary answer of the digging question.

Bit 5 is mirrored by the global flag SCRIPT_GLOBAL_FLAG_DARKMOON_SOUTH_APPROACH.

Monster types​

The level defines three monster types, 0 to 2, and one monster image, wolf (WOLF.CPS, with no decoration file). Every monster of the level, placed at the start or by a script, uses that image, and no type selects a decoration, so the three types look the same. The game stores no name for a monster type; the types are known by their number, their image and their properties:10

Property (INF field)Types 0 and 1Type 2
Armour class (armor_class)75
Hit chance (hit_chance)1918
Level for saving throws (level)36
Hit points (hit_points_dice)2d8 + 26d8
Melee attacks: count and damage1, 1d4 + 11, 2d4
MonsterCapabilityFlagsMONSTER_CAP_ALT_FRAME_TABLEMONSTER_CAP_LARGE, MONSTER_CAP_ALT_FRAME_TABLE
MonsterImmunityFlagsnonenone
Type flags (type_flags)Hold Monster can affect itHold Monster can affect it
Experience (experience)65975
Occupancy class (occupancy_class)11
Attack and step sounds (sound_1, sound_2)37, 3637, 36
Ranged attacksnonenone
Turn resistance, evasion (turn_resistance, damage_modifier)−1, 0−1, 0

Types 0 and 1 are identical in every field. Type 2 has three times as many hit dice and fifteen times the experience of the others, and MONSTER_CAP_LARGE makes weapons roll their second damage profile against it.

Sources​

Locations refer to the game executable reference; the reference files are identified in the file inventory.

Footnotes​

  1. The reference LEVEL4.INF and LEVEL4.MAZ, read with INF.ksy and MAZ.ksy: sublevel names, steps_until_script 22, script timer target [21:13] with interval 180, monster graphics slot wolf, monster types 0–2, the initial monster records and the cell bindings. The event meanings follow BlockEventMask and LevelBlockStateFlags. ↩ ↩2 ↩3

  2. Reachability decoding of the reference LEVEL4.INF with script_decoder.py, using the instruction layouts of the virtual machine reference. Offsets are those of the decoded instructions. Item names come from the name slots of the reference ITEM.DAT templates 28, 32 and 33. ↩ ↩2 ↩3 ↩4 ↩5

  3. The message handler uses the character recorded by the last character-finding token, or picks a random starting slot and takes the first eligible character. ↩

  4. The script timer loader, the script timers routine and the script timers; the tick rate, the pauses and the rest are described on the game clock, the reload at each level change on level records and level changes. The placement checks are those of the monster spawn routine. ↩

  5. The reference ITEM.DAT record 28 (type 36, value −1), the decoded SCRIPT_CREATE_ITEM at offset 84 and the parchment reader; text 15 of the reference TEXT.DAT, summarized. ↩

  6. The decoded scripts of the reference LEVEL5.INF at offsets 120–140 and 168–199. That level's other scripts are not described here. ↩

  7. The reference LEVEL4.MAZ (wall references of the five blocks) and in the wall mappings of LEVEL4.INF (references 60 and 61 with special type INF_WALL_SPECIAL_DECORATION_SCRIPT), with the decoded scripts at offsets 201 and 698–984. ↩

  8. The first 120 bytes of the reference FOREST.ADL and FOREST.SND, loaded by load the sound file into the sound-effect table; the uses by the game are the direct calls listed under the sound effect player. ↩

  9. Program 16 of the reference FOREST.SND, decoded with the SND schema and timed by the speaker and Tandy sound run. ↩

  10. The monster graphics slots and monster type entries of the reference LEVEL4.INF (INF.ksy), copied into the monster type properties by the type loader. Field meanings and their readers are given in the schema. ↩