Skip to content

Commit

Permalink
foundation migrated to LVM
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeb187 committed Jul 21, 2018
1 parent 2bf7365 commit 3a7e65d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 26 deletions.
34 changes: 25 additions & 9 deletions buildings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local number_built
--
-- build schematic, replace material, rotation
--
function settlements.build_schematic(pos, building, replace_wall, name)
function settlements.build_schematic(vm, data, va, pos, building, replace_wall, name)
-- get building node material for better integration to surrounding
local platform_material = minetest.get_node_or_nil(pos)
if not platform_material then
Expand Down Expand Up @@ -41,7 +41,11 @@ function settlements.build_schematic(pos, building, replace_wall, name)
local height = schematic["size"]["y"]
local possible_rotations = {"0", "90", "180", "270"}
local rotation = possible_rotations[ math.random( #possible_rotations ) ]
settlements.foundation(pos,
settlements.foundation(
vm,
data,
va,
pos,
width,
depth,
height,
Expand All @@ -60,7 +64,7 @@ end
--
-- placing buildings within lvm
--
function settlements.place_settlement_lvm(data, va, minp, maxp)
function settlements.place_settlement_lvm(vm, data, va, minp, maxp)
-- find center of chunk
local center = {
x=maxp.x-half_map_chunk_size,
Expand All @@ -80,7 +84,11 @@ function settlements.place_settlement_lvm(data, va, minp, maxp)
settlements.initialize_settlement()
-- build well in the center
building_all_info = schematic_table[1]
settlements.build_schematic(center_surface,
settlements.build_schematic(
vm,
data,
va,
center_surface,
building_all_info["mts"],
building_all_info["rplc"],
building_all_info["name"])
Expand Down Expand Up @@ -110,14 +118,21 @@ function settlements.place_settlement_lvm(data, va, minp, maxp)
then
if settlements.pick_next_building(pos_surface)
then
settlements.build_schematic(pos_surface,
settlements.build_schematic(
vm,
data,
va,
pos_surface,
building_all_info["mts"],
building_all_info["rplc"],
building_all_info["name"])
building_all_info["name"]
)
number_built = number_built + 1
settlement_info[index] = {pos = pos_surface,
settlement_info[index] = {
pos = pos_surface,
name = building_all_info["name"],
hsize = building_all_info["hsize"]}
hsize = building_all_info["hsize"]
}
index = index + 1
if number_of_buildings == number_built
then
Expand Down Expand Up @@ -162,7 +177,8 @@ function settlements.place_settlement_circle(minp, maxp)
settlements.initialize_settlement()
-- build well in the center
building_all_info = schematic_table[1]
settlements.build_schematic(center_surface,
settlements.build_schematic(
center_surface,
building_all_info["mts"],
building_all_info["rplc"],
building_all_info["name"])
Expand Down
39 changes: 24 additions & 15 deletions foundation.lua
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
--
-- function to fill empty space below baseplate when building on a hill
--
function settlements.ground(pos) -- role model: Wendelsteinkircherl, Brannenburg
function settlements.ground(vm, data, va, pos) -- role model: Wendelsteinkircherl, Brannenburg
local c_dirt = minetest.get_content_id("default:dirt")
local c_stone = minetest.get_content_id("default:stone")
--
local p2 = pos
local cnt = 0
local mat = "dirt"
local mat = c_dirt
p2.y = p2.y-1
while true do
cnt = cnt+1
if cnt > 20 then break end
if cnt>math.random(2,4) then mat = "stone" end
minetest.swap_node(p2, {name="default:"..mat})
if cnt>math.random(2,4) then mat = c_stone end
--minetest.swap_node(p2, {name="default:"..mat})
local vi = va:index(p2.x, p2.y, p2.z)
data[vi] = mat
p2.y = p2.y-1
end
return data
end
--
-- function to fill empty space below baseplate when building on a hill
--
function settlements.foundation(pos, width, depth, height, rotation)
function settlements.foundation(vm, data, va, pos, width, depth, height, rotation)
local c_air = minetest.get_content_id("air")
local p5 = settlements.shallowCopy(pos)
local fheight = height * 3 -- remove trees and leaves above
local fwidth
Expand All @@ -34,19 +41,21 @@ function settlements.foundation(pos, width, depth, height, rotation)
for zi = 0,fdepth-1 do
if yi == 0 then
local p = {x=p5.x+xi, y=p5.y, z=p5.z+zi}
minetest.after(1,settlements.ground,p)--(p)
data = settlements.ground(vm, data, va, p)
else
-- minetest.remove_node({x=p5.x+xi, y=p5.y+yi, z=p5.z+zi})
local node = minetest.get_node_or_nil({x=p5.x+xi, y=p5.y+yi, z=p5.z+zi})
if node then
if node.name ~= "air"
then
minetest.swap_node({x=p5.x+xi, y=p5.y+yi, z=p5.z+zi},{name="air"})
end
-- write ground
local vi = va:index(p5.x+xi, p5.y+yi, p5.z+zi)
if data[vi] ~= c_air
--local node = minetest.get_node_or_nil({x=p5.x+xi, y=p5.y+yi, z=p5.z+zi})
--if node then
--if node.name ~= "air"
then
--minetest.swap_node({x=p5.x+xi, y=p5.y+yi, z=p5.z+zi},{name="air"})
data[vi] = c_air
end
end
end
end
end
end

settlements.setlvm(vm, data)
end
4 changes: 2 additions & 2 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ minetest.register_on_generated(function(minp, maxp)
-- if nothing prevents the settlement -> do it
--
--settlements.place_settlement_circle(minp, maxp)
settlements.place_settlement_lvm(data, va, minp, maxp)
settlements.place_settlement_lvm(vm, data, va, minp, maxp)

end
end)
Expand Down Expand Up @@ -140,7 +140,7 @@ minetest.register_craftitem("settlements:tool", {
-- get LVM of current chunk
--
local vm, data, va, emin, emax = settlements.getlvm(minp, maxp)
settlements.place_settlement_lvm(data, va, minp, maxp)
settlements.place_settlement_lvm(vm, data, va, minp, maxp)
end
end
})
Expand Down

0 comments on commit 3a7e65d

Please sign in to comment.