Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

Betrayal.BetrayalGame


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752
01753
01754
01755
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772
01773
01774
/******************************************************************************
BetrayalGame

Creation date: 2010-01-31 15:25
Last change: $Id$
Copyright (c) 2010, Wormbo
******************************************************************************/

class BetrayalGame extends xDeathMatch;


//=============================================================================
// Imports
//=============================================================================

#exec obj load file=AssaultSounds.uax
#exec obj load file=GameSounds.uax
#exec obj load file=InterfaceContent.utx


//=============================================================================
// Localization
//=============================================================================

var localized array<string> BetrayalHints;
var localized array<int> RelevantDMLoadingHints;

var localized string lblMaxUnlagTime, descMaxUnlagTime;
var localized string lblBeamMultiHit, descBeamMultiHit;
var localized string lblSpecialKillRewards, descSpecialKillRewards;
var localized string lblRestorePlayerStats, descRestorePlayerStats;
var localized string lblBrighterPlayerSkins, descBrighterPlayerSkins;
var localized string lblImprovedSlopeDodging, descImprovedSlopeDodging;

var localized string LoadingScreenByNameText;
var localized string LoadingScreenAtTimeText;


//=============================================================================
// Configuration
//=============================================================================

var config float MaxUnlagTime;
var config bool bBeamMultiHit;
var config bool bSpecialKillRewards;
var config bool bRestorePlayerStats;
var config bool bBrighterPlayerSkins;
var config bool bImprovedSlopeDodging;


//=============================================================================
// Properties
//=============================================================================

var() const editconst string Build;
var() const editconst string Copyright;

var class<LocalMessage> AnnouncerMessageClass;
var Sound BetrayedSound;

struct TDrawOp {
	/**
	Available image operations are:
	`bgmapimage
	`bggameimage
	`mapimage
	`gameimage
	`image:package.group.material,u,v,ul,vl
	`random:p1.g1.m1,u1,v1,ul1,vl1;p2.g2.m2,u2,v2,ul2,vl2;...
	The U, V, UL and VL properties are optional.
	You can specify any number of random images you want.

	Available text operations are:
	`mapname
	`maptitle
	`mapauthor
	`gamename
	`gamehint
	`localize:file.section.property
	Any other text is displayed unmodified.
	Localized text is looked up in file.int [section] property=...
	(The file extension depends on your UT2004 language.)
	*/
	var string Content;

	/** The drawing area of this operation. */
	var float Top, Left, Height, Width;

	/** The render style. 1 = normal, 5 = alphablend */
	var byte RenderStyle;

	/**
	Alignment options.
	0 = left/top, 1 = center, 2 = right/bottom
	*/
	var byte AlignH, AlignV;

	/**
	Image style.
	0 = normal, 1 = full image stretched, 2 = clipped, 3 = partially stretched
	*/
	var byte ImageStyle;

	var color DrawColor;
	var string FontName;
	var bool WrapText;
};

var array<TDrawOp> GameDrawOps, DemoDrawOps;


//=============================================================================
// Variables
//=============================================================================

var array<BetrayalTeam> Teams;
var bool bPlayedTenKills, bPlayedFiveKills, bPlayedOneKill;

var BetrayalUnlaggedCollision FirstCollision;
var float LastLocationUpdateTime;
var bool bUnlaggingDisabled;

struct TSavedPRIData {
	// identification
	var string ClientID;
	var int PlayerID;

	// betrayal properties
	var float Score, Deaths;
	var int Hits, Shots, Kills;
	var int PaybackCount, RetributionCount;
	var int BetrayalCount, BetrayedCount;
	var int RemainingRogueTime;
	var array<BetrayalPRI> BetrayedPlayers;
	var int EagleEyes, MultiHits, BestMultiHit, HeadCount;

	// useful general properties
	var bool bFirstBlood;
	var array<TeamPlayerReplicationInfo.WeaponStats> WeaponStatsArray;
	var array<TeamPlayerReplicationInfo.VehicleStats> VehicleStatsArray;
	var byte Spree[6];
	var byte MultiKills[7];
	var int Suicides;
	var int TimePlayed;
};

var array<TSavedPRIData> SavedPRIData;
var array<string> DuplicateClientIDs;

var float VisibilityCheckRange;
var bool bTestBlocked;


event InitGame(string Options, out string Error)
{
	Super.InitGame(Options, Error);
	bForceRespawn = True;
	bAllowTrans   = False;
	MaxLives      = 0;
	if (MaxUnlagTime ~= 0 || Level.NetMode == NM_Standalone)
		bUnlaggingDisabled = True;
}

function InitGameReplicationInfo()
{
	Super.InitGameReplicationInfo();
	if (!bUnlaggingDisabled)
		BetrayalGRI(GameReplicationInfo).MaxUnlagTime = MaxUnlagTime;
	BetrayalGRI(GameReplicationInfo).bPlayersMustBeReady = bPlayersMustBeReady || bTournament;
	BetrayalGRI(GameReplicationInfo).bImprovedSlopeDodging = bImprovedSlopeDodging;
}

function GetServerDetails(out ServerResponseLine ServerState)
{
	Super.GetServerDetails(ServerState);
	AddServerDetail(ServerState, "MultiHit", bBeamMultiHit);
	AddServerDetail(ServerState, "SpecialKillRewards", bSpecialKillRewards);
	AddServerDetail(ServerState, "MaxUnlagTime", BetrayalGRI(GameReplicationInfo).MaxUnlagTime);
}

function bool OnSameTeam(Pawn A, Pawn B)
{
	local BetrayalPRI PRI1, PRI2;

	if (A == None || B == None)
		return false;

	PRI1 = BetrayalPRI(A.PlayerReplicationInfo);
	PRI2 = BetrayalPRI(B.PlayerReplicationInfo);

	return PRI1 != None && PRI2 != None && PRI1.CurrentTeam != None && PRI1.CurrentTeam == PRI2.CurrentTeam;
}

function Logout(Controller Exiting)
{
	local BetrayalPRI PRI;

	PRI = BetrayalPRI(Exiting.PlayerReplicationInfo);
	if (PRI != None) {
		SavePRIData(PRI, False);
		RemoveFromTeam(PRI);
	}

	Super.Logout(Exiting);
}

function Reset()
{
	Super.Reset();
	SavedPRIData.Length = 0;
	bPlayedTenKills  = False;
	bPlayedFiveKills = False;
	bPlayedOneKill   = False;
}

event PostLogin(PlayerController NewPlayer)
{
	local BetrayalPRI PRI;

	Super.PostLogin(NewPlayer);

	PRI = BetrayalPRI(NewPlayer.PlayerReplicationInfo);
	if (PRI != None) {
		PRI.ClientID = Super(GameStats).GetStatsIdentifier(NewPlayer);
		if (RestorePRIData(PRI))
			NewPlayer.ReceiveLocalizedMessage(class'BetrayalMessage', -2);
	}
}


function bool HasDuplicateClientID(BetrayalPRI PRI)
{
	local int i, Low, Middle, High;
	local string ClientID;

	if (PRI == None || PRI.ClientID == "")
		return PRI != None;

	ClientID = PRI.ClientID;

	if (DuplicateClientIDs.Length > 0) {
		// check known duplicates first
		High = DuplicateClientIDs.Length;
		do {
			Middle = (High + Low) / 2;
			if (DuplicateClientIDs[i] < ClientID)
				Low = Middle + 1;
			else
				High = Middle;
		} until (Low >= High);
		if (Low < DuplicateClientIDs.Length && DuplicateClientIDs[i] == ClientID)
			return true;
	}

	// check other players
	for (i = 0; i < GameReplicationInfo.PRIArray.Length; i++) {
		if (GameReplicationInfo.PRIArray[i] != PRI && BetrayalPRI(GameReplicationInfo.PRIArray[i]) != None && BetrayalPRI(GameReplicationInfo.PRIArray[i]).ClientID == ClientID) {
			// found duplicate, remember this one
			DuplicateClientIDs.Insert(Low, 1);
			DuplicateClientIDs[Low] = ClientID;
			return true;
		}
	}
	return false;
}


