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

Function choose_stairs

src/wizard.c:331–364  ·  view source on GitHub ↗

pick a destination for a covetous monster to flee to so that it can heal or for guardians (Kops) to congregate at to block hero's progress */

Source from the content-addressed store, hash-verified

329/* pick a destination for a covetous monster to flee to so that it can
330 heal or for guardians (Kops) to congregate at to block hero's progress */
331void
332choose_stairs(
333 coordxy *sx, coordxy *sy, /* output; left as-is if no spot found */
334 boolean dir) /* True: forward, False: backtrack (usually up) */
335{
336 stairway *stway;
337 boolean stdir = builds_up(&u.uz) ? dir : !dir;
338
339 /* look for stairs in direction 'stdir' (True: up, False: down) */
340 stway = stairway_find_type_dir(FALSE, stdir);
341 if (!stway) {
342 /* no stairs; look for ladder it that direction */
343 stway = stairway_find_type_dir(TRUE, stdir);
344 if (!stway) {
345 /* no ladder either; look for branch stairs or ladder in any
346 direction */
347 for (stway = gs.stairs; stway; stway = stway->next)
348 if (stway->tolev.dnum != u.uz.dnum)
349 break;
350 /* if no branch stairs/ladder, check for regular stairs in
351 opposite direction, then for regular ladder if necessary */
352 if (!stway) {
353 stway = stairway_find_type_dir(FALSE, !stdir);
354 if (!stway)
355 stway = stairway_find_type_dir(TRUE, !stdir);
356 }
357 }
358 /* [note: 'stway' could still be Null if the only access to this
359 level is via magic portal] */
360 }
361
362 if (stway)
363 *sx = stway->sx, *sy = stway->sy;
364}
365
366DISABLE_WARNING_UNREACHABLE_CODE
367

Callers 2

tacticsFunction · 0.85
call_kopsFunction · 0.85

Calls 2

builds_upFunction · 0.85
stairway_find_type_dirFunction · 0.85

Tested by

no test coverage detected