diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 3340e06757..151d134752 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -964,15 +964,20 @@ public class Blocks implements ContentList{ itemBridge = new BufferedItemBridge("bridge-conveyor"){{ requirements(Category.distribution, with(Items.lead, 6, Items.copper, 6)); + fadeIn = moveArrows = false; range = 4; speed = 74f; + arrowSpacing = 6f; bufferCapacity = 14; }}; phaseConveyor = new ItemBridge("phase-conveyor"){{ requirements(Category.distribution, with(Items.phaseFabric, 5, Items.silicon, 7, Items.lead, 10, Items.graphite, 10)); range = 12; + arrowPeriod = 0.9f; + arrowTimeScl = 2.75f; hasPower = true; + pulse = true; consumes.power(0.30f); }}; @@ -1095,8 +1100,10 @@ public class Blocks implements ContentList{ requirements(Category.liquid, with(Items.graphite, 2, Items.metaglass, 2)); }}; - bridgeConduit = new LiquidExtendingBridge("bridge-conduit"){{ + bridgeConduit = new LiquidBridge("bridge-conduit"){{ requirements(Category.liquid, with(Items.graphite, 4, Items.metaglass, 8)); + fadeIn = moveArrows = false; + arrowSpacing = 6f; range = 4; hasPower = false; }}; @@ -1104,8 +1111,11 @@ public class Blocks implements ContentList{ phaseConduit = new LiquidBridge("phase-conduit"){{ requirements(Category.liquid, with(Items.phaseFabric, 5, Items.silicon, 7, Items.metaglass, 20, Items.titanium, 10)); range = 12; + arrowPeriod = 0.9f; + arrowTimeScl = 2.75f; hasPower = true; canOverdrive = false; + pulse = true; consumes.power(0.30f); }}; diff --git a/core/src/mindustry/mod/Mods.java b/core/src/mindustry/mod/Mods.java index 693ac2222a..cde7f8450f 100644 --- a/core/src/mindustry/mod/Mods.java +++ b/core/src/mindustry/mod/Mods.java @@ -626,7 +626,7 @@ public class Mods implements Loadable{ try{ //this binds the content but does not load it entirely Content loaded = parser.parse(l.mod, l.file.nameWithoutExtension(), l.file.readString("UTF-8"), l.file, l.type); - Log.debug("[@] Loaded '@'.", l.mod.meta.name, (loaded instanceof UnlockableContent ? ((UnlockableContent)loaded).localizedName : loaded)); + Log.debug("[@] Loaded '@'.", l.mod.meta.name, (loaded instanceof UnlockableContent u ? u.localizedName : loaded)); }catch(Throwable e){ if(current != content.getLastAdded() && content.getLastAdded() != null){ parser.markError(content.getLastAdded(), l.mod, l.file, e); diff --git a/core/src/mindustry/world/blocks/distribution/BufferedItemBridge.java b/core/src/mindustry/world/blocks/distribution/BufferedItemBridge.java index a87fb0348a..6fe8e90722 100644 --- a/core/src/mindustry/world/blocks/distribution/BufferedItemBridge.java +++ b/core/src/mindustry/world/blocks/distribution/BufferedItemBridge.java @@ -1,12 +1,11 @@ package mindustry.world.blocks.distribution; -import arc.math.*; import arc.util.io.*; import mindustry.gen.*; import mindustry.type.*; import mindustry.world.*; -public class BufferedItemBridge extends ExtendingItemBridge{ +public class BufferedItemBridge extends ItemBridge{ public final int timerAccept = timers++; public float speed = 40f; @@ -19,7 +18,7 @@ public class BufferedItemBridge extends ExtendingItemBridge{ canOverdrive = true; } - public class BufferedItemBridgeBuild extends ExtendingItemBridgeBuild{ + public class BufferedItemBridgeBuild extends ItemBridgeBuild{ ItemBuffer buffer = new ItemBuffer(bufferCapacity); @Override @@ -30,11 +29,9 @@ public class BufferedItemBridge extends ExtendingItemBridge{ Item item = buffer.poll(speed / timeScale); if(timer(timerAccept, 4 / timeScale) && item != null && other.acceptItem(this, item)){ - cycleSpeed = Mathf.lerpDelta(cycleSpeed, 4f, 0.05f); + moved = true; other.handleItem(this, item); buffer.remove(); - }else{ - cycleSpeed = Mathf.lerpDelta(cycleSpeed, 0f, 0.008f); } } diff --git a/core/src/mindustry/world/blocks/distribution/ExtendingItemBridge.java b/core/src/mindustry/world/blocks/distribution/ExtendingItemBridge.java index 98b48e043a..7e2e5eac55 100644 --- a/core/src/mindustry/world/blocks/distribution/ExtendingItemBridge.java +++ b/core/src/mindustry/world/blocks/distribution/ExtendingItemBridge.java @@ -1,70 +1,15 @@ package mindustry.world.blocks.distribution; -import arc.graphics.g2d.*; -import arc.math.*; -import arc.math.geom.*; -import mindustry.core.*; -import mindustry.graphics.*; -import mindustry.world.*; - -import static mindustry.Vars.*; - +/** @deprecated use ItemBridge instead. */ +@Deprecated public class ExtendingItemBridge extends ItemBridge{ public ExtendingItemBridge(String name){ super(name); - hasItems = true; } + @Deprecated public class ExtendingItemBridgeBuild extends ItemBridgeBuild{ - @Override - public void draw(){ - Draw.rect(region, x, y); - Draw.z(Layer.power); - - Tile other = world.tile(link); - if(!linkValid(tile, other)) return; - - int i = tile.absoluteRelativeTo(other.x, other.y); - - float ex = other.worldx() - x - Geometry.d4(i).x * tilesize / 2f, - ey = other.worldy() - y - Geometry.d4(i).y * tilesize / 2f; - - float uptime = state.isEditor() ? 1f : this.uptime; - - ex *= uptime; - ey *= uptime; - - if(Mathf.zero(Renderer.bridgeOpacity)) return; - Draw.alpha(Renderer.bridgeOpacity); - - Lines.stroke(8f); - Lines.line(bridgeRegion, - x + Geometry.d4(i).x * tilesize / 2f, - y + Geometry.d4(i).y * tilesize / 2f, - x + ex, - y + ey, false); - - Draw.rect(endRegion, x, y, i * 90 + 90); - Draw.rect(endRegion, - x + ex + Geometry.d4(i).x * tilesize / 2f, - y + ey + Geometry.d4(i).y * tilesize / 2f, i * 90 + 270); - - int dist = Math.max(Math.abs(other.x - tile.x), Math.abs(other.y - tile.y)); - - int arrows = (dist) * tilesize / 6 - 1; - - Draw.color(); - - for(int a = 0; a < arrows; a++){ - Draw.alpha(Mathf.absin(a / (float)arrows - time / 100f, 0.1f, 1f) * uptime * Renderer.bridgeOpacity); - Draw.rect(arrowRegion, - x + Geometry.d4(i).x * (tilesize / 2f + a * 6f + 2) * uptime, - y + Geometry.d4(i).y * (tilesize / 2f + a * 6f + 2) * uptime, - i * 90f); - } - Draw.reset(); - } } } diff --git a/core/src/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/mindustry/world/blocks/distribution/ItemBridge.java index 53f69b5aef..8f5233f535 100644 --- a/core/src/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/mindustry/world/blocks/distribution/ItemBridge.java @@ -23,12 +23,20 @@ import static mindustry.Vars.*; public class ItemBridge extends Block{ private static BuildPlan otherReq; + public final int timerCheckMoved = timers ++; + public int range; public float transportTime = 2f; public @Load("@-end") TextureRegion endRegion; public @Load("@-bridge") TextureRegion bridgeRegion; public @Load("@-arrow") TextureRegion arrowRegion; + public boolean fadeIn = true; + public boolean moveArrows = true; + public boolean pulse = false; + public float arrowSpacing = 4f, arrowOffset = 2f, arrowPeriod = 0.4f; + public float arrowTimeScl = 6.2f; + //for autolink public @Nullable ItemBridgeBuild lastBuild; @@ -171,10 +179,9 @@ public class ItemBridge extends Block{ public int link = -1; //TODO awful public IntSet incoming = new IntSet(); - public float uptime; + public float warmup; public float time; - public float time2; - public float cycleSpeed = 1f; + public boolean wasMoved, moved; public float transportCounter; @Override @@ -283,24 +290,23 @@ public class ItemBridge extends Block{ @Override public void updateTile(){ - time += cycleSpeed * delta(); - time2 += (cycleSpeed - 1f) * delta(); + if(timer(timerCheckMoved, 30f)){ + wasMoved = moved; + moved = false; + } + + time += wasMoved ? delta() : 0f; checkIncoming(); Tile other = world.tile(link); if(!linkValid(tile, other)){ doDump(); - uptime = 0f; + warmup = 0f; }else{ ((ItemBridgeBuild)other.build).incoming.add(tile.pos()); - if(consValid() && Mathf.zero(1f - efficiency())){ - uptime = Mathf.lerpDelta(uptime, 1f, 0.04f); - }else{ - uptime = Mathf.lerpDelta(uptime, 0f, 0.02f); - } - + warmup = Mathf.approachDelta(warmup, efficiency(), 1f / 30f); updateTransport(other.build); } } @@ -311,21 +317,18 @@ public class ItemBridge extends Block{ } public void updateTransport(Building other){ - boolean any = false; transportCounter += edelta(); while(transportCounter >= transportTime){ Item item = items.take(); if(item != null && other.acceptItem(this, item)){ other.handleItem(this, item); - any = true; + moved = true; }else if(item != null){ items.add(item, 1); items.undoFlow(item); } transportCounter -= transportTime; } - - cycleSpeed = Mathf.lerpDelta(cycleSpeed, any ? 4f : 1f, any ? 0.05f : 0.01f); } @Override @@ -341,8 +344,11 @@ public class ItemBridge extends Block{ int i = relativeTo(other.x, other.y); - Draw.color(Color.white, Color.black, Mathf.absin(Time.time, 6f, 0.07f)); - Draw.alpha(Math.max(uptime, 0.25f) * Renderer.bridgeOpacity); + if(pulse){ + Draw.color(Color.white, Color.black, Mathf.absin(Time.time, 6f, 0.07f)); + } + + Draw.alpha((fadeIn ? Math.max(warmup, 0.25f) : 1f) * Renderer.bridgeOpacity); Draw.rect(endRegion, x, y, i * 90 + 90); Draw.rect(endRegion, other.drawx(), other.drawy(), i * 90 + 270); @@ -357,19 +363,20 @@ public class ItemBridge extends Block{ other.worldx() - Tmp.v1.x, other.worldy() - Tmp.v1.y, false); - int dist = Math.max(Math.abs(other.x - tile.x), Math.abs(other.y - tile.y)); - - float time = time2 / 1.7f; - int arrows = (dist) * tilesize / 4 - 2; + int dist = Math.max(Math.abs(other.x - tile.x), Math.abs(other.y - tile.y)) - 1; Draw.color(); + int arrows = (int)(dist * tilesize / arrowSpacing), dx = Geometry.d4x(i), dy = Geometry.d4y(i); + for(int a = 0; a < arrows; a++){ - Draw.alpha(Mathf.absin(a / (float)arrows - time / 100f, 0.1f, 1f) * uptime * Renderer.bridgeOpacity); + Draw.alpha(Mathf.absin(a - time / arrowTimeScl, arrowPeriod, 1f) * warmup * Renderer.bridgeOpacity); Draw.rect(arrowRegion, - x + Geometry.d4(i).x * (tilesize / 2f + a * 4f + time % 4f), - y + Geometry.d4(i).y * (tilesize / 2f + a * 4f + time % 4f), i * 90f); + x + dx * (tilesize / 2f + a * arrowSpacing + arrowOffset), + y + dy * (tilesize / 2f + a * arrowSpacing + arrowOffset), + i * 90f); } + Draw.reset(); } @@ -460,11 +467,16 @@ public class ItemBridge extends Block{ return Point2.unpack(link).sub(tile.x, tile.y); } + @Override + public byte version(){ + return 1; //TODO write cycleSpeed, 1 + } + @Override public void write(Writes write){ super.write(write); write.i(link); - write.f(uptime); + write.f(warmup); write.b(incoming.size); IntSetIterator it = incoming.iterator(); @@ -472,17 +484,23 @@ public class ItemBridge extends Block{ while(it.hasNext){ write.i(it.next()); } + + write.bool(wasMoved || moved); } @Override public void read(Reads read, byte revision){ super.read(read, revision); link = read.i(); - uptime = read.f(); + warmup = read.f(); byte links = read.b(); for(int i = 0; i < links; i++){ incoming.add(read.i()); } + + if(revision >= 1){ + wasMoved = moved = read.bool(); + } } } } diff --git a/core/src/mindustry/world/blocks/liquid/LiquidBridge.java b/core/src/mindustry/world/blocks/liquid/LiquidBridge.java index 83b2fe3e1e..4214a1cee9 100644 --- a/core/src/mindustry/world/blocks/liquid/LiquidBridge.java +++ b/core/src/mindustry/world/blocks/liquid/LiquidBridge.java @@ -1,13 +1,10 @@ package mindustry.world.blocks.liquid; -import arc.math.*; import mindustry.gen.*; import mindustry.type.*; import mindustry.world.blocks.distribution.*; import mindustry.world.meta.*; -import static mindustry.Vars.*; - public class LiquidBridge extends ItemBridge{ public LiquidBridge(String name){ @@ -20,40 +17,19 @@ public class LiquidBridge extends ItemBridge{ } public class LiquidBridgeBuild extends ItemBridgeBuild{ + @Override - public void updateTile(){ - time += cycleSpeed * delta(); - time2 += (cycleSpeed - 1f) * delta(); - - checkIncoming(); - - Building other = world.build(link); - if(other == null || !linkValid(tile, other.tile())){ - dumpLiquid(liquids.current(), 1f); - }else{ - ((ItemBridgeBuild)other).incoming.add(tile.pos()); - - if(consValid()){ - float alpha = 0.04f; - if(hasPower){ - alpha *= efficiency(); // Exceed boot time unless power is at max. - } - uptime = Mathf.lerpDelta(uptime, 1f, alpha); - }else{ - uptime = Mathf.lerpDelta(uptime, 0f, 0.02f); - } - - if(uptime >= 0.5f){ - - if(moveLiquid(other, liquids.current()) > 0.1f){ - cycleSpeed = Mathf.lerpDelta(cycleSpeed, 4f, 0.05f); - }else{ - cycleSpeed = Mathf.lerpDelta(cycleSpeed, 1f, 0.01f); - } - } + public void updateTransport(Building other){ + if(warmup >= 0.5f){ + moved |= moveLiquid(other, liquids.current()) > 0.05f; } } + @Override + public void doDump(){ + dumpLiquid(liquids.current(), 1f); + } + @Override public boolean acceptItem(Building source, Item item){ return false; diff --git a/core/src/mindustry/world/blocks/liquid/LiquidExtendingBridge.java b/core/src/mindustry/world/blocks/liquid/LiquidExtendingBridge.java index 552c348891..37dcc69b7d 100644 --- a/core/src/mindustry/world/blocks/liquid/LiquidExtendingBridge.java +++ b/core/src/mindustry/world/blocks/liquid/LiquidExtendingBridge.java @@ -1,56 +1,14 @@ package mindustry.world.blocks.liquid; -import arc.math.*; -import mindustry.gen.*; -import mindustry.type.*; -import mindustry.world.blocks.distribution.*; -import mindustry.world.meta.*; - -import static mindustry.Vars.*; - -public class LiquidExtendingBridge extends ExtendingItemBridge{ +/** @deprecated use LiquidBridge instead. */ +@Deprecated +public class LiquidExtendingBridge extends LiquidBridge{ public LiquidExtendingBridge(String name){ super(name); - hasItems = false; - hasLiquids = true; - outputsLiquid = true; - group = BlockGroup.liquids; } - public class LiquidExtendingBridgeBuild extends ExtendingItemBridgeBuild{ - @Override - public void updateTile(){ - time += cycleSpeed * delta(); - time2 += (cycleSpeed - 1f) * delta(); - - checkIncoming(); - - Building other = world.build(link); - if(other == null || !linkValid(tile, other.tile())){ - dumpLiquid(liquids.current(), 1f); - }else{ - ((ItemBridgeBuild)other).incoming.add(tile.pos()); - - if(consValid()){ - uptime = Mathf.lerpDelta(uptime, 1f, 0.04f); - }else{ - uptime = Mathf.lerpDelta(uptime, 0f, 0.02f); - } - - if(uptime >= 0.5f){ - if(moveLiquid(other, liquids.current()) > 0.1f){ - cycleSpeed = Mathf.lerpDelta(cycleSpeed, 4f, 0.05f); - }else{ - cycleSpeed = Mathf.lerpDelta(cycleSpeed, 0f, 0.01f); - } - } - } - } - - @Override - public boolean acceptItem(Building source, Item item){ - return false; - } + @Deprecated + public class LiquidExtendingBridgeBuild extends LiquidBridgeBuild{ } }