Monsters see and remember when others trigger traps

No longer will there be a conga line of hill orcs stepping into
the same arrow trap one after another.
This commit is contained in:
Pasi Kallinen
2022-08-21 11:51:19 +03:00
parent 953d43f5ac
commit fcf5c1ea50
5 changed files with 35 additions and 0 deletions
+1
View File
@@ -1013,6 +1013,7 @@ when breaking a wand of sleep hits the hero with the explosion, don't describe
that as "the sleep ray hits you" that as "the sleep ray hits you"
expose fuz tester to wizard-mode as #fuzzer extended command expose fuz tester to wizard-mode as #fuzzer extended command
monsters which cannot move due to boulders or walls try to escape monsters which cannot move due to boulders or walls try to escape
intelligent monsters see and remember when others trigger traps
Fixes to 3.7.0-x Problems that Were Exposed Via git Repository Fixes to 3.7.0-x Problems that Were Exposed Via git Repository
+1
View File
@@ -1653,6 +1653,7 @@ extern void monstseesu(unsigned long);
extern boolean resist_conflict(struct monst *); extern boolean resist_conflict(struct monst *);
extern boolean mon_knows_traps(struct monst *, int); extern boolean mon_knows_traps(struct monst *, int);
extern void mon_learns_traps(struct monst *, int); extern void mon_learns_traps(struct monst *, int);
extern void mons_see_trap(struct trap *);
/* ### monmove.c ### */ /* ### monmove.c ### */
+20
View File
@@ -1396,4 +1396,24 @@ mon_learns_traps(struct monst *mtmp, int ttyp)
mtmp->mtrapseen |= (1L << (ttyp - 1)); mtmp->mtrapseen |= (1L << (ttyp - 1));
} }
/* monsters see a trap trigger, and remember it */
void
mons_see_trap(struct trap *ttmp)
{
struct monst *mtmp;
coordxy tx = ttmp->tx, ty = ttmp->ty;
int maxdist = levl[tx][ty].lit ? 7*7 : 2;
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (is_animal(mtmp->data) || mindless(mtmp->data)
|| !haseyes(mtmp->data) || !mtmp->mcansee)
continue;
if (dist2(mtmp->mx, mtmp->my, tx, ty) > maxdist)
continue;
if (!m_cansee(mtmp, tx, ty))
continue;
mon_learns_traps(mtmp, ttmp->ttyp);
}
}
/*mondata.c*/ /*mondata.c*/
+11
View File
@@ -1269,6 +1269,7 @@ m_move(register struct monst* mtmp, register int after)
register struct obj *otmp; register struct obj *otmp;
register coordxy xx, yy; register coordxy xx, yy;
coordxy oomx, oomy, lmx, lmy; coordxy oomx, oomy, lmx, lmy;
struct trap *ttmp;
/* cut down the search radius if it thinks character is closer. */ /* cut down the search radius if it thinks character is closer. */
if (distmin(mtmp->mux, mtmp->muy, omx, omy) < SQSRCHRADIUS if (distmin(mtmp->mux, mtmp->muy, omx, omy) < SQSRCHRADIUS
@@ -1321,6 +1322,16 @@ m_move(register struct monst* mtmp, register int after)
|| (is_lava(xx, yy) && !likes_lava(ptr))) || (is_lava(xx, yy) && !likes_lava(ptr)))
continue; continue;
/* ignore obj if there's a trap and monster knows it */
if ((ttmp = t_at(xx, yy)) != 0
&& mon_knows_traps(mtmp, ttmp->ttyp)) {
if (gx == xx && gy == yy) {
gx = mtmp->mux;
gy = mtmp->muy;
}
continue;
}
if (((likegold && otmp->oclass == COIN_CLASS) if (((likegold && otmp->oclass == COIN_CLASS)
|| (likeobjs && index(practical, otmp->oclass) || (likeobjs && index(practical, otmp->oclass)
&& (otmp->otyp != CORPSE && (otmp->otyp != CORPSE
+2
View File
@@ -2553,6 +2553,7 @@ dotrap(struct trap *trap, unsigned trflags)
if (u.usteed) if (u.usteed)
mon_learns_traps(u.usteed, ttype); mon_learns_traps(u.usteed, ttype);
mons_see_trap(trap);
/* /*
* Note: * Note:
@@ -3271,6 +3272,7 @@ mintrap(struct monst *mtmp, unsigned mintrapflags)
} }
mon_learns_traps(mtmp, tt); mon_learns_traps(mtmp, tt);
mons_see_trap(trap);
/* Monster is aggravated by being trapped by you. /* Monster is aggravated by being trapped by you.
Recognizing who made the trap isn't completely Recognizing who made the trap isn't completely