Skip to main content

Casting a spell

Magic · Lasting spells · Choosing a spell

In brief​

A spell is cast from the spell book, which a spellbook or a holy symbol opens. Casting uses the slot at once, asks for a target when the spell needs one, plays its sound and animation, starts its timer, runs its own routine and sets its lasting effect; the book then rests for 72 ticks and the party's block receives a spell-cast event that level scripts can test.

The steps of a cast from the spell book. The spell is recorded as the last spell cast. A spell that needs a free hand is refused when both hands are full or one already holds an item of that kind. The slot is marked used, except for Turn undead, and the cast is announced; the target is chosen when the spell asks for one, otherwise it is the caster. The sound and the animation play. A spell whose effect is already active is refused. A timed spell starts its timer, the spell's own routine runs and can stop the cast, and the lasting effect is set; the defense is recomputed when the flags ask for it. From the book, the spell book then waits 72 ticks and the party's block receives the spell-cast event.
A cast can be refused before the slot is used, or after, when the effect is already active.

Using the spell book​

Using a spellbook opens the mage spell book, using a holy symbol the cleric one; see using items. How the book is laid out and how the player chooses a spell in it are described under choosing a spell in the book.

Casting from the book uses the slot at once: the slots after it in the level move up one place, and the spell goes, as a used slot, to the ninth place. The ready spells thus stay at the front of the level. If the line now selected holds no ready spell, the selection moves up one line, and after the last ready spell of a level it reaches ABORT SPELL; the book stays open. For the next 72 ticks the lines are covered and a click casts nothing, but tabs and pages still work. Turn undead uses no slot.1

The game also sorts the slots of every character, level by level, when the camp menu closes and at some points inside it: ready spells first by ID, then used ones by ID, then the empty slots.

The book closes by itself when the caster falls to 0 hit points or below, is paralyzed or petrified, when the player swaps two characters, and when a level is loaded or the party is defeated.

Anomaly

A spell from the book stopped by its own routine skips the end of the cast (ANOMALY-69). Only the three conjured weapons stop themselves, when Shocking Grasp, Vampiric Touch or Flame Blade cannot make its weapon ("The spell fails!"). The slot is then already used and moved, and the spell's lasting timer started, but the book's 72-tick wait, the redraw of the page and the spell-cast event are all skipped. The page then still shows the old list while the slots have moved, so a click can cast the spell that moved into that line, without the wait (inferred). Spells cast from items have the same gap. A faithful reimplementation keeps the slot spent and skips the same steps.

The steps of a cast​

What each spell's own start and end routines do is not covered here; see the attack spells.

When a character casts a spell from the spell book, the game goes through these steps; the flags are SpellDefinitionFlags of the spell's definition:2

  1. Casting. The definition number is recorded as the last spell cast, which scripts can test with SCRIPT_EXPR_LAST_CAST_SPELL.
    • With SPELL_FLAG_ENDS_INVISIBILITY, a caster with SPELL_EFFECT_INVISIBILITY becomes visible: the Invisibility effect ends, with its message.
    • With SPELL_FLAG_NEEDS_FREE_HAND, the spell is refused when both hands are full ("You must have a free hand for this spell.") or when a hand already holds an item of that kind ("You can't have two of this spell type active.").
    • The spell's slot is marked used, except for Turn undead. The game prints "caster casts spell."
    • With SPELL_FLAG_CHOOSE_TARGET it asks "Cast spell on which character?" and waits; otherwise the caster is the target.
  2. Start. The definition's sound effect plays, and an animation runs on the target's portrait, on every portrait or over the view.
    • The spell is refused when its effect is already active: "name is already under the effect of a spell spell." for the target, "The party is already under the effect of a spell spell." for the party.
    • With SPELL_FLAG_TIMED, a timer is started on the target (see lasting spells).
    • The spell's own start routine runs; it can stop the start here.
    • The lasting effect is set: on the target, on the party, or on every living party member.
    • The target's defense is recomputed with SPELL_FLAG_RECALCULATE_DEFENSE, and the portraits are redrawn.
  3. Afterwards. For a spell from the book, the caster's spell book cannot be used for 72 ticks, about four seconds, until a character timer ends the wait. The game then sends BLOCK_EVENT_SPELL_CAST to the party's block, so a level script can react; see events that start scripts.

Sources​

Locations refer to the game executable reference.

Footnotes​

  1. Open a spell book, the spell-book page, the book buttons and the button list; casting and the slot update in cast a spell from the book and start a spell; the slot sort and the book close; the keyboard handler for the key numbers. ↩

  2. Cast a spell from the book, ask for a spell's target, start a spell, the spell animations, the defense recomputation and the spell casting state. Comparative source: REF-SCUMM-013, castSpell and startSpell. ↩