fix issue #1062 - monster hiding messages

Reported by Umbire:  if a statue of a hider-under was activated by
a statue trap, it would hide underneath its own statue.  Also, the
hero saw a snake hide under unseen submerged kelp.

Both of those things were exposed by new "you see <monster> hide"
message rather than caused by it.  It also led to the [re-]discovery
that an existing monster hiding under a statue that was a not-yet-
triggered trap prevented the trap from producing a monster.

This redoes yesterday's can't-hide-under-statue change:  hiders can
hide under statues again, but they can't hide under anything at trap
locations.  [Pits containing one or more objects are an exception,
although it seems silly that a hero is prevented from falling into
one by the presence of a tiny creepy-crawly hiding under a ring or
dart in there.]  So, hider-underers won't be able to interfere with
statue traps by being present at the trap location.  [Trappers and
lurkers-above probably need a similar restriction; I didn't look.
They avoid trap spots rather than get lured to such by objects.]

It also prevents newly created hider-underers from becoming hidden
as part of the their creation (except when that creation is part
of level creation) whether their creation uses up an object (statue
activation, egg hatching) or there are simply other items present.
That will prevent statue of a hider producing a monster that hides
under the activated statue (which was happening due to the sequence
create monster, transfer any statue contents to monster inventory,
destroy statue).

The can't-hide-under-statues code has been repurposed to prevent
hiding under gold pieces unless there are at least 10 (arbitrary
threshold) of those or they're in a pile with some other object(s).

Sea monsters hide in water regardless of the presence of objects.
Prevent other swimmers from hiding under objects at water locations.
Such creatures don't have gills and shouldn't be able to stay
submerged in hiding for an arbitrary length of time.  [No exception
is made for non-breathers.  The overlap between swimmers and hider-
underers is limited to small snakes, even though it is feasible for
a creature wearing an amulet of magical breathing to polymorph into
one.  Heros don't spend enough time underwater to worry about snakes
hiding under kelp or thrown junk.]

Lastly, alter the "suddenly, you notice a <monster>" message if
monster-vs-monster activity causes one you've just seen going into
hiding comes back out again without any intervening messages.  [I'm
not sure whether something similar is needed for the "Wait.  There's
something there" message in the you-vs-monster case.]

Fixes #1062
This commit is contained in:
PatR
2023-06-16 21:19:43 -07:00
parent 5688754684
commit bbba8b82d2
8 changed files with 113 additions and 36 deletions

View File

@@ -1898,15 +1898,50 @@ m_move_aggress(struct monst *mtmp, coordxy x, coordxy y)
boolean
can_hide_under_obj(struct obj *obj)
{
/* uncomment '#define NO_HIDING_UNDER_STATUES' to prevent hiding under
* statues; that was introduced to avoid nullifying statue traps but
* isn't needed now that hiding at any non-pit trap site is disallowed */
/* #define NO_HIDING_UNDER_STATUES */
struct trap *t;
if (!obj || (obj->otyp == STATUE
/* uncomment this next line for just statue traps */
/* && (t = t_at(obj->ox, obj->oy)) != 0 && t->ttyp == STATUE_TRAP */
))
if (!obj || obj->where != OBJ_FLOOR)
return FALSE;
return TRUE;
nhUse(t);
/* can't hide in/on/under traps (except pits) even when there is an
object here; since obj is on floor, its <ox,oy> are up to date */
if ((t = t_at(obj->ox, obj->oy)) != 0 && !is_pit(t->ttyp))
return FALSE;
/* can't hide under small amount of coins unless non-coins are also
present; we expect coins to be a single stack but don't assume that */
if (obj->oclass == COIN_CLASS) {
long coinquan = 0L;
do {
/* 10 coins is arbitrary amount considered enough to hide under */
if ((coinquan += obj->quan) >= 10L)
break; /* fall through to other checks */
obj = obj->nexthere;
if (!obj)
return FALSE; /* whole pile was less than 10 coins */
} while (obj->oclass == COIN_CLASS);
}
#ifdef NO_HIDING_UNDER_STATUES
/*
* 'obj' might have been changed, but only if we've skipped coins that
* are on the top of a pile. However, the statue loop will clobber it.
*/
/* can't hide under statues regardless of pile stacking order */
while (obj) {
if (obj->otyp == STATUE)
return FALSE;
obj = obj->nexthere;
}
/*
* If we reach here, 'obj' is now Null but wasn't earlier so the original
* 'obj' can be hidden beneath.
*/
#undef NO_HIDING_UNDER_STATUES
#endif
return TRUE; /* can hide under the object */
}
void