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

index 17bde25254af521c2e2d8faad326a9f2d2885d87..68dfa21667ad90fa9370e863cb1f858feeae3cc9 100644 (file)
@@ -2775,6 +2775,7 @@ E void FDECL(mhitm_ad_stck, (struct monst *, struct attack *, struct monst *, st
 E void FDECL(mhitm_ad_wrap, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 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 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 c242af935ff70348f4c02148d5cfc08e93811b57..24315f5ff4a68777baf5dda00a6ba4ec21ee101f 100644 (file)
@@ -1216,24 +1216,9 @@ int dieroll;
             return mhm.hitflags;
         break;
     case AD_SLIM:
-        if (cancelled)
-            break; /* physical damage only */
-        if (!rn2(4) && !slimeproof(pd)) {
-            if (!munslime(mdef, FALSE) && !DEADMONSTER(mdef)) {
-                if (newcham(mdef, &mons[PM_GREEN_SLIME], FALSE,
-                            (boolean) (g.vis && canseemon(mdef))))
-                    pd = mdef->data;
-                mdef->mstrategy &= ~STRAT_WAITFORU;
-                mhm.hitflags = MM_HIT;
-            }
-            /* munslime attempt could have been fatal,
-               potentially to multiple monsters (SCR_FIRE) */
-            if (DEADMONSTER(magr))
-                mhm.hitflags |= MM_AGR_DIED;
-            if (DEADMONSTER(mdef))
-                mhm.hitflags |= MM_DEF_DIED;
-            mhm.damage = 0;
-        }
+        mhitm_ad_slim(magr, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_STCK:
         mhitm_ad_stck(magr, mattk, mdef, &mhm);
index 0f05f7550569f0ca0801d7aac67ad04618ebd191..1151fb164e9bdb79adc2e6863d743718a6d32d3a 100644 (file)
@@ -1477,22 +1477,9 @@ register struct attack *mattk;
         /* plus the normal damage */
         break;
     case AD_SLIM:
-        hitmsg(mtmp, mattk);
-        if (!uncancelled)
-            break;
-        if (flaming(g.youmonst.data)) {
-            pline_The("slime burns away!");
-            mhm.damage = 0;
-        } else if (Unchanging || noncorporeal(g.youmonst.data)
-                   || g.youmonst.data == &mons[PM_GREEN_SLIME]) {
-            You("are unaffected.");
-            mhm.damage = 0;
-        } else if (!Slimed) {
-            You("don't feel very well.");
-            make_slimed(10L, (char *) 0);
-            delayed_killer(SLIMED, KILLED_BY_AN, mtmp->data->mname);
-        } else
-            pline("Yuck!");
+        mhitm_ad_slim(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */
         hitmsg(mtmp, mattk);
index 6db99262685e6f08245a8a6ba645d531d02ed4ac..e04d6261f05be4e4c5fc4e34e63ae7e4cacaff61 100644 (file)
@@ -2960,6 +2960,85 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_slim(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)
+            return; /* physical damage only */
+        if (!rn2(4) && !slimeproof(pd)) {
+            if (!munslime(mdef, TRUE) && !DEADMONSTER(mdef)) {
+                /* this assumes newcham() won't fail; since hero has
+                   a slime attack, green slimes haven't been geno'd */
+                You("turn %s into slime.", mon_nam(mdef));
+                if (newcham(mdef, &mons[PM_GREEN_SLIME], FALSE, FALSE))
+                    pd = mdef->data;
+            }
+            /* munslime attempt could have been fatal */
+            if (DEADMONSTER(mdef)) {
+                mhm->hitflags = MM_DEF_DIED; /* skip death message */
+                mhm->done = TRUE;
+                return;
+            }
+            mhm->damage = 0;
+        }
+    } else if (mdef == &g.youmonst) {
+        /* mhitu */
+        int armpro = magic_negation(mdef);
+        boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro);
+
+        hitmsg(magr, mattk);
+        if (!uncancelled)
+            return;
+        if (flaming(pd)) {
+            pline_The("slime burns away!");
+            mhm->damage = 0;
+        } else if (Unchanging || noncorporeal(pd)
+                   || pd == &mons[PM_GREEN_SLIME]) {
+            You("are unaffected.");
+            mhm->damage = 0;
+        } else if (!Slimed) {
+            You("don't feel very well.");
+            make_slimed(10L, (char *) 0);
+            delayed_killer(SLIMED, KILLED_BY_AN, magr->data->mname);
+        } else
+            pline("Yuck!");
+    } else {
+        /* mhitm */
+        int armpro = magic_negation(mdef);
+        boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro);
+
+        if (cancelled)
+            return; /* physical damage only */
+        if (!rn2(4) && !slimeproof(pd)) {
+            if (!munslime(mdef, FALSE) && !DEADMONSTER(mdef)) {
+                if (newcham(mdef, &mons[PM_GREEN_SLIME], FALSE,
+                            (boolean) (g.vis && canseemon(mdef))))
+                    pd = mdef->data;
+                mdef->mstrategy &= ~STRAT_WAITFORU;
+                mhm->hitflags = MM_HIT;
+            }
+            /* munslime attempt could have been fatal,
+               potentially to multiple monsters (SCR_FIRE) */
+            if (DEADMONSTER(magr))
+                mhm->hitflags |= MM_AGR_DIED;
+            if (DEADMONSTER(mdef))
+                mhm->hitflags |= MM_DEF_DIED;
+            mhm->damage = 0;
+        }
+    }
+}
 
 
 /* Template for monster hits monster for AD_FOO.
@@ -3179,21 +3258,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */
             return mhm.hitflags;
         break;
     case AD_SLIM:
-        if (negated)
-            break; /* physical damage only */
-        if (!rn2(4) && !slimeproof(pd)) {
-            if (!munslime(mdef, TRUE) && !DEADMONSTER(mdef)) {
-                /* this assumes newcham() won't fail; since hero has
-                   a slime attack, green slimes haven't been geno'd */
-                You("turn %s into slime.", mon_nam(mdef));
-                if (newcham(mdef, &mons[PM_GREEN_SLIME], FALSE, FALSE))
-                    pd = mdef->data;
-            }
-            /* munslime attempt could have been fatal */
-            if (DEADMONSTER(mdef))
-                return 2; /* skip death message */
-            mhm.damage = 0;
-        }
+        mhitm_ad_slim(&g.youmonst, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */
         /* there's no msomearmor() function, so just do damage */