| 194 | } |
| 195 | |
| 196 | void FindRangedTarget() |
| 197 | { |
| 198 | int distance, rotations; |
| 199 | bool canTalk; |
| 200 | |
| 201 | // The first MAX_PLRS monsters are reserved for players' golems. |
| 202 | for (int mi = MAX_PLRS; mi < MAXMONSTERS; mi++) { |
| 203 | const auto &monst = monster[mi]; |
| 204 | const int mx = monst._mx; |
| 205 | const int my = monst._my; |
| 206 | if (!CanTargetMonster(mi)) |
| 207 | continue; |
| 208 | |
| 209 | const bool newCanTalk = CanTalkToMonst(mi); |
| 210 | if (pcursmonst != -1 && !canTalk && newCanTalk) |
| 211 | continue; |
| 212 | const int newDdistance = GetDistanceRanged(mx, my); |
| 213 | const int newRotations = GetRotaryDistance(mx, my); |
| 214 | if (pcursmonst != -1 && canTalk == newCanTalk) { |
| 215 | if (distance < newDdistance) |
| 216 | continue; |
| 217 | if (distance == newDdistance && rotations < newRotations) |
| 218 | continue; |
| 219 | } |
| 220 | distance = newDdistance; |
| 221 | rotations = newRotations; |
| 222 | canTalk = newCanTalk; |
| 223 | pcursmonst = mi; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | void FindMeleeTarget() |
| 228 | { |
no test coverage detected