Skip to main content

Character record

CharacterRuntime · 345-byte runtime structure

The engine in ten minutes · The party · Magic

In brief​

The six party characters are stored one after another in an array of records 345 bytes long. Its fields hold the attributes and alignment, the status bits and hit points tested by the eligibility checks, the class with the level and experience of each of its base classes, the lasting spell effects, the mage spells a character knows, its mage and cleric spell slots, the items it carries, its food, its timers and its portrait; nine unused bytes remain.1 The records of a new party are filled when the player creates the party; see initialization.

Layout​

/* One party character (345 bytes, little-endian); partial view. */
typedef struct CharacterRuntime {
uint8_t unknown_00; /* 0x000: the slot number when written; never tested; see "Unused bytes". */
uint8_t status_flags; /* 0x001: CharacterStatusFlags. */
char name[11]; /* 0x002: zero-terminated name, printed in messages. */
uint8_t strength; /* 0x00d: gives the strength hit and damage modifiers and the chance to force a door. */
uint8_t strength_max; /* 0x00e: copied into strength by "remove all effects". */
uint8_t exceptional_strength; /* 0x00f: percentage of an 18 strength; replaces the modifiers when nonzero. */
uint8_t exceptional_strength_max; /* 0x010: second byte of exceptional_strength. */
uint8_t intelligence; /* 0x011: limits at creation and the character sheet; name inferred. */
uint8_t intelligence_max; /* 0x012: second byte of intelligence. */
uint8_t wisdom; /* 0x013: gives the bonus cleric spell slots. */
uint8_t wisdom_max; /* 0x014: second byte of wisdom. */
uint8_t dexterity; /* 0x015: gives the defense and missile modifiers. */
uint8_t dexterity_max; /* 0x016: second byte of dexterity. */
uint8_t constitution; /* 0x017: hit points per level and saving throws. */
uint8_t constitution_max; /* 0x018: second byte of constitution. */
uint8_t charisma; /* 0x019: limits at creation and the character sheet; name inferred. */
uint8_t charisma_max; /* 0x01a: second byte of charisma. */
int16_t hit_points; /* 0x01b: current hit points, signed; compared with 0 and -10. */
int16_t hit_points_max; /* 0x01d: healing does not go above it. */
uint8_t defense; /* 0x01f: recomputed from dexterity, worn armour, shields, bracers and rings; lower is better. */
uint8_t disabled_slots; /* 0x020: bit n toggled when hand n is used, bit 2 after casting. */
uint8_t race_and_sex; /* 0x021: 2 x CharacterRace + 1 for a female character. */
uint8_t class_index; /* 0x022: index of the CharacterClassMask table. */
uint8_t alignment; /* 0x023: 0-8, index of the alignment name; restricts the creation menus. */
int8_t portrait; /* 0x024: portrait number; >= 0 CHARGENA image, < 0 OUTPORTS image. */
uint8_t food; /* 0x025: 100 for a new party; decreased by the food update; 0 stops it. */
uint8_t levels[3]; /* 0x026: level in each class, read for the caster levels. */
uint32_t experience[3]; /* 0x029: experience of each class, same order as levels. */
uint32_t face_image; /* 0x035: far pointer to the portrait image in memory. */
int8_t mage_spell_slots[80]; /* 0x039: eight groups of ten mage spell entries. */
int8_t cleric_spell_slots[80]; /* 0x089: eight groups of ten cleric spell entries. */
uint32_t known_mage_spells; /* 0x0d9: bit i set = mage spell ID i + 1 is known. */
uint16_t inventory[27]; /* 0x0dd: ItemRuntime indices, zero empty; see "Inventory slots" below. */
uint32_t timer_deadlines[10]; /* 0x113: counter deadlines; 0 = unused. */
int8_t timer_events[10]; /* 0x13b: event code of each deadline; negative = a lasting spell. */
int8_t armor_spell_points; /* 0x145: what is left of Armor; damage reduces it, Armor ends at 0. */
uint8_t unknown_146; /* 0x146: never set; read only by the portrait frame; see "Unused bytes". */
uint8_t unknown_147; /* 0x147: only cleared; never read. */
int8_t aid_bonus_points; /* 0x148: the hit points Aid added that damage has not taken back. */
uint32_t spell_effects; /* 0x149: SpellEffectFlags of the spells active on the character. */
uint8_t last_damage; /* 0x14d: low byte of the last damage inflicted. */
int8_t slot_status[2]; /* 0x14e: result of the last use of each hand, shown on the portrait. */
uint8_t book_entry; /* 0x150: spell-book entry last selected. */
uint8_t book_group; /* 0x151: spell-book group last selected. */
uint8_t book_offset; /* 0x152: 0 or 6, the book page offset last used. */
uint8_t unknown_153[6]; /* 0x153: never accessed, only copied with the record. */
} CharacterRuntime;

