fix #H30 - rn2(0) from off by 1 bug in special level door creation
From a bug report, the placement
of random doors by the code that loads special levels would attempt to
evaluate rn2(0) and either get a divide by zero crash (normal build) or an
impossible warning (DEBUG enabled when compiing rnd.c, done automatically
when BETA is defined). The problem was only noticable for random door in
a 1x1 room; none of our distributed levels specify such a thing so regular
users won't have encountered this bug. It's a one line fix.
Altar placement in temples also had a quirk of a similar nature. It
wouldn't trigger rn2(0) problems but would always place the altar to left
of mid-point in rooms with even width and above the center point in ones
with even height. Now the placement is randomized so that sometimes it'll
be to the right and/or below mid-point in such cases.
This also simplifies a couple other instances of similar expressions
that I spotted.
This commit is contained in:
@@ -181,6 +181,8 @@ only count successful statue creations against the monster limit in sp_lev.c
|
|||||||
unseen wand of striking zapped by unseen monster became known if it hit a door
|
unseen wand of striking zapped by unseen monster became known if it hit a door
|
||||||
tweak knight quest messages
|
tweak knight quest messages
|
||||||
guidebook grammar bits
|
guidebook grammar bits
|
||||||
|
special level loader wasn't able to place random door in 1x1 room; could
|
||||||
|
trigger divide-by-0 crash for user-developed custom levels
|
||||||
|
|
||||||
|
|
||||||
Platform- and/or Interface-Specific Fixes
|
Platform- and/or Interface-Specific Fixes
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* SCCS Id: @(#)mklev.c 3.5 2001/11/29 */
|
/* SCCS Id: @(#)mklev.c 3.5 2006/01/28 */
|
||||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
|
|
||||||
@@ -83,8 +83,8 @@ xchar xl,yl,xh,yh;
|
|||||||
{
|
{
|
||||||
register xchar x, y;
|
register xchar x, y;
|
||||||
|
|
||||||
x = (xl == xh) ? xl : (xl + rn2(xh-xl+1));
|
x = rn1(xh - xl + 1, xl);
|
||||||
y = (yl == yh) ? yl : (yl + rn2(yh-yl+1));
|
y = rn1(yh - yl + 1, yl);
|
||||||
if(okdoor(x, y))
|
if(okdoor(x, y))
|
||||||
goto gotit;
|
goto gotit;
|
||||||
|
|
||||||
|
|||||||
20
src/mkroom.c
20
src/mkroom.c
@@ -1,4 +1,4 @@
|
|||||||
/* SCCS Id: @(#)mkroom.c 3.5 2005/03/12 */
|
/* SCCS Id: @(#)mkroom.c 3.5 2006/01/28 */
|
||||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
|
|
||||||
@@ -483,11 +483,19 @@ shrine_pos(roomno)
|
|||||||
int roomno;
|
int roomno;
|
||||||
{
|
{
|
||||||
static coord buf;
|
static coord buf;
|
||||||
|
int delta;
|
||||||
struct mkroom *troom = &rooms[roomno - ROOMOFFSET];
|
struct mkroom *troom = &rooms[roomno - ROOMOFFSET];
|
||||||
|
|
||||||
buf.x = troom->lx + ((troom->hx - troom->lx) / 2);
|
/* if width and height are odd, placement will be the exact center;
|
||||||
buf.y = troom->ly + ((troom->hy - troom->ly) / 2);
|
if either or both are even, center point is a hypothetical spot
|
||||||
return(&buf);
|
between map locations and placement will be adjacent to that */
|
||||||
|
delta = troom->hx - troom->lx;
|
||||||
|
buf.x = troom->lx + delta / 2;
|
||||||
|
if ((delta % 2) && rn2(2)) buf.x++;
|
||||||
|
delta = troom->hy - troom->ly;
|
||||||
|
buf.y = troom->ly + delta / 2;
|
||||||
|
if ((delta % 2) && rn2(2)) buf.y++;
|
||||||
|
return &buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC_OVL void
|
STATIC_OVL void
|
||||||
@@ -555,14 +563,14 @@ int
|
|||||||
somex(croom)
|
somex(croom)
|
||||||
register struct mkroom *croom;
|
register struct mkroom *croom;
|
||||||
{
|
{
|
||||||
return rn2(croom->hx-croom->lx+1) + croom->lx;
|
return rn1(croom->hx - croom->lx + 1, croom->lx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
somey(croom)
|
somey(croom)
|
||||||
register struct mkroom *croom;
|
register struct mkroom *croom;
|
||||||
{
|
{
|
||||||
return rn2(croom->hy-croom->ly+1) + croom->ly;
|
return rn1(croom->hy - croom->ly + 1, croom->ly);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean
|
boolean
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* SCCS Id: @(#)sp_lev.c 3.5 2006/01/02 */
|
/* SCCS Id: @(#)sp_lev.c 3.5 2006/01/28 */
|
||||||
/* Copyright (c) 1989 by Jean-Christophe Collet */
|
/* Copyright (c) 1989 by Jean-Christophe Collet */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
|
|
||||||
@@ -620,7 +620,8 @@ struct mkroom *broom;
|
|||||||
dpos = dd->pos;
|
dpos = dd->pos;
|
||||||
if (dpos == -1) /* The position is RANDOM */
|
if (dpos == -1) /* The position is RANDOM */
|
||||||
dpos = rn2((dwall == W_WEST || dwall == W_EAST) ?
|
dpos = rn2((dwall == W_WEST || dwall == W_EAST) ?
|
||||||
(broom->hy - broom->ly) : (broom->hx - broom->lx));
|
(broom->hy - broom->ly + 1) :
|
||||||
|
(broom->hx - broom->lx + 1));
|
||||||
|
|
||||||
/* Convert wall and pos into an absolute coordinate! */
|
/* Convert wall and pos into an absolute coordinate! */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user