This commit is contained in:
Anuken
2019-03-10 22:51:04 -04:00
880 changed files with 19481 additions and 12588 deletions

View File

@@ -0,0 +1,10 @@
package io.anuke.mindustry.maps;
public class MapException extends RuntimeException{
public final Map map;
public MapException(Map map, String s){
super(s);
this.map = map;
}
}

View File

@@ -54,7 +54,7 @@ public class Maps implements Disposable{
/**Returns map by internal name.*/
public Map getByName(String name){
return maps.get(name.toLowerCase());
return maps.get(name);
}
/**Loads a map from the map folder and returns it. Should only be used for zone maps.
@@ -136,7 +136,7 @@ public class Maps implements Disposable{
map.texture = new Texture(MapIO.generatePixmap(MapIO.readTileData(ds, meta, true)));
}
maps.put(map.name.toLowerCase(), map);
maps.put(map.name, map);
allMaps.add(map);
}
}

View File

@@ -21,7 +21,6 @@ public class BasicGenerator extends RandomGenerator{
@Override
public void generate(Tile[][] tiles){
//todo use set seed
int seed = Mathf.random(99999999);
sim.setSeed(seed);
sim2.setSeed(seed + 1);

View File

@@ -1,5 +1,6 @@
package io.anuke.mindustry.maps.generators;
import io.anuke.mindustry.type.Loadout;
import io.anuke.mindustry.world.Tile;
public abstract class Generator{
@@ -12,7 +13,7 @@ public abstract class Generator{
public Generator(){}
public void init(){
public void init(Loadout loadout){
}

View File

@@ -3,25 +3,41 @@ package io.anuke.mindustry.maps.generators;
import io.anuke.arc.collection.Array;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Point2;
import io.anuke.arc.util.Structs;
import io.anuke.arc.util.noise.Simplex;
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;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.blocks.OreBlock;
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.*;
import static io.anuke.mindustry.Vars.content;
import static io.anuke.mindustry.Vars.world;
public class MapGenerator extends Generator{
private Map map;
private String mapName;
private Array<Decoration> decorations = new Array<>();
private Loadout loadout;
/**How much the landscape is randomly distorted.*/
public float distortion = 3;
/**The amount of final enemy spawns used. -1 to use everything in the map.
* This amount of enemy spawns is selected randomly from the map.*/
public int enemySpawns = -1;
/**Whether floor is distorted along with blocks.*/
public boolean distortFloor = false;
/**Items randomly added to containers and vaults.*/
public ItemStack[] storageDrops = ItemStack.with(Items.copper, 300, Items.lead, 300, Items.silicon, 200, Items.graphite, 200, Items.blastCompound, 200);
public MapGenerator(String mapName){
this.mapName = mapName;
@@ -32,8 +48,30 @@ public class MapGenerator extends Generator{
this.enemySpawns = enemySpawns;
}
public MapGenerator drops(ItemStack[] drops){
this.storageDrops = drops;
return this;
}
public MapGenerator decor(Decoration... decor){
this.decorations.addAll(decor);
return this;
}
public MapGenerator dist(float distortion){
this.distortion = distortion;
return this;
}
public MapGenerator dist(float distortion, boolean floor){
this.distortion = distortion;
this.distortFloor = floor;
return this;
}
@Override
public void init(){
public void init(Loadout loadout){
this.loadout = loadout;
map = world.maps.loadInternalMap(mapName);
width = map.meta.width;
height = map.meta.height;
@@ -71,23 +109,64 @@ public class MapGenerator extends Generator{
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);
if(tiles[newX][newY].block() != Blocks.spawn && !tiles[x][y].block().synthetic()&& !tiles[newX][newY].block().synthetic()){
tiles[x][y].setBlock(tiles[newX][newY].block());
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);
}
}
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 > enemies.size){
throw new IllegalArgumentException("Enemy spawn pool greater than map spawn number.");
}
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);
}
}
}
}
}
}
@@ -96,10 +175,21 @@ public class MapGenerator extends Generator{
throw new IllegalArgumentException("All zone maps must have a core.");
}
//TODO set specific core block?
tiles[core.x][core.y].setBlock(Blocks.core, defaultTeam);
loadout.setup(core.x, core.y);
world.prepareTiles(tiles);
world.setMap(map);
}
public static class Decoration{
public final Block floor;
public final Block wall;
public final double chance;
public Decoration(Block floor, Block wall, double chance){
this.floor = floor;
this.wall = wall;
this.chance = chance;
}
}
}

View File

@@ -24,7 +24,7 @@ public abstract class RandomGenerator extends Generator{
}
}
tiles[width/2][height/2].setBlock(Blocks.core, Team.blue);
tiles[width/2][height/2].setBlock(Blocks.coreShard, Team.blue);
tiles[width/2][height/2 - 6].setBlock(Blocks.launchPad, Team.blue);
}