From 699a25c00b2534383b4ee947b74497203b8c539d Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 11 Apr 2022 17:53:09 -0700 Subject: [PATCH] shop repair revisited This repair behavior should be closer to the orginal, except without the old sequencing issues. --- include/extern.h | 1 - src/shk.c | 33 ++++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/extern.h b/include/extern.h index 186d67144..03495599a 100644 --- a/include/extern.h +++ b/include/extern.h @@ -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 *); diff --git a/src/shk.c b/src/shk.c index 6927a3c47..2f80059ce 100644 --- 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); + } } } -- 2.50.0