This commit is contained in:
Anuken
2019-03-11 08:25:03 -04:00
parent ebd44d3b60
commit c083d059c9
7 changed files with 263 additions and 279 deletions

View File

@@ -16,18 +16,22 @@ public class Map{
public final ObjectMap<String, String> tags;
/** Supplies a new input stream with the data of this map.*/
public final Supplier<InputStream> stream;
/**Map width/height, shorts.*/
public int width, height;
/** Preview texture.*/
public Texture texture;
public Map(String name, ObjectMap<String, String> tags, boolean custom, Supplier<InputStream> streamSupplier){
public Map(String name, int width, int height, ObjectMap<String, String> tags, boolean custom, Supplier<InputStream> streamSupplier){
this.name = name;
this.custom = custom;
this.tags = tags;
this.stream = streamSupplier;
this.width = width;
this.height = height;
}
public Map(String name){
this(name, new ObjectMap<>(), true, () -> null);
public Map(String name, int width, int height){
this(name, width, height, new ObjectMap<>(), true, () -> null);
}
public String getDisplayName(){
@@ -50,10 +54,6 @@ public class Map{
return tags.containsKey(name) && !tags.get(name).trim().isEmpty() ? tags.get(name): Core.bundle.get("unknown");
}
public boolean hasOreGen(){
return !tags.get("oregen", "0").equals("0");
}
@Override
public String toString(){
return "Map{" +

View File

@@ -9,8 +9,6 @@ import io.anuke.mindustry.content.Blocks;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.io.MapIO;
import io.anuke.mindustry.maps.Map;
import io.anuke.mindustry.maps.MapTileData;
import io.anuke.mindustry.maps.MapTileData.TileDataMarker;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.type.Loadout;
import io.anuke.mindustry.world.Block;
@@ -21,8 +19,9 @@ import io.anuke.mindustry.world.blocks.StaticWall;
import io.anuke.mindustry.world.blocks.storage.CoreBlock;
import io.anuke.mindustry.world.blocks.storage.StorageBlock;
import static io.anuke.mindustry.Vars.content;
import static io.anuke.mindustry.Vars.world;
import java.io.IOException;
import static io.anuke.mindustry.Vars.*;
public class MapGenerator extends Generator{
private Map map;
@@ -73,112 +72,109 @@ public class MapGenerator extends Generator{
public void init(Loadout loadout){
this.loadout = loadout;
map = world.maps.loadInternalMap(mapName);
width = map.meta.width;
height = map.meta.height;
width = map.width;
height = map.height;
}
@Override
public void generate(Tile[][] tiles){
MapTileData data = MapIO.readTileData(map, true);
try{
MapIO.readTiles(map, tiles);
Array<Point2> players = new Array<>();
Array<Point2> enemies = new Array<>();
data.position(0, 0);
TileDataMarker marker = data.newDataMarker();
Array<Point2> players = new Array<>();
Array<Point2> enemies = new Array<>();
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
if(tiles[x][y].block() instanceof CoreBlock){
players.add(new Point2(x, y));
tiles[x][y].setBlock(Blocks.air);
}
for(int y = 0; y < data.height(); y++){
for(int x = 0; x < data.width(); x++){
data.read(marker);
if(content.block(marker.wall) instanceof CoreBlock){
players.add(new Point2(x, y));
marker.wall = 0;
if(tiles[x][y].block() == Blocks.spawn){
enemies.add(new Point2(x, y));
tiles[x][y].setBlock(Blocks.air);
}
}
if(enemySpawns != -1 && content.block(marker.wall) == Blocks.spawn){
enemies.add(new Point2(x, y));
marker.wall = 0;
}
tiles[x][y] = new Tile(x, y, marker.floor, marker.wall == Blocks.part.id ? 0 : marker.wall, marker.rotation, marker.team);
}
}
Simplex simplex = new Simplex(Mathf.random(99999));
Simplex simplex = new Simplex(Mathf.random(99999));
for(int x = 0; x < data.width(); x++){
for(int y = 0; y < data.height(); y++){
final double scl = 10;
Tile tile = tiles[x][y];
int newX = Mathf.clamp((int)(simplex.octaveNoise2D(1, 1, 1.0 / scl, x, y) * distortion + x), 0, data.width()-1);
int newY = Mathf.clamp((int)(simplex.octaveNoise2D(1, 1, 1.0 / scl, x + 9999, y + 9999) * distortion + y), 0, data.height()-1);
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
final double scl = 10;
Tile tile = tiles[x][y];
int newX = Mathf.clamp((int)(simplex.octaveNoise2D(1, 1, 1.0 / scl, x, y) * distortion + x), 0, width - 1);
int newY = Mathf.clamp((int)(simplex.octaveNoise2D(1, 1, 1.0 / scl, x + 9999, y + 9999) * distortion + y), 0, height - 1);
if((tile.block() instanceof StaticWall
if((tile.block() instanceof StaticWall
&& tiles[newX][newY].block() instanceof StaticWall)
|| (tile.block() == Blocks.air && !tiles[newX][newY].block().synthetic())
|| (tiles[newX][newY].block() == Blocks.air && tile.block() instanceof StaticWall)){
tile.setBlock(tiles[newX][newY].block());
}
if(distortFloor){
tile.setFloor(tiles[newX][newY].floor());
}
for(Decoration decor : decorations){
if(tile.block() == Blocks.air && !(decor.wall instanceof Floor) && tile.floor() == decor.floor && Mathf.chance(decor.chance)){
tile.setBlock(decor.wall);
}else if(tile.floor() == decor.floor && decor.wall instanceof Floor && Mathf.chance(decor.chance)){
tile.setFloor((Floor)decor.wall);
tile.setBlock(tiles[newX][newY].block());
}
}
if(tile.block() instanceof StorageBlock && !(tile.block() instanceof CoreBlock)){
for(ItemStack stack : storageDrops){
if(Mathf.chance(0.3)){
tile.entity.items.add(stack.item, Math.min(Mathf.random(stack.amount), tile.block().itemCapacity));
if(distortFloor){
tile.setFloor(tiles[newX][newY].floor());
}
for(Decoration decor : decorations){
if(tile.block() == Blocks.air && !(decor.wall instanceof Floor) && tile.floor() == decor.floor && Mathf.chance(decor.chance)){
tile.setBlock(decor.wall);
}else if(tile.floor() == decor.floor && decor.wall instanceof Floor && Mathf.chance(decor.chance)){
tile.setFloor((Floor)decor.wall);
}
}
}
}
}
if(enemySpawns != -1){
if(enemySpawns > enemies.size){
throw new IllegalArgumentException("Enemy spawn pool greater than map spawn number.");
}
enemies.shuffle();
for(int i = 0; i < enemySpawns; i++){
Point2 point = enemies.get(i);
tiles[point.x][point.y].setBlock(Blocks.spawn);
int rad = 10, frad = 12;
for(int x = -rad; x <= rad; x++){
for(int y = -rad; y <= rad; y++){
int wx = x + point.x, wy = y + point.y;
double dst = Mathf.dst(x, y);
if(dst < frad && Structs.inBounds(wx, wy, tiles) && (dst <= rad || Mathf.chance(0.5))){
Tile tile = tiles[wx][wy];
if(tile.floor() instanceof OreBlock){
OreBlock block = (OreBlock)tile.floor();
tile.setFloor(block.base);
if(tile.block() instanceof StorageBlock && !(tile.block() instanceof CoreBlock)){
for(ItemStack stack : storageDrops){
if(Mathf.chance(0.3)){
tile.entity.items.add(stack.item, Math.min(Mathf.random(stack.amount), tile.block().itemCapacity));
}
}
}
}
}
if(enemySpawns != -1){
if(enemySpawns > enemies.size){
throw new IllegalArgumentException("Enemy spawn pool greater than map spawn number.");
}
enemies.shuffle();
for(int i = 0; i < enemySpawns; i++){
Point2 point = enemies.get(i);
tiles[point.x][point.y].setBlock(Blocks.spawn);
int rad = 10, frad = 12;
for(int x = -rad; x <= rad; x++){
for(int y = -rad; y <= rad; y++){
int wx = x + point.x, wy = y + point.y;
double dst = Mathf.dst(x, y);
if(dst < frad && Structs.inBounds(wx, wy, tiles) && (dst <= rad || Mathf.chance(0.5))){
Tile tile = tiles[wx][wy];
if(tile.floor() instanceof OreBlock){
OreBlock block = (OreBlock)tile.floor();
tile.setFloor(block.base);
}
}
}
}
}
}
Point2 core = players.random();
if(core == null){
throw new IllegalArgumentException("All zone maps must have a core.");
}
loadout.setup(core.x, core.y);
world.prepareTiles(tiles);
world.setMap(map);
}catch(IOException e){
throw new RuntimeException(e);
}
Point2 core = players.random();
if(core == null){
throw new IllegalArgumentException("All zone maps must have a core.");
}
loadout.setup(core.x, core.y);
world.prepareTiles(tiles);
world.setMap(map);
}
public static class Decoration{