From 80703597c0df3bc6378d584fbd83b3ec763d8820 Mon Sep 17 00:00:00 2001 From: Sean Hunt Date: Sun, 24 May 2015 21:40:32 +0900 Subject: [PATCH] Clean up a rare corner case with mnearto(). With this fix, if the second mnearto fails, we don't accidentally strand othermon at (0,0). --- src/mon.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/mon.c b/src/mon.c index 189ae52b8..7ebc6693b 100644 --- a/src/mon.c +++ b/src/mon.c @@ -2289,7 +2289,7 @@ boolean move_other; /* make sure mtmp gets to x, y! so move m_at(x, y) */ coord mm; if ((mtmp->mx == x) && (mtmp->my == y)) - return (FALSE); + return FALSE; if (move_other && (othermon = m_at(x, y))) { if (othermon->wormno) @@ -2307,7 +2307,7 @@ boolean move_other; /* make sure mtmp gets to x, y! so move m_at(x, y) */ * no end of trouble. */ if (!enexto(&mm, newx, newy, mtmp->data)) - return (FALSE); + return FALSE; newx = mm.x; newy = mm.y; } @@ -2315,13 +2315,19 @@ boolean move_other; /* make sure mtmp gets to x, y! so move m_at(x, y) */ rloc_to(mtmp, newx, newy); if (move_other && othermon) { + xchar oldx = othermon->mx, oldy = othermon->my; othermon->mx = othermon->my = 0; - (void) mnearto(othermon, x, y, FALSE); + if (!mnearto(othermon, x, y, FALSE)) { + othermon->mx = oldx; + othermon->my = oldy; + return FALSE; + } + if ((othermon->mx != x) || (othermon->my != y)) - return (TRUE); + return TRUE; } - return (FALSE); + return FALSE; } /* monster responds to player action; not the same as a passive attack */