From 7faa0f119e32c53d91de93814aa2ece58233fc93 Mon Sep 17 00:00:00 2001 From: Weathercold Date: Wed, 30 Mar 2022 00:28:26 -0400 Subject: [PATCH] Make closestEnemyCore find the actual closest core (#6676) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- core/src/mindustry/game/Teams.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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 +}