Move an inventory item to a block
SCRIPT_MOVE_INVENTORY_ITEM_TO_BLOCK · opcode 0xf9 · 5 bytes
Script virtual machine · Opcode list · Scripted inventory transfer
Takes a small item at random from a party member's inventory and puts it in a block of the current level. No reference script uses this instruction.
Encoding
Offsets count from the opcode byte. Words are little-endian.
| Offset | Type | Field | Meaning |
|---|---|---|---|
| 0 | u8 | opcode | 0xf9 |
| 1 | s8 | character | Starting party slot, or SCRIPT_CHARACTER_RANDOM_START (−1) from ScriptCharacterSelector. |
| 2 | u16le | block | Destination block of the current level. |
| 4 | s8 | position | Stored as the item's position_raw: 0–3 a floor quarter, 4–7 a flight position, 8 a wall niche (ItemRuntime). |
Example (constructed, not from a level): f9 ff 4a 02 00 takes an item
from a random character and drops it on block 586, [10:18], in the
north-west quarter.
Behavior
- Choose a character. With −1, the starting slot is a roll of 1d6 − 1
(0–5). From that slot, the handler moves forward, wrapping after slot 5,
until a slot has a nonzero
status_flagsbyte (CharacterRuntime); any bit counts, not onlyCHARACTER_STATUS_PRESENT. - Leave a displayed inventory alone. If the character panel is open and that slot is the selected character, whose inventory is on screen, the instruction ends without a transfer (that the test protects the inventory on screen is inferred).
- Find an item. The search starts at a random inventory slot, rolled from 1 to 27 (see the bug below), and visits 27 slots, wrapping from slot 26 to slot 0. The quiver (slot 16) is always skipped, and the two hands (slots 0 and 1) are skipped while the dungeon view is shown, where the portraits display them (purpose inferred). An item qualifies when its icon has a small item shape (shape number 15 or more).
- Transfer. The first qualifying item is removed from the inventory
and inserted at the head of the destination block's item chain, at
position, on the current level. If none qualifies, nothing happens.1
Nothing else is done: no redraw, no block event, and the character's
defense is not computed again. With position 4 to 7 the item lies in a
flight position although no flight is created for it. The block chain and
the item fields are described in
LevelBlockRuntime and
ItemRuntime.
Edge cases
- If all six
status_flagsbytes are zero, step 1 never ends. - An explicit slot of 6 or more is not checked. The handler uses the memory
past the six character records as if it held a character when its
status_flagsbyte is nonzero; otherwise the next step wraps to slot 0 and the search continues among the six characters. The reference scripts never use this instruction.
ANOMALY-84 (bug) — The starting inventory slot is rolled as 1d27, from 1
to 27, while the search wraps from slot 26 to slot 0. A start of 27 reads
the word after the inventory, the low half of the character's first
timer deadline, as
an item index, and slot 26 is not visited in that search. When that word is
nonzero and the item entry it indexes, unchecked against the 600 entries,
has a small-shape icon, the handler clears the low half of the deadline and
inserts that entry at the head of the block's chain without removing it
from where it was. That timer then ends up to 65,535 ticks early, at the
next check of the character's timers. A faithful reimplementation rolls
1–27 and reads that word. The reference scripts never run this
instruction.1
ANOMALY-85 — Removing the item does not compute the character's
defense again, whereas
every exchange of items by the player does. The search can reach the
bracers and ring slots and, with the character panel open, the hands, all
read by the defense routine; when the item taken counted in the defense,
the character keeps the defense it gave until the next recomputation, as when a monster
takes an item. A
faithful reimplementation leaves the defense unchanged.1