Misc map creation utilities
This commit is contained in:
@@ -12,7 +12,7 @@ public class ClearFilter extends GenerateFilter{
|
||||
|
||||
@Override
|
||||
public FilterOption[] options(){
|
||||
return new BlockOption[]{
|
||||
return new FilterOption[]{
|
||||
new BlockOption("target", () -> target, b -> target = b, anyOptional),
|
||||
new BlockOption("replacement", () -> replace, b -> replace = b, anyOptional)
|
||||
};
|
||||
|
||||
@@ -111,6 +111,10 @@ public abstract class GenerateFilter{
|
||||
return Simplex.noise2d(seed, octaves, persistence, 1f / scl, in.x, in.y) * mag;
|
||||
}
|
||||
|
||||
protected float noise(float x, float y, float scl, float mag, float octaves, float persistence){
|
||||
return Simplex.noise2d(seed, octaves, persistence, 1f / scl, x, y) * mag;
|
||||
}
|
||||
|
||||
protected float rnoise(float x, float y, float scl, float mag){
|
||||
return Ridged.noise2d(seed + 1, (int)(x), (int)(y), 1f / scl) * mag;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import mindustry.world.*;
|
||||
import static mindustry.maps.filters.FilterOption.*;
|
||||
|
||||
public class NoiseFilter extends GenerateFilter{
|
||||
float scl = 40, threshold = 0.5f, octaves = 3f, falloff = 0.5f;
|
||||
Block floor = Blocks.stone, block = Blocks.stoneWall, target = Blocks.air;
|
||||
public float scl = 40, threshold = 0.5f, octaves = 3f, falloff = 0.5f, tilt = 0f;
|
||||
public Block floor = Blocks.stone, block = Blocks.stoneWall, target = Blocks.air;
|
||||
|
||||
@Override
|
||||
public FilterOption[] options(){
|
||||
@@ -17,6 +17,7 @@ public class NoiseFilter extends GenerateFilter{
|
||||
new SliderOption("threshold", () -> threshold, f -> threshold = f, 0f, 1f),
|
||||
new SliderOption("octaves", () -> octaves, f -> octaves = f, 1f, 10f),
|
||||
new SliderOption("falloff", () -> falloff, f -> falloff = f, 0f, 1f),
|
||||
new SliderOption("tilt", () -> tilt, f -> tilt = f, -4f, 4f),
|
||||
new BlockOption("target", () -> target, b -> target = b, anyOptional),
|
||||
new BlockOption("floor", () -> floor, b -> floor = b, floorsOptional),
|
||||
new BlockOption("wall", () -> block, b -> block = b, wallsOptional)
|
||||
@@ -30,7 +31,7 @@ public class NoiseFilter extends GenerateFilter{
|
||||
|
||||
@Override
|
||||
public void apply(GenerateInput in){
|
||||
float noise = noise(in, scl, 1f, octaves, falloff);
|
||||
float noise = noise(in.x, in.y + in.x * tilt, scl, 1f, octaves, falloff);
|
||||
|
||||
if(noise > threshold && (target == Blocks.air || in.floor == target || in.block == target)){
|
||||
if(floor != Blocks.air) in.floor = floor;
|
||||
|
||||
@@ -7,7 +7,7 @@ import mindustry.world.*;
|
||||
import static mindustry.maps.filters.FilterOption.*;
|
||||
|
||||
public class OreFilter extends GenerateFilter{
|
||||
public float scl = 23, threshold = 0.81f, octaves = 2f, falloff = 0.3f;
|
||||
public float scl = 23, threshold = 0.81f, octaves = 2f, falloff = 0.3f, tilt = 0f;
|
||||
public Block ore = Blocks.oreCopper, target = Blocks.air;
|
||||
|
||||
@Override
|
||||
@@ -17,6 +17,7 @@ public class OreFilter extends GenerateFilter{
|
||||
new SliderOption("threshold", () -> threshold, f -> threshold = f, 0f, 1f),
|
||||
new SliderOption("octaves", () -> octaves, f -> octaves = f, 1f, 10f),
|
||||
new SliderOption("falloff", () -> falloff, f -> falloff = f, 0f, 1f),
|
||||
new SliderOption("tilt", () -> tilt, f -> tilt = f, -4f, 4f),
|
||||
new BlockOption("ore", () -> ore, b -> ore = b, oresOnly),
|
||||
new BlockOption("target", () -> target, b -> target = b, oresFloorsOptional)
|
||||
};
|
||||
@@ -29,7 +30,7 @@ public class OreFilter extends GenerateFilter{
|
||||
|
||||
@Override
|
||||
public void apply(GenerateInput in){
|
||||
float noise = noise(in, scl, 1f, octaves, falloff);
|
||||
float noise = noise(in.x, in.y + in.x * tilt, scl, 1f, octaves, falloff);
|
||||
|
||||
if(noise > threshold && in.overlay != Blocks.spawn && (target == Blocks.air || in.floor == target || in.overlay == target) && in.floor.asFloor().hasSurface()){
|
||||
in.overlay = ore;
|
||||
|
||||
@@ -7,20 +7,22 @@ import mindustry.*;
|
||||
import mindustry.ai.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.maps.filters.FilterOption.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.storage.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
import static mindustry.maps.filters.FilterOption.*;
|
||||
|
||||
/** Selects X spawns from the spawn pool.*/
|
||||
public class SpawnPathFilter extends GenerateFilter{
|
||||
int radius = 3;
|
||||
public int radius = 3;
|
||||
public Block block = Blocks.air;
|
||||
|
||||
@Override
|
||||
public FilterOption[] options(){
|
||||
return new SliderOption[]{
|
||||
new SliderOption("radius", () -> radius, f -> radius = (int)f, 1, 20).display()
|
||||
return new FilterOption[]{
|
||||
new SliderOption("radius", () -> radius, f -> radius = (int)f, 1, 20).display(),
|
||||
new BlockOption("wall", () -> block, b -> block = b, wallsOnly)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -53,7 +55,7 @@ public class SpawnPathFilter extends GenerateFilter{
|
||||
if(Structs.inBounds(wx, wy, world.width(), world.height()) && Mathf.within(x, y, radius)){
|
||||
Tile other = tiles.getn(wx, wy);
|
||||
if(!other.synthetic()){
|
||||
other.setBlock(Blocks.air);
|
||||
other.setBlock(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import mindustry.world.*;
|
||||
import static mindustry.maps.filters.FilterOption.*;
|
||||
|
||||
public class TerrainFilter extends GenerateFilter{
|
||||
float scl = 40, threshold = 0.9f, octaves = 3f, falloff = 0.5f, magnitude = 1f, circleScl = 2.1f;
|
||||
float scl = 40, threshold = 0.9f, octaves = 3f, falloff = 0.5f, magnitude = 1f, circleScl = 2.1f, tilt = 0f;
|
||||
Block floor = Blocks.air, block = Blocks.stoneWall;
|
||||
|
||||
@Override
|
||||
@@ -20,6 +20,7 @@ public class TerrainFilter extends GenerateFilter{
|
||||
new SliderOption("circle-scale", () -> circleScl, f -> circleScl = f, 0f, 3f),
|
||||
new SliderOption("octaves", () -> octaves, f -> octaves = f, 1f, 10f),
|
||||
new SliderOption("falloff", () -> falloff, f -> falloff = f, 0f, 1f),
|
||||
new SliderOption("tilt", () -> tilt, f -> tilt = f, -4f, 4f),
|
||||
new BlockOption("floor", () -> floor, b -> floor = b, floorsOptional),
|
||||
new BlockOption("wall", () -> block, b -> block = b, wallsOnly)
|
||||
};
|
||||
@@ -32,7 +33,7 @@ public class TerrainFilter extends GenerateFilter{
|
||||
|
||||
@Override
|
||||
public void apply(GenerateInput in){
|
||||
float noise = noise(in, scl, magnitude, octaves, falloff) + Mathf.dst((float)in.x / in.width, (float)in.y / in.height, 0.5f, 0.5f) * circleScl;
|
||||
float noise = noise(in.x, in.y + in.x * tilt, scl, magnitude, octaves, falloff) + Mathf.dst((float)in.x / in.width, (float)in.y / in.height, 0.5f, 0.5f) * circleScl;
|
||||
|
||||
if(floor != Blocks.air){
|
||||
in.floor = floor;
|
||||
|
||||
Reference in New Issue
Block a user