diff --git a/core/src/io/anuke/mindustry/entities/EntityDraw.java b/core/src/io/anuke/mindustry/entities/EntityDraw.java index e0a95627c2..60c67959ff 100644 --- a/core/src/io/anuke/mindustry/entities/EntityDraw.java +++ b/core/src/io/anuke/mindustry/entities/EntityDraw.java @@ -6,6 +6,7 @@ import io.anuke.arc.function.Predicate; import io.anuke.arc.graphics.Camera; import io.anuke.arc.math.geom.Rectangle; import io.anuke.mindustry.entities.traits.DrawTrait; +import io.anuke.mindustry.entities.traits.Entity; public class EntityDraw{ private static final Rectangle viewport = new Rectangle(); @@ -42,15 +43,12 @@ public class EntityDraw{ viewport.set(cam.position.x - cam.width / 2, cam.position.y - cam.height / 2, cam.width, cam.height); } - group.forEach(e -> { - if(!(e instanceof DrawTrait)) return; - T t = (T) e; - - if(!toDraw.test(t) || !e.isAdded()) return; + for(Entity e : group.all()){ + if(!(e instanceof DrawTrait) || !toDraw.test((T)e) || !e.isAdded()) continue; if(!clip || rect.setSize(((DrawTrait) e).drawSize()).setCenter(e.getX(), e.getY()).overlaps(viewport)){ - cons.accept(t); + cons.accept((T)e); } - }); + } } } diff --git a/core/src/io/anuke/mindustry/entities/type/Unit.java b/core/src/io/anuke/mindustry/entities/type/Unit.java index e9b48b1b00..e919b077f2 100644 --- a/core/src/io/anuke/mindustry/entities/type/Unit.java +++ b/core/src/io/anuke/mindustry/entities/type/Unit.java @@ -50,6 +50,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ private static final Vector2 moveVector = new Vector2(); private int lastWeightTile = Pos.invalid, lastWeightDelta; + private boolean wasFlying = false; public float rotation; @@ -228,13 +229,19 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ } public void avoidOthers(float scaling){ - if(isFlying()) return; + boolean flying = isFlying(); if(lastWeightTile != Pos.invalid){ Tile tile = world.tile(lastWeightTile); if(tile != null){ - tile.weight -= Math.min(lastWeightDelta, tile.weight); + int dec = Math.min(lastWeightDelta, wasFlying ? tile.airWeight : tile.weight); + if(!wasFlying){ + tile.weight -= dec; + }else{ + tile.airWeight -= dec; + } + } } @@ -245,25 +252,32 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ for(int cy = -rad; cy <= rad; cy++){ Tile tile = world.tileWorld(x + cx*tilesize, y + cy*tilesize); if(tile == null) continue; + int weight = flying ? tile.airWeight : tile.weight; float scl = (rad - Mathf.dst(tile.worldx(), tile.worldy(), x, y)/(8f * 1.2f * Mathf.sqrt2)) * 0.1f; - moveVector.add(Mathf.sign(x - tile.worldx()) * scaling * tile.weight * scl, Mathf.sign(y - tile.worldy()) * scaling * tile.weight * scl); + moveVector.add(Mathf.sign(x - tile.worldx()) * scaling * weight * scl, Mathf.sign(y - tile.worldy()) * scaling * weight * scl); } } - moveVector.limit(0.2f); + moveVector.limit(flying ? 0.1f : 0.2f); applyImpulse(moveVector.x, moveVector.y); Tile tile = world.tileWorld(x, y); if(tile != null){ - lastWeightDelta = Math.min((int)(mass()), 127 - tile.weight); + int tw = flying ? tile.airWeight : tile.weight; + lastWeightDelta = Math.min((int)(mass()), 127 - tw); lastWeightTile = tile.pos(); - tile.weight += lastWeightDelta; + if(!flying){ + tile.weight += lastWeightDelta; + }else{ + tile.airWeight += lastWeightDelta; + } }else{ lastWeightTile = Pos.invalid; } + wasFlying = flying; } public TileEntity getClosestCore(){ diff --git a/core/src/io/anuke/mindustry/world/Tile.java b/core/src/io/anuke/mindustry/world/Tile.java index 3dcc1862e3..46fce1527e 100644 --- a/core/src/io/anuke/mindustry/world/Tile.java +++ b/core/src/io/anuke/mindustry/world/Tile.java @@ -32,7 +32,7 @@ public class Tile implements Position, TargetTrait{ /** Tile traversal cost. */ public byte cost = 1; /** Weight of [ground] units on this tile.*/ - public byte weight = 0; + public byte weight, airWeight = 0; /** Tile entity, usually null. */ public TileEntity entity; public short x, y;