2017-12-23 16:33:05 +00:00
|
|
|
assert(minetest.get_mapgen_setting("mg_name") == "singlenode", "singlenode mapgen is required.")
|
|
|
|
|
|
|
|
minetest.register_alias("mapgen_singlenode", "ctf_map:ignore")
|
2018-02-04 03:42:44 +00:00
|
|
|
minetest.register_alias("ctf_map:flag", "air")
|
|
|
|
|
2018-01-26 17:15:46 +00:00
|
|
|
minetest.register_alias("flowers:mushroom_red", "air")
|
|
|
|
minetest.register_alias("flowers:mushroom_brown", "air")
|
|
|
|
minetest.register_alias("flowers:waterlily", "air")
|
|
|
|
minetest.register_alias("flowers:rose", "air")
|
|
|
|
minetest.register_alias("flowers:tulip", "air")
|
|
|
|
minetest.register_alias("flowers:dandelion_yellow", "air")
|
|
|
|
minetest.register_alias("flowers:geranium", "air")
|
|
|
|
minetest.register_alias("flowers:viola", "air")
|
|
|
|
minetest.register_alias("flowers:dandelion_white", "air")
|
|
|
|
minetest.register_alias("flowers:chrysanthemum_green", "air")
|
|
|
|
minetest.register_alias("default:grass_1", "air")
|
|
|
|
minetest.register_alias("default:grass_2", "air")
|
|
|
|
minetest.register_alias("default:grass_3", "air")
|
|
|
|
minetest.register_alias("default:grass_4", "air")
|
|
|
|
minetest.register_alias("default:sand_with_kelp", "default:sand")
|
|
|
|
minetest.register_alias("default:grass_5", "air")
|
|
|
|
minetest.register_alias("default:bush_leaves", "air")
|
|
|
|
minetest.register_alias("default:bush_stem", "air")
|
2017-12-23 16:33:05 +00:00
|
|
|
|
|
|
|
|
2018-01-06 03:06:32 +00:00
|
|
|
local max_r = 120
|
2017-12-27 16:27:59 +00:00
|
|
|
local mapdir = minetest.get_modpath("ctf_map") .. "/maps/"
|
2018-01-06 03:06:32 +00:00
|
|
|
ctf_map.map = nil
|
|
|
|
|
2017-12-27 16:27:59 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
local files_hash = {}
|
2018-01-22 02:23:53 +00:00
|
|
|
|
|
|
|
local dirs = minetest.get_dir_list(mapdir, true)
|
|
|
|
table.insert(dirs, ".")
|
|
|
|
for _, dir in pairs(dirs) do
|
|
|
|
local files = minetest.get_dir_list(mapdir .. dir, false)
|
|
|
|
for i=1, #files do
|
|
|
|
files_hash[dir .. "/" .. files[i]:split(".")[1]] = true
|
|
|
|
end
|
2017-12-27 16:27:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
ctf_map.available_maps = {}
|
|
|
|
for key, _ in pairs(files_hash) do
|
|
|
|
table.insert(ctf_map.available_maps, key)
|
|
|
|
end
|
2018-01-22 03:28:16 +00:00
|
|
|
print(dump(ctf_map.available_maps))
|
2017-12-27 16:27:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2018-01-06 03:06:32 +00:00
|
|
|
function ctf_map.place_map(map)
|
2018-01-22 03:52:51 +00:00
|
|
|
ctf_map.emerge_with_callbacks(nil, map.pos1, map.pos2, function()
|
|
|
|
local schempath = mapdir .. map.schematic
|
|
|
|
local res = minetest.place_schematic(map.pos1, schempath,
|
|
|
|
map.rotation == "z" and "0" or "90")
|
2018-01-06 03:06:32 +00:00
|
|
|
|
2018-01-22 03:52:51 +00:00
|
|
|
assert(res)
|
2018-01-06 03:06:32 +00:00
|
|
|
|
|
|
|
for _, value in pairs(ctf_map.map.teams) do
|
2018-01-21 23:09:07 +00:00
|
|
|
ctf_team_base.place(value.color, value.pos)
|
2018-01-06 03:06:32 +00:00
|
|
|
end
|
2018-01-22 03:35:40 +00:00
|
|
|
|
2018-01-26 22:44:56 +00:00
|
|
|
local seed = minetest.get_mapgen_setting("seed")
|
|
|
|
for _, chestzone in pairs(ctf_map.map.chests) do
|
|
|
|
minetest.log("warning", "Placing " .. chestzone.n .. " chests from " ..
|
|
|
|
minetest.pos_to_string(chestzone.from) .. " to "..
|
|
|
|
minetest.pos_to_string(chestzone.to))
|
|
|
|
place_chests(chestzone.from, chestzone.to, seed, chestzone.n)
|
|
|
|
end
|
|
|
|
|
2018-01-22 03:52:51 +00:00
|
|
|
minetest.after(2, function()
|
2018-01-26 18:33:02 +00:00
|
|
|
local msg = "Map: " .. map.name .. " by " .. map.author
|
|
|
|
if map.hint then
|
|
|
|
msg = msg .. "\n" .. map.hint
|
|
|
|
end
|
|
|
|
minetest.chat_send_all(msg)
|
2018-01-27 19:44:03 +00:00
|
|
|
if minetest.global_exists("irc") and irc.connected then
|
2018-01-28 00:39:20 +00:00
|
|
|
irc:say("Map: " .. map.name)
|
2018-01-27 19:44:03 +00:00
|
|
|
end
|
2018-01-22 03:52:51 +00:00
|
|
|
end)
|
2018-01-26 16:17:42 +00:00
|
|
|
|
|
|
|
minetest.after(10, function()
|
|
|
|
minetest.fix_light(ctf_map.map.pos1, ctf_map.map.pos2)
|
|
|
|
end)
|
2018-01-22 03:52:51 +00:00
|
|
|
end, nil)
|
2018-01-06 03:06:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ctf_match.load_map_meta(idx, name)
|
2018-01-26 16:17:42 +00:00
|
|
|
local offset = vector.new(600 * idx, 0, 0)
|
2018-01-06 03:06:32 +00:00
|
|
|
local meta = Settings(mapdir .. name .. ".conf")
|
2017-12-23 16:33:05 +00:00
|
|
|
|
2018-01-21 22:10:37 +00:00
|
|
|
local initial_stuff = meta:get("initial_stuff")
|
2017-12-23 16:33:05 +00:00
|
|
|
local map = {
|
2018-01-21 22:10:37 +00:00
|
|
|
idx = idx,
|
|
|
|
name = meta:get("name"),
|
|
|
|
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"),
|
|
|
|
schematic = name .. ".mts",
|
2018-01-26 22:44:56 +00:00
|
|
|
initial_stuff = initial_stuff and initial_stuff:split(","),
|
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 = {},
|
|
|
|
chests = {},
|
2017-12-23 16:33:05 +00:00
|
|
|
}
|
|
|
|
|
2018-01-06 02:05:51 +00:00
|
|
|
assert(map.r <= max_r)
|
|
|
|
|
|
|
|
map.pos1 = vector.add(offset, { x = -map.r, y = -map.h / 2, z = -map.r })
|
|
|
|
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
|
|
|
|
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"))
|
|
|
|
assert(from and to, "Positions needed for chest zone " .. i .. " in map " .. map.name)
|
|
|
|
|
|
|
|
map.chests[i] = {
|
|
|
|
from = vector.add(offset, from),
|
|
|
|
to = vector.add(offset, to),
|
|
|
|
n = tonumber(meta:get("chests." .. i .. ".n") or "23"),
|
|
|
|
}
|
|
|
|
|
|
|
|
minetest.log("warning", dump(map.chests[i]))
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
if ctf_map.map then
|
|
|
|
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
|
|
|
|
|
|
|
|
-- Load meta data
|
2018-01-06 02:05:51 +00:00
|
|
|
local name = ctf_map.available_maps[idx]
|
2018-01-06 03:06:32 +00:00
|
|
|
ctf_map.map = ctf_match.load_map_meta(idx, name)
|
2018-01-06 03:21:54 +00:00
|
|
|
|
|
|
|
-- Place map
|
2017-12-23 16:33:05 +00:00
|
|
|
ctf_map.place_map(ctf_map.map)
|
|
|
|
end)
|
|
|
|
|
|
|
|
function ctf_match.create_teams()
|
|
|
|
for key, value in pairs(ctf_map.map.teams) do
|
|
|
|
local name = key
|
|
|
|
local color = value.color
|
|
|
|
local flag = value.pos
|
|
|
|
|
|
|
|
if name and color and flag then
|
|
|
|
print(" - creating " .. key)
|
|
|
|
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
|
|
|
|
minetest.log("error", " - Failed to create " .. key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-01-26 18:33:02 +00:00
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
local map = ctf_map.map
|
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local msg = "Map: " .. map.name .. " by " .. map.author
|
|
|
|
if map.hint then
|
|
|
|
msg = msg .. "\n" .. map.hint
|
|
|
|
end
|
|
|
|
minetest.chat_send_player(player:get_player_name(), msg)
|
|
|
|
end)
|