]> granicus.if.org Git - nethack/commitdiff
still more shop shared wall
authorPatR <rankin@nethack.org>
Tue, 7 Feb 2023 22:02:06 +0000 (14:02 -0800)
committerPatR <rankin@nethack.org>
Tue, 7 Feb 2023 22:02:06 +0000 (14:02 -0800)
Neither my fix for #969 nor the followup by entrez dealt with this:
if you were in one shop and dug the wall it shared with another shop,
sometimes the shopkeeper for the room your were in would teleport to
you and demand payment--or attack if you lacked funds--other times the
one from the far room would do so.  For the latter, if you maneuvered
to the gap in the wall (possibly declining to die if angry shopkeeper
managed to kill you) you would get "this shop is deserted" (which is
accurate) but if you subsequently died there, you could get "Welcome
to so-and-so's shop" when the shopkeeper who abandoned her shop was
returned to occupancy after one of them took possession of invent.
And the welcome message might come from the shop that hadn't been
deserted and that you had never left.  (Perhaps always from that one;
I'm not sure.)

Possibly the shopkeeper for the room you're in should get priority
when demanding payment for repairs so that the other one won't
abandon the far shop, but I didn't attempt to tackle that.  This
just suppresses room entry messages when returning the shopkeeper to
her shop if the game is ending.

Not fixed, but amusing:  in one of the tests, the 'far' shopkeeper
who had teleported into the near shop to demand payment for the dug
wall picked up an item from the near shop (in the case I noticed, a
hardware store shk picked up a food ration; just an ordinary item
owned by the stop) while pursuing me to the wall gap.  One shk was
stealing from the other.  :-)

src/shk.c

index 13b6fc7c4594f82fbcc3d338f51a6105900dbc9c..8747d1331d4a19397cad72bc56c94ddd565a6693 100644 (file)
--- a/src/shk.c
+++ b/src/shk.c
@@ -624,13 +624,14 @@ deserted_shop(/*const*/ char* enterstring)
           !n ? "deserted" : "untended");
 }
 
+/* called from check_special_room(hack.c) */
 void
-u_entered_shop(charenterstring)
+u_entered_shop(char *enterstring)
 {
-    register int rt;
-    register struct monst *shkp;
-    register struct eshk *eshkp;
     static char empty_shops[5];
+    struct monst *shkp;
+    struct eshk *eshkp;
+    int rt;
 
     if (!*enterstring)
         return;
@@ -638,8 +639,8 @@ u_entered_shop(char* enterstring)
     shkp = shop_keeper(*enterstring);
     if (!shkp) {
         if (!strchr(empty_shops, *enterstring)
-            && in_rooms(u.ux, u.uy, SHOPBASE)
-                   != in_rooms(u.ux0, u.uy0, SHOPBASE))
+            && (in_rooms(u.ux, u.uy, SHOPBASE)
+                != in_rooms(u.ux0, u.uy0, SHOPBASE)))
             deserted_shop(enterstring);
         Strcpy(empty_shops, u.ushops);
         u.ushops[0] = '\0';
@@ -911,15 +912,20 @@ shopper_financial_report(void)
         }
 }
 
+/* 1: shopkeeper is currently in her shop or its boundary; 0: not */
 int
-inhishop(register struct monst* mtmp)
+inhishop(struct monst *shkp)
 {
-    struct eshk *eshkp = ESHK(mtmp);
+    char *shkrooms;
+    struct eshk *eshkp = ESHK(shkp);
 
-    return (strchr(in_rooms(mtmp->mx, mtmp->my, SHOPBASE), eshkp->shoproom)
-            && on_level(&eshkp->shoplevel, &u.uz));
+    if (!on_level(&eshkp->shoplevel, &u.uz))
+        return FALSE;
+    shkrooms = in_rooms(shkp->mx, shkp->my, SHOPBASE);
+    return (strchr(shkrooms, eshkp->shoproom) != 0);
 }
 
+/* return the shopkeeper for rooms[rmno-2]; returns Null if there isn't one */
 struct monst *
 shop_keeper(char rmno)
 {
@@ -4279,7 +4285,7 @@ shk_move(struct monst *shkp)
     return z;
 }
 
-/* called after shopkeeper moves, in case themove causes re-entry into shop */
+/* called after shopkeeper moves, in case move causes re-entry into shop */
 void
 after_shk_move(struct monst *shkp)
 {
@@ -4288,7 +4294,9 @@ after_shk_move(struct monst *shkp)
     if (eshkp->bill_p == (struct bill_x *) -1000 && inhishop(shkp)) {
         /* reset bill_p, need to re-calc player's occupancy too */
         eshkp->bill_p = &eshkp->bill[0];
-        check_special_room(FALSE);
+        /* only re-check occupancy if game hasn't just ended */
+        if (!gp.program_state.gameover)
+            check_special_room(FALSE);
     }
 }
 
@@ -4301,7 +4309,7 @@ is_fshk(struct monst *mtmp)
 
 /* You are digging in the shop. */
 void
-shopdig(register int fall)
+shopdig(int fall)
 {
     struct monst *shkp = shop_keeper(*u.ushops);
     int lang;