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