Skip to content

Commit

Permalink
fix #H105 - inconsistent handling of "meditating" monsters (trunk only)
Browse files Browse the repository at this point in the history
     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.)
  • Loading branch information
nethack.rankin committed May 25, 2006
1 parent c67b978 commit 0620ca1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 46 deletions.
2 changes: 2 additions & 0 deletions doc/fixes35.0
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 18 additions & 11 deletions src/mon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 :
Expand All @@ -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;
}
Expand All @@ -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;
}
}
}

Expand Down
71 changes: 36 additions & 35 deletions src/music.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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);
}
}
}

Expand All @@ -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);
Expand All @@ -131,7 +132,6 @@ int distance;
was_peaceful ? "" : ", and now seems quieter");
}
}
mtmp = mtmp->nmon;
}
}

Expand All @@ -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;
}
}

Expand All @@ -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;
}
}

Expand Down

0 comments on commit 0620ca1

Please sign in to comment.