From e251bb6a827d89c444a59c0b65c23a4dfa9150d3 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Wed, 15 Dec 2021 22:11:19 +0200 Subject: [PATCH] Decouple mon state adjustment from find_roll_to_hit If you have a function named like that, and it goes and changes the monster state, that's just wrong. Move waking up the monster from the hit into separate function. --- include/extern.h | 1 + src/dokick.c | 1 + src/uhitm.c | 39 ++++++++++++++++++++++++++++----------- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/include/extern.h b/include/extern.h index fe5c2f6f5..4e0c9169a 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2707,6 +2707,7 @@ extern void dynamic_multi_reason(struct monst *, const char *, boolean); extern void erode_armor(struct monst *, int); extern boolean attack_checks(struct monst *, struct obj *); extern void check_caitiff(struct monst *); +extern void mon_maybe_wakeup_on_hit(struct monst *); extern int find_roll_to_hit(struct monst *, uchar, struct obj *, int *, int *); extern boolean force_attack(struct monst *, boolean); extern boolean do_attack(struct monst *); diff --git a/src/dokick.c b/src/dokick.c index 25026d5e6..376e359d0 100644 --- a/src/dokick.c +++ b/src/dokick.c @@ -178,6 +178,7 @@ kick_monster(struct monst *mon, xchar x, xchar y) attknum = 0, tmp = find_roll_to_hit(mon, AT_KICK, (struct obj *) 0, &attknum, &armorpenalty); + mon_maybe_wakeup_on_hit(mon); for (i = 0; i < NATTK; i++) { /* first of two kicks might have provoked counterattack diff --git a/src/uhitm.c b/src/uhitm.c index 2d4bd577a..5a34396d9 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -276,6 +276,24 @@ check_caitiff(struct monst *mtmp) } } +/* wake up monster, maybe unparalyze it */ +void +mon_maybe_wakeup_on_hit(struct monst *mtmp) +{ + if (mtmp->msleeping) + mtmp->msleeping = 0; + + if (!mtmp->mcanmove) { + if (!rn2(10)) { + mtmp->mcanmove = 1; + mtmp->mfrozen = 0; + } + } +} + +/* how easy it is for hero to hit a monster, + using attack type aatyp and/or weapon. + larger value == easier to hit */ int find_roll_to_hit(struct monst *mtmp, uchar aatyp, /* usually AT_WEAP or AT_KICK */ @@ -296,23 +314,15 @@ find_roll_to_hit(struct monst *mtmp, check_caitiff(mtmp); } - /* adjust vs. (and possibly modify) monster state */ + /* adjust vs. monster state */ if (mtmp->mstun) tmp += 2; if (mtmp->mflee) tmp += 2; - - if (mtmp->msleeping) { - mtmp->msleeping = 0; + if (mtmp->msleeping) tmp += 2; - } - if (!mtmp->mcanmove) { + if (!mtmp->mcanmove) tmp += 4; - if (!rn2(10)) { - mtmp->mcanmove = 1; - mtmp->mfrozen = 0; - } - } /* role/race adjustments */ if (Role_if(PM_MONK) && !Upolyd) { @@ -614,6 +624,7 @@ hitum_cleave(struct monst *target, /* non-Null; forcefight at nothing doesn't tmp = find_roll_to_hit(mtmp, uattk->aatyp, uwep, &attknum, &armorpenalty); + mon_maybe_wakeup_on_hit(mtmp); dieroll = rnd(20); mhit = (tmp > dieroll); g.bhitpos.x = tx, g.bhitpos.y = ty; /* normally set up by @@ -649,6 +660,8 @@ hitum(struct monst *mon, struct attack *uattk) int dieroll = rnd(20); int mhit = (tmp > dieroll || u.uswallow); + mon_maybe_wakeup_on_hit(mon); + /* Cleaver attacks three spots, 'mon' and one on either side of 'mon'; it can't be part of dual-wielding but we guard against that anyway; cleave return value reflects status of primary target ('mon') */ @@ -670,6 +683,7 @@ hitum(struct monst *mon, struct attack *uattk) if (u.twoweap && !g.override_confirmation && malive && m_at(x, y) == mon) { tmp = find_roll_to_hit(mon, uattk->aatyp, uswapwep, &attknum, &armorpenalty); + mon_maybe_wakeup_on_hit(mon); dieroll = rnd(20); mhit = (tmp > dieroll || u.uswallow); malive = known_hitum(mon, uswapwep, &mhit, tmp, armorpenalty, uattk, @@ -4584,6 +4598,7 @@ hmonas(struct monst *mon) tmp = find_roll_to_hit(mon, AT_WEAP, weapon, &attknum, &armorpenalty); + mon_maybe_wakeup_on_hit(mon); dieroll = rnd(20); dhit = (tmp > dieroll || u.uswallow); /* caller must set g.bhitpos */ @@ -4625,6 +4640,7 @@ hmonas(struct monst *mon) /*weaponless:*/ tmp = find_roll_to_hit(mon, mattk->aatyp, (struct obj *) 0, &attknum, &armorpenalty); + mon_maybe_wakeup_on_hit(mon); dieroll = rnd(20); dhit = (tmp > dieroll || u.uswallow); if (dhit) { @@ -4817,6 +4833,7 @@ hmonas(struct monst *mon) case AT_ENGL: tmp = find_roll_to_hit(mon, mattk->aatyp, (struct obj *) 0, &attknum, &armorpenalty); + mon_maybe_wakeup_on_hit(mon); if ((dhit = (tmp > rnd(20 + i)))) { wakeup(mon, TRUE); if (mon->data == &mons[PM_SHADE]) {