]> granicus.if.org Git - nethack/commitdiff
Monster ranged attacks and staying away from hero
authorPasi Kallinen <paxed@alt.org>
Wed, 6 Jan 2021 12:38:22 +0000 (14:38 +0200)
committerPasi Kallinen <paxed@alt.org>
Wed, 6 Jan 2021 12:38:39 +0000 (14:38 +0200)
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.

doc/fixes37.0
include/hack.h
src/monmove.c
src/mthrowu.c

index c2f1a0be9e2dce6a27dd226bba5c95298c373d4c..541b955218a28c18654e659c0650063197ac8e9d 100644 (file)
@@ -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 "<mon> 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
index aa9b571063973be53f03a80ca054cb8224ff3292..ca8b855c4fe00b8278f0e0e4c1dd567a0db75d28 100644 (file)
@@ -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
  */
index dc64ae9d2657904dd8edbb7f7f96f7799092f801..85e970dda7cd2ad77203263968401f5736cadf11 100644 (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)) {
index bba8fd939d156e6c9a72d06903b9bf95b0d53c77..c545eca7f1a8cf48670a218c02cceac3591bdeca 100644 (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 */