From 2927348a6caab5cfa955197321150fff73ab84e4 Mon Sep 17 00:00:00 2001 From: Slava0135 <40753025+Slava0135@users.noreply.github.com> Date: Sun, 10 Jan 2021 23:46:29 +0300 Subject: [PATCH] power info fixes (#4303) * power info fixes * a better solution * one little detail --- .../mindustry/world/blocks/power/PowerDiode.java | 4 ++-- .../mindustry/world/blocks/power/PowerGraph.java | 14 +++++++++++++- .../mindustry/world/blocks/power/PowerNode.java | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/core/src/mindustry/world/blocks/power/PowerDiode.java b/core/src/mindustry/world/blocks/power/PowerDiode.java index 75f589eabd..03892d1c54 100644 --- a/core/src/mindustry/world/blocks/power/PowerDiode.java +++ b/core/src/mindustry/world/blocks/power/PowerDiode.java @@ -71,8 +71,8 @@ public class PowerDiode extends Block{ // prevent sending more than the front can handle amount = Mathf.clamp(amount, 0, frontGraph.getTotalBatteryCapacity() * (1 - frontStored)); - backGraph.useBatteries(amount); - frontGraph.chargeBatteries(amount); + backGraph.transferPower(-amount); + frontGraph.transferPower(amount); } } } diff --git a/core/src/mindustry/world/blocks/power/PowerGraph.java b/core/src/mindustry/world/blocks/power/PowerGraph.java index 8c79b63804..03aa029f19 100644 --- a/core/src/mindustry/world/blocks/power/PowerGraph.java +++ b/core/src/mindustry/world/blocks/power/PowerGraph.java @@ -21,6 +21,8 @@ public class PowerGraph{ private final WindowedMean powerBalance = new WindowedMean(60); private float lastPowerProduced, lastPowerNeeded, lastPowerStored; private float lastScaledPowerIn, lastScaledPowerOut, lastCapacity; + //diodes workaround for correct energy production info + private float energyDelta = 0f; private long lastFrameUpdated = -1; private final int graphID; @@ -62,6 +64,15 @@ public class PowerGraph{ return lastPowerStored; } + public void transferPower(float amount){ + if(amount > 0){ + chargeBatteries(amount); + }else{ + useBatteries(-amount); + } + energyDelta += amount; + } + public float getSatisfaction(){ if(Mathf.zero(lastPowerProduced)){ return 0f; @@ -218,7 +229,8 @@ public class PowerGraph{ lastCapacity = getTotalBatteryCapacity(); lastPowerStored = getBatteryStored(); - powerBalance.add((lastPowerProduced - lastPowerNeeded) / Time.delta); + powerBalance.add((lastPowerProduced - lastPowerNeeded + energyDelta) / Time.delta); + energyDelta = 0f; if(!(consumers.size == 0 && producers.size == 0 && batteries.size == 0)){ diff --git a/core/src/mindustry/world/blocks/power/PowerNode.java b/core/src/mindustry/world/blocks/power/PowerNode.java index 1e77e2b41d..43c292e5b0 100644 --- a/core/src/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/mindustry/world/blocks/power/PowerNode.java @@ -107,7 +107,7 @@ public class PowerNode extends PowerBlock{ super.setBars(); bars.add("power", entity -> new Bar(() -> Core.bundle.format("bar.powerbalance", - ((entity.power.graph.getPowerBalance() >= 0 ? "+" : "") + Strings.fixed(entity.power.graph.getPowerBalance() * 60, 1))), + ((entity.power.graph.getPowerBalance() >= 0 ? "+" : "") + UI.formatAmount((int)(entity.power.graph.getPowerBalance() * 60)))), () -> Pal.powerBar, () -> Mathf.clamp(entity.power.graph.getLastPowerProduced() / entity.power.graph.getLastPowerNeeded())));