Targeting priority
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
6
core/src/io/anuke/mindustry/entities/TargetPriority.java
Normal file
6
core/src/io/anuke/mindustry/entities/TargetPriority.java
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package io.anuke.mindustry.entities;
|
||||||
|
|
||||||
|
public enum TargetPriority{
|
||||||
|
base,
|
||||||
|
turret
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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. */
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user