Fixed NaN liquid efficiency

This commit is contained in:
Anuken 2022-07-17 19:12:57 -04:00
parent 1e7219f7d1
commit 26fbf4c71e
4 changed files with 11 additions and 5 deletions

View File

@ -90,7 +90,7 @@ public class MobileInput extends InputHandler implements GestureListener{
void checkTargets(float x, float y){
Unit unit = Units.closestEnemy(player.team(), x, y, 20f, u -> !u.dead);
if(unit != null){
if(unit != null && player.unit().type.canAttack){
player.unit().mineTile = null;
target = unit;
}else{

View File

@ -40,8 +40,10 @@ public class ConsumeLiquid extends ConsumeLiquidBase{
@Override
public float efficiency(Building build){
float ed = build.edelta();
if(ed <= 0.00000001f) return 0f;
//there can be more liquid than necessary, so cap at 1
return Math.min(build.liquids.get(liquid) / (amount * build.edelta()), 1f);
return Math.min(build.liquids.get(liquid) / (amount * ed), 1f);
}
@Override

View File

@ -50,7 +50,9 @@ public class ConsumeLiquidFilter extends ConsumeLiquidBase{
@Override
public float efficiency(Building build){
var liq = getConsumed(build);
return liq != null ? Math.min(build.liquids.get(liq) / (amount * build.edelta()), 1f) : 0f;
float ed = build.edelta();
if(ed <= 0.00000001f) return 0f;
return liq != null ? Math.min(build.liquids.get(liq) / (amount * ed), 1f) : 0f;
}
public @Nullable Liquid getConsumed(Building build){

View File

@ -49,9 +49,11 @@ public class ConsumeLiquids extends Consume{
@Override
public float efficiency(Building build){
float min = 1f, delta = build.edelta();
float ed = build.edelta();
if(ed <= 0.00000001f) return 0f;
float min = 1f;
for(var stack : liquids){
min = Math.min(build.liquids.get(stack.liquid) / (stack.amount * delta), min);
min = Math.min(build.liquids.get(stack.liquid) / (stack.amount * ed), min);
}
return min;
}