Postpone map skipping until flag holder captures or loses the flag (#835)

* Postpone map skipping until flag holder captures or loses the flag

* Wait 5s after flag drop
This commit is contained in:
savilli 2021-03-24 17:34:02 +03:00 committed by GitHub
parent 1568de3449
commit 243061957a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,16 @@ function ctf_match.register_on_skip_map(func)
table.insert(ctf_match.registered_on_skip_map, func) table.insert(ctf_match.registered_on_skip_map, func)
end end
function skip()
for i = 1, #ctf_match.registered_on_skip_map do
ctf_match.registered_on_skip_map[i]()
end
ctf_match.next()
end
local can_vote_skip = false
local voted_skip = false
local flags_hold = 0
function ctf_match.vote_next(name) function ctf_match.vote_next(name)
local tcolor = ctf_colors.get_color(ctf.player(name)).css or "#FFFFFFFF" local tcolor = ctf_colors.get_color(ctf.player(name)).css or "#FFFFFFFF"
minetest.chat_send_all(minetest.colorize("#FFAA11", "Vote started by ") .. minetest.chat_send_all(minetest.colorize("#FFAA11", "Vote started by ") ..
@ -22,10 +32,12 @@ function ctf_match.vote_next(name)
if result == "yes" then if result == "yes" then
minetest.chat_send_all("Vote to skip match passed, " .. minetest.chat_send_all("Vote to skip match passed, " ..
#results.yes .. " to " .. #results.no) #results.yes .. " to " .. #results.no)
for i = 1, #ctf_match.registered_on_skip_map do
ctf_match.registered_on_skip_map[i]() can_vote_skip = false
voted_skip = true
if flags_hold <= 0 then
skip()
end end
ctf_match.next()
else else
minetest.chat_send_all("Vote to skip match failed, " .. minetest.chat_send_all("Vote to skip match failed, " ..
#results.no .. " to " .. #results.yes) #results.no .. " to " .. #results.yes)
@ -53,9 +65,8 @@ minetest.register_chatcommand("vote", {
local matchskip_time local matchskip_time
local matchskip_timer = 0 local matchskip_timer = 0
local can_skip = false
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
if not can_skip then return end if not can_vote_skip then return end
matchskip_timer = matchskip_timer + dtime matchskip_timer = matchskip_timer + dtime
@ -68,18 +79,25 @@ minetest.register_globalstep(function(dtime)
end end
end) end)
local function prevent_autoskip() ctf.register_on_new_game(function()
can_skip = false can_vote_skip = false
end voted_skip = false
flags_hold = 0
ctf.register_on_new_game(prevent_autoskip) end)
ctf_flag.register_on_pick_up(prevent_autoskip) ctf_flag.register_on_pick_up(function()
flags_hold = flags_hold + 1
end)
ctf_flag.register_on_drop(function() ctf_flag.register_on_drop(function()
can_skip = true flags_hold = flags_hold - 1
if voted_skip and flags_hold <= 0 then
minetest.after(5, function()
skip()
end)
end
end) end)
ctf_match.register_on_build_time_end(function() ctf_match.register_on_build_time_end(function()
can_skip = true can_vote_skip = true
matchskip_timer = 0 matchskip_timer = 0
-- Set to initial vote time -- Set to initial vote time
matchskip_time = tonumber(minetest.settings:get("ctf_match.auto_skip_delay")) or 50 * 60 matchskip_time = tonumber(minetest.settings:get("ctf_match.auto_skip_delay")) or 50 * 60