From: Pasi Kallinen Date: Mon, 30 Nov 2020 19:41:28 +0000 (+0200) Subject: Unify ad_drst X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1ca0165bb978aab4e1546f4f5717c2e9101d0d58;p=nethack Unify ad_drst --- diff --git a/include/extern.h b/include/extern.h index 8bfa0465f..6abcd8d1c 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2768,6 +2768,7 @@ E void FDECL(mhitm_ad_sgld, (struct monst *, struct attack *, struct monst *, st 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 void FDECL(mhitm_ad_curs, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); +E void FDECL(mhitm_ad_drst, (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 5a4bfa4bd..8361d5490 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -1216,24 +1216,9 @@ int dieroll; case AD_DRST: case AD_DRDX: case AD_DRCO: - if (!cancelled && !rn2(8)) { - if (g.vis && canspotmon(magr)) - pline("%s %s was poisoned!", s_suffix(Monnam(magr)), - mpoisons_subj(magr, mattk)); - if (resists_poison(mdef)) { - if (g.vis && canspotmon(mdef) && canspotmon(magr)) - pline_The("poison doesn't seem to affect %s.", - mon_nam(mdef)); - } else { - if (rn2(10)) - mhm.damage += rn1(10, 6); - else { - if (g.vis && canspotmon(mdef)) - pline_The("poison was deadly..."); - mhm.damage = mdef->mhp; - } - } - } + mhitm_ad_drst(magr, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_DRIN: if (g.notonhead || !has_head(pd)) { diff --git a/src/mhitu.c b/src/mhitu.c index d4d61a87f..8036df820 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -1130,20 +1130,11 @@ register struct attack *mattk; return mhm.hitflags; break; case AD_DRST: - ptmp = A_STR; - goto dopois; case AD_DRDX: - ptmp = A_DEX; - goto dopois; case AD_DRCO: - ptmp = A_CON; - dopois: - hitmsg(mtmp, mattk); - if (uncancelled && !rn2(8)) { - Sprintf(buf, "%s %s", s_suffix(Monnam(mtmp)), - mpoisons_subj(mtmp, mattk)); - poisoned(buf, ptmp, mdat->mname, 30, FALSE); - } + mhitm_ad_drst(mtmp, mattk, &g.youmonst, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_DRIN: hitmsg(mtmp, mattk); diff --git a/src/uhitm.c b/src/uhitm.c index eca8843b6..d0b526e9f 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -2566,6 +2566,78 @@ struct mhitm_data *mhm; } } +void +mhitm_ad_drst(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 */ + int armpro = magic_negation(mdef); + /* since hero can't be cancelled, only defender's armor applies */ + boolean negated = !(rn2(10) >= 3 * armpro); + + if (!negated && !rn2(8)) { + Your("%s was poisoned!", mpoisons_subj(magr, mattk)); + if (resists_poison(mdef)) { + pline_The("poison doesn't seem to affect %s.", mon_nam(mdef)); + } else { + if (!rn2(10)) { + Your("poison was deadly..."); + mhm->damage = mdef->mhp; + } else + mhm->damage += rn1(10, 6); + } + } + } else if (mdef == &g.youmonst) { + /* mhitu */ + int armpro = magic_negation(mdef); + boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro); + int ptmp; + char buf[BUFSZ]; + + switch (mattk->adtyp) { + case AD_DRST: ptmp = A_STR; break; + case AD_DRDX: ptmp = A_DEX; break; + case AD_DRCO: ptmp = A_CON; break; + } + hitmsg(magr, mattk); + if (uncancelled && !rn2(8)) { + Sprintf(buf, "%s %s", s_suffix(Monnam(magr)), + mpoisons_subj(magr, mattk)); + poisoned(buf, ptmp, pa->mname, 30, FALSE); + } + } else { + /* mhitm */ + int armpro = magic_negation(mdef); + boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro); + + if (!cancelled && !rn2(8)) { + if (g.vis && canspotmon(magr)) + pline("%s %s was poisoned!", s_suffix(Monnam(magr)), + mpoisons_subj(magr, mattk)); + if (resists_poison(mdef)) { + if (g.vis && canspotmon(mdef) && canspotmon(magr)) + pline_The("poison doesn't seem to affect %s.", + mon_nam(mdef)); + } else { + if (rn2(10)) + mhm->damage += rn1(10, 6); + else { + if (g.vis && canspotmon(mdef)) + pline_The("poison was deadly..."); + mhm->damage = mdef->mhp; + } + } + } + } +} + /* Template for monster hits monster for AD_FOO. - replace "break" with return - replace "return" with mhm->done = TRUE @@ -2743,18 +2815,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */ case AD_DRST: case AD_DRDX: case AD_DRCO: - if (!negated && !rn2(8)) { - Your("%s was poisoned!", mpoisons_subj(&g.youmonst, mattk)); - if (resists_poison(mdef)) { - pline_The("poison doesn't seem to affect %s.", mon_nam(mdef)); - } else { - if (!rn2(10)) { - Your("poison was deadly..."); - mhm.damage = mdef->mhp; - } else - mhm.damage += rn1(10, 6); - } - } + mhitm_ad_drst(&g.youmonst, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_DRIN: { struct obj *helmet;