Magic
Home · The engine in ten minutes · CharacterRuntime ·
SpellDefinitionRuntime
In brief
The game describes each spell twice: a short display name in a mage or cleric name table, and a definition holding the full name, the routine that carries the spell out and its flags. Each character records which mage spells it knows and keeps two arrays of spell slots. A mage learns new spells by copying them from scrolls. Spells are chosen in the memorize or pray menu, become ready while the party rests, and are cast from the spell book; used spells come back with rest. Casting follows fixed steps chosen by the definition's flags, and a lasting spell sets an effect that a timer ends.
How the game stores spells
| What | Where | Content |
|---|---|---|
| Display names | Two tables of SpellNamePointer | Mage IDs 1–32, cleric IDs 1–29; the index is the spell's ID. |
| Definitions | One table of SpellDefinitionRuntime | Full name, handlers, flags, effect mask; cleric entries follow the mage ones. |
| Known mage spells | A 32-bit mask in each CharacterRuntime | Bit i set when mage spell ID i + 1 is known. |
| Spell slots | Two 80-entry arrays in each CharacterRuntime | Signed spell IDs, eight groups of ten, for mage and cleric spells. |
A name alone says nothing about a spell's effect or targeting. Some definitions have no start routine: the start then does only its common steps, which is all that most lasting spells need, since their effect comes from the effect bits the start sets. The two definitions that have nothing else either, Bigby's Fist and Ressurection, would only silence the sound in progress and print the cast message; no tab of the book and no item of the original game casts them. The mage and cleric spells lists every identified name with its initial definition data.1
Where spell state lives
The spells themselves never change: the name tables, the definitions and the timer parameters are part of the executable's data, no code writes them, and they are neither saved nor loaded from a file. Everything that changes belongs to a character, to the party or to the spell being cast:2
| State | Kept in | At the start of a game | In a saved game |
|---|---|---|---|
| Known mage spells | Each character | Nine spells for a mage; see entering the game | Saved with the character |
| Spell slots, mage and cleric | Each character | Turn undead for a cleric or a paladin; otherwise empty | Saved with the character |
| Effect bits, Armor reserve, Aid bonus | Each character | None | Saved with the character |
| Spell timers | Each character's timers | None | Saved as the time left |
| Spell-book page last used | Each character | — | Saved with the character |
| Party effect bits | The party variables | None | Saved with the party |
| Conjured weapons | Item types 51 to 56 | — | Saved |
| Last spell cast, spell being cast, open spell book | Game variables | — | Not saved |
| Spells in flight | Flying objects | — | Ended before saving |
The definition is the link between all of these. A slot holds a spell ID; mage spell n is definition n and cleric spell n definition n + 33. Casting reads the definition's flags and routines; a lasting spell sets the bits of the definition's effect mask on its target, on the party or on every member, and starts a timer whose code is the definition number made negative, so that the timer's end finds the definition again, runs its end routine and clears the same bits. Because the bits and the timers are saved with the characters and the party, a lasting spell survives a saved game and expires on time after loading.
A party transferred from Eye of the Beholder I keeps its known mage spells through a conversion table and starts with empty spell slots; see transferring a party.
The pages of this chapter
| Page | What it covers |
|---|---|
| Learning and memorizing spells | Copying scrolls, the memorize and pray menus, the states of a slot. |
| Spell slots | Slots per spell level for mages, clerics and paladins; the wisdom bonus. |
| Casting a spell | The spell book and the steps of a cast. |
| Lasting spells | Timers, durations, and what an active effect changes. |
| Mage and cleric spells | Every spell with the initial data of its definition. |
| Attack spells | Projectiles and the other spells that strike monsters. |
| Other spells | Conjured weapons, healing, protection and detection. |
| Spell anomalies | The anomalies of the spells' own routines. |
Sources
Locations refer to the game executable reference.