From: Pasi Kallinen Date: Mon, 30 Nov 2020 20:59:06 +0000 (+0200) Subject: Unify ad_poly X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=618feabd8831a848e9d3764f1d76ae86fb5de202;p=nethack Unify ad_poly --- diff --git a/include/extern.h b/include/extern.h index 28292037c..856cfd0cf 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2779,6 +2779,7 @@ E void FDECL(mhitm_ad_slim, (struct monst *, struct attack *, struct monst *, st 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 void FDECL(mhitm_ad_poly, (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 88a29c9a2..69ba4405c 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -1224,8 +1224,9 @@ int dieroll; return mhm.hitflags; break; case AD_POLY: - if (!magr->mcan && mhm.damage < mdef->mhp) - mhm.damage = mon_poly(magr, mdef, mhm.damage); + mhitm_ad_poly(magr, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; default: mhm.damage = 0; diff --git a/src/mhitu.c b/src/mhitu.c index 4213609b4..9957e0d3e 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -1480,8 +1480,9 @@ register struct attack *mattk; return mhm.hitflags; break; case AD_POLY: - if (uncancelled && Maybe_Half_Phys(mhm.damage) < (Upolyd ? u.mh : u.uhp)) - mhm.damage = mon_poly(mtmp, &g.youmonst, mhm.damage); + mhitm_ad_poly(mtmp, mattk, &g.youmonst, &mhm); + if (mhm.done) + return mhm.hitflags; break; default: mhm.damage = 0; diff --git a/src/uhitm.c b/src/uhitm.c index 2d745667e..83bdaa7e1 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -3182,6 +3182,40 @@ struct mhitm_data *mhm; } } +void +mhitm_ad_poly(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 < mdef->mhp) + mhm->damage = mon_poly(magr, mdef, mhm->damage); + } else if (mdef == &g.youmonst) { + /* mhitu */ + int armpro = magic_negation(mdef); + boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro); + + if (uncancelled && Maybe_Half_Phys(mhm->damage) < (Upolyd ? u.mh : u.uhp)) + mhm->damage = mon_poly(magr, mdef, mhm->damage); + } else { + /* mhitm */ + int armpro = magic_negation(mdef); + boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro); + + if (!magr->mcan && mhm->damage < mdef->mhp) + mhm->damage = mon_poly(magr, mdef, mhm->damage); + } +} + /* Template for monster hits monster for AD_FOO. - replace "break" with return - replace "return" with mhm->done = TRUE @@ -3419,8 +3453,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */ return mhm.hitflags; break; case AD_POLY: - if (!negated && mhm.damage < mdef->mhp) - mhm.damage = mon_poly(&g.youmonst, mdef, mhm.damage); + mhitm_ad_poly(&g.youmonst, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; default: mhm.damage = 0;