-
Notifications
You must be signed in to change notification settings - Fork 0
/
TM_RoyalTimeAttack_Online.Script.txt
271 lines (235 loc) · 7.86 KB
/
TM_RoyalTimeAttack_Online.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
/**
* Royal Time Attack mode
*/
#Extends "Libs/Nadeo/TMNext/TrackMania/Modes/TMNextBase.Script.txt"
#Const CompatibleMapTypes "TrackMania\\TM_Royal,TM_Royal"
#Const Version "2021-06-02"
#Const ScriptName "Modes/TrackMania/TM_RoyalTimeAttack_Online.Script.txt"
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Libraries
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
#Include "TextLib" as TL
#Include "Libs/Nadeo/TMNext/TrackMania/Modes/RoyalTimeAttack/RoyalTimeAttack.Script.txt" as RoyalTimeAttack
#Include "Libs/Nadeo/TMNext/TrackMania/Modes/RoyalTimeAttack/StateManager.Script.txt" as StateMgr
#Include "ManiaApps/Nadeo/TMxSM/Race/UIModules/Checkpoint_Server.Script.txt" as UIModules_Checkpoint
#Include "ManiaApps/Nadeo/TMxSM/Race/UIModules/PauseMenuOnline_Server.Script.txt" as UIModules_PauseMenu_Online
#Include "ManiaApps/Nadeo/TMxSM/Race/UIModules/ScoresTable_Server.Script.txt" as UIModules_ScoresTable
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Settings
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
#Setting S_TimeLimit 150 as _("Time limit") //< Time limit before going to the next map
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Constants
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
#Const C_ModeName "Royal Time Attack"
//L16N [Royal Time Attack] Description of the mode rules
#Const Description _("""Players must complete as many segments as possible as quickly as possible.""")
#Const C_HudModulePath "" //< Path to the hud module
#Const C_ManiaAppUrl "file://Media/ManiaApps/Nadeo/TMNext/TrackMania/RoyalTimeAttack/RoyalTimeAttack.Script.txt" //< Url of the mania app
#Const C_FakeUsersNb 0
#Const C_EmptyArmorCheckInterval 250 //< Frequency of the empty armor check
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Extends
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
***Match_LogVersions***
***
Log::RegisterScript(ScriptName, Version);
Log::RegisterScript(StateMgr::ScriptName, StateMgr::Version);
Log::RegisterScript(UIModules_Checkpoint::ScriptName, UIModules_Checkpoint::Version);
Log::RegisterScript(UIModules_PauseMenu_Online::ScriptName, UIModules_PauseMenu_Online::Version);
Log::RegisterScript(UIModules_ScoresTable::ScriptName, UIModules_ScoresTable::Version);
Log::RegisterScript(RoyalTimeAttack::ScriptName, RoyalTimeAttack::Version);
***
***Match_LoadLibraries***
***
StateMgr::Load();
RoyalTimeAttack::Load();
***
***Match_UnloadLibraries***
***
RoyalTimeAttack::Unload();
StateMgr::Unload();
***
***Match_Settings***
***
MB_Settings_UseDefaultHud = (C_HudModulePath == "");
MB_Settings_UseDefaultTimer = 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_PauseMenu_Online::SetHelp(Description);
UIModules_ScoresTable::SetScoreMode(UIModules_ScoresTable::C_Mode_RaceProgression);
UIModules_Checkpoint::SetVisibleFor(UIModules_Checkpoint::C_Target_None);
***
***Match_Yield***
***
foreach (Event in PendingEvents) {
switch (Event.Type) {
// Initialize players when they join the server
case CSmModeEvent::EType::OnPlayerAdded: {
StateMgr::InitializePlayer(Event.Player);
RoyalTimeAttack::InitializePlayer(Event.Player);
}
}
}
StateMgr::Yield();
RoyalTimeAttack::Yield();
***
***Match_StartServer***
***
// Initialize mode
Clans::SetClansNb(0);
Race::SetRespawnBehaviour(Race::C_RespawnBehaviour_AlwaysGiveUp);
StateMgr::ForcePlayersStates([StateMgr::C_State_Waiting]);
WarmUp::SetAvailability(False);
CarRank::Reset();
// Initialize network
CrudeExtrapolation_AllowDelay = True; //< Allow a delay on the opponents position to get a better extrapolation
***
***Match_InitMap***
***
declare CMapLandmark[] Map_Starts;
declare Integer Map_NextEmptyArmorCheckTime;
// Find start blocks
{
declare CMapLandmark[] Starts = Map::GetStarts();
declare CMapLandmark[Integer] SortedStarts;
foreach (Start in Starts) {
SortedStarts[Start.Order] = Start;
}
SortedStarts = SortedStarts.sortkey();
foreach (Start in SortedStarts) {
Map_Starts.add(Start);
}
if (Map_Starts.count > 0) {
Map::SetDefaultStart(Map_Starts[0]);
}
}
CarRank::Reset();
***
***Match_StartMap***
***
// Add bot when necessary
Users_SetNbFakeUsers(C_FakeUsersNb, 0);
// Reset race progression
foreach (Score in Scores) {
RoyalTimeAttack::ResetSegmentTimes(Score);
}
if (Map_Starts.count > 0) {
// Initialize race
// `Player.StartTime` will always be rounded to the next tenth of a second (9627 -> 9700)
// For the first spawn of the map we do this to the `StartTime` too, so both values are synchronized
StartTime = ((Now + Race::C_SpawnDuration) / 100 * 100) + 100;
if (S_TimeLimit > 0) {
EndTime = StartTime + (S_TimeLimit * 1000);
} else {
EndTime = -1;
}
Map_NextEmptyArmorCheckTime = StartTime + C_EmptyArmorCheckInterval;
UpdateScoresTableHeader(S_TimeLimit);
// Spawn players for the race
foreach (Player in Players) {
if (Race::IsReadyToStart(Player)) {
RoyalTimeAttack::Start(Map_Starts, Player, StartTime, StartTime);
}
}
StateMgr::ForcePlayersStates([StateMgr::C_State_Playing]);
RoyalTimeAttack::UpdateRanking();
} else {
StartTime = -1;
EndTime = -1;
StateMgr::ForcePlayersStates([StateMgr::C_State_Waiting]);
RoyalTimeAttack::UpdateRanking();
//L16N [Royal Time Attack] The current map is not valid, it will be skipped.
UIManager.UIAll.QueueMessage(3000, 1, CUIConfig::EMessageDisplay::Big, _("This map is not valid"));
MB_Sleep(3000);
MB_StopMap();
}
***
***Match_PlayLoop***
***
// Manage race events
declare RacePendingEvents = Race::GetPendingEvents();
foreach (Event in RacePendingEvents) {
Race::ValidEvent(Event);
// Waypoint
if (Event.Type == Events::C_Type_Waypoint) {
if (Event.Player != Null) {
if (Event.IsEndRace) {
RoyalTimeAttack::CompleteSegment(Event.Player, Event.RaceTime, StartTime);
RoyalTimeAttack::ThrottleUpdateRanking();
Race::StopSkipScoresTable(Event.Player);
}
}
}
}
// Manage mode events
foreach (Event in PendingEvents) {
if (Event.HasBeenPassed || Event.HasBeenDiscarded) continue;
Events::Invalid(Event);
}
// Spawn players
if (PlayersNbDead > 0) { //< Check for unspawned players only if at least one player is unspawned
foreach (Player in Players) {
if (Player.SpawnStatus == CSmPlayer::ESpawnStatus::NotSpawned && Race::IsReadyToStart(Player)) {
RoyalTimeAttack::Start(Map_Starts, Player, StartTime);
}
}
}
// Check if a player was eliminated by an obstacle
if (Now >= Map_NextEmptyArmorCheckTime) {
Map_NextEmptyArmorCheckTime = Now + C_EmptyArmorCheckInterval;
foreach (Player in Players) {
if (
Player.SpawnStatus == CSmPlayer::ESpawnStatus::Spawned &&
Player.Armor <= 0 &&
Race::IsRacing(Player)
) {
Race::StopSkipScoresTable(Player);
}
}
}
// Stop map if time limit is reached
if (EndTime > 0 && Now >= EndTime) MB_StopMap();
***
***Match_EndMap***
***
if (Map_Starts.count > 0) {
// Ensure that we stop the match (after a vote for the next map, ...)
MB_StopMatch();
Race::StopSkipOutroAll();
EndTime = -1;
StateMgr::ForcePlayersStates([StateMgr::C_State_Waiting]);
RoyalTimeAttack::UpdateRanking();
Race::SortScores(Race::C_Sort_TotalPoints);
Scores::SetPlayerWinner(Scores::GetBestPlayer(Scores::C_Sort_MatchPoints));
} else {
MB_SkipPodiumSequence();
}
***
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Functions
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/// Update the info in the scores table header
Void UpdateScoresTableHeader(Integer _TimeLimit) {
if (_TimeLimit > 0) {
//L16N [Royal Time Attack] The duration of one map. %1 will be replaced by a duration in minutes and seconds. eg: "Time limit 2:30".
UIModules_ScoresTable::SetFooterInfo(TL::Compose(_("Time limit %1"), TL::TimeToText(_TimeLimit * 1000)));
} else {
UIModules_ScoresTable::SetFooterInfo("");
}
}