Implemented gamemode validation
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
package io.anuke.mindustry.maps;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.collection.StringMap;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.files.FileHandle;
|
||||
import io.anuke.arc.graphics.Texture;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.game.Rules;
|
||||
import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.io.JsonIO;
|
||||
|
||||
public class Map implements Comparable<Map>{
|
||||
@@ -23,6 +23,10 @@ public class Map implements Comparable<Map>{
|
||||
public Texture texture;
|
||||
/** Build that this map was created in. -1 = unknown or custom build. */
|
||||
public int build;
|
||||
/** All teams present on this map.*/
|
||||
public IntSet teams = new IntSet();
|
||||
/** Number of enemy spawns on this map.*/
|
||||
public int spawns = 0;
|
||||
|
||||
public Map(FileHandle file, int width, int height, StringMap tags, boolean custom, int version, int build){
|
||||
this.custom = custom;
|
||||
@@ -63,20 +67,16 @@ public class Map implements Comparable<Map>{
|
||||
}
|
||||
|
||||
/** Whether this map has a core of the enemy 'wave' team. Default: true.
|
||||
* Used for checking Attack mode validity.*/
|
||||
* Used for checking Attack mode validity.
|
||||
public boolean hasEnemyCore(){
|
||||
return tags.get("enemycore", "true").equals("true");
|
||||
}
|
||||
|
||||
/** Whether this map has a core of any team except the default player team. Default: true.
|
||||
* Used for checking PvP mode validity.*/
|
||||
* Used for checking PvP mode validity.
|
||||
public boolean hasOtherCores(){
|
||||
return tags.get("othercore", "true").equals("true");
|
||||
}
|
||||
|
||||
public boolean attribute(MapAttribute attr){
|
||||
return tags.getBool(attr.name());
|
||||
}
|
||||
}*/
|
||||
|
||||
public String author(){
|
||||
return tag("author");
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package io.anuke.mindustry.maps;
|
||||
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.function.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
/** Defines a specific type of attribute for a map, usually whether or not it supports a certain type of mode.*/
|
||||
public enum MapAttribute{
|
||||
/** Whether a map has a player spawnpoint in it.*/
|
||||
spawnpoint(teams -> teams.contains(defaultTeam.ordinal())),
|
||||
/** Whether a map has a wave team core to attack.*/
|
||||
attack(teams -> teams.contains(waveTeam.ordinal())),
|
||||
/** Whether this map supports PvP.*/
|
||||
pvp(teams -> teams.size > 1);
|
||||
|
||||
private final Predicate<IntSet> validator;
|
||||
|
||||
public static final MapAttribute[] all = values();
|
||||
|
||||
MapAttribute(Predicate<IntSet> set){
|
||||
this.validator = set;
|
||||
}
|
||||
|
||||
//todo also take into account enemy spawnpoints
|
||||
public boolean validate(IntSet teams){
|
||||
return validator.test(teams);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,25 @@
|
||||
package io.anuke.mindustry.maps;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.files.FileHandle;
|
||||
import io.anuke.arc.function.ExceptionRunnable;
|
||||
import io.anuke.arc.graphics.Texture;
|
||||
import io.anuke.arc.files.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.arc.util.serialization.Json;
|
||||
import io.anuke.mindustry.game.SpawnGroup;
|
||||
import io.anuke.mindustry.io.LegacyMapIO;
|
||||
import io.anuke.mindustry.io.MapIO;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.storage.CoreBlock;
|
||||
import io.anuke.arc.util.serialization.*;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.io.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.blocks.storage.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Maps implements Disposable{
|
||||
/** List of all built-in maps. Filenames only. */
|
||||
private static String[] defaultMapNames = {"fortress", "labyrinth", "islands", "tendrils", "caldera", "glacier", "vein"};
|
||||
private static String[] defaultMapNames = {"fortress", "labyrinth", "islands", "tendrils", "caldera", "glacier", "veins"};
|
||||
/** All maps stored in an ordered array. */
|
||||
private Array<Map> maps = new Array<>();
|
||||
/** Serializer for meta. */
|
||||
@@ -110,31 +109,24 @@ public class Maps implements Disposable{
|
||||
MapIO.writeMap(file, map);
|
||||
|
||||
if(!headless){
|
||||
//by default, it does not have an enemy core or any other cores
|
||||
map.tags.put("enemycore", "false");
|
||||
map.tags.put("othercore", "false");
|
||||
IntSet teams = new IntSet();
|
||||
//reset attributes
|
||||
map.teams.clear();
|
||||
map.spawns = 0;
|
||||
|
||||
for(int x = 0; x < map.width; x++){
|
||||
for(int y = 0; y < map.height; y++){
|
||||
Tile tile = world.getTiles()[x][y];
|
||||
|
||||
if(tile.block() instanceof CoreBlock){
|
||||
teams.add(tile.getTeamID());
|
||||
map.teams.add(tile.getTeamID());
|
||||
}
|
||||
|
||||
if(tile.overlay() == Blocks.spawn){
|
||||
map.spawns ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(teams.size > 1){
|
||||
//map must have other team's cores
|
||||
map.tags.put("othercore", "true");
|
||||
}
|
||||
|
||||
if(teams.contains(waveTeam.ordinal())){
|
||||
//map must have default enemy team's core
|
||||
map.tags.put("enemycore", "true");
|
||||
}
|
||||
|
||||
map.texture = new Texture(MapIO.generatePreview(world.getTiles()));
|
||||
}
|
||||
maps.add(map);
|
||||
|
||||
Reference in New Issue
Block a user