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

UTGame.UTGame


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
01775
01776
01777
01778
01779
01780
01781
01782
01783
01784
01785
01786
01787
01788
01789
01790
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995
01996
01997
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010
02011
02012
02013
02014
02015
02016
02017
02018
02019
02020
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035
02036
02037
02038
02039
02040
02041
02042
02043
02044
02045
02046
02047
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080
02081
02082
02083
02084
02085
02086
02087
02088
02089
02090
02091
02092
02093
02094
02095
02096
02097
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109
02110
02111
02112
02113
02114
02115
02116
02117
02118
02119
02120
02121
02122
02123
02124
02125
02126
02127
02128
02129
02130
02131
02132
02133
02134
02135
02136
02137
02138
02139
02140
02141
02142
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164
02165
02166
02167
02168
02169
02170
02171
02172
02173
02174
02175
02176
02177
02178
02179
02180
02181
02182
02183
02184
02185
02186
02187
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212
02213
02214
02215
02216
02217
02218
02219
02220
02221
02222
02223
02224
02225
02226
02227
02228
02229
02230
02231
02232
02233
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249
02250
02251
02252
02253
02254
02255
02256
02257
02258
02259
02260
02261
02262
02263
02264
02265
02266
02267
02268
02269
02270
02271
02272
02273
02274
02275
02276
02277
02278
02279
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289
02290
02291
02292
02293
02294
02295
02296
02297
02298
02299
02300
02301
02302
02303
02304
02305
02306
02307
02308
02309
02310
02311
02312
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324
02325
02326
02327
02328
02329
02330
02331
02332
02333
02334
02335
02336
02337
02338
02339
02340
02341
02342
02343
02344
02345
02346
02347
02348
02349
02350
02351
02352
02353
02354
02355
02356
02357
02358
02359
02360
02361
02362
02363
02364
02365
02366
02367
02368
02369
02370
02371
02372
02373
02374
02375
02376
02377
02378
02379
02380
02381
02382
02383
02384
02385
02386
02387
02388
02389
02390
02391
02392
02393
02394
02395
02396
02397
02398
02399
02400
02401
02402
02403
02404
02405
02406
02407
02408
02409
02410
02411
02412
02413
02414
02415
02416
02417
02418
02419
02420
02421
02422
02423
02424
02425
02426
02427
02428
02429
02430
02431
02432
02433
02434
02435
02436
02437
02438
02439
02440
02441
02442
02443
02444
02445
02446
02447
02448
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488
02489
02490
02491
02492
02493
02494
02495
02496
02497
02498
02499
02500
02501
02502
02503
02504
02505
02506
02507
02508
02509
02510
02511
02512
02513
02514
02515
02516
02517
02518
02519
02520
02521
02522
02523
02524
02525
02526
02527
02528
02529
02530
02531
02532
02533
02534
02535
02536
02537
02538
02539
02540
02541
02542
02543
02544
02545
02546
02547
02548
02549
02550
02551
02552
02553
02554
02555
02556
02557
02558
02559
02560
02561
02562
02563
02564
02565
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580
02581
02582
02583
02584
02585
02586
02587
02588
02589
02590
02591
02592
02593
02594
02595
02596
02597
02598
02599
02600
02601
02602
02603
02604
02605
02606
02607
02608
02609
02610
02611
02612
02613
02614
02615
02616
02617
02618
02619
02620
02621
02622
02623
02624
02625
02626
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638
02639
02640
02641
02642
02643
02644
02645
02646
02647
02648
02649
02650
02651
02652
02653
02654
02655
02656
02657
02658
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674
02675
02676
02677
02678
02679
02680
02681
02682
02683
02684
02685
02686
02687
02688
02689
02690
02691
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704
02705
02706
02707
02708
02709
02710
02711
02712
02713
02714
02715
02716
02717
02718
02719
02720
02721
02722
02723
02724
02725
02726
02727
02728
02729
02730
02731
02732
02733
02734
02735
02736
02737
02738
02739
02740
02741
02742
02743
02744
02745
02746
02747
02748
02749
02750
02751
02752
02753
02754
02755
02756
02757
02758
02759
02760
02761
02762
02763
02764
02765
02766
02767
02768
02769
02770
02771
02772
02773
02774
02775
02776
02777
02778
02779
02780
02781
02782
02783
02784
02785
02786
02787
02788
02789
02790
02791
02792
02793
02794
02795
02796
02797
02798
02799
02800
02801
02802
02803
02804
02805
02806
02807
02808
02809
02810
02811
02812
02813
02814
02815
02816
02817
02818
02819
02820
02821
02822
02823
02824
02825
02826
02827
02828
02829
02830
02831
02832
02833
02834
02835
02836
02837
02838
02839
02840
02841
02842
02843
02844
02845
02846
02847
02848
02849
02850
02851
02852
02853
02854
02855
02856
02857
02858
02859
02860
02861
02862
02863
02864
02865
02866
02867
02868
02869
02870
02871
02872
02873
02874
02875
02876
02877
02878
02879
02880
02881
02882
02883
02884
02885
02886
02887
02888
02889
02890
02891
02892
02893
02894
02895
02896
02897
02898
02899
02900
02901
02902
02903
02904
02905
02906
02907
02908
02909
02910
02911
02912
02913
02914
02915
02916
02917
02918
02919
02920
02921
02922
02923
02924
02925
02926
02927
02928
02929
02930
02931
02932
02933
02934
02935
02936
02937
02938
02939
02940
02941
02942
02943
02944
02945
02946
02947
02948
02949
02950
02951
02952
02953
02954
02955
02956
02957
02958
02959
02960
02961
02962
02963
02964
02965
02966
02967
02968
02969
02970
02971
02972
02973
02974
02975
02976
02977
02978
02979
02980
02981
02982
02983
02984
02985
02986
02987
02988
02989
02990
02991
02992
02993
02994
02995
02996
02997
02998
02999
03000
03001
03002
03003
03004
03005
03006
03007
03008
03009
03010
03011
03012
03013
03014
03015
03016
03017
03018
03019
03020
03021
03022
03023
03024
03025
03026
03027
03028
03029
03030
03031
03032
03033
03034
03035
03036
03037
03038
03039
03040
03041
03042
03043
03044
03045
03046
03047
03048
03049
03050
03051
03052
03053
03054
03055
03056
03057
03058
03059
03060
03061
03062
03063
03064
03065
03066
03067
03068
03069
03070
03071
03072
03073
03074
03075
03076
03077
03078
03079
03080
03081
03082
03083
03084
03085
03086
03087
03088
03089
03090
03091
03092
03093
03094
03095
03096
03097
03098
03099
03100
03101
03102
03103
03104
03105
03106
03107
03108
03109
03110
03111
03112
03113
03114
03115
03116
03117
03118
03119
03120
03121
03122
03123
03124
03125
03126
03127
03128
03129
03130
03131
03132
03133
03134
03135
03136
03137
03138
03139
03140
03141
03142
03143
03144
03145
03146
03147
03148
03149
03150
03151
03152
03153
03154
03155
03156
03157
03158
03159
03160
03161
03162
03163
03164
03165
03166
03167
03168
03169
03170
03171
03172
03173
03174
03175
03176
03177
03178
03179
03180
03181
03182
03183
03184
03185
03186
03187
03188
03189
03190
03191
03192
03193
03194
03195
03196
03197
03198
03199
03200
03201
03202
03203
03204
03205
03206
03207
03208
03209
03210
03211
03212
03213
03214
03215
03216
03217
03218
03219
03220
03221
03222
03223
03224
03225
03226
03227
03228
03229
03230
03231
03232
03233
03234
03235
03236
03237
03238
03239
03240
03241
03242
03243
03244
03245
03246
03247
03248
03249
03250
03251
03252
03253
03254
03255
03256
03257
03258
03259
03260
03261
03262
03263
03264
03265
03266
03267
03268
03269
03270
03271
03272
03273
03274
03275
03276
03277
03278
03279
03280
03281
03282
03283
03284
03285
03286
03287
03288
03289
03290
03291
03292
03293
03294
03295
03296
03297
03298
03299
03300
03301
03302
03303
03304
03305
03306
03307
03308
03309
03310
03311
03312
03313
03314
03315
03316
03317
03318
03319
03320
03321
03322
03323
03324
03325
03326
03327
03328
03329
03330
03331
03332
03333
03334
03335
03336
03337
03338
03339
03340
03341
03342
03343
03344
03345
03346
03347
03348
03349
03350
03351
03352
03353
03354
03355
03356
03357
03358
03359
03360
03361
03362
03363
03364
03365
03366
03367
03368
03369
03370
03371
03372
03373
03374
03375
03376
03377
03378
03379
03380
03381
03382
03383
03384
03385
03386
03387
03388
03389
03390
03391
03392
03393
03394
03395
03396
03397
03398
03399
03400
03401
03402
03403
03404
03405
03406
03407
03408
03409
03410
03411
03412
03413
03414
03415
03416
03417
03418
03419
03420
03421
03422
03423
03424
03425
03426
03427
03428
03429
03430
03431
03432
03433
03434
03435
03436
03437
03438
03439
03440
03441
03442
03443
03444
03445
03446
03447
03448
03449
03450
03451
03452
03453
03454
03455
03456
03457
03458
03459
03460
03461
03462
03463
03464
03465
03466
03467
03468
03469
03470
03471
03472
03473
03474
03475
03476
03477
03478
03479
03480
03481
03482
03483
03484
03485
03486
03487
03488
03489
03490
03491
03492
03493
03494
03495
03496
03497
03498
03499
03500
03501
03502
03503
03504
03505
03506
03507
03508
03509
03510
03511
03512
03513
03514
03515
03516
03517
03518
03519
03520
03521
03522
03523
03524
03525
03526
03527
03528
03529
03530
03531
03532
03533
03534
03535
03536
03537
03538
03539
03540
03541
03542
03543
03544
03545
03546
03547
03548
03549
03550
03551
03552
03553
03554
03555
03556
03557
03558
03559
03560
03561
03562
03563
03564
03565
03566
03567
03568
03569
03570
03571
03572
03573
03574
03575
03576
03577
03578
03579
03580
03581
03582
03583
03584
03585
03586
03587
03588
03589
03590
03591
03592
03593
03594
03595
03596
03597
03598
03599
03600
03601
03602
03603
03604
03605
03606
03607
03608
03609
03610
03611
03612
03613
03614
03615
03616
03617
03618
03619
03620
03621
03622
03623
03624
03625
03626
03627
03628
03629
03630
03631
03632
03633
03634
03635
03636
03637
03638
03639
03640
03641
03642
03643
03644
03645
03646
03647
03648
03649
03650
03651
03652
03653
03654
03655
03656
03657
03658
03659
03660
03661
03662
03663
03664
03665
03666
03667
03668
03669
03670
03671
03672
03673
03674
03675
03676
03677
03678
03679
03680
03681
03682
03683
03684
03685
03686
03687
03688
03689
03690
03691
03692
03693
03694
03695
03696
03697
03698
03699
03700
03701
03702
03703
03704
03705
03706
03707
03708
03709
03710
03711
03712
03713
03714
03715
03716
03717
03718
03719
03720
03721
03722
03723
03724
03725
03726
03727
03728
03729
03730
03731
03732
03733
03734
03735
03736
03737
03738
03739
03740
03741
03742
03743
03744
03745
03746
03747
03748
03749
03750
03751
03752
03753
03754
03755
03756
/**
 *
 * Copyright 1998-2007 Epic Games, Inc. All Rights Reserved.
 */

class UTGame extends GameInfo
    config(Game)
    abstract
    native;

/** if set, when this class is compiled, a menu entry for it will be automatically added/updated in its package.ini file
 * (abstract classes are skipped even if this flag is set)
 */
var bool bExportMenuData;

var bool                bWeaponStay;              // Whether or not weapons stay when picked up.
var bool                bTeamScoreRounds;
var bool                bSoaking;
var bool                bPlayersVsBots;
var bool                bCustomBots;
var bool                bNoCustomCharacters;

var string Acronym;
var localized string Description;

var globalconfig    int     ServerSkillLevel;   // The Server Skill Level ( 0 - 2, Beginner/Experienced/Expert )
var globalconfig    float   EndTimeDelay;
var globalconfig    float   BotRatio;           // only used when bPlayersVsBots is true
var config          int     NetWait;       // time to wait for players in netgames w/ bWaitForNetPlayers (typically team games)
/** how long we wait for clients to perform initial processing at the start of the game (UTPlayerController::bInitialProcessingComplete) */
var config int ClientProcessingTimeout;
var globalconfig    int     MinNetPlayers; // how many players must join before net game will start
var globalconfig    int     RestartWait;

var                 bool    bAutoNumBots;           // Match bots to map's recommended bot count
var globalconfig    bool    bPlayersMustBeReady;    // players must confirm ready for game to start
var globalconfig    bool    bForceRespawn;          /** Force dead players to respawn immediately if true (configurable) */
var                 bool    bTempForceRespawn;      /** Temporary (used in game) version of bForceRespawn */
var globalconfig    bool    bWaitForNetPlayers;     // wait until more than MinNetPlayers players have joined before starting match

var config bool bWarmupRound;           // If true, this match will have a warmup round
var config int WarmupTime;              // How long is the warmup round (In Seconds)
var                 int     WarmupRemaining;        // How much time left in the Warmup Round

var bool    bFirstBlood;
var bool    bQuickStart;
var bool    bSkipPlaySound;     // override "play!" sound
var bool    bStartedCountDown;
var bool    bFinalStartup;
var bool    bOverTimeBroadcast;
var bool bMustHaveMultiplePlayers;
var bool bPlayerBecameActive;
var bool    bMustJoinBeforeStart;   // players can only spectate if they join after the game starts
var bool    bDemoMode;              // turn off HUD, etc.
/** whether not yet driven vehicles can take damage */
var bool bUndrivenVehicleDamage;

var byte StartupStage;              // what startup message to display
var int DesiredPlayerCount;         // bots will fill in to reach this value as needed

var float       SpawnProtectionTime;
var int         DefaultMaxLives;
var config int          LateEntryLives; // defines how many lives in a player can still join

var int PendingMatchElapsedTime;
var int CountDown;
var float AdjustedDifficulty;
var int PlayerKills, PlayerDeaths;

var NavigationPoint LastPlayerStartSpot;    // last place current player looking for start spot started from
var NavigationPoint LastStartSpot;          // last place any player started from

var float EndTime;
var int             EndMessageWait;         // wait before playing which team won the match
var transient int   EndMessageCounter;      // end message counter

var   string                  RulesMenuType;            // Type of rules menu to display.
var   string                  GameUMenuType;            // Type of Game dropdown to display.

var actor EndGameFocus;

var() int                     ResetCountDown;
var() config int              ResetTimeDelay;           // time (seconds) before restarting teams

var UTVehicle VehicleList;

var UTTeamInfo EnemyRoster;
var string EnemyRosterName;
var string DefaultEnemyRosterClass;

/** Default inventory added via AddDefaultInventory() */
var array< class<Inventory> >   DefaultInventory;

// translocator
var bool    bAllowTranslocator;
var UTProj_TransDisc BeaconList;
/** class to add to default inventory when translocator is enabled (translocator can't be enabled unless this has a value) */
var class<Inventory> TranslocatorClass;

// hoverboard
var         bool    bAllowHoverboard;

var class<UTVictoryMessage> VictoryMessageClass;
struct native GameTypePrefix
{
    /** map prefix, e.g. "DM" */
    var string Prefix;
    /** gametype used if none specified on the URL */
    var string GameType;
    /** additional gametypes supported by this map prefix via the URL (used for cooking) */
    var array<string> AdditionalGameTypes;
};
var array<GameTypePrefix> DefaultMapPrefixes; /** Used for loading appropriate game type if non-specified in URL */
var globalconfig array<GameTypePrefix> CustomMapPrefixes; /** Used for loading appropriate game type if non-specified in URL */
var array<string> MapPrefixes; /** Prefix characters for names of maps for this game type */

// console server
var bool bConsoleServer;

/** PlayerController class to use on consoles */
var class<PlayerController> ConsolePlayerControllerClass;

/**
 * This being false implies that only gamepads are valid for input type.
 * This is not 100% precise as you could have a keyboard + gamepad which could be valid if we wanted to allow typing but no movement.
 **/
