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
1=== added file 'data/images/wui/stats/genstats_artifacts.png'
2Binary 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
3=== added file 'data/images/wui/stats/genstats_territorial_big.png'
4Binary 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
5=== added file 'data/images/wui/stats/genstats_territorial_small.png'
6Binary 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
7=== modified file 'data/scripting/win_conditions/artifacts.lua'
8--- data/scripting/win_conditions/artifacts.lua 2019-02-23 09:12:18 +0000
9+++ data/scripting/win_conditions/artifacts.lua 2019-04-25 06:14:06 +0000
10@@ -15,6 +15,7 @@
11 local wc_descname = _("Artifacts")
12 local wc_version = 1
13 local wc_desc = _ "Search for ancient artifacts. Once all of them are found, the team who owns most of them will win the game."
14+local wc_artifacts = _"Artifacts owned"
15
16 -- Table of all artifacts to conquer
17 local artifact_fields = {}
18@@ -50,7 +51,22 @@
19 end
20 end
21
22+ local artifacts_owner = {}
23 local plrs = wl.Game().players
24+
25+ -- statistic variables and functions
26+ -- initializing artifacts owned table
27+ local artifacts_per_player = {}
28+ -- funtion to calculate actual number of owned artifacts per player
29+ local function _calcowned()
30+ for idx, plr in ipairs(wl.Game().players) do
31+ artifacts_per_player[plr.number] = 0
32+ end
33+ for idx, plr in pairs(artifacts_owner) do
34+ artifacts_per_player[plr.number] = artifacts_per_player[plr.number] + 1
35+ end
36+ end
37+
38 if #artifact_fields == 0 then
39 for idx, plr in ipairs(plrs) do
40 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})
41@@ -85,11 +101,22 @@
42 end
43 end
44 end
45+
46+
47+ -- Install statistics hook
48+ hooks.custom_statistic = {
49+ name = wc_artifacts,
50+ pic = "images/wui/stats/genstats_artifacts.png",
51+ calculator = function(p)
52+ _calcowned(p)
53+ return artifacts_per_player[p.number] or 0
54+ end,
55+ }
56
57 -- Iterate all players, if one is defeated, remove him
58 -- from the list, send him a defeated message and give him full vision
59 -- Check if all artifacts have been found (i.e. controlled by a player)
60- local artifacts_owner = {}
61+
62 repeat
63 sleep(1000)
64 check_player_defeated(plrs, lost_game.title, lost_game.body, wc_descname, wc_version)
65@@ -115,7 +142,7 @@
66
67 -- All artifacts are found, the game is over.
68 local artifacts_per_team = {}
69- for idx, plr in ipairs(plrs) do
70+ for idx, plr in ipairs(wl.Game().players) do
71 artifacts_per_team[_getkey(plr)] = 0
72 end
73
74@@ -164,7 +191,6 @@
75 msg = msg .. p((_"Team %1$i (%2$s) owns %3$s."):bformat(t[1].team, members, artifacts))
76 end
77
78-
79 for idx, plr in ipairs(plrs) do
80 local key = _getkey(plr)
81 -- If two or more teams have the same amount of artifacts, they are all considered winners.
82@@ -177,4 +203,5 @@
83 end
84 end
85 end,
86+
87 }
88
89=== modified file 'data/scripting/win_conditions/territorial_functions.lua'
90--- data/scripting/win_conditions/territorial_functions.lua 2019-04-25 04:23:11 +0000
91+++ data/scripting/win_conditions/territorial_functions.lua 2019-04-25 06:14:06 +0000
92@@ -53,6 +53,19 @@
93 points = {}
94 }
95
96+-- variables for the territorial winconditions statsistics hook
97+fields = 0
98+statistics = {
99+ -- TRANSLATORS: subtext of the territorial statistics hook. Keep it short and consistent with the translation of the Win condition.
100+ name = _"Territory percentage",
101+ pic = "images/wui/stats/genstats_territorial_small.png",
102+ calculator = function(p)
103+ local pts = count_owned_valuable_fields_for_all_players(wl.Game().players)
104+ return (pts[p.number]*100//fields)
105+ end,
106+ }
107+
108+
109 -- RST
110 -- .. function:: calculate_territory_points(fields, players, wc_descname, wc_version)
111 --
112
113=== modified file 'data/scripting/win_conditions/territorial_lord.lua'
114--- data/scripting/win_conditions/territorial_lord.lua 2019-04-24 18:59:59 +0000
115+++ data/scripting/win_conditions/territorial_lord.lua 2019-04-25 06:14:06 +0000
116@@ -23,8 +23,6 @@
117 "that area for at least 20 minutes."
118 )
119
120-local fields = 0
121-
122 return {
123 name = wc_name,
124 description = wc_desc,
125@@ -61,6 +59,9 @@
126 end
127 end
128
129+ -- Install statistics hook
130+ hooks.custom_statistic = statistics
131+
132 -- here is the main loop!!!
133 while count_factions(plrs) > 1 and territory_points.remaining_time > 0 do
134 -- Sleep 1 second
135
136=== modified file 'data/scripting/win_conditions/territorial_time.lua'
137--- data/scripting/win_conditions/territorial_time.lua 2019-04-25 04:23:11 +0000
138+++ data/scripting/win_conditions/territorial_time.lua 2019-04-25 06:14:06 +0000
139@@ -27,8 +27,6 @@
140 "after 4 hours, whichever comes first."
141 )
142
143-local fields = 0
144-
145 return {
146 name = wc_name,
147 description = wc_desc,
148@@ -82,6 +80,9 @@
149 end
150 end)
151
152+ -- Install statistics hook
153+ hooks.custom_statistic = statistics
154+
155 -- here is the main loop!!!
156 while game.time < (max_time * 60 * 1000) and count_factions(plrs) > 1 and territory_points.remaining_time > 0 do
157 -- Sleep 1 second

Subscribers

People subscribed via source and target branches

to status/vote changes: