From: Pasi Kallinen Date: Wed, 6 Jan 2021 12:38:22 +0000 (+0200) Subject: Monster ranged attacks and staying away from hero X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bc8dd92621d4ed216eb12b6852c829c92bf4d2ea;p=nethack 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. --- diff --git a/doc/fixes37.0 b/doc/fixes37.0 index c2f1a0be9..541b95521 100644 --- a/doc/fixes37.0 +++ b/doc/fixes37.0 @@ -134,8 +134,7 @@ male hero poly'd into nymph chooses charm vs seduce message based on being male rather than on all nymphs being female but charm message was using hardcoded pronouns She,her for target monster--wrong for male target and noticable if " finishes taking off his suit" is given -hostile monsters with a spit attack or launcher and ammo try to stay away - from melee range +hostile monsters with a ranged attack try to stay away from melee range allow displacing peaceful creatures unicorn horns don't restore attribute loss anymore when a shop is changed from food to health food, change room type to match diff --git a/include/hack.h b/include/hack.h index aa9b57106..ca8b855c4 100644 --- a/include/hack.h +++ b/include/hack.h @@ -475,6 +475,9 @@ enum bodypart_types { #define TELEDS_ALLOW_DRAG 1 #define TELEDS_TELEPORT 2 +#define MON_POLE_DIST 5 /* How far monsters can use pole-weapons */ +#define PET_MISSILE_RANGE2 36 /* Square of distance within which pets shoot */ + /* * option setting restrictions */ diff --git a/src/monmove.c b/src/monmove.c index dc64ae9d2..85e970dda 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -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)) { diff --git a/src/mthrowu.c b/src/mthrowu.c index bba8fd939..c545eca7f 100644 --- a/src/mthrowu.c +++ b/src/mthrowu.c @@ -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 */