var bool bAllowKeyboardAndMouse;

/** Used by the single player game */
var int SinglePlayerMissionID;

/** prefix of filename to record a demo to - a number is added on to get a unique filename (empty string means don't record) */
var string DemoPrefix;

/** class used for AI bots */
var class<UTBot> BotClass;

// These variables are set by the UI on the default object and should be read using the default object of class'UTGame'.

/** Game Map Cycles, there is a map cycle per game mode */
struct native GameMapCycle
{
    var name GameClassName;
    var array<string> Maps;
};
var globalconfig array<GameMapCycle> GameSpecificMapCycles;
/** index of current map in the cycle */
var globalconfig int MapCycleIndex;

/** Array of active bot names. */
struct native ActiveBotInfo
{
    /** name of character */
    var string BotName;
    /** whether the bot is currently in the game */
    var bool bInUse;
};
var globalconfig array<ActiveBotInfo> ActiveBots;

/** forces the spawn location for the next player spawned */
var NavigationPoint ScriptedStartSpot;

/**** Map Voting ************/

/** If true, users will be presented with a map list to move on at the end of the round */
var config bool bAllowMapVoting;

/** How long the voting will take MAX. */
var config int VoteDuration;

/** The object that manages voting */
var UTVoteCollector VoteCollector;

var UTUIScene MidGameMenuTemplate;

var localized string EndOfMatchRulesTemplateStr_Scoring;
var localized string EndOfMatchRulesTemplateStr_Time;

/** object containing speech recognition data to use for this gametype */
var SpeechRecognition SpeechRecognitionData;

/** weapon specific Taunt management (keep them from being used multiple times per round) */
var byte    WeaponTauntUsed[20];

/** Last time bot yelled encouragement to player */
var float LastEncouragementTime;

/** Last time bot yelled mandown to player */
var float LastManDownTime;

/** Current sniper */
var Pawn Sniper;

/** Whether scoring is based on enemy deaths */
var bool bScoreDeaths;

/** Flag whether "X kills remain" has been played yet */
var bool bPlayedTenKills;
var bool bPlayedFiveKills;
var bool bPlayedOneKill;

var name MidgameScorePanelTag;
var bool bMidGameHasMap;

var config bool bForceMidGameMenuAtStart;

/** Used during the campaign to keep player team from using necris vehicles (until they get the magic key) */
var bool bNecrisLocked;

/** Used during the campaign to give player team a health bonuse */
var bool bExtraHealth;

/** Used during the campaign to give player team an armor bonus */
var bool bHeavyArmor;

/** @debug: used to draw HUD message so it's easy to tell when bots are set up incorrectly in SP missions */
var bool bBadSinglePlayerBotNames;

/** Maximum number of custom char meshes allowed. */
var() config int MaxCustomChars;

/** When enabled, allows players on different teams to voice chat with each other.  (Used for Duel games)  Note
  * that spectators still won't be able to talk to players and vice-versa, though. */
var bool bIgnoreTeamForVoiceChat;


/** Voice channels used by these game types */
enum EVoiceChannel
{
    VC_Spectators,
    VC_Team1,
    VC_Team2
};

/** for single player when "Tactical Diversion" card is used - skip adding this many Kismet spawned bots */
var int NumDivertedOpponents;

/** set when admin modified options via UTPlayerController::ServerAdminChangeOption() */
var bool bAdminModifiedOptions;

// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)

function PostBeginPlay()
{
    Super.PostBeginPlay();

    // add translocator to default inventory list, if allowed
    if (bAllowTranslocator)
    {
        if (TranslocatorClass != None)
        {
            DefaultInventory[DefaultInventory.Length] = TranslocatorClass;
        }
        else
        {
            bAllowTranslocator = false;
        }
    }

    if ( bPlayersVsBots )
        UTGameReplicationInfo(GameReplicationInfo).BotDifficulty = GameDifficulty;
}

/**
  * returns whether this game should be considered "pure"
  */
final native function bool IsPureGame();

// Returns whether a mutator should be allowed with this gametype
static function bool AllowMutator( string MutatorClassName )
{
    if ( !Default.bAllowTranslocator && (MutatorClassName ~= "UTGame.UTMutator_NoTranslocator") )
    {
        // already no translocator
        return false;
    }
    if ( !Default.bTeamGame && (MutatorClassName ~= "UTGame.UTMutator_FriendlyFire") )
    {
        // Friendly fire only valid in team games
        return false;
    }
    if (!default.bWeaponStay && MutatorClassName ~= "UTGame.UTMutator_WeaponsRespawn")
    {
        // weapon stay already off
        return false;
    }
    if ( MutatorClassName ~= "UTGame.UTMutator_Survival")
    {
        // survival mutator only for Duel
        return false;
    }
    if (MutatorClassName ~= "UTGame.UTMutator_NoOrbs")
    {
        // No Orbs mutator only for Warfare
        return false;
    }
    return Super.AllowMutator(MutatorClassName);
}

// Parse options for this game...
static event class<GameInfo> SetGameType(string MapName, string Options)
{
    local string ThisMapPrefix;
    local int i,pos;
    local class<GameInfo> NewGameType;
    local string GameOption;


    if (Left(MapName, 9) ~= "EnvyEntry" || Left(MapName, 10) ~= "UTFrontEnd")
    {
        return class'UTEntryGame';
    }

    // allow commandline to override game type setting
    GameOption = ParseOption( Options, "Game");
    if ( GameOption != "" )
    {
        return Default.class;
    }

    // strip the UEDPIE_ from the filename, if it exists (meaning this is a Play in Editor game)
    if (Left(MapName, 7) ~= "UEDPIE_")
    {
        MapName = Right(MapName, Len(MapName) - 7);
    }
    else if (Left(MapName, 10) ~= "UEDPOC_PS3")
    {
        MapName = Right(MapName, Len(MapName) - 10);
    }
    else if (Left(MapName, 12) ~= "UEDPOC_Xenon")
    {
        MapName = Right(MapName, Len(MapName) - 12);
    }

    // replace self with appropriate gametype if no game specified
    pos = InStr(MapName,"-");
    ThisMapPrefix = left(MapName,pos);
    for (i = 0; i < default.MapPrefixes.length; i++)
    {
        if (default.MapPrefixes[i] ~= ThisMapPrefix)
        {
            return Default.class;
        }
    }

    // change game type
    for ( i=0; i<Default.DefaultMapPrefixes.Length; i++ )
    {
        if ( Default.DefaultMapPrefixes[i].Prefix ~= ThisMapPrefix )
        {
            NewGameType = class<GameInfo>(DynamicLoadObject(Default.DefaultMapPrefixes[i].GameType,class'Class'));
            if ( NewGameType != None )
            {
                return NewGameType;
            }
        }
    }
    for ( i=0; i<Default.CustomMapPrefixes.Length; i++ )
    {
        if ( Default.CustomMapPrefixes[i].Prefix ~= ThisMapPrefix )
        {
            NewGameType = class<GameInfo>(DynamicLoadObject(Default.CustomMapPrefixes[i].GameType,class'Class'));
            if ( NewGameType != None )
            {
                return NewGameType;
            }
        }
    }

    // if no gametype found, use DemoGame
    return class'DemoGame';
}

//
// Return beacon text for serverbeacon.
//
event string GetBeaconText()
{
    return
        WorldInfo.ComputerName
    $   " "
    $   Left(WorldInfo.Title,24)
    $   "\\t"
    $   Acronym
    $   "\\t"
    $   GetNumPlayers()
    $   "/"
    $   MaxPlayers;
}

function DriverEnteredVehicle(Vehicle V, Pawn P)
{
    local UTPlayerReplicationInfo UTPRI;
    local UTVehicleBase UTV;

    if ( BaseMutator != None )
        BaseMutator.DriverEnteredVehicle(V, P);

    UTPRI = (V != None) ? UTPlayerReplicationInfo(V.PlayerReplicationInfo) : None;
    if ( UTPRI != None )
    {
        UTV = UTVehicleBase(V);
        if (UTV == None)
        {
            UTV = UTVehicleBase(V.GetVehicleBase());
        }
        if (UTV != None)
        {
            UTPRI.StartDrivingStat(UTV.GetVehicleDrivingStatName());
        }
    }
}

function DriverLeftVehicle(Vehicle V, Pawn P)
{
    local UTPlayerReplicationInfo UTPRI;

    if ( BaseMutator != None )
        BaseMutator.DriverLeftVehicle(V, P);

    UTPRI = UTPlayerReplicationInfo(P.PlayerReplicationInfo);
    if ( UTPRI != None && UTVehicleBase(V) != None )
    {
        UTPRI.StopDrivingStat(UTVehicleBase(V).GetVehicleDrivingStatName());
    }
}

function bool BecomeSpectator(PlayerController P)
{
    if ( (P.PlayerReplicationInfo == None) || !GameReplicationInfo.bMatchHasBegun
         || (NumSpectators >= MaxSpectators) || P.IsInState('RoundEnded') )
    {
        P.ReceiveLocalizedMessage(GameMessageClass, 12);
        return false;
    }

    P.PlayerReplicationInfo.bOnlySpectator = true;
    NumSpectators++;
    NumPlayers--;

    return true;
}

function bool AllowBecomeActivePlayer(PlayerController P)
{
    if ( (P.PlayerReplicationInfo == None) || !GameReplicationInfo.bMatchHasBegun || bMustJoinBeforeStart
         || (NumPlayers >= MaxPlayers) || (MaxLives > 0) || P.IsInState('RoundEnded') )
    {
        P.ReceiveLocalizedMessage(GameMessageClass, 13);
        return false;
    }
    return true;
}

/** Reset() - reset actor to initial state - used when restarting level without reloading. */
function Reset()
{
    local Controller C;
    local int i;

    Super.Reset();

    bOverTimeBroadcast = false;

    // update AI
    FindNewObjectives(None);

    //now respawn all the players
    foreach WorldInfo.AllControllers(class'Controller', C)
    {
        if (C.PlayerReplicationInfo != None && !C.PlayerReplicationInfo.bOnlySpectator)
        {
            RestartPlayer(C);
        }
    }

    //reset timelimit
    GameReplicationInfo.RemainingTime = 60 * TimeLimit;
    // if the round lasted less than one minute, we won't be actually changing RemainingMinute
    // which will prevent it from being replicated, so in that case
    // reduce the time limit by one second to ensure that it is unique
    if ( GameReplicationInfo.RemainingTime == GameReplicationInfo.RemainingMinute )
    {
        GameReplicationInfo.RemainingTime--;
    }
    GameReplicationInfo.RemainingMinute = GameReplicationInfo.RemainingTime;

    // reset weapon taunts
    for ( i=0; i<20; i++ )
    {
        WeaponTauntUsed[i] = 0;
    }
}

function ObjectiveDisabled( UTGameObjective DisabledObjective );
/** re-evaluate objectives for players because the specified one has been changed/completed */
function FindNewObjectives(UTGameObjective DisabledObjective);

function bool CanDisableObjective( UTGameObjective GO )
{
    return true;
}

function NotifyNavigationChanged(NavigationPoint N)
{
    local UTBot B;

    // if a point becomes unblocked, force bots to repath in case it's faster than their current one
    if (!N.bBlocked)
    {
        foreach WorldInfo.AllControllers(class'UTBot', B)
        {
            B.bForceRefreshRoute = true;
        }
    }
}

function bool SkipPlaySound()
{
    return bQuickStart || bSkipPlaySound;
}

//
// Set gameplay speed.
//
function SetGameSpeed( Float T )
{
    local float UTTimeDilation;

    UTTimeDilation = bConsoleServer ? 1.0 : 1.1;
    GameSpeed = FMax(T, 0.1);
    WorldInfo.TimeDilation = UTTimeDilation * GameSpeed;
    SetTimer(WorldInfo.TimeDilation, true);
}

function BroadcastDeathMessage(Controller Killer, Controller Other, class<DamageType> DamageType)
{
    local UTBot B;

    if ( (Killer == Other) || (Killer == None) )
    {
        BroadcastLocalized(self,DeathMessageClass, 1, None, Other.PlayerReplicationInfo, DamageType);
    }
    else
    {
        BroadcastLocalized(self,DeathMessageClass, 0, Killer.PlayerReplicationInfo, Other.PlayerReplicationInfo, damageType);
        if ( PlayerController(Other) != None )
        {
            // maybe taunt him
            if ( ((UTPlayerController(Killer) == None) || UTPlayerController(Killer).bAutoTaunt)
                && (Other.PlayerReplicationInfo != None)
                && (UTPlayerReplicationInfo(Killer.PlayerReplicationInfo) != None)
                && (UTPlayerReplicationInfo(Killer.PlayerReplicationInfo).VoiceClass != None) )
            {
                    Killer.SendMessage(Other.PlayerReplicationInfo, 'TAUNT', 10, DamageType);
            }
        }
        else if ( bTeamGame && (NumBots > 0) )
        {
            if ( UTPlayerController(Killer) != None )
            {
                if ( (Other.PlayerReplicationInfo != None)
                    && (Killer.PlayerReplicationInfo != None) && (Killer.PlayerReplicationInfo.Team != None)
                    && (WorldInfo.TimeSeconds - LastEncouragementTime > 20)
                    && (FRand() < 0.6) )
                {
                    // maybe get encouragement from teammate
                    ForEach WorldInfo.AllControllers(class'UTBot', B)
                    {
                        if ( (B.PlayerReplicationInfo != None) && (B.PlayerReplicationInfo.Team == Killer.PlayerReplicationInfo.Team) && (FRand() < 0.33) )
                        {
                            B.SendMessage(Other.PlayerReplicationInfo, 'ENCOURAGEMENT', 0, DamageType);
                            break;
                        }
                    }
                }
            }
            else
            {
                B = UTBot(Other);
                if ( (B != None) && (FRand() < 0.2)
                    && (Other.PlayerReplicationInfo != None) && (Other.PlayerReplicationInfo.Team != None) )
                {
                    // was bot killed by a sniper?
                    if ( (class<UTDamageType>(DamageType) != None) && (class<UTDamageType>(DamageType).default.DamageWeaponClass == class'UTWeap_SniperRifle')
                        && (Killer.Pawn != None) && (UTWeap_SniperRifle(Killer.Pawn.Weapon) != None) && (VSizeSq(Killer.Pawn.Velocity) < 100.0) )
                    {
                        Sniper = Killer.Pawn;
                        B.SendMessage(None, 'SNIPER', 0, DamageType);
                        return;
                    }

                    // maybe tell human players I was killed
                    B.SendMessage(None, 'MANDOWN', 20, DamageType);
                }
            }
        }
    }
}

function ScoreKill(Controller Killer, Controller Other)
{
    local PlayerReplicationInfo OtherPRI;
    local UTPawn KillerPawn;
    local UTGameReplicationInfo GRI;

    OtherPRI = Other.PlayerReplicationInfo;
    if ( OtherPRI != None )
    {
        OtherPRI.NumLives++;
        if ( (MaxLives > 0) && (OtherPRI.NumLives >=MaxLives) )
            OtherPRI.bOutOfLives = true;
    }

    Super.ScoreKill(Killer,Other);

    if ( (killer == None) || (Other == None) )
        return;

    // adjust bot skills to match player - only for DM, not team games
    GRI = UTGameReplicationInfo(GameReplicationInfo);
    if ( GRI.bStoryMode && !bTeamGame && (killer.IsA('PlayerController') || Other.IsA('PlayerController')) )
    {
        if ( killer.IsA('AIController') )
            AdjustSkill(AIController(killer), PlayerController(Other), false);
        if ( Other.IsA('AIController') )
            AdjustSkill(AIController(Other), PlayerController(Killer), true);
    }

    KillerPawn = UTPawn(Killer.Pawn);
    if ( (KillerPawn != None) && KillerPawn.bKillsAffectHead )
    {
        KillerPawn.SetBigHead();
    }
}

function AdjustSkill(AIController B, PlayerController P, bool bWinner)
{
    local float AdjustmentFactor;

    AdjustmentFactor = FClamp(0.5/FMax(1.0,PlayerKills+PlayerDeaths), 0.1, 0.25);
    if ( bWinner )
    {
        PlayerKills += 1;
        AdjustedDifficulty = FMin(7.0,AdjustedDifficulty + AdjustmentFactor);
    }
    else
    {
        PlayerDeaths += 1;
        AdjustedDifficulty = FMax(0, AdjustedDifficulty - AdjustmentFactor);
    }
    AdjustedDifficulty = FClamp(AdjustedDifficulty, GameDifficulty - 1.25, GameDifficulty + 1.25);
    if ( bWinner == (B.Skill < AdjustedDifficulty) )
    {
        B.Skill = AdjustedDifficulty;
        UTBot(B).ResetSkill();
    }
}

