Unit naming / Fixed #2209
This commit is contained in:
@@ -33,7 +33,7 @@ public class BlockIndexer{
|
||||
/** Maps each team ID to a quarant. A quadrant is a grid of bits, where each bit is set if and only if there is a block of that team in that quadrant. */
|
||||
private GridBits[] structQuadrants;
|
||||
/** Stores all damaged tile entities by team. */
|
||||
private TileArray[] damagedTiles = new TileArray[Team.all.length];
|
||||
private BuildingArray[] damagedTiles = new BuildingArray[Team.all.length];
|
||||
/** All ores available on this map. */
|
||||
private ObjectSet<Item> allOres = new ObjectSet<>();
|
||||
/** Stores teams that are present here as tiles. */
|
||||
@@ -48,6 +48,8 @@ public class BlockIndexer{
|
||||
private TileArray emptySet = new TileArray();
|
||||
/** Array used for returning and reusing. */
|
||||
private Seq<Tile> returnArray = new Seq<>();
|
||||
/** Array used for returning and reusing. */
|
||||
private Seq<Building> breturnArray = new Seq<>();
|
||||
|
||||
public BlockIndexer(){
|
||||
Events.on(BuildinghangeEvent.class, event -> {
|
||||
@@ -68,7 +70,7 @@ public class BlockIndexer{
|
||||
Events.on(WorldLoadEvent.class, event -> {
|
||||
scanOres.clear();
|
||||
scanOres.addAll(Item.getAllOres());
|
||||
damagedTiles = new TileArray[Team.all.length];
|
||||
damagedTiles = new BuildingArray[Team.all.length];
|
||||
flagMap = new TileArray[Team.all.length][BlockFlag.all.length];
|
||||
unitCaps = new int[Team.all.length];
|
||||
|
||||
@@ -136,21 +138,21 @@ public class BlockIndexer{
|
||||
}
|
||||
|
||||
/** Returns all damaged tiles by team. */
|
||||
public TileArray getDamaged(Team team){
|
||||
public BuildingArray getDamaged(Team team){
|
||||
returnArray.clear();
|
||||
|
||||
if(damagedTiles[team.id] == null){
|
||||
damagedTiles[team.id] = new TileArray();
|
||||
damagedTiles[team.id] = new BuildingArray();
|
||||
}
|
||||
|
||||
TileArray set = damagedTiles[team.id];
|
||||
for(Tile tile : set){
|
||||
if((tile.build == null || tile.build.team() != team || !tile.build.damaged()) || tile.block() instanceof BuildBlock){
|
||||
returnArray.add(tile);
|
||||
BuildingArray set = damagedTiles[team.id];
|
||||
for(Building build : set){
|
||||
if((!build.isValid() || build.team != team || !build.damaged()) || build.block instanceof BuildBlock){
|
||||
breturnArray.add(build);
|
||||
}
|
||||
}
|
||||
|
||||
for(Tile tile : returnArray){
|
||||
for(Building tile : breturnArray){
|
||||
set.remove(tile);
|
||||
}
|
||||
|
||||
@@ -211,11 +213,10 @@ public class BlockIndexer{
|
||||
|
||||
public void notifyTileDamaged(Building entity){
|
||||
if(damagedTiles[entity.team().id] == null){
|
||||
damagedTiles[entity.team().id] = new TileArray();
|
||||
damagedTiles[entity.team().id] = new BuildingArray();
|
||||
}
|
||||
|
||||
TileArray set = damagedTiles[entity.team().id];
|
||||
set.add(entity.tile());
|
||||
damagedTiles[entity.team().id].add(entity);
|
||||
}
|
||||
|
||||
public Building findEnemyTile(Team team, float x, float y, float range, Boolf<Building> pred){
|
||||
@@ -471,4 +472,35 @@ public class BlockIndexer{
|
||||
return tiles.iterator();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO copy-pasted code, generics would be nice here
|
||||
public static class BuildingArray implements Iterable<Building>{
|
||||
private Seq<Building> tiles = new Seq<>(false, 16);
|
||||
private IntSet contained = new IntSet();
|
||||
|
||||
public void add(Building tile){
|
||||
if(contained.add(tile.pos())){
|
||||
tiles.add(tile);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(Building tile){
|
||||
if(contained.remove(tile.pos())){
|
||||
tiles.remove(tile);
|
||||
}
|
||||
}
|
||||
|
||||
public int size(){
|
||||
return tiles.size;
|
||||
}
|
||||
|
||||
public Building first(){
|
||||
return tiles.first();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Building> iterator(){
|
||||
return tiles.iterator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user