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

index db195453dee57bfc567a2f2f3015ac8e92fd6220..40cbd2fabfac3a47cac9428525137465acc00349 100644 (file)
@@ -2766,6 +2766,7 @@ E void FDECL(mhitm_ad_elec, (struct monst *, struct attack *, struct monst *, st
 E void FDECL(mhitm_ad_acid, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_sgld, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_tlpt, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
+E void FDECL(mhitm_ad_blnd, (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 327222810314fa439e75b812695c5da591fa33b7..97fc90f6d3eb9ffe674a34525c9bde472a7eb009 100644 (file)
@@ -1123,19 +1123,9 @@ int dieroll;
         }
         break;
     case AD_BLND:
-        if (can_blnd(magr, mdef, mattk->aatyp, (struct obj *) 0)) {
-            register unsigned rnd_tmp;
-
-            if (g.vis && mdef->mcansee && canspotmon(mdef))
-                pline("%s is blinded.", Monnam(mdef));
-            rnd_tmp = d((int) mattk->damn, (int) mattk->damd);
-            if ((rnd_tmp += mdef->mblinded) > 127)
-                rnd_tmp = 127;
-            mdef->mblinded = rnd_tmp;
-            mdef->mcansee = 0;
-            mdef->mstrategy &= ~STRAT_WAITFORU;
-        }
-        mhm.damage = 0;
+        mhitm_ad_blnd(magr, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_HALU:
         if (!magr->mcan && haseyes(pd) && mdef->mcansee) {
index efea5a60dbe558a01b1d9042e07c1843dedbf5ba..e0f3da06dc33452a96945c941d0c01a9b31e4c9d 100644 (file)
@@ -1125,14 +1125,9 @@ register struct attack *mattk;
         }
         break;
     case AD_BLND:
-        if (can_blnd(mtmp, &g.youmonst, mattk->aatyp, (struct obj *) 0)) {
-            if (!Blind)
-                pline("%s blinds you!", Monnam(mtmp));
-            make_blinded(Blinded + (long) mhm.damage, FALSE);
-            if (!Blind)
-                Your1(vision_clears);
-        }
-        mhm.damage = 0;
+        mhitm_ad_blnd(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_DRST:
         ptmp = A_STR;
index 9bdbd20ee39e615a2e169eef5c1394018280aae7..2148d458bca7c41c1a8540eb51f612165b89db99 100644 (file)
@@ -2432,6 +2432,54 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_blnd(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 (can_blnd(magr, mdef, mattk->aatyp, (struct obj *) 0)) {
+            if (!Blind && mdef->mcansee)
+                pline("%s is blinded.", Monnam(mdef));
+            mdef->mcansee = 0;
+            mhm->damage += mdef->mblinded;
+            if (mhm->damage > 127)
+                mhm->damage = 127;
+            mdef->mblinded = mhm->damage;
+        }
+        mhm->damage = 0;
+    } else if (mdef == &g.youmonst) {
+        /* mhitu */
+        if (can_blnd(magr, mdef, mattk->aatyp, (struct obj *) 0)) {
+            if (!Blind)
+                pline("%s blinds you!", Monnam(magr));
+            make_blinded(Blinded + (long) mhm->damage, FALSE);
+            if (!Blind)
+                Your1(vision_clears);
+        }
+        mhm->damage = 0;
+    } else {
+        /* mhitm */
+        if (can_blnd(magr, mdef, mattk->aatyp, (struct obj *) 0)) {
+            register unsigned rnd_tmp;
+
+            if (g.vis && mdef->mcansee && canspotmon(mdef))
+                pline("%s is blinded.", Monnam(mdef));
+            rnd_tmp = d((int) mattk->damn, (int) mattk->damd);
+            if ((rnd_tmp += mdef->mblinded) > 127)
+                rnd_tmp = 127;
+            mdef->mblinded = rnd_tmp;
+            mdef->mcansee = 0;
+            mdef->mstrategy &= ~STRAT_WAITFORU;
+        }
+        mhm->damage = 0;
+    }
+}
 
 /* Template for monster hits monster for AD_FOO.
    - replace "break" with return
@@ -2573,16 +2621,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */
             return mhm.hitflags;
         break;
     case AD_BLND:
-        if (can_blnd(&g.youmonst, mdef, mattk->aatyp, (struct obj *) 0)) {
-            if (!Blind && mdef->mcansee)
-                pline("%s is blinded.", Monnam(mdef));
-            mdef->mcansee = 0;
-            mhm.damage += mdef->mblinded;
-            if (mhm.damage > 127)
-                mhm.damage = 127;
-            mdef->mblinded = mhm.damage;
-        }
-        mhm.damage = 0;
+        mhitm_ad_blnd(&g.youmonst, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_CURS:
         if (night() && !rn2(10) && !mdef->mcan) {