Split leprechaun avoidance into separate function

This commit is contained in:
Pasi Kallinen
2021-12-28 19:11:30 +02:00
parent 2b197fbc33
commit ea0c488178

View File

@@ -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 */