From 9b1c66ba1519096c991d3461c582f2f6776bb79c Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 10 Jan 2021 15:39:00 -0500 Subject: [PATCH] #4298 --- core/src/mindustry/entities/comp/PlayerComp.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/entities/comp/PlayerComp.java b/core/src/mindustry/entities/comp/PlayerComp.java index 5e6c214cc6..aababe65e3 100644 --- a/core/src/mindustry/entities/comp/PlayerComp.java +++ b/core/src/mindustry/entities/comp/PlayerComp.java @@ -59,6 +59,12 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra return team.core(); } + /** @return largest/closest core, with largest cores getting priority */ + @Nullable + public CoreBuild bestCore(){ + return team.cores().min(Structs.comps(Structs.comparingInt(c -> -c.block.size), Structs.comparingFloat(c -> c.dst(x, y)))); + } + public TextureRegion icon(){ //display default icon for dead players if(dead()) return core() == null ? UnitTypes.alpha.icon(Cicon.full) : ((CoreBlock)core().block).unitType.icon(Cicon.full); @@ -112,7 +118,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra clearUnit(); } - CoreBuild core = closestCore(); + CoreBuild core; if(!dead()){ set(unit); @@ -124,7 +130,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra Tile tile = unit.tileOn(); unit.elevation = Mathf.approachDelta(unit.elevation, (tile != null && tile.solid()) || boosting ? 1f : 0f, 0.08f); } - }else if(core != null){ + }else if((core = bestCore()) != null){ //have a small delay before death to prevent the camera from jumping around too quickly //(this is not for balance, it just looks better this way) deathTimer += Time.delta;