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));
211 // prevent sending the welcome message again when score types are sent again because the scoring system has changed
212 // it can happen in some game modes like Race when the qualyfing session ends and the race starts
213 // NOTE: CS(this) is not initialized yet when a local client connects to a local dedicated server
214 bool welcome_msg_too = (!CS(this) || time < CS(this).jointime + 5);
215 WriteByte(MSG_ENTITY, welcome_msg_too);
216 // welcome message is sent here because it needs to know the gametype
218 SendWelcomemessage_msg_type(this, false, MSG_ENTITY);
222 void ScoreInfo_Init(int teams)
224 if(scores_initialized)
226 scores_initialized.SendFlags |= 1; // force a resend
230 scores_initialized = new_pure(ent_client_scoreinfo);
231 Net_LinkEntity(scores_initialized, false, 0, ScoreInfo_SendEntity);
234 TeamScore_Spawn(NUM_TEAM_1, "Red");
236 TeamScore_Spawn(NUM_TEAM_2, "Blue");
238 TeamScore_Spawn(NUM_TEAM_3, "Yellow");
240 TeamScore_Spawn(NUM_TEAM_4, "Pink");
244 * per-player score entities
247 bool PlayerScore_SendEntity(entity this, entity to, float sendflags)
249 WriteHeader(MSG_ENTITY, ENT_CLIENT_SCORES);
250 WriteByte(MSG_ENTITY, etof(this.owner));
253 FOREACH(Scores, true, {
254 int p = 1 << (i % 16);
255 if (this.(scores(it)) > 127 || this.(scores(it)) <= -128)
259 WriteShort(MSG_ENTITY, sendflags);
260 WriteShort(MSG_ENTITY, longflags);
261 FOREACH(Scores, true, {
262 int p = 1 << (i % 16);
266 WriteInt24_t(MSG_ENTITY, this.(scores(it)));
268 WriteChar(MSG_ENTITY, this.(scores(it)));
275 float PlayerScore_Clear(entity player)
279 if(teamscores_entities_count)
282 if(MUTATOR_CALLHOOK(ForbidPlayerScore_Clear)) return 0;
284 sk = CS(player).scorekeeper;
285 FOREACH(Scores, true, {
286 if(sk.(scores(it)) != 0)
287 if(scores_label(it) != "")
288 sk.SendFlags |= BIT(i % 16);
296 void Score_ClearAll()
300 FOREACH_CLIENTSLOT(true, {
301 sk = CS(it).scorekeeper;
303 FOREACH(Scores, true, {
304 if(sk.(scores(it)) != 0)
305 if(scores_label(it) != "")
306 sk.SendFlags |= BIT(i % 16);
311 for(t = 0; t < 16; ++t)
313 sk = teamscorekeepers[t];
316 for(int j = 0; j < MAX_TEAMSCORE; ++j)
318 if(sk.(teamscores(j)) != 0)
319 if(teamscores_label(j) != "")
320 sk.SendFlags |= BIT(j);
321 sk.(teamscores(j)) = 0;
326 void PlayerScore_Attach(entity player)
328 if(CS(player).scorekeeper)
329 error("player already has a scorekeeper");
330 entity sk = new_pure(scorekeeper);
332 Net_LinkEntity(sk, false, 0, PlayerScore_SendEntity);
333 CS(player).scorekeeper = sk;
336 void PlayerScore_Detach(entity player)
338 if(!CS(player).scorekeeper)
339 error("player has no scorekeeper");
340 delete(CS(player).scorekeeper);
341 CS(player).scorekeeper = NULL;
344 float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score)
346 bool mutator_returnvalue = MUTATOR_CALLHOOK(AddPlayerScore, scorefield, score, player);
347 score = M_ARGV(1, float);
349 if(!mutator_returnvalue && game_stopped)
354 if(!scores_initialized) return 0; // FIXME remove this when everything uses this system
355 entity s = CS(player).scorekeeper;
360 LOG_WARN("Adding score to unknown player!");
365 return s.(scores(scorefield));
367 if(scores_label(scorefield) != "")
368 s.SendFlags |= BIT(scorefield.m_id % 16);
370 PlayerStats_GameReport_Event_Player(s.owner, strcat(PLAYERSTATS_TOTAL, scores_label(scorefield)), score);
371 s.(scores(scorefield)) += score;
372 MUTATOR_CALLHOOK(AddedPlayerScore, scorefield, score, player);
373 return s.(scores(scorefield));
376 float PlayerScore_Set(entity player, PlayerScoreField scorefield, float score)
378 if(!scores_initialized) return 0; // FIXME remove this when everything uses this system
379 entity s = CS(player).scorekeeper;
384 LOG_WARN("Setting score of unknown player!");
388 float oldscore = s.(scores(scorefield));
389 if(oldscore == score)
392 if(scores_label(scorefield) != "")
393 s.SendFlags |= BIT(scorefield.m_id % 16);
394 s.(scores(scorefield)) = score;
395 return s.(scores(scorefield));
398 float PlayerTeamScore_Add(entity player, PlayerScoreField pscorefield, float tscorefield, float score)
401 r = PlayerScore_Add(player, pscorefield, score);
402 if(teamscores_entities_count) // only for teamplay
403 r = TeamScore_Add(player, tscorefield, score);
407 float PlayerScore_Compare(entity t1, entity t2, bool strict)
409 if(!t1 || !t2) return (!t2) - !t1;
411 vector result = '0 0 0';
412 FOREACH(Scores, true, {
413 var .float f = scores(it);
414 result = ScoreField_Compare(t1, t2, f, scores_flags(it), result, strict);
417 if (result.x == 0 && strict)
418 result.x = t1.owner.playerid - t2.owner.playerid;
423 void WinningConditionHelper(entity this)
428 entity winnerscorekeeper;
429 entity secondscorekeeper;
433 // gametype:P<pure>:S<slots>::plabel,plabel:tlabel,tlabel:teamid:tscore,tscore:teamid:tscore,tscore
434 // score labels always start with a symbol or with lower case
435 // so to match pure, match for :P0:
436 // to match full, match for :S0:
438 fullstatus = autocvar_g_full_getstatus_responses;
441 s = strcat(s, ":", autocvar_g_xonoticversion);
442 s = strcat(s, ":P", ftos(cvar_purechanges_count));
443 s = strcat(s, ":S", ftos(nJoinAllowed(this, NULL)));
444 s = strcat(s, ":F", ftos(serverflags));
445 s = strcat(s, ":T", sv_termsofservice_url_escaped);
446 s = strcat(s, ":M", modname);
447 s = strcat(s, "::", GetPlayerScoreString(NULL, (fullstatus ? 1 : 2)));
449 if(teamscores_entities_count)
453 s = strcat(s, ":", GetTeamScoreString(0, 1));
454 for(t = 0; t < 16; ++t)
455 if(teamscorekeepers[t])
456 s = strcat(s, ":", ftos(t+1), ":", GetTeamScoreString(t+1, 1));
458 WinningConditionHelper_winnerteam = -1;
459 WinningConditionHelper_secondteam = -1;
460 winnerscorekeeper = NULL;
461 secondscorekeeper = NULL;
462 for(t = 0; t < 16; ++t)
464 sk = teamscorekeepers[t];
465 c = TeamScore_Compare(winnerscorekeeper, sk, 1);
468 WinningConditionHelper_secondteam = WinningConditionHelper_winnerteam;
469 WinningConditionHelper_winnerteam = t + 1;
470 secondscorekeeper = winnerscorekeeper;
471 winnerscorekeeper = sk;
475 c = TeamScore_Compare(secondscorekeeper, sk, 1);
478 WinningConditionHelper_secondteam = t + 1;
479 secondscorekeeper = sk;
484 WinningConditionHelper_equality = (TeamScore_Compare(winnerscorekeeper, secondscorekeeper, 0) == 0);
485 if(WinningConditionHelper_equality)
486 WinningConditionHelper_winnerteam = WinningConditionHelper_secondteam = -1;
488 WinningConditionHelper_topscore = winnerscorekeeper.teamscores_primary;
489 WinningConditionHelper_secondscore = secondscorekeeper.teamscores_primary;
490 WinningConditionHelper_lowerisbetter = (teamscores_flags_primary & SFL_LOWER_IS_BETTER);
491 WinningConditionHelper_zeroisworst = (teamscores_flags_primary & SFL_ZERO_IS_WORST);
493 WinningConditionHelper_winner = NULL; // not supported in teamplay
494 WinningConditionHelper_second = NULL; // not supported in teamplay
498 WinningConditionHelper_winner = NULL;
499 WinningConditionHelper_second = NULL;
500 winnerscorekeeper = NULL;
501 secondscorekeeper = NULL;
502 FOREACH_CLIENT(IS_PLAYER(it), {
503 sk = CS(it).scorekeeper;
504 c = PlayerScore_Compare(winnerscorekeeper, sk, true);
507 WinningConditionHelper_second = WinningConditionHelper_winner;
508 WinningConditionHelper_winner = it;
509 secondscorekeeper = winnerscorekeeper;
510 winnerscorekeeper = sk;
514 c = PlayerScore_Compare(secondscorekeeper, sk, true);
517 WinningConditionHelper_second = it;
518 secondscorekeeper = sk;
523 WinningConditionHelper_equality = (PlayerScore_Compare(winnerscorekeeper, secondscorekeeper, false) == 0);
524 if(WinningConditionHelper_equality)
525 WinningConditionHelper_winner = WinningConditionHelper_second = NULL;
527 WinningConditionHelper_topscore = winnerscorekeeper.scores_primary;
528 WinningConditionHelper_secondscore = secondscorekeeper.scores_primary;
529 WinningConditionHelper_lowerisbetter = (scores_flags_primary & SFL_LOWER_IS_BETTER);
530 WinningConditionHelper_zeroisworst = (scores_flags_primary & SFL_ZERO_IS_WORST);
532 WinningConditionHelper_winnerteam = -1; // no teamplay
533 WinningConditionHelper_secondteam = -1; // no teamplay
536 if(WinningConditionHelper_topscore == 0)
538 if(scores_flags_primary & SFL_ZERO_IS_WORST)
540 if(WinningConditionHelper_lowerisbetter)
541 WinningConditionHelper_topscore = 999999999;
543 WinningConditionHelper_topscore = -999999999;
545 if(player_count == 0) // special case: empty servers DO end the match at a 0:0 tie
546 WinningConditionHelper_equality = 0;
549 if(WinningConditionHelper_secondscore == 0)
551 if(scores_flags_primary & SFL_ZERO_IS_WORST)
553 if(WinningConditionHelper_lowerisbetter)
554 WinningConditionHelper_secondscore = 999999999;
556 WinningConditionHelper_secondscore = -999999999;
560 strcpy(worldstatus, s);
562 FOREACH_CLIENT(true, {
566 s = GetPlayerScoreString(it, 1);
567 s = strcat(s, IS_REAL_CLIENT(it) ? ":human" : ":bot");
568 if(!(IS_PLAYER(it) || INGAME_JOINED(it)))
569 s = strcat(s, ":spectator");
573 if (IS_PLAYER(it) || INGAME_JOINED(it))
574 s = GetPlayerScoreString(it, 2);
579 strcpy(it.clientstatus, s);
583 string GetScoreLogLabel(string label, float fl)
585 if(fl & SFL_LOWER_IS_BETTER)
586 label = strcat(label, "<");
587 if((fl & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
588 label = strcat(label, "!!");
589 else if((fl & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
590 label = strcat(label, "!");
594 string GetPlayerScoreString(entity pl, float shortString)
605 FOREACH(Scores, true, {
606 if ((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
608 f = scores_flags(it);
609 l = scores_label(it);
610 out = strcat(out, GetScoreLogLabel(l, f), ",");
614 FOREACH(Scores, true, {
615 if((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
617 f = scores_flags(it);
618 l = scores_label(it);
619 out = strcat(out, GetScoreLogLabel(l, f), ",");
623 FOREACH(Scores, true, {
624 if((scores_flags(it) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
625 if((scores_flags(it) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
627 f = scores_flags(it);
628 l = scores_label(it);
629 out = strcat(out, GetScoreLogLabel(l, f), ",");
632 out = substring(out, 0, strlen(out) - 1);
634 else if((sk = CS(pl).scorekeeper))
636 FOREACH(Scores, true, {
637 if ((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
638 out = strcat(out, ftos(sk.(scores(it))), ",");
641 FOREACH(Scores, true, {
642 if ((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
643 out = strcat(out, ftos(sk.(scores(it))), ",");
646 FOREACH(Scores, true, {
647 if((scores_flags(it) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
648 if((scores_flags(it) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
649 out = strcat(out, ftos(sk.(scores(it))), ",");
651 out = substring(out, 0, strlen(out) - 1);
656 string GetTeamScoreString(float tm, float shortString)
667 for(i = 0; i < MAX_TEAMSCORE; ++i)
668 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
670 f = teamscores_flags(i);
671 l = teamscores_label(i);
672 out = strcat(out, GetScoreLogLabel(l, f), ",");
675 for(i = 0; i < MAX_TEAMSCORE; ++i)
676 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
678 f = teamscores_flags(i);
679 l = teamscores_label(i);
680 out = strcat(out, GetScoreLogLabel(l, f), ",");
683 for(i = 0; i < MAX_TEAMSCORE; ++i)
684 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
685 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
687 f = teamscores_flags(i);
688 l = teamscores_label(i);
689 out = strcat(out, GetScoreLogLabel(l, f), ",");
691 out = substring(out, 0, strlen(out) - 1);
693 else if((sk = teamscorekeepers[tm - 1]))
695 for(i = 0; i < MAX_TEAMSCORE; ++i)
696 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
697 out = strcat(out, ftos(sk.(teamscores(i))), ",");
699 for(i = 0; i < MAX_TEAMSCORE; ++i)
700 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
701 out = strcat(out, ftos(sk.(teamscores(i))), ",");
703 for(i = 0; i < MAX_TEAMSCORE; ++i)
704 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
705 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
706 out = strcat(out, ftos(sk.(teamscores(i))), ",");
707 out = substring(out, 0, strlen(out) - 1);
712 float PlayerTeamScore_Compare(entity p1, entity p2, float teams, bool strict)
714 if(teams && teamscores_entities_count)
716 if(p1.team != p2.team)
720 t1 = teamscorekeepers[p1.team - 1];
721 t2 = teamscorekeepers[p2.team - 1];
722 r = TeamScore_Compare(t1, t2, ((teams >= 0) ? 1 : strict));
729 return PlayerScore_Compare(CS(p1).scorekeeper, CS(p2).scorekeeper, strict);
732 entity PlayerScore_Sort(.float field, int teams, bool strict, bool nospectators)
734 entity p, plist, pprev, pbest, pbestprev, pfirst, plast;
739 FOREACH_CLIENT(true, { it.(field) = 0; });
741 FOREACH_CLIENT(CS(it).scorekeeper,
744 if(it.frags == FRAGS_SPECTATOR)
750 // Now plist points to the whole list.
752 pfirst = plast = NULL;
757 pprev = pbestprev = NULL;
759 for(p = plist; (pprev = p), (p = p.chain); )
761 if(PlayerTeamScore_Compare(p, pbest, teams, strict) > 0)
768 // remove pbest out of the chain
769 if(pbestprev == NULL)
772 pbestprev.chain = pbest.chain;
776 if(!plast || PlayerTeamScore_Compare(plast, pbest, teams, strict))
791 float TeamScore_GetCompareValue(float t)
796 if(t <= 0 || t >= 16)
800 error("Reading score of invalid team!");
803 sk = teamscorekeepers[t - 1];
806 s = sk.teamscores_primary;
807 if(teamscores_flags_primary & SFL_ZERO_IS_WORST)
810 if(teamscores_flags_primary & SFL_LOWER_IS_BETTER)
815 const float NAMEWIDTH = 22;
816 const float SCORESWIDTH = 58;
817 // TODO put this somewhere in common?
818 string Score_NicePrint_ItemColor(float vflags)
820 if(vflags & SFL_SORT_PRIO_PRIMARY)
822 else if(vflags & SFL_SORT_PRIO_SECONDARY)
828 void Score_NicePrint_Team(entity to, float t, float w)
836 sk = teamscorekeepers[t - 1];
839 s = strcat(s, Team_ColoredFullName(t));
840 for(i = 0; i < MAX_TEAMSCORE; ++i)
841 if(teamscores_label(i) != "")
843 fl = teamscores_flags(i);
844 sc = sk.(teamscores(i));
845 s = strcat(s, " ", Score_NicePrint_ItemColor(fl), ScoreString(fl, sc));
851 s = strcat(s, strpad(max(0, NAMEWIDTH - strlennocol(s)), ""));
853 FOREACH(Scores, true, {
854 if(scores_label(it) != "")
856 fl = scores_flags(it);
857 s2 = scores_label(it);
858 s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, substring(s2, 0, w)));
865 void Score_NicePrint_Player(entity to, entity p, float w)
873 sk = CS(p).scorekeeper;
875 s = strcat(s, playername(p.netname, p.team, false));
878 i = strlennocol(s) - NAMEWIDTH;
880 s = substring(s, 0, strlen(s) - i);
883 s = strcat(s, strpad(i, ""));
888 FOREACH(Scores, true, {
889 if(scores_label(it) != "")
891 fl = scores_flags(it);
892 sc = sk.(scores(it));
893 s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, ScoreString(fl, sc)));
900 void Score_NicePrint_Spectators(entity to)
902 print_to(to, "Spectators:");
905 void Score_NicePrint_Spectator(entity to, entity p)
907 print_to(to, strcat(" ", playername(p.netname, p.team, false)));
910 .float score_dummyfield;
911 void Score_NicePrint(entity to)
917 FOREACH(Scores, true, {
918 if(scores_label(it) != "")
921 w = bound(6, floor(SCORESWIDTH / t - 1), 9);
923 p = PlayerScore_Sort(score_dummyfield, 1, true, false);
926 if(!teamscores_entities_count)
927 Score_NicePrint_Team(to, t, w);
930 if(teamscores_entities_count)
932 Score_NicePrint_Team(to, p.team, w);
933 Score_NicePrint_Player(to, p, w);
939 FOREACH_CLIENT(!IS_PLAYER(it), {
941 Score_NicePrint_Spectators(to);
942 Score_NicePrint_Spectator(to, it);
947 void PlayerScore_PlayerStats(entity p)
949 entity s = CS(p).scorekeeper;
950 FOREACH(Scores, true, {
951 if(s.(scores(it)) != 0 && scores_label(it) != "")
952 PlayerStats_GameReport_Event_Player(s.owner,
953 strcat(PLAYERSTATS_SCOREBOARD, scores_label(it)), s.(scores(it)));
957 void PlayerScore_TeamStats()
961 for(t = 0; t < 16; ++t)
963 sk = teamscorekeepers[t];
966 for(i = 0; i < MAX_TEAMSCORE; ++i)
967 if(sk.(teamscores(i)) != 0 && teamscores_label(i) != "")
968 // the +1 is important here!
969 PlayerStats_GameReport_Event_Team(t+1,
970 strcat(PLAYERSTATS_SCOREBOARD, teamscores_label(i)), sk.(teamscores(i)));