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

index 2607c69b0274f24447d1a12d485b869532f66c76..51a1544d60d61cedacb4e47bafd1975daafebdba 100644 (file)
@@ -2760,6 +2760,7 @@ E void FDECL(mhitm_ad_corr, (struct monst *, struct attack *, struct monst *, st
 E void FDECL(mhitm_ad_dcay, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 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 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 4850e31951494b625a3f2fb3da21837e85778661..5448e1359922cfc07741504c3dda4e0288ada5d9 100644 (file)
@@ -1016,36 +1016,9 @@ int dieroll;
         }
         break;
     case AD_FIRE:
-        if (cancelled) {
-            mhm.damage = 0;
-            break;
-        }
-        if (g.vis && canseemon(mdef))
-            pline("%s is %s!", Monnam(mdef), on_fire(pd, mattk));
-        if (completelyburns(pd)) { /* paper golem or straw golem */
-            /* note: the life-saved case is hypothetical because
-               life-saving doesn't work for golems */
-            if (g.vis && canseemon(mdef))
-                pline("%s %s!", Monnam(mdef),
-                      !mlifesaver(mdef) ? "burns completely"
-                                        : "is totally engulfed in flames");
-            monkilled(mdef, (char *) 0, AD_FIRE);
-            if (!DEADMONSTER(mdef))
-                return 0;
-            return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED));
-        }
-        mhm.damage += destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE);
-        mhm.damage += destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE);
-        if (resists_fire(mdef)) {
-            if (g.vis && canseemon(mdef))
-                pline_The("fire doesn't seem to burn %s!", mon_nam(mdef));
-            shieldeff(mdef->mx, mdef->my);
-            golemeffects(mdef, AD_FIRE, mhm.damage);
-            mhm.damage = 0;
-        }
-        /* only potions damage resistant players in destroy_item */
-        mhm.damage += destroy_mitem(mdef, POTION_CLASS, AD_FIRE);
-        ignite_items(mdef->minvent);
+        mhitm_ad_fire(magr, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_COLD:
         if (cancelled) {
index 0c4dde8850fd447db0e1e77ab314637fb84f7524..5430d9f12ba99928e8adfce5c7f7d4789260b7d9 100644 (file)
@@ -1098,29 +1098,9 @@ register struct attack *mattk;
             mhm.damage = 0;
         break;
     case AD_FIRE:
-        hitmsg(mtmp, mattk);
-        if (uncancelled) {
-            pline("You're %s!", on_fire(g.youmonst.data, mattk));
-            if (completelyburns(g.youmonst.data)) { /* paper or straw golem */
-                You("go up in flames!");
-                /* KMH -- this is okay with unchanging */
-                rehumanize();
-                break;
-            } else if (Fire_resistance) {
-                pline_The("fire doesn't feel hot!");
-                mhm.damage = 0;
-            }
-            if ((int) mtmp->m_lev > rn2(20))
-                destroy_item(SCROLL_CLASS, AD_FIRE);
-            if ((int) mtmp->m_lev > rn2(20))
-                destroy_item(POTION_CLASS, AD_FIRE);
-            if ((int) mtmp->m_lev > rn2(25))
-                destroy_item(SPBOOK_CLASS, AD_FIRE);
-            if ((int) mtmp->m_lev > rn2(20))
-                ignite_items(g.invent);
-            burn_away_slime();
-        } else
-            mhm.damage = 0;
+        mhitm_ad_fire(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_COLD:
         hitmsg(mtmp, mattk);
index 88ce1958b584435ada5c8c7b65bcd510b51799f1..f1d64f07e4b5dc7d3c54c4dafc64acbde0099f6f 100644 (file)
@@ -1953,6 +1953,127 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_fire(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 %s!", Monnam(mdef), on_fire(pd, mattk));
+        if (completelyburns(pd)) { /* paper golem or straw golem */
+            if (!Blind)
+                /* note: the life-saved case is hypothetical because
+                   life-saving doesn't work for golems */
+                pline("%s %s!", Monnam(mdef),
+                      !mlifesaver(mdef) ? "burns completely"
+                                        : "is totally engulfed in flames");
+            else
+                You("smell burning%s.",
+                    (pd == &mons[PM_PAPER_GOLEM]) ? " paper"
+                      : (pd == &mons[PM_STRAW_GOLEM]) ? " straw" : "");
+            xkilled(mdef, XKILL_NOMSG | XKILL_NOCORPSE);
+            mhm->damage = 0;
+            return;
+            /* Don't return yet; keep hp<1 and mhm.damage=0 for pet msg */
+        }
+        mhm->damage += destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE);
+        mhm->damage += destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE);
+        if (resists_fire(mdef)) {
+            if (!Blind)
+                pline_The("fire doesn't heat %s!", mon_nam(mdef));
+            golemeffects(mdef, AD_FIRE, mhm->damage);
+            shieldeff(mdef->mx, mdef->my);
+            mhm->damage = 0;
+        }
+        /* only potions damage resistant players in destroy_item */
+        mhm->damage += destroy_mitem(mdef, POTION_CLASS, AD_FIRE);
+        ignite_items(mdef->minvent);
+    } 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 %s!", on_fire(pd, mattk));
+            if (completelyburns(pd)) { /* paper or straw golem */
+                You("go up in flames!");
+                /* KMH -- this is okay with unchanging */
+                rehumanize();
+                return;
+            } else if (Fire_resistance) {
+                pline_The("fire doesn't feel hot!");
+                mhm->damage = 0;
+            }
+            if ((int) magr->m_lev > rn2(20))
+                destroy_item(SCROLL_CLASS, AD_FIRE);
+            if ((int) magr->m_lev > rn2(20))
+                destroy_item(POTION_CLASS, AD_FIRE);
+            if ((int) magr->m_lev > rn2(25))
+                destroy_item(SPBOOK_CLASS, AD_FIRE);
+            if ((int) magr->m_lev > rn2(20))
+                ignite_items(g.invent);
+            burn_away_slime();
+        } 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 %s!", Monnam(mdef), on_fire(pd, mattk));
+        if (completelyburns(pd)) { /* paper golem or straw golem */
+            /* note: the life-saved case is hypothetical because
+               life-saving doesn't work for golems */
+            if (g.vis && canseemon(mdef))
+                pline("%s %s!", Monnam(mdef),
+                      !mlifesaver(mdef) ? "burns completely"
+                                        : "is totally engulfed in flames");
+            monkilled(mdef, (char *) 0, AD_FIRE);
+            if (!DEADMONSTER(mdef)) {
+                mhm->hitflags = MM_MISS;
+                mhm->done = TRUE;
+                return;
+            }
+            mhm->hitflags = (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED));
+            mhm->done = TRUE;
+            return;
+        }
+        mhm->damage += destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE);
+        mhm->damage += destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE);
+        if (resists_fire(mdef)) {
+            if (g.vis && canseemon(mdef))
+                pline_The("fire doesn't seem to burn %s!", mon_nam(mdef));
+            shieldeff(mdef->mx, mdef->my);
+            golemeffects(mdef, AD_FIRE, mhm->damage);
+            mhm->damage = 0;
+        }
+        /* only potions damage resistant players in destroy_item */
+        mhm->damage += destroy_mitem(mdef, POTION_CLASS, AD_FIRE);
+        ignite_items(mdef->minvent);
+    }
+}
+
+
 /* Template for monster hits monster for AD_FOO.
    - replace "break" with return
    - replace "return" with mhm->done = TRUE
@@ -2053,40 +2174,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */
         }
         break;
     case AD_FIRE:
