Merge lp:~widelands-dev/widelands/territorial_unify_notifications into lp:widelands

Proposed by Toni Förster
Status: Merged
Merged at revision: 9078
Proposed branch: lp:~widelands-dev/widelands/territorial_unify_notifications
Merge into: lp:widelands
Prerequisite: lp:~widelands-dev/widelands/collectors_notification
Diff against target: 234 lines (+69/-54)
4 files modified
data/scripting/win_conditions/territorial_functions.lua (+8/-3)
data/scripting/win_conditions/territorial_lord.lua (+19/-16)
data/scripting/win_conditions/territorial_time.lua (+39/-32)
data/scripting/win_conditions/win_condition_functions.lua (+3/-3)
To merge this branch: bzr merge lp:~widelands-dev/widelands/territorial_unify_notifications
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+362502@code.launchpad.net

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

Description of the change

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4422. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/490530981.
Appveyor build 4210. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_territorial_unify_notifications-4210.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I think this is a great change. 2 nits.

Let's postpone this to Build21 though to make sure we don't get accidental nil values again.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4525. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/498321069.
Appveyor build 4312. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_territorial_unify_notifications-4312.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4529. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/498743350.
Appveyor build 4316. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_territorial_unify_notifications-4316.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4595. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/505417581.
Appveyor build 4383. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_territorial_unify_notifications-4383.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4687. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/516995509.
Appveyor build 4473. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_territorial_unify_notifications-4473.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4698. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/517401116.
Appveyor build 4484. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_territorial_unify_notifications-4484.

Revision history for this message
GunChleoc (gunchleoc) wrote :

When the 20 minutes timer reaches 0, the game is not lost or won.

Note that I have pushed to this branch, so don't forget to pull, because that is so annoying when it happens.

review: Needs Fixing
Revision history for this message
Toni Förster (stonerl) wrote :

I'll have a look.

Revision history for this message
Toni Förster (stonerl) wrote :

fixed in r8979

Revision history for this message
GunChleoc (gunchleoc) wrote :

@bunnybot merge

