MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / FindClosestPlayer

Function FindClosestPlayer

scripts/AIGame3.cpp:313–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

311}
312
313int FindClosestPlayer(int objhandle) {
314 vector objpos, playerpos;
315 float closest_dist = FLT_MAX;
316 int closest_player = OBJECT_HANDLE_NONE;
317 msafe_struct mstruct;
318
319 // Get the object position
320 mstruct.objhandle = objhandle;
321 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
322 objpos = mstruct.pos;
323
324 // Loop though all possible players and compute distance
325 for (int p = 0; p < MAX_PLAYERS; p++) {
326
327 // Get player position
328 mstruct.slot = p;
329 MSafe_GetValue(MSAFE_OBJECT_PLAYER_HANDLE, &mstruct);
330
331 // See if this player active
332 if (mstruct.objhandle == OBJECT_HANDLE_NONE)
333 continue;
334
335 // Get the target position
336 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
337
338 // Get the normalized vector from the source to the target
339 float dist = vm_VectorDistanceQuick(&objpos, &mstruct.pos);
340
341 if (dist < closest_dist) {
342 closest_dist = dist;
343 closest_player = mstruct.objhandle;
344 }
345 }
346
347 return closest_player;
348}
349
350// ==================
351// Clear Shot System

Callers 1

DoNotifyMethod · 0.85

Calls 1

vm_VectorDistanceQuickFunction · 0.70

Tested by

no test coverage detected