interesting metrics (idea by KrimZon) to maybe sort players in the
[divverent/nexuiz.git] / data / qcsrc / server / scores_rules.qc
1 float c1, c2, c3, c4;
2 void CheckAllowedTeams (entity for_whom);
3
4 // NOTE: SP_ constants may not be >= MAX_SCORE; ST_constants may not be >= MAX_TEAMSCORE
5 // scores that should be in all modes:
6 float ScoreRules_teams;
7 void ScoreRules_basics(float teams, float sprio, float stprio, float score_enabled)
8 {
9         float i;
10         for(i = 0; i < MAX_SCORE; ++i)
11                 ScoreInfo_SetLabel_PlayerScore(i, "", 0);
12         for(i = 0; i < MAX_TEAMSCORE; ++i)
13                 ScoreInfo_SetLabel_TeamScore(i, "", 0);
14
15         ScoreRules_teams = teams;
16
17         if(score_enabled)
18                 ScoreInfo_SetLabel_TeamScore  (ST_SCORE,        "score",     stprio);
19
20         if not(independent_players)
21                 ScoreInfo_SetLabel_PlayerScore(SP_KILLS,        "kills",     0);
22
23         ScoreInfo_SetLabel_PlayerScore(SP_DEATHS,       "deaths",    SFL_LOWER_IS_BETTER);
24
25         if not(independent_players)
26                 ScoreInfo_SetLabel_PlayerScore(SP_SUICIDES,     "suicides",  SFL_LOWER_IS_BETTER);
27
28         if(score_enabled)
29                 ScoreInfo_SetLabel_PlayerScore(SP_SCORE,        "score",     sprio);
30 }
31 void ScoreRules_basics_end()
32 {
33         ScoreInfo_Init(ScoreRules_teams);
34 }
35 void ScoreRules_generic()
36 {
37         CheckAllowedTeams(world);
38         if(teams_matter)
39         {
40                 CheckAllowedTeams(world);
41                 ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, TRUE);
42         }
43         else
44                 ScoreRules_basics(0, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, TRUE);
45         ScoreRules_basics_end();
46 }
47
48 // g_ctf
49 #define ST_CTF_CAPS 1
50 #define SP_CTF_CAPS 4
51 #define SP_CTF_PICKUPS 5
52 #define SP_CTF_DROPS 6
53 #define SP_CTF_FCKILLS 7
54 #define SP_CTF_RETURNS 8
55 void ScoreRules_ctf()
56 {
57         float sp_score, sp_caps;
58         sp_score = sp_caps = 0;
59         switch(g_ctf_win_mode)
60         {
61                 case 0: // caps only
62                         sp_caps = SFL_SORT_PRIO_PRIMARY;
63                         break;
64                 case 1: // caps, then score
65                         sp_caps = SFL_SORT_PRIO_PRIMARY;
66                         sp_score = SFL_SORT_PRIO_SECONDARY;
67                         break;
68                 case 2: // score only
69                 default:
70                         sp_caps = SFL_SORT_PRIO_SECONDARY; // looks better ;)
71                         sp_score = SFL_SORT_PRIO_PRIMARY;
72                         break;
73         }
74
75         CheckAllowedTeams(world);
76         ScoreRules_basics(2 + (c3>=0), SFL_SORT_PRIO_PRIMARY, sp_score, TRUE); // NOTE this assumes that the rogue team is team 3
77         ScoreInfo_SetLabel_TeamScore  (ST_CTF_CAPS,     "caps",      sp_caps);
78         ScoreInfo_SetLabel_PlayerScore(SP_CTF_CAPS,     "caps",      SFL_SORT_PRIO_SECONDARY);
79         ScoreInfo_SetLabel_PlayerScore(SP_CTF_PICKUPS,  "pickups",   0);
80         ScoreInfo_SetLabel_PlayerScore(SP_CTF_FCKILLS,  "fckills",   0);
81         ScoreInfo_SetLabel_PlayerScore(SP_CTF_RETURNS,  "returns",   0);
82         ScoreInfo_SetLabel_PlayerScore(SP_CTF_DROPS,    "drops",     SFL_LOWER_IS_BETTER);
83         ScoreRules_basics_end();
84 }
85
86 // g_domination
87 #define ST_DOM_TICKS 1
88 #define SP_DOM_TICKS 4
89 #define SP_DOM_TAKES 5
90 void ScoreRules_dom()
91 {
92         float sp_domticks, sp_score;
93         sp_score = sp_domticks = 0;
94         if(cvar("g_domination_disable_frags"))
95                 sp_domticks = SFL_SORT_PRIO_PRIMARY;
96         else
97                 sp_score = SFL_SORT_PRIO_PRIMARY;
98         CheckAllowedTeams(world);
99         ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), sp_score, sp_score, TRUE);
100         ScoreInfo_SetLabel_TeamScore  (ST_DOM_TICKS,    "ticks",     sp_domticks);
101         ScoreInfo_SetLabel_PlayerScore(SP_DOM_TICKS,    "ticks",     sp_domticks);
102         ScoreInfo_SetLabel_PlayerScore(SP_DOM_TAKES,    "takes",     0);
103         ScoreRules_basics_end();
104 }
105
106 // LMS stuff
107 #define SP_LMS_LIVES 4
108 #define SP_LMS_RANK 5
109 void ScoreRules_lms()
110 {
111         ScoreRules_basics(0, 0, 0, FALSE);
112         ScoreInfo_SetLabel_PlayerScore(SP_LMS_LIVES,    "lives",     SFL_SORT_PRIO_SECONDARY);
113         ScoreInfo_SetLabel_PlayerScore(SP_LMS_RANK,     "rank",      SFL_LOWER_IS_BETTER | SFL_RANK | SFL_SORT_PRIO_PRIMARY | SFL_ALLOW_HIDE);
114         ScoreRules_basics_end();
115 }
116
117 // Key hunt stuff
118 #define ST_KH_CAPS 1
119 #define SP_KH_CAPS 4
120 #define SP_KH_PUSHES 5
121 #define SP_KH_DESTROYS 6
122 #define SP_KH_PICKUPS 7
123 #define SP_KH_KCKILLS 8
124 #define SP_KH_LOSSES 9
125 void ScoreRules_kh(float teams)
126 {
127         ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, TRUE);
128         ScoreInfo_SetLabel_TeamScore  (ST_KH_CAPS,      "caps",      SFL_SORT_PRIO_SECONDARY);
129         ScoreInfo_SetLabel_PlayerScore(SP_KH_CAPS,      "caps",      SFL_SORT_PRIO_SECONDARY);
130         ScoreInfo_SetLabel_PlayerScore(SP_KH_PUSHES,    "pushes",    0);
131         ScoreInfo_SetLabel_PlayerScore(SP_KH_DESTROYS,  "destroyed", SFL_LOWER_IS_BETTER);
132         ScoreInfo_SetLabel_PlayerScore(SP_KH_PICKUPS,   "pickups",   0);
133         ScoreInfo_SetLabel_PlayerScore(SP_KH_KCKILLS,   "kckills",   0);
134         ScoreInfo_SetLabel_PlayerScore(SP_KH_LOSSES,    "losses",    SFL_LOWER_IS_BETTER);
135         ScoreRules_basics_end();
136 }
137
138 // Race stuff
139 #define ST_RACE_LAPS 1
140 #define SP_RACE_LAPS 4
141 #define SP_RACE_FASTEST 5
142 #define SP_RACE_TIME 5
143 //#define SP_RACE_RANK 6
144 void ScoreRules_race()
145 {
146         ScoreRules_basics(race_teams, 0, 0, FALSE);
147         if(race_teams)
148         {
149                 ScoreInfo_SetLabel_TeamScore(  ST_RACE_LAPS,    "laps",      SFL_SORT_PRIO_PRIMARY);
150                 ScoreInfo_SetLabel_PlayerScore(SP_RACE_LAPS,    "laps",      SFL_SORT_PRIO_PRIMARY);
151                 ScoreInfo_SetLabel_PlayerScore(SP_RACE_TIME,    "time",      SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
152                 //ScoreInfo_SetLabel_PlayerScore(SP_RACE_RANK,    "rank",      SFL_LOWER_IS_BETTER | SFL_RANK | SFL_ALLOW_HIDE);
153         }
154         else if(g_race_qualifying)
155         {
156                 ScoreInfo_SetLabel_PlayerScore(SP_RACE_FASTEST, "fastest",   SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME);
157         }
158         else
159         {
160                 //ScoreInfo_SetLabel_TeamScore(  ST_RACE_LAPS,    "laps",      0);
161                 ScoreInfo_SetLabel_PlayerScore(SP_RACE_LAPS,    "laps",      SFL_SORT_PRIO_PRIMARY);
162                 ScoreInfo_SetLabel_PlayerScore(SP_RACE_TIME,    "time",      SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
163         }
164         ScoreRules_basics_end();
165 }
166
167 // Assault stuff
168 #define ST_ASSAULT_OBJECTIVES 1
169 #define SP_ASSAULT_OBJECTIVES 4
170 void ScoreRules_assault()
171 {
172         ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, TRUE);
173         ScoreInfo_SetLabel_TeamScore(  ST_ASSAULT_OBJECTIVES,    "objectives",      SFL_SORT_PRIO_PRIMARY);
174         ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES,    "objectives",      SFL_SORT_PRIO_PRIMARY);
175         ScoreRules_basics_end();
176 }
177
178 // Nexball stuff
179 #define ST_NEXBALL_GOALS 1
180 #define SP_NEXBALL_GOALS 4
181 #define SP_NEXBALL_FAULTS 5
182 void ScoreRules_nexball(float teams)
183 {
184         ScoreRules_basics(teams, 0, 0, TRUE);
185         ScoreInfo_SetLabel_TeamScore(   ST_NEXBALL_GOALS,  "goals", SFL_SORT_PRIO_PRIMARY);
186         ScoreInfo_SetLabel_PlayerScore( SP_NEXBALL_GOALS,  "goals", SFL_SORT_PRIO_PRIMARY);
187         ScoreInfo_SetLabel_PlayerScore(SP_NEXBALL_FAULTS, "faults", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER);
188         ScoreRules_basics_end();
189 }