From 486622e3e45fa5e92955ab41f950db21957b9d46 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 14 Nov 2021 23:10:15 -0500 Subject: [PATCH] Many crazy things --- ...ump-liquid.png => impulse-pump-liquid.png} | Bin .../{thermal-pump.png => impulse-pump.png} | Bin .../blocks/liquid/reinforced-pump-liquid.png | Bin 0 -> 210 bytes .../sprites/blocks/liquid/reinforced-pump.png | Bin 0 -> 859 bytes core/assets-raw/sprites/items/item-oxide.png | Bin 0 -> 295 bytes .../sprites/items/liquid-hydrogen.png | Bin 0 -> 320 bytes .../assets-raw/sprites/items/liquid-ozone.png | Bin 0 -> 322 bytes core/assets/bundles/bundle.properties | 4 +- core/assets/bundles/bundle_be.properties | 4 +- core/assets/bundles/bundle_bg.properties | 4 +- core/assets/bundles/bundle_cs.properties | 4 +- core/assets/bundles/bundle_da.properties | 4 +- core/assets/bundles/bundle_de.properties | 4 +- core/assets/bundles/bundle_es.properties | 4 +- core/assets/bundles/bundle_et.properties | 4 +- core/assets/bundles/bundle_eu.properties | 4 +- core/assets/bundles/bundle_fi.properties | 4 +- core/assets/bundles/bundle_fil.properties | 4 +- core/assets/bundles/bundle_fr.properties | 4 +- core/assets/bundles/bundle_hu.properties | 4 +- core/assets/bundles/bundle_in_ID.properties | 4 +- core/assets/bundles/bundle_it.properties | 4 +- core/assets/bundles/bundle_ja.properties | 4 +- core/assets/bundles/bundle_ko.properties | 6 +- core/assets/bundles/bundle_lt.properties | 4 +- core/assets/bundles/bundle_nl.properties | 4 +- core/assets/bundles/bundle_nl_BE.properties | 4 +- core/assets/bundles/bundle_pl.properties | 4 +- core/assets/bundles/bundle_pt_BR.properties | 4 +- core/assets/bundles/bundle_pt_PT.properties | 4 +- core/assets/bundles/bundle_ro.properties | 4 +- core/assets/bundles/bundle_ru.properties | 4 +- core/assets/bundles/bundle_sr.properties | 4 +- core/assets/bundles/bundle_sv.properties | 4 +- core/assets/bundles/bundle_th.properties | 4 +- core/assets/bundles/bundle_tk.properties | 4 +- core/assets/bundles/bundle_tr.properties | 4 +- core/assets/bundles/bundle_uk_UA.properties | 4 +- core/assets/bundles/bundle_vi.properties | 4 +- core/assets/bundles/bundle_zh_CN.properties | 4 +- core/assets/bundles/bundle_zh_TW.properties | 4 +- core/assets/icons/icons.properties | 7 +- core/assets/logicids.dat | Bin 3263 -> 3315 bytes core/src/mindustry/content/Blocks.java | 38 ++++++-- core/src/mindustry/content/Items.java | 24 +++--- core/src/mindustry/content/Liquids.java | 19 +++- core/src/mindustry/content/TechTree.java | 2 +- .../mindustry/entities/comp/BuildingComp.java | 17 ++-- core/src/mindustry/graphics/Drawf.java | 4 +- core/src/mindustry/io/SaveFileReader.java | 3 +- core/src/mindustry/type/Liquid.java | 19 ++++ core/src/mindustry/ui/Bar.java | 24 ++---- core/src/mindustry/world/Block.java | 62 ++++++++------ .../mindustry/world/blocks/defense/Door.java | 4 +- .../world/blocks/defense/Thruster.java | 6 +- .../world/blocks/distribution/Conveyor.java | 6 +- .../blocks/distribution/DirectionBridge.java | 16 ++-- .../distribution/DirectionalUnloader.java | 12 +-- .../world/blocks/distribution/Duct.java | 8 +- .../world/blocks/distribution/DuctRouter.java | 6 +- .../world/blocks/distribution/ItemBridge.java | 6 +- .../blocks/distribution/PayloadRouter.java | 6 +- .../world/blocks/distribution/Sorter.java | 4 +- .../blocks/distribution/StackConveyor.java | 8 +- .../world/blocks/heat/HeatBlock.java | 2 + .../world/blocks/heat/HeatProducer.java | 81 ++---------------- .../world/blocks/liquid/Conduit.java | 8 +- .../world/blocks/payloads/BlockProducer.java | 8 +- .../world/blocks/payloads/PayloadLoader.java | 10 +-- .../blocks/payloads/PayloadMassDriver.java | 10 +-- .../world/blocks/payloads/PayloadSource.java | 8 +- .../world/blocks/power/PowerDiode.java | 6 +- .../world/blocks/power/PowerNode.java | 10 +-- .../world/blocks/production/BeamDrill.java | 6 +- .../world/blocks/production/Drill.java | 8 +- .../blocks/production/GenericCrafter.java | 71 +++++++++++++-- .../world/blocks/production/Pump.java | 13 +++ .../world/blocks/production/WallCrafter.java | 6 +- .../world/blocks/sandbox/ItemSource.java | 4 +- .../world/blocks/sandbox/LiquidSource.java | 4 +- .../world/blocks/storage/Unloader.java | 4 +- .../world/blocks/units/Reconstructor.java | 10 +-- .../world/blocks/units/UnitFactory.java | 8 +- core/src/mindustry/world/draw/DrawBlock.java | 8 ++ .../mindustry/world/draw/DrawHeatOutput.java | 58 +++++++++++++ core/src/mindustry/world/meta/StatValues.java | 8 ++ 86 files changed, 472 insertions(+), 318 deletions(-) rename core/assets-raw/sprites/blocks/liquid/{thermal-pump-liquid.png => impulse-pump-liquid.png} (100%) rename core/assets-raw/sprites/blocks/liquid/{thermal-pump.png => impulse-pump.png} (100%) create mode 100644 core/assets-raw/sprites/blocks/liquid/reinforced-pump-liquid.png create mode 100644 core/assets-raw/sprites/blocks/liquid/reinforced-pump.png create mode 100644 core/assets-raw/sprites/items/item-oxide.png create mode 100644 core/assets-raw/sprites/items/liquid-hydrogen.png create mode 100644 core/assets-raw/sprites/items/liquid-ozone.png create mode 100644 core/src/mindustry/world/draw/DrawHeatOutput.java diff --git a/core/assets-raw/sprites/blocks/liquid/thermal-pump-liquid.png b/core/assets-raw/sprites/blocks/liquid/impulse-pump-liquid.png similarity index 100% rename from core/assets-raw/sprites/blocks/liquid/thermal-pump-liquid.png rename to core/assets-raw/sprites/blocks/liquid/impulse-pump-liquid.png diff --git a/core/assets-raw/sprites/blocks/liquid/thermal-pump.png b/core/assets-raw/sprites/blocks/liquid/impulse-pump.png similarity index 100% rename from core/assets-raw/sprites/blocks/liquid/thermal-pump.png rename to core/assets-raw/sprites/blocks/liquid/impulse-pump.png diff --git a/core/assets-raw/sprites/blocks/liquid/reinforced-pump-liquid.png b/core/assets-raw/sprites/blocks/liquid/reinforced-pump-liquid.png new file mode 100644 index 0000000000000000000000000000000000000000..63d230191d4479fb43bd392212dbd6273125ec4a GIT binary patch literal 210 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=jKx9jP7LeL$-D$|dOTemLn`LH zy>^kS*?@=j!tICu{}+8XYg@1;S&jL8<=TST8QDTWbqov*vn50oi_iV!l6h=W{Pbpg zMU3o*?{N=K-3s0I>cEoa7nD`q6(aR_J^Jj=B|V|$UdyUSliREx+|O|M&bBKPMEv9p zYpJpR5n{41RmetbO|p~De&%!cvYs-qfXy$k_CLv>A;EHa;tLSp)78&qol`;+0KB_U A1^@s6 literal 0 HcmV?d00001 diff --git a/core/assets-raw/sprites/blocks/liquid/reinforced-pump.png b/core/assets-raw/sprites/blocks/liquid/reinforced-pump.png new file mode 100644 index 0000000000000000000000000000000000000000..1f1884f6bbece018023c29bc7b9e44e135643d62 GIT binary patch literal 859 zcmV-h1El?WfQC51-lujQH~NqZ*yH zO$aYuzB-TSf?%273SpYpAUys!{f;j4Q3zgbs(B6qEf9gw2_ULXHBTXM1-L?^EsZJw zT3%F}2*CnydiUo1@cG^>w2EBCMgeGfHBBf46~Hh*LxV7`NkXUC2mmdo^-xdV$ zgD}3c0F3Ygu=35iSqLrwD}*Tm0dRYI>k1SA3ZV?ZgrJ$H9cTprE}s`dx(|>5Nak13 zQ2!EW!T_X%6oS-7GA*^wKxhGAB}Lkx z=CcsC0GRio9T6H^0C*Fx_Z(ht?JVh*)&^q&hAJKo)}3Q%mhL&uy&Oeek9z@Fix@9}w%6mH0}?0zWG$aH zUw%w33SoY49f?`P%7>UQKPKmeK);Iukn*kOk;9y&04xY=WB^zl9&(to1ptL$0M120%ue2En~87B$}uz|zJ+fHp>}qsu%J6aut0z6(NU?EyhGe*}a}uH7!= lIn-_w@|Px#;Ymb6R9J=Wma!GWFbqT;9%C>8b5KG{%_td#IxQ(PM<&P~rUi1AbiyJ9zSgqu zTax{hQd85$>evlSp0l)m=#JExRIq05fiMSJ%~^4lo9tRRnkqKAo?kVF}KXEeL=}EfC01gIEFFAAQ)TqXPWe zdPx#`bk7VR9J=Wl|2puArOTJi*5BRCRBSM&*XuuNIZ+S+prY|S>~5f6ZIwA$iVw} zBLMK%hZVFFmXtF!KEb1poj@ z*E>0JiXqe=XM`oXnb__=9`_q#tqC<3O`xbwqFrD~IhT)v!vI-;76MzW2GQsVfco=k zZ#WZxRGvrF1mLOP0x%uJSBt%fYR#v^qu%RzHYXrGmfTgX0%+5r7M8vd-2(14tXnZE zQwuzwYjh`4lU^ESt|Te4z+Px#{7FPXR9J=Wl|2puArOTJD=qgVn^@X<8c*bDY%NXpBwK2S6=r0aUq(&Tmuw>g z@8gXCz+WF$vQC)hoVoFFNTxN_#gefXL@crzTS3^tUULluIS^$oL9ALo9#7X$b52bF z0D$x5#!eiEl<+4RQHd@l*1O+r*9&8-2{)Hapa>^XFEGtHmrsJD07ZZrf?5oNSo8$I z{rRjnoC`p!$Rp|kh}3TZxQ^kgC0;~WhyCVJAN4%D6VM(@>8dsX)ah^wYu|`wf%F>U zR`kl%g2?BZ+=QVaG { - node(thermalPump, () -> { + node(impulsePump, () -> { }); }); diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index 962a9666f2..75fb1fe866 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -572,6 +572,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, } public void dumpLiquid(Liquid liquid, float scaling){ + dumpLiquid(liquid, scaling, -1); + } + + /** @param outputDir output liquid direction relative to rotation, or -1 to use any direction. */ + public void dumpLiquid(Liquid liquid, float scaling, int outputDir){ int dump = this.cdump; if(liquids.get(liquid) <= 0.0001f) return; @@ -581,6 +586,9 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, for(int i = 0; i < proximity.size; i++){ incrementDump(proximity.size); Building other = proximity.get((i + dump) % proximity.size); + + if(outputDir != -1 && (relativeTo(other) + rotation) % 4 != outputDir) return; + other = other.getLiquidDestination(self(), liquid); if(other != null && other.team == team && other.block.hasLiquids && canDumpLiquid(other, liquid) && other.liquids != null){ @@ -1211,13 +1219,8 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, public void displayBars(Table table){ for(Func bar : block.bars.list()){ - //TODO fix conclusively - try{ - table.add(bar.get(self())).growX(); - table.row(); - }catch(ClassCastException e){ - break; - } + table.add(bar.get(self())).growX(); + table.row(); } } diff --git a/core/src/mindustry/graphics/Drawf.java b/core/src/mindustry/graphics/Drawf.java index e0dd6f27b2..efa7eb10fc 100644 --- a/core/src/mindustry/graphics/Drawf.java +++ b/core/src/mindustry/graphics/Drawf.java @@ -128,13 +128,13 @@ public class Drawf{ } public static void liquid(TextureRegion region, float x, float y, float alpha, Color color, float rotation){ - Draw.color(color, alpha); + Draw.color(color, alpha * color.a); Draw.rect(region, x, y, rotation); Draw.color(); } public static void liquid(TextureRegion region, float x, float y, float alpha, Color color){ - Draw.color(color, alpha); + Draw.color(color, alpha * color.a); Draw.rect(region, x, y); Draw.color(); } diff --git a/core/src/mindustry/io/SaveFileReader.java b/core/src/mindustry/io/SaveFileReader.java index 37f07b3e86..02a5b15756 100644 --- a/core/src/mindustry/io/SaveFileReader.java +++ b/core/src/mindustry/io/SaveFileReader.java @@ -59,7 +59,8 @@ public abstract class SaveFileReader{ "cryofluidmixer", "cryofluid-mixer", "block-forge", "constructor", "block-unloader", "payload-unloader", - "block-loader", "payload-loader" + "block-loader", "payload-loader", + "thermal-pump", "impulse-pump" ); public static final ObjectMap modContentNameMap = ObjectMap.of( diff --git a/core/src/mindustry/type/Liquid.java b/core/src/mindustry/type/Liquid.java index f170cccd92..ce5972c36e 100644 --- a/core/src/mindustry/type/Liquid.java +++ b/core/src/mindustry/type/Liquid.java @@ -14,9 +14,12 @@ import mindustry.world.meta.*; import static mindustry.entities.Puddles.*; +/** A better name for this class would be "fluid", but it's too late for that. */ public class Liquid extends UnlockableContent{ protected static final Rand rand = new Rand(); + /** TODO If true, this fluid is treated as a gas (and does not create puddles) */ + public boolean gas = false; /** Color used in pipes and on the ground. */ public Color color; /** Color of this liquid in gas form. */ @@ -58,6 +61,22 @@ public class Liquid extends UnlockableContent{ this(name, new Color(Color.black)); } + @Override + public void init(){ + super.init(); + + if(gas){ + //always "boils", it's a gas + boilPoint = -1; + //ensure no accidental global mutation + color = color.cpy(); + //all gases are transparent + color.a = 0.5f; + //for gases, gas color is implicitly their color + gasColor = color; + } + } + /** @return true if this liquid will boil in this global environment. */ public boolean willBoil(){ return Attribute.heat.env() >= boilPoint; diff --git a/core/src/mindustry/ui/Bar.java b/core/src/mindustry/ui/Bar.java index 1d566435e4..2e6896cca1 100644 --- a/core/src/mindustry/ui/Bar.java +++ b/core/src/mindustry/ui/Bar.java @@ -30,19 +30,11 @@ public class Bar extends Element{ public Bar(Prov name, Prov color, Floatp fraction){ this.fraction = fraction; - try{ - lastValue = value = Mathf.clamp(fraction.get()); - }catch(Exception e){ //getting the fraction may involve referring to invalid data - lastValue = value = 0f; - } + lastValue = value = Mathf.clamp(fraction.get()); update(() -> { - try{ - this.name = name.get(); - this.blinkColor.set(color.get()); - setColor(color.get()); - }catch(Exception e){ //getting the fraction may involve referring to invalid data - this.name = ""; - } + this.name = name.get(); + this.blinkColor.set(color.get()); + setColor(color.get()); }); } @@ -85,12 +77,8 @@ public class Bar extends Element{ public void draw(){ if(fraction == null) return; - float computed; - try{ - computed = Mathf.clamp(fraction.get()); - }catch(Exception e){ //getting the fraction may involve referring to invalid data - computed = 0f; - } + float computed = Mathf.clamp(fraction.get()); + if(lastValue > computed){ blink = 1f; diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 30b775d1bf..76f20d8090 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -454,10 +454,14 @@ public class Block extends UnlockableContent{ Liquid liquid = consumes.get(ConsumeType.liquid).liquid; current = entity -> liquid; }else{ - current = entity -> entity.liquids == null ? Liquids.water : entity.liquids.current(); + current = entity -> entity.liquids.current(); } - bars.add("liquid", entity -> new Bar(() -> entity.liquids.get(current.get(entity)) <= 0.001f ? Core.bundle.get("bar.liquid") : current.get(entity).localizedName, - () -> current.get(entity).barColor(), () -> entity == null || entity.liquids == null ? 0f : entity.liquids.get(current.get(entity)) / liquidCapacity)); + + bars.add("liquid", entity -> new Bar( + () -> entity.liquids.get(current.get(entity)) <= 0.001f ? Core.bundle.get("bar.liquid") : current.get(entity).localizedName, + () -> current.get(entity).barColor(), + () -> entity.liquids.get(current.get(entity)) / liquidCapacity) + ); } if(hasPower && consumes.hasPower()){ @@ -465,12 +469,20 @@ public class Block extends UnlockableContent{ boolean buffered = cons.buffered; float capacity = cons.capacity; - bars.add("power", entity -> new Bar(() -> buffered ? Core.bundle.format("bar.poweramount", Float.isNaN(entity.power.status * capacity) ? "" : UI.formatAmount((int)(entity.power.status * capacity))) : - Core.bundle.get("bar.power"), () -> Pal.powerBar, () -> Mathf.zero(cons.requestedPower(entity)) && entity.power.graph.getPowerProduced() + entity.power.graph.getBatteryStored() > 0f ? 1f : entity.power.status)); + bars.add("power", entity -> new Bar( + () -> buffered ? Core.bundle.format("bar.poweramount", Float.isNaN(entity.power.status * capacity) ? "" : UI.formatAmount((int)(entity.power.status * capacity))) : + Core.bundle.get("bar.power"), + () -> Pal.powerBar, + () -> Mathf.zero(cons.requestedPower(entity)) && entity.power.graph.getPowerProduced() + entity.power.graph.getBatteryStored() > 0f ? 1f : entity.power.status) + ); } if(hasItems && configurable){ - bars.add("items", entity -> new Bar(() -> Core.bundle.format("bar.items", entity.items.total()), () -> Pal.items, () -> (float)entity.items.total() / itemCapacity)); + bars.add("items", entity -> new Bar( + () -> Core.bundle.format("bar.items", entity.items.total()), + () -> Pal.items, + () -> (float)entity.items.total() / itemCapacity) + ); } if(unitCapModifier != 0){ @@ -515,46 +527,46 @@ public class Block extends UnlockableContent{ } - public void drawPlan(BuildPlan req, Eachable list, boolean valid){ - drawPlan(req, list, valid, 1f); + public void drawPlan(BuildPlan plan, Eachable list, boolean valid){ + drawPlan(plan, list, valid, 1f); } - public void drawPlan(BuildPlan req, Eachable list, boolean valid, float alpha){ + public void drawPlan(BuildPlan plan, Eachable list, boolean valid, float alpha){ Draw.reset(); Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime, 6f, 0.28f)); Draw.alpha(alpha); float prevScale = Draw.scl; - Draw.scl *= req.animScale; - drawRequestRegion(req, list); + Draw.scl *= plan.animScale; + drawRequestRegion(plan, list); Draw.scl = prevScale; Draw.reset(); } - public void drawRequestRegion(BuildPlan req, Eachable list){ - TextureRegion reg = getRequestRegion(req, list); - Draw.rect(reg, req.drawx(), req.drawy(), !rotate ? 0 : req.rotation * 90); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + TextureRegion reg = getRequestRegion(plan, list); + Draw.rect(reg, plan.drawx(), plan.drawy(), !rotate ? 0 : plan.rotation * 90); - if(req.worldContext && player != null && teamRegion != null && teamRegion.found()){ + if(plan.worldContext && player != null && teamRegion != null && teamRegion.found()){ if(teamRegions[player.team().id] == teamRegion) Draw.color(player.team().color); - Draw.rect(teamRegions[player.team().id], req.drawx(), req.drawy()); + Draw.rect(teamRegions[player.team().id], plan.drawx(), plan.drawy()); Draw.color(); } - drawRequestConfig(req, list); + drawRequestConfig(plan, list); } - public TextureRegion getRequestRegion(BuildPlan req, Eachable list){ + public TextureRegion getRequestRegion(BuildPlan plan, Eachable list){ return fullIcon; } - public void drawRequestConfig(BuildPlan req, Eachable list){ + public void drawRequestConfig(BuildPlan plan, Eachable list){ } - public void drawRequestConfigCenter(BuildPlan req, Object content, String region, boolean cross){ + public void drawRequestConfigCenter(BuildPlan plan, Object content, String region, boolean cross){ if(content == null){ if(cross){ - Draw.rect("cross", req.drawx(), req.drawy()); + Draw.rect("cross", plan.drawx(), plan.drawy()); } return; } @@ -562,15 +574,15 @@ public class Block extends UnlockableContent{ if(color == null) return; Draw.color(color); - Draw.rect(region, req.drawx(), req.drawy()); + Draw.rect(region, plan.drawx(), plan.drawy()); Draw.color(); } - public void drawRequestConfigCenter(BuildPlan req, Object content, String region){ - drawRequestConfigCenter(req, content, region, false); + public void drawRequestConfigCenter(BuildPlan plan, Object content, String region){ + drawRequestConfigCenter(plan, content, region, false); } - public void drawRequestConfigTop(BuildPlan req, Eachable list){ + public void drawRequestConfigTop(BuildPlan plan, Eachable list){ } diff --git a/core/src/mindustry/world/blocks/defense/Door.java b/core/src/mindustry/world/blocks/defense/Door.java index 8de012a979..6703029b20 100644 --- a/core/src/mindustry/world/blocks/defense/Door.java +++ b/core/src/mindustry/world/blocks/defense/Door.java @@ -51,8 +51,8 @@ public class Door extends Wall{ } @Override - public TextureRegion getRequestRegion(BuildPlan req, Eachable list){ - return req.config == Boolean.TRUE ? openRegion : region; + public TextureRegion getRequestRegion(BuildPlan plan, Eachable list){ + return plan.config == Boolean.TRUE ? openRegion : region; } public class DoorBuild extends Building{ diff --git a/core/src/mindustry/world/blocks/defense/Thruster.java b/core/src/mindustry/world/blocks/defense/Thruster.java index f015b02b38..934ccc5036 100644 --- a/core/src/mindustry/world/blocks/defense/Thruster.java +++ b/core/src/mindustry/world/blocks/defense/Thruster.java @@ -15,9 +15,9 @@ public class Thruster extends Wall{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - Draw.rect(region, req.drawx(), req.drawy()); - Draw.rect(topRegion, req.drawx(), req.drawy(), req.rotation * 90); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + Draw.rect(region, plan.drawx(), plan.drawy()); + Draw.rect(topRegion, plan.drawx(), plan.drawy(), plan.rotation * 90); } @Override diff --git a/core/src/mindustry/world/blocks/distribution/Conveyor.java b/core/src/mindustry/world/blocks/distribution/Conveyor.java index d91df61d7a..f2acfd661b 100644 --- a/core/src/mindustry/world/blocks/distribution/Conveyor.java +++ b/core/src/mindustry/world/blocks/distribution/Conveyor.java @@ -66,13 +66,13 @@ public class Conveyor extends Block implements Autotiler{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - int[] bits = getTiling(req, list); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + int[] bits = getTiling(plan, list); if(bits == null) return; TextureRegion region = regions[bits[0]][0]; - Draw.rect(region, req.drawx(), req.drawy(), region.width * bits[1] * Draw.scl, region.height * bits[2] * Draw.scl, req.rotation * 90); + Draw.rect(region, plan.drawx(), plan.drawy(), region.width * bits[1] * Draw.scl, region.height * bits[2] * Draw.scl, plan.rotation * 90); } @Override diff --git a/core/src/mindustry/world/blocks/distribution/DirectionBridge.java b/core/src/mindustry/world/blocks/distribution/DirectionBridge.java index d1b26f2072..7addb04d30 100644 --- a/core/src/mindustry/world/blocks/distribution/DirectionBridge.java +++ b/core/src/mindustry/world/blocks/distribution/DirectionBridge.java @@ -47,19 +47,19 @@ public class DirectionBridge extends Block{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - Draw.rect(region, req.drawx(), req.drawy()); - Draw.rect(dirRegion, req.drawx(), req.drawy(), req.rotation * 90); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + Draw.rect(region, plan.drawx(), plan.drawy()); + Draw.rect(dirRegion, plan.drawx(), plan.drawy(), plan.rotation * 90); } @Override - public void drawRequestConfigTop(BuildPlan req, Eachable list){ + public void drawRequestConfigTop(BuildPlan plan, Eachable list){ otherReq = null; otherDst = range; - Point2 d = Geometry.d4(req.rotation); + Point2 d = Geometry.d4(plan.rotation); list.each(other -> { - if(other.block == this && req != other && Mathf.clamp(other.x - req.x, -1, 1) == d.x && Mathf.clamp(other.y - req.y, -1, 1) == d.y){ - int dst = Math.max(Math.abs(other.x - req.x), Math.abs(other.y - req.y)); + if(other.block == this && plan != other && Mathf.clamp(other.x - plan.x, -1, 1) == d.x && Mathf.clamp(other.y - plan.y, -1, 1) == d.y){ + int dst = Math.max(Math.abs(other.x - plan.x), Math.abs(other.y - plan.y)); if(dst <= otherDst){ otherReq = other; otherDst = dst; @@ -68,7 +68,7 @@ public class DirectionBridge extends Block{ }); if(otherReq != null){ - drawBridge(req.rotation, req.drawx(), req.drawy(), otherReq.drawx(), otherReq.drawy(), null); + drawBridge(plan.rotation, plan.drawx(), plan.drawy(), otherReq.drawx(), otherReq.drawy(), null); } } diff --git a/core/src/mindustry/world/blocks/distribution/DirectionalUnloader.java b/core/src/mindustry/world/blocks/distribution/DirectionalUnloader.java index 29cc41a4cd..7a780dd8df 100644 --- a/core/src/mindustry/world/blocks/distribution/DirectionalUnloader.java +++ b/core/src/mindustry/world/blocks/distribution/DirectionalUnloader.java @@ -46,15 +46,15 @@ public class DirectionalUnloader extends Block{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - Draw.rect(region, req.drawx(), req.drawy()); - Draw.rect(topRegion, req.drawx(), req.drawy(), req.rotation * 90); - drawRequestConfig(req, list); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + Draw.rect(region, plan.drawx(), plan.drawy()); + Draw.rect(topRegion, plan.drawx(), plan.drawy(), plan.rotation * 90); + drawRequestConfig(plan, list); } @Override - public void drawRequestConfig(BuildPlan req, Eachable list){ - drawRequestConfigCenter(req, req.config, "duct-unloader-center"); + public void drawRequestConfig(BuildPlan plan, Eachable list){ + drawRequestConfigCenter(plan, plan.config, "duct-unloader-center"); } @Override diff --git a/core/src/mindustry/world/blocks/distribution/Duct.java b/core/src/mindustry/world/blocks/distribution/Duct.java index 8061b2e0dd..215468e316 100644 --- a/core/src/mindustry/world/blocks/distribution/Duct.java +++ b/core/src/mindustry/world/blocks/distribution/Duct.java @@ -50,16 +50,16 @@ public class Duct extends Block implements Autotiler{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - int[] bits = getTiling(req, list); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + int[] bits = getTiling(plan, list); if(bits == null) return; Draw.scl(bits[1], bits[2]); Draw.alpha(0.5f); - Draw.rect(botRegions[bits[0]], req.drawx(), req.drawy(), req.rotation * 90); + Draw.rect(botRegions[bits[0]], plan.drawx(), plan.drawy(), plan.rotation * 90); Draw.color(); - Draw.rect(topRegions[bits[0]], req.drawx(), req.drawy(), req.rotation * 90); + Draw.rect(topRegions[bits[0]], plan.drawx(), plan.drawy(), plan.rotation * 90); Draw.scl(); } diff --git a/core/src/mindustry/world/blocks/distribution/DuctRouter.java b/core/src/mindustry/world/blocks/distribution/DuctRouter.java index d8492bc07e..b04f75afbe 100644 --- a/core/src/mindustry/world/blocks/distribution/DuctRouter.java +++ b/core/src/mindustry/world/blocks/distribution/DuctRouter.java @@ -53,9 +53,9 @@ public class DuctRouter extends Block{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - Draw.rect(region, req.drawx(), req.drawy()); - Draw.rect(topRegion, req.drawx(), req.drawy(), req.rotation * 90); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + Draw.rect(region, plan.drawx(), plan.drawy()); + Draw.rect(topRegion, plan.drawx(), plan.drawy(), plan.rotation * 90); } public class DuctRouterBuild extends Building{ diff --git a/core/src/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/mindustry/world/blocks/distribution/ItemBridge.java index 9be6bb6428..5857438bb7 100644 --- a/core/src/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/mindustry/world/blocks/distribution/ItemBridge.java @@ -61,16 +61,16 @@ public class ItemBridge extends Block{ } @Override - public void drawRequestConfigTop(BuildPlan req, Eachable list){ + public void drawRequestConfigTop(BuildPlan plan, Eachable list){ otherReq = null; list.each(other -> { - if(other.block == this && req != other && req.config instanceof Point2 p && p.equals(other.x - req.x, other.y - req.y)){ + if(other.block == this && plan != other && plan.config instanceof Point2 p && p.equals(other.x - plan.x, other.y - plan.y)){ otherReq = other; } }); if(otherReq != null){ - drawBridge(req, otherReq.drawx(), otherReq.drawy(), 0); + drawBridge(plan, otherReq.drawx(), otherReq.drawy(), 0); } } diff --git a/core/src/mindustry/world/blocks/distribution/PayloadRouter.java b/core/src/mindustry/world/blocks/distribution/PayloadRouter.java index 186e67b6d0..2a42ba8ac0 100644 --- a/core/src/mindustry/world/blocks/distribution/PayloadRouter.java +++ b/core/src/mindustry/world/blocks/distribution/PayloadRouter.java @@ -21,10 +21,10 @@ public class PayloadRouter extends PayloadConveyor{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - super.drawRequestRegion(req, list); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + super.drawRequestRegion(plan, list); - Draw.rect(overRegion, req.drawx(), req.drawy()); + Draw.rect(overRegion, plan.drawx(), plan.drawy()); } public class PayloadRouterBuild extends PayloadConveyorBuild{ diff --git a/core/src/mindustry/world/blocks/distribution/Sorter.java b/core/src/mindustry/world/blocks/distribution/Sorter.java index afe3ce6e7f..e14131dc27 100644 --- a/core/src/mindustry/world/blocks/distribution/Sorter.java +++ b/core/src/mindustry/world/blocks/distribution/Sorter.java @@ -32,8 +32,8 @@ public class Sorter extends Block{ } @Override - public void drawRequestConfig(BuildPlan req, Eachable list){ - drawRequestConfigCenter(req, req.config, "center", true); + public void drawRequestConfig(BuildPlan plan, Eachable list){ + drawRequestConfigCenter(plan, plan.config, "center", true); } @Override diff --git a/core/src/mindustry/world/blocks/distribution/StackConveyor.java b/core/src/mindustry/world/blocks/distribution/StackConveyor.java index 0f7c276553..6f376c7329 100644 --- a/core/src/mindustry/world/blocks/distribution/StackConveyor.java +++ b/core/src/mindustry/world/blocks/distribution/StackConveyor.java @@ -82,17 +82,17 @@ public class StackConveyor extends Block implements Autotiler{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - int[] bits = getTiling(req, list); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + int[] bits = getTiling(plan, list); if(bits == null) return; TextureRegion region = regions[0]; - Draw.rect(region, req.drawx(), req.drawy(), req.rotation * 90); + Draw.rect(region, plan.drawx(), plan.drawy(), plan.rotation * 90); for(int i = 0; i < 4; i++){ if((bits[3] & (1 << i)) == 0){ - Draw.rect(edgeRegion, req.drawx(), req.drawy(), (req.rotation - i) * 90); + Draw.rect(edgeRegion, plan.drawx(), plan.drawy(), (plan.rotation - i) * 90); } } } diff --git a/core/src/mindustry/world/blocks/heat/HeatBlock.java b/core/src/mindustry/world/blocks/heat/HeatBlock.java index 797435e323..665df310de 100644 --- a/core/src/mindustry/world/blocks/heat/HeatBlock.java +++ b/core/src/mindustry/world/blocks/heat/HeatBlock.java @@ -3,4 +3,6 @@ package mindustry.world.blocks.heat; /** Basic interface for any block that produces heat.*/ public interface HeatBlock{ float heat(); + /** @return heat as a fraction of max heat */ + float heatFrac(); } diff --git a/core/src/mindustry/world/blocks/heat/HeatProducer.java b/core/src/mindustry/world/blocks/heat/HeatProducer.java index 7e0cdb6188..6fd1020ee9 100644 --- a/core/src/mindustry/world/blocks/heat/HeatProducer.java +++ b/core/src/mindustry/world/blocks/heat/HeatProducer.java @@ -1,47 +1,28 @@ package mindustry.world.blocks.heat; -import arc.graphics.*; -import arc.graphics.g2d.*; import arc.math.*; -import arc.util.*; import arc.util.io.*; -import mindustry.annotations.Annotations.*; -import mindustry.content.*; -import mindustry.entities.*; -import mindustry.entities.units.*; -import mindustry.gen.*; import mindustry.graphics.*; -import mindustry.logic.*; import mindustry.ui.*; -import mindustry.world.*; import mindustry.world.blocks.power.NuclearReactor.*; -import mindustry.world.meta.*; +import mindustry.world.blocks.production.*; +import mindustry.world.draw.*; -public class HeatProducer extends Block{ +public class HeatProducer extends GenericCrafter{ public float heatOutput = 10f; public float warmupRate = 0.15f; - public float consumeTime = 100; - - public @Load("@-heat") TextureRegion heatRegion; - public @Load("@-glow") TextureRegion glowRegion; - public @Load("@-top1") TextureRegion topRegion1; - public @Load("@-top2") TextureRegion topRegion2; - public Color heatColor = new Color(1f, 0.22f, 0.22f, 0.8f); - public float heatPulse = 0.3f, heatPulseScl = 10f, glowMult = 1.2f; - public Effect consumeEffect = Fx.none; public HeatProducer(String name){ super(name); + drawer = new DrawHeatOutput(); update = solid = rotate = true; canOverdrive = false; } @Override public void setStats(){ - stats.timePeriod = consumeTime; super.setStats(); - stats.add(Stat.productionTime, consumeTime / 60f, StatUnit.seconds); //TODO heat prod stats } @@ -52,64 +33,20 @@ public class HeatProducer extends Block{ bars.add("heat", (NuclearReactorBuild entity) -> new Bar("bar.heat", Pal.lightOrange, () -> entity.heat)); } - @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - Draw.rect(region, req.drawx(), req.drawy()); - Draw.rect(req.rotation > 1 ? topRegion2 : topRegion1, req.drawx(), req.drawy(), req.rotation * 90); - } - - @Override - public TextureRegion[] icons(){ - return new TextureRegion[]{region, topRegion1}; - } - - public class HeatProducerBuild extends Building implements HeatBlock{ + public class HeatProducerBuild extends GenericCrafterBuild implements HeatBlock{ public float heat; - public float progress; @Override public void updateTile(){ - if(consValid()){ - progress += getProgressIncrease(consumeTime); - - if(progress >= 1f){ - consume(); - consumeEffect.at(this); - progress -= 1f; - } - } + super.updateTile(); //heat approaches target at the same speed regardless of efficiency heat = Mathf.approachDelta(heat, heatOutput * efficiency() * Mathf.num(consValid()), warmupRate * delta()); } @Override - public void draw(){ - Draw.rect(region, x, y); - - Draw.rect(rotation > 1 ? topRegion2 : topRegion1, x, y, rotdeg()); - - if(heat > 0){ - Draw.z(Layer.blockAdditive); - Draw.blend(Blending.additive); - Draw.color(heatColor, heat / heatOutput * (heatColor.a * (1f - heatPulse + Mathf.absin(heatPulseScl, heatPulse)))); - Draw.rect(heatRegion, x, y, rotdeg()); - Draw.color(Draw.getColor().mul(glowMult)); - Draw.rect(glowRegion, x, y); - Draw.blend(); - Draw.color(); - } - } - - @Override - public double sense(LAccess sensor){ - if(sensor == LAccess.progress) return Mathf.clamp(progress); - return super.sense(sensor); - } - - @Override - public boolean shouldAmbientSound(){ - return cons.valid(); + public float heatFrac(){ + return heat / heatOutput; } @Override @@ -120,14 +57,12 @@ public class HeatProducer extends Block{ @Override public void write(Writes write){ super.write(write); - write.f(progress); write.f(heat); } @Override public void read(Reads read, byte revision){ super.read(read, revision); - progress = read.f(); heat = read.f(); } } diff --git a/core/src/mindustry/world/blocks/liquid/Conduit.java b/core/src/mindustry/world/blocks/liquid/Conduit.java index 7fc599fca7..2944196b37 100644 --- a/core/src/mindustry/world/blocks/liquid/Conduit.java +++ b/core/src/mindustry/world/blocks/liquid/Conduit.java @@ -52,17 +52,17 @@ public class Conduit extends LiquidBlock implements Autotiler{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - int[] bits = getTiling(req, list); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + int[] bits = getTiling(plan, list); if(bits == null) return; Draw.scl(bits[1], bits[2]); Draw.color(botColor); Draw.alpha(0.5f); - Draw.rect(botRegions[bits[0]], req.drawx(), req.drawy(), req.rotation * 90); + Draw.rect(botRegions[bits[0]], plan.drawx(), plan.drawy(), plan.rotation * 90); Draw.color(); - Draw.rect(topRegions[bits[0]], req.drawx(), req.drawy(), req.rotation * 90); + Draw.rect(topRegions[bits[0]], plan.drawx(), plan.drawy(), plan.rotation * 90); Draw.scl(); } diff --git a/core/src/mindustry/world/blocks/payloads/BlockProducer.java b/core/src/mindustry/world/blocks/payloads/BlockProducer.java index 43da658451..53f21612c4 100644 --- a/core/src/mindustry/world/blocks/payloads/BlockProducer.java +++ b/core/src/mindustry/world/blocks/payloads/BlockProducer.java @@ -39,10 +39,10 @@ public abstract class BlockProducer extends PayloadBlock{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - Draw.rect(region, req.drawx(), req.drawy()); - Draw.rect(outRegion, req.drawx(), req.drawy(), req.rotation * 90); - Draw.rect(topRegion, req.drawx(), req.drawy()); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + Draw.rect(region, plan.drawx(), plan.drawy()); + Draw.rect(outRegion, plan.drawx(), plan.drawy(), plan.rotation * 90); + Draw.rect(topRegion, plan.drawx(), plan.drawy()); } @Override diff --git a/core/src/mindustry/world/blocks/payloads/PayloadLoader.java b/core/src/mindustry/world/blocks/payloads/PayloadLoader.java index 6f34af5b61..4a97cce600 100644 --- a/core/src/mindustry/world/blocks/payloads/PayloadLoader.java +++ b/core/src/mindustry/world/blocks/payloads/PayloadLoader.java @@ -51,11 +51,11 @@ public class PayloadLoader extends PayloadBlock{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - Draw.rect(region, req.drawx(), req.drawy()); - Draw.rect(inRegion, req.drawx(), req.drawy(), req.rotation * 90); - Draw.rect(outRegion, req.drawx(), req.drawy(), req.rotation * 90); - Draw.rect(topRegion, req.drawx(), req.drawy()); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + Draw.rect(region, plan.drawx(), plan.drawy()); + Draw.rect(inRegion, plan.drawx(), plan.drawy(), plan.rotation * 90); + Draw.rect(outRegion, plan.drawx(), plan.drawy(), plan.rotation * 90); + Draw.rect(topRegion, plan.drawx(), plan.drawy()); } public class PayloadLoaderBuild extends PayloadBlockBuild{ diff --git a/core/src/mindustry/world/blocks/payloads/PayloadMassDriver.java b/core/src/mindustry/world/blocks/payloads/PayloadMassDriver.java index 41dffd0279..091a813a44 100644 --- a/core/src/mindustry/world/blocks/payloads/PayloadMassDriver.java +++ b/core/src/mindustry/world/blocks/payloads/PayloadMassDriver.java @@ -87,11 +87,11 @@ public class PayloadMassDriver extends PayloadBlock{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - Draw.rect(baseRegion, req.drawx(), req.drawy()); - Draw.rect(topRegion, req.drawx(), req.drawy()); - Draw.rect(outRegion, req.drawx(), req.drawy(), req.rotation * 90); - Draw.rect(region, req.drawx(), req.drawy()); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + Draw.rect(baseRegion, plan.drawx(), plan.drawy()); + Draw.rect(topRegion, plan.drawx(), plan.drawy()); + Draw.rect(outRegion, plan.drawx(), plan.drawy(), plan.rotation * 90); + Draw.rect(region, plan.drawx(), plan.drawy()); } @Override diff --git a/core/src/mindustry/world/blocks/payloads/PayloadSource.java b/core/src/mindustry/world/blocks/payloads/PayloadSource.java index 03fc0eb320..bacd26f287 100644 --- a/core/src/mindustry/world/blocks/payloads/PayloadSource.java +++ b/core/src/mindustry/world/blocks/payloads/PayloadSource.java @@ -64,10 +64,10 @@ public class PayloadSource extends PayloadBlock{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - Draw.rect(region, req.drawx(), req.drawy()); - Draw.rect(outRegion, req.drawx(), req.drawy(), req.rotation * 90); - Draw.rect(topRegion, req.drawx(), req.drawy()); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + Draw.rect(region, plan.drawx(), plan.drawy()); + Draw.rect(outRegion, plan.drawx(), plan.drawy(), plan.rotation * 90); + Draw.rect(topRegion, plan.drawx(), plan.drawy()); } public boolean canProduce(Block b){ diff --git a/core/src/mindustry/world/blocks/power/PowerDiode.java b/core/src/mindustry/world/blocks/power/PowerDiode.java index 20db770b82..558850c1ae 100644 --- a/core/src/mindustry/world/blocks/power/PowerDiode.java +++ b/core/src/mindustry/world/blocks/power/PowerDiode.java @@ -35,9 +35,9 @@ public class PowerDiode extends Block{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - Draw.rect(fullIcon, req.drawx(), req.drawy()); - Draw.rect(arrow, req.drawx(), req.drawy(), !rotate ? 0 : req.rotation * 90); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + Draw.rect(fullIcon, plan.drawx(), plan.drawy()); + Draw.rect(arrow, plan.drawx(), plan.drawy(), !rotate ? 0 : plan.rotation * 90); } // battery % of the graph on either side, defaults to zero diff --git a/core/src/mindustry/world/blocks/power/PowerNode.java b/core/src/mindustry/world/blocks/power/PowerNode.java index 4e5a5c1598..fd310c4b49 100644 --- a/core/src/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/mindustry/world/blocks/power/PowerNode.java @@ -302,23 +302,23 @@ public class PowerNode extends PowerBlock{ } @Override - public void drawRequestConfigTop(BuildPlan req, Eachable list){ - if(req.config instanceof Point2[] ps){ + public void drawRequestConfigTop(BuildPlan plan, Eachable list){ + if(plan.config instanceof Point2[] ps){ setupColor(1f); for(Point2 point : ps){ - int px = req.x + point.x, py = req.y + point.y; + int px = plan.x + point.x, py = plan.y + point.y; otherReq = null; list.each(other -> { if(other.block != null && (px >= other.x - ((other.block.size-1)/2) && py >= other.y - ((other.block.size-1)/2) && px <= other.x + other.block.size/2 && py <= other.y + other.block.size/2) - && other != req && other.block.hasPower){ + && other != plan && other.block.hasPower){ otherReq = other; } }); if(otherReq == null || otherReq.block == null) continue; - drawLaser(player == null ? Team.sharded : player.team(), req.drawx(), req.drawy(), otherReq.drawx(), otherReq.drawy(), size, otherReq.block.size); + drawLaser(player == null ? Team.sharded : player.team(), plan.drawx(), plan.drawy(), otherReq.drawx(), otherReq.drawy(), size, otherReq.block.size); } Draw.color(); } diff --git a/core/src/mindustry/world/blocks/production/BeamDrill.java b/core/src/mindustry/world/blocks/production/BeamDrill.java index 226b776137..33759c1de0 100644 --- a/core/src/mindustry/world/blocks/production/BeamDrill.java +++ b/core/src/mindustry/world/blocks/production/BeamDrill.java @@ -71,9 +71,9 @@ public class BeamDrill extends Block{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - Draw.rect(region, req.drawx(), req.drawy()); - Draw.rect(topRegion, req.drawx(), req.drawy(), req.rotation * 90); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + Draw.rect(region, plan.drawx(), plan.drawy()); + Draw.rect(topRegion, plan.drawx(), plan.drawy(), plan.rotation * 90); } @Override diff --git a/core/src/mindustry/world/blocks/production/Drill.java b/core/src/mindustry/world/blocks/production/Drill.java index 6db1bee899..c7795a853e 100644 --- a/core/src/mindustry/world/blocks/production/Drill.java +++ b/core/src/mindustry/world/blocks/production/Drill.java @@ -82,16 +82,16 @@ public class Drill extends Block{ } @Override - public void drawRequestConfigTop(BuildPlan req, Eachable list){ - if(!req.worldContext) return; - Tile tile = req.tile(); + public void drawRequestConfigTop(BuildPlan plan, Eachable list){ + if(!plan.worldContext) return; + Tile tile = plan.tile(); if(tile == null) return; countOre(tile); if(returnItem == null || !drawMineItem) return; Draw.color(returnItem.color); - Draw.rect(itemRegion, req.drawx(), req.drawy()); + Draw.rect(itemRegion, plan.drawx(), plan.drawy()); Draw.color(); } diff --git a/core/src/mindustry/world/blocks/production/GenericCrafter.java b/core/src/mindustry/world/blocks/production/GenericCrafter.java index aea5700c02..aae3c984b9 100644 --- a/core/src/mindustry/world/blocks/production/GenericCrafter.java +++ b/core/src/mindustry/world/blocks/production/GenericCrafter.java @@ -7,9 +7,11 @@ import arc.util.*; import arc.util.io.*; import mindustry.content.*; import mindustry.entities.*; +import mindustry.entities.units.*; import mindustry.gen.*; import mindustry.logic.*; import mindustry.type.*; +import mindustry.ui.*; import mindustry.world.*; import mindustry.world.draw.*; import mindustry.world.meta.*; @@ -19,7 +21,13 @@ public class GenericCrafter extends Block{ public @Nullable ItemStack outputItem; /** Overwrites outputItem if not null. */ public @Nullable ItemStack[] outputItems; + + /** Written to outputLiquids as a single-element array if outputLiquids is null. */ public @Nullable LiquidStack outputLiquid; + /** Overwrites outputLiquid if not null. */ + public @Nullable LiquidStack[] outputLiquids; + /** Liquid output directions, specified in the same order as outputLiquids. Use -1 to dump in every direction. Rotations are relative to block. */ + public int[] liquidOutputDirections = {-1}; public float craftTime = 80; public Effect craftEffect = Fx.none; @@ -52,8 +60,27 @@ public class GenericCrafter extends Block{ stats.add(Stat.output, StatValues.items(craftTime, outputItems)); } - if(outputLiquid != null){ - stats.add(Stat.output, outputLiquid.liquid, outputLiquid.amount * (60f / craftTime), true); + if(outputLiquids != null){ + stats.add(Stat.output, StatValues.liquids(craftTime, outputLiquids)); + } + } + + @Override + public void setBars(){ + super.setBars(); + + //set up liquid bars for multiple liquid outputs; TODO multiple inputs not yet supported due to inherent complexity + //TODO this will currently screw up input display if input liquids are available + if(outputLiquids != null && outputLiquids.length > 1){ + bars.remove("liquid"); + + for(var stack : outputLiquids){ + bars.add("liquid-" + stack.liquid.name, entity -> new Bar( + () -> stack.liquid.localizedName, + () -> stack.liquid.barColor(), + () -> entity.liquids.get(stack.liquid) / liquidCapacity) + ); + } } } @@ -70,9 +97,21 @@ public class GenericCrafter extends Block{ if(outputItems == null && outputItem != null){ outputItems = new ItemStack[]{outputItem}; } + if(outputLiquids == null && outputLiquid != null){ + outputLiquids = new LiquidStack[]{outputLiquid}; + } super.init(); } + public void drawPlanBase(BuildPlan req, Eachable list){ + super.drawRequestRegion(req, list); + } + + @Override + public void drawRequestRegion(BuildPlan plan, Eachable list){ + drawer.drawPlan(this, plan, list); + } + @Override public TextureRegion[] icons(){ return drawer.icons(this); @@ -102,13 +141,21 @@ public class GenericCrafter extends Block{ @Override public boolean shouldConsume(){ if(outputItems != null){ - for(ItemStack output : outputItems){ + for(var output : outputItems){ if(items.get(output.item) + output.amount > itemCapacity){ return false; } } } - return (outputLiquid == null || !(liquids.get(outputLiquid.liquid) >= liquidCapacity - 0.001f)) && enabled; + if(outputLiquids != null){ + for(var output : outputLiquids){ + if(liquids.get(output.liquid) >= liquidCapacity - 0.001f){ + return false; + } + } + } + + return enabled; } @Override @@ -141,15 +188,17 @@ public class GenericCrafter extends Block{ consume(); if(outputItems != null){ - for(ItemStack output : outputItems){ + for(var output : outputItems){ for(int i = 0; i < output.amount; i++){ offload(output.item); } } } - if(outputLiquid != null){ - handleLiquid(this, outputLiquid.liquid, outputLiquid.amount); + if(outputLiquids != null){ + for(var output : outputLiquids){ + handleLiquid(this, output.liquid, output.amount); + } } craftEffect.at(x, y); @@ -163,8 +212,12 @@ public class GenericCrafter extends Block{ } } - if(outputLiquid != null){ - dumpLiquid(outputLiquid.liquid); + if(outputLiquids != null){ + for(int i = 0; i < outputLiquids.length; i++){ + int dir = liquidOutputDirections.length > i ? liquidOutputDirections[i] : -1; + + dumpLiquid(outputLiquids[i].liquid, 2f, dir); + } } } diff --git a/core/src/mindustry/world/blocks/production/Pump.java b/core/src/mindustry/world/blocks/production/Pump.java index f18b0c7640..7d759448c2 100644 --- a/core/src/mindustry/world/blocks/production/Pump.java +++ b/core/src/mindustry/world/blocks/production/Pump.java @@ -15,6 +15,8 @@ import static mindustry.Vars.*; public class Pump extends LiquidBlock{ /** Pump amount per tile. */ public float pumpAmount = 0.2f; + /** Interval in-between item consumptions, if applicable. */ + public float consumeTime = 60f * 5f; public Pump(String name){ super(name); @@ -41,6 +43,10 @@ public class Pump extends LiquidBlock{ for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){ if(canPump(other)){ + if(liquidDrop != null && other.floor().liquidDrop != liquidDrop){ + liquidDrop = null; + break; + } liquidDrop = other.floor().liquidDrop; amount += other.floor().liquidMultiplier; } @@ -81,6 +87,7 @@ public class Pump extends LiquidBlock{ } public class PumpBuild extends LiquidBuild{ + public float consTimer; public float amount = 0f; public Liquid liquidDrop = null; @@ -121,6 +128,12 @@ public class Pump extends LiquidBlock{ if(consValid() && liquidDrop != null){ float maxPump = Math.min(liquidCapacity - liquids.total(), amount * pumpAmount * edelta()); liquids.add(liquidDrop, maxPump); + + //does nothing for most pumps, as those do not require items. + if((consTimer += delta()) >= consumeTime){ + consume(); + consumeTime = 0f; + } } dumpLiquid(liquids.current()); diff --git a/core/src/mindustry/world/blocks/production/WallCrafter.java b/core/src/mindustry/world/blocks/production/WallCrafter.java index c93ea43c31..da13ed5419 100644 --- a/core/src/mindustry/world/blocks/production/WallCrafter.java +++ b/core/src/mindustry/world/blocks/production/WallCrafter.java @@ -81,9 +81,9 @@ public class WallCrafter extends Block{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - Draw.rect(region, req.drawx(), req.drawy()); - Draw.rect(topRegion, req.drawx(), req.drawy(), req.rotation * 90); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + Draw.rect(region, plan.drawx(), plan.drawy()); + Draw.rect(topRegion, plan.drawx(), plan.drawy(), plan.rotation * 90); } @Override diff --git a/core/src/mindustry/world/blocks/sandbox/ItemSource.java b/core/src/mindustry/world/blocks/sandbox/ItemSource.java index 3a86cf01f5..c203b359b6 100644 --- a/core/src/mindustry/world/blocks/sandbox/ItemSource.java +++ b/core/src/mindustry/world/blocks/sandbox/ItemSource.java @@ -45,8 +45,8 @@ public class ItemSource extends Block{ } @Override - public void drawRequestConfig(BuildPlan req, Eachable list){ - drawRequestConfigCenter(req, req.config, "center", true); + public void drawRequestConfig(BuildPlan plan, Eachable list){ + drawRequestConfigCenter(plan, plan.config, "center", true); } @Override diff --git a/core/src/mindustry/world/blocks/sandbox/LiquidSource.java b/core/src/mindustry/world/blocks/sandbox/LiquidSource.java index ff42509efb..4a10160a4b 100644 --- a/core/src/mindustry/world/blocks/sandbox/LiquidSource.java +++ b/core/src/mindustry/world/blocks/sandbox/LiquidSource.java @@ -41,8 +41,8 @@ public class LiquidSource extends Block{ } @Override - public void drawRequestConfig(BuildPlan req, Eachable list){ - drawRequestConfigCenter(req, req.config, "center", true); + public void drawRequestConfig(BuildPlan plan, Eachable list){ + drawRequestConfigCenter(plan, plan.config, "center", true); } public class LiquidSourceBuild extends Building{ diff --git a/core/src/mindustry/world/blocks/storage/Unloader.java b/core/src/mindustry/world/blocks/storage/Unloader.java index eae61826d3..7eb76243af 100644 --- a/core/src/mindustry/world/blocks/storage/Unloader.java +++ b/core/src/mindustry/world/blocks/storage/Unloader.java @@ -44,8 +44,8 @@ public class Unloader extends Block{ } @Override - public void drawRequestConfig(BuildPlan req, Eachable list){ - drawRequestConfigCenter(req, req.config, "unloader-center"); + public void drawRequestConfig(BuildPlan plan, Eachable list){ + drawRequestConfigCenter(plan, plan.config, "unloader-center"); } @Override diff --git a/core/src/mindustry/world/blocks/units/Reconstructor.java b/core/src/mindustry/world/blocks/units/Reconstructor.java index 22a6155998..c6e03236a8 100644 --- a/core/src/mindustry/world/blocks/units/Reconstructor.java +++ b/core/src/mindustry/world/blocks/units/Reconstructor.java @@ -32,11 +32,11 @@ public class Reconstructor extends UnitBlock{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - Draw.rect(region, req.drawx(), req.drawy()); - Draw.rect(inRegion, req.drawx(), req.drawy(), req.rotation * 90); - Draw.rect(outRegion, req.drawx(), req.drawy(), req.rotation * 90); - Draw.rect(topRegion, req.drawx(), req.drawy()); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + Draw.rect(region, plan.drawx(), plan.drawy()); + Draw.rect(inRegion, plan.drawx(), plan.drawy(), plan.rotation * 90); + Draw.rect(outRegion, plan.drawx(), plan.drawy(), plan.rotation * 90); + Draw.rect(topRegion, plan.drawx(), plan.drawy()); } @Override diff --git a/core/src/mindustry/world/blocks/units/UnitFactory.java b/core/src/mindustry/world/blocks/units/UnitFactory.java index d0295fc36b..de257a693b 100644 --- a/core/src/mindustry/world/blocks/units/UnitFactory.java +++ b/core/src/mindustry/world/blocks/units/UnitFactory.java @@ -116,10 +116,10 @@ public class UnitFactory extends UnitBlock{ } @Override - public void drawRequestRegion(BuildPlan req, Eachable list){ - Draw.rect(region, req.drawx(), req.drawy()); - Draw.rect(outRegion, req.drawx(), req.drawy(), req.rotation * 90); - Draw.rect(topRegion, req.drawx(), req.drawy()); + public void drawRequestRegion(BuildPlan plan, Eachable list){ + Draw.rect(region, plan.drawx(), plan.drawy()); + Draw.rect(outRegion, plan.drawx(), plan.drawy(), plan.rotation * 90); + Draw.rect(topRegion, plan.drawx(), plan.drawy()); } public static class UnitPlan{ diff --git a/core/src/mindustry/world/draw/DrawBlock.java b/core/src/mindustry/world/draw/DrawBlock.java index 2961cab669..e769c1585f 100644 --- a/core/src/mindustry/world/draw/DrawBlock.java +++ b/core/src/mindustry/world/draw/DrawBlock.java @@ -2,7 +2,10 @@ package mindustry.world.draw; import arc.graphics.g2d.*; import arc.math.*; +import arc.util.*; +import mindustry.entities.units.*; import mindustry.world.*; +import mindustry.world.blocks.production.*; import mindustry.world.blocks.production.GenericCrafter.*; /** An implementation of custom rendering behavior for a crafter block. @@ -20,6 +23,11 @@ public class DrawBlock{ } + /** Draws the planned version of this block. */ + public void drawPlan(GenericCrafter crafter, BuildPlan plan, Eachable list){ + crafter.drawPlanBase(plan, list); + } + /** Load any relevant texture regions. */ public void load(Block block){ diff --git a/core/src/mindustry/world/draw/DrawHeatOutput.java b/core/src/mindustry/world/draw/DrawHeatOutput.java new file mode 100644 index 0000000000..1a8bf20e6d --- /dev/null +++ b/core/src/mindustry/world/draw/DrawHeatOutput.java @@ -0,0 +1,58 @@ +package mindustry.world.draw; + +import arc.*; +import arc.graphics.*; +import arc.graphics.g2d.*; +import arc.math.*; +import arc.util.*; +import mindustry.entities.units.*; +import mindustry.graphics.*; +import mindustry.world.*; +import mindustry.world.blocks.heat.*; +import mindustry.world.blocks.production.*; +import mindustry.world.blocks.production.GenericCrafter.*; + +public class DrawHeatOutput extends DrawBlock{ + public TextureRegion heat, glow, top1, top2; + + public Color heatColor = new Color(1f, 0.22f, 0.22f, 0.8f); + public float heatPulse = 0.3f, heatPulseScl = 10f, glowMult = 1.2f; + + @Override + public void draw(GenericCrafterBuild build){ + Draw.rect(build.block.region, build.x, build.y); + + Draw.rect(build.rotation > 1 ? top2 : top1, build.x, build.y, build.rotdeg()); + + if(build instanceof HeatBlock heater && heater.heat() > 0){ + Draw.z(Layer.blockAdditive); + Draw.blend(Blending.additive); + Draw.color(heatColor, heater.heatFrac() * (heatColor.a * (1f - heatPulse + Mathf.absin(heatPulseScl, heatPulse)))); + Draw.rect(heat, build.x, build.y, build.rotdeg()); + Draw.color(Draw.getColor().mul(glowMult)); + Draw.rect(glow, build.x, build.y); + Draw.blend(); + Draw.color(); + } + } + + @Override + public void drawPlan(GenericCrafter block, BuildPlan plan, Eachable list){ + Draw.rect(block.region, plan.drawx(), plan.drawy()); + Draw.rect(plan.rotation > 1 ? top2 : top1, plan.drawx(), plan.drawy(), plan.rotation * 90); + } + + @Override + public void load(Block block){ + heat = Core.atlas.find(block.name + "-heat"); + glow = Core.atlas.find(block.name + "-glow"); + top1 = Core.atlas.find(block.name + "-top1"); + top2 = Core.atlas.find(block.name + "-top2"); + } + + @Override + public TextureRegion[] icons(Block block){ + return new TextureRegion[]{block.region, top1}; + } + +} diff --git a/core/src/mindustry/world/meta/StatValues.java b/core/src/mindustry/world/meta/StatValues.java index ba07d8e19d..af071b3f06 100644 --- a/core/src/mindustry/world/meta/StatValues.java +++ b/core/src/mindustry/world/meta/StatValues.java @@ -61,6 +61,14 @@ public class StatValues{ }; } + public static StatValue liquids(float timePeriod, LiquidStack... stacks){ + return table -> { + for(var stack : stacks){ + table.add(new LiquidDisplay(stack.liquid, stack.amount * (60f / timePeriod), true)).padRight(5); + } + }; + } + public static StatValue items(ItemStack... stacks){ return items(true, stacks); }