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