// Monitor killed messages for fraglimit
function Killed( Controller Killer, Controller KilledPlayer, Pawn KilledPawn, class<DamageType> damageType )
{
    local bool      bEnemyKill;
    local UTPlayerReplicationInfo KillerPRI, KilledPRI;
    local UTVehicle V;

    if ( UTBot(KilledPlayer) != None )
        UTBot(KilledPlayer).WasKilledBy(Killer);

    if ( Killer != None )
        KillerPRI = UTPlayerReplicationInfo(Killer.PlayerReplicationInfo);
    if ( KilledPlayer != None )
        KilledPRI = UTPlayerReplicationInfo(KilledPlayer.PlayerReplicationInfo);

    bEnemyKill = ( ((KillerPRI != None) && (KillerPRI != KilledPRI) && (KilledPRI != None)) && (!bTeamGame || (KillerPRI.Team != KilledPRI.Team)) );

    if ( (KillerPRI != None) && UTVehicle(KilledPawn) != None )
    {
        KillerPRI.IncrementVehicleKillStat(UTVehicle(KilledPawn).GetVehicleKillStatName());
    }
    if ( KilledPRI != None )
    {
        KilledPRI.LastKillerPRI = KillerPRI;

        if ( class<UTDamageType>(DamageType) != None )
        {
            class<UTDamageType>(DamageType).static.ScoreKill(KillerPRI, KilledPRI, KilledPawn);
        }
        else
        {
            // assume it's some kind of environmental damage
            if ( KillerPRI == KilledPRI )
            {
                KilledPRI.IncrementSuicideStat('SUICIDES_ENVIRONMENT');
            }
            else
            {
                if ( KillerPRI != None )
                    KillerPRI.IncrementKillStat('KILLS_ENVIRONMENT');
                KilledPRI.IncrementDeathStat('DEATHS_ENVIRONMENT');
            }
        }
        if ( KilledPRI.Spree > 4 )
        {
            EndSpree(KillerPRI, KilledPRI);
        }
        else
        {
            KilledPRI.Spree = 0;
        }
        if ( KillerPRI != None )
        {
            KillerPRI.LogMultiKills(bEnemyKill);

            if ( !bFirstBlood && bEnemyKill )
            {
                bFirstBlood = True;
                BroadcastLocalizedMessage( class'UTFirstBloodMessage', 0, KillerPRI );
                KillerPRI.IncrementEventStat('EVENT_FIRSTBLOOD');
            }
            if ( KillerPRI != KilledPRI && (!bTeamGame || (KilledPRI.Team != KillerPRI.Team)) )
            {
                KillerPRI.IncrementSpree();
            }
        }
    }
    super.Killed(Killer, KilledPlayer, KilledPawn, damageType);

    if ( ((WorldInfo.NetMode == NM_Standalone) || (SinglePlayerMissionID != INDEX_NONE)) && (PlayerController(KilledPlayer) != None) )
    {
        // tell bots not to get into nearby vehicles
        for ( V=VehicleList; V!=None; V=V.NextVehicle )
            if ( WorldInfo.GRI.OnSameTeam(KilledPlayer,V) )
                V.PlayerStartTime = 0;
    }
}

/** ForceRespawn()
returns true if dead players should respawn immediately
*/
function bool ForceRespawn()
{
    return ( bForceRespawn || bTempForceRespawn || (MaxLives > 0) || (DefaultMaxLives > 0) );
}

// Parse options for this game...
event InitGame( string Options, out string ErrorMessage )
{
    local string InOpt;
    local int i;
    local name GameClassName;
    local bool bVoteOverride;

    // reset map cycle if we're just starting up
    if (WorldInfo.TimeSeconds == 0.0)
    {
        MapCycleIndex = INDEX_NONE;
        SaveConfig();
    }

    // make sure no bots got saved in the .ini as in use
    for (i = 0; i < ActiveBots.length; i++)
    {
        ActiveBots[i].bInUse = false;
    }

    Super.InitGame(Options, ErrorMessage);

    InOpt = ParseOption(Options, "ForceRespawn");
    if (InOpt != "")
    {
        bForceRespawn = bool(InOpt);
    }

    SetGameSpeed(GameSpeed);
    MaxLives = Max(0,GetIntOption( Options, "MaxLives", MaxLives ));
    if ( MaxLives > 0 )
    {
        bTempForceRespawn = true;
    }
    else if ( DefaultMaxLives > 0 )
    {
        bTempForceRespawn = true;
        MaxLives = DefaultMaxLives;
    }
    if( DefaultMaxLives > 0 )
    {
        TimeLimit = 0;
    }

    // Set goal score to end match... If automated testing, no score limit (end by timelimit only)
    GoalScore = (!bAutomatedPerfTesting) ? Max(0,GetIntOption( Options, "GoalScore", GoalScore )) : 0;

    if ( WorldInfo.IsConsoleBuild() )
    {
        LogInternal("CONSOLE SERVER");
        WorldInfo.bUseConsoleInput = true;
        bConsoleServer = true;
        PlayerControllerClass = ConsolePlayerControllerClass;
    }

    if( WorldInfo.IsConsoleBuild() )
    {
        bAllowKeyboardAndMouse = ( ParseOption( Options, "AllowKeyboard" ) ~= "1" );
        if( bAllowKeyboardAndMouse )
        {
            LogInternal("KeyboardAndMouse Enabled");
        }
    }

    InOpt = ParseOption( Options, "DemoMode");
    if ( InOpt != "" )
    {
        bDemoMode = bool(InOpt);
    }

    bAutoNumBots = (WorldInfo.NetMode == NM_Standalone);
    InOpt = ParseOption( Options, "bAutoNumBots");
    if ( InOpt != "" )
    {
        LogInternal("bAutoNumBots: "$bool(InOpt));
        bAutoNumBots = bool(InOpt);
    }

    if ( bTeamGame && (WorldInfo.NetMode != NM_Standalone) )
    {
        InOpt = ParseOption( Options, "VsBots");
        if ( InOpt != "" )
        {
            BotRatio = float(InOpt);
            bPlayersVsBots = (BotRatio > 0);
            LogInternal("bPlayersVsBots: "$bool(InOpt));
        }
        if ( bPlayersVsBots )
        {
            bAutoNumBots = false;
        }
    }

    InOpt = ParseOption( Options, "AutoContinueToNextRound");
    if( InOpt != "" )
    {
        LogInternal("AutoContinueToNextRound: "$bool(InOpt));
        bAutoContinueToNextRound = bool(InOpt);
    }

    if ( HasOption(Options, "NumPlay") )
        bAutoNumBots = false;

    DesiredPlayerCount = bAutoNumBots ? LevelRecommendedPlayers() : Clamp(GetIntOption( Options, "NumPlay", 1 ),1,32);

    InOpt = ParseOption( Options, "PlayersMustBeReady");
    if ( InOpt != "" )
    {
        LogInternal("PlayerMustBeReady: "$Bool(InOpt));
        bPlayersMustBeReady = bool(InOpt);
    }

    InOpt = ParseOption( Options, "MinNetPlayers");
    if (InOpt != "")
    {
        MinNetPlayers = int(InOpt);
        LogInternal("MinNetPlayers: "@MinNetPlayers);
    }

    bWaitForNetPlayers = ( WorldInfo.NetMode != NM_StandAlone );

    InOpt = ParseOption(Options,"QuickStart");
    if ( InOpt != "" )
    {
        bQuickStart = true;
    }
    // Quick start the match if passed in as option or automated testing
    bQuickStart = bQuickStart || bAutomatedPerfTesting;

    AdjustedDifficulty = GameDifficulty;

    if (WorldInfo.NetMode != NM_StandAlone)
    {
        InOpt = ParseOption( Options, "WarmupTime");
        if (InOpt != "")
        {
            WarmupTime = int(InOpt);
            WarmupRemaining = WarmupTime;
            bWarmupRound = (WarmupTime > 0);
        }
    }
    else
    {
        bWarmupRound = false;
    }

    InOpt = ParseOption(Options,"SPI");
    if ( InOpt != "" )
    {
        bPauseable = true;
        SinglePlayerMissionID = int(InOpt);

        InOpt = ParseOption(Options,"NecrisLocked");
        if ( InOpt != "" )
        {
            bNecrisLocked = bool(InOpt);
        }
        InOpt = ParseOption(Options,"CoolSpawn");
        if ( InOpt != "" )
        {
            bExtraHealth = bool(InOpt);
        }
        InOpt = ParseOption(Options,"HeavyArmor");
        if ( InOpt != "" )
        {
            bHeavyArmor = bool(InOpt);
        }
        NumDivertedOpponents = GetIntOption(Options, "diverted", 0);
    }
    else
    {
        SinglePlayerMissionID = INDEX_None;

        // No Custom chars not available when in campaign
        InOpt = ParseOption(Options,"NoCustomChars");

        if ( (InOpt != "") || WorldInfo.IsDemoBuild()  )
        {
            bNoCustomCharacters = true;
        }
    }

    DemoPrefix = ParseOption(Options,"demo");

    // Verify there are maps for map voting

    InOpt = ParseOption(Options,"Vote");
    if ( InOpt != "" && SinglePlayerMissionID == INDEX_None)
    {
        bAllowMapVoting = bool(InOpt);
    }

    InOpt = ParseOption(Options,"VoteDuration");
    if (InOpt != "")
    {
        VoteDuration = int(InOpt);
    }

    // No Map Vote in Instant Action
    if ( WorldInfo.NetMode == NM_StandAlone )
    {
        bAllowMapVoting = false;
    }

    if ( bAllowMapVoting )
    {
        // Default to false, and turn back to true if we have maps.
        bVoteOverride = true;
        GameClassName = class.name;
        for (i=0; i<default.GameSpecificMapCycles.Length; i++)
        {
            if (default.GameSpecificMapCycles[i].GameClassName == GameClassName)
            {
                if (default.GameSpecificMapCycles[i].Maps.Length > 1)
                {
                    bVoteOverride = false;
                    break;
                }
            }
        }

        if (bVoteOverride)
        {
            LogInternal("-- MAPVOTE has been disabled due to lack of maps!");
            bAllowMapVoting = false;
        }

        else
        {
            LogInternal("-- MAPVOTE is ENABLED!!!!!");
        }
    }
}

/**
 * Only allow local players to pause
 */
function bool SetPause(PlayerController PC, optional delegate<CanUnpause> CanUnpauseDelegate)
{
    local UTPlayerController OtherPC;

    if ( !PC.IsLocalPlayerController() )
    {
        return false;
    }

    //@hack: unfortunately the character construction process requires game tick so we can't be paused while
    // clients are doing it or they will appear to hang on the loading screen
    foreach WorldInfo.AllControllers(class'UTPlayerController', OtherPC)
    {
        if (!OtherPC.bInitialProcessingComplete)
        {
            return false;
        }
    }

    return Super.SetPause(PC, CanUnpauseDelegate);
}

function int LevelRecommendedPlayers()
{
    local UTMapInfo MapInfo;

    MapInfo = UTMapInfo(WorldInfo.GetMapInfo());
    return (MapInfo != None) ? Min(12, (MapInfo.RecommendedPlayersMax + MapInfo.RecommendedPlayersMin) / 2) : 1;
}

event PlayerController Login
(
    string Portal,
    string Options,
    out string ErrorMessage
)
{
    local PlayerController NewPlayer;
    local Controller C;

    if ( MaxLives > 0 )
    {
        // check that game isn't too far along
        foreach WorldInfo.AllControllers(class'Controller', C)
        {
            if ( (C.PlayerReplicationInfo != None) && (C.PlayerReplicationInfo.NumLives > LateEntryLives) )
            {
                Options = "?SpectatorOnly=1"$Options;
                break;
            }
        }
    }

    NewPlayer = Super.Login(Portal, Options, ErrorMessage);

    if ( UTPlayerController(NewPlayer) != None )
    {
        if ( bMustJoinBeforeStart && GameReplicationInfo.bMatchHasBegun )
            UTPlayerController(NewPlayer).bLatecomer = true;
    }

    return NewPlayer;
}

function bool ShouldRespawn(PickupFactory Other)
{
    return true;
}

function bool WantFastSpawnFor(AIController B)
{
    return ( NumBots < 4 );
}

function float SpawnWait(AIController B)
{
    if ( B.PlayerReplicationInfo.bOutOfLives )
        return 999;
    if ( (WorldInfo.NetMode == NM_Standalone) || (SinglePlayerMissionID != INDEX_NONE) )
    {
        if ( WantFastSpawnFor(B) )
            return 0;

        return (FMax(2,NumBots-4) * FRand());
    }
    return bPlayersVsBots ? 0.5 : FRand();
}

/**
 * Look at the current game rules and determine if there are too many bots.  In a single player
 * game, this function will always return false since the teams are preset and changes are not allowed.
 *
 * @Param BotToRemove       The Bot to remove
 */

function bool TooManyBots(Controller botToRemove)
{
    // We only auto-manage bots if we are not in single player mode.
    if ( SinglePlayerMissionID == INDEX_NONE )
    {
        if ( (WorldInfo.NetMode != NM_Standalone) && bPlayersVsBots )
            return ( NumBots > Min(16,BotRatio*NumPlayers) );
        if ( bPlayerBecameActive )
        {
            bPlayerBecameActive = false;
            return true;
        }
        return ( NumBots + NumPlayers > DesiredPlayerCount );
    }
    return false;
}

function RestartGame()
{

    if (bAllowMapVoting && VoteCollector != none && !VoteCollector.bVoteDecided)
    {
        VoteCollector.TimesUp();
    }

    if ( bGameRestarted )
        return;

    if ( EndTime > WorldInfo.TimeSeconds ) // still showing end screen
        return;



    Super.RestartGame();
}


function bool CheckEndGame(PlayerReplicationInfo Winner, string Reason)
{
    local Controller P;
    local bool bLastMan;

    if ( bOverTime )
    {
        if ( Numbots + NumPlayers == 0 )
            return true;
        bLastMan = true;
        foreach WorldInfo.AllControllers(class'Controller', P)
        {
            if ( (P.PlayerReplicationInfo != None) && !P.PlayerReplicationInfo.bOutOfLives )
            {
                bLastMan = false;
                break;
            }
        }
        if ( bLastMan )
        {
            return true;
        }
    }

    bLastMan = ( Reason ~= "LastMan" );

    if ( !bLastMan && CheckModifiedEndGame(Winner, Reason) )
        return false;

    if ( Winner == None )
    {
        // find winner
        foreach WorldInfo.AllControllers(class'Controller', P)
        {
            if ( P.bIsPlayer && !P.PlayerReplicationInfo.bOutOfLives
                && ((Winner == None) || (P.PlayerReplicationInfo.Score >= Winner.Score)) )
            {
                Winner = P.PlayerReplicationInfo;
            }
        }
    }

    // check for tie
    if ( !bLastMan )
    {
        foreach WorldInfo.AllControllers(class'Controller', P)
        {
            if ( P.bIsPlayer &&
                (Winner != P.PlayerReplicationInfo) &&
                (P.PlayerReplicationInfo.Score == Winner.Score)
                && !P.PlayerReplicationInfo.bOutOfLives )
            {
                if ( !bOverTimeBroadcast )
                {
                    StartupStage = 7;
                    PlayStartupMessage();
                    bOverTimeBroadcast = true;
                }
                return false;
            }
        }
    }

    EndTime = WorldInfo.TimeSeconds + EndTimeDelay;
    GameReplicationInfo.Winner = Winner;

    SetEndGameFocus(Winner);
    return true;
}

