]> git.lizzy.rs Git - worldedit.git/commitdiff
Replace worldedit.spiral with worldedit.pyramid, as well as related chat commands.
authorAnthony Zhang <azhang9@gmail.com>
Wed, 26 Sep 2012 22:02:42 +0000 (18:02 -0400)
committerAnthony Zhang <azhang9@gmail.com>
Wed, 26 Sep 2012 22:02:42 +0000 (18:02 -0400)
README.md
functions.lua
init.lua

index e513605b655d2f1eb2749fa51f6b9b1405b68b2c..5324efb0284c1fc3493f53a3790c97c20b67a3c5 100644 (file)
--- a/README.md
+++ b/README.md
@@ -125,13 +125,13 @@ Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length>
     //cylinder z -12 3 mesecons:mesecon
     //cylinder ? 2 4 stone
     
-### //spiral <size> <node>
+### //pyramid <height> <node>
 
-Add spiral at WorldEdit position 1 with size <size>, composed of <node>.
+Add pyramid at WorldEdit position 1 with height <height>, composed of <node>.
 
-    //spiral 8 dirt
-    //spiral 5 default:glass
-    //spiral 2 stone
+    //pyramid 8 dirt
+    //pyramid 5 default:glass
+    //pyramid 2 stone
 
 
 ### //copy x/y/z/? <amount>
