Made team a separate class
This commit is contained in:
@@ -242,7 +242,7 @@ public class Vars implements Loadable{
|
|||||||
unitGroups = new EntityGroup[Team.all.length];
|
unitGroups = new EntityGroup[Team.all.length];
|
||||||
|
|
||||||
for(Team team : Team.all){
|
for(Team team : Team.all){
|
||||||
unitGroups[team.ordinal()] = entities.add(BaseUnit.class).enableMapping();
|
unitGroups[(int) team.id] = entities.add(BaseUnit.class).enableMapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(EntityGroup<?> group : entities.all()){
|
for(EntityGroup<?> group : entities.all()){
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ public class BlockIndexer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ObjectSet<Tile>[] getFlagged(Team team){
|
private ObjectSet<Tile>[] getFlagged(Team team){
|
||||||
return flagMap[team.ordinal()];
|
return flagMap[(int) team.id];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return whether this item is present on this map.*/
|
/** @return whether this item is present on this map.*/
|
||||||
@@ -115,11 +115,11 @@ public class BlockIndexer{
|
|||||||
public ObjectSet<Tile> getDamaged(Team team){
|
public ObjectSet<Tile> getDamaged(Team team){
|
||||||
returnArray.clear();
|
returnArray.clear();
|
||||||
|
|
||||||
if(damagedTiles[team.ordinal()] == null){
|
if(damagedTiles[(int) team.id] == null){
|
||||||
damagedTiles[team.ordinal()] = new ObjectSet<>();
|
damagedTiles[(int) team.id] = new ObjectSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectSet<Tile> set = damagedTiles[team.ordinal()];
|
ObjectSet<Tile> set = damagedTiles[(int) 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 +135,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[team.ordinal()][type.ordinal()];
|
return flagMap[(int) team.id][type.ordinal()];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get all enemy blocks with a flag. */
|
/** Get all enemy blocks with a flag. */
|
||||||
@@ -155,11 +155,11 @@ public class BlockIndexer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void notifyTileDamaged(TileEntity entity){
|
public void notifyTileDamaged(TileEntity entity){
|
||||||
if(damagedTiles[entity.getTeam().ordinal()] == null){
|
if(damagedTiles[(int) entity.getTeam().id] == null){
|
||||||
damagedTiles[entity.getTeam().ordinal()] = new ObjectSet<>();
|
damagedTiles[(int) entity.getTeam().id] = new ObjectSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectSet<Tile> set = damagedTiles[entity.getTeam().ordinal()];
|
ObjectSet<Tile> set = damagedTiles[(int) entity.getTeam().id];
|
||||||
set.add(entity.tile);
|
set.add(entity.tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,11 +287,11 @@ public class BlockIndexer{
|
|||||||
|
|
||||||
//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[data.team.ordinal()].set(quadrantX, quadrantY);
|
structQuadrants[(int) data.team.id].set(quadrantX, quadrantY);
|
||||||
continue; //no need to process futher
|
continue; //no need to process futher
|
||||||
}
|
}
|
||||||
|
|
||||||
structQuadrants[data.team.ordinal()].set(quadrantX, quadrantY, false);
|
structQuadrants[(int) data.team.id].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 +299,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[data.team.ordinal()].set(quadrantX, quadrantY);
|
structQuadrants[(int) data.team.id].set(quadrantX, quadrantY);
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -308,7 +308,7 @@ public class BlockIndexer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean getQuad(Team team, int quadrantX, int quadrantY){
|
private boolean getQuad(Team team, int quadrantX, int quadrantY){
|
||||||
return structQuadrants[team.ordinal()].get(quadrantX, quadrantY);
|
return structQuadrants[(int) team.id].get(quadrantX, quadrantY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int quadWidth(){
|
private int quadWidth(){
|
||||||
|
|||||||
@@ -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[team.ordinal()][PathTarget.enemyCores.ordinal()] == null) return 0;
|
if(pathMap[(int) team.id][PathTarget.enemyCores.ordinal()] == null) return 0;
|
||||||
return pathMap[team.ordinal()][PathTarget.enemyCores.ordinal()].weights[x][y];
|
return pathMap[(int) 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[team.ordinal()][target.ordinal()];
|
PathData data = pathMap[(int) 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(team.ordinal(), target.ordinal())){
|
if(!created.get((int) team.id, target.ordinal())){
|
||||||
created.set(team.ordinal(), target.ordinal());
|
created.set((int) 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) != team.ordinal() && PathTile.team(tile) != Team.derelict.ordinal());
|
return PathTile.passable(tile) || (PathTile.team(tile) != (int) 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[team.ordinal()][target.ordinal()] = path;
|
pathMap[(int) team.id][target.ordinal()] = path;
|
||||||
|
|
||||||
//grab targets from passed array
|
//grab targets from passed array
|
||||||
synchronized(path.targets){
|
synchronized(path.targets){
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ public class GameState{
|
|||||||
private State state = State.menu;
|
private State state = State.menu;
|
||||||
|
|
||||||
public int enemies(){
|
public int enemies(){
|
||||||
return net.client() ? enemies : unitGroups[waveTeam.ordinal()].count(b -> !(b instanceof BaseDrone));
|
return net.client() ? enemies : unitGroups[(int) waveTeam.id].count(b -> !(b instanceof BaseDrone));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseUnit boss(){
|
public BaseUnit boss(){
|
||||||
return unitGroups[waveTeam.ordinal()].find(BaseUnit::isBoss);
|
return unitGroups[(int) waveTeam.id].find(BaseUnit::isBoss);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(State astate){
|
public void set(State astate){
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ public class Logic implements ApplicationListener{
|
|||||||
Time.update();
|
Time.update();
|
||||||
|
|
||||||
if(state.rules.waves && state.rules.waveTimer && !state.gameOver){
|
if(state.rules.waves && state.rules.waveTimer && !state.gameOver){
|
||||||
if(!state.rules.waitForWaveToEnd || unitGroups[waveTeam.ordinal()].size() == 0){
|
if(!state.rules.waitForWaveToEnd || unitGroups[(int) waveTeam.id].size() == 0){
|
||||||
state.wavetime = Math.max(state.wavetime - Time.delta(), 0);
|
state.wavetime = Math.max(state.wavetime - Time.delta(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -376,17 +376,17 @@ public class Renderer implements ApplicationListener{
|
|||||||
|
|
||||||
private void drawAllTeams(boolean flying){
|
private void drawAllTeams(boolean flying){
|
||||||
for(Team team : Team.all){
|
for(Team team : Team.all){
|
||||||
EntityGroup<BaseUnit> group = unitGroups[team.ordinal()];
|
EntityGroup<BaseUnit> group = unitGroups[(int) team.id];
|
||||||
|
|
||||||
if(group.count(p -> p.isFlying() == flying) + playerGroup.count(p -> p.isFlying() == flying && p.getTeam() == team) == 0 && flying) continue;
|
if(group.count(p -> p.isFlying() == flying) + playerGroup.count(p -> p.isFlying() == flying && p.getTeam() == team) == 0 && flying) continue;
|
||||||
|
|
||||||
unitGroups[team.ordinal()].draw(u -> u.isFlying() == flying && !u.isDead(), Unit::drawUnder);
|
unitGroups[(int) team.id].draw(u -> u.isFlying() == flying && !u.isDead(), Unit::drawUnder);
|
||||||
playerGroup.draw(p -> p.isFlying() == flying && p.getTeam() == team && !p.isDead(), Unit::drawUnder);
|
playerGroup.draw(p -> p.isFlying() == flying && p.getTeam() == team && !p.isDead(), Unit::drawUnder);
|
||||||
|
|
||||||
unitGroups[team.ordinal()].draw(u -> u.isFlying() == flying && !u.isDead(), Unit::drawAll);
|
unitGroups[(int) team.id].draw(u -> u.isFlying() == flying && !u.isDead(), Unit::drawAll);
|
||||||
playerGroup.draw(p -> p.isFlying() == flying && p.getTeam() == team, Unit::drawAll);
|
playerGroup.draw(p -> p.isFlying() == flying && p.getTeam() == team, Unit::drawAll);
|
||||||
|
|
||||||
unitGroups[team.ordinal()].draw(u -> u.isFlying() == flying && !u.isDead(), Unit::drawOver);
|
unitGroups[(int) team.id].draw(u -> u.isFlying() == flying && !u.isDead(), Unit::drawOver);
|
||||||
playerGroup.draw(p -> p.isFlying() == flying && p.getTeam() == team, Unit::drawOver);
|
playerGroup.draw(p -> p.isFlying() == flying && p.getTeam() == team, Unit::drawOver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class EditorTile extends Tile{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getTeamID() == team.ordinal()) return;
|
if(getTeamID() == (int) team.id) return;
|
||||||
op(OpType.team, getTeamID());
|
op(OpType.team, getTeamID());
|
||||||
super.setTeam(team);
|
super.setTeam(team);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ public enum EditorTool{
|
|||||||
if(tile.link().synthetic()){
|
if(tile.link().synthetic()){
|
||||||
Team dest = tile.getTeam();
|
Team dest = tile.getTeam();
|
||||||
if(dest == editor.drawTeam) return;
|
if(dest == editor.drawTeam) return;
|
||||||
fill(editor, x, y, false, t -> t.getTeamID() == dest.ordinal() && t.link().synthetic(), t -> t.setTeam(editor.drawTeam));
|
fill(editor, x, y, false, t -> t.getTeamID() == (int) dest.id && t.link().synthetic(), t -> t.setTeam(editor.drawTeam));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)team.ordinal();
|
this.team = (byte) (int) team.id;
|
||||||
this.rotation = (byte)rotation;
|
this.rotation = (byte)rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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() != team.ordinal() && tile.entity.collide(hitter)){
|
if(tile != null && !collidedBlocks.contains(tile.pos()) && tile.entity != null && tile.getTeamID() != (int) 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());
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ 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[team.ordinal()].intersect(x, y, width, height, cons);
|
unitGroups[(int) team.id].intersect(x, y, width, height, cons);
|
||||||
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,7 +167,7 @@ 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[team.ordinal()].intersect(x - radius, y - radius, radius*2f, radius*2f, unit -> {
|
unitGroups[(int) team.id].intersect(x - radius, y - radius, radius*2f, radius*2f, unit -> {
|
||||||
if(unit.withinDst(x, y, radius)){
|
if(unit.withinDst(x, y, radius)){
|
||||||
cons.get(unit);
|
cons.get(unit);
|
||||||
}
|
}
|
||||||
@@ -183,7 +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){
|
for(Team team : Team.all){
|
||||||
unitGroups[team.ordinal()].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);
|
||||||
@@ -199,7 +199,7 @@ public class Units{
|
|||||||
EnumSet<Team> targets = state.teams.enemiesOf(team);
|
EnumSet<Team> targets = state.teams.enemiesOf(team);
|
||||||
|
|
||||||
for(Team other : targets){
|
for(Team other : targets){
|
||||||
unitGroups[other.ordinal()].intersect(x, y, width, height, cons);
|
unitGroups[(int) other.id].intersect(x, y, width, height, cons);
|
||||||
}
|
}
|
||||||
|
|
||||||
playerGroup.intersect(x, y, width, height, player -> {
|
playerGroup.intersect(x, y, width, height, player -> {
|
||||||
@@ -217,7 +217,7 @@ public class Units{
|
|||||||
/** Iterates over all units. */
|
/** Iterates over all units. */
|
||||||
public static void all(Cons<Unit> cons){
|
public static void all(Cons<Unit> cons){
|
||||||
for(Team team : Team.all){
|
for(Team team : Team.all){
|
||||||
unitGroups[team.ordinal()].all().each(cons);
|
unitGroups[(int) team.id].all().each(cons);
|
||||||
}
|
}
|
||||||
|
|
||||||
playerGroup.all().each(cons);
|
playerGroup.all().each(cons);
|
||||||
|
|||||||
@@ -365,7 +365,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityGroup targetGroup(){
|
public EntityGroup targetGroup(){
|
||||||
return unitGroups[team.ordinal()];
|
return unitGroups[(int) team.id];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -169,7 +169,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(team.ordinal());
|
stream.writeByte((int) 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);
|
||||||
@@ -220,7 +220,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
|
|
||||||
for(Team team : Team.all){
|
for(Team team : Team.all){
|
||||||
if(team != getTeam() || !(this instanceof Player)){
|
if(team != getTeam() || !(this instanceof Player)){
|
||||||
avoid(unitGroups[team.ordinal()].intersect(cx, cy, fsize, fsize));
|
avoid(unitGroups[(int) team.id].intersect(cx, cy, fsize, fsize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ 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[event.team.ordinal()];
|
EntityGroup<BaseUnit> group = unitGroups[(int) event.team.id];
|
||||||
|
|
||||||
if(!(event.tile.entity instanceof BuildEntity)) return;
|
if(!(event.tile.entity instanceof BuildEntity)) return;
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public enum Gamemode{
|
|||||||
attack(rules -> {
|
attack(rules -> {
|
||||||
rules.unitDrops = true;
|
rules.unitDrops = true;
|
||||||
rules.attackMode = true;
|
rules.attackMode = true;
|
||||||
}, map -> map.teams.contains(waveTeam.ordinal())),
|
}, map -> map.teams.contains((int) waveTeam.id)),
|
||||||
pvp(rules -> {
|
pvp(rules -> {
|
||||||
rules.pvp = true;
|
rules.pvp = true;
|
||||||
rules.enemyCoreBuildRadius = 600f;
|
rules.enemyCoreBuildRadius = 600f;
|
||||||
|
|||||||
@@ -1,27 +1,35 @@
|
|||||||
package mindustry.game;
|
package mindustry.game;
|
||||||
|
|
||||||
import arc.Core;
|
import arc.*;
|
||||||
import arc.graphics.Color;
|
import arc.graphics.*;
|
||||||
|
import arc.struct.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
|
|
||||||
public enum Team{
|
public class Team{
|
||||||
derelict(Color.valueOf("4d4e58")),
|
/** All registered teams. */
|
||||||
sharded(Pal.accent),
|
public final static Array<Team> all = new Array<>();
|
||||||
crux(Color.valueOf("e82d2d")),
|
public final static Team
|
||||||
green(Color.valueOf("4dd98b")),
|
derelict = new Team("derelict", Color.valueOf("4d4e58")),
|
||||||
purple(Color.valueOf("9a4bdf")),
|
sharded = new Team("sharded", Pal.accent.cpy()),
|
||||||
blue(Color.royal.cpy());
|
crux = new Team("crux", Color.valueOf("e82d2d")),
|
||||||
|
green = new Team("green", Color.valueOf("4dd98b")),
|
||||||
|
purple = new Team("purple", Color.valueOf("9a4bdf")),
|
||||||
|
blue = new Team("blue", Color.royal.cpy());
|
||||||
|
|
||||||
public final static Team[] all = values();
|
|
||||||
public final Color color;
|
public final Color color;
|
||||||
public final int intColor;
|
public final int intColor;
|
||||||
|
public final String name;
|
||||||
|
public final int id;
|
||||||
|
|
||||||
Team(Color color){
|
public Team(String name, Color color){
|
||||||
|
this.name = name;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
intColor = Color.rgba8888(color);
|
this.intColor = Color.rgba8888(color);
|
||||||
|
this.id = all.size;
|
||||||
|
all.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String localized(){
|
public String localized(){
|
||||||
return Core.bundle.get("team." + name() + ".name");
|
return Core.bundle.get("team." + name + ".name");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,23 +6,22 @@ import mindustry.world.*;
|
|||||||
|
|
||||||
/** Class for various team-based utilities. */
|
/** Class for various team-based utilities. */
|
||||||
public class Teams{
|
public class Teams{
|
||||||
private TeamData[] map = new TeamData[Team.all.length];
|
private TeamData[] map = new TeamData[256];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a team.
|
* Register a team.
|
||||||
* @param team The team type enum.
|
* @param team The team type enum.
|
||||||
* @param enemies The array of enemies of this team. Any team not in this array is considered neutral.
|
|
||||||
*/
|
*/
|
||||||
public void add(Team team, Team... enemies){
|
public void add(Team team){
|
||||||
map[team.ordinal()] = new TeamData(team, EnumSet.of(enemies));
|
map[team.id] = new TeamData(team);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns team data by type. */
|
/** Returns team data by type. */
|
||||||
public TeamData get(Team team){
|
public TeamData get(Team team){
|
||||||
if(map[team.ordinal()] == null){
|
if(map[team.id] == null){
|
||||||
add(team, Array.with(Team.all).select(t -> t != team).toArray(Team.class));
|
add(team);
|
||||||
}
|
}
|
||||||
return map[team.ordinal()];
|
return map[team.id];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns whether a team is active, e.g. whether it has any cores remaining. */
|
/** Returns whether a team is active, e.g. whether it has any cores remaining. */
|
||||||
@@ -31,14 +30,10 @@ public class Teams{
|
|||||||
return team == Vars.waveTeam || get(team).cores.size > 0;
|
return team == Vars.waveTeam || get(team).cores.size > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a set of all teams that are enemies of this team. */
|
|
||||||
public EnumSet<Team> enemiesOf(Team team){
|
|
||||||
return get(team).enemies;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns whether {@param other} is an enemy of {@param #team}. */
|
/** Returns whether {@param other} is an enemy of {@param #team}. */
|
||||||
public boolean areEnemies(Team team, Team other){
|
public boolean areEnemies(Team team, Team other){
|
||||||
return enemiesOf(team).contains(other);
|
//todo what about derelict?
|
||||||
|
return team != other;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Allocates a new array with the active teams.
|
/** Allocates a new array with the active teams.
|
||||||
@@ -49,13 +44,11 @@ public class Teams{
|
|||||||
|
|
||||||
public static class TeamData{
|
public static class TeamData{
|
||||||
public final ObjectSet<Tile> cores = new ObjectSet<>();
|
public final ObjectSet<Tile> cores = new ObjectSet<>();
|
||||||
public final EnumSet<Team> enemies;
|
|
||||||
public final Team team;
|
public final Team team;
|
||||||
public Queue<BrokenBlock> brokenBlocks = new Queue<>();
|
public Queue<BrokenBlock> brokenBlocks = new Queue<>();
|
||||||
|
|
||||||
public TeamData(Team team, EnumSet<Team> enemies){
|
public TeamData(Team team){
|
||||||
this.team = team;
|
this.team = team;
|
||||||
this.enemies = enemies;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,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(team.ordinal());
|
map.teams.add((int) team.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ public abstract class SaveVersion extends SaveFileReader{
|
|||||||
Array<TeamData> data = state.teams.getActive();
|
Array<TeamData> data = state.teams.getActive();
|
||||||
stream.writeInt(data.size);
|
stream.writeInt(data.size);
|
||||||
for(TeamData team : data){
|
for(TeamData team : data){
|
||||||
stream.writeInt(team.team.ordinal());
|
stream.writeInt((int) team.team.id);
|
||||||
stream.writeInt(team.brokenBlocks.size);
|
stream.writeInt(team.brokenBlocks.size);
|
||||||
for(BrokenBlock block : team.brokenBlocks){
|
for(BrokenBlock block : team.brokenBlocks){
|
||||||
stream.writeShort(block.x);
|
stream.writeShort(block.x);
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public class TypeIO{
|
|||||||
|
|
||||||
@WriteClass(BaseUnit.class)
|
@WriteClass(BaseUnit.class)
|
||||||
public static void writeBaseUnit(ByteBuffer buffer, BaseUnit unit){
|
public static void writeBaseUnit(ByteBuffer buffer, BaseUnit unit){
|
||||||
buffer.put((byte)unit.getTeam().ordinal());
|
buffer.put((byte) (int) unit.getTeam().id);
|
||||||
buffer.putInt(unit.getID());
|
buffer.putInt(unit.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ public class TypeIO{
|
|||||||
|
|
||||||
@WriteClass(Team.class)
|
@WriteClass(Team.class)
|
||||||
public static void writeTeam(ByteBuffer buffer, Team reason){
|
public static void writeTeam(ByteBuffer buffer, Team reason){
|
||||||
buffer.put((byte)reason.ordinal());
|
buffer.put((byte) (int) reason.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(Team.class)
|
@ReadClass(Team.class)
|
||||||
|
|||||||
@@ -628,7 +628,7 @@ public class HudFragment extends Fragment{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(state.rules.waveTimer){
|
if(state.rules.waveTimer){
|
||||||
builder.append((state.rules.waitForWaveToEnd && unitGroups[waveTeam.ordinal()].size() > 0) ? Core.bundle.get("wave.waveInProgress") : ( waitingf.get((int)(state.wavetime/60))));
|
builder.append((state.rules.waitForWaveToEnd && unitGroups[(int) waveTeam.id].size() > 0) ? Core.bundle.get("wave.waveInProgress") : ( waitingf.get((int)(state.wavetime/60))));
|
||||||
}else if(state.enemies() == 0){
|
}else if(state.enemies() == 0){
|
||||||
builder.append(Core.bundle.get("waiting"));
|
builder.append(Core.bundle.get("waiting"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ public class Tile implements Position, TargetTrait{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setTeam(Team team){
|
public void setTeam(Team team){
|
||||||
this.team = (byte)team.ordinal();
|
this.team = (byte) (int) 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)team.ordinal();
|
this.team = (byte) (int) team.id;
|
||||||
this.rotation = (byte)Mathf.mod(rotation, 4);
|
this.rotation = (byte)Mathf.mod(rotation, 4);
|
||||||
changed();
|
changed();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,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[tile.getTeam().ordinal()].all()){
|
for(BaseUnit unit : unitGroups[(int) tile.getTeam().id].all()){
|
||||||
unit.onCommand(UnitCommand.all[0]);
|
unit.onCommand(UnitCommand.all[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ public class CommandCenter extends Block{
|
|||||||
|
|
||||||
Team team = (player == null ? tile.getTeam() : player.getTeam());
|
Team team = (player == null ? tile.getTeam() : player.getTeam());
|
||||||
|
|
||||||
for(BaseUnit unit : unitGroups[team.ordinal()].all()){
|
for(BaseUnit unit : unitGroups[(int) team.id].all()){
|
||||||
unit.onCommand(command);
|
unit.onCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,13 +55,13 @@ public class SStats implements SteamUserStatsCallback{
|
|||||||
|
|
||||||
private void checkUpdate(){
|
private void checkUpdate(){
|
||||||
if(campaign()){
|
if(campaign()){
|
||||||
SStat.maxUnitActive.max(unitGroups[player.getTeam().ordinal()].size());
|
SStat.maxUnitActive.max(unitGroups[(int) player.getTeam().id].size());
|
||||||
|
|
||||||
if(unitGroups[player.getTeam().ordinal()].count(u -> u.getType() == UnitTypes.phantom) >= 10){
|
if(unitGroups[(int) player.getTeam().id].count(u -> u.getType() == UnitTypes.phantom) >= 10){
|
||||||
active10Phantoms.complete();
|
active10Phantoms.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(unitGroups[player.getTeam().ordinal()].count(u -> u.getType() == UnitTypes.crawler) >= 50){
|
if(unitGroups[(int) player.getTeam().id].count(u -> u.getType() == UnitTypes.crawler) >= 50){
|
||||||
active50Crawlers.complete();
|
active50Crawlers.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ public class ServerControl implements ApplicationListener{
|
|||||||
info(" &lyPlaying on map &fi{0}&fb &lb/&ly Wave {1}", Strings.capitalize(world.getMap().name()), state.wave);
|
info(" &lyPlaying on map &fi{0}&fb &lb/&ly Wave {1}", Strings.capitalize(world.getMap().name()), state.wave);
|
||||||
|
|
||||||
if(state.rules.waves){
|
if(state.rules.waves){
|
||||||
info("&ly {0} enemies.", unitGroups[Team.crux.ordinal()].size());
|
info("&ly {0} enemies.", unitGroups[(int) Team.crux.id].size());
|
||||||
}else{
|
}else{
|
||||||
info("&ly {0} seconds until next wave.", (int)(state.wavetime / 60));
|
info("&ly {0} seconds until next wave.", (int)(state.wavetime / 60));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,8 +106,8 @@ public class ApplicationTests{
|
|||||||
Time.update();
|
Time.update();
|
||||||
Time.update();
|
Time.update();
|
||||||
Time.setDeltaProvider(() -> 1f);
|
Time.setDeltaProvider(() -> 1f);
|
||||||
unitGroups[waveTeam.ordinal()].updateEvents();
|
unitGroups[(int) waveTeam.id].updateEvents();
|
||||||
assertFalse(unitGroups[waveTeam.ordinal()].isEmpty(), "No enemies spawned.");
|
assertFalse(unitGroups[(int) waveTeam.id].isEmpty(), "No enemies spawned.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user