From c623ddf2e20064ae3fbba9f908541edeef488076 Mon Sep 17 00:00:00 2001 From: PatR Date: Wed, 22 May 2024 22:22:59 -0700 Subject: [PATCH] fix github issue #1246 - fading spellbook Issue reported by chadministratorwastaken: persistent inventory window didn't update if reading a spellbook caused that book to fade to blank paper. Issue was reported for 'curses' but it was general. The core made the possibly-revised book type become discovered but that wouldn't update perm_invent unless the type of book hadn't been discovered. So if plain spellbook wasn't known yet, the persistent inventory window did update as intended, but if spellbook of blank paper was already discovered, the window continued to show the old book type instead of changing to reflect the revised type (until subsequent activity triggered another perm_invent update). Fixes #1246 --- doc/fixes3-7-0.txt | 2 ++ src/spell.c | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index f9455aa36..342fed083 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -567,6 +567,8 @@ perm_invent: when buying shop goods using itemized purchasing while persistent soon as any item was bought (actual item-by-item purchase worked ok) perm_invent: making an engraving which reduced known enchantment of a weapon or known charge count of a marker didn't update persistent inventory +perm_invent: over-reading a spellbook so that in faded to blank didn't update + persistent inventory to show that if blank spellbook was already known change getloc fastmove keys in number_pad mode from hardcoded HJKL to the run/rush movement keys (meta+number) allow using rush/run prefix key in getloc to fastmove the cursor diff --git a/src/spell.c b/src/spell.c index 76eca4334..f1fd18270 100644 --- a/src/spell.c +++ b/src/spell.c @@ -358,11 +358,12 @@ learn(void) int i; short booktype; char splname[BUFSZ]; - boolean costly = TRUE; + boolean costly = TRUE, faded_to_blank = FALSE; struct obj *book = gc.context.spbook.book; /* JDS: lenses give 50% faster reading; 33% smaller read time */ - if (gc.context.spbook.delay && ublindf && ublindf->otyp == LENSES && rn2(2)) + if (gc.context.spbook.delay && ublindf + && ublindf->otyp == LENSES && rn2(2)) gc.context.spbook.delay++; if (Confusion) { /* became confused while learning */ (void) confused_book(book); @@ -400,6 +401,7 @@ learn(void) if (book->spestudied > MAX_SPELL_STUDY) { pline("This spellbook is too faint to be read any more."); book->otyp = booktype = SPE_BLANK_PAPER; + faded_to_blank = TRUE; /* reset spestudied as if polymorph had taken place */ book->spestudied = rn2(book->spestudied); } else { @@ -409,7 +411,6 @@ learn(void) book->spestudied++; exercise(A_WIS, TRUE); /* extra study */ } - makeknown((int) booktype); } else { /* (spellid(i) == NO_SPELL) */ /* for a normal book, spestudied will be zero, but for a polymorphed one, spestudied will be non-zero and @@ -418,6 +419,7 @@ learn(void) /* pre-used due to being the product of polymorph */ pline("This spellbook is too faint to read even once."); book->otyp = booktype = SPE_BLANK_PAPER; + faded_to_blank = TRUE; /* reset spestudied as if polymorph had taken place */ book->spestudied = rn2(book->spestudied); } else { @@ -432,7 +434,17 @@ learn(void) You("add %s to your repertoire, as '%c'.", splname, spellet(i)); } + } + if (i < MAXSPELL) { + /* might be learning a new spellbook type or spellbook of blank paper; + if so, persistent inventory will get updated */ makeknown((int) booktype); + /* makeknown() calls update inventory when discovering something + new but is a no-op for something that's already known so wouldn't + update persistent inventory to reflect faded book if spellbook of + blank paper happens to already be discovered */ + if (faded_to_blank) + update_inventory(); } if (book->cursed) { /* maybe a demon cursed it */