]> granicus.if.org Git - nethack/commitdiff
Unify ad_poly
authorPasi Kallinen <paxed@alt.org>
Mon, 30 Nov 2020 20:59:06 +0000 (22:59 +0200)
committerPasi Kallinen <paxed@alt.org>
Fri, 4 Dec 2020 07:30:18 +0000 (09:30 +0200)
include/extern.h
src/mhitm.c
src/mhitu.c
src/uhitm.c

index 28292037c9c904582b8cc608cc24468e017e6507..856cfd0cf84673ba68fae28000f831b2d3214daf 100644 (file)
@@ -2779,6 +2779,7 @@ E void FDECL(mhitm_ad_slim, (struct monst *, struct attack *, struct monst *, st
 E void FDECL(mhitm_ad_ench, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_slow, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_conf, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
+E void FDECL(mhitm_ad_poly, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E int FDECL(damageum, (struct monst *, struct attack *, int));
 E void FDECL(missum, (struct monst *, struct attack *, BOOLEAN_P));
 E int FDECL(passive, (struct monst *, struct obj *, BOOLEAN_P, int,
index 88a29c9a21c6d173788f7c65e5bfd91650924076..69ba4405c460395a2462e077615bc0d2c6840c1f 100644 (file)
@@ -1224,8 +1224,9 @@ int dieroll;
             return mhm.hitflags;
         break;
     case AD_POLY:
-        if (!magr->mcan && mhm.damage < mdef->mhp)
-            mhm.damage = mon_poly(magr, mdef, mhm.damage);
+        mhitm_ad_poly(magr, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     default:
         mhm.damage = 0;
index 4213609b418a5ab8693d97dc60abc5125924e83f..9957e0d3e93608fff3e1951dfce1dcfc8e0d84f1 100644 (file)
@@ -1480,8 +1480,9 @@ register struct attack *mattk;
             return mhm.hitflags;
         break;
     case AD_POLY:
-        if (uncancelled && Maybe_Half_Phys(mhm.damage) < (Upolyd ? u.mh : u.uhp))
-            mhm.damage = mon_poly(mtmp, &g.youmonst, mhm.damage);
+        mhitm_ad_poly(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     default:
         mhm.damage = 0;
index 2d745667e49512b1e698af63443bdecf71f1b4a5..83bdaa7e16c140205ab342a05a38efd49fe60f1b 100644 (file)
@@ -3182,6 +3182,40 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_poly(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 */
+        int armpro = magic_negation(mdef);
+        /* since hero can't be cancelled, only defender's armor applies */
+        boolean negated = !(rn2(10) >= 3 * armpro);
+
+        if (!negated && mhm->damage < mdef->mhp)
+            mhm->damage = mon_poly(magr, mdef, mhm->damage);
+    } else if (mdef == &g.youmonst) {
+        /* mhitu */
+        int armpro = magic_negation(mdef);
+        boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro);
+
+        if (uncancelled && Maybe_Half_Phys(mhm->damage) < (Upolyd ? u.mh : u.uhp))
+            mhm->damage = mon_poly(magr, mdef, mhm->damage);
+    } else {
+        /* mhitm */
+        int armpro = magic_negation(mdef);
+        boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro);
+
+        if (!magr->mcan && mhm->damage < mdef->mhp)
+            mhm->damage = mon_poly(magr, mdef, mhm->damage);
+    }
+}
+
 /* Template for monster hits monster for AD_FOO.
    - replace "break" with return
    - replace "return" with mhm->done = TRUE
@@ -3419,8 +3453,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */
             return mhm.hitflags;
         break;
     case AD_POLY:
-        if (!negated && mhm.damage < mdef->mhp)
-            mhm.damage = mon_poly(&g.youmonst, mdef, mhm.damage);
+        mhitm_ad_poly(&g.youmonst, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     default:
         mhm.damage = 0;