* 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. */
| 1067 | * those should be used instead. This function does that evaluation. |
| 1068 | */ |
| 1069 | boolean |
| 1070 | should_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 */ |
no test coverage detected