Fixed compilation

This commit is contained in:
Anuken
2019-12-26 19:40:54 -05:00
parent de5979f4ee
commit 4858e602ed
18 changed files with 129 additions and 103 deletions

View File

@ -1,10 +1,10 @@
package mindustry.ai;
import arc.*;
import arc.struct.*;
import arc.func.*;
import arc.math.*;
import arc.math.geom.*;
import arc.struct.*;
import mindustry.content.*;
import mindustry.entities.type.*;
import mindustry.game.EventType.*;
@ -28,15 +28,15 @@ public class BlockIndexer{
private final ObjectSet<Item> itemSet = new ObjectSet<>();
/** Stores all ore quadtrants on the map. */
private ObjectMap<Item, ObjectSet<Tile>> ores = new ObjectMap<>();
/** Tags all quadrants. */
/** 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 ObjectSet<Tile>[] damagedTiles = new ObjectSet[Team.all.length];
private ObjectSet<Tile>[] damagedTiles = new ObjectSet[Team.all().length];
/**All ores available on this map.*/
private ObjectSet<Item> allOres = new ObjectSet<>();
/** Maps teams to a map of flagged tiles by type. */
private ObjectSet<Tile>[][] flagMap = new ObjectSet[Team.all.length][BlockFlag.all.length];
private ObjectSet<Tile>[][] flagMap = new ObjectSet[Team.all().length][BlockFlag.all.length];
/** Maps tile positions to their last known tile index data. */
private IntMap<TileIndex> typeMap = new IntMap<>();
/** Empty set used for returning. */
@ -59,8 +59,8 @@ public class BlockIndexer{
Events.on(WorldLoadEvent.class, event -> {
scanOres.clear();
scanOres.addAll(Item.getAllOres());
damagedTiles = new ObjectSet[Team.all.length];
flagMap = new ObjectSet[Team.all.length][BlockFlag.all.length];
damagedTiles = new ObjectSet[Team.all().length];
flagMap = new ObjectSet[Team.all().length][BlockFlag.all.length];
for(int i = 0; i < flagMap.length; i++){
for(int j = 0; j < BlockFlag.all.length; j++){
@ -73,10 +73,7 @@ public class BlockIndexer{
ores = null;
//create bitset for each team type that contains each quadrant
structQuadrants = new GridBits[Team.all.length];
for(int i = 0; i < Team.all.length; i++){
structQuadrants[i] = new GridBits(Mathf.ceil(world.width() / (float)quadrantSize), Mathf.ceil(world.height() / (float)quadrantSize));
}
structQuadrants = new GridBits[Team.all().length];
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
@ -103,7 +100,29 @@ public class BlockIndexer{
}
private ObjectSet<Tile>[] getFlagged(Team team){
return flagMap[(int)team.id];
return flagMap[team.id];
}
private GridBits structQuadrant(Team t){
if(structQuadrants[t.id] == null){
structQuadrants[t.id] = new GridBits(Mathf.ceil(world.width() / (float)quadrantSize), Mathf.ceil(world.height() / (float)quadrantSize));
}
return structQuadrants[t.id];
}
/** Updates all the structure quadrants for a newly activated team. */
public void updateTeamIndex(Team team){
//go through every tile... ouch
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
Tile tile = world.tile(x, y);
if(tile.getTeam() == team){
int quadrantX = tile.x / quadrantSize;
int quadrantY = tile.y / quadrantSize;
structQuadrant(team).set(quadrantX, quadrantY);
}
}
}
}
/** @return whether this item is present on this map.*/
@ -115,11 +134,11 @@ public class BlockIndexer{
public ObjectSet<Tile> getDamaged(Team team){
returnArray.clear();
if(damagedTiles[(int)team.id] == null){
damagedTiles[(int)team.id] = new ObjectSet<>();
if(damagedTiles[team.id] == null){
damagedTiles[team.id] = new ObjectSet<>();
}
ObjectSet<Tile> set = damagedTiles[(int)team.id];
ObjectSet<Tile> set = damagedTiles[team.id];
for(Tile tile : set){
if((tile.entity == null || tile.entity.getTeam() != team || !tile.entity.damaged()) || tile.block() instanceof BuildBlock){
returnArray.add(tile);
@ -135,7 +154,7 @@ public class BlockIndexer{
/** Get all allied blocks with a flag. */
public ObjectSet<Tile> getAllied(Team team, BlockFlag type){
return flagMap[(int)team.id][type.ordinal()];
return flagMap[team.id][type.ordinal()];
}
/** Get all enemy blocks with a flag. */
@ -282,16 +301,16 @@ public class BlockIndexer{
int quadrantY = tile.y / quadrantSize;
int index = quadrantX + quadrantY * quadWidth();
for(Team team : Team.all){
TeamData data = state.teams.get(team);
for(TeamData data : state.teams.getActive()){
GridBits bits = structQuadrant(data.team);
//fast-set this quadrant to 'occupied' if the tile just placed is already of this team
if(tile.getTeam() == data.team && tile.entity != null && tile.block().targetable){
structQuadrants[(int)data.team.id].set(quadrantX, quadrantY);
bits.set(quadrantX, quadrantY);
continue; //no need to process futher
}
structQuadrants[(int)data.team.id].set(quadrantX, quadrantY, false);
bits.set(quadrantX, quadrantY, false);
outer:
for(int x = quadrantX * quadrantSize; x < world.width() && x < (quadrantX + 1) * quadrantSize; x++){
@ -299,7 +318,7 @@ public class BlockIndexer{
Tile result = world.ltile(x, y);
//when a targetable block is found, mark this quadrant as occupied and stop searching
if(result.entity != null && result.getTeam() == data.team){
structQuadrants[(int)data.team.id].set(quadrantX, quadrantY);
bits.set(quadrantX, quadrantY);
break outer;
}
}
@ -308,7 +327,7 @@ public class BlockIndexer{
}
private boolean getQuad(Team team, int quadrantX, int quadrantY){
return structQuadrants[(int)team.id].get(quadrantX, quadrantY);
return structQuadrant(team).get(quadrantX, quadrantY);
}
private int quadWidth(){

View File

@ -27,9 +27,9 @@ public class Pathfinder implements Runnable{
/** unordered array of path data for iteration only. DO NOT iterate ot access this in the main thread.*/
private Array<PathData> list = new Array<>();
/** Maps teams + flags to a valid path to get to that flag for that team. */
private PathData[][] pathMap = new PathData[Team.all.length][PathTarget.all.length];
private PathData[][] pathMap = new PathData[Team.all().length][PathTarget.all.length];
/** Grid map of created path data that should not be queued again. */
private GridBits created = new GridBits(Team.all.length, PathTarget.all.length);
private GridBits created = new GridBits(Team.all().length, PathTarget.all.length);
/** handles task scheduling on the update thread. */
private TaskQueue queue = new TaskQueue();
/** current pathfinding thread */
@ -42,8 +42,8 @@ public class Pathfinder implements Runnable{
//reset and update internal tile array
tiles = new int[world.width()][world.height()];
pathMap = new PathData[Team.all.length][PathTarget.all.length];
created = new GridBits(Team.all.length, PathTarget.all.length);
pathMap = new PathData[Team.all().length][PathTarget.all.length];
created = new GridBits(Team.all().length, PathTarget.all.length);
list = new Array<>();
for(int x = 0; x < world.width(); x++){
@ -84,8 +84,8 @@ public class Pathfinder implements Runnable{
}
public int debugValue(Team team, int x, int y){
if(pathMap[(int)team.id][PathTarget.enemyCores.ordinal()] == null) return 0;
return pathMap[(int)team.id][PathTarget.enemyCores.ordinal()].weights[x][y];
if(pathMap[team.id][PathTarget.enemyCores.ordinal()] == null) return 0;
return pathMap[team.id][PathTarget.enemyCores.ordinal()].weights[x][y];
}
/** Update a tile in the internal pathfinding grid. Causes a complete pathfinding reclaculation. */
@ -149,12 +149,12 @@ public class Pathfinder implements Runnable{
public Tile getTargetTile(Tile tile, Team team, PathTarget target){
if(tile == null) return null;
PathData data = pathMap[(int)team.id][target.ordinal()];
PathData data = pathMap[team.id][target.ordinal()];
if(data == null){
//if this combination is not found, create it on request
if(!created.get((int)team.id, target.ordinal())){
created.set((int)team.id, target.ordinal());
if(!created.get(team.id, target.ordinal())){
created.set(team.id, target.ordinal());
//grab targets since this is run on main thread
IntArray targets = target.getTargets(team, new IntArray());
queue.post(() -> createPath(team, target, targets));
@ -188,7 +188,7 @@ public class Pathfinder implements Runnable{
/** @return whether a tile can be passed through by this team. Pathfinding thread only.*/
private boolean passable(int x, int y, Team team){
int tile = tiles[x][y];
return PathTile.passable(tile) || (PathTile.team(tile) != (int)team.id && PathTile.team(tile) != (int)Team.derelict.id);
return PathTile.passable(tile) || (PathTile.team(tile) != team.id && PathTile.team(tile) != (int)Team.derelict.id);
}
/**
@ -238,7 +238,7 @@ public class Pathfinder implements Runnable{
PathData path = new PathData(team, target, world.width(), world.height());
list.add(path);
pathMap[(int)team.id][target.ordinal()] = path;
pathMap[team.id][target.ordinal()] = path;
//grab targets from passed array
synchronized(path.targets){

View File

@ -11,7 +11,7 @@ import mindustry.content.Blocks;
import mindustry.content.Fx;
import mindustry.entities.Damage;
import mindustry.entities.Effects;
import mindustry.entities.type.BaseUnit;
import mindustry.entities.type.*;
import mindustry.game.EventType.WorldLoadEvent;
import mindustry.game.SpawnGroup;
import mindustry.world.Tile;
@ -91,10 +91,10 @@ public class WaveSpawner{
}
if(state.rules.attackMode && state.teams.isActive(state.rules.waveTeam) && !state.teams.playerCores().isEmpty()){
Tile firstCore = state.teams.playerCores().first();
for(Tile core : state.teams.get(state.rules.waveTeam).cores){
Tmp.v1.set(firstCore).sub(core.worldx(), core.worldy()).limit(coreMargin + core.block().size*tilesize);
cons.accept(core.worldx() + Tmp.v1.x, core.worldy() + Tmp.v1.y, false);
TileEntity firstCore = state.teams.playerCores().first();
for(TileEntity core : state.teams.get(state.rules.waveTeam).cores){
Tmp.v1.set(firstCore).sub(core.x, core.y).limit(coreMargin + core.block.size*tilesize);
cons.accept(core.x + Tmp.v1.x, core.y + Tmp.v1.y, false);
}
}
}
@ -108,8 +108,8 @@ public class WaveSpawner{
}
if(state.rules.attackMode && state.teams.isActive(state.rules.waveTeam)){
for(Tile core : state.teams.get(state.rules.waveTeam).cores){
cons.get(core.worldx(), core.worldy());
for(TileEntity core : state.teams.get(state.rules.waveTeam).cores){
cons.get(core.x, core.y);
}
}
}

View File

@ -74,7 +74,7 @@ public class EditorTile extends Tile{
return;
}
if(getTeamID() == (int)team.id) return;
if(getTeamID() == team.id) return;
op(OpType.team, getTeamID());
super.setTeam(team);
}

View File

@ -415,7 +415,7 @@ public class MapGenerateDialog extends FloatingDialog{
this.floor = floor.id;
this.block = wall.id;
this.ore = ore.id;
this.team = (byte) (int)team.id;
this.team = (byte) team.id;
this.rotation = (byte)rotation;
}

View File

@ -88,7 +88,7 @@ public class Damage{
tr.trns(angle, length);
Intc2 collider = (cx, cy) -> {
Tile tile = world.ltile(cx, cy);
if(tile != null && !collidedBlocks.contains(tile.pos()) && tile.entity != null && tile.getTeamID() != (int)team.id && tile.entity.collide(hitter)){
if(tile != null && !collidedBlocks.contains(tile.pos()) && tile.entity != null && tile.getTeamID() != team.id && tile.entity.collide(hitter)){
tile.entity.collision(hitter);
collidedBlocks.add(tile.pos());
hitter.getBulletType().hit(hitter, tile.worldx(), tile.worldy());

View File

@ -1,15 +1,12 @@
package mindustry.entities;
import arc.struct.EnumSet;
import arc.func.Cons;
import arc.func.Boolf;
import arc.math.Mathf;
import arc.math.geom.Geometry;
import arc.math.geom.Rectangle;
import mindustry.entities.traits.TargetTrait;
import arc.func.*;
import arc.math.*;
import arc.math.geom.*;
import mindustry.entities.traits.*;
import mindustry.entities.type.*;
import mindustry.game.Team;
import mindustry.world.Tile;
import mindustry.game.*;
import mindustry.world.*;
import static mindustry.Vars.*;
@ -157,7 +154,11 @@ public class Units{
/** Iterates over all units in a rectangle. */
public static void nearby(Team team, float x, float y, float width, float height, Cons<Unit> cons){
unitGroups[(int)team.id].intersect(x, y, width, height, cons);
unitGroup.intersect(x, y, width, height, u -> {
if(u.getTeam() == team){
cons.get(u);
}
});
playerGroup.intersect(x, y, width, height, player -> {
if(player.getTeam() == team){
cons.get(player);
@ -167,8 +168,8 @@ public class Units{
/** Iterates over all units in a circle around this position. */
public static void nearby(Team team, float x, float y, float radius, Cons<Unit> cons){
unitGroups[(int)team.id].intersect(x - radius, y - radius, radius*2f, radius*2f, unit -> {
if(unit.withinDst(x, y, radius)){
unitGroup.intersect(x - radius, y - radius, radius*2f, radius*2f, unit -> {
if(unit.getTeam() == team && unit.withinDst(x, y, radius)){
cons.get(unit);
}
});
@ -182,10 +183,7 @@ public class Units{
/** Iterates over all units in a rectangle. */
public static void nearby(float x, float y, float width, float height, Cons<Unit> cons){
for(Team team : Team.all){
unitGroups[(int)team.id].intersect(x, y, width, height, cons);
}
unitGroup.intersect(x, y, width, height, cons);
playerGroup.intersect(x, y, width, height, cons);
}
@ -196,14 +194,14 @@ public class Units{
/** Iterates over all units that are enemies of this team. */
public static void nearbyEnemies(Team team, float x, float y, float width, float height, Cons<Unit> cons){
EnumSet<Team> targets = state.teams.enemiesOf(team);
for(Team other : targets){
unitGroups[(int)other.id].intersect(x, y, width, height, cons);
}
unitGroup.intersect(x, y, width, height, u -> {
if(state.teams.areEnemies(team, u.getTeam())){
cons.get(u);
}
});
playerGroup.intersect(x, y, width, height, player -> {
if(targets.contains(player.getTeam())){
if(state.teams.areEnemies(team, player.getTeam())){
cons.get(player);
}
});
@ -220,4 +218,8 @@ public class Units{
playerGroup.all().each(cons);
}
public static void each(Team team, Cons<BaseUnit> cons){
unitGroup.all().each(t -> t.getTeam() == team, cons);
}
}

View File

@ -167,7 +167,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
public void writeSave(DataOutput stream, boolean net) throws IOException{
if(item.item == null) item.item = Items.copper;
stream.writeByte((int)team.id);
stream.writeByte(team.id);
stream.writeBoolean(isDead());
stream.writeFloat(net ? interpolator.target.x : x);
stream.writeFloat(net ? interpolator.target.y : y);

View File

@ -114,12 +114,10 @@ public class BuilderDrone extends BaseDrone implements BuilderTrait{
public BuilderDrone(){
if(reset.check()){
Events.on(BuildSelectEvent.class, event -> {
EntityGroup<BaseUnit> group = unitGroups[(int)event.team.id];
if(!(event.tile.entity instanceof BuildEntity)) return;
for(BaseUnit unit : group.all()){
if(unit instanceof BuilderDrone){
for(BaseUnit unit : unitGroup.all()){
if(unit instanceof BuilderDrone && unit.getTeam() == getTeam()){
BuilderDrone drone = (BuilderDrone)unit;
if(drone.isBuilding()){
//stop building if opposite building begins.

View File

@ -6,10 +6,9 @@ import arc.util.*;
import mindustry.graphics.*;
public class Team implements Comparable<Team>{
public final Color color;
public final int intColor;
public final String name;
public final byte id;
public final Color color;
public String name;
/** All 256 registered teams. */
private static final Team[] all = new Team[256];
@ -48,7 +47,6 @@ public class Team implements Comparable<Team>{
protected Team(int id, String name, Color color){
this.name = name;
this.color = color;
this.intColor = Color.rgba8888(color);
this.id = (byte)id;
int us = Pack.u(this.id);

View File

@ -3,12 +3,12 @@ package mindustry.game;
import arc.func.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.entities.type.*;
import mindustry.world.blocks.storage.CoreBlock.*;
import static mindustry.Vars.state;
import static mindustry.Vars.*;
/** Class for various team-based utilities. */
public class Teams{
@ -33,6 +33,10 @@ public class Teams{
return Geometry.findClosest(x, y, get(team).cores);
}
public Array<Team> enemiesOf(Team team){
return get(team).enemies;
}
public boolean eachEnemyCore(Team team, Boolf<CoreEntity> ret){
for(TeamData data : active){
if(areEnemies(team, data.team)){
@ -104,6 +108,8 @@ public class Teams{
//register in active list if needed
if(data.active() && !active.contains(data)){
active.add(data);
updateEnemies();
indexer.updateTeamIndex(data.team);
}
}
@ -114,12 +120,24 @@ public class Teams{
//unregister in active list
if(!data.active()){
active.remove(data);
updateEnemies();
}
}
private void updateEnemies(){
for(TeamData data : active){
data.enemies.clear();
for(TeamData other : active){
if(areEnemies(data.team, other.team)){
data.enemies.add(other.team);
}
}
}
}
public class TeamData{
private final Array<CoreEntity> cores = new Array<>();
public final Array<CoreEntity> cores = new Array<>();
public final Array<Team> enemies = new Array<>();
public final Team team;
public Queue<BrokenBlock> brokenBlocks = new Queue<>();

View File

@ -92,7 +92,7 @@ public class MapIO{
public void setTeam(Team team){
super.setTeam(team);
if(block instanceof CoreBlock){
map.teams.add((int)team.id);
map.teams.add(team.id);
}
}
};
@ -146,7 +146,7 @@ public class MapIO{
public static int colorFor(Block floor, Block wall, Block ore, Team team){
if(wall.synthetic()){
return team.intColor;
return team.color.rgba();
}
return Color.rgba8888(wall.solid ? wall.color : ore == Blocks.air ? floor.color : ore.color);
}

View File

@ -146,7 +146,7 @@ public class Tile implements Position, TargetTrait{
}
public void setTeam(Team team){
this.team = (byte) (int)team.id;
this.team = (byte) team.id;
}
public byte getTeamID(){
@ -156,7 +156,7 @@ public class Tile implements Position, TargetTrait{
public void setBlock(@NonNull Block type, Team team, int rotation){
preChanged();
this.block = type;
this.team = (byte) (int)team.id;
this.team = (byte) team.id;
this.rotation = (byte)Mathf.mod(rotation, 4);
changed();
}

View File

@ -57,7 +57,7 @@ public class BuildBlock extends Block{
public static void onDeconstructFinish(Tile tile, Block block, int builderID){
Team team = tile.getTeam();
Effects.effect(Fx.breakBlock, tile.drawx(), tile.drawy(), block.size);
world.removeBlock(tile);
tile.remove();
Events.fire(new BlockBuildEndEvent(tile, playerGroup.getByID(builderID), team, true));
if(shouldPlay()) Sounds.breaks.at(tile, calcPitch(false));
}

View File

@ -1,11 +1,11 @@
package mindustry.world.blocks.units;
import arc.*;
import arc.struct.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.*;
@ -13,7 +13,6 @@ import mindustry.entities.Effects.*;
import mindustry.entities.type.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.graphics.*;
import mindustry.ui.*;
import mindustry.world.*;
@ -21,7 +20,7 @@ import mindustry.world.meta.*;
import java.io.*;
import static mindustry.Vars.*;
import static mindustry.Vars.indexer;
public class CommandCenter extends Block{
protected TextureRegion[] commandRegions = new TextureRegion[UnitCommand.all.length];
@ -58,9 +57,7 @@ public class CommandCenter extends Block{
ObjectSet<Tile> set = indexer.getAllied(tile.getTeam(), BlockFlag.comandCenter);
if(set.size == 1){
for(BaseUnit unit : unitGroups[(int)tile.getTeam().id].all()){
unit.onCommand(UnitCommand.all[0]);
}
Units.each(tile.getTeam(), u -> u.onCommand(UnitCommand.all[0]));
}
}
@ -114,12 +111,7 @@ public class CommandCenter extends Block{
}
}
Team team = (player == null ? tile.getTeam() : player.getTeam());
for(BaseUnit unit : unitGroups[(int)team.id].all()){
unit.onCommand(command);
}
Units.each(tile.getTeam(), u -> u.onCommand(command));
Events.fire(new CommandIssueEvent(tile, command));
}

View File

@ -33,7 +33,7 @@ task run(dependsOn: classes, type: JavaExec){
}
if(args.contains("debug")){
main = "io.anuke.mindustry.DebugLauncher"
main = "mindustry.debug.DebugLauncher"
}
}

View File

@ -1,9 +1,9 @@
package mindustry.desktop.steam;
import arc.*;
import com.codedisaster.steamworks.*;
import arc.struct.*;
import arc.util.*;
import com.codedisaster.steamworks.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.entities.type.*;
@ -11,7 +11,6 @@ import mindustry.entities.units.*;
import mindustry.game.EventType.*;
import mindustry.game.Stats.*;
import mindustry.type.*;
import mindustry.world.*;
import static mindustry.Vars.*;
import static mindustry.desktop.steam.SAchievement.*;
@ -55,18 +54,18 @@ public class SStats implements SteamUserStatsCallback{
private void checkUpdate(){
if(campaign()){
SStat.maxUnitActive.max(unitGroups[(int)player.getTeam().id].size());
SStat.maxUnitActive.max(unitGroup.count(t -> t.getTeam() == player.getTeam()));
if(unitGroups[(int)player.getTeam().id].count(u -> u.getType() == UnitTypes.phantom) >= 10){
if(unitGroup.count(u -> u.getType() == UnitTypes.phantom && u.getTeam() == player.getTeam()) >= 10){
active10Phantoms.complete();
}
if(unitGroups[(int)player.getTeam().id].count(u -> u.getType() == UnitTypes.crawler) >= 50){
if(unitGroup.count(u -> u.getType() == UnitTypes.crawler && u.getTeam() == player.getTeam()) >= 50){
active50Crawlers.complete();
}
for(Tile tile : state.teams.get(player.getTeam()).cores){
if(!content.items().contains(i -> i.type == ItemType.material && tile.entity.items.get(i) < tile.block().itemCapacity)){
for(TileEntity entity : state.teams.get(player.getTeam()).cores){
if(!content.items().contains(i -> i.type == ItemType.material && entity.items.get(i) < entity.block.itemCapacity)){
fillCoreAllCampaign.complete();
break;
}

View File

@ -1,3 +1,3 @@
org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=447f3bb0e4616f82680f3234ad4e0cce48880884
archash=44e060c9f2bf11eb7e41f79d967fdfeca9f8b62a