Better DefenderAI / Vela building / Anuken/Mindustry-Suggestions/issues/2074

This commit is contained in:
Anuken
2021-03-05 11:10:12 -05:00
parent 0c28bb7dcf
commit b6c645b701
6 changed files with 26 additions and 19 deletions

View File

@@ -266,20 +266,20 @@ public class Units{
return result;
}
/** Returns the closest ally of this team using a custom comparison function. Filter by predicate. */
public static Unit closest(Team team, float x, float y, Boolf<Unit> predicate, Sortf sort){
/** Returns the closest ally of this team in a range. Filter by predicate. */
public static Unit closest(Team team, float x, float y, float range, Boolf<Unit> predicate, Sortf sort){
result = null;
cdist = 0f;
for(Unit e : Groups.unit){
if(!predicate.get(e) || e.team() != team) continue;
nearby(team, x, y, range, e -> {
if(!predicate.get(e)) return;
float cost = sort.cost(e, x, y);
if(result == null || cost < cdist){
float dist = sort.cost(e, x, y);
if(result == null || dist < cdist){
result = e;
cdist = cost;
cdist = dist;
}
}
});
return result;
}