mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-08 23:07:33 +07:00
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:
@ -36,11 +36,19 @@ public class Teams{
|
||||
|
||||
@Nullable
|
||||
public CoreBuild closestEnemyCore(float x, float y, Team team){
|
||||
CoreBuild closest = null;
|
||||
float closestDst = Float.MAX_VALUE;
|
||||
|
||||
for(Team enemy : team.data().coreEnemies){
|
||||
CoreBuild tile = Geometry.findClosest(x, y, enemy.cores());
|
||||
if(tile != null) return tile;
|
||||
for(CoreBuild core : enemy.cores()){
|
||||
float dst = Mathf.dst2(x, y, core.getX(), core.getY());
|
||||
if(closestDst > dst){
|
||||
closest = core;
|
||||
closestDst = dst;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
Reference in New Issue
Block a user