Fixed liquid turrets not targeting closest fire

This commit is contained in:
Anuken
2021-06-28 11:35:46 -04:00
parent a5c44e7998
commit fcdbd4b117
2 changed files with 16 additions and 6 deletions

View File

@@ -100,17 +100,27 @@ public class LiquidTurret extends Turret{
@Override
protected void findTarget(){
if(extinguish && liquids.current().canExtinguish()){
Fire result = null;
float mindst = 0f;
int tr = (int)(range / tilesize);
for(int x = -tr; x <= tr; x++){
for(int y = -tr; y <= tr; y++){
Tile other = world.tileWorld(x + tile.x, y + tile.y);
Tile other = world.tile(x + tile.x, y + tile.y);
var fire = Fires.get(x + tile.x, y + tile.y);
float dst = fire == null ? 0 : dst2(fire);
//do not extinguish fires on other team blocks
if(other != null && Fires.has(x + tile.x, y + tile.y) && (other.build == null || other.team() == team)){
target = Fires.get(x + tile.x, y + tile.y);
return;
if(other != null && fire != null && dst <= range * range && (result == null || dst < mindst) && (other.build == null || other.team() == team)){
result = fire;
mindst = dst;
}
}
}
if(result != null){
target = result;
//don't run standard targeting
return;
}
}
super.findTarget();