mirror of
https://github.com/Anuken/Mindustry.git
synced 2024-09-21 13:28:12 +03:00
Targeting priority
This commit is contained in:
parent
3d8547d7dd
commit
edfd402ccd
@ -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;
|
||||
}
|
||||
|
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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. */
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user