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

Function should_displace

src/monmove.c:1069–1103  ·  view source on GitHub ↗

* should_displace() * * Displacement of another monster is a last resort and only * used on approach. If there are better ways to get to target, * those should be used instead. This function does that evaluation. */

Source from the content-addressed store, hash-verified

1067 * those should be used instead. This function does that evaluation.
1068 */
1069boolean
1070should_displace(
1071 struct monst *mtmp,
1072 const struct mfndposdata *data,
1073 coordxy ggx,
1074 coordxy ggy)
1075{
1076 int shortest_with_displacing = -1;
1077 int shortest_without_displacing = -1;
1078 int count_without_displacing = 0;
1079 int i, nx, ny;
1080 int ndist;
1081
1082 for (i = 0; i < data->cnt; i++) {
1083 nx = data->poss[i].x;
1084 ny = data->poss[i].y;
1085 ndist = dist2(nx, ny, ggx, ggy);
1086 if (MON_AT(nx, ny) && (data->info[i] & ALLOW_MDISP) && !(data->info[i] & ALLOW_M)
1087 && !undesirable_disp(mtmp, nx, ny)) {
1088 if (shortest_with_displacing == -1
1089 || (ndist < shortest_with_displacing))
1090 shortest_with_displacing = ndist;
1091 } else {
1092 if ((shortest_without_displacing == -1)
1093 || (ndist < shortest_without_displacing))
1094 shortest_without_displacing = ndist;
1095 count_without_displacing++;
1096 }
1097 }
1098 if (shortest_with_displacing > -1
1099 && (shortest_with_displacing < shortest_without_displacing
1100 || !count_without_displacing))
1101 return TRUE;
1102 return FALSE;
1103}
1104
1105/* have monster wield a pick-axe if it wants to dig and it has one;
1106 return True if it spends this move wielding one, False otherwise */

Callers 2

dog_moveFunction · 0.85
m_moveFunction · 0.85

Calls 2

dist2Function · 0.85
undesirable_dispFunction · 0.85

Tested by

no test coverage detected