Targeting priority

This commit is contained in:
Anuken
2019-10-14 18:54:50 -04:00
parent 3d8547d7dd
commit edfd402ccd
5 changed files with 15 additions and 2 deletions

View File

@@ -164,6 +164,10 @@ public class BlockIndexer{
} }
public TileEntity findTile(Team team, float x, float y, float range, Predicate<Tile> pred){ public TileEntity findTile(Team team, float x, float y, float range, Predicate<Tile> pred){
return findTile(team, x, y, range, pred, false);
}
public TileEntity findTile(Team team, float x, float y, float range, Predicate<Tile> pred, boolean usePriority){
TileEntity closest = null; TileEntity closest = null;
float dst = 0; float dst = 0;
@@ -184,7 +188,7 @@ public class BlockIndexer{
TileEntity e = other.entity; TileEntity e = other.entity;
float ndst = Mathf.dst(x, y, e.x, e.y); 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; dst = ndst;
closest = e; closest = e;
} }

View File

@@ -0,0 +1,6 @@
package io.anuke.mindustry.entities;
public enum TargetPriority{
base,
turret
}

View File

@@ -87,7 +87,7 @@ public class Units{
if(team == Team.derelict) return null; if(team == Team.derelict) return null;
for(Team enemy : state.teams.enemiesOf(team)){ 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){ if(entity != null){
return entity; return entity;
} }

View File

@@ -83,6 +83,8 @@ public class Block extends BlockStorage{
public BlockGroup group = BlockGroup.none; public BlockGroup group = BlockGroup.none;
/** List of block flags. Used for AI indexing. */ /** List of block flags. Used for AI indexing. */
public EnumSet<BlockFlag> flags = EnumSet.of(); public EnumSet<BlockFlag> 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. */ /** Whether the block can be tapped and selected to configure. */
public boolean configurable; public boolean configurable;
/** Whether this block consumes touchDown events when tapped. */ /** Whether this block consumes touchDown events when tapped. */

View File

@@ -72,6 +72,7 @@ public abstract class Turret extends Block{
public Turret(String name){ public Turret(String name){
super(name); super(name);
priority = TargetPriority.turret;
update = true; update = true;
solid = true; solid = true;
layer = Layer.turret; layer = Layer.turret;