There is no padding.

Attributes​

The names intelligence and charisma are inferred from the order in which the character sheet prints the attributes and from a comparative source. The _max names of the second bytes are descriptive: the second bytes hold the character's normal values, not limits.

Each of the six attributes is followed by a second byte. At the end of party setup the game copies each attribute into its second byte, and hit_points into hit_points_max; removing all magical effects copies strength_max back into strength, and so does the end of giant strength. Only strength_max and exceptional_strength_max are ever read; no code compares an attribute with its second byte, and the other five second bytes are never read. The character sheet prints alignment, the strength and the five other attributes; what each attribute changes in play is described under attributes. The class's levels and experience follow the class components, in the same order.2

Status, hit points and class​

  • status_flags and hit_points are what the eligibility checks test: a character is present, not dead or conscious according to them. Damage subtracts from hit_points; at −10 or less the death path keeps only the lowest bit of status_flags and clears food; see damage characters.3
  • status_flags uses only its four low bits, the CharacterStatusFlags; no code sets or tests bits 0x10 to 0x80.4
  • race_and_sex holds the race in its upper bits and CHARACTER_SEX_FEMALE in its lowest bit.
  • class_index selects the character's CharacterClassMask, and scripts can look for a character by race or portrait; see condition expression tokens.
  • spell_effects holds the SpellEffectFlags that the spells cast on the character set while they last.5
  • The spells use levels for the caster's level, heal up to hit_points_max, and keep the reserves of Armor and Aid in armor_spell_points and aid_bonus_points.
  • constitution and race_and_sex take part in saving throws; defense receives the defense adjustment of an equipped item type.

Inventory slots​

inventory holds 27 item indices: hands 0 and 1, backpack 2 to 15, the quiver 16, body armour 17, bracers 18, helmet 19, neck 20, boots 21, belt 22 to 24 and rings 25 and 26. Slot 16 is the head of a chain of arrows, not a single item. Which items each slot accepts, and how they are moved, is described in the inventory. When a character's spell book is opened, book_entry, book_group and book_offset give the entry selected first.6

Spell slots​

A slot holds a spell ID, read as a signed byte:

ValueMeaning
0Empty slot.
positiveA spell ready to be cast from the spell book.
negativeA spell chosen in the memorize or pray menu and not yet gained, or cast since; resting turns it positive.

The list builder counts entries by absolute ID and separately counts the positive ones. A used spell becomes positive again only while the party rests, one slot at a time, for a character that carries a holy symbol or a spellbook; see resting. Resting also casts healers' cure spells, which marks their slots used, and writes Lay on Hands into a paladin's first ten cleric slots.7

Each array holds eight groups of ten slots, one group per spell level: spell level g, the spell's group in the mage and cleric spells, uses entries 10 (g − 1) to 10 (g − 1) + 9. Only the memorize and pray menus fill the slots: when the player leaves them, the array is rewritten level by level, in the order of the spell IDs, ready copies before the others. They and the setup of a new party put 29, the cleric ID of Turn undead, into entry 0 of cleric_spell_slots (offset 0x89), and the menus skip that value when they count the slots, in the mage array too (see the True Seeing bug). Resting makes the negative slots positive; casting makes a positive slot negative.8

Known mage spells​

known_mage_spells is separate from the slots. When a mage copies a scroll, the game checks the spell's bit and sets it once the spell is chosen; see learning from scrolls. Spell names are displayed through the separate SpellNamePointer tables.9

Character timers​

Each character has ten timer pairs: a deadline in shared-counter ticks and an event code. Setting one stores the counter plus a duration, replacing a pending timer with the same code, and makes the character's entry in the game's timed updates come back at the earliest deadline; character timers gives the rules and what sets each code. A negative code − n belongs to a lasting spell: when its deadline passes, the effect of spell definition n ends. The other codes do the following when their deadline passes:10