review: Approve
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4788. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/524155429.
Appveyor build 4569. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_territorial_unify_notifications-4569.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/scripting/win_conditions/territorial_functions.lua'
--- data/scripting/win_conditions/territorial_functions.lua 2019-04-07 15:01:04 +0000
+++ data/scripting/win_conditions/territorial_functions.lua 2019-04-24 19:01:15 +0000
@@ -48,7 +48,7 @@
48 -- We record the last winning player name here to prevent crashes with retrieving48 -- We record the last winning player name here to prevent crashes with retrieving
49 -- the player name when the player was just defeated a few ms ago49 -- the player name when the player was just defeated a few ms ago
50 last_winning_player_name = "",50 last_winning_player_name = "",
51 remaining_time = 10,51 remaining_time = 1201,
52 all_player_points = {},52 all_player_points = {},
53 points = {}53 points = {}
54}54}
@@ -112,10 +112,15 @@
112 -- Set the remaining time according to whether the winner is still the same112 -- Set the remaining time according to whether the winner is still the same
113 if territory_was_kept then113 if territory_was_kept then
114 -- Still the same winner114 -- Still the same winner
115 territory_points.remaining_time = territory_points.remaining_time - 30115 territory_points.remaining_time = territory_points.remaining_time - 1
116 elseif winning_points == -1 then116 elseif winning_points == -1 then
117 -- No winner. This value is used to calculate whether to send a report to players.117 -- No winner. This value is used to calculate whether to send a report to players.
118 territory_points.remaining_time = 10118 if territory_points.remaining_time == 1800 then
119 territory_points.remaining_time = 1201
120 elseif territory_points.remaining_time ~= 1201 then
121 territory_points.remaining_time = 1800
122 end
123
119 else124 else
120 -- Winner changed125 -- Winner changed
121 territory_points.remaining_time = 20 * 60 -- 20 minutes126 territory_points.remaining_time = 20 * 60 -- 20 minutes
122127
=== modified file 'data/scripting/win_conditions/territorial_lord.lua'
--- data/scripting/win_conditions/territorial_lord.lua 2019-03-09 10:55:24 +0000
+++ data/scripting/win_conditions/territorial_lord.lua 2019-04-24 19:01:15 +0000
@@ -42,25 +42,29 @@
42 -- time in secs, if == 0 -> victory42 -- time in secs, if == 0 -> victory
43 territory_points.remaining_time = time_to_keep_territory43 territory_points.remaining_time = time_to_keep_territory
4444
45 local function _send_state()45 local function _send_state(show_popup)
46 set_textdomain("win_conditions")46 set_textdomain("win_conditions")
4747
48 for idx, player in ipairs(plrs) do48 for idx, player in ipairs(plrs) do
49 local msg = ""49 local msg = ""
50 if territory_points.last_winning_team == player.team or territory_points.last_winning_player == player.number then50 if (territory_points.last_winning_team >= 0 or territory_points.last_winning_player >= 0) then
51 msg = msg .. winning_status_header() .. vspace(8)51 if territory_points.last_winning_team == player.team or territory_points.last_winning_player == player.number then
52 msg = msg .. winning_status_header()
53 else
54 msg = msg .. losing_status_header(plrs)
55 end
52 else56 else
53 msg = msg .. losing_status_header(plrs) .. vspace(8)57 msg = p(_"Currently no faction owns more than half of the map’s area.")
54 end58 end
55 msg = msg .. vspace(8) .. game_status.body .. territory_status(fields, "has")59 msg = msg .. vspace(8) .. game_status.body .. territory_status(fields, "has")
56 player:send_message(game_status.title, msg, {popup = true})60 send_message(player, game_status.title, msg, {popup = show_popup})
57 end61 end
58 end62 end
5963
60 -- here is the main loop!!!64 -- here is the main loop!!!
61 while true do65 while count_factions(plrs) > 1 and territory_points.remaining_time > 0 do
62 -- Sleep 30 seconds == STATISTICS_SAMPLE_TIME66 -- Sleep 1 second
63 sleep(30000)67 sleep(1000)
6468
65 -- A player might have been defeated since the last calculation69 -- A player might have been defeated since the last calculation
66 check_player_defeated(plrs, lost_game.title, lost_game.body)70 check_player_defeated(plrs, lost_game.title, lost_game.body)
@@ -68,16 +72,15 @@
68 -- Check if a player or team is a candidate and update variables72 -- Check if a player or team is a candidate and update variables
69 calculate_territory_points(fields, wl.Game().players)73 calculate_territory_points(fields, wl.Game().players)
7074
71 -- Do this stuff, if the game is over
72 if territory_points.remaining_time == 0 or count_factions(plrs) <= 1 then
73 territory_game_over(fields, wl.Game().players, wc_descname, wc_version)
74 break
75 end
76
77 -- If there is a candidate, check whether we have to send an update75 -- If there is a candidate, check whether we have to send an update
78 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 then76 if (territory_points.remaining_time % 300 == 0 and territory_points.remaining_time ~= 0) then
79 _send_state()77 local show_popup = false
78 if territory_points.remaining_time % 600 == 0 then show_popup = true end
79 _send_state(show_popup)
80 end80 end
81 end81 end
82
83 -- Game has ended
84 territory_game_over(fields, wl.Game().players, wc_descname, wc_version)
82 end85 end
83}86}
8487
=== modified file 'data/scripting/win_conditions/territorial_time.lua'
--- data/scripting/win_conditions/territorial_time.lua 2019-03-09 10:55:24 +0000
+++ data/scripting/win_conditions/territorial_time.lua 2019-04-24 19:01:15 +0000
@@ -36,65 +36,72 @@
36 fields = wl.Game().map:count_conquerable_fields()36 fields = wl.Game().map:count_conquerable_fields()
37 end,37 end,
38 func = function()38 func = function()
39 local game = wl.Game()
39 local plrs = wl.Game().players40 local plrs = wl.Game().players
4041
41 -- set the objective with the game type for all players42 -- set the objective with the game type for all players
42 broadcast_objective("win_condition", wc_descname, wc_desc)43 broadcast_objective("win_condition", wc_descname, wc_desc)
4344
44 -- variables to track the maximum 4 hours of gametime45 -- variables to track the maximum 4 hours of gametime
45 local remaining_max_time = 4 * 60 * 60 -- 4 hours46 local max_time = 4 * 60
4647
47 local function _send_state()48 local function _send_state(remaining_time, plrs, show_popup)
48 set_textdomain("win_conditions")49 set_textdomain("win_conditions")
4950
50 local remaining_max_minutes = remaining_max_time // 6051 local remaining_time_minutes = remaining_time // 60
51 for idx, player in ipairs(plrs) do52 for idx, player in ipairs(plrs) do
52 local msg = ""53 local msg = ""
53 if territory_points.remaining_time < remaining_max_time and54 if territory_points.remaining_time < remaining_time and
54 (territory_points.last_winning_team >= 0 or territory_points.last_winning_player >= 0) then55 (territory_points.last_winning_team >= 0 or territory_points.last_winning_player >= 0) then
55 if territory_points.last_winning_team == player.team or territory_points.last_winning_player == player.number then56 if territory_points.last_winning_team == player.team or territory_points.last_winning_player == player.number then
56 msg = msg .. winning_status_header() .. vspace(8)57 msg = msg .. winning_status_header()
57 else58 else
58 msg = msg .. losing_status_header(plrs) .. vspace(8)59 msg = msg .. losing_status_header(plrs)
59 end60 end
60 -- TRANSLATORS: Refers to "You own more than half of the map’s area. Keep it for x more minute(s) to win the game."61 elseif remaining_time <= 1200 then
61 msg = msg .. p((ngettext("Otherwise the game will end in %i minute.",62 territory_points.remaining_time = remaining_time
62 "Otherwise the game will end in %i minutes.",63 msg = msg .. format_remaining_time(remaining_time_minutes)
63 remaining_max_minutes))
64 :format(remaining_max_minutes))
65 else64 else
66 msg = msg .. p((ngettext("The game will end in %i minute.",65 msg = msg .. format_remaining_time(remaining_time_minutes)
67 "The game will end in %i minutes.",
68 remaining_max_minutes))
69 :format(remaining_max_minutes))
70 end66 end
71 msg = msg .. vspace(8) .. game_status.body .. territory_status(fields, "has")67 msg = msg .. vspace(8) .. game_status.body .. territory_status(fields, "has")
72 player:send_message(game_status.title, msg, {popup = true})68 send_message(player, game_status.title, msg, {popup = show_popup})
73 end69 end
74 end70 end
7571
72 -- Start a new coroutine that triggers status notifications.
73 run(function()
74 local remaining_time = max_time
75 local msg = ""
76 while game.time <= ((max_time - 5) * 60 * 1000) and count_factions(plrs) > 1 and territory_points.remaining_time > 0 do
77 remaining_time, show_popup = notification_remaining_time(max_time, remaining_time)
78 if territory_points.remaining_time == 1201 then
79 msg = msg .. format_remaining_time(remaining_time) .. vspace(8) .. game_status.body .. territory_status(fields, "has")
80 broadcast(plrs, game_status.title, msg, {popup = show_popup})
81 end
82 end
83 end)
84
76 -- here is the main loop!!!85 -- here is the main loop!!!
77 while true do86 while game.time < (max_time * 60 * 1000) and count_factions(plrs) > 1 and territory_points.remaining_time > 0 do
78 -- Sleep 30 seconds == STATISTICS_SAMPLE_TIME87 -- Sleep 1 second
79 sleep(30000)88 sleep(1000)
8089
81 remaining_max_time = remaining_max_time - 30
82 -- A player might have been defeated since the last calculation90 -- A player might have been defeated since the last calculation
83 check_player_defeated(plrs, lost_game.title, lost_game.body)91 check_player_defeated(plrs, lost_game.title, lost_game.body)
92
84 -- Check if a player or team is a candidate and update variables93 -- Check if a player or team is a candidate and update variables
85 -- Returns the names and points for the teams and players without a team94 -- Returns the names and points for the teams and players without a team
86 calculate_territory_points(fields, wl.Game().players)95 calculate_territory_points(fields, plrs)
8796
88 -- Game is over, do stuff after loop97 -- check if there is a candidate and we need to send an update
89 if territory_points.remaining_time <= 0 or remaining_max_time <= 0 or count_factions(plrs) <= 1 then break end98 if (territory_points.remaining_time % 300 == 0 and territory_points.remaining_time ~= 0) then
9099 local remaining_time = (max_time * 60 * 1000 - game.time) // 1000
91 -- at the beginning send remaining max time message only each 30 minutes100 local show_popup = false
92 -- if only 30 minutes or less are left, send each 5 minutes101
93 -- also check if there is a candidate and we need to send an update102 if territory_points.remaining_time % 600 == 0 then show_popup = true end
94 if ((remaining_max_time < (30 * 60) and remaining_max_time % (5 * 60) == 0)103 _send_state(remaining_time, plrs, show_popup)
95 or remaining_max_time % (30 * 60) == 0)104
96 or territory_points.remaining_time % 300 == 0 then
97 _send_state()
98 end105 end
99 end106 end
100107
101108
=== modified file 'data/scripting/win_conditions/win_condition_functions.lua'
--- data/scripting/win_conditions/win_condition_functions.lua 2019-03-09 08:58:52 +0000
+++ data/scripting/win_conditions/win_condition_functions.lua 2019-04-24 19:01:15 +0000
@@ -295,13 +295,13 @@
295 time = (ngettext("%1% hour and %2%", "%1% hours and %2%", h, m)):bformat(h, time)295 time = (ngettext("%1% hour and %2%", "%1% hours and %2%", h, m)):bformat(h, time)
296 elseif m > 0 then296 elseif m > 0 then
297 -- TRANSLATORS: Context: 'The game will end in 30 minutes.'297 -- TRANSLATORS: Context: 'The game will end in 30 minutes.'
298 time = (ngettext("%i minute", "%i minutes", m)):format(m)298 time = (ngettext("%i minute", "%i minutes", m)):bformat(m)
299 else299 else
300 -- TRANSLATORS: Context: 'The game will end in 2 hours.'300 -- TRANSLATORS: Context: 'The game will end in 2 hours.'
301 time = (ngettext("%1% hour", "%1% hours", h)):bformat(h)301 time = (ngettext("%1% hour", "%1% hours", h)):bformat(h)
302 end302 end
303 -- TRANSLATORS: Context: 'The game will end in (2 hours and) 30 minutes.'303 -- TRANSLATORS: Context: 'The game will end in (2 hours and) 30 minutes.'
304 return p(_"The game will end in %s."):format(time)304 return p(_"The game will end in %s."):bformat(time)
305end305end
306306
307-- RST307-- RST
@@ -312,7 +312,7 @@
312-- Returns the remaining time and whether the notification should popup.312-- Returns the remaining time and whether the notification should popup.
313--313--
314-- To be used when sending status messages.314-- To be used when sending status messages.
315-- Status messages are to be send every 30 minutes and every 5 during the last 30 minutes,315-- Status messages are to be sent every 30 minutes and every 5 during the last 30 minutes,
316-- the message window pops up ever hour, 30, 20 & 10 minutes before the game ends.316-- the message window pops up ever hour, 30, 20 & 10 minutes before the game ends.
317--317--
318-- :arg max_time: The time maximum game time in minutes318-- :arg max_time: The time maximum game time in minutes

Subscribers

People subscribed via source and target branches

to status/vote changes: