diff --git a/gameserver/src/main/java/brainwine/gameserver/zone/gen/GeneratorConfig.java b/gameserver/src/main/java/brainwine/gameserver/zone/gen/GeneratorConfig.java index eafb3f1..9fbbd19 100644 --- a/gameserver/src/main/java/brainwine/gameserver/zone/gen/GeneratorConfig.java +++ b/gameserver/src/main/java/brainwine/gameserver/zone/gen/GeneratorConfig.java @@ -15,6 +15,7 @@ import brainwine.gameserver.util.WeightedMap; import brainwine.gameserver.zone.gen.caves.CaveDecorator; import brainwine.gameserver.zone.gen.caves.CaveType; import brainwine.gameserver.zone.gen.models.Deposit; +import brainwine.gameserver.zone.gen.models.LayerSeparator; import brainwine.gameserver.zone.gen.models.OreDeposit; import brainwine.gameserver.zone.gen.models.SpecialStructure; import brainwine.gameserver.zone.gen.models.StoneType; @@ -33,6 +34,7 @@ public class GeneratorConfig { private double dungeonChance = 0.25; private double backgroundAccentChance = 0.033; private double backgroundDrawingChance = 0.001; + private LayerSeparator layerSeparator; private WeightedMap stoneTypes = new WeightedMap<>(); private WeightedMap spawnBuildings = new WeightedMap<>(); private WeightedMap dungeons = new WeightedMap<>(); @@ -86,6 +88,10 @@ public class GeneratorConfig { return backgroundDrawingChance; } + public LayerSeparator getLayerSeparator() { + return layerSeparator; + } + @JsonSetter(value = "stone_types", nulls = Nulls.SKIP) public WeightedMap getStoneTypes() { return stoneTypes; diff --git a/gameserver/src/main/java/brainwine/gameserver/zone/gen/models/LayerSeparator.java b/gameserver/src/main/java/brainwine/gameserver/zone/gen/models/LayerSeparator.java new file mode 100644 index 0000000..8bc144a --- /dev/null +++ b/gameserver/src/main/java/brainwine/gameserver/zone/gen/models/LayerSeparator.java @@ -0,0 +1,51 @@ +package brainwine.gameserver.zone.gen.models; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import brainwine.gameserver.item.Item; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class LayerSeparator { + + @JsonProperty("item") + private Item item; + + @JsonProperty("min_thickness") + private int minThickness = 3; + + @JsonProperty("max_thickness") + private int maxThickness = 6; + + @JsonProperty("min_amplitude") + private double minAmplitude = 20; + + @JsonProperty("max_amplitude") + private double maxAimplitude = 20; + + @JsonCreator + private LayerSeparator(@JsonProperty(value = "item", required = true) Item item) { + this.item = item; + } + + public Item getItem() { + return item; + } + + public int getMinThickness() { + return minThickness; + } + + public int getMaxThickness() { + return maxThickness; + } + + public double getMinAmplitude() { + return minAmplitude; + } + + public double getMaxAmplitude() { + return maxAimplitude; + } +} diff --git a/gameserver/src/main/java/brainwine/gameserver/zone/gen/tasks/CaveGeneratorTask.java b/gameserver/src/main/java/brainwine/gameserver/zone/gen/tasks/CaveGeneratorTask.java index 40f5868..3921ee7 100644 --- a/gameserver/src/main/java/brainwine/gameserver/zone/gen/tasks/CaveGeneratorTask.java +++ b/gameserver/src/main/java/brainwine/gameserver/zone/gen/tasks/CaveGeneratorTask.java @@ -99,11 +99,11 @@ public class CaveGeneratorTask implements GeneratorTask { // Generate a cave wall with a thickness depending on the size of the cave if(asteroids || stoneType != StoneType.DEFAULT) { ctx.updateBlock(x, y, Layer.BASE, stoneType.getBaseItem()); - int checkDistance = asteroids? 5 : 3; + int checkDistance = asteroids ? 5 : 3; for(int i = x - checkDistance; i <= x + checkDistance; i++) { for(int j = y - checkDistance; j <= y + checkDistance; j++) { - if(ctx.inBounds(i, j) && !cells[i][j]) { + if((asteroids ? ctx.isAir(i, j, Layer.FRONT) : ctx.isEarthy(i, j)) && !cells[i][j]) { double maxDistance = asteroids ? 4.5 + ctx.nextDouble() - 1 : MathUtils.clamp(cave.getSize() / 16.0, 1.8, checkDistance) + (ctx.nextDouble() - 0.5); double distance = Math.hypot(i - x, j - y); @@ -169,7 +169,8 @@ public class CaveGeneratorTask implements GeneratorTask { for(int x = 0; x < width; x++) { for(int y = 0; y < height; y++) { - if((y >= ctx.getSurface(x) + ctx.nextInt(3)) && ctx.nextDouble() <= cellRate) { + if((terrainType == TerrainType.ASTEROIDS ? ctx.isAir(x, y, Layer.FRONT) : ctx.isEarthy(x, y)) + && (y >= ctx.getSurface(x) + ctx.nextInt(3)) && ctx.nextDouble() <= cellRate) { cells[x][y] = true; } } diff --git a/gameserver/src/main/java/brainwine/gameserver/zone/gen/tasks/TerrainGeneratorTask.java b/gameserver/src/main/java/brainwine/gameserver/zone/gen/tasks/TerrainGeneratorTask.java index 26783f8..21e4dc2 100644 --- a/gameserver/src/main/java/brainwine/gameserver/zone/gen/tasks/TerrainGeneratorTask.java +++ b/gameserver/src/main/java/brainwine/gameserver/zone/gen/tasks/TerrainGeneratorTask.java @@ -1,10 +1,12 @@ package brainwine.gameserver.zone.gen.tasks; +import brainwine.gameserver.item.Item; import brainwine.gameserver.item.Layer; import brainwine.gameserver.util.SimplexNoise; import brainwine.gameserver.util.WeightedMap; import brainwine.gameserver.zone.gen.GeneratorConfig; import brainwine.gameserver.zone.gen.GeneratorContext; +import brainwine.gameserver.zone.gen.models.LayerSeparator; import brainwine.gameserver.zone.gen.models.TerrainType; import brainwine.gameserver.zone.gen.surface.SurfaceRegion; import brainwine.gameserver.zone.gen.surface.SurfaceRegionType; @@ -14,6 +16,7 @@ public class TerrainGeneratorTask implements GeneratorTask { private final TerrainType type; private final double minAmplitude; private final double maxAmplitude; + private final LayerSeparator layerSeparator; private final int surfaceRegionSize; private final WeightedMap surfaceRegionTypes; @@ -21,6 +24,7 @@ public class TerrainGeneratorTask implements GeneratorTask { type = config.getTerrainType(); minAmplitude = config.getMinAmplitude(); maxAmplitude = config.getMaxAmplitude(); + layerSeparator = config.getLayerSeparator(); surfaceRegionSize = config.getSurfaceRegionSize(); surfaceRegionTypes = config.getSurfaceRegionTypes(); } @@ -72,5 +76,24 @@ public class TerrainGeneratorTask implements GeneratorTask { ctx.updateBlock(x, y, Layer.BASE, "base/earth"); } } + + // Generate layer separators + if(layerSeparator != null) { + Item item = layerSeparator.getItem(); + int minThickness = layerSeparator.getMinThickness(); + int maxThickness = layerSeparator.getMaxThickness(); + double amplitude = ctx.nextDouble() * (layerSeparator.getMaxAmplitude() - layerSeparator.getMinAmplitude()) + layerSeparator.getMinAmplitude(); + + for(int depth : ctx.getZone().getDepths()) { + for(int x = 0; x < width; x++) { + int start = (int)(SimplexNoise.noise2(ctx.getSeed(), x / 256.0, 0, 7) * amplitude) + depth - maxThickness / 2; + int size = ctx.nextInt(maxThickness - minThickness) + minThickness; + + for(int y = start; y < start + size; y++) { + ctx.updateBlock(x, y, item.getLayer(), item); + } + } + } + } } } diff --git a/gameserver/src/main/resources/defaults/generators/deep.json b/gameserver/src/main/resources/defaults/generators/deep.json index a218fd0..f23768f 100644 --- a/gameserver/src/main/resources/defaults/generators/deep.json +++ b/gameserver/src/main/resources/defaults/generators/deep.json @@ -4,6 +4,13 @@ "dungeon_chance": 0.4, "background_accent_chance": 0.033, "background_drawing_chance": 0.001, + "layer_separator": { + "item": "ground/blackrock", + "min_thickness": 3, + "max_thickness": 6, + "min_amplitude": 20, + "max_amplitude": 20 + }, "stone_types": { "default": 17, "limestone": 4 diff --git a/gameserver/src/main/resources/defaults/generators/hell.json b/gameserver/src/main/resources/defaults/generators/hell.json index c577dc7..67c5ddf 100644 --- a/gameserver/src/main/resources/defaults/generators/hell.json +++ b/gameserver/src/main/resources/defaults/generators/hell.json @@ -7,6 +7,13 @@ "dungeon_chance": 0.375, "background_accent_chance": 0.033, "background_drawing_chance": 0.001, + "layer_separator": { + "item": "ground/blackrock", + "min_thickness": 3, + "max_thickness": 6, + "min_amplitude": 20, + "max_amplitude": 20 + }, "stone_types": { "default": 1 },