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