From 0c14854519b62cf11a792b9acd1f86605cd3317e Mon Sep 17 00:00:00 2001 From: Patrick 'Quezler' Mounier Date: Thu, 31 Oct 2019 20:41:48 +0100 Subject: [PATCH] Stash --- .../world/blocks/power/PowerDiode.java | 46 ++++++++++--------- .../world/blocks/power/PowerGraph.java | 7 ++- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerDiode.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerDiode.java index fe89f0b7e8..55c81a800e 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerDiode.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerDiode.java @@ -31,28 +31,30 @@ public class PowerDiode extends Block{ if(!back.block().hasPower || !front.block().hasPower) return; PowerGraph backGraph = back.entity.power.graph; PowerGraph frontGraph = front.entity.power.graph; - if(backGraph == frontGraph) return; - // skip if the receiving graph is already full - if(frontGraph.getBatteryStored() == frontGraph.getTotalBatteryCapacity()) return; - - // half the difference - float send = Mathf.clamp((backGraph.getBatteryStored() - frontGraph.getBatteryStored()) / 2, 0f, Integer.MAX_VALUE); - - // send all overflow if all batteries of the sending graph are full - if(backGraph.getBatteryStored() == backGraph.getTotalBatteryCapacity()){ - send += backGraph.getLastPowerProduced() - backGraph.getPowerNeeded(); - } - - // limit offering to space available - send = Mathf.clamp(send, 0f, frontGraph.getTotalBatteryCapacity() - frontGraph.getBatteryStored()); - - // limit to sendable power - send = Mathf.clamp(send, 0f, backGraph.getBatteryStored()); - - if (send == 0f) return; - backGraph.useBatteries(send); - frontGraph.chargeBatteries(send); +// backGraph +// if(backGraph == frontGraph) return; +// +// // skip if the receiving graph is already full +// if(frontGraph.getBatteryStored() == frontGraph.getTotalBatteryCapacity()) return; +// +// // half the difference +// float send = Mathf.clamp((backGraph.getBatteryStored() - frontGraph.getBatteryStored()) / 2, 0f, Integer.MAX_VALUE); +// +// // send all overflow if all batteries of the sending graph are full +// if(backGraph.getBatteryStored() == backGraph.getTotalBatteryCapacity()){ +// send += backGraph.getLastPowerProduced() - backGraph.getPowerNeeded(); +// } +// +// // limit offering to space available +// send = Mathf.clamp(send, 0f, frontGraph.getTotalBatteryCapacity() - frontGraph.getBatteryStored()); +// +// // limit to sendable power +// send = Mathf.clamp(send, 0f, backGraph.getBatteryStored()); +// +// if (send == 0f) return; +// backGraph.useBatteries(send); +// frontGraph.chargeBatteries(send); } @Override @@ -82,4 +84,6 @@ public class PowerDiode extends Block{ if(rotation == 3) return world.ltile(x, y - 1); return null; } + + } 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 e4cbf26c65..d74a1aca63 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java @@ -26,6 +26,9 @@ public class PowerGraph{ private final int graphID; private static int lastGraphID; + public float diodeTo = 0f; + public float diodeFrom = 0f; + { graphID = lastGraphID++; } @@ -56,7 +59,7 @@ public class PowerGraph{ } public float getPowerProduced(){ - float powerProduced = 0f; + float powerProduced = diodeTo; for(Tile producer : producers){ if(producer.entity == null) continue; powerProduced += producer.block().getPowerProduction(producer) * producer.entity.delta(); @@ -65,7 +68,7 @@ public class PowerGraph{ } public float getPowerNeeded(){ - float powerNeeded = 0f; + float powerNeeded = diodeFrom; for(Tile consumer : consumers){ Consumers consumes = consumer.block().consumes; if(consumes.hasPower()){