Where an item is
Items · On the floor and in the air · Saving and restoring
In brief
An item entry does not say who carries it: its block and level fields tell only whether it is free, on a floor, in flight, carried or in a quiver. New items are copies of the first hundred entries, which are templates; items leave the game when their entry is freed. The whole table is saved, but the piles of a level are rebuilt from it at each visit, in entry order.
Locations and levels
An item entry does not say who carries it. Its block and level fields only tell whether it lies in the world:1
| The item is… | Block field (location_raw) | Level field (level_raw) | Position |
|---|---|---|---|
| Unused, free for a new item | −1 | not meaningful | — |
| On the floor or in a niche | the block | the level | 0–3 floor, 8 niche |
| In flight | the block it is crossing | the current level | 4–7 |
| Carried in an inventory slot or on the pointer | 0 | 0 | not meaningful |
| In a quiver | −2 | 255 | 0 |
| A free conjured-weapon entry | −2 | 255, or 0 as read from the file | — |
| A template of the original data | 0 | 0 | 0 |
A carried item is found only through the inventory slot, the quiver or the pointer that refers to it. The game copies any entry that is not free; in the original data every copy is taken from the first hundred entries, which never lie in the world; see templates and records.
New items are copies of a template entry: the game takes the first unused entry from 1 upwards and copies the template into it; nothing is created when the 600 entries are all in use. Monsters' thrown weapons and drops, the items of a new party and of recruited companions, and the items that scripts create or launch are made this way. Items leave the game when their entry is freed: food that is eaten, potions, scrolls and spent wands, a scroll copied into the spellbook, and items removed by scripts or taken by a companion who leaves.
An item taken by a monster is only removed from the character's slot, whereas every other way of discarding a carried item frees its entry. The entry keeps the "carried" values: it is never shown again, never reused for a new item, and stays counted among the 600 entries for the rest of the game. A faithful reimplementation removes the item from play without returning its entry to the free pool.
Items across level changes and saves
This section summarizes saving and restoring.
All 600 entries belong to the whole game and are saved together. The piles of a level's blocks are not saved: every time a level is loaded, the game empties them and puts back each item whose level is that level and whose block is positive. Carried and quiver items are never put on a floor this way, and an item carried on the pointer stays there through a level change.2
Before a save, a load or a level change, every flight ends at once: a thrown item falls where it is and its block's script can run. Items lying on other levels stay as they were, unless a level script moves them from there.
Because the piles are rebuilt in the order of the table, the order a player built by dropping items is not kept when the party leaves and comes back: at each position, the item with the highest entry number comes out on top.
What scripts can do with items
Level scripts use the item table directly:
- identify items lying in a block — and, if the party stands there, those carried by active characters;
- remove items held or lying in a block, including all items of a given type;
- create and place an item from a template, optionally changing some of its fields;
- move an item between blocks or levels with
SCRIPT_MOVE_PARTY_OR_OBJECT; - launch a copy of an item from a block with
SCRIPT_LAUNCH_OBJECT.
A mage can also learn spells from scrolls; see learning from scrolls.
ANOMALY-129 — When a script removes the items of a given type and value
from the inventories, the game redraws the hand of each character who lost
an item from a hand, except the sixth character, although it removes that
character's items too. The removed item's picture stays in the sixth
character's hand until its portrait is next redrawn (inferred). A faithful
reimplementation redraws the hands of characters 0 to 4 only.3
Sources
Locations refer to the game executable reference.