Skip to main content

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.

The order of a pile after the party leaves a level and comes back. Items dropped in the order entry 312, entry 45, entry 207 lie with 207, the last dropped, on top. The level's piles are rebuilt in the order of the item table, so on return entry 312, the highest entry number, is on top, then 207, then 45.
On a level loaded again, the highest entry number lies on top of each pile.

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−1not meaningful—
On the floor or in a nichethe blockthe level0–3 floor, 8 niche
In flightthe block it is crossingthe current level4–7
Carried in an inventory slot or on the pointer00not meaningful
In a quiver−22550
A free conjured-weapon entry−2255, or 0 as read from the file—
A template of the original data000

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.

Anomaly

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:

A mage can also learn spells from scrolls; see learning from scrolls.

Anomaly

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.

Footnotes​

  1. Duplicate an item, remove the selected inventory item, lose an item to a monster and the chain routines. ↩

  2. Rebuild the block item chains and save a game. ↩

  3. Delete inventory items by type and value. ↩