]> granicus.if.org Git - nethack/commitdiff
Unify ad_stun
authorPasi Kallinen <paxed@alt.org>
Tue, 1 Dec 2020 09:05:14 +0000 (11:05 +0200)
committerPasi Kallinen <paxed@alt.org>
Fri, 4 Dec 2020 07:30:19 +0000 (09:30 +0200)
include/extern.h
src/mhitm.c
src/mhitu.c
src/uhitm.c

index 94f3d8a0dea90b9732d29ebfc3b6ec4da47efdae..f4d5c0fcf578b377d7cfe1d54ebce2f16505341e 100644 (file)
@@ -2789,6 +2789,7 @@ E void FDECL(mhitm_ad_phys, (struct monst *, struct attack *, struct monst *, st
 E void FDECL(mhitm_ad_ston, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_were, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_heal, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
+E void FDECL(mhitm_ad_stun, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E boolean FDECL(do_stone_u, (struct monst *));
 E void FDECL(do_stone_mon, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E int FDECL(damageum, (struct monst *, struct attack *, int));
index e638a97b0c06c698f68d8cc3fc7dfdc2725259e9..decb034b8a56ab75b452a0bd7978f88451677907 100644 (file)
@@ -950,13 +950,10 @@ int dieroll;
         }
         break;
     case AD_STUN:
-        if (magr->mcan)
-            break;
-        if (canseemon(mdef))
-            pline("%s %s for a moment.", Monnam(mdef),
-                  makeplural(stagger(pd, "stagger")));
-        mdef->mstun = 1;
-        goto physical;
+        mhitm_ad_stun(magr, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
+        break;
     case AD_LEGS:
         if (magr->mcan) {
             mhm.damage = 0;
index 1e630dfd690f98eefb7583d6c9b9a0f03b6a89aa..a67f78e384a702525d0f307f4bcfba45f25aad51 100644 (file)
@@ -1239,11 +1239,9 @@ register struct attack *mattk;
             return mhm.hitflags;
         break;
     case AD_STUN:
-        hitmsg(mtmp, mattk);
-        if (!mtmp->mcan && !rn2(4)) {
-            make_stunned((HStun & TIMEOUT) + (long) mhm.damage, TRUE);
-            mhm.damage /= 2;
-        }
+        mhitm_ad_stun(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_ACID:
         mhitm_ad_acid(mtmp, mattk, &g.youmonst, &mhm);
index 56e6bc2c5319f007d4b1908c62ea3654d56bfd98..7824e6ac2242e8761ea9d130724d6e8c884b2bb3 100644 (file)
@@ -3771,6 +3771,45 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_stun(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 */
+        if (!Blind)
+            pline("%s %s for a moment.", Monnam(mdef),
+                  makeplural(stagger(pd, "stagger")));
+        mdef->mstun = 1;
+        mhitm_ad_phys(magr, mattk, mdef, mhm);
+        if (mhm->done)
+            return;
+    } else if (mdef == &g.youmonst) {
+        /* mhitu */
+        hitmsg(magr, mattk);
+        if (!magr->mcan && !rn2(4)) {
+            make_stunned((HStun & TIMEOUT) + (long) mhm->damage, TRUE);
+            mhm->damage /= 2;
+        }
+    } else {
+        /* mhitm */
+        if (magr->mcan)
+            return;
+        if (canseemon(mdef))
+            pline("%s %s for a moment.", Monnam(mdef),
+                  makeplural(stagger(pd, "stagger")));
+        mdef->mstun = 1;
+        mhitm_ad_phys(magr, mattk, mdef, mhm);
+        if (mhm->done)
+            return;
+    }
+}
+
 /* Template for monster hits monster for AD_FOO.
    - replace "break" with return
    - replace "return" with mhm->done = TRUE
@@ -3833,11 +3872,10 @@ int specialdmg; /* blessed and/or silver bonus against various things */
     }
     switch (mattk->adtyp) {
     case AD_STUN:
-        if (!Blind)
-            pline("%s %s for a moment.", Monnam(mdef),
-                  makeplural(stagger(pd, "stagger")));
-        mdef->mstun = 1;
-        goto physical;
+        mhitm_ad_stun(&g.youmonst, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
+        break;
     case AD_LEGS:
 #if 0
         if (u.ucancelled) {