]> granicus.if.org Git - nethack/commitdiff
Unify ad_conf
authorPasi Kallinen <paxed@alt.org>
Mon, 30 Nov 2020 20:55:26 +0000 (22:55 +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 414e1d0f8e05b5c13f253dff0c22ab90065a3616..28292037c9c904582b8cc608cc24468e017e6507 100644 (file)
@@ -2778,6 +2778,7 @@ E void FDECL(mhitm_ad_slee, (struct monst *, struct attack *, struct monst *, st
 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 void FDECL(mhitm_ad_slow, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
+E void FDECL(mhitm_ad_conf, (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 ffb11fe1f8d121f64c452abcbf2786257bc36c6b..88a29c9a21c6d173788f7c65e5bfd91650924076 100644 (file)
@@ -1096,16 +1096,9 @@ int dieroll;
             return mhm.hitflags;
         break;
     case AD_CONF:
-        /* Since confusing another monster doesn't have a real time
-         * limit, setting spec_used would not really be right (though
-         * we still should check for it).
-         */
-        if (!magr->mcan && !mdef->mconf && !magr->mspec_used) {
-            if (g.vis && canseemon(mdef))
-                pline("%s looks confused.", Monnam(mdef));
-            mdef->mconf = 1;
-            mdef->mstrategy &= ~STRAT_WAITFORU;
-        }
+        mhitm_ad_conf(magr, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_BLND:
         mhitm_ad_blnd(magr, mattk, mdef, &mhm);
index dcee2988dfb1f1003d3291100c41aa0913a66fc3..4213609b418a5ab8693d97dc60abc5125924e83f 100644 (file)
@@ -1419,16 +1419,9 @@ register struct attack *mattk;
             return mhm.hitflags;
         break;
     case AD_CONF:
-        hitmsg(mtmp, mattk);
-        if (!mtmp->mcan && !rn2(4) && !mtmp->mspec_used) {
-            mtmp->mspec_used = mtmp->mspec_used + (mhm.damage + rn2(6));
-            if (Confusion)
-                You("are getting even more confused.");
-            else
-                You("are getting confused.");
-            make_confused(HConfusion + mhm.damage, FALSE);
-        }
-        mhm.damage = 0;
+        mhitm_ad_conf(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_DETH:
         pline("%s reaches out with its deadly touch.", Monnam(mtmp));
index 16bf66c349dc127faa757cd363762dbce02637ca..2d745667e49512b1e698af63443bdecf71f1b4a5 100644 (file)
@@ -3139,6 +3139,48 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_conf(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 (!mdef->mconf) {
+            if (canseemon(mdef))
+                pline("%s looks confused.", Monnam(mdef));
+            mdef->mconf = 1;
+        }
+    } else if (mdef == &g.youmonst) {
+        /* mhitu */
+        hitmsg(magr, mattk);
+        if (!magr->mcan && !rn2(4) && !magr->mspec_used) {
+            magr->mspec_used = magr->mspec_used + (mhm->damage + rn2(6));
+            if (Confusion)
+                You("are getting even more confused.");
+            else
+                You("are getting confused.");
+            make_confused(HConfusion + mhm->damage, FALSE);
+        }
+        mhm->damage = 0;
+    } else {
+        /* mhitm */
+        /* Since confusing another monster doesn't have a real time
+         * limit, setting spec_used would not really be right (though
+         * we still should check for it).
+         */
+        if (!magr->mcan && !mdef->mconf && !magr->mspec_used) {
+            if (g.vis && canseemon(mdef))
+                pline("%s looks confused.", Monnam(mdef));
+            mdef->mconf = 1;
+            mdef->mstrategy &= ~STRAT_WAITFORU;
+        }
+    }
+}
 
 /* Template for monster hits monster for AD_FOO.
    - replace "break" with return
@@ -3372,11 +3414,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */
             return mhm.hitflags;
         break;
     case AD_CONF:
-        if (!mdef->mconf) {
-            if (canseemon(mdef))
-                pline("%s looks confused.", Monnam(mdef));
-            mdef->mconf = 1;
-        }
+        mhitm_ad_conf(&g.youmonst, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_POLY:
         if (!negated && mhm.damage < mdef->mhp)