From 0620ca1bc6ce9b5e11ba46d377cf6f3ac0583a11 Mon Sep 17 00:00:00 2001 From: "nethack.rankin" Date: Thu, 25 May 2006 04:36:11 +0000 Subject: [PATCH] fix #H105 - inconsistent handling of "meditating" monsters (trunk only) From a bug report, monsters with the wait strategy (described as "meditating" by stethoscope probing) could be affected by music but left meditating. Various wake up attempts shared the same situation. Finish waiting if the monster would have been woken (or pacified). I didn't search for places that diddle the msleeping bit directly instead of calling one of the assorted wake() routines. A fair bit of this is making usage of DEADMONSTER() be consistent. Sooner or later there'll be another monster movement overhaul and those if (DEADMONSTER(mon)) continue; statements will all go away. (Probably just wishful thinking.) --- doc/fixes35.0 | 2 ++ src/mon.c | 29 +++++++++++++-------- src/music.c | 71 ++++++++++++++++++++++++++------------------------- 3 files changed, 56 insertions(+), 46 deletions(-) diff --git a/doc/fixes35.0 b/doc/fixes35.0 index c4419dfc7..038d9ff41 100644 --- a/doc/fixes35.0 +++ b/doc/fixes35.0 @@ -140,6 +140,8 @@ don't welcome the hero to Delphi if the Oracle was angered before first entry shopkeeper polymorphed into animal form can no longer speak don't give attribute adjustment messages ("you feel wise") unless the current value actually changes +meditating monsters stop meditating when affected by something which wakes + sleeping mosnters Platform- and/or Interface-Specific Fixes diff --git a/src/mon.c b/src/mon.c index 623a6d902..139735783 100644 --- a/src/mon.c +++ b/src/mon.c @@ -580,10 +580,9 @@ movemon() for(mtmp = fmon; mtmp; mtmp = nmtmp) { nmtmp = mtmp->nmon; + if (DEADMONSTER(mtmp)) continue; /* Find a monster that we have not treated yet. */ - if(DEADMONSTER(mtmp)) - continue; if(mtmp->movement < NORMAL_SPEED) continue; @@ -2188,11 +2187,13 @@ register struct monst *mtmp; int got_mad = 0; /* guardians will sense this attack even if they can't see it */ - for (mon = fmon; mon; mon = mon->nmon) - if (!DEADMONSTER(mon) && mon->data == q_guardian && mon->mpeaceful) { + for (mon = fmon; mon; mon = mon->nmon) { + if (DEADMONSTER(mon)) continue; + if (mon->data == q_guardian && mon->mpeaceful) { mon->mpeaceful = 0; if (canseemon(mon)) ++got_mad; } + } if (got_mad && !Hallucination) pline_The("%s appear%s to be angry too...", got_mad == 1 ? q_guardian->mname : @@ -2208,22 +2209,26 @@ register struct monst *mtmp; mtmp->msleeping = 0; finish_meating(mtmp); setmangry(mtmp); - if(mtmp->m_ap_type) seemimic(mtmp); - else if (context.forcefight && !context.mon_moving && mtmp->mundetected) { + if (mtmp->m_ap_type) { + seemimic(mtmp); + } else if (context.forcefight && !context.mon_moving && + mtmp->mundetected) { mtmp->mundetected = 0; newsym(mtmp->mx, mtmp->my); } } -/* Wake up nearby monsters. */ +/* Wake up nearby monsters without angering them. */ void wake_nearby() { register struct monst *mtmp; - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (!DEADMONSTER(mtmp) && distu(mtmp->mx,mtmp->my) < u.ulevel*20) { + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) continue; + if (distu(mtmp->mx,mtmp->my) < u.ulevel * 20) { mtmp->msleeping = 0; + mtmp->mstrategy &= ~STRAT_WAITMASK; if (mtmp->mtame && !mtmp->isminion) EDOG(mtmp)->whistletime = moves; } @@ -2238,9 +2243,11 @@ register int x, y, distance; register struct monst *mtmp; for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (!DEADMONSTER(mtmp) && mtmp->msleeping && (distance == 0 || - dist2(mtmp->mx, mtmp->my, x, y) < distance)) + if (DEADMONSTER(mtmp)) continue; + if (distance == 0 || dist2(mtmp->mx, mtmp->my, x, y) < distance) { mtmp->msleeping = 0; + mtmp->mstrategy &= ~STRAT_WAITMASK; + } } } diff --git a/src/music.c b/src/music.c index 6e0124acc..388334dec 100644 --- a/src/music.c +++ b/src/music.c @@ -61,23 +61,22 @@ STATIC_OVL void awaken_monsters(distance) int distance; { - register struct monst *mtmp = fmon; + register struct monst *mtmp; register int distm; - while(mtmp) { - if (!DEADMONSTER(mtmp)) { - distm = distu(mtmp->mx, mtmp->my); - if (distm < distance) { - mtmp->msleeping = 0; - mtmp->mcanmove = 1; - mtmp->mfrozen = 0; - /* May scare some monsters */ - if (distm < distance/3 && + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) continue; + if ((distm = distu(mtmp->mx, mtmp->my)) < distance) { + mtmp->msleeping = 0; + mtmp->mcanmove = 1; + mtmp->mfrozen = 0; + /* may scare some monsters -- waiting monsters excluded */ + if ((mtmp->mstrategy & STRAT_WAITMASK) != 0) + mtmp->mstrategy &= ~STRAT_WAITMASK; + else if (distm < distance/3 && !resist(mtmp, TOOL_CLASS, 0, NOTELL)) - monflee(mtmp, 0, FALSE, TRUE); - } + monflee(mtmp, 0, FALSE, TRUE); } - mtmp = mtmp->nmon; } } @@ -89,15 +88,15 @@ STATIC_OVL void put_monsters_to_sleep(distance) int distance; { - register struct monst *mtmp = fmon; - - while(mtmp) { - if (!DEADMONSTER(mtmp) && distu(mtmp->mx, mtmp->my) < distance && - sleep_monst(mtmp, d(10,10), TOOL_CLASS)) { - mtmp->msleeping = 1; /* 10d10 turns + wake_nearby to rouse */ - slept_monst(mtmp); - } - mtmp = mtmp->nmon; + register struct monst *mtmp; + + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) continue; + if (distu(mtmp->mx, mtmp->my) < distance && + sleep_monst(mtmp, d(10,10), TOOL_CLASS)) { + mtmp->msleeping = 1; /* 10d10 turns + wake_nearby to rouse */ + slept_monst(mtmp); + } } } @@ -109,15 +108,17 @@ STATIC_OVL void charm_snakes(distance) int distance; { - register struct monst *mtmp = fmon; + register struct monst *mtmp; int could_see_mon, was_peaceful; - while (mtmp) { - if (!DEADMONSTER(mtmp) && mtmp->data->mlet == S_SNAKE && mtmp->mcanmove && + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) continue; + if (mtmp->data->mlet == S_SNAKE && mtmp->mcanmove && distu(mtmp->mx, mtmp->my) < distance) { was_peaceful = mtmp->mpeaceful; mtmp->mpeaceful = 1; mtmp->mavenge = 0; + mtmp->mstrategy &= ~STRAT_WAITMASK; could_see_mon = canseemon(mtmp); mtmp->mundetected = 0; newsym(mtmp->mx, mtmp->my); @@ -131,7 +132,6 @@ int distance; was_peaceful ? "" : ", and now seems quieter"); } } - mtmp = mtmp->nmon; } } @@ -143,20 +143,21 @@ STATIC_OVL void calm_nymphs(distance) int distance; { - register struct monst *mtmp = fmon; + register struct monst *mtmp; - while (mtmp) { - if (!DEADMONSTER(mtmp) && mtmp->data->mlet == S_NYMPH && mtmp->mcanmove && + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) continue; + if (mtmp->data->mlet == S_NYMPH && mtmp->mcanmove && distu(mtmp->mx, mtmp->my) < distance) { mtmp->msleeping = 0; mtmp->mpeaceful = 1; mtmp->mavenge = 0; + mtmp->mstrategy &= ~STRAT_WAITMASK; if (canseemon(mtmp)) pline( "%s listens cheerfully to the music, then seems quieter.", Monnam(mtmp)); } - mtmp = mtmp->nmon; } } @@ -165,19 +166,19 @@ int distance; void awaken_soldiers() { - register struct monst *mtmp = fmon; + register struct monst *mtmp; - while(mtmp) { - if (!DEADMONSTER(mtmp) && - is_mercenary(mtmp->data) && mtmp->data != &mons[PM_GUARD]) { + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) continue; + if (is_mercenary(mtmp->data) && mtmp->data != &mons[PM_GUARD]) { mtmp->mpeaceful = mtmp->msleeping = mtmp->mfrozen = 0; mtmp->mcanmove = 1; + mtmp->mstrategy &= ~STRAT_WAITMASK; if (canseemon(mtmp)) pline("%s is now ready for battle!", Monnam(mtmp)); else Norep("You hear the rattle of battle gear being readied."); } - mtmp = mtmp->nmon; } } -- 2.40.0