Toni Förster has proposed merging lp:~widelands-dev/widelands/territorial_unify_notifications into lp:widelands with lp:~widelands-dev/widelands/collectors_notification as a prerequisite.
Commit message: - Notifications for Territorial are unified. - Notifications are properly formatted (hour and minute) - remaining time notifications and winning/losing status notifications are not mixed up any more - new string added to territorial_lord - string removed from territorial_time Requested reviews: Widelands Developers (widelands-dev) For more details, see: https://code.launchpad.net/~widelands-dev/widelands/territorial_unify_notifications/+merge/362502 Further details are here: https://wl.widelands.org/forum/post/26905/ -- Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/territorial_unify_notifications into lp:widelands.
=== modified file 'data/scripting/win_conditions/collectors.lua' --- data/scripting/win_conditions/collectors.lua 2019-01-30 23:12:08 +0000 +++ data/scripting/win_conditions/collectors.lua 2019-01-30 23:12:09 +0000 @@ -170,7 +170,7 @@ .. h2(ngettext("Team Total: %i point", "Team Total: %i points", points)):format(points) msg = msg .. vspace(8) .. message end - + broadcast(plrs, game_status.title, msg, {popup = show_popup}) end === modified file 'data/scripting/win_conditions/territorial_functions.lua' --- data/scripting/win_conditions/territorial_functions.lua 2018-12-03 20:30:01 +0000 +++ data/scripting/win_conditions/territorial_functions.lua 2019-01-30 23:12:09 +0000 @@ -103,7 +103,7 @@ -- We record the last winning player name here to prevent crashes with retrieving -- the player name when the player was just defeated a few ms ago last_winning_player_name = "", - remaining_time = 10, + remaining_time = 1201, all_player_points = {}, points = {} } @@ -167,10 +167,15 @@ -- Set the remaining time according to whether the winner is still the same if territory_was_kept then -- Still the same winner - territory_points.remaining_time = territory_points.remaining_time - 30 + territory_points.remaining_time = territory_points.remaining_time - 1 elseif winning_points == -1 then -- No winner. This value is used to calculate whether to send a report to players. - territory_points.remaining_time = 10 + if territory_points.remaining_time == 1800 then + territory_points.remaining_time = 1201 + elseif territory_points.remaining_time ~= 1201 then + territory_points.remaining_time = 1800 + end + else -- Winner changed territory_points.remaining_time = 20 * 60 -- 20 minutes === modified file 'data/scripting/win_conditions/territorial_lord.lua' --- data/scripting/win_conditions/territorial_lord.lua 2018-12-03 20:30:01 +0000 +++ data/scripting/win_conditions/territorial_lord.lua 2019-01-30 23:12:09 +0000 @@ -39,25 +39,30 @@ -- Get all valueable fields of the map local fields = get_buildable_fields() - local function _send_state() + local function _send_state(show_popup) set_textdomain("win_conditions") for idx, player in ipairs(plrs) do local msg = "" - if territory_points.last_winning_team == player.team or territory_points.last_winning_player == player.number then - msg = msg .. winning_status_header() .. vspace(8) + if (territory_points.last_winning_team >= 0 or territory_points.last_winning_player >= 0) then + if territory_points.last_winning_team == player.team or territory_points.last_winning_player == player.number then + msg = msg .. winning_status_header() + else + msg = msg .. losing_status_header(plrs) + end else - msg = msg .. losing_status_header(plrs) .. vspace(8) - end - msg = msg .. vspace(8) .. game_status.body .. territory_status(fields, "has") - send_message(player, game_status.title, msg, {popup = true}) + msg = p(_"Currently no faction owns more than half of the map’s area.") + end + msg = msg .. vspace(8) .. game_status.body .. territory_status(fields, "has") + player:send_message(game_status.title, msg, {popup = show_popup}) + end end end -- here is the main loop!!! - while true do - -- Sleep 30 seconds == STATISTICS_SAMPLE_TIME - sleep(30000) + while count_factions(plrs) > 1 or territory_points.remaining_time > 0 do + -- Sleep 1 second + sleep(1000) -- A player might have been defeated since the last calculation check_player_defeated(plrs, lost_game.title, lost_game.body) @@ -65,16 +70,15 @@ -- Check if a player or team is a candidate and update variables calculate_territory_points(fields, wl.Game().players) - -- Do this stuff, if the game is over - if territory_points.remaining_time == 0 or count_factions(plrs) <= 1 then - territory_game_over(fields, wl.Game().players, wc_descname, wc_version) - break - end - -- If there is a candidate, check whether we have to send an update - if (territory_points.last_winning_team >= 0 or territory_points.last_winning_player >= 0) and territory_points.remaining_time >= 0 and territory_points.remaining_time % 300 == 0 then - _send_state() + if (territory_points.remaining_time % 300 == 0 and territory_points.remaining_time ~= 0) then + local show_popup = false + if territory_points.remaining_time % 600 == 0 then show_popup = true end + _send_state(show_popup) end end + + -- Game has ended + territory_game_over(fields, wl.Game().players, wc_descname, wc_version) end } === modified file 'data/scripting/win_conditions/territorial_time.lua' --- data/scripting/win_conditions/territorial_time.lua 2018-12-03 20:30:01 +0000 +++ data/scripting/win_conditions/territorial_time.lua 2019-01-30 23:12:09 +0000 @@ -27,11 +27,11 @@ "after 4 hours, whichever comes first." ) - return { name = wc_name, description = wc_desc, func = function() + local game = wl.Game() local plrs = wl.Game().players -- set the objective with the game type for all players @@ -41,59 +41,65 @@ local fields = get_buildable_fields() -- variables to track the maximum 4 hours of gametime - local remaining_max_time = 4 * 60 * 60 -- 4 hours + local max_time = 4 * 60 - local function _send_state() + local function _send_state(remaining_time, plrs, show_popup) set_textdomain("win_conditions") - local remaining_max_minutes = remaining_max_time // 60 + local remaining_time_minutes = remaining_time // 60 for idx, player in ipairs(plrs) do local msg = "" - if territory_points.remaining_time < remaining_max_time and + if territory_points.remaining_time < remaining_time and (territory_points.last_winning_team >= 0 or territory_points.last_winning_player >= 0) then if territory_points.last_winning_team == player.team or territory_points.last_winning_player == player.number then - msg = msg .. winning_status_header() .. vspace(8) + msg = msg .. winning_status_header() else - msg = msg .. losing_status_header(plrs) .. vspace(8) + msg = msg .. losing_status_header(plrs) end - -- TRANSLATORS: Refers to "You own more than half of the map’s area. Keep it for x more minute(s) to win the game." - msg = msg .. p((ngettext("Otherwise the game will end in %i minute.", - "Otherwise the game will end in %i minutes.", - remaining_max_minutes)) - :format(remaining_max_minutes)) + elseif remaining_time <= 1200 then + territory_points.remaining_time = remaining_time + msg = msg .. format_remaining_time(remaining_time_minutes) else - msg = msg .. p((ngettext("The game will end in %i minute.", - "The game will end in %i minutes.", - remaining_max_minutes)) - :format(remaining_max_minutes)) + msg = msg .. format_remaining_time(remaining_time_minutes) end msg = msg .. vspace(8) .. game_status.body .. territory_status(fields, "has") - send_message(player, game_status.title, msg, {popup = true}) + player:send_message(game_status.title, msg, {popup = show_popup}) end end + -- Start a new coroutine that triggers status notifications. + run(function() + local remaining_time = max_time + local msg = "" + while game.time <= ((max_time - 5) * 60 * 1000) and count_factions(plrs) > 1 and territory_points.remaining_time > 0 do + remaining_time, show_popup = notification_remaining_time(max_time, remaining_time) + if territory_points.remaining_time == 1201 then + msg = msg .. format_remaining_time(remaining_time) .. vspace(8) .. game_status.body .. territory_status(fields, "has") + broadcast(plrs, game_status.title, msg, {popup = show_popup}) + end + end + end) + -- here is the main loop!!! - while true do - -- Sleep 30 seconds == STATISTICS_SAMPLE_TIME - sleep(30000) + while game.time < (max_time * 60 * 1000) and count_factions(plrs) > 1 and territory_points.remaining_time > 0 do + -- Sleep 1 seconds + sleep(1000) - remaining_max_time = remaining_max_time - 30 -- A player might have been defeated since the last calculation check_player_defeated(plrs, lost_game.title, lost_game.body) + -- Check if a player or team is a candidate and update variables -- Returns the names and points for the teams and players without a team - calculate_territory_points(fields, wl.Game().players) - - -- Game is over, do stuff after loop - if territory_points.remaining_time <= 0 or remaining_max_time <= 0 or count_factions(plrs) <= 1 then break end - - -- at the beginning send remaining max time message only each 30 minutes - -- if only 30 minutes or less are left, send each 5 minutes - -- also check if there is a candidate and we need to send an update - if ((remaining_max_time < (30 * 60) and remaining_max_time % (5 * 60) == 0) - or remaining_max_time % (30 * 60) == 0) - or territory_points.remaining_time % 300 == 0 then - _send_state() + calculate_territory_points(fields, plrs) + + -- check if there is a candidate and we need to send an update + if (territory_points.remaining_time % 300 == 0 and territory_points.remaining_time ~= 0) then + local remaining_time = (max_time * 60 * 1000 - game.time) // 1000 + local show_popup = false + + if territory_points.remaining_time % 600 == 0 then show_popup = true end + _send_state(remaining_time, plrs, show_popup) + end end === modified file 'data/scripting/win_conditions/win_condition_functions.lua' --- data/scripting/win_conditions/win_condition_functions.lua 2019-01-30 23:12:08 +0000 +++ data/scripting/win_conditions/win_condition_functions.lua 2019-01-30 23:12:09 +0000 @@ -108,7 +108,7 @@ function broadcast(plrs, header, msg, goptions) local options = goptions or {} for idx, p in ipairs(plrs) do - send_message(p, header, msg, options) + p:send_message(header, msg, options) end end
_______________________________________________ Mailing list: https://launchpad.net/~widelands-dev Post to : widelands-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~widelands-dev More help : https://help.launchpad.net/ListHelp