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