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

Function rnd_nextto_goodpos

src/trap.c:4946–4972  ·  view source on GitHub ↗

pick a random goodpos() next to x,y for monster mtmp. mtmp could be &gy.youmonst, uses then crawl_destination(). returns TRUE if any good position found, with the coord in x,y */

Source from the content-addressed store, hash-verified

4944 mtmp could be &gy.youmonst, uses then crawl_destination().
4945 returns TRUE if any good position found, with the coord in x,y */
4946boolean
4947rnd_nextto_goodpos(coordxy *x, coordxy *y, struct monst *mtmp)
4948{
4949 int i, j;
4950 boolean is_u = (mtmp == &gy.youmonst);
4951 coordxy nx, ny, k, dirs[N_DIRS];
4952
4953 for (i = 0; i < N_DIRS; ++i)
4954 dirs[i] = i;
4955 for (i = N_DIRS; i > 0; --i) {
4956 j = rn2(i);
4957 k = dirs[j];
4958 dirs[j] = dirs[i - 1];
4959 dirs[i - 1] = k;
4960 }
4961 for (i = 0; i < N_DIRS; ++i) {
4962 nx = *x + xdir[dirs[i]];
4963 ny = *y + ydir[dirs[i]];
4964 /* crawl_destination and goodpos both include an isok() check */
4965 if (is_u ? crawl_destination(nx, ny) : goodpos(nx, ny, mtmp, 0)) {
4966 *x = nx;
4967 *y = ny;
4968 return TRUE;
4969 }
4970 }
4971 return FALSE;
4972}
4973
4974/* print a message about being back on the ground after leaving a pool */
4975void

Callers 2

place_worm_tail_randomlyFunction · 0.85
drownFunction · 0.85

Calls 3

rn2Function · 0.85
crawl_destinationFunction · 0.85
goodposFunction · 0.85

Tested by

no test coverage detected