Merge lp:~widelands-dev/widelands/territorial_unify_notifications into lp:widelands
- territorial_unify_notifications
- Merge into trunk
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 |
Related bugs: |
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
Further details are here: https:/
bunnybot (widelandsofficial) wrote : | # |
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.
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 4525. State: errored. Details: https:/
Appveyor build 4312. State: success. Details: https:/
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 4529. State: passed. Details: https:/
Appveyor build 4316. State: success. Details: https:/
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 4595. State: errored. Details: https:/
Appveyor build 4383. State: failed. Details: https:/
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 4687. State: passed. Details: https:/
Appveyor build 4473. State: success. Details: https:/
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 4698. State: errored. Details: https:/
Appveyor build 4484. State: success. Details: https:/
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.
Toni Förster (stonerl) wrote : | # |
I'll have a look.
Toni Förster (stonerl) wrote : | # |
fixed in r8979
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 4788. State: passed. Details: https:/
Appveyor build 4569. State: success. Details: https:/
Preview Diff
1 | === modified file 'data/scripting/win_conditions/territorial_functions.lua' | |||
2 | --- data/scripting/win_conditions/territorial_functions.lua 2019-04-07 15:01:04 +0000 | |||
3 | +++ data/scripting/win_conditions/territorial_functions.lua 2019-04-24 19:01:15 +0000 | |||
4 | @@ -48,7 +48,7 @@ | |||
5 | 48 | -- We record the last winning player name here to prevent crashes with retrieving | 48 | -- We record the last winning player name here to prevent crashes with retrieving |
6 | 49 | -- the player name when the player was just defeated a few ms ago | 49 | -- the player name when the player was just defeated a few ms ago |
7 | 50 | last_winning_player_name = "", | 50 | last_winning_player_name = "", |
9 | 51 | remaining_time = 10, | 51 | remaining_time = 1201, |
10 | 52 | all_player_points = {}, | 52 | all_player_points = {}, |
11 | 53 | points = {} | 53 | points = {} |
12 | 54 | } | 54 | } |
13 | @@ -112,10 +112,15 @@ | |||
14 | 112 | -- Set the remaining time according to whether the winner is still the same | 112 | -- Set the remaining time according to whether the winner is still the same |
15 | 113 | if territory_was_kept then | 113 | if territory_was_kept then |
16 | 114 | -- Still the same winner | 114 | -- Still the same winner |
18 | 115 | territory_points.remaining_time = territory_points.remaining_time - 30 | 115 | territory_points.remaining_time = territory_points.remaining_time - 1 |
19 | 116 | elseif winning_points == -1 then | 116 | elseif winning_points == -1 then |
20 | 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. |
22 | 118 | territory_points.remaining_time = 10 | 118 | if territory_points.remaining_time == 1800 then |
23 | 119 | territory_points.remaining_time = 1201 | ||
24 | 120 | elseif territory_points.remaining_time ~= 1201 then | ||
25 | 121 | territory_points.remaining_time = 1800 | ||
26 | 122 | end | ||
27 | 123 | |||
28 | 119 | else | 124 | else |
29 | 120 | -- Winner changed | 125 | -- Winner changed |
30 | 121 | territory_points.remaining_time = 20 * 60 -- 20 minutes | 126 | territory_points.remaining_time = 20 * 60 -- 20 minutes |
31 | 122 | 127 | ||
32 | === modified file 'data/scripting/win_conditions/territorial_lord.lua' | |||
33 | --- data/scripting/win_conditions/territorial_lord.lua 2019-03-09 10:55:24 +0000 | |||
34 | +++ data/scripting/win_conditions/territorial_lord.lua 2019-04-24 19:01:15 +0000 | |||
35 | @@ -42,25 +42,29 @@ | |||
36 | 42 | -- time in secs, if == 0 -> victory | 42 | -- time in secs, if == 0 -> victory |
37 | 43 | territory_points.remaining_time = time_to_keep_territory | 43 | territory_points.remaining_time = time_to_keep_territory |
38 | 44 | 44 | ||
40 | 45 | local function _send_state() | 45 | local function _send_state(show_popup) |
41 | 46 | set_textdomain("win_conditions") | 46 | set_textdomain("win_conditions") |
42 | 47 | 47 | ||
43 | 48 | for idx, player in ipairs(plrs) do | 48 | for idx, player in ipairs(plrs) do |
44 | 49 | local msg = "" | 49 | local msg = "" |
47 | 50 | if territory_points.last_winning_team == player.team or territory_points.last_winning_player == player.number then | 50 | if (territory_points.last_winning_team >= 0 or territory_points.last_winning_player >= 0) then |
48 | 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 |
49 | 52 | msg = msg .. winning_status_header() | ||
50 | 53 | else | ||
51 | 54 | msg = msg .. losing_status_header(plrs) | ||
52 | 55 | end | ||
53 | 52 | else | 56 | else |
55 | 53 | msg = msg .. losing_status_header(plrs) .. vspace(8) | 57 | msg = p(_"Currently no faction owns more than half of the map’s area.") |
56 | 54 | end | 58 | end |
57 | 55 | msg = msg .. vspace(8) .. game_status.body .. territory_status(fields, "has") | 59 | msg = msg .. vspace(8) .. game_status.body .. territory_status(fields, "has") |
59 | 56 | player:send_message(game_status.title, msg, {popup = true}) | 60 | send_message(player, game_status.title, msg, {popup = show_popup}) |
60 | 57 | end | 61 | end |
61 | 58 | end | 62 | end |
62 | 59 | 63 | ||
63 | 60 | -- here is the main loop!!! | 64 | -- here is the main loop!!! |
67 | 61 | while true do | 65 | while count_factions(plrs) > 1 and territory_points.remaining_time > 0 do |
68 | 62 | -- Sleep 30 seconds == STATISTICS_SAMPLE_TIME | 66 | -- Sleep 1 second |
69 | 63 | sleep(30000) | 67 | sleep(1000) |
70 | 64 | 68 | ||
71 | 65 | -- A player might have been defeated since the last calculation | 69 | -- A player might have been defeated since the last calculation |
72 | 66 | check_player_defeated(plrs, lost_game.title, lost_game.body) | 70 | check_player_defeated(plrs, lost_game.title, lost_game.body) |
73 | @@ -68,16 +72,15 @@ | |||
74 | 68 | -- Check if a player or team is a candidate and update variables | 72 | -- Check if a player or team is a candidate and update variables |
75 | 69 | calculate_territory_points(fields, wl.Game().players) | 73 | calculate_territory_points(fields, wl.Game().players) |
76 | 70 | 74 | ||
77 | 71 | -- Do this stuff, if the game is over | ||
78 | 72 | if territory_points.remaining_time == 0 or count_factions(plrs) <= 1 then | ||
79 | 73 | territory_game_over(fields, wl.Game().players, wc_descname, wc_version) | ||
80 | 74 | break | ||
81 | 75 | end | ||
82 | 76 | |||
83 | 77 | -- If there is a candidate, check whether we have to send an update | 75 | -- If there is a candidate, check whether we have to send an update |
86 | 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 then | 76 | if (territory_points.remaining_time % 300 == 0 and territory_points.remaining_time ~= 0) then |
87 | 79 | _send_state() | 77 | local show_popup = false |
88 | 78 | if territory_points.remaining_time % 600 == 0 then show_popup = true end | ||
89 | 79 | _send_state(show_popup) | ||
90 | 80 | end | 80 | end |
91 | 81 | end | 81 | end |
92 | 82 | |||
93 | 83 | -- Game has ended | ||
94 | 84 | territory_game_over(fields, wl.Game().players, wc_descname, wc_version) | ||
95 | 82 | end | 85 | end |
96 | 83 | } | 86 | } |
97 | 84 | 87 | ||
98 | === modified file 'data/scripting/win_conditions/territorial_time.lua' | |||
99 | --- data/scripting/win_conditions/territorial_time.lua 2019-03-09 10:55:24 +0000 | |||
100 | +++ data/scripting/win_conditions/territorial_time.lua 2019-04-24 19:01:15 +0000 | |||
101 | @@ -36,65 +36,72 @@ | |||
102 | 36 | fields = wl.Game().map:count_conquerable_fields() | 36 | fields = wl.Game().map:count_conquerable_fields() |
103 | 37 | end, | 37 | end, |
104 | 38 | func = function() | 38 | func = function() |
105 | 39 | local game = wl.Game() | ||
106 | 39 | local plrs = wl.Game().players | 40 | local plrs = wl.Game().players |
107 | 40 | 41 | ||
108 | 41 | -- set the objective with the game type for all players | 42 | -- set the objective with the game type for all players |
109 | 42 | broadcast_objective("win_condition", wc_descname, wc_desc) | 43 | broadcast_objective("win_condition", wc_descname, wc_desc) |
110 | 43 | 44 | ||
111 | 44 | -- variables to track the maximum 4 hours of gametime | 45 | -- variables to track the maximum 4 hours of gametime |
113 | 45 | local remaining_max_time = 4 * 60 * 60 -- 4 hours | 46 | local max_time = 4 * 60 |
114 | 46 | 47 | ||
116 | 47 | local function _send_state() | 48 | local function _send_state(remaining_time, plrs, show_popup) |
117 | 48 | set_textdomain("win_conditions") | 49 | set_textdomain("win_conditions") |
118 | 49 | 50 | ||
120 | 50 | local remaining_max_minutes = remaining_max_time // 60 | 51 | local remaining_time_minutes = remaining_time // 60 |
121 | 51 | for idx, player in ipairs(plrs) do | 52 | for idx, player in ipairs(plrs) do |
122 | 52 | local msg = "" | 53 | local msg = "" |
124 | 53 | if territory_points.remaining_time < remaining_max_time and | 54 | if territory_points.remaining_time < remaining_time and |
125 | 54 | (territory_points.last_winning_team >= 0 or territory_points.last_winning_player >= 0) then | 55 | (territory_points.last_winning_team >= 0 or territory_points.last_winning_player >= 0) then |
126 | 55 | if territory_points.last_winning_team == player.team or territory_points.last_winning_player == player.number then | 56 | if territory_points.last_winning_team == player.team or territory_points.last_winning_player == player.number then |
128 | 56 | msg = msg .. winning_status_header() .. vspace(8) | 57 | msg = msg .. winning_status_header() |
129 | 57 | else | 58 | else |
131 | 58 | msg = msg .. losing_status_header(plrs) .. vspace(8) | 59 | msg = msg .. losing_status_header(plrs) |
132 | 59 | end | 60 | end |
138 | 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 |
139 | 61 | msg = msg .. p((ngettext("Otherwise the game will end in %i minute.", | 62 | territory_points.remaining_time = remaining_time |
140 | 62 | "Otherwise the game will end in %i minutes.", | 63 | msg = msg .. format_remaining_time(remaining_time_minutes) |
136 | 63 | remaining_max_minutes)) | ||
137 | 64 | :format(remaining_max_minutes)) | ||
141 | 65 | else | 64 | else |
146 | 66 | msg = msg .. p((ngettext("The game will end in %i minute.", | 65 | msg = msg .. format_remaining_time(remaining_time_minutes) |
143 | 67 | "The game will end in %i minutes.", | ||
144 | 68 | remaining_max_minutes)) | ||
145 | 69 | :format(remaining_max_minutes)) | ||
147 | 70 | end | 66 | end |
148 | 71 | msg = msg .. vspace(8) .. game_status.body .. territory_status(fields, "has") | 67 | msg = msg .. vspace(8) .. game_status.body .. territory_status(fields, "has") |
150 | 72 | player:send_message(game_status.title, msg, {popup = true}) | 68 | send_message(player, game_status.title, msg, {popup = show_popup}) |
151 | 73 | end | 69 | end |
152 | 74 | end | 70 | end |
153 | 75 | 71 | ||
154 | 72 | -- Start a new coroutine that triggers status notifications. | ||
155 | 73 | run(function() | ||
156 | 74 | local remaining_time = max_time | ||
157 | 75 | local msg = "" | ||
158 | 76 | while game.time <= ((max_time - 5) * 60 * 1000) and count_factions(plrs) > 1 and territory_points.remaining_time > 0 do | ||
159 | 77 | remaining_time, show_popup = notification_remaining_time(max_time, remaining_time) | ||
160 | 78 | if territory_points.remaining_time == 1201 then | ||
161 | 79 | msg = msg .. format_remaining_time(remaining_time) .. vspace(8) .. game_status.body .. territory_status(fields, "has") | ||
162 | 80 | broadcast(plrs, game_status.title, msg, {popup = show_popup}) | ||
163 | 81 | end | ||
164 | 82 | end | ||
165 | 83 | end) | ||
166 | 84 | |||
167 | 76 | -- here is the main loop!!! | 85 | -- here is the main loop!!! |
171 | 77 | while true do | 86 | while game.time < (max_time * 60 * 1000) and count_factions(plrs) > 1 and territory_points.remaining_time > 0 do |
172 | 78 | -- Sleep 30 seconds == STATISTICS_SAMPLE_TIME | 87 | -- Sleep 1 second |
173 | 79 | sleep(30000) | 88 | sleep(1000) |
174 | 80 | 89 | ||
175 | 81 | remaining_max_time = remaining_max_time - 30 | ||
176 | 82 | -- A player might have been defeated since the last calculation | 90 | -- A player might have been defeated since the last calculation |
177 | 83 | check_player_defeated(plrs, lost_game.title, lost_game.body) | 91 | check_player_defeated(plrs, lost_game.title, lost_game.body) |
178 | 92 | |||
179 | 84 | -- Check if a player or team is a candidate and update variables | 93 | -- Check if a player or team is a candidate and update variables |
180 | 85 | -- Returns the names and points for the teams and players without a team | 94 | -- Returns the names and points for the teams and players without a team |
193 | 86 | calculate_territory_points(fields, wl.Game().players) | 95 | calculate_territory_points(fields, plrs) |
194 | 87 | 96 | ||
195 | 88 | -- Game is over, do stuff after loop | 97 | -- check if there is a candidate and we need to send an update |
196 | 89 | if territory_points.remaining_time <= 0 or remaining_max_time <= 0 or count_factions(plrs) <= 1 then break end | 98 | if (territory_points.remaining_time % 300 == 0 and territory_points.remaining_time ~= 0) then |
197 | 90 | 99 | local remaining_time = (max_time * 60 * 1000 - game.time) // 1000 | |
198 | 91 | -- at the beginning send remaining max time message only each 30 minutes | 100 | local show_popup = false |
199 | 92 | -- if only 30 minutes or less are left, send each 5 minutes | 101 | |
200 | 93 | -- also check if there is a candidate and we need to send an update | 102 | if territory_points.remaining_time % 600 == 0 then show_popup = true end |
201 | 94 | if ((remaining_max_time < (30 * 60) and remaining_max_time % (5 * 60) == 0) | 103 | _send_state(remaining_time, plrs, show_popup) |
202 | 95 | or remaining_max_time % (30 * 60) == 0) | 104 | |
191 | 96 | or territory_points.remaining_time % 300 == 0 then | ||
192 | 97 | _send_state() | ||
203 | 98 | end | 105 | end |
204 | 99 | end | 106 | end |
205 | 100 | 107 | ||
206 | 101 | 108 | ||
207 | === modified file 'data/scripting/win_conditions/win_condition_functions.lua' | |||
208 | --- data/scripting/win_conditions/win_condition_functions.lua 2019-03-09 08:58:52 +0000 | |||
209 | +++ data/scripting/win_conditions/win_condition_functions.lua 2019-04-24 19:01:15 +0000 | |||
210 | @@ -295,13 +295,13 @@ | |||
211 | 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) |
212 | 296 | elseif m > 0 then | 296 | elseif m > 0 then |
213 | 297 | -- TRANSLATORS: Context: 'The game will end in 30 minutes.' | 297 | -- TRANSLATORS: Context: 'The game will end in 30 minutes.' |
215 | 298 | time = (ngettext("%i minute", "%i minutes", m)):format(m) | 298 | time = (ngettext("%i minute", "%i minutes", m)):bformat(m) |
216 | 299 | else | 299 | else |
217 | 300 | -- TRANSLATORS: Context: 'The game will end in 2 hours.' | 300 | -- TRANSLATORS: Context: 'The game will end in 2 hours.' |
218 | 301 | time = (ngettext("%1% hour", "%1% hours", h)):bformat(h) | 301 | time = (ngettext("%1% hour", "%1% hours", h)):bformat(h) |
219 | 302 | end | 302 | end |
220 | 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.' |
222 | 304 | return p(_"The game will end in %s."):format(time) | 304 | return p(_"The game will end in %s."):bformat(time) |
223 | 305 | end | 305 | end |
224 | 306 | 306 | ||
225 | 307 | -- RST | 307 | -- RST |
226 | @@ -312,7 +312,7 @@ | |||
227 | 312 | -- Returns the remaining time and whether the notification should popup. | 312 | -- Returns the remaining time and whether the notification should popup. |
228 | 313 | -- | 313 | -- |
229 | 314 | -- To be used when sending status messages. | 314 | -- To be used when sending status messages. |
231 | 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, |
232 | 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. |
233 | 317 | -- | 317 | -- |
234 | 318 | -- :arg max_time: The time maximum game time in minutes | 318 | -- :arg max_time: The time maximum game time in minutes |
Continuous integration builds have changed state:
Travis build 4422. State: passed. Details: https:/ /travis- ci.org/ widelands/ widelands/ builds/ 490530981. /ci.appveyor. com/project/ widelands- dev/widelands/ build/_ widelands_ dev_widelands_ territorial_ unify_notificat ions-4210.
Appveyor build 4210. State: success. Details: https:/