function bool RestorePRIData(BetrayalPRI PRI)
{
	local int i, j;

	if (!bRestorePlayerStats || PRI == None || PRI.bOnlySpectator || HasDuplicateClientID(PRI)) {
		//log("Can't restore data for " $ PRI.PlayerName);
		return false;
	}

	for (i = 0; i < SavedPRIData.Length; i++) {
		if (SavedPRIData[i].ClientID == PRI.ClientID) {
			//log("Restoring data for " $ PRI.PlayerName@PRI.ClientID);
			PRI.PlayerID          = SavedPRIData[i].PlayerID;
			PRI.Score             = SavedPRIData[i].Score;
			PRI.StartTime         = ElapsedTime - SavedPRIData[i].TimePlayed;
			PRI.Deaths            = SavedPRIData[i].Deaths;
			PRI.Hits              = SavedPRIData[i].Hits;
			PRI.Shots             = SavedPRIData[i].Shots;
			PRI.PaybackCount      = SavedPRIData[i].PaybackCount;
			PRI.RetributionCount  = SavedPRIData[i].RetributionCount;
			PRI.BetrayalCount     = SavedPRIData[i].BetrayalCount;
			PRI.BetrayedCount     = SavedPRIData[i].BetrayedCount;
			PRI.EagleEyes         = SavedPRIData[i].EagleEyes;
			PRI.MultiHits         = SavedPRIData[i].MultiHits;
			PRI.BestMultiHit      = SavedPRIData[i].BestMultiHit;
			PRI.HeadCount         = SavedPRIData[i].HeadCount;
			if (SavedPRIData[0].RemainingRogueTime > 0) {
				PRI.SetRogueTimer(False);
				RemoveFromTeam(PRI);
				PRI.RemainingRogueTime = SavedPRIData[i].RemainingRogueTime;
				for (j = 0; j < SavedPRIData[i].BetrayedPlayers.Length; j++) {
					if (SavedPRIData[i].BetrayedPlayers[j] != None && SavedPRIData[i].BetrayedPlayers[j].Betrayer == None)
						SavedPRIData[i].BetrayedPlayers[j].Betrayer = PRI;
				}
			}
			PRI.Kills             = SavedPRIData[i].Kills;
			PRI.RepKills          = SavedPRIData[i].Kills;
			PRI.bFirstBlood       = SavedPRIData[i].bFirstBlood;
			PRI.WeaponStatsArray  = SavedPRIData[i].WeaponStatsArray;
			PRI.VehicleStatsArray = SavedPRIData[i].VehicleStatsArray;
			PRI.Suicides          = SavedPRIData[i].Suicides;
			for (j = 0; j < ArrayCount(PRI.Spree); j++)
				PRI.Spree[j]      = SavedPRIData[i].Spree[j];
			for (j = 0; j < ArrayCount(PRI.MultiKills); j++)
				PRI.MultiKills[j] = SavedPRIData[i].MultiKills[j];
			SavedPRIData.Remove(i, 1);
			return true;
		}
	}
	//log("No data to restore for " $ PRI.PlayerName@PRI.ClientID);
}

function SavePRIData(BetrayalPRI PRI, bool bBecomingSpectator)
{
	local int j;
	local BetrayalPRI OtherPRI;

	if (!bRestorePlayerStats || PRI == None || !bBecomingSpectator && PRI.bOnlySpectator || HasDuplicateClientID(PRI)) {
		//log("Can't save data for " $ PRI.PlayerName);
		return;
	}

	//log("Saving data for " $ PRI.PlayerName@PRI.ClientID);
	SavedPRIData.Insert(0, 1);
	SavedPRIData[0].ClientID          = PRI.ClientID;
	SavedPRIData[0].PlayerID          = PRI.PlayerID;
	SavedPRIData[0].TimePlayed        = ElapsedTime - PRI.StartTime;
	SavedPRIData[0].Score             = PRI.Score;
	SavedPRIData[0].Deaths            = PRI.Deaths;
	SavedPRIData[0].Hits              = PRI.Hits;
	SavedPRIData[0].Shots             = PRI.Shots;
	SavedPRIData[0].PaybackCount      = PRI.PaybackCount;
	SavedPRIData[0].RetributionCount  = PRI.RetributionCount;
	SavedPRIData[0].BetrayalCount     = PRI.BetrayalCount;
	SavedPRIData[0].BetrayedCount     = PRI.BetrayedCount;
	SavedPRIData[0].EagleEyes         = PRI.EagleEyes;
	SavedPRIData[0].MultiHits         = PRI.MultiHits;
	SavedPRIData[0].BestMultiHit      = PRI.BestMultiHit;
	SavedPRIData[0].HeadCount         = PRI.HeadCount;
	if (PRI.bIsRogue && PRI.RemainingRogueTime > 0) {
		SavedPRIData[0].RemainingRogueTime = PRI.RemainingRogueTime;
		for (j = 0; j < GameReplicationInfo.PRIArray.Length; j++) {
			OtherPRI = BetrayalPRI(GameReplicationInfo.PRIArray[j]);
			if (OtherPRI != None && OtherPRI.Betrayer == PRI)
				SavedPRIData[0].BetrayedPlayers[SavedPRIData[0].BetrayedPlayers.Length] = OtherPRI;
		}
	}
	SavedPRIData[0].Kills             = PRI.Kills;
	SavedPRIData[0].bFirstBlood       = PRI.bFirstBlood;
	SavedPRIData[0].WeaponStatsArray  = PRI.WeaponStatsArray;
	SavedPRIData[0].VehicleStatsArray = PRI.VehicleStatsArray;
	SavedPRIData[0].Suicides          = PRI.Suicides;
	for (j = 0; j < ArrayCount(PRI.Spree); j++)
		SavedPRIData[0].Spree[j]      = PRI.Spree[j];
	for (j = 0; j < ArrayCount(PRI.MultiKills); j++)
		SavedPRIData[0].MultiKills[j] = PRI.MultiKills[j];
}

function bool BecomeSpectator(PlayerController P)
{
	if (!P.PlayerReplicationInfo.bOnlySpectator && Super.BecomeSpectator(P)) {
		SavePRIData(BetrayalPRI(P.PlayerReplicationInfo), True);
		RemoveFromTeam(BetrayalPRI(P.PlayerReplicationInfo));
		return true;
	}
	return false;
}

function bool AllowBecomeActivePlayer(PlayerController P)
{
	if (P.PlayerReplicationInfo.bOnlySpectator && Super.AllowBecomeActivePlayer(P)) {
		if (BetrayalPRI(P.PlayerReplicationInfo) != None)
			BetrayalPRI(P.PlayerReplicationInfo).bReactivating = True;
		return true;
	}
	return false;
}


function RemoveFromTeam(BetrayalPRI PRI)
{
	local BetrayalTeam Team;
	local int i, NumTeammates;

	if (PRI == None || PRI.CurrentTeam == None)
		return;

	//Drop the PRI from the team
	Team = PRI.CurrentTeam;
	NumTeammates = Team.LoseTeammate(PRI);

	if (NumTeammates == 1 ) {
		for (i = 0; i < ArrayCount(Team.Teammates); i++) {
			if (Team.Teammates[i] != None) {
				Team.Teammates[i].Score += Team.TeamPot;
				//Increment pot stat
				//Team.Teammates[i].AddToEventStat('EVENT_POOLPOINTS', Team.TeamPot);

				//Disband the team
				NumTeammates = Team.LoseTeammate(Team.Teammates[i]);
				break;
			}
		}
	}

	//Destroy the team completely
	if (NumTeammates == 0) {
		RemoveTeam(Team);
		Team.Destroy();
	}
}


function RemoveTeam(BetrayalTeam Team)
{
	local int i;

	for (i = 0; i < Teams.length; i++) {
		//Remove the team we're looking for
		if (Teams[i] == Team) {
			Teams.Remove(i, 1);
			break;
		}
	}
}

function bool InOrder(PlayerReplicationInfo P1, PlayerReplicationInfo P2)
{
	if (P1.bOnlySpectator)
		return P2.bOnlySpectator;
	else if (P2.bOnlySpectator)
		return true;

	if (P1.Score < P2.Score)
		return false;
	if (P1.Score == P2.Score) {
		if (P1.Deaths > P2.Deaths)
			return false;
		if (P1.Deaths == P2.Deaths && P1.Kills < P2.Kills)
			return false;
	}
	return true;
}


function SortPRIArray()
{
	local int i;
	local int Low, Middle, High;

	for (i = 1; i < GameReplicationInfo.PRIArray.Length; i++) {
		High = i;
		do {
			Middle = (High + Low) / 2;
			if (InOrder(GameReplicationInfo.PRIArray[Low], GameReplicationInfo.PRIArray[i]))
				Low = Middle + 1;
			else
				High = Middle;
		} until (Low >= High);
		if (Low < i) {
			GameReplicationInfo.PRIArray.Insert(Low, 1);
			GameReplicationInfo.PRIArray[Low] = GameReplicationInfo.PRIArray[i+1];
			GameReplicationInfo.PRIArray.Remove(i+1, 1);
		}
	}
}

function ScoreSpecialKill(Controller Killer)
{
	local PlayerReplicationInfo PRI;

	if (bGameEnded || !bSpecialKillRewards || Killer == None || Killer.PlayerReplicationInfo == None)
		return;

	PRI = Killer.PlayerReplicationInfo;
	PRI.Score += 1;
	PRI.NetUpdateTime = Level.TimeSeconds - 1;
	ScoreEvent(PRI, 1, "special_kill");
	CheckScore(PRI);
}


