]> granicus.if.org Git - nethack/commitdiff
Unify ad_legs
authorPasi Kallinen <paxed@alt.org>
Tue, 1 Dec 2020 09:10:54 +0000 (11:10 +0200)
committerPasi Kallinen <paxed@alt.org>
Fri, 4 Dec 2020 07:30:20 +0000 (09:30 +0200)
include/extern.h
src/mhitm.c
src/mhitu.c
src/uhitm.c

index f4d5c0fcf578b377d7cfe1d54ebce2f16505341e..b72d73296edd2bacd6bdae4ea6571d458d9e4c84 100644 (file)
@@ -2790,6 +2790,7 @@ E void FDECL(mhitm_ad_ston, (struct monst *, struct attack *, struct monst *, st
 E void FDECL(mhitm_ad_were, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_heal, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_stun, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
+E void FDECL(mhitm_ad_legs, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E boolean FDECL(do_stone_u, (struct monst *));
 E void FDECL(do_stone_mon, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E int FDECL(damageum, (struct monst *, struct attack *, int));
index decb034b8a56ab75b452a0bd7978f88451677907..b892e56c3f2d5510c9cb0d0fe50648285508126c 100644 (file)
@@ -955,11 +955,10 @@ int dieroll;
             return mhm.hitflags;
         break;
     case AD_LEGS:
-        if (magr->mcan) {
-            mhm.damage = 0;
-            break;
-        }
-        goto physical;
+        mhitm_ad_legs(magr, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
+        break;
     case AD_WERE:
         mhitm_ad_were(magr, mattk, mdef, &mhm);
         if (mhm.done)
index a67f78e384a702525d0f307f4bcfba45f25aad51..030c98ee955d0f7e4d69bd5a1b42920fe97972f6 100644 (file)
@@ -1073,46 +1073,11 @@ register struct attack *mattk;
         if (mhm.done)
             return mhm.hitflags;
         break;
-    case AD_LEGS: {
-        long side = rn2(2) ? RIGHT_SIDE : LEFT_SIDE;
-        const char *sidestr = (side == RIGHT_SIDE) ? "right" : "left",
-                   *Monst_name = Monnam(mtmp), *leg = body_part(LEG);
-
-        /* This case is too obvious to ignore, but Nethack is not in
-         * general very good at considering height--most short monsters
-         * still _can_ attack you when you're flying or mounted.
-         */
-        if ((u.usteed || Levitation || Flying) && !is_flyer(mtmp->data)) {
-            pline("%s tries to reach your %s %s!", Monst_name, sidestr, leg);
-            mhm.damage = 0;
-        } else if (mtmp->mcan) {
-            pline("%s nuzzles against your %s %s!", Monnam(mtmp),
-                  sidestr, leg);
-            mhm.damage = 0;
-        } else {
-            if (uarmf) {
-                if (rn2(2) && (uarmf->otyp == LOW_BOOTS
-                               || uarmf->otyp == IRON_SHOES)) {
-                    pline("%s pricks the exposed part of your %s %s!",
-                          Monst_name, sidestr, leg);
-                } else if (!rn2(5)) {
-                    pline("%s pricks through your %s boot!", Monst_name,
-                          sidestr);
-                } else {
-                    pline("%s scratches your %s boot!", Monst_name,
-                          sidestr);
-                    mhm.damage = 0;
-                    break;
-                }
-            } else
-                pline("%s pricks your %s %s!", Monst_name, sidestr, leg);
-
-            set_wounded_legs(side, rnd(60 - ACURR(A_DEX)));
-            exercise(A_STR, FALSE);
-            exercise(A_DEX, FALSE);
-        }
+    case AD_LEGS:
+        mhitm_ad_legs(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
-    }
     case AD_STON:
         mhitm_ad_ston(mtmp, mattk, &g.youmonst, &mhm);
         if (mhm.done)
index 7824e6ac2242e8761ea9d130724d6e8c884b2bb3..9c33c959a760604b6227c7cd6832b44c74d41b83 100644 (file)
@@ -3810,6 +3810,80 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_legs(magr, mattk, mdef, mhm)
+struct monst *magr;
+struct attack *mattk;
+struct monst *mdef;
+struct mhitm_data *mhm;
+{
+    struct permonst *pd = mdef->data;
+
+    if (magr == &g.youmonst) {
+        /* uhitm */
+#if 0
+        if (u.ucancelled) {
+            mhm->damage = 0;
+            return;
+        }
+#endif
+        mhitm_ad_phys(magr, mattk, mdef, mhm);
+        if (mhm->done)
+            return;
+    } else if (mdef == &g.youmonst) {
+        /* mhitu */
+        int armpro = magic_negation(mdef);
+        boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro);
+
+        long side = rn2(2) ? RIGHT_SIDE : LEFT_SIDE;
+        const char *sidestr = (side == RIGHT_SIDE) ? "right" : "left",
+                   *Monst_name = Monnam(magr), *leg = body_part(LEG);
+
+        /* This case is too obvious to ignore, but Nethack is not in
+         * general very good at considering height--most short monsters
+         * still _can_ attack you when you're flying or mounted.
+         */
+        if ((u.usteed || Levitation || Flying) && !is_flyer(magr->data)) {
+            pline("%s tries to reach your %s %s!", Monst_name, sidestr, leg);
+            mhm->damage = 0;
+        } else if (magr->mcan) {
+            pline("%s nuzzles against your %s %s!", Monnam(magr),
+                  sidestr, leg);
+            mhm->damage = 0;
+        } else {
+            if (uarmf) {
+                if (rn2(2) && (uarmf->otyp == LOW_BOOTS
+                               || uarmf->otyp == IRON_SHOES)) {
+                    pline("%s pricks the exposed part of your %s %s!",
+                          Monst_name, sidestr, leg);
+                } else if (!rn2(5)) {
+                    pline("%s pricks through your %s boot!", Monst_name,
+                          sidestr);
+                } else {
+                    pline("%s scratches your %s boot!", Monst_name,
+                          sidestr);
+                    mhm->damage = 0;
+                    return;
+                }
+            } else
+                pline("%s pricks your %s %s!", Monst_name, sidestr, leg);
+
+            set_wounded_legs(side, rnd(60 - ACURR(A_DEX)));
+            exercise(A_STR, FALSE);
+            exercise(A_DEX, FALSE);
+        }
+    } else {
+        /* mhitm */
+        if (magr->mcan) {
+            mhm->damage = 0;
+            return;
+        }
+        mhitm_ad_phys(magr, mattk, mdef, mhm);
+        if (mhm->done)
+            return;
+    }
+}
+
 /* Template for monster hits monster for AD_FOO.
    - replace "break" with return
    - replace "return" with mhm->done = TRUE
@@ -3877,13 +3951,10 @@ int specialdmg; /* blessed and/or silver bonus against various things */
             return mhm.hitflags;
         break;
     case AD_LEGS:
-#if 0
-        if (u.ucancelled) {
-            mhm.damage = 0;
-            break;
-        }
-#endif
-        goto physical;
+        mhitm_ad_legs(&g.youmonst, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
+        break;
     case AD_WERE:
         mhitm_ad_were(&g.youmonst, mattk, mdef, &mhm);
         if (mhm.done)