fix #K4172 - selling all into container

When using #loot to put items into a shop-owned container on a shop's
floor, you are asked "Sell it? [ynaq] (n)" for each item, but the 'a'
and 'q' choices only worked as y or n for the current item.  By the
next one, the preferred answer had been reset to default and ynaq was
asked again.

Set a flag in use_container() to have in_container() set the sell vs
don't sell state for the first item but not for any others.  Reset
the state at the end of use_container() instead of after each item in
in_container().

This bug was present in 3.6.x, also in 3.4.3, and probably earlier.
This commit is contained in:
PatR
2024-07-03 23:28:05 -07:00
parent 7fa328fda3
commit 10c85d68bb
4 changed files with 23 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1445 $ $NHDT-Date: 1718303201 2024/06/13 18:26:41 $
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1450 $ $NHDT-Date: 1720074479 2024/07/04 06:27:59 $
General Fixes and Modified Features
-----------------------------------
@@ -1431,6 +1431,12 @@ buying shop items which include any unpaid ones inside containers would reveal
recent change to pay via menu made the problem become more visible;
shopping has been changed such that buying anything that is inside a
container requires that the whole container be bought as a unit
using #loot -> 'i'n to put multiple items into a shop-owned container would
ask whether to sell each item to the shop, and was prepared to accept
'a' to sell the current one plus all the rest beyond it, or to accept
'q' to not sell the current one or any beyond it, but the sell vs
don't-sell state was being reset for each item so 'a' and 'q' didn't
stick beyond the current one
Fixes to 3.7.0-x General Problems Exposed Via git Repository

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 decl.h $NHDT-Date: 1706079834 2024/01/24 07:03:54 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.355 $ */
/* NetHack 3.7 decl.h $NHDT-Date: 1720074483 2024/07/04 06:28:03 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.373 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2007. */
/* NetHack may be freely redistributed. See license for details. */
@@ -937,6 +937,7 @@ struct instance_globals_s {
boolean simple_options_help;
/* pickup.c */
boolean sellobj_first; /* True => need sellobj_state(); False => don't */
boolean shop_filter;
/* pline.c */

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 decl.c $NHDT-Date: 1706079841 2024/01/24 07:04:01 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.314 $ */
/* NetHack 3.7 decl.c $NHDT-Date: 1720074480 2024/07/04 06:28:00 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.334 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2009. */
/* NetHack may be freely redistributed. See license for details. */
@@ -792,6 +792,7 @@ static const struct instance_globals_s g_init_s = {
(struct menucoloring *) 0, /* save_colorings */
FALSE, /* simple_options_help */
/* pickup.c */
FALSE, /* sellobj_first */
FALSE, /* shop_filter */
/* pline.c */
#ifdef DUMPLOG_CORE

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 pickup.c $NHDT-Date: 1707521383 2024/02/09 23:29:43 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.370 $ */
/* NetHack 3.7 pickup.c $NHDT-Date: 1720074481 2024/07/04 06:28:01 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.374 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
@@ -2608,12 +2608,14 @@ in_container(struct obj *obj)
if (obj->oclass != COIN_CLASS) {
/* sellobj() will take an unpaid item off the shop bill */
was_unpaid = obj->unpaid ? TRUE : FALSE;
/* don't sell when putting the item into your own container,
* but handle billing correctly */
sellobj_state(gc.current_container->no_charge
? SELL_DONTSELL : SELL_DELIBERATE);
if (gs.sellobj_first) {
/* don't sell when putting the item into your own container,
but handle billing correctly */
sellobj_state(gc.current_container->no_charge
? SELL_DONTSELL : SELL_DELIBERATE);
gs.sellobj_first = FALSE;
}
sellobj(obj, u.ux, u.uy);
sellobj_state(SELL_NORMAL);
}
}
if (Icebox && !age_is_relative(obj)) {
@@ -2645,8 +2647,8 @@ in_container(struct obj *obj)
/* if carried, shop goods will be flagged 'unpaid' and obfree() will
handle bill issues, but if on floor, we need to put them on bill
before deleting them (non-shop items will be flagged 'no_charge') */
if (floor_container
&& costly_spot(gc.current_container->ox, gc.current_container->oy)) {
if (floor_container && costly_spot(gc.current_container->ox,
gc.current_container->oy)) {
struct obj save_no_charge;
save_no_charge.no_charge = gc.current_container->no_charge;
@@ -2943,6 +2945,7 @@ use_container(
long loss;
ga.abort_looting = FALSE;
gs.sellobj_first = TRUE; /* in_container() should call sellobj_state() */
emptymsg[0] = '\0';
if (!u_handsy())
@@ -3176,6 +3179,7 @@ use_container(
update_inventory();
}
sellobj_state(SELL_NORMAL); /* in case in_container() set it */
*objp = gc.current_container; /* might have become null */
if (gc.current_container)
gc.current_container = 0; /* avoid hanging on to stale pointer */