Scripted characters, flags and messages
Scripts · SCRIPT_DIALOGUE · ScriptFlagTarget
In brief
Scripts damage, heal and reward characters, set and clear the flags that remember what has happened, allow or forbid resting, print messages, drive dialogue screens whose answers the next conditions test, play sounds, wait, launch objects and run special events and sequences.
Characters
Healing or hurting directly.
SCRIPT_MODIFY_CHARACTER_HP
adds a signed amount to the current hit points of one character or of all six
that are present and not dead, without exceeding their maximum, and redraws
their hit points and portraits. A negative amount has no lower limit and
never kills. No original script uses it.1
Damaging characters.
SCRIPT_DAMAGE_CHARACTERS
affects one character or all six. For each, the game rolls the damage dice, may
grant a saving throw that halves or cancels the damage (
ScriptSavingThrowType,
ScriptSavingThrowEffect), applies the
ScriptDamageFlags, and subtracts the result
from an eligible character's hit points (
CharacterEligibilityMask). A
character at −10 hit points or below dies. In the original scripts the flags
either let a ring of Feather Fall cancel falling damage or change
nothing.2
Awarding experience.
SCRIPT_AWARD_EXPERIENCE
with SCRIPT_EXPERIENCE_PARTY (ScriptExperienceTarget)
divides an amount equally, rounding toward zero, between the characters that
are present and not dead; if none is, nobody receives anything. Each share
then follows the ordinary experience rules.
A negative amount removes experience, and one that takes it below zero makes
the class gain levels. No original script uses it.3
Flags and resting
SCRIPT_SET_FLAGS and
SCRIPT_CLEAR_FLAGS are how
scripts remember what has happened. Their target is a
ScriptFlagTarget:4
| Target | Set | Clear |
|---|---|---|
SCRIPT_FLAG_TARGET_LEVEL | One bit of the current level's 32 flags | Clears that bit |
SCRIPT_FLAG_TARGET_GLOBAL | One bit of the 32 global flags | Clears that bit |
SCRIPT_FLAG_TARGET_RUN_VARIABLE | Run variable = 1 | Run variable = 0 |
SCRIPT_FLAG_TARGET_REST_ALLOWED | The party may rest | The rest command refuses |
SCRIPT_FLAG_TARGET_MONSTER | Provokes a monster | No effect; the instruction takes 3 bytes |
Level flags typically record that a message has been shown or a puzzle solved; global flags carry such facts from one level to another. The rest setting survives level changes and is saved with the game; levels 2, 7 and 16 use it — on level 7, for example, resting is forbidden before a lightning trap. The other conditions of a rest are described under resting.
Messages, dialogue, sound and timing
Messages. SCRIPT_PRINT_MESSAGE
prints one of the level's strings in a chosen color. When
the text names a character, it is the character selected by the last condition
or, failing that, the first eligible character from a random starting slot.
SCRIPT_DRAW_SCENE redraws the
view, which scripts do after changing walls or moving the party.5
Dialogue screens. SCRIPT_DIALOGUE
drives the illustrated dialogue screen through a sequence of
ScriptDialogueCommand values: open the
screen and load the dialogue texts of TEXT.DAT, draw a region of a named
picture (ScriptDialogueBitmapFrame),
show a text with an optional prompt, ask a question, and restore the normal
view. A question offers two or three answers labelled with strings of the
level; the answer chosen, numbered from 1, becomes the run variable that the
next conditions test. Texts are word-wrapped in a ten-line window below the
picture and shown a page at a time; the player answers a prompt with Space,
Enter, M or a click on its button, and picks an answer with the mouse, or
with the Left and Right arrows and Enter. The game loop does not run
meanwhile, so monsters and timed events wait for the player
(text window and pages,
answer buttons).6
Sound and delays. SCRIPT_PLAY_SOUND
plays a sound effect at once, or as an environmental sound coming from a
block: louder the nearer the block, dropped beyond a distance of 15, and
played at the end of the game loop's pass unless another environmental sound
comes first. Sound numbers above 127 are read as negative and play nothing.
SCRIPT_DELAY waits until
the game's free-running counter has advanced by the given number of ticks,
about 55 ms each; the game loop does not run meanwhile.7
Special events and sequences
Launching objects. SCRIPT_LAUNCH_OBJECT
sends a magic flying object (SCRIPT_LAUNCH_MAGIC, ScriptLaunchKind)
or a copy of an item flying from a block in a direction, as a
monster spell or a thrown item launched by no
character. The original scripts launch fireballs as traps, and twice a
dart.8
Special events. SCRIPT_SPECIAL_EVENT
runs one of seven fixed routines (ScriptSpecialEvent):
a lightning effect drawn before lightning damage, choosing a party member,
a level gain for that member, the resurrection of a dead member or of a
character whose bones the party carries, the recruitment of a particular
character, the removal of two quest items, and the reloading of the level's
wall graphics. Choosing a member and resurrection report their result in the
run variable.8
Sequences. SCRIPT_RUN_SEQUENCE
starts a larger scripted sequence selected by a
ScriptSequenceSelector: conversations
with non-player characters, which may end with one joining the party, a portal
animation and a copy-protection check. Some conversation choices change global
flags or the party's direction. The portal animation releases the level's
door, monster and decoration shapes and does not change level itself: the
script that follows does. The script resumes only if the sequence
returns.9
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.