From: Pasi Kallinen Date: Tue, 1 Dec 2020 09:05:14 +0000 (+0200) Subject: Unify ad_stun X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=337e7da049718cae352f3d5c83f4e83de79da926;p=nethack Unify ad_stun --- diff --git a/include/extern.h b/include/extern.h index 94f3d8a0d..f4d5c0fcf 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2789,6 +2789,7 @@ E void FDECL(mhitm_ad_phys, (struct monst *, struct attack *, struct monst *, st E void FDECL(mhitm_ad_ston, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); E void FDECL(mhitm_ad_were, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); E void FDECL(mhitm_ad_heal, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); +E void FDECL(mhitm_ad_stun, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); E boolean FDECL(do_stone_u, (struct monst *)); E void FDECL(do_stone_mon, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); E int FDECL(damageum, (struct monst *, struct attack *, int)); diff --git a/src/mhitm.c b/src/mhitm.c index e638a97b0..decb034b8 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -950,13 +950,10 @@ int dieroll; } break; case AD_STUN: - if (magr->mcan) - break; - if (canseemon(mdef)) - pline("%s %s for a moment.", Monnam(mdef), - makeplural(stagger(pd, "stagger"))); - mdef->mstun = 1; - goto physical; + mhitm_ad_stun(magr, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; + break; case AD_LEGS: if (magr->mcan) { mhm.damage = 0; diff --git a/src/mhitu.c b/src/mhitu.c index 1e630dfd6..a67f78e38 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -1239,11 +1239,9 @@ register struct attack *mattk; return mhm.hitflags; break; case AD_STUN: - hitmsg(mtmp, mattk); - if (!mtmp->mcan && !rn2(4)) { - make_stunned((HStun & TIMEOUT) + (long) mhm.damage, TRUE); - mhm.damage /= 2; - } + mhitm_ad_stun(mtmp, mattk, &g.youmonst, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_ACID: mhitm_ad_acid(mtmp, mattk, &g.youmonst, &mhm); diff --git a/src/uhitm.c b/src/uhitm.c index 56e6bc2c5..7824e6ac2 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -3771,6 +3771,45 @@ struct mhitm_data *mhm; } } +void +mhitm_ad_stun(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 (!Blind) + pline("%s %s for a moment.", Monnam(mdef), + makeplural(stagger(pd, "stagger"))); + mdef->mstun = 1; + mhitm_ad_phys(magr, mattk, mdef, mhm); + if (mhm->done) + return; + } else if (mdef == &g.youmonst) { + /* mhitu */ + hitmsg(magr, mattk); + if (!magr->mcan && !rn2(4)) { + make_stunned((HStun & TIMEOUT) + (long) mhm->damage, TRUE); + mhm->damage /= 2; + } + } else { + /* mhitm */ + if (magr->mcan) + return; + if (canseemon(mdef)) + pline("%s %s for a moment.", Monnam(mdef), + makeplural(stagger(pd, "stagger"))); + mdef->mstun = 1; + mhitm_ad_phys(magr, mattk, mdef, mhm); + if (mhm->done) + return; + } +} + /* Template for monster hits monster for AD_FOO. - replace "break" with return - replace "return" with mhm->done = TRUE @@ -3833,11 +3872,10 @@ int specialdmg; /* blessed and/or silver bonus against various things */ } switch (mattk->adtyp) { case AD_STUN: - if (!Blind) - pline("%s %s for a moment.", Monnam(mdef), - makeplural(stagger(pd, "stagger"))); - mdef->mstun = 1; - goto physical; + mhitm_ad_stun(&g.youmonst, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; + break; case AD_LEGS: #if 0 if (u.ucancelled) {