function Killed(Controller Killer, Controller Killed, Pawn KilledPawn, class<DamageType> damageType)
{
	local bool bEnemyKill;
	local int Score;
	local string KillInfo;

	bEnemyKill = Killer != Killed;

	if (KilledPawn != None && KilledPawn.GetSpree() > 4) {
		if (bEnemyKill && Killer != None)
			Killer.AwardAdrenaline(ADR_MajorKill);
		EndSpree(Killer, Killed);
	}
	if (Killer != None && Killer.bIsPlayer && Killed != None && Killed.bIsPlayer) {
		if (BetrayalPRI(Killer.PlayerReplicationInfo) != None)
			BetrayalPRI(Killer.PlayerReplicationInfo).LogMultiKills(ADR_MajorKill, bEnemyKill);
		else if (UnrealPlayer(Killer) != None)
			UnrealPlayer(Killer).LogMultiKills(ADR_MajorKill, bEnemyKill);

		if (bEnemyKill)
			DamageType.static.ScoreKill(Killer, Killed);

		if (!bFirstBlood && Killer != Killed && bEnemyKill) {
			Killer.AwardAdrenaline(ADR_MajorKill);
			bFirstBlood = True;
			if (TeamPlayerReplicationInfo(Killer.PlayerReplicationInfo) != None)
				TeamPlayerReplicationInfo(Killer.PlayerReplicationInfo).bFirstBlood = true;
			BroadcastLocalizedMessage(class'FirstBloodMessage', 0, Killer.PlayerReplicationInfo);
			SpecialEvent(Killer.PlayerReplicationInfo, "first_blood");
		}
		if (Killer == Killed)
			Killer.AwardAdrenaline(ADR_MinorError);
		else if (bTeamGame && Killed.PlayerReplicationInfo.Team == Killer.PlayerReplicationInfo.Team)
			Killer.AwardAdrenaline(ADR_KillTeamMate);
		else {
			Killer.AwardAdrenaline(ADR_Kill);
			if (Killer.Pawn != None) {
				Killer.Pawn.IncrementSpree();
				if (Killer.Pawn.GetSpree() > 4)
					NotifySpree(Killer, Killer.Pawn.GetSpree());
			}
		}
	}

	// Vehicle Score Kill
	if (Killer != None && Killer.bIsPlayer && Killer.PlayerReplicationInfo != None && Vehicle(KilledPawn) != None && (Killed != None || Vehicle(KilledPawn).bEjectDriver) && Vehicle(KilledPawn).IndependentVehicle()) {
		Score = VehicleScoreKill(Killer, Killed, Vehicle(KilledPawn), KillInfo);
		if (Score > 0) {
			/* if driver(s) have been ejected from vehicle, Killed == None */
			if (!bEnemyKill && Killed != None && Killed.PlayerReplicationInfo != None) {
				Score = -Score; // substract score if team kill.
				KillInfo = "TeamKill_" $ KillInfo;
			}

			if (Score != 0) {
				Killer.PlayerReplicationInfo.Score += Score;
				Killer.PlayerReplicationInfo.NetUpdateTime = Level.TimeSeconds - 1;
				ScoreEvent(Killer.PlayerReplicationInfo, Score, KillInfo);
			}
		}
	}

	Super(UnrealMPGameInfo).Killed(Killer, Killed, KilledPawn, damageType);
}



function ScoreKill(Controller Killer, Controller Other)
{
	local BetrayalPRI KillerPRI, OtherPRI;
	local Bot B;
	local int i, ScoreValue;
	local float BetrayalValue;

	if (PlayerController(Other) != None)
		PlayerController(Other).WaitDelay = Level.TimeSeconds + 0.75;

	if (Killer != None)
		KillerPRI = BetrayalPRI(Killer.PlayerReplicationInfo);

	OtherPRI = BetrayalPRI(Other.PlayerReplicationInfo);
	if (Killer == Other || Killer == None) {
		// self kill by suicide or environment
		if (Other != None && Other.PlayerReplicationInfo != None) {
			if (OtherPRI != None)
				OtherPRI.AddKillBy(OtherPRI.PlayerID);
			Other.PlayerReplicationInfo.Score -= 1;
			Other.PlayerReplicationInfo.NetUpdateTime = Level.TimeSeconds - 1;
			ScoreEvent(Other.PlayerReplicationInfo, -1, "self_frag");
		}
	}
	else if (KillerPRI != None) {
		if (OtherPRI != None) {
			OtherPRI.AddKillBy(KillerPRI.PlayerID);

			ScoreValue = OtherPRI.ScoreValueFor(KillerPRI);
			KillerPRI.Score += ScoreValue;
			ScoreEvent(Killer.PlayerReplicationInfo, ScoreValue, "frag");
			if (OtherPRI.bIsRogue && OtherPRI == KillerPRI.Betrayer) {
				// betrayer was busted, rogue value is handed over to the killer
				OtherPRI.Score -= OtherPRI.RogueValue;
				ScoreEvent(OtherPRI, -OtherPRI.RogueValue, "payback");

				if (PlayerController(KillerPRI.Owner) != None)
					PlayerController(KillerPRI.Owner).ReceiveLocalizedMessage(AnnouncerMessageClass, 2);
				if (PlayerController(OtherPRI.Owner) != None)
					PlayerController(OtherPRI.Owner).ReceiveLocalizedMessage(AnnouncerMessageClass, 3);

				//Retribution stat
				KillerPRI.RetributionCount++;
				OtherPRI.PaybackCount++;

				Killer.AwardAdrenaline(ADR_MinorBonus);
				Other.AwardAdrenaline(ADR_MinorError);
				OtherPRI.RogueExpired();
			}
			KillerPRI.NetUpdateTime = Level.TimeSeconds - 1;
			KillerPRI.Kills++;
			KillerPRI.RepKills++;
			if (KillerPRI.CurrentTeam != None) {
				KillerPRI.CurrentTeam.TeamPot++;

				if (KillerPRI.CurrentTeam.TeamPot > 2) {
					for (i = 0; i < ArrayCount(KillerPRI.CurrentTeam.Teammates); i++) {
						if (KillerPRI.CurrentTeam.Teammates[i] != None) {
							B = Bot(KillerPRI.CurrentTeam.Teammates[i].Owner);
							if (B != None && BetrayalSquadAI(B.Squad) != None && !BetrayalSquadAI(B.Squad).bBetrayTeam) {
								BetrayalValue = KillerPRI.CurrentTeam.TeamPot + 0.3 * BetrayalPRI(B.PlayerReplicationInfo).ScoreValueFor(KillerPRI);
								if (BetrayalValue > 1.5 + KillerPRI.RogueValue - B.Aggressiveness + BetrayalPRI(B.PlayerReplicationInfo).GetTrustworthiness() && FRand() < 0.25 || GoalScore > 0 && KillerPRI.Score + BetrayalValue >= GoalScore) {
									// log(Instigator.Controller.ShotTarget.Controller.PlayerReplicationInfo.PlayerName$" betrayal value "$BetrayalValue$" vs "$(1.5 + RogueValue - B.Aggressiveness + UTBetrayalPRI(B.PlayerReplicationInfo).GetTrustWorthiness()));
									BetrayalSquadAI(B.Squad).bBetrayTeam = true;
								}
							}
						}
					}
				}
			}
			if (bAllowTaunts && Killer != None && Killer != Other && Killer.AutoTaunt() && Killer.PlayerReplicationInfo != None && Killer.PlayerReplicationInfo.VoiceType != None) {
				Killer.SendMessage(OtherPRI, 'AUTOTAUNT', Killer.PlayerReplicationInfo.VoiceType.static.PickRandomTauntFor(Killer, false, PlayerController(Killer) == None), 10, 'GLOBAL');
			}
		}
	}

	if (GameRulesModifiers != None)
		GameRulesModifiers.ScoreKill(Killer, Other);

	if (Killer != None || bOvertime) {
		CheckScore(Killer.PlayerReplicationInfo);
	}

	if (bAdjustSkill && (PlayerController(Killer) != None || PlayerController(Other) != None)) {
		if (AIController(Killer) != None)
			AdjustSkill(AIController(Killer), PlayerController(Other),true);
		if (AIController(Other) != None)
			AdjustSkill(AIController(Other), PlayerController(Killer),false);
	}
}

function ShotTeammate(BetrayalPRI InstigatorPRI, BetrayalPRI HitPRI, Pawn ShotInstigator, Pawn HitPawn)
{
	local BetrayalTeam Team;
	local BetrayalPRI PRI;
	local int i;
	local Bot B;

	if (Level.TimeSeconds - HitPawn.SpawnTime < SpawnProtectionTime)
		return;

	HitPRI.AddBetrayalBy(InstigatorPRI.PlayerID);
	Team = InstigatorPRI.CurrentTeam;
	InstigatorPRI.Score += Team.TeamPot;
	ScoreEvent(InstigatorPRI, Team.TeamPot, "team_frag");
	InstigatorPRI.TotalPotStolen += Team.TeamPot;
	InstigatorPRI.SetRogueTimer(InstigatorPRI.RogueValue / 2 >= Team.TeamPot);
	Team.TeamPot = 0;

	InstigatorPRI.BetrayalCount++;
	InstigatorPRI.BetrayedTeam = Team;
	InstigatorPRI.Betrayed = HitPRI;
	HitPRI.Betrayer = InstigatorPRI;
	HitPRI.BetrayedCount++;
	//InstigatorPRI.PlaySound(BetrayingSound);
	ShotInstigator.Controller.AwardAdrenaline(ADR_MajorKill);

	for (i = 0; i < GameReplicationInfo.PRIArray.Length; i++) {
		PRI = BetrayalPRI(GameReplicationInfo.PRIArray[i]);
		if (PRI != None && PlayerController(PRI.Owner) != None) {
			if (PRI.CurrentTeam == Team) {
				// big, with "assassin"
				PlayerController(PRI.Owner).ReceiveLocalizedMessage(AnnouncerMessageClass, 0, InstigatorPRI, HitPRI, Team);
			}
			else {
				// smaller, no announcement
				PlayerController(PRI.Owner).ReceiveLocalizedMessage(AnnouncerMessageClass, 4, InstigatorPRI, HitPRI, Team);
			}
		}
	}

	RemoveFromTeam(InstigatorPRI);

	if (Team != None) {
		// give betrayer to other teammate
		for (i = 0; i < ArrayCount(Team.Teammates); i++) {
			if (Team.Teammates[i] != None) {
				if (Team.Teammates[i] != HitPRI)
					Team.Teammates[i].BetrayedCount++;
				Team.Teammates[i].Betrayer = InstigatorPRI;
				if (PlayerController(Team.Teammates[i].Owner) != None)
					PlayerController(Team.Teammates[i].Owner).ClientPlaySound(BetrayedSound);
				else {
					B = Bot(Team.Teammates[i].Owner);
					if (B != None) {
						if (BetrayalSquadAI(B.Squad) != None)
							BetrayalSquadAI(B.Squad).bBetrayTeam = False; // no point trying, the pot is gone
						if (B.Pawn != None)
							B.AssignSquadResponsibility(); // ensure the bot looks for a target other than remaining teammates
					}
				}
			}
		}
	}
}

