From: Pasi Kallinen Date: Mon, 30 Nov 2020 17:18:42 +0000 (+0200) Subject: Unify ad_dcay X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6436ea1532213d6ee5f8248dfc4b06034ff45b4c;p=nethack Unify ad_dcay --- diff --git a/include/extern.h b/include/extern.h index 78417eba6..e45fcdbd3 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2757,6 +2757,7 @@ E boolean FDECL(shade_miss, (struct monst *, struct monst *, struct obj *, BOOLEAN_P, BOOLEAN_P)); E void FDECL(mhitm_ad_rust, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); E void FDECL(mhitm_ad_corr, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); +E void FDECL(mhitm_ad_dcay, (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 397673396..875884b37 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -1111,22 +1111,9 @@ int dieroll; return mhm.hitflags; break; case AD_DCAY: - if (magr->mcan) - break; - if (completelyrots(pd)) { /* PM_WOOD_GOLEM || PM_LEATHER_GOLEM */ - /* note: the life-saved case is hypothetical because - life-saving doesn't work for golems */ - if (g.vis && canseemon(mdef)) - pline("%s %s to pieces!", Monnam(mdef), - !mlifesaver(mdef) ? "falls" : "starts to fall"); - monkilled(mdef, (char *) 0, AD_DCAY); - if (!DEADMONSTER(mdef)) - return 0; - return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); - } - erode_armor(mdef, ERODE_CORRODE); - mdef->mstrategy &= ~STRAT_WAITFORU; - mhm.damage = 0; + mhitm_ad_dcay(magr, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_STON: if (magr->mcan) diff --git a/src/mhitu.c b/src/mhitu.c index 767ed19e7..ec8988807 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -1498,16 +1498,9 @@ register struct attack *mattk; return mhm.hitflags; break; case AD_DCAY: - hitmsg(mtmp, mattk); - if (mtmp->mcan) - break; - if (completelyrots(g.youmonst.data)) { - You("rot!"); - /* KMH -- this is okay with unchanging */ - rehumanize(); - break; - } - erode_armor(&g.youmonst, ERODE_ROT); + mhitm_ad_dcay(mtmp, mattk, &g.youmonst, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_HEAL: /* a cancelled nurse is just an ordinary monster, diff --git a/src/uhitm.c b/src/uhitm.c index 53ff72678..859122d6f 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -1776,6 +1776,62 @@ struct mhitm_data *mhm; } } +void +mhitm_ad_dcay(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 (completelyrots(pd)) { /* wood golem or leather golem */ + pline("%s %s to pieces!", Monnam(mdef), + !mlifesaver(mdef) ? "falls" : "starts to fall"); + xkilled(mdef, XKILL_NOMSG); + } + erode_armor(mdef, ERODE_ROT); + mhm->damage = 0; + } else if (mdef == &g.youmonst) { + /* mhitu */ + hitmsg(magr, mattk); + if (magr->mcan) + return; + if (completelyrots(pd)) { + You("rot!"); + /* KMH -- this is okay with unchanging */ + rehumanize(); + return; + } + erode_armor(mdef, ERODE_ROT); + } else { + /* mhitm */ + if (magr->mcan) + return; + if (completelyrots(pd)) { /* PM_WOOD_GOLEM || PM_LEATHER_GOLEM */ + /* note: the life-saved case is hypothetical because + life-saving doesn't work for golems */ + if (g.vis && canseemon(mdef)) + pline("%s %s to pieces!", Monnam(mdef), + !mlifesaver(mdef) ? "falls" : "starts to fall"); + monkilled(mdef, (char *) 0, AD_DCAY); + if (!DEADMONSTER(mdef)) { + mhm->done = TRUE; + mhm->hitflags = MM_MISS; + return; + } + mhm->done = TRUE; + mhm->hitflags = (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); + return; + } + erode_armor(mdef, ERODE_CORRODE); + mdef->mstrategy &= ~STRAT_WAITFORU; + mhm->damage = 0; + } +} + /* Template for monster hits monster for AD_FOO. - replace "break" with return - replace "return" with mhm->done = TRUE @@ -2064,13 +2120,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */ return mhm.hitflags; break; case AD_DCAY: - if (completelyrots(pd)) { /* wood golem or leather golem */ - pline("%s %s to pieces!", Monnam(mdef), - !mlifesaver(mdef) ? "falls" : "starts to fall"); - xkilled(mdef, XKILL_NOMSG); - } - erode_armor(mdef, ERODE_ROT); - mhm.damage = 0; + mhitm_ad_dcay(&g.youmonst, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_DREN: if (!negated && !rn2(4))