MCPcopy Create free account
hub / github.com/diasurgical/devilution / FindRangedTarget

Function FindRangedTarget

SourceX/controls/plrctrls.cpp:196–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194}
195
196void 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
227void FindMeleeTarget()
228{

Callers 1

CheckMonstersNearbyFunction · 0.85

Calls 4

CanTargetMonsterFunction · 0.85
CanTalkToMonstFunction · 0.85
GetDistanceRangedFunction · 0.85
GetRotaryDistanceFunction · 0.85

Tested by

no test coverage detected