From ff4a59ef23c7462b190fca1c1ff952edd65aa11e Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sat, 9 Jan 2016 12:06:50 +0200 Subject: [PATCH] Fix bz258: Covetous monsters malfunction when there are no upstairs Make the monsters pick downstairs/ladders if the branch builds up (like Sokoban), otherwise try upstairs/ladders. --- src/wizard.c | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/src/wizard.c b/src/wizard.c index facacc799..830aa0a60 100644 --- a/src/wizard.c +++ b/src/wizard.c @@ -306,11 +306,49 @@ register struct monst *mtmp; return dstrat; } +void +choose_stairs(sx, sy) +xchar *sx; +xchar *sy; +{ + xchar x = 0, y = 0; + + if (builds_up(&u.uz)) { + if (xdnstair) { + x = xdnstair; + y = ydnstair; + } else if (xdnladder) { + x = xdnladder; + y = ydnladder; + } + } else { + if (xupstair) { + x = xupstair; + y = yupstair; + } else if (xupladder) { + x = xupladder; + y = yupladder; + } + } + + if (!x && sstairs.sx) { + x = sstairs.sx; + y = sstairs.sy; + } + + if (x && y) { + *sx = x; + *sy = y; + } + +} + int tactics(mtmp) register struct monst *mtmp; { unsigned long strat = strategy(mtmp); + xchar sx, sy; mtmp->mstrategy = (mtmp->mstrategy & (STRAT_WAITMASK | STRAT_APPEARMSG)) | strat; @@ -318,15 +356,14 @@ register struct monst *mtmp; switch (strat) { case STRAT_HEAL: /* hide and recover */ /* if wounded, hole up on or near the stairs (to block them) */ - /* unless, of course, there are no stairs (e.g. endlevel) */ + choose_stairs(&sx, &sy); mtmp->mavenge = 1; /* covetous monsters attack while fleeing */ if (In_W_tower(mtmp->mx, mtmp->my, &u.uz) - || (mtmp->iswiz && !xupstair && !mon_has_amulet(mtmp))) { + || (mtmp->iswiz && !sx && !mon_has_amulet(mtmp))) { if (!rn2(3 + mtmp->mhp / 10)) (void) rloc(mtmp, TRUE); - } else if (xupstair - && (mtmp->mx != xupstair || mtmp->my != yupstair)) { - (void) mnearto(mtmp, xupstair, yupstair, TRUE); + } else if (sx && (mtmp->mx != sx || mtmp->my != sy)) { + (void) mnearto(mtmp, sx, sy, TRUE); } /* if you're not around, cast healing spells */ if (distu(mtmp->mx, mtmp->my) > (BOLT_LIM * BOLT_LIM)) -- 2.40.0