From ed6b78e227d37e0674e1355cd4cb1d9283f9681a Mon Sep 17 00:00:00 2001 From: PatR Date: Sun, 3 Dec 2023 18:03:16 -0800 Subject: [PATCH] fix #K4054 - spellbook weight bug Report was that converting a novel into a blank spellbook via water damage resulted in a spellbook of blank paper that increased weight when put into a bag of holding. Spellbooks weigh 50 units but novels were defined with a weight of 0; when one was created, a non-zero weight of 1 got assigned. Blanking it didn't update the weight; that stayed at 1. Putting it into a container reset the weight to match the new type: spellbook of blank paper, so its weight increased. Do that when blanking rather than wait until a container might fix it up. If it is already in a [possibly nested] container, update that container's weight too along with any outer ones. This also changes the base weight of novel from 0 to 10, so it still gets magically heavier when turned into a spellbook of blank paper. (The alternative seems to be to destroy it instead.) The Book of the Dead weighed only 20 units which seemed odd to be so much less than a spellbook. This changes that to 50 to match those. --- doc/fixes3-7-0.txt | 2 ++ include/objects.h | 4 ++-- src/trap.c | 36 ++++++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index c8e6ba70b..c9e0cb3d8 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -1309,6 +1309,8 @@ if a monster fled from hero by intentionally jumping into a vault teleporter, it would teleport randomly instead of into the vault, and if the teleport trap's niche wasn't mapped yet, the trap would become mapped but the spot would remain a secret corridor and not become accessible +spellbooks weight 50 units but Book of the Dead only 20, and novels only 1; + the Book of the Dead has been changed to 50 and novels to 10 Fixes to 3.7.0-x General Problems Exposed Via git Repository diff --git a/include/objects.h b/include/objects.h index 2bf90dd5a..11de04b07 100644 --- a/include/objects.h +++ b/include/objects.h @@ -1401,12 +1401,12 @@ MARKER(LAST_SPELL, SPE_BLANK_PAPER) /* tribute book for 3.6 */ OBJECT(OBJ("novel", "paperback"), BITS(0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, P_NONE, PAPER), - 0, SPBOOK_CLASS, 1, 0, 0, 20, 0, 0, 0, 1, 20, CLR_BRIGHT_BLUE, + 0, SPBOOK_CLASS, 1, 0, 10, 20, 0, 0, 0, 1, 20, CLR_BRIGHT_BLUE, SPE_NOVEL), /* a special, one of a kind, spellbook */ OBJECT(OBJ("Book of the Dead", "papyrus"), BITS(0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, P_NONE, PAPER), - 0, SPBOOK_CLASS, 0, 0, 20, 10000, 0, 0, 0, 7, 20, HI_PAPER, + 0, SPBOOK_CLASS, 0, 0, 50, 10000, 0, 0, 0, 7, 20, HI_PAPER, SPE_BOOK_OF_THE_DEAD), #undef SPELL diff --git a/src/trap.c b/src/trap.c index e4d9b7d07..8dee860a3 100644 --- a/src/trap.c +++ b/src/trap.c @@ -4475,26 +4475,23 @@ water_damage( update_inventory(); return ER_DAMAGED; } else if (obj->oclass == SPBOOK_CLASS) { - if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { - /* - * FIXME? - * This might be given when hero can't see or feel it. - * The book can't be inside a container but it could get - * dunked away from hero if laying on ice which melts. - */ - pline("Steam rises from %s.", the(xname(obj))); + int otyp = obj->otyp; + + if (otyp == SPE_BOOK_OF_THE_DEAD) { + coordxy ox = 0, oy = 0; + + /* note: The Book of the Dead can't be contained or buried */ + if (get_obj_location(obj, &ox, &oy, CONTAINED_TOO | BURIED_TOO)) + obj->ox = ox, obj->oy = oy; + if (isok(ox, oy) && cansee(ox, oy)) + pline("Steam rises from %s.", the(xname(obj))); return 0; - } else if (obj->otyp == SPE_BLANK_PAPER) { + } else if (otyp == SPE_BLANK_PAPER) { return 0; } if (in_invent) Your("%s %s.", ostr, vtense(ostr, "fade")); - if (obj->otyp == SPE_NOVEL) { - obj->novelidx = 0; - free_oname(obj); - } - obj->otyp = SPE_BLANK_PAPER; /* same re-init as over-reading or polymorph; matters if it gets polymorphed into non-blank; doesn't matter if eventually written @@ -4502,6 +4499,17 @@ water_damage( if (obj->spestudied) obj->spestudied = rn2(obj->spestudied); obj->dknown = 0; + /* blanking a novel is more involved than blanking a spellbook */ + if (otyp == SPE_NOVEL) { /* old type */ + obj->novelidx = 0; /* overloads corpsenm, not used for splbooks */ + free_oname(obj); + /* novels weigh less than spellbooks; apparently blanking them + magically makes them become heavier */ + do { + obj->owt = weight(obj); + obj = (obj->where == OBJ_CONTAINED) ? obj->ocontainer : 0; + } while (obj); + } if (in_invent) update_inventory(); return ER_DAMAGED;