Mapgen: write SuperUltraSigmaMapgen part 7.4
This commit is contained in:
@@ -325,7 +325,7 @@ end
|
|||||||
|
|
||||||
---@param mapGenerator MapGen
|
---@param mapGenerator MapGen
|
||||||
---@param layer MapGen.Layer
|
---@param layer MapGen.Layer
|
||||||
---@param hight number
|
---@param height number
|
||||||
---@param temp number
|
---@param temp number
|
||||||
---@param humidity number
|
---@param humidity number
|
||||||
---@param data number[]
|
---@param data number[]
|
||||||
@@ -333,24 +333,25 @@ end
|
|||||||
---@param x number
|
---@param x number
|
||||||
---@param y number
|
---@param y number
|
||||||
---@param z 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 ids = mapGenerator.nodeIDs
|
||||||
|
|
||||||
local m = math.random(-10, 10)
|
local m = math.random(-5, 5)
|
||||||
|
|
||||||
temp = mathMin(100, mathMax(0, temp + m))
|
temp = mathMin(100, mathMax(0, temp + m))
|
||||||
humidity = mathMin(100, mathMax(0, humidity + 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
|
data[index] = ids.air
|
||||||
elseif y > hight and y <= 0 then
|
elseif y > height and y <= 0 then
|
||||||
data[index] = ids.water
|
data[index] = ids.water
|
||||||
elseif y <= hight then
|
elseif y <= height then
|
||||||
if isCavern(layer, x, y, z) then
|
if isCavern(layer, x, y, z) then
|
||||||
data[index] = ids.air
|
data[index] = ids.air
|
||||||
elseif y == hight then
|
elseif y == height then
|
||||||
generateSoil(biome, data, index, x, y, z)
|
generateSoil(biome, data, index, x, y, z)
|
||||||
else
|
else
|
||||||
generateRock(ids, data, index, x, y, z)
|
generateRock(ids, data, index, x, y, z)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ local mathSqrt = math.sqrt
|
|||||||
---@field tetrahedronsList MapGen.Tetrahedron[]
|
---@field tetrahedronsList MapGen.Tetrahedron[]
|
||||||
local Layer = {
|
local Layer = {
|
||||||
peaksList = {},
|
peaksList = {},
|
||||||
biomesByName = {},
|
biomesByName = {},
|
||||||
biomesList = {},
|
biomesList = {},
|
||||||
biomesDiagram = {},
|
biomesDiagram = {},
|
||||||
cavernsByName = {},
|
cavernsByName = {},
|
||||||
@@ -79,30 +79,80 @@ function Layer:getPeaksByPos(xPos, yPos, zPos, radius)
|
|||||||
return peaks, totalWeight
|
return peaks, totalWeight
|
||||||
end
|
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.
|
---Initialization of the biome diagram using the Voronoi method.
|
||||||
function Layer:initBiomesDiagram()
|
function Layer:initBiomesDiagram()
|
||||||
local diagram = self.biomesDiagram
|
local diagram = self.biomesDiagram
|
||||||
|
local pastBiomesNames
|
||||||
|
local pastDiagramSlice
|
||||||
|
|
||||||
for temp = 0, 100 do
|
-- A counter for logging unique slices in the biome diagram.
|
||||||
diagram[temp] = {}
|
local uniqueDiagramSlices = 0
|
||||||
|
|
||||||
for humidity = 0, 100 do
|
for height = self.minY, self.maxY do
|
||||||
local minDistance = math.huge
|
diagram[height] = {}
|
||||||
local closestBiome = nil
|
|
||||||
|
|
||||||
---@param biome MapGen.Layer.Biome
|
local newBiomesNames, biomes = getBiomesNamesByHeight(height, self.biomesList)
|
||||||
for _, biome in ipairs(self.biomesList) do
|
|
||||||
local distance = (temp - biome.tempPoint)^2 + (humidity - biome.humidityPoint)^2
|
|
||||||
|
|
||||||
if distance < minDistance then
|
if pastBiomesNames ~= nil and dump(pastBiomesNames) == dump(newBiomesNames) then
|
||||||
minDistance = distance
|
diagram[height] = pastDiagramSlice
|
||||||
closestBiome = biome
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
diagram[temp][humidity] = closestBiome
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
pastDiagramSlice = diagram[height]
|
||||||
|
uniqueDiagramSlices = uniqueDiagramSlices + 1
|
||||||
|
|
||||||
|
::continue::
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Logger.infoLog('MapGen.Layer.initBiomesDiagram(): Initialized to %s unique slices for the layer `%s` biome diagram.', uniqueDiagramSlices, self.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
return Layer
|
return Layer
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
---@field name string
|
---@field name string
|
||||||
---@field tempPoint number
|
---@field tempPoint number
|
||||||
---@field humidityPoint number
|
---@field humidityPoint number
|
||||||
|
---@field minY number
|
||||||
|
---@field maxY number
|
||||||
---@field groundNodes MapGen.Biome.GroundNodes
|
---@field groundNodes MapGen.Biome.GroundNodes
|
||||||
---@field soilHeight number
|
---@field soilHeight number
|
||||||
local Biome = {}
|
local Biome = {}
|
||||||
@@ -9,6 +11,8 @@ local Biome = {}
|
|||||||
---@class MapGen.Layer.BiomeDef
|
---@class MapGen.Layer.BiomeDef
|
||||||
---@field tempPoint number
|
---@field tempPoint number
|
||||||
---@field humidityPoint number
|
---@field humidityPoint number
|
||||||
|
---@field minY number
|
||||||
|
---@field maxY number
|
||||||
---@field groundNodes MapGen.Biome.GroundNodes
|
---@field groundNodes MapGen.Biome.GroundNodes
|
||||||
---@field soilHeight number
|
---@field soilHeight number
|
||||||
|
|
||||||
@@ -21,6 +25,8 @@ function Biome:new(name, def)
|
|||||||
name = name,
|
name = name,
|
||||||
tempPoint = def.tempPoint,
|
tempPoint = def.tempPoint,
|
||||||
humidityPoint = def.humidityPoint,
|
humidityPoint = def.humidityPoint,
|
||||||
|
minY = def.minY,
|
||||||
|
maxY = def.maxY,
|
||||||
groundNodes = def.groundNodes,
|
groundNodes = def.groundNodes,
|
||||||
soilHeight = def.soilHeight,
|
soilHeight = def.soilHeight,
|
||||||
}, {__index = self})
|
}, {__index = self})
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
-- Ensure
|
-- Ensure
|
||||||
dofile(core.get_modpath('smc__api__ensure')..'/init.lua')
|
dofile(core.get_modpath('smc__api__ensure')..'/init.lua')
|
||||||
|
|
||||||
|
-- Logger
|
||||||
|
dofile(core.get_modpath('smc__api__logger')..'/init.lua')
|
||||||
|
|
||||||
-- Math
|
-- Math
|
||||||
dofile(core.get_modpath('smc__api__math')..'/init.lua')
|
dofile(core.get_modpath('smc__api__math')..'/init.lua')
|
||||||
|
|
||||||
@@ -162,6 +165,8 @@ mapGenerator:registerCavern('world', 'cavern1', {
|
|||||||
mapGenerator:registerBiome('world', "biome1", {
|
mapGenerator:registerBiome('world', "biome1", {
|
||||||
tempPoint = 0,
|
tempPoint = 0,
|
||||||
humidityPoint = 0,
|
humidityPoint = 0,
|
||||||
|
minY = -10000,
|
||||||
|
maxY = 1000,
|
||||||
groundNodes = {
|
groundNodes = {
|
||||||
soil = "soils:clay_soil_baren",
|
soil = "soils:clay_soil_baren",
|
||||||
turf = "soils:clay_soil_baren",
|
turf = "soils:clay_soil_baren",
|
||||||
@@ -172,6 +177,8 @@ mapGenerator:registerBiome('world', "biome1", {
|
|||||||
mapGenerator:registerBiome('world', "biome2", {
|
mapGenerator:registerBiome('world', "biome2", {
|
||||||
tempPoint = 100,
|
tempPoint = 100,
|
||||||
humidityPoint = 100,
|
humidityPoint = 100,
|
||||||
|
minY = -1000,
|
||||||
|
maxY = 1000,
|
||||||
groundNodes = {
|
groundNodes = {
|
||||||
soil = "soils:rocky_soil_baren",
|
soil = "soils:rocky_soil_baren",
|
||||||
turf = "soils:rocky_soil_baren",
|
turf = "soils:rocky_soil_baren",
|
||||||
|
|||||||
Reference in New Issue
Block a user