From 2a50fb1845c5dc22a3405f895cf1e5920af1e727 Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 16 Nov 2019 13:42:25 -0800 Subject: [PATCH 1/2] place_monster() debugging Show more information if place_monster() detects something wrong. I don't know whether it will actually be useful. --- include/extern.h | 3 ++- src/do_name.c | 38 +++++++++++++++++++++++++++++++++++++- src/steed.c | 16 ++++++++++------ 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/include/extern.h b/include/extern.h index d4a4b432d..0a2fa788d 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1,4 +1,4 @@ -/* NetHack 3.6 extern.h $NHDT-Date: 1573869062 2019/11/16 01:51:02 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.740 $ */ +/* NetHack 3.6 extern.h $NHDT-Date: 1573940539 2019/11/16 21:42:19 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.741 $ */ /* Copyright (c) Steve Creps, 1988. */ /* NetHack may be freely redistributed. See license for details. */ @@ -450,6 +450,7 @@ E char *FDECL(Amonnam, (struct monst *)); E char *FDECL(a_monnam, (struct monst *)); E char *FDECL(distant_monnam, (struct monst *, int, char *)); E char *FDECL(mon_nam_too, (struct monst *, struct monst *)); +E char *FDECL(minimal_monnam, (struct monst *, BOOLEAN_P)); E char *FDECL(rndmonnam, (char *)); E const char *FDECL(hcolor, (const char *)); E const char *NDECL(rndcolor); diff --git a/src/do_name.c b/src/do_name.c index 999fe2055..c8965a706 100644 --- a/src/do_name.c +++ b/src/do_name.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 do_name.c $NHDT-Date: 1560611967 2019/06/15 15:19:27 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.149 $ */ +/* NetHack 3.6 do_name.c $NHDT-Date: 1573940540 2019/11/16 21:42:20 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.150 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Pasi Kallinen, 2018. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1978,6 +1978,42 @@ struct monst *mon, *other_mon; return outbuf; } +/* for debugging messages, where data might be suspect and we aren't + taking what the hero does or doesn't know into consideration */ +char * +minimal_monnam(mon, ckloc) +struct monst *mon; +boolean ckloc; +{ + struct permonst *ptr; + char *outbuf = nextmbuf(); + + if (!mon) { + Strcpy(outbuf, "[Null monster]"); + } else if ((ptr = mon->data) == 0) { + Strcpy(outbuf, "[Null mon->data]"); + } else if (ptr < &mons[0]) { + Sprintf(outbuf, "[Invalid mon->data %s < %s]", + fmt_ptr((genericptr_t) mon->data), + fmt_ptr((genericptr_t) &mons[0])); + } else if (ptr >= &mons[NUMMONS]) { + Sprintf(outbuf, "[Invalid mon->data %s >= %s]", + fmt_ptr((genericptr_t) mon->data), + fmt_ptr((genericptr_t) &mons[NUMMONS])); + } else if (ckloc && ptr == &mons[PM_LONG_WORM] + && level.monsters[mon->mx][mon->my] != mon) { + Sprintf(outbuf, "%s <%d,%d>", + mons[PM_LONG_WORM_TAIL].mname, mon->mx, mon->my); + } else { + Sprintf(outbuf, "%s%s <%d,%d>", + mon->mtame ? "tame " : mon->mpeaceful ? "peaceful " : "", + mon->data->mname, mon->mx, mon->my); + if (mon->cham != NON_PM) + Sprintf(eos(outbuf), "{%s}", mons[mon->cham].mname); + } + return outbuf; +} + /* fake monsters used to be in a hard-coded array, now in a data file */ STATIC_OVL char * bogusmon(buf, code) diff --git a/src/steed.c b/src/steed.c index c7540a28a..2f09e5896 100644 --- a/src/steed.c +++ b/src/steed.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 steed.c $NHDT-Date: 1559670610 2019/06/04 17:50:10 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.66 $ */ +/* NetHack 3.6 steed.c $NHDT-Date: 1573940541 2019/11/16 21:42:21 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.67 $ */ /* Copyright (c) Kevin Hugo, 1998-1999. */ /* NetHack may be freely redistributed. See license for details. */ @@ -742,6 +742,8 @@ place_monster(mon, x, y) struct monst *mon; int x, y; { + struct monst *othermon; + const char *monnm, *othnm; char buf[QBUFSZ]; buf[0] = '\0'; @@ -749,8 +751,8 @@ int x, y; vault guards (either living or dead) are parked at <0,0> */ if (!isok(x, y) && (x != 0 || y != 0 || !mon->isgd)) { describe_level(buf); - impossible("trying to place monster at <%d,%d> mstate:%lx on %s", - x, y, mon->mstate, buf); + impossible("trying to place %s at <%d,%d> mstate:%lx on %s", + minimal_monnam(mon, TRUE), x, y, mon->mstate, buf); x = y = 0; } if (mon == u.usteed @@ -762,10 +764,12 @@ int x, y; mon->mstate, buf); return; } - if (level.monsters[x][y]) { + if ((othermon = level.monsters[x][y]) != 0) { describe_level(buf); - impossible("placing monster over another at <%d,%d>, mstates:%lx %lx on %s?", - x, y, level.monsters[x][y]->mstate, mon->mstate, buf); + monnm = minimal_monnam(mon, FALSE); + othnm = (mon != othermon) ? minimal_monnam(othermon, TRUE) : "itself"; + impossible("placing %s over %s at <%d,%d>, mstates:%lx %lx on %s?", + monnm, othnm, x, y, othermon->mstate, mon->mstate, buf); } mon->mx = x, mon->my = y; level.monsters[x][y] = mon; From 145ba8ec12a97fec407eb2f2d41c52e678dabc55 Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 16 Nov 2019 13:47:21 -0800 Subject: [PATCH 2/2] ball&chain reformatting This has been sitting around for a while. --- src/ball.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/ball.c b/src/ball.c index 9a309676a..c02e6d2f5 100644 --- a/src/ball.c +++ b/src/ball.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 ball.c $NHDT-Date: 1570566373 2019/10/08 20:26:13 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.43 $ */ +/* NetHack 3.6 ball.c $NHDT-Date: 1573940835 2019/11/16 21:47:15 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.44 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) David Cohrs, 2006. */ /* NetHack may be freely redistributed. See license for details. */ @@ -178,7 +178,7 @@ check_restriction(restriction) int restriction; { boolean ret = FALSE; - + if (!bcrestriction || (restriction == override_restriction)) ret = TRUE; else @@ -194,8 +194,7 @@ placebc() #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED) char panicbuf[BUFSZ]; - Sprintf(panicbuf, - "placebc denied, restriction in effect"); + Sprintf(panicbuf, "placebc denied, restriction in effect"); paniclog("placebc", panicbuf); #endif return; @@ -239,10 +238,9 @@ int pin; #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED) char panicbuf[BUFSZ]; - Sprintf(panicbuf, - "lift_covet_and_placebc denied, %s", - (pin != bcrestriction) ? - "pin mismatch" : "restriction in effect"); + Sprintf(panicbuf, "lift_covet_and_placebc denied, %s", + (pin != bcrestriction) ? "pin mismatch" + : "restriction in effect"); paniclog("placebc", panicbuf); #endif return; @@ -265,8 +263,7 @@ int linenum; #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED) char panicbuf[BUFSZ]; - Sprintf(panicbuf, - "Placebc denied to %s:%d, restricted by %s:%d", + Sprintf(panicbuf, "Placebc denied to %s:%d, restricted by %s:%d", funcnm, linenum, bcpbreadcrumbs.funcnm, bcpbreadcrumbs.linenum); paniclog("Placebc", panicbuf); @@ -296,10 +293,9 @@ int linenum; if (bcrestriction) { char panicbuf[BUFSZ]; - Sprintf(panicbuf, - "Unplacebc from %s:%d, when restricted to %s:%d", - funcnm, linenum, - bcubreadcrumbs.funcnm, bcubreadcrumbs.linenum); + Sprintf(panicbuf, "Unplacebc from %s:%d, when restricted to %s:%d", + funcnm, linenum, + bcubreadcrumbs.funcnm, bcubreadcrumbs.linenum); paniclog("Unplacebc", panicbuf); } bcpbreadcrumbs.in_effect = FALSE; @@ -342,8 +338,8 @@ int linenum; #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED) char panicbuf[BUFSZ]; - Sprintf(panicbuf, - "Lift_covet_and_placebc denied to %s:%d, restricted by %s:%d", + Sprintf(panicbuf, + "Lift_covet_and_placebc denied to %s:%d, restricted by %s:%d", funcnm, linenum, bcpbreadcrumbs.funcnm, bcpbreadcrumbs.linenum); paniclog("Lift_covet_and_placebc", panicbuf);