diff --git a/core/assets/scripts/base.js b/core/assets/scripts/base.js index 3d8073e48e..b6e377fa24 100755 --- a/core/assets/scripts/base.js +++ b/core/assets/scripts/base.js @@ -21,5 +21,15 @@ const extend = function(classType, params){ return new JavaAdapter(classType, params) } +//these are not sctrictly necessary, but are kept for edge cases +const run = method => new java.lang.Runnable(){run: method} +const boolf = method => new Boolf(){get: method} +const boolp = method => new Boolp(){get: method} +const floatf = method => new Floatf(){get: method} +const floatp = method => new Floatp(){get: method} +const cons = method => new Cons(){get: method} +const prov = method => new Prov(){get: method} +const func = method => new Func(){get: method} + const newEffect = (lifetime, renderer) => new Effects.Effect(lifetime, new Effects.EffectRenderer({render: renderer})) Call = Packages.mindustry.gen.Call diff --git a/core/assets/scripts/global.js b/core/assets/scripts/global.js index daeaa17942..28b4b83e38 100755 --- a/core/assets/scripts/global.js +++ b/core/assets/scripts/global.js @@ -23,6 +23,16 @@ const extend = function(classType, params){ return new JavaAdapter(classType, params) } +//these are not sctrictly necessary, but are kept for edge cases +const run = method => new java.lang.Runnable(){run: method} +const boolf = method => new Boolf(){get: method} +const boolp = method => new Boolp(){get: method} +const floatf = method => new Floatf(){get: method} +const floatp = method => new Floatp(){get: method} +const cons = method => new Cons(){get: method} +const prov = method => new Prov(){get: method} +const func = method => new Func(){get: method} + const newEffect = (lifetime, renderer) => new Effects.Effect(lifetime, new Effects.EffectRenderer({render: renderer})) Call = Packages.mindustry.gen.Call @@ -82,6 +92,7 @@ importPackage(Packages.mindustry.world.blocks.environment) importPackage(Packages.mindustry.world.blocks.experimental) importPackage(Packages.mindustry.world.blocks.legacy) importPackage(Packages.mindustry.world.blocks.liquid) +importPackage(Packages.mindustry.world.blocks.logic) importPackage(Packages.mindustry.world.blocks.payloads) importPackage(Packages.mindustry.world.blocks.power) importPackage(Packages.mindustry.world.blocks.production) diff --git a/core/src/mindustry/ai/types/FormationAI.java b/core/src/mindustry/ai/types/FormationAI.java index 883804f42c..9ef064cfe1 100644 --- a/core/src/mindustry/ai/types/FormationAI.java +++ b/core/src/mindustry/ai/types/FormationAI.java @@ -66,7 +66,7 @@ public class FormationAI extends AIController implements FormationMember{ //TODO return formation size //eturn ((Commanderc)unit).formation(). } - return unit.hitSize * 2f; + return unit.hitSize * 1.7f; } @Override diff --git a/core/src/mindustry/entities/comp/CommanderComp.java b/core/src/mindustry/entities/comp/CommanderComp.java index 9fa314cfcf..89be9842f5 100644 --- a/core/src/mindustry/entities/comp/CommanderComp.java +++ b/core/src/mindustry/entities/comp/CommanderComp.java @@ -17,6 +17,8 @@ abstract class CommanderComp implements Unitc{ transient @Nullable Formation formation; transient Seq controlling = new Seq<>(); + /** minimum speed of any unit in the formation. */ + transient float minFormationSpeed; @Override public void update(){ @@ -45,13 +47,15 @@ abstract class CommanderComp implements Unitc{ void command(Formation formation, Seq units){ clearCommand(); - float spacing = 8f; + float spacing = hitSize() * 1.7f; + minFormationSpeed = type().speed; controlling.addAll(units); for(Unit unit : units){ FormationAI ai; unit.controller(ai = new FormationAI(base(), formation)); spacing = Math.max(spacing, ai.formationSize()); + minFormationSpeed = Math.min(minFormationSpeed, unit.type().speed); } this.formation = formation; diff --git a/core/src/mindustry/input/DesktopInput.java b/core/src/mindustry/input/DesktopInput.java index f2321c1863..ef9bfbf31d 100644 --- a/core/src/mindustry/input/DesktopInput.java +++ b/core/src/mindustry/input/DesktopInput.java @@ -570,7 +570,15 @@ public class DesktopInput extends InputHandler{ boolean legs = unit.isGrounded(); float strafePenalty = legs ? 1f : Mathf.lerp(1f, unit.type().strafePenalty, Angles.angleDist(unit.vel().angle(), unit.rotation()) / 180f); - float speed = unit.type().speed * Mathf.lerp(1f, unit.type().canBoost ? unit.type().boostMultiplier : 1f, unit.elevation) * strafePenalty; + float baseSpeed = unit.type().speed; + + //limit speed to minimum formation speed to preserve formation + if(unit instanceof Commanderc && ((Commanderc)unit).isCommanding()){ + //add a tiny multiplier to let units catch up just in case + baseSpeed = ((Commanderc)unit).minFormationSpeed() * 0.98f; + } + + float speed = baseSpeed * Mathf.lerp(1f, unit.type().canBoost ? unit.type().boostMultiplier : 1f, unit.elevation) * strafePenalty; float xa = Core.input.axis(Binding.move_x); float ya = Core.input.axis(Binding.move_y); boolean boosted = (unit instanceof Mechc && unit.isFlying()); diff --git a/core/src/mindustry/input/MobileInput.java b/core/src/mindustry/input/MobileInput.java index 24478ab7bf..a05d209f90 100644 --- a/core/src/mindustry/input/MobileInput.java +++ b/core/src/mindustry/input/MobileInput.java @@ -803,7 +803,16 @@ public class MobileInput extends InputHandler implements GestureListener{ targetPos.set(Core.camera.position); float attractDst = 15f; float strafePenalty = legs ? 1f : Mathf.lerp(1f, type.strafePenalty, Angles.angleDist(unit.vel.angle(), unit.rotation) / 180f); - float speed = type.speed * Mathf.lerp(1f, type.canBoost ? type.boostMultiplier : 1f, unit.elevation) * strafePenalty; + + float baseSpeed = unit.type().speed; + + //limit speed to minimum formation speed to preserve formation + if(unit instanceof Commanderc && ((Commanderc)unit).isCommanding()){ + //add a tiny multiplier to let units catch up just in case + baseSpeed = ((Commanderc)unit).minFormationSpeed() * 0.98f; + } + + float speed = baseSpeed * Mathf.lerp(1f, type.canBoost ? type.boostMultiplier : 1f, unit.elevation) * strafePenalty; float range = unit.hasWeapons() ? unit.range() : 0f; float bulletSpeed = unit.hasWeapons() ? type.weapons.first().bullet.speed : 0f; float mouseAngle = unit.angleTo(unit.aimX(), unit.aimY());