From aa8f73c890f19d8492a7f8aa1a7537440280da9f Mon Sep 17 00:00:00 2001 From: PatR Date: Thu, 15 Sep 2022 14:14:12 -0700 Subject: [PATCH] empty horn of plenty Format a horn of plenty whose charge count is unknown but is known to be empty as "empty horn of plenty" like is done for real containers. This was too easy; I must have missed something.... --- include/obj.h | 16 ++++++++++++++-- src/mkobj.c | 8 +++++++- src/objnam.c | 10 ++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/include/obj.h b/include/obj.h index 52f922887..84fe5befc 100644 --- a/include/obj.h +++ b/include/obj.h @@ -121,10 +121,22 @@ struct obj { Bitfield(in_use, 1); /* for magic items before useup items */ Bitfield(bypass, 1); /* mark this as an object to be skipped by bhito() */ Bitfield(cknown, 1); /* for containers (including statues): the contents - * are known; also applicable to tins */ - Bitfield(lknown, 1); /* locked/unlocked status is known */ + * are known; also applicable to tins; also applies + * to horn of plenty but only for empty/non-empty */ + Bitfield(lknown, 1); /* locked/unlocked status is known; assigned for bags + * and for horn of plenty (when tipping) even though + * they have no locks */ Bitfield(pickup_prev, 1); /* was picked up previously */ +#if 0 /* 3 free bits */ +#else + /* not implemented */ + Bitfield(tknown, 1); /* trap status known for chests */ + Bitfield(eknown, 1); /* effect known for wands zapped or rings worn when + * not seen yet after being picked up while blind + * [maybe for remaining stack of used potion too] */ + /* 1 free bit */ +#endif int corpsenm; /* type of corpse is mons[corpsenm] */ #define leashmon corpsenm /* gets m_id of attached pet */ diff --git a/src/mkobj.c b/src/mkobj.c index 18ac0fe7e..7de478aee 100644 --- a/src/mkobj.c +++ b/src/mkobj.c @@ -2556,6 +2556,10 @@ hornoplenty( impossible("bad horn o' plenty"); } else if (horn->spe < 1) { pline1(nothing_happens); + if (!horn->cknown) { + horn->cknown = 1; + update_inventory(); + } } else { struct obj *obj; const char *what; @@ -2604,8 +2608,10 @@ hornoplenty( targetbox->owt = weight(targetbox); /* item still in magic horn was weightless; when it's now in a carried container, hero's encumbrance could change */ - if (carried(targetbox)) + if (carried(targetbox)) { (void) encumber_msg(); + update_inventory(); /* for contents count or wizweight */ + } } else { /* assumes this is taking place at hero's location */ if (!can_reach_floor(TRUE)) { diff --git a/src/objnam.c b/src/objnam.c index af873e9be..165b7b07d 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -1144,10 +1144,12 @@ doname_base( (when that is known, suffix of "(n:0)" will be appended, making the prefix be redundant; note that 'known' flag isn't set when emptiness gets discovered because then - charging magic would yield known number of new charges) */ - && ((obj->otyp == BAG_OF_TRICKS) - ? (obj->spe == 0 && !obj->known) - /* not bag of tricks: empty if container which has no contents */ + charging magic would yield known number of new charges); + horn of plenty isn't a container but is close enough */ + && ((obj->otyp == BAG_OF_TRICKS || obj->otyp == HORN_OF_PLENTY) + ? (obj->spe == 0 && !known) + /* not a bag of tricks or horn of plenty: it's empty if + it is a container that has no contents */ : ((Is_container(obj) || obj->otyp == STATUE) && !Has_contents(obj)))) Strcat(prefix, "empty ");