Make closestEnemyCore find the actual closest core (#6676)

* Make closestEnemyCore find the actual closest core

this function should return the closest core of all of `team`’s enemies, but it instead returns the closest core of the first enemy team that has a core

* Glenn method
This commit is contained in:
Weathercold 2022-03-30 00:28:26 -04:00 committed by GitHub
parent 47b8e8d9fa
commit 7faa0f119e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,11 +36,19 @@ public class Teams{
@Nullable @Nullable
public CoreBuild closestEnemyCore(float x, float y, Team team){ public CoreBuild closestEnemyCore(float x, float y, Team team){
CoreBuild closest = null;
float closestDst = Float.MAX_VALUE;
for(Team enemy : team.data().coreEnemies){ for(Team enemy : team.data().coreEnemies){
CoreBuild tile = Geometry.findClosest(x, y, enemy.cores()); for(CoreBuild core : enemy.cores()){
if(tile != null) return tile; float dst = Mathf.dst2(x, y, core.getX(), core.getY());
if(closestDst > dst){
closest = core;
closestDst = dst;
} }
return null; }
}
return closest;
} }
@Nullable @Nullable