Remove vector helpers as they have been added to the lua api
This commit is contained in:
parent
a2e3cc8573
commit
46c8c60cb3
@ -30,8 +30,8 @@ function ctf.area.get_flag(pos)
|
|||||||
team.flags[i].z == pos.z
|
team.flags[i].z == pos.z
|
||||||
) then
|
) then
|
||||||
if result then
|
if result then
|
||||||
minetest.chat_send_all("[CTF WARNING] Multiple teams have same flag. Please report this to the server operator / admin")
|
minetest.chat_send_all("[CTF ERROR] Multiple teams have same flag. Please report this to the server operator / admin")
|
||||||
print("CTF WARNING DATA")
|
print("CTF ERROR DATA")
|
||||||
print("Multiple teams have same flag.")
|
print("Multiple teams have same flag.")
|
||||||
print("This is a sign of ctf.txt corruption.")
|
print("This is a sign of ctf.txt corruption.")
|
||||||
print("----------------")
|
print("----------------")
|
||||||
@ -48,7 +48,7 @@ function ctf.area.get_flag(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- delete a flag from a team
|
-- 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
|
if not team or team == "" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -73,11 +73,17 @@ function ctf.area.nearest_flag(pos)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
print("ctf.setting('flag_protect_distance') is "..dump(ctf.setting("flag_protect_distance")))
|
|
||||||
|
|
||||||
local nodes = minetest.env:find_nodes_in_area(
|
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"}
|
{"group:is_flag"}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -85,10 +91,11 @@ function ctf.area.nearest_flag(pos)
|
|||||||
local closest = nil
|
local closest = nil
|
||||||
local _dis = 1000
|
local _dis = 1000
|
||||||
|
|
||||||
for a=1, #nodes do
|
for a = 1, #nodes do
|
||||||
if v3.distance(pos, nodes[a]) < _dis then
|
local this_dis = vector.distance(pos, nodes[a])
|
||||||
|
if this_dis < _dis then
|
||||||
closest = nodes[a]
|
closest = nodes[a]
|
||||||
_dis = v3.distance(pos, nodes[a])
|
_dis = this_dis
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,60 +4,6 @@
|
|||||||
|
|
||||||
ctf = {}
|
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
|
-- Modules
|
||||||
dofile(minetest.get_modpath("ctf").."/core.lua")
|
dofile(minetest.get_modpath("ctf").."/core.lua")
|
||||||
dofile(minetest.get_modpath("ctf").."/diplomacy.lua")
|
dofile(minetest.get_modpath("ctf").."/diplomacy.lua")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user