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.
This commit is contained in:
PatR
2019-06-23 18:48:13 -07:00
parent 68d28bd748
commit 87be6fad43
+20 -16
View File
@@ -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) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2009. */ /*-Copyright (c) Robert Patrick Rankin, 2009. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -669,7 +669,6 @@ xchar x, y;
char tryct = 0; char tryct = 0;
/* pick a random direction from x, y and search for goodpos() */ /* pick a random direction from x, y and search for goodpos() */
do { do {
random_dir(ox, oy, &nx, &ny); random_dir(ox, oy, &nx, &ny);
} while (!goodpos(nx, ny, worm, 0) && (tryct++ < 50)); } while (!goodpos(nx, ny, worm, 0) && (tryct++ < 50));
@@ -700,21 +699,26 @@ xchar x, y;
STATIC_OVL STATIC_OVL
void void
random_dir(x, y, nx, ny) random_dir(x, y, nx, ny)
register xchar x, y; xchar x, y;
register xchar *nx, *ny; xchar *nx, *ny;
{ {
*nx = x; *nx = x + (x > 1 /* extreme left ? */
*ny = y; ? (x < COLNO - 1 /* extreme right ? */
? (rn2(3) - 1) /* neither so +1, 0, or -1 */
*nx += (x > 1 /* extreme left ? */ : -rn2(2)) /* right edge, use -1 or 0 */
? (x < COLNO /* extreme right ? */ : rn2(2)); /* left edge, use 0 or 1 */
? (rn2(3) - 1) /* neither so +1, 0, or -1 */ if (*nx != x) /* if x has changed, do same thing with y */
: -rn2(2)) /* 0, or -1 */ *ny = y + (y > 0 /* y==0 is ok (x==0 is not) */
: rn2(2)); /* 0, or 1 */ ? (y < ROWNO - 1
? (rn2(3) - 1)
*ny += (*nx == x /* same kind of thing with y */ : -rn2(2))
? (y > 1 ? (y < ROWNO ? (rn2(2) ? 1 : -1) : -1) : 1) : rn2(2));
: (y > 1 ? (y < ROWNO ? (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 */ /* for size_monst(cmd.c) to support #stats */