Add ctf_flag.assert_flag()

This commit is contained in:
rubenwardy 2015-11-25 20:11:44 +00:00
parent 0a4f30df25
commit a914b43439

View File

@ -168,24 +168,11 @@ function ctf_flag.delete(team, pos)
end end
end end
function ctf_flag.assert_flags() function ctf_flag.assert_flag(flag)
for tname, team in pairs(ctf.teams) do
ctf_flag.assert_flags_team(tname)
end
end
function ctf_flag.assert_flags_team(tname)
local team = ctf.team(tname)
if not tname or not team then
return false
end
for i=1, #team.flags do
local flag = team.flags[i]
minetest.get_voxel_manip(flag, { x = flag.x + 1, y = flag.y + 1, z = flag.z + 1}) minetest.get_voxel_manip(flag, { x = flag.x + 1, y = flag.y + 1, z = flag.z + 1})
local nodename = minetest.get_node(flag).name local nodename = minetest.get_node(flag).name
if nodename ~= "ctf_flag:flag" then if nodename ~= "ctf_flag:flag" then
ctf.log("flag", tname .. " has wrong node at flag position, " .. nodename .. ", correcting...") ctf.log("flag", flag.team .. " has wrong node at flag position, " .. nodename .. ", correcting...")
minetest.set_node(flag, { name = "ctf_flag:flag"}) minetest.set_node(flag, { name = "ctf_flag:flag"})
local function base_at(flag, dx, dz) local function base_at(flag, dx, dz)
@ -204,6 +191,26 @@ function ctf_flag.assert_flags_team(tname)
base_at(flag, 1, -1) base_at(flag, 1, -1)
base_at(flag, 1, 0) base_at(flag, 1, 0)
base_at(flag, 1, 1) base_at(flag, 1, 1)
if minetest.get_node(flag).name ~= "ctf_flag:flag" then
ctf_flag.update(flag)
end end
end end
end end
function ctf_flag.assert_flags()
for tname, team in pairs(ctf.teams) do
ctf_flag.assert_flags_team(tname)
end
end
function ctf_flag.assert_flags_team(tname)
local team = ctf.team(tname)
if not tname or not team then
return false
end
for i=1, #team.flags do
ctf_flag.assert_flag(team.flags[i])
end
end