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;
26 var .float scores_secondary;
27 float scores_flags_secondary;
30 int ScoreField_Compare(entity t1, entity t2, .float field, float fieldflags, int previous)
32 if(fieldflags & SFL_NOT_SORTABLE) // column does not sort
34 if (t1.(field) == t2.(field))
37 if(fieldflags & SFL_ZERO_IS_WORST)
44 else if (t2.(field) == 0)
51 if (fieldflags & SFL_LOWER_IS_BETTER)
52 previous = (t2.(field) - t1.(field));
54 previous = (t1.(field) - t2.(field));
63 bool TeamScore_SendEntity(entity this, entity to, float sendflags)
67 WriteHeader(MSG_ENTITY, ENT_CLIENT_TEAMSCORES);
68 int t = this.team - 1;
69 assert(t, eprint(this));
70 WriteByte(MSG_ENTITY, t);
73 for(i = 0; i < MAX_TEAMSCORE; ++i)
74 if(this.(teamscores(i)) > 127 || this.(teamscores(i)) <= -128)
77 #if MAX_TEAMSCORE <= 8
78 WriteByte(MSG_ENTITY, sendflags);
79 WriteByte(MSG_ENTITY, longflags);
81 WriteShort(MSG_ENTITY, sendflags);
82 WriteShort(MSG_ENTITY, longflags);
84 for(i = 0; i < MAX_TEAMSCORE; ++i)
85 if(sendflags & BIT(i))
87 if(longflags & BIT(i))
88 WriteInt24_t(MSG_ENTITY, this.(teamscores(i)));
90 WriteChar(MSG_ENTITY, this.(teamscores(i)));
96 void TeamScore_Spawn(float t, string name)
98 entity ts = new_pure(csqc_score_team);
99 ts.netname = name; // not used yet, FIXME
101 Net_LinkEntity(ts, false, 0, TeamScore_SendEntity);
102 teamscorekeepers[t - 1] = ts;
103 ++teamscores_entities_count;
104 PlayerStats_GameReport_AddTeam(t);
107 float TeamScore_AddToTeam(int t, float scorefield, float score)
116 if(!scores_initialized) return 0; // FIXME remove this when everything uses this system
117 if(t <= 0 || t >= 16)
121 error("Adding score to invalid team!");
123 s = teamscorekeepers[t - 1];
128 error("Adding score to unknown team!");
131 if(teamscores_label(scorefield) != "")
132 s.SendFlags |= BIT(scorefield);
133 return (s.(teamscores(scorefield)) += score);
136 float TeamScore_Add(entity player, float scorefield, float score)
138 return TeamScore_AddToTeam(player.team, scorefield, score);
141 // strict: compare others fields too besides primary and secondary
142 int TeamScore_Compare(entity t1, entity t2, bool strict)
144 if(!t1 || !t2) return (!t2) - !t1;
146 // supporting MAX_TEAMSCORE > 2 requires keeping track of primary and secondary teamscore
147 if (MAX_TEAMSCORE > 2)
148 error("MAX_TEAMSCORE > 2 not supported");
150 // first compare primary, then others (don't check secondary flag since there are only 2 teamscores)
152 int i = boolean(teamscores_primary && teamscores_primary == teamscores(1));
153 result = ScoreField_Compare(t1, t2, teamscores(i), teamscores_flags(i), result);
154 if (result == 0 && strict)
156 i = (i + 1) % MAX_TEAMSCORE;
157 result = ScoreField_Compare(t1, t2, teamscores(i), teamscores_flags(i), result);
159 result = t1.team - t2.team;
166 * the scoreinfo entity
169 void ScoreInfo_SetLabel_PlayerScore(PlayerScoreField i, string label, float scoreflags)
171 scores_label(i) = label;
172 scores_flags(i) = scoreflags;
173 if((scoreflags & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
175 scores_primary = scores(i);
176 scores_flags_primary = scoreflags;
178 else if((scoreflags & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
180 scores_secondary = scores(i);
181 scores_flags_secondary = scoreflags;
185 PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_TOTAL, label));
186 PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_SCOREBOARD, label));
190 void ScoreInfo_SetLabel_TeamScore(float i, string label, float scoreflags)
192 teamscores_label(i) = label;
193 teamscores_flags(i) = scoreflags;
194 if((scoreflags & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
196 teamscores_primary = teamscores(i);
197 teamscores_flags_primary = scoreflags;
201 PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_TOTAL, label));
202 PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_SCOREBOARD, label));
206 bool ScoreInfo_SendEntity(entity this, entity to, int sf)
209 WriteHeader(MSG_ENTITY, ENT_CLIENT_SCORES_INFO);
210 WriteRegistered(Gametypes, MSG_ENTITY, MapInfo_LoadedGametype);
211 FOREACH(Scores, true, {
212 WriteString(MSG_ENTITY, scores_label(it));
213 WriteByte(MSG_ENTITY, scores_flags(it));
215 for(i = 0; i < MAX_TEAMSCORE; ++i)
217 WriteString(MSG_ENTITY, teamscores_label(i));
218 WriteByte(MSG_ENTITY, teamscores_flags(i));
220 // prevent sending the welcome message again when score types are sent again because the scoring system has changed
221 // it can happen in some game modes like Race when the qualyfing session ends and the race starts
222 bool welcome_msg_too = (!CS(to) || time < CS(to).jointime + 5);
223 WriteByte(MSG_ENTITY, welcome_msg_too);
224 // welcome message is sent here because it needs to know the gametype
226 SendWelcomeMessage(to, MSG_ENTITY);
230 void ScoreInfo_Init(int teams)
232 if(scores_initialized)
234 scores_initialized.SendFlags |= 1; // force a resend
238 scores_initialized = new_pure(ent_client_scoreinfo);
239 Net_LinkEntity(scores_initialized, false, 0, ScoreInfo_SendEntity);
242 TeamScore_Spawn(NUM_TEAM_1, "Red");
244 TeamScore_Spawn(NUM_TEAM_2, "Blue");
246 TeamScore_Spawn(NUM_TEAM_3, "Yellow");
248 TeamScore_Spawn(NUM_TEAM_4, "Pink");
252 * per-player score entities
255 bool PlayerScore_SendEntity(entity this, entity to, float sendflags)
257 WriteHeader(MSG_ENTITY, ENT_CLIENT_SCORES);
258 WriteByte(MSG_ENTITY, etof(this.owner));
261 FOREACH(Scores, true, {
262 int p = 1 << (i % 16);
263 if (this.(scores(it)) > 127 || this.(scores(it)) <= -128)
267 WriteShort(MSG_ENTITY, sendflags);
268 WriteShort(MSG_ENTITY, longflags);
269 FOREACH(Scores, true, {
270 int p = 1 << (i % 16);
274 WriteInt24_t(MSG_ENTITY, this.(scores(it)));
276 WriteChar(MSG_ENTITY, this.(scores(it)));
283 float PlayerScore_Clear(entity player)
287 if(teamscores_entities_count)
290 if(MUTATOR_CALLHOOK(ForbidPlayerScore_Clear)) return 0;
292 sk = CS(player).scorekeeper;
293 FOREACH(Scores, true, {
294 if(sk.(scores(it)) != 0)
295 if(scores_label(it) != "")
296 sk.SendFlags |= BIT(i % 16);
304 void Score_ClearAll()
308 FOREACH_CLIENTSLOT(true, {
309 sk = CS(it).scorekeeper;
311 FOREACH(Scores, true, {
312 if(sk.(scores(it)) != 0)
313 if(scores_label(it) != "")
314 sk.SendFlags |= BIT(i % 16);
319 for(t = 0; t < 16; ++t)
321 sk = teamscorekeepers[t];
324 for(int j = 0; j < MAX_TEAMSCORE; ++j)
326 if(sk.(teamscores(j)) != 0)
327 if(teamscores_label(j) != "")
328 sk.SendFlags |= BIT(j);
329 sk.(teamscores(j)) = 0;
334 void PlayerScore_Attach(entity player)
336 if(CS(player).scorekeeper)
337 error("player already has a scorekeeper");
338 entity sk = new_pure(scorekeeper);
340 Net_LinkEntity(sk, false, 0, PlayerScore_SendEntity);
341 CS(player).scorekeeper = sk;
344 void PlayerScore_Detach(entity player)
346 if(!CS(player).scorekeeper)
347 error("player has no scorekeeper");
348 delete(CS(player).scorekeeper);
349 CS(player).scorekeeper = NULL;
352 float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score)
354 bool mutator_returnvalue = MUTATOR_CALLHOOK(AddPlayerScore, scorefield, score, player);
355 score = M_ARGV(1, float);
357 if(!mutator_returnvalue && game_stopped)
362 if(!scores_initialized) return 0; // FIXME remove this when everything uses this system
363 entity s = CS(player).scorekeeper;
368 LOG_WARN("Adding score to unknown player!");
373 return s.(scores(scorefield));
375 if(scores_label(scorefield) != "")
376 s.SendFlags |= BIT(scorefield.m_id % 16);
378 PlayerStats_GameReport_Event_Player(s.owner, strcat(PLAYERSTATS_TOTAL, scores_label(scorefield)), score);
379 s.(scores(scorefield)) += score;
380 MUTATOR_CALLHOOK(AddedPlayerScore, scorefield, score, player);
381 return s.(scores(scorefield));
384 float PlayerScore_Set(entity player, PlayerScoreField scorefield, float score)
386 if(!scores_initialized) return 0; // FIXME remove this when everything uses this system
387 entity s = CS(player).scorekeeper;
392 LOG_WARN("Setting score of unknown player!");
396 float oldscore = s.(scores(scorefield));
397 if(oldscore == score)
400 if(scores_label(scorefield) != "")
401 s.SendFlags |= BIT(scorefield.m_id % 16);
402 s.(scores(scorefield)) = score;
403 return s.(scores(scorefield));
406 float PlayerTeamScore_Add(entity player, PlayerScoreField pscorefield, float tscorefield, float score)
409 r = PlayerScore_Add(player, pscorefield, score);
410 if(teamscores_entities_count) // only for teamplay
411 r = TeamScore_Add(player, tscorefield, score);
415 // strict: compare others fields too besides primary and secondary
416 float PlayerScore_Compare(entity t1, entity t2, bool strict)
418 if(!t1 || !t2) return (!t2) - !t1;
421 result = ScoreField_Compare(t1, t2, scores_primary, scores_flags_primary, result);
422 // NOTE: if (scores_secondary) doesn't work because it's a field pointer
423 if (result == 0 && scores_flags_secondary)
424 result = ScoreField_Compare(t1, t2, scores_secondary, scores_flags_secondary, result);
426 if (result == 0 && strict)
428 FOREACH(Scores, true, {
429 if (scores_flags(it) & SFL_SORT_PRIO_MASK)
431 if (scores_label(it) == "")
433 var .float f = scores(it);
434 result = ScoreField_Compare(t1, t2, f, scores_flags(it), result);
438 result = t1.owner.playerid - t2.owner.playerid;
444 void WinningConditionHelper(entity this)
448 entity winnerscorekeeper;
449 entity secondscorekeeper;
453 // gametype:P<pure>:S<slots>::plabel,plabel:tlabel,tlabel:teamid:tscore,tscore:teamid:tscore,tscore
454 // score labels always start with a symbol or with lower case
455 // so to match pure, match for :P0:
456 // to match full, match for :S0:
458 // NOTE can't use a single strcat because strcat concatenates max 8 strings
459 s = strcat(GetGametype(),
460 ":", autocvar_g_xonoticversion,
461 ":P", ftos(cvar_purechanges_count),
462 ":S", ftos(nJoinAllowed(this, NULL)));
464 ":F", ftos(serverflags),
465 ":T", sv_termsofservice_url_escaped,
468 "::", GetPlayerScoreString(NULL, (autocvar_g_full_getstatus_responses ? 1 : 2)));
470 if(teamscores_entities_count)
474 s = strcat(s, ":", GetTeamScoreString(0, 1));
475 for(t = 0; t < 16; ++t)
476 if(teamscorekeepers[t])
477 s = strcat(s, ":", ftos(t+1), ":", GetTeamScoreString(t+1, 1));
479 WinningConditionHelper_winnerteam = -1;
480 WinningConditionHelper_secondteam = -1;
481 winnerscorekeeper = NULL;
482 secondscorekeeper = NULL;
483 for(t = 0; t < 16; ++t)
485 sk = teamscorekeepers[t];
486 c = TeamScore_Compare(winnerscorekeeper, sk, true);
489 WinningConditionHelper_secondteam = WinningConditionHelper_winnerteam;
490 WinningConditionHelper_winnerteam = t + 1;
491 secondscorekeeper = winnerscorekeeper;
492 winnerscorekeeper = sk;
496 c = TeamScore_Compare(secondscorekeeper, sk, true);
499 WinningConditionHelper_secondteam = t + 1;
500 secondscorekeeper = sk;
505 WinningConditionHelper_equality = (TeamScore_Compare(winnerscorekeeper, secondscorekeeper, false) == 0);
506 if(WinningConditionHelper_equality)
507 WinningConditionHelper_winnerteam = WinningConditionHelper_secondteam = -1;
509 WinningConditionHelper_topscore = winnerscorekeeper.teamscores_primary;
510 WinningConditionHelper_secondscore = secondscorekeeper.teamscores_primary;
511 WinningConditionHelper_lowerisbetter = (teamscores_flags_primary & SFL_LOWER_IS_BETTER);
512 WinningConditionHelper_zeroisworst = (teamscores_flags_primary & SFL_ZERO_IS_WORST);
514 WinningConditionHelper_winner = NULL; // not supported in teamplay
515 WinningConditionHelper_second = NULL; // not supported in teamplay
519 WinningConditionHelper_winner = NULL;
520 WinningConditionHelper_second = NULL;
521 winnerscorekeeper = NULL;
522 secondscorekeeper = NULL;
523 FOREACH_CLIENT(IS_PLAYER(it), {
524 sk = CS(it).scorekeeper;
525 c = PlayerScore_Compare(winnerscorekeeper, sk, true);
528 WinningConditionHelper_second = WinningConditionHelper_winner;
529 WinningConditionHelper_winner = it;
530 secondscorekeeper = winnerscorekeeper;
531 winnerscorekeeper = sk;
535 c = PlayerScore_Compare(secondscorekeeper, sk, true);
538 WinningConditionHelper_second = it;
539 secondscorekeeper = sk;
544 WinningConditionHelper_equality = (PlayerScore_Compare(winnerscorekeeper, secondscorekeeper, false) == 0);
545 if(WinningConditionHelper_equality)
546 WinningConditionHelper_winner = WinningConditionHelper_second = NULL;
548 WinningConditionHelper_topscore = winnerscorekeeper.scores_primary;
549 WinningConditionHelper_secondscore = secondscorekeeper.scores_primary;
550 WinningConditionHelper_lowerisbetter = (scores_flags_primary & SFL_LOWER_IS_BETTER);
551 WinningConditionHelper_zeroisworst = (scores_flags_primary & SFL_ZERO_IS_WORST);
553 WinningConditionHelper_winnerteam = -1; // no teamplay
554 WinningConditionHelper_secondteam = -1; // no teamplay
557 if(WinningConditionHelper_topscore == 0)
559 if(scores_flags_primary & SFL_ZERO_IS_WORST)
561 if(WinningConditionHelper_lowerisbetter)
562 WinningConditionHelper_topscore = 999999999;
564 WinningConditionHelper_topscore = -999999999;
566 if(player_count == 0) // special case: empty servers DO end the match at a 0:0 tie
567 WinningConditionHelper_equality = 0;
570 if(WinningConditionHelper_secondscore == 0)
572 if(scores_flags_primary & SFL_ZERO_IS_WORST)
574 if(WinningConditionHelper_lowerisbetter)
575 WinningConditionHelper_secondscore = 999999999;
577 WinningConditionHelper_secondscore = -999999999;
581 if (s != worldstatus)
582 strcpy(worldstatus, s);
584 FOREACH_CLIENT(true, {
586 if(autocvar_g_full_getstatus_responses)
588 s = GetPlayerScoreString(it, 1);
589 s = strcat(s, IS_REAL_CLIENT(it) ? ":human" : ":bot");
590 if(!(IS_PLAYER(it) || INGAME_JOINED(it)))
591 s = strcat(s, ":spectator");
595 if (IS_PLAYER(it) || INGAME_JOINED(it))
596 s = GetPlayerScoreString(it, 2);
601 if (s != it.clientstatus)
602 strcpy(it.clientstatus, s);
606 string GetScoreLogLabel(string label, float fl)
608 if(fl & SFL_LOWER_IS_BETTER)
609 label = strcat(label, "<");
610 if((fl & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
611 label = strcat(label, "!!");
612 else if((fl & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
613 label = strcat(label, "!");
617 string GetPlayerScoreString(entity pl, float shortString)
628 FOREACH(Scores, true, {
629 if ((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
631 f = scores_flags(it);
632 l = scores_label(it);
633 out = strcat(out, GetScoreLogLabel(l, f), ",");
637 FOREACH(Scores, true, {
638 if((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
640 f = scores_flags(it);
641 l = scores_label(it);
642 out = strcat(out, GetScoreLogLabel(l, f), ",");
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)
650 f = scores_flags(it);
651 l = scores_label(it);
652 out = strcat(out, GetScoreLogLabel(l, f), ",");
655 out = substring(out, 0, strlen(out) - 1);
657 else if((sk = CS(pl).scorekeeper))
659 FOREACH(Scores, true, {
660 if ((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
661 out = strcat(out, ftos(sk.(scores(it))), ",");
664 FOREACH(Scores, true, {
665 if ((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
666 out = strcat(out, ftos(sk.(scores(it))), ",");
669 FOREACH(Scores, true, {
670 if((scores_flags(it) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
671 if((scores_flags(it) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
672 out = strcat(out, ftos(sk.(scores(it))), ",");
674 out = substring(out, 0, strlen(out) - 1);
679 string GetTeamScoreString(float tm, float shortString)
690 for(i = 0; i < MAX_TEAMSCORE; ++i)
691 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
693 f = teamscores_flags(i);
694 l = teamscores_label(i);
695 out = strcat(out, GetScoreLogLabel(l, f), ",");
698 for(i = 0; i < MAX_TEAMSCORE; ++i)
699 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
701 f = teamscores_flags(i);
702 l = teamscores_label(i);
703 out = strcat(out, GetScoreLogLabel(l, f), ",");
706 for(i = 0; i < MAX_TEAMSCORE; ++i)
707 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
708 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
710 f = teamscores_flags(i);
711 l = teamscores_label(i);
712 out = strcat(out, GetScoreLogLabel(l, f), ",");
714 out = substring(out, 0, strlen(out) - 1);
716 else if((sk = teamscorekeepers[tm - 1]))
718 for(i = 0; i < MAX_TEAMSCORE; ++i)
719 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
720 out = strcat(out, ftos(sk.(teamscores(i))), ",");
722 for(i = 0; i < MAX_TEAMSCORE; ++i)
723 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
724 out = strcat(out, ftos(sk.(teamscores(i))), ",");
726 for(i = 0; i < MAX_TEAMSCORE; ++i)
727 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
728 if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
729 out = strcat(out, ftos(sk.(teamscores(i))), ",");
730 out = substring(out, 0, strlen(out) - 1);
735 // strict: compare others fields too besides primary and secondary
736 int PlayerTeamScore_Compare(entity p1, entity p2, float teams, bool strict)
738 if(teams && teamscores_entities_count)
740 if(p1.team != p2.team)
744 t1 = teamscorekeepers[p1.team - 1];
745 t2 = teamscorekeepers[p2.team - 1];
746 r = TeamScore_Compare(t1, t2, ((teams >= 0) ? 1 : strict));
753 return PlayerScore_Compare(CS(p1).scorekeeper, CS(p2).scorekeeper, strict);
756 entity PlayerScore_Sort(.float field, int teams, bool strict, bool nospectators)
758 entity p, plist, pprev, pbest, pbestprev, pfirst, plast;
763 FOREACH_CLIENT(true, { it.(field) = 0; });
765 FOREACH_CLIENT(CS(it).scorekeeper,
768 if(it.frags == FRAGS_SPECTATOR)
774 // Now plist points to the whole list.
776 pfirst = plast = NULL;
781 pprev = pbestprev = NULL;
783 for(p = plist; (pprev = p), (p = p.chain); )
785 if(PlayerTeamScore_Compare(p, pbest, teams, strict) > 0)
792 // remove pbest out of the chain
793 if(pbestprev == NULL)
796 pbestprev.chain = pbest.chain;
800 if(!plast || PlayerTeamScore_Compare(plast, pbest, teams, strict))
815 float TeamScore_GetCompareValue(float t)
820 if(t <= 0 || t >= 16)
824 error("Reading score of invalid team!");
827 sk = teamscorekeepers[t - 1];
830 s = sk.teamscores_primary;
831 if(teamscores_flags_primary & SFL_ZERO_IS_WORST)
834 if(teamscores_flags_primary & SFL_LOWER_IS_BETTER)
839 const float NAMEWIDTH = 22;
840 const float SCORESWIDTH = 58;
841 // TODO put this somewhere in common?
842 string Score_NicePrint_ItemColor(float vflags)
844 if(vflags & SFL_SORT_PRIO_PRIMARY)
846 else if(vflags & SFL_SORT_PRIO_SECONDARY)
852 void Score_NicePrint_Team(entity to, float t, float w)
860 sk = teamscorekeepers[t - 1];
863 s = strcat(s, Team_ColoredFullName(t));
864 for(i = 0; i < MAX_TEAMSCORE; ++i)
865 if(teamscores_label(i) != "")
867 fl = teamscores_flags(i);
868 sc = sk.(teamscores(i));
869 s = strcat(s, " ", Score_NicePrint_ItemColor(fl), ScoreString(fl, sc, 0));
875 s = strcat(s, strpad(max(0, NAMEWIDTH - strlennocol(s)), ""));
877 FOREACH(Scores, true, {
878 if(scores_label(it) != "")
880 fl = scores_flags(it);
881 s2 = scores_label(it);
882 s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, substring(s2, 0, w)));
889 void Score_NicePrint_Player(entity to, entity p, float w)
897 sk = CS(p).scorekeeper;
899 s = strcat(s, playername(p.netname, p.team, false));
902 i = strlennocol(s) - NAMEWIDTH;
904 s = substring(s, 0, strlen(s) - i);
907 s = strcat(s, strpad(i, ""));
912 FOREACH(Scores, true, {
913 if(scores_label(it) != "")
915 fl = scores_flags(it);
916 sc = sk.(scores(it));
917 s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, ScoreString(fl, sc, 0)));
924 void Score_NicePrint_Spectators(entity to)
926 print_to(to, "Spectators:");
929 void Score_NicePrint_Spectator(entity to, entity p)
931 print_to(to, strcat(" ", playername(p.netname, p.team, false)));
934 .float score_dummyfield;
935 void Score_NicePrint(entity to)
941 FOREACH(Scores, true, {
942 if(scores_label(it) != "")
945 w = bound(6, floor(SCORESWIDTH / t - 1), 9);
947 p = PlayerScore_Sort(score_dummyfield, 1, true, false);
950 if(!teamscores_entities_count)
951 Score_NicePrint_Team(to, t, w);
954 if(teamscores_entities_count)
956 Score_NicePrint_Team(to, p.team, w);
957 Score_NicePrint_Player(to, p, w);
963 FOREACH_CLIENT(!IS_PLAYER(it), {
965 Score_NicePrint_Spectators(to);
966 Score_NicePrint_Spectator(to, it);
971 void PlayerScore_PlayerStats(entity p)
973 entity s = CS(p).scorekeeper;
974 FOREACH(Scores, true, {
975 if(s.(scores(it)) != 0 && scores_label(it) != "")
976 PlayerStats_GameReport_Event_Player(s.owner,
977 strcat(PLAYERSTATS_SCOREBOARD, scores_label(it)), s.(scores(it)));
981 void PlayerScore_TeamStats()
985 for(t = 0; t < 16; ++t)
987 sk = teamscorekeepers[t];
990 for(i = 0; i < MAX_TEAMSCORE; ++i)
991 if(sk.(teamscores(i)) != 0 && teamscores_label(i) != "")
992 // the +1 is important here!
993 PlayerStats_GameReport_Event_Team(t+1,
994 strcat(PLAYERSTATS_SCOREBOARD, teamscores_label(i)), sk.(teamscores(i)));