Made team a separate class
This commit is contained in:
@@ -22,7 +22,7 @@ public enum Gamemode{
|
||||
attack(rules -> {
|
||||
rules.unitDrops = true;
|
||||
rules.attackMode = true;
|
||||
}, map -> map.teams.contains(waveTeam.ordinal())),
|
||||
}, map -> map.teams.contains((int) waveTeam.id)),
|
||||
pvp(rules -> {
|
||||
rules.pvp = true;
|
||||
rules.enemyCoreBuildRadius = 600f;
|
||||
|
||||
@@ -1,27 +1,35 @@
|
||||
package mindustry.game;
|
||||
|
||||
import arc.Core;
|
||||
import arc.graphics.Color;
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.graphics.*;
|
||||
|
||||
public enum Team{
|
||||
derelict(Color.valueOf("4d4e58")),
|
||||
sharded(Pal.accent),
|
||||
crux(Color.valueOf("e82d2d")),
|
||||
green(Color.valueOf("4dd98b")),
|
||||
purple(Color.valueOf("9a4bdf")),
|
||||
blue(Color.royal.cpy());
|
||||
public class Team{
|
||||
/** All registered teams. */
|
||||
public final static Array<Team> all = new Array<>();
|
||||
public final static Team
|
||||
derelict = new Team("derelict", Color.valueOf("4d4e58")),
|
||||
sharded = new Team("sharded", Pal.accent.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 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;
|
||||
intColor = Color.rgba8888(color);
|
||||
this.intColor = Color.rgba8888(color);
|
||||
this.id = all.size;
|
||||
all.add(this);
|
||||
}
|
||||
|
||||
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. */
|
||||
public class Teams{
|
||||
private TeamData[] map = new TeamData[Team.all.length];
|
||||
private TeamData[] map = new TeamData[256];
|
||||
|
||||
/**
|
||||
* Register a team.
|
||||
* @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){
|
||||
map[team.ordinal()] = new TeamData(team, EnumSet.of(enemies));
|
||||
public void add(Team team){
|
||||
map[team.id] = new TeamData(team);
|
||||
}
|
||||
|
||||
/** Returns team data by type. */
|
||||
public TeamData get(Team team){
|
||||
if(map[team.ordinal()] == null){
|
||||
add(team, Array.with(Team.all).select(t -> t != team).toArray(Team.class));
|
||||
if(map[team.id] == null){
|
||||
add(team);
|
||||
}
|
||||
return map[team.ordinal()];
|
||||
return map[team.id];
|
||||
}
|
||||
|
||||
/** 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;
|
||||
}
|
||||
|
||||
/** 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}. */
|
||||
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.
|
||||
@@ -49,13 +44,11 @@ public class Teams{
|
||||
|
||||
public static class TeamData{
|
||||
public final ObjectSet<Tile> cores = new ObjectSet<>();
|
||||
public final EnumSet<Team> enemies;
|
||||
public final Team team;
|
||||
public Queue<BrokenBlock> brokenBlocks = new Queue<>();
|
||||
|
||||
public TeamData(Team team, EnumSet<Team> enemies){
|
||||
public TeamData(Team team){
|
||||
this.team = team;
|
||||
this.enemies = enemies;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user