Fixed #9538
This commit is contained in:
@@ -19,8 +19,23 @@ public class UnitGroup{
|
|||||||
public int collisionLayer;
|
public int collisionLayer;
|
||||||
public volatile float[] positions, originalPositions;
|
public volatile float[] positions, originalPositions;
|
||||||
public volatile boolean valid;
|
public volatile boolean valid;
|
||||||
|
public long lastSpeedUpdate = -1;
|
||||||
public float minSpeed = 999999f;
|
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){
|
public void calculateFormation(Vec2 dest, int collisionLayer){
|
||||||
this.collisionLayer = collisionLayer;
|
this.collisionLayer = collisionLayer;
|
||||||
|
|
||||||
@@ -33,19 +48,16 @@ public class UnitGroup{
|
|||||||
cy /= units.size;
|
cy /= units.size;
|
||||||
positions = new float[units.size * 2];
|
positions = new float[units.size * 2];
|
||||||
|
|
||||||
|
|
||||||
//all positions are relative to the center
|
//all positions are relative to the center
|
||||||
for(int i = 0; i < units.size; i ++){
|
for(int i = 0; i < units.size; i ++){
|
||||||
Unit unit = units.get(i);
|
Unit unit = units.get(i);
|
||||||
positions[i * 2] = unit.x - cx;
|
positions[i * 2] = unit.x - cx;
|
||||||
positions[i * 2 + 1] = unit.y - cy;
|
positions[i * 2 + 1] = unit.y - cy;
|
||||||
unit.command().groupIndex = i;
|
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
|
//run on new thread to prevent stutter
|
||||||
Vars.mainExecutor.submit(() -> {
|
Vars.mainExecutor.submit(() -> {
|
||||||
|
|||||||
@@ -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()))){
|
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();
|
var build = unit.buildOn();
|
||||||
tmpPayload.unit = unit;
|
tmpPayload.unit = unit;
|
||||||
|
|||||||
Reference in New Issue
Block a user