-
Notifications
You must be signed in to change notification settings - Fork 0
/
TM_RoundsThenTimeattack.Script.txt
633 lines (550 loc) · 21 KB
/
TM_RoundsThenTimeattack.Script.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
#Extends "Modes/Nadeo/Trackmania/Base/TrackmaniaRoundsBase.Script.txt"
// #RequireContext CSmMode
#Const CompatibleMapTypes "TrackMania\\TM_Race,TM_Race"
#Const Version "2024-08-12"
#Const ScriptName "Modes/TM2020-Gamemodes/TM_RoundsThenTimeattack.Script.txt"
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// MARK: Libraries
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
#Include "TextLib" as TL
#Include "MathLib" as ML
#Include "Libs/Nadeo/CMGame/Utils/Semver.Script.txt" as Semver
#Include "Libs/Nadeo/Trackmania/MainMenu/Constants.Script.txt" as MenuConsts
#Include "Libs/Nadeo/Trackmania/Modes/Rounds/StateManager.Script.txt" as StateMgr
#Include "Libs/Nadeo/TMGame/Utils/Tracking.Script.txt" as Tracking
#Include "Libs/Nadeo/TMGame/Modes/Base/UIModules/Checkpoint_Server.Script.txt" as UIModules_Checkpoint
#Include "Libs/Nadeo/TMGame/Modes/Base/UIModules/PauseMenuOnline_Server.Script.txt" as UIModules_PauseMenu_Online
#Include "Libs/Nadeo/CMGame/Modes/UIModules_Server.Script.txt" as UIModules_Server
#Include "Libs/Nadeo/CMGame/Modes/UIModules_Common.Script.txt" as UIModules_Common
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// MARK: Settings
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
#Setting S_DisableFreeCam False
#Setting S_TimeLimit 300 as _("Time limit") ///< Time limit before going to the next map
#Setting S_PointsLimit 50 as _("Points limit")
#Setting S_FinishTimeout -1 as _("Finish timeout")
#Setting S_RoundsPerMap -1 as _("Number of rounds per track") ///< Number of round to play on one map before going to the next one
#Setting S_MapsPerMatch -1 as _("Number of tracks per match") ///< Number of maps to play before finishing the match
#Setting S_UseTieBreak True as _("Use tie-break") ///< Continue to play the map until the tie is broken
#Setting S_WarmUpNb 0 as _("Number of warm up")
#Setting S_WarmUpDuration 0 as _("Duration of one warm up")
#Setting S_WarmUpTimeout -1 as _("Warm up timeout")
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// MARK: Constants
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
#Const C_ModeName "Rounds"
//L16N [Rounds] Description of the mode rules
#Const Description _("$zIn $<$t$6F9Rounds$z$z$> mode, the goal is to win a maximum number of $<$t$6F9points.\n\n$z$>The rounds mode consists of $<$t$6F9a series of races$z$>.\nWhen you finish a race in a good $<$t$6F9position$z$>, you get $<$t$6F9points$z$>, added to your total.\n\nThe $<$t$6F9winner$z$> is the first player whose total reaches the $<$t$6F9point limit$z$> (30 for example).")
#Const C_HudModulePath "" //< Path to the hud module
#Const C_ManiaAppUrl "file://Media/ManiaApps/Nadeo/Trackmania/Modes/Rounds.Script.txt" //< Url of the mania app
#Const C_FakeUsersNb 0
#Const C_PointsLimit_NotReached 0
#Const C_PointsLimit_Reached 1
#Const C_PointsLimit_Tie 2
#Const C_UploadRecord True
#Const C_DisplayRecordGhost False
#Const C_DisplayRecordMedal False
#Const C_CelebrateRecordGhost True
#Const C_CelebrateRecordMedal True
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// MARK: Extends
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
***Match_LogVersions***
***
Log::RegisterScript(ScriptName, Version);
Log::RegisterScript(Semver::ScriptName, Semver::Version);
Log::RegisterScript(ModeUtils::ScriptName, ModeUtils::Version);
Log::RegisterScript(StateMgr::ScriptName, StateMgr::Version);
***
***Match_LoadLibraries***
***
StateMgr::Load();
***
***Match_UnloadLibraries***
***
StateMgr::Unload();
***
***Match_Settings***
***
MB_Settings_UseDefaultHud = (C_HudModulePath == "");
MB_Settings_UseDefaultRespawnBehaviour = False;
***
***Match_Rules***
***
ModeInfo::SetName(C_ModeName);
ModeInfo::SetType(ModeInfo::C_Type_FreeForAll);
ModeInfo::SetRules(Description);
ModeInfo::SetStatusMessage("");
***
***Match_LoadHud***
***
if (C_HudModulePath != "") Hud_Load(C_HudModulePath);
***
***Match_AfterLoadHud***
***
ClientManiaAppUrl = C_ManiaAppUrl;
Race::SortScores(Race::C_Sort_TotalPoints);
UIModules_ScoresTable::SetScoreMode(UIModules_ScoresTable::C_Mode_Points);
UIModules_Checkpoint::SetVisibilityTimeDiff(False);
UIModules_Checkpoint::SetRankMode(UIModules_Checkpoint::C_RankMode_CurrentRace);
UIModules_PauseMenu_Online::SetHelp(Description);
UIModules_Sign16x9Small::SetScoreMode(UIModules_Sign16x9Small::C_ScoreMode_Points);
// Hide SM Overlay
UIManager.UIAll.OverlayHideSpectatorInfos = True;
UIManager.UIAll.OverlayHideCountdown = True;
***
***Match_Yield***
***
foreach (Event in PendingEvents) {
switch (Event.Type) {
// Initialize players when they join the server
case CSmModeEvent::EType::OnPlayerAdded: {
StateMgr::InitializePlayer(Event.Player);
CarRank::InitializePlayer(Event.Player);
}
}
}
StateMgr::Yield();
***
***Match_InitServer***
***
declare Integer Server_PointsLimit;
declare Integer Server_RoundsPerMap;
declare Integer Server_MapsPerMatch;
***
***Match_StartServer***
***
// Initialize mode
Clans::SetClansNb(0);
Scores::SaveInScore(Scores::C_Points_Match);
StateMgr::ForcePlayersStates([StateMgr::C_State_Waiting]);
WarmUp::SetAvailability(True);
Race::SetupRecord(
MenuConsts::C_ScopeType_Season,
MenuConsts::C_ScopeType_PersonalBest,
MenuConsts::C_GameMode_Rounds,
"",
C_UploadRecord,
C_DisplayRecordGhost,
C_DisplayRecordMedal,
C_CelebrateRecordGhost,
C_CelebrateRecordMedal
);
Server_PointsLimit = S_PointsLimit - 1;
Server_RoundsPerMap = S_RoundsPerMap - 1;
Server_MapsPerMatch = S_MapsPerMatch - 1;
***
***Match_InitMap***
***
declare Integer Map_ValidRoundsNb;
declare Boolean Map_Skipped;
UpdateScoresTableFooter(S_PointsLimit, S_RoundsPerMap, S_MapsPerMatch, Map_ValidRoundsNb);
***
***Match_StartMap***
***
// Add bot when necessary
Users_SetNbFakeUsers(C_FakeUsersNb, 0);
UIManager.UIAll.PlayerDisableFreeCam = S_DisableFreeCam;
Map_Skipped = True;
CarRank::Reset();
// Warm up
UIModules_ScoresTable::SetFooterInfo(_("Warm up"));
MB_WarmUp(S_WarmUpNb, S_WarmUpDuration * 1000, S_WarmUpTimeout * 1000);
***
***Match_InitRound***
***
declare Boolean Round_IsTimeAttack;
declare Integer Round_TimeLimit;
declare Integer[Ident] Round_Scores_Times;
***
***Match_StartRound***
***
UpdateScoresTableFooter(S_PointsLimit, S_RoundsPerMap, S_MapsPerMatch, Map_ValidRoundsNb);
StateMgr::ForcePlayersStates([StateMgr::C_State_Playing]);
Round_IsTimeAttack = (Map_ValidRoundsNb + 1 >= S_RoundsPerMap);
if (Round_IsTimeAttack) {
Race::SetRespawnBehaviour(Race::C_RespawnBehaviour_GiveUpBeforeFirstCheckpoint);
Round_TimeLimit = S_TimeLimit;
StartTime = Now + Race::C_SpawnDuration;
SetTimeLimit(StartTime, S_TimeLimit);
UIModules_Server::Private_CustomizableModule_SetProperties("Rounds_SmallScoresTable", UIModules_Common::K_ModuleProperties {
Position = <-158.5, 40.>,
Scale = 1.,
Visible = False
});
UIModules_ScoresTable::SetScoreMode(UIModules_ScoresTable::C_Mode_PrevTime);
} else {
Race::SetRespawnBehaviour(Race::C_RespawnBehaviour_NeverGiveUp);
UIModules_Server::Private_CustomizableModule_SetProperties("Rounds_SmallScoresTable", UIModules_Common::K_ModuleProperties {
Position = <-158.5, 40.>,
Scale = 1.,
Visible = True
});
UIModules_ScoresTable::SetScoreMode(UIModules_ScoresTable::C_Mode_Points);
}
UIModules_ScoresTable::SetCustomTimes([]);
***
***Rounds_PlayerSpawned***
***
CarRank::ThrottleUpdate(CarRank::C_SortCriteria_CurrentRace);
***
***Match_PlayLoop***
***
// Manage race events
foreach (Event in Race::GetPendingEvents()) {
Race::ValidEvent(Event);
// Waypoint
if (Event.Type == Events::C_Type_Waypoint) {
CarRank::ThrottleUpdate(CarRank::C_SortCriteria_CurrentRace);
if (Event.Player != Null && Event.Player.Score != Null) {
if (Event.IsEndRace) {
Scores::UpdatePlayerBestRaceIfBetter(Event.Player);
Scores::UpdatePlayerBestLapIfBetter(Event.Player);
Scores::UpdatePlayerPrevRace(Event.Player);
Race::SortScores(Race::C_Sort_TotalPoints);
if (Round_IsTimeAttack) {
if (!Round_Scores_Times.existskey(Event.Player.Score.Id)) {
Round_Scores_Times[Event.Player.Score.Id] = Event.RaceTime;
declare Integer[Text] CustomTimes = UIModules_ScoresTable::GetCustomTimes();
CustomTimes[Event.Player.User.WebServicesUserId] = Event.RaceTime;
UIModules_ScoresTable::SetCustomTimes(CustomTimes);
} else if (Round_Scores_Times[Event.Player.Score.Id] > Event.RaceTime) {
Round_Scores_Times[Event.Player.Score.Id] = Event.RaceTime;
declare Integer[Text] CustomTimes = UIModules_ScoresTable::GetCustomTimes();
CustomTimes[Event.Player.User.WebServicesUserId] = Event.RaceTime;
UIModules_ScoresTable::SetCustomTimes(CustomTimes);
}
} else {
ComputeLatestRaceScores();
}
// Start the countdown if it's the first player to finish
if (EndTime <= 0) {
EndTime = GetFinishTimeout(S_FinishTimeout);
}
}
if (Event.IsEndLap) {
Scores::UpdatePlayerBestLapIfBetter(Event.Player);
}
}
}
}
if (Round_IsTimeAttack) {
if (PlayersNbDead > 0) {
foreach (Player in Players) {
if (Player.SpawnStatus == CSmPlayer::ESpawnStatus::NotSpawned && Race::IsReadyToStart(Player)) {
Race::Start(Player);
}
}
}
// Update the map duration setting
if (Round_TimeLimit != S_TimeLimit) {
Round_TimeLimit = S_TimeLimit;
SetTimeLimit(StartTime, S_TimeLimit);
}
}
// Manage mode events
foreach (Event in PendingEvents) {
if (Event.HasBeenPassed || Event.HasBeenDiscarded) continue;
Events::Invalid(Event);
}
// Server info change
if (
Server_PointsLimit != S_PointsLimit ||
Server_RoundsPerMap != S_RoundsPerMap ||
Server_MapsPerMatch != S_MapsPerMatch
) {
Server_PointsLimit = S_PointsLimit;
Server_RoundsPerMap = S_RoundsPerMap;
Server_MapsPerMatch = S_MapsPerMatch;
UpdateScoresTableFooter(S_PointsLimit, S_RoundsPerMap, S_MapsPerMatch, Map_ValidRoundsNb);
}
***
***Rounds_CheckStopRound***
***
// End the round
// If All players finished
if (!Round_IsTimeAttack && Players.count > 0 && PlayersNbAlive <= 0) {
MB_StopRound();
Round_Skipped = False;
}
// If time limit is reached
if (EndTime > 0 && Now >= EndTime) {
MB_StopRound();
Round_Skipped = False;
}
// If forced end round or round skipped after pause
if (Round_ForceEndRound || Round_SkipPauseRound) {
MB_StopRound();
Round_Skipped = False;
}
***
***Match_EndRound***
***
Race::StopSkipOutroAll();
EndTime = -1;
StateMgr::ForcePlayersStates([StateMgr::C_State_Waiting]);
CarRank::Update(CarRank::C_SortCriteria_CurrentRace);
if (Semver::Compare(XmlRpc::GetApiVersion(), ">=", "2.1.1")) {
Scores::XmlRpc_SendScores(Scores::C_Section_PreEndRound, "");
}
if (Round_ForceEndRound || Round_SkipPauseRound || Round_Skipped) {
// Cancel points
foreach (Score in Scores) {
Scores::SetPlayerRoundPoints(Score, 0);
}
// Do not launch the forced end round sequence after a pause
if (!Round_SkipPauseRound) {
ForcedEndRoundSequence();
}
MB_SetValidRound(False);
} else {
Map_ValidRoundsNb += 1;
UIManager.UIAll.ScoreTableVisibility = CUIConfig::EVisibility::ForcedVisible;
UIManager.UIAll.UISequence = CUIConfig::EUISequence::EndRound;
// Get the last round points
if (Round_IsTimeAttack) {
MB_Sleep(3000);
ComputeBestRaceScores(Round_Scores_Times);
UIModules_ScoresTable::SetCustomTimes([]);
UIModules_ScoresTable::SetScoreMode(UIModules_ScoresTable::C_Mode_Points);
} else {
ComputeLatestRaceScores();
}
Race::SortScores(Race::C_Sort_TotalPoints);
MB_Sleep(3000);
// Add them to the total scores
ComputeScores();
Race::SortScores(Race::C_Sort_TotalPoints);
MB_Sleep(3000);
UIManager.UIAll.ScoreTableVisibility = CUIConfig::EVisibility::Normal;
UIManager.UIAll.UISequence = CUIConfig::EUISequence::Playing;
if (MapIsOver(S_UseTieBreak, S_PointsLimit, Map_ValidRoundsNb, S_RoundsPerMap)) {
Map_Skipped = False;
MB_StopMap();
}
}
***
***Match_EndMap***
***
if (MatchIsOver(S_UseTieBreak, S_PointsLimit, MB_GetMapCount(), S_MapsPerMatch, S_RoundsPerMap, Map_Skipped)) MB_StopMatch();
if (!MB_MapIsRunning() && MB_MatchIsRunning()) MB_SkipPodiumSequence();
Race::SortScores(Race::C_Sort_TotalPoints);
declare CSmScore Winner <=> Scores::GetBestPlayer(Scores::C_Sort_MatchPoints);
Scores::SetPlayerWinner(Winner);
if (!MB_MatchIsRunning()) {
// Compute ranking for tracking
declare Integer PreviousPoints = 0;
declare Integer Rank = 0;
foreach (Key => Score in Scores) {
if (Key == 0 || Scores::GetPlayerMatchPoints(Score) < PreviousPoints) {
PreviousPoints = Scores::GetPlayerMatchPoints(Score);
Rank = Key + 1;
}
Tracking::SendPlayerMatchResult(UIManager, Score.User, Rank, Winner == Score && Scores.count > 1);
}
}
***
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// MARK: Functions
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Update the time limit
*
* @param _StartTime The starting time of the map
* @param _NewTimeLimit The time limit before going to the next map
*/
Void SetTimeLimit(Integer _StartTime, Integer _NewTimeLimit) {
if (_NewTimeLimit <= 0) {
EndTime = -1;
UIModules_ScoresTable::SetFooterInfo(TL::Compose("%1 -", _("Time Limit")));
} else {
EndTime = _StartTime + (_NewTimeLimit * 1000);
UIModules_ScoresTable::SetFooterInfo(TL::Compose("%1 "^TL::TimeToText(_NewTimeLimit*1000), _("Time Limit")));
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Update the scores table footer text
*
* @param _PointsLimit The points limit
* @param _RoundsPerMap The number of rounds per map
* @param _MapsPerMatch The number of maps per match
* @param _ValidRoundsNb Number of valid rounds played
*/
Void UpdateScoresTableFooter(Integer _PointsLimit, Integer _RoundsPerMap, Integer _MapsPerMatch, Integer _ValidRoundsNb) {
declare Text[] Parts;
declare Text Message = "";
if (_PointsLimit > 0) {
if (Parts.count > 0) Message ^= "\n";
Message ^= """%{{{Parts.count + 1}}}{{{_PointsLimit}}}""";
//L16N [Rounds] Number of points to reach to win the match.
Parts.add(_("Points limit : "));
}
if (_RoundsPerMap > 0) {
if (Parts.count > 0) Message ^= "\n";
Message ^= """%{{{Parts.count + 1}}}{{{ML::Min(_ValidRoundsNb+1, _RoundsPerMap)}}}/{{{_RoundsPerMap}}}""";
//L16N [Rounds] Number of rounds played during the track.
Parts.add(_("Rounds : "));
}
if (_MapsPerMatch > 0) {
if (Parts.count > 0) Message ^= "\n";
Message ^= """%{{{Parts.count + 1}}}{{{MB_GetMapCount()}}}/{{{_MapsPerMatch}}}""";
//L16N [Rounds] Number of tracks played during the match.
Parts.add(_("Tracks : "));
}
switch (Parts.count) {
case 0: UIModules_ScoresTable::SetFooterInfo(Message);
case 1: UIModules_ScoresTable::SetFooterInfo(TL::Compose(Message, Parts[0]));
case 2: UIModules_ScoresTable::SetFooterInfo(TL::Compose(Message, Parts[0], Parts[1]));
case 3: UIModules_ScoresTable::SetFooterInfo(TL::Compose(Message, Parts[0], Parts[1], Parts[2]));
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Get the time left to the players to finish the round after the first player
*
* @return The time left in ms
*/
Integer GetFinishTimeout(Integer _FinishTimeout) {
declare Integer FinishTimeout = 0;
if (_FinishTimeout >= 0) {
FinishTimeout = _FinishTimeout * 1000;
} else {
FinishTimeout = 5000;
if (Map.TMObjective_IsLapRace && Race::GetLapsNb() > 0 && Map.TMObjective_NbLaps > 0) {
FinishTimeout += ((Map.TMObjective_AuthorTime / Map.TMObjective_NbLaps) * Race::GetLapsNb()) / 6;
} else {
FinishTimeout += Map.TMObjective_AuthorTime / 6;
}
}
return Now + FinishTimeout;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/// Compute the latest race scores
Void ComputeLatestRaceScores() {
Race::SortScores(Race::C_Sort_PrevRaceTime);
// Points distributed between all players
declare Integer I = 0;
declare Integer[] PointsRepartition = PointsRepartition::GetPointsRepartition();
foreach (Score in Scores) {
if (Scores::GetPlayerPrevRaceTime(Score) > 0) {
declare Integer Points = 0;
if (PointsRepartition.count > 0) {
if (PointsRepartition.existskey(I)) {
Points = PointsRepartition[I];
} else {
Points = PointsRepartition[PointsRepartition.count - 1];
}
}
Scores::SetPlayerRoundPoints(Score, Points);
I += 1;
} else {
Scores::SetPlayerRoundPoints(Score, 0);
}
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/// Compute the latest race scores
Void ComputeBestRaceScores(Integer[Ident] _Times) {
declare Integer[Ident] Times = _Times.sort();
// Points distributed between all players
declare Integer I = 0;
declare Integer[] PointsRepartition = PointsRepartition::GetPointsRepartition();
foreach (ScoreId => Time in Times) {
if (!Scores.existskey(ScoreId)) continue;
declare CSmScore Score <=> Scores[ScoreId];
declare Integer Points = 0;
if (PointsRepartition.count > 0) {
if (PointsRepartition.existskey(I)) {
Points = PointsRepartition[I];
} else {
Points = PointsRepartition[PointsRepartition.count - 1];
}
}
Scores::SetPlayerRoundPoints(Score, Points);
I += 1;
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/// Compute the map scores
Void ComputeScores() {
Scores::EndRound();
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Check if the points limit was reached
*
* @param _UseTieBreak Prevent ties or not
* @param _PointsLimit Number of points to get to win the match
*
* @return C_PointsLimit_Reached if the points limit is reached
* C_PointsLimit_Tie if there is a tie
* C_PointsLimit_NotReached if the points limit is not reached
*/
Integer PointsLimitReached(Boolean _UseTieBreak, Integer _PointsLimit) {
declare Integer MaxScore = -1;
declare Boolean Tie = False;
foreach (Score in Scores) {
declare Integer Points = Scores::GetPlayerMatchPoints(Score);
if (Points > MaxScore) {
MaxScore = Points;
Tie = False;
} else if (Points == MaxScore) {
Tie = True;
}
}
if (_UseTieBreak && Tie) return C_PointsLimit_Tie; //< There is a tie and it is not allowed
if (_PointsLimit > 0 && MaxScore >= _PointsLimit) return C_PointsLimit_Reached; //< There is a points limit and it is reached
return C_PointsLimit_NotReached; //< There is no points limit or the points limit is not reached
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Check if we should go to the next map
*
* @param _UseTieBreak Prevent ties or not
* @param _PointsLimit Number of points to get to win the match
* @param _ValidRoundsNb Number of valid rounds played
* @param _RoundsPerMap Number of rounds to play to complete the map
*
* @return True if it is the case, false otherwise
*/
Boolean MapIsOver(Boolean _UseTieBreak, Integer _PointsLimit, Integer _ValidRoundsNb, Integer _RoundsPerMap) {
declare Integer PointsLimitReached = PointsLimitReached(_UseTieBreak, _PointsLimit);
Log::Log("""[Rounds] MapIsOver() > _UseTieBreak: {{{_UseTieBreak}}} | _PointsLimit: {{{_PointsLimit}}} | _ValidRoundsNb: {{{_ValidRoundsNb}}} | _RoundsPerMap: {{{_RoundsPerMap}}} | PointsLimitReached: {{{PointsLimitReached}}}""");
if (PointsLimitReached == C_PointsLimit_Reached) return True; //< There is a points limit and it is reached
if (_RoundsPerMap > 0 && _ValidRoundsNb >= _RoundsPerMap) return True; //< There is a rounds limit and it is reached
return False;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Check if we should go to the next match
*
* @param _UseTieBreak Prevent ties or not
* @param _PointsLimit Number of points to get to win the match
* @param _MapsPerMatch Number of maps to play to complete a match
* @param _RoundsPerMap Number of rounds to play to complete the map
*
* @return True if it is the case, false otherwise
*/
Boolean MatchIsOver(Boolean _UseTieBreak, Integer _PointsLimit, Integer _MapCount, Integer _MapsPerMatch, Integer _RoundsPerMap, Boolean _MapSkipped) {
declare Integer PointsLimitReached = PointsLimitReached(_UseTieBreak, _PointsLimit);
Log::Log("""[Rounds] MatchIsOver() > _UseTieBreak: {{{_UseTieBreak}}} | _PointsLimit: {{{_PointsLimit}}} | _MapCount: {{{_MapCount}}} | _MapsPerMatch: {{{_MapsPerMatch}}} | _RoundsPerMap: {{{_RoundsPerMap}}} | PointsLimitReached: {{{PointsLimitReached}}} | _MapSkipped : {{{_MapSkipped}}}""");
// If there is a point limit and it is reached, stop the match
if (PointsLimitReached == C_PointsLimit_Reached) {
return True;
}
// If there is an explicit maps limit ...
else if (_MapsPerMatch >= 1) {
if (
(_MapCount >= _MapsPerMatch && PointsLimitReached != C_PointsLimit_Tie) || //< ... stop the match if the maps limit is reached and the match is not a tie
(_MapSkipped && _MapsPerMatch == 1 && _MapCount >= _MapsPerMatch) //< ... stop the match if the map was skipped and the match is played on only one map
) {
return True;
}
}
// If there is a rounds limit but no maps limit, continue to play until another limit is reached
else if (_RoundsPerMap >= 1) {
return False;
}
// If there is neither a points limit nor a rounds limit, always stop the match at the end of the first map, even if there is a tie
else {
return True;
}
// In all other cases continue to play
return False;
}