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_MASKfinds 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_maskofItemTypeRuntime.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 index | Class name in the executable | Mask byte | Bits |
|---|---|---|---|
| 0 | FIGHTER | 0x01 | CHARACTER_CLASS_FIGHTER |
| 1 | RANGER | 0x20 | CHARACTER_CLASS_RANGER |
| 2 | PALADIN | 0x10 | CHARACTER_CLASS_PALADIN |
| 3 | MAGE | 0x02 | CHARACTER_CLASS_MAGE |
| 4 | CLERIC | 0x04 | CHARACTER_CLASS_CLERIC |
| 5 | THIEF | 0x08 | CHARACTER_CLASS_THIEF |
| 6 | FIGHTER/CLERIC | 0x05 | fighter, cleric |
| 7 | FIGHTER/THIEF | 0x09 | fighter, thief |
| 8 | FIGHTER/MAGE | 0x03 | fighter, mage |
| 9 | FIGHTER/MAGE/THIEF | 0x0b | fighter, mage, thief |
| 10 | THIEF/MAGE | 0x0a | mage, thief |
| 11 | CLERIC/THIEF | 0x0c | cleric, thief |
| 12 | FIGHTER/CLERIC/MAGE | 0x07 | fighter, mage, cleric |
| 13 | RANGER/CLERIC | 0x05 | fighter, cleric — no ranger bit |
| 14 | CLERIC/MAGE | 0x06 | mage, cleric |
The class index is read as a signed byte.
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.