diff --git a/core/assets-raw/sprites_replacement/blocks/distribution/bridge-conveyor-end.png b/core/assets-raw/sprites_replacement/blocks/distribution/bridge-conveyor-end.png new file mode 100644 index 0000000000..b553fc29a7 Binary files /dev/null and b/core/assets-raw/sprites_replacement/blocks/distribution/bridge-conveyor-end.png differ diff --git a/core/assets/sprites/sprites.png b/core/assets/sprites/sprites.png index c5ff193236..7329e0099d 100644 Binary files a/core/assets/sprites/sprites.png and b/core/assets/sprites/sprites.png differ diff --git a/core/src/io/anuke/mindustry/entities/type/Unit.java b/core/src/io/anuke/mindustry/entities/type/Unit.java index 207f6eca2f..c133a7abfc 100644 --- a/core/src/io/anuke/mindustry/entities/type/Unit.java +++ b/core/src/io/anuke/mindustry/entities/type/Unit.java @@ -219,6 +219,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ return status.hasEffect(effect); } + //TODO optimize public void avoidOthers(float scaling){ hitbox(queryRect); queryRect.setSize(queryRect.getWidth() * scaling); diff --git a/core/src/io/anuke/mindustry/world/Pos.java b/core/src/io/anuke/mindustry/world/Pos.java index bdbf3a2f7c..9a2860ee2a 100644 --- a/core/src/io/anuke/mindustry/world/Pos.java +++ b/core/src/io/anuke/mindustry/world/Pos.java @@ -2,6 +2,7 @@ package io.anuke.mindustry.world; /**Methods for a packed position 'struct', contained in an int.*/ public class Pos{ + public static final int invalid = get(-1, -1); /**Returns packed position from an x/y position. The values must be within short limits.*/ public static int get(int x, int y){ diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java index 395251ecdf..7e4bfe30d3 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java @@ -7,12 +7,10 @@ import io.anuke.arc.collection.IntArray; import io.anuke.arc.collection.IntSet; import io.anuke.arc.collection.IntSet.IntSetIterator; import io.anuke.arc.graphics.Color; -import io.anuke.arc.graphics.g2d.CapStyle; -import io.anuke.arc.graphics.g2d.Draw; -import io.anuke.arc.graphics.g2d.Lines; -import io.anuke.arc.graphics.g2d.TextureRegion; +import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.math.Mathf; import io.anuke.arc.math.geom.Geometry; +import io.anuke.arc.math.geom.Point2; import io.anuke.arc.util.Time; import io.anuke.mindustry.entities.type.Player; import io.anuke.mindustry.entities.type.TileEntity; @@ -34,8 +32,6 @@ import static io.anuke.mindustry.Vars.tilesize; import static io.anuke.mindustry.Vars.world; public class ItemBridge extends Block{ - protected static int lastPlaced; - protected int timerTransport = timers++; protected int range; protected float transportTime = 2f; @@ -85,29 +81,39 @@ public class ItemBridge extends Block{ @Override public void playerPlaced(Tile tile){ - Tile last = world.tile(lastPlaced); - if(linkValid(tile, last)){ - ItemBridgeEntity entity = last.entity(); - if(!linkValid(last, world.tile(entity.link))){ - Call.linkItemBridge(null, last, tile); + Tile link = findLink(tile.x, tile.y); + if(linkValid(tile, link)){ + Call.linkItemBridge(null, link, tile); + } + } + + public Tile findLink(int x, int y){ + for(int j = 0; j < 4; j ++){ + Point2 p = Geometry.d4(j + 1); + for(int i = 1; i <= range; i++){ + Tile tile = world.tile(x + p.x * i, y + p.y * i); + + if(tile == null) break; + if(tile.block() == this && tile.entity().link == Pos.invalid){ + return tile; + } } } - lastPlaced = tile.pos(); + return null; } @Override public void drawPlace(int x, int y, int rotation, boolean valid){ - Lines.stroke(2f); - Draw.color(Pal.placing); - for(int i = 0; i < 4; i++){ - Lines.dashLine( - x * tilesize + Geometry.d4[i].x * (tilesize / 2f + 2), - y * tilesize + Geometry.d4[i].y * (tilesize / 2f + 2), - x * tilesize + Geometry.d4[i].x * (range + 0.5f) * tilesize, - y * tilesize + Geometry.d4[i].y * (range + 0.5f) * tilesize, - range); - } + Tile link = findLink(x, y); + Lines.stroke(1f, Pal.placing); + if(link != null){ + int rot = link.absoluteRelativeTo(x, y); + float w = (link.x == x ? tilesize : Math.abs(link.x - x) * tilesize - tilesize); + float h = (link.y == y ? tilesize : Math.abs(link.y - y) * tilesize - tilesize); + Lines.rect((x + link.x)/2f * tilesize - w/2f, (y + link.y)/2f * tilesize - h/2f, w, h); + Fill.poly(link.x * tilesize + Geometry.d4[rot].x * tilesize, link.y * tilesize + Geometry.d4[rot].y * tilesize, 3, 2.8f, link.absoluteRelativeTo(x, y)*90); + } Draw.reset(); } @@ -175,6 +181,7 @@ public class ItemBridge extends Block{ Tile other = world.tile(entity.link); if(!linkValid(tile, other)){ + entity.link = Pos.invalid; tryDump(tile); entity.uptime = 0f; }else{ @@ -310,7 +317,7 @@ public class ItemBridge extends Block{ } public static class ItemBridgeEntity extends TileEntity{ - public int link = -1; + public int link = Pos.invalid; public IntSet incoming = new IntSet(); public float uptime; public float time;