diff --git a/mods/capturetheflag/ctf/area.lua b/mods/capturetheflag/ctf/area.lua index 71a3747..bfe8fc5 100644 --- a/mods/capturetheflag/ctf/area.lua +++ b/mods/capturetheflag/ctf/area.lua @@ -30,8 +30,8 @@ function ctf.area.get_flag(pos) team.flags[i].z == pos.z ) then if result then - minetest.chat_send_all("[CTF WARNING] Multiple teams have same flag. Please report this to the server operator / admin") - print("CTF WARNING DATA") + minetest.chat_send_all("[CTF ERROR] Multiple teams have same flag. Please report this to the server operator / admin") + print("CTF ERROR DATA") print("Multiple teams have same flag.") print("This is a sign of ctf.txt corruption.") print("----------------") @@ -48,7 +48,7 @@ function ctf.area.get_flag(pos) end -- delete a flag from a team -function ctf.area.delete_flag(team,pos) +function ctf.area.delete_flag(team, pos) if not team or team == "" then return end @@ -73,11 +73,17 @@ function ctf.area.nearest_flag(pos) return nil end - print("ctf.setting('flag_protect_distance') is "..dump(ctf.setting("flag_protect_distance"))) - local nodes = minetest.env:find_nodes_in_area( - {x=pos.x-ctf.setting("flag_protect_distance"),y=pos.y-ctf.setting("flag_protect_distance"),z=pos.z-ctf.setting("flag_protect_distance")}, - {x=pos.x+ctf.setting("flag_protect_distance"),y=pos.y+ctf.setting("flag_protect_distance"),z=pos.z+ctf.setting("flag_protect_distance")}, + { + x = pos.x - ctf.setting("flag_protect_distance"), + y = pos.y - ctf.setting("flag_protect_distance"), + z = pos.z - ctf.setting("flag_protect_distance") + }, + { + x = pos.x + ctf.setting("flag_protect_distance"), + y = pos.y + ctf.setting("flag_protect_distance"), + z = pos.z + ctf.setting("flag_protect_distance") + }, {"group:is_flag"} ) @@ -85,10 +91,11 @@ function ctf.area.nearest_flag(pos) local closest = nil local _dis = 1000 - for a=1, #nodes do - if v3.distance(pos, nodes[a]) < _dis then + for a = 1, #nodes do + local this_dis = vector.distance(pos, nodes[a]) + if this_dis < _dis then closest = nodes[a] - _dis = v3.distance(pos, nodes[a]) + _dis = this_dis end end @@ -105,7 +112,7 @@ function ctf.area.get_area(pos) return false end local flag = ctf.area.get_flag(closest) - + if flag then return flag.team end @@ -119,11 +126,11 @@ function ctf.area.get_spawn(team) if team and ctf.teams and ctf.team(team) then if ctf.team(team).spawn and minetest.env:get_node(ctf.team(team).spawn).name == "ctf:flag" then local flag = ctf.area.get_flag(ctf.team(team).spawn) - + if not flag then return false end - + local _team = flag.team -- Check to see if spawn is already defined @@ -145,7 +152,7 @@ function ctf.area.asset_flags(team) if not team or not ctf.team(team) then return false end - + print("Checking the flags of "..team) local tmp = ctf.team(team).flags @@ -155,4 +162,4 @@ function ctf.area.asset_flags(team) print("Replacing flag...") end end -end \ No newline at end of file +end diff --git a/mods/capturetheflag/ctf/init.lua b/mods/capturetheflag/ctf/init.lua index 9c1b9c8..cd00178 100644 --- a/mods/capturetheflag/ctf/init.lua +++ b/mods/capturetheflag/ctf/init.lua @@ -4,60 +4,6 @@ ctf = {} --- Helpers -v3={} -function v3.distance(v, w) - return math.sqrt( - math.pow(v.x - w.x, 2) + - math.pow(v.y - w.y, 2) + - math.pow(v.z - w.z, 2) - ) -end -function v3.get_direction(pos1,pos2) - - local x_raw = pos2.x -pos1.x - local y_raw = pos2.y -pos1.y - local z_raw = pos2.z -pos1.z - - - local x_abs = math.abs(x_raw) - local y_abs = math.abs(y_raw) - local z_abs = math.abs(z_raw) - - if x_abs >= y_abs and - x_abs >= z_abs then - - y_raw = y_raw * (1/x_abs) - z_raw = z_raw * (1/x_abs) - - x_raw = x_raw/x_abs - - end - - if y_abs >= x_abs and - y_abs >= z_abs then - - - x_raw = x_raw * (1/y_abs) - z_raw = z_raw * (1/y_abs) - - y_raw = y_raw/y_abs - - end - - if z_abs >= y_abs and - z_abs >= x_abs then - - x_raw = x_raw * (1/z_abs) - y_raw = y_raw * (1/z_abs) - - z_raw = z_raw/z_abs - - end - - return {x=x_raw,y=y_raw,z=z_raw} -end - -- Modules dofile(minetest.get_modpath("ctf").."/core.lua") dofile(minetest.get_modpath("ctf").."/diplomacy.lua")