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.)
This commit is contained in:
nethack.rankin
2006-05-25 04:36:11 +00:00
parent c67b9788fc
commit 0620ca1bc6
3 changed files with 55 additions and 45 deletions
+2
View File
@@ -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 shopkeeper polymorphed into animal form can no longer speak
don't give attribute adjustment messages ("you feel wise") unless the current don't give attribute adjustment messages ("you feel wise") unless the current
value actually changes value actually changes
meditating monsters stop meditating when affected by something which wakes
sleeping mosnters
Platform- and/or Interface-Specific Fixes Platform- and/or Interface-Specific Fixes
+18 -11
View File
@@ -580,10 +580,9 @@ movemon()
for(mtmp = fmon; mtmp; mtmp = nmtmp) { for(mtmp = fmon; mtmp; mtmp = nmtmp) {
nmtmp = mtmp->nmon; nmtmp = mtmp->nmon;
if (DEADMONSTER(mtmp)) continue;
/* Find a monster that we have not treated yet. */ /* Find a monster that we have not treated yet. */
if(DEADMONSTER(mtmp))
continue;
if(mtmp->movement < NORMAL_SPEED) if(mtmp->movement < NORMAL_SPEED)
continue; continue;
@@ -2188,11 +2187,13 @@ register struct monst *mtmp;
int got_mad = 0; int got_mad = 0;
/* guardians will sense this attack even if they can't see it */ /* guardians will sense this attack even if they can't see it */
for (mon = fmon; mon; mon = mon->nmon) for (mon = fmon; mon; mon = mon->nmon) {
if (!DEADMONSTER(mon) && mon->data == q_guardian && mon->mpeaceful) { if (DEADMONSTER(mon)) continue;
if (mon->data == q_guardian && mon->mpeaceful) {
mon->mpeaceful = 0; mon->mpeaceful = 0;
if (canseemon(mon)) ++got_mad; if (canseemon(mon)) ++got_mad;
} }
}
if (got_mad && !Hallucination) if (got_mad && !Hallucination)
pline_The("%s appear%s to be angry too...", pline_The("%s appear%s to be angry too...",
got_mad == 1 ? q_guardian->mname : got_mad == 1 ? q_guardian->mname :
@@ -2208,22 +2209,26 @@ register struct monst *mtmp;
mtmp->msleeping = 0; mtmp->msleeping = 0;
finish_meating(mtmp); finish_meating(mtmp);
setmangry(mtmp); setmangry(mtmp);
if(mtmp->m_ap_type) seemimic(mtmp); if (mtmp->m_ap_type) {
else if (context.forcefight && !context.mon_moving && mtmp->mundetected) { seemimic(mtmp);
} else if (context.forcefight && !context.mon_moving &&
mtmp->mundetected) {
mtmp->mundetected = 0; mtmp->mundetected = 0;
newsym(mtmp->mx, mtmp->my); newsym(mtmp->mx, mtmp->my);
} }
} }
/* Wake up nearby monsters. */ /* Wake up nearby monsters without angering them. */
void void
wake_nearby() wake_nearby()
{ {
register struct monst *mtmp; register struct monst *mtmp;
for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (!DEADMONSTER(mtmp) && distu(mtmp->mx,mtmp->my) < u.ulevel*20) { if (DEADMONSTER(mtmp)) continue;
if (distu(mtmp->mx,mtmp->my) < u.ulevel * 20) {
mtmp->msleeping = 0; mtmp->msleeping = 0;
mtmp->mstrategy &= ~STRAT_WAITMASK;
if (mtmp->mtame && !mtmp->isminion) if (mtmp->mtame && !mtmp->isminion)
EDOG(mtmp)->whistletime = moves; EDOG(mtmp)->whistletime = moves;
} }
@@ -2238,9 +2243,11 @@ register int x, y, distance;
register struct monst *mtmp; register struct monst *mtmp;
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (!DEADMONSTER(mtmp) && mtmp->msleeping && (distance == 0 || if (DEADMONSTER(mtmp)) continue;
dist2(mtmp->mx, mtmp->my, x, y) < distance)) if (distance == 0 || dist2(mtmp->mx, mtmp->my, x, y) < distance) {
mtmp->msleeping = 0; mtmp->msleeping = 0;
mtmp->mstrategy &= ~STRAT_WAITMASK;
}
} }
} }
+35 -34
View File
@@ -61,23 +61,22 @@ STATIC_OVL void
awaken_monsters(distance) awaken_monsters(distance)
int distance; int distance;
{ {
register struct monst *mtmp = fmon; register struct monst *mtmp;
register int distm; register int distm;
while(mtmp) { for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (!DEADMONSTER(mtmp)) { if (DEADMONSTER(mtmp)) continue;
distm = distu(mtmp->mx, mtmp->my); if ((distm = distu(mtmp->mx, mtmp->my)) < distance) {
if (distm < distance) { mtmp->msleeping = 0;
mtmp->msleeping = 0; mtmp->mcanmove = 1;
mtmp->mcanmove = 1; mtmp->mfrozen = 0;
mtmp->mfrozen = 0; /* may scare some monsters -- waiting monsters excluded */
/* May scare some monsters */ if ((mtmp->mstrategy & STRAT_WAITMASK) != 0)
if (distm < distance/3 && mtmp->mstrategy &= ~STRAT_WAITMASK;
else if (distm < distance/3 &&
!resist(mtmp, TOOL_CLASS, 0, NOTELL)) !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) put_monsters_to_sleep(distance)
int distance; int distance;
{ {
register struct monst *mtmp = fmon; register struct monst *mtmp;
while(mtmp) { for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (!DEADMONSTER(mtmp) && distu(mtmp->mx, mtmp->my) < distance && if (DEADMONSTER(mtmp)) continue;
sleep_monst(mtmp, d(10,10), TOOL_CLASS)) { if (distu(mtmp->mx, mtmp->my) < distance &&
mtmp->msleeping = 1; /* 10d10 turns + wake_nearby to rouse */ sleep_monst(mtmp, d(10,10), TOOL_CLASS)) {
slept_monst(mtmp); mtmp->msleeping = 1; /* 10d10 turns + wake_nearby to rouse */
} slept_monst(mtmp);
mtmp = mtmp->nmon; }
} }
} }
@@ -109,15 +108,17 @@ STATIC_OVL void
charm_snakes(distance) charm_snakes(distance)
int distance; int distance;
{ {
register struct monst *mtmp = fmon; register struct monst *mtmp;
int could_see_mon, was_peaceful; int could_see_mon, was_peaceful;
while (mtmp) { for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (!DEADMONSTER(mtmp) && mtmp->data->mlet == S_SNAKE && mtmp->mcanmove && if (DEADMONSTER(mtmp)) continue;
if (mtmp->data->mlet == S_SNAKE && mtmp->mcanmove &&
distu(mtmp->mx, mtmp->my) < distance) { distu(mtmp->mx, mtmp->my) < distance) {
was_peaceful = mtmp->mpeaceful; was_peaceful = mtmp->mpeaceful;
mtmp->mpeaceful = 1; mtmp->mpeaceful = 1;
mtmp->mavenge = 0; mtmp->mavenge = 0;
mtmp->mstrategy &= ~STRAT_WAITMASK;
could_see_mon = canseemon(mtmp); could_see_mon = canseemon(mtmp);
mtmp->mundetected = 0; mtmp->mundetected = 0;
newsym(mtmp->mx, mtmp->my); newsym(mtmp->mx, mtmp->my);
@@ -131,7 +132,6 @@ int distance;
was_peaceful ? "" : ", and now seems quieter"); was_peaceful ? "" : ", and now seems quieter");
} }
} }
mtmp = mtmp->nmon;
} }
} }
@@ -143,20 +143,21 @@ STATIC_OVL void
calm_nymphs(distance) calm_nymphs(distance)
int distance; int distance;
{ {
register struct monst *mtmp = fmon; register struct monst *mtmp;
while (mtmp) { for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (!DEADMONSTER(mtmp) && mtmp->data->mlet == S_NYMPH && mtmp->mcanmove && if (DEADMONSTER(mtmp)) continue;
if (mtmp->data->mlet == S_NYMPH && mtmp->mcanmove &&
distu(mtmp->mx, mtmp->my) < distance) { distu(mtmp->mx, mtmp->my) < distance) {
mtmp->msleeping = 0; mtmp->msleeping = 0;
mtmp->mpeaceful = 1; mtmp->mpeaceful = 1;
mtmp->mavenge = 0; mtmp->mavenge = 0;
mtmp->mstrategy &= ~STRAT_WAITMASK;
if (canseemon(mtmp)) if (canseemon(mtmp))
pline( pline(
"%s listens cheerfully to the music, then seems quieter.", "%s listens cheerfully to the music, then seems quieter.",
Monnam(mtmp)); Monnam(mtmp));
} }
mtmp = mtmp->nmon;
} }
} }
@@ -165,19 +166,19 @@ int distance;
void void
awaken_soldiers() awaken_soldiers()
{ {
register struct monst *mtmp = fmon; register struct monst *mtmp;
while(mtmp) { for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (!DEADMONSTER(mtmp) && if (DEADMONSTER(mtmp)) continue;
is_mercenary(mtmp->data) && mtmp->data != &mons[PM_GUARD]) { if (is_mercenary(mtmp->data) && mtmp->data != &mons[PM_GUARD]) {
mtmp->mpeaceful = mtmp->msleeping = mtmp->mfrozen = 0; mtmp->mpeaceful = mtmp->msleeping = mtmp->mfrozen = 0;
mtmp->mcanmove = 1; mtmp->mcanmove = 1;
mtmp->mstrategy &= ~STRAT_WAITMASK;
if (canseemon(mtmp)) if (canseemon(mtmp))
pline("%s is now ready for battle!", Monnam(mtmp)); pline("%s is now ready for battle!", Monnam(mtmp));
else else
Norep("You hear the rattle of battle gear being readied."); Norep("You hear the rattle of battle gear being readied.");
} }
mtmp = mtmp->nmon;
} }
} }