]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/scores.qc
bloodloss
[divverent/nexuiz.git] / data / qcsrc / server / scores.qc
1 .entity scorekeeper;
2 entity teamscorekeepers[16];
3 string scores_label[MAX_SCORE];
4 float scores_flags[MAX_SCORE];
5 string teamscores_label[MAX_TEAMSCORE];
6 float teamscores_flags[MAX_TEAMSCORE];
7 float teamscores_entities_count;
8 var .float scores_primary;
9 var .float teamscores_primary;
10 float scores_flags_primary;
11 float teamscores_flags_primary;
12
13 vector ScoreField_Compare(entity t1, entity t2, .float field, float fieldflags, vector previous) // returns: cmp value, best prio
14 {
15         if(!(fieldflags & SFL_SORT_PRIO_MASK)) // column does not sort
16                 return previous;
17         if(fieldflags & SFL_SORT_PRIO_MASK < previous_y)
18                 return previous;
19         if(t1.field == t2.field)
20                 return previous;
21
22         previous_y = fieldflags & SFL_SORT_PRIO_MASK;
23
24         if(fieldflags & SFL_ZERO_IS_WORST)
25         {
26                 if(t1.field == 0)
27                 {
28                         previous_x = -1;
29                         return previous;
30                 }
31                 else if(t2.field == 0)
32                 {
33                         previous_x = +1;
34                         return previous;
35                 }
36         }
37
38         if(fieldflags & SFL_LOWER_IS_BETTER)
39                 previous_x = (t2.field - t1.field);
40         else
41                 previous_x = (t1.field - t2.field);
42
43         return previous;
44 }
45
46 /*
47  * teamscore entities
48  */
49
50 float TeamScore_SendEntity(entity to, float sendflags)
51 {
52         float i;
53
54         WriteByte(MSG_ENTITY, ENT_CLIENT_TEAMSCORES);
55         WriteByte(MSG_ENTITY, self.team - 1);
56 #if MAX_TEAMSCORE <= 3
57         for(i = 0; i < MAX_TEAMSCORE; ++i)
58                 WriteShort(MSG_ENTITY, self.teamscores[i]);
59 #else
60 #if MAX_TEAMSCORE <= 8
61         WriteByte(MSG_ENTITY, sendflags);
62 #else
63         WriteShort(MSG_ENTITY, sendflags);
64 #endif
65         float p;
66         for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
67                 if(sendflags & p)
68                         WriteShort(MSG_ENTITY, self.teamscores[i]);
69 #endif
70
71         return TRUE;
72 }
73
74 void TeamScore_Spawn(float t, string name)
75 {
76         entity ts;
77         ts = spawn();
78         ts.classname = "csqc_score_team";
79         ts.netname = name; // not used yet, FIXME
80         ts.team = t;
81         Net_LinkEntity(ts, FALSE, 0, TeamScore_SendEntity);
82         teamscorekeepers[t - 1] = ts;
83         ++teamscores_entities_count;
84 }
85
86 float TeamScore_AddToTeam(float t, float scorefield, float score)
87 {
88         entity s;
89
90         if(gameover)
91                 score = 0;
92
93         if(!scores_initialized) return 0; // FIXME remove this when everything uses this system
94         if(t <= 0 || t >= 16)
95                 error("Adding score to invalid team!");
96         s = teamscorekeepers[t - 1];
97         if(!s)
98                 error("Adding score to unknown team!");
99         if(score)
100                 if(teamscores_label[scorefield] != "")
101                         s.SendFlags |= pow(2, scorefield);
102         return (s.(teamscores[scorefield]) += score);
103 }
104
105 float TeamScore_Add(entity player, float scorefield, float score)
106 {
107         return TeamScore_AddToTeam(player.team, scorefield, score);
108 }
109
110 float TeamScore_Compare(entity t1, entity t2)
111 {
112         if(!t1 || !t2) return (!t2) - !t1;
113
114         vector result;
115         float i;
116         for(i = 0; i < MAX_TEAMSCORE; ++i)
117         {
118                 var .float f;
119                 f = teamscores[i];
120                 result = ScoreField_Compare(t1, t2, f, teamscores_flags[i], result);
121         }
122         return result_x;
123 }
124
125 /*
126  * the scoreinfo entity
127  */
128
129 void ScoreInfo_SetLabel_PlayerScore(float i, string label, float scoreflags)
130 {
131         scores_label[i] = label;
132         scores_flags[i] = scoreflags;
133         if(scoreflags & SFL_SORT_PRIO_MASK == SFL_SORT_PRIO_PRIMARY)
134         {
135                 scores_primary = scores[i];
136                 scores_flags_primary = scoreflags;
137         }
138 }
139
140 void ScoreInfo_SetLabel_TeamScore(float i, string label, float scoreflags)
141 {
142         teamscores_label[i] = label;
143         teamscores_flags[i] = scoreflags;
144         if(scoreflags & SFL_SORT_PRIO_MASK == SFL_SORT_PRIO_PRIMARY)
145         {
146                 teamscores_primary = teamscores[i];
147                 teamscores_flags_primary = scoreflags;
148         }
149 }
150
151 float ScoreInfo_SendEntity(entity to, float sf)
152 {
153         float i;
154         WriteByte(MSG_ENTITY, ENT_CLIENT_SCORES_INFO);
155         WriteByte(MSG_ENTITY, game);
156         for(i = 0; i < MAX_SCORE; ++i)
157         {
158                 WriteString(MSG_ENTITY, scores_label[i]);
159                 WriteByte(MSG_ENTITY, scores_flags[i]);
160         }
161         for(i = 0; i < MAX_TEAMSCORE; ++i)
162         {
163                 WriteString(MSG_ENTITY, teamscores_label[i]);
164                 WriteByte(MSG_ENTITY, teamscores_flags[i]);
165         }
166         return TRUE;
167 }
168
169 void ScoreInfo_Init(float teams)
170 {
171         if(scores_initialized)
172         {
173                 scores_initialized.SendFlags |= 1; // force a resend
174         }
175         else
176         {
177                 scores_initialized = spawn();
178                 scores_initialized.classname = "ent_client_scoreinfo";
179                 Net_LinkEntity(scores_initialized, FALSE, 0, ScoreInfo_SendEntity);
180         }
181         if(teams >= 1)
182                 TeamScore_Spawn(COLOR_TEAM1, "Red");
183         if(teams >= 2)
184                 TeamScore_Spawn(COLOR_TEAM2, "Blue");
185         if(teams >= 3)
186                 TeamScore_Spawn(COLOR_TEAM3, "Yellow");
187         if(teams >= 4)
188                 TeamScore_Spawn(COLOR_TEAM4, "Pink");
189 }
190
191 /*
192  * per-player score entities
193  */
194
195 float PlayerScore_SendEntity(entity to, float sendflags)
196 {
197         float i;
198
199         WriteByte(MSG_ENTITY, ENT_CLIENT_SCORES);
200         WriteByte(MSG_ENTITY, num_for_edict(self.owner));
201 #if MAX_SCORE <= 3
202         for(i = 0; i < MAX_SCORE; ++i)
203                 WriteShort(MSG_ENTITY, self.scores[i]);
204 #else
205 #if MAX_SCORE <= 8
206         WriteByte(MSG_ENTITY, sendflags);
207 #else
208         WriteShort(MSG_ENTITY, sendflags);
209 #endif
210         float p;
211         for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
212                 if(sendflags & p)
213                         WriteShort(MSG_ENTITY, self.scores[i]);
214 #endif
215
216         return TRUE;
217 }
218
219 void PlayerScore_Clear(entity player)
220 {
221         entity sk;
222         float i;
223
224         if(teamscores_entities_count)
225                 return;
226         if(g_lms) return;
227         if(g_arena) return;
228         if(g_race && !g_race_qualifying) return;
229
230         sk = player.scorekeeper;
231         for(i = 0; i < MAX_SCORE; ++i)
232         {
233                 if(sk.(scores[i]) != 0)
234                         if(scores_label[i] != "")
235                                 sk.SendFlags |= pow(2, i);
236                 sk.(scores[i]) = 0;
237         }
238 }
239
240 void Score_ClearAll()
241 {
242         entity p, sk;
243         float i, t;
244         FOR_EACH_CLIENTSLOT(p)
245         {
246                 sk = p.scorekeeper;
247                 if(!sk)
248                         continue;
249                 for(i = 0; i < MAX_SCORE; ++i)
250                 {
251                         if(sk.(scores[i]) != 0)
252                                 if(scores_label[i] != "")
253                                         sk.SendFlags |= pow(2, i);
254                         sk.(scores[i]) = 0;
255                 }
256         }
257         for(t = 0; t < 16; ++t)
258         {
259                 sk = teamscorekeepers[t];
260                 if(!sk)
261                         continue;
262                 for(i = 0; i < MAX_TEAMSCORE; ++i)
263                 {
264                         if(sk.(teamscores[i]) != 0)
265                                 if(teamscores_label[i] != "")
266                                         sk.SendFlags |= pow(2, i);
267                         sk.(teamscores[i]) = 0;
268                 }
269         }
270 }
271
272 void PlayerScore_Attach(entity player)
273 {
274         entity sk;
275         if(player.scorekeeper)
276                 error("player already has a scorekeeper");
277         sk = spawn();
278         sk.owner = player;
279         Net_LinkEntity(sk, FALSE, 0, PlayerScore_SendEntity);
280         player.scorekeeper = sk;
281 }
282
283 void PlayerScore_Detach(entity player)
284 {
285         if(!player.scorekeeper)
286                 error("player has no scorekeeper");
287         remove(player.scorekeeper);
288         player.scorekeeper = world;
289 }
290
291 float PlayerScore_Add(entity player, float scorefield, float score)
292 {
293         entity s;
294
295         if(gameover)
296                 score = 0;
297
298         if(!scores_initialized) return 0; // FIXME remove this when everything uses this system
299         s = player.scorekeeper;
300         if(!s)
301                 error("Adding score to unknown player!");
302         if(score)
303                 if(scores_label[scorefield] != "")
304                         s.SendFlags |= pow(2, scorefield);
305         return (s.(scores[scorefield]) += score);
306 }
307
308 float PlayerTeamScore_Add(entity player, float pscorefield, float tscorefield, float score)
309 {
310         float r;
311         r = PlayerScore_Add(player, pscorefield, score);
312         if(teamscores_entities_count) // only for teamplay
313                 r = TeamScore_Add(player, tscorefield, score);
314         return r;
315 }
316
317 float PlayerScore_Compare(entity t1, entity t2)
318 {
319         if(!t1 || !t2) return (!t2) - !t1;
320
321         vector result;
322         float i;
323         for(i = 0; i < MAX_SCORE; ++i)
324         {
325                 var .float f;
326                 f = scores[i];
327                 result = ScoreField_Compare(t1, t2, f, scores_flags[i], result);
328         }
329         return result_x;
330 }
331
332 void WinningConditionHelper()
333 {
334         float c;
335         string s;
336         entity p;
337         float fullstatus;
338
339         s = GetGametype();
340         s = strcat(s, ":", cvar_string("g_nexuizversion"));
341         s = strcat(s, "::", GetPlayerScoreString(world, 2)); // make this 1 once we can
342
343         fullstatus = cvar("g_full_getstatus_responses");
344
345         if(teamscores_entities_count)
346         {
347                 float t;
348
349                 s = strcat(s, ":", GetTeamScoreString(0, 1));
350                 for(t = 0; t < 16; ++t)
351                         if(teamscorekeepers[t])
352                                 s = strcat(s, ":", ftos(t+1), ":", GetTeamScoreString(t+1, 1));
353
354                 WinningConditionHelper_equality = 0;
355                 WinningConditionHelper_winnerteam = 0;
356                 for(t = 1; t < 16; ++t)
357                 {
358                         entity sk1, sk2;
359                         sk1 = teamscorekeepers[WinningConditionHelper_winnerteam];
360                         sk2 = teamscorekeepers[t];
361                         c = TeamScore_Compare(sk1, sk2);
362                         if(c == 0)
363                                 WinningConditionHelper_equality = 1;
364                         else if(c < 0)
365                         {
366                                 WinningConditionHelper_equality = 0;
367                                 WinningConditionHelper_winnerteam = t;
368                         }
369                 }
370
371                 WinningConditionHelper_topscore = teamscorekeepers[WinningConditionHelper_winnerteam].teamscores_primary;
372                 WinningConditionHelper_lowerisbetter = (teamscores_flags_primary & SFL_LOWER_IS_BETTER);
373                 WinningConditionHelper_zeroisworst = (teamscores_flags_primary & SFL_ZERO_IS_WORST);
374
375                 if(teamscores_flags_primary & SFL_TIME)
376                         WinningConditionHelper_topscore /= 10;
377
378                 if(WinningConditionHelper_equality)
379                         WinningConditionHelper_winnerteam = -1;
380
381                 WinningConditionHelper_winner = world;
382                 if(WinningConditionHelper_equality)
383                         WinningConditionHelper_winnerteam = -1;
384                 else
385                         ++WinningConditionHelper_winnerteam; // map to Nexuiz team numbers (as opposed to colors)
386
387                 if(WinningConditionHelper_topscore == 0)
388                 {
389                         if(scores_flags_primary & SFL_ZERO_IS_WORST)
390                         {
391                                 if(WinningConditionHelper_lowerisbetter)
392                                         WinningConditionHelper_topscore = 999999999;
393                                 else
394                                         WinningConditionHelper_topscore = -999999999;
395                         }
396                         WinningConditionHelper_equality = 0;
397                 }
398         }
399         else
400         {
401                 WinningConditionHelper_equality = 0;
402                 WinningConditionHelper_winner = world;
403                 FOR_EACH_PLAYER(p)
404                 {
405                         c = PlayerScore_Compare(WinningConditionHelper_winner.scorekeeper, p.scorekeeper);
406                         if(c == 0)
407                                 WinningConditionHelper_equality = 1;
408                         else if(c < 0)
409                         {
410                                 WinningConditionHelper_equality = 0;
411                                 WinningConditionHelper_winner = p;
412                         }
413                 }
414
415                 WinningConditionHelper_topscore = WinningConditionHelper_winner.scorekeeper.scores_primary;
416                 WinningConditionHelper_lowerisbetter = (scores_flags_primary & SFL_LOWER_IS_BETTER);
417                 WinningConditionHelper_zeroisworst = (teamscores_flags_primary & SFL_ZERO_IS_WORST);
418
419                 if(teamscores_flags_primary & SFL_TIME)
420                         WinningConditionHelper_topscore /= 10;
421
422                 WinningConditionHelper_winnerteam = -1;
423                 if(WinningConditionHelper_equality)
424                         WinningConditionHelper_winner = world;
425
426                 if(WinningConditionHelper_topscore == 0)
427                 {
428                         if(scores_flags_primary & SFL_ZERO_IS_WORST)
429                         {
430                                 if(WinningConditionHelper_lowerisbetter)
431                                         WinningConditionHelper_topscore = 999999999;
432                                 else
433                                         WinningConditionHelper_topscore = -999999999;
434                         }
435                         WinningConditionHelper_equality = 0;
436                 }
437         }
438
439         if(worldstatus)
440                 strunzone(worldstatus);
441         worldstatus = strzone(s);
442
443         FOR_EACH_CLIENT(p)
444         {
445                 if(fullstatus)
446                 {
447                         s = GetPlayerScoreString(p, 1);
448                         if(clienttype(p) == CLIENTTYPE_REAL)
449                                 s = strcat(s, ":human");
450                         else
451                                 s = strcat(s, ":bot");
452                         if(p.classname == "player" || g_arena || g_lms)
453                                 s = strcat(s, ":", ftos(p.team));
454                         else
455                                 s = strcat(s, ":spectator");
456                 }
457                 else
458                 {
459                         if(p.classname == "player" || g_arena || g_lms)
460                                 s = GetPlayerScoreString(p, 2);
461                         else
462                                 s = "-666";
463                 }
464
465                 if(p.clientstatus)
466                         strunzone(p.clientstatus);
467                 p.clientstatus = strzone(s);
468         }
469 }
470
471 string GetScoreLogLabel(string label, float fl)
472 {
473         if(fl & SFL_LOWER_IS_BETTER)
474                 label = strcat(label, "<");
475         if(fl & SFL_SORT_PRIO_MASK == SFL_SORT_PRIO_PRIMARY)
476                 label = strcat(label, "!!");
477         else if(fl & SFL_SORT_PRIO_MASK == SFL_SORT_PRIO_SECONDARY)
478                 label = strcat(label, "!");
479         return label;
480 }
481
482 string GetPlayerScoreString(entity pl, float shortString)
483 {
484         string out;
485         entity sk;
486         float i, f;
487         string l;
488
489         out = "";
490         if(!pl)
491         {
492                 // label
493                 for(i = 0; i < MAX_SCORE; ++i)
494                         if(scores_flags[i] & SFL_SORT_PRIO_MASK == SFL_SORT_PRIO_PRIMARY)
495                         {
496                                 f = scores_flags[i];
497                                 l = scores_label[i];
498                                 out = strcat(out, GetScoreLogLabel(l, f), ",");
499                         }
500                 if(shortString < 2)
501                 for(i = 0; i < MAX_SCORE; ++i)
502                         if(scores_flags[i] & SFL_SORT_PRIO_MASK == SFL_SORT_PRIO_SECONDARY)
503                         {
504                                 f = scores_flags[i];
505                                 l = scores_label[i];
506                                 out = strcat(out, GetScoreLogLabel(l, f), ",");
507                         }
508                 if(shortString < 1)
509                 for(i = 0; i < MAX_SCORE; ++i)
510                         if(scores_flags[i] & SFL_SORT_PRIO_MASK != SFL_SORT_PRIO_PRIMARY)
511                         if(scores_flags[i] & SFL_SORT_PRIO_MASK != SFL_SORT_PRIO_SECONDARY)
512                         {
513                                 f = scores_flags[i];
514                                 l = scores_label[i];
515                                 out = strcat(out, GetScoreLogLabel(l, f), ",");
516                         }
517                 out = substring(out, 0, strlen(out) - 1);
518         }
519         else if((sk = pl.scorekeeper))
520         {
521                 for(i = 0; i < MAX_SCORE; ++i)
522                         if(scores_flags[i] & SFL_SORT_PRIO_MASK == SFL_SORT_PRIO_PRIMARY)
523                                 out = strcat(out, ftos(sk.(scores[i])), ",");
524                 if(shortString < 2)
525                 for(i = 0; i < MAX_SCORE; ++i)
526                         if(scores_flags[i] & SFL_SORT_PRIO_MASK == SFL_SORT_PRIO_SECONDARY)
527                                 out = strcat(out, ftos(sk.(scores[i])), ",");
528                 if(shortString < 1)
529                 for(i = 0; i < MAX_SCORE; ++i)
530                         if(scores_flags[i] & SFL_SORT_PRIO_MASK != SFL_SORT_PRIO_PRIMARY)
531                         if(scores_flags[i] & SFL_SORT_PRIO_MASK != SFL_SORT_PRIO_SECONDARY)
532                                 out = strcat(out, ftos(sk.(scores[i])), ",");
533                 out = substring(out, 0, strlen(out) - 1);
534         }
535         return out;
536 }
537
538 string GetTeamScoreString(float tm, float shortString)
539 {
540         string out;
541         entity sk;
542         float i, f;
543         string l;
544
545         out = "";
546         if(tm == 0)
547         {
548                 // label
549                 for(i = 0; i < MAX_SCORE; ++i)
550                         if(teamscores_flags[i] & SFL_SORT_PRIO_MASK == SFL_SORT_PRIO_PRIMARY)
551                         {
552                                 f = teamscores_flags[i];
553                                 l = teamscores_label[i];
554                                 out = strcat(out, GetScoreLogLabel(l, f), ",");
555                         }
556                 if(shortString < 2)
557                 for(i = 0; i < MAX_SCORE; ++i)
558                         if(teamscores_flags[i] & SFL_SORT_PRIO_MASK == SFL_SORT_PRIO_SECONDARY)
559                         {
560                                 f = teamscores_flags[i];
561                                 l = teamscores_label[i];
562                                 out = strcat(out, GetScoreLogLabel(l, f), ",");
563                         }
564                 if(shortString < 1)
565                 for(i = 0; i < MAX_SCORE; ++i)
566                         if(teamscores_flags[i] & SFL_SORT_PRIO_MASK != SFL_SORT_PRIO_PRIMARY)
567                         if(teamscores_flags[i] & SFL_SORT_PRIO_MASK != SFL_SORT_PRIO_SECONDARY)
568                         {
569                                 f = teamscores_flags[i];
570                                 l = teamscores_label[i];
571                                 out = strcat(out, GetScoreLogLabel(l, f), ",");
572                         }
573                 out = substring(out, 0, strlen(out) - 1);
574         }
575         else if((sk = teamscorekeepers[tm - 1]))
576         {
577                 for(i = 0; i < MAX_TEAMSCORE; ++i)
578                         if(teamscores_flags[i] & SFL_SORT_PRIO_MASK == SFL_SORT_PRIO_PRIMARY)
579                                 out = strcat(out, ftos(sk.(teamscores[i])), ",");
580                 if(shortString < 2)
581                 for(i = 0; i < MAX_TEAMSCORE; ++i)
582                         if(teamscores_flags[i] & SFL_SORT_PRIO_MASK == SFL_SORT_PRIO_SECONDARY)
583                                 out = strcat(out, ftos(sk.(teamscores[i])), ",");
584                 if(shortString < 1)
585                 for(i = 0; i < MAX_TEAMSCORE; ++i)
586                         if(teamscores_flags[i] & SFL_SORT_PRIO_MASK != SFL_SORT_PRIO_PRIMARY)
587                         if(teamscores_flags[i] & SFL_SORT_PRIO_MASK != SFL_SORT_PRIO_SECONDARY)
588                                 out = strcat(out, ftos(sk.(teamscores[i])), ",");
589                 out = substring(out, 0, strlen(out) - 1);
590         }
591         return out;
592 }
593
594 float PlayerTeamScore_Compare(entity p1, entity p2)
595 {
596         if(teamscores_entities_count)
597                 if(p1.team != p2.team)
598                 {
599                         entity t1, t2;
600                         float r;
601                         t1 = teamscorekeepers[p1.team - 1];
602                         t2 = teamscorekeepers[p2.team - 1];
603                         r = TeamScore_Compare(t1, t2);
604                         if(r == 0) // ensure a deterministic order
605                                 r = p1.team - p2.team;
606                         return r;
607                 }
608         
609         return PlayerScore_Compare(p1.scorekeeper, p2.scorekeeper);
610 }
611
612 entity PlayerScore_Sort(.float field)
613 {
614         entity p, plist, pprev, pbest, pbestprev, pfirst, plast;
615         float i;
616
617         plist = world;
618
619         FOR_EACH_CLIENT(p)
620                 p.field = 0;
621
622         FOR_EACH_PLAYER(p) if(p.scorekeeper)
623         {
624                 p.chain = plist;
625                 plist = p;
626         }
627         // Now plist points to the whole list.
628         
629         pfirst = plast = world;
630
631         i = 0;
632         while(plist)
633         {
634                 pprev = pbestprev = world;
635                 pbest = plist;
636                 for(p = plist; (pprev = p), (p = p.chain); )
637                 {
638                         if(PlayerTeamScore_Compare(p, pbest) > 0)
639                         {
640                                 pbest = p;
641                                 pbestprev = pprev;
642                         }
643                 }
644
645                 // remove pbest out of the chain
646                 if(pbestprev == world)
647                         plist = pbest.chain;
648                 else
649                         pbestprev.chain = pbest.chain;
650                 pbest.chain = world;
651
652                 pbest.field = ++i;
653
654                 if not(pfirst)
655                         pfirst = pbest;
656                 if(plast)
657                         plast.chain = pbest;
658                 plast = pbest;
659         }
660
661         return pfirst;
662 }
663
664 float TeamScore_GetCompareValue(float t)
665 {
666         float s;
667         entity sk;
668
669         if(t <= 0 || t >= 16)
670                 error("Reading score of invalid team!");
671
672         sk = teamscorekeepers[t - 1];
673         if not(sk)
674                 return -999999999;
675         s = sk.teamscores_primary;
676         if(teamscores_flags_primary & SFL_ZERO_IS_WORST)
677                 if(!s)
678                         return -999999999;
679         if(teamscores_flags_primary & SFL_LOWER_IS_BETTER)
680                 s = -s;
681         return s;
682 }
683
684 #define NAMEWIDTH 22
685 #define SCORESWIDTH 58
686 // TODO put this somewhere in common?
687 string Score_NicePrint_ItemColor(float vflags)
688 {
689         if(vflags & SFL_SORT_PRIO_PRIMARY)
690                 return "^3";
691         else if(vflags & SFL_SORT_PRIO_SECONDARY)
692                 return "^5";
693         else
694                 return "^7";
695 }
696
697 void Score_NicePrint_Team(entity to, float t, float w)
698 {
699         string s, s2;
700         float i;
701         entity sk;
702         float fl, sc;
703         s = "";
704
705         sk = teamscorekeepers[t - 1];
706         if(sk)
707         {
708                 s = strcat(s, ColoredTeamName(t));
709                 for(i = 0; i < MAX_TEAMSCORE; ++i)
710                         if(teamscores_label[i] != "")
711                         {
712                                 fl = teamscores_flags[i];
713                                 sc = sk.(teamscores[i]);
714                                 s = strcat(s, " ", Score_NicePrint_ItemColor(fl), ScoreString(fl, sc));
715                         }
716         }
717         else
718                 s = "Scores:";
719
720         s = strcat(s, strpad(max(0, NAMEWIDTH - strlennocol(s)), ""));
721         
722         for(i = 0; i < MAX_SCORE; ++i)
723                 if(scores_label[i] != "")
724                 {
725                         fl = scores_flags[i];
726                         s2 = scores_label[i];
727                         s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, substring(s2, 0, w)));
728                 }
729
730         print_to(to, s);
731 }
732
733 void Score_NicePrint_Player(entity to, entity p, float w)
734 {
735         string s;
736         float i;
737         entity sk;
738         float fl, sc;
739         s = "  ";
740
741         sk = p.scorekeeper;
742
743         s = strcat(s, p.netname);
744         for(;;)
745         {
746                 i = strlennocol(s) - NAMEWIDTH;
747                 if(i > 0)
748                         s = substring(s, 0, strlen(s) - i);
749                 else
750                 {
751                         s = strcat(s, strpad(i, ""));
752                         break;
753                 }
754         }
755         
756         for(i = 0; i < MAX_SCORE; ++i)
757                 if(scores_label[i] != "")
758                 {
759                         fl = scores_flags[i];
760                         sc = sk.(scores[i]);
761                         s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, ScoreString(fl, sc)));
762                 }
763
764         print_to(to, s);
765 }
766
767 void Score_NicePrint_Spectators(entity to)
768 {
769         print_to(to, "Spectators:");
770 }
771
772 void Score_NicePrint_Spectator(entity to, entity p)
773 {
774         print_to(to, strcat("  ", p.netname));
775 }
776
777 .float score_dummyfield;
778 void Score_NicePrint(entity to)
779 {
780         entity p;
781         float t, i;
782         float w;
783
784         t = 0;
785         for(i = 0; i < MAX_SCORE; ++i)
786                 if(scores_label[i] != "")
787                         ++t;
788         w = bound(6, floor(SCORESWIDTH / t - 1), 9);
789
790         p = PlayerScore_Sort(score_dummyfield);
791         t = -1;
792
793         if(!teamscores_entities_count)
794                 Score_NicePrint_Team(to, t, w);
795         while(p)
796         {
797                 if(teamscores_entities_count)
798                         if(t != p.team)
799                                 Score_NicePrint_Team(to, p.team, w);
800                 Score_NicePrint_Player(to, p, w);
801                 t = p.team;
802                 p = p.chain;
803         }
804         
805         t = 0;
806         FOR_EACH_CLIENT(p)
807         if(p.classname != "player")
808         {
809                 if not(t)
810                         Score_NicePrint_Spectators(to);
811                 Score_NicePrint_Spectator(to, p);
812                 t = 1;
813         }
814 }
815