Better targeting range calculation
This commit is contained in:
@@ -269,7 +269,6 @@ public class BlockIndexer{
|
||||
public Building findTile(Team team, float x, float y, float range, Boolf<Building> pred, boolean usePriority){
|
||||
Building closest = null;
|
||||
float dst = 0;
|
||||
float range2 = range * range;
|
||||
|
||||
for(int rx = Math.max((int)((x - range) / tilesize / quadrantSize), 0); rx <= (int)((x + range) / tilesize / quadrantSize) && rx < quadWidth(); rx++){
|
||||
for(int ry = Math.max((int)((y - range) / tilesize / quadrantSize), 0); ry <= (int)((y + range) / tilesize / quadrantSize) && ry < quadHeight(); ry++){
|
||||
@@ -282,13 +281,13 @@ public class BlockIndexer{
|
||||
|
||||
if(e == null || e.team != team || !pred.get(e) || !e.block.targetable || e.team == Team.derelict) continue;
|
||||
|
||||
float ndst = e.dst2(x, y);
|
||||
if(ndst < range2 && (closest == null ||
|
||||
float bdst = e.dst(x, y) - e.hitSize() / 2f;
|
||||
if(bdst < range && (closest == null ||
|
||||
//this one is closer, and it is at least of equal priority
|
||||
(ndst < dst && (!usePriority || closest.block.priority.ordinal() <= e.block.priority.ordinal())) ||
|
||||
(bdst < dst && (!usePriority || closest.block.priority.ordinal() <= e.block.priority.ordinal())) ||
|
||||
//priority is used, and new block has higher priority regardless of range
|
||||
(usePriority && closest.block.priority.ordinal() < e.block.priority.ordinal()))){
|
||||
dst = ndst;
|
||||
dst = bdst;
|
||||
closest = e;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user