mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-10 02:37:12 +07:00
power info fixes (#4303)
* power info fixes * a better solution * one little detail
This commit is contained in:
parent
96c8e0f415
commit
2927348a6c
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)){
|
||||
|
||||
|
@ -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())));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user