]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/scores.qh
Merge branch 'master' into Mario/weaponarena_available
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / scores.qh
1 #pragma once
2
3 #include <common/scores.qh>
4
5 entity scores_initialized; // non-NULL when scores labels/rules have been set
6 .float scoreboard_pos;
7
8 /**
9  * Attaches a PlayerScore entity to a player. Use that in ClientConnect.
10  * Remember to detach it in ClientDisconnect!
11  */
12 void PlayerScore_Attach(entity player);
13
14 /**
15  * Detaches a PlayerScore entity from the player. Use that in ClientDisconnect.
16  */
17 void PlayerScore_Detach(entity player);
18
19 /**
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.
24  */
25 float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score);
26
27 /**
28  * Sets the player's score to the score parameter.
29  * NEVER call this if PlayerScore_Attach has not been called yet!
30  * Means: FIXME make players unable to join the game when not called ClientConnect yet.
31  * Returns the new (or old if unchanged) score.
32  */
33 float PlayerScore_Set(entity player, PlayerScoreField scorefield, float score);
34
35 /**
36  * \brief Returns the player's score.
37  * \param[in] player Player to inspect.
38  * \param[in] scorefield Field of the score.
39  * \return Player's score.
40  */
41 #define PlayerScore_Get(player, scorefield) PlayerScore_Add(player, scorefield, 0)
42
43 /**
44  * Initialize the score of this player if needed.
45  * Does nothing in teamplay.
46  * Use that when a spectator becomes a player.
47  * Returns whether clearing has been performed
48  */
49 float PlayerScore_Clear(entity player);
50
51 /**
52  * Adds a score to the player's team's scores.
53  * NEVER call this if team has not been set yet!
54  * Returns the new score.
55  */
56 float TeamScore_Add(entity player, float scorefield, float score);
57
58 /**
59  * Adds a score to the given team.
60  * NEVER call this if team has not been set yet!
61  * Returns the new score.
62  */
63 float TeamScore_AddToTeam(int t, float scorefield, float score);
64
65 /**
66  * Returns a value indicating the team score (and higher is better).
67  */
68 float TeamScore_GetCompareValue(float t);
69
70 /**
71  * Adds a score to both the player and the team. Returns the team score if
72  * possible, otherwise the player score.
73  */
74 float PlayerTeamScore_Add(entity player, PlayerScoreField pscorefield, float tscorefield, float score);
75
76 /**
77  * Set the label of a team score item, as well as the scoring flags.
78  */
79 void ScoreInfo_SetLabel_TeamScore(float i, string label, float scoreflags);
80
81 /**
82  * Set the label of a player score item, as well as the scoring flags.
83  */
84 void ScoreInfo_SetLabel_PlayerScore(PlayerScoreField i, string label, float scoreflags);
85
86 /**
87  * Initialize the scores info for the given number of teams.
88  * Set all labels right before this call.
89  */
90 void ScoreInfo_Init(float teams);
91
92 /**
93  * Clear ALL scores (for ready-restart).
94  */
95 void Score_ClearAll();
96
97 /**
98  * Prints the scores to the console of a player.
99  */
100 void Score_NicePrint(entity to);
101
102 /**
103  * Sets the following results for the current scores entities.
104  */
105 void WinningConditionHelper(entity this);
106 float WinningConditionHelper_topscore;      ///< highest score
107 float WinningConditionHelper_secondscore;   ///< second highest score
108 float WinningConditionHelper_winnerteam;    ///< the color of the winning team, or -1 if none
109 float WinningConditionHelper_secondteam;    ///< the color of the second team, or -1 if none
110 float WinningConditionHelper_equality;      ///< we have no winner
111 entity WinningConditionHelper_winner;       ///< the winning player, or NULL if none
112 entity WinningConditionHelper_second;       ///< the second player, or NULL if none
113 float WinningConditionHelper_lowerisbetter; ///< lower is better, duh
114 float WinningConditionHelper_zeroisworst;   ///< zero is worst, duh
115 #define WINNINGCONDITIONHELPER_LOWERISBETTER_WORST 999999999
116
117 /**
118  * Returns score strings for eventlog etc.
119  * When called with NULL, or 0, as argument, they return the labels in the
120  * same order.
121  * The strings are comma separated; labels that end with !! designate primary,
122  * labels that end with ! designate high priority.
123  * Labels get an appended < if the scores are better if smaller (e.g. deaths).
124  * High priorities always come first.
125  * Example label string: score!!,kills,deaths<,suicides<
126  * If shortString is set, only the sort keys are returned.
127  */
128 string GetPlayerScoreString(entity pl, float shortString);
129 string GetTeamScoreString(float tm, float shortString);
130
131 /**
132  * Sorts the players and stores their place in the given field, starting with
133  * 1. Non-players get 0 written into that field.
134  * Returns the beginning of a sorted chain of the non-spectators.
135  * teams: >0: sort by teams first (always strict ordering); <0: sort by teams only (respects strict flag)
136  * strict: return a strict ordering
137  * nospectators: exclude spectators
138  */
139 entity PlayerScore_Sort(.float field, float teams, float strict, float nospectators);