Skip to content

Commit

Permalink
Fix the ladder ranking for lap mode.
Browse files Browse the repository at this point in the history
All players that finished the race are now sorted by times instead of being considered equal.
  • Loading branch information
Aessi committed Feb 1, 2018
1 parent d121389 commit 944d0d8
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions Common/Scripts/Libs/Nadeo/TrackMania/Scores.Script.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Scores library
* Manage players and teams scores
*/
#Const Version "2017-06-28"
#Const Version "2018-01-02"
#Const ScriptName "Libs/Nadeo/TrackMania/Scores.Script.txt"

// ---------------------------------- //
Expand Down Expand Up @@ -1222,6 +1222,36 @@ Void SetupLadder(CTmScore _Score, Integer _LadderRank, Integer _LadderClan, Real
*/
Void ComputeLadder(Integer _SortCriteria, Integer _Order) {
Log::Log("""[Scores] Compute ladder with the following sort criteria : {{{_SortCriteria}}} and order: {{{_Order}}}""");

// Special computation with two criterias for best race checkpoints
if (_SortCriteria == C_Sort_BestRaceCheckpointsProgress) {
declare DoubleRanking = Integer[CTmScore][Integer];
foreach (Score in Scores) {
declare Points = GetPlayerBestRaceCheckpointsProgress(Score);
declare Time = -Private_GetPlayerLastCheckpointTime(Score.BestRace);

if (!DoubleRanking.existskey(Points)) {
DoubleRanking[Points] = Integer[CTmScore];
}
DoubleRanking[Points][Score] = Time;
}
DoubleRanking = DoubleRanking.sortkey();

declare Rank = 1;
foreach (Points => Times in DoubleRanking) {
declare SortedTimes = Times.sort();
foreach (Score => Time in SortedTimes) {
declare LibScores_BestRaceCheckpointsProgressPoints for Score = 0;
if (Points <= 0 || Time > 0) { //< The player did not start the race (check time > 0 because we inversed its value in the previous step)
LibScores_BestRaceCheckpointsProgressPoints = 0;
} else {
LibScores_BestRaceCheckpointsProgressPoints = Rank;
}
Rank += 1;
}
}
}

foreach (Score in Scores) {
declare Points = 0;
declare Time = -1;
Expand All @@ -1248,7 +1278,8 @@ Void ComputeLadder(Integer _SortCriteria, Integer _Order) {
Points = GetPlayerBestRaceNbRespawns(Score);
}
case C_Sort_BestRaceCheckpointsProgress: {
Points = GetPlayerBestRaceCheckpointsProgress(Score);
declare LibScores_BestRaceCheckpointsProgressPoints for Score = 0;
Points = LibScores_BestRaceCheckpointsProgressPoints;
Time = Private_GetPlayerLastCheckpointTime(Score.BestRace);
}
case C_Sort_PrevRaceTime: {
Expand Down

0 comments on commit 944d0d8

Please sign in to comment.