diff --git a/core/src/io/anuke/mindustry/ai/BlockIndexer.java b/core/src/io/anuke/mindustry/ai/BlockIndexer.java index b57e364d91..0fdbbb7c5e 100644 --- a/core/src/io/anuke/mindustry/ai/BlockIndexer.java +++ b/core/src/io/anuke/mindustry/ai/BlockIndexer.java @@ -164,6 +164,10 @@ public class BlockIndexer{ } public TileEntity findTile(Team team, float x, float y, float range, Predicate pred){ + return findTile(team, x, y, range, pred, false); + } + + public TileEntity findTile(Team team, float x, float y, float range, Predicate pred, boolean usePriority){ TileEntity closest = null; float dst = 0; @@ -184,7 +188,7 @@ public class BlockIndexer{ TileEntity e = other.entity; float ndst = Mathf.dst(x, y, e.x, e.y); - if(ndst < range && (closest == null || ndst < dst)){ + if(ndst < range && (closest == null || ndst < dst || (usePriority && closest.block.priority.ordinal() < e.block.priority.ordinal()))){ dst = ndst; closest = e; } diff --git a/core/src/io/anuke/mindustry/entities/TargetPriority.java b/core/src/io/anuke/mindustry/entities/TargetPriority.java new file mode 100644 index 0000000000..47b0213de3 --- /dev/null +++ b/core/src/io/anuke/mindustry/entities/TargetPriority.java @@ -0,0 +1,6 @@ +package io.anuke.mindustry.entities; + +public enum TargetPriority{ + base, + turret +} diff --git a/core/src/io/anuke/mindustry/entities/Units.java b/core/src/io/anuke/mindustry/entities/Units.java index af3d3f4fe7..c9d0073998 100644 --- a/core/src/io/anuke/mindustry/entities/Units.java +++ b/core/src/io/anuke/mindustry/entities/Units.java @@ -87,7 +87,7 @@ public class Units{ if(team == Team.derelict) return null; for(Team enemy : state.teams.enemiesOf(team)){ - TileEntity entity = indexer.findTile(enemy, x, y, range, pred); + TileEntity entity = indexer.findTile(enemy, x, y, range, pred, true); if(entity != null){ return entity; } diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 838eeeee7a..2d505333bb 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -83,6 +83,8 @@ public class Block extends BlockStorage{ public BlockGroup group = BlockGroup.none; /** List of block flags. Used for AI indexing. */ public EnumSet flags = EnumSet.of(); + /** Targeting priority of this block, as seen by enemies.*/ + public TargetPriority priority = TargetPriority.base; /** Whether the block can be tapped and selected to configure. */ public boolean configurable; /** Whether this block consumes touchDown events when tapped. */ diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java index 948161dfd1..8a124ea3cc 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java @@ -72,6 +72,7 @@ public abstract class Turret extends Block{ public Turret(String name){ super(name); + priority = TargetPriority.turret; update = true; solid = true; layer = Layer.turret;