mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-10 15:19:24 +07:00
Stash
This commit is contained in:
parent
4c5e30dbcc
commit
0c14854519
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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()){
|
||||
|
Loading…
Reference in New Issue
Block a user