diff --git a/core/src/mindustry/game/Teams.java b/core/src/mindustry/game/Teams.java index 0f3bf22c69..cc6f7fb15e 100644 --- a/core/src/mindustry/game/Teams.java +++ b/core/src/mindustry/game/Teams.java @@ -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 @@ -368,4 +376,4 @@ public class Teams{ '}'; } } -} \ No newline at end of file +}