-        if (negated) {
-            mhm.damage = 0;
-            break;
-        }
-        if (!Blind)
-            pline("%s is %s!", Monnam(mdef), on_fire(pd, mattk));
-        if (completelyburns(pd)) { /* paper golem or straw golem */
-            if (!Blind)
-                /* note: the life-saved case is hypothetical because
-                   life-saving doesn't work for golems */
-                pline("%s %s!", Monnam(mdef),
-                      !mlifesaver(mdef) ? "burns completely"
-                                        : "is totally engulfed in flames");
-            else
-                You("smell burning%s.",
-                    (pd == &mons[PM_PAPER_GOLEM]) ? " paper"
-                      : (pd == &mons[PM_STRAW_GOLEM]) ? " straw" : "");
-            xkilled(mdef, XKILL_NOMSG | XKILL_NOCORPSE);
-            mhm.damage = 0;
-            break;
-            /* Don't return yet; keep hp<1 and mhm.damage=0 for pet msg */
-        }
-        mhm.damage += destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE);
-        mhm.damage += destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE);
-        if (resists_fire(mdef)) {
-            if (!Blind)
-                pline_The("fire doesn't heat %s!", mon_nam(mdef));
-            golemeffects(mdef, AD_FIRE, mhm.damage);
-            shieldeff(mdef->mx, mdef->my);
-            mhm.damage = 0;
-        }
-        /* only potions damage resistant players in destroy_item */
-        mhm.damage += destroy_mitem(mdef, POTION_CLASS, AD_FIRE);
-        ignite_items(mdef->minvent);
+        mhitm_ad_fire(&g.youmonst, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_COLD:
         if (negated) {