This commit is contained in:
Anuken 2024-02-11 09:06:28 -05:00
parent e99b9c2ad1
commit da0bcdcca3
2 changed files with 21 additions and 5 deletions

View File

@ -19,7 +19,22 @@ public class UnitGroup{
public int collisionLayer;
public volatile float[] positions, originalPositions;
public volatile boolean valid;
public long lastSpeedUpdate = -1;
public float minSpeed = 999999f;
public void updateMinSpeed(){
if(lastSpeedUpdate == Vars.state.updateId) return;
lastSpeedUpdate = Vars.state.updateId;
for(Unit unit : units){
//don't factor in the floor speed multiplier
Floor on = unit.isFlying() ? Blocks.air.asFloor() : unit.floorOn();
minSpeed = Math.min(unit.speed() / on.speedMultiplier, minSpeed);
}
if(Float.isInfinite(minSpeed) || Float.isNaN(minSpeed)) minSpeed = 999999f;
}
public void calculateFormation(Vec2 dest, int collisionLayer){
this.collisionLayer = collisionLayer;
@ -33,19 +48,16 @@ public class UnitGroup{
cy /= units.size;
positions = new float[units.size * 2];
//all positions are relative to the center
for(int i = 0; i < units.size; i ++){
Unit unit = units.get(i);
positions[i * 2] = unit.x - cx;
positions[i * 2 + 1] = unit.y - cy;
unit.command().groupIndex = i;
//don't factor in the floor speed multiplier
Floor on = unit.isFlying() ? Blocks.air.asFloor() : unit.floorOn();
minSpeed = Math.min(unit.speed() / on.speedMultiplier, minSpeed);
}
if(Float.isInfinite(minSpeed) || Float.isNaN(minSpeed)) minSpeed = 999999f;
updateMinSpeed();
//run on new thread to prevent stutter
Vars.mainExecutor.submit(() -> {

View File

@ -148,6 +148,10 @@ public class CommandAI extends AIController{
}
}
if(group != null){
group.updateMinSpeed();
}
if(!net.client() && command == UnitCommand.enterPayloadCommand && unit.buildOn() != null && (targetPos == null || (world.buildWorld(targetPos.x, targetPos.y) != null && world.buildWorld(targetPos.x, targetPos.y) == unit.buildOn()))){
var build = unit.buildOn();
tmpPayload.unit = unit;