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
+40 -21
View File
@@ -1,10 +1,10 @@
package mindustry.ai; package mindustry.ai;
import arc.*; import arc.*;
import arc.struct.*;
import arc.func.*; import arc.func.*;
import arc.math.*; import arc.math.*;
import arc.math.geom.*; import arc.math.geom.*;
import arc.struct.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.entities.type.*; import mindustry.entities.type.*;
import mindustry.game.EventType.*; import mindustry.game.EventType.*;
@@ -28,15 +28,15 @@ public class BlockIndexer{
private final ObjectSet<Item> itemSet = new ObjectSet<>(); 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 = new ObjectMap<>(); 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; private GridBits[] structQuadrants;
/** Stores all damaged tile entities by team. */ /** 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.*/ /**All ores available on this map.*/
private ObjectSet<Item> allOres = new ObjectSet<>(); private ObjectSet<Item> allOres = new ObjectSet<>();
/** 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]; 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<>(); private IntMap<TileIndex> typeMap = new IntMap<>();
/** Empty set used for returning. */ /** Empty set used for returning. */
@@ -59,8 +59,8 @@ public class BlockIndexer{
Events.on(WorldLoadEvent.class, event -> { Events.on(WorldLoadEvent.class, event -> {
scanOres.clear(); scanOres.clear();
scanOres.addAll(Item.getAllOres()); scanOres.addAll(Item.getAllOres());
damagedTiles = new ObjectSet[Team.all.length]; damagedTiles = new ObjectSet[Team.all().length];
flagMap = new ObjectSet[Team.all.length][BlockFlag.all.length]; flagMap = new ObjectSet[Team.all().length][BlockFlag.all.length];
for(int i = 0; i < flagMap.length; i++){ for(int i = 0; i < flagMap.length; i++){
for(int j = 0; j < BlockFlag.all.length; j++){ for(int j = 0; j < BlockFlag.all.length; j++){
@@ -73,10 +73,7 @@ public class BlockIndexer{
ores = null; ores = null;
//create bitset for each team type that contains each quadrant //create bitset for each team type that contains each quadrant
structQuadrants = new GridBits[Team.all.length]; 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));
}
for(int x = 0; x < world.width(); x++){ for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){ for(int y = 0; y < world.height(); y++){
@@ -103,7 +100,29 @@ public class BlockIndexer{
} }
private ObjectSet<Tile>[] getFlagged(Team team){ 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.*/ /** @return whether this item is present on this map.*/
@@ -115,11 +134,11 @@ public class BlockIndexer{
public ObjectSet<Tile> getDamaged(Team team){ public ObjectSet<Tile> getDamaged(Team team){
returnArray.clear(); returnArray.clear();
if(damagedTiles[(int)team.id] == null){ if(damagedTiles[team.id] == null){
damagedTiles[(int)team.id] = new ObjectSet<>(); damagedTiles[team.id] = new ObjectSet<>();
} }
ObjectSet<Tile> set = damagedTiles[(int)team.id]; ObjectSet<Tile> set = damagedTiles[team.id];
for(Tile tile : set){ for(Tile tile : set){
if((tile.entity == null || tile.entity.getTeam() != team || !tile.entity.damaged()) || tile.block() instanceof BuildBlock){ if((tile.entity == null || tile.entity.getTeam() != team || !tile.entity.damaged()) || tile.block() instanceof BuildBlock){
returnArray.add(tile); returnArray.add(tile);
@@ -135,7 +154,7 @@ public class BlockIndexer{
/** Get all allied blocks with a flag. */ /** Get all allied blocks with a flag. */
public ObjectSet<Tile> getAllied(Team team, BlockFlag type){ 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. */ /** Get all enemy blocks with a flag. */
@@ -282,16 +301,16 @@ public class BlockIndexer{
int quadrantY = tile.y / quadrantSize; int quadrantY = tile.y / quadrantSize;
int index = quadrantX + quadrantY * quadWidth(); int index = quadrantX + quadrantY * quadWidth();
for(Team team : Team.all){ for(TeamData data : state.teams.getActive()){
TeamData data = state.teams.get(team); GridBits bits = structQuadrant(data.team);
//fast-set this quadrant to 'occupied' if the tile just placed is already of this 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){ 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 continue; //no need to process futher
} }
structQuadrants[(int)data.team.id].set(quadrantX, quadrantY, false); bits.set(quadrantX, quadrantY, false);
outer: outer:
for(int x = quadrantX * quadrantSize; x < world.width() && x < (quadrantX + 1) * quadrantSize; x++){ 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); Tile result = world.ltile(x, y);
//when a targetable block is found, mark this quadrant as occupied and stop searching //when a targetable block is found, mark this quadrant as occupied and stop searching
if(result.entity != null && result.getTeam() == data.team){ if(result.entity != null && result.getTeam() == data.team){
structQuadrants[(int)data.team.id].set(quadrantX, quadrantY); bits.set(quadrantX, quadrantY);
break outer; break outer;
} }
} }
@@ -308,7 +327,7 @@ public class BlockIndexer{
} }
private boolean getQuad(Team team, int quadrantX, int quadrantY){ 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(){ private int quadWidth(){
+11 -11
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.*/ /** unordered array of path data for iteration only. DO NOT iterate ot access this in the main thread.*/
private Array<PathData> list = new Array<>(); private Array<PathData> list = new Array<>();
/** Maps teams + flags to a valid path to get to that flag for that team. */ /** 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. */ /** 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. */ /** handles task scheduling on the update thread. */
private TaskQueue queue = new TaskQueue(); private TaskQueue queue = new TaskQueue();
/** current pathfinding thread */ /** current pathfinding thread */
@@ -42,8 +42,8 @@ public class Pathfinder implements Runnable{
//reset and update internal tile array //reset and update internal tile array
tiles = new int[world.width()][world.height()]; tiles = new int[world.width()][world.height()];
pathMap = new PathData[Team.all.length][PathTarget.all.length]; pathMap = new PathData[Team.all().length][PathTarget.all.length];
created = new GridBits(Team.all.length, PathTarget.all.length); created = new GridBits(Team.all().length, PathTarget.all.length);
list = new Array<>(); list = new Array<>();
for(int x = 0; x < world.width(); x++){ 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){ public int debugValue(Team team, int x, int y){
if(pathMap[(int)team.id][PathTarget.enemyCores.ordinal()] == null) return 0; if(pathMap[team.id][PathTarget.enemyCores.ordinal()] == null) return 0;
return pathMap[(int)team.id][PathTarget.enemyCores.ordinal()].weights[x][y]; return pathMap[team.id][PathTarget.enemyCores.ordinal()].weights[x][y];
} }
/** Update a tile in the internal pathfinding grid. Causes a complete pathfinding reclaculation. */ /** 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){ public Tile getTargetTile(Tile tile, Team team, PathTarget target){
if(tile == null) return null; if(tile == null) return null;
PathData data = pathMap[(int)team.id][target.ordinal()]; PathData data = pathMap[team.id][target.ordinal()];
if(data == null){ if(data == null){
//if this combination is not found, create it on request //if this combination is not found, create it on request
if(!created.get((int)team.id, target.ordinal())){ if(!created.get(team.id, target.ordinal())){
created.set((int)team.id, target.ordinal()); created.set(team.id, target.ordinal());
//grab targets since this is run on main thread //grab targets since this is run on main thread
IntArray targets = target.getTargets(team, new IntArray()); IntArray targets = target.getTargets(team, new IntArray());
queue.post(() -> createPath(team, target, targets)); 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.*/ /** @return whether a tile can be passed through by this team. Pathfinding thread only.*/
private boolean passable(int x, int y, Team team){ private boolean passable(int x, int y, Team team){
int tile = tiles[x][y]; 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()); PathData path = new PathData(team, target, world.width(), world.height());
list.add(path); list.add(path);
pathMap[(int)team.id][target.ordinal()] = path; pathMap[team.id][target.ordinal()] = path;
//grab targets from passed array //grab targets from passed array
synchronized(path.targets){ synchronized(path.targets){
+7 -7
View File
@@ -11,7 +11,7 @@ import mindustry.content.Blocks;
import mindustry.content.Fx; import mindustry.content.Fx;
import mindustry.entities.Damage; import mindustry.entities.Damage;
import mindustry.entities.Effects; import mindustry.entities.Effects;
import mindustry.entities.type.BaseUnit; import mindustry.entities.type.*;
import mindustry.game.EventType.WorldLoadEvent; import mindustry.game.EventType.WorldLoadEvent;
import mindustry.game.SpawnGroup; import mindustry.game.SpawnGroup;
import mindustry.world.Tile; 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()){ if(state.rules.attackMode && state.teams.isActive(state.rules.waveTeam) && !state.teams.playerCores().isEmpty()){
Tile firstCore = state.teams.playerCores().first(); TileEntity firstCore = state.teams.playerCores().first();
for(Tile core : state.teams.get(state.rules.waveTeam).cores){ for(TileEntity core : state.teams.get(state.rules.waveTeam).cores){
Tmp.v1.set(firstCore).sub(core.worldx(), core.worldy()).limit(coreMargin + core.block().size*tilesize); Tmp.v1.set(firstCore).sub(core.x, core.y).limit(coreMargin + core.block.size*tilesize);
cons.accept(core.worldx() + Tmp.v1.x, core.worldy() + Tmp.v1.y, false); 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)){ if(state.rules.attackMode && state.teams.isActive(state.rules.waveTeam)){
for(Tile core : state.teams.get(state.rules.waveTeam).cores){ for(TileEntity core : state.teams.get(state.rules.waveTeam).cores){
cons.get(core.worldx(), core.worldy()); cons.get(core.x, core.y);
} }
} }
} }
+1 -1
View File
@@ -74,7 +74,7 @@ public class EditorTile extends Tile{
return; return;
} }
if(getTeamID() == (int)team.id) return; if(getTeamID() == team.id) return;
op(OpType.team, getTeamID()); op(OpType.team, getTeamID());
super.setTeam(team); super.setTeam(team);
} }
@@ -415,7 +415,7 @@ public class MapGenerateDialog extends FloatingDialog{
this.floor = floor.id; this.floor = floor.id;
this.block = wall.id; this.block = wall.id;
this.ore = ore.id; this.ore = ore.id;
this.team = (byte) (int)team.id; this.team = (byte) team.id;
this.rotation = (byte)rotation; this.rotation = (byte)rotation;
} }
+1 -1
View File
@@ -88,7 +88,7 @@ public class Damage{
tr.trns(angle, length); tr.trns(angle, length);
Intc2 collider = (cx, cy) -> { Intc2 collider = (cx, cy) -> {
Tile tile = world.ltile(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); tile.entity.collision(hitter);
collidedBlocks.add(tile.pos()); collidedBlocks.add(tile.pos());
hitter.getBulletType().hit(hitter, tile.worldx(), tile.worldy()); hitter.getBulletType().hit(hitter, tile.worldx(), tile.worldy());
+24 -22
View File
@@ -1,15 +1,12 @@
package mindustry.entities; package mindustry.entities;
import arc.struct.EnumSet; import arc.func.*;
import arc.func.Cons; import arc.math.*;
import arc.func.Boolf; import arc.math.geom.*;
import arc.math.Mathf; import mindustry.entities.traits.*;
import arc.math.geom.Geometry;
import arc.math.geom.Rectangle;
import mindustry.entities.traits.TargetTrait;
import mindustry.entities.type.*; import mindustry.entities.type.*;
import mindustry.game.Team; import mindustry.game.*;
import mindustry.world.Tile; import mindustry.world.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
@@ -157,7 +154,11 @@ public class Units{
/** Iterates over all units in a rectangle. */ /** Iterates over all units in a rectangle. */
public static void nearby(Team team, float x, float y, float width, float height, Cons<Unit> cons){ 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 -> { playerGroup.intersect(x, y, width, height, player -> {
if(player.getTeam() == team){ if(player.getTeam() == team){
cons.get(player); cons.get(player);
@@ -167,8 +168,8 @@ public class Units{
/** Iterates over all units in a circle around this position. */ /** 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){ 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 -> { unitGroup.intersect(x - radius, y - radius, radius*2f, radius*2f, unit -> {
if(unit.withinDst(x, y, radius)){ if(unit.getTeam() == team && unit.withinDst(x, y, radius)){
cons.get(unit); cons.get(unit);
} }
}); });
@@ -182,10 +183,7 @@ public class Units{
/** Iterates over all units in a rectangle. */ /** Iterates over all units in a rectangle. */
public static void nearby(float x, float y, float width, float height, Cons<Unit> cons){ public static void nearby(float x, float y, float width, float height, Cons<Unit> cons){
for(Team team : Team.all){ unitGroup.intersect(x, y, width, height, cons);
unitGroups[(int)team.id].intersect(x, y, width, height, cons);
}
playerGroup.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. */ /** 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){ public static void nearbyEnemies(Team team, float x, float y, float width, float height, Cons<Unit> cons){
EnumSet<Team> targets = state.teams.enemiesOf(team); unitGroup.intersect(x, y, width, height, u -> {
if(state.teams.areEnemies(team, u.getTeam())){
for(Team other : targets){ cons.get(u);
unitGroups[(int)other.id].intersect(x, y, width, height, cons); }
} });
playerGroup.intersect(x, y, width, height, player -> { playerGroup.intersect(x, y, width, height, player -> {
if(targets.contains(player.getTeam())){ if(state.teams.areEnemies(team, player.getTeam())){
cons.get(player); cons.get(player);
} }
}); });
@@ -220,4 +218,8 @@ public class Units{
playerGroup.all().each(cons); playerGroup.all().each(cons);
} }
public static void each(Team team, Cons<BaseUnit> cons){
unitGroup.all().each(t -> t.getTeam() == team, cons);
}
} }
+1 -1
View File
@@ -167,7 +167,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
public void writeSave(DataOutput stream, boolean net) throws IOException{ public void writeSave(DataOutput stream, boolean net) throws IOException{
if(item.item == null) item.item = Items.copper; if(item.item == null) item.item = Items.copper;
stream.writeByte((int)team.id); stream.writeByte(team.id);
stream.writeBoolean(isDead()); stream.writeBoolean(isDead());
stream.writeFloat(net ? interpolator.target.x : x); stream.writeFloat(net ? interpolator.target.x : x);
stream.writeFloat(net ? interpolator.target.y : y); stream.writeFloat(net ? interpolator.target.y : y);
@@ -114,12 +114,10 @@ public class BuilderDrone extends BaseDrone implements BuilderTrait{
public BuilderDrone(){ public BuilderDrone(){
if(reset.check()){ if(reset.check()){
Events.on(BuildSelectEvent.class, event -> { Events.on(BuildSelectEvent.class, event -> {
EntityGroup<BaseUnit> group = unitGroups[(int)event.team.id];
if(!(event.tile.entity instanceof BuildEntity)) return; if(!(event.tile.entity instanceof BuildEntity)) return;
for(BaseUnit unit : group.all()){ for(BaseUnit unit : unitGroup.all()){
if(unit instanceof BuilderDrone){ if(unit instanceof BuilderDrone && unit.getTeam() == getTeam()){
BuilderDrone drone = (BuilderDrone)unit; BuilderDrone drone = (BuilderDrone)unit;
if(drone.isBuilding()){ if(drone.isBuilding()){
//stop building if opposite building begins. //stop building if opposite building begins.
+2 -4
View File
@@ -6,10 +6,9 @@ import arc.util.*;
import mindustry.graphics.*; import mindustry.graphics.*;
public class Team implements Comparable<Team>{ public class Team implements Comparable<Team>{
public final Color color;
public final int intColor;
public final String name;
public final byte id; public final byte id;
public final Color color;
public String name;
/** All 256 registered teams. */ /** All 256 registered teams. */
private static final Team[] all = new Team[256]; 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){ protected Team(int id, String name, Color color){
this.name = name; this.name = name;
this.color = color; this.color = color;
this.intColor = Color.rgba8888(color);
this.id = (byte)id; this.id = (byte)id;
int us = Pack.u(this.id); int us = Pack.u(this.id);
+22 -4
View File
@@ -3,12 +3,12 @@ package mindustry.game;
import arc.func.*; import arc.func.*;
import arc.math.geom.*; import arc.math.geom.*;
import arc.struct.*; import arc.struct.*;
import arc.util.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.entities.type.*; import mindustry.entities.type.*;
import mindustry.world.blocks.storage.CoreBlock.*; import mindustry.world.blocks.storage.CoreBlock.*;
import static mindustry.Vars.state; import static mindustry.Vars.*;
/** Class for various team-based utilities. */ /** Class for various team-based utilities. */
public class Teams{ public class Teams{
@@ -33,6 +33,10 @@ public class Teams{
return Geometry.findClosest(x, y, get(team).cores); 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){ public boolean eachEnemyCore(Team team, Boolf<CoreEntity> ret){
for(TeamData data : active){ for(TeamData data : active){
if(areEnemies(team, data.team)){ if(areEnemies(team, data.team)){
@@ -104,6 +108,8 @@ public class Teams{
//register in active list if needed //register in active list if needed
if(data.active() && !active.contains(data)){ if(data.active() && !active.contains(data)){
active.add(data); active.add(data);
updateEnemies();
indexer.updateTeamIndex(data.team);
} }
} }
@@ -114,12 +120,24 @@ public class Teams{
//unregister in active list //unregister in active list
if(!data.active()){ if(!data.active()){
active.remove(data); 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{ 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 final Team team;
public Queue<BrokenBlock> brokenBlocks = new Queue<>(); public Queue<BrokenBlock> brokenBlocks = new Queue<>();
+2 -2
View File
@@ -92,7 +92,7 @@ public class MapIO{
public void setTeam(Team team){ public void setTeam(Team team){
super.setTeam(team); super.setTeam(team);
if(block instanceof CoreBlock){ 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){ public static int colorFor(Block floor, Block wall, Block ore, Team team){
if(wall.synthetic()){ if(wall.synthetic()){
return team.intColor; return team.color.rgba();
} }
return Color.rgba8888(wall.solid ? wall.color : ore == Blocks.air ? floor.color : ore.color); return Color.rgba8888(wall.solid ? wall.color : ore == Blocks.air ? floor.color : ore.color);
} }
+2 -2
View File
@@ -146,7 +146,7 @@ public class Tile implements Position, TargetTrait{
} }
public void setTeam(Team team){ public void setTeam(Team team){
this.team = (byte) (int)team.id; this.team = (byte) team.id;
} }
public byte getTeamID(){ public byte getTeamID(){
@@ -156,7 +156,7 @@ public class Tile implements Position, TargetTrait{
public void setBlock(@NonNull Block type, Team team, int rotation){ public void setBlock(@NonNull Block type, Team team, int rotation){
preChanged(); preChanged();
this.block = type; this.block = type;
this.team = (byte) (int)team.id; this.team = (byte) team.id;
this.rotation = (byte)Mathf.mod(rotation, 4); this.rotation = (byte)Mathf.mod(rotation, 4);
changed(); changed();
} }
@@ -57,7 +57,7 @@ public class BuildBlock extends Block{
public static void onDeconstructFinish(Tile tile, Block block, int builderID){ public static void onDeconstructFinish(Tile tile, Block block, int builderID){
Team team = tile.getTeam(); Team team = tile.getTeam();
Effects.effect(Fx.breakBlock, tile.drawx(), tile.drawy(), block.size); 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)); Events.fire(new BlockBuildEndEvent(tile, playerGroup.getByID(builderID), team, true));
if(shouldPlay()) Sounds.breaks.at(tile, calcPitch(false)); if(shouldPlay()) Sounds.breaks.at(tile, calcPitch(false));
} }
@@ -1,11 +1,11 @@
package mindustry.world.blocks.units; package mindustry.world.blocks.units;
import arc.*; import arc.*;
import arc.struct.*;
import arc.graphics.*; import arc.graphics.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.scene.ui.*; import arc.scene.ui.*;
import arc.scene.ui.layout.*; import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*; import arc.util.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.entities.*; import mindustry.entities.*;
@@ -13,7 +13,6 @@ import mindustry.entities.Effects.*;
import mindustry.entities.type.*; import mindustry.entities.type.*;
import mindustry.entities.units.*; import mindustry.entities.units.*;
import mindustry.game.EventType.*; import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.ui.*; import mindustry.ui.*;
import mindustry.world.*; import mindustry.world.*;
@@ -21,7 +20,7 @@ import mindustry.world.meta.*;
import java.io.*; import java.io.*;
import static mindustry.Vars.*; import static mindustry.Vars.indexer;
public class CommandCenter extends Block{ public class CommandCenter extends Block{
protected TextureRegion[] commandRegions = new TextureRegion[UnitCommand.all.length]; 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); ObjectSet<Tile> set = indexer.getAllied(tile.getTeam(), BlockFlag.comandCenter);
if(set.size == 1){ if(set.size == 1){
for(BaseUnit unit : unitGroups[(int)tile.getTeam().id].all()){ Units.each(tile.getTeam(), u -> u.onCommand(UnitCommand.all[0]));
unit.onCommand(UnitCommand.all[0]);
}
} }
} }
@@ -114,12 +111,7 @@ public class CommandCenter extends Block{
} }
} }
Team team = (player == null ? tile.getTeam() : player.getTeam()); Units.each(tile.getTeam(), u -> u.onCommand(command));
for(BaseUnit unit : unitGroups[(int)team.id].all()){
unit.onCommand(command);
}
Events.fire(new CommandIssueEvent(tile, command)); Events.fire(new CommandIssueEvent(tile, command));
} }
+1 -1
View File
@@ -33,7 +33,7 @@ task run(dependsOn: classes, type: JavaExec){
} }
if(args.contains("debug")){ if(args.contains("debug")){
main = "io.anuke.mindustry.DebugLauncher" main = "mindustry.debug.DebugLauncher"
} }
} }
@@ -1,9 +1,9 @@
package mindustry.desktop.steam; package mindustry.desktop.steam;
import arc.*; import arc.*;
import com.codedisaster.steamworks.*;
import arc.struct.*; import arc.struct.*;
import arc.util.*; import arc.util.*;
import com.codedisaster.steamworks.*;
import mindustry.*; import mindustry.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.entities.type.*; import mindustry.entities.type.*;
@@ -11,7 +11,6 @@ import mindustry.entities.units.*;
import mindustry.game.EventType.*; import mindustry.game.EventType.*;
import mindustry.game.Stats.*; import mindustry.game.Stats.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
import static mindustry.desktop.steam.SAchievement.*; import static mindustry.desktop.steam.SAchievement.*;
@@ -55,18 +54,18 @@ public class SStats implements SteamUserStatsCallback{
private void checkUpdate(){ private void checkUpdate(){
if(campaign()){ 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(); 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(); active50Crawlers.complete();
} }
for(Tile tile : state.teams.get(player.getTeam()).cores){ for(TileEntity entity : state.teams.get(player.getTeam()).cores){
if(!content.items().contains(i -> i.type == ItemType.material && tile.entity.items.get(i) < tile.block().itemCapacity)){ if(!content.items().contains(i -> i.type == ItemType.material && entity.items.get(i) < entity.block.itemCapacity)){
fillCoreAllCampaign.complete(); fillCoreAllCampaign.complete();
break; break;
} }
+1 -1
View File
@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=447f3bb0e4616f82680f3234ad4e0cce48880884 archash=44e060c9f2bf11eb7e41f79d967fdfeca9f8b62a