diff --git a/build.gradle b/build.gradle index cefdf7d49c..2d33e1b054 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ allprojects { appName = 'Mindustry' gdxVersion = '1.9.8' roboVMVersion = '2.3.0' - uCoreVersion = 'f5ae8c0d58b6b7b42e95e57114220b11beb43fb3' + uCoreVersion = '1042ca8a3959a1354f5249acc89e396035a3f266' getVersionString = { String buildVersion = getBuildVersion() diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index c8f595fb08..71e864effc 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -495,6 +495,8 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra spawner = -1; } + avoidOthers(1f); + Tile tile = world.tileWorld(x, y); boostHeat = Mathf.lerpDelta(boostHeat, (tile != null && tile.solid()) || (isBoosting && ((!movement.isZero() && moved) || !isLocal)) ? 1f : 0f, 0.08f); diff --git a/core/src/io/anuke/mindustry/entities/Unit.java b/core/src/io/anuke/mindustry/entities/Unit.java index 80fe2a4454..62e1d20232 100644 --- a/core/src/io/anuke/mindustry/entities/Unit.java +++ b/core/src/io/anuke/mindustry/entities/Unit.java @@ -2,6 +2,7 @@ package io.anuke.mindustry.entities; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; import io.anuke.mindustry.content.blocks.Blocks; import io.anuke.mindustry.entities.traits.*; @@ -39,6 +40,9 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ /**Maximum absolute value of a velocity vector component.*/ public static final float maxAbsVelocity = 127f / velocityPercision; + private static final Rectangle queryRect = new Rectangle(); + private static final Vector2 moveVector = new Vector2(); + public final UnitInventory inventory = new UnitInventory(this); public float rotation; public float hitTime; @@ -182,6 +186,18 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ return status.hasEffect(effect); } + public void avoidOthers(float scaling){ + getHitbox(queryRect); + queryRect.setSize(queryRect.getWidth() * scaling); + + Units.getNearby(queryRect, t -> { + if(t == this || t.getCarrier() == this || getCarrier() == t || t.isFlying() != isFlying()) return; + float dst = distanceTo(t); + moveVector.set(x, y).sub(t.getX(), t.getY()).setLength(1f * (1f - (dst / queryRect.getWidth()))); + applyImpulse(moveVector.x, moveVector.y); + }); + } + public TileEntity getClosestCore(){ TeamData data = state.teams.get(team); diff --git a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java index f0f8a54226..635d2634b2 100644 --- a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java @@ -41,6 +41,7 @@ import static io.anuke.mindustry.Vars.*; /**Base class for AI units.*/ public abstract class BaseUnit extends Unit implements ShooterTrait{ + protected static int timerIndex = 0; protected static final int timerTarget = timerIndex++; @@ -305,11 +306,10 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{ return; } - if(!Net.client()){ + avoidOthers(1.2f); - if(spawner != -1 && (world.tile(spawner) == null || world.tile(spawner).entity == null)){ - damage(health); - } + if(spawner != -1 && (world.tile(spawner) == null || world.tile(spawner).entity == null)){ + damage(health); } if(squad != null){ diff --git a/core/src/io/anuke/mindustry/entities/units/GroundUnit.java b/core/src/io/anuke/mindustry/entities/units/GroundUnit.java index 2c918bf266..2beb1d4843 100644 --- a/core/src/io/anuke/mindustry/entities/units/GroundUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/GroundUnit.java @@ -121,10 +121,6 @@ public abstract class GroundUnit extends BaseUnit{ stuckTime = !vec.set(x, y).sub(lastPosition()).isZero(0.0001f) ? 0f : stuckTime + Timers.delta(); - if(!velocity.isZero(0.0001f) && (Units.invalidateTarget(target, this) || (distanceTo(target) > getWeapon().getAmmo().getRange()))){ - rotation = Mathf.slerpDelta(rotation, velocity.angle(), type.rotatespeed); - } - if(!velocity.isZero()){ baseRotation = Mathf.slerpDelta(baseRotation, velocity.angle(), 0.05f); } @@ -249,6 +245,8 @@ public abstract class GroundUnit extends BaseUnit{ if((tile == null || tile.solid() || tile.floor().drownTime > 0) || stuckTime > 10f){ baseRotation += Mathf.sign(id % 2 - 0.5f) * Timers.delta() * 3f; } + + rotation = Mathf.slerpDelta(rotation, velocity.angle(), type.rotatespeed); } protected void circle(float circleLength){ @@ -272,7 +270,10 @@ public abstract class GroundUnit extends BaseUnit{ if(tile == targetTile) return; + float angle = angleTo(targetTile); + velocity.add(vec.trns(angleTo(targetTile), type.speed)); + rotation = Mathf.slerpDelta(rotation, angle, type.rotatespeed); } protected void moveAwayFromCore(){ @@ -293,6 +294,9 @@ public abstract class GroundUnit extends BaseUnit{ if(tile == targetTile || core == null || distanceTo(core) < 90f) return; + float angle = angleTo(targetTile); + velocity.add(vec.trns(angleTo(targetTile), type.speed)); + rotation = Mathf.slerpDelta(rotation, angle, type.rotatespeed); } } diff --git a/core/src/io/anuke/mindustry/maps/Sectors.java b/core/src/io/anuke/mindustry/maps/Sectors.java index 6b63fbb3eb..fea7ca4c49 100644 --- a/core/src/io/anuke/mindustry/maps/Sectors.java +++ b/core/src/io/anuke/mindustry/maps/Sectors.java @@ -296,8 +296,6 @@ public class Sectors{ return null; }); - - }