function SetEndGameFocus(PlayerReplicationInfo Winner)
{
    local Controller P;
    local Vehicle V;

    EndGameFocus = Controller(Winner.Owner).Pawn;
    if ( (EndGameFocus == None) && (Controller(Winner.Owner) != None) )
    {
        RestartPlayer(Controller(Winner.Owner));
        EndGameFocus = Controller(Winner.Owner).Pawn;
    }

    // redirect to owner if using remote controlled vehicle (e.g. Redeemer)
    V = Vehicle(EndGameFocus);
    if (V != None && !V.bAttachDriver && V.Driver != None)
    {
        EndGameFocus = V.Driver;
    }

    if ( EndGameFocus != None )
    {
        EndGameFocus.bAlwaysRelevant = true;
    }
    foreach WorldInfo.AllControllers(class'Controller', P)
    {
        P.GameHasEnded(EndGameFocus, (P.PlayerReplicationInfo != None) && (P.PlayerReplicationInfo == Winner) );
    }
}

function bool AtCapacity(bool bSpectator)
{
    local Controller C;
    local bool bForcedSpectator;

    if ( WorldInfo.NetMode == NM_Standalone )
        return false;

    if ( bPlayersVsBots )
        MaxPlayers = Min(MaxPlayers,16);

    if ( MaxLives <= 0 )
        return Super.AtCapacity(bSpectator);

    foreach WorldInfo.AllControllers(class'Controller', C)
    {
        if ( (C.PlayerReplicationInfo != None) && (C.PlayerReplicationInfo.NumLives > LateEntryLives) )
        {
            bForcedSpectator = true;
            break;
        }
    }
    if ( !bForcedSpectator )
        return Super.AtCapacity(bSpectator);

    return ( GetNumPlayers() + NumSpectators >= MaxPlayers + MaxSpectators );
}

event PostLogin( playercontroller NewPlayer )
{
    local UTPlayerController PC;
    local UTGameReplicationInfo GRI;

    Super.PostLogin(NewPlayer);

    PC = UTPlayerController(NewPlayer);
    if (PC != None)
    {
        PC.PlayStartUpMessage(StartupStage);
        PC.ClientSetSpeechRecognitionObject(SpeechRecognitionData);

        GRI = UTGameReplicationInfo(GameReplicationInfo);
        if ( bForceMidGameMenuAtStart && !GRI.bStoryMode && !GRI.bMatchHasBegun && (NetWait - PendingMatchElapsedTime > 5) )
        {
            UTPlayerReplicationInfo(PC.PlayerReplicationInfo).ShowMidGameMenu(true);
        }

        if ( NumPlayers > 1 && SinglePlayerMissionID != INDEX_None )
        {
            SkipCinematics(PC);
        }
    }

    //@hack: unfortunately the character construction process requires game tick so we can't be paused while
    // clients are doing it or they will appear to hang on the loading screen
    Pausers.length = 0;
    WorldInfo.Pauser = None;
}

/**
 * Updates the online subsystem's information for player counts so that
 * LAN matches can show the correct player counts
 */
function UpdateGameSettingsCounts()
{
    local int TotalOpenConnections, TotalConnections;
    if (GameSettings != None)
    {
        // Make sure that we don't exceed our max allowing player counts for this game type!  Usually this is 32.
        GameSettings.NumPublicConnections = Clamp( GameSettings.NumPublicConnections, 0, MaxPlayers );
        GameSettings.NumPrivateConnections = Clamp( GameSettings.NumPrivateConnections, 0, MaxPlayers - GameSettings.NumPublicConnections );

        // Update the number of open slots available
        GameSettings.NumOpenPublicConnections = GameSettings.NumPublicConnections - GetNumPlayers();
        if (GameSettings.NumOpenPublicConnections < 0)
        {
            GameSettings.NumOpenPublicConnections = 0;
        }

        TotalOpenConnections = GameSettings.NumOpenPublicConnections + GameSettings.NumOpenPrivateConnections;
        TotalConnections = GameSettings.NumPublicConnections + GameSettings.NumPrivateConnections;

        GameSettings.SetStringSettingValue(class'UTGameSearchCommon'.const.CONTEXT_FULLSERVER,
            TotalOpenConnections == 0 ? class'UTGameSearchCommon'.const.CONTEXT_FULLSERVER_YES : class'UTGameSearchCommon'.const.CONTEXT_FULLSERVER_NO, false);
        GameSettings.SetStringSettingValue(class'UTGameSearchCommon'.const.CONTEXT_EMPTYSERVER,
            TotalOpenConnections == TotalConnections ? class'UTGameSearchCommon'.const.CONTEXT_EMPTYSERVER_YES : class'UTGameSearchCommon'.const.CONTEXT_EMPTYSERVER_NO, false);

        OnlineSub.GameInterface.UpdateOnlineGame(GameSettings);
    }
}

function AssignHoverboard(UTPawn P)
{
    if ( P != None )
        P.bHasHoverboard = bAllowHoverboard;
}

/** return a value based on how much this pawn needs help */
function int GetHandicapNeed(Pawn Other)
{
    return 0;
}

function RestartPlayer(Controller aPlayer)
{
    local UTVehicle V, Best;
    local vector ViewDir;
    local float BestDist, Dist;
    local UTPlayerController PC;

    PC = UTPlayerController(aPlayer);
    if (PC != None)
    {
        // can't respawn if still doing initial processing (loading characters, etc)
        if (!PC.bInitialProcessingComplete )
        {
            return;
        }

        // can't respawn if you have to join before the game starts and this player didn't
        if (bMustJoinBeforeStart && PC != None && PC.bLatecomer)
        {
            return;
        }
    }

    // can't respawn if out of lives
    if ( aPlayer.PlayerReplicationInfo.bOutOfLives )
    {
        return;
    }

    if ( UTBot(aPlayer) != None )
    {
        if ( TooManyBots(aPlayer) )
        {
            aPlayer.Destroy();
            return;
        }
        else if ( UTGameReplicationInfo(GameReplicationInfo).bStoryMode )
        {
            CampaignSkillAdjust(UTBot(aPlayer));
        }
    }

    Super.RestartPlayer(aPlayer);

    if ( aPlayer.Pawn == None )
    {
        // pawn spawn failed
        return;
    }
    if ( bExtraHealth
        && (aPlayer.PlayerReplicationInfo.Team != None) && (aPlayer.PlayerReplicationInfo.Team.TeamIndex == 0) )
    {
        aPlayer.Pawn.Health = 140;
    }

    AssignHoverboard(UTPawn(aPlayer.Pawn));

    if ( ((WorldInfo.NetMode == NM_Standalone) || (SinglePlayerMissionID != INDEX_NONE)) && (PlayerController(aPlayer) != None) )
    {
        // tell bots not to get into nearby vehicles for a little while
        BestDist = 2000;
        ViewDir = vector(aPlayer.Pawn.Rotation);
        for ( V=VehicleList; V!=None; V=V.NextVehicle )
        {
            if ( !bTeamGame && V.bTeamLocked )
            {
                V.bTeamLocked = false;
            }
            if ( V.bTeamLocked && WorldInfo.GRI.OnSameTeam(aPlayer,V) )
            {
                Dist = VSize(V.Location - aPlayer.Pawn.Location);
                if ( (ViewDir Dot (V.Location - aPlayer.Pawn.Location)) < 0 )
                    Dist *= 2;
                if ( Dist < BestDist )
                {
                    Best = V;
                    BestDist = Dist;
                }
            }
        }
        if ( Best != None )
            Best.PlayerStartTime = WorldInfo.TimeSeconds + 8;
    }


    // Make sure VOIP state for this player is updated.  They may have just entered the game after spectating
    // for awhile post-connection.
    if( PC != None )
    {
        SetupPlayerMuteList( PC, false );       // Force spectator channel?
    }
}

/**
  * Called to adjust skill when bot respawns
  */
function CampaignSkillAdjust(UTBot aBot)
{
    aBot.Skill = AdjustedDifficulty;
}

function AddDefaultInventory( pawn PlayerPawn )
{
    local int i;

    for (i=0; i<DefaultInventory.Length; i++)
    {
        // Ensure we don't give duplicate items
        if (PlayerPawn.FindInventoryType( DefaultInventory[i] ) == None)
        {
            // Only activate the first weapon
            PlayerPawn.CreateInventory(DefaultInventory[i], (i > 0));
        }
    }

    PlayerPawn.AddDefaultInventory();
}

function bool CanSpectate( PlayerController Viewer, PlayerReplicationInfo ViewTarget )
{
    return ( (ViewTarget != None) && ((WorldInfo.NetMode == NM_Standalone) || Viewer.PlayerReplicationInfo.bOnlySpectator) );
}

function ChangeName(Controller Other, string S, bool bNameChange)
{
    local Controller APlayer;

    if ( Other.PlayerReplicationInfo.playername~=S )
    {
        return;
    }

    // Cap player name's at 15 characters...
    if (Len(s)>15)
    {
        s = Left(S,15);
    }

    foreach WorldInfo.AllControllers(class'Controller', APlayer)
    {
        if (APlayer.bIsPlayer && APlayer.PlayerReplicationInfo.playername ~= S)
        {
            if ( PlayerController(Other) != None )
            {
                    PlayerController(Other).ReceiveLocalizedMessage( GameMessageClass, 8 );
                    if ( Other.PlayerReplicationInfo.PlayerName ~= DefaultPlayerName )
                    {
                        Other.PlayerReplicationInfo.SetPlayerName(DefaultPlayerName$Other.PlayerReplicationInfo.PlayerID);
                    }
                return;
            }
        }
    }

    Other.PlayerReplicationInfo.SetPlayerName(S);
}

function SetAlias(Controller Other, string NewAlias)
{
    local Controller APlayer;

    if ( Other.PlayerReplicationInfo.GetPlayerAlias() ~= NewAlias )
    {
        return;
    }

    // Cap player name's at 15 characters...
    if (Len(NewAlias)>15)
    {
        NewAlias = Left(NewAlias,15);
    }

    foreach WorldInfo.AllControllers(class'Controller', APlayer)
    {
        if (APlayer.bIsPlayer && APlayer.PlayerReplicationInfo.GetPlayerAlias() ~= NewAlias)
        {
            if ( PlayerController(Other) != None )
            {
                    PlayerController(Other).ReceiveLocalizedMessage( GameMessageClass, 8 );
                return;
            }
        }
    }

    Other.PlayerReplicationInfo.SetPlayerAlias(NewAlias);
}


function DiscardInventory( Pawn Other, optional controller Killer )
{
    if (UTPlayerReplicationInfo(Other.PlayerReplicationInfo) != None && Other.PlayerReplicationInfo.bHasFlag)
    {
        UTPlayerReplicationInfo(Other.PlayerReplicationInfo).GetFlag().Drop(Killer);
    }
    else if ( Other.DrivenVehicle != None && UTPlayerReplicationInfo(Other.DrivenVehicle.PlayerReplicationInfo) != None
        && Other.DrivenVehicle.PlayerReplicationInfo.bHasFlag )
    {
        UTPlayerReplicationInfo(Other.DrivenVehicle.PlayerReplicationInfo).GetFlag().Drop(Killer);
    }

    Super.DiscardInventory(Other);
}

function Logout(controller Exiting)
{
    local int i, CharIndex;
    local UTPlayerReplicationInfo PRI;
    local byte TeamNum;
    local UTPlayerController ExitingPC;

    PRI = UTPlayerReplicationInfo(Exiting.PlayerReplicationInfo);
    if ( PRI.bHasFlag )
    {
        PRI.GetFlag().Drop();
    }

    CharIndex = PRI.SinglePlayerCharacterIndex;
    TeamNum = PRI.GetTeamNum();


    // Remove from all mute lists so they can rejoin properly
    ExitingPC = UTPlayerController( Exiting );
    if( ExitingPC != None )
    {
        RemovePlayerFromMuteLists( ExitingPC );
    }


    Super.Logout(Exiting);

    if (Exiting.IsA('UTBot') && !UTBot(Exiting).bSpawnedByKismet)
    {
        i = ActiveBots.Find('BotName', Exiting.PlayerReplicationInfo.PlayerName);
        if (i != INDEX_NONE)
        {
            ActiveBots[i].bInUse = false;
        }
        NumBots--;
    }

    if (SinglePlayerMissionID != INDEX_NONE)
    {
        if (CharIndex != INDEX_NONE && !Exiting.IsA('UTBot'))
        {
            AddBot(UTGameReplicationInfo(GameReplicationInfo).SinglePlayerBotNames[CharIndex], TeamNum != 255, TeamNum);
        }
    }
    else if ( NeedPlayers() )
    {
        AddBot();
    }

    if (MaxLives > 0)
    {
        CheckMaxLives(None);
    }

    //VotingHandler.PlayerExit(Exiting);
}

exec function KillBots()
{
    local UTBot B;

    DesiredPlayerCount = NumPlayers;
    bPlayersVsBots = false;

    foreach WorldInfo.AllControllers(class'UTBot', B)
    {
        KillBot(B);
        }
    }

function KillBot(UTBot B)
{
    if ( B == None )
        return;

    if ( (Vehicle(B.Pawn) != None) && (Vehicle(B.Pawn).Driver != None) )
        Vehicle(B.Pawn).Driver.KilledBy(Vehicle(B.Pawn).Driver);
    else if (B.Pawn != None)
        B.Pawn.KilledBy( B.Pawn );
    if (B != None)
        B.Destroy();
}

function bool NeedPlayers()
{
    if ( bMustJoinBeforeStart )
    {
        return false;
    }
    else if ( bPlayersVsBots )
    {
        return (NumBots < Min(16, BotRatio * NumPlayers));
    }
    else if (SinglePlayerMissionID != INDEX_NONE)
    {
        return (GetNumPlayers() + NumBots < DesiredPlayerCount);
    }
    else
    {
        return (NumPlayers + NumBots < DesiredPlayerCount);
    }
}

exec function AddBots(int Num)
{
    local int AddCount;

    DesiredPlayerCount = Clamp(Max(DesiredPlayerCount, NumPlayers+NumBots)+Num, 1, 32);

    // add up to 8 immediately, then the rest automatically via game timer.
    while ( (NumPlayers + NumBots < DesiredPlayerCount) && (AddBot() != none) && (AddCount < 8) )
    {
        LogInternal("added bot");
        AddCount++;
    }
}

exec function UTBot AddNamedBot(string BotName, optional bool bUseTeamIndex, optional int TeamIndex)
{
    DesiredPlayerCount = Clamp(Max(DesiredPlayerCount, NumPlayers + NumBots) + 1, 1, 32);
    return AddBot(BotName, bUseTeamIndex, TeamIndex);
}

function UTBot AddBot(optional string BotName, optional bool bUseTeamIndex, optional int TeamIndex)
{
    local UTBot NewBot;
    local int i;

    if (BotName == "")
    {
        i = ActiveBots.Find('bInUse', false);
        if (i != INDEX_NONE)
        {
            BotName = ActiveBots[i].BotName;
            ActiveBots[i].bInUse = true;
        }
    }
    else
    {
        i = ActiveBots.Find('BotName', BotName);
        if (i != INDEX_NONE)
        {
            ActiveBots[i].bInUse = true;
        }
    }

    NewBot = SpawnBot(BotName, bUseTeamIndex, TeamIndex);
    if ( NewBot == None )
    {
        WarnInternal("Failed to spawn bot.");
        return none;
    }
    NewBot.PlayerReplicationInfo.PlayerID = CurrentID++;
    NumBots++;
    if ( WorldInfo.NetMode == NM_Standalone )
    {
        RestartPlayer(NewBot);
    }
    else
    {
        NewBot.GotoState('Dead','MPStart');
    }

    return NewBot;
}

/* Spawn and initialize a bot
*/
function UTBot SpawnBot(optional string botName,optional bool bUseTeamIndex, optional int TeamIndex)
{
    local UTBot NewBot;
    local UTTeamInfo BotTeam;
    local CharacterInfo BotInfo;

    BotTeam = GetBotTeam(,bUseTeamIndex,TeamIndex);
    BotInfo = BotTeam.GetBotInfo(botName);

    NewBot = Spawn(BotClass);

    if ( NewBot != None )
    {
        if (SinglePlayerMissionID != INDEX_NONE && BotName != "" && BotName != BotInfo.CharName)
        {
            WarnInternal("Single player bot" @ BotName @ "could not be found (bad spelling?)");
            bBadSinglePlayerBotNames = true;
        }
        InitializeBot(NewBot, BotTeam, BotInfo);

        if (BaseMutator != None)
        {
            BaseMutator.NotifyLogin(NewBot);
        }
    }

    return NewBot;
}

