Add layer separator zone generator feature

This commit is contained in:
kuroppoi 2024-02-17 22:33:20 +01:00
parent c6779f0f61
commit 3bba0893b5
6 changed files with 98 additions and 3 deletions

View file

@ -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<StoneType> stoneTypes = new WeightedMap<>();
private WeightedMap<Prefab> spawnBuildings = new WeightedMap<>();
private WeightedMap<Prefab> 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<StoneType> getStoneTypes() {
return stoneTypes;

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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<SurfaceRegionType> 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);
}
}
}
}
}
}

View file

@ -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

View file

@ -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
},