From ea0c4881784fbc4a6d01ece0528a204518990f15 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Tue, 28 Dec 2021 19:11:30 +0200 Subject: [PATCH] Split leprechaun avoidance into separate function --- src/monmove.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/monmove.c b/src/monmove.c index 345010ec9..2cb5825e0 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -15,6 +15,7 @@ static int m_arrival(struct monst *); static boolean holds_up_web(xchar, xchar); static int count_webbing_walls(xchar, xchar); static boolean soko_allow_web(struct monst *); +static boolean leppie_avoidance(struct monst *); static boolean m_balks_at_approaching(struct monst *); static boolean stuff_prevents_passage(struct monst *); static int vamp_shift(struct monst *, struct permonst *, boolean); @@ -856,6 +857,21 @@ m_digweapon_check(struct monst* mtmp, xchar nix, xchar niy) return FALSE; } +/* does leprechaun want to avoid the hero? */ +static boolean +leppie_avoidance(struct monst *mtmp) +{ + struct obj *lepgold, *ygold; + + if (mtmp->data == &mons[PM_LEPRECHAUN] + && ((lepgold = findgold(mtmp->minvent)) + && (lepgold->quan + > ((ygold = findgold(g.invent)) ? ygold->quan : 0L)))) + return TRUE; + + return FALSE; +} + /* does monster want to avoid you? */ static boolean m_balks_at_approaching(struct monst* mtmp) @@ -1100,7 +1116,6 @@ m_move(register struct monst* mtmp, register int after) if (mtmp->mconf || (u.uswallow && mtmp == u.ustuck)) { appr = 0; } else { - struct obj *lepgold, *ygold; boolean should_see = (couldsee(omx, omy) && (levl[gx][gy].lit || !levl[omx][omy].lit) && (dist2(omx, omy, gx, gy) <= 36)); @@ -1114,10 +1129,7 @@ m_move(register struct monst* mtmp, register int after) || ptr->mlet == S_LIGHT) && !rn2(3))) appr = 0; - if (monsndx(ptr) == PM_LEPRECHAUN && (appr == 1) - && ((lepgold = findgold(mtmp->minvent)) - && (lepgold->quan - > ((ygold = findgold(g.invent)) ? ygold->quan : 0L)))) + if (appr == 1 && leppie_avoidance(mtmp)) appr = -1; /* hostiles with ranged weapon or attack try to stay away */