From 3a7e65d8ad2e0ae147939d177b57d62d4d04f84b Mon Sep 17 00:00:00 2001 From: Rochambeau Date: Sat, 21 Jul 2018 20:31:29 +0200 Subject: [PATCH] foundation migrated to LVM --- buildings.lua | 34 +++++++++++++++++++++++++--------- foundation.lua | 39 ++++++++++++++++++++++++--------------- init.lua | 4 ++-- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/buildings.lua b/buildings.lua index 1a72137..a54b734 100644 --- a/buildings.lua +++ b/buildings.lua @@ -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 @@ -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, @@ -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, @@ -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"]) @@ -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 @@ -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"]) diff --git a/foundation.lua b/foundation.lua index 9152c84..b3a0a5a 100644 --- a/foundation.lua +++ b/foundation.lua @@ -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 @@ -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 \ No newline at end of file diff --git a/init.lua b/init.lua index 1b78a96..6c4d764 100644 --- a/init.lua +++ b/init.lua @@ -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) @@ -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 })