-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemyTracker.java
More file actions
45 lines (40 loc) · 1.13 KB
/
Copy pathEnemyTracker.java
File metadata and controls
45 lines (40 loc) · 1.13 KB
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
36
37
38
39
40
41
42
43
44
45
//package Bla1AI;
import com.springrts.ai.oo.AIFloat3;
import com.springrts.ai.oo.clb.*;
import java.util.ArrayList;
/**
* Write a description of class EnemyTracker here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class EnemyTracker
{
ArrayList<AIFloat3> enemyLocs;
public EnemyTracker()
{
enemyLocs = new ArrayList<AIFloat3>();
}
public void add(Unit unit){
enemyLocs.add(unit.getPos());
}
public void remove(Unit unit){
enemyLocs.remove(unit);
}
public boolean locsStored(){
return enemyLocs.size()!=0;
}
public AIFloat3 getLocationClosestTo(AIFloat3 loc){
if(enemyLocs.size()==0)
return null;
float minDistance = CallbackHelper.getDistanceBetween(loc, enemyLocs.get(0));
AIFloat3 ans = enemyLocs.get(0);
for(AIFloat3 location: enemyLocs){
if(CallbackHelper.getDistanceBetween(loc, location)<minDistance){
minDistance = CallbackHelper.getDistanceBetween(loc, location);
ans = location;
}
}
return ans;
}
}