diff --git a/core/src/mindustry/editor/MapGenerateDialog.java b/core/src/mindustry/editor/MapGenerateDialog.java index 71f4f60264..fc496f64a0 100644 --- a/core/src/mindustry/editor/MapGenerateDialog.java +++ b/core/src/mindustry/editor/MapGenerateDialog.java @@ -340,6 +340,7 @@ public class MapGenerateDialog extends BaseDialog{ if(filter.isPost() && applied) continue; p.button((icon == '\0' ? "" : icon + " ") + filter.name(), Styles.cleart, () -> { + filter.randomize(); filters.add(filter); rebuildFilters(); update(); diff --git a/core/src/mindustry/editor/MapInfoDialog.java b/core/src/mindustry/editor/MapInfoDialog.java index a18828f1f0..da4bf5a4b3 100644 --- a/core/src/mindustry/editor/MapInfoDialog.java +++ b/core/src/mindustry/editor/MapInfoDialog.java @@ -3,6 +3,7 @@ package mindustry.editor; import arc.*; import arc.scene.ui.*; import arc.struct.*; +import arc.util.*; import mindustry.*; import mindustry.game.*; import mindustry.io.*; @@ -73,8 +74,12 @@ public class MapInfoDialog extends BaseDialog{ t.row(); t.add("@editor.generation").padRight(8).left(); t.button("@edit", () -> { - generate.show(Vars.maps.readFilters(editor.tags.get("genfilters", "")), - filters -> editor.tags.put("genfilters", JsonIO.write(filters))); + generate.show(maps.readFilters(editor.tags.get("genfilters", "")), + filters -> { + //reset seed to 0 so it is not written + filters.each(f -> f.seed = 0); + editor.tags.put("genfilters", JsonIO.write(filters)); + }); hide(); }).left().width(200f); diff --git a/core/src/mindustry/maps/filters/BlendFilter.java b/core/src/mindustry/maps/filters/BlendFilter.java index d8d1ceda9e..ab5171b00f 100644 --- a/core/src/mindustry/maps/filters/BlendFilter.java +++ b/core/src/mindustry/maps/filters/BlendFilter.java @@ -1,6 +1,5 @@ package mindustry.maps.filters; -import arc.util.*; import mindustry.content.*; import mindustry.gen.*; import mindustry.world.*; @@ -13,12 +12,12 @@ public class BlendFilter extends GenerateFilter{ @Override public FilterOption[] options(){ - return Structs.arr( - new SliderOption("radius", () -> radius, f -> radius = f, 1f, 10f), - new BlockOption("block", () -> block, b -> block = b, anyOptional), - new BlockOption("floor", () -> floor, b -> floor = b, anyOptional), - new BlockOption("ignore", () -> ignore, b -> ignore = b, floorsOptional) - ); + return new FilterOption[]{ + new SliderOption("radius", () -> radius, f -> radius = f, 1f, 10f), + new BlockOption("block", () -> block, b -> block = b, anyOptional), + new BlockOption("floor", () -> floor, b -> floor = b, anyOptional), + new BlockOption("ignore", () -> ignore, b -> ignore = b, floorsOptional) + }; } @Override diff --git a/core/src/mindustry/maps/filters/ClearFilter.java b/core/src/mindustry/maps/filters/ClearFilter.java index 59e1a5b53c..1ce2ca6a25 100644 --- a/core/src/mindustry/maps/filters/ClearFilter.java +++ b/core/src/mindustry/maps/filters/ClearFilter.java @@ -1,6 +1,5 @@ package mindustry.maps.filters; -import arc.util.*; import mindustry.content.*; import mindustry.gen.*; import mindustry.world.*; @@ -12,7 +11,9 @@ public class ClearFilter extends GenerateFilter{ @Override public FilterOption[] options(){ - return Structs.arr(new BlockOption("block", () -> block, b -> block = b, b -> oresOnly.get(b) || wallsOnly.get(b))); + return new BlockOption[]{ + new BlockOption("block", () -> block, b -> block = b, b -> oresOnly.get(b) || wallsOnly.get(b)) + }; } @Override diff --git a/core/src/mindustry/maps/filters/CoreSpawnFilter.java b/core/src/mindustry/maps/filters/CoreSpawnFilter.java index 84447ea1f3..5e18726d45 100644 --- a/core/src/mindustry/maps/filters/CoreSpawnFilter.java +++ b/core/src/mindustry/maps/filters/CoreSpawnFilter.java @@ -1,7 +1,6 @@ package mindustry.maps.filters; import arc.struct.*; -import arc.util.*; import mindustry.gen.*; import mindustry.world.*; import mindustry.world.blocks.storage.*; @@ -14,10 +13,9 @@ public class CoreSpawnFilter extends GenerateFilter{ @Override public FilterOption[] options(){ - return Structs.arr( //disabled until necessary // SliderOption("amount", () -> amount, f -> amount = (int)f, 1, 10).display() - ); + return new FilterOption[]{}; } @Override diff --git a/core/src/mindustry/maps/filters/DistortFilter.java b/core/src/mindustry/maps/filters/DistortFilter.java index 4ae9c5a1d2..23f7f42a91 100644 --- a/core/src/mindustry/maps/filters/DistortFilter.java +++ b/core/src/mindustry/maps/filters/DistortFilter.java @@ -1,6 +1,5 @@ package mindustry.maps.filters; -import arc.util.*; import mindustry.gen.*; import mindustry.maps.filters.FilterOption.*; import mindustry.world.*; @@ -10,10 +9,10 @@ public class DistortFilter extends GenerateFilter{ @Override public FilterOption[] options(){ - return Structs.arr( - new SliderOption("scale", () -> scl, f -> scl = f, 1f, 200f), - new SliderOption("mag", () -> mag, f -> mag = f, 0.5f, 100f) - ); + return new SliderOption[]{ + new SliderOption("scale", () -> scl, f -> scl = f, 1f, 200f), + new SliderOption("mag", () -> mag, f -> mag = f, 0.5f, 100f) + }; } @Override @@ -28,7 +27,7 @@ public class DistortFilter extends GenerateFilter{ @Override public void apply(){ - Tile tile = in.tile(in.x + noise(in.x, in.y, scl, mag) - mag / 2f, in.y + noise(in.x, in.y + o, scl, mag) - mag / 2f); + Tile tile = in.tile(in.x + noise(in.x, in.y, scl, mag) - mag / 2f, in.y + noise(in.x, in.y, scl, mag) - mag / 2f); in.floor = tile.floor(); if(!tile.block().synthetic() && !in.block.synthetic()) in.block = tile.block(); diff --git a/core/src/mindustry/maps/filters/EnemySpawnFilter.java b/core/src/mindustry/maps/filters/EnemySpawnFilter.java index 682d82debf..7d2a5d8d1d 100644 --- a/core/src/mindustry/maps/filters/EnemySpawnFilter.java +++ b/core/src/mindustry/maps/filters/EnemySpawnFilter.java @@ -1,7 +1,6 @@ package mindustry.maps.filters; import arc.struct.*; -import arc.util.*; import mindustry.content.*; import mindustry.gen.*; import mindustry.maps.filters.FilterOption.*; @@ -13,9 +12,9 @@ public class EnemySpawnFilter extends GenerateFilter{ @Override public FilterOption[] options(){ - return Structs.arr( - new SliderOption("amount", () -> amount, f -> amount = (int)f, 1, 10).display() - ); + return new SliderOption[]{ + new SliderOption("amount", () -> amount, f -> amount = (int)f, 1, 10).display() + }; } @Override diff --git a/core/src/mindustry/maps/filters/GenerateFilter.java b/core/src/mindustry/maps/filters/GenerateFilter.java index b938914528..51db9bf07b 100644 --- a/core/src/mindustry/maps/filters/GenerateFilter.java +++ b/core/src/mindustry/maps/filters/GenerateFilter.java @@ -12,8 +12,8 @@ import mindustry.gen.*; import mindustry.world.*; public abstract class GenerateFilter{ - protected transient float o = (float)(Math.random() * 10000000.0); - protected transient int seed; + public int seed = 0; + protected transient GenerateInput in; public void apply(Tiles tiles, GenerateInput in){ @@ -93,7 +93,7 @@ public abstract class GenerateFilter{ /** set the seed to a random number */ public void randomize(){ - seed = Mathf.random(99999999); + seed = Mathf.random(999999999); } /** @return whether this filter needs a read/write buffer (e.g. not a 1:1 tile mapping). */ @@ -109,19 +109,19 @@ public abstract class GenerateFilter{ //utility generation functions protected float noise(float x, float y, float scl, float mag){ - return (float)in.noise.octaveNoise2D(1f, 0f, 1f / scl, x + o, y + o) * mag; + return (float)in.noise.octaveNoise2D(1f, 0f, 1f / scl, x, y) * mag; } protected float noise(float x, float y, float scl, float mag, float octaves, float persistence){ - return (float)in.noise.octaveNoise2D(octaves, persistence, 1f / scl, x + o, y + o) * mag; + return (float)in.noise.octaveNoise2D(octaves, persistence, 1f / scl, x, y) * mag; } protected float rnoise(float x, float y, float scl, float mag){ - return RidgedPerlin.noise2d(seed + 1, (int)(x + o), (int)(y + o), 1f / scl) * mag; + return RidgedPerlin.noise2d(seed + 1, (int)(x), (int)(y), 1f / scl) * mag; } protected float rnoise(float x, float y, int octaves, float scl, float falloff, float mag){ - return RidgedPerlin.noise2d(seed + 1, (int)(x + o), (int)(y + o), octaves, falloff, 1f / scl) * mag; + return RidgedPerlin.noise2d(seed + 1, (int)(x), (int)(y), octaves, falloff, 1f / scl) * mag; } protected float chance(){ diff --git a/core/src/mindustry/maps/filters/MedianFilter.java b/core/src/mindustry/maps/filters/MedianFilter.java index 001d79bba5..d97d469952 100644 --- a/core/src/mindustry/maps/filters/MedianFilter.java +++ b/core/src/mindustry/maps/filters/MedianFilter.java @@ -2,7 +2,6 @@ package mindustry.maps.filters; import arc.math.*; import arc.struct.*; -import arc.util.*; import mindustry.gen.*; import mindustry.maps.filters.FilterOption.*; import mindustry.world.*; @@ -17,10 +16,10 @@ public class MedianFilter extends GenerateFilter{ @Override public FilterOption[] options(){ - return Structs.arr( - new SliderOption("radius", () -> radius, f -> radius = f, 1f, 10f), - new SliderOption("percentile", () -> percentile, f -> percentile = f, 0f, 1f) - ); + return new SliderOption[]{ + new SliderOption("radius", () -> radius, f -> radius = f, 1f, 10f), + new SliderOption("percentile", () -> percentile, f -> percentile = f, 0f, 1f) + }; } @Override diff --git a/core/src/mindustry/maps/filters/MirrorFilter.java b/core/src/mindustry/maps/filters/MirrorFilter.java index 9e91fb4847..33bd6ace94 100644 --- a/core/src/mindustry/maps/filters/MirrorFilter.java +++ b/core/src/mindustry/maps/filters/MirrorFilter.java @@ -19,10 +19,10 @@ public class MirrorFilter extends GenerateFilter{ @Override public FilterOption[] options(){ - return Structs.arr( - new SliderOption("angle", () -> angle, f -> angle = (int)f, 0, 360, 45), - new ToggleOption("rotate", () -> rotate, f -> rotate = f) - ); + return new FilterOption[]{ + new SliderOption("angle", () -> angle, f -> angle = (int)f, 0, 360, 45), + new ToggleOption("rotate", () -> rotate, f -> rotate = f) + }; } @Override diff --git a/core/src/mindustry/maps/filters/NoiseFilter.java b/core/src/mindustry/maps/filters/NoiseFilter.java index acbf8162c6..986ee077ce 100644 --- a/core/src/mindustry/maps/filters/NoiseFilter.java +++ b/core/src/mindustry/maps/filters/NoiseFilter.java @@ -1,6 +1,5 @@ package mindustry.maps.filters; -import arc.util.*; import mindustry.content.*; import mindustry.gen.*; import mindustry.world.*; @@ -13,15 +12,15 @@ public class NoiseFilter extends GenerateFilter{ @Override public FilterOption[] options(){ - return Structs.arr( - new SliderOption("scale", () -> scl, f -> scl = f, 1f, 500f), - 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 BlockOption("target", () -> target, b -> target = b, anyOptional), - new BlockOption("floor", () -> floor, b -> floor = b, floorsOptional), - new BlockOption("wall", () -> block, b -> block = b, wallsOptional) - ); + return new FilterOption[]{ + new SliderOption("scale", () -> scl, f -> scl = f, 1f, 500f), + 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 BlockOption("target", () -> target, b -> target = b, anyOptional), + new BlockOption("floor", () -> floor, b -> floor = b, floorsOptional), + new BlockOption("wall", () -> block, b -> block = b, wallsOptional) + }; } @Override diff --git a/core/src/mindustry/maps/filters/OreFilter.java b/core/src/mindustry/maps/filters/OreFilter.java index 5487ea0d59..67c79ab82c 100644 --- a/core/src/mindustry/maps/filters/OreFilter.java +++ b/core/src/mindustry/maps/filters/OreFilter.java @@ -1,6 +1,5 @@ package mindustry.maps.filters; -import arc.util.*; import mindustry.content.*; import mindustry.gen.*; import mindustry.world.*; @@ -13,14 +12,14 @@ public class OreFilter extends GenerateFilter{ @Override public FilterOption[] options(){ - return Structs.arr( - new SliderOption("scale", () -> scl, f -> scl = f, 1f, 500f), - 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 BlockOption("ore", () -> ore, b -> ore = b, oresOnly), - new BlockOption("target", () -> target, b -> target = b, oresFloorsOptional) - ); + return new FilterOption[]{ + new SliderOption("scale", () -> scl, f -> scl = f, 1f, 500f), + 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 BlockOption("ore", () -> ore, b -> ore = b, oresOnly), + new BlockOption("target", () -> target, b -> target = b, oresFloorsOptional) + }; } @Override diff --git a/core/src/mindustry/maps/filters/OreMedianFilter.java b/core/src/mindustry/maps/filters/OreMedianFilter.java index cba1d56936..97f5557925 100644 --- a/core/src/mindustry/maps/filters/OreMedianFilter.java +++ b/core/src/mindustry/maps/filters/OreMedianFilter.java @@ -2,7 +2,6 @@ package mindustry.maps.filters; import arc.math.*; import arc.struct.*; -import arc.util.*; import mindustry.*; import mindustry.content.*; import mindustry.gen.*; @@ -17,10 +16,10 @@ public class OreMedianFilter extends GenerateFilter{ @Override public FilterOption[] options(){ - return Structs.arr( - new SliderOption("radius", () -> radius, f -> radius = f, 1f, 12f), - new SliderOption("percentile", () -> percentile, f -> percentile = f, 0f, 1f) - ); + return new SliderOption[]{ + new SliderOption("radius", () -> radius, f -> radius = f, 1f, 12f), + new SliderOption("percentile", () -> percentile, f -> percentile = f, 0f, 1f) + }; } @Override diff --git a/core/src/mindustry/maps/filters/RiverNoiseFilter.java b/core/src/mindustry/maps/filters/RiverNoiseFilter.java index aeefe8422a..af82b91886 100644 --- a/core/src/mindustry/maps/filters/RiverNoiseFilter.java +++ b/core/src/mindustry/maps/filters/RiverNoiseFilter.java @@ -1,6 +1,5 @@ package mindustry.maps.filters; -import arc.util.*; import mindustry.content.*; import mindustry.gen.*; import mindustry.world.*; @@ -13,16 +12,16 @@ public class RiverNoiseFilter extends GenerateFilter{ @Override public FilterOption[] options(){ - return Structs.arr( - new SliderOption("scale", () -> scl, f -> scl = f, 1f, 500f), - new SliderOption("threshold", () -> threshold, f -> threshold = f, -1f, 1f), - new SliderOption("threshold2", () -> threshold2, f -> threshold2 = f, -1f, 1f), - new SliderOption("octaves", () -> octaves, f -> octaves = f, 1f, 10f), - new SliderOption("falloff", () -> falloff, f -> falloff = f, 0f, 1f), - new BlockOption("block", () -> block, b -> block = b, wallsOnly), - new BlockOption("floor", () -> floor, b -> floor = b, floorsOnly), - new BlockOption("floor2", () -> floor2, b -> floor2 = b, floorsOnly) - ); + return new FilterOption[]{ + new SliderOption("scale", () -> scl, f -> scl = f, 1f, 500f), + new SliderOption("threshold", () -> threshold, f -> threshold = f, -1f, 1f), + new SliderOption("threshold2", () -> threshold2, f -> threshold2 = f, -1f, 1f), + new SliderOption("octaves", () -> octaves, f -> octaves = f, 1f, 10f), + new SliderOption("falloff", () -> falloff, f -> falloff = f, 0f, 1f), + new BlockOption("block", () -> block, b -> block = b, wallsOnly), + new BlockOption("floor", () -> floor, b -> floor = b, floorsOnly), + new BlockOption("floor2", () -> floor2, b -> floor2 = b, floorsOnly) + }; } @Override diff --git a/core/src/mindustry/maps/filters/ScatterFilter.java b/core/src/mindustry/maps/filters/ScatterFilter.java index b766183087..5787648276 100644 --- a/core/src/mindustry/maps/filters/ScatterFilter.java +++ b/core/src/mindustry/maps/filters/ScatterFilter.java @@ -1,6 +1,5 @@ package mindustry.maps.filters; -import arc.util.*; import mindustry.content.*; import mindustry.gen.*; import mindustry.world.*; @@ -13,12 +12,12 @@ public class ScatterFilter extends GenerateFilter{ @Override public FilterOption[] options(){ - return Structs.arr( - new SliderOption("chance", () -> chance, f -> chance = f, 0f, 1f), - new BlockOption("flooronto", () -> flooronto, b -> flooronto = b, floorsOptional), - new BlockOption("floor", () -> floor, b -> floor = b, floorsOptional), - new BlockOption("block", () -> block, b -> block = b, wallsOresOptional) - ); + return new FilterOption[]{ + new SliderOption("chance", () -> chance, f -> chance = f, 0f, 1f), + new BlockOption("flooronto", () -> flooronto, b -> flooronto = b, floorsOptional), + new BlockOption("floor", () -> floor, b -> floor = b, floorsOptional), + new BlockOption("block", () -> block, b -> block = b, wallsOresOptional) + }; } @Override diff --git a/core/src/mindustry/maps/filters/SpawnPathFilter.java b/core/src/mindustry/maps/filters/SpawnPathFilter.java index ac49b13d31..09d453e513 100644 --- a/core/src/mindustry/maps/filters/SpawnPathFilter.java +++ b/core/src/mindustry/maps/filters/SpawnPathFilter.java @@ -19,9 +19,9 @@ public class SpawnPathFilter extends GenerateFilter{ @Override public FilterOption[] options(){ - return Structs.arr( - new SliderOption("radius", () -> radius, f -> radius = (int)f, 1, 20).display() - ); + return new SliderOption[]{ + new SliderOption("radius", () -> radius, f -> radius = (int)f, 1, 20).display() + }; } @Override diff --git a/core/src/mindustry/maps/filters/TerrainFilter.java b/core/src/mindustry/maps/filters/TerrainFilter.java index f494d0c143..2c4a9f48c3 100644 --- a/core/src/mindustry/maps/filters/TerrainFilter.java +++ b/core/src/mindustry/maps/filters/TerrainFilter.java @@ -1,7 +1,6 @@ package mindustry.maps.filters; import arc.math.*; -import arc.util.*; import mindustry.content.*; import mindustry.gen.*; import mindustry.world.*; @@ -14,16 +13,16 @@ public class TerrainFilter extends GenerateFilter{ @Override public FilterOption[] options(){ - return Structs.arr( - new SliderOption("scale", () -> scl, f -> scl = f, 1f, 500f), - new SliderOption("mag", () -> magnitude, f -> magnitude = f, 0f, 2f), - new SliderOption("threshold", () -> threshold, f -> threshold = f, 0f, 1f), - 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 BlockOption("floor", () -> floor, b -> floor = b, floorsOptional), - new BlockOption("wall", () -> block, b -> block = b, wallsOnly) - ); + return new FilterOption[]{ + new SliderOption("scale", () -> scl, f -> scl = f, 1f, 500f), + new SliderOption("mag", () -> magnitude, f -> magnitude = f, 0f, 2f), + new SliderOption("threshold", () -> threshold, f -> threshold = f, 0f, 1f), + 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 BlockOption("floor", () -> floor, b -> floor = b, floorsOptional), + new BlockOption("wall", () -> block, b -> block = b, wallsOnly) + }; } @Override