Character eligibility tests
CharacterEligibilityMask · 16-bit argument of the character eligibility routine
The party · CharacterRuntime ·
The engine in ten minutes
Many effects apply only to some party members: the living ones, the conscious ones, those present. The game asks one routine whether a party slot passes a set of tests, and these bits choose the tests. The routine returns a nonzero value when the character passes every selected test.1
typedef enum CharacterEligibilityMask {
CHARACTER_ELIGIBLE_PRESENT = 0x01, /* CHARACTER_STATUS_PRESENT is set. */
CHARACTER_ELIGIBLE_NOT_DEAD = 0x02, /* hit_points is above -10 and CHARACTER_STATUS_PETRIFIED is clear. */
CHARACTER_ELIGIBLE_CONSCIOUS = 0x04, /* hit_points is above 0 and CHARACTER_STATUS_PETRIFIED is clear. */
CHARACTER_ELIGIBLE_NOT_PARALYZED_OR_PETRIFIED = 0x08, /* CHARACTER_STATUS_PARALYZED and CHARACTER_STATUS_PETRIFIED are both clear. */
CHARACTER_ELIGIBLE_NOT_POISONED = 0x10, /* CHARACTER_STATUS_POISONED is clear. */
CHARACTER_ELIGIBLE_NOT_PARALYZED = 0x20, /* CHARACTER_STATUS_PARALYZED is clear. */
CHARACTER_ELIGIBLE_HAS_FOOD = 0x40 /* food is greater than zero (unsigned). */
} CharacterEligibilityMask;
The comments describe what the routine tests, not necessarily why. The names
NOT_DEAD and CONSCIOUS are inferred from the hit-point thresholds. The
status bits are those of CharacterStatusFlags
and the fields those of CharacterRuntime;
hit_points is read as signed. food is also the byte that the death path
sets to zero.2
How the routine behaves
- A mask bit that is not set adds no test, so a mask of 0 accepts every slot.
- Higher mask bits are not tested.
- The routine does not check that the slot is in range: a slot of -1 would read the memory before the first character.
Masks used by scripts
| Mask | Value | Used by |
|---|---|---|
CHARACTER_ELIGIBLE_PRESENT | 0x01 | Counting the party members who hold an item, in conditions. |
PRESENT and NOT_DEAD | 0x03 | Hit-point changes, damage, experience awards, choosing the character named in a message. |
PRESENT and CONSCIOUS | 0x05 | Finding a character in conditions. |
PRESENT, NOT_DEAD, CONSCIOUS and NOT_PARALYZED_OR_PETRIFIED | 0x0f | Counting the active characters in conditions. |
These are the masks passed by the routines in the sources below; other callers can pass other masks.3
Masks used by character actions
| Mask | Value | Used by |
|---|---|---|
CHARACTER_ELIGIBLE_PRESENT | 0x01 | Swapping two characters; a single-target projectile reaching a slot. |
PRESENT and NOT_DEAD | 0x03 | Choosing the character a monster attacks in melee. |
PRESENT and CONSCIOUS | 0x05 | Eating the item in hand. |
PRESENT, CONSCIOUS and NOT_PARALYZED_OR_PETRIFIED | 0x0d | Using a hand item (attacks, casting); the party check that starts the defeat sequence when nobody passes. |
What each condition then allows is summarized under conditions.4
Masks used by resting
| Mask | Value | Used by |
|---|---|---|
CHARACTER_ELIGIBLE_PRESENT | 0x01 | Counting the characters present for Insal; the first test of the poison checks. |
CHARACTER_ELIGIBLE_NOT_DEAD | 0x02 | After PRESENT: finding Insal. |
CHARACTER_ELIGIBLE_NOT_POISONED | 0x10 | Failed after PRESENT: the poison question and the hourly poison damage. |
PRESENT and NOT_DEAD | 0x03 | Choosing the most injured character; the eight-hour wounds and hunger. |
PRESENT and CONSCIOUS | 0x05 | Recovering a spell. |
PRESENT, CONSCIOUS and NOT_PARALYZED_OR_PETRIFIED | 0x0d | The healer that lets the game offer healing; the end of the rest when nobody passes. |
PRESENT, NOT_DEAD and HAS_FOOD | 0x43 | Deciding whether spells are left to recover. |
The resting section sums up what each condition allows during a rest.5
Sources
Locations refer to the game executable reference.