/* Initialize bot
*/
function InitializeBot(UTBot NewBot, UTTeamInfo BotTeam, const out CharacterInfo BotInfo)
{
    NewBot.Initialize(AdjustedDifficulty, BotInfo);
    BotTeam.AddToTeam(NewBot);
    ChangeName(NewBot, BotInfo.CharName, false);
    BotTeam.SetBotOrders(NewBot);
}

function UTTeamInfo GetBotTeam(optional int TeamBots,optional bool bUseTeamIndex,optional int TeamIndex)
{
    local class<UTTeamInfo> RosterClass;

    if ( EnemyRoster != None )
    {
        return EnemyRoster;
    }
    if ( EnemyRosterName != "" )
    {
        RosterClass = class<UTTeamInfo>(DynamicLoadObject(EnemyRosterName,class'Class'));
        if ( RosterClass != None)
            EnemyRoster = spawn(RosterClass);
    }
    if ( EnemyRoster == None )
    {
        RosterClass = class<UTTeamInfo>(DynamicLoadObject(DefaultEnemyRosterClass,class'Class'));
        if ( RosterClass != None)
        {
            EnemyRoster = spawn(RosterClass);
        }
    }
    EnemyRoster.Initialize(TeamIndex);
    return EnemyRoster;
}

function InitGameReplicationInfo()
{
    local UTGameReplicationInfo GRI;
    local UTMutator M;
    local UTGameUISceneClient SC;

    Super.InitGameReplicationInfo();

    GRI = UTGameReplicationInfo(GameReplicationInfo);
    GRI.GoalScore = GoalScore;
    GRI.TimeLimit = TimeLimit;
    GameReplicationInfo.RemainingTime = 60 * TimeLimit;
    GRI.MinNetPlayers = MinNetPlayers;
    GRI.bConsoleServer = (WorldInfo.bUseConsoleInput || WorldInfo.IsConsoleBuild());
    GRI.bAllowKeyboardAndMouse = bAllowKeyboardAndMouse;

    GRI.bRequireReady = bPlayersMustBeReady;

    // Flag the match if in story mode
    GRI.bStoryMode = SinglePlayerMissionID > INDEX_NONE;
    GRI.SinglePlayerMissionID = SinglePlayerMissionID;

    if ( SinglePlayerMissionID > INDEX_NONE )
    {
        SC = UTGameUISceneClient(class'UIRoot'.static.GetSceneClient());
        if ( SC != none )
        {
            GRI.MessageOfTheDay = SC.MissionText;
        }
    }

    if ( !bForceRespawn && !GRI.bStoryMode )
    {
        GRI.bSHowMOTD = true;
    }

    // Create the list of mutators.

    M = GetBaseUTMutator();
    while (M != none )
    {
        GRI.MutatorList $= GRI.MutatorList == "" ? Pathname(M.Class) : ("?"$Pathname(M.Class));
        M = M.GetNextUTMutator();
    }

    GRI.RulesString = "";
    GRI.AddGameRule(GetMapTypeRule());
    GRI.AddGameRule(GetEndGameConditionRule());
    GRI.AddGameRule(" ");
}

function string GetMapTypeRule()
{
    return GameName@"<Strings:UTGameUI.Generic.On>"@WorldInfo.GetMapName();
}


function string GetEndGameConditionRule()
{
    return GetEndOfMatchRules(GoalScore, TimeLimit);
}

function ReduceDamage( out int Damage, pawn injured, Controller instigatedBy, vector HitLocation, out vector Momentum, class<DamageType> DamageType )
{
    local float InstigatorSkill;
    local UTVehicle V;

    if ( InstigatedBy != None )
    {
        if ( InstigatedBy != Injured.Controller )
        {
            if (WorldInfo.TimeSeconds - injured.SpawnTime < SpawnProtectionTime && !DamageType.default.bCausedByWorld)
            {
                Damage = 0;
                return;
            }

            V = UTVehicle(Injured);
            if (V != None && !V.bHasBeenDriven && !bUndrivenVehicleDamage)
            {
                Damage = 0;
                Super.ReduceDamage(Damage, Injured, InstigatedBy, HitLocation, Momentum, DamageType);
                return;
            }
        }
        else if ( (DamageType != None) && DamageType.Default.bDontHurtInstigator )
        {
            Damage = 0;
            return;
        }
    }

    Super.ReduceDamage( Damage, injured, InstigatedBy, HitLocation, Momentum, DamageType );

    if ( instigatedBy == None )
        return;

    if ( WorldInfo.Game.GameDifficulty < 4.5 )
    {
        if ( (WorldInfo.Game.GameDifficulty < 4) && injured.IsPlayerPawn() && (injured.Controller == instigatedby) && ((WorldInfo.NetMode == NM_Standalone) || (SinglePlayerMissionID != INDEX_NONE)) )
            Damage *= 0.5;

        //skill level modification
        if ( (AIController(instigatedBy) != None) && ((WorldInfo.NetMode == NM_Standalone) || (SinglePlayerMissionID != INDEX_NONE)) )
        {
            InstigatorSkill = AIController(instigatedBy).Skill;
            if ( (InstigatorSkill < 4.5) && injured.IsHumanControlled() )
                {
                    if ( ((instigatedBy.Pawn != None) && (instigatedBy.Pawn.Weapon != None) && instigatedBy.Pawn.Weapon.bMeleeWeapon)
                        || ((injured.Weapon != None) && injured.Weapon.bMeleeWeapon && (VSize(injured.location - instigatedBy.Pawn.Location) < 600)) )
                            Damage = Damage * (0.64 + 0.08 * InstigatorSkill);
                    else
                            Damage = Damage * (0.25 + 0.15 * InstigatorSkill);
            }
        }
    }
    if ( InstigatedBy.Pawn != None )
    {
        Damage = Damage * instigatedBy.Pawn.GetDamageScaling();
    }
}

function NotifySpree(UTPlayerReplicationInfo Other, int num)
{
    local PlayerController PC;

    if (num % 5 != 0 || num == 0 || num > 30)
    {
        return;
    }
    num = (num/5) - 1;

    Other.IncrementEventStat(class'UTLeaderboardWriteDM'.Default.SPREE[num]);
    foreach WorldInfo.AllControllers(class'PlayerController', PC)
    {
        PC.ReceiveLocalizedMessage( class'UTKillingSpreeMessage', Num, Other );
    }
    if ( (UTPlayerController(Other.Owner) == None) || UTPlayerController(Other.Owner).bAutoTaunt )
    {
        Controller(Other.Owner).SendMessage(None, 'TAUNT', 10, None);
    }
}

function EndSpree(UTPlayerReplicationInfo Killer, UTPlayerReplicationInfo Other)
{
    local PlayerController PC;

    if ( Other == None )
        return;

    Other.Spree = 0;
    if ( Killer != None )
    {
        Killer.IncrementEventStat('EVENT_ENDSPREE');
    }

    foreach WorldInfo.AllControllers(class'PlayerController', PC)
    {
        if ( (Killer == Other) || (Killer == None) )
        {
            PC.ReceiveLocalizedMessage( class'UTKillingSpreeMessage', 1, None, Other );
        }
        else
        {
            PC.ReceiveLocalizedMessage( class'UTKillingSpreeMessage', 0, Other, Killer );
        }
    }
}


//------------------------------------------------------------------------------
// Game States


/**
 * This is called once the client has sent the server their unique net id.
 * It is now possible to set up their mute list.
 *
 * @param PC the playercontroller that is ready for updates
 */
function UpdateGameplayMuteList( PlayerController PC )
{
    local UTPlayerController UTPC;

    UTPC = UTPlayerController( PC );
    if( UTPC != None )
    {
        SetupPlayerMuteList( UTPC, false );  // Force spectator channel?
    }
}



/**
 * Sets up the voice mute list based upon this player's team/spectator state. Opponents are
 * added the specified player's mute list and vice versa.
 *
 * @param PC the player controller to initialize muting for
 */
function SetupPlayerMuteList( UTPlayerController PC, bool bForceSpectatorChannel )
{
    local TeamInfo MyTeam;
    local int MyVoiceChannel;
    local TeamInfo OtherTeam;
    local UTPlayerController OtherPC;
    local int OtherVoiceChannel;
    local UniqueNetId ZeroUniqueNetId;

    // Make sure we have a valid unique online ID.  If we don't, then one of the following is true:
    //    * Player isn't signed into an online profile (we don't support voice chat unless you're signed in online.)
    //    * Player doesn't have a unique online ID (maybe it's an AI or something?)
    //    * Player's unique online ID isn't available to the server yet
    if (PC.PlayerReplicationInfo != None && PC.PlayerReplicationInfo.UniqueId != ZeroUniqueNetId)
    {
        // `log( "VOIP| SetupPlayerMuteList:  For player [" @ PC.PlayerReplicationInfo.PlayerName @ " : " @ PC.PlayerReplicationInfo.UniqueId.Uid[0]@PC.PlayerReplicationInfo.UniqueId.Uid[1]@PC.PlayerReplicationInfo.UniqueId.Uid[2]@PC.PlayerReplicationInfo.UniqueId.Uid[3]@PC.PlayerReplicationInfo.UniqueId.Uid[4]@PC.PlayerReplicationInfo.UniqueId.Uid[5]@PC.PlayerReplicationInfo.UniqueId.Uid[6]@PC.PlayerReplicationInfo.UniqueId.Uid[7] @ "]  Force spectator [" @ bForceSpectatorChannel @ "]" );

        // Start off in the spectator channel
        MyTeam = PC.PlayerReplicationInfo.Team;
        MyVoiceChannel = VC_Spectators;
        if( !bForceSpectatorChannel && !PC.PlayerReplicationInfo.bIsSpectator )
        {
            // OK, we're not a spectator and we were not asked to be forced into that channel
            MyVoiceChannel = VC_Team1;
            if( !bIgnoreTeamForVoiceChat && MyTeam != None && MyTeam.TeamIndex > 0 && PC.PlayerReplicationInfo.TeamID != 255 )
            {
                // We're on team 2 and we were asked to respect the team settings
                MyVoiceChannel = VC_Team2;
            }
        }

        // `log( "VOIP|                           My voice channel [" @ MyVoiceChannel @ "]  Spectator [" @ PC.PlayerReplicationInfo.bIsSpectator @ "]" );

        // Check all players
        foreach WorldInfo.AllControllers( class'UTPlayerController', OtherPC )
        {
            if (OtherPC != PC && OtherPC.PlayerReplicationInfo != None)
            {
                // Make sure the other player has a valid online ID.
                if( OtherPC.PlayerReplicationInfo.UniqueId != ZeroUniqueNetId )
                {
                    // Start the other player off in the spectator channel
                    OtherVoiceChannel = VC_Spectators;
                    if( !bForceSpectatorChannel && !OtherPC.PlayerReplicationInfo.bIsSpectator )
                    {
                        // Other player isn't a spectator, so assume team 1 first
                        OtherVoiceChannel = VC_Team1;
                        OtherTeam = OtherPC.PlayerReplicationInfo.Team;
                        if( !bIgnoreTeamForVoiceChat && OtherTeam != None && OtherTeam.TeamIndex > 0 && OtherPC.PlayerReplicationInfo.TeamID != 255 )
                        {
                            // Other player is on a team and it's team 2, and we were asked to respect that
                            OtherVoiceChannel = VC_Team2;
                        }
                    }

                    // If not on the same team and not in the list already, mute
                    if( OtherVoiceChannel != MyVoiceChannel )
                    {
                        // `log( "VOIP|                           Cannot hear [" @ OtherPC.PlayerReplicationInfo.PlayerName @ " : " @ OtherPC.PlayerReplicationInfo.UniqueId.Uid[0]@OtherPC.PlayerReplicationInfo.UniqueId.Uid[1]@OtherPC.PlayerReplicationInfo.UniqueId.Uid[2]@OtherPC.PlayerReplicationInfo.UniqueId.Uid[3]@OtherPC.PlayerReplicationInfo.UniqueId.Uid[4]@OtherPC.PlayerReplicationInfo.UniqueId.Uid[5]@OtherPC.PlayerReplicationInfo.UniqueId.Uid[6]@OtherPC.PlayerReplicationInfo.UniqueId.Uid[7] @ "]  Voice channel [" @ OtherVoiceChannel @ "]  Spectator [" @ OtherPC.PlayerReplicationInfo.bIsSpectator @ "]" );

                        PC.GameplayMutePlayer( OtherPC.PlayerReplicationInfo.UniqueId );
                        OtherPC.GameplayMutePlayer( PC.PlayerReplicationInfo.UniqueId );
                    }
                    else
                    {
                        // `log( "VOIP|                           Can hear [" @ OtherPC.PlayerReplicationInfo.PlayerName @ " : " @ OtherPC.PlayerReplicationInfo.UniqueId.Uid[0]@OtherPC.PlayerReplicationInfo.UniqueId.Uid[1]@OtherPC.PlayerReplicationInfo.UniqueId.Uid[2]@OtherPC.PlayerReplicationInfo.UniqueId.Uid[3]@OtherPC.PlayerReplicationInfo.UniqueId.Uid[4]@OtherPC.PlayerReplicationInfo.UniqueId.Uid[5]@OtherPC.PlayerReplicationInfo.UniqueId.Uid[6]@OtherPC.PlayerReplicationInfo.UniqueId.Uid[7] @ "]  Voice channel [" @ OtherVoiceChannel @ "]  Spectator [" @ OtherPC.PlayerReplicationInfo.bIsSpectator @ "]" );

                        PC.GameplayUnmutePlayer( OtherPC.PlayerReplicationInfo.UniqueId );
                        OtherPC.GameplayUnmutePlayer( PC.PlayerReplicationInfo.UniqueId );
                    }
                }
                else
                {
                    // `log( "VOIP|                           Skipping [" @ OtherPC.PlayerReplicationInfo.PlayerName @ "], player doesn't have a UniqueNetId." );
                }
            }
        }
    }
    else
    {
        // `log( "VOIP| SetupPlayerMuteList:  Player [" @ PC.PlayerReplicationInfo.PlayerName @ "] doesn't have a UniqueNetId.  Nothing to do." );
    }
}



/**
 * Removes the specified player from all other player's mute lists
 *
 * @param PC Player controller to remove from other mute lists
 */
function RemovePlayerFromMuteLists( UTPlayerController PC )
{
    local UTPlayerController CurPC;

    if( PC != None )
    {
        foreach WorldInfo.AllControllers( class'UTPlayerController', CurPC )
        {
            if( CurPC != PC )
            {
                CurPC.GameplayUnmutePlayer( PC.PlayerReplicationInfo.UniqueId );
            }
        }
    }
}


/**
 * Reset everyone's channel to the same thing and then rebuild the gameplay
 * mute lists for each player
 */
function ResetAllPlayerMuteListsToSpectatorChannel()
{
    local UTPlayerController PC;

    // Allow everyone to hear each other
    foreach WorldInfo.AllControllers( class'UTPlayerController', PC )
    {
        // Clear the gameplay mute list so everyone can talk to each other while traveling
        SetupPlayerMuteList( PC, true );    // Force spectator channel?
    }
}



function StartMatch()
{
    local bool bTemp;
    local UTPlayerController PC;

    GotoState('MatchInProgress');

    GameReplicationInfo.RemainingMinute = GameReplicationInfo.RemainingTime;
    Super.StartMatch();

    bTemp = bMustJoinBeforeStart;
    bMustJoinBeforeStart = false;

    AddInitialBots();

    bMustJoinBeforeStart = bTemp;

    LogInternal("START MATCH");


    // Setup team VOIP mute lists
    foreach WorldInfo.AllControllers( class'UTPlayerController', PC )
    {
        SetupPlayerMuteList( PC, false );   // Force spectator channel?
    }


    // we had to wait for the constructioning and the commandline causeevent for the flythrough was lost
    // so we need to fire off another one once we know that we are in the match and meshes have been constructioned!
    if( bDoingAFlyThrough == TRUE )
    {
        foreach WorldInfo.AllControllers(class'UTPlayerController', PC)
        {
            PC.ConsoleCommand( "ce FlyThrough" );
            break;
        }
    }

    foreach WorldInfo.AllControllers(class'UTPlayerController', PC)
    {
        PC.IncrementNumberOfMatchesPlayed();
        break;
    }

    if( bCheckingForFragmentation == TRUE )
    {
        //ConsoleCommand( "killparticles" );
        ConsoleCommand( "MemFragCheck" );
    }
    if( bCheckingForMemLeaks == TRUE )
    {
        //ConsoleCommand( "MemLeakCheck" );
        ConsoleCommand( "MEMTAG_UPDATE" );
    }

    if( BugLocString != "" || BugRotString != "" )
    {
        if( PC.CheatManager != none )
        {
            //`log( "BugLocString:" @ BugLocString );
            //`log( "BugRotString:" @ BugRotString );

            PC.CheatManager.BugItGoString( BugLocString, BugRotString );
        }
    }

    //SetTimer( 10.0f, TRUE, 'TrackMemoryFunctor');
}

