From: nethack.rankin Date: Thu, 27 Oct 2011 02:24:54 +0000 (+0000) Subject: shop feedback ("gold piecess") (trunk only) X-Git-Tag: MOVE2GIT~155 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3337f05af8045e2104600948e5bc2e9652420803;p=nethack shop feedback ("gold piecess") (trunk only) From a bug report, dropping and selling a container that had some things owned by the hero and some already owned by the shop, you could get "You sold some items inside for N gold piecess." Shop handing for containers has been changed significantly since 3.4.3, but the typo "pieces" that then optionally gets plural "s" appended was still there. While testing the trivial fix, I noticed suboptional feedback in the prompt about selling. For a container owned by the shop, it said "items" even when there was just one hero owned item inside. Fortunately this potentinal can of worns only seemed to have one tiny weeny worm in it.... The revised version of count_buc() that I've had laying around for a while is also included. The fixes entry is for "piecess", not escaped/captured/exterminated worms, and goes into fixes34.4 despite this patch being labeled "trunk only". Separate patch for trunk to follow. --- diff --git a/doc/fixes34.4 b/doc/fixes34.4 index 9161a69d5..f34526a89 100644 --- a/doc/fixes34.4 +++ b/doc/fixes34.4 @@ -412,6 +412,7 @@ temporary loss of Dex from wounded legs will become permanent if it occurs character escape sequence handling during options processing was vulernable to malformed escapes and could potentially be abused to clobber the stack and launch a buffer overrun attack +fix message typo, "you sold some items inside for N gold piecess" Platform- and/or Interface-Specific Fixes diff --git a/include/extern.h b/include/extern.h index ed0cdb78b..0d7dfdedb 100644 --- a/include/extern.h +++ b/include/extern.h @@ -952,6 +952,7 @@ E void NDECL(reassign); E int NDECL(doorganize); E int FDECL(count_unpaid, (struct obj *)); E int FDECL(count_buc, (struct obj *,int)); +E long FDECL(count_contents, (struct obj *,BOOLEAN_P,BOOLEAN_P,BOOLEAN_P)); E void FDECL(carry_obj_effects, (struct obj *)); E const char *FDECL(currency, (long)); E void FDECL(silly_thing, (const char *,struct obj *)); diff --git a/src/invent.c b/src/invent.c index 9d2ca7dbd..15f967f11 100644 --- a/src/invent.c +++ b/src/invent.c @@ -2056,6 +2056,9 @@ count_unpaid(list) /* * Returns the number of items with b/u/c/unknown within the given list. * This does NOT include contained objects. + * + * Assumes that the hero sees or touches or otherwise senses the objects + * at some point: bknown is forced for priest[ess], like in xname(). */ int count_buc(list, type) @@ -2064,31 +2067,37 @@ count_buc(list, type) { int count = 0; - while (list) { - if (Role_if(PM_PRIEST)) list->bknown = TRUE; - switch(type) { - case BUC_BLESSED: - if (list->oclass != COIN_CLASS && list->bknown && list->blessed) - count++; - break; - case BUC_CURSED: - if (list->oclass != COIN_CLASS && list->bknown && list->cursed) - count++; - break; - case BUC_UNCURSED: - if (list->oclass != COIN_CLASS && - list->bknown && !list->blessed && !list->cursed) - count++; - break; - case BUC_UNKNOWN: - if (list->oclass != COIN_CLASS && !list->bknown) - count++; - break; - default: - impossible("need count of curse status %d?", type); - return 0; - } - list = list->nobj; + for ( ; list; list = list->nobj) { + /* coins are "none of the above" as far as BUCX filtering goes */ + if (list->oclass == COIN_CLASS) continue; + /* priests always know bless/curse state */ + if (Role_if(PM_PRIEST)) list->bknown = 1; + + /* check whether this object matches the requested type */ + if (!list->bknown ? (type == BUC_UNKNOWN) : + list->blessed ? (type == BUC_BLESSED) : + list->cursed ? (type == BUC_CURSED) : + (type == BUC_UNCURSED)) + ++count; + } + return count; +} + +long +count_contents(container, nested, quantity, everything) +struct obj *container; +boolean nested, /* include contents of any nested containers */ + quantity, /* count all vs count separate stacks */ + everything; /* all objects vs only unpaid objects */ +{ + struct obj *otmp; + long count = 0L; + + for (otmp = container->cobj; otmp; otmp = otmp->nobj) { + if (nested && Has_contents(otmp)) + count += count_contents(otmp, nested, quantity, everything); + if (everything || otmp->unpaid) + count += quantity ? otmp->quan : 1L; } return count; } diff --git a/src/objnam.c b/src/objnam.c index 7eec819e9..ed3bab967 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -736,14 +736,15 @@ register struct obj *obj; if (obj->greased) Strcat(prefix, "greased "); if (cknown && Has_contents(obj)) { - struct obj *curr; - long itemcount = 0L; + /* we count all objects (obj->quantity); perhaps we should + count seperate stacks instead (or even introduce a user + preference option to choose between the two alternatives) + since it's somewhat odd so see "containing 1002 items" + when there are 2 scrolls plus 1000 gold pieces */ + long itemcount = count_contents(obj, FALSE, TRUE, TRUE); - /* Count the number of contained objects */ - for (curr = obj->cobj; curr; curr = curr->nobj) - itemcount += curr->quan; Sprintf(eos(bp), " containing %ld item%s", - itemcount, plur(itemcount)); + itemcount, plur(itemcount)); } switch(obj->oclass) { diff --git a/src/shk.c b/src/shk.c index 59701b45f..2823935f8 100644 --- a/src/shk.c +++ b/src/shk.c @@ -2876,9 +2876,15 @@ xchar x, y; if (short_funds) offer = shkmoney; if (!sell_response) { - only_partially_your_contents = (container && - contained_cost(obj, shkp, 0L, FALSE, FALSE) != - contained_cost(obj, shkp, 0L, FALSE, TRUE)); + long yourc = 0L, shksc; + + if (container) { + /* number of items owned by shk */ + shksc = count_contents(obj, TRUE, TRUE, FALSE); + /* number of items owned by you (total - shksc) */ + yourc = count_contents(obj, TRUE, TRUE, TRUE) - shksc; + only_partially_your_contents = shksc && yourc; + } /* " offers * for ..." query formatting. Normal item(s): @@ -2895,22 +2901,26 @@ xchar x, y; Your container: "... your . Sell it?" "... your and its contents. Sell them?" + "... your and item inside. Sell them?" "... your and items inside. Sell them?" Shk's container: - (empty case won't happen--nothing to sell) - "... the contents of the . Sell them?" + "... your item in the . Sell it?" "... your items in the . Sell them?" */ Sprintf(qbuf, "%s offers%s %ld gold piece%s for %s%s ", shkname(shkp), short_funds ? " only" : "", offer, plur(offer), - (cltmp && !ltmp) ? (only_partially_your_contents ? - "your items in " : the_contents_of) : "", + (cltmp && !ltmp) ? + ((yourc == 1L) ? "your item in " : + "your items in ") : "", obj->unpaid ? "the" : "your"); - one = (obj->quan == 1L && !cltmp); + one = obj->unpaid ? (yourc == 1L) : + (obj->quan == 1L && !cltmp); Sprintf(qsfx, "%s. Sell %s?", (cltmp && ltmp) ? (only_partially_your_contents ? - " and items inside" : and_its_contents) : "", + ((yourc == 1L) ? " and item inside" : + " and items inside") : + and_its_contents) : "", one ? "it" : "them"); (void)safe_qbuf(qbuf, qbuf, qsfx, obj, xname, simpleonames, @@ -2932,7 +2942,7 @@ xchar x, y; pay(-offer, shkp); shk_names_obj(shkp, obj, (sell_how != SELL_NORMAL) ? (!ltmp && cltmp && only_partially_your_contents) ? - "sold some items inside %s for %ld gold pieces%s.%s" : + "sold some items inside %s for %ld gold piece%s.%s" : "sold %s for %ld gold piece%s.%s" : "relinquish %s and receive %ld gold piece%s in compensation.%s", offer, "");