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

Function find_friends

src/dogmove.c:693–735  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

691}
692
693staticfn int
694find_friends(struct monst *mtmp, struct monst *mtarg, int maxdist)
695{
696 struct monst *pal;
697 int dx = sgn(mtarg->mx - mtmp->mx),
698 dy = sgn(mtarg->my - mtmp->my);
699 int curx = mtarg->mx, cury = mtarg->my;
700 int dist = distmin(mtarg->mx, mtarg->my, mtmp->mx, mtmp->my);
701
702 for ( ; dist <= maxdist; ++dist) {
703 curx += dx;
704 cury += dy;
705
706 if (!isok(curx, cury))
707 return 0;
708
709 /* If the pet can't see beyond this point, don't
710 * check any farther
711 */
712 if (!m_cansee(mtmp, curx, cury))
713 return 0;
714
715 /* Does pet think you're here? */
716 if (mtmp->mux == curx && mtmp->muy == cury)
717 return 1;
718
719 pal = m_at(curx, cury);
720
721 if (pal) {
722 if (pal->mtame) {
723 /* Pet won't notice invisible pets */
724 if (!pal->minvis || perceives(mtmp->data))
725 return 1;
726 } else {
727 /* Quest leaders and guardians are always seen */
728 if (pal->data->msound == MS_LEADER
729 || pal->data->msound == MS_GUARDIAN)
730 return 1;
731 }
732 }
733 }
734 return 0;
735}
736
737staticfn long
738score_targ(struct monst *mtmp, struct monst *mtarg)

Callers 1

score_targFunction · 0.85

Calls 3

sgnFunction · 0.85
distminFunction · 0.85
isokFunction · 0.85

Tested by

no test coverage detected