mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-10 23:28:52 +07:00
Implemented conservative generators / Closes #804
This commit is contained in:
parent
1ae20553ff
commit
01e3912827
@ -120,7 +120,7 @@ public class ItemLiquidGenerator extends PowerGenerator{
|
||||
float maximumPossible = maxLiquidGenerate * calculationDelta;
|
||||
float used = Math.min(entity.liquids.get(liquid) * calculationDelta, maximumPossible);
|
||||
|
||||
entity.liquids.remove(liquid, used);
|
||||
entity.liquids.remove(liquid, used * entity.power.graph.getUsageFraction());
|
||||
entity.productionEfficiency = baseLiquidEfficiency * used / maximumPossible;
|
||||
|
||||
if(used > 0.001f && Mathf.chance(0.05 * entity.delta())){
|
||||
@ -137,7 +137,7 @@ public class ItemLiquidGenerator extends PowerGenerator{
|
||||
}
|
||||
|
||||
if(entity.generateTime > 0f){
|
||||
entity.generateTime -= Math.min(1f / itemDuration * entity.delta(), entity.generateTime);
|
||||
entity.generateTime -= Math.min(1f / itemDuration * entity.delta() * entity.power.graph.getUsageFraction(), entity.generateTime);
|
||||
|
||||
if(randomlyExplode && state.rules.reactorExplosions && Mathf.chance(entity.delta() * 0.06 * Mathf.clamp(entity.explosiveness - 0.5f))){
|
||||
//this block is run last so that in the event of a block destruction, no code relies on the block type
|
||||
|
@ -19,7 +19,7 @@ public class PowerGraph{
|
||||
private final ObjectSet<Tile> all = new ObjectSet<>();
|
||||
|
||||
private final WindowedMean powerBalance = new WindowedMean(60);
|
||||
private float lastPowerProduced, lastPowerNeeded;
|
||||
private float lastPowerProduced, lastPowerNeeded, lastUsageFraction;
|
||||
|
||||
private long lastFrameUpdated = -1;
|
||||
private final int graphID;
|
||||
@ -54,6 +54,10 @@ public class PowerGraph{
|
||||
return Mathf.clamp(lastPowerProduced / lastPowerNeeded);
|
||||
}
|
||||
|
||||
public float getUsageFraction(){
|
||||
return lastUsageFraction;
|
||||
}
|
||||
|
||||
public float getPowerProduced(){
|
||||
float powerProduced = 0f;
|
||||
for(Tile producer : producers){
|
||||
@ -180,7 +184,7 @@ public class PowerGraph{
|
||||
tile.entity.power.status = 1f;
|
||||
}
|
||||
|
||||
lastPowerNeeded = lastPowerProduced = 1f;
|
||||
lastPowerNeeded = lastPowerProduced = lastUsageFraction = 1f;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -188,6 +192,7 @@ public class PowerGraph{
|
||||
|
||||
float powerNeeded = getPowerNeeded();
|
||||
float powerProduced = getPowerProduced();
|
||||
float rawProduced = powerProduced;
|
||||
|
||||
lastPowerNeeded = powerNeeded;
|
||||
lastPowerProduced = powerProduced;
|
||||
@ -208,6 +213,12 @@ public class PowerGraph{
|
||||
}
|
||||
|
||||
powerBalance.addValue((lastPowerProduced - lastPowerNeeded) / Time.delta());
|
||||
|
||||
//overproducing: 10 / 20 = 0.5
|
||||
//underproducing: 20 / 10 = 2 -> clamp -> 1.0
|
||||
//nothing being produced: 20 / 0 -> 1.0
|
||||
//nothing being consumed: 0 / 20 -> 0.0
|
||||
lastUsageFraction = Mathf.zero(rawProduced) ? 1f : Mathf.clamp(powerNeeded / rawProduced);
|
||||
}
|
||||
|
||||
public void add(PowerGraph graph){
|
||||
|
Loading…
Reference in New Issue
Block a user