Skip to content

Commit

Permalink
MapGen: simplify conditions; use constants. Relates to lord-server#1084
Browse files Browse the repository at this point in the history
  • Loading branch information
alek13 committed Jul 27, 2023
1 parent f779917 commit 07f4d2d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 17 additions & 10 deletions mods/lord/lottmapgen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ local LO_RANDOM = -0.4
local ICE_TEMPERATURE = -0.8

local SAND_LAYER_THICKNESS = 6
local BEACH_LAYERS_COUNT = 2
local COAST_LAYERS_COUNT = 4

local PAPCHA = 3 -- Papyrus
local PAPYRUS_CHANCE = 3 -- Papyrus

-- /!\ Warning /!\ : duplicated in config.lua (TODO)
-- Biomes:
Expand Down Expand Up @@ -276,7 +278,7 @@ end

-- On generated function
minetest.register_on_generated(function(min_pos, max_pos, seed)
if min_pos.y < (water_level-1000) or min_pos.y > 5000 then
if min_pos.y < (water_level-300) or min_pos.y > 1000 then
return
end

Expand Down Expand Up @@ -311,7 +313,7 @@ minetest.register_on_generated(function(min_pos, max_pos, seed)
local random = nvals_random[xz_noise_index]
local biome = detect_current_biome(temperature, humidity, random)

local sand_y = (water_level + 2) + math_random(-1, 1) -- sandline
local sand_y = (water_level + BEACH_LAYERS_COUNT) + math_random(-1, 1) -- sandline
local sand_min_y = (water_level - 15) + math_random(-5, 0) -- lowest sand
local is_open = true -- open to sky?
local is_solid = true -- solid node above?
Expand All @@ -323,8 +325,12 @@ minetest.register_on_generated(function(min_pos, max_pos, seed)
local vi_uu = area:index(x, y - 2, z)
local node_id_uu = data[vi_uu] -- under-under

local node_is_stone = node_id == c_stone or node_id == c_stone_w_copper or node_id == c_stone_w_iron or node_id == c_stone_w_coal
local node_is_space = node_id == c_air or node_id == c_water or node_id == c_river_water
local node_uu_is_not_space = node_id_uu ~= c_air and node_id_uu ~= c_water

-- if stone
if node_id == c_stone or node_id == c_stone_w_copper or node_id == c_stone_w_iron or node_id == c_stone_w_coal then
if node_is_stone then

if y > water_level - 32 then
local biome_stone = get_biome_stone(biome)
Expand All @@ -336,14 +342,14 @@ minetest.register_on_generated(function(min_pos, max_pos, seed)
if not is_solid then -- if surface
surface_y = y

if node_id_uu ~= c_air and node_id_uu ~= c_water then -- if supported by 2 stone nodes
if node_uu_is_not_space then -- if supported by 2 stone nodes

if y <= sand_y and y >= sand_min_y then -- sand
if y <= sand_y and y >= sand_min_y then -- surface in the sand layer
data[vi] = get_biome_sand(biome)
if -- papyrus
is_open and is_water_above and y == (water_level - 1) and
biome > 4 and biome ~= BIOME_MORDOR and
math_random(PAPCHA) == 2
math_random(PAPYRUS_CHANCE) == 1
then
lottmapgen_papyrus(x, (water_level + 1), z, area, data)
data[vi] = c_dirt
Expand All @@ -359,7 +365,8 @@ minetest.register_on_generated(function(min_pos, max_pos, seed)
end

else -- underground
if node_id_uu ~= c_air and node_id_uu ~= c_water then

if node_uu_is_not_space then

-- The sand layer becomes thinner, if you got closer to the continent.
-- Thickness (approximately):
Expand All @@ -379,7 +386,7 @@ minetest.register_on_generated(function(min_pos, max_pos, seed)
)
local sand_layer_thickness = SAND_LAYER_THICKNESS - thickness_delta
local sand_layer_bottom = (surface_y - sand_layer_thickness) + math_random(-1, 1)
local under_the_hill = surface_y > 4
local under_the_hill = surface_y > COAST_LAYERS_COUNT

local s_min_y = math_max(sand_min_y, sand_layer_bottom)
if y >= s_min_y and y < surface_y and not under_the_hill then
Expand All @@ -392,7 +399,7 @@ minetest.register_on_generated(function(min_pos, max_pos, seed)
is_open = false
is_solid = true

elseif node_id == c_air or node_id == c_water or node_id == c_river_water then
elseif node_is_space then

is_solid = false

Expand Down
2 changes: 2 additions & 0 deletions util/mt-ide-helper/minetest_types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pointed_thing = {}
-- `minetest.` / `core.` functions
--

minetest = {}

-- Escape sequences:

--- * `color` is a ColorString
Expand Down

0 comments on commit 07f4d2d

Please sign in to comment.