Fixed some generation issues
This commit is contained in:
@@ -9,6 +9,8 @@ import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.io.JsonIO;
|
||||
import io.anuke.mindustry.maps.filters.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class Map implements Comparable<Map>{
|
||||
/** Whether this is a custom map. */
|
||||
public final boolean custom;
|
||||
@@ -69,7 +71,7 @@ public class Map implements Comparable<Map>{
|
||||
|
||||
/** Returns the generation filters that this map uses on load.*/
|
||||
public Array<GenerateFilter> filters(){
|
||||
return JsonIO.read(Array.class, tags.get("genfilters", "{}"));
|
||||
return world.maps.readFilters(tags.get("genfilters", ""));
|
||||
}
|
||||
|
||||
public String author(){
|
||||
|
||||
@@ -10,6 +10,7 @@ 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.maps.filters.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.blocks.storage.*;
|
||||
|
||||
@@ -181,6 +182,34 @@ public class Maps implements Disposable{
|
||||
map.file.delete();
|
||||
}
|
||||
|
||||
/** Reads JSON of filters, returning a new default array if not found.*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Array<GenerateFilter> readFilters(String str){
|
||||
if(str == null || str.isEmpty()){
|
||||
return Array.with(
|
||||
//stone
|
||||
new ScatterFilter(){{
|
||||
flooronto = Blocks.stone;
|
||||
block = Blocks.rock;
|
||||
}},
|
||||
new ScatterFilter(){{
|
||||
flooronto = Blocks.shale;
|
||||
block = Blocks.shaleBoulder;
|
||||
}},
|
||||
new ScatterFilter(){{
|
||||
flooronto = Blocks.snow;
|
||||
block = Blocks.snowrock;
|
||||
}},
|
||||
new ScatterFilter(){{
|
||||
flooronto = Blocks.ice;
|
||||
block = Blocks.snowrock;
|
||||
}}
|
||||
);
|
||||
}else{
|
||||
return JsonIO.read(Array.class, str);
|
||||
}
|
||||
}
|
||||
|
||||
public String writeWaves(Array<SpawnGroup> groups){
|
||||
if(groups == null){
|
||||
return "[]";
|
||||
|
||||
@@ -68,12 +68,7 @@ public abstract class GenerateFilter{
|
||||
|
||||
/** an input for generating at a certain coordinate. should only be instantiated once. */
|
||||
public static class GenerateInput{
|
||||
/** input floor */
|
||||
public Floor srcfloor;
|
||||
/** input block */
|
||||
public Block srcblock;
|
||||
/** input overlay */
|
||||
public Block srcore;
|
||||
|
||||
/** input size parameters */
|
||||
public int x, y, width, height;
|
||||
|
||||
@@ -85,9 +80,9 @@ public abstract class GenerateFilter{
|
||||
TileProvider buffer;
|
||||
|
||||
public void apply(int x, int y, Block floor, Block block, Block ore){
|
||||
this.floor = this.srcfloor = (Floor)floor;
|
||||
this.block = this.srcblock = block;
|
||||
this.ore = srcore = ore;
|
||||
this.floor = floor;
|
||||
this.block = block;
|
||||
this.ore = ore;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class NoiseFilter extends GenerateFilter{
|
||||
|
||||
if(noise > threshold){
|
||||
in.floor = floor;
|
||||
if(wallsOnly.test(in.srcblock)) in.block = block;
|
||||
if(wallsOnly.test(in.block)) in.block = block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class RiverNoiseFilter extends GenerateFilter{
|
||||
if(noise >= threshold){
|
||||
in.floor = floor;
|
||||
|
||||
if(in.srcblock.solid){
|
||||
if(in.block.solid){
|
||||
in.block = block;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ import io.anuke.mindustry.world.Block;
|
||||
import static io.anuke.mindustry.maps.filters.FilterOption.*;
|
||||
|
||||
public class ScatterFilter extends GenerateFilter{
|
||||
float chance = 0.1f;
|
||||
Block flooronto = Blocks.air, floor = Blocks.air, block = Blocks.air;
|
||||
protected float chance = 0.014f;
|
||||
protected Block flooronto = Blocks.air, floor = Blocks.air, block = Blocks.air;
|
||||
|
||||
{
|
||||
options(
|
||||
@@ -23,7 +23,7 @@ public class ScatterFilter extends GenerateFilter{
|
||||
@Override
|
||||
public void apply(){
|
||||
|
||||
if(block != Blocks.air && (in.srcfloor == flooronto || flooronto == Blocks.air) && in.srcblock == Blocks.air && chance() <= chance){
|
||||
if(block != Blocks.air && (in.floor == flooronto || flooronto == Blocks.air) && in.block == Blocks.air && chance() <= chance){
|
||||
if(!block.isOverlay()){
|
||||
in.block = block;
|
||||
}else{
|
||||
@@ -31,7 +31,7 @@ public class ScatterFilter extends GenerateFilter{
|
||||
}
|
||||
}
|
||||
|
||||
if(floor != Blocks.air && (in.srcfloor == flooronto || flooronto == Blocks.air) && chance() <= chance){
|
||||
if(floor != Blocks.air && (in.floor == flooronto || flooronto == Blocks.air) && chance() <= chance){
|
||||
in.floor = floor;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user