From 175e5b67f53eac64f6391862f6b882be626a2aab Mon Sep 17 00:00:00 2001 From: "nethack.rankin" Date: Fri, 15 Dec 2006 02:36:58 +0000 Subject: [PATCH] accessible() There's some discussion in the newsgroup about an engraving bug, and while verifying that it's reproducible I've come across an unintentional change between the current code and 3.4.3. A recent change made engraving use accessible(), and that routine wasn't yielding an appropriate value when applied to a raised drawbridge if the terrain in front of it was ice or floor (ie, moat or lava had been filled in). Several places which used the ACCESSIBLE() macro instead of the function suffer from same problem. This doesn't attempt to address the newsgroup bug (which is that an engraving written on a lowered bridge transfers to the underlying terrain if the bridge is raised, even when that terrain is water or lava; the converse case applies too, an engraving on the ground gets transfered to the bridge when it lowers). --- src/engrave.c | 2 +- src/mail.c | 4 ++-- src/monmove.c | 21 ++++++++++++++++----- src/steed.c | 5 ++--- src/teleport.c | 7 +++---- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/engrave.c b/src/engrave.c index 39405ffaf..c8b919027 100644 --- a/src/engrave.c +++ b/src/engrave.c @@ -499,7 +499,7 @@ doengrave() if(Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)/* in bubble */) { You_cant("write in thin air!"); return(0); - } else if (closed_door(u.ux, u.uy) || !accessible(u.ux, u.uy)) { + } else if (!accessible(u.ux, u.uy)) { /* stone, tree, wall, secret corridor, pool, lava, bars */ You_cant("write here."); return 0; diff --git a/src/mail.c b/src/mail.c index 50f4c89e9..34999b7b9 100644 --- a/src/mail.c +++ b/src/mail.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)mail.c 3.5 2006/04/14 */ +/* SCCS Id: @(#)mail.c 3.5 2006/12/13 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -228,7 +228,7 @@ md_stop(stopp, startp) for (y = u.uy-1; y <= u.uy+1; y++) { if (!isok(x, y) || (x == u.ux && y == u.uy)) continue; - if (ACCESSIBLE(levl[x][y].typ) && !MON_AT(x,y)) { + if (accessible(x, y) && !MON_AT(x,y)) { distance = dist2(x,y,startp->x,startp->y); if (min_distance < 0 || distance < min_distance || (distance == min_distance && rn2(2))) { diff --git a/src/monmove.c b/src/monmove.c index 2deb55104..d2c4a5c4a 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)monmove.c 3.5 2006/08/16 */ +/* SCCS Id: @(#)monmove.c 3.5 2006/12/13 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1324,7 +1324,18 @@ boolean accessible(x, y) register int x, y; { - return((boolean)(ACCESSIBLE(levl[x][y].typ) && !closed_door(x, y))); + int levtyp = levl[x][y].typ; + + if (levtyp == DRAWBRIDGE_UP) { + /* use underlying terrain in front of closed drawbridge */ + switch (levl[x][y].drawbridgemask & DB_UNDER) { + case DB_MOAT: levtyp = MOAT; break; + case DB_LAVA: levtyp = LAVAPOOL; break; + case DB_ICE: levtyp = ICE; break; + case DB_FLOOR: levtyp = ROOM; break; + } + } + return (boolean)(ACCESSIBLE(levtyp) && !closed_door(x, y)); } /* decide where the monster thinks you are standing */ @@ -1388,9 +1399,9 @@ register struct monst *mtmp; || (disp != 2 && mx == mtmp->mx && my == mtmp->my) || ((mx != u.ux || my != u.uy) && !passes_walls(mtmp->data) && - (!ACCESSIBLE(levl[mx][my].typ) || - (closed_door(mx, my) && - !(can_ooze(mtmp) || can_fog(mtmp))))) + !(accessible(mx, my) || + (closed_door(mx, my) && + (can_ooze(mtmp) || can_fog(mtmp))))) || !couldsee(mx, my)); } else { found_you: diff --git a/src/steed.c b/src/steed.c index 091c708f2..6bd27b4cb 100644 --- a/src/steed.c +++ b/src/steed.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)steed.c 3.5 2006/10/11 */ +/* SCCS Id: @(#)steed.c 3.5 2006/12/13 */ /* Copyright (c) Kevin Hugo, 1998-1999. */ /* NetHack may be freely redistributed. See license for details. */ @@ -437,8 +437,7 @@ int forceit; for (y = u.uy-1; y <= u.uy+1; y++) { if (!isok(x, y) || (x == u.ux && y == u.uy)) continue; - if (ACCESSIBLE(levl[x][y].typ) && - !MON_AT(x,y) && !closed_door(x,y)) { + if (accessible(x, y) && !MON_AT(x,y)) { distance = distu(x,y); if (min_distance < 0 || distance < min_distance || (distance == min_distance && rn2(2))) { diff --git a/src/teleport.c b/src/teleport.c index 7d3f58189..5101c0f84 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)teleport.c 3.5 2006/08/05 */ +/* SCCS Id: @(#)teleport.c 3.5 2006/12/13 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -73,13 +73,12 @@ unsigned gpflags; return (is_flyer(mdat) || likes_lava(mdat)); } if (passes_walls(mdat) && may_passwall(x,y)) return TRUE; + if (amorphous(mdat) && closed_door(x,y)) return TRUE; } - if (!ACCESSIBLE(levl[x][y].typ)) { + if (!accessible(x, y)) { if (!(is_pool(x,y) && ignorewater)) return FALSE; } - if (closed_door(x, y) && (!mdat || !amorphous(mdat))) - return FALSE; if (sobj_at(BOULDER, x, y) && (!mdat || !throws_rocks(mdat))) return FALSE; return TRUE; -- 2.40.0