From 0ad8a192bfd6e7f674475763cd7a51642918aa7d Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 24 Dec 2018 17:50:21 -0800 Subject: [PATCH 1/5] formatting: parse_conf_file() --- src/files.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/files.c b/src/files.c index 3dd137743..a73349c3e 100644 --- a/src/files.c +++ b/src/files.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 files.c $NHDT-Date: 1543395733 2018/11/28 09:02:13 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.244 $ */ +/* NetHack 3.6 files.c $NHDT-Date: 1545702598 2018/12/25 01:49:58 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.248 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Derek S. Ray, 2015. */ /* NetHack may be freely redistributed. See license for details. */ @@ -3051,7 +3051,8 @@ boolean FDECL((*proc), (char *)); *ep = '\0'; /* trim off spaces at end of line */ - while (--ep >= inbuf && (*ep == ' ' || *ep == '\t' || *ep == '\r')) + while (--ep >= inbuf + && (*ep == ' ' || *ep == '\t' || *ep == '\r')) *ep = '\0'; if (!config_error_nextline(inbuf)) { @@ -3194,9 +3195,7 @@ int which_set; config_error_add("Missing finish for symset \"%s\"", symset[which_set].name ? symset[which_set].name : "unknown"); - config_error_done(); - return 1; } From 02cfd131ee3ab94e2437e8f23877631a2bb16213 Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 24 Dec 2018 18:43:51 -0800 Subject: [PATCH 2/5] status gold vs symset:Blank Symset:Blank sets all the map symbols (except STRANGE_OBJECT) to . The status lines for !STATUS_HILITES force status to use '$' instead of ' ' for the prefix before ":1234" for gold, but the status lines for STATUS_HILITES did not. tty ended up with ":1234" for gold. win32 and curses both ignore the prefix and construct their own, but since win32 uses the map symbol for that it must also be ending up with ":1234" (I assume; I haven't seen it). curses is forcing '$' for the prefix, even on the rogue level. This attempts to fix win32 without be able to test the result. I've left curses alone. --- doc/fixes36.2 | 2 ++ src/botl.c | 31 ++++++++++----------- win/tty/wintty.c | 66 ++++++++++++++++++++++++--------------------- win/win32/mswproc.c | 21 +++++++++------ 4 files changed, 64 insertions(+), 56 deletions(-) diff --git a/doc/fixes36.2 b/doc/fixes36.2 index dbe5691c9..14f45097e 100644 --- a/doc/fixes36.2 +++ b/doc/fixes36.2 @@ -337,6 +337,8 @@ a config file line with OPTIONS=symset:default, roguesymset:RogueEpyx during the processing of symset:default done after RogueEpyx had already been processed avoid potential segfault when doing 'more information' lookup +when built with STATUS_HILITES enabled (the default), gold on status line + was missing '$' prefix for symset:Blank tty: turn off an optimization that is the suspected cause of Windows reported partial status lines following level changes tty: ensure that current status fields are always copied to prior status diff --git a/src/botl.c b/src/botl.c index 4fea3b64b..d8244734d 100644 --- a/src/botl.c +++ b/src/botl.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 botl.c $NHDT-Date: 1544917592 2018/12/15 23:46:32 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.131 $ */ +/* NetHack 3.6 botl.c $NHDT-Date: 1545705812 2018/12/25 02:43:32 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.132 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Michael Allison, 2006. */ /* NetHack may be freely redistributed. See license for details. */ @@ -38,6 +38,14 @@ get_strength_str() return buf; } +void +check_gold_symbol() +{ + nhsym goldch = showsyms[COIN_CLASS + SYM_OFF_O]; + + iflags.invis_goldsym = (goldch <= (nhsym) ' '); +} + char * do_statusline1() { @@ -87,17 +95,6 @@ do_statusline1() return newbot1; } -void -check_gold_symbol() -{ - int goldch, goldoc; - unsigned int goldos; - int goldglyph = objnum_to_glyph(GOLD_PIECE); - - (void) mapglyph(goldglyph, &goldch, &goldoc, &goldos, 0, 0); - iflags.invis_goldsym = ((char) goldch <= ' '); -} - char * do_statusline2() { @@ -126,7 +123,7 @@ do_statusline2() money = 0L; /* ought to issue impossible() and then discard gold */ Sprintf(eos(dloc), "%s:%-2ld", /* strongest hero can lift ~300000 gold */ (iflags.in_dumplog || iflags.invis_goldsym) ? "$" - : encglyph(objnum_to_glyph(GOLD_PIECE)), + : encglyph(objnum_to_glyph(GOLD_PIECE)), min(money, 999999L)); dln = strlen(dloc); /* '$' encoded as \GXXXXNNNN is 9 chars longer than display will need */ @@ -623,7 +620,8 @@ bot_via_windowport() * sequence. */ Sprintf(blstats[idx][BL_GOLD].val, "%s:%ld", - encglyph(objnum_to_glyph(GOLD_PIECE)), + (iflags.in_dumplog || iflags.invis_goldsym) ? "$" + : encglyph(objnum_to_glyph(GOLD_PIECE)), blstats[idx][BL_GOLD].a.a_long); valset[BL_GOLD] = TRUE; /* indicate val already set */ @@ -727,8 +725,7 @@ boolean *valsetlist; * * Also, even if context.rndencode hasn't changed and the * gold amount itself hasn't changed, the glyph portion of the - * encoding may have changed if a new symset was put into - * effect. + * encoding may have changed if a new symset was put into effect. * * \GXXXXNNNN:25 * XXXX = the context.rndencode portion @@ -751,7 +748,7 @@ boolean *valsetlist; if (!update_all && !chg) { reset = hilite_reset_needed(prev, bl_hilite_moves); if (reset) - curr->time = prev->time = 0L; + curr->time = prev->time = 0L; } #endif diff --git a/win/tty/wintty.c b/win/tty/wintty.c index ca9d60c1d..6116c467f 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 wintty.c $NHDT-Date: 1544919891 2018/12/16 00:24:51 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.189 $ */ +/* NetHack 3.6 wintty.c $NHDT-Date: 1545705819 2018/12/25 02:43:39 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.190 $ */ /* Copyright (c) David Cohrs, 1991 */ /* NetHack may be freely redistributed. See license for details. */ @@ -497,7 +497,7 @@ tty_player_selection() goto give_up; } -makepicks: + makepicks: nextpick = RS_ROLE; do { if (nextpick == RS_ROLE) { @@ -965,7 +965,7 @@ makepicks: tty_display_nhwindow(BASE_WINDOW, FALSE); return; -give_up: + give_up: /* Quit */ if (selected) free((genericptr_t) selected); /* [obsolete] */ @@ -1243,11 +1243,11 @@ tty_askname() } #if defined(UNIX) || defined(VMS) if (c != '-' && c != '@') - if (!(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') && + if (!(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') /* reject leading digit but allow digits elsewhere (avoids ambiguity when character name gets appended to uid to construct save file name) */ - !(c >= '0' && c <= '9' && ct > 0)) + && !(c >= '0' && c <= '9' && ct > 0)) c = '_'; #endif if (ct < (int) (sizeof plname) - 1) { @@ -1478,16 +1478,18 @@ winid window; struct WinDesc *cw; boolean clear; { - if (cw->offx == 0) + if (cw->offx == 0) { if (cw->offy) { tty_curs(window, 1, 0); cl_eos(); - } else if (clear) + } else if (clear) { clear_screen(); - else + } else { docrt(); - else + } + } else { docorner((int) cw->offx, cw->maxrow + 1); + } } STATIC_OVL void @@ -2115,7 +2117,7 @@ struct WinDesc *cw; tty_nhbell(); break; } else if (index(gacc, morc)) { - group_accel: + group_accel: /* group accelerator; for the PICK_ONE case, we know that it matches exactly one item in order to be in gacc[] */ invert_all(window, page_start, page_end, morc); @@ -3396,15 +3398,16 @@ tty_nhgetch() if (WIN_MESSAGE != WIN_ERR && wins[WIN_MESSAGE]) wins[WIN_MESSAGE]->flags &= ~WIN_STOP; if (iflags.debug_fuzzer) { - i = randomkey(); + i = randomkey(); } else { #ifdef UNIX - i = (++nesting == 1) ? tgetch() - : (read(fileno(stdin), (genericptr_t) &nestbuf, 1) - == 1) ? (int) nestbuf : EOF; - --nesting; + i = (++nesting == 1) + ? tgetch() + : (read(fileno(stdin), (genericptr_t) &nestbuf, 1) == 1) + ? (int) nestbuf : EOF; + --nesting; #else - i = tgetch(); + i = tgetch(); #endif } if (!i) @@ -3617,7 +3620,7 @@ static boolean truncation_expected = FALSE; * for all platforms eventually and the conditional * setting below can be removed. */ -static int do_field_opt = +static int do_field_opt = #if defined(DISABLE_TTY_FIELD_OPT) 0; #else @@ -3684,11 +3687,11 @@ boolean enable; * BL_XP, BL_AC, BL_HD, BL_TIME, BL_HUNGER, BL_HP, BL_HPMAX, * BL_LEVELDESC, BL_EXP, BL_CONDITION * -- fldindex could also be BL_FLUSH (-1), which is not really - * a field index, but is a special trigger to tell the + * a field index, but is a special trigger to tell the * windowport that it should output all changes received * to this point. It marks the end of a bot() cycle. * -- fldindex could also be BL_RESET (-3), which is not really - * a field index, but is a special advisory to to tell the + * a field index, but is a special advisory to to tell the * windowport that it should redisplay all its status fields, * even if no changes have been presented to it. * -- ptr is usually a "char *", unless fldindex is BL_CONDITION. @@ -3707,7 +3710,7 @@ boolean enable; * BL_MASK_LEV 0x00000400L * BL_MASK_FLY 0x00000800L * BL_MASK_RIDE 0x00001000L - * -- The value passed for BL_GOLD includes an encoded leading + * -- The value passed for BL_GOLD usually includes an encoded leading * symbol for GOLD "\GXXXXNNNN:nnn". If the window port needs to use * the textual gold amount without the leading "$:" the port will * have to skip past ':' in the passed "ptr" for the BL_GOLD case. @@ -3739,8 +3742,7 @@ unsigned long *colormasks; int i; long *condptr = (long *) ptr; char *text = (char *) ptr; - char *lastchar = (char *) 0; - char *fval = (char *) 0; + char *fval, *lastchar, *p; boolean reset_state = NO_RESET; if ((fldidx < BL_RESET) || (fldidx >= MAXBLSTATS)) @@ -3787,8 +3789,9 @@ unsigned long *colormasks; /* The core botl engine sends a single blank to the window port for carrying-capacity when its unused. Let's suppress that */ - if (fldidx >= 0 && fldidx < MAXBLSTATS && - tty_status[NOW][fldidx].lth == 1 && status_vals[fldidx][0] == ' ') { + if (fldidx >= 0 && fldidx < MAXBLSTATS + && tty_status[NOW][fldidx].lth == 1 + && status_vals[fldidx][0] == ' ') { status_vals[fldidx][0] = '\0'; tty_status[NOW][fldidx].lth = 0; } @@ -3801,7 +3804,8 @@ unsigned long *colormasks; hpbar_percent = percent; hpbar_color = (color & 0x00FF); } - if (iflags.wc2_hitpointbar && (tty_procs.wincap2 & WC2_FLUSH_STATUS) != 0L) { + if (iflags.wc2_hitpointbar + && (tty_procs.wincap2 & WC2_FLUSH_STATUS) != 0L) { tty_status[NOW][BL_TITLE].color = hpbar_color; tty_status[NOW][BL_TITLE].dirty = TRUE; } @@ -3824,7 +3828,9 @@ unsigned long *colormasks; tty_status[NOW][fldidx].lth += 2; /* '[' and ']' */ break; case BL_GOLD: - tty_status[NOW][fldidx].lth -= (10 - 1); /* \GXXXXNNNN counts as 1 */ + /* \GXXXXNNNN counts as 1 */ + if ((p = index(status_vals[fldidx], '\\')) != 0 && p[1] == 'G') + tty_status[NOW][fldidx].lth -= (10 - 1); break; case BL_CAP: fval = status_vals[fldidx]; @@ -3859,7 +3865,7 @@ do_setlast() last_on_row[row] = fld; break; - } + } } STATIC_OVL int @@ -3942,7 +3948,7 @@ int *topsz, *bottomsz; tty_status[NOW][idx].y = row; tty_status[NOW][idx].x = col; - /* On a change to the field length, everything + /* On a change to the field length, everything further to the right must be updated as well */ if (tty_status[NOW][idx].lth != tty_status[BEFORE][idx].lth) update_right = TRUE; @@ -4395,8 +4401,7 @@ render_status(VOID_ARGS) if (coloridx != NO_COLOR && coloridx != CLR_MAX) term_start_color(coloridx); } - tty_putstatusfield(&tty_status[NOW][idx], - text, x, y); + tty_putstatusfield(&tty_status[NOW][idx], text, x, y); if (iflags.hilite_delta) { if (coloridx != NO_COLOR && coloridx != CLR_MAX) term_end_color(); @@ -4445,4 +4450,3 @@ render_status(VOID_ARGS) #endif /* TTY_GRAPHICS */ /*wintty.c*/ - diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index 8393ea3e0..8c37b3fd5 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mswproc.c $NHDT-Date: 1536411259 2018/09/08 12:54:19 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.118 $ */ +/* NetHack 3.6 mswproc.c $NHDT-Date: 1545705822 2018/12/25 02:43:42 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.130 $ */ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ @@ -3084,24 +3084,29 @@ mswin_status_update(int idx, genericptr_t ptr, int chg, int percent, int color, case BL_GOLD: { char buf[BUFSZ]; char *p; + ZeroMemory(buf, sizeof(buf)); - mapglyph(objnum_to_glyph(GOLD_PIECE), &ochar, &ocolor, &ospecial, - 0, 0); + if (iflags.invis_goldsym) + ochar = GOLD_SYM; + else + mapglyph(objnum_to_glyph(GOLD_PIECE), + &ochar, &ocolor, &ospecial, 0, 0); buf[0] = ochar; p = strchr(text, ':'); if (p) { strncpy(buf + 1, p, sizeof(buf) - 2); } else { buf[1] = ':'; - strncpy(buf + 2, text, sizeof(buf) - 2); + strncpy(buf + 2, text, sizeof(buf) - 3); } - - Sprintf(status_field->string, status_field->format ? status_field->format : "%s", buf); + buf[sizeof buf - 1] = '\0'; + Sprintf(status_field->string, + status_field->format ? status_field->format : "%s", buf); nhassert(status_string->str == status_field->string); } break; default: { - Sprintf(status_field->string, status_field->format ? status_field->format : "%s", - text); + Sprintf(status_field->string, + status_field->format ? status_field->format : "%s", text); nhassert(status_string->str == status_field->string); } break; } From 99cd9ea26442f3787a80dc1546994224feda1357 Mon Sep 17 00:00:00 2001 From: PatR Date: Tue, 25 Dec 2018 13:05:35 -0800 Subject: [PATCH 3/5] simplify container_contents() iflags.in_dumplog is accessible even when DUMPLOG is not enabled. --- src/end.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/end.c b/src/end.c index 3803a4366..cb966162f 100644 --- a/src/end.c +++ b/src/end.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 end.c $NHDT-Date: 1545646111 2018/12/24 10:08:31 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.160 $ */ +/* NetHack 3.6 end.c $NHDT-Date: 1545771927 2018/12/25 21:05:27 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.161 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1557,12 +1557,7 @@ boolean identified, all_containers, reportempty; { register struct obj *box, *obj; char buf[BUFSZ]; - boolean cat, - dumping = -#ifdef DUMPLOG - iflags.in_dumplog ? TRUE : -#endif - FALSE; + boolean cat, dumping = iflags.in_dumplog; for (box = list; box; box = box->nobj) { if (Is_container(box) || box->otyp == STATUE) { From f52c7b0de777b93a8eeb14953e9d741b4aa3cfec Mon Sep 17 00:00:00 2001 From: nhmall Date: Tue, 25 Dec 2018 16:34:28 -0500 Subject: [PATCH 4/5] merge fix-up --- src/botl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/botl.c b/src/botl.c index 30b27ae8e..4e4e56394 100644 --- a/src/botl.c +++ b/src/botl.c @@ -585,8 +585,8 @@ bot_via_windowport() Sprintf(g.blstats[idx][BL_GOLD].val, "%s:%ld", (iflags.in_dumplog || iflags.invis_goldsym) ? "$" : encglyph(objnum_to_glyph(GOLD_PIECE)), - blstats[idx][BL_GOLD].a.a_long); - valset[BL_GOLD] = TRUE; /* indicate val already set */ + g.blstats[idx][BL_GOLD].a.a_long); + g.valset[BL_GOLD] = TRUE; /* indicate val already set */ /* Power (magical energy) */ g.blstats[idx][BL_ENE].a.a_int = min(u.uen, 9999); From 3aca92215c66e8fa6b1034e01830d19bf491f5ff Mon Sep 17 00:00:00 2001 From: PatR Date: Tue, 25 Dec 2018 13:48:51 -0800 Subject: [PATCH 5/5] prices of items on shop floor get_cost_of_item() was giving different information from shop #chat when dealing with containers owned by hero containing objects owned by the shop. And when it was legitimately reporting a price of 0, doname_with_price() wasn't reporting 'no charge' for items inside a shop that were owned by hero or that shopkeeper didn't care about. Extend the shop price reveal to far-look, but only when hero and item being examined are inside the same shop. --- doc/fixes36.2 | 4 ++++ src/objnam.c | 11 ++++++++--- src/pager.c | 5 +++-- src/shk.c | 25 ++++++++++--------------- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/doc/fixes36.2 b/doc/fixes36.2 index 14f45097e..2b164de23 100644 --- a/doc/fixes36.2 +++ b/doc/fixes36.2 @@ -303,6 +303,8 @@ limit carrying heavy loads from water to land failing to carry a wished-for item behaved differenctly from dropping one life-saving while weak/starving/fainting boosted nutrition without restoring lost point of strength, making temporary loss be permanent +unlike #chat in a shop, walking on an item in a shop failed to include price + for hero-owned container holding shop-owned items Fixes to Post-3.6.1 Problems that Were Exposed Via git Repository @@ -458,6 +460,8 @@ being trapped (bear trap, web, molten or solidified lava, chained to buried pit ends when either of those starts so doesn't apply) early level traps are sometimes covered by the remains of fake players fake player characters resist Conflict +when inside a shop, far-look now includes shop prices for items marked as + having been seen up close NetHack Community Patches (or Variation) Included diff --git a/src/objnam.c b/src/objnam.c index 6a805852d..597a79249 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 objnam.c $NHDT-Date: 1544520422 2018/12/11 09:27:02 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.230 $ */ +/* NetHack 3.6 objnam.c $NHDT-Date: 1545774525 2018/12/25 21:48:45 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.231 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2011. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1210,10 +1210,15 @@ unsigned doname_flags; obj->unpaid ? "unpaid" : "contents", quotedprice, currency(quotedprice)); } else if (with_price) { - long price = get_cost_of_shop_item(obj); + long price = get_cost_of_shop_item(obj); /* updates obj->ox,oy */ - if (price > 0) + if (price > 0L) Sprintf(eos(bp), " (%ld %s)", price, currency(price)); + else if (obj->no_charge /* only set for items on shop floor */ + && *u.ushops /* but make sure hero is inside same shop */ + && (*in_rooms(u.ux, u.uy, SHOPBASE) + == *in_rooms(obj->ox, obj->oy, SHOPBASE))) + Strcat(bp, " (no charge)"); } if (!strncmp(prefix, "a ", 2)) { /* save current prefix, without "a "; might be empty */ diff --git a/src/pager.c b/src/pager.c index e8748452e..2ae5d8074 100644 --- a/src/pager.c +++ b/src/pager.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 pager.c $NHDT-Date: 1545595360 2018/12/23 20:02:40 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.144 $ */ +/* NetHack 3.6 pager.c $NHDT-Date: 1545774524 2018/12/25 21:48:44 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.145 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2018. */ /* NetHack may be freely redistributed. See license for details. */ @@ -223,7 +223,8 @@ int x, y, glyph; if (otmp) { Strcpy(buf, (otmp->otyp != STRANGE_OBJECT) - ? distant_name(otmp, doname_vague_quan) + ? distant_name(otmp, otmp->dknown ? doname_with_price + : doname_vague_quan) : obj_descr[STRANGE_OBJECT].oc_name); if (fakeobj) dealloc_obj(otmp), otmp = 0; diff --git a/src/shk.c b/src/shk.c index 315de4c1d..9f6715415 100644 --- a/src/shk.c +++ b/src/shk.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 shk.c $NHDT-Date: 1545383616 2018/12/21 09:13:36 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.144 $ */ +/* NetHack 3.6 shk.c $NHDT-Date: 1545774524 2018/12/25 21:48:44 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.145 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -921,7 +921,7 @@ register struct obj *obj, *merge; if (onbill(obj, shkp, TRUE)) break; } - /* sanity check, more or less */ + /* sanity check, in case obj is on bill but not marked 'unpaid' */ if (!shkp) shkp = shop_keeper(*u.ushops); /* @@ -1962,8 +1962,8 @@ unsigned id; return (struct obj *) 0; } -/* Returns the price of an arbitrary item in the shop. - Returns 0 if the item doesn't belong to a shopkeeper. */ +/* Returns the price of an arbitrary item in the shop, + 0 if the item doesn't belong to a shopkeeper or hero is not in the shop. */ long get_cost_of_shop_item(obj) register struct obj *obj; @@ -1972,16 +1972,12 @@ register struct obj *obj; xchar x, y; long cost = 0L; - if (*u.ushops - && obj->oclass != COIN_CLASS + if (*u.ushops && obj->oclass != COIN_CLASS && obj != uball && obj != uchain && get_obj_location(obj, &x, &y, 0) - && (obj->unpaid - || (obj->where == OBJ_FLOOR - && !obj->no_charge && costly_spot(x, y))) - && (shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) != 0 - && inhishop(shkp)) { - cost = obj->quan * get_cost(obj, shkp); + && *in_rooms(u.ux, u.uy, SHOPBASE) == *in_rooms(x, y, SHOPBASE) + && (shkp = shop_keeper(inside_shop(x, y))) != 0 && inhishop(shkp)) { + cost = obj->no_charge ? 0L : obj->quan * get_cost(obj, shkp); if (Has_contents(obj)) cost += contained_cost(obj, shkp, 0L, FALSE, FALSE); } @@ -4168,9 +4164,8 @@ register struct obj *first_obj; for (otmp = first_obj; otmp; otmp = otmp->nexthere) { if (otmp->oclass == COIN_CLASS) continue; - cost = (otmp->no_charge || otmp == uball || otmp == uchain) - ? 0L - : get_cost(otmp, (struct monst *) 0); + cost = (otmp->no_charge || otmp == uball || otmp == uchain) ? 0L + : get_cost(otmp, shkp); contentsonly = !cost; if (Has_contents(otmp)) cost += contained_cost(otmp, shkp, 0L, FALSE, FALSE);