circle around center
parent
cf0f7b9606
commit
4355a4eeca
|
@ -1,12 +1,16 @@
|
||||||
function settlements.build_schematic(pos)
|
-- list of schematics
|
||||||
-- list of schematics
|
local schematic_table = { hut = schem_path.."hut.mts",
|
||||||
local schematic_table = { schem_path.."hut.mts",
|
garden = schem_path.."garden.mts",
|
||||||
schem_path.."garden.mts",
|
lamp = schem_path.."lamp.mts",
|
||||||
schem_path.."lamp.mts",
|
tower = schem_path.."tower.mts",
|
||||||
schem_path.."tower.mts",
|
well = schem_path.."well.mts"}
|
||||||
schem_path.."well.mts",}
|
-- iterate over whole table to get all keys
|
||||||
-- pick one of those schematics
|
local keyset = {}
|
||||||
local building = schematic_table[math.random(1, #schematic_table)]
|
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
|
-- get building node material for better integration to surrounding
|
||||||
local balcony_material = minetest.get_node_or_nil(pos).name
|
local balcony_material = minetest.get_node_or_nil(pos).name
|
||||||
-- pick random material
|
-- pick random material
|
||||||
|
@ -25,3 +29,30 @@ function settlements.build_schematic(pos)
|
||||||
-- place schematic
|
-- place schematic
|
||||||
minetest.place_schematic(pos, schematic, "random", nil, true)
|
minetest.place_schematic(pos, schematic, "random", nil, true)
|
||||||
end
|
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
|
|
@ -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
|
|
@ -8,14 +8,14 @@ function settlements.ground(pos) -- Wendelsteinkircherl, Brannenburg
|
||||||
p2.y = p2.y-1
|
p2.y = p2.y-1
|
||||||
while true do
|
while true do
|
||||||
cnt = cnt+1
|
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
|
if cnt>math.random(2,4) then mat = "stone"end
|
||||||
minetest.set_node(p2, {name="default:"..mat})
|
minetest.set_node(p2, {name="default:"..mat})
|
||||||
p2.y = p2.y-1
|
p2.y = p2.y-1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--
|
--
|
||||||
--
|
-- Function to fill empty space below baseplate when building on a hill
|
||||||
--
|
--
|
||||||
function settlements.foundation(pos, width, depth, height)
|
function settlements.foundation(pos, width, depth, height)
|
||||||
local p5 = settlements.shallowCopy(pos)
|
local p5 = settlements.shallowCopy(pos)
|
||||||
|
|
3
init.lua
3
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
|
if math.random(0,10)<9 or os.time() < last_time then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
place_settlement(minp, maxp)
|
-- place_settlement(minp, maxp)
|
||||||
|
settlements.place_settlement_circle(minp, maxp)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|
30
utils.lua
30
utils.lua
|
@ -87,33 +87,3 @@ function settlements.find_locations(minp, maxp)
|
||||||
end
|
end
|
||||||
return location_list
|
return location_list
|
||||||
end
|
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
|
|
Loading…
Reference in New Issue