/** This is our TrackMemory functor where we can put anything we want to do every N seconds. **/
function TrackMemoryFunctor()
{
    ConsoleCommand( "DUMPALLOCS -AlphaSort" );
}


function EndGame(PlayerReplicationInfo Winner, string Reason )
{
    local Sequence GameSequence;
    local array<SequenceObject> Events;
    local int i;

    if ( (Reason ~= "triggered") ||
     (Reason ~= "LastMan")   ||
     (Reason ~= "TimeLimit") ||
     (Reason ~= "FragLimit") ||
     (Reason ~= "TeamScoreLimit") )
    {
        Super.EndGame(Winner,Reason);
        if ( bGameEnded )
        {
            // trigger any Kismet "Game Ended" events
            GameSequence = WorldInfo.GetGameSequence();
            if (GameSequence != None)
            {
                GameSequence.FindSeqObjectsByClass(class'UTSeqEvent_GameEnded', true, Events);
                for (i = 0; i < Events.length; i++)
                {
                    UTSeqEvent_GameEnded(Events[i]).CheckActivate(self, None);
                }
            }

            GotoState('MatchOver');
        }
    }
}

/** FindPlayerStart()
* Return the 'best' player start for this player to start from.  PlayerStarts are rated by RatePlayerStart().
* @param Player is the controller for whom we are choosing a playerstart
* @param InTeam specifies the Player's team (if the player hasn't joined a team yet)
* @param IncomingName specifies the tag of a teleporter to use as the Playerstart
* @returns NavigationPoint chosen as player start (usually a PlayerStart)
 */
function NavigationPoint FindPlayerStart(Controller Player, optional byte InTeam, optional string incomingName)
{
    local NavigationPoint Best;

    if (ScriptedStartSpot != None)
    {
        Best = ScriptedStartSpot;
        ScriptedStartSpot = None;
    }
    else
    {
        // Save LastPlayerStartSpot for use in RatePlayerStart()
        if ( (Player != None) && (Player.StartSpot != None) )
        {
            LastPlayerStartSpot = Player.StartSpot;
        }

        Best = Super.FindPlayerStart(Player, InTeam, incomingName );

        // Save LastStartSpot for use in RatePlayerStart()
        if ( Best != None )
        {
            LastStartSpot = Best;
        }
    }

    return Best;
}

function bool DominatingVictory()
{
    return ( (PlayerReplicationInfo(GameReplicationInfo.Winner).Deaths == 0)
        && (PlayerReplicationInfo(GameReplicationInfo.Winner).Score >= 5) );
}

function bool IsAWinner(PlayerController C)
{
    if ( C.PlayerReplicationInfo == None )
    {
        return false;
    }
    return ( C.PlayerReplicationInfo.bOnlySpectator || (C.PlayerReplicationInfo == GameReplicationInfo.Winner) );
}

function PlayEndOfMatchMessage()
{
    local UTPlayerController PC;

    if ( DominatingVictory() )
    {
        foreach WorldInfo.AllControllers(class'UTPlayerController', PC)
        {
            if (IsAWinner(PC))
            {
                PC.ClientPlayAnnouncement(VictoryMessageClass, 0);
            }
            else
            {
                PC.ClientPlayAnnouncement(VictoryMessageClass, 1);
            }
        }
    }
    else
        PlayRegularEndOfMatchMessage();
}

function PlayRegularEndOfMatchMessage()
{
    local UTPlayerController PC;

    foreach WorldInfo.AllControllers(class'UTPlayerController', PC)
    {
        if ( (PC.PlayerReplicationInfo != None) && !PC.PlayerReplicationInfo.bOnlySpectator )
        {
            if ( IsAWinner(PC) )
            {
                PC.ClientPlayAnnouncement(VictoryMessageClass, 2);
            }
            else
            {
                PC.ClientPlayAnnouncement(VictoryMessageClass, 3);
            }
        }
    }
}

function PlayStartupMessage()
{
    local UTPlayerController P;

    // keep message displayed for waiting players
    foreach WorldInfo.AllControllers(class'UTPlayerController', P)
    {
        P.PlayStartUpMessage(StartupStage);
    }
}

function bool JustStarted(float MaxElapsedTime)
{
    return GameReplicationInfo.ElapsedTime < MaxElapsedTime;
}

/** ends the current round; sends the game into state RoundOver and sets the ViewTarget for all players to be the given actor */
function EndRound(Actor EndRoundFocus)
{
    local Controller C;

    //round has ended
    if ( !bGameEnded )
    {
        foreach WorldInfo.AllControllers(class'Controller', C)
        {
            C.RoundHasEnded(EndRoundFocus);
        }
    }
    GotoState('RoundOver');
}

function bool MatchIsInProgress()
{
    return false;
}

function AddInitialBots()
{
    local int AddCount;

    // add any bots immediately
    while (NeedPlayers() && AddBot() != None && AddCount < 16)
    {
        AddCount++;
    }
}

function UTBot SinglePlayerAddBot(optional string BotName, optional bool bUseTeamIndex, optional int TeamIndex)
{
    local int i, CharIndex;
    local UTGameReplicationInfo GRI;
    local UTPlayerReplicationInfo PRI;
    if ( BotName != "" )
    {
        GRI = UTGameReplicationInfo(GameReplicationInfo);
        if ( GRI != none )
        {
            CharIndex = INDEX_None;
            for (i=0;i<4;i++)
            {
                if ( GRI.SinglePlayerBotNames[i] ~= BotName )
                {
                    CharIndex = i;
                    break;
                }
            }

            // Try to add one of the player bots.  See if that player is on the server
            // and if so, ignore the bot.
            if ( CharIndex != INDEX_None )
            {
                for (i=0;i<GRI.PRIArray.Length;i++)
                {
                    PRI = UTPlayerReplicationInfo(GRI.PRIArray[i]);
                    if ( PRI.SinglePlayerCharacterIndex == CharIndex )  // Player existing playing this character so don't add this bot.
                    {
                        return None;
                    }
                }
            }
        }
    }

    return AddBot(BotName, bUseTeamIndex, TeamIndex);
}

auto State PendingMatch
{

    function RestartPlayer(Controller aPlayer)
    {
        if (UTGameReplicationInfo(GameReplicationInfo).bWarmupRound)
        {
            Global.RestartPlayer(aPlayer);
        }
    }

    // Override these 4 functions so that if we are in a warmup round, they get ignored.

    function CheckLives();
    function bool CheckScore(PlayerReplicationInfo Scorer);
    function ScoreKill(Controller Killer, Controller Other);
    function ScoreFlag(Controller Scorer, UTCTFFlag theFlag);

    function Timer()
    {
        local PlayerController P;
        local bool bReady;
        local UTBot B;

        Global.Timer();

        // first check if there are enough net players, and enough time has elapsed to give people
        // a chance to join
        if ( NumPlayers == 0 )
        {
            bWaitForNetPlayers = true;

            if (bWarmupRound)
            {
                WarmupRemaining = WarmupTime;
                GameReplicationInfo.RemainingTime = WarmupRemaining;
            }
        }
        else
        {
            foreach WorldInfo.AllControllers(class'UTBot', B)
            {
                if (TooManyBots(B))
                {
                    B.Destroy();
                }
            }

            AddInitialBots();

            if (bWarmupRound)
            {
                if (WarmupRemaining > 0)
                {
                    WarmupRemaining--;
                    GameReplicationInfo.RemainingTime = WarmupRemaining;
                    if (WarmupRemaining % 60 == 0)
                    {
                        GameReplicationInfo.RemainingMinute = WarmupRemaining;
                    }
                    return;
                }
                else if (WarmupRemaining == 0)
                {
                    WarmupRemaining = -1;
                    UTGameReplicationInfo(GameReplicationInfo).bWarmupRound = false;
                    ResetLevel();
                }
            }
        }

        if ( bWaitForNetPlayers && (WorldInfo.NetMode != NM_Standalone) )
        {
            if ( (NumPlayers >= MinNetPlayers) && (NumPlayers > 0) )
                PendingMatchElapsedTime++;
            else
                PendingMatchElapsedTime = 0;
            if ( (NumPlayers == MaxPlayers) || (PendingMatchElapsedTime > NetWait) )
            {
                // wait until players finish clientside processing (or it times out)
                if (PendingMatchElapsedTime <= ClientProcessingTimeout)
                {
                    if (!InitialProcessingIsComplete())
                    {
                        PlayStartupMessage();
                        return;
                    }
                }
                bWaitForNetPlayers = false;
                CountDown = Default.CountDown;
            }
            else
            {
                PlayStartupMessage();
                return;
            }
        }
        else if (WorldInfo.NetMode == NM_Standalone && !InitialProcessingIsComplete())
        {
            // PlayStartupMessage() intentionally left out here (mesh construction messsage should be visible)
            return;
        }

        // check if players are ready
        bReady = true;

        StartupStage = 1;
        if ( !bStartedCountDown && (bPlayersMustBeReady || (WorldInfo.NetMode == NM_Standalone)) )
        {
            foreach WorldInfo.AllControllers(class'PlayerController', P)
            {
                if ( P.PlayerReplicationInfo != None && P.bIsPlayer && P.PlayerReplicationInfo.bWaitingPlayer
                    && !P.PlayerReplicationInfo.bReadyToPlay )
                {
                    bReady = false;
                }
            }
        }
        if ( bReady && SinglePlayerMissionID == INDEX_None )
        {

            if (!bStartedCountDown)
            {
                if (DemoPrefix != "")
                {
                    ConsoleCommand("demorec" @ DemoPrefix $ "-%td");
                }
                bStartedCountDown = true;
            }
            CountDown--;
            if ( CountDown <= 0 )
                StartMatch();
            else
                StartupStage = 5 - CountDown;
        }
        PlayStartupMessage();
    }

    function BeginState(Name PreviousStateName)
    {
        if (bWarmupRound)
        {
            GameReplicationInfo.RemainingTime = WarmupRemaining;
            GameReplicationInfo.RemainingMinute = WarmupRemaining;
        }
        bWaitingToStartMatch = true;
        UTGameReplicationInfo(GameReplicationInfo).bWarmupRound = bWarmupRound;
        StartupStage = 0;
    }

    function EndState(Name NextStateName)
    {
        UTGameReplicationInfo(GameReplicationInfo).bWarmupRound = false;
    }


Begin:
    if (WorldInfo.NetMode == NM_Standalone || WorldInfo.NetMode == NM_ListenServer)
    {
        Sleep(0.0); //@hack - so local player has time to get friendly faction from profile
        AddInitialBots();
    }

    // quickstart for solo loading of a map
    if (DesiredPlayerCount <= 1 && WorldInfo.NetMode == NM_StandAlone && SinglePlayerMissionID == INDEX_NONE)
    {
        bQuickStart = true;
    }

    if ( bQuickStart )
    {
        if (DemoPrefix != "")
        {
            ConsoleCommand("demorec" @ DemoPrefix $ "-%td");
        }
WaitForMeshes:
        sleep(0.2);
        if ( !InitialProcessingIsComplete() )
        {
            Goto('WaitForMeshes');
        }
        StartMatch();
    }
}


function bool InitialProcessingIsComplete()
{
    local UTPlayerController UTPC;

    foreach WorldInfo.AllControllers(class'UTPlayerController', UTPC)
    {
        if (!UTPC.bInitialProcessingComplete && !UTPC.PlayerReplicationInfo.bOnlySpectator)
        {
            return false;
        }
    }
    return true;
}

function DoMapVote()
{
    local int i;
    local name GameClassName;

    VoteCollector = Spawn(class'UTVoteCollector',none);
    if ( VoteCollector != none )
    {
        GameClassName = class.name;
        for (i=0; i<default.GameSpecificMapCycles.Length; i++)
        {
            if (default.GameSpecificMapCycles[i].GameClassName == GameClassName)
            {
                VoteCollector.Initialize(default.GameSpecificMapCycles[i].Maps);
            }
        }
    }
    else
    {
        LogInternal("Could not create the voting collector.");
    }

    if (RestartWait < VoteDuration)
    {
        RestartWait = VoteDuration;
    }
    UTGameReplicationInfo(GameReplicationInfo).MapVoteTimeRemaining = RestartWait;
}

state MatchInProgress
{
    function bool MatchIsInProgress()
    {
        return true;
    }

    function bool ChangeTeam(Controller Other, int Num, bool bNewTeam)
    {
        local bool bSuccess;
        local UTPlayerController UTPC;

        // Call parent implementation
        bSuccess = Global.ChangeTeam(Other, Num, bNewTeam);

        // OK, we changed teams while mid-game.  Update our voice muting state.
        UTPC = UTPlayerController( Other );
        if( UTPC != None )
        {
            SetupPlayerMuteList( UTPC, false );     // Force spectator channel?
        }

        return bSuccess;
    }

    function Timer()
    {
        local PlayerController P;

        Global.Timer();
        if ( !bFinalStartup )
        {
            bFinalStartup = true;
            PlayStartupMessage();
        }
        // force respawn failsafe
        if ( ForceRespawn() )
        {
            foreach WorldInfo.AllControllers(class'PlayerController', P)
            {
                if (P.Pawn == None && !P.PlayerReplicationInfo.bOnlySpectator && !P.IsTimerActive('DoForcedRespawn'))
                {
                    P.ServerReStartPlayer();
                }
            }
        }
        if ( NeedPlayers() )
        {
            AddBot();
        }

        if ( bOverTime )
        {
            EndGame(None,"TimeLimit");
        }
        else if ( TimeLimit > 0 )
        {
            GameReplicationInfo.bStopCountDown = false;
            if ( GameReplicationInfo.RemainingTime <= 0 )
            {
                EndGame(None,"TimeLimit");
            }
        }
        else if ( (MaxLives > 0) && (NumPlayers + NumBots != 1) )
        {
            CheckMaxLives(none);
        }
    }

    function BeginState(Name PreviousStateName)
    {
        local PlayerReplicationInfo PRI;

        if (PreviousStateName != 'RoundOver')
        {
            foreach DynamicActors(class'PlayerReplicationInfo', PRI)
            {
                PRI.StartTime = 0;
            }
            GameReplicationInfo.ElapsedTime = 0;
            bWaitingToStartMatch = false;
            StartupStage = 5;
            PlayStartupMessage();
            StartupStage = 6;
        }
    }
}