CodeEffect
0, 1Hand 0 for code 0, hand 1 for code 1: its bit of disabled_slots is toggled, its slot_status is cleared and the portrait is redrawn.
2, 3The same hand's slot_status is cleared and the portrait redrawn; code 4 or 5 is then set for that hand, 9 ticks later under SPELL_EFFECT_HASTE, 36 otherwise.
4, 5As codes 0 and 1.
6last_damage is cleared and the portrait redrawn; each damage to the character sets this code 18 ticks ahead.
7"name no longer has giant strength.": strength and exceptional_strength take back the values of their second bytes.
8Poison: while the character has CHARACTER_STATUS_POISONED, 5 points of damage, none under SPELL_EFFECT_SLOW_POISON, then the same code again 546 ticks later; see effects on characters.
9If the character is still paralyzed: "name is no longer paralyzed!" and CHARACTER_STATUS_PARALYZED is cleared.
10Nothing; no caller sets it.
11Bit 2 of disabled_slots is cleared, and the spell book is redrawn when it is open for the character: the book, unusable since a spell was cast from it 72 ticks earlier, can be used again.
12SPELL_EFFECT_HASTE is cleared: "name slows down."

The status bits are CharacterStatusFlags.

A saved game stores each timer as the number of ticks it has left (1 for a timer already due, 0 for an unused one). Loading adds the current counter back and schedules the character's entry for its earliest timer; see loading, failures and the end of the game.11

Portrait​

When a game is loaded, the portrait of each character is drawn again from portrait: a number of 0 or more selects an image of CHARGENA.CPS, a negative number − n − 1 selects image n of OUTPORTS.CPS. The image goes to the memory addressed by face_image, which is a run-time pointer: loading keeps the pointer already in memory and ignores the saved one.11

The food byte is decreased by one every 1080 ticks for each present character whose food is not zero and whose hit points are above −10; see food.12

Initialization​

The records of a new party are written in two stages, described under creating the party:13

  • When a character is created: race_and_sex, class_index, alignment, name and portrait from the player's choices; every attribute and its second byte from the roll; levels from the class; all three experience totals, also those of unused components; defense; hit_points and hit_points_max. Modifying the character changes only the first byte of each attribute.
  • When the party enters the game: status_flags set to CHARACTER_STATUS_PRESENT, food to 100 and unknown_00 to the slot number; starting items in inventory; known_mage_spells for mages and Turn undead in cleric_spell_slots for clerics and paladins; the attributes and hit_points copied again into their second bytes and hit_points_max; defense recomputed with the items.

A transferred party and a recruited character are written in other ways, described on those pages.

Unused bytes​

Every access to these offsets found in the resident code and the overlays is listed below. An access through a record pointer received as an argument could escape the search for byte 0; none is known.

Nine bytes take no part in the examined game logic. They are saved and loaded with the rest of the record, and copied with it when two characters swap places or a companion joins; the six prepared companion records stored in the executable hold zero in all of them.4

OffsetFieldWhat the code does with it
0x000unknown_00Written with the slot number: for slots 1 to 5 when the game starts, and for slots 0 to 3 when a new party enters the game. A party transfer copies it from the Eye of the Beholder I record and keeps it when it clears a record. No code bases a decision on it, and nothing writes it again when characters change places, so it does not follow the slot.
0x146unknown_146Only cleared, when all of a character's effects are removed. The portrait frame of protective spells is also drawn when it is nonzero, but no code gives it another value.
0x147unknown_147Only cleared, with 0x146.
0x153–0x158unknown_153Never read or written on their own.

A reimplementation can keep these bytes only to preserve the record and saved-game layout.

Sources​

Locations refer to the game executable reference.

Footnotes​

  1. The array is the character table; slot arrays read, built and written, and listed by the spell group lists; inventory searched by inventory search by type and value. ↩

  2. Copy to the second bytes, character sheet, award experience and gain a level. Comparative source: REF-SCUMM-014. ↩

  3. Character eligibility routine and character damage routines. ↩

  4. Byte 0 is written by starting status and items and the start-up tables reset, copied by the party transfer and kept by its record clear; bytes 0x146 and 0x147 by remove all of a character's effects, and 0x146 is read by the portrait frame; the record copies are the swap and the companion records of the recruitment. The status writes are those of the afflict routine, the death path and the character removal. ↩ ↩2

  5. Apply and remove a spell definition. ↩

  6. The inventory-slot masks and open a spell book. ↩

  7. Positive-slot scan, slot rearrangement and negation, and recover a spell in the rest routine. ↩

  8. Read and write the spell-slot arrays, the memorize and pray menus, the starting spells and the casting from the spell book. ↩

  9. Scroll copying. ↩

  10. Set a character timer and the character timer events, in the timed-callback table; poison damage goes through the character damage routines. Comparative sources: REF-SCUMM-014, setCharEventTimer, and REF-SCUMM-021, timerSpecialCharacterUpdate. ↩

  11. Convert character timers, re-arm the character timer updates and read a saved game, which also draws the portraits. Schema: SAV.ksy. ↩ ↩2

  12. Food handler. ↩

  13. Generate a character, create a character, modify a character and party setup. ↩