From 81a12e3d38c83eacfce4a3eeaec14724dcdb4c8f Mon Sep 17 00:00:00 2001 From: BremaWeb Date: Sat, 30 Nov 2013 13:23:50 -0600 Subject: restructured, use Settings interface for config, use protection API --- functions.lua | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 functions.lua (limited to 'functions.lua') diff --git a/functions.lua b/functions.lua new file mode 100644 index 0000000..92cad80 --- /dev/null +++ b/functions.lua @@ -0,0 +1,54 @@ +function landrush.get_chunk(pos) + local x = math.floor(pos.x/landrush.config:get("chunkSize")) + -- 3 levels of vertical protection + local y = 0 + + if ( pos.y < -200 ) then + y = - 32000 + elseif ( pos.y < -60 ) then + y = -200 + elseif ( pos.y < 140 ) then + y = -30 + else + y = 90 + end + + + local z = math.floor(pos.z/landrush.config:get("chunkSize")) + return x..","..y..","..z +end + +function landrush.get_chunk_center(pos) + local x = math.floor(pos.x/landrush.config:get("chunkSize"))*landrush.config:get("chunkSize")+7.5 + local y = 0 + + if ( pos.y < -200 ) then + y = - 32000 + elseif ( pos.y < -60 ) then + y = -200 + elseif ( pos.y < 120 ) then + y = -30 + else + y = 120 + end + + local z = math.floor(pos.z/landrush.config:get("chunkSize"))*landrush.config:get("chunkSize")+7.5 + return {x=x,y=y,z=z} +end + +function landrush.get_owner(pos) + local chunk = landrush.get_chunk(pos) + if landrush.claims[chunk] then + return landrush.claims[chunk].owner + end +end + +function landrush.get_distance(pos1,pos2) + + if ( pos1 ~= nil and pos2 ~= nil ) then + return math.abs(math.floor(math.sqrt( (pos1.x - pos2.x)^2 + (pos1.z - pos2.z)^2 ))) + else + return 0 + end + +end -- cgit v1.2.3