State MatchOver
{
    function RestartPlayer(Controller aPlayer) {}
    function ScoreKill(Controller Killer, Controller Other) {}

    function ReduceDamage( out int Damage, pawn injured, Controller instigatedBy, vector HitLocation, out vector Momentum, class<DamageType> DamageType )
    {
        Damage = 0;
        Momentum = vect(0,0,0);
    }

    function bool ChangeTeam(Controller Other, int num, bool bNewTeam)
    {
        // we don't want newly joining players to get stuck as a spectator for the next match,
        // mark them as out of the game and pretend we succeeded
        Other.PlayerReplicationInfo.bOutOfLives = true;
        return true;
    }

    event PostLogin(PlayerController NewPlayer)
    {
        Global.PostLogin(NewPlayer);

        NewPlayer.GameHasEnded(EndGameFocus);
    }

    function Timer()
    {
        local PlayerController PC;
        local Sequence GameSequence;
        local array<SequenceObject> AllInterpActions;
        local SeqAct_Interp InterpAction;
        local int i, j;
        local bool bIsInCinematic;

        Global.Timer();

        if ( !bGameRestarted && (WorldInfo.TimeSeconds > EndTime + RestartWait) )
        {
            RestartGame();
        }

        if ( EndGameFocus != None )
        {
            EndGameFocus.bAlwaysRelevant = true;

            // if we're not in a cinematic (matinee controlled camera), force all players' ViewTarget to the EndGameFocus
            GameSequence = WorldInfo.GetGameSequence();
            if (GameSequence != None)
            {
                // find any matinee actions that exist
                GameSequence.FindSeqObjectsByClass(class'SeqAct_Interp', true, AllInterpActions);
                for (i = 0; i < AllInterpActions.length && !bIsInCinematic; i++)
                {
                    InterpAction = SeqAct_Interp(AllInterpActions[i]);
                    if (InterpAction.InterpData != None && InterpAction.GroupInst.length > 0)
                    {
                        for (j = 0; j < InterpAction.InterpData.InterpGroups.length; j++)
                        {
                            if (InterpGroupDirector(InterpAction.InterpData.InterpGroups[j]) != None)
                            {
                                bIsInCinematic = true;
                                break;
                            }
                        }
                    }
                }
            }
            if (!bIsInCinematic)
            {
                foreach WorldInfo.AllControllers(class'PlayerController', PC)
                {
                    PC.ClientSetViewtarget(EndGameFocus);
                }
            }
        }

        // play end-of-match message for winner/losers (for single and muli-player)
        EndMessageCounter++;
        if ( EndMessageCounter == EndMessageWait )
        {
            PlayEndOfMatchMessage();
        }
    }

    function bool NeedPlayers()
    {
        return false;
    }

    function BeginState(Name PreviousStateName)
    {
        local Pawn P;

        // Reset VOIP muting so everyone can talk to each other
        ResetAllPlayerMuteListsToSpectatorChannel();

        GameReplicationInfo.bStopCountDown = true;
        foreach WorldInfo.AllPawns(class'Pawn', P)
        {
            P.TurnOff();
        }

        if ( SinglePlayerMissionID == INDEX_NONE && bAllowMapVoting )
        {
            DoMapVote();
        }
    }

    function ResetLevel()
    {
        RestartGame();
    }
}

state RoundOver extends MatchOver
{
    ignores DoMapVote;

    event BeginState(name PreviousStateName)
    {
        Super.BeginState(PreviousStateName);
        ResetCountDown = Max(2, ResetTimeDelay);
    }

    function bool ChangeTeam(Controller Other, int Num, bool bNewTeam)
    {
        return Global.ChangeTeam(Other, Num, bNewTeam);
    }

    function ResetLevel()
    {
        // note that we need to change the state BEFORE calling ResetLevel() so that we don't unintentionally override
        // functions that ResetLevel() may call
        GotoState('');
        Global.ResetLevel();
        GotoState('MatchInProgress');
        ResetCountDown = 0;
    }

    event Timer()
    {
        Global.Timer();

        ResetCountdown--;
        if (ResetCountdown == 1)
        {
            ResetLevel();
        }
    }
}

/** ChoosePlayerStart()
* Return the 'best' player start for this player to start from.  PlayerStarts are rated by RatePlayerStart().
* @param Player is the controller for whom we are choosing a playerstart
* @param InTeam specifies the Player's team (if the player hasn't joined a team yet)
* @returns NavigationPoint chosen as player start (usually a PlayerStart)
 */
function PlayerStart ChoosePlayerStart( Controller Player, optional byte InTeam )
{
    local PlayerStart P, BestStart;
    local float BestRating, NewRating;
    local array<playerstart> PlayerStarts;
    local int i, RandStart;
    local byte Team;

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

    // make array of enabled playerstarts
    foreach WorldInfo.AllNavigationPoints(class'PlayerStart', P)
    {
        if ( P.bEnabled )
            PlayerStarts[PlayerStarts.Length] = P;
    }

    // Avoid randomness for profiling.
    if( bFixedPlayerStart )
    {
        RandStart = 0;
    }
    // start at random point to randomize finding "good enough" playerstart
    else
    {
        RandStart = Rand(PlayerStarts.Length);
    }

    for ( i=RandStart; i<PlayerStarts.Length; i++ )
    {
        P = PlayerStarts[i];
        NewRating = RatePlayerStart(P,Team,Player);
        if ( NewRating >= 30 )
        {
            // this PlayerStart is good enough
            return P;
        }
        if ( NewRating > BestRating )
        {
            BestRating = NewRating;
            BestStart = P;
        }
    }
    for ( i=0; i<RandStart; i++ )
    {
        P = PlayerStarts[i];
        NewRating = RatePlayerStart(P,Team,Player);
        if ( NewRating >= 30 )
        {
            // this PlayerStart is good enough
            return P;
        }
        if ( NewRating > BestRating )
        {
            BestRating = NewRating;
            BestStart = P;
        }
    }
    return BestStart;
}

/** RatePlayerStart()
* Return a score representing how desireable a playerstart is.
* @param P is the playerstart being rated
* @param Team is the team of the player choosing the playerstart
* @param Player is the controller choosing the playerstart
* @returns playerstart score
*/
function float RatePlayerStart(PlayerStart P, byte Team, Controller Player)
{
    local float Score, NextDist;
    local Controller OtherPlayer;
    local bool bTwoPlayerGame;

    // Primary starts are more desireable
    Score = P.bPrimaryStart ? 30 : 20;

    if ( (P == LastStartSpot) || (P == LastPlayerStartSpot) )
    {
        // avoid re-using starts
        Score -= 15.0;
    }

    bTwoPlayerGame = ( NumPlayers + NumBots == 2 );

    if (Player != None)
    {
        ForEach WorldInfo.AllControllers(class'Controller', OtherPlayer)
        {
            if ( OtherPlayer.bIsPlayer && (OtherPlayer.Pawn != None) )
            {
                // check if playerstart overlaps this pawn
                if ( (Abs(P.Location.Z - OtherPlayer.Pawn.Location.Z) < P.CylinderComponent.CollisionHeight + OtherPlayer.Pawn.CylinderComponent.CollisionHeight)
                    && (VSize2D(P.Location - OtherPlayer.Pawn.Location) < P.CylinderComponent.CollisionRadius + OtherPlayer.Pawn.CylinderComponent.CollisionRadius) )
                {
                    // overlapping - would telefrag
                    return -10;
                }

                NextDist = VSize(OtherPlayer.Pawn.Location - P.Location);
                if ( (NextDist < 3000) && !WorldInfo.GRI.OnSameTeam(Player,OtherPlayer) && FastTrace(P.Location, OtherPlayer.Pawn.Location+vect(0,0,1)*OtherPlayer.Pawn.CylinderComponent.CollisionHeight) )
                {
                    // avoid starts close to visible enemy
                    if ( (OtherPlayer.PlayerReplicationInfo != None) && (UTPlayerReplicationInfo(Player.PlayerReplicationInfo).LastKillerPRI == OtherPlayer.PlayerReplicationInfo) )
                    {
                        // really avoid guy that killed me last
                        Score -= 7;
                    }
                    Score -= (5 - 0.001*NextDist);
                }
                else if ( (NextDist < 1500) && (OtherPlayer.PlayerReplicationInfo != None) && (UTPlayerReplicationInfo(Player.PlayerReplicationInfo).LastKillerPRI == OtherPlayer.PlayerReplicationInfo) )
                {
                    // really avoid guy that killed me last
                    Score -= 7;
                }
                else if ( bTwoPlayerGame )
                {
                    // in 2 player game, look for any visibility
                    Score += FMin(2,0.001*NextDist);
                    if ( FastTrace(P.Location, OtherPlayer.Pawn.Location) )
                        Score -= 5;
                }
            }
        }
    }
    return FMax(Score, 0.2);
}

// check if all other players are out
function bool CheckMaxLives(PlayerReplicationInfo Scorer)
{
    local Controller C;
    local PlayerReplicationInfo Living;
    local bool bNoneLeft;

    if ( MaxLives > 0 )
    {
        if ( (Scorer != None) && !Scorer.bOutOfLives )
            Living = Scorer;
        bNoneLeft = true;
        foreach WorldInfo.AllControllers(class'Controller', C)
        {
            if ( (C.PlayerReplicationInfo != None) && C.bIsPlayer
                && !C.PlayerReplicationInfo.bOutOfLives
                && !C.PlayerReplicationInfo.bOnlySpectator )
            {
                if ( Living == None )
                {
                    Living = C.PlayerReplicationInfo;
                }
                else if (C.PlayerReplicationInfo != Living)
                {
                    bNoneLeft = false;
                        break;
                }
            }
        }
        if ( bNoneLeft )
        {
            if ( Living != None )
            {
                EndGame(Living,"LastMan");
            }
            else
            {
                EndGame(Scorer,"LastMan");
            }
            return true;
        }
    }
    return false;
}

/* CheckScore()
see if this score means the game ends
*/
function bool CheckScore(PlayerReplicationInfo Scorer)
{
    local controller C;

    if ( CheckMaxLives(Scorer) )
    {
        return false;
    }

    if ( Scorer != None )
    {
        if ( bScoreDeaths && (GoalScore > 0) )
        {
            if ( Scorer.Score == GoalScore - 10 )
            {
                if ( !bPlayedTenKills && (GoalScore > 19) )
                {
                    GameReplicationInfo.SortPRIArray();
                    if ( Scorer == GameReplicationInfo.PRIArray[0] )
                    {
                        bPlayedTenKills = true;
                        BroadcastLocalized(self,class'UTKillsRemainingMessage', 0);
                    }
                }
            }
            else if ( Scorer.Score == GoalScore - 5 )
            {
                if ( !bPlayedFiveKills && (GoalScore > 9) )
                {
                    GameReplicationInfo.SortPRIArray();
                    if ( Scorer == GameReplicationInfo.PRIArray[0] )
                    {
                        bPlayedFiveKills = true;
                        BroadcastLocalized(self,class'UTKillsRemainingMessage', 1);
                    }
                }
            }
            else if ( (Scorer.Score == GoalScore - 1) && !bPlayedOneKill )
            {
                GameReplicationInfo.SortPRIArray();
                if ( Scorer == GameReplicationInfo.PRIArray[0] )
                {
                    bPlayedOneKill = true;
                    BroadcastLocalized(self,class'UTKillsRemainingMessage', 2);
                }
            }
        }
        if ( (GoalScore > 0) && (Scorer.Score >= GoalScore) )
        {
            EndGame(Scorer,"fraglimit");
        }
        else if ( bOverTime )
        {
            // end game only if scorer has highest score
            foreach WorldInfo.AllControllers(class'Controller', C)
            {
                if ( (C.PlayerReplicationInfo != None)
                    && (C.PlayerReplicationInfo != Scorer)
                    && (C.PlayerReplicationInfo.Score >= Scorer.Score) )
                {
                    return false;
                }
            }
            EndGame(Scorer,"fraglimit");
        }
    }
    return true;
}

function RegisterVehicle(UTVehicle V)
{
    // add to AI vehicle list
    V.NextVehicle = VehicleList;
    VehicleList = V;
}

/**
ActivateVehicleFactory()
Called by UTVehicleFactory in its PostBeginPlay()
*/
function ActivateVehicleFactory(UTVehicleFactory VF)
{
    local UTGameObjective O, Best;
    local float BestDist, NewDist;

    if ( !bTeamGame )
        VF.bStartNeutral = true;
    if ( VF.bStartNeutral )
    {
        VF.Activate(255);
    }
    else
    {
        ForEach WorldInfo.AllNavigationPoints(class'UTGameObjective',O)
        {
            NewDist = VSize(VF.Location - O.Location);
            if ( (Best == None) || (NewDist < BestDist) )
            {
                Best = O;
                BestDist = NewDist;
            }
        }

        if ( Best != None )
            VF.Activate(Best.DefenderTeamIndex);
        else
            VF.Activate(255);
    }
}


static function int OrderToIndex(int Order)
{
    return Order;
}

function ViewObjective(PlayerController PC)
{
    local int i,Index,Score;
    local Controller C;

    if (WorldInfo.GRI.PRIArray.Length==0)
    {
        return;
    }

    // Prime the score
    Score = -1;
    Index = -1;
    for ( i=0; i<WorldInfo.GRI.PRIArray.Length; i++ )
    {
        if (WorldInfo.GRI.PRIArray[i].Score > Score)
        {
            C = Controller(WorldInfo.GRI.PRIArray[i].Owner);
            if (C!=none && C.Pawn != none)
            {
                Score = WorldInfo.GRI.PRIArray[i].Score;
                Index = i;
            }
        }
    }

    if (Index == -1)
    {
        return;
    }

    if ( Index>=0 && Index<WorldInfo.GRI.PRIArray.Length )
    {
        PC.SetViewTarget( Controller(WorldInfo.GRI.PRIArray[Index].Owner).Pawn );
    }
}

function bool PickupQuery(Pawn Other, class<Inventory> ItemClass, Actor Pickup)
{
    if (bDemoMode)
    {
        if (ItemClass!=class'UTGame.UTWeap_ShockRifle' || ItemClass!=class'UTGame.UTWeap_RocketLauncher')
            return false;
    }

    return Super.PickupQuery(Other, ItemClass, Pickup);
}

function string DecodeEvent(name EventType, int TeamNo, string InstigatorName, string AdditionalName, class<object> AdditionalObj)
{
    local string s;
    if (EventType == 'TeamDeathWhileTyping')
    {
        return AdditionalName@"killed his teammate"@InstigatorName@"while he was typing! ("$AdditionalObj$")";
    }
    else if (EventType == 'DeathWhileTyping')
    {
        return AdditionalName@"killed"@InstigatorName@"while he was typing! ("$AdditionalObj$")";
    }
    else if (EventType == 'TeamDeath')
    {
        return AdditionalName@"killed his teammate"@InstigatorName$" ("$AdditionalObj$")";
    }
    else if (EventType == 'TeamDeath')
    {
        return AdditionalName@"killed"@InstigatorName$" ("$AdditionalObj$")";
    }
    else if (EventType == 'VehicleKill')
    {
        return InstigatorName$"blew up a"@AdditionalObj;
    }
    else if (EventType == 'Connect')
    {
        return InstigatorName$"has joined the game!";
    }
    else if (EventType == 'Reconnect')
    {
        return InstigatorName$"has returned to the game!";
    }
    else if (EventType == 'Disconnect')
    {
        return InstigatorName$"has left the game!";
    }
    else if (EventType == 'MatchBegins')
    {
        return "... The match begins ...";
    }
    else if (EventType == 'NewRound')
    {
        return "... Next Round ...";
    }
    else if (Left(""$EventType,10) ~= "MatchEnded")
    {
        s = ""$EventType;
        return "... Match Ended ("$Right(s,len(s)-10)$") ...";
    }
    else
        return "";
}

function AddMutator(string mutname, optional bool bUserAdded)
{
    if ( InStr(MutName,".")<0 )
    {
        MutName = "UTGame."$MutName;
    }

    Super.AddMutator(mutname, bUserAdded);
}

/**
 * This function allows the server to override any requested teleport attempts from a client
 *
 * @returns     returns true if the teleport is allowed
 */
function bool AllowClientToTeleport(UTPlayerReplicationInfo ClientPRI, Actor DestinationActor)
{
    return true;
}

/** displays the path to the given base for the given player */
function ShowPathTo(PlayerController P, int TeamNum);

event HandleSeamlessTravelPlayer(out Controller C)
{
    local UTBot B;
    local UTPlayerController PC;
    local string BotName;
    local int BotTeamIndex;

    B = UTBot(C);
    if (B != None && UTPlayerReplicationInfo(B.PlayerReplicationInfo) != None && UTPlayerReplicationInfo(B.PlayerReplicationInfo).bPrecachedBot)
    {
        NumBots++; // because Logout() will decrement it
        B.LifeSpan = 0.001; //@hack: so bot doesn't go away until everything has been processed
    }
    else if (B != None && B.Class != BotClass)
    {
        // re-create bot
        BotName = B.PlayerReplicationInfo.PlayerName;
        BotTeamIndex = B.GetTeamNum();
        B.Destroy();
        C = AddBot(BotName, (BotTeamIndex != 255), BotTeamIndex);
    }
    else
    {
        Super.HandleSeamlessTravelPlayer(C);

        // make sure bots get a new squad
        if (B != None && B.Squad == None)
        {
            GetBotTeam().AddToTeam(B);
        }

        PC = UTPlayerController(C);
        if (PC != None)
        {
            PC.ClientSetSpeechRecognitionObject(SpeechRecognitionData);
            // bInitialProcessingComplete might have got lost if we did class replacement
            if (!PC.bInitialProcessingComplete)
            {
                PC.bInitialProcessingComplete = true;
                PC.ClientSetProcessingComplete();
            }
        }
    }

}

