Merge lp:~widelands-dev/widelands/bug-1817550-Statistics-hook-Winconditions into lp:widelands

Proposed by hessenfarmer
Status: Merged
Merged at revision: 9081
Proposed branch: lp:~widelands-dev/widelands/bug-1817550-Statistics-hook-Winconditions
Merge into: lp:widelands
Diff against target: 157 lines (+49/-7)
4 files modified
data/scripting/win_conditions/artifacts.lua (+30/-3)
data/scripting/win_conditions/territorial_functions.lua (+13/-0)
data/scripting/win_conditions/territorial_lord.lua (+3/-2)
data/scripting/win_conditions/territorial_time.lua (+3/-2)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1817550-Statistics-hook-Winconditions
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+365086@code.launchpad.net

Commit message

- Added statistics hook for territorial Win conditions
- Added statistics hook for artifacts wincondition
- fixed a bug in artifacts which led to coroutine error if Player defeated when reaching win condition

Description of the change

This is for Build 21.

Win condition statictic Windows will be shown showing the percentage of territory owned for territorial and artifacts owned for artifact wc.

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

Continuous integration builds have changed state:

Travis build 4649. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/511361384.
Appveyor build 4436. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1817550_Statistics_hook_Winconditions-4436.

Revision history for this message
GunChleoc (gunchleoc) wrote :

2 nits - not tested yet.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Thanks for the review.
the double // is intentional to get an integer back (Stats expect integers)
Will check if it is possible to move to territorial functions.

Revision history for this message
GunChleoc (gunchleoc) wrote :

OK, the double // is correct then :)

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

moved the statistics Table definititon to territorial fuctions

Revision history for this message
GunChleoc (gunchleoc) wrote :

Tested and working :)

@bunnybot merge

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

Continuous integration builds have changed state:

Travis build 4794. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/524332830.
Appveyor build 4575. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1817550_Statistics_hook_Winconditions-4575.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Refusing to merge, since Travis is not green. Use @bunnybot merge force for merging anyways.

Travis build 4794. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/524332830.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Unrelated Travis failure already fixed in trunk

