Compare commits

..

No commits in common. "bad8dd4f58edce68cf5ecfdb7738e344fca08e5a" and "2b824e5e412977846cdef346e3b7541f67b06858" have entirely different histories.

View File

@ -8,7 +8,7 @@
#Extends "Libs/Nadeo/TMNext/TrackMania/Modes/TMNextRoundsBase.Script.txt"
#Const CompatibleMapTypes "TrackMania\\TM_Race,TM_Race"
#Const Version "2023-08-08"
#Const Version "2022-06-11"
#Const ScriptName "Modes/TM2020-Gamemodes/TM_ReverseCup.Script.txt"
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
@ -34,7 +34,6 @@
#Setting S_NbOfWinners 1 as _("Number of winners")
#Setting S_FinishTimeout -1 as _("Finish timeout")
#Setting S_ComplexPointsRepartition "" as "JSON of PointsRepartition depending for the number of the Players Alive" // Example: {"3": [3, 6, 10], "4,5": [1, 3, 6,10]}
#Setting S_PointsRepartition "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20"
#Setting S_RoundsPerMap 5 as _("Number of rounds per map") ///< Number of round to play on one map before going to the next one
@ -160,12 +159,12 @@ foreach (Event in PendingEvents) {
if (Server_MatchInfo.RegistrationClosed && !Server_MatchInfo.Participants.exists(Event.Player.User.Login)) {
Scores::SetPlayerMatchPoints(Event.Player.Score, C_Points_Spectator);
// Equivalent of getCustomPoints:
declare netwrite Text[][Text] Net_TMxSM_ScoresTable_CustomPoints for Teams[0] = [];
declare netwrite Text[][Text] Net_TMxSM_ScoresTable_CustomPoints for Teams[0];
Net_TMxSM_ScoresTable_CustomPoints[Event.Player.User.WebServicesUserId] = [C_Text_Spectator, C_Color_Spectator];
}
}
}
declare netwrite Integer Net_ReverseCup_LiveRanking_Update for Teams[0] = 0;
declare netwrite Integer Net_ReverseCup_LiveRanking_Update for Teams[0];
Net_ReverseCup_LiveRanking_Update += 1;
}
@ -178,7 +177,6 @@ declare Integer Server_PointsLimit;
declare Integer Server_RoundsPerMap;
declare Integer Server_NbOfWinners;
declare Integer Server_DNF_LossPoints;
declare Text Server_ComplexPointsRepartition;
***
***Match_StartServer***
@ -205,14 +203,12 @@ Server_PointsLimit = S_PointsStartup;
Server_RoundsPerMap = S_RoundsPerMap;
Server_NbOfWinners = S_NbOfWinners;
Server_DNF_LossPoints = S_DNF_LossPoints;
Server_ComplexPointsRepartition = S_ComplexPointsRepartition;
***
***Match_StartMatch***
***
UIModules_ScoresTable::SetCustomPoints([]);
UpdateComplexPointsRepartition(S_ComplexPointsRepartition);
declare K_MatchInfo Server_MatchInfo for This = K_MatchInfo {};
Server_MatchInfo = K_MatchInfo {};
***
@ -296,7 +292,7 @@ MB_WarmUp(S_WarmUpNb, S_WarmUpDuration * 1000, S_WarmUpTimeout * 1000);
***Match_StartWarmUp***
***
declare netwrite Integer Net_ReverseCup_LiveRanking_Update for Teams[0] = 0;
declare netwrite Integer Net_ReverseCup_LiveRanking_Update for Teams[0];
Net_ReverseCup_LiveRanking_Update += 1;
***
@ -325,30 +321,15 @@ if (S_EnableCollisions) {
ModeUtils::PlaySound(CUIConfig::EUISound::PhaseChange, 0);
if (S_RoundsPerMap > 0) {
UIModules_BigMessage::SetMessage(_("Round: ") ^ TL::ToText(G_NbOfValidRounds + 1) ^ " / " ^ TL::ToText(S_RoundsPerMap));
} else {
UIModules_BigMessage::SetMessage(_("Round: ") ^ TL::ToText(G_NbOfValidRounds + 1));
}
UIModules_BigMessage::SetMessage(_("Rounds : ") ^ TL::ToText(G_NbOfValidRounds + 1) ^ " / " ^ TL::ToText(S_RoundsPerMap));
MB_Sleep(3000);
UIModules_BigMessage::SetMessage("");
declare Integer Round_NbPlayersInThisRound = 0;
***
***Match_StartRound***
***
UpdateScoresTableFooter(S_PointsStartup, S_RoundsPerMap, G_NbOfValidRounds, S_NbOfWinners);
declare K_MatchInfo Server_MatchInfo for This = K_MatchInfo {};
foreach (Score in Scores) {
if (Score.User == Null) continue;
if (Scores::GetPlayerMatchPoints(Score) < C_Points_LastChance) continue;
if (!Server_MatchInfo.Participants.exists(Score.User.Login)) continue;
Round_NbPlayersInThisRound += 1;
}
CheckRoundBeforePlay(Round_NbPlayersInThisRound);
CheckRoundBeforePlay();
UpdateDNFLossPoints(Server_DNF_LossPoints);
StateMgr::ForcePlayersStates([CupCommon_Const::C_State_Playing]);
@ -375,7 +356,7 @@ CarRank::ThrottleUpdate(CarRank::C_SortCriteria_CurrentRace);
***Match_PlayLoop***
***
// Manage race events
declare Events::K_RaceEvent[] RacePendingEvents = Race::GetPendingEvents();
declare RacePendingEvents = Race::GetPendingEvents();
foreach (Event in RacePendingEvents) {
Race::ValidEvent(Event);
@ -384,10 +365,10 @@ foreach (Event in RacePendingEvents) {
CarRank::ThrottleUpdate(CarRank::C_SortCriteria_CurrentRace);
if (Event.Player != Null) {
if (Event.IsEndRace) {
Scores::UpdatePlayerBestRaceIfBetter(Event.Player);
Scores::UpdatePlayerBestLapIfBetter(Event.Player);
declare BetterRace = Scores::UpdatePlayerBestRaceIfBetter(Event.Player);
declare BetterLap = Scores::UpdatePlayerBestLapIfBetter(Event.Player);
Scores::UpdatePlayerPrevRace(Event.Player);
ComputeLatestRaceScores(Round_NbPlayersInThisRound);
ComputeLatestRaceScores();
Race::SortScores(Race::C_Sort_TotalPoints);
@ -398,7 +379,7 @@ foreach (Event in RacePendingEvents) {
}
}
if (Event.IsEndLap) {
Scores::UpdatePlayerBestLapIfBetter(Event.Player);
declare Better = Scores::UpdatePlayerBestLapIfBetter(Event.Player);
}
}
}
@ -427,11 +408,6 @@ if (Server_PointsLimit != S_PointsStartup ||
UpdateScoresTableFooter(S_PointsStartup, S_RoundsPerMap, G_NbOfValidRounds, S_NbOfWinners);
UpdateDNFLossPoints(Server_DNF_LossPoints);
}
if (Server_ComplexPointsRepartition != S_ComplexPointsRepartition) {
Server_ComplexPointsRepartition = S_ComplexPointsRepartition;
UpdateComplexPointsRepartition(Server_ComplexPointsRepartition);
}
***
***Match_EndRound***
@ -459,7 +435,7 @@ if (Round_ForceEndRound || Round_SkipPauseRound || Round_Skipped) {
MB_Sleep(3000);
} else {
// Get the last round points
ComputeLatestRaceScores(Round_NbPlayersInThisRound);
ComputeLatestRaceScores();
+++Cup_EndRound_BeforeScoresUpdate+++
Race::SortScores(Race::C_Sort_TotalPoints);
UIManager.UIAll.ScoreTableVisibility = CUIConfig::EVisibility::ForcedVisible;
@ -491,11 +467,11 @@ UIModules_ScoresTable::DisplayRoundPoints(False);
Race::SortScores(Race::C_Sort_TotalPoints);
if (MB_MatchIsRunning()) {
MB_SkipPodiumSequence();
} else {
declare CSmScore Eliminated <=> Scores::GetBestPlayer(Scores::C_Sort_MatchPoints);
if (!MB_MatchIsRunning()) {
declare Eliminated <=> Scores::GetBestPlayer(Scores::C_Sort_MatchPoints);
Scores::SetPlayerWinner(Eliminated);
} else {
MB_SkipPodiumSequence();
}
***
@ -507,10 +483,10 @@ declare Text[] WinnersNames;
foreach (Player in Players) {
if(!Spectators.exists(Player)) {
if (Scores::GetPlayerMatchPoints(Player.Score) >= C_Points_LastChance) {
if (Player.User.ClubTag == "") {
WinnersNames.add(Player.User.Name);
} else {
if (Player.User.ClubTag != "") {
WinnersNames.add("[$<"^Player.User.ClubTag^"$>] " ^ Player.User.Name);
} else {
WinnersNames.add(Player.User.Name);
}
}
}
@ -548,7 +524,7 @@ UIModules_ScoresTable::ResetTrophies();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
Void UpdateDNFLossPoints(Integer _DNF_LossPoints) {
declare netwrite Integer Net_ReverseCup_DNF_LossPoints for Teams[0] = 0;
declare netwrite Integer Net_ReverseCup_DNF_LossPoints for Teams[0];
Net_ReverseCup_DNF_LossPoints = _DNF_LossPoints;
}
@ -562,7 +538,7 @@ Void UpdateDNFLossPoints(Integer _DNF_LossPoints) {
*/
Void UpdateScoresTableFooter(Integer _PointsLimit, Integer _RoundsPerMap, Integer _ValidRoundsNb, Integer _NbOfWinners) {
declare Text[] Parts;
declare Text Message = "";
declare Message = "";
if (_PointsLimit > 0) {
if (Parts.count > 0) Message ^= "\n";
@ -591,28 +567,13 @@ Void UpdateDNFLossPoints(Integer _DNF_LossPoints) {
}
}
Void UpdateComplexPointsRepartition(Text _ComplexPointsRepartition) {
declare Integer[][Integer] Server_ComplexPointsRepartition for This = [];
Server_ComplexPointsRepartition = [];
declare Integer[][Text] TextComplexPointsRepartition;
TextComplexPointsRepartition.fromjson(_ComplexPointsRepartition);
foreach (TextMultipleRemainingPlayers => PointsRepartition in TextComplexPointsRepartition) {
declare Text[] MultipleRemainingPlayers = TL::Split(",", TextMultipleRemainingPlayers);
foreach (TextRemainingPlayers in MultipleRemainingPlayers) {
Server_ComplexPointsRepartition[TL::ToInteger(TextRemainingPlayers)] = PointsRepartition;
}
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Get the time left to the players to finish the round after the first player
*
* @return The time left in ms
*/
Integer GetFinishTimeout() {
declare Integer FinishTimeout = 0;
declare FinishTimeout = 0;
if (S_FinishTimeout >= 0) {
FinishTimeout = S_FinishTimeout * 1000;
@ -636,7 +597,7 @@ Integer GetFinishTimeout() {
* @param _Rank The rank of the new looser
*/
Void AnnounceEliminated(Text _Name, Integer _Rank) {
declare Text Message = "";
declare Message = "";
switch (_Rank) {
case 1: Message = TL::Compose("$f90$i$<%1$> takes 1st place!", _Name);
case 2: Message = TL::Compose("$f90$i$<%1$> takes 2nd place!", _Name);
@ -648,19 +609,11 @@ Void AnnounceEliminated(Text _Name, Integer _Rank) {
UIModules_BigMessage::SetMessage(Message);
}
Integer[] GetPointsRepartition(Integer _NbPlayersInThisRound) {
declare Integer[] PointsRepartition;
declare Integer[][Integer] Server_ComplexPointsRepartition for This = [];
Integer[] GetPointsRepartition() {
declare Integer[] PointsRepartition = PointsRepartition::GetPointsRepartition();
if (Server_ComplexPointsRepartition.existskey(_NbPlayersInThisRound)) {
PointsRepartition = Server_ComplexPointsRepartition[_NbPlayersInThisRound];
} else {
PointsRepartition = PointsRepartition::GetPointsRepartition();
}
if (S_FastForwardPointsRepartition && _NbPlayersInThisRound > PointsRepartition.count) {
if (S_FastForwardPointsRepartition) {
foreach (Score in Scores) {
if (_NbPlayersInThisRound <= PointsRepartition.count) break;
declare Integer Points = Scores::GetPlayerMatchPoints(Score);
if (Points > C_Points_Spectator && Points <= C_Points_Eliminated) {
PointsRepartition = PointsRepartition.slice(1, PointsRepartition.count - 1);
@ -673,32 +626,33 @@ Integer[] GetPointsRepartition(Integer _NbPlayersInThisRound) {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/// Compute the latest race scores
Void ComputeLatestRaceScores(Integer _NbPlayersInThisRound) {
Void ComputeLatestRaceScores() {
Race::SortScores(Race::C_Sort_PrevRaceTime);
// Points distributed between all players
declare Integer Key = 0;
declare I = 0;
declare J = 0;
declare CSmPlayer[] LastChancePlayersDNF_WithWorstCheckpoints;
declare Integer MinCheckpointNbPassed = 9999;
declare Integer[] PointsRepartition = GetPointsRepartition(_NbPlayersInThisRound);
declare Integer[] PointsRepartition = GetPointsRepartition();
foreach (Score in Scores) {
// Skip Spectators and already eliminated players
if (Scores::GetPlayerMatchPoints(Score) < C_Points_LastChance) continue;
if (Scores::GetPlayerPrevRaceTime(Score) > 0) {
declare Integer Points = 0;
declare Points = 0;
if (PointsRepartition.count > 0) {
if (PointsRepartition.existskey(Key)) {
Points = 0 - PointsRepartition[Key];
if (PointsRepartition.existskey(I)) {
Points = 0 - PointsRepartition[I];
} else {
Points = 0 - PointsRepartition[PointsRepartition.count - 1];
}
}
Scores::SetPlayerRoundPoints(Score, Points);
Key += 1;
I += 1;
} else {
// Apply DNF penality if Disconnected
if (Score.User == Null) {
@ -729,6 +683,7 @@ Void ComputeLatestRaceScores(Integer _NbPlayersInThisRound) {
Scores::SetPlayerRoundPoints(Score, 0 - S_DNF_LossPoints);
}
}
J += 1;
}
if(S_LastChance_DNF_Mode == 1) {
foreach(Player in LastChancePlayersDNF_WithWorstCheckpoints) {
@ -746,7 +701,7 @@ Void ComputeScores() {
Race::SortScores(Race::C_Sort_TotalPoints);
declare Integer MaxRoundPoints = 0;
declare MaxRoundPoints = 0;
foreach (Score in Scores) {
if (MaxRoundPoints > Scores::GetPlayerRoundPoints(Score) && Scores::GetPlayerMatchPoints(Score) > C_Points_Eliminated) MaxRoundPoints = Scores::GetPlayerRoundPoints(Score);
}
@ -812,7 +767,7 @@ Void ComputeScores() {
* @return True if it is the case, false otherwise
*/
Boolean MapIsOver() {
if (S_RoundsPerMap > 0 && G_NbOfValidRounds >= S_RoundsPerMap) return True;
if (G_NbOfValidRounds >= S_RoundsPerMap) return True;
return False;
}
@ -824,17 +779,20 @@ Boolean MapIsOver() {
*/
Boolean MatchIsOver() {
Log::Log("[Cup] MatchIsOver() check | S_PointsStartup : "^S_PointsStartup);
declare Integer NbOfPlayersActive = 0;
foreach (Score in Scores) {
if (Scores::GetPlayerMatchPoints(Score) >= C_Points_LastChance) NbOfPlayersActive += 1;
declare NbOfPlayersActive = 0;
foreach (Player in Players) {
if(!Spectators.exists(Player)) {
if (Scores::GetPlayerMatchPoints(Player.Score) >= C_Points_LastChance) NbOfPlayersActive += 1;
}
}
declare K_MatchInfo Server_MatchInfo for This = K_MatchInfo {};
if (Server_MatchInfo.Participants.count == 1) {
return NbOfPlayersActive == 0;
}
// If there's only one player they need to reach the points limit to win
// If there's more than one player then all players except one must reach the points limit
declare PlayerEliminatedLimit = ML::Max(Players.count - 1, 1);
Log::Log("""[Cup] Match is over ? {{{(S_NbOfWinners >= NbOfPlayersActive)}}} | ({{{S_NbOfWinners}}} >= {{{NbOfPlayersActive}}})""");
if (S_NbOfWinners >= NbOfPlayersActive) return True;
return S_NbOfWinners >= NbOfPlayersActive;
return False;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
@ -861,14 +819,14 @@ Void DisplayCustomPoints() {
/** Check round before playing it, if necessary to fast forward it
*
*/
Void CheckRoundBeforePlay(Integer _NbPlayersInThisRound) {
Void CheckRoundBeforePlay() {
if(S_AllowFastForwardRounds == True) {
declare Integer[] PointsRepartition = GetPointsRepartition(_NbPlayersInThisRound);
declare Integer[] PointsRepartition = GetPointsRepartition();
declare Boolean IsRoundFastForwardCompatible = True;
// Check if no players are LastChance or have more points than the minimum points
foreach (Score in Scores) {
declare Integer PlayerMatchPoints = Scores::GetPlayerMatchPoints(Score);
declare PlayerMatchPoints = Scores::GetPlayerMatchPoints(Score);
if (PlayerMatchPoints == C_Points_LastChance || PlayerMatchPoints > PointsRepartition[0]) {
IsRoundFastForwardCompatible = False;
@ -879,7 +837,7 @@ Void CheckRoundBeforePlay(Integer _NbPlayersInThisRound) {
// if no one, do :
if(IsRoundFastForwardCompatible == True) {
foreach (Score in Scores) {
declare Integer PlayerMatchPoints = Scores::GetPlayerMatchPoints(Score);
declare PlayerMatchPoints = Scores::GetPlayerMatchPoints(Score);
if (PlayerMatchPoints > C_Points_Eliminated) {
Scores::SetPlayerMatchPoints(Score, C_Points_LastChance);
}
@ -895,7 +853,7 @@ Void CheckRoundBeforePlay(Integer _NbPlayersInThisRound) {
}
Void UpdateLiveRaceUI() {
declare netwrite Integer Net_ReverseCup_LiveRanking_Update for Teams[0] = 0;
declare netwrite Integer Net_ReverseCup_LiveRanking_Update for Teams[0];
Net_ReverseCup_LiveRanking_Update += 1;
}