From 2873ff87513ee8c3cf794f33e80cc6192d89953a Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 19 Oct 2020 18:56:17 +1000 Subject: [PATCH] Minor cleanup to player score sorting functions --- qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc | 2 +- .../common/gamemodes/gamemode/race/sv_race.qc | 2 +- qcsrc/common/playerstats.qc | 4 ++-- qcsrc/server/scores.qc | 20 +++++++++---------- qcsrc/server/scores.qh | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc index 08c4f84be..70bd105ef 100644 --- a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc +++ b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc @@ -149,7 +149,7 @@ MUTATOR_HOOKFUNCTION(cts, reset_map_global) Score_NicePrint(NULL); race_ClearRecords(); - PlayerScore_Sort(race_place, 0, 1, 0); + PlayerScore_Sort(race_place, 0, true, false); FOREACH_CLIENT(true, { if(it.race_place) diff --git a/qcsrc/common/gamemodes/gamemode/race/sv_race.qc b/qcsrc/common/gamemodes/gamemode/race/sv_race.qc index 39c72a459..bd5f8b438 100644 --- a/qcsrc/common/gamemodes/gamemode/race/sv_race.qc +++ b/qcsrc/common/gamemodes/gamemode/race/sv_race.qc @@ -208,7 +208,7 @@ MUTATOR_HOOKFUNCTION(rc, reset_map_global) Score_NicePrint(NULL); race_ClearRecords(); - PlayerScore_Sort(race_place, 0, 1, 0); + PlayerScore_Sort(race_place, 0, true, false); FOREACH_CLIENT(true, { if(it.race_place) diff --git a/qcsrc/common/playerstats.qc b/qcsrc/common/playerstats.qc index 4a7f35203..2400d4750 100644 --- a/qcsrc/common/playerstats.qc +++ b/qcsrc/common/playerstats.qc @@ -167,8 +167,8 @@ void PlayerStats_GameReport(bool finished) { if(PS_GR_OUT_DB < 0) { return; } - PlayerScore_Sort(score_dummyfield, 0, 0, 0); - PlayerScore_Sort(scoreboard_pos, 1, 1, 1); + PlayerScore_Sort(score_dummyfield, 0, false, false); + PlayerScore_Sort(scoreboard_pos, 1, true, true); if(teamplay) { PlayerScore_TeamStats(); } FOREACH_CLIENT(true, { diff --git a/qcsrc/server/scores.qc b/qcsrc/server/scores.qc index eefd06fe3..3113e8a96 100644 --- a/qcsrc/server/scores.qc +++ b/qcsrc/server/scores.qc @@ -24,7 +24,7 @@ var .float teamscores_primary; float scores_flags_primary; float teamscores_flags_primary; -vector ScoreField_Compare(entity t1, entity t2, .float field, float fieldflags, vector previous, float strict) // returns: cmp value, best prio +vector ScoreField_Compare(entity t1, entity t2, .float field, float fieldflags, vector previous, bool strict) // returns: cmp value, best prio { if(!strict && !(fieldflags & SFL_SORT_PRIO_MASK)) // column does not sort return previous; @@ -139,7 +139,7 @@ float TeamScore_Add(entity player, float scorefield, float score) return TeamScore_AddToTeam(player.team, scorefield, score); } -float TeamScore_Compare(entity t1, entity t2, float strict) +float TeamScore_Compare(entity t1, entity t2, bool strict) { if(!t1 || !t2) return (!t2) - !t1; @@ -396,7 +396,7 @@ float PlayerTeamScore_Add(entity player, PlayerScoreField pscorefield, float tsc return r; } -float PlayerScore_Compare(entity t1, entity t2, float strict) +float PlayerScore_Compare(entity t1, entity t2, bool strict) { if(!t1 || !t2) return (!t2) - !t1; @@ -492,7 +492,7 @@ void WinningConditionHelper(entity this) secondscorekeeper = NULL; FOREACH_CLIENT(IS_PLAYER(it), { sk = CS(it).scorekeeper; - c = PlayerScore_Compare(winnerscorekeeper, sk, 1); + c = PlayerScore_Compare(winnerscorekeeper, sk, true); if(c < 0) { WinningConditionHelper_second = WinningConditionHelper_winner; @@ -502,7 +502,7 @@ void WinningConditionHelper(entity this) } else { - c = PlayerScore_Compare(secondscorekeeper, sk, 1); + c = PlayerScore_Compare(secondscorekeeper, sk, true); if(c < 0) { WinningConditionHelper_second = it; @@ -511,7 +511,7 @@ void WinningConditionHelper(entity this) } }); - WinningConditionHelper_equality = (PlayerScore_Compare(winnerscorekeeper, secondscorekeeper, 0) == 0); + WinningConditionHelper_equality = (PlayerScore_Compare(winnerscorekeeper, secondscorekeeper, false) == 0); if(WinningConditionHelper_equality) WinningConditionHelper_winner = WinningConditionHelper_second = NULL; @@ -699,7 +699,7 @@ string GetTeamScoreString(float tm, float shortString) return out; } -float PlayerTeamScore_Compare(entity p1, entity p2, float teams, float strict) +float PlayerTeamScore_Compare(entity p1, entity p2, float teams, bool strict) { if(teams && teamscores_entities_count) { @@ -719,7 +719,7 @@ float PlayerTeamScore_Compare(entity p1, entity p2, float teams, float strict) return PlayerScore_Compare(CS(p1).scorekeeper, CS(p2).scorekeeper, strict); } -entity PlayerScore_Sort(.float field, float teams, float strict, float nospectators) +entity PlayerScore_Sort(.float field, int teams, bool strict, bool nospectators) { entity p, plist, pprev, pbest, pbestprev, pfirst, plast; float i, j; @@ -763,7 +763,7 @@ entity PlayerScore_Sort(.float field, float teams, float strict, float nospectat pbest.chain = NULL; ++i; - if(!plast || PlayerTeamScore_Compare(plast, pbest, teams, 0)) + if(!plast || PlayerTeamScore_Compare(plast, pbest, teams, false)) j = i; pbest.(field) = j; @@ -910,7 +910,7 @@ void Score_NicePrint(entity to) }); w = bound(6, floor(SCORESWIDTH / t - 1), 9); - p = PlayerScore_Sort(score_dummyfield, 1, 1, 0); + p = PlayerScore_Sort(score_dummyfield, 1, true, false); t = -1; if(!teamscores_entities_count) diff --git a/qcsrc/server/scores.qh b/qcsrc/server/scores.qh index ad4061966..cae0169aa 100644 --- a/qcsrc/server/scores.qh +++ b/qcsrc/server/scores.qh @@ -136,4 +136,4 @@ string GetTeamScoreString(float tm, float shortString); * strict: return a strict ordering * nospectators: exclude spectators */ -entity PlayerScore_Sort(.float field, float teams, float strict, float nospectators); +entity PlayerScore_Sort(.float field, int teams, bool strict, bool nospectators); -- 2.39.2