diff --git a/mods/CORE/MapGen/src/MapGen.lua b/mods/CORE/MapGen/src/MapGen.lua index c92a13a..0e21452 100644 --- a/mods/CORE/MapGen/src/MapGen.lua +++ b/mods/CORE/MapGen/src/MapGen.lua @@ -21,7 +21,7 @@ end local require = Mod.getInfo('smc__core__map_gen').require ---Numeric values ​​defining the surface height and climate for the node. ----@alias MapGen.Factors {height:number, temp:number, humidity:number} +---@alias MapGen.Factors {height:number, temp:number, humidity:number, weight:number} ---Table of all past generation factor calculations for nodes. --- @@ -690,8 +690,10 @@ local function generateNode(mapGenerator, layer, factors, data, data2, index, x, scattHeight, scattTemp, scattHumidity = mathRound(scattHeight), mathRound(scattTemp), mathRound(scattHumidity) height, temp, humidity = mathRound(height), mathRound(scattTemp), mathRound(scattHumidity) + local diagramPoint = layer.biomesDiagram[height][scattTemp][scattHumidity] -- TODO: разобраться со смещением по вертикали ---@type MapGen.Biome - local biome = layer.biomesDiagram[scattHeight][scattTemp][scattHumidity] + local biome = diagramPoint.biome + factors.weight = diagramPoint.weight -- If the block is above surface height and above water level... if y > height and y > waterLevel then @@ -1036,6 +1038,9 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed) end end + -- Clear post processing tables + dataPostProcessing, vmPostProcessing = {}, {} + core.generate_ores(voxelManip, minPos, maxPos) core.generate_decorations(voxelManip, minPos, maxPos) diff --git a/mods/CORE/MapGen/src/MapGen/Layer.lua b/mods/CORE/MapGen/src/MapGen/Layer.lua index f03f51f..075cfe5 100644 --- a/mods/CORE/MapGen/src/MapGen/Layer.lua +++ b/mods/CORE/MapGen/src/MapGen/Layer.lua @@ -1,7 +1,7 @@ local assert, dump, type = assert, dump, type local pairs, ipairs = pairs, ipairs -local mathHuge = math.huge +local mathHuge, mathClamp = math.huge, math.clamp local tableInsert, tableSort = table.insert, table.sort local id = core.get_content_id @@ -39,7 +39,7 @@ local Triangle = require('MapGen.Triangle') ---@field biomesVerticalScattering integer ---@field biomesByName table ---@field biomesList MapGen.Biome[] ----@field biomesDiagram table +---@field biomesDiagram table>> --- ---@field cavernsByName table ---@field cavernsList MapGen.Cavern[] @@ -512,6 +512,7 @@ function Layer:initBiomesDiagram() for humidity = self.minHumidity, self.maxHumidity do local minDistance = mathHuge + local pastClosestBiome = nil local closestBiome = nil ---@param biome MapGen.Biome @@ -520,17 +521,28 @@ function Layer:initBiomesDiagram() if distance < minDistance then minDistance = distance + pastClosestBiome = closestBiome 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 + closestBiome = self.biomesList[1] end + + local weight + if pastClosestBiome ~= nil then + ---Distances from the center of the nearest biome to the current point. + local distance1 = (temp - closestBiome.tempPoint)^2 + (humidity - closestBiome.humidityPoint)^2 + ---Half the distance between the centers of two nearest biomes (i.e. the distance to the biome boundary) + local distance2 = (pastClosestBiome.tempPoint - closestBiome.tempPoint)^2 + (pastClosestBiome.humidityPoint - closestBiome.humidityPoint) / 2 + + weight = mathClamp(distance1 / distance2, 0, 1) + else + weight = 1 + end + + diagram[height][temp][humidity] = { biome = closestBiome, weight = weight} end end @@ -540,6 +552,8 @@ function Layer:initBiomesDiagram() ::continue:: end + print(dump(diagram[0][50][50])) + Logger.infoLog('MapGen.Layer.initBiomesDiagram(): Initialized to %s unique slices for the layer `%s` biome diagram.', uniqueDiagramSlices, self.name) end diff --git a/mods/CORE/MapGen/src/MapGen/Ore.lua b/mods/CORE/MapGen/src/MapGen/Ore.lua index 5826896..b071508 100644 --- a/mods/CORE/MapGen/src/MapGen/Ore.lua +++ b/mods/CORE/MapGen/src/MapGen/Ore.lua @@ -38,6 +38,8 @@ local Ore = {} --- ---If `nil`, ore will generate on the entire layer. ---@field biomes string[]? +---@field minY integer +---@field maxY integer --- ---List of node names where ore will spawn. ---@field wherein string[] @@ -66,6 +68,9 @@ function Ore:new(name, def) local instance = getInstance(self, {}) instance.name = name instance.type = def.type + instance.biomes = def.biomes + instance.minY = def.minY + instance.maxY = def.maxY instance.wherein = def.wherein instance.nodeName = def.nodeName instance.nodeParam2 = def.nodeParam2 or 0 diff --git a/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua b/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua index 8a8ee07..37125e9 100644 --- a/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua +++ b/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua @@ -48,8 +48,8 @@ mapGenerator:registerLayer('midgard', { maxHumidity = 100, calcTemp = calcTemp, calcHumidity = calcHumidity, - biomesVerticalScattering = 5, - biomesGorizontalScattering = 5, + biomesVerticalScattering = 2, + biomesGorizontalScattering = 0, triangulationLandscapeFile = 'tarion.json', triangulationTempFile = 'tarion.json', triangulationHumidityFile = 'tarion.json', @@ -730,9 +730,9 @@ end mapGenerator:registerBiome('midgard', 'green_meadow', { tempPoint = 80, - humidityPoint = 60, - minY = 100, - maxY = -50, + humidityPoint = 80, + minY = -50, + maxY = 100, groundNodes = { soil = 'soils:humus', turf = 'soils:turf_meadow', @@ -763,6 +763,30 @@ mapGenerator:registerBiome('midgard', 'green_meadow', { --postProcessing = postProcessing }) +mapGenerator:registerBiome('midgard', 'test_factors_biome', { + tempPoint = 10, + humidityPoint = 10, + minY = -50, + maxY = 100, + groundNodes = { + soil = 'soils:humus', + turf = 'soils:turf_meadow', + rock = 'rocks:sylite', + bottom = 'soils:humus', + }, + soilHeight = 5, + generateTurf = function (self, mapGenerator, factors, data, data2, index, x, y, z) + local weight = factors.weight + if weight <= 0.3 then + data[index] = id('rocks:sylite') + elseif weight <= 0.6 then + data[index] = id('rocks:sylite_gray') + else + data[index] = id('rocks:sylite_black') + end + end +}) + mapGenerator:registerTree('test_tree', { path = core.get_modpath(core.get_current_modname())..'/schems/test_tree.mts', }) @@ -816,22 +840,4 @@ mapGenerator:registerCavern('midgard', 'test_cavern', { step = 100 })--]] -mapGenerator:registerOre('midgard', 'test_ore', { - type = 'cheesed', - nodeName = 'air', - wherein = {'rocks:sylite'}, - threshold = 0.5, - noiseParams = { - baseNoise = { - offset = 0, - scale = 4, - spread = {x = 10, y = 30, z = 30}, - seed = 12, - octaves = 2, - persistence = 0.6, - lacunarity = 2 - } - } -}) - return mapGenerator