diff --git a/core/src/mindustry/ai/UnitGroup.java b/core/src/mindustry/ai/UnitGroup.java index 0e78137ebe..8c255c1752 100644 --- a/core/src/mindustry/ai/UnitGroup.java +++ b/core/src/mindustry/ai/UnitGroup.java @@ -16,6 +16,7 @@ import mindustry.gen.*; public class UnitGroup{ public Seq units = new Seq<>(); public float[] positions; + public float minSpeed = 999999f; public volatile boolean valid; public void calculateFormation(Vec2 dest, int collisionLayer){ @@ -35,6 +36,7 @@ public class UnitGroup{ positions[i * 2] = unit.x - cx; positions[i * 2 + 1] = unit.y - cy; unit.command().groupIndex = i; + minSpeed = Math.min(unit.speed(), minSpeed); } //run on new thread to prevent stutter diff --git a/core/src/mindustry/ai/types/CommandAI.java b/core/src/mindustry/ai/types/CommandAI.java index cb57fe944f..a2a75008e9 100644 --- a/core/src/mindustry/ai/types/CommandAI.java +++ b/core/src/mindustry/ai/types/CommandAI.java @@ -297,6 +297,11 @@ public class CommandAI extends AIController{ } } + @Override + public float prefSpeed(){ + return group == null ? super.prefSpeed() : group.minSpeed; + } + @Override public boolean shouldFire(){ return stance != UnitStance.holdFire; diff --git a/core/src/mindustry/entities/units/AIController.java b/core/src/mindustry/entities/units/AIController.java index 547775896a..6b688eb60a 100644 --- a/core/src/mindustry/entities/units/AIController.java +++ b/core/src/mindustry/entities/units/AIController.java @@ -124,7 +124,7 @@ public class AIController implements UnitController{ if(tile == targetTile || (costType == Pathfinder.costNaval && !targetTile.floor().isLiquid)) return; - unit.movePref(vec.trns(unit.angleTo(targetTile.worldx(), targetTile.worldy()), unit.speed())); + unit.movePref(vec.trns(unit.angleTo(targetTile.worldx(), targetTile.worldy()), prefSpeed())); } public void updateWeapons(){ @@ -270,13 +270,13 @@ public class AIController implements UnitController{ vec.setAngle(Angles.moveToward(unit.vel().angle(), vec.angle(), 6f)); } - vec.setLength(unit.speed()); + vec.setLength(prefSpeed()); unit.moveAt(vec); } public void circle(Position target, float circleLength){ - circle(target, circleLength, unit.speed()); + circle(target, circleLength, prefSpeed()); } public void circle(Position target, float circleLength, float speed){ @@ -308,15 +308,17 @@ public class AIController implements UnitController{ public void moveTo(Position target, float circleLength, float smooth, boolean keepDistance, @Nullable Vec2 offset, boolean arrive){ if(target == null) return; + float speed = prefSpeed(); + vec.set(target).sub(unit); float length = circleLength <= 0.001f ? 1f : Mathf.clamp((unit.dst(target) - circleLength) / smooth, -1f, 1f); - vec.setLength(unit.speed() * length); + vec.setLength(speed * length); if(arrive){ Tmp.v3.set(-unit.vel.x / unit.type.accel * 2f, -unit.vel.y / unit.type.accel * 2f).add((target.getX() - unit.x), (target.getY() - unit.y)); - vec.add(Tmp.v3).limit(unit.speed() * length); + vec.add(Tmp.v3).limit(speed * length); } if(length < -0.5f){ @@ -331,7 +333,7 @@ public class AIController implements UnitController{ if(offset != null){ vec.add(offset); - vec.setLength(unit.speed() * length); + vec.setLength(speed * length); } //do not move when infinite vectors are used or if its zero. @@ -348,6 +350,10 @@ public class AIController implements UnitController{ } } + public float prefSpeed(){ + return unit.speed(); + } + @Override public void unit(Unit unit){ if(this.unit == unit) return; diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index a1047b35ad..652eb9c949 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -277,6 +277,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ } unit.lastCommanded = player.coloredName(); + ai.group = null; //remove when other player command if(!headless && player != Vars.player){