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

Function rloc

src/teleport.c:1798–1895  ·  view source on GitHub ↗

place a monster at a random location, typically due to teleport; return TRUE if successful, FALSE if not; rlocflags is RLOC_foo flags */

Source from the content-addressed store, hash-verified

1796/* place a monster at a random location, typically due to teleport;
1797 return TRUE if successful, FALSE if not; rlocflags is RLOC_foo flags */
1798boolean
1799rloc(
1800 struct monst *mtmp, /* mtmp->mx==0 implies migrating monster arrival */
1801 unsigned rlocflags)
1802{
1803 coord cc, backupcc, candy[ROWNO * (COLNO - 1)]; /* room for entire map */
1804 unsigned cc_flags;
1805 coordxy x, y;
1806 int trycount, i, j, candycount;
1807
1808 if (mtmp == u.usteed) {
1809 tele();
1810 return TRUE;
1811 }
1812
1813 if (mtmp->iswiz && mtmp->mx) { /* Wizard, not just arriving */
1814 stairway *stway;
1815
1816 if (!In_W_tower(u.ux, u.uy, &u.uz)) {
1817 stway = stairway_find_forwiz(FALSE, TRUE);
1818 } else if (!stairway_find_forwiz(TRUE, FALSE)) { /* bottom of tower */
1819 stway = stairway_find_forwiz(TRUE, TRUE);
1820 } else {
1821 stway = stairway_find_forwiz(TRUE, FALSE);
1822 }
1823
1824 x = stway ? stway->sx : 0;
1825 y = stway ? stway->sy : 0;
1826
1827 /* if the wiz teleports away to heal, try the up staircase,
1828 to block the player's escaping before he's healed
1829 (deliberately use `goodpos' rather than `rloc_pos_ok' here) */
1830 if (goodpos(x, y, mtmp, NO_MM_FLAGS))
1831 goto found_xy;
1832 }
1833
1834 /* wizard-mode player can choose destination by setting 'montelecontrol'
1835 option; ignored if/when this is arrival of a migrating monster */
1836 if (iflags.mon_telecontrol && mtmp->mx) {
1837 cc.x = mtmp->mx, cc.y = mtmp->my;
1838 if (control_mon_tele(mtmp, &cc, rlocflags, TRUE)) {
1839 x = cc.x, y = cc.y;
1840 goto found_xy;
1841 }
1842 }
1843
1844 /* this used to try randomly 1000 times, then fallback to left-to-right
1845 top-to-bottom exhaustive check; now that the exhaustive check uses
1846 randomized order, reduce the number of random attempts to 50;
1847 on levels with lots of available space, random can find a spot more
1848 quickly but might fail to find one no matter how many tries it makes */
1849 for (trycount = 0; trycount < 50; ++trycount) {
1850 x = rnd(COLNO - 1); /* 1..COLNO-1 */
1851 y = rn2(ROWNO); /* 0..ROWNO-1 */
1852 if (rloc_pos_ok(x, y, mtmp)) /* rejects 'onscary' */
1853 goto found_xy;
1854 }
1855

Callers 15

mk_mplayerFunction · 0.85
stealgoldFunction · 0.85
stealarmFunction · 0.85
stealamuletFunction · 0.85
mhitm_ad_sgldFunction · 0.85
mhitm_ad_tlptFunction · 0.85
mhitm_ad_healFunction · 0.85
mhitm_ad_seduFunction · 0.85
dismount_steedFunction · 0.85
mvault_teleFunction · 0.85
mtele_trapFunction · 0.85
u_teleport_monFunction · 0.85

Calls 11

teleFunction · 0.85
In_W_towerFunction · 0.85
stairway_find_forwizFunction · 0.85
goodposFunction · 0.85
control_mon_teleFunction · 0.85
rndFunction · 0.85
rn2Function · 0.85
rloc_pos_okFunction · 0.85
collect_coordsFunction · 0.85
rloc_to_coreFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected