forked from Apancore.Studio/simple-makes-complex
MapGen: updagrade biomes scattering
This commit is contained in:
@@ -44,7 +44,6 @@ local Cavern = require('MapGen.Cavern')
|
|||||||
---@field isRunning boolean A static field that guarantees that only one instance of the `MapGen` class will work.
|
---@field isRunning boolean A static field that guarantees that only one instance of the `MapGen` class will work.
|
||||||
---@field nodeIDs table<string, number>
|
---@field nodeIDs table<string, number>
|
||||||
---@field waterLevel number
|
---@field waterLevel number
|
||||||
---@field biomesBorderScattering number
|
|
||||||
local MapGen = {
|
local MapGen = {
|
||||||
layersByName = {},
|
layersByName = {},
|
||||||
layersList = {},
|
layersList = {},
|
||||||
@@ -56,7 +55,6 @@ local MapGen = {
|
|||||||
---@class MapGenDef
|
---@class MapGenDef
|
||||||
---@field nodes table<string, string>
|
---@field nodes table<string, string>
|
||||||
---@field waterLevel number?
|
---@field waterLevel number?
|
||||||
---@field biomesBorderScattering number?
|
|
||||||
|
|
||||||
---@param def MapGenDef
|
---@param def MapGenDef
|
||||||
---@return MapGen
|
---@return MapGen
|
||||||
@@ -72,7 +70,6 @@ function MapGen:new(def)
|
|||||||
nodes = def.nodes,
|
nodes = def.nodes,
|
||||||
nodeIDs = nodesIDs,
|
nodeIDs = nodesIDs,
|
||||||
waterLevel = def.waterLevel or 0,
|
waterLevel = def.waterLevel or 0,
|
||||||
biomesBorderScattering = def.biomesBorderScattering or 0
|
|
||||||
}, {__index = self})
|
}, {__index = self})
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
@@ -301,24 +298,32 @@ local function generateNode(mapGenerator, layer, height, temp, humidity, data, i
|
|||||||
local ids = mapGenerator.nodeIDs
|
local ids = mapGenerator.nodeIDs
|
||||||
local waterLevel = mapGenerator.waterLevel
|
local waterLevel = mapGenerator.waterLevel
|
||||||
|
|
||||||
local scattering = mapGenerator.biomesBorderScattering
|
-- Creating a rougher biome boundary.
|
||||||
|
local scatteringGorizontal = layer.biomesGorizontalScattering
|
||||||
|
local scatteringVertical = layer.biomesVerticalScattering
|
||||||
|
local scattHeight = y
|
||||||
|
|
||||||
if scattering ~= 0 then
|
if scatteringGorizontal ~= 0 then
|
||||||
---@diagnostic disable-next-line: param-type-not-match
|
---@diagnostic disable-next-line: param-type-not-match
|
||||||
scattering = math.random(scattering * -1, scattering)
|
scatteringGorizontal = math.random(scatteringGorizontal * -1, scatteringGorizontal)
|
||||||
temp = temp + scattering
|
temp = temp + scatteringGorizontal
|
||||||
humidity = humidity + scattering
|
humidity = humidity + scatteringGorizontal
|
||||||
--scatteringY = y + scattering
|
|
||||||
end
|
end
|
||||||
|
|
||||||
temp = mathMin(layer.maxTemp, mathMax(layer.minTemp, temp))
|
if scatteringVertical ~= 0 then
|
||||||
humidity = mathMin(layer.maxHumidity, mathMax(layer.minHumidity, humidity))
|
---@diagnostic disable-next-line: param-type-not-match
|
||||||
--scatteringY = mathMin(layer.maxY, mathMax(layer.minY, scatteringY + scattering))
|
scatteringVertical = math.random(scatteringVertical * -1, scatteringVertical)
|
||||||
|
scattHeight = scattHeight + scatteringVertical
|
||||||
|
end
|
||||||
|
|
||||||
height, temp, humidity = mathRound(height), mathRound(temp), mathRound(humidity)
|
temp = math.clamp(temp, layer.minTemp, layer.maxTemp)
|
||||||
|
humidity = math.clamp(humidity, layer.minHumidity, layer.maxHumidity)
|
||||||
|
scattHeight = math.clamp(scattHeight, layer.minY, layer.maxY)
|
||||||
|
|
||||||
|
height, scattHeight, temp, humidity = mathRound(height), mathRound(scattHeight), mathRound(temp), mathRound(humidity)
|
||||||
|
|
||||||
---@type MapGen.Biome
|
---@type MapGen.Biome
|
||||||
local biome = layer.biomesDiagram[y][temp][humidity]
|
local biome = layer.biomesDiagram[scattHeight][temp][humidity]
|
||||||
|
|
||||||
-- If the block is above surface height and above water level...
|
-- If the block is above surface height and above water level...
|
||||||
if y > height and y > waterLevel then
|
if y > height and y > waterLevel then
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
---@field biomesByName table<string, MapGen.Biome>
|
---@field biomesByName table<string, MapGen.Biome>
|
||||||
---@field biomesList MapGen.Biome[]
|
---@field biomesList MapGen.Biome[]
|
||||||
---@field biomesDiagram table
|
---@field biomesDiagram table
|
||||||
|
---@field biomesGorizontalScattering number
|
||||||
|
---@field biomesVerticalScattering number
|
||||||
---@field cavernsByName table<string, MapGen.Cavern>
|
---@field cavernsByName table<string, MapGen.Cavern>
|
||||||
---@field cavernsList MapGen.Cavern[]
|
---@field cavernsList MapGen.Cavern[]
|
||||||
---@field trianglesList MapGen.Triangle[]
|
---@field trianglesList MapGen.Triangle[]
|
||||||
@@ -39,6 +41,8 @@ local Layer = {
|
|||||||
---@field maxHumidity number
|
---@field maxHumidity number
|
||||||
---@field calcTemp (fun(self:MapGen.Layer, value:number, height:number):number)?
|
---@field calcTemp (fun(self:MapGen.Layer, value:number, height:number):number)?
|
||||||
---@field calcHumidity (fun(self:MapGen.Layer, value:number, height:number):number)?
|
---@field calcHumidity (fun(self:MapGen.Layer, value:number, height:number):number)?
|
||||||
|
---@field biomesGorizontalScattering number?
|
||||||
|
---@field biomesVerticalScattering number?
|
||||||
|
|
||||||
---@param self MapGen.Layer
|
---@param self MapGen.Layer
|
||||||
---@param value number
|
---@param value number
|
||||||
@@ -73,6 +77,8 @@ function Layer:new(name, def)
|
|||||||
maxHumidity = def.maxHumidity,
|
maxHumidity = def.maxHumidity,
|
||||||
calcTemp = def.calcTemp,
|
calcTemp = def.calcTemp,
|
||||||
calcHumidity = def.calcHumidity,
|
calcHumidity = def.calcHumidity,
|
||||||
|
biomesGorizontalScattering = def.biomesGorizontalScattering or 0,
|
||||||
|
biomesVerticalScattering = def.biomesVerticalScattering or 0,
|
||||||
}, {__index = self})
|
}, {__index = self})
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ local MapGen = mapGenRequire('MapGen')
|
|||||||
water = "liquids:water_source",
|
water = "liquids:water_source",
|
||||||
},
|
},
|
||||||
waterLevel = 10,
|
waterLevel = 10,
|
||||||
biomesBorderScattering = 5,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
local function calcTemp(layer, value, height)
|
local function calcTemp(layer, value, height)
|
||||||
@@ -89,6 +88,8 @@ mapGenerator:RegisterLayer("world", {
|
|||||||
maxHumidity = 100,
|
maxHumidity = 100,
|
||||||
calcTemp = calcTemp,
|
calcTemp = calcTemp,
|
||||||
calcHumidity = calcHumidity,
|
calcHumidity = calcHumidity,
|
||||||
|
biomesVerticalScattering = 10,
|
||||||
|
biomesGorizontalScattering = 5
|
||||||
})
|
})
|
||||||
|
|
||||||
local land1 = {
|
local land1 = {
|
||||||
@@ -242,7 +243,7 @@ mapGenerator:registerBiome('world', "biome1", {
|
|||||||
tempPoint = 0,
|
tempPoint = 0,
|
||||||
humidityPoint = 0,
|
humidityPoint = 0,
|
||||||
minY = -10000,
|
minY = -10000,
|
||||||
maxY = 1000,
|
maxY = -25,
|
||||||
groundNodes = {
|
groundNodes = {
|
||||||
soil = "soils:clay_soil_baren",
|
soil = "soils:clay_soil_baren",
|
||||||
turf = "soils:clay_soil_baren",
|
turf = "soils:clay_soil_baren",
|
||||||
@@ -257,7 +258,7 @@ mapGenerator:registerBiome('world', "biome1", {
|
|||||||
mapGenerator:registerBiome('world', "biome2", {
|
mapGenerator:registerBiome('world', "biome2", {
|
||||||
tempPoint = 100,
|
tempPoint = 100,
|
||||||
humidityPoint = 100,
|
humidityPoint = 100,
|
||||||
minY = -1000,
|
minY = -25,
|
||||||
maxY = 1000,
|
maxY = 1000,
|
||||||
groundNodes = {
|
groundNodes = {
|
||||||
soil = "soils:rocky_soil_baren",
|
soil = "soils:rocky_soil_baren",
|
||||||
|
|||||||
Reference in New Issue
Block a user