Races
CharacterRace · bits 1 to 7 of race_and_sex in
CharacterRuntime, read as
race_and_sex >> 1
The party · Condition expression tokens · Character record
Each character has a race and a sex, chosen together when the character is created. The game stores them in one byte: the race in the upper bits and the sex in the lowest bit. The race limits the classes and attributes a character may take, and scripts can look for a character of a given race.
The byte is the number of the entry chosen in the creation menu, whose twelve entries read HUMAN MALE, HUMAN FEMALE, ELF MALE and so on to HALFLING FEMALE. The code shifts the byte right once to index its race tables, Raise Dead refuses race 1, the elf, and the item-loss message writes "her" when the lowest bit is set.1
/* Race of a character: race_and_sex >> 1 (EOB II DOS). */
typedef enum CharacterRace {
CHARACTER_RACE_HUMAN = 0,
CHARACTER_RACE_ELF = 1, /* Cannot be raised by Raise Dead. */
CHARACTER_RACE_HALF_ELF = 2,
CHARACTER_RACE_DWARF = 3, /* Gets a different starting weapon choice. */
CHARACTER_RACE_GNOME = 4,
CHARACTER_RACE_HALFLING = 5
} CharacterRace;
/* Lowest bit of race_and_sex. */
#define CHARACTER_SEX_FEMALE 0x01 /* Clear: male. */
So race_and_sex = 2 × race + sex, from 0 (human male) to 11 (halfling
female).
Where it is used
- Creation. The race selects the classes a character may choose and the attribute modifiers and limits; see race, class and alignment.
- Starting items. A dwarf's starting weapon is chosen differently; see creating the party.2
- Saving throws. The saving throws against monster attacks use the race; the script saving throw compares the whole byte instead (see its anomaly).
- Raise Dead does not work on an elf; see the attack spells.
- Scripts.
SCRIPT_EXPR_FIND_CHARACTER_BY_RACEselects a conscious character of a race; the original levels look for elves and dwarves most often; see what the conditions test. - Messages.
CHARACTER_SEX_FEMALEchooses between "her" and "his" when a monster takes an item; see melee attacks.
Sources
Locations refer to the game executable reference.