3 #include <common/scores.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 * \brief Returns the player's score.
29 * \param[in] player Player to inspect.
30 * \param[in] scorefield Field of the score.
31 * \return Player's score.
33 #define PlayerScore_Get(player, scorefield) PlayerScore_Add(player, scorefield, 0)
36 * Initialize the score of this player if needed.
37 * Does nothing in teamplay.
38 * Use that when a spectator becomes a player.
39 * Returns whether clearing has been performed
41 float PlayerScore_Clear(entity player);
44 * Adds a score to the player's team's scores.
45 * NEVER call this if team has not been set yet!
46 * Returns the new score.
48 float TeamScore_Add(entity player, float scorefield, float score);
51 * Adds a score to the given team.
52 * NEVER call this if team has not been set yet!
53 * Returns the new score.
55 float TeamScore_AddToTeam(float t, float scorefield, float score);
58 * Returns a value indicating the team score (and higher is better).
60 float TeamScore_GetCompareValue(float t);
63 * Adds a score to both the player and the team. Returns the team score if
64 * possible, otherwise the player score.
66 float PlayerTeamScore_Add(entity player, PlayerScoreField pscorefield, float tscorefield, float score);
69 * Adds to the generic score fields for both the player and the team.
71 #define PlayerTeamScore_AddScore(p, s) PlayerTeamScore_Add(p, SP_SCORE, ST_SCORE, s)
74 * Set the label of a team score item, as well as the scoring flags.
76 void ScoreInfo_SetLabel_TeamScore(float i, string label, float scoreflags);
79 * Set the label of a player score item, as well as the scoring flags.
81 void ScoreInfo_SetLabel_PlayerScore(PlayerScoreField i, string label, float scoreflags);
84 * Initialize the scores info for the given number of teams.
85 * Set all labels right before this call.
87 void ScoreInfo_Init(float teams);
90 * Clear ALL scores (for ready-restart).
92 void Score_ClearAll();
95 * Prints the scores to the console of a player.
97 void Score_NicePrint(entity to);
100 * Sets the following results for the current scores entities.
102 void WinningConditionHelper(entity this);
103 float WinningConditionHelper_topscore; ///< highest score
104 float WinningConditionHelper_secondscore; ///< second highest score
105 float WinningConditionHelper_winnerteam; ///< the color of the winning team, or -1 if none
106 float WinningConditionHelper_secondteam; ///< the color of the second team, or -1 if none
107 float WinningConditionHelper_equality; ///< we have no winner
108 entity WinningConditionHelper_winner; ///< the winning player, or NULL if none
109 entity WinningConditionHelper_second; ///< the second player, or NULL if none
110 float WinningConditionHelper_lowerisbetter; ///< lower is better, duh
111 float WinningConditionHelper_zeroisworst; ///< zero is worst, duh
112 #define WINNINGCONDITIONHELPER_LOWERISBETTER_WORST 999999999
115 * Returns score strings for eventlog etc.
116 * When called with NULL, or 0, as argument, they return the labels in the
118 * The strings are comma separated; labels that end with !! designate primary,
119 * labels that end with ! designate high priority.
120 * Labels get an appended < if the scores are better if smaller (e.g. deaths).
121 * High priorities always come first.
122 * Example label string: score!!,kills,deaths<,suicides<
123 * If shortString is set, only the sort keys are returned.
125 string GetPlayerScoreString(entity pl, float shortString);
126 string GetTeamScoreString(float tm, float shortString);
129 * Sorts the players and stores their place in the given field, starting with
130 * 1. Non-players get 0 written into that field.
131 * Returns the beginning of a sorted chain of the non-spectators.
132 * teams: >0: sort by teams first (always strict ordering); <0: sort by teams only (respects strict flag)
133 * strict: return a strict ordering
134 * nospectators: exclude spectators
136 entity PlayerScore_Sort(.float field, float teams, float strict, float nospectators);