win_condition_functions.lua

This script contains functions that are shared by different win conditions.

make_extra_data(plr, name, version[, extra])

Constructs a string containing information about the win condition. this can e.g be used to inform the meta server about it.

Parameters
  • plr (Player) – Player to calculate extra data for

  • name (string) – Name of the win-condition

  • version (integer) – Version the win-condition

  • extra (array) – list of other extra arguments that should be passed to the server. They will also be incorporated into the extra string.

Returns

the extra string that can be passed on

check_player_defeated(plrs, heading, msg, wc_name, wc_ver)

Checks whether one of the players in the list was defeated and if yes, removes that player from the list and sends him/her a message.

Parameters
  • plrs – List of Players to be checked

  • heading – Heading of the message the defeated player will get

  • msg – Message the defeated player will get

  • wc_name – Name of the win condition. If not nil, meth:wl.game.Game.report_result will be called.

  • wc_ver – Version of the win condition

Returns

nil

count_factions(plrs)

Calculates and returns the number of factions that are still involved in the running game. A faction is a team or an unteamed player.

Parameters

plrs – List the players will be saved to

Returns

the number of factions left in game

broadcast(plrs, header, msg[, options])

broadcast a message to all players using wl.game.Player.send_message. All parameters are passed literally.

broadcast_objective(header, msg, body)

broadcast an objective to all players technically, it is assigned to player1, because all players will see all objectives

Parameters
  • name – A unique name for the objective

  • title – The title to be displayed for the objective

  • body – The content text to be displayed for the objective

count_owned_valuable_fields_for_all_players(players[, attribute])

Counts all owned fields for each player.

Parameters
  • players – Table of all players

  • attribute – If this is set, only count fields that have an immovable with this attribute

Returns

a table with playernumber = count_of_owned_fields entries

rank_players(all_player_points, plrs)

Rank the players and teams according to the highest points

Parameters
  • all_player_points – A table of playernumber = points entries for all players

  • plrs – A table of all Player objects

Returns

A table with ranked player and team points, sorted by points descending. Example:

{
   -- A player without team
   {
      team = 0,
      points = 1000,
      players = {
         { "number" = 5, "points" = 1000 }
      }
   },
   -- This team has a draw with player 5
   {
      team = 1,
      points = 1000,
      players = {
         { "number" = 2, "points" = 500 }
         { "number" = 3, "points" = 400 }
         { "number" = 4, "points" = 100 }
   },
   -- Another player without team
   {
      team = 0,
      points = 800,
      players = {
         { "number" = 1, "points" = 800 }
      }
   },
}
format_remaining_time(remaining_time)

return a message that contains the remaining game time to be used when sending status meassages

Parameters

remaining_time – The remaining game time in minutes

notification_remaining_time(max_time)

Calculate the remaining game time for notifications. Should only be called within a coroutine, because the routine gets blocked. Returns the remaining time and whether the notification should popup.

To be used when sending status messages. Status messages are to be sent every 30 minutes and every 5 during the last 30 minutes, the message window pops up ever hour, 30, 20 & 10 minutes before the game ends.

Parameters

max_time – The time maximum game time in minutes