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
This commit is contained in:
PatR
2024-05-22 22:22:59 -07:00
parent f634bb863f
commit c623ddf2e2
2 changed files with 17 additions and 3 deletions

View File

@@ -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

View File

@@ -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 */