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.
8962. By Toni Förster

merged trunk

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.

8963. By Toni Förster

merge trunk

8964. By Toni Förster

- addressed GunChleoc's nits
- split remaining time string
- removed erroneous end

8965. By Toni Förster

use send_message() from ui.lua

8966. By Toni Förster

merged trunk

8967. By Toni Förster

merged trunk

8968. By Toni Förster

merged trunk

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.

8969. By Toni Förster

merged trunk

8970. By Toni Förster

merge trunk

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.

8971. By Toni Förster

merged trunk

8972. By Toni Förster

merged trunk

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.

8973. By Toni Förster

merged trunk

8974. By Toni Förster

merged trunk

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.

8975. By Toni Förster

merged trunk

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.

8976. By Toni Förster

merged trunk

8977. By GunChleoc

Merged trunk.

8978. By GunChleoc

Prevent translations from going fuzzy.

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.

8979. By Toni Förster

OR ain't AND

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
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 -- We record the last winning player name here to prevent crashes with retrieving
6 -- the player name when the player was just defeated a few ms ago
7 last_winning_player_name = "",
8- remaining_time = 10,
9+ remaining_time = 1201,
10 all_player_points = {},
11 points = {}
12 }
13@@ -112,10 +112,15 @@
14 -- Set the remaining time according to whether the winner is still the same
15 if territory_was_kept then
16 -- Still the same winner
17- territory_points.remaining_time = territory_points.remaining_time - 30
18+ territory_points.remaining_time = territory_points.remaining_time - 1
19 elseif winning_points == -1 then
20 -- No winner. This value is used to calculate whether to send a report to players.
21- territory_points.remaining_time = 10
22+ if territory_points.remaining_time == 1800 then
23+ territory_points.remaining_time = 1201
24+ elseif territory_points.remaining_time ~= 1201 then
25+ territory_points.remaining_time = 1800
26+ end
27+
28 else
29 -- Winner changed
30 territory_points.remaining_time = 20 * 60 -- 20 minutes
31
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 -- time in secs, if == 0 -> victory
37 territory_points.remaining_time = time_to_keep_territory
38
39- local function _send_state()
40+ local function _send_state(show_popup)
41 set_textdomain("win_conditions")
42
43 for idx, player in ipairs(plrs) do
44 local msg = ""
45- if territory_points.last_winning_team == player.team or territory_points.last_winning_player == player.number then
46- msg = msg .. winning_status_header() .. vspace(8)
47+ if (territory_points.last_winning_team >= 0 or territory_points.last_winning_player >= 0) then
48+ if territory_points.last_winning_team == player.team or territory_points.last_winning_player == player.number then
49+ msg = msg .. winning_status_header()
50+ else
51+ msg = msg .. losing_status_header(plrs)
52+ end
53 else
54- msg = msg .. losing_status_header(plrs) .. vspace(8)
55+ msg = p(_"Currently no faction owns more than half of the map’s area.")
56 end
57 msg = msg .. vspace(8) .. game_status.body .. territory_status(fields, "has")
58- player:send_message(game_status.title, msg, {popup = true})
59+ send_message(player, game_status.title, msg, {popup = show_popup})
60 end
61 end
62
63 -- here is the main loop!!!
64- while true do
65- -- Sleep 30 seconds == STATISTICS_SAMPLE_TIME
66- sleep(30000)
67+ while count_factions(plrs) > 1 and territory_points.remaining_time > 0 do
68+ -- Sleep 1 second
69+ sleep(1000)
70
71 -- A player might have been defeated since the last calculation
72 check_player_defeated(plrs, lost_game.title, lost_game.body)
73@@ -68,16 +72,15 @@
74 -- Check if a player or team is a candidate and update variables
75 calculate_territory_points(fields, wl.Game().players)
76
77- -- Do this stuff, if the game is over
78- if territory_points.remaining_time == 0 or count_factions(plrs) <= 1 then
79- territory_game_over(fields, wl.Game().players, wc_descname, wc_version)
80- break
81- end
82-
83 -- If there is a candidate, check whether we have to send an update
84- 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
85- _send_state()
86+ if (territory_points.remaining_time % 300 == 0 and territory_points.remaining_time ~= 0) then
87+ local show_popup = false
88+ if territory_points.remaining_time % 600 == 0 then show_popup = true end
89+ _send_state(show_popup)
90 end
91 end
92+
93+ -- Game has ended
94+ territory_game_over(fields, wl.Game().players, wc_descname, wc_version)
95 end
96 }
97
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 fields = wl.Game().map:count_conquerable_fields()
103 end,
104 func = function()
105+ local game = wl.Game()
106 local plrs = wl.Game().players
107
108 -- set the objective with the game type for all players
109 broadcast_objective("win_condition", wc_descname, wc_desc)
110
111 -- variables to track the maximum 4 hours of gametime
112- local remaining_max_time = 4 * 60 * 60 -- 4 hours
113+ local max_time = 4 * 60
114
115- local function _send_state()
116+ local function _send_state(remaining_time, plrs, show_popup)
117 set_textdomain("win_conditions")
118
119- local remaining_max_minutes = remaining_max_time // 60
120+ local remaining_time_minutes = remaining_time // 60
121 for idx, player in ipairs(plrs) do
122 local msg = ""
123- if territory_points.remaining_time < remaining_max_time and
124+ if territory_points.remaining_time < remaining_time and
125 (territory_points.last_winning_team >= 0 or territory_points.last_winning_player >= 0) then
126 if territory_points.last_winning_team == player.team or territory_points.last_winning_player == player.number then
127- msg = msg .. winning_status_header() .. vspace(8)
128+ msg = msg .. winning_status_header()
129 else
130- msg = msg .. losing_status_header(plrs) .. vspace(8)
131+ msg = msg .. losing_status_header(plrs)
132 end
133- -- TRANSLATORS: Refers to "You own more than half of the map’s area. Keep it for x more minute(s) to win the game."
134- msg = msg .. p((ngettext("Otherwise the game will end in %i minute.",
135- "Otherwise the game will end in %i minutes.",
136- remaining_max_minutes))
137- :format(remaining_max_minutes))
138+ elseif remaining_time <= 1200 then
139+ territory_points.remaining_time = remaining_time
140+ msg = msg .. format_remaining_time(remaining_time_minutes)
141 else
142- msg = msg .. p((ngettext("The game will end in %i minute.",
143- "The game will end in %i minutes.",
144- remaining_max_minutes))
145- :format(remaining_max_minutes))
146+ msg = msg .. format_remaining_time(remaining_time_minutes)
147 end
148 msg = msg .. vspace(8) .. game_status.body .. territory_status(fields, "has")
149- player:send_message(game_status.title, msg, {popup = true})
150+ send_message(player, game_status.title, msg, {popup = show_popup})
151 end
152 end
153
154+ -- Start a new coroutine that triggers status notifications.
155+ run(function()
156+ local remaining_time = max_time
157+ local msg = ""
158+ while game.time <= ((max_time - 5) * 60 * 1000) and count_factions(plrs) > 1 and territory_points.remaining_time > 0 do
159+ remaining_time, show_popup = notification_remaining_time(max_time, remaining_time)
160+ if territory_points.remaining_time == 1201 then
161+ msg = msg .. format_remaining_time(remaining_time) .. vspace(8) .. game_status.body .. territory_status(fields, "has")
162+ broadcast(plrs, game_status.title, msg, {popup = show_popup})
163+ end
164+ end
165+ end)
166+
167 -- here is the main loop!!!
168- while true do
169- -- Sleep 30 seconds == STATISTICS_SAMPLE_TIME
170- sleep(30000)
171+ while game.time < (max_time * 60 * 1000) and count_factions(plrs) > 1 and territory_points.remaining_time > 0 do
172+ -- Sleep 1 second
173+ sleep(1000)
174
175- remaining_max_time = remaining_max_time - 30
176 -- A player might have been defeated since the last calculation
177 check_player_defeated(plrs, lost_game.title, lost_game.body)
178+
179 -- Check if a player or team is a candidate and update variables
180 -- Returns the names and points for the teams and players without a team
181- calculate_territory_points(fields, wl.Game().players)
182-
183- -- Game is over, do stuff after loop
184- if territory_points.remaining_time <= 0 or remaining_max_time <= 0 or count_factions(plrs) <= 1 then break end
185-
186- -- at the beginning send remaining max time message only each 30 minutes
187- -- if only 30 minutes or less are left, send each 5 minutes
188- -- also check if there is a candidate and we need to send an update
189- if ((remaining_max_time < (30 * 60) and remaining_max_time % (5 * 60) == 0)
190- or remaining_max_time % (30 * 60) == 0)
191- or territory_points.remaining_time % 300 == 0 then
192- _send_state()
193+ calculate_territory_points(fields, plrs)
194+
195+ -- check if there is a candidate and we need to send an update
196+ if (territory_points.remaining_time % 300 == 0 and territory_points.remaining_time ~= 0) then
197+ local remaining_time = (max_time * 60 * 1000 - game.time) // 1000
198+ local show_popup = false
199+
200+ if territory_points.remaining_time % 600 == 0 then show_popup = true end
201+ _send_state(remaining_time, plrs, show_popup)
202+
203 end
204 end
205
206
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 time = (ngettext("%1% hour and %2%", "%1% hours and %2%", h, m)):bformat(h, time)
212 elseif m > 0 then
213 -- TRANSLATORS: Context: 'The game will end in 30 minutes.'
214- time = (ngettext("%i minute", "%i minutes", m)):format(m)
215+ time = (ngettext("%i minute", "%i minutes", m)):bformat(m)
216 else
217 -- TRANSLATORS: Context: 'The game will end in 2 hours.'
218 time = (ngettext("%1% hour", "%1% hours", h)):bformat(h)
219 end
220 -- TRANSLATORS: Context: 'The game will end in (2 hours and) 30 minutes.'
221- return p(_"The game will end in %s."):format(time)
222+ return p(_"The game will end in %s."):bformat(time)
223 end
224
225 -- RST
226@@ -312,7 +312,7 @@
227 -- Returns the remaining time and whether the notification should popup.
228 --
229 -- To be used when sending status messages.
230--- Status messages are to be send every 30 minutes and every 5 during the last 30 minutes,
231+-- Status messages are to be sent every 30 minutes and every 5 during the last 30 minutes,
232 -- the message window pops up ever hour, 30, 20 & 10 minutes before the game ends.
233 --
234 -- :arg max_time: The time maximum game time in minutes

Subscribers

People subscribed via source and target branches

to status/vote changes: