3 #include <common/constants.qh>
5 entity scores_initialized; // non-NULL when scores labels/rules have been set
9 * Attaches a PlayerScore entity to a player. Use that in ClientConnect.
10 * Remember to detach it in ClientDisconnect!
12 void PlayerScore_Attach(entity player);
15 * Detaches a PlayerScore entity from the player. Use that in ClientDisconnect.
17 void PlayerScore_Detach(entity player);
20 * Adds a score to the player's scores.
21 * NEVER call this if PlayerScore_Attach has not been called yet!
22 * Means: FIXME make players unable to join the game when not called ClientConnect yet.
23 * Returns the new score.
25 float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score);
28 * Initialize the score of this player if needed.
29 * Does nothing in teamplay.
30 * Use that when a spectator becomes a player.
31 * Returns whether clearing has been performed
33 float PlayerScore_Clear(entity player);
36 * Adds a score to the player's team's scores.
37 * NEVER call this if team has not been set yet!
38 * Returns the new score.
40 float TeamScore_Add(entity player, float scorefield, float score);
43 * Adds a score to the given team.
44 * NEVER call this if team has not been set yet!
45 * Returns the new score.
47 float TeamScore_AddToTeam(float t, float scorefield, float score);
50 * Returns a value indicating the team score (and higher is better).
52 float TeamScore_GetCompareValue(float t);
55 * Adds a score to both the player and the team. Returns the team score if
56 * possible, otherwise the player score.
58 float PlayerTeamScore_Add(entity player, PlayerScoreField pscorefield, float tscorefield, float score);
61 * Adds to the generic score fields for both the player and the team.
63 #define PlayerTeamScore_AddScore(p, s) PlayerTeamScore_Add(p, SP_SCORE, ST_SCORE, s)
66 * Set the label of a team score item, as well as the scoring flags.
68 void ScoreInfo_SetLabel_TeamScore(float i, string label, float scoreflags);
71 * Set the label of a player score item, as well as the scoring flags.
73 void ScoreInfo_SetLabel_PlayerScore(PlayerScoreField i, string label, float scoreflags);
76 * Initialize the scores info for the given number of teams.
77 * Set all labels right before this call.
79 void ScoreInfo_Init(float teams);
82 * Clear ALL scores (for ready-restart).
84 void Score_ClearAll();
87 * Prints the scores to the console of a player.
89 void Score_NicePrint(entity to);
92 * Sets the following results for the current scores entities.
94 void WinningConditionHelper(entity this);
95 float WinningConditionHelper_topscore; ///< highest score
96 float WinningConditionHelper_secondscore; ///< second highest score
97 float WinningConditionHelper_winnerteam; ///< the color of the winning team, or -1 if none
98 float WinningConditionHelper_secondteam; ///< the color of the second team, or -1 if none
99 float WinningConditionHelper_equality; ///< we have no winner
100 entity WinningConditionHelper_winner; ///< the winning player, or NULL if none
101 entity WinningConditionHelper_second; ///< the second player, or NULL if none
102 float WinningConditionHelper_lowerisbetter; ///< lower is better, duh
103 float WinningConditionHelper_zeroisworst; ///< zero is worst, duh
104 #define WINNINGCONDITIONHELPER_LOWERISBETTER_WORST 999999999
107 * Returns score strings for eventlog etc.
108 * When called with NULL, or 0, as argument, they return the labels in the
110 * The strings are comma separated; labels that end with !! designate primary,
111 * labels that end with ! designate high priority.
112 * Labels get an appended < if the scores are better if smaller (e.g. deaths).
113 * High priorities always come first.
114 * Example label string: score!!,kills,deaths<,suicides<
115 * If shortString is set, only the sort keys are returned.
117 string GetPlayerScoreString(entity pl, float shortString);
118 string GetTeamScoreString(float tm, float shortString);
121 * Sorts the players and stores their place in the given field, starting with
122 * 1. Non-players get 0 written into that field.
123 * Returns the beginning of a sorted chain of the non-spectators.
124 * teams: >0: sort by teams first (always strict ordering); <0: sort by teams only (respects strict flag)
125 * strict: return a strict ordering
126 * nospectators: exclude spectators
128 entity PlayerScore_Sort(.float field, float teams, float strict, float nospectators);