Improve match duration metric; move to ctf_match (#539)
This commit is contained in:
parent
ff483a2092
commit
a417e857ef
5 changed files with 27 additions and 11 deletions
|
@ -15,7 +15,12 @@ ctf.register_on_init(function()
|
|||
minetest.settings:set_bool("enable_pvp", true)
|
||||
end)
|
||||
|
||||
ctf_match.register_on_build_time_start(function()
|
||||
ctf_match.match_start_time = nil
|
||||
end)
|
||||
|
||||
ctf_match.register_on_build_time_end(function()
|
||||
ctf_match.match_start_time = os.time()
|
||||
minetest.sound_play({name="ctf_match_attack"}, { gain = 1.0 })
|
||||
end)
|
||||
|
||||
|
|
|
@ -94,3 +94,9 @@ ctf_flag.register_on_capture(function(attname, flag)
|
|||
|
||||
ctf_match.check_for_winner()
|
||||
end)
|
||||
|
||||
ctf_match.match_start_time = nil
|
||||
function ctf_match.get_match_duration()
|
||||
return ctf_match.match_start_time and
|
||||
(os.time() - ctf_match.match_start_time)
|
||||
end
|
||||
|
|
|
@ -53,7 +53,7 @@ end
|
|||
|
||||
local function summary_func(name)
|
||||
local fs = ctf_stats.get_formspec_match_summary(ctf_stats.current,
|
||||
ctf_stats.winner_team, ctf_stats.winner_player, os.time() - ctf_stats.start)
|
||||
ctf_stats.winner_team, ctf_stats.winner_player, ctf_match.get_match_duration())
|
||||
|
||||
fs = fs .. "button[6,7.5;4,1;b_prev;<< Previous match]"
|
||||
|
||||
|
|
|
@ -58,10 +58,13 @@ function ctf_stats.get_formspec_match_summary(stats, winner_team, winner_player,
|
|||
blue.score = blue.score + pstat.score
|
||||
end
|
||||
|
||||
local match_length = string.format("%02d:%02d:%02d",
|
||||
local match_length = "-"
|
||||
if time then
|
||||
match_length = string.format("%02d:%02d:%02d",
|
||||
math.floor(time / 3600), -- hours
|
||||
math.floor((time % 3600) / 60), -- minutes
|
||||
math.floor(time % 60)) -- seconds
|
||||
end
|
||||
|
||||
local ret = ctf_stats.get_formspec("Match Summary", players, 1)
|
||||
|
||||
|
@ -242,7 +245,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
fs = fs .. "button[6,7.5;4,1;b_curr;Current match >>]"
|
||||
elseif fields.b_curr then
|
||||
fs = ctf_stats.get_formspec_match_summary(ctf_stats.current,
|
||||
ctf_stats.winner_team, ctf_stats.winner_player, os.time() - ctf_stats.start)
|
||||
ctf_stats.winner_team, ctf_stats.winner_player, ctf_match.get_match_duration())
|
||||
fs = fs .. "button[6,7.5;4,1;b_prev;<< Previous match]"
|
||||
else
|
||||
return
|
||||
|
|
|
@ -79,8 +79,6 @@ function ctf_stats.load()
|
|||
blue = {}
|
||||
}
|
||||
|
||||
ctf_stats.start = os.time()
|
||||
|
||||
-- Strip players which have no score
|
||||
for name, player_stats in pairs(ctf_stats.players) do
|
||||
if not player_stats.score or player_stats.score <= 0 then
|
||||
|
@ -241,7 +239,7 @@ ctf_match.register_on_winner(function(winner)
|
|||
|
||||
-- Show match summary
|
||||
local fs = ctf_stats.get_formspec_match_summary(ctf_stats.current,
|
||||
ctf_stats.winner_team, ctf_stats.winner_player, os.time() - ctf_stats.start)
|
||||
ctf_stats.winner_team, ctf_stats.winner_player, ctf_match.get_match_duration())
|
||||
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
minetest.show_formspec(player:get_player_name(), "ctf_stats:eom", fs)
|
||||
|
@ -258,7 +256,7 @@ ctf_match.register_on_skip_match(function()
|
|||
|
||||
-- Show match summary
|
||||
local fs = ctf_stats.get_formspec_match_summary(ctf_stats.current,
|
||||
ctf_stats.winner_team, ctf_stats.winner_player, os.time() - ctf_stats.start)
|
||||
ctf_stats.winner_team, ctf_stats.winner_player, ctf_match.get_match_duration())
|
||||
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
minetest.show_formspec(player:get_player_name(), "ctf_stats:eom", fs)
|
||||
|
@ -276,10 +274,14 @@ ctf_match.register_on_new_match(function()
|
|||
}
|
||||
ctf_stats.winner_team = "-"
|
||||
ctf_stats.winner_player = "-"
|
||||
ctf_stats.start = os.time()
|
||||
_needs_save = true
|
||||
end)
|
||||
|
||||
ctf_stats.start = nil
|
||||
ctf_match.register_on_build_time_end(function()
|
||||
ctf_stats.start = os.time()
|
||||
end)
|
||||
|
||||
-- ctf_map can't be added as a dependency, as that'd result
|
||||
-- in cyclic dependencies between ctf_map and ctf_stats
|
||||
minetest.after(0, function()
|
||||
|
|
Loading…
Reference in a new issue