From: Pasi Kallinen Date: Mon, 30 Nov 2020 20:46:59 +0000 (+0200) Subject: Unify ad_ench X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b80c30bcf1a474d2569f124514ec9cb93b66094c;p=nethack Unify ad_ench --- diff --git a/include/extern.h b/include/extern.h index 68dfa2166..161e17258 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2776,6 +2776,7 @@ E void FDECL(mhitm_ad_wrap, (struct monst *, struct attack *, struct monst *, st E void FDECL(mhitm_ad_plys, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); E void FDECL(mhitm_ad_slee, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); 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 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, diff --git a/src/mhitm.c b/src/mhitm.c index 24315f5ff..db2dfa4ee 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -1231,8 +1231,9 @@ int dieroll; return mhm.hitflags; break; case AD_ENCH: - /* there's no msomearmor() function, so just do damage */ - /* if (cancelled) break; */ + mhitm_ad_ench(magr, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_POLY: if (!magr->mcan && mhm.damage < mdef->mhp) diff --git a/src/mhitu.c b/src/mhitu.c index 1151fb164..cb26e2cb0 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -1482,36 +1482,9 @@ register struct attack *mattk; return mhm.hitflags; break; case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ - hitmsg(mtmp, mattk); - /* uncancelled is sufficient enough; please - don't make this attack less frequent */ - if (uncancelled) { - struct obj *obj = some_armor(&g.youmonst); - - if (!obj) { - /* some rings are susceptible; - amulets and blindfolds aren't (at present) */ - switch (rn2(5)) { - case 0: - break; - case 1: - obj = uright; - break; - case 2: - obj = uleft; - break; - case 3: - obj = uamul; - break; - case 4: - obj = ublindf; - break; - } - } - if (drain_item(obj, FALSE)) { - pline("%s less effective.", Yobjnam2(obj, "seem")); - } - } + mhitm_ad_ench(mtmp, mattk, &g.youmonst, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_POLY: if (uncancelled && Maybe_Half_Phys(mhm.damage) < (Upolyd ? u.mh : u.uhp)) diff --git a/src/uhitm.c b/src/uhitm.c index e04d6261f..171ea78ea 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -3040,6 +3040,58 @@ struct mhitm_data *mhm; } } +void +mhitm_ad_ench(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 */ + /* there's no msomearmor() function, so just do damage */ + } else if (mdef == &g.youmonst) { + /* mhitu */ + int armpro = magic_negation(mdef); + boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro); + + hitmsg(magr, mattk); + /* uncancelled is sufficient enough; please + don't make this attack less frequent */ + if (uncancelled) { + struct obj *obj = some_armor(mdef); + + if (!obj) { + /* some rings are susceptible; + amulets and blindfolds aren't (at present) */ + switch (rn2(5)) { + case 0: + break; + case 1: + obj = uright; + break; + case 2: + obj = uleft; + break; + case 3: + obj = uamul; + break; + case 4: + obj = ublindf; + break; + } + } + if (drain_item(obj, FALSE)) { + pline("%s less effective.", Yobjnam2(obj, "seem")); + } + } + } else { + /* mhitm */ + /* there's no msomearmor() function, so just do damage */ + } +} /* Template for monster hits monster for AD_FOO. - replace "break" with return @@ -3262,9 +3314,10 @@ int specialdmg; /* blessed and/or silver bonus against various things */ if (mhm.done) return mhm.hitflags; break; - case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ - /* there's no msomearmor() function, so just do damage */ - /* if (negated) break; */ + case AD_ENCH: + mhitm_ad_ench(&g.youmonst, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_SLOW: if (!negated && mdef->mspeed != MSLOW) {