function float SpawnWait(AIController B)
{
	local BetrayalPRI PRI;

	if (B.PlayerReplicationInfo.bOutOfLives)
		return 999;

	PRI = BetrayalPRI(B.PlayerReplicationInfo);
	if (PRI != None && PRI.bIsRogue)
		return FRand(); // respawn rogues immediately

	return FRand() * Sqrt(NumBots); // don't wait too long; player wants action? - player gets action!
}

function bool WantsPickups(Bot B)
{
	return false; // there are none anyway
}

function bool ShouldSpawnNearby(BetrayalPRI SpawningPRI, BetrayalPRI OtherPRI)
{
	return SpawningPRI != None && OtherPRI != None && (
		SpawningPRI.CurrentTeam != None && SpawningPRI.CurrentTeam == OtherPRI.CurrentTeam ||
		OtherPRI.bIsRogue && SpawningPRI.Betrayer == OtherPRI ||
		SpawningPRI.bIsRogue && OtherPRI.Betrayer == SpawningPRI);
}

function bool ValidateStartSpot(NavigationPoint StartSpot, out PlayerStart ClosestPlayerStart)
{
	local Inventory Inv;
	local NavPointRatingInfo NPRI;

	if (bScriptInitialized) {
		Inv = StartSpot.Inventory;
		if (Inv != None) {
			// yay, inventory chain abuse :)
			do {
				NPRI = NavPointRatingInfo(Inv);
				Inv = Inv.Inventory;
			} until (NPRI != None || Inv == None);
		}
		if (NPRI == None) {
			NPRI = StartSpot.Spawn(class'NavPointRatingInfo', StartSpot,, StartSpot.Location);
			if (NPRI != None) {
				NPRI.Inventory = StartSpot.Inventory;
				StartSpot.Inventory = NPRI;
			}
			else {
				NPRI = StartSpot.Spawn(class'NavPointRatingInfoBlocked', StartSpot,, StartSpot.Location);
				if (NPRI != None) {
					NPRI.Inventory = StartSpot.Inventory;
					StartSpot.Inventory = NPRI;
				}
			}
		}
		if (NPRI != None) {
			ClosestPlayerStart = NPRI.GetClosestPlayerStart();
			return ClosestPlayerStart != None && NPRI.Touching.Length == 0;
		}
	}
	ClosestPlayerStart = PlayerStart(StartSpot);

	return ClosestPlayerStart != None;
}

function float RatePlayerStart(NavigationPoint N, byte Team, Controller Player)
{
	local PlayerStart P;
	local float Score, NextDist;
	local Controller OtherPlayer;

	if (Player != None)
		Team = Player.GetTeamNum();

	Score = 3000 * FRand(); //randomize
	if (PlayerStart(N) == None)
		Score -= 10000;

	// find nearby PlayerStart (only for selected types of navigation points)
	if (!ValidateStartSpot(N, P) || !P.bEnabled || N.PhysicsVolume.bWaterVolume)
		return Score - 10000000;

	//assess candidate
	if (P.bPrimaryStart)
		Score += 10000000;
	else
		Score += 5000000;

	if (N == LastStartSpot || N == LastPlayerStartSpot)
		Score -= 10000.0;

	for (OtherPlayer = Level.ControllerList; OtherPlayer != None; OtherPlayer = OtherPlayer.NextController) {
		if (OtherPlayer.bIsPlayer && OtherPlayer.Pawn != None) {
			NextDist = VSize(OtherPlayer.Pawn.Location - N.Location);
			//if (NextDist < OtherPlayer.Pawn.CollisionRadius + OtherPlayer.Pawn.CollisionHeight)
			//	return -10000.0;
			// limit the visibility checks if there are many players on the server
			if (NextDist < VisibilityCheckRange && FastTrace(N.Location, OtherPlayer.Pawn.Location)) {
				Score -= Square(300.0 - 0.1 * NextDist);
			}
			else if (Player != None && ShouldSpawnNearby(BetrayalPRI(Player.PlayerReplicationInfo), BetrayalPRI(OtherPlayer.PlayerReplicationInfo))) {
				Score -= 5 * NextDist;
			}
			else {
				Score += NextDist;
			}
		}
	}
	return FMax(Score, 5);
}

function NavigationPoint FindPlayerStart(Controller Player, optional byte InTeam, optional string incomingName)
{
	local NavigationPoint N, BestStart;
	local float BestRating, NewRating;
	local byte Team;

	if (Player != None && Player.StartSpot != None)
		LastPlayerStartSpot = Player.StartSpot;

	// always pick StartSpot at start of match
	if (Player != None && Player.StartSpot != None && Level.NetMode == NM_Standalone && (bWaitingToStartMatch || Player.PlayerReplicationInfo != None && Player.PlayerReplicationInfo.bWaitingPlayer))
		return Player.StartSpot;

	if (GameRulesModifiers != None) {
		N = GameRulesModifiers.FindPlayerStart(Player, InTeam, incomingName);
		if ( N != None )
			return N;
	}

	// original code would check for incoming teleporter here, but uhh - this isn't a single player story

	// use InTeam if player doesn't have a team yet
	if (Player != None && Player.PlayerReplicationInfo != None) {
		if (Player.PlayerReplicationInfo.Team != None)
			Team = Player.PlayerReplicationInfo.Team.TeamIndex;
		else
			Team = InTeam;
	}
	else
		Team = InTeam;

	// find start with positive rating
	VisibilityCheckRange = FMin(10000.0 / Sqrt(1 + NumPlayers + NumBots), 3000.0);
	for (N = Level.NavigationPointList; N != None; N = N.NextNavigationPoint) {
		NewRating = RatePlayerStart(N, Team, Player);
		if (NewRating > BestRating) {
			BestRating = NewRating;
			BestStart = N;
		}
	}

	if (BestStart == None /* || who cares? ((PlayerStart(BestStart) == None) && (Player != None) && Player.bIsPlayer)*/ ) {
		log("Warning - PATHS NOT DEFINED or NO PLAYERSTART with positive rating");
		BestRating = -100000000;
		foreach AllActors(class'NavigationPoint', N) {
			NewRating = RatePlayerStart(N, 0, Player);
			if (InventorySpot(N) != None)
				NewRating -= 50;
			NewRating += 20 * FRand();
			if (NewRating > BestRating) {
				BestRating = NewRating;
				BestStart = N;
			}
		}
	}

	if (BestStart != None)
		LastStartSpot = BestStart;

	return BestStart;
}

function rotator FindBestDirectionFor(vector StartLocation, rotator StartRotation, float CheckDist)
{
	local vector X, Y, Z, HL, HN;
	local vector BestDir;

	GetAxes(StartRotation, X, Y, Z);

	BestDir = 0.1 * vector(StartRotation);

	if (Trace(HL, HN, StartLocation + CheckDist * X, StartLocation) != None) {
		BestDir += (VSize(HL - StartLocation) / CheckDist) * HN * vect(1,1,0);
	}
	else {
		BestDir += X;
	}

	if (Trace(HL, HN, StartLocation - CheckDist * X, StartLocation) != None) {
		BestDir += (VSize(HL - StartLocation) / CheckDist) * HN * vect(1,1,0);
	}
	else {
		BestDir -= X;
	}

	if (Trace(HL, HN, StartLocation + CheckDist * Y, StartLocation) != None) {
		BestDir += (VSize(HL - StartLocation) / CheckDist) * HN * vect(1,1,0);
	}
	else {
		BestDir += Y;
	}

	if (Trace(HL, HN, StartLocation - CheckDist * Y, StartLocation) != None) {
		BestDir += (VSize(HL - StartLocation) / CheckDist) * HN * vect(1,1,0);
	}
	else {
		BestDir -= Y;
	}

	return rotator(BestDir);
}

