Fixed shouldConsume checking

This commit is contained in:
Anuken 2022-03-02 14:44:08 -05:00
parent 544df52730
commit 804fce06e7

View File

@ -1657,25 +1657,31 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
//TODO why check for old state?
boolean prevValid = efficiency > 0, update = shouldConsume() && productionValid();
float minEfficiency = 1f;
//assume efficiency is 1 for the calculations below
efficiency = optionalEfficiency = 1f;
if(update){
float minEfficiency = 1f;
//first pass: get the minimum efficiency of any consumer
for(var cons : block.nonOptionalConsumers){
minEfficiency = Math.min(minEfficiency, cons.efficiency(self()));
//assume efficiency is 1 for the calculations below
efficiency = optionalEfficiency = 1f;
//first pass: get the minimum efficiency of any consumer
for(var cons : block.nonOptionalConsumers){
minEfficiency = Math.min(minEfficiency, cons.efficiency(self()));
}
//same for optionals
for(var cons : block.optionalConsumers){
optionalEfficiency = Math.min(optionalEfficiency, cons.efficiency(self()));
}
//efficiency is now this minimum value
efficiency = minEfficiency;
optionalEfficiency = Math.min(optionalEfficiency, minEfficiency);
}else{
//should not consume, efficiency now zero
efficiency = optionalEfficiency = 0f;
}
//same for optionals
for(var cons : block.optionalConsumers){
optionalEfficiency = Math.min(optionalEfficiency, cons.efficiency(self()));
}
//efficiency is now this minimum value
efficiency = minEfficiency;
optionalEfficiency = Math.min(optionalEfficiency, minEfficiency);
updateEfficiencyMultiplier();
//second pass: update every consumer based on efficiency