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

Function domove_fight_empty

src/hack.c:2228–2338  ·  view source on GitHub ↗

force-fight (x,y) which doesn't have anything to fight */

Source from the content-addressed store, hash-verified

2226
2227/* force-fight (x,y) which doesn't have anything to fight */
2228staticfn boolean
2229domove_fight_empty(coordxy x, coordxy y)
2230{
2231 static const char unknown_obstacle[] = "an unknown obstacle";
2232 boolean off_edge = !isok(x, y);
2233 int glyph = !off_edge ? glyph_at(x, y) : GLYPH_UNEXPLORED;
2234
2235 if (off_edge)
2236 x = 0, y = 1; /* for forcefight against the edge of the map; make
2237 * sure 'bad' coordinates are within array bounds in
2238 * case a bounds check gets overlooked; avoid <0,0>
2239 * because m_at() might find a vault guard there */
2240
2241 /* specifying 'F' with no monster wastes a turn */
2242 if (svc.context.forcefight
2243 /* remembered an 'I' && didn't use a move command */
2244 || (glyph_is_invisible(glyph) && !m_at(x, y)
2245 && !svc.context.nopick)) {
2246 struct obj *boulder = 0;
2247 boolean explo = (Upolyd && attacktype(gy.youmonst.data, AT_EXPL)),
2248 solid = (off_edge || (!accessible(x, y)
2249 || IS_FURNITURE(levl[x][y].typ)));
2250 char buf[BUFSZ];
2251
2252 if (off_edge) {
2253 /* treat as if solid rock, even on planes' levels */
2254 Strcpy(buf, unknown_obstacle);
2255 goto futile;
2256 }
2257
2258 if (!Underwater) {
2259 boulder = sobj_at(BOULDER, x, y);
2260 /* if a statue is displayed at the target location,
2261 player is attempting to attack it [and boulder
2262 handling below is suitable for handling that] */
2263 if (glyph_is_statue(glyph)
2264 || (Hallucination && glyph_is_monster(glyph)))
2265 boulder = sobj_at(STATUE, x, y);
2266
2267 /* force fight at boulder/statue or wall/door while wielding
2268 pick: start digging to break the boulder or wall */
2269 if (svc.context.forcefight
2270 /* can we dig? */
2271 && uwep && dig_typ(uwep, x, y)
2272 /* should we dig? */
2273 && !glyph_is_invisible(glyph) && !glyph_is_monster(glyph)) {
2274 (void) use_pick_axe2(uwep);
2275 return TRUE;
2276 }
2277 }
2278
2279 /* about to become known empty -- remove 'I' if present */
2280 unmap_object(x, y);
2281 if (boulder)
2282 map_object(boulder, TRUE);
2283 newsym(x, y);
2284 glyph = glyph_at(x, y); /* might have just changed */
2285 nhUse(glyph);

Callers 2

move_out_of_boundsFunction · 0.85
domove_coreFunction · 0.85

Calls 15

isokFunction · 0.85
glyph_atFunction · 0.85
attacktypeFunction · 0.85
accessibleFunction · 0.85
sobj_atFunction · 0.85
dig_typFunction · 0.85
use_pick_axe2Function · 0.85
unmap_objectFunction · 0.85
map_objectFunction · 0.85
newsymFunction · 0.85
ansimpleonameFunction · 0.85
is_poolFunction · 0.85

Tested by

no test coverage detected