Scripted movement, monsters and items
Scripts · SCRIPT_MOVE_PARTY_OR_OBJECT · Where an item is
In brief
Scripts move the party, the monsters of a block or its items, turn the party or flying objects, and change level. They place monsters from the same fields as the level's initial monsters, provoke them, and create, remove, identify or drop items.
Moving the party, monsters and items
SCRIPT_MOVE_PARTY_OR_OBJECT
moves one of three things, selected by a
ScriptMoveTarget:1
- The party is set down in the destination block through the ordinary
party move, which raises the leave and enter events. If the destination's
first wall reference is
WALL_REFERENCE_CLEARED_ON_ENTRY(SpecialWallReference), its four wall references are cleared. - Every monster of a block is placed in the destination with the usual monster movement events. The game also overwrites each monster's direction with its position within the block, an anomaly.
- The items of a block, all of them or only those of one
ItemType, go to a block of the same or another level. On the current level they are relinked into the destination's item chain, and objects flying in the source block follow them, or stop if the destination is on another level. Items moved from another level ignore the type filter, and when the destination is the current level they appear only once the level is loaded again (details). This is how the original levels make items dropped or thrown into stairs and teleporters arrive at the destination.
Turning. SCRIPT_CHANGE_DIRECTION
adds a signed amount to a direction, wrapping to 0–3. With
SCRIPT_DIRECTION_PARTY (ScriptDirectionTarget)
it turns the party; with SCRIPT_DIRECTION_MOVERS it turns the objects moving
in the block that started the script.2
Changing level.
SCRIPT_LOAD_LEVEL_OR_MONSTERS
saves the state of the current level, loads the destination level, places the
party and stops the current run. Stairs and level exits use it. Its other form,
which no original script uses, replaces the images of one of the level's two
monster graphics banks.3
Monsters
Placing a monster. SCRIPT_SPAWN_MONSTER
creates a
monster from the same fields as an initial monster record of the
INF file. Nothing happens if the block is full, if the
party is in it, or if the new monster or one already there occupies the block
alone. Otherwise the game takes a free slot — one whose monster has no hit points
left — or, if all 30 monsters are alive, reuses the slot of the living monster
farthest from the party, except monsters carrying a particular flag. The new
monster rolls its hit points from its type's dice, and entering the block raises
the monster-enter event.4
Provoking a monster. SCRIPT_SET_FLAGS with
SCRIPT_FLAG_TARGET_MONSTER (ScriptFlagTarget)
sets a bit in one monster's runtime flags and switches it to
MONSTER_MODE_PURSUE (MonsterMode), without
changing its stored destination. The original scripts always set
MONSTER_RUNTIME_PROVOKED,
the flag that damage also sets, so the monster turns on the party: this is how
the clerics of level 5 attack. See
modes and provocation.5
Items
Creating an item. SCRIPT_CREATE_ITEM
copies a template item, optionally overrides some of its bytes (
ScriptItemOverrideFlags) and places
the copy. With SCRIPT_ITEM_DESTINATION_HELD_OR_CURRENT
(ScriptItemDestination) it goes into the
hand when the hand is free, otherwise into the current block; with
SCRIPT_ITEM_DESTINATION_CURRENT_BLOCK into the current block; any other value
names the block, at a position given as a floor quarter or a wall niche.
When the item table is full, nothing is created; valid template numbers are
not established.6
Removing items. SCRIPT_DELETE_ITEM
removes items according to a selector (
ScriptDeleteTarget):7
| Selector | Removes |
|---|---|
SCRIPT_DELETE_HELD_ITEM | The item currently held or selected. |
SCRIPT_DELETE_ALL_IN_BLOCK | Every item of a block. |
| Any other value | The items of a block whose type equals the selector. |
Removed items are unlinked from their ItemRuntime
chain and their entries freed. Removing the items of one type rebuilds the
block's chain, and the remaining items end in reverse order; see
items on the floor.
Identifying items. SCRIPT_IDENTIFY_ITEMS
sets ITEM_RUNTIME_IDENTIFIED (ItemRuntimeFlags)
on every item of a block. If that block is the party's, it also identifies the
items carried by every character present, dead or alive, quiver included. It
redraws nothing. No original script uses it.8
Dropping an item from an inventory.
SCRIPT_MOVE_INVENTORY_ITEM_TO_BLOCK
takes, from a random starting slot of a character's inventory (see
ScriptCharacterSelector), the first
item with a small shape, never the quiver nor anything shown on screen, and
puts it into a block. It neither redraws nor computes the defense again, and
its random start can read one word past the inventory. No original script
uses it.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.