@@ -268,11 +268,11 @@ Adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `
 
 Returns the number of nodes added.
 
-### worldedit.spiral(pos, size, nodename)
+### worldedit.pyramid(pos, height, nodename)
 
-Adds a spiral at `pos` with size `size`.
+Adds a pyramid at `pos` with height `height`.
 
-Returns the number of nodes changed.
+Returns the number of nodes added.
 
 ### worldedit.copy(pos1, pos2, axis, amount)
 
index 4b98a84663d03d9432cb721d8b7e748aa719a653..9f75468cfed14000027447a314ddb5fde2127158 100644 (file)
@@ -76,7 +76,7 @@ worldedit.replace = function(pos1, pos2, searchnode, replacenode)
 end\r
 \r
 --adds a hollow sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added\r
-worldedit.hollow_sphere = function(pos, radius, nodename)\r
+worldedit.hollow_sphere = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed\r
        local node = {name=nodename}\r
        local pos1 = {x=0, y=0, z=0}\r
        local full_radius = radius * radius + radius\r
@@ -96,7 +96,7 @@ worldedit.hollow_sphere = function(pos, radius, nodename)
 end\r
 \r
 --adds a sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added\r
-worldedit.sphere = function(pos, radius, nodename)\r
+worldedit.sphere = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed\r
        local node = {name=nodename}\r
        local pos1 = {x=0, y=0, z=0}\r
        local full_radius = radius * radius + radius\r
@@ -134,7 +134,7 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)
        local node = {name=nodename}\r
        local count = 0\r
        local step = 1\r
-       if length < 0\r
+       if length < 0 then\r
                length = -length\r
                step = -1\r
        end\r
@@ -195,7 +195,7 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename)
        local node = {name=nodename}\r
        local count = 0\r
        local step = 1\r
-       if length < 0\r
+       if length < 0 then\r
                length = -length\r
                step = -1\r
        end\r
@@ -238,77 +238,33 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename)
        return count\r
 end\r
 \r
---adds a spiral at `pos` with size `size`, composed of `nodename`, returning the number of nodes changed\r
-worldedit.spiral = function(pos, size, nodename)\r
-       local shift_x, shift_y\r
-       sa = spiralt(size)\r
-       shift_y = #sa -- "Height" of the Array\r
-       local fe = sa[1]\r
-       shift_x = #fe -- "Width" of the Array\r
-       fe = nil\r
+--adds a pyramid at `pos` with height `height`, composed of `nodename`, returning the number of nodes added\r
+worldedit.pyramid = function(pos, height, nodename)\r
+       local pos1x, pos1y, pos1z = pos.x - height, pos.y, pos.z - height\r
+       local pos2x, pos2y, pos2z = pos.x + height, pos.y + height, pos.z + height\r
+       local pos = {x=0, y=pos1y, z=0}\r
 \r
        local count = 0\r
        local node = {name=nodename}\r
-       for x, v in ipairs(sa) do\r
-               for y, z in ipairs(v) do\r
-                       minetest.env:add_node({x=pos.x - shift_x + x,y=pos.y - shift_y + y,z=pos.z + z}, node)\r
-                       count = count + 1\r
+       local env = minetest.env\r
+       while pos.y <= pos2y do --each vertical level of the pyramid\r
+               pos.x = pos1x\r
+               while pos.x <= pos2x do\r
+                       pos.z = pos1z\r
+                       while pos.z <= pos2z do\r
+                               env:add_node(pos, node)\r
+                               pos.z = pos.z + 1\r
+                       end\r
+                       pos.x = pos.x + 1\r
                end\r
-       end\r
-       return count\r
-end\r
+               count = count + ((pos2y - pos.y) * 2 + 1) ^ 2\r
+               pos.y = pos.y + 1\r
 \r
---wip: \r
-sign = function(s)\r
-       if s > 0 then\r
-               return 1\r
-       end\r
-       if s < 0 then\r
-               return -1\r
-       end\r
-       return 0\r
-end\r
+               pos1x, pos2x = pos1x + 1, pos2x - 1\r
+               pos1z, pos2z = pos1z + 1, pos2z - 1\r
 \r
---wip: needs to be faster\r
-function spiral_index(y, x) -- returns the value at (x, y) in a spiral that starts at 1 and goes outwards\r
-       if y == -x and y >= x then\r
-               return (2 * y + 1) ^ 2\r
-       end\r
-       local l = math.max(math.abs(y), math.abs(x))\r
-       local value\r
-       if math.abs(y) == l then\r
-               value = x\r
-               if y < 0 then\r
-                       value = -value\r
-               end\r
-       else\r
-               value = y\r
-               if x < 0 then\r
-                       value = -value\r
-               end\r
-       end\r
-       t1 = l * 2\r
-       if x + y < 0 then\r
-               t1 = -t1\r
-       end\r
-       t2 = y ^ 2 - x ^ 2\r
-       if t2 < 0 then\r
-               t2 = -t2\r
        end\r
-       return ((2 * l - 1) ^ 2) + (l * 4) + t1 + (t2 * (l - value))\r
-end\r
-\r
---wip: needs to be faster\r
-function spiralt(side)\r
-       local spiral = {}\r
-       local start, stop = math.floor((-side+1)/2), math.floor((side-1)/2)\r
-       for i = 1, side do\r
-               spiral[i] = {}\r
-               for j = 1, side do\r
-                       spiral[i][j] = side ^ 2 - spiral_index(stop - i + 1,start + j - 1) --moves the coordinates so (0,0) is at the center of the spiral\r
-               end\r
-       end\r
-       return spiral\r
+       return count\r
 end\r
 \r
 --copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied\r
@@ -621,7 +577,7 @@ worldedit.deserialize_old = function(originpos, value)
 end\r
 \r
 --saves the nodes and meta defined by positions `pos1` and `pos2` into a file, returning the number of nodes saved\r
-worldedit.metasave = function(pos1, pos2, file)\r
+worldedit.metasave = function(pos1, pos2, file) --wip: simply work with strings instead of doing IO\r
        local path = minetest.get_worldpath() .. "/schems"\r
        local filename = path .. "/" .. file .. ".wem"\r
        os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist\r
@@ -662,7 +618,7 @@ worldedit.metasave = function(pos1, pos2, file)
 end\r
 \r
 --loads the nodes and meta from `file` to position `pos1`, returning the number of nodes loaded\r
-worldedit.metaload = function(pos1, file)\r
+worldedit.metaload = function(pos1, file) --wip: simply work with strings instead of doing IO\r
        local filename = minetest.get_worldpath() .. "/schems/" .. file .. ".wem"\r
        local rows, err = table.load(filename)\r
        if err then return _,err end\r
index a7e1947abf2e8b6941db95ba71c58ee1e593854b..da462c57a883f429ec355f99d3c0c5e96e8fd5a1 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -271,9 +271,9 @@ minetest.register_chatcommand("/hollowcylinder", {
        end,\r
 })\r
 \r
-minetest.register_chatcommand("/spiral", {\r
-       params = "<size> <node>",\r
-       description = "Add spiral at WorldEdit position 1 with size <size>, composed of <node>",\r
+minetest.register_chatcommand("/pyramid", {\r
+       params = "<height> <node>",\r
+       description = "Add pyramid at WorldEdit position 1 with height <height>, composed of <node>",\r
        privs = {worldedit=true},\r
        func = function(name, param)\r
                local pos = worldedit.pos1[name]\r
@@ -292,8 +292,8 @@ minetest.register_chatcommand("/spiral", {
                        return\r
                end\r
 \r
-               local count = worldedit.spiral(pos, tonumber(size), nodename)\r
-               minetest.chat_send_player(name, count .. " nodes changed")\r
+               local count = worldedit.pyramid(pos, tonumber(size), nodename)\r
+               minetest.chat_send_player(name, count .. " nodes added")\r
        end,\r
 })\r
 \r