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

Function find_misc

src/muse.c:2094–2245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2092#define MUSE_BAG 10
2093
2094boolean
2095find_misc(struct monst *mtmp)
2096{
2097 struct obj *obj;
2098 struct permonst *mdat = mtmp->data;
2099 coordxy x = mtmp->mx, y = mtmp->my;
2100 struct trap *t;
2101 coordxy xx, yy;
2102 int pmidx = NON_PM;
2103 boolean immobile = (mdat->mmove == 0);
2104 boolean stuck = (mtmp == u.ustuck);
2105
2106 gm.m.misc = (struct obj *) 0;
2107 gm.m.has_misc = 0;
2108 if (is_animal(mdat) || mindless(mdat))
2109 return 0;
2110 if (u.uswallow && stuck)
2111 return FALSE;
2112
2113 /* We arbitrarily limit to times when a player is nearby for the
2114 * same reason as Junior Pac-Man doesn't have energizers eaten until
2115 * you can see them...
2116 */
2117 if (dist2(x, y, mtmp->mux, mtmp->muy) > 36)
2118 return FALSE;
2119
2120 if (!stuck && !immobile && !mtmp->mtrapped && (mtmp->cham == NON_PM)
2121 && mons[(pmidx = monsndx(mdat))].difficulty < 6) {
2122 boolean ignore_boulders = (verysmall(mdat) || throws_rocks(mdat)
2123 || passes_walls(mdat)),
2124 diag_ok = !NODIAG(pmidx);
2125
2126 for (xx = x - 1; xx <= x + 1; xx++)
2127 for (yy = y - 1; yy <= y + 1; yy++)
2128 if (isok(xx, yy) && !u_at(xx, yy)
2129 && (diag_ok || xx == x || yy == y)
2130 && ((xx == x && yy == y) || !svl.level.monsters[xx][yy]))
2131 if ((t = t_at(xx, yy)) != 0
2132 && (ignore_boulders || !sobj_at(BOULDER, xx, yy))
2133 && !onscary(xx, yy, mtmp)) {
2134 /* use trap if it's the correct type and will
2135 polymorph the monster */
2136 if (t->ttyp == POLY_TRAP &&
2137 !wearing_iron_shoes(mtmp)) {
2138 gt.trapx = xx;
2139 gt.trapy = yy;
2140 gm.m.has_misc = MUSE_POLY_TRAP;
2141 return TRUE;
2142 }
2143 }
2144 }
2145 if (nohands(mdat))
2146 return 0;
2147
2148 /* normally we would want to bracket a macro expansion containing
2149 'if' without matching 'else' with 'do { ... } while (0)' but we
2150 can't do that here because it would intercept 'continue' */
2151#define nomore(x) if (gm.m.has_misc == (x)) continue

Callers 1

dochugFunction · 0.85

Calls 9

dist2Function · 0.85
isokFunction · 0.85
t_atFunction · 0.85
sobj_atFunction · 0.85
onscaryFunction · 0.85
wearing_iron_shoesFunction · 0.85
rn2Function · 0.85
canletgoFunction · 0.85
attacktypeFunction · 0.85

Tested by

no test coverage detected