Remove vector helpers as they have been added to the lua api

This commit is contained in:
rubenwardy 2014-12-28 16:05:08 +00:00
parent a2e3cc8573
commit 46c8c60cb3
2 changed files with 22 additions and 69 deletions

View File

@ -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
@ -105,7 +112,7 @@ function ctf.area.get_area(pos)
return false return false
end end
local flag = ctf.area.get_flag(closest) local flag = ctf.area.get_flag(closest)
if flag then if flag then
return flag.team return flag.team
end end
@ -119,11 +126,11 @@ function ctf.area.get_spawn(team)
if team and ctf.teams and ctf.team(team) then 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 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) local flag = ctf.area.get_flag(ctf.team(team).spawn)
if not flag then if not flag then
return false return false
end end
local _team = flag.team local _team = flag.team
-- Check to see if spawn is already defined -- 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 if not team or not ctf.team(team) then
return false return false
end end
print("Checking the flags of "..team) print("Checking the flags of "..team)
local tmp = ctf.team(team).flags local tmp = ctf.team(team).flags
@ -155,4 +162,4 @@ function ctf.area.asset_flags(team)
print("Replacing flag...") print("Replacing flag...")
end end
end end
end end

View File

@ -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")