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

Function best_target

src/dogmove.c:837–885  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

835}
836
837staticfn struct monst *
838best_target(struct monst *mtmp, boolean forced) /* Pet */
839{
840 int dx, dy;
841 long bestscore = -40000L, currscore;
842 struct monst *best_targ = 0, *temp_targ = 0;
843
844 /* Help! */
845 if (!mtmp)
846 return 0;
847
848 /* If the pet is blind, it's not going to see any target */
849 if (!mtmp->mcansee)
850 return 0;
851
852 /* Search for any monsters lined up with the pet, within an arbitrary
853 * distance from the pet (7 squares, even along diagonals). Monsters
854 * are assigned scores and the best score is chosen.
855 */
856 for (dy = -1; dy < 2; ++dy) {
857 for (dx = -1; dx < 2; ++dx) {
858 if (!dx && !dy)
859 continue;
860 /* Traverse the line to find the first monster within 7
861 * squares. Invisible monsters are skipped (if the
862 * pet doesn't have see invisible).
863 */
864 temp_targ = find_targ(mtmp, dx, dy, 7);
865
866 /* Nothing in this line? */
867 if (!temp_targ)
868 continue;
869
870 /* Decide how attractive the target is */
871 currscore = score_targ(mtmp, temp_targ);
872
873 if (currscore > bestscore) {
874 bestscore = currscore;
875 best_targ = temp_targ;
876 }
877 }
878 }
879
880 /* Filter out targets the pet doesn't like */
881 if (!forced && bestscore < 0L)
882 best_targ = 0;
883
884 return best_targ;
885}
886
887/* Pet considers and maybe executes a ranged attack */
888int

Callers 2

pet_ranged_attkFunction · 0.85
dog_moveFunction · 0.85

Calls 2

find_targFunction · 0.85
score_targFunction · 0.85

Tested by

no test coverage detected