From 4355a4eeca00c2e181b36e976057ad9a96591cad Mon Sep 17 00:00:00 2001 From: Rochambeau Date: Fri, 29 Jun 2018 14:52:56 +0200 Subject: [PATCH] circle around center --- buildings.lua | 49 ++++++++++++++++++++++++++++++++++++--------- convert_lua_mts.lua | 30 +++++++++++++++++++++++++++ foundation.lua | 4 ++-- init.lua | 3 ++- utils.lua | 30 --------------------------- 5 files changed, 74 insertions(+), 42 deletions(-) create mode 100644 convert_lua_mts.lua diff --git a/buildings.lua b/buildings.lua index e74f2d9..0d39a6e 100644 --- a/buildings.lua +++ b/buildings.lua @@ -1,12 +1,16 @@ -function settlements.build_schematic(pos) - -- list of schematics - local schematic_table = { schem_path.."hut.mts", - schem_path.."garden.mts", - schem_path.."lamp.mts", - schem_path.."tower.mts", - schem_path.."well.mts",} - -- pick one of those schematics - local building = schematic_table[math.random(1, #schematic_table)] +-- list of schematics +local schematic_table = { hut = schem_path.."hut.mts", + garden = schem_path.."garden.mts", + lamp = schem_path.."lamp.mts", + tower = schem_path.."tower.mts", + well = schem_path.."well.mts"} +-- iterate over whole table to get all keys +local keyset = {} +for k in pairs(schematic_table) do + table.insert(keyset, k) +end + +function settlements.build_schematic(pos, building) -- get building node material for better integration to surrounding local balcony_material = minetest.get_node_or_nil(pos).name -- pick random material @@ -24,4 +28,31 @@ function settlements.build_schematic(pos) settlements.foundation(pos, width, depth, height) -- place schematic minetest.place_schematic(pos, schematic, "random", nil, true) +end +-- +-- placing buildings in circles around center +-- +function settlements.place_settlement_circle(minp, maxp) + local half_map_chunk_size = 40 + -- find center of chunk + local center = {x=maxp.x-half_map_chunk_size, y=maxp.y-half_map_chunk_size, z=maxp.z-half_map_chunk_size} + -- find center_surcafe of chunk + local center_surface = settlements.find_surface(center) + -- go build settlement around center + if center_surface then + minetest.chat_send_all("Dorf") + -- pick one of those schematics + local building = schematic_table["tower"] + settlements.build_schematic(center_surface, building) + -- now some buildings around in a circle + local x, z, r = center_surface.x, center_surface.z, 15 + for i = 0, 360, 45 do + local angle = i * math.pi / 180 + local ptx, ptz = x + r * math.cos( angle ), z + r * math.sin( angle ) + local pos1 = { x=ptx, y=center_surface.y, z=ptz} + local pos_surcafe = settlements.find_surface(pos1) + settlements.build_schematic(pos1, schematic_table[keyset[math.random(#keyset)]]) +-- minetest.set_node(pos1, {name="default:cobble"}) + end + end end \ No newline at end of file diff --git a/convert_lua_mts.lua b/convert_lua_mts.lua new file mode 100644 index 0000000..03a0c78 --- /dev/null +++ b/convert_lua_mts.lua @@ -0,0 +1,30 @@ +-- +function settlements.convert_mts_to_lua() + local building = schem_path.."hut.mts" + local str = minetest.serialize_schematic(building, "lua", {lua_use_comments = true, lua_num_indent_spaces = 0}).." return(schematic)" + local schematic = loadstring(str)() + local file = io.open(schem_path.."hut"..".lua", "w") + file:write(dump(schematic)) + file:close() +print(dump(schematic)) +end + + + +function settlements.mts_save() + local f = assert(io.open(schem_path.."hut.lua", "r")) + local content = f:read("*all").." return(schematic2)" + f:close() + + local schematic2 = loadstring("schematic2 = "..content)() + local seb = minetest.serialize_schematic(schematic2, "mts", {}) + local filename = schem_path .. "hut2" .. ".mts" + filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\") + local file, err = io.open(filename, "wb") + if err == nil and seb then + file:write(seb) + file:flush() + file:close() + end + print("Wrote: " .. filename) +end \ No newline at end of file diff --git a/foundation.lua b/foundation.lua index 4d6a647..d6cec52 100644 --- a/foundation.lua +++ b/foundation.lua @@ -8,14 +8,14 @@ function settlements.ground(pos) -- Wendelsteinkircherl, Brannenburg p2.y = p2.y-1 while true do cnt = cnt+1 - if cnt > 200 then break end + if cnt > 100 then break end if cnt>math.random(2,4) then mat = "stone"end minetest.set_node(p2, {name="default:"..mat}) p2.y = p2.y-1 end end -- --- +-- Function to fill empty space below baseplate when building on a hill -- function settlements.foundation(pos, width, depth, height) local p5 = settlements.shallowCopy(pos) diff --git a/init.lua b/init.lua index 5146222..934e1f9 100644 --- a/init.lua +++ b/init.lua @@ -38,7 +38,8 @@ minetest.register_on_generated(function(minp, maxp, seed) if math.random(0,10)<9 or os.time() < last_time then return end - place_settlement(minp, maxp) +-- place_settlement(minp, maxp) + settlements.place_settlement_circle(minp, maxp) end) -- diff --git a/utils.lua b/utils.lua index 92274c9..16cfc38 100644 --- a/utils.lua +++ b/utils.lua @@ -87,33 +87,3 @@ function settlements.find_locations(minp, maxp) end return location_list end --- -function settlements.convert_mts_to_lua() - local building = schem_path.."hut.mts" - local str = minetest.serialize_schematic(building, "lua", {lua_use_comments = true, lua_num_indent_spaces = 0}).." return(schematic)" - local schematic = loadstring(str)() - local file = io.open(schem_path.."hut"..".lua", "w") - file:write(dump(schematic)) - file:close() -print(dump(schematic)) -end - - - -function settlements.mts_save() - local f = assert(io.open(schem_path.."hut.lua", "r")) - local content = f:read("*all").." return(schematic2)" - f:close() - - local schematic2 = loadstring("schematic2 = "..content)() - local seb = minetest.serialize_schematic(schematic2, "mts", {}) - local filename = schem_path .. "hut2" .. ".mts" - filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\") - local file, err = io.open(filename, "wb") - if err == nil and seb then - file:write(seb) - file:flush() - file:close() - end - print("Wrote: " .. filename) -end \ No newline at end of file