3 #include <common/mapinfo.qh>
4 #include <common/mutators/base.qh>
5 #include <common/net_linked.qh>
6 #include <common/playerstats.qh>
7 #include <common/scores.qh>
8 #include <common/state.qh>
9 #include <common/stats.qh>
10 #include <common/teams.qh>
11 #include <common/weapons/_all.qh>
12 #include <server/client.qh>
13 #include <server/command/common.qh>
14 #include <server/intermission.qh>
15 #include <server/mutators/_mod.qh>
16 #include <server/round_handler.qh>
17 #include <server/world.qh>
20 entity teamscorekeepers[16];
21 float teamscores_entities_count;
22 var .float scores_primary;
23 var .float teamscores_primary;
24 float scores_flags_primary;
25 float teamscores_flags_primary;
27 vector ScoreField_Compare(entity t1, entity t2, .float field, float fieldflags, vector previous, bool strict) // returns: cmp value, best prio
29 if(!strict && !(fieldflags & SFL_SORT_PRIO_MASK)) // column does not sort
31 if((fieldflags & SFL_SORT_PRIO_MASK) < previous.y)
33 if (t1.(field) == t2.(field))
36 previous.y = fieldflags & SFL_SORT_PRIO_MASK;
38 if(fieldflags & SFL_ZERO_IS_WORST)
45 else if (t2.(field) == 0)
52 if (fieldflags & SFL_LOWER_IS_BETTER)
53 previous.x = (t2.(field) - t1.(field));
55 previous.x = (t1.(field) - t2.(field));
64 bool TeamScore_SendEntity(entity this, entity to, float sendflags)
68 WriteHeader(MSG_ENTITY, ENT_CLIENT_TEAMSCORES);
69 int t = this.team - 1;
70 assert(t, eprint(this));
71 WriteByte(MSG_ENTITY, t);
74 for(i = 0; i < MAX_TEAMSCORE; ++i)
75 if(this.(teamscores(i)) > 127 || this.(teamscores(i)) <= -128)
78 #if MAX_TEAMSCORE <= 8
79 WriteByte(MSG_ENTITY, sendflags);
80 WriteByte(MSG_ENTITY, longflags);
82 WriteShort(MSG_ENTITY, sendflags);
83 WriteShort(MSG_ENTITY, longflags);
85 for(i = 0; i < MAX_TEAMSCORE; ++i)
86 if(sendflags & BIT(i))
88 if(longflags & BIT(i))
89 WriteInt24_t(MSG_ENTITY, this.(teamscores(i)));
91 WriteChar(MSG_ENTITY, this.(teamscores(i)));
97 void TeamScore_Spawn(float t, string name)
99 entity ts = new_pure(csqc_score_team);
100 ts.netname = name; // not used yet, FIXME
102 Net_LinkEntity(ts, false, 0, TeamScore_SendEntity);
103 teamscorekeepers[t - 1] = ts;
104 ++teamscores_entities_count;
105 PlayerStats_GameReport_AddTeam(t);
108 float TeamScore_AddToTeam(int t, float scorefield, float score)
117 if(!scores_initialized) return 0; // FIXME remove this when everything uses this system
118 if(t <= 0 || t >= 16)
122 error("Adding score to invalid team!");
124 s = teamscorekeepers[t - 1];
129 error("Adding score to unknown team!");
132 if(teamscores_label(scorefield) != "")
133 s.SendFlags |= BIT(scorefield);
134 return (s.(teamscores(scorefield)) += score);
137 float TeamScore_Add(entity player, float scorefield, float score)
139 return TeamScore_AddToTeam(player.team, scorefield, score);
142 float TeamScore_Compare(entity t1, entity t2, bool strict)
144 if(!t1 || !t2) return (!t2) - !t1;
146 vector result = '0 0 0';
148 for(i = 0; i < MAX_TEAMSCORE; ++i)
152 result = ScoreField_Compare(t1, t2, f, teamscores_flags(i), result, strict);
155 if (result.x == 0 && strict)
156 result.x = t1.team - t2.team;
162 * the scoreinfo entity
165 void ScoreInfo_SetLabel_PlayerScore(PlayerScoreField i, string label, float scoreflags)
167 scores_label(i) = label;
168 scores_flags(i) = scoreflags;
169 if((scoreflags & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
171 scores_primary = scores(i);
172 scores_flags_primary = scoreflags;
176 PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_TOTAL, label));
177 PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_SCOREBOARD, label));
181 void ScoreInfo_SetLabel_TeamScore(float i, string label, float scoreflags)
183 teamscores_label(i) = label;
184 teamscores_flags(i) = scoreflags;
185 if((scoreflags & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
187 teamscores_primary = teamscores(i);
188 teamscores_flags_primary = scoreflags;
192 PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_TOTAL, label));
193 PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_SCOREBOARD, label));
197 bool ScoreInfo_SendEntity(entity this, entity to, int sf)
200 WriteHeader(MSG_ENTITY, ENT_CLIENT_SCORES_INFO);
201 WriteRegistered(Gametypes, MSG_ENTITY, MapInfo_LoadedGametype);
202 FOREACH(Scores, true, {
203 WriteString(MSG_ENTITY, scores_label(it));
204 WriteByte(MSG_ENTITY, scores_flags(it));
206 for(i = 0; i < MAX_TEAMSCORE; ++i)
208 WriteString(MSG_ENTITY, teamscores_label(i));
209 WriteByte(MSG_ENTITY, teamscores_flags(i));
214 void ScoreInfo_Init(int teams)
216 if(scores_initialized)
218 scores_initialized.SendFlags |= 1; // force a resend
222 scores_initialized = new_pure(ent_client_scoreinfo);
223 Net_LinkEntity(scores_initialized, false, 0, ScoreInfo_SendEntity);
226 TeamScore_Spawn(NUM_TEAM_1, "Red");
228 TeamScore_Spawn(NUM_TEAM_2, "Blue");
230 TeamScore_Spawn(NUM_TEAM_3, "Yellow");
232 TeamScore_Spawn(NUM_TEAM_4, "Pink");
236 * per-player score entities
239 bool PlayerScore_SendEntity(entity this, entity to, float sendflags)
241 WriteHeader(MSG_ENTITY, ENT_CLIENT_SCORES);
242 WriteByte(MSG_ENTITY, etof(this.owner));
245 FOREACH(Scores, true, {
246 int p = 1 << (i % 16);
247 if (this.(scores(it)) > 127 || this.(scores(it)) <= -128)
251 WriteShort(MSG_ENTITY, sendflags);
252 WriteShort(MSG_ENTITY, longflags);
253 FOREACH(Scores, true, {
254 int p = 1 << (i % 16);
258 WriteInt24_t(MSG_ENTITY, this.(scores(it)));
260 WriteChar(MSG_ENTITY, this.(scores(it)));
267 float PlayerScore_Clear(entity player)
271 if(teamscores_entities_count)
274 if(MUTATOR_CALLHOOK(ForbidPlayerScore_Clear)) return 0;
276 sk = CS(player).scorekeeper;
277 FOREACH(Scores, true, {
278 if(sk.(scores(it)) != 0)
279 //if(scores_label(it) != "")
280 sk.SendFlags |= (2 ** (i % 16));
288 void Score_ClearAll()
292 FOREACH_CLIENTSLOT(true, {
293 sk = CS(it).scorekeeper;
295 FOREACH(Scores, true, {
296 if(sk.(scores(it)) != 0)
297 //if(scores_label(it) != "")
298 sk.SendFlags |= (2 ** (i % 16));
303 for(t = 0; t < 16; ++t)
305 sk = teamscorekeepers[t];
308 for(int j = 0; j < MAX_TEAMSCORE; ++j)
310 if(sk.(teamscores(j)) != 0)
311 //if(teamscores_label(j) != "")
312 sk.SendFlags |= (2 ** j);
313 sk.(teamscores(j)) = 0;
318 void PlayerScore_Attach(entity player)
320 if(CS(player).scorekeeper)
321 error("player already has a scorekeeper");
322 entity sk = new_pure(scorekeeper);
324 Net_LinkEntity(sk, false, 0, PlayerScore_SendEntity);
325 CS(player).scorekeeper = sk;
328 void PlayerScore_Detach(entity player)
330 if(!CS(player).scorekeeper)
331 error("player has no scorekeeper");
332 delete(CS(player).scorekeeper);
333 CS(player).scorekeeper = NULL;
336 float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score)
338 bool mutator_returnvalue = MUTATOR_CALLHOOK(AddPlayerScore, scorefield, score, player);
339 score = M_ARGV(1, float);
341 if(!mutator_returnvalue && game_stopped)
346 if(!scores_initialized) return 0; // FIXME remove this when everything uses this system
347 entity s = CS(player).scorekeeper;
352 LOG_WARN("Adding score to unknown player!");
357 return s.(scores(scorefield));
359 //if(scores_label(scorefield) != "")
360 s.SendFlags |= (2 ** (scorefield.m_id % 16));
362 PlayerStats_GameReport_Event_Player(s.owner, strcat(PLAYERSTATS_TOTAL, scores_label(scorefield)), score);
363 s.(scores(scorefield)) += score;
364 MUTATOR_CALLHOOK(AddedPlayerScore, scorefield, score, player);
365 return s.(scores(scorefield));
368 float PlayerScore_Set(entity player, PlayerScoreField scorefield, float score)
370 if(!scores_initialized) return 0; // FIXME remove this when everything uses this system
371 entity s = CS(player).scorekeeper;
376 LOG_WARN("Setting score of unknown player!");
380 float oldscore = s.(scores(scorefield));
381 if(oldscore == score)
384 if(scores_label(scorefield) != "")
385 s.SendFlags |= BIT(scorefield.m_id % 16);
386 s.(scores(scorefield)) = score;
387 return s.(scores(scorefield));
390 float PlayerTeamScore_Add(entity player, PlayerScoreField pscorefield, float tscorefield, float score)
393 r = PlayerScore_Add(player, pscorefield, score);
394 if(teamscores_entities_count) // only for teamplay
395 r = TeamScore_Add(player, tscorefield, score);
399 float PlayerScore_Compare(entity t1, entity t2, bool strict)
401 if(!t1 || !t2) return (!t2) - !t1;
403 vector result = '0 0 0';
404 FOREACH(Scores, true, {
405 var .float f = scores(it);
406 result = ScoreField_Compare(t1, t2, f, scores_flags(it), result, strict);
409 if (result.x == 0 && strict)
410 result.x = t1.owner.playerid - t2.owner.playerid;
415 bool Score_NewLeader()
418 if (WinningConditionHelper_winnerteam != WinningConditionHelper_winnerteam_last && (WinningConditionHelper_secondteam || WinningConditionHelper_equality))
420 WinningConditionHelper_winnerteam_last = WinningConditionHelper_winnerteam;
424 if (WinningConditionHelper_winner != WinningConditionHelper_winner_last && (WinningConditionHelper_second || WinningConditionHelper_equality))
426 WinningConditionHelper_winner_last = WinningConditionHelper_winner;
433 void WinningConditionHelper(entity this)
438 entity winnerscorekeeper;
439 entity secondscorekeeper;
443 // gametype:P<pure>:S<slots>::plabel,plabel:tlabel,tlabel:teamid:tscore,tscore:teamid:tscore,tscore
444 // score labels always start with a symbol or with lower case
445 // so to match pure, match for :P0:
446 // to match full, match for :S0:
448 fullstatus = autocvar_g_full_getstatus_responses;
451 s = strcat(s, ":", autocvar_g_xonoticversion);
452 s = strcat(s, ":P", ftos(cvar_purechanges_count));
453 s = strcat(s, ":S", ftos(nJoinAllowed(this, NULL)));
454 s = strcat(s, ":F", ftos(serverflags));
455 s = strcat(s, ":M", modname);
456 s = strcat(s, "::", GetPlayerScoreString(NULL, (fullstatus ? 1 : 2)));
458 if(teamscores_entities_count)
462 s = strcat(s, ":", GetTeamScoreString(0, 1));
463 for(t = 0; t < 16; ++t)
464 if(teamscorekeepers[t])
465 s = strcat(s, ":", ftos(t+1), ":", GetTeamScoreString(t+1, 1));
467 WinningConditionHelper_winnerteam = -1;
468 WinningConditionHelper_secondteam = -1;
469 winnerscorekeeper = NULL;
470 secondscorekeeper = NULL;
471 for(t = 0; t < 16; ++t)
473 sk = teamscorekeepers[t];
474 c = TeamScore_Compare(winnerscorekeeper, sk, 1);
477 WinningConditionHelper_secondteam = WinningConditionHelper_winnerteam;
478 WinningConditionHelper_winnerteam = t + 1;
479 secondscorekeeper = winnerscorekeeper;
480 winnerscorekeeper = sk;
484 c = TeamScore_Compare(secondscorekeeper, sk, 1);
487 WinningConditionHelper_secondteam = t + 1;
488 secondscorekeeper = sk;
493 WinningConditionHelper_equality = (TeamScore_Compare(winnerscorekeeper, secondscorekeeper, 0) == 0);
494 if(WinningConditionHelper_equality)
495 WinningConditionHelper_winnerteam = WinningConditionHelper_secondteam = -1;
497 WinningConditionHelper_topscore = winnerscorekeeper.teamscores_primary;
498 WinningConditionHelper_secondscore = secondscorekeeper.teamscores_primary;
499 WinningConditionHelper_lowerisbetter = (teamscores_flags_primary & SFL_LOWER_IS_BETTER);
500 WinningConditionHelper_zeroisworst = (teamscores_flags_primary & SFL_ZERO_IS_WORST);
502 WinningConditionHelper_winner = NULL; // not supported in teamplay
503 WinningConditionHelper_second = NULL; // not supported in teamplay
507 WinningConditionHelper_winner = NULL;
508 WinningConditionHelper_second = NULL;
509 winnerscorekeeper = NULL;
510 secondscorekeeper = NULL;
511 FOREACH_CLIENT(IS_PLAYER(it), {
512 sk = CS(it).scorekeeper;
513 c = PlayerScore_Compare(winnerscorekeeper, sk, true);
516 WinningConditionHelper_second = WinningConditionHelper_winner;
517 WinningConditionHelper_winner = it;
518 secondscorekeeper = winnerscorekeeper;
519 winnerscorekeeper = sk;
523 c = PlayerScore_Compare(secondscorekeeper, sk, true);
526 WinningConditionHelper_second = it;
527 secondscorekeeper = sk;
532 WinningConditionHelper_equality = (PlayerScore_Compare(winnerscorekeeper, secondscorekeeper, false) == 0);
533 if(WinningConditionHelper_equality)
535 WinningConditionHelper_equality_one = WinningConditionHelper_winner;
536 WinningConditionHelper_equality_two = WinningConditionHelper_second;
537 WinningConditionHelper_winner = WinningConditionHelper_second = NULL;
541 WinningConditionHelper_equality_one = WinningConditionHelper_equality_two = NULL;
544 WinningConditionHelper_topscore = winnerscorekeeper.scores_primary;
545 WinningConditionHelper_secondscore = secondscorekeeper.scores_primary;
546 WinningConditionHelper_lowerisbetter = (scores_flags_primary & SFL_LOWER_IS_BETTER);
547 WinningConditionHelper_zeroisworst = (scores_flags_primary & SFL_ZERO_IS_WORST);
549 WinningConditionHelper_winnerteam = -1; // no teamplay
550 WinningConditionHelper_secondteam = -1; // no teamplay
553 if(WinningConditionHelper_topscore == 0)
555 if(scores_flags_primary & SFL_ZERO_IS_WORST)
557 if(WinningConditionHelper_lowerisbetter)
558 WinningConditionHelper_topscore = 999999999;
560 WinningConditionHelper_topscore = -999999999;
562 if(player_count == 0) // special case: empty servers DO end the match at a 0:0 tie
563 WinningConditionHelper_equality = 0;
566 if(WinningConditionHelper_secondscore == 0)
568 if(scores_flags_primary & SFL_ZERO_IS_WORST)
570 if(WinningConditionHelper_lowerisbetter)
571 WinningConditionHelper_secondscore = 999999999;
573 WinningConditionHelper_secondscore = -999999999;
577 strcpy(worldstatus, s);
579 FOREACH_CLIENT(true, {
583 s = GetPlayerScoreString(it, 1);
584 s = strcat(s, IS_REAL_CLIENT(it) ? ":human" : ":bot");
585 if(!IS_PLAYER(it) && !MUTATOR_CALLHOOK(GetPlayerStatus, it))
586 s = strcat(s, ":spectator");
590 if (IS_PLAYER(it) || MUTATOR_CALLHOOK(GetPlayerStatus, it))
591 s = GetPlayerScoreString(it, 2);
596 strcpy(it.clientstatus, s);
600 string GetScoreLogLabel(string label, float fl)
602 if(fl & SFL_LOWER_IS_BETTER)
603 label = strcat(label, "<");
604 if((fl & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
605 label = strcat(label, "!!");
606 else if((fl & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
607 label = strcat(label, "!");
611 string GetPlayerScoreString(entity pl, float shortString)
622 FOREACH(Scores, true, {
623 if ((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
625 f = scores_flags(it);
626 l = scores_label(it);
627 out = strcat(out, GetScoreLogLabel(l, f), ",");
631 FOREACH(Scores, true, {
632 if((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
634 f = scores_flags(it);
635 l = scores_label(it);
636 out = strcat(out, GetScoreLogLabel(l, f), ",");
640 FOREACH(Scores, true, {
641 if((scores_flags(it) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
642 if((scores_flags(it) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
644 f = scores_flags(it);
645 l = scores_label(it);
646 out = strcat(out, GetScoreLogLabel(l, f), ",");
649 out = substring(out, 0, strlen(out) - 1);
651 else if((sk = CS(pl).scorekeeper))
653 FOREACH(Scores, true, {
654 if ((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
655 out = strcat(out, ftos(sk.(scores(it))), ",");
658 FOREACH(Scores, true, {
659 if ((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
660 out = strcat(out, ftos(sk.(scores(it))), ",");
663 FOREACH(Scores, true, {
664 if((scores_flags(it) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
665 if((scores_flags(it) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
666 out = strcat(out, ftos(sk.(scores(it))), ",");
668 out = substring(out, 0, strlen(out) - 1);
673 string GetTeamScoreString(float tm, float shortString)
684 for(i = 0; i < MAX_TEAMSCORE; ++i)
685 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
687 f = teamscores_flags(i);
688 l = teamscores_label(i);
689 out = strcat(out, GetScoreLogLabel(l, f), ",");
692 for(i = 0; i < MAX_TEAMSCORE; ++i)
693 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
695 f = teamscores_flags(i);
696 l = teamscores_label(i);
697 out = strcat(out, GetScoreLogLabel(l, f), ",");
700 for(i = 0; i < MAX_TEAMSCORE; ++i)
701 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
702 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
704 f = teamscores_flags(i);
705 l = teamscores_label(i);
706 out = strcat(out, GetScoreLogLabel(l, f), ",");
708 out = substring(out, 0, strlen(out) - 1);
710 else if((sk = teamscorekeepers[tm - 1]))
712 for(i = 0; i < MAX_TEAMSCORE; ++i)
713 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
714 out = strcat(out, ftos(sk.(teamscores(i))), ",");
716 for(i = 0; i < MAX_TEAMSCORE; ++i)
717 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
718 out = strcat(out, ftos(sk.(teamscores(i))), ",");
720 for(i = 0; i < MAX_TEAMSCORE; ++i)
721 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
722 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
723 out = strcat(out, ftos(sk.(teamscores(i))), ",");
724 out = substring(out, 0, strlen(out) - 1);
729 float PlayerTeamScore_Compare(entity p1, entity p2, float teams, bool strict)
731 if(teams && teamscores_entities_count)
733 if(p1.team != p2.team)
737 t1 = teamscorekeepers[p1.team - 1];
738 t2 = teamscorekeepers[p2.team - 1];
739 r = TeamScore_Compare(t1, t2, ((teams >= 0) ? 1 : strict));
746 return PlayerScore_Compare(CS(p1).scorekeeper, CS(p2).scorekeeper, strict);
749 entity PlayerScore_Sort(.float field, int teams, bool strict, bool nospectators)
751 entity p, plist, pprev, pbest, pbestprev, pfirst, plast;
756 FOREACH_CLIENT(true, { it.(field) = 0; });
758 FOREACH_CLIENT(CS(it).scorekeeper,
761 if(it.frags == FRAGS_SPECTATOR)
767 // Now plist points to the whole list.
769 pfirst = plast = NULL;
774 pprev = pbestprev = NULL;
776 for(p = plist; (pprev = p), (p = p.chain); )
778 if(PlayerTeamScore_Compare(p, pbest, teams, strict) > 0)
785 // remove pbest out of the chain
786 if(pbestprev == NULL)
789 pbestprev.chain = pbest.chain;
793 if(!plast || PlayerTeamScore_Compare(plast, pbest, teams, strict))
808 float TeamScore_GetCompareValue(float t)
813 if(t <= 0 || t >= 16)
817 error("Reading score of invalid team!");
820 sk = teamscorekeepers[t - 1];
823 s = sk.teamscores_primary;
824 if(teamscores_flags_primary & SFL_ZERO_IS_WORST)
827 if(teamscores_flags_primary & SFL_LOWER_IS_BETTER)
832 const float NAMEWIDTH = 22;
833 const float SCORESWIDTH = 58;
834 // TODO put this somewhere in common?
835 string Score_NicePrint_ItemColor(float vflags)
837 if(vflags & SFL_SORT_PRIO_PRIMARY)
839 else if(vflags & SFL_SORT_PRIO_SECONDARY)
845 void Score_NicePrint_Team(entity to, float t, float w)
853 sk = teamscorekeepers[t - 1];
856 s = strcat(s, Team_ColoredFullName(t));
857 for(i = 0; i < MAX_TEAMSCORE; ++i)
858 if(teamscores_label(i) != "")
860 fl = teamscores_flags(i);
861 sc = sk.(teamscores(i));
862 s = strcat(s, " ", Score_NicePrint_ItemColor(fl), ScoreString(fl, sc));
868 s = strcat(s, strpad(max(0, NAMEWIDTH - strlennocol(s)), ""));
870 FOREACH(Scores, true, {
871 if(scores_label(it) != "")
873 fl = scores_flags(it);
874 s2 = scores_label(it);
875 s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, substring(s2, 0, w)));
882 void Score_NicePrint_Player(entity to, entity p, float w)
890 sk = CS(p).scorekeeper;
892 s = strcat(s, playername(p.netname, p.team, false));
895 i = strlennocol(s) - NAMEWIDTH;
897 s = substring(s, 0, strlen(s) - i);
900 s = strcat(s, strpad(i, ""));
905 FOREACH(Scores, true, {
906 if(scores_label(it) != "")
908 fl = scores_flags(it);
909 sc = sk.(scores(it));
910 s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, ScoreString(fl, sc)));
917 void Score_NicePrint_Spectators(entity to)
919 print_to(to, "Spectators:");
922 void Score_NicePrint_Spectator(entity to, entity p)
924 print_to(to, strcat(" ", playername(p.netname, p.team, false)));
927 .float score_dummyfield;
928 void Score_NicePrint(entity to)
934 FOREACH(Scores, true, {
935 if(scores_label(it) != "")
938 w = bound(6, floor(SCORESWIDTH / t - 1), 9);
940 p = PlayerScore_Sort(score_dummyfield, 1, true, false);
943 if(!teamscores_entities_count)
944 Score_NicePrint_Team(to, t, w);
947 if(teamscores_entities_count)
949 Score_NicePrint_Team(to, p.team, w);
950 Score_NicePrint_Player(to, p, w);
956 FOREACH_CLIENT(!IS_PLAYER(it), {
958 Score_NicePrint_Spectators(to);
959 Score_NicePrint_Spectator(to, it);
964 void PlayerScore_PlayerStats(entity p)
966 entity s = CS(p).scorekeeper;
967 FOREACH(Scores, true, {
968 if(s.(scores(it)) != 0 && scores_label(it) != "")
969 PlayerStats_GameReport_Event_Player(s.owner,
970 strcat(PLAYERSTATS_SCOREBOARD, scores_label(it)), s.(scores(it)));
974 void PlayerScore_TeamStats()
978 for(t = 0; t < 16; ++t)
980 sk = teamscorekeepers[t];
983 for(i = 0; i < MAX_TEAMSCORE; ++i)
984 if(sk.(teamscores(i)) != 0 && teamscores_label(i) != "")
985 // the +1 is important here!
986 PlayerStats_GameReport_Event_Team(t+1,
987 strcat(PLAYERSTATS_SCOREBOARD, teamscores_label(i)), sk.(teamscores(i)));