This commit is contained in:
Anuken
2021-01-10 15:39:00 -05:00
parent 9c846bd2c9
commit 9b1c66ba15

View File

@ -59,6 +59,12 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
return team.core(); 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(){ public TextureRegion icon(){
//display default icon for dead players //display default icon for dead players
if(dead()) return core() == null ? UnitTypes.alpha.icon(Cicon.full) : ((CoreBlock)core().block).unitType.icon(Cicon.full); 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(); clearUnit();
} }
CoreBuild core = closestCore(); CoreBuild core;
if(!dead()){ if(!dead()){
set(unit); set(unit);
@ -124,7 +130,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
Tile tile = unit.tileOn(); Tile tile = unit.tileOn();
unit.elevation = Mathf.approachDelta(unit.elevation, (tile != null && tile.solid()) || boosting ? 1f : 0f, 0.08f); 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 //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) //(this is not for balance, it just looks better this way)
deathTimer += Time.delta; deathTimer += Time.delta;