Source reformat

This commit is contained in:
Anuken
2019-04-08 09:03:18 -04:00
parent 4a96b9bb00
commit b40beb0d1d
331 changed files with 2822 additions and 3274 deletions
@@ -17,31 +17,31 @@ import io.anuke.mindustry.world.meta.BlockFlag;
import static io.anuke.mindustry.Vars.*;
/**Class used for indexing special target blocks for AI.*/
/** Class used for indexing special target blocks for AI. */
@SuppressWarnings("unchecked")
public class BlockIndexer{
/**Size of one ore quadrant.*/
/** Size of one ore quadrant. */
private final static int oreQuadrantSize = 20;
/**Size of one structure quadrant.*/
/** Size of one structure quadrant. */
private final static int structQuadrantSize = 12;
/**Set of all ores that are being scanned.*/
/** Set of all ores that are being scanned. */
private final ObjectSet<Item> scanOres = ObjectSet.with(Item.getAllOres().toArray(Item.class));
private final ObjectSet<Item> itemSet = new ObjectSet<>();
/**Stores all ore quadtrants on the map.*/
/** Stores all ore quadtrants on the map. */
private ObjectMap<Item, ObjectSet<Tile>> ores;
/**Tags all quadrants.*/
/** Tags all quadrants. */
private Bits[] structQuadrants;
/**Stores all damaged tile entities by team.*/
/** Stores all damaged tile entities by team. */
private ObjectSet<Tile>[] damagedTiles = new ObjectSet[Team.all.length];
/**Maps teams to a map of flagged tiles by type.*/
/** Maps teams to a map of flagged tiles by type. */
private ObjectSet<Tile>[][] flagMap = new ObjectSet[Team.all.length][BlockFlag.all.length];
/**Maps tile positions to their last known tile index data.*/
/** Maps tile positions to their last known tile index data. */
private IntMap<TileIndex> typeMap = new IntMap<>();
/**Empty set used for returning.*/
/** Empty set used for returning. */
private ObjectSet<Tile> emptySet = new ObjectSet<>();
/**Array used for returning and reusing.*/
/** Array used for returning and reusing. */
private Array<Tile> returnArray = new Array<>();
public BlockIndexer(){
@@ -72,7 +72,7 @@ public class BlockIndexer{
//create bitset for each team type that contains each quadrant
structQuadrants = new Bits[Team.all.length];
for(int i = 0; i < Team.all.length; i++){
structQuadrants[i] = new Bits(Mathf.ceil(world.width() / (float) structQuadrantSize) * Mathf.ceil(world.height() / (float) structQuadrantSize));
structQuadrants[i] = new Bits(Mathf.ceil(world.width() / (float)structQuadrantSize) * Mathf.ceil(world.height() / (float)structQuadrantSize));
}
for(int x = 0; x < world.width(); x++){
@@ -101,7 +101,7 @@ public class BlockIndexer{
return flagMap[team.ordinal()];
}
/**Returns all damaged tiles by team.*/
/** Returns all damaged tiles by team. */
public ObjectSet<Tile> getDamaged(Team team){
returnArray.clear();
@@ -123,12 +123,12 @@ public class BlockIndexer{
return set;
}
/**Get all allied blocks with a flag.*/
/** Get all allied blocks with a flag. */
public ObjectSet<Tile> getAllied(Team team, BlockFlag type){
return flagMap[team.ordinal()][type.ordinal()];
}
/**Get all enemy blocks with a flag.*/
/** Get all enemy blocks with a flag. */
public Array<Tile> getEnemy(Team team, BlockFlag type){
returnArray.clear();
for(Team enemy : state.teams.enemiesOf(team)){
@@ -154,8 +154,8 @@ public class BlockIndexer{
TileEntity closest = null;
float dst = 0;
for(int rx = Math.max((int) ((x - range) / tilesize / structQuadrantSize), 0); rx <= (int) ((x + range) / tilesize / structQuadrantSize) && rx < quadWidth(); rx++){
for(int ry = Math.max((int) ((y - range) / tilesize / structQuadrantSize), 0); ry <= (int) ((y + range) / tilesize / structQuadrantSize) && ry < quadHeight(); ry++){
for(int rx = Math.max((int)((x - range) / tilesize / structQuadrantSize), 0); rx <= (int)((x + range) / tilesize / structQuadrantSize) && rx < quadWidth(); rx++){
for(int ry = Math.max((int)((y - range) / tilesize / structQuadrantSize), 0); ry <= (int)((y + range) / tilesize / structQuadrantSize) && ry < quadHeight(); ry++){
if(!getQuad(team, rx, ry)) continue;
@@ -167,7 +167,8 @@ public class BlockIndexer{
other = other.target();
if(other.entity == null || other.getTeam() != team || !pred.test(other) || !other.block().targetable) continue;
if(other.entity == null || other.getTeam() != team || !pred.test(other) || !other.block().targetable)
continue;
TileEntity e = other.entity;
@@ -194,7 +195,7 @@ public class BlockIndexer{
return ores.get(item, emptySet);
}
/**Find the closest ore block relative to a position.*/
/** Find the closest ore block relative to a position. */
public Tile findClosestOre(float xp, float yp, Item item){
Tile tile = Geometry.findClosest(xp, yp, world.indexer.getOrePositions(item));
@@ -214,7 +215,7 @@ public class BlockIndexer{
private void process(Tile tile){
if(tile.block().flags.size() > 0 &&
tile.getTeam() != Team.none){
tile.getTeam() != Team.none){
ObjectSet<Tile>[] map = getFlagged(tile.getTeam());
for(BlockFlag flag : tile.block().flags){
@@ -235,13 +236,13 @@ public class BlockIndexer{
itemSet.clear();
Tile rounded = world.tile(Mathf.clamp(quadrantX * oreQuadrantSize + oreQuadrantSize / 2, 0, world.width() - 1),
Mathf.clamp(quadrantY * oreQuadrantSize + oreQuadrantSize / 2, 0, world.height() - 1));
Mathf.clamp(quadrantY * oreQuadrantSize + oreQuadrantSize / 2, 0, world.height() - 1));
//find all items that this quadrant contains
for(int x = quadrantX * structQuadrantSize; x < world.width() && x < (quadrantX + 1) * structQuadrantSize; x++){
for(int y = quadrantY * structQuadrantSize; y < world.height() && y < (quadrantY + 1) * structQuadrantSize; y++){
Tile result = world.tile(x, y);
if( result == null || result.drop() == null || !scanOres.contains(result.drop())) continue;
if(result == null || result.drop() == null || !scanOres.contains(result.drop())) continue;
itemSet.add(result.drop());
}
@@ -294,16 +295,16 @@ public class BlockIndexer{
}
private boolean getQuad(Team team, int quadrantX, int quadrantY){
int index = quadrantX + quadrantY * Mathf.ceil(world.width() / (float) structQuadrantSize);
int index = quadrantX + quadrantY * Mathf.ceil(world.width() / (float)structQuadrantSize);
return structQuadrants[team.ordinal()].get(index);
}
private int quadWidth(){
return Mathf.ceil(world.width() / (float) structQuadrantSize);
return Mathf.ceil(world.width() / (float)structQuadrantSize);
}
private int quadHeight(){
return Mathf.ceil(world.height() / (float) structQuadrantSize);
return Mathf.ceil(world.height() / (float)structQuadrantSize);
}
private void scanOres(){
@@ -324,9 +325,9 @@ public class BlockIndexer{
//add position of quadrant to list when an ore is found
if(tile.drop() != null && scanOres.contains(tile.drop()) && tile.block() == Blocks.air){
ores.get(tile.drop()).add(world.tile(
//make sure to clamp quadrant middle position, since it might go off bounds
Mathf.clamp(qx * oreQuadrantSize + oreQuadrantSize / 2, 0, world.width() - 1),
Mathf.clamp(qy * oreQuadrantSize + oreQuadrantSize / 2, 0, world.height() - 1)));
//make sure to clamp quadrant middle position, since it might go off bounds
Mathf.clamp(qx * oreQuadrantSize + oreQuadrantSize / 2, 0, world.width() - 1),
Mathf.clamp(qy * oreQuadrantSize + oreQuadrantSize / 2, 0, world.height() - 1)));
}
}
}
@@ -65,9 +65,9 @@ public class Pathfinder{
Tile other = world.tile(dx, dy);
if(other == null) continue;
if(values[dx][dy] < value && (target == null || values[dx][dy]< tl) &&
!other.solid() &&
!(point.x != 0 && point.y != 0 && (world.solid(tile.x + point.x, tile.y) || world.solid(tile.x, tile.y + point.y)))){ //diagonal corner trap
if(values[dx][dy] < value && (target == null || values[dx][dy] < tl) &&
!other.solid() &&
!(point.x != 0 && point.y != 0 && (world.solid(tile.x + point.x, tile.y) || world.solid(tile.x, tile.y + point.y)))){ //diagonal corner trap
target = other;
tl = values[dx][dy];
}
@@ -86,8 +86,10 @@ public class Pathfinder{
return (!tile.solid()) || (tile.breakable() && (tile.target().getTeam() != team));
}
/**Clears the frontier, increments the search and sets up all flow sources.
* This only occurs for active teams.*/
/**
* Clears the frontier, increments the search and sets up all flow sources.
* This only occurs for active teams.
*/
private void update(Tile tile, Team team){
//make sure team exists
if(paths != null && paths[team.ordinal()] != null && paths[team.ordinal()].weights != null){
@@ -126,7 +128,7 @@ public class Pathfinder{
Tile tile = world.tile(x, y);
if(state.teams.areEnemies(tile.getTeam(), team)
&& tile.block().flags.contains(BlockFlag.target)){
&& tile.block().flags.contains(BlockFlag.target)){
path.frontier.addFirst(tile.pos());
path.weights[x][y] = 0;
path.searches[x][y] = (short)path.search;
@@ -162,7 +164,7 @@ public class Pathfinder{
Tile other = world.tile(dx, dy);
if(other != null && (path.weights[dx][dy] > cost + other.cost || path.searches[dx][dy] < path.search)
&& passable(other, team)){
&& passable(other, team)){
if(other.cost < 0) throw new IllegalArgumentException("Tile cost cannot be negative! " + other);
path.frontier.addFirst(Pos.get(dx, dy));
path.weights[dx][dy] = cost + other.cost;
@@ -16,9 +16,7 @@ import io.anuke.mindustry.game.SpawnGroup;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.world.Pos;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.*;
import static io.anuke.mindustry.Vars.*;
@@ -56,7 +54,7 @@ public class WaveSpawner{
return groundSpawns.size;
}
/**@return true if the player is near a ground spawn point.*/
/** @return true if the player is near a ground spawn point. */
public boolean playerNear(){
return groundSpawns.count(g -> Mathf.dst(g.x * tilesize, g.y * tilesize, player.x, player.y) < maxShockwaveDst) > 0;
}
@@ -88,7 +86,7 @@ public class WaveSpawner{
for(GroundSpawn spawn : groundSpawns){
spawnX = spawn.x * tilesize;
spawnY = spawn.y * tilesize;
spread = tilesize*2;
spread = tilesize * 2;
for(int i = 0; i < spawned; i++){
Tmp.v1.rnd(spread);
@@ -96,7 +94,7 @@ public class WaveSpawner{
BaseUnit unit = group.createUnit(waveTeam);
unit.set(spawnX + Tmp.v1.x, spawnY + Tmp.v1.y);
Time.run(Math.min(i*5, 60*2), () -> shockwave(unit));
Time.run(Math.min(i * 5, 60 * 2), () -> shockwave(unit));
}
Time.run(20f, () -> Effects.effect(Fx.spawnShockwave, spawn.x * tilesize, spawn.y * tilesize));
//would be interesting to see player structures survive this without hacks
@@ -125,7 +123,7 @@ public class WaveSpawner{
//hide spawnpoints, they have served their purpose
world.tile(x, y).setBlock(Blocks.air);
Log.info("Add spawn "+ x + " " + y);
Log.info("Add spawn " + x + " " + y);
}
}
}
@@ -145,7 +143,7 @@ public class WaveSpawner{
groundSpawns.add(spawn);
FlyerSpawn fspawn = new FlyerSpawn();
fspawn.angle = Angles.angle(world.width()/2f, world.height()/2f, x, y);
fspawn.angle = Angles.angle(world.width() / 2f, world.height() / 2f, x, y);
flySpawns.add(fspawn);
}