diff options
author | BremaWeb <brandon@bremaweb.com> | 2013-11-30 13:23:50 -0600 |
---|---|---|
committer | BremaWeb <brandon@bremaweb.com> | 2013-11-30 13:23:50 -0600 |
commit | 81a12e3d38c83eacfce4a3eeaec14724dcdb4c8f (patch) | |
tree | 58701772bd01e4ab332a0699cdcf0a3e0bf8e432 /functions.lua | |
parent | 6b22f3d60f1b942485ccbb6dc5417fbe65119db9 (diff) |
restructured, use Settings interface for config, use protection API
Diffstat (limited to 'functions.lua')
-rw-r--r-- | functions.lua | 54 |
1 files changed, 54 insertions, 0 deletions
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 |