--[[ Deploy Nodes for Minetest Copyright (c) 2012 cornernote, Brett O'Donnell Source Code: https://github.com/cornernote/minetest-deploy_nodes License: GPLv3 SPIRAL ]]-- -- expose api deploy_spiral = {} -- deploy deploy_spiral.deploy = function(pos,placer,nodename,width,height,spacer) -- set the pos to the center of the node pos.x = math.floor(pos.x+0.5) pos.y = math.floor(pos.y+0.5) pos.z = math.floor(pos.z+0.5) height = tonumber(height)-1 if height < 0 then height = 0 end spacer = tonumber(spacer)+1 if spacer < 1 then spacer = 1 end -- check for space if deploy_nodes.check_for_space==true then for x=width*spacer*-0.5,width*spacer*0.5 do for y=0,height-1 do for z=width*spacer*-0.5,width*spacer*0.5 do if x~=0 or y~=0 or z~=0 then local checkpos = {x=pos.x+x,y=pos.y+y,z=pos.z+z} local checknode = minetest.env:get_node(checkpos).name if checknode~="air" then minetest.chat_send_player(placer:get_player_name(), "[deploy_spiral] no room to build because "..checknode.." is in the way at "..dump(checkpos).."") return end end end end end end -- remove spiral node minetest.env:remove_node(pos) -- build the spiral -- spiral matrix - http://rosettacode.org/wiki/Spiral_matrix#Lua av, sn = math.abs, function(s) return s~=0 and s/av(s) or 0 end local function sindex(z, x) -- returns the value at (x, z) in a spiral that starts at 1 and goes outwards if z == -x and z >= x then return (2*z+1)^2 end local l = math.max(av(z), av(x)) return (2*l-1)^2+4*l+2*l*sn(x+z)+sn(z^2-x^2)*(l-(av(z)==l and sn(z)*x or sn(x)*z)) -- OH GOD WHAT end local function spiralt(side) local ret, id, start, stop = {}, 0, math.floor((-side+1)/2), math.floor((side-1)/2) for i = 1, side do for j = 1, side do local id = side^2 - sindex(stop - i + 1,start + j - 1) ret[id] = {x=i,z=j} end end return ret end -- connect the joined parts local spiral = spiralt(width) local node = {name=nodename} local np,lp for y=0,height do lp = nil for _,v in ipairs(spiral) do np = { x=pos.x+v.x*spacer-spacer-width*spacer*0.5, y=pos.y+y, z=pos.z+v.z*spacer-spacer-width*spacer*0.5, } if lp~=nil then if lp.x~=np.x then if lp.x