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

Function find_defensive

src/muse.c:440–750  ·  view source on GitHub ↗

Select a defensive item/action for a monster. Returns TRUE iff one is found. */

Source from the content-addressed store, hash-verified

438/* Select a defensive item/action for a monster. Returns TRUE iff one is
439 found. */
440boolean
441find_defensive(struct monst *mtmp, boolean tryescape)
442{
443 struct obj *obj;
444 struct trap *t;
445 int fraction;
446 coordxy x = mtmp->mx, y = mtmp->my;
447 boolean stuck = (mtmp == u.ustuck),
448 immobile = (mtmp->data->mmove == 0);
449 stairway *stway;
450
451 gm.m.defensive = (struct obj *) 0;
452 gm.m.has_defense = 0;
453
454 if (is_animal(mtmp->data) || mindless(mtmp->data))
455 return FALSE;
456 if (!tryescape && dist2(x, y, mtmp->mux, mtmp->muy) > 25)
457 return FALSE;
458 if (tryescape && Is_knox(&u.uz)
459 && !m_next2u(mtmp) && m_next2m(mtmp))
460 return FALSE;
461 if (u.uswallow && stuck)
462 return FALSE;
463
464 /*
465 * Since unicorn horns don't get used up, the monster would look
466 * silly trying to use the same cursed horn round after round,
467 * so skip cursed unicorn horns.
468 *
469 * Unicorns use their own horns; they're excluded from inventory
470 * scanning by nohands(). Ki-rin is depicted in the AD&D Monster
471 * Manual with same horn as a unicorn, so let it use its horn too.
472 * is_unicorn() doesn't include it; the class differs and it has
473 * no interest in gems.
474 */
475 if (mtmp->mconf || mtmp->mstun || !mtmp->mcansee) {
476 obj = 0;
477 if (!nohands(mtmp->data)) {
478 for (obj = mtmp->minvent; obj; obj = obj->nobj)
479 if (obj->otyp == UNICORN_HORN && !obj->cursed)
480 break;
481 }
482 if (obj || is_unicorn(mtmp->data) || mtmp->data == &mons[PM_KI_RIN]) {
483 gm.m.defensive = obj;
484 gm.m.has_defense = MUSE_UNICORN_HORN;
485 return TRUE;
486 }
487 }
488
489 if (mtmp->mconf || mtmp->mstun) {
490 struct obj *liztin = 0;
491
492 for (obj = mtmp->minvent; obj; obj = obj->nobj) {
493 if (obj->otyp == CORPSE && obj->corpsenm == PM_LIZARD) {
494 gm.m.defensive = obj;
495 gm.m.has_defense = MUSE_LIZARD_CORPSE;
496 return TRUE;
497 } else if (obj->otyp == TIN && obj->corpsenm == PM_LIZARD) {

Callers 2

dochugFunction · 0.85
m_moveFunction · 0.85

Calls 15

dist2Function · 0.85
m_next2mFunction · 0.85
mcould_eat_tinFunction · 0.85
rn2Function · 0.85
m_use_healingFunction · 0.85
poly_when_stonedFunction · 0.85
lined_upFunction · 0.85
stairway_atFunction · 0.85
isokFunction · 0.85
t_atFunction · 0.85
sobj_atFunction · 0.85
onscaryFunction · 0.85

Tested by

no test coverage detected