mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-13 17:27:35 +07:00
Implemented conservative generators / Closes #804
This commit is contained in:
@ -120,7 +120,7 @@ public class ItemLiquidGenerator extends PowerGenerator{
|
|||||||
float maximumPossible = maxLiquidGenerate * calculationDelta;
|
float maximumPossible = maxLiquidGenerate * calculationDelta;
|
||||||
float used = Math.min(entity.liquids.get(liquid) * calculationDelta, maximumPossible);
|
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;
|
entity.productionEfficiency = baseLiquidEfficiency * used / maximumPossible;
|
||||||
|
|
||||||
if(used > 0.001f && Mathf.chance(0.05 * entity.delta())){
|
if(used > 0.001f && Mathf.chance(0.05 * entity.delta())){
|
||||||
@ -137,7 +137,7 @@ public class ItemLiquidGenerator extends PowerGenerator{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(entity.generateTime > 0f){
|
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))){
|
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
|
//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 ObjectSet<Tile> all = new ObjectSet<>();
|
||||||
|
|
||||||
private final WindowedMean powerBalance = new WindowedMean(60);
|
private final WindowedMean powerBalance = new WindowedMean(60);
|
||||||
private float lastPowerProduced, lastPowerNeeded;
|
private float lastPowerProduced, lastPowerNeeded, lastUsageFraction;
|
||||||
|
|
||||||
private long lastFrameUpdated = -1;
|
private long lastFrameUpdated = -1;
|
||||||
private final int graphID;
|
private final int graphID;
|
||||||
@ -54,6 +54,10 @@ public class PowerGraph{
|
|||||||
return Mathf.clamp(lastPowerProduced / lastPowerNeeded);
|
return Mathf.clamp(lastPowerProduced / lastPowerNeeded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getUsageFraction(){
|
||||||
|
return lastUsageFraction;
|
||||||
|
}
|
||||||
|
|
||||||
public float getPowerProduced(){
|
public float getPowerProduced(){
|
||||||
float powerProduced = 0f;
|
float powerProduced = 0f;
|
||||||
for(Tile producer : producers){
|
for(Tile producer : producers){
|
||||||
@ -180,7 +184,7 @@ public class PowerGraph{
|
|||||||
tile.entity.power.status = 1f;
|
tile.entity.power.status = 1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPowerNeeded = lastPowerProduced = 1f;
|
lastPowerNeeded = lastPowerProduced = lastUsageFraction = 1f;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,6 +192,7 @@ public class PowerGraph{
|
|||||||
|
|
||||||
float powerNeeded = getPowerNeeded();
|
float powerNeeded = getPowerNeeded();
|
||||||
float powerProduced = getPowerProduced();
|
float powerProduced = getPowerProduced();
|
||||||
|
float rawProduced = powerProduced;
|
||||||
|
|
||||||
lastPowerNeeded = powerNeeded;
|
lastPowerNeeded = powerNeeded;
|
||||||
lastPowerProduced = powerProduced;
|
lastPowerProduced = powerProduced;
|
||||||
@ -208,6 +213,12 @@ public class PowerGraph{
|
|||||||
}
|
}
|
||||||
|
|
||||||
powerBalance.addValue((lastPowerProduced - lastPowerNeeded) / Time.delta());
|
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){
|
public void add(PowerGraph graph){
|
||||||
|
Reference in New Issue
Block a user