87 lines
2.7 KiB
Lua
87 lines
2.7 KiB
Lua
-- Imports -----------------------------------------------------------------------------------------
|
|
|
|
local core = _G.core
|
|
|
|
local path = core.get_game_info().path
|
|
local C = dofile(path.."/common/constants.lua")
|
|
local Region = dofile(path.."/common/region.lua")
|
|
|
|
|
|
-- Private -----------------------------------------------------------------------------------------
|
|
|
|
local private = {}
|
|
|
|
--[[
|
|
Apply biomes to the given region.
|
|
|
|
This function will both update the `Region.META..BIOME` table so that each x,z column has an
|
|
assigned biome, but it will also update the data within the region to have that biome fully
|
|
applied from decorations to fill material.
|
|
|
|
Args:
|
|
region:Region - the region currently being generated
|
|
]]--
|
|
function private.apply_to(region)
|
|
private.assign_biomes(region)
|
|
private.fill_surface(region)
|
|
end
|
|
|
|
--[[
|
|
Assigns a specific biome to each position in the region.
|
|
|
|
Args:
|
|
region:Region - the region currently being generated
|
|
]]--
|
|
function private.assign_biomes(region)
|
|
region:iterate_columns(function(x, z)
|
|
local terrain_type = region:get_meta(Region.META.TERRAIN_TYPE, x, z)
|
|
local terrain = C.TERRAIN_TYPES[terrain_type]
|
|
region:set_meta(Region.META.BIOME, x, z, core.get_biome_id(terrain.name))
|
|
end)
|
|
end
|
|
|
|
--[[
|
|
Replace the upper layers of stone with biome-specific top and filler nodes.
|
|
|
|
Args:
|
|
region:Region - the region currently being generated
|
|
]]--
|
|
function private.fill_surface(region)
|
|
region:iterate_columns(function(x, z)
|
|
local biome_id = region:get_meta(Region.META.BIOME, x, z)
|
|
local biome_name = core.get_biome_name(biome_id)
|
|
local biome = core.registered_biomes[biome_name]
|
|
|
|
local y = region:get_meta(Region.META.ALTITUDE, x, z)
|
|
local top_count = biome.depth_top or 0
|
|
local filler_count = biome.depth_filler or 0
|
|
|
|
while y >= region.fill_min.y do
|
|
if top_count > 0 then
|
|
local content_id = core.get_content_id(biome.node_top)
|
|
if content_id then
|
|
region:set_content_id(x, y, z, content_id)
|
|
end
|
|
top_count = top_count - 1
|
|
elseif filler_count > 0 then
|
|
local content_id = core.get_content_id(biome.node_filler)
|
|
if content_id then
|
|
region:set_content_id(x, y, z, content_id)
|
|
end
|
|
filler_count = filler_count - 1
|
|
else
|
|
break
|
|
end
|
|
|
|
y = y - 1
|
|
end
|
|
end)
|
|
end
|
|
|
|
|
|
-- Export ------------------------------------------------------------------------------------------
|
|
|
|
return {
|
|
apply_to = private.apply_to
|
|
}
|