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

Function can_hide_under_obj

src/monmove.c:2120–2167  ·  view source on GitHub ↗

returns TRUE if a mon can hide under the obj */

Source from the content-addressed store, hash-verified

2118
2119/* returns TRUE if a mon can hide under the obj */
2120boolean
2121can_hide_under_obj(struct obj *obj)
2122{
2123/* uncomment '#define NO_HIDING_UNDER_STATUES' to prevent hiding under
2124 * statues; that was introduced to avoid nullifying statue traps but
2125 * isn't needed now that hiding at any non-pit trap site is disallowed */
2126/* #define NO_HIDING_UNDER_STATUES */
2127 struct trap *t;
2128
2129 if (!obj || obj->where != OBJ_FLOOR)
2130 return FALSE;
2131 /* can't hide in/on/under traps (except pits) even when there is an
2132 object here; since obj is on floor, its <ox,oy> are up to date */
2133 if ((t = t_at(obj->ox, obj->oy)) != 0 && !is_pit(t->ttyp))
2134 return FALSE;
2135 /* can't hide under small amount of coins unless non-coins are also
2136 present; we expect coins to be a single stack but don't assume that */
2137 if (obj->oclass == COIN_CLASS) {
2138 long coinquan = 0L;
2139
2140 do {
2141 /* 10 coins is arbitrary amount considered enough to hide under */
2142 if ((coinquan += obj->quan) >= 10L)
2143 break; /* fall through to other checks */
2144 obj = obj->nexthere;
2145 if (!obj)
2146 return FALSE; /* whole pile was less than 10 coins */
2147 } while (obj->oclass == COIN_CLASS);
2148 }
2149#ifdef NO_HIDING_UNDER_STATUES
2150 /*
2151 * 'obj' might have been changed, but only if we've skipped coins that
2152 * are on the top of a pile. However, the statue loop will clobber it.
2153 */
2154 /* can't hide under statues regardless of pile stacking order */
2155 while (obj) {
2156 if (obj->otyp == STATUE)
2157 return FALSE;
2158 obj = obj->nexthere;
2159 }
2160 /*
2161 * If we reach here, 'obj' is now Null but wasn't earlier so the original
2162 * 'obj' can be hidden beneath.
2163 */
2164#undef NO_HIDING_UNDER_STATUES
2165#endif
2166 return TRUE; /* can hide under the object */
2167}
2168
2169void
2170dissolve_bars(coordxy x, coordxy y)

Callers 3

maybe_unhide_atFunction · 0.85
hideunderFunction · 0.85
m_moveFunction · 0.85

Calls 1

t_atFunction · 0.85

Tested by

no test coverage detected