From da493284125267796203190363211769a9a4685f Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 6 Nov 2021 16:31:42 -0400 Subject: [PATCH] Stack router + Consistent item source + Item void flow --- .../blocks/distribution/ducts/arrow-glow.png | Bin 0 -> 2058 bytes .../distribution/ducts/surge-router-top.png | Bin 0 -> 165 bytes .../distribution/ducts/surge-router.png | Bin 0 -> 443 bytes core/assets/icons/icons.properties | 1 + core/assets/logicids.dat | Bin 3071 -> 3085 bytes core/src/mindustry/content/Blocks.java | 14 ++- .../mindustry/entities/comp/BuildingComp.java | 15 ++- .../blocks/distribution/StackConveyor.java | 7 +- .../blocks/distribution/StackRouter.java | 93 ++++++++++++++++++ .../world/blocks/sandbox/ItemSource.java | 23 ++++- .../world/blocks/sandbox/ItemVoid.java | 18 +++- .../mindustry/world/modules/ItemModule.java | 6 ++ 12 files changed, 162 insertions(+), 15 deletions(-) create mode 100644 core/assets-raw/sprites/blocks/distribution/ducts/arrow-glow.png create mode 100644 core/assets-raw/sprites/blocks/distribution/ducts/surge-router-top.png create mode 100644 core/assets-raw/sprites/blocks/distribution/ducts/surge-router.png create mode 100644 core/src/mindustry/world/blocks/distribution/StackRouter.java diff --git a/core/assets-raw/sprites/blocks/distribution/ducts/arrow-glow.png b/core/assets-raw/sprites/blocks/distribution/ducts/arrow-glow.png new file mode 100644 index 0000000000000000000000000000000000000000..469de3074286ab983f166c989bf1ec8935dd365a GIT binary patch literal 2058 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I4mJh`hT^KKFANOK=2amPB|(Yh3I#>^X_+~x z3MG{VsS2qTnQ06R6}R3_kDm5egQx9&q^mxoC&!VZ9rKK>XFUDRUl!xJN`LCC%AQVL z9fwI@6MgRd_&)z--Gc>l&anE575B)wpHM7zJo=~bNv*2+k9^HO-a z!}sZ%_yyPd8O`NGb%yTU_9%bnw{Lbh zTb?gyE$t|MFDJqo`HIW^kWI^x_p44nMxTx1Of0RF|`%!1$}>$>Orv#WMck zPA+bbEf<$A^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E;v<@V2Jm0 zaSVxQeS0;Ui$Q_IB{27Y^)^wKWy;Pb-*-Q9&^KOs<$YyYg3FOY!S7$JQV)ncsuGe4 z3{n<+y4P9p6obejRtJS!4SGq640G?@V|t~yB+mJjvrBE)%J~U@Y}? zaSVxQeLH=9(IE$cWA=F)cJKu^`uN=Pvbuczgzy8cN3S=2<%pTDu>PRWL>8Y%T`vM; zR&{ZynNL5Ry1Cq!@9?TS^Y45=eed0yv_{)e<82Ic&>ViOfy*%Z$&I&N=NL3Pyu@U#sh<%OFBkoJjQhxhs)Z-a85%UW)+8>{ zNO&upD;;Bduy(nq0>}I{M{^a9+0oJBy*OPS%xH%fW zxtwK=J>K%FvtrWKUAd1%zc32=8(D@aN+mDw?&x1~k9(Rx3QvGQ)zcEjd&}InMR-T6gzbP%kqB0|SGntDnm{r-UW|@)f+O literal 0 HcmV?d00001 diff --git a/core/assets/icons/icons.properties b/core/assets/icons/icons.properties index 8186900200..2f97c447d2 100755 --- a/core/assets/icons/icons.properties +++ b/core/assets/icons/icons.properties @@ -425,3 +425,4 @@ 63283=surge-duct|block-surge-duct-ui 63282=surge-conveyor|block-surge-conveyor-ui 63281=duct-unloader|block-duct-unloader-ui +63280=surge-router|block-surge-router-ui diff --git a/core/assets/logicids.dat b/core/assets/logicids.dat index 966264a93fb49e1ebf9728276f3936ee61189bf3..e81d33169c27a84dfa1400efcc24548383d966e8 100644 GIT binary patch delta 28 jcmew_-Ydbxux=yMNltE_;?kn@RNbQd(vr<5IL(;=kXZ@h delta 16 XcmeB`_%F`Huy!NUNzTnTIZc=VGo=N) diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 22f0fec617..61e4b02533 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -75,7 +75,7 @@ public class Blocks implements ContentList{ conveyor, titaniumConveyor, plastaniumConveyor, armoredConveyor, distributor, junction, itemBridge, phaseConveyor, sorter, invertedSorter, router, overflowGate, underflowGate, massDriver, duct, ductRouter, ductBridge, ductUnloader, - surgeConveyor, + surgeConveyor, surgeRouter, //liquid mechanicalPump, rotaryPump, thermalPump, conduit, pulseConduit, platedConduit, liquidRouter, liquidContainer, liquidTank, liquidJunction, bridgeConduit, phaseConduit, @@ -1328,6 +1328,18 @@ public class Blocks implements ContentList{ consumes.power(1f / 60f); }}; + surgeRouter = new StackRouter("surge-router"){{ + requirements(Category.distribution, with(Items.graphite, 10, Items.surgeAlloy, 10)); + + speed = 6f; + + hasPower = true; + consumesPower = true; + conductivePower = true; + baseEfficiency = 1f; + consumes.power(3f / 60f); + }}; + //endregion //region liquid diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index 6774862c35..288985cd70 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -1099,6 +1099,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, return block.uiIcon; } + /** @return the item module to use for flow rate calculations */ + public ItemModule flowItems(){ + return items; + } + @Override public void display(Table table){ //display the block stuff @@ -1126,7 +1131,9 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, if(displayFlow){ String ps = " " + StatUnit.perSecond.localized(); - if(items != null){ + var flowItems = flowItems(); + + if(flowItems != null){ table.row(); table.left(); table.table(l -> { @@ -1136,9 +1143,9 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, l.clearChildren(); l.left(); for(Item item : content.items()){ - if(items.hasFlowItem(item)){ + if(flowItems.hasFlowItem(item)){ l.image(item.uiIcon).padRight(3f); - l.label(() -> items.getFlowRate(item) < 0 ? "..." : Strings.fixed(items.getFlowRate(item), 1) + ps).color(Color.lightGray); + l.label(() -> flowItems.getFlowRate(item) < 0 ? "..." : Strings.fixed(flowItems.getFlowRate(item), 1) + ps).color(Color.lightGray); l.row(); } } @@ -1147,7 +1154,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, rebuild.run(); l.update(() -> { for(Item item : content.items()){ - if(items.hasFlowItem(item) && !current.get(item.id)){ + if(flowItems.hasFlowItem(item) && !current.get(item.id)){ current.set(item.id); rebuild.run(); } diff --git a/core/src/mindustry/world/blocks/distribution/StackConveyor.java b/core/src/mindustry/world/blocks/distribution/StackConveyor.java index cce5470752..5fc7eb716e 100644 --- a/core/src/mindustry/world/blocks/distribution/StackConveyor.java +++ b/core/src/mindustry/world/blocks/distribution/StackConveyor.java @@ -112,7 +112,6 @@ public class StackConveyor extends Block implements Autotiler{ public int link = -1; public float cooldown; public Item lastItem; - public float glow; boolean proxUpdating = false; @@ -133,9 +132,9 @@ public class StackConveyor extends Block implements Autotiler{ Tile from = world.tile(link); //TODO do not draw for certain configurations? - if(glowRegion.found() && glow > 0f){ + if(glowRegion.found() && power != null && power.status > 0f){ Draw.z(Layer.blockAdditive); - Draw.color(glowColor, glowAlpha * glow); + Draw.color(glowColor, glowAlpha * power.status); Draw.blend(Blending.additive); Draw.rect(glowRegion, x, y, rotation * 90); Draw.blend(); @@ -253,8 +252,6 @@ public class StackConveyor extends Block implements Autotiler{ lastItem = items.first(); } - if(power != null) glow = Mathf.lerpDelta(glow, power.status, 0.6f); - //do not continue if disabled, will still allow one to be reeled in to prevent visual stacking if(!enabled) return; diff --git a/core/src/mindustry/world/blocks/distribution/StackRouter.java b/core/src/mindustry/world/blocks/distribution/StackRouter.java new file mode 100644 index 0000000000..f812889374 --- /dev/null +++ b/core/src/mindustry/world/blocks/distribution/StackRouter.java @@ -0,0 +1,93 @@ +package mindustry.world.blocks.distribution; + +import arc.graphics.*; +import arc.graphics.g2d.*; +import mindustry.annotations.Annotations.*; +import mindustry.gen.*; +import mindustry.graphics.*; +import mindustry.type.*; +import mindustry.world.*; + +public class StackRouter extends DuctRouter{ + public float baseEfficiency = 0f; + + public @Load(value = "@-glow", fallback = "arrow-glow") TextureRegion glowRegion; + public float glowAlpha = 1f; + public Color glowColor = Pal.redLight; + + public StackRouter(String name){ + super(name); + itemCapacity = 10; + } + + public class StackRouterBuild extends DuctRouterBuild{ + public boolean unloading = false; + + @Override + public void updateTile(){ + float cap = speed; + + if(!unloading && current != null && items.total() >= itemCapacity){ + if(progress < cap){ + //when items are full, begin offload timer + progress += edelta(); + } + + if(progress >= cap){ + unloading = true; + progress %= cap; + } + } + + //unload as many as possible when in unloading state + if(unloading && current != null){ + //unload when possible + var target = target(); + while(target != null && items.total() > 0){ + target.handleItem(this, current); + int mod = sortItem != null && current != sortItem ? 2 : 3; + cdump = (byte)((cdump + 1) % mod); + items.remove(current, 1); + + target = target(); + } + + //if out of items, unloading is over + if(items.total() == 0){ + current = null; + unloading = false; + } + } + + if(current == null && items.total() > 0){ + current = items.first(); + } + } + + @Override + public void draw(){ + super.draw(); + + if(glowRegion.found() && power != null && power.status > 0){ + Draw.z(Layer.blockAdditive); + Draw.color(glowColor, glowAlpha * power.status); + Draw.blend(Blending.additive); + Draw.rect(glowRegion, x, y, rotation * 90); + Draw.blend(); + Draw.color(); + } + } + + @Override + public float efficiency(){ + if(!enabled) return 0; + return baseEfficiency + (power == null ? 0 : power.status); + } + + @Override + public boolean acceptItem(Building source, Item item){ + return !unloading && (current == null || item == current) && items.total() < itemCapacity && + (Edges.getFacingEdge(source.tile(), tile).relativeTo(tile) == rotation); + } + } +} diff --git a/core/src/mindustry/world/blocks/sandbox/ItemSource.java b/core/src/mindustry/world/blocks/sandbox/ItemSource.java index c286af2674..3a86cf01f5 100644 --- a/core/src/mindustry/world/blocks/sandbox/ItemSource.java +++ b/core/src/mindustry/world/blocks/sandbox/ItemSource.java @@ -14,6 +14,7 @@ import mindustry.world.meta.*; import static mindustry.Vars.*; public class ItemSource extends Block{ + public int itemsPerSecond = 100; public ItemSource(String name){ super(name); @@ -36,6 +37,13 @@ public class ItemSource extends Block{ bars.remove("items"); } + @Override + public void setStats(){ + super.setStats(); + + stats.add(Stat.output, itemsPerSecond, StatUnit.itemsSecond); + } + @Override public void drawRequestConfig(BuildPlan req, Eachable list){ drawRequestConfigCenter(req, req.config, "center", true); @@ -47,7 +55,8 @@ public class ItemSource extends Block{ } public class ItemSourceBuild extends Building{ - Item outputItem; + public float counter; + public Item outputItem; @Override public void draw(){ @@ -66,9 +75,15 @@ public class ItemSource extends Block{ public void updateTile(){ if(outputItem == null) return; - items.set(outputItem, 1); - dump(outputItem); - items.set(outputItem, 0); + counter += edelta(); + float limit = 60f / itemsPerSecond; + + while(counter >= limit){ + items.set(outputItem, 1); + dump(outputItem); + items.set(outputItem, 0); + counter -= limit; + } } @Override diff --git a/core/src/mindustry/world/blocks/sandbox/ItemVoid.java b/core/src/mindustry/world/blocks/sandbox/ItemVoid.java index fcda607542..61c4bb75c2 100644 --- a/core/src/mindustry/world/blocks/sandbox/ItemVoid.java +++ b/core/src/mindustry/world/blocks/sandbox/ItemVoid.java @@ -4,6 +4,7 @@ import mindustry.gen.*; import mindustry.type.*; import mindustry.world.*; import mindustry.world.meta.*; +import mindustry.world.modules.*; public class ItemVoid extends Block{ @@ -15,8 +16,23 @@ public class ItemVoid extends Block{ } public class ItemVoidBuild extends Building{ + //I need a fake item module, because items can't be added to older blocks (breaks saves) + public ItemModule flowItems = new ItemModule(); + @Override - public void handleItem(Building source, Item item){} + public ItemModule flowItems(){ + return flowItems; + } + + @Override + public void updateTile(){ + flowItems.update(updateFlow); + } + + @Override + public void handleItem(Building source, Item item){ + flowItems.handleFlow(item, 1); + } @Override public boolean acceptItem(Building source, Item item){ diff --git a/core/src/mindustry/world/modules/ItemModule.java b/core/src/mindustry/world/modules/ItemModule.java index 2a27f82df3..f5624def6d 100644 --- a/core/src/mindustry/world/modules/ItemModule.java +++ b/core/src/mindustry/world/modules/ItemModule.java @@ -273,6 +273,12 @@ public class ItemModule extends BlockModule{ } } + public void handleFlow(Item item, int amount){ + if(flow != null){ + cacheSums[item.id] += amount; + } + } + public void undoFlow(Item item){ if(flow != null){ cacheSums[item.id] -= 1;