function RestartPlayer(Controller aPlayer)
{
	local NavigationPoint StartSpot;
	local int TeamNum;
	local class<Pawn> DefaultPlayerClass;
	local rotator StartSpotRotation;

	if (bMustJoinBeforeStart && UnrealPlayer(aPlayer) != None && UnrealPlayer(aPlayer).bLatecomer)
		return;

	if (aPlayer.PlayerReplicationInfo.bOutOfLives)
		return;

	if (aPlayer.IsA('Bot') && TooManyBots(aPlayer)) {
		aPlayer.Destroy();
		return;
	}
	if (bRestartLevel && Level.NetMode != NM_DedicatedServer && Level.NetMode != NM_ListenServer)
		return;

	if (aPlayer.PlayerReplicationInfo == None || aPlayer.PlayerReplicationInfo.Team == None)
		TeamNum = 255;
	else
		TeamNum = aPlayer.PlayerReplicationInfo.Team.TeamIndex;

	StartSpot = FindPlayerStart(aPlayer, TeamNum);
	if (StartSpot == None) {
		log(" Player start not found!!!");
		return;
	}
	StartSpotRotation = StartSpot.Rotation;
	StartSpotRotation.Roll = 0;
	StartSpotRotation.Pitch = 0;

	if (aPlayer.PreviousPawnClass != None && aPlayer.PawnClass != aPlayer.PreviousPawnClass) {
		BaseMutator.PlayerChangedClass(aPlayer);
	}
	if (PlayerStart(StartSpot) == None) {
		// mappers don't usually pay attention to NavPoint rotations, so figure out better spawn rotation for them
		StartSpotRotation = FindBestDirectionFor(StartSpot.Location, StartSpotRotation, 250);
	}
	if (aPlayer.PawnClass != None)
		aPlayer.Pawn = Spawn(aPlayer.PawnClass,,, StartSpot.Location, StartSpotRotation);

	if (aPlayer.Pawn == None) {
		DefaultPlayerClass = GetDefaultPlayerClass(aPlayer);
		aPlayer.Pawn = Spawn(DefaultPlayerClass,,, StartSpot.Location, StartSpotRotation);
	}
	if (aPlayer.Pawn == None) {
		log("Couldn't spawn player of type "$aPlayer.PawnClass$" at "$StartSpot);
		aPlayer.GotoState('Dead');
		if (PlayerController(aPlayer) != None)
			PlayerController(aPlayer).ClientGotoState('Dead', 'Begin');
		return;
	}
	if (PlayerController(aPlayer) != None)
		PlayerController(aPlayer).TimeMargin = -0.1;
	aPlayer.Pawn.Anchor = startSpot;
	aPlayer.Pawn.LastStartSpot = PlayerStart(startSpot);
	aPlayer.Pawn.LastStartTime = Level.TimeSeconds;
	aPlayer.PreviousPawnClass = aPlayer.Pawn.Class;

	aPlayer.Possess(aPlayer.Pawn);
	aPlayer.PawnClass = aPlayer.Pawn.Class;

	aPlayer.Pawn.PlayTeleportEffect(true, true);
	aPlayer.ClientSetRotation(aPlayer.Pawn.Rotation);
	AddDefaultInventory(aPlayer.Pawn);
	TriggerEvent(StartSpot.Event, StartSpot, aPlayer.Pawn);
}


function bool PlayerCanRestart(PlayerController aPlayer)
{
	return Level.TimeSeconds >= aPlayer.WaitDelay;
}

function CheckScore(PlayerReplicationInfo Scorer)
{
	local Controller C;

	if (CheckMaxLives(Scorer))
		return;

	if (GameRulesModifiers != None && GameRulesModifiers.CheckScore(Scorer))
		return;

	if (Scorer != None) {
		if (GoalScore > 0 && Scorer.Score < GoalScore) {
			if (Scorer.Score == GoalScore - 1 && !bPlayedOneKill) {
				SortPRIArray();
				if (Scorer == GameReplicationInfo.PRIArray[0]) {
					bPlayedOneKill = true;
					bPlayedFiveKills = true;
					bPlayedTenKills = true;
					BroadcastLocalized(Self, AnnouncerMessageClass, 12);
				}
			}
			else if (Scorer.Score >= GoalScore - 5) {
				if (!bPlayedFiveKills && GoalScore > 9) {
					SortPRIArray();
					if (Scorer == GameReplicationInfo.PRIArray[0]) {
						bPlayedFiveKills = true;
						bPlayedTenKills = true;
						BroadcastLocalized(Self, AnnouncerMessageClass, 11);
					}
				}
			}
			else if (Scorer.Score >= GoalScore - 10) {
				if (!bPlayedTenKills && GoalScore > 19) {
					SortPRIArray();
					if (Scorer == GameReplicationInfo.PRIArray[0]) {
						bPlayedTenKills = true;
						BroadcastLocalized(Self, AnnouncerMessageClass, 10);
					}
				}
			}
		}
		if (GoalScore > 0 && Scorer.Score >= GoalScore) {
			EndGame(Scorer, "fraglimit");
		}
		else if (bOverTime) {
			// end game only if scorer has highest score
			for (C = Level.ControllerList; C != None; C = C.NextController) {
				if (C.PlayerReplicationInfo != None && C.PlayerReplicationInfo != Scorer && C.PlayerReplicationInfo.Score >= Scorer.Score)
					return;
			}
			EndGame(Scorer, "fraglimit");
		}
	}
}

function UpdateUnlagLocations()
{
	local BetrayalUnlaggedCollision UnlaggedCollision, NextCollision;

	LastLocationUpdateTime = Level.TimeSeconds;
	for (UnlaggedCollision = FirstCollision; UnlaggedCollision != None; UnlaggedCollision = NextCollision) {
		NextCollision = UnlaggedCollision.NextCollision; // collision could get destroyed, so remember next one
		UnlaggedCollision.UpdateUnlagLocation();
	}
}

function EnableUnlag(Pawn Attacker, vector FireStart, vector FireDir)
{
	local BetrayalUnlaggedCollision UnlaggedCollision;
	local float UnlagTime;
	local BetrayalPRI BPRI;

	if (Attacker != None)
		BPRI = BetrayalPRI(Attacker.PlayerReplicationInfo);

	if (Attacker == None || PlayerController(Attacker.Controller) == None || NetConnection(PlayerController(Attacker.Controller).Player) == None || BPRI != None && !BPRI.bUseUnlagging)
		return; // not controlled by a remote player

	if (LastLocationUpdateTime != Level.TimeSeconds) {
		UpdateUnlagLocations();
	}

	if (BPRI != None)
		UnlagTime = BPRI.GamePing;
	else
		UnlagTime = PlayerController(Attacker.Controller).ExactPing;

	for (UnlaggedCollision = FirstCollision; UnlaggedCollision != None; UnlaggedCollision = UnlaggedCollision.NextCollision) {
		UnlaggedCollision.EnableUnlag(UnlagTime, FireStart, FireDir);
	}
}

function DisableUnlag()
{
	local BetrayalUnlaggedCollision UnlaggedCollision;

	for (UnlaggedCollision = FirstCollision; UnlaggedCollision != None; UnlaggedCollision = UnlaggedCollision.NextCollision) {
		UnlaggedCollision.DisableUnlag();
	}
}


state MatchInprogress
{
	function Timer()
	{
		local int i, j, NumBetrayers, MaxTeamSize;
		local BetrayalPRI PRI, Teammate;
		local BetrayalTeam NewTeam;
		local array<BetrayalPRI> Freelancers;

		Super.Timer();

		if (bGameEnded)
			return;

		if (NumPlayers + NumBots > 6)
			MaxTeamSize = 3;
		else
			MaxTeamSize = 2;

		// find all freelancers
		for (i= 0; i < GameReplicationInfo.PRIArray.Length; i++) {
			PRI = BetrayalPRI(GameReplicationInfo.PRIArray[i]);
			if (PRI != None && PRI.CurrentTeam == None && !PRI.bIsRogue && !PRI.bIsSpectator && !PRI.bOnlySpectator) {
				// shuffle them to make things less boring, but put "innocent" players first
				if (PRI.Betrayed != None) {
					j = Rand(NumBetrayers + 1) + Freelancers.Length - NumBetrayers;
					NumBetrayers++;
				}
				else {
					j = Rand(Freelancers.Length + 1 - NumBetrayers);
				}
				Freelancers.Insert(j, 1);
				Freelancers[j] = PRI;
			}
		}

		// first try to place on existing team - but not the one you've betrayed before, or one that has too big a pot
		for (i = 0; i < Freelancers.Length; i++) {
			PRI = Freelancers[i];
			for (j = 0; j < Teams.Length; j++) {
				if (!Teams[j].MemberWasBetrayedBy(PRI) && Teams[j].AddTeammate(PRI, MaxTeamSize)) {
					//Successfully added to a team
					if (PlayerController(PRI.Owner) != None)
						PlayerController(PRI.Owner).ReceiveLocalizedMessage(AnnouncerMessageClass, 1);

					PRI.Betrayed = None;
					return;
				}
			}
		}

		// maybe form team from freelancers who didn't betray each other recently, but only if enough players are on the server
		if (NumPlayers + NumBots > 3) {
			for (i = 0; i < Freelancers.Length - 1; i++) {
				PRI = Freelancers[i];
				for (j = i + 1; j < Freelancers.Length; j++) {
					if (PRI.Betrayed != Freelancers[j] && Freelancers[j].Betrayed != PRI) {
						Teammate = Freelancers[j];
						break;
					}
				}
			}
			if (Teammate != None) {
				// can form a new team
				NewTeam = Spawn(class'BetrayalTeam');
				if (NewTeam != None) {
					Teams[Teams.Length] = NewTeam;
					if (!NewTeam.AddTeammate(PRI, MaxTeamSize) || !NewTeam.AddTeammate(Teammate, MaxTeamSize)) {
						NewTeam.Reset();
						return;
					}
					if (PlayerController(PRI.Owner) != None) {
						PlayerController(PRI.Owner).ReceiveLocalizedMessage(AnnouncerMessageClass, 1);
					}
					if (PlayerController(Teammate.Owner) != None) {
						PlayerController(Teammate.Owner).ReceiveLocalizedMessage(AnnouncerMessageClass, 1);
					}

					if (MaxTeamSize > 2) {
						// see if we can find a third teammate
						for (i = j + 1; i < Freelancers.Length; i++) {
							if (PRI.Betrayed != Freelancers[i] && Freelancers[i].Betrayed != PRI && Teammate.Betrayed != Freelancers[i] && Freelancers[i].Betrayed != Teammate && NewTeam.AddTeammate(Freelancers[i], MaxTeamSize)) {
								//Successfully added to a team
								if (PlayerController(Freelancers[i].Owner) != None) {
									PlayerController(Freelancers[i].Owner).ReceiveLocalizedMessage(AnnouncerMessageClass, 1);
								}
								Freelancers[i].Betrayed = None;
								break;
							}
						}
					}
					PRI.Betrayed = None;
					Teammate.Betrayed = None;
				}
			}
		}
	}

	function Tick(float DeltaTime)
	{
		if (LastLocationUpdateTime != Level.TimeSeconds) {
			UpdateUnlagLocations();
		}
	}
}

