GunChleoc has proposed merging 
lp:~widelands-dev/widelands/bug-1418154-collectors-teams into lp:widelands.

Commit message:
Collectors now reports team scores as well as player scores.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1418154 in widelands: "Collectors in teams: points are shown for each 
single player"
  https://bugs.launchpad.net/widelands/+bug/1418154

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1418154-collectors-teams/+merge/294702
-- 
Your team Widelands Developers is requested to review the proposed merge of 
lp:~widelands-dev/widelands/bug-1418154-collectors-teams into lp:widelands.
=== modified file 'data/scripting/win_conditions/collectors.lua'
--- data/scripting/win_conditions/collectors.lua	2016-03-15 08:42:41 +0000
+++ data/scripting/win_conditions/collectors.lua	2016-05-14 10:42:25 +0000
@@ -31,13 +31,17 @@
    -- set the objective with the game type for all players
    broadcast_objective("win_condition", wc_descname, wc_desc)
 
-   -- Simple flowing text. One Paragraph
-   local function p(s)
-      return "<p line-spacing=3 font-size=12>" .. s .. "<br></p>" ..
-         "<p font-size=8> <br></p>"
+   local plrs = wl.Game().players
+   local teams = {}
+   for idx,plr in ipairs(plrs) do
+      if (plr.team ~= 0) then
+         if (teams[plr.team] == nil) then
+            teams[plr.team] = {}
+         end
+         table.insert(teams[plr.team], plr)
+      end
    end
 
-
    -- The list of wares that give points
    local point_table = {
       barbarians = {
@@ -93,36 +97,42 @@
        },
    }
 
-   -- Calculate the momentary points for one player
-   local function _calc_points(plr)
+   -- Calculate the momentary points for a list of players
+   local function _calc_points(players)
       set_textdomain("win_conditions")
