]> granicus.if.org Git - nethack/commitdiff
shop repair revisited
authorPatR <rankin@nethack.org>
Tue, 12 Apr 2022 00:53:09 +0000 (17:53 -0700)
committerPatR <rankin@nethack.org>
Tue, 12 Apr 2022 00:53:09 +0000 (17:53 -0700)
This repair behavior should be closer to the orginal, except without
the old sequencing issues.

include/extern.h
src/shk.c

index 186d671446e40986386392e783040e4d92fa7df4..03495599a42e61dc51d84e5192c8653398ea525a 100644 (file)
@@ -2437,7 +2437,6 @@ extern void sellobj(struct obj *, xchar, xchar);
 extern int doinvbill(int);
 extern struct monst *shkcatch(struct obj *, xchar, xchar);
 extern void add_damage(xchar, xchar, long);
-extern int repair_damage(struct monst *, struct damage *);
 extern void fix_shop_damage(void);
 extern int shk_move(struct monst *);
 extern void after_shk_move(struct monst *);
index 6927a3c475474172e39cf6c00246b0cb3c442877..2f80059ce8e01f8bdb6c327d6ccb0c9cd501e486 100644 (file)
--- a/src/shk.c
+++ b/src/shk.c
@@ -19,9 +19,7 @@ static void kops_gone(boolean);
 #define ANGRY(mon) (!NOTANGRY(mon))
 #define IS_SHOP(x) (g.rooms[x].rtype >= SHOPBASE)
 
-#define muteshk(shkp)                       \
-    (helpless(shkp) \
-     || (shkp)->data->msound <= MS_ANIMAL)
+#define muteshk(shkp) (helpless(shkp) || (shkp)->data->msound <= MS_ANIMAL)
 
 extern const struct shclass shtypes[]; /* defined in shknam.c */
 
@@ -67,6 +65,7 @@ static void shk_fixes_damage(struct monst *);
 static xchar *litter_getpos(int *, xchar, xchar, struct monst *);
 static void litter_scatter(xchar *, int, xchar, xchar, struct monst *);
 static void litter_newsyms(xchar *, xchar, xchar);
+static int repair_damage(struct monst *, struct damage *, boolean);
 static void sub_one_frombill(struct obj *, struct monst *);
 static void add_one_tobill(struct obj *, boolean, struct monst *);
 static void dropped_container(struct obj *, struct monst *, boolean);
@@ -3651,7 +3650,7 @@ shk_fixes_damage(struct monst *shkp)
     else if (!Deaf && shk_closeby)
         You_hear("someone muttering an incantation.");
 
-    (void) repair_damage(shkp, dam);
+    (void) repair_damage(shkp, dam, FALSE);
 
     discard_damage_struct(dam);
 }
@@ -3768,17 +3767,18 @@ litter_newsyms(xchar *litter, xchar x, xchar y)
  * 0: repair postponed, 1: silent repair (no messages), 2: normal repair
  * 3: untrap
  */
-int
+static int
 repair_damage(
     struct monst *shkp,
-    struct damage *tmp_dam)
+    struct damage *tmp_dam,
+    boolean catchup)
 {
     xchar x, y;
     xchar *litter;
     struct obj *otmp;
     struct trap *ttmp;
     int k, disposition = 1;
-    boolean catchup, stop_picking = FALSE;
+    boolean stop_picking = FALSE;
 
     if (!repairable_damage(tmp_dam, shkp))
         return 0;
@@ -3881,11 +3881,26 @@ void
 fix_shop_damage(void)
 {
     struct monst *shkp;
+    struct damage *damg, *nextdamg;
+
+    /* if this level has no shop damage, there's nothing to do */
+    if (!g.level.damagelist)
+        return;
 
+    /* go through all shopkeepers on the level */
     for (shkp = next_shkp(fmon, FALSE); shkp;
          shkp = next_shkp(shkp->nmon, FALSE)) {
-        if (shkp->mcanmove && inhishop(shkp))
-            shk_fixes_damage(shkp);
+        /* if this shopkeeper isn't in his shop or can't move, skip */
+        if (shk_impaired(shkp))
+            continue;
+        /* go through all damage data trying to have this shopkeeper
+           fix it; repair_damage() will only make repairs for damage
+           matching shop controlled by specified shopkeeper */
+        for (damg = g.level.damagelist; damg; damg = nextdamg) {
+            nextdamg = damg->next;
+            if (repair_damage(shkp, damg, TRUE))
+                discard_damage_struct(damg);
+        }
     }
 }