From: Pasi Kallinen Date: Mon, 30 Nov 2020 18:15:13 +0000 (+0200) Subject: Unify ad_elec X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8a78c49feafd7e6d83713451997e6f99998c5861;p=nethack Unify ad_elec --- diff --git a/include/extern.h b/include/extern.h index 7e6fa7acf..c899cdc18 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2762,6 +2762,7 @@ E void FDECL(mhitm_ad_dren, (struct monst *, struct attack *, struct monst *, st E void FDECL(mhitm_ad_drli, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); E void FDECL(mhitm_ad_fire, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); 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 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 f6c4b3abc..f0f95fda8 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -1026,22 +1026,9 @@ int dieroll; return mhm.hitflags; break; case AD_ELEC: - if (cancelled) { - mhm.damage = 0; - break; - } - if (g.vis && canseemon(mdef)) - pline("%s gets zapped!", Monnam(mdef)); - mhm.damage += destroy_mitem(mdef, WAND_CLASS, AD_ELEC); - if (resists_elec(mdef)) { - if (g.vis && canseemon(mdef)) - pline_The("zap doesn't shock %s!", mon_nam(mdef)); - shieldeff(mdef->mx, mdef->my); - golemeffects(mdef, AD_ELEC, mhm.damage); - mhm.damage = 0; - } - /* only rings damage resistant players in destroy_item */ - mhm.damage += destroy_mitem(mdef, RING_CLASS, AD_ELEC); + mhitm_ad_elec(magr, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_ACID: if (magr->mcan) { diff --git a/src/mhitu.c b/src/mhitu.c index be4fb308b..3b146cd20 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -1108,19 +1108,9 @@ register struct attack *mattk; return mhm.hitflags; break; case AD_ELEC: - hitmsg(mtmp, mattk); - if (uncancelled) { - You("get zapped!"); - if (Shock_resistance) { - pline_The("zap doesn't shock you!"); - mhm.damage = 0; - } - if ((int) mtmp->m_lev > rn2(20)) - destroy_item(WAND_CLASS, AD_ELEC); - if ((int) mtmp->m_lev > rn2(20)) - destroy_item(RING_CLASS, AD_ELEC); - } else - mhm.damage = 0; + mhitm_ad_elec(mtmp, mattk, &g.youmonst, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_SLEE: hitmsg(mtmp, mattk); diff --git a/src/uhitm.c b/src/uhitm.c index c3e2fdff5..2d78004ed 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -2140,6 +2140,79 @@ struct mhitm_data *mhm; } } +void +mhitm_ad_elec(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 */ + int armpro = magic_negation(mdef); + /* since hero can't be cancelled, only defender's armor applies */ + boolean negated = !(rn2(10) >= 3 * armpro); + + if (negated) { + mhm->damage = 0; + return; + } + if (!Blind) + pline("%s is zapped!", Monnam(mdef)); + mhm->damage += destroy_mitem(mdef, WAND_CLASS, AD_ELEC); + if (resists_elec(mdef)) { + if (!Blind) + pline_The("zap doesn't shock %s!", mon_nam(mdef)); + golemeffects(mdef, AD_ELEC, mhm->damage); + shieldeff(mdef->mx, mdef->my); + mhm->damage = 0; + } + /* only rings damage resistant players in destroy_item */ + mhm->damage += destroy_mitem(mdef, RING_CLASS, AD_ELEC); + } else if (mdef == &g.youmonst) { + /* mhitu */ + int armpro = magic_negation(mdef); + boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro); + + hitmsg(magr, mattk); + if (uncancelled) { + You("get zapped!"); + if (Shock_resistance) { + pline_The("zap doesn't shock you!"); + mhm->damage = 0; + } + if ((int) magr->m_lev > rn2(20)) + destroy_item(WAND_CLASS, AD_ELEC); + if ((int) magr->m_lev > rn2(20)) + destroy_item(RING_CLASS, AD_ELEC); + } else + mhm->damage = 0; + } else { + /* mhitm */ + int armpro = magic_negation(mdef); + boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro); + + if (cancelled) { + mhm->damage = 0; + return; + } + if (g.vis && canseemon(mdef)) + pline("%s gets zapped!", Monnam(mdef)); + mhm->damage += destroy_mitem(mdef, WAND_CLASS, AD_ELEC); + if (resists_elec(mdef)) { + if (g.vis && canseemon(mdef)) + pline_The("zap doesn't shock %s!", mon_nam(mdef)); + shieldeff(mdef->mx, mdef->my); + golemeffects(mdef, AD_ELEC, mhm->damage); + mhm->damage = 0; + } + /* only rings damage resistant players in destroy_item */ + mhm->damage += destroy_mitem(mdef, RING_CLASS, AD_ELEC); + } +} + /* Template for monster hits monster for AD_FOO. - replace "break" with return @@ -2251,22 +2324,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */ return mhm.hitflags; break; case AD_ELEC: - if (negated) { - mhm.damage = 0; - break; - } - if (!Blind) - pline("%s is zapped!", Monnam(mdef)); - mhm.damage += destroy_mitem(mdef, WAND_CLASS, AD_ELEC); - if (resists_elec(mdef)) { - if (!Blind) - pline_The("zap doesn't shock %s!", mon_nam(mdef)); - golemeffects(mdef, AD_ELEC, mhm.damage); - shieldeff(mdef->mx, mdef->my); - mhm.damage = 0; - } - /* only rings damage resistant players in destroy_item */ - mhm.damage += destroy_mitem(mdef, RING_CLASS, AD_ELEC); + mhitm_ad_elec(&g.youmonst, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_ACID: if (resists_acid(mdef))