Fix turret shooting priority when there are multiple teams (#5299)
This commit is contained in:
@@ -300,19 +300,30 @@ public class BlockIndexer{
|
|||||||
breturnArray.size = 0;
|
breturnArray.size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Building findEnemyTile(@Nullable Team team, float x, float y, float range, Boolf<Building> pred){
|
public Building findEnemyTile(Team team, float x, float y, float range, Boolf<Building> pred){
|
||||||
|
Building target = null;
|
||||||
|
float targetDist = 0;
|
||||||
|
|
||||||
for(int i = 0; i < activeTeams.size; i++){
|
for(int i = 0; i < activeTeams.size; i++){
|
||||||
Team enemy = activeTeams.items[i];
|
Team enemy = activeTeams.items[i];
|
||||||
|
|
||||||
if(enemy == team || (team == Team.derelict && !state.rules.coreCapture)) continue;
|
if(enemy == team || (team == Team.derelict && !state.rules.coreCapture)) continue;
|
||||||
|
|
||||||
Building entity = indexer.findTile(enemy, x, y, range, pred, true);
|
Building candidate = indexer.findTile(enemy, x, y, range, pred, true);
|
||||||
if(entity != null){
|
if(candidate == null) continue;
|
||||||
return entity;
|
|
||||||
|
//if a block has the same priority, the closer one should be targeted
|
||||||
|
float dist = candidate.dst(x, y) - candidate.hitSize() / 2f;
|
||||||
|
if(target == null ||
|
||||||
|
//if its closer and is at least equal priority
|
||||||
|
(dist < targetDist && candidate.block.priority.ordinal() >= target.block.priority.ordinal()) ||
|
||||||
|
// block has higher priority (so range doesnt matter)
|
||||||
|
(candidate.block.priority.ordinal() > target.block.priority.ordinal())){
|
||||||
|
target = candidate;
|
||||||
|
targetDist = dist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Building findTile(Team team, float x, float y, float range, Boolf<Building> pred){
|
public Building findTile(Team team, float x, float y, float range, Boolf<Building> pred){
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ public class Units{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the closest target enemy. First, units are checked, then tile entities. */
|
/** Returns the closest target enemy. First, units are checked, then buildings. */
|
||||||
public static Teamc bestTarget(Team team, float x, float y, float range, Boolf<Unit> unitPred, Boolf<Building> tilePred, Sortf sort){
|
public static Teamc bestTarget(Team team, float x, float y, float range, Boolf<Unit> unitPred, Boolf<Building> tilePred, Sortf sort){
|
||||||
if(team == Team.derelict) return null;
|
if(team == Team.derelict) return null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user