Merge lp:~widelands-dev/widelands/fh1-winconditions into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8382
Proposed branch: lp:~widelands-dev/widelands/fh1-winconditions
Merge into: lp:widelands
Diff against target: 826 lines (+465/-61)
9 files modified
data/scripting/formatting.lua (+3/-0)
data/scripting/richtext.lua (+413/-0)
data/scripting/win_conditions/artifacts.lua (+6/-7)
data/scripting/win_conditions/collectors.lua (+11/-13)
data/scripting/win_conditions/territorial_lord.lua (+8/-11)
data/scripting/win_conditions/territorial_time.lua (+12/-18)
data/scripting/win_conditions/win_condition_functions.lua (+1/-0)
data/scripting/win_conditions/win_condition_texts.lua (+4/-4)
data/scripting/win_conditions/wood_gnome.lua (+7/-8)
To merge this branch: bzr merge lp:~widelands-dev/widelands/fh1-winconditions
Reviewer Review Type Date Requested Status
Klaus Halfmann code review Approve
kaputtnik (community) testing Approve
Review via email: mp+323987@code.launchpad.net

Commit message

Converted win condition scripts to new font renderer. Formatting functions for the new renderer live in data/scripting/richtext.lua

Description of the change

I decided to add a separate script for the formatting stuff. This way, we can keep the old renderer around until after the release so that savegames won't crash.

I will replace the online documentation for Richtext once we have support for campaign scenarios - I haven't touched the message boxes and objectives yet.

To post a comment you must log in.
Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Uhm, this is all lua, what would be the way to test this?

I cannot judge much about that code.
I will however compile the code and play around with some winconditions

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2179. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/231575243.
Appveyor build 2014. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_fh1_winconditions-2014.

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

I played this some time now and got an ugly crash, here:

Cmd_EnemyFlagAction::execute player(3): flag->owner(4) number=4
Assertion failed: (it != entries_.end()), function drop, file /Users/klaus/develop/widelands-repo/fh1-winconditions/src/graphic/texture_cache.cc, line 79.

3 libsystem_c.dylib 0x00007fffb52b3893 __assert_rtn + 320
4 widelands 0x000000010f9d6bad TextureCache::drop() + 845 (texture_cache.cc:79)
5 widelands 0x000000010f9d6121 TextureCache::insert(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::unique_ptr<Texture, std::__1::default_delete<Texture> >) + 801 (texture_cache.cc:63)
6 widelands 0x000000010f3b6aac RT::SdlTtfFont::render(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, RGBColor const&, int, TextureCache*) + 3932 (sdl_ttf_font.cc:131)
7 widelands 0x000000010f393ac5 RT::TextNode::render(TextureCache*) + 85 (rt_render.cc:521)
8 widelands 0x000000010f3a2764 RT::DivTagRenderNode::render(TextureCache*) + 3012 (rt_render.cc:746)
9 widelands 0x000000010f39bfeb RT::Renderer::render(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned short, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) + 315 (rt_render.cc:1487)
10 widelands 0x000000010f2b6876 (anonymous namespace)::RTImage::texture() const + 262 (font_handler1.cc:92)
11 widelands 0x000000010f2b6685 (anonymous namespace)::RTImage::width() const + 21 (font_handler1.cc:75)
12 widelands 0x000000010f2b3612 UI::FontHandler1::render(std::__1::basic_string<char, std::__1::char_traits<char>,

Maybe this is again the memory problem we face on trunk, no idea, mmh

Revision history for this message
GunChleoc (gunchleoc) wrote :

Yes, it must be a problem that we have in trunk already - the worst thing that should happen here is reverting to the old font renderer if the text can't be parsed and the ending up with empty text or lots of visible tags.

Revision history for this message
GunChleoc (gunchleoc) wrote :
Revision history for this message
kaputtnik (franku) wrote :

This looks really good now :-)

Played an hour or so but no crash anymore. The output of 'new size' is a bit annoying, i guess it switches between Kilobytes and Bytes (?):

TransientCache: Dropping 11 bytes, new size 4082. [...]
TransientCache: Dropping 4032 bytes, new size 31452972. [...]
[...]
TransientCache: Dropping 4 bytes, new size 4092.

But it never exceeds the size of 4093 (as far as i can see).

There are a lot of such outputs if you just move the mouse around, also moving the mouse on black areas. Don't know if this much processor time consuming. Maybe here is a chance of optimization?

review: Approve (testing)
Revision history for this message
kaputtnik (franku) wrote :

Sorry, wrong branch :-S

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Code Revire is ok for me.
In case of an error some layout may be broken, well. We will find that.

