Added unit tests for batteries...

...and fixed battery distribution until all tests passed
This commit is contained in:
Timmeey86
2018-11-26 08:58:16 +01:00
parent 560d388df4
commit 99139dfcca
2 changed files with 49 additions and 4 deletions

View File

@@ -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);
}