Separate ctf_flag.get_nearest with team_dist
This commit is contained in:
parent
622dcb8468
commit
2c2ebfe437
@ -24,7 +24,6 @@ end)
|
|||||||
|
|
||||||
function ctf_flag.get_nearest(pos)
|
function ctf_flag.get_nearest(pos)
|
||||||
local closest = nil
|
local closest = nil
|
||||||
local closest_team = nil
|
|
||||||
local closest_distSQ = 1000000
|
local closest_distSQ = 1000000
|
||||||
local pd = ctf.setting("flag.protect_distance")
|
local pd = ctf.setting("flag.protect_distance")
|
||||||
local pdSQ = pd * pd
|
local pdSQ = pd * pd
|
||||||
@ -34,16 +33,20 @@ function ctf_flag.get_nearest(pos)
|
|||||||
local distSQ = vector.distanceSQ(pos, team.flags[i])
|
local distSQ = vector.distanceSQ(pos, team.flags[i])
|
||||||
if distSQ < pdSQ and distSQ < closest_distSQ then
|
if distSQ < pdSQ and distSQ < closest_distSQ then
|
||||||
closest = team.flags[i]
|
closest = team.flags[i]
|
||||||
closest_team = tname
|
|
||||||
closest_distSQ = distSQ
|
closest_distSQ = distSQ
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return closest_team, closest_distSQ
|
return closest, closest_distSQ
|
||||||
end
|
end
|
||||||
|
|
||||||
ctf.register_on_territory_query(ctf_flag.get_nearest)
|
function ctf_flag.get_nearest_team_dist(pos)
|
||||||
|
local flag, distSQ = ctf_flag.get_nearest(pos)
|
||||||
|
return flag.team, distSQ
|
||||||
|
end
|
||||||
|
|
||||||
|
ctf.register_on_territory_query(ctf_flag.get_nearest_team_dist)
|
||||||
|
|
||||||
function ctf.get_spawn(team)
|
function ctf.get_spawn(team)
|
||||||
if not ctf.team(team) then
|
if not ctf.team(team) then
|
||||||
@ -72,12 +75,10 @@ function minetest.is_protected(pos, name)
|
|||||||
return old_is_protected(pos, name)
|
return old_is_protected(pos, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
local tname, distsq = ctf_flag.get_nearest(pos)
|
local flag, distSQ = ctf_flag.get_nearest(pos)
|
||||||
if distsq < rs then
|
if flag and pos.y >= flag.y and distSQ < rs then
|
||||||
minetest.chat_send_player(name,
|
minetest.chat_send_player(name,
|
||||||
"Too close to the flag to build! You need to be at least " .. r .. " nodes away.")
|
"Too close to the flag to build! Leave at least " .. r .. " blocks around the flag.")
|
||||||
minetest.chat_send_player(name,
|
|
||||||
"This is to stop new or respawning players from being trapped.")
|
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
return old_is_protected(pos, name)
|
return old_is_protected(pos, name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user