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

index 51a1544d60d61cedacb4e47bafd1975daafebdba..7e6fa7acff98dc38fe6e1482b3ad088347a6b09a 100644 (file)
@@ -2761,6 +2761,7 @@ E void FDECL(mhitm_ad_dcay, (struct monst *, struct attack *, struct monst *, st
 E void FDECL(mhitm_ad_dren, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_drli, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_fire, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
+E void FDECL(mhitm_ad_cold, (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 5448e1359922cfc07741504c3dda4e0288ada5d9..f6c4b3abc1ca82e82a751514372811d324940fd0 100644 (file)
@@ -1021,20 +1021,9 @@ int dieroll;
             return mhm.hitflags;
         break;
     case AD_COLD:
-        if (cancelled) {
-            mhm.damage = 0;
-            break;
-        }
-        if (g.vis && canseemon(mdef))
-            pline("%s is covered in frost!", Monnam(mdef));
-        if (resists_cold(mdef)) {
-            if (g.vis && canseemon(mdef))
-                pline_The("frost doesn't seem to chill %s!", mon_nam(mdef));
-            shieldeff(mdef->mx, mdef->my);
-            golemeffects(mdef, AD_COLD, mhm.damage);
-            mhm.damage = 0;
-        }
-        mhm.damage += destroy_mitem(mdef, POTION_CLASS, AD_COLD);
+        mhitm_ad_cold(magr, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_ELEC:
         if (cancelled) {
index 5430d9f12ba99928e8adfce5c7f7d4789260b7d9..be4fb308b8749c01862cff4a3ae83159fb9d843a 100644 (file)
@@ -1103,17 +1103,9 @@ register struct attack *mattk;
             return mhm.hitflags;
         break;
     case AD_COLD:
-        hitmsg(mtmp, mattk);
-        if (uncancelled) {
-            pline("You're covered in frost!");
-            if (Cold_resistance) {
-                pline_The("frost doesn't seem cold!");
-                mhm.damage = 0;
-            }
-            if ((int) mtmp->m_lev > rn2(20))
-                destroy_item(POTION_CLASS, AD_COLD);
-        } else
-            mhm.damage = 0;
+        mhitm_ad_cold(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_ELEC:
         hitmsg(mtmp, mattk);
index f1d64f07e4b5dc7d3c54c4dafc64acbde0099f6f..c3e2fdff5bb59181a322d2faa098a5d1a2c287a9 100644 (file)
@@ -2073,6 +2073,73 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_cold(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 = 0;
+            return;
+        }
+        if (!Blind)
+            pline("%s is covered in frost!", Monnam(mdef));
+        if (resists_cold(mdef)) {
+            shieldeff(mdef->mx, mdef->my);
+            if (!Blind)
+                pline_The("frost doesn't chill %s!", mon_nam(mdef));
+            golemeffects(mdef, AD_COLD, mhm->damage);
+            mhm->damage = 0;
+        }
+        mhm->damage += destroy_mitem(mdef, POTION_CLASS, AD_COLD);
+    } else if (mdef == &g.youmonst) {
+        /* mhitu */
+        int armpro = magic_negation(mdef);
+        boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro);
+
+        hitmsg(magr, mattk);
+        if (uncancelled) {
+            pline("You're covered in frost!");
+            if (Cold_resistance) {
+                pline_The("frost doesn't seem cold!");
+                mhm->damage = 0;
+            }
+            if ((int) magr->m_lev > rn2(20))
+                destroy_item(POTION_CLASS, AD_COLD);
+        } else
+            mhm->damage = 0;
+    } else {
+        /* mhitm */
+        int armpro = magic_negation(mdef);
+        boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro);
+
+        if (cancelled) {
+            mhm->damage = 0;
+            return;
+        }
+        if (g.vis && canseemon(mdef))
+            pline("%s is covered in frost!", Monnam(mdef));
+        if (resists_cold(mdef)) {
+            if (g.vis && canseemon(mdef))
+                pline_The("frost doesn't seem to chill %s!", mon_nam(mdef));
+            shieldeff(mdef->mx, mdef->my);
+            golemeffects(mdef, AD_COLD, mhm->damage);
+            mhm->damage = 0;
+        }
+        mhm->damage += destroy_mitem(mdef, POTION_CLASS, AD_COLD);
+    }
+}
+
 
 /* Template for monster hits monster for AD_FOO.
    - replace "break" with return
@@ -2179,20 +2246,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */
             return mhm.hitflags;
         break;
     case AD_COLD:
-        if (negated) {
-            mhm.damage = 0;
-            break;
-        }
-        if (!Blind)
-            pline("%s is covered in frost!", Monnam(mdef));
-        if (resists_cold(mdef)) {
-            shieldeff(mdef->mx, mdef->my);
-            if (!Blind)
-                pline_The("frost doesn't chill %s!", mon_nam(mdef));
-            golemeffects(mdef, AD_COLD, mhm.damage);
-            mhm.damage = 0;
-        }
-        mhm.damage += destroy_mitem(mdef, POTION_CLASS, AD_COLD);
+        mhitm_ad_cold(&g.youmonst, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_ELEC:
         if (negated) {