static function string GetLoadingHint(PlayerController Ref, string MapName, color HintColor)
{
	local string DemoName, RecordedBy, Timestamp, MapTitle, MapAuthor, MapDescription, GameTypeName, Content, Parsed;
	local Material MapScreenshot, MapBackground, GameScreenshot, GameBackground;
	local TexScaler BGInterlaceScaler;
	local Combiner BGCombiner;
	local UT2K4ServerLoading LoadingScreen;
	local DrawOpText HintTextOp;
	local class<GameInfo> GameClass;
	local int i, ClientSide, Start, End;
	local BetrayalDrawImageOp Image;
	local BetrayalDrawTextOp Text;
	local array<string> Parts;
	local array<TDrawOp> DrawOps;
	local bool bWrapText;

	foreach Ref.AllObjects(class'UT2K4ServerLoading', LoadingScreen) {
		if (!LoadingScreen.bDeleteMe)
			break;
	}

	if (LoadingScreen != None) {
		HintTextOp = DrawOpText(LoadingScreen.Operations[3]);
		if (Right(MapName, 6) ~= ".demo4") {
			DemoName = MapName;
			LoadDemoData(Ref, DemoName, MapName, MapTitle, MapDescription, MapAuthor, MapScreenshot, RecordedBy, Timestamp, ClientSide);
			DrawOps = default.DemoDrawOps;
		}
		else {
			LoadMapData(MapName, MapTitle, MapDescription, MapAuthor, MapScreenshot);
			DrawOps = default.GameDrawOps;
		}
		GameClass = LoadingScreen.GameClass;
		if (GameClass != None) {
			GameTypeName = GameClass.default.GameName;
			GameScreenshot = Material(DynamicLoadObject(GameClass.default.GameName, class'Material', true));
		}

		if (MapScreenshot != None) {
			BGInterlaceScaler = new(None) class'TexScaler';
			BGInterlaceScaler.Material = Texture'InterfaceContent.Menu.InterlaceLines';
			BGInterlaceScaler.VScale   = 0.05;

			BGCombiner = new(None) class'Combiner';
			BGCombiner.Material1        = BGInterlaceScaler;
			BGCombiner.CombineOperation = CO_Multiply;
			MapBackground = BGCombiner;
			if (MaterialSequence(MapScreenshot) != None) {
				// pick random sequence items for background and smaller preview image
				BGCombiner.Material2 = MaterialSequence(MapScreenshot).SequenceItems[Rand(MaterialSequence(MapScreenshot).SequenceItems.Length)].Material;
				do {
					i = Rand(MaterialSequence(MapScreenshot).SequenceItems.Length);
				} until (Rand(5) == 0 || BGCombiner.Material2 != MaterialSequence(MapScreenshot).SequenceItems[i].Material);
				MapScreenshot = MaterialSequence(MapScreenshot).SequenceItems[i].Material;
			}
			else {
				BGCombiner.Material2 = MapScreenshot;
			}
		}

		if (GameScreenshot != None) {
			BGInterlaceScaler = new(None) class'TexScaler';
			BGInterlaceScaler.Material = Texture'InterfaceContent.Menu.InterlaceLines';
			BGInterlaceScaler.VScale   = 0.05;

			BGCombiner = new(None) class'Combiner';
			BGCombiner.Material1        = BGInterlaceScaler;
			BGCombiner.CombineOperation = CO_Multiply;
			GameBackground = BGCombiner;
			if (MaterialSequence(GameScreenshot) != None) {
				// pick random sequence items for background and smaller preview image
				BGCombiner.Material2 = MaterialSequence(GameScreenshot).SequenceItems[Rand(MaterialSequence(GameScreenshot).SequenceItems.Length)].Material;
				do {
					i = Rand(MaterialSequence(GameScreenshot).SequenceItems.Length);
				} until (Rand(5) == 0 || BGCombiner.Material2 != MaterialSequence(GameScreenshot).SequenceItems[i].Material);
				GameScreenshot = MaterialSequence(GameScreenshot).SequenceItems[i].Material;
			}
			else {
				BGCombiner.Material2 = GameScreenshot;
			}
		}

		// ensure interface quality
		FixQuality(MapScreenshot);
		FixQuality(MapBackground);

		// remove all draw operations
		LoadingScreen.Operations.Length = 0;

		// create new list of draw operations
		for (i = 0; i < DrawOps.Length; ++i) {
			switch (Locs(DrawOps[i].Content)) {
			case "`bgmapimage":
				if (MapBackground != None)
					Image = AddImage(LoadingScreen, MapBackground, DrawOps[i].Top, DrawOps[i].Left, DrawOps[i].Height, DrawOps[i].Width);
				else if (GameBackground != None)
					Image = AddImage(LoadingScreen, GameBackground, DrawOps[i].Top, DrawOps[i].Left, DrawOps[i].Height, DrawOps[i].Width);
				else
					Image = AddImage(LoadingScreen, Texture'BlackTexture', DrawOps[i].Top, DrawOps[i].Left, DrawOps[i].Height, DrawOps[i].Width);
				Image.RenderStyle   = DrawOps[i].RenderStyle;
				Image.DrawColor     = DrawOps[i].DrawColor;
				Image.Justification = DrawOps[i].AlignH;
				break;

			case "`bggameimage":
				if (GameBackground != None)
					Image = AddImage(LoadingScreen, GameBackground, DrawOps[i].Top, DrawOps[i].Left, DrawOps[i].Height, DrawOps[i].Width);
				else if (MapBackground != None)
					Image = AddImage(LoadingScreen, MapBackground, DrawOps[i].Top, DrawOps[i].Left, DrawOps[i].Height, DrawOps[i].Width);
				else
					Image = AddImage(LoadingScreen, Texture'BlackTexture', DrawOps[i].Top, DrawOps[i].Left, DrawOps[i].Height, DrawOps[i].Width);
				Image.RenderStyle   = DrawOps[i].RenderStyle;
				Image.DrawColor     = DrawOps[i].DrawColor;
				Image.Justification = DrawOps[i].AlignH;
				break;

			case "`mapimage":
				if (MapScreenshot != None)
					Image = AddImage(LoadingScreen, MapScreenshot, DrawOps[i].Top, DrawOps[i].Left, DrawOps[i].Height, DrawOps[i].Width);
				else
					Image = AddImage(LoadingScreen, Texture'InterfaceContent.Menu.NoLevelPreview', DrawOps[i].Top, DrawOps[i].Left, DrawOps[i].Height, DrawOps[i].Width);
				Image.RenderStyle   = DrawOps[i].RenderStyle;
				Image.DrawColor     = DrawOps[i].DrawColor;
				Image.Justification = DrawOps[i].AlignH;
				break;

			case "`gameimage":
				if (GameScreenshot != None)
					Image = AddImage(LoadingScreen, GameScreenshot, DrawOps[i].Top, DrawOps[i].Left, DrawOps[i].Height, DrawOps[i].Width);
				else
					Image = AddImage(LoadingScreen, Texture'BlackTexture', DrawOps[i].Top, DrawOps[i].Left, DrawOps[i].Height, DrawOps[i].Width);
				Image.RenderStyle   = DrawOps[i].RenderStyle;
				Image.DrawColor     = DrawOps[i].DrawColor;
				Image.Justification = DrawOps[i].AlignH;
				break;

			case "`gamehint":
				Text = AddText(LoadingScreen, "", DrawOps[i].AlignH, DrawOps[i].Top, DrawOps[i].Left, DrawOps[i].Height, DrawOps[i].Width, DrawOps[i].AlignV);
				Text.RenderStyle = DrawOps[i].RenderStyle;
				Text.DrawColor   = DrawOps[i].DrawColor;
				Text.FontName    = DrawOps[i].FontName;
				Text.bWrapText   = bWrapText;
				Text.Source      = HintTextOp;
				break;

			default:
				if (Left(DrawOps[i].Content, 7) ~= "`image:") {
					// an image
					switch (Split(Mid(DrawOps[i].Content, 7), ",", Parts)) {
					case 1:
						Parts[1] = "-1";
					case 2:
						Parts[2] = "-1";
					case 3:
						Parts[3] = "-1";
					case 4:
						Parts[4] = "-1";
					}
					Image = AddImage(LoadingScreen, Material(DynamicLoadObject(Parts[0], class'Material', true)), DrawOps[i].Top, DrawOps[i].Left, DrawOps[i].Height, DrawOps[i].Width);
					Image.RenderStyle   = DrawOps[i].RenderStyle;
					Image.DrawColor     = DrawOps[i].DrawColor;
					Image.Justification = DrawOps[i].AlignH;
					Image.ImageStyle    = DrawOps[i].ImageStyle;
					Image.SubX          = int(Parts[1]);
					Image.SubY          = int(Parts[2]);
					Image.SubXL         = int(Parts[3]);
					Image.SubYL         = int(Parts[4]);
				}
				else if (Left(DrawOps[i].Content, 8) ~= "`random:") {
					// a random image from a list
					Split(Mid(DrawOps[i].Content, 8), ";", Parts);
					switch (Split(Parts[Rand(Parts.Length)], ",", Parts)) {
					case 1:
						Parts[1] = "-1";
					case 2:
						Parts[2] = "-1";
					case 3:
						Parts[3] = "-1";
					case 4:
						Parts[4] = "-1";
					}
					Image = AddImage(LoadingScreen, Material(DynamicLoadObject(Parts[0], class'Material', true)), DrawOps[i].Top, DrawOps[i].Left, DrawOps[i].Height, DrawOps[i].Width);
					Image.RenderStyle   = DrawOps[i].RenderStyle;
					Image.DrawColor     = DrawOps[i].DrawColor;
					Image.Justification = DrawOps[i].AlignH;
					Image.ImageStyle    = DrawOps[i].ImageStyle;
					Image.SubX          = int(Parts[1]);
					Image.SubY          = int(Parts[2]);
					Image.SubXL         = int(Parts[3]);
					Image.SubYL         = int(Parts[4]);
				}
				else {
					if (Left(DrawOps[i].Content, 10) ~= "`localize:") {
						// a localized string
						Split(Mid(DrawOps[i].Content, 10), ".", Parts);
						while (Parts.Length > 3) {
							Parts[2] $= "." $ Parts[3];
							Parts.Remove(3, 1);
						}
						Content = Localize(Parts[1], Parts[2], Parts[0]);
					}
					else {
						// plain text
						Content = DrawOps[i].Content;
					}
					Parsed = "";
					bWrapText = DrawOps[i].WrapText;
					do {
						Start = InStr(Content, "\`{"); // nevermind the backslash, I'm just working around my highlighter's bug
						if (Start == -1) {
							Parsed $= Content;
							break;
						}
						Parsed $= Left(Content, Start);
						Content = Mid(Content, Start+2);
						End = InStr(Content, "}");
						if (End == -1)
							End = Len(Content);

						switch (Left(Content, End)) {
						case "maptitle":
							Parsed $= MapTitle;
							break;

						case "mapname":
							Parsed $= LoadingScreen.StripMap(MapName);
							break;

						case "demoname":
							Parsed $= DemoName;
							break;

						case "demotype":
							Parsed $= Eval(ClientSide != 0, class'UT2K4Demos'.default.ltClientSide, class'UT2K4Demos'.default.ltServerSide);
							break;

						case "recordedby":
							Parsed $= RecordedBy;
							break;

						case "timestamp":
							Parsed $= Timestamp;
							break;

						case "byplayer":
							Parsed $= Repl(default.LoadingScreenByNameText, "`name", RecordedBy);
							break;

						case "attime":
							Parsed $= Repl(default.LoadingScreenAtTimeText, "`time", Timestamp);
							break;

						case "gamename":
							Parsed $= GameTypeName;
							break;

						case "lf":
							Parsed $= Chr(10);
							bWrapText = True;
							break;
						}
						Content = Mid(Content, End + 1);
					}
					Text = AddText(LoadingScreen, Parsed, DrawOps[i].AlignH, DrawOps[i].Top, DrawOps[i].Left, DrawOps[i].Height, DrawOps[i].Width, DrawOps[i].AlignV);
					Text.RenderStyle = DrawOps[i].RenderStyle;
					Text.DrawColor   = DrawOps[i].DrawColor;
					Text.FontName    = DrawOps[i].FontName;
					Text.bWrapText   = bWrapText;
				}
			}
		}
	}
	return Super.GetLoadingHint(Ref, MapName, HintColor);
}

