This commit is contained in:
Anuken
2020-11-08 17:50:30 -05:00
8 changed files with 14 additions and 24 deletions

View File

@@ -79,7 +79,7 @@ public class BuilderAI extends AIController{
float dist = Math.min(cons.dst(unit) - buildingRange, 0); float dist = Math.min(cons.dst(unit) - buildingRange, 0);
//make sure you can reach the request in time //make sure you can reach the request in time
if(dist / unit.type.speed < cons.buildCost * 0.9f){ if(dist / unit.speed() < cons.buildCost * 0.9f){
following = b; following = b;
found = true; found = true;
} }

View File

@@ -55,7 +55,7 @@ public class FlyingAI extends AIController{
vec.setAngle(Mathf.slerpDelta(unit.vel().angle(), vec.angle(), 0.6f)); vec.setAngle(Mathf.slerpDelta(unit.vel().angle(), vec.angle(), 0.6f));
} }
vec.setLength(unit.type.speed); vec.setLength(unit.speed());
unit.moveAt(vec); unit.moveAt(vec);
} }

View File

@@ -65,7 +65,7 @@ public class SuicideAI extends GroundAI{
if(!blocked){ if(!blocked){
moveToTarget = true; moveToTarget = true;
//move towards target directly //move towards target directly
unit.moveAt(vec.set(target).sub(unit).limit(unit.type.speed)); unit.moveAt(vec.set(target).sub(unit).limit(unit.speed()));
} }
} }

View File

@@ -640,7 +640,7 @@ public class NetServer implements ApplicationListener{
Unit unit = player.unit(); Unit unit = player.unit();
long elapsed = Time.timeSinceMillis(con.lastReceivedClientTime); long elapsed = Time.timeSinceMillis(con.lastReceivedClientTime);
float maxSpeed = ((player.unit().type.canBoost && player.unit().isFlying()) ? player.unit().type.boostMultiplier : 1f) * player.unit().type.speed; float maxSpeed = ((player.unit().type.canBoost && player.unit().isFlying()) ? player.unit().type.boostMultiplier : 1f) * player.unit().speed();
if(unit.isGrounded()){ if(unit.isGrounded()){
maxSpeed *= unit.floorSpeedMultiplier(); maxSpeed *= unit.floorSpeedMultiplier();
} }

View File

@@ -34,7 +34,7 @@ import static mindustry.Vars.*;
abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, Itemsc, Rotc, Unitc, Weaponsc, Drawc, Boundedc, Syncc, Shieldc, Commanderc, Displayable, Senseable, Ranged{ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, Itemsc, Rotc, Unitc, Weaponsc, Drawc, Boundedc, Syncc, Shieldc, Commanderc, Displayable, Senseable, Ranged{
@Import boolean hovering, dead; @Import boolean hovering, dead;
@Import float x, y, rotation, elevation, maxHealth, drag, armor, hitSize, health, ammo; @Import float x, y, rotation, elevation, maxHealth, drag, armor, hitSize, health, ammo, minFormationSpeed;
@Import Team team; @Import Team team;
@Import int id; @Import int id;
@@ -68,9 +68,14 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
return type.hasWeapons(); return type.hasWeapons();
} }
public float speed(){
//limit speed to minimum formation speed to preserve formation
return isCommanding() ? minFormationSpeed * 0.98f : type.speed;
}
/** @return speed with boost multipliers factored in. */ /** @return speed with boost multipliers factored in. */
public float realSpeed(){ public float realSpeed(){
return Mathf.lerp(1f, type.canBoost ? type.boostMultiplier : 1f, elevation) * type.speed; return Mathf.lerp(1f, type.canBoost ? type.boostMultiplier : 1f, elevation) * speed();
} }
/** Iterates through this unit and everything it is controlling. */ /** Iterates through this unit and everything it is controlling. */

View File

@@ -95,7 +95,7 @@ public class AIController implements UnitController{
if(tile == targetTile || (costType == Pathfinder.costWater && !targetTile.floor().isLiquid)) return; if(tile == targetTile || (costType == Pathfinder.costWater && !targetTile.floor().isLiquid)) return;
unit.moveAt(vec.trns(unit.angleTo(targetTile), unit.type.speed)); unit.moveAt(vec.trns(unit.angleTo(targetTile), unit.speed()));
} }
protected void updateWeapons(){ protected void updateWeapons(){
@@ -176,7 +176,7 @@ public class AIController implements UnitController{
} }
protected void circle(Position target, float circleLength){ protected void circle(Position target, float circleLength){
circle(target, circleLength, unit.type.speed); circle(target, circleLength, unit.speed());
} }
protected void circle(Position target, float circleLength, float speed){ protected void circle(Position target, float circleLength, float speed){

View File

@@ -604,13 +604,6 @@ public class DesktopInput extends InputHandler{
boolean ground = unit.isGrounded(); boolean ground = unit.isGrounded();
float strafePenalty = ground ? 1f : Mathf.lerp(1f, unit.type.strafePenalty, Angles.angleDist(unit.vel().angle(), unit.rotation()) / 180f); float strafePenalty = ground ? 1f : Mathf.lerp(1f, unit.type.strafePenalty, Angles.angleDist(unit.vel().angle(), unit.rotation()) / 180f);
float baseSpeed = unit.type.speed;
//limit speed to minimum formation speed to preserve formation
if(unit.isCommanding()){
//add a tiny multiplier to let units catch up just in case
baseSpeed = unit.minFormationSpeed * 0.95f;
}
float speed = unit.realSpeed() * strafePenalty; float speed = unit.realSpeed() * strafePenalty;
float xa = Core.input.axis(Binding.move_x); float xa = Core.input.axis(Binding.move_x);

View File

@@ -857,14 +857,6 @@ public class MobileInput extends InputHandler implements GestureListener{
float attractDst = 15f; float attractDst = 15f;
float strafePenalty = legs ? 1f : Mathf.lerp(1f, type.strafePenalty, Angles.angleDist(unit.vel.angle(), unit.rotation) / 180f); float strafePenalty = legs ? 1f : Mathf.lerp(1f, type.strafePenalty, Angles.angleDist(unit.vel.angle(), unit.rotation) / 180f);
float baseSpeed = unit.type.speed;
//limit speed to minimum formation speed to preserve formation
if(unit.isCommanding()){
//add a tiny multiplier to let units catch up just in case
baseSpeed = unit.minFormationSpeed * 0.98f;
}
float speed = unit.realSpeed() * strafePenalty; float speed = unit.realSpeed() * strafePenalty;
float range = unit.hasWeapons() ? unit.range() : 0f; float range = unit.hasWeapons() ? unit.range() : 0f;
float bulletSpeed = unit.hasWeapons() ? type.weapons.first().bullet.speed : 0f; float bulletSpeed = unit.hasWeapons() ? type.weapons.first().bullet.speed : 0f;
@@ -906,7 +898,7 @@ public class MobileInput extends InputHandler implements GestureListener{
if(player.within(targetPos, attractDst)){ if(player.within(targetPos, attractDst)){
movement.setZero(); movement.setZero();
unit.vel.approachDelta(Vec2.ZERO, type.speed * type.accel / 2f); unit.vel.approachDelta(Vec2.ZERO, unit.speed() * type.accel / 2f);
} }
float expansion = 3f; float expansion = 3f;