From af6c53ac7cd01df904f5a53c1a3a00ac48f18aea Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sat, 10 May 2025 18:42:38 +0300 Subject: [PATCH] m_respond code reorg and splitting --- src/mon.c | 68 +++++++++++++++++++++++++++++++-------------------- src/monmove.c | 13 ++-------- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/mon.c b/src/mon.c index 89d2949a5..049d21d14 100644 --- a/src/mon.c +++ b/src/mon.c @@ -22,6 +22,8 @@ staticfn boolean vamprises(struct monst *); staticfn void logdeadmon(struct monst *, int); staticfn void anger_quest_guardians(struct monst *); staticfn boolean ok_to_obliterate(struct monst *); +staticfn void m_respond_shrieker(struct monst *); +staticfn void m_respond_medusa(struct monst *); staticfn void qst_guardians_respond(void); staticfn void peacefuls_respond(struct monst *); staticfn void wake_nearto_core(coordxy, coordxy, int, boolean); @@ -4013,36 +4015,50 @@ mnearto( return res; } -/* monster responds to player action; not the same as a passive attack; - assumes reason for response has been tested, and response _must_ be made */ +/* shrieker special action: shriek, maybe summon monster, aggravate */ +staticfn void +m_respond_shrieker(struct monst *mtmp) +{ + if (!Deaf) { + pline("%s shrieks.", Monnam(mtmp)); + stop_occupation(); + } + if (!rn2(10)) { /* 1/10 chance per shriek to create a monster */ + /* new monster has a 1/13 chance to be a purple worm, random + otherwise; baby purple worm if adult is too difficult */ + (void) makemon(rn2(13) ? (struct permonst *) 0 + : &mons[montoostrong(PM_PURPLE_WORM, + monmax_difficulty_lev()) + ? PM_BABY_PURPLE_WORM : PM_PURPLE_WORM], + 0, 0, NO_MM_FLAGS); + } + aggravate(); +} + +/* medusa special action: gaze at hero */ +staticfn void +m_respond_medusa(struct monst *mtmp) +{ + int i; + + for (i = 0; i < NATTK; i++) + if (mtmp->data->mattk[i].aatyp == AT_GAZE) { + (void) gazemu(mtmp, &mtmp->data->mattk[i]); + break; + } +} + +/* monster responds to player action; not the same as a passive attack */ void m_respond(struct monst *mtmp) { - if (mtmp->data->msound == MS_SHRIEK) { - if (!Deaf) { - pline("%s shrieks.", Monnam(mtmp)); - stop_occupation(); - } - if (!rn2(10)) { /* 1/10 chance per shriek to create a monster */ - /* new monster has a 1/13 chance to be a purple worm, random - otherwise; baby purple worm if adult is too difficult */ - (void) makemon(rn2(13) ? (struct permonst *) 0 - : &mons[montoostrong(PM_PURPLE_WORM, - monmax_difficulty_lev()) - ? PM_BABY_PURPLE_WORM : PM_PURPLE_WORM], - 0, 0, NO_MM_FLAGS); - } + if (mtmp->data->msound == MS_SHRIEK && !um_dist(mtmp->mx, mtmp->my, 1)) + m_respond_shrieker(mtmp); + if (mtmp->data == &mons[PM_MEDUSA] && couldsee(mtmp->mx, mtmp->my)) + m_respond_medusa(mtmp); + /* Erinyes will inform surrounding monsters of your crimes */ + if (mtmp->data == &mons[PM_ERINYS] && !mtmp->mpeaceful && m_canseeu(mtmp)) aggravate(); - } - if (mtmp->data == &mons[PM_MEDUSA]) { - int i; - - for (i = 0; i < NATTK; i++) - if (mtmp->data->mattk[i].aatyp == AT_GAZE) { - (void) gazemu(mtmp, &mtmp->data->mattk[i]); - break; - } - } } /* how quest guardians respond when you attack the quest leader */ diff --git a/src/monmove.c b/src/monmove.c index b8c58cc8b..8bf665099 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -738,17 +738,8 @@ dochug(struct monst *mtmp) return 0; } - /* Erinyes will inform surrounding monsters of your crimes */ - if (mdat == &mons[PM_ERINYS] && !mtmp->mpeaceful && m_canseeu(mtmp)) - aggravate(); - - /* Shriekers and Medusa have irregular abilities which must be - checked every turn. These abilities do not cost a turn when - used. */ - if (mdat->msound == MS_SHRIEK && !um_dist(mtmp->mx, mtmp->my, 1)) - m_respond(mtmp); - if (mdat == &mons[PM_MEDUSA] && couldsee(mtmp->mx, mtmp->my)) - m_respond(mtmp); + /* some monsters have special abilities */ + m_respond(mtmp); if (DEADMONSTER(mtmp)) return 1; /* m_respond gaze can kill medusa */