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