2017-12-23 16:33:05 +00:00
|
|
|
local c_stone = minetest.get_content_id("ctf_map:ind_stone")
|
2017-12-28 12:48:58 +00:00
|
|
|
local c_stone_red = minetest.get_content_id("ctf_map:ind_stone_red")
|
2017-12-23 16:33:05 +00:00
|
|
|
local c_glass = minetest.get_content_id("ctf_map:ind_glass")
|
|
|
|
local c_glass_red = minetest.get_content_id("ctf_map:ind_glass_red")
|
|
|
|
local c_map_ignore = minetest.get_content_id("ctf_map:ignore")
|
2017-12-28 12:48:58 +00:00
|
|
|
local c_actual_st = minetest.get_content_id("default:stone")
|
2018-11-12 04:06:52 +00:00
|
|
|
local c_water = minetest.get_content_id("default:water_source")
|
2018-04-06 13:04:56 +00:00
|
|
|
-- local c_water_f = minetest.get_content_id("default:water_flowing")
|
2017-12-23 16:33:05 +00:00
|
|
|
local c_air = minetest.get_content_id("air")
|
|
|
|
|
|
|
|
function ctf_map.remove_middle_barrier()
|
|
|
|
local r = ctf_map.map.r
|
|
|
|
local h = ctf_map.map.h
|
|
|
|
|
2018-01-26 17:40:09 +00:00
|
|
|
local min = vector.add(ctf_map.map.offset, {
|
2017-12-23 16:33:05 +00:00
|
|
|
x = -r + 1,
|
|
|
|
y = -h / 2,
|
|
|
|
z = -1
|
2018-01-26 17:40:09 +00:00
|
|
|
})
|
|
|
|
local max = vector.add(ctf_map.map.offset, {
|
2017-12-23 16:33:05 +00:00
|
|
|
x = r - 1,
|
|
|
|
y = h / 2,
|
|
|
|
z = 1
|
2018-01-26 17:40:09 +00:00
|
|
|
})
|
2017-12-23 16:33:05 +00:00
|
|
|
|
|
|
|
local vm = minetest.get_voxel_manip()
|
|
|
|
local emin, emax = vm:read_from_map(min, max)
|
|
|
|
local a = VoxelArea:new{
|
|
|
|
MinEdge = emin,
|
|
|
|
MaxEdge = emax
|
|
|
|
}
|
|
|
|
local data = vm:get_data()
|
|
|
|
for x = min.x, max.x do
|
|
|
|
for y = min.y, max.y do
|
2018-11-12 04:06:52 +00:00
|
|
|
local vi = a:index(x, y, 0)
|
|
|
|
local adj1 = a:index(x, y, 1)
|
|
|
|
local adj2 = a:index(x, y, -1)
|
|
|
|
|
2017-12-23 16:33:05 +00:00
|
|
|
if data[vi] == c_glass_red then
|
2018-11-12 04:06:52 +00:00
|
|
|
-- If surrounding nodes are water, replace node with water
|
|
|
|
if data[adj1] == c_water and data[adj2] == c_water then
|
|
|
|
data[vi] = c_water
|
|
|
|
-- Else replace with air
|
|
|
|
else
|
|
|
|
data[vi] = c_air
|
|
|
|
end
|
2017-12-28 12:48:58 +00:00
|
|
|
elseif data[vi] == c_stone_red then
|
|
|
|
data[vi] = c_actual_st
|
2017-12-23 16:33:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
vm:set_data(data)
|
|
|
|
vm:write_to_map(data)
|
|
|
|
vm:update_map()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ctf_map.place_middle_barrier(center, r, h, direction)
|
|
|
|
assert(direction == "x" or direction == "z")
|
|
|
|
|
|
|
|
local min = {
|
|
|
|
x = -r + 1,
|
|
|
|
y = -h / 2 + 1,
|
|
|
|
z = -r + 1,
|
|
|
|
}
|
|
|
|
local max = {
|
|
|
|
x = r - 1,
|
|
|
|
y = h / 2 - 1,
|
|
|
|
z = r - 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
local other = "z"
|
|
|
|
if direction == "z" then
|
|
|
|
other = "x"
|
|
|
|
end
|
|
|
|
|
|
|
|
min[direction] = -1
|
|
|
|
max[direction] = 1
|
|
|
|
min = vector.add(center, min)
|
|
|
|
max = vector.add(center, max)
|
|
|
|
|
|
|
|
|
|
|
|
local vm = minetest.get_voxel_manip()
|
|
|
|
local emin, emax = vm:read_from_map(min, max)
|
|
|
|
local a = VoxelArea:new{
|
|
|
|
MinEdge = emin,
|
|
|
|
MaxEdge = emax
|
|
|
|
}
|
|
|
|
|
|
|
|
local data = vm:get_data()
|
|
|
|
for x = min[other], max[other] do
|
|
|
|
for y = min.y, max.y do
|
|
|
|
local vi
|
|
|
|
if other == "x" then
|
|
|
|
vi = a:index(x, y, center.z)
|
|
|
|
else
|
|
|
|
vi = a:index(center.x, y, x)
|
|
|
|
end
|
2018-11-12 04:06:52 +00:00
|
|
|
if data[vi] == c_air or data[vi] == c_water then
|
2017-12-23 16:33:05 +00:00
|
|
|
data[vi] = c_glass_red
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
vm:set_data(data)
|
|
|
|
vm:write_to_map(data)
|
|
|
|
vm:update_map()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function ctf_map.place_outer_barrier(center, r, h)
|
|
|
|
local minp = vector.subtract(center, r)
|
|
|
|
local maxp = vector.add(center, r)
|
|
|
|
minp.y = center.y - h / 2
|
|
|
|
maxp.y = center.y + h / 2
|
|
|
|
|
|
|
|
print("Loading data into LVM")
|
|
|
|
|
|
|
|
local vm = minetest.get_voxel_manip()
|
|
|
|
local emin, emax = vm:read_from_map(minp, maxp)
|
|
|
|
local a = VoxelArea:new{
|
|
|
|
MinEdge = emin,
|
|
|
|
MaxEdge = emax
|
|
|
|
}
|
|
|
|
local data = vm:get_data()
|
|
|
|
|
|
|
|
print("Placing left wall")
|
|
|
|
|
|
|
|
-- Left
|
2018-04-06 13:04:56 +00:00
|
|
|
do
|
|
|
|
local x = center.x - r
|
|
|
|
for z = minp.z, maxp.z do
|
|
|
|
for y = minp.y, maxp.y do
|
|
|
|
local vi = a:index(x, y, z)
|
|
|
|
if data[vi] == c_air or data[vi] == c_glass or data[vi] == c_map_ignore then
|
|
|
|
data[vi] = c_glass
|
|
|
|
else
|
|
|
|
data[vi] = c_stone
|
|
|
|
end
|
2017-12-23 16:33:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
print("Placing right wall")
|
|
|
|
|
|
|
|
-- Right
|
2018-04-06 13:04:56 +00:00
|
|
|
do
|
|
|
|
local x = center.x + r
|
|
|
|
for z = minp.z, maxp.z do
|
|
|
|
for y = minp.y, maxp.y do
|
|
|
|
local vi = a:index(x, y, z)
|
|
|
|
if data[vi] == c_air or data[vi] == c_glass or data[vi] == c_map_ignore then
|
|
|
|
data[vi] = c_glass
|
|
|
|
else
|
|
|
|
data[vi] = c_stone
|
|
|
|
end
|
2017-12-23 16:33:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
print("Placing front wall")
|
|
|
|
|
|
|
|
-- Front
|
2018-04-06 13:04:56 +00:00
|
|
|
do
|
|
|
|
local z = center.z - r
|
|
|
|
for x = minp.x, maxp.x do
|
|
|
|
for y = minp.y, maxp.y do
|
|
|
|
local vi = a:index(x, y, z)
|
|
|
|
if data[vi] == c_air or data[vi] == c_glass or data[vi] == c_map_ignore then
|
|
|
|
data[vi] = c_glass
|
|
|
|
else
|
|
|
|
data[vi] = c_stone
|
|
|
|
end
|
2017-12-23 16:33:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
print("Placing back wall")
|
|
|
|
|
|
|
|
-- Back
|
2018-04-06 13:04:56 +00:00
|
|
|
do
|
|
|
|
local z = center.z + r
|
|
|
|
for x = minp.x, maxp.x do
|
|
|
|
for y = minp.y, maxp.y do
|
|
|
|
local vi = a:index(x, y, z)
|
|
|
|
if data[vi] == c_air or data[vi] == c_glass or data[vi] == c_map_ignore then
|
|
|
|
data[vi] = c_glass
|
|
|
|
else
|
|
|
|
data[vi] = c_stone
|
|
|
|
end
|
2017-12-23 16:33:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-12 04:05:38 +00:00
|
|
|
print("Placing bedrock")
|
|
|
|
|
|
|
|
-- Bedrock
|
|
|
|
do
|
|
|
|
local y = minp.y
|
|
|
|
for x = minp.x, maxp.x do
|
|
|
|
for z = minp.z, maxp.z do
|
|
|
|
data[a:index(x, y, z)] = c_stone
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
print("Placing ceiling")
|
|
|
|
|
|
|
|
-- Ceiling
|
|
|
|
do
|
|
|
|
local y = maxp.y
|
|
|
|
for x = minp.x, maxp.x do
|
|
|
|
for z = minp.z, maxp.z do
|
|
|
|
data[a:index(x, y, z)] = c_glass
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-23 16:33:05 +00:00
|
|
|
print("Writing to engine!")
|
|
|
|
|
|
|
|
vm:set_data(data)
|
|
|
|
vm:write_to_map(data)
|
|
|
|
vm:update_map()
|
|
|
|
end
|
|
|
|
|
|
|
|
if minetest.get_modpath("ctf") then
|
|
|
|
local old_is_protected = minetest.is_protected
|
|
|
|
function minetest.is_protected(pos, name)
|
|
|
|
if ctf_match.build_timer <= 0 then
|
|
|
|
return old_is_protected(pos, name)
|
|
|
|
end
|
|
|
|
|
|
|
|
local tname = ctf.player(name).team
|
|
|
|
if tname and
|
|
|
|
(tname == "blue" and pos.z >= 0) or (tname == "red" and pos.z <= 0) then
|
|
|
|
minetest.chat_send_player(name, "Can't dig beyond the barrier!")
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return old_is_protected(pos, name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function pos_check()
|
|
|
|
if ctf_match.build_timer <= 0 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
2019-03-17 03:32:15 +00:00
|
|
|
if ctf_map.get_team_relative_z(player) < 0 and not ctf_map.can_cross(player) then
|
|
|
|
local name = player:get_player_name()
|
|
|
|
minetest.chat_send_player(name, "Match hasn't started yet!")
|
|
|
|
ctf.move_to_spawn(name)
|
2017-12-23 16:33:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if ctf_match.build_timer > 0.2 then
|
|
|
|
minetest.after(0.2, pos_check)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ctf_match.register_on_build_time_start(function()
|
|
|
|
minetest.after(0.2, pos_check)
|
|
|
|
end)
|
|
|
|
end
|