review: Approve (code review)
Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for the review :)

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/scripting/formatting.lua'
--- data/scripting/formatting.lua 2016-10-19 09:00:29 +0000
+++ data/scripting/formatting.lua 2017-06-16 07:57:28 +0000
@@ -1,3 +1,6 @@
1-- TODO(GunChleoc): This is for the legacy font renderer. Remove when we remove the old renderer.
2
3
1-- RST4-- RST
2-- formatting.lua5-- formatting.lua
3-- --------------6-- --------------
47
=== added file 'data/scripting/richtext.lua'
--- data/scripting/richtext.lua 1970-01-01 00:00:00 +0000
+++ data/scripting/richtext.lua 2017-06-16 07:57:28 +0000
@@ -0,0 +1,413 @@
1-- TODO(GunChleoc): Wrap all tags and document allowed attributes when we're done
2
3-- RST
4-- richtext.lua
5-- ------------
6--
7-- Functions to simplify and unique text formatting in scenarios and help files.
8-- Most of these functions are simple wrapper functions that make working with
9-- widelands rich text formatting system more bearable.
10-- Function names generally follow HTML names.
11
12
13-- RST
14-- .. function:: localize_list(items, listtype, former_textdomain)
15--
16-- Turns an array of string items into a localized string list with
17-- appropriate concatenation.
18--
19-- e.g. localize_list({"foo", "bar", baz"}, "or", "widelands") will return
20-- _"foo, bar or baz"
21--
22-- :arg items: An array of strings
23-- :arg listtype: The type of concatenation to use.
24-- Legal values are "&", "and", "or", and ";"
25-- :arg former_textdomain: The textdomain to restore after running this function.
26-- :returns: The concatenated list string, using localized concatenation operators.
27--
28-- Same algorithm as in src/base/i18n
29function localize_list(items, listtype, former_textdomain)
30 set_textdomain("widelands")
31 local result = ""
32 for i, item in pairs(items) do
33 if (i == 1) then
34 result = item
35 elseif (i == #items) then
36 if (listtype == "&") then
37 result = _"%1$s & %2$s":bformat(result, item)
38 elseif (listtype == "or") then
39 result = _"%1$s or %2$s":bformat(result, item)
40 elseif (listtype == ",") then
41 result = _"%1$s, %2$s":bformat(result, item)
42 else
43 result = _"%1$s and %2$s":bformat(result, item)
44 end
45 else
46 result = _"%1$s, %2$s":bformat(result, item)
47 end
48 end
49 set_textdomain(former_textdomain)
50 return result
51end
52
53
54-- RST
55-- .. function:: rt(text_or_attributes[, text = nil])
56--
57-- Wraps a block of text into Lua rich text.
58-- Only call this once for the whole text that gets sent to the backend.
59-- There is no general need to wrap an rt tag around your text,
60-- because the backend will take care of it.
61-- So, only use this function if you wish to add some attributes to the tag.
62--
63-- Allowed attributes are:
64-- padding, padding_r, padding_l, padding_b, padding_t: TODO(GunChleoc): Document
65-- background: a background color or image
66-- debug: add visual debug information and debug log
67-- editor_mode: allow multiple blank spaces for editing
68--
69-- :arg attributes: the attributes for the rt tag.
70-- :type attributes: :class:`string`
71-- :arg text: the text to be enclosed in rich text tags.
72-- :type text: :class:`string`
73-- :returns: the wrapped rich text.
74--
75function rt(text_or_attributes, text)
76 if text then
77 return "<rt " .. text_or_attributes .. ">" .. text .. "</rt>"
78 else
79 return "<rt>" .. text_or_attributes .. "</rt>"
80 end
81end
82
83
84-- RST
85-- .. function:: img(src[, attributes = nil])
86--
87-- Turns an image src path into an image tag for richtext.
88--
89-- :arg src: the file path to the image.
90-- :type src: :class:`string`
91-- :arg attributes: the attributes for the div tag.
92-- :type attributes: :class:`string`
93--
94-- Allowed attributes are:
95-- color: a hex color to be applied to the image's player color mask, if it has any
96-- ref: TODO(GunChleoc): I have no idea what it does.
97--
98-- :returns: the img tag.
99--
100function img(src, attributes)
101 if attributes then
102 return "<img src=" .. src .." " .. attributes .. ">"
103 else
104 return "<img src=" .. src .. ">"
105 end
106end
107
108
109function title(font_face, text)
110 return p_font("align=center", "size=38 face=".. font_face .. " color=2F9131", text)
111end
112
113
114-- RST
115-- .. function:: h1(text_or_color[, text = nil])
116--
117-- Returns a paragraph formatted as a big heading with a small gap after it.
118-- The mnemonic comes from HTML.
119--
120-- :returns: A paragraph with text formatted as heading.
121function h1(text_or_color, text)
122 if text then
123 return p_font("", "size=18 bold=1 color=".. text_or_color, vspace(6) .. text .. vspace(1))
124 else
125 return p_font("", "size=18 bold=1 color=D1D1D1", vspace(6) .. text_or_color .. vspace(1))
126 end
127end
128
129-- RST
130-- .. function:: h2(text)
131--
132-- Like :func:`h1` but smaller.
133--
134-- :returns: A paragraph with text formatted as heading.
135function h2(text)
136 return p_font("", "size=14 bold=1 color=D1D1D1", vspace(6) .. text .. vspace(1))
137end
138
139-- RST
140-- .. function:: h3(text)
141--
142-- Like :func:`h2` but smaller.
143--
144-- :returns: A paragraph with text formatted as heading.
145--
146function h3(text)
147 return p_font("", "size=13 color=D1D1D1", vspace(4) .. text .. vspace(1))
148end
149
150-- RST
151-- .. function:: h4(text)
152--
153-- Like :func:`h3` but smaller.
154--
155-- :returns: A paragraph with text formatted as heading.
156--
157function h4(text)
158 return p_font("", "size=12 italic=1 color=D1D1D1", text)
159end
160
161-- RST
162-- .. function:: p(text_or_attributes[, text = nil])
163--
164-- Returns one paragraph with text followed by a small vertical gap. Options
165-- can be given as first argument similar to :func:`rt`.
166--
167-- Allowed attributes are documented in the open_p function.
168--
169-- :returns: The text wrapped in <p>%s</p>
170function p(text_or_attributes, text)
171 if text then
172 return open_p(text_or_attributes) .. text .. close_p()
173 else
174 return open_p() .. text_or_attributes .. close_p()
175 end
176end
177
178
179-- RST
180-- .. function:: p(text_or_attributes[, text = nil])
181--
182-- Returns one paragraph with text followed by a small vertical gap. Options
183-- can be given as first argument similar to :func:`rt`.
184--
185-- Allowed p attributes are documented in the open_p function.
186--
187-- Allowed font attributes are are documented in the font function.
188--
189-- :returns: The text wrapped in <p attributes><font attributes>text</font></p>
190function p_font(p_or_font_or_attributes, text_or_font_attributes, text)
191 if text then
192 return ("<p %s>"):format(p_or_font_or_attributes) .. "<font " .. text_or_font_attributes .. ">" .. text .. close_p()
193 else
194 return "<p><font " .. p_or_font_or_attributes .. ">" .. text_or_font_attributes .. close_p()
195 end
196end
197
198
199-- RST
200-- .. function:: open_p([attributes = nil])
201--
202-- Returns a paragraph open tag and default font size. Options
203-- can be given as first argument similar to :func:`rt`.
204--
205-- Allowed attributes are:
206-- indent: indents the first line of the paragraph
207-- align: horizontal alignment (left, center, right)
208-- valign: vertical alignment (top, middle, bottom)
209-- spacing: line spacing in pixels
210--
211-- :returns: <p> with added attributes and default font
212function open_p(attributes)
213 if attributes then
214 return ("<p %s>"):format(attributes) .. "<font size=12>"
215 else
216 return "<p><font size=12>"
217 end
218end
219
220
221-- RST
222-- .. function:: close_p(t)
223--
224-- Closes a paragraph.
225--
226-- :returns: The closing tags for a paragraph
227function close_p(t)
228 return vspace(6) .. "</font></p>"
229end
230
231-- RST
232-- .. function:: font(attributes, text)
233--
234-- Wraps the text in font tags.
235--
236-- Allowed attributes are:
237-- size: the font size in pt
238-- face: sans, serif or condensed
239-- color: a hex color
240-- bold: if you add bold=1, the text will be bold
241-- italic: if you add italic=1, the text will be italic
242-- underline: if you add underline=1, the text will be underlined
243-- shadow: if you add shadow=1, the text will have a shadow
244-- ref: TODO(GunChleoc): I don't know what this does.
245--
246-- :returns: The text wrapped in font tags with the given attributes
247--
248function font(attributes, text)
249 return ("<font %s>"):format(attributes) .. text .. "</font>"
250end
251
252-- RST
253-- .. function:: space(gap)
254--
255-- Adds a horizontal space
256-- :arg gap: the size of the space as pixels.
257--
258-- :returns: a space tag
259--
260function space(gap)
261 return "<space gap="..gap..">"
262end
263
264-- RST
265-- .. function:: vspace(gap)
266--
267-- Adds a vertical space
268-- :arg gap: the size of the space as pixels.
269--
270-- :returns: a vspace tag
271--
272function vspace(gap)
273 return "<vspace gap="..gap..">"
274end
275
276-- RST
277-- .. function:: dl(dt, dd)
278--
279-- This function imitates a HTML description list
280-- :arg dt: "description term", will be rendered in bold.
281-- :arg dd: "description data", will be rendered normally.
282--
283-- :returns: a p tag containing the formatted text
284--
285function dl(dt, dd)
286 return p(b(dt) .. " " .. dd)
287end
288
289-- RST
290-- .. function:: li(text_or_symbol[, text = nil])
291--
292-- Adds the symbol in front of the text to create a list item and
293-- wraps it in a paragraph
294--
295-- :arg symbol: the item symbol for the list, e.g. "•" or "→"
296-- :arg text: the text of the list item
297--
298-- :returns: a p tag containint the formatted text
299function li(text_or_symbol, text)
300 if text then
301 return p(text_or_symbol .. " " .. text .. vspace(6))
302 else
303 return p("• " .. text_or_symbol .. vspace(6))
304 end
305end
306
307-- RST
308-- .. function:: li_arrow(text)
309--
310-- Creates a list item with an arrow
311--
312-- :arg text: the text of the list item
313--
314-- :returns: li("→", text)
315function li_arrow(text)
316 -- TODO(GunChleoc): Reverse arrow for rtl languages.
317 return li("→", text)
318end
319
320-- RST
321-- .. function li_image(imagepath, text)
322--
323-- Places a paragraph of text to the right of an image
324
325-- :arg imagepath: the full path to the image file
326-- :arg text_width_percent: the percentatge of space that the text will occupy
327-- :arg text: the text to be placed next to the image
328--
329-- :returns: the text wrapped in a paragraph and placed next to the image, The outer tag is a div.
330function li_image(imagepath, text_width_percent, text)
331 return p("<br>") .. div("width=100%", "") ..
332 div(p(img(imagepath))) ..
333 div(p(space(6))) ..
334 div("width="..text_width_percent.."%", p(text)) ..
335 div("width=100%", "")
336end
337
338-- RST
339-- .. function:: a(link)
340--
341-- This function imitates a HTML link. We can't do real links yet, so the text just gets underlines.
342-- :arg link: the text to format
343--
344-- :returns: a font tag containing the underlined text
345--
346function a(link)
347 return font("underline=1", link)
348end
349
350-- RST
351-- .. function:: b(link)
352--
353-- This makes the text bold.
354-- :arg link: the text to format
355--
356-- :returns: a font tag containing the bold text
357--
358function b(text)
359 return font("bold=1", text)
360end
361
362-- RST
363-- .. function:: i(link)
364--
365-- This makes the text italic.
366-- :arg link: the text to format
367--
368-- :returns: a font tag containing the italic text
369--
370function i(text)
371 return font("italic=1", text)
372end
373
374-- RST
375-- .. function:: u(link)
376--
377-- This underlines the text.
378-- :arg link: the text to format
379--
380-- :returns: a font tag containing the underlined text
381--
382function u(text)
383 return font("underline=1", text)
384end
385
386-- RST
387-- .. function:: div(text_or_attributes[, text = nil])
388--
389-- Wraps a block of text into a div tag.
390--
391-- :arg attributes: the attributes for the div tag.
392-- :type attributes: :class:`string`
393--
394-- Allowed attributes are:
395-- padding, padding_r, padding_l, padding_b, padding_t: TODO(GunChleoc): Document
396-- margin: TODO(GunChleoc): Document
397-- float: TODO(GunChleoc): this does not work yet
398-- margin: inner margin for the div
399-- valign: vertical alignment
400-- background: a background color or image
401-- width: the width of the div in pixels or percent
402--
403-- :arg text: the text to be enclosed in div tags.
404-- :type text: :class:`string`
405-- :returns: the text wrapped in a div tag.
406--
407function div(text_or_attributes, text)
408 if text then
409 return ("<div %s>"):format(text_or_attributes) .. text .. "</div>"
410 else
411 return ("<div>") .. text_or_attributes .. "</div>"
412 end
413end
0414
=== modified file 'data/scripting/win_conditions/artifacts.lua'
--- data/scripting/win_conditions/artifacts.lua 2016-09-20 17:01:35 +0000
+++ data/scripting/win_conditions/artifacts.lua 2017-06-16 07:57:28 +0000
@@ -4,7 +4,6 @@
44
5include "scripting/coroutine.lua" -- for sleep5include "scripting/coroutine.lua" -- for sleep
6include "scripting/win_conditions/win_condition_functions.lua"6include "scripting/win_conditions/win_condition_functions.lua"
7include "scripting/formatting.lua"
87
9set_textdomain("win_conditions")8set_textdomain("win_conditions")
109
@@ -53,7 +52,7 @@
53 local plrs = wl.Game().players52 local plrs = wl.Game().players
54 if #artifact_fields == 0 then53 if #artifact_fields == 0 then
55 for idx, plr in ipairs(plrs) do54 for idx, plr in ipairs(plrs) do
56 send_message(plr, _"No Artifacts", rt(p(_"There are no artifacts on this map. This should not happen. Please file a bug report on https://launchpad.net/widelands and specify your Widelands version and the map you tried to load.")), {popup = true})55 send_message(plr, _"No Artifacts", p(_"There are no artifacts on this map. This should not happen. Please file a bug report on https://launchpad.net/widelands and specify your Widelands version and the map you tried to load."), {popup = true})
57 end56 end
58 return57 return
59 end58 end
@@ -61,17 +60,17 @@
61 local found_artifact = {60 local found_artifact = {
62 -- TRANSLATORS: Keep this as short as possible. You can also translate this as "New artifact"61 -- TRANSLATORS: Keep this as short as possible. You can also translate this as "New artifact"
63 title = _"Artifact Found",62 title = _"Artifact Found",
64 body = rt(p(_[[Your team found a new artifact.]]))63 body = p(_[[Your team found a new artifact.]])
65 }64 }
66 local lost_artifact = {65 local lost_artifact = {
67 -- TRANSLATORS: Keep this as short as possible.66 -- TRANSLATORS: Keep this as short as possible.
68 title = _"Artifact Lost",67 title = _"Artifact Lost",
69 body = rt(p(_[[One of your team’s artifacts was stolen by an enemy.]]))68 body = p(_[[One of your team’s artifacts was stolen by an enemy.]])
70 }69 }
71 local stole_artifact = {70 local stole_artifact = {
72 -- TRANSLATORS: Keep this as short as possible.71 -- TRANSLATORS: Keep this as short as possible.
73 title = _"Artifact Conquered",72 title = _"Artifact Conquered",
74 body = rt(p(_[[Your team stole an artifact from an enemy.]]))73 body = p(_[[Your team stole an artifact from an enemy.]])
75 }74 }
7675
77 local function _broadcast_to_team(player, msg, f)76 local function _broadcast_to_team(player, msg, f)
@@ -174,10 +173,10 @@
174 local key = _getkey(plr)173 local key = _getkey(plr)
175 -- If two or more teams have the same amount of artifacts, they are all considered winners.174 -- If two or more teams have the same amount of artifacts, they are all considered winners.
176 if artifacts_per_team[key] == max_artifacts then175 if artifacts_per_team[key] == max_artifacts then
177 plr:send_message(won_game_over.title, rt(won_game_over.body .. msg))176 plr:send_message(won_game_over.title, won_game_over.body .. msg)
178 wl.game.report_result(plr, 1, make_extra_data(plr, wc_descname, wc_version, {score=artifacts_per_team[key]}))177 wl.game.report_result(plr, 1, make_extra_data(plr, wc_descname, wc_version, {score=artifacts_per_team[key]}))
179 else178 else
180 plr:send_message(lost_game_over.title, rt(lost_game_over.body .. msg))179 plr:send_message(lost_game_over.title, lost_game_over.body .. msg)
181 wl.game.report_result(plr, 0, make_extra_data(plr, wc_descname, wc_version, {score=artifacts_per_team[key]}))180 wl.game.report_result(plr, 0, make_extra_data(plr, wc_descname, wc_version, {score=artifacts_per_team[key]}))
182 end181 end
183 end182 end
184183
=== modified file 'data/scripting/win_conditions/collectors.lua'
--- data/scripting/win_conditions/collectors.lua 2016-12-01 21:14:28 +0000
+++ data/scripting/win_conditions/collectors.lua 2017-06-16 07:57:28 +0000
@@ -4,8 +4,6 @@
44
5include "scripting/coroutine.lua" -- for sleep5include "scripting/coroutine.lua" -- for sleep
6include "scripting/messages.lua"6include "scripting/messages.lua"
7include "scripting/formatting.lua"
8include "scripting/format_scenario.lua"
9include "scripting/table.lua"7include "scripting/table.lua"
10include "scripting/win_conditions/win_condition_functions.lua"8include "scripting/win_conditions/win_condition_functions.lua"
119
@@ -108,7 +106,7 @@
108 plr:get_buildings(plr.tribe_name .. "_headquarters"), plr:get_buildings(plr.tribe_name .. "_warehouse"), plr:get_buildings(plr.tribe_name .. "_port")106 plr:get_buildings(plr.tribe_name .. "_headquarters"), plr:get_buildings(plr.tribe_name .. "_warehouse"), plr:get_buildings(plr.tribe_name .. "_port")
109 )107 )
110108
111 descr = descr .. h2((_"Status for %s"):format(plr.name)) .. "<p line-spacing=3 font-size=12>"109 descr = descr .. h2((_"Status for %s"):format(plr.name))
112 local points = 0110 local points = 0
113 for idx, ware in ipairs(point_table[plr.tribe_name .. "_order"]) do111 for idx, ware in ipairs(point_table[plr.tribe_name .. "_order"]) do
114 local value = point_table[plr.tribe_name][ware]112 local value = point_table[plr.tribe_name][ware]
@@ -121,11 +119,11 @@
121119
122 local warename = wl.Game():get_ware_description(ware).descname120 local warename = wl.Game():get_ware_description(ware).descname
123 -- TRANSLATORS: For example: 'gold (3 P) x 4 = 12 P', P meaning 'Points'121 -- TRANSLATORS: For example: 'gold (3 P) x 4 = 12 P', P meaning 'Points'
124 descr = descr .. listitem_bullet(_"%1$s (%2$i P) x %3$i = %4$i P"):bformat(122 descr = descr .. li(_"%1$s (%2$i P) x %3$i = %4$i P"):bformat(
125 warename, value, count, lpoints123 warename, value, count, lpoints
126 )124 )
127 end125 end
128 descr = descr .. "</p>" .. h3(ngettext("Total: %i point", "Total: %i points", points)):format(points)126 descr = descr .. h3(ngettext("Total: %i point", "Total: %i points", points)):format(points)
129 team_points = team_points + points127 team_points = team_points + points
130 end128 end
131129
@@ -135,10 +133,10 @@
135133
136 -- Send all players the momentary game state134 -- Send all players the momentary game state
137 local function _send_state(remaining_time, plrs)135 local function _send_state(remaining_time, plrs)
138 local msg = ""136 local msg = vspace(8)
139 set_textdomain("win_conditions")137 set_textdomain("win_conditions")
140 if remaining_time <= 0 then138 if remaining_time <= 0 then
141 msg = p(_"The game has ended.")139 msg = p(_"The game has ended.") .. vspace(8)
142 else140 else
143 local h = math.floor(remaining_time / 60)141 local h = math.floor(remaining_time / 60)
144 local m = remaining_time % 60142 local m = remaining_time % 60
@@ -157,14 +155,14 @@
157 end155 end
158 end156 end
159 -- TRANSLATORS: Context: 'The game will end in 2 hours and 30 minutes.'157 -- TRANSLATORS: Context: 'The game will end in 2 hours and 30 minutes.'
160 msg = p(_"The game will end in %s."):format(time)158 msg = p(_"The game will end in %s."):format(time) .. vspace(8)
161 end159 end
162160
163 -- Points for players without team161 -- Points for players without team
164 for idx, plr in ipairs(plrs) do162 for idx, plr in ipairs(plrs) do
165 if (plr.team == 0) then163 if (plr.team == 0) then
166 local points, pstat = _calc_points({plr})164 local points, pstat = _calc_points({plr})
167 msg = msg .. "<p font-size=8> <br></p>" .. pstat165 msg = msg .. vspace(8) .. pstat
168 end166 end
169 end167 end
170 -- Team points168 -- Team points
@@ -173,11 +171,11 @@
173 local message = h1((_"Status for Team %d"):format(idx))171 local message = h1((_"Status for Team %d"):format(idx))
174 .. pstat172 .. pstat
175 .. h2(ngettext("Team Total: %i point", "Team Total: %i points", points)):format(points)173 .. h2(ngettext("Team Total: %i point", "Team Total: %i points", points)):format(points)
176 msg = msg .. "<p font-size=8> <br></p>" .. message174 msg = msg .. vspace(8) .. message
177 end175 end
178176
179 for idx, plr in ipairs(plrs) do177 for idx, plr in ipairs(plrs) do
180 send_message(plr, game_status.title, "<rt>" .. msg .. "</rt>", {popup = true})178 send_message(plr, game_status.title, msg, {popup = true})
181 end179 end
182 end180 end
183181
@@ -201,10 +199,10 @@
201 local lost_or_won = 0199 local lost_or_won = 0
202 if (info[2] < win_points) then200 if (info[2] < win_points) then
203 lost_or_won = 0201 lost_or_won = 0
204 player:send_message(lost_game_over.title, rt(lost_game_over.body))202 player:send_message(lost_game_over.title, lost_game_over.body)
205 else203 else
206 lost_or_won = 1204 lost_or_won = 1
207 player:send_message(won_game_over.title, rt(won_game_over.body))205 player:send_message(won_game_over.title, won_game_over.body)
208 end206 end
209 if (player.team == 0) then207 if (player.team == 0) then
210 wl.game.report_result(player, lost_or_won, make_extra_data(player, wc_descname, wc_version, {score=info[2]}))208 wl.game.report_result(player, lost_or_won, make_extra_data(player, wc_descname, wc_version, {score=info[2]}))
211209
=== modified file 'data/scripting/win_conditions/territorial_lord.lua'
--- data/scripting/win_conditions/territorial_lord.lua 2016-09-17 11:29:34 +0000
+++ data/scripting/win_conditions/territorial_lord.lua 2017-06-16 07:57:28 +0000
@@ -3,7 +3,6 @@
3-- =======================================================================3-- =======================================================================
44
5include "scripting/coroutine.lua" -- for sleep5include "scripting/coroutine.lua" -- for sleep
6include "scripting/formatting.lua"
7include "scripting/messages.lua"6include "scripting/messages.lua"
8include "scripting/table.lua"7include "scripting/table.lua"
9include "scripting/win_conditions/win_condition_functions.lua"8include "scripting/win_conditions/win_condition_functions.lua"
@@ -155,16 +154,14 @@
155 if candidateisteam then154 if candidateisteam then
156 candidate = (_"Team %i"):format(currentcandidate)155 candidate = (_"Team %i"):format(currentcandidate)
157 end156 end
158 local msg1 = (_"%s owns more than half of the map’s area."):format(candidate)157 local msg1 = p(_"%s owns more than half of the map’s area."):format(candidate)
159 msg1 = msg1 .. "\n"158 msg1 = msg1 .. p(ngettext("You’ve still got %i minute to prevent a victory.",
160 msg1 = msg1 .. (ngettext("You’ve still got %i minute to prevent a victory.",
161 "You’ve still got %i minutes to prevent a victory.",159 "You’ve still got %i minutes to prevent a victory.",
162 remaining_time / 60))160 remaining_time / 60))
163 :format(remaining_time / 60)161 :format(remaining_time / 60)
164162
165 local msg2 = _"You own more than half of the map’s area."163 local msg2 = p(_"You own more than half of the map’s area.")
166 msg2 = msg2 .. "\n"164 msg2 = msg2 .. p(ngettext("Keep it for %i more minute to win the game.",
167 msg2 = msg2 .. (ngettext("Keep it for %i more minute to win the game.",
168 "Keep it for %i more minutes to win the game.",165 "Keep it for %i more minutes to win the game.",
169 remaining_time / 60))166 remaining_time / 60))
170 :format(remaining_time / 60)167 :format(remaining_time / 60)
@@ -172,9 +169,9 @@
172 for idx, player in ipairs(plrs) do169 for idx, player in ipairs(plrs) do
173 if candidateisteam and currentcandidate == player.team170 if candidateisteam and currentcandidate == player.team
174 or not candidateisteam and currentcandidate == player.name then171 or not candidateisteam and currentcandidate == player.name then
175 send_message(player, game_status.title, rt(p(msg2)), {popup = true})172 send_message(player, game_status.title, msg2, {popup = true})
176 else173 else
177 send_message(player, game_status.title, rt(p(msg1)), {popup = true})174 send_message(player, game_status.title, msg1, {popup = true})
178 end175 end
179 end176 end
180 end177 end
@@ -201,10 +198,10 @@
201 p.see_all = 1198 p.see_all = 1
202 if candidateisteam and currentcandidate == p.team199 if candidateisteam and currentcandidate == p.team
203 or not candidateisteam and currentcandidate == p.name then200 or not candidateisteam and currentcandidate == p.name then
204 p:send_message(won_game_over.title, rt(won_game_over.body))201 p:send_message(won_game_over.title, won_game_over.body)
205 wl.game.report_result(p, 1, make_extra_data(p, wc_descname, wc_version, {score=_landsizes[p.number]}))202 wl.game.report_result(p, 1, make_extra_data(p, wc_descname, wc_version, {score=_landsizes[p.number]}))
206 else203 else
207 p:send_message(lost_game_over.title, rt(lost_game_over.body))204 p:send_message(lost_game_over.title, lost_game_over.body)
208 wl.game.report_result(p, 0, make_extra_data(p, wc_descname, wc_version, {score=_landsizes[p.number]}))205 wl.game.report_result(p, 0, make_extra_data(p, wc_descname, wc_version, {score=_landsizes[p.number]}))
209 end206 end
210 end207 end
211208
=== modified file 'data/scripting/win_conditions/territorial_time.lua'
--- data/scripting/win_conditions/territorial_time.lua 2016-09-17 11:29:34 +0000
+++ data/scripting/win_conditions/territorial_time.lua 2017-06-16 07:57:28 +0000
@@ -6,7 +6,6 @@
6-- here. Pull that out into a separate script and reuse.6-- here. Pull that out into a separate script and reuse.
77
8include "scripting/coroutine.lua" -- for sleep8include "scripting/coroutine.lua" -- for sleep
9include "scripting/formatting.lua"
10include "scripting/messages.lua"9include "scripting/messages.lua"
11include "scripting/table.lua"10include "scripting/table.lua"
12include "scripting/win_conditions/win_condition_functions.lua"11include "scripting/win_conditions/win_condition_functions.lua"
@@ -179,10 +178,9 @@
179 local function _status(points, has_had)178 local function _status(points, has_had)
180 local msg = ""179 local msg = ""
181 for i=1,#points do180 for i=1,#points do
182 msg = msg .. "\n"
183 if (has_had == "has") then181 if (has_had == "has") then
184 msg = msg ..182 msg = msg ..
185 listitem_bullet(183 li(
186 (wc_has_territory):bformat(184 (wc_has_territory):bformat(
187 points[i][1],185 points[i][1],
188 _percent(points[i][2], #fields),186 _percent(points[i][2], #fields),
@@ -190,7 +188,7 @@
190 #fields))188 #fields))
191 else189 else
192 msg = msg ..190 msg = msg ..
193 listitem_bullet(191 li(
194 (wc_had_territory):bformat(192 (wc_had_territory):bformat(
195 points[i][1],193 points[i][1],
196 _percent(points[i][2], #fields),194 _percent(points[i][2], #fields),
@@ -204,17 +202,15 @@
204202
205 local function _send_state(points)203 local function _send_state(points)
206 set_textdomain("win_conditions")204 set_textdomain("win_conditions")
207 local msg1 = (_"%s owns more than half of the map’s area."):format(currentcandidate)205 local msg1 = p(_"%s owns more than half of the map’s area."):format(currentcandidate)
208 msg1 = msg1 .. "<br>"206 msg1 = msg1 .. p(ngettext("You’ve still got %i minute to prevent a victory.",
209 msg1 = msg1 .. (ngettext("You’ve still got %i minute to prevent a victory.",
210 "You’ve still got %i minutes to prevent a victory.",207 "You’ve still got %i minutes to prevent a victory.",
211 remaining_time // 60))208 remaining_time // 60))
212 :format(remaining_time // 60)209 :format(remaining_time // 60)
213 msg1 = p(msg1)210 msg1 = p(msg1)
214211
215 local msg2 = _"You own more than half of the map’s area."212 local msg2 = p(_"You own more than half of the map’s area.")
216 msg2 = msg2 .. "<br>"213 msg2 = msg2 .. p(ngettext("Keep it for %i more minute to win the game.",
217 msg2 = msg2 .. (ngettext("Keep it for %i more minute to win the game.",
218 "Keep it for %i more minutes to win the game.",214 "Keep it for %i more minutes to win the game.",
219 remaining_time // 60))215 remaining_time // 60))
220 :format(remaining_time // 60)216 :format(remaining_time // 60)
@@ -225,9 +221,9 @@
225 if remaining_time < remaining_max_time and _maxpoints(points) > ( #fields / 2 ) then221 if remaining_time < remaining_max_time and _maxpoints(points) > ( #fields / 2 ) then
226 if candidateisteam and currentcandidate == team_str:format(pl.team)222 if candidateisteam and currentcandidate == team_str:format(pl.team)
227 or not candidateisteam and currentcandidate == pl.name then223 or not candidateisteam and currentcandidate == pl.name then
228 msg = msg .. msg2 .. "\n\n"224 msg = msg .. msg2 .. vspace(8)
229 else225 else
230 msg = msg .. msg1 .. "\n\n"226 msg = msg .. msg1 .. vspace(8)
231 end227 end
232 -- TRANSLATORS: Refers to "You own more than half of the map’s area. Keep it for x more minute(s) to win the game."228 -- TRANSLATORS: Refers to "You own more than half of the map’s area. Keep it for x more minute(s) to win the game."
233 msg = msg .. p((ngettext("Otherwise the game will end in %i minute.",229 msg = msg .. p((ngettext("Otherwise the game will end in %i minute.",
@@ -240,10 +236,8 @@
240 remaining_max_time // 60))236 remaining_max_time // 60))
241 :format(remaining_max_time // 60))237 :format(remaining_max_time // 60))
242 end238 end
243 msg = msg .. "\n\n"239 msg = msg .. vspace(8) .. game_status.body .. _status(points, "has")
244 msg = msg .. "</rt>" .. rt(game_status.body) .. "<rt>"240 send_message(pl, game_status.title, msg, {popup = true})
245 msg = msg .. _status(points, "has")
246 send_message(pl, game_status.title, rt(msg), {popup = true})
247 end241 end
248 end242 end
249243
@@ -295,10 +289,10 @@
295 for i=1,#points do289 for i=1,#points do
296 if points[i][1] == team_str:format(pl.team) or points[i][1] == pl.name then290 if points[i][1] == team_str:format(pl.team) or points[i][1] == pl.name then
297 if points[i][2] >= maxpoints then291 if points[i][2] >= maxpoints then
298 pl:send_message(won_game_over.title, wonmsg .. rt(_status(points, "had")))292 pl:send_message(won_game_over.title, wonmsg .. _status(points, "had"))
299 wl.game.report_result(pl, 1, make_extra_data(pl, wc_descname, wc_version, {score=_landsizes[pl.number]}))293 wl.game.report_result(pl, 1, make_extra_data(pl, wc_descname, wc_version, {score=_landsizes[pl.number]}))
300 else294 else
301 pl:send_message(lost_game_over.title, lostmsg .. rt(_status(points, "had")))295 pl:send_message(lost_game_over.title, lostmsg .. _status(points, "had"))
302 wl.game.report_result(pl, 0, make_extra_data(pl, wc_descname, wc_version, {score=_landsizes[pl.number]}))296 wl.game.report_result(pl, 0, make_extra_data(pl, wc_descname, wc_version, {score=_landsizes[pl.number]}))
303 end297 end
304 end298 end
305299
=== modified file 'data/scripting/win_conditions/win_condition_functions.lua'
--- data/scripting/win_conditions/win_condition_functions.lua 2016-03-15 08:42:41 +0000
+++ data/scripting/win_conditions/win_condition_functions.lua 2017-06-16 07:57:28 +0000
@@ -1,3 +1,4 @@
1include "scripting/richtext.lua"
1include "scripting/messages.lua"2include "scripting/messages.lua"
23
3-- RST4-- RST
45
=== modified file 'data/scripting/win_conditions/win_condition_texts.lua'
--- data/scripting/win_conditions/win_condition_texts.lua 2016-09-20 17:01:35 +0000
+++ data/scripting/win_conditions/win_condition_texts.lua 2017-06-16 07:57:28 +0000
@@ -1,13 +1,13 @@
1include "scripting/formatting.lua"1include "scripting/richtext.lua"
22
3won_game = {3won_game = {
4 title = _"Congratulations!",4 title = _"Congratulations!",
5 body = rt(p(_"You have won this game!"))5 body = p(_"You have won this game!")
6}6}
77
8lost_game = {8lost_game = {
9 title = _"You are defeated!",9 title = _"You are defeated!",
10 body = rt(p(_"You lost your last warehouse and are therefore defeated. You may continue as spectator if you want."))10 body = p(_"You lost your last warehouse and are therefore defeated. You may continue as spectator if you want.")
11}11}
1212
13won_game_over = {13won_game_over = {
@@ -23,5 +23,5 @@
23game_status = {23game_status = {
24 title = _"Status",24 title = _"Status",
25 -- TRANSLATORS: This is an overview for all players.25 -- TRANSLATORS: This is an overview for all players.
26 body = h3(_"Player overview:")26 body = h2(_"Player overview:")
27}27}
2828
=== modified file 'data/scripting/win_conditions/wood_gnome.lua'
--- data/scripting/win_conditions/wood_gnome.lua 2016-12-18 17:02:44 +0000
+++ data/scripting/win_conditions/wood_gnome.lua 2017-06-16 07:57:28 +0000
@@ -3,7 +3,6 @@
3-- =======================================================================3-- =======================================================================
44
5include "scripting/coroutine.lua" -- for sleep5include "scripting/coroutine.lua" -- for sleep
6include "scripting/formatting.lua"
7include "scripting/table.lua"6include "scripting/table.lua"
8include "scripting/win_conditions/win_condition_functions.lua"7include "scripting/win_conditions/win_condition_functions.lua"
98
@@ -92,14 +91,14 @@
92 local playerpoints = _calc_points()91 local playerpoints = _calc_points()
93 local msg = p(ngettext("The game will end in %i minute.", "The game will end in %i minutes.", remaining_time))92 local msg = p(ngettext("The game will end in %i minute.", "The game will end in %i minutes.", remaining_time))
94 :format(remaining_time)93 :format(remaining_time)
95 msg = msg .. "<p font-size=8> <br></p>" .. game_status.body94 msg = msg .. vspace(8) .. game_status.body
96 for idx,plr in ipairs(plrs) do95 for idx,plr in ipairs(plrs) do
97 local trees = (ngettext ("%i tree", "%i trees", playerpoints[plr.number]))96 local trees = (ngettext ("%i tree", "%i trees", playerpoints[plr.number]))
98 :format(playerpoints[plr.number])97 :format(playerpoints[plr.number])
99 -- TRANSLATORS: %1$s = player name, %2$s = x tree(s)98 -- TRANSLATORS: %1$s = player name, %2$s = x tree(s)
100 msg = msg .. p(_"%1$s has %2$s at the moment."):bformat(plr.name,trees)99 msg = msg .. p(_"%1$s has %2$s at the moment."):bformat(plr.name,trees)
101 end100 end
102 broadcast(plrs, game_status.title, rt(msg))101 broadcast(plrs, game_status.title, msg)
103 end102 end
104103
105 -- Start a new coroutine that checks for defeated players104 -- Start a new coroutine that checks for defeated players
@@ -143,14 +142,14 @@
143 end142 end
144 table.sort(points, function(a,b) return a[2] < b[2] end)143 table.sort(points, function(a,b) return a[2] < b[2] end)
145144
146 local msg = "<p font-size=8> <br></p>" .. game_status.body145 local msg = vspace(8) .. game_status.body
147 for idx,plr in ipairs(plrs) do146 for idx,plr in ipairs(plrs) do
148 msg = msg .. "<p font-size=8> <br></p>"147 msg = msg .. vspace(8)
149 local trees = (ngettext ("%i tree", "%i trees", playerpoints[plr.number])):format(playerpoints[plr.number])148 local trees = (ngettext ("%i tree", "%i trees", playerpoints[plr.number])):format(playerpoints[plr.number])
150 -- TRANSLATORS: %1$s = player name, %2$s = x tree(s)149 -- TRANSLATORS: %1$s = player name, %2$s = x tree(s)
151 msg = msg .. p(_"%1$s had %2$s."):bformat(plr.name,trees)150 msg = msg .. p(_"%1$s had %2$s."):bformat(plr.name,trees)
152 end151 end
153 msg = msg .. "<p font-size=8> <br></p>"152 msg = msg .. vspace(8)
154 local trees = (ngettext ("%i tree", "%i trees", playerpoints[points[#points][1].number]))153 local trees = (ngettext ("%i tree", "%i trees", playerpoints[points[#points][1].number]))
155 :format(playerpoints[points[#points][1].number])154 :format(playerpoints[points[#points][1].number])
156 -- TRANSLATORS: %1$s = player name, %2$s = x tree(s)155 -- TRANSLATORS: %1$s = player name, %2$s = x tree(s)
@@ -160,12 +159,12 @@
160 for i=1,#points-1 do159 for i=1,#points-1 do
161 privmsg = lost_game_over.body160 privmsg = lost_game_over.body
162 privmsg = privmsg .. msg161 privmsg = privmsg .. msg
163 points[i][1]:send_message(lost_game_over.title, rt(privmsg))162 points[i][1]:send_message(lost_game_over.title, privmsg)
164 wl.game.report_result(points[i][1], 0, make_extra_data(points[i][1], wc_descname, wc_version, {score=points[i][2]}))163 wl.game.report_result(points[i][1], 0, make_extra_data(points[i][1], wc_descname, wc_version, {score=points[i][2]}))
165 end164 end
166 privmsg = won_game_over.body165 privmsg = won_game_over.body
167 privmsg = privmsg .. msg166 privmsg = privmsg .. msg
168 points[#points][1]:send_message(won_game_over.title, rt(privmsg))167 points[#points][1]:send_message(won_game_over.title, privmsg)
169 wl.game.report_result(points[#points][1], 1,168 wl.game.report_result(points[#points][1], 1,
170 make_extra_data(points[#points][1], wc_descname, wc_version, {score=points[#points][2]}))169 make_extra_data(points[#points][1], wc_descname, wc_version, {score=points[#points][2]}))
171end170end

Subscribers

People subscribed via source and target branches

to status/vote changes: