New team system / Prototype dedicated PvP gamemode
This commit is contained in:
@@ -14,11 +14,15 @@ public enum GameMode{
|
||||
noWaves{{
|
||||
disableWaves = true;
|
||||
hidden = true;
|
||||
autoSpawn = true;
|
||||
}},
|
||||
pvp{{
|
||||
disableWaves = true;
|
||||
isPvp = true;
|
||||
hidden = true;
|
||||
}};
|
||||
public boolean infiniteResources;
|
||||
public boolean disableWaveTimer;
|
||||
public boolean disableWaves;
|
||||
public boolean hidden;
|
||||
|
||||
public boolean infiniteResources, disableWaveTimer, disableWaves, hidden, autoSpawn, isPvp;
|
||||
|
||||
public String description(){
|
||||
return Bundles.get("mode." + name() + ".description");
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
package io.anuke.mindustry.game;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.util.ThreadArray;
|
||||
import io.anuke.ucore.util.ThreadSet;
|
||||
|
||||
/**
|
||||
* Class for various team-based utilities.
|
||||
*/
|
||||
public class TeamInfo{
|
||||
private ObjectMap<Team, TeamData> map = new ObjectMap<>();
|
||||
private ThreadSet<Team> allies = new ThreadSet<>(),
|
||||
enemies = new ThreadSet<>();
|
||||
private ThreadSet<TeamData> allyData = new ThreadSet<>(),
|
||||
enemyData = new ThreadSet<>();
|
||||
private ThreadSet<TeamData> allTeamData = new ThreadSet<>();
|
||||
private ThreadSet<Team> allTeams = new ThreadSet<>();
|
||||
private int allyBits = 0;
|
||||
private int enemyBits = 0;
|
||||
|
||||
/**
|
||||
* Returns all teams on a side.
|
||||
*/
|
||||
public ObjectSet<TeamData> getTeams(boolean ally){
|
||||
return ally ? allyData : enemyData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all team data.
|
||||
*/
|
||||
public ObjectSet<TeamData> getTeams(){
|
||||
return allTeamData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a team.
|
||||
*
|
||||
* @param team The team type enum.
|
||||
* @param ally Whether this team is an ally with the player or an enemy with the player.
|
||||
* In PvP situations with dedicated servers, the sides can be arbitrary.
|
||||
*/
|
||||
public void add(Team team, boolean ally){
|
||||
if(has(team)) throw new RuntimeException("Can't define team information twice!");
|
||||
|
||||
TeamData data = new TeamData(team, ally);
|
||||
|
||||
if(ally){
|
||||
allies.add(team);
|
||||
allyData.add(data);
|
||||
allyBits |= (1 << team.ordinal());
|
||||
}else{
|
||||
enemies.add(team);
|
||||
enemyData.add(data);
|
||||
enemyBits |= (1 << team.ordinal());
|
||||
}
|
||||
|
||||
allTeamData.add(data);
|
||||
allTeams.add(team);
|
||||
|
||||
map.put(team, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns team data by type. Call {@link #has(Team)} first to make sure it's active!
|
||||
*/
|
||||
public TeamData get(Team team){
|
||||
if(!has(team)) throw new RuntimeException("This team is not active! Check has() before calling get().");
|
||||
return map.get(team);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the specified team is active, e.g. whether it is participating in the game.
|
||||
*/
|
||||
public boolean has(Team team){
|
||||
return map.containsKey(team);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of all teams that are enemies of this team.
|
||||
* For teams not active, an empty set is returned.
|
||||
*/
|
||||
public ObjectSet<Team> enemiesOf(Team team){
|
||||
boolean ally = allies.contains(team);
|
||||
boolean enemy = enemies.contains(team);
|
||||
|
||||
//this team isn't even in the game, so target everything!
|
||||
if(!ally && !enemy) return allTeams;
|
||||
|
||||
return ally ? enemies : allies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of all teams that are allies of this team.
|
||||
* For teams not active, an empty set is returned.
|
||||
*/
|
||||
public ObjectSet<Team> alliesOf(Team team){
|
||||
boolean ally = allies.contains(team);
|
||||
boolean enemy = enemies.contains(team);
|
||||
|
||||
//this team isn't even in the game, so target everything!
|
||||
if(!ally && !enemy) return allTeams;
|
||||
|
||||
return !ally ? enemies : allies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of all teams that are enemies of this team.
|
||||
* For teams not active, an empty set is returned.
|
||||
*/
|
||||
public ObjectSet<TeamData> enemyDataOf(Team team){
|
||||
boolean ally = allies.contains(team);
|
||||
boolean enemy = enemies.contains(team);
|
||||
|
||||
//this team isn't even in the game, so target everything!
|
||||
if(!ally && !enemy) return allTeamData;
|
||||
|
||||
return ally ? enemyData : allyData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not these two teams are enemies.
|
||||
*/
|
||||
public boolean areEnemies(Team team, Team other){
|
||||
if(team == other) return false; //fast fail to be more efficient
|
||||
boolean ally = (allyBits & (1 << team.ordinal())) != 0;
|
||||
boolean enemy = (enemyBits & (1 << other.ordinal())) != 0;
|
||||
return (ally == enemy) || !ally; //if it's not in the game, target everything.
|
||||
}
|
||||
|
||||
public class TeamData{
|
||||
public final Array<Tile> cores = new ThreadArray<>();
|
||||
public final Team team;
|
||||
public final boolean ally;
|
||||
|
||||
public TeamData(Team team, boolean ally){
|
||||
this.team = team;
|
||||
this.ally = ally;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package io.anuke.mindustry.game;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.util.EnumSet;
|
||||
import io.anuke.ucore.util.ThreadArray;
|
||||
|
||||
/**
|
||||
* Class for various team-based utilities.
|
||||
*/
|
||||
public class Teams{
|
||||
private TeamData[] map = new TeamData[Team.all.length];
|
||||
|
||||
/**
|
||||
* 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){
|
||||
if(map[team.ordinal()] != null) throw new RuntimeException("Can't define team information twice!");
|
||||
|
||||
map[team.ordinal()] = new TeamData(team, EnumSet.of(enemies));
|
||||
}
|
||||
|
||||
/**Returns team data by type.*/
|
||||
public TeamData get(Team team){
|
||||
if(map[team.ordinal()] == null){
|
||||
//By default, a non-defined team will be enemies of everything.
|
||||
Team[] others = new Team[Team.all.length-1];
|
||||
for(int i = 0, j = 0; i < Team.all.length; i++){
|
||||
if(Team.all[i] != team) others[j++] = Team.all[i];
|
||||
}
|
||||
add(team, others);
|
||||
}
|
||||
return map[team.ordinal()];
|
||||
}
|
||||
|
||||
/**Returns whether a team is active, e.g. whether it has any cores remaining.*/
|
||||
public boolean isActive(Team team){
|
||||
//the enemy wave team is always active
|
||||
return (!Vars.state.mode.disableWaves && 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);
|
||||
}
|
||||
|
||||
public class TeamData{
|
||||
public final Array<Tile> cores = new ThreadArray<>();
|
||||
public final EnumSet<Team> enemies;
|
||||
public final Team team;
|
||||
|
||||
public TeamData(Team team, EnumSet<Team> enemies){
|
||||
this.team = team;
|
||||
this.enemies = enemies;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user