Added math.order
apparently builtin already has the math. namespace, testing for it doesn't seam to work? but assigning an empty table over it makes it angry, so lets not do that
This commit is contained in:
parent
a3c297ac21
commit
13b78ff838
8
sparkapi/lua/math.lua
Normal file
8
sparkapi/lua/math.lua
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
function math.order(x, y) -- might change to arbitrary args later, but now now ... this is just the simple impl written for the quarry
|
||||||
|
if not x or not y then return nil end
|
||||||
|
if x <= y then
|
||||||
|
return x, y
|
||||||
|
else
|
||||||
|
return y, x
|
||||||
|
end
|
||||||
|
end
|
@ -14,15 +14,6 @@ local function Position(x, y, z) ---
|
|||||||
return {x=x, y=y, z=z}
|
return {x=x, y=y, z=z}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function order(x, y) ---
|
|
||||||
--- Returns (smaller, bigger)
|
|
||||||
if x <= y then
|
|
||||||
return x, y
|
|
||||||
else
|
|
||||||
return y,x
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function try_drain_energy(target_pos, amount) ---
|
local function try_drain_energy(target_pos, amount) ---
|
||||||
--- Returns true if drained, false otherwise
|
--- Returns true if drained, false otherwise
|
||||||
--- Removes amount energy from target_pos if energy >= amount
|
--- Removes amount energy from target_pos if energy >= amount
|
||||||
@ -99,9 +90,9 @@ local function on_marker_placed(pos, quarry_pos, player)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local minx, maxx = order(pos.x, quarry_pos.x)
|
local minx, maxx = math.order(pos.x, quarry_pos.x)
|
||||||
local miny, maxy = order(pos.y, quarry_pos.y)
|
local miny, maxy = math.order(pos.y, quarry_pos.y)
|
||||||
local minz, maxz = order(pos.z, quarry_pos.z)
|
local minz, maxz = math.order(pos.z, quarry_pos.z)
|
||||||
|
|
||||||
local diffx = maxx - minx
|
local diffx = maxx - minx
|
||||||
local diffy = maxy - miny
|
local diffy = maxy - miny
|
||||||
@ -112,7 +103,6 @@ local function on_marker_placed(pos, quarry_pos, player)
|
|||||||
diffz < 2 or diffz >= MAX_SIZE
|
diffz < 2 or diffz >= MAX_SIZE
|
||||||
then
|
then
|
||||||
notify.hud.sendtext(player, "Invalid dimensions for quarry 3x3x3")
|
notify.hud.sendtext(player, "Invalid dimensions for quarry 3x3x3")
|
||||||
-- minetest.chat_send_player(player:get_player_name(), "Invalid dimensions for quarry")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -149,9 +139,9 @@ end
|
|||||||
|
|
||||||
local function prepare_area(pos, pos2)
|
local function prepare_area(pos, pos2)
|
||||||
local placement_done = true
|
local placement_done = true
|
||||||
local minx, maxx = order(pos.x, pos2.x)
|
local minx, maxx = math.order(pos.x, pos2.x)
|
||||||
local miny, maxy = order(pos.y, pos2.y)
|
local miny, maxy = math.order(pos.y, pos2.y)
|
||||||
local minz, maxz = order(pos.z, pos2.z)
|
local minz, maxz = math.order(pos.z, pos2.z)
|
||||||
for x=minx , maxx do
|
for x=minx , maxx do
|
||||||
for y=miny, maxy do
|
for y=miny, maxy do
|
||||||
for z=minz, maxz do
|
for z=minz, maxz do
|
||||||
@ -231,9 +221,9 @@ local function timer_trigger(pos, elapsed)
|
|||||||
else
|
else
|
||||||
--shrink the operational area here to a 2d space with one piece of border taken away to drill there
|
--shrink the operational area here to a 2d space with one piece of border taken away to drill there
|
||||||
--
|
--
|
||||||
local posx, pos2x = order(pos.x, marker_pos.x)
|
local posx, pos2x = math.order(pos.x, marker_pos.x)
|
||||||
local posy, pos2y = order(pos.y, marker_pos.y)
|
local posy, pos2y = math.order(pos.y, marker_pos.y)
|
||||||
local posz, pos2z = order(pos.z, marker_pos.z)
|
local posz, pos2z = math.order(pos.z, marker_pos.z)
|
||||||
posx = posx +1
|
posx = posx +1
|
||||||
pos2x = pos2x -1
|
pos2x = pos2x -1
|
||||||
posz = posz + 1
|
posz = posz + 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user