-      local bs = array_combine(
-         plr:get_buildings(plr.tribe_name .. "_headquarters"), plr:get_buildings(plr.tribe_name .. "_warehouse"), plr:get_buildings(plr.tribe_name .. "_port")
-      )
-
-      local points = 0
-      local descr = { "</p>" .. h2((_"Status for %s"):format(plr.name)) .. "<p line-spacing=3 font-size=12>"}
-      for idx, ware in ipairs(point_table[plr.tribe_name .. "_order"]) do
-         local value = point_table[plr.tribe_name][ware]
-         local count = 0
-         for idx,b in ipairs(bs) do
-            count = count + b:get_wares(ware)
-         end
-         local lpoints = count * value
-         points = points + lpoints
-
-         local warename = wl.Game():get_ware_description(ware).descname
-         -- TRANSLATORS: For example: 'gold (3 P) x 4 = 12 P', P meaning 'Points'
-         descr[#descr+1] = listitem_bullet(_"%1$s (%2$i P) x %3$i = %4$i P"):bformat(
-            warename, value, count, lpoints
+      local team_points = 0
+      local descr = ""
+
+      for idx, plr in ipairs(players) do
+         local bs = array_combine(
+            plr:get_buildings(plr.tribe_name .. "_headquarters"), plr:get_buildings(plr.tribe_name .. "_warehouse"), plr:get_buildings(plr.tribe_name .. "_port")
          )
+
+         descr = descr .. h2((_"Status for %s"):format(plr.name))
+         local points = 0
+         for idx, ware in ipairs(point_table[plr.tribe_name .. "_order"]) do
+            local value = point_table[plr.tribe_name][ware]
+            local count = 0
+            for idx,b in ipairs(bs) do
+               count = count + b:get_wares(ware)
+            end
+            local lpoints = count * value
+            points = points + lpoints
+
+            local warename = wl.Game():get_ware_description(ware).descname
+            -- TRANSLATORS: For example: 'gold (3 P) x 4 = 12 P', P meaning 'Points'
+            descr = descr .. listitem_bullet(_"%1$s (%2$i P) x %3$i = %4$i P"):bformat(
+               warename, value, count, lpoints
+            )
+         end
+         descr = descr .. "</p>" .. h3(ngettext("Total: %i point", "Total: %i points", points)):format(points)
+         team_points = team_points + points
       end
-      descr[#descr+1] =  "</p>" .. h3(ngettext("Total: %i point", "Total: %i points", points)):format(points)
-              .. "<p line-spacing=3 font-size=12>"
-      return points, p(table.concat(descr, "\n"))
+      
+      return team_points, descr
    end
 
-   local plrs = wl.Game().players
+   
    -- Send all players the momentary game state
    local function _send_state(remaining_time, plrs)
       set_textdomain("win_conditions")
@@ -144,12 +154,21 @@
       end
       -- TRANSLATORS: Context: 'The game will end in 2 hours and 30 minutes.'
       local msg = p(_"The game will end in %s."):format(time)
-      msg = msg .. "\n\n"
 
+      -- Points for players without team
       for idx, plr in ipairs(plrs) do
-         local points, pstat = _calc_points(plr)
-
-         msg = msg .. pstat
+         if (plr.team == 0) then
+            local points, pstat = _calc_points({plr})
+            msg = msg .. "<p font-size=8> <br></p>" .. pstat
+         end
+      end
+      -- Team points
+      for idx, team in ipairs(teams) do
+         local points, pstat = _calc_points(team)
+         local message = h1((_"Status for Team %d"):format(idx))
+            .. pstat
+            .. h2(ngettext("Team Total: %i point", "Team Total: %i points", points)):format(points)
+         msg = msg .. "<p font-size=8> <br></p>" .. message
       end
 
       for idx, plr in ipairs(plrs) do
@@ -160,15 +179,29 @@
    local function _game_over(plrs)
       local points = {}
       for idx,plr in ipairs(plrs) do
-         points[#points + 1] = { plr, _calc_points(plr) }
+         if (plr.team == 0) then
+            points[#points + 1] = { plr, _calc_points({plr}) }
+         else
+            points[#points + 1] = { plr, _calc_points(teams[plr.team]) }
+         end
       end
       table.sort(points, function(a,b) return a[2] < b[2] end)
       for i=1,#points-1 do
-         points[i][1]:send_message(lost_game_over.title, lost_game_over.body)
-         wl.game.report_result(points[i][1], 0, make_extra_data(points[i][1], wc_descname, wc_version, {score=points[i][2]}))
-      end
-      points[#points][1]:send_message(won_game_over.title, won_game_over.body)
-      wl.game.report_result(points[#points][1], 1, make_extra_data(points[#points][1], wc_descname, wc_version, {score=points[#points][2]}))
+         local player = points[i][1]
+         player:send_message(lost_game_over.title, lost_game_over.body)
+         if (player.team == 0) then
+            wl.game.report_result(player, 0, make_extra_data(player, wc_descname, wc_version, {score=points[i][2]}))
+         else
+            wl.game.report_result(player, 0, make_extra_data(player, wc_descname, wc_version, {score=_calc_points({player}), team_score=points[i][2]}))
+         end
+      end
+      local player = points[#points][1]
+      player:send_message(won_game_over.title, won_game_over.body)
+      if (player.team == 0) then
+         wl.game.report_result(player, 1, make_extra_data(player, wc_descname, wc_version, {score=points[#points][2]}))
+      else
+         wl.game.report_result(player, 1, make_extra_data(player, wc_descname, wc_version, {score=_calc_points({player}), team_score=points[#points][2]}))
+      end
    end
 
    -- Instantiate the hook to calculate points

=== modified file 'src/wui/game_summary.cc'
--- src/wui/game_summary.cc	2016-02-18 18:27:52 +0000
+++ src/wui/game_summary.cc	2016-05-14 10:42:25 +0000
@@ -70,7 +70,7 @@
 	hbox1->add_space(PADDING);
 
 	UI::Box * info_box = new UI::Box(hbox1, 0, 0, UI::Box::Vertical, 0, 0);
-	info_area_label_ = new UI::Textarea(info_box, _("Player info:"));
+	info_area_label_ = new UI::Textarea(info_box, _("Player Info:"));
 	info_box->add(info_area_label_, UI::Align::kLeft);
 	info_area_ = new UI::MultilineTextarea(
 						  info_box, 0, 0, 130,
@@ -275,6 +275,9 @@
 		if (key == "score") {
 			info_str +=
 				(boost::format("%1% : %2%\n") % _("Score") % pair.at(1)).str();
+		} else if (key == "team_score") {
+			info_str +=
+				(boost::format("%1% : %2%\n") % _("Team Score") % pair.at(1)).str();
 		} else if (key == "resign_reason") {
 			info_str +=
 				(boost::format("%1%\n") % pair.at(1)).str();

_______________________________________________
Mailing list: https://launchpad.net/~widelands-dev
Post to     : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to