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

Function find_targ

src/dogmove.c:649–691  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

647}
648
649staticfn struct monst *
650find_targ(
651 struct monst *mtmp,
652 int dx, int dy,
653 int maxdist)
654{
655 struct monst *targ = 0;
656 int curx = mtmp->mx, cury = mtmp->my;
657 int dist = 0;
658
659 /* Walk outwards */
660 for ( ; dist < maxdist; ++dist) {
661 curx += dx;
662 cury += dy;
663 if (!isok(curx, cury))
664 break;
665
666 /* FIXME: Check if we hit a wall/door/boulder to
667 * short-circuit unnecessary subsequent checks
668 */
669
670 /* If we can't see up to here, forget it - will this
671 * mean pets in corridors don't breathe at monsters
672 * in rooms? If so, is that necessarily bad?
673 */
674 if (!m_cansee(mtmp, curx, cury))
675 break;
676
677 if (curx == mtmp->mux && cury == mtmp->muy)
678 return &gy.youmonst;
679
680 if ((targ = m_at(curx, cury)) != 0) {
681 /* Is the monster visible to the pet? */
682 if ((!targ->minvis || perceives(mtmp->data)) && !targ->mundetected
683 /* if a long worm, only accept the head as a target */
684 && targ->mx == curx && targ->my == cury) /* not tail */
685 break;
686 /* If the pet can't see it, it assumes it ain't there */
687 targ = 0;
688 }
689 }
690 return targ;
691}
692
693staticfn int
694find_friends(struct monst *mtmp, struct monst *mtarg, int maxdist)

Callers 1

best_targetFunction · 0.85

Calls 1

isokFunction · 0.85

Tested by

no test coverage detected