Skip to main content

Character class masks

CharacterClassMask · 1 byte per class, from a 15-entry table indexed by class_index of CharacterRuntime

The party · Condition expression tokens · ItemTypeRuntime

A character's class can be single or combined, such as fighter/mage. To ask "is this character a cleric?", the game turns the class into a byte with one bit per base class. Scripts use it to find a character of a given class, and the item code uses it to check who may use an item.1

typedef enum CharacterClassMask {
CHARACTER_CLASS_FIGHTER = 0x01,
CHARACTER_CLASS_MAGE = 0x02,
CHARACTER_CLASS_CLERIC = 0x04,
CHARACTER_CLASS_THIEF = 0x08,
CHARACTER_CLASS_PALADIN = 0x10,
CHARACTER_CLASS_RANGER = 0x20
} CharacterClassMask;

Where it is used​

  • SCRIPT_EXPR_FIND_CHARACTER_BY_CLASS_MASK finds a character whose byte shares a bit with its operand; see condition expression tokens.1
  • The item class check ANDs the byte with the character_class_mask of ItemTypeRuntime.1

The class table​

The bit order follows the list of the six base-class names in the executable, and the table follows its list of 15 class names:2

Class indexClass name in the executableMask byteBits
0FIGHTER0x01CHARACTER_CLASS_FIGHTER
1RANGER0x20CHARACTER_CLASS_RANGER
2PALADIN0x10CHARACTER_CLASS_PALADIN
3MAGE0x02CHARACTER_CLASS_MAGE
4CLERIC0x04CHARACTER_CLASS_CLERIC
5THIEF0x08CHARACTER_CLASS_THIEF
6FIGHTER/CLERIC0x05fighter, cleric
7FIGHTER/THIEF0x09fighter, thief
8FIGHTER/MAGE0x03fighter, mage
9FIGHTER/MAGE/THIEF0x0bfighter, mage, thief
10THIEF/MAGE0x0amage, thief
11CLERIC/THIEF0x0ccleric, thief
12FIGHTER/CLERIC/MAGE0x07fighter, mage, cleric
13RANGER/CLERIC0x05fighter, cleric — no ranger bit
14CLERIC/MAGE0x06mage, cleric

The class index is read as a signed byte.

Anomaly

Every combined class is the union of its components' bits, except RANGER/CLERIC: it has the same byte as FIGHTER/CLERIC, so a test for CHARACTER_CLASS_RANGER does not find a ranger/cleric. Whether this is intended is unknown.

Sources​

Locations refer to the game executable reference.

Footnotes​

  1. Class mask table, read by the expression evaluator and the item class check. ↩ ↩2 ↩3

  2. Class names and base-class names. ↩