/** @return an objective that should be recommended to the given player based on their auto objective settings and the current game state */
function Actor GetAutoObjectiveFor(UTPlayerController PC);

/** @return the first mutator in the mutator list that's a UTMutator */
function UTMutator GetBaseUTMutator()
{
    local Mutator M;
    local UTMutator UTMut;

    for (M = BaseMutator; M != None; M = M.NextMutator)
    {
        UTMut = UTMutator(M);
        if (UTMut != None)
        {
            return UTMut;
        }
    }

    return None;
}

/** parses the given player's recognized speech into bot orders, etc */
function ProcessSpeechRecognition(UTPlayerController Speaker, const out array<SpeechRecognizedWord> Words)
{
    local UTMutator UTMut;

    UTMut = GetBaseUTMutator();
    if (UTMut != None)
    {
        UTMut.ProcessSpeechRecognition(Speaker, Words);
    }
}

/**
 * Write player scores used in skill calculations
 */
function WriteOnlinePlayerScores()
{
    local int Index;
    local int Count;
    local UTPlayerController PC;
    local PlayerReplicationInfo PRI;
    local array<OnlinePlayerScore> PlayerScores;
    local float TimeInGame;
    local UniqueNetId ZeroUniqueId;

    if ((SinglePlayerMissionID > INDEX_None) || (WorldInfo.NetMode == NM_Standalone))
    {
        //We don't record single player stats
        return;
    }

    if (OnlineSub != None && OnlineSub.StatsInterface != None)
    {
        // Iterate through the players building their score data
        foreach WorldInfo.AllControllers(class'UTPlayerController',PC)
        {
            PRI = PC.PlayerReplicationInfo;

            // Don't record stats for bots (bots have a zero unique net id)
            if (PRI != None && (PRI.UniqueId != ZeroUniqueId))
            {
                TimeInGame = float(WorldInfo.GRI.ElapsedTime - PRI.StartTime);
                //Game has lasted more than 10 seconds, you've been in at least 30 secs of it or 90% of the elapsed time 
                if (WorldInfo.GRI.ElapsedTime > 10 && (TimeInGame >= Min(30.0f, float(WorldInfo.GRI.ElapsedTime) * 0.9f)))
                {
                    // Build the skill data for this player
                    Count++;
                    PlayerScores.Length = Count;
                    PlayerScores[Count-1].PlayerId = PRI.UniqueId;
                    PlayerScores[Count-1].Score = PRI.Score;
                    // Each player is on their own team (rated as individuals)
                    PlayerScores[Count-1].TeamId = 255;
                }
            }
        }

        // Iterate through the inactive players building their score data
        for (Index = 0; Index < GameReplicationInfo.InactivePRIArray.Length; Index++)
        {
            // Ignore bots (bots have a zero unique net id) or players in the game less than 30 seconds
            PRI = GameReplicationInfo.InactivePRIArray[Index];
            if (PRI != None && PRI.UniqueId != ZeroUniqueId)
            {
                // Build the skill data for this player
                Count++;
                PlayerScores.Length = Count;
                PlayerScores[Count-1].PlayerId = PRI.UniqueId;
                PlayerScores[Count-1].Score = PRI.Score;
                // Each player is on their own team (rated as individuals)
                PlayerScores[Count-1].TeamId = 255;
            }
        }

        if (PlayerScores.Length > 0)
        {
            // Now write out the scores
            OnlineSub.StatsInterface.WriteOnlinePlayerScores(PlayerScores);
        }
        else
        {
            WarnInternal("There were no playerscores to write out");
        }
    }
}

/**
 * Sorts the scores and assigns relative positions to the players
 *
 * @param PlayerScores the raw scores before sorting and relative position setting
 */
native function SortPlayerScores(out array<OnlinePlayerScore> PlayerScores);

/** @return the index of the current map in the given list (used when starting up a server to start counting at the current map) */
function int GetCurrentMapCycleIndex(const out array<string> MapList)
{
    return MapList.Find(string(WorldInfo.GetPackageName()));
}

/**
 * Returns the next map to play.  If we are in story mode, we need to go back to the map selection menu
 */
function string GetNextMap()
{
    local bool SPResult;
    local int GameIndex;
    local string MapName;
    local array<string> MapList;

    if ( SinglePlayerMissionID > INDEX_NONE)
    {
        // TODO Add code to determine a win or loss

        SPResult = GetSinglePlayerResult();
        return "UTM-MissionSelection?SPI="$SinglePlayerMissionID$"?SPResult="$int(SPResult)$"?Difficulty="$GameDifficulty;

    }
    else
    {
        if (VoteCollector != none && VoteCollector.bVoteDecided )
        {
            MapName = VoteCollector.GetWinningMap();
            if (MapName != "")
            {
                return MapName;
            }
        }

        GameIndex = GameSpecificMapCycles.Find('GameClassName', Class.Name);
        if (GameIndex != INDEX_NONE)
        {
            if (MapCycleIndex == INDEX_NONE)
            {
                //@FIXME: use temporary because compiler's "can't pass array elements by reference" restriction
                //	doesn't understand that 'const out' is safe
                MapList = GameSpecificMapCycles[GameIndex].Maps;
                MapCycleIndex = GetCurrentMapCycleIndex(MapList);
                if (MapCycleIndex == INDEX_NONE)
                {
                    // assume current map is actually zero
                    MapCycleIndex = 0;
                }
            }
            MapCycleIndex = (MapCycleIndex + 1 < GameSpecificMapCycles[GameIndex].Maps.length) ? (MapCycleIndex + 1) : 0;
            // don't save if admin made changes as this object doesn't get those changes
            // (to avoid the current game getting disrupted)
            // and thus saving here would clobber the changes that were made
            if (!bAdminModifiedOptions)
            {
                SaveConfig();
            }

            return GameSpecificMapCycles[GameIndex].Maps[MapCycleIndex];
        }
        else
        {
            return "";
        }
    }
}

function ProcessServerTravel(string URL, optional bool bAbsolute)
{
    local Controller C;

    if (!IsInState('MatchOver'))
    {
        foreach WorldInfo.AllControllers(class'Controller', C)
        {
            C.GameHasEnded();
        }
        GotoState('MatchOver');
    }

    Super.ProcessServerTravel(URL, bAbsolute);

    // on dedicated servers, add a delay to the travel process to give clients a little more time to construct any meshes
    // since that process will get cut off when the server completely finishes travelling
    if (WorldInfo.NetMode == NM_DedicatedServer && WorldInfo.IsInSeamlessTravel())
    {
        WorldInfo.SetSeamlessTravelMidpointPause(true);
        SetTimer(7.0, false, 'ContinueSeamlessTravel');
    }
}

function ContinueSeamlessTravel()
{
    WorldInfo.SetSeamlessTravelMidpointPause(false);
}

/**
 * @Retuns the results of the match.
 */
function bool GetSinglePlayerResult()
{
    local UTPlayerController PC;
    foreach WorldInfo.AllControllers(class'UTPlayerController', PC)
    {
        if ( PC != none && LocalPlayer(PC.Player) != none )
        {
            return IsAWinner(PC);
        }
    }

    // Default to a winner
    return true;
}

/**
 * @Returns a string that describes how to win the match
 *
 */
static function string GetEndOfMatchRules(int InGoalScore, int InTimeLimit)
{
    local string Work;
    if ( InGoalScore > 0 )
    {
        Work = default.EndOfMatchRulesTemplateStr_Scoring;
    }
    else
    {
        Work = default.EndOfMatchRulesTemplateStr_Time;
    }

    Work = Repl(Work,"`g",string(InGoalScore));
    Work = Repl(Work,"`t",string(InTimeLimit));

    return Work;
}

/**
 * Returns through outparameters what location message to play
 * Returns true if it returned message information
 */
function bool GetLocationFor(Pawn StatusPawn, out Actor LocationObject, out int MessageIndex, int LocationSpeechOffset)
{
    local UTPickupFactory F;
    local UTGameObjective Best, O;
    local float NewDistSq, BestDistSq;
    local UTBot B;

    // see if it's a bot heading for an objective or a power up
    B = UTBot(StatusPawn.Controller);
    if ( B != None )
    {
        O = (B.Squad != None) ? B.Squad.SquadObjective : B.SquadRouteGoal;
        if ( O == None )
        {
            O = UTGameObjective(B.RouteGoal);
        }
        if ( O != None )
        {
            if ( O.bHasLocationSpeech )
            {
                MessageIndex = O.GetLocationMessageIndex(B, StatusPawn);
                LocationObject = O;
                return true;
            }
        }
        else
        {
            F = UTPickupFactory(StatusPawn.Controller.RouteGoal);
            if ( (F != None) && F.bHasLocationSpeech )
            {
                MessageIndex = 0;
                LocationObject = F;
                return true;
            }
        }
    }

    // try to find nearby objective
    ForEach WorldInfo.AllNavigationPoints(class'UTGameObjective', O)
    {
        if ( O.bHasLocationSpeech )
        {
            if ( LocationSpeechOffset >= O.LocationSpeech.Length )
            {
                return false;
            }
            NewDistSq = VSizeSq(StatusPawn.Location - O.Location);
            if ( (Best == None) || (NewDistSq < BestDistSq) )
            {
                Best = O;
                BestDistSq = NewDistSq;
            }
        }
    }
    if ( Best != None )
    {
        MessageIndex = Best.GetLocationMessageIndex(B, StatusPawn);
        LocationObject = Best;
        return true;
    }

    MessageIndex = 10;
    return true;
}

function bool GetTravelType()
{
    return SinglePlayerMissionID > INDEX_NONE;
}

/**
 * AllowCheats - Allow cheating in single player games and coop games.
 */
function bool AllowCheats(PlayerController P)
{
    return ( (WorldInfo.NetMode == NM_Standalone) || ((SinglePlayerMissionID != INDEX_NONE) && (WorldInfo.NetMode == NM_ListenServer)) );
}

function SkipCinematics(PlayerController PC)
{
    local Sequence GameSequence;
    local array<SequenceObject> SkipEvents;
    local int i;

    LogInternal("### SkipCinematics"@Role@WorldInfo.GRI.bMatchHAsBegun@SinglePlayerMissionID);

    // on host, check if should skip tutorial
    if ( Role == ROLE_Authority && WorldInfo.GRI.bMatchHasBegun && SinglePlayerMissionID != INDEX_NONE )
    {
        GameSequence = WorldInfo.GetGameSequence();
        if (GameSequence != None)
        {
            GameSequence.FindSeqObjectsByClass(class'UTSeqEvent_SkipCinematic', true, SkipEvents);
            for (i = 0; i < SkipEvents.length; i++)
            {
                if ( UTSeqEvent_SkipCinematic(SkipEvents[i]).bEnabled &&
                    UTSeqEvent_SkipCinematic(SkipEvents[i]).CheckActivate(self, self) )
                {
                    return;
                }
            }
        }
    }
}

/**
 * Used to update any changes in game settings that need to be published to
 * players that are searching for games
 */
function UpdateGameSettings()
{
    local string MapName;
    local string GameTypeName;

    if (GameSettings != None && GameInterface != None)
    {
        MapName = WorldInfo.GetMapName(true);
        GameTypeName = PathName(WorldInfo.GetGameClass());

        GameSettings.SetPropertyFromStringByName('CustomMapName',MapName);
        GameSettings.SetPropertyFromStringByName('CustomGameMode',GameTypeName);

        // Is this game still pure?
        GameSettings.SetStringSettingValue(class'UTGameSearchCommon'.const.CONTEXT_PURESERVER,
            IsPureGame() ? class'UTGameSearchCommon'.const.CONTEXT_PURESERVER_YES : class'UTGameSearchCommon'.const.CONTEXT_PURESERVER_NO,
            false);

        // make sure we advertise that we're locked if a password is required to login
        GameSettings.SetStringSettingValue(class'UTGameSearchCommon'.const.CONTEXT_LOCKEDSERVER,
            RequiresPassword() ? class'UTGameSearchCommon'.const.CONTEXT_LOCKEDSERVER_YES : class'UTGameSearchCommon'.const.CONTEXT_LOCKEDSERVER_NO,
            false);

        GameInterface.UpdateOnlineGame(GameSettings);
    }
}

defaultproperties
{
   bExportMenuData=True
   bWeaponStay=True
   bWaitForNetPlayers=True
   bAllowMapVoting=True
   Acronym="???"
   EndTimeDelay=4.000000
   BotRatio=1.000000
   NetWait=15
   ClientProcessingTimeout=30
   MinNetPlayers=1
   RestartWait=30
   SpawnProtectionTime=2.000000
   LateEntryLives=1
   CountDown=4
   EndMessageWait=1
   DefaultInventory(0)=Class'UTGame.UTWeap_Enforcer'
   DefaultInventory(1)=Class'UTGame.UTWeap_ImpactHammer'
   VictoryMessageClass=Class'UTGame.UTVictoryMessage'
   DefaultMapPrefixes(0)=(Prefix="DM",GameType="UTGame.UTDeathmatch",AdditionalGameTypes=("UTGame.UTTeamGame","UTGame.UTDuelGame"))
   DefaultMapPrefixes(1)=(Prefix="CTF",GameType="UTGameContent.UTCTFGame_Content")
   DefaultMapPrefixes(2)=(Prefix="WAR",GameType="UTGameContent.UTOnslaughtGame_Content")
   DefaultMapPrefixes(3)=(Prefix="VCTF",GameType="UTGameContent.UTVehicleCTFGame_Content")
   DefaultMapPrefixes(4)=(Prefix="DG",GameType="UTGame.DemoGame")
   DefaultMapPrefixes(5)=(Prefix="UTM",GameType="UTGame.UTMissionSelectionGame")
   DefaultMapPrefixes(6)=(Prefix="UTCIN",GameType="UTGame.UTCinematicGame")
   ConsolePlayerControllerClass=Class'UTGame.UTConsolePlayerController'
   BotClass=Class'UTGame.UTBot'
   GameSpecificMapCycles(0)=(GameClassName="UTOnslaughtGame",Maps=("WAR-Downtown","WAR-SinkHole","WAR-Dusk","WAR-Islander","WAR-Avalanche","WAR-MarketDistrict","WAR-OnyxCoast","WAR-Powersurge","WAR-Serenity","WAR-FloodGate","WAR-Torlan"))
   GameSpecificMapCycles(1)=(GameClassName="UTOnslaughtGame_Content",Maps=("WAR-Serenity_Necris"))
   GameSpecificMapCycles(2)=(GameClassName="UTVehicleCTFGame_Content",Maps=("vCTF-Kargo"))
   GameSpecificMapCycles(3)=(GameClassName="UTDuelGame",Maps=("DM-Biohazard"))
   GameSpecificMapCycles(4)=(GameClassName="UTDeathmatch",Maps=("DM-Arsenal"))
   GameSpecificMapCycles(5)=(GameClassName="UTCTFGame_Content",Maps=("CTF-Hydrosis"))
   VoteDuration=45
   MidGameMenuTemplate=UTUIScene_MidGameMenu'UI_InGameHud.Menus.MidGameMenu'
   SpeechRecognitionData=SpeechRecognition'SpeechRecognition.Alphabet'
   LastEncouragementTime=-20.000000
   MidgameScorePanelTag="DMPanel"
   MaxCustomChars=12
   bRestartLevel=False
   bPauseable=False
   bLoggingGame=True
   bUseSeamlessTravel=True
   bRequiresPushToTalk=True
   DefaultPawnClass=Class'UTGame.UTPawn'
   HUDType=Class'UTGame.UTHUD'
   GoalScore=25
   TimeLimit=20
   DeathMessageClass=Class'UTGame.UTDeathMessage'
   PlayerControllerClass=Class'UTGame.UTPlayerController'
   PlayerReplicationInfoClass=Class'UTGame.UTPlayerReplicationInfo'
   GameReplicationInfoClass=Class'UTGame.UTGameReplicationInfo'
   Name="Default__UTGame"
   ObjectArchetype=GameInfo'Engine.Default__GameInfo'
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Thu 22/11/2007 16:03:58.000 - Creation time: Mon 26/11/2007 17:42:02.281 - Created with UnCodeX