1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-09-21 13:28:12 +03:00

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){
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;
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;
}

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;
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;
}

View File

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

View File

@ -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;