From a2a79a1250fce40d297316de17ba7da20de8f506 Mon Sep 17 00:00:00 2001 From: Kestrel Gregorich-Trevor Date: Thu, 20 Jan 2022 12:31:10 -0600 Subject: [PATCH] Clean up set_apparxy() This commit removes the gotos from set_apparxy, making it easier to read. It also cuts out at 1-2 variable assignments on certain calls, so technically it is an efficiency win as well. --- src/monmove.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/monmove.c b/src/monmove.c index 9608fdb52..bfa42ca8d 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -1828,13 +1828,14 @@ set_apparxy(register struct monst* mtmp) */ /* pet knows your smell; grabber still has hold of you */ - if (mtmp->mtame || mtmp == u.ustuck) - goto found_you; - - /* monsters which know where you are don't suddenly forget, + if (mtmp->mtame || mtmp == u.ustuck || + /* monsters which know where you are don't suddenly forget, if you haven't moved away */ - if (u_at(mx, my)) - goto found_you; + u_at(mx,my)) { + mtmp->mux = u.ux; + mtmp->muy = u.uy; + return; + } notseen = (!mtmp->mcansee || (Invis && !perceives(mtmp->data))); notthere = (Displaced && mtmp->data != &mons[PM_DISPLACER_BEAST]); @@ -1850,8 +1851,11 @@ set_apparxy(register struct monst* mtmp) } else { disp = 0; } - if (!disp) - goto found_you; + if (!disp) { + mtmp->mux = u.ux; + mtmp->muy = u.uy; + return; + } /* without something like the following, invisibility and displacement are too powerful */ @@ -1861,8 +1865,11 @@ set_apparxy(register struct monst* mtmp) register int try_cnt = 0; do { - if (++try_cnt > 200) - goto found_you; /* punt */ + if (++try_cnt > 200) { + mx = u.ux; + my = u.uy; + break; /* punt */ + } mx = u.ux - disp + rn2(2 * disp + 1); my = u.uy - disp + rn2(2 * disp + 1); } while (!isok(mx, my) @@ -1873,7 +1880,6 @@ set_apparxy(register struct monst* mtmp) && (can_ooze(mtmp) || can_fog(mtmp))))) || !couldsee(mx, my)); } else { - found_you: mx = u.ux; my = u.uy; }