← Back to team overview

widelands-dev team mailing list archive

Re: [Merge] lp:~widelands-dev/widelands/collectors_notification into lp:widelands

 

I'm going to add more info to the notification_remaining_time() function.

Since I wanted this to be in place for build 20, I'm going to address count_factions() later. I'd like to unify more code, were possible. But this would also involve some changes to strings.

Diff comments:

> === modified file 'data/scripting/win_conditions/collectors.lua'
> --- data/scripting/win_conditions/collectors.lua	2018-10-13 08:51:51 +0000
> +++ data/scripting/win_conditions/collectors.lua	2019-01-02 13:47:40 +0000
> @@ -28,7 +28,11 @@
>  
>     -- set the objective with the game type for all players
>     broadcast_objective("win_condition", wc_descname, wc_desc)
> -
> +   
> +   -- set the maximum game time of 4 hours
> +   local max_time = 4 * 60
> +   
> +   local game = wl.Game()
>     local plrs = wl.Game().players

I thought about this but the same variable is used in wood gnome & territorial, so I'd like to keep this as uniform as possible.

>     local teams = {}
>     for idx,plr in ipairs(plrs) do
> @@ -221,10 +199,14 @@
>              lost_or_won = 1
>              player:send_message(won_game_over.title, won_game_over.body)
>           end
> -         if (player.team == 0) then
> -            wl.game.report_result(player, lost_or_won, make_extra_data(player, wc_descname, wc_version, {score=info[2]}))
> +         if (count_factions(plrs) > 1) then

Going to do this in the next iteration.

> +            if (player.team == 0) then
> +               wl.game.report_result(player, lost_or_won, make_extra_data(player, wc_descname, wc_version, {score=info[2]}))
> +            else
> +               wl.game.report_result(player, lost_or_won, make_extra_data(player, wc_descname, wc_version, {score=info[3], team_score=info[2]}))
> +            end
>           else
> -            wl.game.report_result(player, lost_or_won, make_extra_data(player, wc_descname, wc_version, {score=info[3], team_score=info[2]}))
> +            wl.game.report_result(player, lost_or_won)
>           end
>        end
>     end
> 
> === modified file 'data/scripting/win_conditions/win_condition_functions.lua'
> --- data/scripting/win_conditions/win_condition_functions.lua	2018-09-28 17:20:32 +0000
> +++ data/scripting/win_conditions/win_condition_functions.lua	2019-01-02 13:47:40 +0000
> @@ -237,3 +237,59 @@
>     table.sort(ranked_players_and_teams, function(a,b) return a["points"] > b["points"] end)
>     return ranked_players_and_teams
>  end
> +
> +-- RST
> +-- .. function:: format_remaining_time(remaining_time)
> +--
> +--    return a message that contains the remaining game time
> +--    to be used when sending status meassages
> +--
> +--    :arg remaining_time:    The remaining game time in minutes
> +function format_remaining_time(remaining_time)
> +   local h = 0
> +   local m = 60
> +   local time = ""
> +   set_textdomain("win_conditions")
> +   
> +   if (remaining_time ~= 60) then
> +      h = math.floor(remaining_time / 60)
> +      m = remaining_time % 60
> +   end
> +
> +   if ((h > 0) and (m > 0)) then
> +      -- TRANSLATORS: Context: 'The game will end in 2 hours and 30 minutes.'
> +      time = (ngettext("%1% hour and %2% minutes", "%1% hours and %2% minutes", h, m)):bformat(h, m)
> +   elseif m > 0 then
> +      -- TRANSLATORS: Context: 'The game will end in 30 minutes.'
> +      time = (ngettext("%i minute", "%i minutes", m)):format(m)
> +   else
> +      -- TRANSLATORS: Context: 'The game will end in 2 hours.'
> +      time = (ngettext("%1% hour", "%1% hours", h)):bformat(h)
> +   end
> +   -- TRANSLATORS: Context: 'The game will end in (2 hours and) 30 minutes.'
> +   return p(_"The game will end in %s."):format(time)
> +end
> +
> +-- RST
> +-- .. function:: notification_remaining_time(max_time)
> +--
> +--    calculate the remaining game time for notifications 
> +--    returns the remaining time and whether the notification should popup
> +--    to be used when sending status meassages
> +--    status messages are to be send every 30 minutes and every 5 during the last 30 minutes
> +--    the message window pops up ever hour 30, 20 & 10 minutes berfore the game ends.

Will do so.

> +--
> +--    :arg max_time:    The time maximum game time in minutes
> +function notification_remaining_time(max_time, remaining_time)
> +   local show_popup = false
> +   if (wl.Game().time < ((max_time - 30) * 60 * 1000)) then --
> +      wake_me(wl.Game().time + (30 * 60 * 1000)) -- 30 minutes
> +      remaining_time = remaining_time - 30
> +      if (remaining_time % 60 == 0) or (remaining_time == 30) then show_popup = true end
> +   else
> +      wake_me(wl.Game().time + (300 * 1000)) --5 Minutes
> +      remaining_time = remaining_time - 5
> +      if ((remaining_time ~= 0) and (remaining_time % 10 == 0)) then show_popup = true end
> +   end
> +   return remaining_time, show_popup
> +end
> \ No newline at end of file


-- 
https://code.launchpad.net/~widelands-dev/widelands/collectors_notification/+merge/361334
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/collectors_notification.


References