diff --git a/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java b/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java index 75bd3bd578..c0c9e240cf 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java @@ -120,7 +120,7 @@ public class ItemLiquidGenerator extends PowerGenerator{ float maximumPossible = maxLiquidGenerate * calculationDelta; float used = Math.min(entity.liquids.get(liquid) * calculationDelta, maximumPossible); - entity.liquids.remove(liquid, used); + entity.liquids.remove(liquid, used * entity.power.graph.getUsageFraction()); entity.productionEfficiency = baseLiquidEfficiency * used / maximumPossible; if(used > 0.001f && Mathf.chance(0.05 * entity.delta())){ @@ -137,7 +137,7 @@ public class ItemLiquidGenerator extends PowerGenerator{ } if(entity.generateTime > 0f){ - entity.generateTime -= Math.min(1f / itemDuration * entity.delta(), entity.generateTime); + entity.generateTime -= Math.min(1f / itemDuration * entity.delta() * entity.power.graph.getUsageFraction(), entity.generateTime); if(randomlyExplode && state.rules.reactorExplosions && Mathf.chance(entity.delta() * 0.06 * Mathf.clamp(entity.explosiveness - 0.5f))){ //this block is run last so that in the event of a block destruction, no code relies on the block type diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java index d0d1a80425..0c217d1fc2 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java @@ -19,7 +19,7 @@ public class PowerGraph{ private final ObjectSet all = new ObjectSet<>(); private final WindowedMean powerBalance = new WindowedMean(60); - private float lastPowerProduced, lastPowerNeeded; + private float lastPowerProduced, lastPowerNeeded, lastUsageFraction; private long lastFrameUpdated = -1; private final int graphID; @@ -54,6 +54,10 @@ public class PowerGraph{ return Mathf.clamp(lastPowerProduced / lastPowerNeeded); } + public float getUsageFraction(){ + return lastUsageFraction; + } + public float getPowerProduced(){ float powerProduced = 0f; for(Tile producer : producers){ @@ -180,7 +184,7 @@ public class PowerGraph{ tile.entity.power.status = 1f; } - lastPowerNeeded = lastPowerProduced = 1f; + lastPowerNeeded = lastPowerProduced = lastUsageFraction = 1f; return; } @@ -188,6 +192,7 @@ public class PowerGraph{ float powerNeeded = getPowerNeeded(); float powerProduced = getPowerProduced(); + float rawProduced = powerProduced; lastPowerNeeded = powerNeeded; lastPowerProduced = powerProduced; @@ -208,6 +213,12 @@ public class PowerGraph{ } powerBalance.addValue((lastPowerProduced - lastPowerNeeded) / Time.delta()); + + //overproducing: 10 / 20 = 0.5 + //underproducing: 20 / 10 = 2 -> clamp -> 1.0 + //nothing being produced: 20 / 0 -> 1.0 + //nothing being consumed: 0 / 20 -> 0.0 + lastUsageFraction = Mathf.zero(rawProduced) ? 1f : Mathf.clamp(powerNeeded / rawProduced); } public void add(PowerGraph graph){