From 04a9069b8b3002474e8f1b1b1d5fbf7cd7c68d4c Mon Sep 17 00:00:00 2001 From: Erik Lunna Date: Mon, 30 Oct 2023 10:43:19 +0100 Subject: [PATCH] Blessed potions of amnesia can let you select which spell to forget. This was suggested by mobileuser. I also was able to fix some incorrect prompts for reinforce memory and the amnesia menu when the spell menu is displayed. --- src/potion.c | 2 +- src/spell.c | 48 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/potion.c b/src/potion.c index c77c0cd8a..68e6c8304 100644 --- a/src/potion.c +++ b/src/potion.c @@ -927,7 +927,7 @@ register struct obj *otmp; newuhs(FALSE); if (otmp->blessed && ACURR(A_INT) > 12 && num_spells() > 0) { - if (yn("Do you want to forget your last spell?") != 'y') { + if (yn("Do you want to forget a spell?") != 'y') { goto forget_routine; } else { forget_spell(); diff --git a/src/spell.c b/src/spell.c index 4333920b6..2e612412d 100644 --- a/src/spell.c +++ b/src/spell.c @@ -41,7 +41,7 @@ STATIC_DCL boolean FDECL(confused_book, (struct obj *)); STATIC_DCL void FDECL(deadbook, (struct obj *)); STATIC_PTR int NDECL(learn); STATIC_DCL boolean NDECL(rejectcasting); -STATIC_DCL boolean FDECL(getspell, (int *)); +STATIC_DCL boolean FDECL(getspell, (int *, const char *)); STATIC_PTR int FDECL(CFDECLSPEC spell_cmp, (const genericptr, const genericptr)); STATIC_DCL void NDECL(sortspells); @@ -746,11 +746,12 @@ rejectcasting() * parameter. Otherwise return FALSE. */ STATIC_OVL boolean -getspell(spell_no) +getspell(spell_no, descr) int *spell_no; +const char *descr; { int nspells, idx; - char ilet, lets[BUFSZ], qbuf[QBUFSZ]; + char ilet, lets[BUFSZ], qbuf[QBUFSZ], buf[BUFSZ]; if (spellid(0) == NO_SPELL) { You("don't know any spells right now."); @@ -780,7 +781,8 @@ int *spell_no; Sprintf(lets, "a-zA-Z0-%c", '9' + nspells - 11); for (;;) { - Sprintf(qbuf, "Cast which spell? [%s *?]", lets); + Sprintf(qbuf, "%s which spell? [%s *?]", descr, lets); + qbuf[0] = highc(qbuf[0]); ilet = yn_function(qbuf, (char *) 0, '\0'); if (ilet == '*' || ilet == '?') break; /* use menu mode */ @@ -796,8 +798,8 @@ int *spell_no; return TRUE; } } - return dospellmenu("Choose which spell to cast", SPELLMENU_CAST, - spell_no); + Sprintf(buf, "Choose which spell to %s", descr); + return dospellmenu(buf, SPELLMENU_CAST, spell_no); } /* the 'Z' command -- cast a spell */ @@ -806,7 +808,7 @@ docast() { int spell_no; - if (getspell(&spell_no)) + if (getspell(&spell_no, "cast")) return spelleffects(spell_no, FALSE, FALSE); return 0; } @@ -1731,16 +1733,32 @@ losespells() void forget_spell() { - int n, lastspell; - - for (n = 0; n < MAXSPELL; ++n) + int n, spell_no; + boolean found = FALSE; + if (!getspell(&spell_no, "forget")) + return; + + for (n = 0; n < MAXSPELL; ++n) { + if (n == spell_no) { + Your("%s spell has been forgotten.", spellname(spell_no)); + spellknow(n) = 0; + spellid(n) = NO_SPELL; + found = TRUE; + } + if (found && spellid(n+1) != NO_SPELL) { + /* Move the next spell down one slot */ + spl_book[n].sp_id = spl_book[n+1].sp_id; + spl_book[n].sp_lev = spl_book[n+1].sp_lev; + spl_book[n].sp_know = spl_book[n+1].sp_know; + /* Remove it too */ + spellknow(n+1) = 0; + spellid(n+1) = NO_SPELL; + } if (spellid(n) == NO_SPELL) break; - lastspell = n - 1; + } + - Your("%s spell has been forgotten.", spellname(lastspell)); - spellknow(lastspell) = 0; - spellid(lastspell) = NO_SPELL; } /* * Allow player to sort the list of known spells. Manually swapping @@ -2384,7 +2402,7 @@ studyspell() /*Vars are for studying spells 'W', 'F', 'I', 'N'*/ int spell_no; - if (getspell(&spell_no)) { + if (getspell(&spell_no, "study")) { if (spellknow(spell_no) <= 0) { You("are unable to focus your memory of the spell."); return (FALSE);