From 3a8971cc17cb5c8ef73ff405eedcc8e2e0bdda1a Mon Sep 17 00:00:00 2001 From: PatR Date: Tue, 9 Jan 2024 12:07:24 -0800 Subject: [PATCH] more invocation handling While testing the wall crumbling message TODO yesterday, I saw a case where the top line of the moat around the invocation area was truncated even through there were 3 lines of map (on a cavernous level rather than maze one) above where it cut off. This improves things although it may not be 100% correct. Picking the invocation position is unchanged, so there should be no risk of it now being positioned too close to the map edge. It's possible that it has been farther away from the edge than necessary though; if so, it will still be. --- src/mklev.c | 25 ++++++++++++++++--------- src/mkmaze.c | 25 ++++++++++++++----------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/mklev.c b/src/mklev.c index ec6c163a6..f80f538fe 100644 --- a/src/mklev.c +++ b/src/mklev.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 mklev.c $NHDT-Date: 1704225560 2024/01/02 19:59:20 $ $NHDT-Branch: keni-luabits2 $:$NHDT-Revision: 1.174 $ */ +/* NetHack 3.7 mklev.c $NHDT-Date: 1704830831 2024/01/09 20:07:11 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.175 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Alex Smith, 2017. */ /* NetHack may be freely redistributed. See license for details. */ @@ -2155,10 +2155,6 @@ mkgrave(struct mkroom *croom) return; } -/* maze levels have slightly different constraints from normal levels */ -#define x_maze_min 2 -#define y_maze_min 2 - /* * Major level transmutation: add a set of stairs (to the Sanctum) after * an earthquake that leaves behind a new topology, centered at inv_pos. @@ -2270,13 +2266,22 @@ mkinvpos(coordxy x, coordxy y, int dist) boolean make_rocks; register struct rm *lev = &levl[x][y]; struct monst *mon; + /* maze levels have slightly different constraints from normal levels; + these are also defined in mkmaze.c and may not be appropriate for + mazes with corridors wider than 1 or for cavernous levels */ +#define x_maze_min 2 +#define y_maze_min 2 /* clip at existing map borders if necessary */ - if (!within_bounded_area(x, y, x_maze_min + 1, y_maze_min + 1, - gx.x_maze_max - 1, gy.y_maze_max - 1)) { + if (!within_bounded_area(x, y, x_maze_min, y_maze_min, + gx.x_maze_max, gy.y_maze_max)) { /* outermost 2 columns and/or rows may be truncated due to edge */ - if (dist < (7 - 2)) - panic("mkinvpos: <%d,%d> (%d) off map edge!", x, y, dist); + if (dist < (7 - 2)) { /* panic() or impossible() */ + void (*errfunc)(const char *, ...) PRINTF_F(1, 2); + + errfunc = !isok(x, y) ? panic : impossible; + (*errfunc)("mkinvpos: <%d,%d> (%d) off map edge!", x, y, dist); + } return; } @@ -2347,6 +2352,8 @@ mkinvpos(coordxy x, coordxy y, int dist) /* display new value of position; could have a monster/object on it */ newsym(x, y); +#undef x_maze_min +#undef y_maze_min } /* reduces clutter in mkinvokearea() while avoiding potential static analyzer diff --git a/src/mkmaze.c b/src/mkmaze.c index ef7d5d8d9..e98bd015d 100644 --- a/src/mkmaze.c +++ b/src/mkmaze.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 mkmaze.c $NHDT-Date: 1648064596 2022/03/23 19:43:16 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.133 $ */ +/* NetHack 3.7 mkmaze.c $NHDT-Date: 1704830842 2024/01/09 20:07:22 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.158 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Pasi Kallinen, 2018. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1013,18 +1013,21 @@ pick_vibrasquare_location(void) coordxy x, y; stairway *stway; int trycnt = 0; + /* these are also defined in mklev.c and they may not be appropriate + for mazes with corridors wider than 1 or for cavernous levels */ #define x_maze_min 2 #define y_maze_min 2 -/* - * Pick a position where the stairs down to Moloch's Sanctum - * level will ultimately be created. At that time, an area - * will be altered: walls removed, moat and traps generated, - * boulders destroyed. The position picked here must ensure - * that that invocation area won't extend off the map. - * - * We actually allow up to 2 squares around the usual edge of - * the area to get truncated; see mkinvokearea(mklev.c). - */ + + /* + * Pick a position where the stairs down to Moloch's Sanctum + * level will ultimately be created. At that time, an area + * will be altered: walls removed, moat and traps generated, + * boulders destroyed. The position picked here must ensure + * that that invocation area won't extend off the map. + * + * We actually allow up to 2 squares around the usual edge of + * the area to get truncated; see mkinvokearea(mklev.c). + */ #define INVPOS_X_MARGIN (6 - 2) #define INVPOS_Y_MARGIN (5 - 2) #define INVPOS_DISTANCE 11