DefenderAI that makes octs follow units (#4757)

This commit is contained in:
MEEP of Faith
2021-03-05 07:21:26 -08:00
committed by GitHub
parent 2bb303e709
commit 0c28bb7dcf
3 changed files with 55 additions and 1 deletions

View File

@@ -248,7 +248,7 @@ public class Units{
return result;
}
/** Returns the closest ally of this team. Filter by predicate. */
/** 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){
result = null;
cdist = 0f;
@@ -266,6 +266,24 @@ 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){
result = null;
cdist = 0f;
for(Unit e : Groups.unit){
if(!predicate.get(e) || e.team() != team) continue;
float cost = sort.cost(e, x, y);
if(result == null || cost < cdist){
result = e;
cdist = cost;
}
}
return result;
}
/** Returns the closest ally of this team. Filter by predicate.
* Unlike the closest() function, this only guarantees that unit hitboxes overlap the range. */
public static Unit closestOverlap(Team team, float x, float y, float range, Boolf<Unit> predicate){