diff --git a/main/src/omaloon/content/blocks/OlDistributionBlocks.java b/main/src/omaloon/content/blocks/OlDistributionBlocks.java index 04a201a7..31d8a301 100644 --- a/main/src/omaloon/content/blocks/OlDistributionBlocks.java +++ b/main/src/omaloon/content/blocks/OlDistributionBlocks.java @@ -74,7 +74,7 @@ public static void load(){ health = 65; }}; - tubeOverflowGate = new TubeGate("tube-overflow-gate"){{ + tubeOverflowGate = new TubeOverflowGate("tube-overflow-gate"){{ requirements(Category.distribution, with( OlItems.cobalt, 3, OlItems.nickel, 2, OlItems.composite, 1 @@ -83,12 +83,11 @@ public static void load(){ health = 65; }}; - tubeUnderflowGate = new TubeGate("tube-underflow-gate"){{ + tubeUnderflowGate = new TubeUnderflowGate("tube-underflow-gate"){{ requirements(Category.distribution, with( OlItems.cobalt, 3, OlItems.nickel, 2, OlItems.composite, 1 )); - reverse = true; researchCostMultiplier = 0.3f; health = 65; }}; diff --git a/main/src/omaloon/world/blocks/distribution/TubeGate.java b/main/src/omaloon/world/blocks/distribution/TubeGate.java deleted file mode 100644 index cd30caf2..00000000 --- a/main/src/omaloon/world/blocks/distribution/TubeGate.java +++ /dev/null @@ -1,61 +0,0 @@ -package omaloon.world.blocks.distribution; - -import arc.util.*; -import mindustry.gen.*; -import mindustry.type.*; -import mindustry.world.*; - -// TODO animation breaks if items flow too fast, unlikely to be fixed. -public class TubeGate extends TubeRouter{ - public boolean reverse = false; - - public TubeGate(String name){ - super(name); - rotate = false; - } - - public class TubeGateBuild extends TubeRouterBuild{ - @Override - public boolean acceptItem(Building source, Item item){ - if(lastInput == null) lastInput = source.tile; - return team == source.team && lastItem == null && items.total() == 0; - } - - // TODO movement depends on lastInput, please do not - @Override - public Building getTileTarget(Item item, Tile from, boolean set){ - if(item == null || from == null) return null; - - int otherDir = relativeTo(from); - Building front = nearby((otherDir + 2) % 4); - - if(reverse){ - if(lookSides(item, from, false) == null && front != null && front.acceptItem(this, item)){ - return front; - }else{ - return lookSides(item, from, set); - } - }else{ - if(front != null && front.acceptItem(this, item)){ - return front; - }else{ - return lookSides(item, from, set); - } - } - } - - public @Nullable Building lookSides(Item item, Tile from, boolean set){ - int otherDir = relativeTo(from); - for(int i = 0; i < 4; i += 2){ - Building other = nearby((otherDir + 1 + i + targetRot) % 4); - if(set) targetRot = (byte)((i + targetRot + 2) % 4); - if(other == null || other.tile == from) continue; - if(other.acceptItem(this, item)){ - return other; - } - } - - return null; - } - } -} diff --git a/main/src/omaloon/world/blocks/distribution/TubeOverflowGate.java b/main/src/omaloon/world/blocks/distribution/TubeOverflowGate.java new file mode 100644 index 00000000..93a6f3f3 --- /dev/null +++ b/main/src/omaloon/world/blocks/distribution/TubeOverflowGate.java @@ -0,0 +1,83 @@ +package omaloon.world.blocks.distribution; + +import mindustry.gen.*; +import mindustry.type.*; +import mindustry.world.*; +import arc.util.*; +import arc.graphics.g2d.*; +import mindustry.graphics.*; + +import static mindustry.Vars.itemSize; + +public class TubeOverflowGate extends TubeRouter { + public TubeOverflowGate(String name){ + super(name); + rotate = false; + } + + public class TubeOverflowGateBuild extends TubeRouterBuild { + + @Override + public void draw(){ + Draw.z(Layer.block - 0.2f); + Draw.rect(bottomRegion, x, y); + + Draw.z(Layer.block - 0.1f); + Building target = getTileTarget(lastItem, lastInput, false); + float rot = 0f; + + if(target != null && lastItem != null && lastInput != null){ + int turn = arc.math.Mathf.mod(relativeTo(target) + 1 - relativeTo(lastInput), 4) - 1; + rot = turn * 90f * arc.math.Mathf.clamp(time); + float d = itemInterp.apply(arc.math.Mathf.clamp(time)); + + Draw.rect( + lastItem.uiIcon, + x + arc.math.Angles.trnsx(rot + relativeTo(lastInput) * 90f, 4f * d), + y + arc.math.Angles.trnsy(rot + relativeTo(lastInput) * 90f, 4f * d), + itemSize, + itemSize + ); + } + + Draw.z(Layer.block); + + float rotatorAngle = 45f; + if(target != null && lastItem != null && lastInput != null){ + int turn = arc.math.Mathf.mod(relativeTo(target) + 1 - relativeTo(lastInput), 4) - 1; + rotatorAngle = rot + relativeTo(lastInput) * 90f + (turn > 0 ? -45f : 45f); + } + + Drawf.spinSprite(rotatorRegion, x, y, rotatorAngle); + Draw.rect(region, x, y); + if(sideRegion[0].found()) Draw.rect(sideRegion[0], x, y, rotdeg()); + } + + @Override + public Building getTileTarget(Item item, Tile from, boolean set){ + if(item == null || from == null) return null; + + int otherDir = relativeTo(from); + Building front = nearby((otherDir + 2) % 4); + + if(front != null && front.acceptItem(this, item)){ + return front; + }else{ + return lookSides(item, from, set); + } + } + + public @Nullable Building lookSides(Item item, Tile from, boolean set){ + int otherDir = relativeTo(from); + for(int i = 0; i < 4; i += 2){ + Building other = nearby((otherDir + 1 + i + targetRot) % 4); + if(set) targetRot = (byte)((i + targetRot + 2) % 4); + if(other == null || other.tile == from) continue; + if(other.acceptItem(this, item)){ + return other; + } + } + return null; + } + } +} diff --git a/main/src/omaloon/world/blocks/distribution/TubeRouter.java b/main/src/omaloon/world/blocks/distribution/TubeRouter.java index fd4eef17..8a52c39f 100644 --- a/main/src/omaloon/world/blocks/distribution/TubeRouter.java +++ b/main/src/omaloon/world/blocks/distribution/TubeRouter.java @@ -57,10 +57,17 @@ public void setStats(){ public class TubeRouterBuild extends RouterBuild{ public byte targetRot = (byte)rotation; + public arc.struct.IntSeq buffer = new arc.struct.IntSeq(); @Override public boolean acceptItem(Building source, Item item){ - return super.acceptItem(source, item) && source != front(); + return super.acceptItem(source, item) && source != front() && items.total() < itemCapacity; + } + + @Override + public void handleItem(Building source, Item item){ + buffer.add(item.id, source == null ? 0 : source.tile.pos()); + items.add(item, 1); } @Override @@ -76,9 +83,10 @@ public void draw(){ Draw.z(Layer.block - 0.1f); Building target = getTileTarget(lastItem, lastInput, false); float rot = 0f; + int turn = 0; if(target != null && lastItem != null && lastInput != null){ - int turn = Mathf.mod(relativeTo(target) + 1 - relativeTo(lastInput), 4) - 1; + turn = Mathf.mod(relativeTo(target) + 1 - relativeTo(lastInput), 4) - 1; rot = turn * 90f * Mathf.clamp(time); float d = itemInterp.apply(Mathf.clamp(time)); @@ -94,7 +102,8 @@ public void draw(){ Draw.z(Layer.block); - Drawf.spinSprite(rotatorRegion, x, y, rot + 45f); + float pushOffset = (turn == 1 ? 30f : (turn == -1 ? -30f : 0f)); + Drawf.spinSprite(rotatorRegion, x, y, rot + 45f + pushOffset); Draw.rect(region, x, y); if(sideRegion[rotation > 1 ? 1 : 0].found()) Draw.rect(sideRegion[rotation > 1 ? 1 : 0], x, y, rotdeg()); } @@ -116,20 +125,26 @@ public void draw(){ @Override public void updateTile(){ - if(lastItem == null && items.any()){ - lastItem = items.first(); + if(lastItem == null && buffer.size > 0){ + int id = buffer.removeIndex(0); + int pos = buffer.removeIndex(0); + lastItem = mindustry.Vars.content.item(id); + lastInput = mindustry.Vars.world.tile(pos); + time = 0f; } Building target = getTileTarget(lastItem, lastInput, false); if(lastItem != null && target != null){ - time += 1f / speed * delta(); + float speedMultiplier = 1f + (buffer.size / 2f); + time += 1f / speed * delta() * speedMultiplier; if(time >= 1f || instantTransfer){ getTileTarget(lastItem, lastInput, true); target.handleItem(this, lastItem); items.remove(lastItem, 1); lastItem = null; + if(time > 1f) time -= 1f; else time = 0f; } } } diff --git a/main/src/omaloon/world/blocks/distribution/TubeUnderflowGate.java b/main/src/omaloon/world/blocks/distribution/TubeUnderflowGate.java new file mode 100644 index 00000000..576a79b4 --- /dev/null +++ b/main/src/omaloon/world/blocks/distribution/TubeUnderflowGate.java @@ -0,0 +1,31 @@ +package omaloon.world.blocks.distribution; + +import mindustry.gen.*; +import mindustry.type.*; +import mindustry.world.*; +import arc.util.*; + +public class TubeUnderflowGate extends TubeOverflowGate { + public TubeUnderflowGate(String name) { + super(name); + } + + public class TubeUnderflowGateBuild extends TubeOverflowGateBuild { + @Override + public Building getTileTarget(Item item, Tile from, boolean set){ + if(item == null || from == null) return null; + + int otherDir = relativeTo(from); + Building front = nearby((otherDir + 2) % 4); + + Building side = lookSides(item, from, set); + if(side != null){ + return side; + }else if (front != null && front.acceptItem(this, item)){ + return front; + } + + return null; + } + } +}