1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include "player.h"
// Please set your dStageActor_c's z coordinate
// Please check return for -1
char NearestPlayer(dStageActor_c* actor) {
char nearest = -1;
float current = 1000000000000000000000000000000.0;
OSReport("FINDING NEAREST PLAYER\n");
for(char ii = 0; ii < 4; ii++) {
OSReport("K, let's check out Player %d\n", ii);
dStageActor_c* player = GetSpecificPlayerActor(ii);
if(!player) {
OSReport("Player %d is NULL\n", ii);
continue;
}
OSReport("Player %d is ok\n", ii);
OSReport("[%f,%f,%f] - [%f,%f,%f]\n",
actor->pos.x, actor->pos.y, actor->pos.z,
player->pos.x, player->pos.y, player->pos.z);
float distance = VECDistance(&actor->pos, &player->pos);
OSReport("Distance: %f [%f]\n", distance, current);
if(distance < current) {
current = distance;
nearest = ii;
OSReport("Nearest is now %d\n", ii);
}
}
OSReport("NearestPlayer returning %d\n", nearest);
if(nearest < 0) {
OSReport("***FIX ME IMMEDIATELY***\n***NEED Z COORDINATES FOR ACTOR***\n");
}
return nearest;
}
|