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
|
globalize_all_functions
const string PRIVATE_MATCH_PLAYLIST = "private_match"
global struct CustomMatchSettingContainer
{
string playlistVar
string defaultValue
string localizedName
bool isEnumSetting
// enum setting
array< string > enumNames
array< string > enumValues
}
struct {
array<string> modes = [ // default modes in vanilla
"tdm",
"aitdm",
"cp",
"at",
"ctf",
"lts",
"ps",
"speedball",
"mfd",
"ttdm",
"fd_easy",
"fd_normal",
"fd_hard",
"fd_master",
"fd_insane"
]
array<string> maps = [ // default maps in vanilla
"mp_forwardbase_kodai",
"mp_grave",
"mp_homestead",
"mp_thaw",
"mp_black_water_canal",
"mp_eden",
"mp_drydock",
"mp_crashsite3",
"mp_complex3",
"mp_angel_city",
"mp_colony02",
"mp_glitch",
"mp_relic02",
"mp_wargames",
"mp_rise",
"mp_lf_stacks",
"mp_lf_deck",
"mp_lf_meadow",
"mp_lf_traffic",
"mp_lf_township",
"mp_lf_uma"
]
table< string, array< CustomMatchSettingContainer > > customMatchSettingsByCategory // we set these up in sh_private_lobby_modes_init
} file
void function AddPrivateMatchMode( string mode )
{
if ( !file.modes.contains( mode ) )
file.modes.append( mode )
#if CLIENT
// call this on ui too so the client and ui states are the same
RunUIScript( "AddPrivateMatchMode", mode )
#endif
}
void function AddPrivateMatchMap( string map )
{
if ( !file.maps.contains( map ) )
file.maps.append( map )
#if CLIENT
// call this on ui too so the client and ui states are the same
RunUIScript( "AddPrivateMatchMap", map )
#endif
}
void function AddPrivateMatchModeSettingArbitrary( string category, string playlistVar, string defaultValue, string localizedName = "" )
{
if ( localizedName == "" )
localizedName = "#" + playlistVar
if ( !( category in file.customMatchSettingsByCategory ) )
file.customMatchSettingsByCategory[ category ] <- []
bool found = false
foreach ( CustomMatchSettingContainer setting in file.customMatchSettingsByCategory[ category ] )
{
if ( setting.playlistVar == playlistVar )
{
found = true
break
}
}
if ( !found )
{
CustomMatchSettingContainer setting
setting.playlistVar = playlistVar
setting.defaultValue = defaultValue
setting.localizedName = localizedName
setting.isEnumSetting = false
file.customMatchSettingsByCategory[ category ].append( setting )
}
#if CLIENT
// call this on ui too so the client and ui states are the same
RunUIScript( "AddPrivateMatchModeSettingArbitrary", category, playlistVar, defaultValue, localizedName )
#endif
}
void function AddPrivateMatchModeSettingEnum( string category, string playlistVar, array< string > enums, string defaultValue, string localizedName = "" )
{
table< string, string > pairs
for ( int i = 0; i < enums.len(); i++ )
pairs[ enums[ i ] ] <- i.tostring()
AddPrivateMatchModeSettingEnumEx( category, playlistVar, pairs, defaultValue, localizedName )
}
void function AddPrivateMatchModeSettingEnumUIHack( string category, string playlistVar, string serializedEnumPairs, string defaultValue, string localizedName )
{
// this fucking sucks, but RunUIScript won't take tables, so we serialize to a string
// we use \n as a delimeter and basically serialize to an array
array< string > serializedArray = split( serializedEnumPairs, "\n" )
table< string, string > enumPairs
for ( int i = 0; i < serializedArray.len(); i += 2 )
enumPairs[ serializedArray[ i ] ] <- serializedArray[ i + 1 ]
AddPrivateMatchModeSettingEnumEx( category, playlistVar, enumPairs, defaultValue, localizedName )
}
void function AddPrivateMatchModeSettingEnumEx( string category, string playlistVar, table< string, string > enumPairs, string defaultValue, string localizedName = "" )
{
if ( localizedName == "" )
localizedName = "#" + playlistVar
if ( !( category in file.customMatchSettingsByCategory ) )
file.customMatchSettingsByCategory[ category ] <- []
bool found = false
foreach ( CustomMatchSettingContainer setting in file.customMatchSettingsByCategory[ category ] )
{
if ( setting.playlistVar == playlistVar )
{
found = true
break
}
}
if ( !found )
{
CustomMatchSettingContainer setting
setting.playlistVar = playlistVar
setting.defaultValue = defaultValue
setting.localizedName = localizedName
setting.isEnumSetting = true
foreach ( string name, string value in enumPairs )
{
setting.enumNames.append( name )
setting.enumValues.append( value )
}
file.customMatchSettingsByCategory[ category ].append( setting )
}
#if CLIENT
// call this on ui too so the client and ui states are the same
// note: RunUIScript can't take tables, so manually serialize ( sucks, but just how it is ), using \n as a delimeter since i dont believe its ever used in vars
string serializedString
foreach ( string k, string v in enumPairs )
serializedString += k + "\n" + v + "\n"
RunUIScript( "AddPrivateMatchModeSettingEnumUIHack", category, playlistVar, serializedString, defaultValue, localizedName )
#endif
}
array< string > function GetPrivateMatchSettingCategories( bool uiAllowAllModeCategories = false )
{
array< string > categories
foreach ( string k, v in file.customMatchSettingsByCategory )
{
// can only do this in ui because it relies on GetUIVar
#if UI
bool gamemode = k.find( "#GAMEMODE_" ) == 0
if ( !uiAllowAllModeCategories && ( gamemode || k.find( "#PL_" ) == 0 ) )
{
if ( gamemode )
{
if ( k.slice( 10 ) != PrivateMatch_GetSelectedMode() )
{
continue
}
}
else if ( k.slice( 4 ) != PrivateMatch_GetSelectedMode() )
{
continue
}
}
#endif
categories.append( k )
}
return categories
}
array< CustomMatchSettingContainer > function GetPrivateMatchCustomSettingsForCategory( string category )
{
return file.customMatchSettingsByCategory[ category ]
}
array<string> function GetPrivateMatchModes()
{
//array<string> modesArray
//
//int numModes = GetPlaylistGamemodesCount( PRIVATE_MATCH_PLAYLIST )
//for ( int modeIndex = 0; modeIndex < numModes; modeIndex++ )
//{
// modesArray.append( GetPlaylistGamemodeByIndex( PRIVATE_MATCH_PLAYLIST, modeIndex ) )
//}
//return modesArray
return file.modes
}
int function GetPrivateMatchModeIndex( string modeName )
{
//int indexForName = 0
//
//int numModes = GetPlaylistGamemodesCount( PRIVATE_MATCH_PLAYLIST )
//for ( int modeIndex = 0; modeIndex < numModes; modeIndex++ )
//{
// if ( GetPlaylistGamemodeByIndex( PRIVATE_MATCH_PLAYLIST, modeIndex ) != modeName )
// continue
//
// indexForName = modeIndex;
// break
//}
//
//return indexForName
return file.modes.find( modeName )
}
array<string> function GetPrivateMatchMapsForMode( string modeName )
{
//array<string> mapsArray
//
//int modeIndex = GetPrivateMatchModeIndex( modeName )
//int numMaps = GetPlaylistGamemodeByIndexMapsCount( PRIVATE_MATCH_PLAYLIST, modeIndex )
//for ( int mapIndex = 0; mapIndex < numMaps; mapIndex++ )
//{
// mapsArray.append( GetPlaylistGamemodeByIndexMapByIndex( PRIVATE_MATCH_PLAYLIST, modeIndex, mapIndex ) )
//}
//
//return mapsArray
array<string> maps
// use the private match playlist for this if the gamemode is in it already
int privatePlaylistModeIndex = GetPrivateMatchModeIndex( modeName )
if ( privatePlaylistModeIndex < GetPlaylistGamemodesCount( PRIVATE_MATCH_PLAYLIST ) )
{
for ( int i = 0; i < GetPlaylistGamemodeByIndexMapsCount( PRIVATE_MATCH_PLAYLIST, privatePlaylistModeIndex ); i++ )
maps.append( GetPlaylistGamemodeByIndexMapByIndex( PRIVATE_MATCH_PLAYLIST, privatePlaylistModeIndex, i ) )
}
else
{
int numMaps = GetPlaylistGamemodeByIndexMapsCount( modeName, 0 )
for ( int i = 0; i < numMaps; i++ )
maps.append( GetPlaylistGamemodeByIndexMapByIndex( modeName, 0, i ) )
}
return maps
}
// never called
/*array<string> function GetPrivateMatchModesForMap( string mapName )
{
array<string> modesArray
int numModes = GetPlaylistGamemodesCount( PRIVATE_MATCH_PLAYLIST )
for ( int modeIndex = 0; modeIndex < numModes; modeIndex++ )
{
int numMaps = GetPlaylistGamemodeByIndexMapsCount( PRIVATE_MATCH_PLAYLIST, modeIndex )
for ( int mapIndex = 0; mapIndex < numMaps; mapIndex++ )
{
if ( GetPlaylistGamemodeByIndexMapByIndex( PRIVATE_MATCH_PLAYLIST, modeIndex, mapIndex ) != mapName )
continue
modesArray.append( GetPlaylistGamemodeByIndex( PRIVATE_MATCH_PLAYLIST, modeIndex ) )
}
}
return modesArray
}*/
string function GetPrivateMatchMapForIndex( int index )
{
array<string> mapsArray = GetPrivateMatchMaps()
if ( index >= mapsArray.len() || index < 0 )
return ""
return mapsArray[index]
}
string function GetPrivateMatchModeForIndex( int index )
{
array<string> modesArray = GetPrivateMatchModes()
if ( index >= modesArray.len() || index < 0 )
return ""
return modesArray[index]
}
int function GetPrivateMatchMapIndex( string mapName )
{
array<string> mapsArray = GetPrivateMatchMaps()
for ( int index = 0; index < mapsArray.len(); index++ )
{
if ( mapsArray[index] == mapName )
return index
}
return 0
}
/*
int function GetPrivateMatchModeIndex( string modeName )
{
array<string> modesArray = GetPrivateMatchModes()
for ( int index = 0; index < modesArray.len(); index++ )
{
if ( modesArray[index] == modeName )
return index
}
return 0
}
*/
array<string> function GetPrivateMatchMaps()
{
//array<string> mapsArray
//
//int numModes = GetPlaylistGamemodesCount( PRIVATE_MATCH_PLAYLIST )
//for ( int modeIndex = 0; modeIndex < numModes; modeIndex++ )
//{
// int numMaps = GetPlaylistGamemodeByIndexMapsCount( PRIVATE_MATCH_PLAYLIST, modeIndex )
// for ( int mapIndex = 0; mapIndex < numMaps; mapIndex++ )
// {
// string mapName = GetPlaylistGamemodeByIndexMapByIndex( PRIVATE_MATCH_PLAYLIST, modeIndex, mapIndex )
// if ( mapsArray.contains( mapName ) )
// continue
//
// mapsArray.append( mapName )
// }
//}
//
//return mapsArray
return file.maps
}
array<string> function GetPlaylistMaps( string playlistName )
{
array<string> mapsArray
int numModes = GetPlaylistGamemodesCount( playlistName )
for ( int modeIndex = 0; modeIndex < numModes; modeIndex++ )
{
int numMaps = GetPlaylistGamemodeByIndexMapsCount( playlistName, modeIndex )
for ( int mapIndex = 0; mapIndex < numMaps; mapIndex++ )
{
string mapName = GetPlaylistGamemodeByIndexMapByIndex( playlistName, modeIndex, mapIndex )
if ( mapsArray.contains( mapName ) )
continue
mapsArray.append( mapName )
}
}
return mapsArray
}
bool function MapSettings_SupportsTitans( string mapName )
{
if ( mapName.find( "mp_lf_") != null )
return false
if ( mapName.find( "coliseum" ) != null )
return false;
return true
}
bool function MapSettings_SupportsAI( string mapName )
{
if ( mapName.find( "mp_lf_") != null )
return false
if ( mapName.find( "coliseum" ) != null )
return false;
return true
}
bool function ModeSettings_RequiresTitans( string modeName )
{
switch ( modeName )
{
case "lts":
return true
}
return false
}
bool function ModeSettings_RequiresAI( string modeName )
{
switch ( modeName )
{
case "aitdm":
case "at":
return true
}
if ( modeName.find( "fd" ) == 0 ) // bob edit: unsure if this keeps vanilla compatibility, but just make sure fd modes are counted as requiring ai
return true
return false
}
#if !CLIENT
string function PrivateMatch_GetSelectedMap()
{
var mapIndex = level.ui.privatematch_map
string mapName = GetPrivateMatchMapForIndex( expect int(mapIndex) )
return mapName
}
string function PrivateMatch_GetSelectedMode()
{
var modeIndex = level.ui.privatematch_mode
string modeName = GetPrivateMatchModeForIndex( expect int(modeIndex) )
return modeName
}
#endif
bool function PrivateMatch_IsValidMapModeCombo( string mapName, string modeName )
{
array<string> mapsForMode = GetPrivateMatchMapsForMode( modeName )
return mapsForMode.contains( mapName )
}
// end private match stuff
int function Player_GetMaxMatchmakingDelay( entity player )
{
// return GetCurrentPlaylistVarInt( "matchmaking_delay", 0 )
return 300
}
int function Player_GetRemainingMatchmakingDelay( entity player )
{
int lastLeaveTime = player.GetPersistentVarAsInt( PERSISTENCE_LAST_LEAVE_TIME )
return Player_GetMaxMatchmakingDelay( player ) - (GetCurrentTimeForPersistence() - lastLeaveTime)
}
int function Player_NextAvailableMatchmakingTime( entity player )
{
#if MP
int lastLeaveTime = player.GetPersistentVarAsInt( PERSISTENCE_LAST_LEAVE_TIME )
if ( GetCurrentTimeForPersistence() - lastLeaveTime < Player_GetMaxMatchmakingDelay( player ) )
{
return Player_GetRemainingMatchmakingDelay( player )
}
#endif
return 0
}
int function GetCurrentTimeForPersistence()
{
// Returns the unix timestap offset to the timezone we want to use
return GetUnixTimestamp() + DAILY_RESET_TIME_ZONE_OFFSET * SECONDS_PER_HOUR
}
|