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