Monster ranged attacks and staying away from hero

Move the check for monsters that want to stay away from hero
due to having a ranged attack into a separate function.

Add monsters with polearms and breath attacks to it.
Monsters with breath attacks stay away only if they haven't
used their breath recently, or if they are injured.
This commit is contained in:
Pasi Kallinen
2021-01-06 14:38:22 +02:00
parent c6306e1117
commit bc8dd92621
4 changed files with 38 additions and 12 deletions

View File

@@ -12,6 +12,7 @@ static int FDECL(disturb, (struct monst *));
static void FDECL(release_hero, (struct monst *));
static void FDECL(distfleeck, (struct monst *, int *, int *, int *));
static int FDECL(m_arrival, (struct monst *));
static boolean FDECL(m_balks_at_approaching, (struct monst *));
static boolean FDECL(stuff_prevents_passage, (struct monst *));
static int FDECL(vamp_shift, (struct monst *, struct permonst *,
BOOLEAN_P));
@@ -847,6 +848,36 @@ xchar nix,niy;
return FALSE;
}
/* does monster want to avoid you? */
static boolean
m_balks_at_approaching(mtmp)
struct monst *mtmp;
{
/* peaceful, far away, or can't see you */
if (mtmp->mpeaceful
|| (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) >= 5*5)
|| !m_canseeu(mtmp))
return FALSE;
/* has ammo+launcher or can spit */
if (m_has_launcher_and_ammo(mtmp)
|| attacktype(mtmp->data, AT_SPIT))
return TRUE;
/* is using a polearm and in range */
if (MON_WEP(mtmp) && is_pole(MON_WEP(mtmp))
&& dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= MON_POLE_DIST)
return TRUE;
/* breath attack, and hp loss or breath not used */
if (attacktype(mtmp->data, AT_BREA)
&& ((mtmp->mhp < (mtmp->mhpmax+1) / 3)
|| !mtmp->mspec_used))
return TRUE;
return FALSE;
}
/* Return values:
* 0: did not move, but can still attack and do other stuff.
* 1: moved, possibly can attack.
@@ -1015,11 +1046,8 @@ register int after;
> ((ygold = findgold(g.invent)) ? ygold->quan : 0L))))
appr = -1;
/* hostiles with ranged weapons or spit attack try to stay away */
if (!mtmp->mpeaceful
&& (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) < 5*5)
&& m_canseeu(mtmp) &&
(m_has_launcher_and_ammo(mtmp) || attacktype(mtmp->data, AT_SPIT)))
/* hostiles with ranged weapon or attack try to stay away */
if (m_balks_at_approaching(mtmp))
appr = -1;
if (!should_see && can_track(ptr)) {

View File

@@ -13,10 +13,6 @@ static int FDECL(m_lined_up, (struct monst *, struct monst *));
#define URETREATING(x, y) \
(distmin(u.ux, u.uy, x, y) > distmin(u.ux0, u.uy0, x, y))
#define POLE_LIM 5 /* How far monsters can use pole-weapons */
#define PET_MISSILE_RANGE2 36 /* Square of distance within which pets shoot */
/*
* Keep consistent with breath weapons in zap.c, and AD_* in monattk.h.
*/
@@ -910,7 +906,7 @@ struct monst *mtmp;
if (otmp != MON_WEP(mtmp))
return; /* polearm must be wielded */
if (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) > POLE_LIM
if (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) > MON_POLE_DIST
|| !couldsee(mtmp->mx, mtmp->my))
return; /* Out of range, or intervening wall */