Stash
This commit is contained in:
@@ -31,28 +31,30 @@ public class PowerDiode extends Block{
|
|||||||
if(!back.block().hasPower || !front.block().hasPower) return;
|
if(!back.block().hasPower || !front.block().hasPower) return;
|
||||||
PowerGraph backGraph = back.entity.power.graph;
|
PowerGraph backGraph = back.entity.power.graph;
|
||||||
PowerGraph frontGraph = front.entity.power.graph;
|
PowerGraph frontGraph = front.entity.power.graph;
|
||||||
if(backGraph == frontGraph) return;
|
|
||||||
|
|
||||||
// skip if the receiving graph is already full
|
// backGraph
|
||||||
if(frontGraph.getBatteryStored() == frontGraph.getTotalBatteryCapacity()) return;
|
// if(backGraph == frontGraph) return;
|
||||||
|
//
|
||||||
// half the difference
|
// // skip if the receiving graph is already full
|
||||||
float send = Mathf.clamp((backGraph.getBatteryStored() - frontGraph.getBatteryStored()) / 2, 0f, Integer.MAX_VALUE);
|
// if(frontGraph.getBatteryStored() == frontGraph.getTotalBatteryCapacity()) return;
|
||||||
|
//
|
||||||
// send all overflow if all batteries of the sending graph are full
|
// // half the difference
|
||||||
if(backGraph.getBatteryStored() == backGraph.getTotalBatteryCapacity()){
|
// float send = Mathf.clamp((backGraph.getBatteryStored() - frontGraph.getBatteryStored()) / 2, 0f, Integer.MAX_VALUE);
|
||||||
send += backGraph.getLastPowerProduced() - backGraph.getPowerNeeded();
|
//
|
||||||
}
|
// // send all overflow if all batteries of the sending graph are full
|
||||||
|
// if(backGraph.getBatteryStored() == backGraph.getTotalBatteryCapacity()){
|
||||||
// limit offering to space available
|
// send += backGraph.getLastPowerProduced() - backGraph.getPowerNeeded();
|
||||||
send = Mathf.clamp(send, 0f, frontGraph.getTotalBatteryCapacity() - frontGraph.getBatteryStored());
|
// }
|
||||||
|
//
|
||||||
// limit to sendable power
|
// // limit offering to space available
|
||||||
send = Mathf.clamp(send, 0f, backGraph.getBatteryStored());
|
// send = Mathf.clamp(send, 0f, frontGraph.getTotalBatteryCapacity() - frontGraph.getBatteryStored());
|
||||||
|
//
|
||||||
if (send == 0f) return;
|
// // limit to sendable power
|
||||||
backGraph.useBatteries(send);
|
// send = Mathf.clamp(send, 0f, backGraph.getBatteryStored());
|
||||||
frontGraph.chargeBatteries(send);
|
//
|
||||||
|
// if (send == 0f) return;
|
||||||
|
// backGraph.useBatteries(send);
|
||||||
|
// frontGraph.chargeBatteries(send);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -82,4 +84,6 @@ public class PowerDiode extends Block{
|
|||||||
if(rotation == 3) return world.ltile(x, y - 1);
|
if(rotation == 3) return world.ltile(x, y - 1);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ public class PowerGraph{
|
|||||||
private final int graphID;
|
private final int graphID;
|
||||||
private static int lastGraphID;
|
private static int lastGraphID;
|
||||||
|
|
||||||
|
public float diodeTo = 0f;
|
||||||
|
public float diodeFrom = 0f;
|
||||||
|
|
||||||
{
|
{
|
||||||
graphID = lastGraphID++;
|
graphID = lastGraphID++;
|
||||||
}
|
}
|
||||||
@@ -56,7 +59,7 @@ public class PowerGraph{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public float getPowerProduced(){
|
public float getPowerProduced(){
|
||||||
float powerProduced = 0f;
|
float powerProduced = diodeTo;
|
||||||
for(Tile producer : producers){
|
for(Tile producer : producers){
|
||||||
if(producer.entity == null) continue;
|
if(producer.entity == null) continue;
|
||||||
powerProduced += producer.block().getPowerProduction(producer) * producer.entity.delta();
|
powerProduced += producer.block().getPowerProduction(producer) * producer.entity.delta();
|
||||||
@@ -65,7 +68,7 @@ public class PowerGraph{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public float getPowerNeeded(){
|
public float getPowerNeeded(){
|
||||||
float powerNeeded = 0f;
|
float powerNeeded = diodeFrom;
|
||||||
for(Tile consumer : consumers){
|
for(Tile consumer : consumers){
|
||||||
Consumers consumes = consumer.block().consumes;
|
Consumers consumes = consumer.block().consumes;
|
||||||
if(consumes.hasPower()){
|
if(consumes.hasPower()){
|
||||||
|
|||||||
Reference in New Issue
Block a user