MCPcopy Create free account
hub / github.com/NetHack/NetHack / undesirable_disp

Function undesirable_disp

src/monmove.c:2276–2312  ·  view source on GitHub ↗

* mon-to-mon displacement is a deliberate "get out of my way" act, * not an accidental bump, so we don't consider mstun or mconf in * undesired_disp(). * * We do consider many other things about the target and its * location however. */

Source from the content-addressed store, hash-verified

2274 * location however.
2275 */
2276boolean
2277undesirable_disp(
2278 struct monst *mtmp, /* barging creature */
2279 coordxy x,
2280 coordxy y) /* spot 'mtmp' is considering moving to */
2281{
2282 boolean is_pet = (mtmp->mtame && !mtmp->isminion);
2283 struct trap *trap = t_at(x, y);
2284
2285 if (is_pet) {
2286 /* Pets avoid a trap if you've seen it usually. */
2287 if (trap && trap->tseen && rn2(40))
2288 return TRUE;
2289 /* Pets avoid cursed locations */
2290 if (cursed_object_at(x, y))
2291 return TRUE;
2292
2293 /* Monsters avoid a trap if they've seen that type before */
2294 } else if (trap && rn2(40)
2295 && mon_knows_traps(mtmp, trap->ttyp)) {
2296 return TRUE;
2297 }
2298
2299 /* oversimplification: creatures that bargethrough can't swap places
2300 when target monster is in rock or closed door or water (in particular,
2301 avoid moving to spots where mondied() won't leave a corpse; doesn't
2302 matter whether barger is capable of moving to such a target spot if
2303 it were unoccupied) */
2304 if (!accessible(x, y)
2305 /* mondied() allows is_pool() as an exception to !accessible(),
2306 but we'll only do that if 'mtmp' is already at a water location
2307 so that we don't swap a water critter onto land */
2308 && !(is_pool(x, y) && is_pool(mtmp->mx, mtmp->my)))
2309 return TRUE;
2310
2311 return FALSE;
2312}
2313
2314/*
2315 * Inventory prevents passage under door.

Callers 2

dog_moveFunction · 0.85
should_displaceFunction · 0.85

Calls 6

t_atFunction · 0.85
rn2Function · 0.85
cursed_object_atFunction · 0.85
mon_knows_trapsFunction · 0.85
accessibleFunction · 0.85
is_poolFunction · 0.85

Tested by

no test coverage detected