]> granicus.if.org Git - nethack/commitdiff
Unify ad_ench
authorPasi Kallinen <paxed@alt.org>
Mon, 30 Nov 2020 20:46:59 +0000 (22:46 +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 68dfa21667ad90fa9370e863cb1f858feeae3cc9..161e172581f0b740eced0a27258e15135db88ab2 100644 (file)
@@ -2776,6 +2776,7 @@ E void FDECL(mhitm_ad_wrap, (struct monst *, struct attack *, struct monst *, st
 E void FDECL(mhitm_ad_plys, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_slee, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_slim, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
+E void FDECL(mhitm_ad_ench, (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 24315f5ff4a68777baf5dda00a6ba4ec21ee101f..db2dfa4ee409984b72f37e624224f7501b5557d4 100644 (file)
@@ -1231,8 +1231,9 @@ int dieroll;
             return mhm.hitflags;
         break;
     case AD_ENCH:
-        /* there's no msomearmor() function, so just do damage */
-        /* if (cancelled) break; */
+        mhitm_ad_ench(magr, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_POLY:
         if (!magr->mcan && mhm.damage < mdef->mhp)
index 1151fb164e9bdb79adc2e6863d743718a6d32d3a..cb26e2cb095c460d5b5150040d90914b5cb651ce 100644 (file)
@@ -1482,36 +1482,9 @@ register struct attack *mattk;
             return mhm.hitflags;
         break;
     case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */
-        hitmsg(mtmp, mattk);
-        /* uncancelled is sufficient enough; please
-           don't make this attack less frequent */
-        if (uncancelled) {
-            struct obj *obj = some_armor(&g.youmonst);
-
-            if (!obj) {
-                /* some rings are susceptible;
-                   amulets and blindfolds aren't (at present) */
-                switch (rn2(5)) {
-                case 0:
-                    break;
-                case 1:
-                    obj = uright;
-                    break;
-                case 2:
-                    obj = uleft;
-                    break;
-                case 3:
-                    obj = uamul;
-                    break;
-                case 4:
-                    obj = ublindf;
-                    break;
-                }
-            }
-            if (drain_item(obj, FALSE)) {
-                pline("%s less effective.", Yobjnam2(obj, "seem"));
-            }
-        }
+        mhitm_ad_ench(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_POLY:
         if (uncancelled && Maybe_Half_Phys(mhm.damage) < (Upolyd ? u.mh : u.uhp))
index e04d6261f05be4e4c5fc4e34e63ae7e4cacaff61..171ea78eaa50e5aa8502d9fb2e4046e8e307b229 100644 (file)
@@ -3040,6 +3040,58 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_ench(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 */
+        /* there's no msomearmor() function, so just do damage */
+    } else if (mdef == &g.youmonst) {
+        /* mhitu */
+        int armpro = magic_negation(mdef);
+        boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro);
+
+        hitmsg(magr, mattk);
+        /* uncancelled is sufficient enough; please
+           don't make this attack less frequent */
+        if (uncancelled) {
+            struct obj *obj = some_armor(mdef);
+
+            if (!obj) {
+                /* some rings are susceptible;
+                   amulets and blindfolds aren't (at present) */
+                switch (rn2(5)) {
+                case 0:
+                    break;
+                case 1:
+                    obj = uright;
+                    break;
+                case 2:
+                    obj = uleft;
+                    break;
+                case 3:
+                    obj = uamul;
+                    break;
+                case 4:
+                    obj = ublindf;
+                    break;
+                }
+            }
+            if (drain_item(obj, FALSE)) {
+                pline("%s less effective.", Yobjnam2(obj, "seem"));
+            }
+        }
+    } else {
+        /* mhitm */
+        /* there's no msomearmor() function, so just do damage */
+    }
+}
 
 /* Template for monster hits monster for AD_FOO.
    - replace "break" with return
@@ -3262,9 +3314,10 @@ int specialdmg; /* blessed and/or silver bonus against various things */
         if (mhm.done)
             return mhm.hitflags;
         break;
-    case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */
-        /* there's no msomearmor() function, so just do damage */
-        /* if (negated) break; */
+    case AD_ENCH:
+        mhitm_ad_ench(&g.youmonst, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_SLOW:
         if (!negated && mdef->mspeed != MSLOW) {