place a monster at a random location, typically due to teleport; return TRUE if successful, FALSE if not; rlocflags is RLOC_foo flags */
| 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 */ |
| 1798 | boolean |
| 1799 | rloc( |
| 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 |
no test coverage detected