]> granicus.if.org Git - nethack/commitdiff
Fix billing/credit when hero nests their containers on a shop floor
authorTung Nguyen <tungtn3@gmail.com>
Wed, 9 Mar 2016 04:18:15 +0000 (15:18 +1100)
committerTung Nguyen <tungtn3@gmail.com>
Fri, 11 Mar 2016 07:35:26 +0000 (18:35 +1100)
This fixes a bug where the hero could accidentally donate the contents
of their bag to a shopkeeper if they put it in another bag on the shop
floor that also belonged to the hero.  To reproduce:

 1. Drop a sack on the floor, but don't sell it.
 2. Get another sack and put in hero-owned objects.
 3. Put the sack with objects into the sack on the shop floor.
 4. Take out the sack with the objects from the sack on the shop floor.

The shopkeeper will claim you owe them for the objects in the sack, and
view the contents of the sack will show them as belonging to the
shopkeeper.

This fix is what those previous fixes for `SELL_DONTSELL` were for.

Based on DynaHack commit f91ce0b (Fix billing/credit when hero nests
their containers on a shop floor) by me.

src/pickup.c

index 38c7aeea75cff65450b0ffb2542f7d9e2281cad1..a332e57f6849c463e5ee513cfe8f3ca96e2d4e08 100644 (file)
@@ -2025,15 +2025,14 @@ register struct obj *obj;
         (void) snuff_lit(obj);
 
     if (floor_container && costly_spot(u.ux, u.uy)) {
-        if (obj->oclass == COIN_CLASS) {
-            ; /* defer gold until after put-in message */
-        } else if (current_container->no_charge && !obj->unpaid) {
-            /* don't sell when putting the item into your own container */
-            obj->no_charge = 1;
-        } else {
+        /* defer gold until after put-in message */
+        if (obj->oclass != COIN_CLASS) {
             /* sellobj() will take an unpaid item off the shop bill */
             was_unpaid = obj->unpaid ? TRUE : FALSE;
-            sellobj_state(SELL_DELIBERATE);
+            /* don't sell when putting the item into your own container,
+             * but handle billing correctly */
+            sellobj_state(current_container->no_charge
+                          ? SELL_DONTSELL : SELL_DELIBERATE);
             sellobj(obj, u.ux, u.uy);
             sellobj_state(SELL_NORMAL);
         }