Better team building presence check
This commit is contained in:
@@ -70,8 +70,8 @@ public class BlockIndexer{
|
|||||||
for(Team team : Team.all){
|
for(Team team : Team.all){
|
||||||
var data = state.teams.get(team);
|
var data = state.teams.get(team);
|
||||||
if(data != null){
|
if(data != null){
|
||||||
if(data.buildings != null) data.buildings.clear();
|
if(data.buildingTree != null) data.buildingTree.clear();
|
||||||
if(data.turrets != null) data.turrets.clear();
|
if(data.turretTree != null) data.turretTree.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,17 +113,20 @@ public class BlockIndexer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//no longer part of the building list
|
||||||
|
data.buildings.remove(tile.build);
|
||||||
|
|
||||||
//update the unit cap when building is removed
|
//update the unit cap when building is removed
|
||||||
data.unitCap -= tile.block().unitCapModifier;
|
data.unitCap -= tile.block().unitCapModifier;
|
||||||
|
|
||||||
//unregister building from building quadtree
|
//unregister building from building quadtree
|
||||||
if(data.buildings != null){
|
if(data.buildingTree != null){
|
||||||
data.buildings.remove(build);
|
data.buildingTree.remove(build);
|
||||||
}
|
}
|
||||||
|
|
||||||
//remove indexed turret
|
//remove indexed turret
|
||||||
if(data.turrets != null && build.block.attacks){
|
if(data.turretTree != null && build.block.attacks){
|
||||||
data.turrets.remove(build);
|
data.turretTree.remove(build);
|
||||||
}
|
}
|
||||||
|
|
||||||
//is no longer registered
|
//is no longer registered
|
||||||
@@ -230,7 +233,7 @@ public class BlockIndexer{
|
|||||||
}else{
|
}else{
|
||||||
breturnArray.clear();
|
breturnArray.clear();
|
||||||
|
|
||||||
var buildings = team.data().buildings;
|
var buildings = team.data().buildingTree;
|
||||||
if(buildings == null) return false;
|
if(buildings == null) return false;
|
||||||
buildings.intersect(wx - range, wy - range, range*2f, range*2f, b -> {
|
buildings.intersect(wx - range, wy - range, range*2f, range*2f, b -> {
|
||||||
if(b.within(wx, wy, range + b.hitSize() / 2f) && pred.get(b)){
|
if(b.within(wx, wy, range + b.hitSize() / 2f) && pred.get(b)){
|
||||||
@@ -256,7 +259,7 @@ public class BlockIndexer{
|
|||||||
|
|
||||||
breturnArray.clear();
|
breturnArray.clear();
|
||||||
|
|
||||||
var buildings = team.data().buildings;
|
var buildings = team.data().buildingTree;
|
||||||
if(buildings == null) return false;
|
if(buildings == null) return false;
|
||||||
buildings.intersect(rect, b -> {
|
buildings.intersect(rect, b -> {
|
||||||
if(pred.get(b)){
|
if(pred.get(b)){
|
||||||
@@ -324,7 +327,7 @@ public class BlockIndexer{
|
|||||||
breturnArray.clear();
|
breturnArray.clear();
|
||||||
for(int i = 0; i < activeTeams.size; i++){
|
for(int i = 0; i < activeTeams.size; i++){
|
||||||
Team team = activeTeams.items[i];
|
Team team = activeTeams.items[i];
|
||||||
var buildings = team.data().buildings;
|
var buildings = team.data().buildingTree;
|
||||||
if(buildings == null) continue;
|
if(buildings == null) continue;
|
||||||
buildings.intersect(x - range, y - range, range*2f, range*2f, breturnArray);
|
buildings.intersect(x - range, y - range, range*2f, range*2f, breturnArray);
|
||||||
}
|
}
|
||||||
@@ -374,7 +377,7 @@ public class BlockIndexer{
|
|||||||
public Building findTile(Team team, float x, float y, float range, Boolf<Building> pred, boolean usePriority){
|
public Building findTile(Team team, float x, float y, float range, Boolf<Building> pred, boolean usePriority){
|
||||||
Building closest = null;
|
Building closest = null;
|
||||||
float dst = 0;
|
float dst = 0;
|
||||||
var buildings = team.data().buildings;
|
var buildings = team.data().buildingTree;
|
||||||
if(buildings == null) return null;
|
if(buildings == null) return null;
|
||||||
|
|
||||||
breturnArray.clear();
|
breturnArray.clear();
|
||||||
@@ -444,6 +447,9 @@ public class BlockIndexer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//record in list of buildings
|
||||||
|
data.buildings.add(tile.build);
|
||||||
|
|
||||||
//update the unit cap when new tile is registered
|
//update the unit cap when new tile is registered
|
||||||
data.unitCap += tile.block().unitCapModifier;
|
data.unitCap += tile.block().unitCapModifier;
|
||||||
|
|
||||||
@@ -452,17 +458,17 @@ public class BlockIndexer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//insert the new tile into the quadtree for targeting
|
//insert the new tile into the quadtree for targeting
|
||||||
if(data.buildings == null){
|
if(data.buildingTree == null){
|
||||||
data.buildings = new QuadTree<>(new Rect(0, 0, world.unitWidth(), world.unitHeight()));
|
data.buildingTree = new QuadTree<>(new Rect(0, 0, world.unitWidth(), world.unitHeight()));
|
||||||
}
|
}
|
||||||
data.buildings.insert(tile.build);
|
data.buildingTree.insert(tile.build);
|
||||||
|
|
||||||
if(tile.block().attacks && tile.build instanceof Ranged){
|
if(tile.block().attacks && tile.build instanceof Ranged){
|
||||||
if(data.turrets == null){
|
if(data.turretTree == null){
|
||||||
data.turrets = new TurretQuadtree(new Rect(0, 0, world.unitWidth(), world.unitHeight()));
|
data.turretTree = new TurretQuadtree(new Rect(0, 0, world.unitWidth(), world.unitHeight()));
|
||||||
}
|
}
|
||||||
|
|
||||||
data.turrets.insert(tile.build);
|
data.turretTree.insert(tile.build);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyBuildDamaged(tile.build);
|
notifyBuildDamaged(tile.build);
|
||||||
|
|||||||
@@ -216,9 +216,8 @@ public class Control implements ApplicationListener, Loadable{
|
|||||||
float unitsPerTick = 1f;
|
float unitsPerTick = 1f;
|
||||||
|
|
||||||
boolean anyBuilds = false;
|
boolean anyBuilds = false;
|
||||||
for(Tile tile : world.tiles){
|
for(var build : state.rules.defaultTeam.data().buildings){
|
||||||
var build = tile.build;
|
if(!(build instanceof CoreBuild)){
|
||||||
if(!(build instanceof CoreBuild) && build != null && build.team == state.rules.defaultTeam){
|
|
||||||
var ccore = build.closestCore();
|
var ccore = build.closestCore();
|
||||||
|
|
||||||
if(ccore != null && build.within(ccore, state.rules.enemyCoreBuildRadius)){
|
if(ccore != null && build.within(ccore, state.rules.enemyCoreBuildRadius)){
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ public class Units{
|
|||||||
buildResult = null;
|
buildResult = null;
|
||||||
cdist = 0f;
|
cdist = 0f;
|
||||||
|
|
||||||
var buildings = team.data().buildings;
|
var buildings = team.data().buildingTree;
|
||||||
if(buildings == null) return null;
|
if(buildings == null) return null;
|
||||||
buildings.intersect(wx - range, wy - range, range*2f, range*2f, b -> {
|
buildings.intersect(wx - range, wy - range, range*2f, range*2f, b -> {
|
||||||
if(pred.get(b)){
|
if(pred.get(b)){
|
||||||
@@ -466,7 +466,7 @@ public class Units{
|
|||||||
if(other.tree().any(x, y, width, height)){
|
if(other.tree().any(x, y, width, height)){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(other.turrets != null && other.turrets.any(x, y, width, height)){
|
if(other.turretTree != null && other.turretTree.any(x, y, width, height)){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,12 +147,12 @@ public class Teams{
|
|||||||
for(Team team : Team.all){
|
for(Team team : Team.all){
|
||||||
TeamData data = team.data();
|
TeamData data = team.data();
|
||||||
|
|
||||||
data.presentFlag = false;
|
data.presentFlag = data.buildings.size > 0;
|
||||||
data.unitCount = 0;
|
data.unitCount = 0;
|
||||||
data.units.clear();
|
data.units.clear();
|
||||||
data.players.clear();
|
data.players.clear();
|
||||||
if(data.tree != null){
|
if(data.unitTree != null){
|
||||||
data.tree.clear();
|
data.unitTree.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data.typeCounts != null){
|
if(data.typeCounts != null){
|
||||||
@@ -169,9 +169,7 @@ public class Teams{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//update presence flag.
|
//TODO this is slow and dumb
|
||||||
Groups.build.each(b -> b.team.data().presentFlag = true);
|
|
||||||
|
|
||||||
for(Unit unit : Groups.unit){
|
for(Unit unit : Groups.unit){
|
||||||
if(unit.type == null) continue;
|
if(unit.type == null) continue;
|
||||||
TeamData data = unit.team.data();
|
TeamData data = unit.team.data();
|
||||||
@@ -243,21 +241,23 @@ public class Teams{
|
|||||||
public Queue<BlockPlan> blocks = new Queue<>();
|
public Queue<BlockPlan> blocks = new Queue<>();
|
||||||
|
|
||||||
/** Quadtree for all buildings of this team. Null if not active. */
|
/** Quadtree for all buildings of this team. Null if not active. */
|
||||||
public @Nullable QuadTree<Building> buildings;
|
public @Nullable QuadTree<Building> buildingTree;
|
||||||
/** Turrets by range. Null if not active. */
|
/** Turrets by range. Null if not active. */
|
||||||
public @Nullable QuadTree<Building> turrets;
|
public @Nullable QuadTree<Building> turretTree;
|
||||||
|
/** Quadtree for units of this team. Do not access directly. */
|
||||||
|
public @Nullable QuadTree<Unit> unitTree;
|
||||||
/** Current unit cap. Do not modify externally. */
|
/** Current unit cap. Do not modify externally. */
|
||||||
public int unitCap;
|
public int unitCap;
|
||||||
/** Total unit count. */
|
/** Total unit count. */
|
||||||
public int unitCount;
|
public int unitCount;
|
||||||
/** Counts for each type of unit. Do not access directly. */
|
/** Counts for each type of unit. Do not access directly. */
|
||||||
public @Nullable int[] typeCounts;
|
public @Nullable int[] typeCounts;
|
||||||
/** Quadtree for units of this team. Do not access directly. */
|
|
||||||
public @Nullable QuadTree<Unit> tree;
|
|
||||||
/** Units of this team. Updated each frame. */
|
/** Units of this team. Updated each frame. */
|
||||||
public Seq<Unit> units = new Seq<>();
|
public Seq<Unit> units = new Seq<>(false);
|
||||||
/** Same as units, but players. */
|
/** Same as units, but players. */
|
||||||
public Seq<Player> players = new Seq<>();
|
public Seq<Player> players = new Seq<>(false);
|
||||||
|
/** All buildings. Updated on team change / building addition or removal. Includes even buildings that do not update(). */
|
||||||
|
public Seq<Building> buildings = new Seq<>(false);
|
||||||
/** Units of this team by type. Updated each frame. */
|
/** Units of this team by type. Updated each frame. */
|
||||||
public @Nullable Seq<Unit>[] unitsByType;
|
public @Nullable Seq<Unit>[] unitsByType;
|
||||||
|
|
||||||
@@ -270,8 +270,8 @@ public class Teams{
|
|||||||
|
|
||||||
//grab all buildings from quadtree.
|
//grab all buildings from quadtree.
|
||||||
var builds = new Seq<Building>();
|
var builds = new Seq<Building>();
|
||||||
if(buildings != null){
|
if(buildingTree != null){
|
||||||
buildings.getObjects(builds);
|
buildingTree.getObjects(builds);
|
||||||
}
|
}
|
||||||
|
|
||||||
//no remaining blocks, cease building if applicable
|
//no remaining blocks, cease building if applicable
|
||||||
@@ -294,8 +294,8 @@ public class Teams{
|
|||||||
/** Make all buildings within this range derelict / explode. */
|
/** Make all buildings within this range derelict / explode. */
|
||||||
public void makeDerelict(float x, float y, float range){
|
public void makeDerelict(float x, float y, float range){
|
||||||
var builds = new Seq<Building>();
|
var builds = new Seq<Building>();
|
||||||
if(buildings != null){
|
if(buildingTree != null){
|
||||||
buildings.intersect(x - range, y - range, range * 2f, range * 2f, builds);
|
buildingTree.intersect(x - range, y - range, range * 2f, range * 2f, builds);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var build : builds){
|
for(var build : builds){
|
||||||
@@ -308,8 +308,8 @@ public class Teams{
|
|||||||
/** Make all buildings within this range explode. */
|
/** Make all buildings within this range explode. */
|
||||||
public void timeDestroy(float x, float y, float range){
|
public void timeDestroy(float x, float y, float range){
|
||||||
var builds = new Seq<Building>();
|
var builds = new Seq<Building>();
|
||||||
if(buildings != null){
|
if(buildingTree != null){
|
||||||
buildings.intersect(x - range, y - range, range * 2f, range * 2f, builds);
|
buildingTree.intersect(x - range, y - range, range * 2f, range * 2f, builds);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var build : builds){
|
for(var build : builds){
|
||||||
@@ -344,8 +344,8 @@ public class Teams{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public QuadTree<Unit> tree(){
|
public QuadTree<Unit> tree(){
|
||||||
if(tree == null) tree = new QuadTree<>(Vars.world.getQuadBounds(new Rect()));
|
if(unitTree == null) unitTree = new QuadTree<>(Vars.world.getQuadBounds(new Rect()));
|
||||||
return tree;
|
return unitTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int countType(UnitType type){
|
public int countType(UnitType type){
|
||||||
|
|||||||
Reference in New Issue
Block a user