static function array<string> GetAllLoadHints(optional bool bThisClassOnly)
{
	local int i;
	local array<string> Hints, DMHints;

	if (!bThisClassOnly || default.BetrayalHints.Length == 0) {
		DMHints = Super.GetAllLoadhints(bThisClassOnly);
		for (i = 0; i < default.RelevantDMLoadingHints.Length; i++)
			Hints[Hints.Length] = DMHints[default.RelevantDMLoadingHints[i]];
	}
	for (i = 0; i < default.BetrayalHints.Length; i++)
		Hints[Hints.Length] = default.BetrayalHints[i];

	return Hints;
}

static function BetrayalDrawImageOp AddImage(UT2K4LoadingPageBase LoadingScreen, Material Image, float Top, float Left, float Height, float Width)
{
	local BetrayalDrawImageOp NewImage;

	NewImage = new(None) class'BetrayalDrawImageOp';
	LoadingScreen.Operations[LoadingScreen.Operations.Length] = NewImage;

	NewImage.Image = Image;
	NewImage.SetPos(Top, Left);
	NewImage.SetSize(Height, Width);
	return NewImage;
}

static function BetrayalDrawTextOp AddText(UT2K4LoadingPageBase LoadingScreen, string Text, byte Just, float Top, float Left, float Height, float Width, optional byte VAlign)
{
	local BetrayalDrawTextOp NewText;

	NewText = new(None) class'BetrayalDrawTextOp';
	LoadingScreen.Operations[LoadingScreen.Operations.Length] = NewText;

	NewText.SetPos(Top, Left);
	NewText.Text = Text;
	NewText.SetSize(Height, Width);
	NewText.Justification = Just;
	NewText.VertAlign = VAlign;
	return NewText;

}

static function bool LoadDemoData(PlayerController Ref, string DemoName, out string MapName, out string MapTitle, out string MapDescription, out string MapAuthor, out Material MapScreenshot, out string RecordedBy, out string Timestamp, out int ClientSide)
{
	local string GameType, ReqPackages;
	local int ScoreLimit, TimeLimit;

	if (Ref == None || Ref.Player == None || GUIController(Ref.Player.GUIController) == None || !GUIController(Ref.Player.GUIController).GetDEMHeader(DemoName, MapName, GameType, ScoreLimit, TimeLimit, ClientSide, RecordedBy, Timestamp, ReqPackages))
		return false;

	return LoadMapData(MapName, MapTitle, MapDescription, MapAuthor, MapScreenshot);
}

static function bool LoadMapData(string MapName, out string MapTitle, out string MapDescription, out string MapAuthor, out Material MapScreenshot)
{
	local array<CacheManager.MapRecord> MapRecords;
	local int i;
	local LevelSummary MapSummary;
	local string MapDecoText, DecoTextPackage, DecoTextName;
	local DecoText DecoText;

	class'CacheManager'.static.GetMapList(MapRecords);
	for (i = 0; i < MapRecords.Length; ++i) {
		if (MapRecords[i].MapName ~= MapName) {
			MapTitle       = MapRecords[i].FriendlyName;
			MapDescription = MapRecords[i].Description;
			MapAuthor      = MapRecords[i].Author;
			MapDecoText    = MapRecords[i].TextName;
			if (MapRecords[i].ScreenshotRef != "")
				MapScreenshot = Material(DynamicLoadObject(MapRecords[i].ScreenshotRef, class'Material', True));
			break;
		}
	}

	// try loading from map summary if cache doesn't provide title and screenshot
	if (MapTitle == "" || MapScreenshot == None) {
		MapSummary = LevelSummary(DynamicLoadObject(MapName $ ".LevelSummary", class'LevelSummary', True));
		if (MapSummary != None) {
			MapTitle       = MapSummary.Title;
			MapDescription = MapSummary.Description;
			MapAuthor      = MapSummary.Author;
			MapDecoText    = MapSummary.DecoTextName;
			MapScreenshot  = MapSummary.Screenshot;
		}
		return false;
	}

	// try loading deco text if no description
	if (MapDescription == "" && Divide(MapDecoText, ".", DecoTextPackage, DecoTextName)) {
		DecoText = class'XUtil'.static.LoadDecoText(DecoTextPackage, DecoTextName);
		for (i = 0; i < DecoText.Rows.Length; i++) {
			if (MapDescription != "")
				MapDescription $= "|";
			MapDescription $= DecoText.Rows[i];
		}
	}

	// fallback values for title
	if (MapTitle == "" || MapTitle == class'LevelInfo'.default.Title)
		MapTitle = Mid(MapName, InStr(MapName, "-") + 1);

	return true;
}


static function FixQuality(Material Mat)
{
	local Texture T;
	local Combiner C;
	local Shader S;
	local Modifier M;

	if (Mat == None)
		return;

	FixQuality(Mat.FallbackMaterial);

	T = Texture(Mat);
	if (T != None) {
		if (T.LODSet != LODSET_None)
			T.LODSet = LODSET_Interface;
		FixQuality(T.Detail);
		return;
	}

	M = Modifier(Mat);
	if (M != None) {
		FixQuality(M.Material);
		return;
	}

	S = Shader(Mat);
	if (S != None) {
		FixQuality(S.Diffuse);
		FixQuality(S.Opacity);
		FixQuality(S.Specular);
		FixQuality(S.SpecularityMask);
		FixQuality(S.SelfIllumination);
		FixQuality(S.SelfIlluminationMask);
		FixQuality(S.Detail);
		return;
	}

	C = Combiner(Mat);
	if (C != None) {
		FixQuality(C.Material1);
		FixQuality(C.Material2);
		FixQuality(C.Mask);
		return;
	}
}


static function FillPlayInfo(PlayInfo PlayInfo)
{
	Super.FillPlayInfo(PlayInfo);

	PlayInfo.AddSetting(default.RulesGroup, "bBeamMultiHit", default.lblBeamMultiHit, 0, 0, "Check");
	PlayInfo.AddSetting(default.RulesGroup, "MaxUnlagTime", default.lblMaxUnlagTime, 0, 0, "Text", "5;0.0:1.0",, True);
	PlayInfo.AddSetting(default.RulesGroup, "bSpecialKillRewards", default.lblSpecialKillRewards, 0, 0, "Check");
	PlayInfo.AddSetting(default.RulesGroup, "bRestorePlayerStats", default.lblRestorePlayerStats, 0, 0, "Check");
	PlayInfo.AddSetting(default.RulesGroup, "bBrighterPlayerSkins", default.lblBrighterPlayerSkins, 0, 0, "Check");
	PlayInfo.AddSetting(default.RulesGroup, "bImprovedSlopeDodging", default.lblImprovedSlopeDodging, 0, 0, "Check");
}


