2018-07-19 21:16:48 +00:00
|
|
|
assert(minetest.get_mapgen_setting("mg_name") == "singlenode", "singlenode mapgen is required.")
|
2017-12-23 16:33:05 +00:00
|
|
|
|
|
|
|
minetest.register_alias("mapgen_singlenode", "ctf_map:ignore")
|
2018-02-04 03:42:44 +00:00
|
|
|
minetest.register_alias("ctf_map:flag", "air")
|
2019-03-17 14:43:31 +00:00
|
|
|
minetest.register_alias("ctf_map:ind_cobble", "ctf_map:cobble")
|
|
|
|
minetest.register_alias("ctf_map:ind_stone", "ctf_map:stone")
|
2018-02-04 03:42:44 +00:00
|
|
|
|
2019-07-05 00:51:13 +00:00
|
|
|
minetest.register_alias_force("flowers:mushroom_red", "air")
|
|
|
|
minetest.register_alias_force("flowers:mushroom_brown", "air")
|
|
|
|
minetest.register_alias_force("flowers:waterlily", "air")
|
|
|
|
minetest.register_alias_force("flowers:rose", "air")
|
|
|
|
minetest.register_alias_force("flowers:tulip", "air")
|
|
|
|
minetest.register_alias_force("flowers:dandelion_yellow", "air")
|
|
|
|
minetest.register_alias_force("flowers:geranium", "air")
|
|
|
|
minetest.register_alias_force("flowers:viola", "air")
|
|
|
|
minetest.register_alias_force("flowers:dandelion_white", "air")
|
|
|
|
minetest.register_alias_force("flowers:chrysanthemum_green", "air")
|
|
|
|
minetest.register_alias_force("default:grass_1", "air")
|
|
|
|
minetest.register_alias_force("default:grass_2", "air")
|
|
|
|
minetest.register_alias_force("default:grass_3", "air")
|
|
|
|
minetest.register_alias_force("default:grass_4", "air")
|
|
|
|
minetest.register_alias_force("default:sand_with_kelp", "default:sand")
|
|
|
|
minetest.register_alias_force("default:grass_5", "air")
|
|
|
|
minetest.register_alias_force("default:bush_leaves", "air")
|
|
|
|
minetest.register_alias_force("default:bush_stem", "air")
|
|
|
|
minetest.register_alias_force("default:stone_with_gold", "default:stone")
|
2017-12-23 16:33:05 +00:00
|
|
|
|
2018-07-19 21:16:58 +00:00
|
|
|
|
2019-10-11 10:20:56 +00:00
|
|
|
local max_r = 120
|
|
|
|
ctf_map.mapdir = minetest.get_modpath("ctf_map") .. "/maps/"
|
|
|
|
ctf_map.map = nil
|
2018-01-06 03:06:32 +00:00
|
|
|
|
2019-03-17 03:38:24 +00:00
|
|
|
-- Modify server status message to include map info
|
|
|
|
local map_str
|
|
|
|
local old_server_status = minetest.get_server_status
|
|
|
|
function minetest.get_server_status(name, joined)
|
2019-03-17 10:49:00 +00:00
|
|
|
local status = old_server_status(name, joined)
|
2019-03-17 03:38:24 +00:00
|
|
|
|
|
|
|
if not ctf_map.map or not map_str then
|
|
|
|
return status
|
|
|
|
end
|
|
|
|
|
|
|
|
local str = map_str
|
2019-03-17 10:49:00 +00:00
|
|
|
if name and minetest.get_player_by_name(name) then
|
2019-03-17 03:38:24 +00:00
|
|
|
str = minetest.colorize("#44FF44", str)
|
|
|
|
end
|
|
|
|
status = status .. "\n" .. str
|
|
|
|
|
|
|
|
-- If player just joined, also display map hint
|
|
|
|
if joined and ctf_map.map.hint then
|
|
|
|
status = status .. "\n" .. minetest.colorize("#22FF22", ctf_map.map.hint)
|
|
|
|
end
|
|
|
|
|
|
|
|
return status
|
|
|
|
end
|
|
|
|
|
2017-12-27 16:27:59 +00:00
|
|
|
|
2019-05-12 17:33:32 +00:00
|
|
|
function ctf_map.get_idx_and_map(param)
|
|
|
|
param = param:lower():trim()
|
|
|
|
for i, map in pairs(ctf_map.available_maps) do
|
|
|
|
if map.name:lower():find(param, 1, true) or
|
|
|
|
map.path:lower():find(param, 1, true) then
|
|
|
|
return i, map
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-24 20:17:23 +00:00
|
|
|
local next_idx
|
|
|
|
minetest.register_chatcommand("set_next", {
|
|
|
|
privs = { ctf_admin = true },
|
|
|
|
func = function(name, param)
|
2019-05-12 17:33:32 +00:00
|
|
|
local idx, map = ctf_map.get_idx_and_map(param)
|
|
|
|
if idx then
|
|
|
|
next_idx = idx
|
2019-10-18 05:52:18 +00:00
|
|
|
minetest.log("action", name .. " selected '" .. map.name .. "' as next map")
|
2019-05-12 17:33:32 +00:00
|
|
|
return true, "Selected " .. map.name
|
|
|
|
else
|
|
|
|
return false, "Couldn't find any matches"
|
2018-06-24 20:17:23 +00:00
|
|
|
end
|
2018-06-24 22:14:12 +00:00
|
|
|
end,
|
|
|
|
})
|
2017-12-27 16:27:59 +00:00
|
|
|
|
2019-10-11 14:03:40 +00:00
|
|
|
local function load_map_meta(idx, path, filename)
|
|
|
|
minetest.log("info", "load_map_meta: Loading map meta from \"" .. path .. filename .. "\"")
|
|
|
|
local conf_path = ctf_map.mapdir .. path .. filename .. ".conf"
|
2019-05-12 13:23:31 +00:00
|
|
|
local offset = vector.new(600 * idx, 0, 0)
|
|
|
|
local meta = Settings(conf_path)
|
2017-12-27 16:27:59 +00:00
|
|
|
|
2019-05-12 13:23:31 +00:00
|
|
|
if not meta:get("r") then
|
|
|
|
error("Map was not properly configured " .. conf_path)
|
2018-11-16 19:52:02 +00:00
|
|
|
end
|
2017-12-23 16:33:05 +00:00
|
|
|
|
2018-01-21 22:10:37 +00:00
|
|
|
local initial_stuff = meta:get("initial_stuff")
|
2019-02-24 05:11:16 +00:00
|
|
|
local treasures = meta:get("treasures")
|
2019-10-17 05:18:06 +00:00
|
|
|
local start_time = meta:get("start_time")
|
|
|
|
local time_speed = meta:get("time_speed")
|
|
|
|
|
2017-12-23 16:33:05 +00:00
|
|
|
local map = {
|
2018-01-21 22:10:37 +00:00
|
|
|
name = meta:get("name"),
|
2019-10-11 14:03:40 +00:00
|
|
|
path = path,
|
|
|
|
filename = filename,
|
2018-01-21 22:10:37 +00:00
|
|
|
author = meta:get("author"),
|
2018-01-26 18:33:02 +00:00
|
|
|
hint = meta:get("hint"),
|
2018-01-21 22:10:37 +00:00
|
|
|
rotation = meta:get("rotation"),
|
2019-05-12 13:23:31 +00:00
|
|
|
screenshot = meta:get("screenshot"),
|
2019-10-11 10:20:56 +00:00
|
|
|
skybox = ctf_map.skybox_exists(path, filename),
|
2019-05-15 15:04:25 +00:00
|
|
|
license = meta:get("license"),
|
|
|
|
others = meta:get("others"),
|
2019-10-09 06:16:51 +00:00
|
|
|
base_node = meta:get("base_node"),
|
2019-10-11 10:20:56 +00:00
|
|
|
schematic = path .. filename .. ".mts",
|
2018-01-26 22:44:56 +00:00
|
|
|
initial_stuff = initial_stuff and initial_stuff:split(","),
|
2019-10-17 05:18:06 +00:00
|
|
|
treasures = treasures and treasures:split(";"),
|
|
|
|
start_time = start_time and tonumber(start_time),
|
|
|
|
time_speed = time_speed and tonumber(time_speed),
|
2018-01-21 22:10:37 +00:00
|
|
|
r = tonumber(meta:get("r")),
|
|
|
|
h = tonumber(meta:get("h")),
|
2018-01-26 17:40:09 +00:00
|
|
|
offset = offset,
|
2018-01-26 22:44:56 +00:00
|
|
|
teams = {},
|
2019-02-24 05:11:16 +00:00
|
|
|
chests = {}
|
2017-12-23 16:33:05 +00:00
|
|
|
}
|
|
|
|
|
2018-07-19 21:16:58 +00:00
|
|
|
assert(map.r <= max_r)
|
2018-01-06 02:05:51 +00:00
|
|
|
|
|
|
|
map.pos1 = vector.add(offset, { x = -map.r, y = -map.h / 2, z = -map.r })
|
2019-10-17 05:18:06 +00:00
|
|
|
map.pos2 = vector.add(offset, { x = map.r, y = map.h / 2, z = map.r })
|
2017-12-28 12:49:17 +00:00
|
|
|
|
2018-01-26 22:44:56 +00:00
|
|
|
-- Read teams from config
|
2017-12-23 16:33:05 +00:00
|
|
|
local i = 1
|
|
|
|
while meta:get("team." .. i) do
|
2017-12-27 16:01:14 +00:00
|
|
|
local tname = meta:get("team." .. i)
|
2017-12-23 16:33:05 +00:00
|
|
|
local tcolor = meta:get("team." .. i .. ".color")
|
2017-12-27 16:01:14 +00:00
|
|
|
local tpos = minetest.string_to_pos(meta:get("team." .. i .. ".pos"))
|
2017-12-23 16:33:05 +00:00
|
|
|
|
|
|
|
map.teams[tname] = {
|
|
|
|
color = tcolor,
|
2018-01-06 02:05:51 +00:00
|
|
|
pos = vector.add(offset, tpos),
|
2017-12-23 16:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
|
2018-01-26 22:44:56 +00:00
|
|
|
-- Read custom chest zones from config
|
|
|
|
i = 1
|
2019-10-18 05:52:18 +00:00
|
|
|
minetest.log("info", "Parsing chest zones of " .. map.name .. "...")
|
2018-01-26 22:44:56 +00:00
|
|
|
while meta:get("chests." .. i .. ".from") do
|
|
|
|
local from = minetest.string_to_pos(meta:get("chests." .. i .. ".from"))
|
|
|
|
local to = minetest.string_to_pos(meta:get("chests." .. i .. ".to"))
|
2019-04-10 10:07:31 +00:00
|
|
|
assert(from and to, "Positions needed for chest zone " ..
|
2019-05-12 13:23:31 +00:00
|
|
|
i .. " in map " .. map.name)
|
2018-01-26 22:44:56 +00:00
|
|
|
|
|
|
|
map.chests[i] = {
|
|
|
|
from = vector.add(offset, from),
|
|
|
|
to = vector.add(offset, to),
|
|
|
|
n = tonumber(meta:get("chests." .. i .. ".n") or "23"),
|
|
|
|
}
|
|
|
|
|
2019-10-18 05:52:18 +00:00
|
|
|
minetest.log("info", dump(map.chests[i]))
|
2018-01-26 22:44:56 +00:00
|
|
|
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Add default chest zones if none given
|
|
|
|
if i == 1 then
|
|
|
|
while meta:get("team." .. i) do
|
|
|
|
local chests1
|
|
|
|
if i == 1 then
|
|
|
|
chests1 = vector.add(offset, { x = -map.r, y = -map.h / 2, z = 0 })
|
|
|
|
elseif i == 2 then
|
|
|
|
chests1 = map.pos1
|
|
|
|
end
|
|
|
|
|
|
|
|
local chests2
|
|
|
|
if i == 1 then
|
|
|
|
chests2 = map.pos2
|
|
|
|
elseif i == 2 then
|
|
|
|
chests2 = vector.add(offset, { x = map.r, y = map.h / 2, z = 0 })
|
|
|
|
end
|
|
|
|
|
|
|
|
map.chests[i] = {
|
|
|
|
from = chests1,
|
|
|
|
to = chests2,
|
|
|
|
n = 23,
|
|
|
|
}
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-23 16:33:05 +00:00
|
|
|
return map
|
|
|
|
end
|
|
|
|
|
2019-05-12 13:23:31 +00:00
|
|
|
local function load_maps()
|
|
|
|
local files_hash = {}
|
|
|
|
|
2019-10-11 10:20:56 +00:00
|
|
|
local dirs = minetest.get_dir_list(ctf_map.mapdir, true)
|
2019-05-12 13:23:31 +00:00
|
|
|
table.insert(dirs, ".")
|
|
|
|
for _, dir in pairs(dirs) do
|
|
|
|
if dir ~= ".git" then
|
2019-10-11 10:20:56 +00:00
|
|
|
local files = minetest.get_dir_list(ctf_map.mapdir .. dir, false)
|
2019-05-12 13:23:31 +00:00
|
|
|
for i = 1, #files do
|
|
|
|
local parts = files[i]:split(".")
|
|
|
|
local filename = parts[1]
|
|
|
|
local extension = parts[2]
|
|
|
|
if extension == "mts" then
|
2019-10-11 14:03:40 +00:00
|
|
|
files_hash[#files_hash + 1] = {
|
|
|
|
subdir = dir .. "/",
|
|
|
|
filename = filename
|
|
|
|
}
|
2019-05-12 13:23:31 +00:00
|
|
|
else
|
2019-05-12 17:36:39 +00:00
|
|
|
if extension ~= "conf" and extension ~= "md" and extension ~= "png"
|
2019-05-12 13:23:31 +00:00
|
|
|
and files[i] ~= ".git" then
|
|
|
|
error("Map extension is not '.mts': " .. files[i])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local idx = 1
|
|
|
|
ctf_map.available_maps = {}
|
2019-10-11 14:03:40 +00:00
|
|
|
for i, path in pairs(files_hash) do
|
|
|
|
local conf = Settings(ctf_map.mapdir .. "/" ..
|
|
|
|
path.subdir .. path.filename .. ".conf")
|
|
|
|
local val = minetest.settings:get("ctf.maps." ..
|
|
|
|
string.gsub(path.subdir .. path.filename, "%./", ""):gsub("/", "."))
|
2019-05-12 13:23:31 +00:00
|
|
|
if not conf:get_bool("disabled", false) and val ~= "false" then
|
2019-10-11 14:03:40 +00:00
|
|
|
local map = load_map_meta(idx, path.subdir, path.filename)
|
2019-05-12 13:23:31 +00:00
|
|
|
table.insert(ctf_map.available_maps, map)
|
2019-10-11 10:20:56 +00:00
|
|
|
|
2019-05-12 13:23:31 +00:00
|
|
|
minetest.log("action", "Found map '" .. map.name .. "'")
|
|
|
|
minetest.log("info", dump(map))
|
|
|
|
idx = idx + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not next(ctf_map.available_maps) then
|
2019-10-11 10:20:56 +00:00
|
|
|
error("No maps found in directory " .. ctf_map.mapdir)
|
2019-05-12 13:23:31 +00:00
|
|
|
end
|
|
|
|
return ctf_map.available_maps
|
|
|
|
end
|
|
|
|
|
|
|
|
load_maps()
|
|
|
|
|
|
|
|
minetest.register_chatcommand("maps_reload", {
|
|
|
|
privs = { ctf_admin = true },
|
|
|
|
func = function(name, param)
|
|
|
|
local maps = load_maps()
|
|
|
|
next_idx = nil
|
|
|
|
return true, #maps .. " maps found: " .. table.concat(maps, ", ")
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
local function place_map(map)
|
|
|
|
ctf_map.emerge_with_callbacks(nil, map.pos1, map.pos2, function()
|
2019-10-11 10:20:56 +00:00
|
|
|
local schempath = ctf_map.mapdir .. map.schematic
|
2019-05-12 13:23:31 +00:00
|
|
|
local res = minetest.place_schematic(map.pos1, schempath,
|
|
|
|
map.rotation == "z" and "0" or "90")
|
|
|
|
|
|
|
|
assert(res)
|
|
|
|
|
|
|
|
for _, value in pairs(ctf_map.map.teams) do
|
|
|
|
ctf_map.place_base(value.color, value.pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
local seed = minetest.get_mapgen_setting("seed")
|
|
|
|
for _, chestzone in pairs(ctf_map.map.chests) do
|
2019-10-18 05:52:18 +00:00
|
|
|
minetest.log("info", "Placing " .. chestzone.n .. " chests from " ..
|
2019-05-12 13:23:31 +00:00
|
|
|
minetest.pos_to_string(chestzone.from) .. " to "..
|
|
|
|
minetest.pos_to_string(chestzone.to))
|
|
|
|
place_chests(chestzone.from, chestzone.to, seed, chestzone.n)
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.after(2, function()
|
|
|
|
local msg = "Map: " .. map.name .. " by " .. map.author
|
|
|
|
if map.hint then
|
|
|
|
msg = msg .. "\n" .. map.hint
|
|
|
|
end
|
|
|
|
minetest.chat_send_all(msg)
|
|
|
|
if minetest.global_exists("irc") and irc.connected then
|
|
|
|
irc:say("Map: " .. map.name)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.after(10, function()
|
|
|
|
minetest.fix_light(ctf_map.map.pos1, ctf_map.map.pos2)
|
|
|
|
end)
|
|
|
|
end, nil)
|
|
|
|
end
|
|
|
|
|
2017-12-23 16:33:05 +00:00
|
|
|
ctf_match.register_on_new_match(function()
|
2018-01-26 23:24:31 +00:00
|
|
|
minetest.clear_objects({ mode = "quick" })
|
|
|
|
|
2018-01-06 03:21:54 +00:00
|
|
|
-- Choose next map index, but don't select the same one again
|
|
|
|
local idx
|
2018-06-24 20:17:23 +00:00
|
|
|
if next_idx then
|
|
|
|
idx = next_idx
|
|
|
|
elseif ctf_map.map then
|
2018-01-06 03:21:54 +00:00
|
|
|
idx = math.random(#ctf_map.available_maps - 1)
|
2018-01-22 03:28:16 +00:00
|
|
|
if idx >= ctf_map.map.idx then
|
2018-01-06 03:21:54 +00:00
|
|
|
idx = idx + 1
|
|
|
|
end
|
|
|
|
else
|
|
|
|
idx = math.random(#ctf_map.available_maps)
|
|
|
|
end
|
2018-06-24 20:17:23 +00:00
|
|
|
next_idx = (idx % #ctf_map.available_maps) + 1
|
2018-01-06 03:21:54 +00:00
|
|
|
|
|
|
|
-- Load meta data
|
2019-05-12 13:23:31 +00:00
|
|
|
ctf_map.map = ctf_map.available_maps[idx]
|
|
|
|
ctf_map.map.idx = idx
|
2018-01-06 03:21:54 +00:00
|
|
|
|
2019-05-12 13:23:31 +00:00
|
|
|
map_str = "Map: " .. ctf_map.map.name .. " by " .. ctf_map.map.author
|
2019-07-06 04:46:04 +00:00
|
|
|
|
|
|
|
-- Register per-map treasures, or the default set of treasures
|
|
|
|
-- if treasures field hasn't been defined in map meta
|
|
|
|
if ctf_treasure then
|
|
|
|
treasurer.treasures = {}
|
|
|
|
if ctf_map.treasures then
|
|
|
|
for _, item in pairs(ctf_map.treasures) do
|
|
|
|
item = item:split(",")
|
|
|
|
-- treasurer.register_treasure(name, rarity, preciousness, count)
|
|
|
|
if #item == 4 then
|
|
|
|
treasurer.register_treasure(item[1],
|
|
|
|
tonumber(item[2]),
|
|
|
|
tonumber(item[3]),
|
|
|
|
tonumber(item[4]))
|
|
|
|
-- treasurer.register_treasure(name, rarity, preciousness, {min, max})
|
|
|
|
elseif #item == 5 then
|
|
|
|
treasurer.register_treasure(item[1],
|
|
|
|
tonumber(item[2]),
|
|
|
|
tonumber(item[3]),
|
|
|
|
{
|
|
|
|
tonumber(item[4]),
|
|
|
|
tonumber(item[5])
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- If treasure is a part of map's initial stuff, don't register it
|
|
|
|
local blacklist = ctf_map.map.initial_stuff or give_initial_stuff.get_stuff()
|
|
|
|
for _, def in pairs(ctf_treasure.get_default_treasures()) do
|
|
|
|
local is_valid = true
|
|
|
|
for _, b_item in pairs(blacklist) do
|
|
|
|
local b_stack = ItemStack(b_item)
|
|
|
|
local t_stack = ItemStack(def[1])
|
|
|
|
if b_stack:get_name() == t_stack:get_name() and
|
|
|
|
t_stack:get_count() == 1 then
|
|
|
|
is_valid = false
|
|
|
|
minetest.log("action",
|
|
|
|
"ctf_map: Omitting treasure - " .. def[1])
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if is_valid then
|
2019-10-18 05:52:18 +00:00
|
|
|
minetest.log("action",
|
2019-07-06 04:46:04 +00:00
|
|
|
"ctf_map: Registering treasure - " .. def[1])
|
|
|
|
treasurer.register_treasure(def[1], def[2], def[3], def[4])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-11 10:20:56 +00:00
|
|
|
-- Place map
|
|
|
|
place_map(ctf_map.map)
|
|
|
|
|
2019-10-17 05:18:06 +00:00
|
|
|
-- Update time speed
|
|
|
|
ctf_map.update_time()
|
|
|
|
|
2019-10-11 10:20:56 +00:00
|
|
|
-- Update players' skyboxes last
|
|
|
|
ctf_map.set_skybox_all()
|
2017-12-23 16:33:05 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
function ctf_match.create_teams()
|
|
|
|
for key, value in pairs(ctf_map.map.teams) do
|
|
|
|
local name = key
|
|
|
|
local color = value.color
|
2019-07-11 06:57:10 +00:00
|
|
|
local flag = table.copy(value.pos)
|
2017-12-23 16:33:05 +00:00
|
|
|
|
|
|
|
if name and color and flag then
|
2019-10-18 05:52:18 +00:00
|
|
|
minetest.log("action", "Creating team " .. key)
|
2017-12-23 16:33:05 +00:00
|
|
|
ctf.team({
|
|
|
|
name = name,
|
|
|
|
color = color,
|
|
|
|
add_team = true
|
|
|
|
})
|
|
|
|
|
|
|
|
ctf_flag.add(name, flag)
|
|
|
|
|
|
|
|
minetest.after(0, function()
|
|
|
|
ctf_flag.assert_flag(flag)
|
|
|
|
end)
|
|
|
|
else
|
2019-10-18 05:52:18 +00:00
|
|
|
minetest.log("error", "Failed to create team " .. key)
|
2017-12-23 16:33:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-10-11 10:20:56 +00:00
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
if ctf_map.map then
|
|
|
|
ctf_map.set_skybox(player)
|
|
|
|
end
|
|
|
|
end)
|