]> granicus.if.org Git - nethack/commitdiff
Unify ad_sgld
authorPasi Kallinen <paxed@alt.org>
Mon, 30 Nov 2020 18:32:38 +0000 (20:32 +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 7d9907babb2c3be8cf7164bf86f8b9029ea8848d..8456059c15591801585a42cb0fff4efbda919a45 100644 (file)
@@ -2764,6 +2764,7 @@ E void FDECL(mhitm_ad_fire, (struct monst *, struct attack *, struct monst *, st
 E void FDECL(mhitm_ad_cold, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_elec, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 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 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 f5e15a5333cf0c0886863af494aadc558c6403ac..6b21059dfac771d28aa75b78ece4e593bcced2c8 100644 (file)
@@ -1193,32 +1193,9 @@ int dieroll;
         }
         break;
     case AD_SGLD:
-        mhm.damage = 0;
-        if (magr->mcan)
-            break;
-        /* technically incorrect; no check for stealing gold from
-         * between mdef's feet...
-         */
-        {
-            struct obj *gold = findgold(mdef->minvent);
-
-            if (!gold)
-                break;
-            obj_extract_self(gold);
-            add_to_minv(magr, gold);
-        }
-        mdef->mstrategy &= ~STRAT_WAITFORU;
-        if (g.vis && canseemon(mdef)) {
-            Strcpy(buf, Monnam(magr));
-            pline("%s steals some gold from %s.", buf, mon_nam(mdef));
-        }
-        if (!tele_restrict(magr)) {
-            boolean couldspot = canspotmon(magr);
-
-            (void) rloc(magr, TRUE);
-            if (g.vis && couldspot && !canspotmon(magr))
-                pline("%s suddenly disappears!", buf);
-        }
+        mhitm_ad_sgld(magr, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_DRLI: /* drain life */
         mhitm_ad_drli(magr, mattk, mdef, &mhm);
index 1e45dadcced57bd505b82427c48ce89c87396b77..e012a71962a9738ceff31fb5243adb8ccef9293e 100644 (file)
@@ -1330,11 +1330,9 @@ register struct attack *mattk;
         }
         break;
     case AD_SGLD:
-        hitmsg(mtmp, mattk);
-        if (g.youmonst.data->mlet == mdat->mlet)
-            break;
-        if (!mtmp->mcan)
-            stealgold(mtmp);
+        mhitm_ad_sgld(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
 
     case AD_SSEX:
index 330342f7ef0cde410c52ea6fdd283fe55715a250..176912b043a4425c32f6a471bb7908af4a88e54b 100644 (file)
@@ -2262,6 +2262,74 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_sgld(magr, mattk, mdef, mhm)
+struct monst *magr;
+struct attack *mattk;
+struct monst *mdef;
+struct mhitm_data *mhm;
+{
+    struct permonst *pa = magr->data;
+    struct permonst *pd = mdef->data;
+
+    if (magr == &g.youmonst) {
+        /* uhitm */
+        struct obj *mongold = findgold(mdef->minvent);
+
+        if (mongold) {
+            obj_extract_self(mongold);
+            if (merge_choice(g.invent, mongold) || inv_cnt(FALSE) < 52) {
+                addinv(mongold);
+                Your("purse feels heavier.");
+            } else {
+                You("grab %s's gold, but find no room in your knapsack.",
+                    mon_nam(mdef));
+                dropy(mongold);
+            }
+        }
+        exercise(A_DEX, TRUE);
+        mhm->damage = 0;
+    } else if (mdef == &g.youmonst) {
+        /* mhitu */
+        hitmsg(magr, mattk);
+        if (pd->mlet == pa->mlet)
+            return;
+        if (!magr->mcan)
+            stealgold(magr);
+    } else {
+        /* mhitm */
+        char buf[BUFSZ];
+
+        mhm->damage = 0;
+        if (magr->mcan)
+            return;
+        /* technically incorrect; no check for stealing gold from
+         * between mdef's feet...
+         */
+        {
+            struct obj *gold = findgold(mdef->minvent);
+
+            if (!gold)
+                return;
+            obj_extract_self(gold);
+            add_to_minv(magr, gold);
+        }
+        mdef->mstrategy &= ~STRAT_WAITFORU;
+        if (g.vis && canseemon(mdef)) {
+            Strcpy(buf, Monnam(magr));
+            pline("%s steals some gold from %s.", buf, mon_nam(mdef));
+        }
+        if (!tele_restrict(magr)) {
+            boolean couldspot = canspotmon(magr);
+
+            (void) rloc(magr, TRUE);
+            if (g.vis && couldspot && !canspotmon(magr))
+                pline("%s suddenly disappears!", buf);
+        }
+    }
+}
+
+
 
 /* Template for monster hits monster for AD_FOO.
    - replace "break" with return
@@ -2297,7 +2365,6 @@ int specialdmg; /* blessed and/or silver bonus against various things */
     register struct permonst *pd = mdef->data;
     int armpro;
     boolean negated;
-    struct obj *mongold;
     struct mhitm_data mhm;
     mhm.damage = d((int) mattk->damn, (int) mattk->damd);
     mhm.hitflags = MM_MISS;
@@ -2394,22 +2461,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */
         mhm.damage = 0;
         break;
     case AD_SGLD:
-        /* This you as a leprechaun, so steal
-           real gold only, no lesser coins */
-        mongold = findgold(mdef->minvent);
-        if (mongold) {
-            obj_extract_self(mongold);
-            if (merge_choice(g.invent, mongold) || inv_cnt(FALSE) < 52) {
-                addinv(mongold);
-                Your("purse feels heavier.");
-            } else {
-                You("grab %s's gold, but find no room in your knapsack.",
-                    mon_nam(mdef));
-                dropy(mongold);
-            }
-        }
-        exercise(A_DEX, TRUE);
-        mhm.damage = 0;
+        mhitm_ad_sgld(&g.youmonst, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_TLPT:
         if (mhm.damage <= 0)