From: Pasi Kallinen Date: Mon, 30 Nov 2020 19:12:18 +0000 (+0200) Subject: Unify ad_blnd X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d325e2cc60cd25f5e8c7cfa33d3d7cff7747a914;p=nethack Unify ad_blnd --- diff --git a/include/extern.h b/include/extern.h index db195453d..40cbd2fab 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2766,6 +2766,7 @@ E void FDECL(mhitm_ad_elec, (struct monst *, struct attack *, struct monst *, st 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 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 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 327222810..97fc90f6d 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -1123,19 +1123,9 @@ int dieroll; } break; case AD_BLND: - if (can_blnd(magr, mdef, mattk->aatyp, (struct obj *) 0)) { - register unsigned rnd_tmp; - - if (g.vis && mdef->mcansee && canspotmon(mdef)) - pline("%s is blinded.", Monnam(mdef)); - rnd_tmp = d((int) mattk->damn, (int) mattk->damd); - if ((rnd_tmp += mdef->mblinded) > 127) - rnd_tmp = 127; - mdef->mblinded = rnd_tmp; - mdef->mcansee = 0; - mdef->mstrategy &= ~STRAT_WAITFORU; - } - mhm.damage = 0; + mhitm_ad_blnd(magr, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_HALU: if (!magr->mcan && haseyes(pd) && mdef->mcansee) { diff --git a/src/mhitu.c b/src/mhitu.c index efea5a60d..e0f3da06d 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -1125,14 +1125,9 @@ register struct attack *mattk; } break; case AD_BLND: - if (can_blnd(mtmp, &g.youmonst, mattk->aatyp, (struct obj *) 0)) { - if (!Blind) - pline("%s blinds you!", Monnam(mtmp)); - make_blinded(Blinded + (long) mhm.damage, FALSE); - if (!Blind) - Your1(vision_clears); - } - mhm.damage = 0; + mhitm_ad_blnd(mtmp, mattk, &g.youmonst, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_DRST: ptmp = A_STR; diff --git a/src/uhitm.c b/src/uhitm.c index 9bdbd20ee..2148d458b 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -2432,6 +2432,54 @@ struct mhitm_data *mhm; } } +void +mhitm_ad_blnd(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 */ + if (can_blnd(magr, mdef, mattk->aatyp, (struct obj *) 0)) { + if (!Blind && mdef->mcansee) + pline("%s is blinded.", Monnam(mdef)); + mdef->mcansee = 0; + mhm->damage += mdef->mblinded; + if (mhm->damage > 127) + mhm->damage = 127; + mdef->mblinded = mhm->damage; + } + mhm->damage = 0; + } else if (mdef == &g.youmonst) { + /* mhitu */ + if (can_blnd(magr, mdef, mattk->aatyp, (struct obj *) 0)) { + if (!Blind) + pline("%s blinds you!", Monnam(magr)); + make_blinded(Blinded + (long) mhm->damage, FALSE); + if (!Blind) + Your1(vision_clears); + } + mhm->damage = 0; + } else { + /* mhitm */ + if (can_blnd(magr, mdef, mattk->aatyp, (struct obj *) 0)) { + register unsigned rnd_tmp; + + if (g.vis && mdef->mcansee && canspotmon(mdef)) + pline("%s is blinded.", Monnam(mdef)); + rnd_tmp = d((int) mattk->damn, (int) mattk->damd); + if ((rnd_tmp += mdef->mblinded) > 127) + rnd_tmp = 127; + mdef->mblinded = rnd_tmp; + mdef->mcansee = 0; + mdef->mstrategy &= ~STRAT_WAITFORU; + } + mhm->damage = 0; + } +} /* Template for monster hits monster for AD_FOO. - replace "break" with return @@ -2573,16 +2621,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */ return mhm.hitflags; break; case AD_BLND: - if (can_blnd(&g.youmonst, mdef, mattk->aatyp, (struct obj *) 0)) { - if (!Blind && mdef->mcansee) - pline("%s is blinded.", Monnam(mdef)); - mdef->mcansee = 0; - mhm.damage += mdef->mblinded; - if (mhm.damage > 127) - mhm.damage = 127; - mdef->mblinded = mhm.damage; - } - mhm.damage = 0; + mhitm_ad_blnd(&g.youmonst, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_CURS: if (night() && !rn2(10) && !mdef->mcan) {