Mapgen: write SuperUltraSigmaMapgen part 7.4

This commit is contained in:
Van
2025-11-24 20:50:10 +03:00
parent 83695071d2
commit 41c9933144
4 changed files with 86 additions and 22 deletions

View File

@@ -325,7 +325,7 @@ end
---@param mapGenerator MapGen
---@param layer MapGen.Layer
---@param hight number
---@param height number
---@param temp number
---@param humidity number
---@param data number[]
@@ -333,24 +333,25 @@ end
---@param x number
---@param y number
---@param z number
local function generateNode(mapGenerator, layer, hight, temp, humidity, data, index, x, y, z)
local function generateNode(mapGenerator, layer, height, temp, humidity, data, index, x, y, z)
local ids = mapGenerator.nodeIDs
local m = math.random(-10, 10)
local m = math.random(-5, 5)
temp = mathMin(100, mathMax(0, temp + m))
humidity = mathMin(100, mathMax(0, humidity + m))
--height = mathMin(layer.maxY, mathMax(layer.minY, y + m))
local biome = layer.biomesDiagram[mathRound(temp)][mathRound(humidity)]
local biome = layer.biomesDiagram[y][mathRound(temp)][mathRound(humidity)]
if y > hight and y > 0 then
if y > height and y > 0 then
data[index] = ids.air
elseif y > hight and y <= 0 then
elseif y > height and y <= 0 then
data[index] = ids.water
elseif y <= hight then
elseif y <= height then
if isCavern(layer, x, y, z) then
data[index] = ids.air
elseif y == hight then
elseif y == height then
generateSoil(biome, data, index, x, y, z)
else
generateRock(ids, data, index, x, y, z)

View File

@@ -14,7 +14,7 @@ local mathSqrt = math.sqrt
---@field tetrahedronsList MapGen.Tetrahedron[]
local Layer = {
peaksList = {},
biomesByName = {},
biomesByName = {},
biomesList = {},
biomesDiagram = {},
cavernsByName = {},
@@ -79,30 +79,80 @@ function Layer:getPeaksByPos(xPos, yPos, zPos, radius)
return peaks, totalWeight
end
---@param height number
---@param biomesList MapGen.Layer.Biome[]
---@return string[], MapGen.Layer.Biome[]
local function getBiomesNamesByHeight(height, biomesList)
local biomesNames = {}
local biomes = {}
for _, biome in ipairs(biomesList) do
if height >= biome.minY and height <= biome.maxY then
table.insert(biomesNames, biome.name)
table.insert(biomes, biome)
end
end
table.sort(biomesNames)
return biomesNames, biomes
end
---Initialization of the biome diagram using the Voronoi method.
function Layer:initBiomesDiagram()
local diagram = self.biomesDiagram
local pastBiomesNames
local pastDiagramSlice
for temp = 0, 100 do
diagram[temp] = {}
-- A counter for logging unique slices in the biome diagram.
local uniqueDiagramSlices = 0
for humidity = 0, 100 do
local minDistance = math.huge
local closestBiome = nil
for height = self.minY, self.maxY do
diagram[height] = {}
---@param biome MapGen.Layer.Biome
for _, biome in ipairs(self.biomesList) do
local distance = (temp - biome.tempPoint)^2 + (humidity - biome.humidityPoint)^2
local newBiomesNames, biomes = getBiomesNamesByHeight(height, self.biomesList)
if distance < minDistance then
minDistance = distance
closestBiome = biome
if pastBiomesNames ~= nil and dump(pastBiomesNames) == dump(newBiomesNames) then
diagram[height] = pastDiagramSlice
goto continue
end
pastBiomesNames = newBiomesNames
for temp = 0, 100 do
diagram[height][temp] = {}
for humidity = 0, 100 do
local minDistance = math.huge
local closestBiome = nil
---@param biome MapGen.Layer.Biome
for _, biome in ipairs(biomes) do
local distance = (temp - biome.tempPoint)^2 + (humidity - biome.humidityPoint)^2
if distance < minDistance then
minDistance = distance
closestBiome = biome
end
end
-- If there is no nearby biome for this height...
if closestBiome == nil then
-- ... then the first registered biome in the layer will be the default one.
diagram[height][temp][humidity] = self.biomesList[1]
else
diagram[height][temp][humidity] = closestBiome
end
end
diagram[temp][humidity] = closestBiome
end
pastDiagramSlice = diagram[height]
uniqueDiagramSlices = uniqueDiagramSlices + 1
::continue::
end
Logger.infoLog('MapGen.Layer.initBiomesDiagram(): Initialized to %s unique slices for the layer `%s` biome diagram.', uniqueDiagramSlices, self.name)
end
return Layer

View File

@@ -2,6 +2,8 @@
---@field name string
---@field tempPoint number
---@field humidityPoint number
---@field minY number
---@field maxY number
---@field groundNodes MapGen.Biome.GroundNodes
---@field soilHeight number
local Biome = {}
@@ -9,6 +11,8 @@ local Biome = {}
---@class MapGen.Layer.BiomeDef
---@field tempPoint number
---@field humidityPoint number
---@field minY number
---@field maxY number
---@field groundNodes MapGen.Biome.GroundNodes
---@field soilHeight number
@@ -21,6 +25,8 @@ function Biome:new(name, def)
name = name,
tempPoint = def.tempPoint,
humidityPoint = def.humidityPoint,
minY = def.minY,
maxY = def.maxY,
groundNodes = def.groundNodes,
soilHeight = def.soilHeight,
}, {__index = self})

View File

@@ -8,6 +8,9 @@
-- Ensure
dofile(core.get_modpath('smc__api__ensure')..'/init.lua')
-- Logger
dofile(core.get_modpath('smc__api__logger')..'/init.lua')
-- Math
dofile(core.get_modpath('smc__api__math')..'/init.lua')
@@ -162,6 +165,8 @@ mapGenerator:registerCavern('world', 'cavern1', {
mapGenerator:registerBiome('world', "biome1", {
tempPoint = 0,
humidityPoint = 0,
minY = -10000,
maxY = 1000,
groundNodes = {
soil = "soils:clay_soil_baren",
turf = "soils:clay_soil_baren",
@@ -172,6 +177,8 @@ mapGenerator:registerBiome('world', "biome1", {
mapGenerator:registerBiome('world', "biome2", {
tempPoint = 100,
humidityPoint = 100,
minY = -1000,
maxY = 1000,
groundNodes = {
soil = "soils:rocky_soil_baren",
turf = "soils:rocky_soil_baren",