Added unit tests for batteries...
...and fixed battery distribution until all tests passed
This commit is contained in:
@@ -80,9 +80,15 @@ public class PowerGraph{
|
||||
if(MathUtils.isEqual(stored, 0f)){ return 0f; }
|
||||
|
||||
float used = Math.min(stored, needed);
|
||||
float percentageRemaining = 1f - (used / stored);
|
||||
float consumedPowerPercentage = Math.min(1.0f, needed / stored);
|
||||
for(Tile battery : batteries){
|
||||
battery.entity.power.satisfaction *= percentageRemaining;
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.has(ConsumePower.class)){
|
||||
ConsumePower consumePower = consumes.get(ConsumePower.class);
|
||||
if(consumePower.powerCapacity > 0f){
|
||||
battery.entity.power.satisfaction = Math.max(0.0f, battery.entity.power.satisfaction - consumedPowerPercentage);
|
||||
}
|
||||
}
|
||||
}
|
||||
return used;
|
||||
}
|
||||
@@ -91,9 +97,15 @@ public class PowerGraph{
|
||||
float capacity = getBatteryCapacity();
|
||||
if(MathUtils.isEqual(capacity, 0f)){ return 0f; }
|
||||
|
||||
float thing = Math.min(1, excess / capacity);
|
||||
for(Tile battery : batteries){
|
||||
battery.entity.power.satisfaction += (1 - battery.entity.power.satisfaction) * thing;
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.has(ConsumePower.class)){
|
||||
ConsumePower consumePower = consumes.get(ConsumePower.class);
|
||||
if(consumePower.powerCapacity > 0f){
|
||||
float additionalPowerPercentage = Math.min(1.0f, excess / consumePower.powerCapacity);
|
||||
battery.entity.power.satisfaction = Math.min(1.0f, battery.entity.power.satisfaction + additionalPowerPercentage);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Math.min(excess, capacity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user