Skip to main content

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.

The life of a spell for a character. A mage learns a spell by copying a scroll; a cleric or a paladin needs no learning. In the memorize or pray menu the player chooses spells, which wait in their slots. A step of rest makes a waiting spell ready. Casting it from the spell book uses the slot, and rest makes the used slot ready again. A lasting spell sets an effect and starts a timer; when the timer expires, the effect ends.
A mage must copy a scroll first; every spell waits for a rest before it can be cast.

How the game stores spells​

WhatWhereContent
Display namesTwo tables of SpellNamePointerMage IDs 1–32, cleric IDs 1–29; the index is the spell's ID.
DefinitionsOne table of SpellDefinitionRuntimeFull name, handlers, flags, effect mask; cleric entries follow the mage ones.
Known mage spellsA 32-bit mask in each CharacterRuntimeBit i set when mage spell ID i + 1 is known.
Spell slotsTwo 80-entry arrays in each CharacterRuntimeSigned 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

StateKept inAt the start of a gameIn a saved game
Known mage spellsEach characterNine spells for a mage; see entering the gameSaved with the character
Spell slots, mage and clericEach characterTurn undead for a cleric or a paladin; otherwise emptySaved with the character
Effect bits, Armor reserve, Aid bonusEach characterNoneSaved with the character
Spell timersEach character's timersNoneSaved as the time left
Spell-book page last usedEach character—Saved with the character
Party effect bitsThe party variablesNoneSaved with the party
Conjured weaponsItem types 51 to 56—Saved
Last spell cast, spell being cast, open spell bookGame variables—Not saved
Spells in flightFlying 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​

PageWhat it covers
Learning and memorizing spellsCopying scrolls, the memorize and pray menus, the states of a slot.
Spell slotsSlots per spell level for mages, clerics and paladins; the wisdom bonus.
Casting a spellThe spell book and the steps of a cast.
Lasting spellsTimers, durations, and what an active effect changes.
Mage and cleric spellsEvery spell with the initial data of its definition.
Attack spellsProjectiles and the other spells that strike monsters.
Other spellsConjured weapons, healing, protection and detection.
Spell anomaliesThe anomalies of the spells' own routines.

Sources​

Locations refer to the game executable reference.

Footnotes​

  1. The spell-name tables and their table selection; the initial definition table, read by the definition-name formatting and the spell cast; character spell state in the spell-slot routines. ↩

  2. The initial definition table and the spell-name tables, with their readers; the save writer, the saved-game reader and settle the level; the party's spell effects; the character timers and end a spell's effect. ↩