locs is an arrayList of all the metal locations. manage.getAllUnitPos() is a method that returns all the locations of my units.
This method is supposed to traverse through all the locations, then see if the location is shorter than the current location, and if it is already occupied.
Code: Select all
public AIFloat3 getClosestMetalSpot(Unit uni){
AIFloat3 ans = locs.get(0);
float minDistance = getDistancebetween(uni.getPos(), locs.get(0));
for(AIFloat3 loc: locs){
boolean collision = false;
if(getDistancebetween(uni.getPos(), loc)<minDistance){
for(AIFloat3 occuLoc:manage.getAllUnitPos()){
if(loc.equals(occuLoc)){
collision = true;
}
}
if(!collision){
ans = loc;
minDistance = getDistancebetween(uni.getPos(), loc);
}
}
}
return ans;
}