From 87be6fad432f8a17a23214f1974f0b40b133aa86 Mon Sep 17 00:00:00 2001 From: PatR Date: Sun, 23 Jun 2019 18:48:13 -0700 Subject: [PATCH] worm segment placement random_dir() for picking a spot to put a segment of a long worm's tail (when it is being placed on the map, perhaps after teleport, not when movement allows it to grow) had mistakes in three of the four compass directions. The one for the top of the map was benign; it just neglected to use the top row (#0). But it could pick a value off the edge of the map for bottom and right or both. This doesn't explain a couple of long worm [segment] oddities on the Astral level because that level doesn't go all the way to the edge. --- src/worm.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/worm.c b/src/worm.c index 80d644499..1d7dd8ad2 100644 --- a/src/worm.c +++ b/src/worm.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 worm.c $NHDT-Date: 1543892216 2018/12/04 02:56:56 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.28 $ */ +/* NetHack 3.6 worm.c $NHDT-Date: 1561340880 2019/06/24 01:48:00 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.30 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2009. */ /* NetHack may be freely redistributed. See license for details. */ @@ -669,7 +669,6 @@ xchar x, y; char tryct = 0; /* pick a random direction from x, y and search for goodpos() */ - do { random_dir(ox, oy, &nx, &ny); } while (!goodpos(nx, ny, worm, 0) && (tryct++ < 50)); @@ -700,21 +699,26 @@ xchar x, y; STATIC_OVL void random_dir(x, y, nx, ny) -register xchar x, y; -register xchar *nx, *ny; +xchar x, y; +xchar *nx, *ny; { - *nx = x; - *ny = y; - - *nx += (x > 1 /* extreme left ? */ - ? (x < COLNO /* extreme right ? */ - ? (rn2(3) - 1) /* neither so +1, 0, or -1 */ - : -rn2(2)) /* 0, or -1 */ - : rn2(2)); /* 0, or 1 */ - - *ny += (*nx == x /* same kind of thing with y */ - ? (y > 1 ? (y < ROWNO ? (rn2(2) ? 1 : -1) : -1) : 1) - : (y > 1 ? (y < ROWNO ? (rn2(3) - 1) : -rn2(2)) : rn2(2))); + *nx = x + (x > 1 /* extreme left ? */ + ? (x < COLNO - 1 /* extreme right ? */ + ? (rn2(3) - 1) /* neither so +1, 0, or -1 */ + : -rn2(2)) /* right edge, use -1 or 0 */ + : rn2(2)); /* left edge, use 0 or 1 */ + if (*nx != x) /* if x has changed, do same thing with y */ + *ny = y + (y > 0 /* y==0 is ok (x==0 is not) */ + ? (y < ROWNO - 1 + ? (rn2(3) - 1) + : -rn2(2)) + : rn2(2)); + else /* when x has remained the same, force y to change */ + *ny = y + (y > 0 + ? (y < ROWNO - 1 + ? (rn2(2) ? 1 : -1) /* not at edge, so +1 or -1 */ + : -1) /* bottom, use -1 */ + : 1); /* top, use +1 */ } /* for size_monst(cmd.c) to support #stats */