static event bool AcceptPlayInfoProperty(string PropertyName)
{
	switch (PropertyName) {
	case "bAllowTrans":
	case "bForceRespawn":
	case "bAllowWeaponThrowing":
	case "bWeaponStay":
		return false;
	default:
		return Super.AcceptPlayInfoProperty(PropertyName);
	}
}


/**
Returns the description text for a configurable property.
*/
static event string GetDescriptionText(string PropName)
{
	switch (PropName) {
		case "bBeamMultiHit":
			return default.descBeamMultiHit;
		case "MaxUnlagTime":
			return default.descMaxUnlagTime;
		case "bSpecialKillRewards":
			return default.descSpecialKillRewards;
		case "bRestorePlayerStats":
			return default.descRestorePlayerStats;
		case "bBrighterPlayerSkins":
			return default.descBrighterPlayerSkins;
		case "bImprovedSlopeDodging":
			return default.descImprovedSlopeDodging;
		default:
			return Super.GetDescriptionText(PropName);
	}
}


//=============================================================================
// Default values
//=============================================================================

defaultproperties
{
	GameName    = "Betrayal"
	Description = "Cooperate to get bonus points.  Betray your team to keep them."
	Acronym     = "BET"
	GoalScore   = 100

	Build     = "%%%%-%%-%% %%:%%"
	Copyright = "Copyright 2003-2013 by Wormbo"

	bBeamMultiHit = False
	MaxUnlagTime  = 0.25
	bSpecialKillRewards = False
	bRestorePlayerStats = True
	bImprovedSlopeDodging = True

	MutatorClass           = "Betrayal.BetrayalMutator"
	HUDType                = "Betrayal.BetrayalHud"
	ScoreBoardType         = "Betrayal.BetrayalScoreboard"
	DefaultPlayerClassName = "Betrayal.BetrayalPawn"
	HUDSettingsMenu        = "Betrayal.BetrayalClientSettingsMenu"
	LocalStatsScreenClass  = "Betrayal.BetrayalStatsScreen"
	LoginMenuClass         = "GUI2K4.UT2K4PlayerLoginMenu"

	BetrayedSound = Sound'GameSounds.DDAverted'

	DMSquadClass             = class'BetrayalSquadAI'
	GameReplicationInfoClass = class'BetrayalGRI'
	AnnouncerMessageClass    = class'BetrayalMessage'
	DeathMessageClass        = class'BetrayalDeathMessage'

	lblMaxUnlagTime          = "Max. Unlag Time"
	descMaxUnlagTime         = "Maximum shot unlag time."
	lblBeamMultiHit          = "Instagib Beam Multi-Hit"
	descBeamMultiHit         = "Whether the Instagib rifle shoots through players."
	lblSpecialKillRewards    = "Special Kill Rewards"
	descSpecialKillRewards   = "Adds an additional point for special kills, such as multiple hits per shot, head shots or nice mid-air hits."
	lblRestorePlayerStats    = "Restore Player Stats"
	descRestorePlayerStats   = "Save the player's stats of he/she becomes spectator or leaves the server and restore them on rejoin in the same match."
	lblBrighterPlayerSkins   = "Brighter Player Skins"
	descBrighterPlayerSkins  = "Slightly increases player skin brightness. (For the TAM-/UTComp-impaired players.)"
	lblImprovedSlopeDodging  = "Improved slope dodging"
	descImprovedSlopeDodging = "Adjusts the dodging direction when dodging up a (walkable) slope."

	RelevantDMLoadingHints = (1,2,3,7,9,11,12,13)
	BetrayalHints[0] = "Shoot with %FIRE% to kill enemies, shoot with %ALTFIRE% to kill your teammates and take the team pot."
	BetrayalHints[1] = "Try getting retribution on a former teammate who betrayed you. Doing so within 30 seconds after betrayal will award you additional points."
	BetrayalHints[2] = "Make sure you hit with the first shot when trying to betray your team. Betraying shots have a different color, so your teammate will notice your intentions if you miss."
	BetrayalHints[3] = "Don't betray your team right away. The few points in the team pot might not be worth the trouble of avoiding payback. Later betraying at the right time can decide the match very quickly, though."
	BetrayalHints[4] = "The player beacons reflect your relation to that player and tell how much points you will get for killing him/her. Blue is for teammates, red is for a former teammate who betrayed you, green is for the former teammates who are seeking payback on you."
	BetrayalHints[5] = "Be aware of your teammates' scores when they get closer to the goal score. You may need to betray them to prevent them from taking the pot to win the match."
	BetrayalHints[6] = "You can access client-side Betrayal options via %MYMENU%."
	BetrayalHints[7] = "You can access client-side Betrayal options via %MENU3SPN%."
	BetrayalHints[8] = "You can access client-side Betrayal options via the standard HUD settings page."
	// ^-- stupid hint parsing algorithm
	BetrayalHints[9] = "After you betrayed your team, try to not give them a chance for retribution. When they succeed your score will decrease!"

	LoadingScreenByNameText = "by `name"
	LoadingScreenAtTimeText = "at `time"

	GameDrawOps(0) = (Content="`bgmapimage",Height=1.0,Width=1.0,RenderStyle=1,DrawColor=(R=200,G=200,B=200,A=255))
	GameDrawOps(1) = (Content="`random:2k4Menus.MainMenu.Char01,0,0,1024,768;2k4Menus.MainMenu.Char02,0,0,1024,768;2k4Menus.MainMenu.Char03,0,0,1024,768",Top=0.0,Left=0.0,Height=1.0,Width=1.0,RenderStyle=5,DrawColor=(R=255,G=255,B=255,A=255))
	GameDrawOps(2) = (Content="`image:2k4Menus.MainMenu.2k4Logo",Top=0.0,Left=0.325,Height=0.25,Width=0.35,RenderStyle=5,DrawColor=(R=224,G=224,B=224,A=255))
	GameDrawOps(3) = (Content="`mapimage",Top=0.25,Left=0.1,Height=0.4,Width=0.4,RenderStyle=1,DrawColor=(R=255,G=255,B=255,A=255))
	GameDrawOps(4) = (Content="`image:2k4Menus.Controls.outlinesquare",Top=0.25,Left=0.1,Height=0.4,Width=0.4,RenderStyle=5,ImageStyle=3,DrawColor=(R=128,G=128,B=128,A=255))
	GameDrawOps(5) = (Content="`{gamename}",Top=0.05,Left=0.0,Height=0.2,Width=0.6,RenderStyle=1,AlignH=1,AlignV=2,FontName="XInterface.UT2LargeFont",DrawColor=(R=255,G=255,B=255,A=255))
	GameDrawOps(6) = (Content="`{maptitle}",Top=0.65,Left=0.0,Height=0.15,Width=0.6,RenderStyle=1,AlignH=1,FontName="XInterface.UT2LargeFont",DrawColor=(R=255,G=255,B=255,A=255))
	GameDrawOps(7) = (Content="`gamehint",Top=0.8,Left=0.05,Height=0.18,Width=0.9,RenderStyle=1,AlignV=2,WrapText=True,FontName="GUI2K4.fntUT2k4SmallHeader",DrawColor=(R=255,G=255,B=255,A=255))

	DemoDrawOps(0) = (Content="`bgmapimage",Height=1.0,Width=1.0,RenderStyle=1,DrawColor=(R=200,G=200,B=200,A=255))
	DemoDrawOps(1) = (Content="`random:2k4Menus.MainMenu.Char01,0,0,1024,768;2k4Menus.MainMenu.Char02,0,0,1024,768;2k4Menus.MainMenu.Char03,0,0,1024,768",Top=0.0,Left=0.0,Height=1.0,Width=1.0,RenderStyle=5,DrawColor=(R=255,G=255,B=255,A=255))
	DemoDrawOps(2) = (Content="`image:2k4Menus.MainMenu.2k4Logo",Top=0.0,Left=0.325,Height=0.25,Width=0.35,RenderStyle=5,DrawColor=(R=224,G=224,B=224,A=255))
	DemoDrawOps(3) = (Content="`mapimage",Top=0.25,Left=0.1,Height=0.4,Width=0.4,RenderStyle=1,DrawColor=(R=255,G=255,B=255,A=255))
	DemoDrawOps(4) = (Content="`image:2k4Menus.Controls.outlinesquare",Top=0.25,Left=0.1,Height=0.4,Width=0.4,RenderStyle=5,ImageStyle=3,DrawColor=(R=128,G=128,B=128,A=255))
	DemoDrawOps(5) = (Content="`{gamename}`{lf}`{maptitle}",Top=0.05,Left=0.0,Height=0.2,Width=0.6,RenderStyle=1,AlignH=1,AlignV=2,FontName="XInterface.UT2LargeFont",DrawColor=(R=255,G=255,B=255,A=255))
	DemoDrawOps(6) = (Content="`{demotype}`{lf}`{byplayer}`{lf}`{attime}",Top=0.65,Left=0.0,Height=0.3,Width=0.6,RenderStyle=1,AlignH=1,FontName="XInterface.UT2LargeFont",DrawColor=(R=255,G=255,B=255,A=255))
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Mi 5.2.2014 18:52:16.000 - Creation time: Do 14.8.2014 09:58:34.799 - Created with UnCodeX