Village spawner: Guarantee well placement

This commit is contained in:
Wuzzy 2019-09-05 20:06:31 +02:00
parent 51a96d0f13
commit 963f1c67e1
2 changed files with 8 additions and 5 deletions

View File

@ -315,8 +315,8 @@ local function check_empty(pos)
return #stones <= 15 and #leaves <= 2 and #trees == 0 return #stones <= 15 and #leaves <= 2 and #trees == 0
end end
function village.spawn_chunk(pos, orient, replace, pr, chunktype, nofill) function village.spawn_chunk(pos, orient, replace, pr, chunktype, nofill, dont_check_empty)
if nofill ~= true and not check_empty(pos) then if not dont_check_empty and not check_empty(pos) then
minetest.log("verbose", "[village] Chunk not generated (too many stone/leaves/trees in the way) at "..minetest.pos_to_string(pos)) minetest.log("verbose", "[village] Chunk not generated (too many stone/leaves/trees in the way) at "..minetest.pos_to_string(pos))
return false return false
end end
@ -515,7 +515,7 @@ function village.spawn_road(pos, houses, built, roads, depth, pr, replace, dont_
return true return true
end end
function village.spawn_village(pos, pr) function village.spawn_village(pos, pr, force_place_well)
local name = village.name.generate(pr) local name = village.name.generate(pr)
local depth = pr:next(village.min_size, village.max_size) local depth = pr:next(village.min_size, village.max_size)
@ -550,7 +550,7 @@ function village.spawn_village(pos, pr)
local t1 = os.clock() local t1 = os.clock()
-- Every village generation starts with a well. -- Every village generation starts with a well.
chunk_ok = village.spawn_chunk(pos, "0", replace, pr, "well") chunk_ok = village.spawn_chunk(pos, "0", replace, pr, "well", nil, force_place_well == true)
if not chunk_ok then if not chunk_ok then
-- Oops! Not enough space for the well. Village generation fails. -- Oops! Not enough space for the well. Village generation fails.
return false return false
@ -651,6 +651,7 @@ function village.spawn_village(pos, pr)
{}, {},
pr, pr,
"lamppost", "lamppost",
true,
true true
) )
end end

View File

@ -57,7 +57,9 @@ minetest.register_node(
local pr = PseudoRandom(shortseed + pos.x + pos.y + pos.z) local pr = PseudoRandom(shortseed + pos.x + pos.y + pos.z)
village.spawn_village({x=pos.x,y=pos.y-1,z=pos.z}, pr) -- Spawn village on placement.
-- Guarantee that at least the well is placed, to avoid confusion.
village.spawn_village({x=pos.x,y=pos.y-1,z=pos.z}, pr, true)
end, end,
}) })