@bunnybot merge force

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'data/images/wui/stats/genstats_artifacts.png'
0Binary files data/images/wui/stats/genstats_artifacts.png 1970-01-01 00:00:00 +0000 and data/images/wui/stats/genstats_artifacts.png 2019-04-25 06:14:06 +0000 differ0Binary files data/images/wui/stats/genstats_artifacts.png 1970-01-01 00:00:00 +0000 and data/images/wui/stats/genstats_artifacts.png 2019-04-25 06:14:06 +0000 differ
=== added file 'data/images/wui/stats/genstats_territorial_big.png'
1Binary files data/images/wui/stats/genstats_territorial_big.png 1970-01-01 00:00:00 +0000 and data/images/wui/stats/genstats_territorial_big.png 2019-04-25 06:14:06 +0000 differ1Binary files data/images/wui/stats/genstats_territorial_big.png 1970-01-01 00:00:00 +0000 and data/images/wui/stats/genstats_territorial_big.png 2019-04-25 06:14:06 +0000 differ
=== added file 'data/images/wui/stats/genstats_territorial_small.png'
2Binary files data/images/wui/stats/genstats_territorial_small.png 1970-01-01 00:00:00 +0000 and data/images/wui/stats/genstats_territorial_small.png 2019-04-25 06:14:06 +0000 differ2Binary files data/images/wui/stats/genstats_territorial_small.png 1970-01-01 00:00:00 +0000 and data/images/wui/stats/genstats_territorial_small.png 2019-04-25 06:14:06 +0000 differ
=== modified file 'data/scripting/win_conditions/artifacts.lua'
--- data/scripting/win_conditions/artifacts.lua 2019-02-23 09:12:18 +0000
+++ data/scripting/win_conditions/artifacts.lua 2019-04-25 06:14:06 +0000
@@ -15,6 +15,7 @@
15local wc_descname = _("Artifacts")15local wc_descname = _("Artifacts")
16local wc_version = 116local wc_version = 1
17local wc_desc = _ "Search for ancient artifacts. Once all of them are found, the team who owns most of them will win the game."17local wc_desc = _ "Search for ancient artifacts. Once all of them are found, the team who owns most of them will win the game."
18local wc_artifacts = _"Artifacts owned"
1819
19-- Table of all artifacts to conquer20-- Table of all artifacts to conquer
20local artifact_fields = {}21local artifact_fields = {}
@@ -50,7 +51,22 @@
50 end51 end
51 end52 end
5253
54 local artifacts_owner = {}
53 local plrs = wl.Game().players55 local plrs = wl.Game().players
56
57 -- statistic variables and functions
58 -- initializing artifacts owned table
59 local artifacts_per_player = {}
60 -- funtion to calculate actual number of owned artifacts per player
61 local function _calcowned()
62 for idx, plr in ipairs(wl.Game().players) do
63 artifacts_per_player[plr.number] = 0
64 end
65 for idx, plr in pairs(artifacts_owner) do
66 artifacts_per_player[plr.number] = artifacts_per_player[plr.number] + 1
67 end
68 end
69
54 if #artifact_fields == 0 then70 if #artifact_fields == 0 then
55 for idx, plr in ipairs(plrs) do71 for idx, plr in ipairs(plrs) do
56 send_message(plr, _"No Artifacts", p(_"There are no artifacts on this map. This should not happen. Please file a bug report on %s and specify your Widelands version and the map you tried to load."):bformat("https://wl.widelands.org/wiki/ReportingBugs/"), {popup = true})72 send_message(plr, _"No Artifacts", p(_"There are no artifacts on this map. This should not happen. Please file a bug report on %s and specify your Widelands version and the map you tried to load."):bformat("https://wl.widelands.org/wiki/ReportingBugs/"), {popup = true})
@@ -85,11 +101,22 @@
85 end101 end
86 end102 end
87 end103 end
104
105
106 -- Install statistics hook
107 hooks.custom_statistic = {
108 name = wc_artifacts,
109 pic = "images/wui/stats/genstats_artifacts.png",
110 calculator = function(p)
111 _calcowned(p)
112 return artifacts_per_player[p.number] or 0
113 end,
114 }
88115
89 -- Iterate all players, if one is defeated, remove him116 -- Iterate all players, if one is defeated, remove him
90 -- from the list, send him a defeated message and give him full vision117 -- from the list, send him a defeated message and give him full vision
91 -- Check if all artifacts have been found (i.e. controlled by a player)118 -- Check if all artifacts have been found (i.e. controlled by a player)
92 local artifacts_owner = {}119
93 repeat120 repeat
94 sleep(1000)121 sleep(1000)
95 check_player_defeated(plrs, lost_game.title, lost_game.body, wc_descname, wc_version)122 check_player_defeated(plrs, lost_game.title, lost_game.body, wc_descname, wc_version)
@@ -115,7 +142,7 @@
115142
116 -- All artifacts are found, the game is over.143 -- All artifacts are found, the game is over.
117 local artifacts_per_team = {}144 local artifacts_per_team = {}
118 for idx, plr in ipairs(plrs) do145 for idx, plr in ipairs(wl.Game().players) do
119 artifacts_per_team[_getkey(plr)] = 0146 artifacts_per_team[_getkey(plr)] = 0
120 end147 end
121148
@@ -164,7 +191,6 @@
164 msg = msg .. p((_"Team %1$i (%2$s) owns %3$s."):bformat(t[1].team, members, artifacts))191 msg = msg .. p((_"Team %1$i (%2$s) owns %3$s."):bformat(t[1].team, members, artifacts))
165 end192 end
166193
167
168 for idx, plr in ipairs(plrs) do194 for idx, plr in ipairs(plrs) do
169 local key = _getkey(plr)195 local key = _getkey(plr)
170 -- If two or more teams have the same amount of artifacts, they are all considered winners.196 -- If two or more teams have the same amount of artifacts, they are all considered winners.
@@ -177,4 +203,5 @@
177 end203 end
178 end204 end
179 end,205 end,
206
180}207}
181208
=== modified file 'data/scripting/win_conditions/territorial_functions.lua'
--- data/scripting/win_conditions/territorial_functions.lua 2019-04-25 04:23:11 +0000
+++ data/scripting/win_conditions/territorial_functions.lua 2019-04-25 06:14:06 +0000
@@ -53,6 +53,19 @@
53 points = {}53 points = {}
54}54}
5555
56-- variables for the territorial winconditions statsistics hook
57fields = 0
58statistics = {
59 -- TRANSLATORS: subtext of the territorial statistics hook. Keep it short and consistent with the translation of the Win condition.
60 name = _"Territory percentage",
61 pic = "images/wui/stats/genstats_territorial_small.png",
62 calculator = function(p)
63 local pts = count_owned_valuable_fields_for_all_players(wl.Game().players)
64 return (pts[p.number]*100//fields)
65 end,
66 }
67
68
56-- RST69-- RST
57-- .. function:: calculate_territory_points(fields, players, wc_descname, wc_version)70-- .. function:: calculate_territory_points(fields, players, wc_descname, wc_version)
58--71--
5972
=== modified file 'data/scripting/win_conditions/territorial_lord.lua'
--- data/scripting/win_conditions/territorial_lord.lua 2019-04-24 18:59:59 +0000
+++ data/scripting/win_conditions/territorial_lord.lua 2019-04-25 06:14:06 +0000
@@ -23,8 +23,6 @@
23 "that area for at least 20 minutes."23 "that area for at least 20 minutes."
24)24)
2525
26local fields = 0
27
28return {26return {
29 name = wc_name,27 name = wc_name,
30 description = wc_desc,28 description = wc_desc,
@@ -61,6 +59,9 @@
61 end59 end
62 end60 end
6361
62 -- Install statistics hook
63 hooks.custom_statistic = statistics
64
64 -- here is the main loop!!!65 -- here is the main loop!!!
65 while count_factions(plrs) > 1 and territory_points.remaining_time > 0 do66 while count_factions(plrs) > 1 and territory_points.remaining_time > 0 do
66 -- Sleep 1 second67 -- Sleep 1 second
6768
=== modified file 'data/scripting/win_conditions/territorial_time.lua'
--- data/scripting/win_conditions/territorial_time.lua 2019-04-25 04:23:11 +0000
+++ data/scripting/win_conditions/territorial_time.lua 2019-04-25 06:14:06 +0000
@@ -27,8 +27,6 @@
27 "after 4 hours, whichever comes first."27 "after 4 hours, whichever comes first."
28)28)
2929
30local fields = 0
31
32return {30return {
33 name = wc_name,31 name = wc_name,
34 description = wc_desc,32 description = wc_desc,
@@ -82,6 +80,9 @@
82 end80 end
83 end)81 end)
8482
83 -- Install statistics hook
84 hooks.custom_statistic = statistics
85
85 -- here is the main loop!!!86 -- here is the main loop!!!
86 while game.time < (max_time * 60 * 1000) and count_factions(plrs) > 1 and territory_points.remaining_time > 0 do87 while game.time < (max_time * 60 * 1000) and count_factions(plrs) > 1 and territory_points.remaining_time > 0 do
87 -- Sleep 1 second88 -- Sleep 1 second

Subscribers

People subscribed via source and target branches

to status/vote changes: