Scroll Thief — 57 of 138

Daniel M. Stelzer

Release 2

Section E - Listing Spells

Listing spells is an action applying to nothing. Understand "spells" or "list spells" or "memory" as listing spells.

[ In the Reliques of Tolti-Aph Graham Nelson used a say-phrase for this, but I prefer to make it an action and call it with "try". ]

After thinking:

try listing spells.

Carry out listing spells:

[Step one - does the player know any spells?]

say "You have ";

if the player's memory is empty:

say "no spells ";

else:

let the temporary holding space be the player's memory [make a copy of the array to sort];

sort the temporary holding space;

let the max be the number of entries in the temporary holding space;

let N be 1;

while N <= the max:

let xyzzy be entry N in the temporary holding space;

let the count be the memory count of xyzzy;

if N plus the count >= the max and N is greater than 1, say "and "; [in other words, if this is the last spell in the list and also not the first]

say "the [xyzzy] spell[if the max is greater than one] [count times][end if][if N plus the count is less than the max],[end if] ";

increase N by the count;

say "committed to memory.";

unless the player is unmodified:

say "You also have the [if the player is empowered]yonk[else]lleps[end if] spell half-cast, ready to go off.";

let the accessibility list be the set of learnable spells;

if the accessibility list is not empty:

say "The [accessibility list] spell[if the number of entries in the accessibility list is greater than 1]s are[else] is[end if][if the player's memory is not empty] also[else], however,[end if] close at hand."

To say (N - a number) times:

if N is less than one, say "[N in words] times (somehow...)";

if N is one, say "once";

if N is two, say "twice";

if N is three, say "thrice";

if N is greater than three, say "[N in words] times".

To decide what list of spells is the set of learnable spells:

let L be a list of spells;

repeat with the tome running through spell books enclosed by the player:

repeat with xyzzy running through spells inscribed in the tome:

add xyzzy to L, if absent;

repeat with the page running through spell scrolls enclosed by the player:

add the inscribed spell of the page to L, if absent;

let K be a list of spells;

repeat through the Table of Spells in reverse casting count order: [This is a really non-idiomatic way to sort a list of spells based on a property.]

if the spell entry is listed in L and the spell entry is not listed in the player's memory and the spell entry is not the null-spell:

add the spell entry to K;

decide on K.

Listing spells is acting fast.