Item type entry
ItemTypeRuntime · 16-byte runtime structure
The engine in ten minutes · Items · Combat · ITEMTYPE.DAT format
In brief
All items of one kind share an item type: where it can be worn, which classes
can use it, its damage dice and other properties. The game copies each
16-byte entry of ITEMTYPE.DAT into a table in
memory, and an item's ItemRuntime type selects its
entry.1
Layout
/* Shared properties of one item type (16 bytes, little-endian). */
typedef struct ItemTypeRuntime {
uint16_t inventory_slot_mask; /* 0x00: InventorySlotMask of the slots that accept the item. */
uint16_t usage_mask_raw; /* 0x02: never read; 0 for conjured types. */
int8_t defense_adjustment_raw; /* 0x04: added to defense for a worn item; -30 marks a free conjured type. */
uint8_t character_class_mask; /* 0x05: CharacterClassMask of classes allowed to use it. */
uint8_t hand_requirement_raw; /* 0x06: 0 any hand, 1 first hand only, 2 both hands. */
int8_t dice_count_a; /* 0x07: dice count, first damage profile. */
int8_t die_sides_a; /* 0x08: die sides, first damage profile. */
int8_t damage_bonus_a; /* 0x09: bonus, used by both profiles (see below). */
int8_t dice_count_b; /* 0x0a: dice count, second damage profile. */
int8_t die_sides_b; /* 0x0b: die sides, second damage profile. */
int8_t damage_bonus_b_raw; /* 0x0c: bonus of the second profile (inferred); never read. */
uint8_t unknown_0d; /* 0x0d: never read; 0 in the original data. */
uint16_t properties_raw; /* 0x0e: low 7 bits = ItemKind; bit 0x80: can be lost to a monster's attack; upper bits never tested. */
} ItemTypeRuntime;
There is no padding. The dice bytes are sign-extended by the dice routine,
and defense_adjustment_raw is compared with −30; the signedness of the
other fields is unknown.
How the game uses it
| Check | What the game compares |
|---|---|
| Inventory placement | inventory_slot_mask against the mask of the destination slot; see inventory slots.2 |
| Class restriction | character_class_mask ANDed with the character's CharacterClassMask.2 |
| Weapon resistance | CHARACTER_CLASS_CLERIC in character_class_mask spares a weapon from MONSTER_IMMUNE_WEAPON_HALVED, but the damage calculation reads the entry numbered like the item rather than its type; see monster immunities. |
| Item kind | The low seven bits of properties_raw, an ItemKind: what using the item does; see using items. |
| Hands | hand_requirement_raw: an item needing both hands in the first hand makes the second unusable, and a weapon needing the first hand cannot be used from the second; see two hands.3 |
| Defense | For an item of kind 0 worn as body armour or bracers, or a shield in a hand, defense_adjustment_raw minus the item's value is added to defense; see what worn items change.2 |
| Item names | The kind selects how an identified item's name is built; see item names.2 |
| Item loss | Bit 0x80 of properties_raw marks the items that a monster with MONSTER_CAP_ITEM_LOSS can remove from an inventory; see melee attacks and the types marked.4 |
These checks are parts of larger routines: a matching mask alone is not the complete rule for using or wearing an item.
Damage profiles
Nothing in the game reads damage_bonus_b_raw.
The damage routine chooses dice B against a monster type with
MONSTER_CAP_LARGE and dice A
otherwise, but passes damage_bonus_a as the bonus in both cases.
damage_bonus_b_raw is inferred to be the bonus of dice B. Four entries of the
reference ITEMTYPE.DAT have different values in the two bonus positions, so a
reimplementation of this routine must use bonus A for both profiles to match
the original.5
Changes during play
The table is writable, so the values in memory need not match the file.
Types 51 to 56 form a pool for conjured weapons: one routine takes the first
of them whose defense_adjustment_raw is −30 and fills it, and the routine
that frees an item created for a conjured weapon writes −30 back into its
type. These six types are saved with the game, which keeps a conjured weapon
usable after loading; see
what a saved game holds.
Only Shocking Grasp, Vampiric Touch and Flame Blade reserve them; each
writes an inventory_slot_mask, usage_mask_raw and defense_adjustment_raw
of 0, character_class_mask 0x0f, its dice in both profiles and kind 1.
Apart from loading ITEMTYPE.DAT, loading a saved game and these two
routines, nothing writes the table.6
Sources
Locations refer to the game executable reference; comparative sources are listed in the technical references.