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