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

Function u_collide_m

src/do.c:1411–1445  ·  view source on GitHub ↗

when arriving on a level, if hero and a monster are trying to share same spot, move one; extracted from goto_level(); also used by wiz_makemap() */

Source from the content-addressed store, hash-verified

1409/* when arriving on a level, if hero and a monster are trying to share same
1410 spot, move one; extracted from goto_level(); also used by wiz_makemap() */
1411void
1412u_collide_m(struct monst *mtmp)
1413{
1414 coord cc;
1415
1416 if (!mtmp || mtmp == u.usteed || mtmp != m_at(u.ux, u.uy)) {
1417 impossible("level arrival collision: %s?",
1418 !mtmp ? "no monster"
1419 : (mtmp == u.usteed) ? "steed is on map"
1420 : "monster not co-located");
1421 return;
1422 }
1423
1424 /* There's a monster at your target destination; it might be one
1425 which accompanied you--see mon_arrive(dogmove.c)--or perhaps
1426 it was already here. Randomly move you to an adjacent spot
1427 or else the monster to any nearby location. Prior to 3.3.0
1428 the latter was done unconditionally. */
1429 if (!rn2(2) && enexto(&cc, u.ux, u.uy, gy.youmonst.data)
1430 && next2u(cc.x, cc.y))
1431 u_on_newpos(cc.x, cc.y); /*[maybe give message here?]*/
1432 else
1433 mnexto(mtmp, RLOC_NOMSG);
1434
1435 if ((mtmp = m_at(u.ux, u.uy)) != 0) {
1436 /* there was an unconditional impossible("mnexto failed")
1437 here, but it's not impossible and we're prepared to cope
1438 with the situation, so only say something when debugging */
1439 if (wizard)
1440 pline("(monster in hero's way)");
1441 if (!rloc(mtmp, RLOC_NOMSG) || (mtmp = m_at(u.ux, u.uy)) != 0)
1442 /* no room to move it; send it away, to return later */
1443 m_into_limbo(mtmp);
1444 }
1445}
1446
1447staticfn void
1448familiar_level_msg(void)

Callers 2

goto_levelFunction · 0.85
makemap_prepostFunction · 0.85

Calls 8

rn2Function · 0.85
enextoFunction · 0.85
u_on_newposFunction · 0.85
mnextoFunction · 0.85
rlocFunction · 0.85
m_into_limboFunction · 0.85
impossibleFunction · 0.70
plineFunction · 0.70

Tested by

no test coverage detected