Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

# Gameplay.PlayerCharacterController

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
03757
03758
03759
03760
03761
03762
03763
03764
03765
03766
03767
03768
03769
03770
03771
03772
03773
03774
03775
03776
03777
03778
03779
03780
03781
03782
03783
03784
03785
03786
03787
03788
03789
03790
03791
03792
03793
03794
03795
03796
03797
03798
03799
03800
03801
03802
03803
03804
03805
03806
03807
03808
03809
03810
03811
03812
03813
03814
03815
03816
03817
03818
03819
03820
03821
03822
03823
03824
03825
03826
03827
03828
03829
03830
03831
03832
03833
03834
03835
03836
03837
03838
03839
03840
03841
03842
03843
03844
03845
03846
03847
03848
03849
03850
03851
03852
03853
03854
03855
03856
03857
03858
03859
03860
03861
03862
03863
03864
03865
03866
03867
03868
03869
03870
03871
03872
03873
03874
03875
03876
03877
03878
03879
03880
03881
03882
03883
03884
03885
03886
03887
03888
03889
03890
03891
03892
03893
03894
03895
03896
03897
03898
03899
03900
03901
03902
03903
03904
03905
03906
03907
03908
03909
03910
03911
03912
03913
03914
03915
03916
03917
03918
03919
03920
03921
03922
03923
03924
03925
03926
03927
03928
03929
03930
03931
03932
03933
03934
03935
03936
03937
03938
03939
03940
03941
03942
03943
03944
03945
03946
03947
03948
03949
03950
03951
03952
03953
03954
03955
03956
03957
03958
03959
03960
03961
03962
03963
03964
03965
03966
03967
03968
03969
03970
03971
03972
03973
03974
03975
03976
03977
03978
03979
03980
03981
03982
03983
03984
03985
03986
03987
03988
03989
03990
03991
03992
03993
03994
03995
03996
03997
03998
03999
04000
04001
04002
04003
04004
04005
04006
04007
04008
04009
04010
04011
04012
04013
04014
04015
04016
04017
04018
04019
04020
04021
04022
04023
04024
04025
04026
04027
04028
04029
04030
04031
04032
04033
04034
04035
04036
04037
04038
04039
04040
04041
04042
04043
04044
04045
04046
04047
04048
04049
04050
04051
04052
04053
04054
04055
04056
04057
04058
04059
04060
04061
04062
04063
04064
04065
04066
04067
04068
04069
04070
04071
04072
04073
04074
04075
04076
04077
04078
04079
04080
04081
04082
04083
04084
04085
04086
04087
04088
04089
04090
04091
04092
04093
04094
04095
04096
04097
04098
04099
04100
04101
04102
04103
04104
04105
04106
04107
04108
04109
04110
04111
04112
04113
04114
04115
04116
04117
04118
04119
04120
04121
04122
04123
04124
04125
04126
04127
04128
04129
04130
04131
04132
04133
04134
04135
04136
04137
04138
04139
04140
04141
04142
04143
04144
04145
04146
04147
04148
04149
04150
04151
04152
04153
04154
04155
04156
04157
04158
04159
04160
04161
04162
04163
04164
04165
04166
04167
04168
04169
04170
04171
04172
04173
04174
04175
04176
04177
04178
04179
04180
04181
04182
04183
04184
04185
04186
04187
04188
04189
04190
04191
04192
04193
04194
04195
04196
04197
04198
04199
04200
04201
04202
04203
04204
04205
04206
04207
04208
04209
04210
04211
04212
04213
04214
04215
04216
04217
04218
04219
04220
04221
04222
04223
04224
04225
04226
04227
04228
04229
04230
04231
04232
04233
04234
04235
04236
04237
04238
04239
04240
04241
04242
04243
04244
04245
04246
04247
04248
04249
04250
04251
04252
04253
04254
04255
04256
04257
04258
04259
04260
04261
04262
04263
04264
04265
04266
04267
04268
04269
04270
04271
04272
04273
04274
04275
04276
04277
04278
04279
04280
04281
04282
04283
04284
04285
04286
04287
04288
04289
04290
04291
04292
04293
04294
04295
04296
04297
04298
04299
04300
04301
04302
04303
04304
04305
04306
04307
04308
04309
04310
04311
04312
04313
04314
04315
04316
04317
04318
04319
04320
04321
04322
04323
04324
04325
04326
04327
04328
04329
04330
04331
04332
04333
04334
04335
04336
04337
04338
04339
04340
04341
04342
04343
04344
04345
04346
04347
04348
04349
04350
04351
04352
04353
04354
04355
04356
04357
04358
04359
04360
04361
04362
04363
04364
04365
04366
04367
04368
04369
04370
04371
04372
04373
04374
04375
04376
04377
04378
04379
04380
04381
04382
04383
04384
04385
04386
04387
04388
04389
04390
04391
04392
04393
04394
04395
04396
04397
04398
04399
04400
04401
04402
04403
04404
04405
04406
04407
04408
04409
04410
04411
04412
04413
04414
04415
04416
04417
04418
04419
04420
04421
04422
04423
04424
04425
04426
04427
04428
04429
04430
04431
04432
04433
04434
04435
04436
04437
04438
04439
04440
04441
04442
04443
04444
04445
04446
04447
04448
04449
04450
04451
04452
04453
04454
04455
04456
04457
04458
04459
04460
04461
04462
04463
04464
04465
04466
04467
04468
04469
04470
04471
04472
04473
04474
04475
04476
04477
04478
04479
04480
04481
04482
04483
04484
04485
04486
04487
04488
04489
04490
04491
04492
04493
04494
04495
04496
04497
04498
04499
04500
04501
04502
04503
04504
04505
04506
04507
04508
04509
04510
04511
04512
04513
04514
04515
04516
04517
04518
04519
04520
04521
04522
04523
04524
04525
04526
04527
04528
04529
04530
04531
04532
04533
04534
04535
04536
04537
04538
04539
04540
04541
04542
04543
04544
04545
04546
04547
04548
04549
04550
04551
04552
04553
04554
04555
04556
04557
04558
04559
04560
04561
04562
04563
04564
04565
04566
04567
04568
04569
04570
04571
04572
04573
04574
04575
04576
04577
04578
04579
04580
04581
04582
04583
04584
04585
04586
04587
04588
04589
04590
04591
04592
04593
04594
04595
04596
04597
04598
04599
04600
04601
04602
04603
04604
04605
04606
04607
04608
04609
04610
04611
04612
04613
04614
04615
04616
04617
04618
04619
04620
04621
04622
04623
04624
04625
04626
04627
04628
04629
04630
04631
04632
04633
04634
04635
04636
04637
04638
04639
04640
04641
04642
04643
04644
04645
04646
04647
04648
04649
04650
04651
04652
04653
04654
04655
04656
04657
04658
04659
04660
04661
04662
04663
04664
04665
04666
04667
04668
04669
04670
04671
04672
04673
04674
04675
04676
04677
04678
04679
04680
04681
04682
04683
04684
04685
04686
04687
04688
04689
04690
04691
04692
04693
04694
04695
04696
04697
04698
04699
04700
04701
04702
04703
04704
04705
04706
04707
04708
04709
04710
04711
04712
04713
04714
04715
04716
04717
04718
04719
04720
04721
04722
04723
04724
04725
04726
04727
04728
04729
04730
04731
04732
04733
04734
04735
04736
04737
04738
04739
04740
04741
04742
04743
04744
04745
04746
04747
04748
04749
04750
04751
04752
04753
04754
04755
04756
04757
04758
04759
04760
04761
04762
04763
04764
04765
04766
04767
04768
04769
04770
04771
04772
04773
04774
04775
04776
04777
04778
04779
04780
04781
04782
04783
04784
04785
04786
04787
04788
04789
04790
04791
04792
04793
04794
04795
04796
04797
04798
04799
04800
04801
04802
04803
04804
04805
04806
04807
04808
04809
04810
04811
04812
04813
04814
04815
04816
04817
04818
04819
04820
04821
04822
04823
04824
04825
04826
04827
04828
04829
04830
04831
04832
04833
04834
04835
04836
04837
04838
04839
04840
04841
04842
04843
04844
04845
04846
04847
04848
04849
04850
04851
04852
04853
04854
04855
04856
04857
04858
04859
04860
04861
04862
04863
04864
04865
04866
04867
04868
04869
04870
04871
04872
04873
04874
04875
04876
04877
04878
04879
04880
04881
04882
04883
04884
04885
04886
04887
04888
04889
04890
04891
04892
04893
04894
04895
04896
04897
04898
04899
04900
04901
04902
04903
04904
04905
04906
04907
04908
04909
04910
04911
04912
04913
04914
04915
04916
04917
04918
04919
04920
04921
04922
04923
04924
04925
04926
04927
04928
04929
04930
04931
04932
04933
04934
04935
04936
04937
04938
04939
04940
04941
04942
04943
04944
04945
04946
04947
04948
04949
04950
04951
04952
04953
04954
04955
04956
04957
04958
04959
04960
04961
04962
04963
04964
04965
04966
04967
04968
04969
04970
04971
04972
04973
04974
04975
04976
04977
04978
04979
04980
04981
04982
04983
04984
04985
04986
04987
04988
04989
04990
04991
04992
04993
04994
04995
04996
04997
04998
04999
05000
05001
05002
05003
05004
05005
05006
05007
05008
05009
05010
05011
05012
05013
05014
05015
05016
05017
05018
05019
05020
05021
05022
05023
05024
05025
05026
05027
05028
05029
05030
05031
05032
05033
05034
05035
05036
05037
05038
05039
05040
05041
05042
05043
05044
05045
05046
05047
05048
05049
05050
05051
05052
05053
05054
05055
05056
05057
05058
05059
05060
05061
05062
05063
05064
05065
05066
05067
05068
05069
05070
05071
05072
05073
05074
05075
05076
05077
05078
05079
05080
05081
05082
05083
05084
05085
05086
05087
05088
05089
05090
05091
05092
05093
05094
05095
05096
05097
05098
05099
05100
05101
05102
05103
05104
05105
05106
05107
05108
05109
05110
05111
05112
05113
05114
05115
05116
05117
05118
05119
05120
05121
05122
05123
05124
05125
05126
05127
05128
05129
05130
05131
05132
05133
05134
05135
05136
05137
05138
05139
05140
05141
05142
05143
05144
05145
05146
05147
05148
05149
05150
05151
05152
05153
05154
05155
05156
05157
05158
05159
05160
05161
05162
05163
05164
05165
05166
05167
05168
05169
05170
05171
05172
05173
05174
05175
05176
05177
05178
05179
05180
05181
05182
05183
05184
05185
05186
05187
05188
05189
05190
05191
05192
05193
05194
05195
05196
05197
05198
05199
05200
05201
05202
05203
05204
05205
05206
05207
05208
05209
05210
05211
05212
05213
05214
05215
05216
05217
05218
05219
05220
05221
05222
05223
05224
05225
05226
05227
05228
05229
05230
05231
05232
05233
05234
05235
05236
05237
05238
05239
05240
05241
05242
05243
05244
05245
05246
05247
05248
05249
05250
05251
05252
05253
05254
05255
05256
05257
05258
05259
05260
05261
05262
05263
05264
05265
05266
05267
05268
05269
05270
05271
05272
05273
05274
05275
05276
05277
05278
05279
05280
05281
05282
05283
05284
05285
05286
05287
05288
05289
05290
05291
05292
05293
05294
05295
05296
05297
05298
05299
05300
05301
05302
05303
05304
05305
05306
05307
05308
05309
05310
05311
05312
05313
05314
05315
05316
05317
05318
05319
05320
05321
05322
05323
05324
05325
05326
05327
05328
05329
05330
05331
05332
05333
05334
05335
05336
05337
05338
05339
05340
05341
05342
05343
05344
05345
05346
05347
05348
05349
05350
05351
05352
05353
05354
05355
05356
05357
05358
05359
05360
05361
05362
05363
05364
05365
05366
05367
05368
05369
05370
05371
05372
05373
05374
05375
05376
05377
05378
05379
05380
05381
05382
05383
05384
05385
05386
05387
05388
05389
05390
05391
05392
05393
05394
05395
05396
05397
05398
05399
05400
05401
05402
05403
05404
05405
05406
05407
05408
05409
05410
05411
05412
05413
05414
05415
05416
05417
05418
05419
05420
05421
05422
05423
05424
05425
05426
05427
05428
05429
05430
05431
05432
05433
05434
05435
05436
05437
05438
05439
05440
05441
05442
05443
05444
05445
05446
05447
05448
05449
05450
05451
05452
05453
05454
05455
05456
05457
05458
05459
05460
05461
05462
05463
05464
05465
05466
05467
05468
05469
05470
05471
05472
05473
05474
05475
05476
05477
05478
05479
05480
05481
05482
05483
05484
05485
05486
05487
05488
05489
05490
05491
05492
05493
05494
05495
05496
05497
05498
05499
05500
05501
05502
05503
05504
05505
05506
05507
05508
05509
05510
05511
05512
05513
05514
05515
05516
05517
05518
05519
05520
05521
05522
05523
05524
05525
05526
05527
05528
05529
05530
05531
05532
05533
05534
05535
05536
05537
05538
05539
05540
05541
05542
05543
05544
05545
05546
05547
05548
05549
05550
05551
05552
05553
05554
05555
05556
05557
05558
05559
05560
05561
05562
05563
05564
05565
05566
05567
05568
05569
05570
05571
05572
05573
05574
05575
05576
05577
05578
05579
05580
05581
05582
05583
05584
05585
05586
05587
05588
05589
05590
05591
05592
05593
05594
05595
05596
05597
05598
05599
05600
05601
05602
05603
05604
05605
05606
05607
05608
05609
05610
05611
05612
05613
05614
05615
05616
05617
05618
05619
05620
05621
05622
05623
05624
05625
05626
05627
05628
05629
05630
05631
05632
05633
05634
05635
05636
05637
05638
05639
05640
05641
05642
05643
05644
05645
05646
05647
05648
05649
05650
05651
05652
05653
05654
05655
05656
05657
05658
05659
05660
05661
05662
05663
05664
05665
05666
05667
05668
05669
05670
05671
05672
05673
05674
05675
05676
05677
05678
05679
05680
05681
05682
05683
05684
05685
05686
05687
05688
05689
05690
05691
05692
05693
05694
05695
05696
05697
05698
05699
05700
05701
05702
05703
05704
05705
05706
05707
05708
05709
05710
05711
05712
05713
05714
05715
05716
05717
05718
05719
05720
05721
05722
05723
05724
05725
05726
05727
05728
05729
05730
05731
05732
05733
05734
05735
05736
05737
05738
05739
05740
05741
05742
05743
05744
05745
05746
05747
05748
05749
05750
05751
05752
05753
05754
05755
05756
05757
05758
05759
05760
05761
05762
05763
05764
05765
05766
05767
05768
05769
05770
05771
05772
05773
05774
05775
05776
05777
05778
05779
05780
05781
05782
05783
05784
05785
05786
05787
05788
05789
05790
05791
05792
05793
05794
05795
05796
05797
05798
05799
05800
05801
05802
05803
05804
05805
05806
05807
05808
05809
05810
05811
05812
05813
05814
05815
05816
05817
05818
05819
05820
05821
05822
05823
05824
05825
05826
05827
05828
05829
05830
05831
05832
05833
05834
05835
05836
05837
05838
05839
05840
05841
05842
05843
05844
05845
05846
05847
05848
05849
05850
05851
05852
05853
05854
05855
05856
05857
05858
05859
05860
05861
05862
05863
05864
05865
05866
05867
05868
05869
05870
05871
05872
05873
05874
05875
05876
05877
05878
05879
05880
05881
05882
05883
05884
05885
05886
05887
05888
05889
05890
05891
05892
05893
05894
05895
05896
05897
05898
05899
05900
05901
05902
05903
05904
05905
05906
05907
05908
05909
05910
05911
05912
05913
05914
05915
05916
05917
05918
05919
05920
05921
05922
05923
05924
05925
05926
05927
05928
05929
05930
05931
05932
05933
05934
05935
05936
05937
05938
05939
05940
05941
05942
05943
05944
05945
05946
05947
05948
05949
05950
05951
05952
05953
05954
05955
05956
05957
05958
05959
05960
05961
05962
05963
05964
05965
05966
05967
05968
05969
05970
05971
05972
05973
05974
05975
05976
05977
05978
05979
05980
05981
05982
05983
05984
05985
05986
05987
05988
05989
05990
05991
05992
05993
05994
05995
05996
05997
05998
05999
06000
06001
06002
06003
06004
06005
06006
06007
06008
06009
06010
06011
06012
06013
06014
06015
06016
06017
06018
06019
06020
06021
06022
06023
06024
06025
06026
06027
06028
06029
06030
06031
06032
06033
06034
06035
06036
06037
06038
06039
06040
06041
06042
06043
06044
06045
06046
06047
06048
06049
06050
06051
06052
06053
06054
06055
06056
06057
06058
06059
06060
06061
06062
06063
06064
06065
06066
06067
06068
06069
06070
06071
06072
06073
06074
06075
06076
06077
06078
06079
06080
06081
06082
06083
06084
06085
06086
06087
06088
06089
06090
06091
06092
06093
06094
06095
06096
06097
06098
06099
06100
06101
06102
06103
06104
06105
06106
06107
06108
06109
06110
06111
06112
06113
06114
06115
06116
06117
06118
06119
06120
06121
06122
06123
06124
06125
06126
06127
06128
06129
06130
06131
06132
06133
06134
06135
06136
06137
06138
06139
06140
06141
06142
06143
06144
06145
06146
06147
06148
06149
06150
06151
06152
06153
06154
06155
06156
06157
06158
06159
06160
06161
06162
06163
06164
06165
06166
06167
06168
06169
06170
06171
06172
06173
06174
06175
06176
06177
06178
06179
06180
06181
06182
06183
06184
06185
06186
06187
06188
06189
06190
06191
06192
06193
06194
06195
06196
06197
06198
06199
06200
06201
06202
06203
06204
06205
06206
06207
06208
06209
06210
06211
06212
06213
06214
06215
06216
06217
06218
06219
06220
06221
06222
06223
06224
06225
06226
06227
06228
06229
06230
06231
06232
06233
06234
06235
06236
06237
06238
06239
06240
06241
06242
06243
06244
06245
06246
06247
06248
06249
06250
06251
06252
06253
06254
06255
06256
06257
06258
06259
06260
06261
06262
06263
06264
06265
06266
06267
06268
06269
06270
06271
06272
06273
06274
06275
06276
06277
06278
06279
06280
06281
06282
06283
06284
06285
06286
06287
06288
06289
06290
06291
06292
06293
06294
06295
06296
06297
06298
06299
06300
06301
06302
06303
06304
06305
06306
06307
06308
06309
06310
06311
06312
06313
06314
06315
06316
06317
06318
06319
06320
06321
06322
06323
06324
06325
06326
06327
06328
06329
06330
06331
06332
06333
06334
06335
06336
06337
06338
06339
06340
06341
06342
06343
06344
06345
06346
06347
06348
06349
06350
06351
06352
06353
06354
06355
06356
06357
06358
06359
06360
06361
06362
06363
06364
06365
06366
06367
06368
06369
06370
06371
06372
06373
06374
06375
06376
06377
06378
06379
06380
06381
06382
06383
06384
06385
06386
06387
06388
06389
06390
06391
06392
06393
06394
06395
06396
06397
06398
06399
06400
06401
06402
06403
06404
06405
06406
06407
06408
06409
06410
06411
06412
06413
06414
06415
06416
06417
06418
06419
06420
06421
06422
06423
06424
06425
06426
06427
06428
06429
06430
06431
06432
06433
06434
06435
06436
06437
06438
06439
06440
06441
06442
06443
06444
06445
06446
06447
06448
06449
06450
06451
06452
06453
06454
06455
06456
06457
06458
06459
06460
06461
06462
06463
06464
06465
06466
06467
06468
06469
06470
06471
06472
06473
06474
06475
06476
06477
06478
06479
06480
06481
06482
06483
06484
06485
06486
06487
06488
06489
06490
06491
06492
06493
06494
06495
06496
06497
06498
06499
06500
06501
06502
06503
06504
06505
06506
06507
06508
06509
06510
06511
06512
06513
06514
06515
06516
06517
06518
06519
06520
06521
06522
06523
06524
06525
06526
06527
06528
06529
06530
06531
06532
06533
06534
06535
06536
06537
06538
06539
06540
06541
06542
06543
06544
06545
06546
06547
06548
06549
06550
06551
06552
06553
06554
06555
06556
06557
06558
06559
06560
06561
06562
06563
06564
06565
06566
06567
06568
06569
06570
06571
06572
06573
06574
06575
06576
06577
06578
06579
06580
06581
06582
06583
06584
06585
06586
06587
06588
06589
06590
06591
06592
06593
06594
06595
06596
06597
06598
06599
06600
06601
06602
06603
06604
06605
06606
06607
06608
06609
06610
06611
06612
06613
06614
06615
06616
06617
06618
06619
06620
06621

    class PlayerCharacterController extends Engine.PlayerController
    	native
    	dependsOn(Rook)
    	dependsOn(InventoryStationAccess)
    	dependsOn(Character)
    	dependsOn(ClientSideCharacter);

    import enum EDirectionType from ClientSideCharacter;
    import enum EClientPainType from Character;

    // Inputs
    var input byte
    	bObjectives, bZoom, bQuickChat, bDropWeapon, bLoadoutSelection;

    var Rook Rook;
    var Character Character;

    enum EDigitalAxisInput
    {
    	DAI_Zero,
    	DAI_Positive,
    	DAI_Negative
    };

    // Client movement prediction
    var Array<SavedMove>	TribesSavedMoves;
    var Array<SavedMove>	TribesFreeMoves;
    var SavedMove			TribesPendingMove;
    var Vector				replayFromStartLocation;
    var Vector				replayFromEndLocation;
    var float				replayFromAccumulator;
    var Vector				replayFromVelocity;
    var float				replayFromEnergy;
    var Character.MovementState	replayFromMovement;
    var int					replicateMoveCalls;
    var int					combinedMoves;
    var int					correctedMoves;
    var int					dualMoves;
    var float				ExactPing;
    var globalconfig float	TimeMarginSlack;
    var float				lastReplicationCallTime;
    var bool				bDebugSpeedhack;
    var float				SpeedhackLastAppTime;
    var float				SpeedhackLastComparison;
    var float				SpeedhackComparison;

    var string currentHUDClass; // Store the HUD class so that the HUD can be restored when loading a saved game

    var int debugLogLevel; // use debugMovementReplication console command

    // ClientAdjustPosition replication (event called at end of frame)
    struct native ClientAdjustment
    {
    	var float TimeStamp;
    	var float accumulator;
    	var float energy;
    	var name newState;
    	var Character.MovementState movement;
    	var Vector StartLoc;
    	var Vector EndLoc;
    	var Vector NewVel;
    };
    var ClientAdjustment PendingAdjustment;

    // HUD related stuff
    var transient TribesHUDManager HUDManager;
    var() string spectatorHUDClass;
    var() string countdownHUDClass;
    var() string gameEndHUDClass;
    var() string respawnHUDClass;
    var() string vehicleHUDClass;
    var() string turretHUDClass;
    var() string waitRoundEndHUDClass;
    var() string waitGameStartHUDClass;
    var() string commandHUDClass;
    // Muted players
    var Array<String> MutedPlayerList;

    // GUI
    var() string GUIPackage;
    var() string SPEscapeMenuClass;
    var() string MPEscapeMenuClass;
    var() string MPStatsClass;
    var() string MPWeaponStatsClass;
    var() string MPGameStatsClass;
    var() string MPAdminClass;
    var() string HelpScreenClass;
    var transient MojoCore.CinematicOverlay CinematicOverlay;

    // Sensor system
    var SensorListNode detectedFriendlyList;
    var SensorListNode detectedEnemyList;
    var bool commandHUDVisible;
    var float radarZoomScale;

    // Client-side scripting info
    var transient ClientSideCharacter clientSideChar;
    var Array<Actor> RenderedRooks;

    var bool	bForcedRespawn;		// whether the player is doing a forced respawn

    var() string inventoryStationMenuClass;

    // debug hud data

    var int animationDebugCounter;
    var int movementDebugCounter;

    enum AlertnessModeType
    {
        AlertnessMode_Default,          // default alertness (combat on fire weapon, degrades over time to alert then neutral)
        AlertnessMode_Combat,           // force combat
        AlertnessMode_Alert,            // force alert
        AlertnessMode_Neutral,          // force neutral
    };

    var editconst AlertnessModeType alertnessMode;
    var float alertnessDecayTime;       // time in seconds to decay from combat to alert, and from alert to neutral

    enum GroundMovementModeType
    {
        GroundMovementMode_Any,         // walk, run and sprint are allowed (35kph+)
        GroundMovementMode_Sprint,      // natural sprint (25kph)
        GroundMovementMode_Run,         // natural run (15kph)
        GroundMovementMode_Walk,        // natural walk (5kph)
        GroundMovementMode_Stand,       // only stand is allowed (not allowed to move)
    };

    var GroundMovementModeType groundMovementMode;

    // Loadout
    var private Loadout			currentLoadout;		// used by GameInfo::RestartPlayer to equip the player

    // Radar zooming
    var config Array<float> radarZoomScales;
    var config int radarZoomIndex;

    // Zooming
    var config Array<float> zoomedFOVs;
    var config Array<float> zoomedMouseScale;
    var config Array<float> zoomMagnificationLevels;
    var config float zoomSpeed;
    var config int zoomLevel;
    var float	maxSpectatorZoom;
    var float	minSpectatorZoom;

    // Chat window sizes
    var config Array<int>	ChatWindowSizes;
    var config int			ChatWindowSizeIndex;
    var config Array<int>	SPChatWindowSizes;
    var config int			SPChatWindowSizeIndex;

    // invenotry station external camera offset
    var config Vector		InvExtCamOffset;

    // whether to color hud markers with team colors (alternative is relative)
    var config bool			bTeamMarkerColors;

    // Hide weapons for fps gain
    var config bool bHideFirstPersonWeapon;

    // Identification (under crosshair)
    var Actor			lastIdentified;
    var float			lastIdentifiedDuration;		// how long (in seconds) has crosshair been held over "lastIdentified"
    var Vector			lastIdentifiedHitLocation;	// where the crosshair taytrace hit "lastIdentified"
    var private float	m_identifyTime;
    var private float	m_identifyFrequency;
    var private float	m_identifyRange;
    var private float	IdentifyRadius;		// radius from center of screen where identify can occur
    // Store the screen res, we do this to make the Idetify work better
    var String			ResolutionString;	// current resolution string
    var int				ResolutionX;		// current resolution x
    var int				ResolutionY;		// current resolution y

    // Combat
    var Actor lastHurt; // the last actor that we hurt
    var class<Weapon> lastWeaponClass; // the last weapon class we had equipped (used for stat tracking)

    // Inventory Station
    var InventoryStationInteraction inventoryStationInterface;
    var InventoryStationAccess inventoryStation;

    // Resupply Station
    var ResupplyStation currentResupply;

    // see comment in clientInventoryStationAccess
    var bool inventoryStationWaitingForCharacter;
    var InventoryStationAccess inventoryStationWaitingForCharacterInput;

    // User input
    var bool	bWasUsingDeployable;

    // Damage flash
    var(PlayerCharacterController) Vector		damageFlashColor		"X=Red, Y=Green, Z=Blue, Values should be quite high (> 900)";
    var(PlayerCharacterController) float		damageFlashScale		"Lower values = greater effect";
    var(PlayerCharacterController) float		maxFlashThreshold		"The percentage of damage where the maximum flash occurs";
    var(PlayerCharacterController) float		minFlashThreshold		"The percentage of damage where the minimum flash occurs";
    var(PlayerCharacterController) float		damageFlashMultiplier	"The multiplier is applied to the amount of damage and then added to the flash color";

    // Used when the players view is being controlled by a camera (see state CameraControlled)
    var PlayerControllerCamera controllingCamera;

    // Rounds and spawning
    var RoundInfo roundInfo;
    var BaseInfo	spawnBase;				// the base at which the player has elected to spawn
    var float		respawnDelay;			// current number of seconds before a player is allowed to respawn (started after dying)
    var int			livesLeft;				// number of lives the player has (or -1 for infinite lives)
    var bool		bWaitingForRoundEnd;	// if the player must wait for the round to end

    var bool bUseEnabled;

    // Player-specific objectives
    var float objectivesUpdateRate;
    var ObjectivesList objectives;

    // Variables for the prompt window & Useable objects
    var UseableObject			CurrentUseableObject;			// (only on server) Object the player will use when triggered
    var UseableObject			PromptingUseableObject;			// (only on server) Object the player will see a prompt for (usually the currentUseableObject)
    var class<UseableObject>	PromptingObjectClass;			// (replicated to client) Currently focused useable object class
    var class<Actor>			PromptingDataClass;				// (replicated to client)
    var Vector					PromptingObjectLocation;		// (replicated to client) Location of the currently focused useable object
    var byte					PromptingObjectPromptIndex;		// (replicated to client) Index of the prompt to use for this character on the promping object
    var bool					PromptingObjectCanBeUsed;		// (replicated to client) Whether the prompting object can be used
    var InventoryStationAccess	CurrentUseableInventoryAccess;	// (replicated to client) Inventory station access the user is using
    var string					lowPriorityPromptText;			// General prompts that don't rely on useable objects (use localised message class)
    var float					lowPriorityPromptTimeout;		//

    var private TalkingHeadCamera	currentTalkingHeadCam;
    var private Script				talkingHeadScript;			// The script that showed the current talking head

    var bool	bCountDown;
    var float	countDown;

    var int		ChatCount;
    var float	LastValidChatTime;
    var float	ChatSpamMutedTime;
    var config int MaxMessageTextLength;		// max length of any chat message text
    var config bool ChatSpamGuardEnabled;		// whether the chat spam guard is enabled
    var config int ChatSpamMaxMessages;			// max messages in threshold time
    var config float ChatSpamThresholdTime;		// threshold time
    var config float ChatSpamMutePeriod;		// mute period after exceeding limits

    // cahced key bindings - updateCachedKeyBindings
    var string vehiclePositionSwitchOneKey;
    var string vehiclePositionSwitchTwoKey;
    var string vehiclePositionSwitchThreeKey;
    var string gameStatsKey;
    var string myStatsKey;
    var string adminKey;
    var string respawnKey;

    struct native DynamicTurretRotationProcessingOutput
    {
    	var rotator worldSpaceNoRollRotation;
    	var rotator vehicleSpaceRotation;
    };

    // Skins
    // Skin preferences
    // On the client, this serves as a record of which skin the player likes to use for a given team and role and is stored in the config.
    // On the server, this info is requested from the client and stored on a per-client basis.
    var private Array<CustomPlayerLoadout.SkinPreferenceMapping> skinPreferences;

    // PlayerCamera
    var bool bJustRespawned;		// whether the player had respawed this frame
    var class<Armor> armorClassBeforeInventoryAccess;
    var PlayerCamera camera;
    var Name introCameraOldState;
    var Script introCameraScript;			// The script that showed the current talking head

    var bool bOldBehindView;

    // Points of interest to be displayed on the command map
    var Array<PointOfInterest> PointsOfInterest;

    replication
    {
    	// Client to server
    	unreliable if( Role<ROLE_Authority )
    		TribesServerMove, TribesStateServerMove, TribesShortServerMove, TribesDualServerMove, QuickChat, TeamQuickChat, serverTurretMove, tribesServerDrive,
    		serverVehicleTurretMove;

    	reliable if( Role<ROLE_Authority )
    		serverNextWeapon, serverPrevWeapon, serverSelectWeapon, setIsFemale, switchTeam, spectate, serverFinishInventoryStationAccess, serverToggleReady,
    		serverActivatePack, serverEquipDeployable, serverEquipCarryable, serverEquipFallbackWeapon, serverSpectate,
    		debugSwitchSpawnBase,
    		serverFinishEquippingPreRestart,
    		serverCommandHUDShown, serverCommandHUDHidden,
    		serverSetRadarZoomScale,
    		serverSetSkin,
    		ServerRestartPlayerInVehicle, ServerRestartPlayerAtBase, ServerKillPlayer, ServerPlayerSelectRespawn, ServerCancelRespawn,
    		serverSwitchVehiclePosition,
    		serverFinishQuickInventoryStationAccess,
    		serverInventoryStationSwitchVehiclePosition,
    		serverDebugMovementReplication,
    		serverSetForcedRespawn,
    		ServerViewNextMPObject, ServerViewNextSpectatorStart;

    	// Server to client
    	unreliable if( Role == ROLE_Authority )
    		TribesLongClientAdjustPosition, TribesAdjustState, TribesShortClientAdjustPositionEx, TribesClientAdjustPositionEx,
    		clientAdjustTurretPosition, respawnDelay;

    	reliable if (Role == ROLE_Authority)
    		clientSetCheats, clientTribesSetHUD,
    		clientInventoryStationAccess, clientInventoryStationWait,
    		clientTerminateInventoryStationAccess,
    		clientGetSkinPreference,
    		clientSetSkinPreference,
    		clientWeaponUseEnergy,
    		clientLoadSkinClasses,
    		roundInfo,
    		ClientDamagedFrom,
    		PromptingObjectClass, PromptingObjectLocation, PromptingObjectPromptIndex, PromptingObjectCanBeUsed, CurrentUseableInventoryAccess, PromptingDataClass,
    		PlayPainSound;

    	reliable if (Role == ROLE_Authority && bNetOwner)
    		objectives, detectedFriendlyList, detectedEnemyList;
    }

    // Speedhack checking
    native final function bool CheckSpeedHack(float DeltaTime);

    function GameSaved()
    {
    	TeamMessage(None, Localize("Prompts", "MSG_Prompt_gamesaved", "Localisation\\GUI\\Prompts"), 'Announcer');
    }

    simulated function updateCachedKeyBindings()
    {
    	// dedicated server has no interaction master
    	if(Level.NetMode == NM_DedicatedServer)
    		return;

    	vehiclePositionSwitchOneKey = player.interactionMaster.getKeyFromBinding("switchVehiclePosition 1", true);
    	vehiclePositionSwitchTwoKey = player.interactionMaster.getKeyFromBinding("switchVehiclePosition 2", true);
    	vehiclePositionSwitchThreeKey = player.interactionMaster.getKeyFromBinding("switchVehiclePosition 3", true);

    	gameStatsKey = player.interactionMaster.getKeyFromBinding("ShowGameStats", true);
    	myStatsKey = player.interactionMaster.getKeyFromBinding("ShowMyStats", true);
    	adminKey = player.interactionMaster.getKeyFromBinding("ShowAdmin", true);
    	respawnKey = player.interactionMaster.getKeyFromBinding("Respawn true", true);
    	//Log("UpdatedCachedKeyBindings, "$gameStatsKey@myStatsKey@adminKey);
    }

    simulated function Destroyed()
    {
    	local int i;

    	DestroySensorLists();

    	if(HUDManager != None)
    		HUDManager.Cleanup();

    	PointsOfInterest.Length = 0;

    	for (i = 0; i < TribesFreeMoves.Length; i++)
    	{
    		TribesFreeMoves[i].Delete();
    	}
    	for (i = 0; i < TribesSavedMoves.Length; i++)
    	{
    		TribesSavedMoves[i].Delete();
    	}

    	super.Destroyed();
    }

    // Paul: Overriding ClientGotoState to not call it if we are already in the requested state
    function ClientGotoState(name NewState, optional name NewLabel)
    {
    	// only goto the state if we are not already in it or the new label is specified
    	if(! IsInState(NewState) || NewLabel != '')
    		GotoState(NewState,NewLabel);
    }

    function serverSetForcedRespawn(bool bForced)
    {
    	bForcedRespawn = bForced;
    }

    simulated function SetForcedRespawn(bool bForced)
    {
    	//Log("SetForcedRespawn called with "$bForced);
    	bForcedRespawn = bForced;
    	serverSetForcedRespawn(bForced);
    }

    // Sensor system functions /////////////////////////////////////////////////////////////////////////

    function DestroySensorLists()
    {
    	DestroySensorList(detectedFriendlyList);
    	DestroySensorList(detectedEnemyList);

    	detectedFriendlyList = None;
    	detectedEnemyList = None;
    }

    function DestroySensorList(SensorListNode head)
    {
    	local SensorListNode sln;
    	local SensorListNode dsln;

    	sln = head;

    	while (sln != None)
    	{
    		dsln = sln;
    		sln = dsln.next;
    		dsln.Destroy();
    	}
    }

    function int calculateHeight(float rookZ)
    {
    	local Vector pos;
    	local float height;
    	local float heightDiff;

    	if (Pawn != None)
    	{
    		pos = Pawn.Location;
    		height = Pawn.CollisionHeight * 2;
    	}
    	else
    	{
    		pos = Location;
    		height = 140;
    	}

    	heightDiff = rookZ - pos.Z;

    	if (heightDiff > height)
    		return 1;
    	else if (heightDiff < -height)
    		return -1;

    	return 0;
    }

    function bool isRookRelevant(Rook sensedRook)
    {
    	local Vector pos;
    	local float radarRadius;
    	local float distanceSquared2D;

    	if (commandHUDVisible)
    		return true;

    	if (Pawn != None)
    		pos = Pawn.Location;
    	else
    		pos = Location;

    	radarRadius = (radarZoomScale * Level.GetMapTextureExtent()) / 2.0;

    	distanceSquared2D = VSizeSquared2D(pos - sensedRook.Location);

    	return distanceSquared2D <= (radarRadius * radarRadius);
    }

    function addDetectedFriendly(Rook detectedFriendly)
    {
    	local SensorListNode sln;

    	if (Pawn != detectedFriendly && isRookRelevant(detectedFriendly))
    	{
    		sln = new class'SensorListNode'(self, detectedFriendly);

    		sln.next = detectedFriendlyList;
    		sln.prev = None;

    		if (detectedFriendlyList != None)
    			detectedFriendlyList.prev = sln;

    		detectedFriendlyList = sln;
    	}
    }

    function removeDetectedFriendly(SensorListNode sln)
    {
    	if (detectedFriendlyList == sln)
    		detectedFriendlyList = sln.next;

    	sln.detachNode();
    	sln.Destroy();
    }

    function addDetectedEnemy(Rook detectedEnemy)
    {
    	local SensorListNode sln;

    	if (isRookRelevant(detectedEnemy))
    	{
    		sln = new class'SensorListNode'(self, detectedEnemy);

    		sln.next = detectedEnemyList;
    		sln.prev = None;

    		if (detectedEnemyList != None)
    			detectedEnemyList.prev = sln;

    		detectedEnemyList = sln;
    	}
    }

    function removeDetectedEnemy(SensorListNode sln)
    {
    	if (detectedEnemyList == sln)
    		detectedEnemyList = sln.next;

    	sln.detachNode();
    	sln.Destroy();
    }

    // End sensor system functions /////////////////////////////////////////////////////////////////////

    // Skin functions //////////////////////////////////////////////////////////////////////////////////

    //
    // Loads the skin classes on the client
    //
    function clientLoadSkinClasses()
    {
    	class'SkinInfo'.static.loadAllSkins(Level);
    }

    // Asks the client for its skin preference
    // NOTE: this should not be used until the main menu "default mesh" gui is implemented.
    // Please set userSkinName in TribesReplicationInfo
    function clientGetSkinPreference(Mesh mesh)
    {
    	serverSetSkin(getSkinPreference(mesh), mesh);
    }

    // Tells the client to set a skin preference
    function clientSetSkinPreference(Mesh mesh, String skinPath)
    {
    	saveSkinPreference(mesh, skinPath);
    }

    // Sends a player's skin preference to the server
    // NOTE: this should not be used until the main menu "default mesh" gui is implemented.
    // Please set userSkinName in TribesReplicationInfo
    function serverSetSkin(string skinPath, Mesh mesh)
    {
    	if (GameInfo(Level.Game).allowSkinChanges())
    	{
    		saveSkinPreference(mesh, skinPath);
    		updateCharacterUserSkin();
    	}
    	else
    		LOG("Skin changes are not allowed by the game type");
    }

    // Updates the PRI with the correct user skin choice for a character
    // private, call clientGetSkinPreference
    private function updateCharacterUserSkin()
    {
    	local TribesReplicationInfo tri;

    	if (character == None)
    		return;

    	tri = TribesReplicationInfo(PlayerReplicationInfo);
    	if (tri != None)
    	{
    		tri.userSkinName = getSkinPreference(character.Mesh);
    	}
    }

    // get the player's skin preference for a given team and combat role. Returns the skin path.
    function string getSkinPreference(Mesh mesh)
    {
    	local int idx;
    	idx = getSkinPreferenceRecord(mesh);
    	if (idx != -1)
    	{
    		return skinPreferences[idx].skin;
    	}

    	return "";
    }

    // save a skin preference for a given team and combat role in the user setting
    function saveSkinPreference(Mesh mesh, string skinPath)
    {
    	local int idx;
    	idx = getSkinPreferenceRecord(mesh);
    	if (idx == -1)
    	{
    		addSkinPreferenceRecord(mesh, skinPath);
    	}
    	else
    	{
    		skinPreferences[idx].mesh = mesh;
    		skinPreferences[idx].skin = skinPath;
    	}

    	SaveConfig();
    }

    private function int getSkinPreferenceRecord(Mesh mesh)
    {
    	local int i;
    	for (i = 0; i < skinPreferences.Length; i++)
    	{
    		if (skinPreferences[i].mesh == mesh)
    			return i;
    	}

    	return -1;
    }

    private function int addSkinPreferenceRecord(Mesh mesh, string skinPath)
    {
    	skinPreferences.Length = skinPreferences.Length + 1;
    	skinPreferences[skinPreferences.Length - 1].mesh = mesh;
    	skinPreferences[skinPreferences.Length - 1].skin = skinPath;

    	return skinPreferences.Length - 1;
    }

    ///////////////////////////////////////////////////////////////////////////////
    //
    // check other TRI for absolute friendliness. Please don't change this
    // to use IsFriendly - it must return false if the other team is different
    // in any way to this controllers team - even if it is None.
    //
    function bool IsFriendlyPRI(PlayerReplicationInfo OtherPRI)
    {
    	// Check for None PRI, or the case where the PRI is not of type TRI. This should not happen,
    	// but adding this check avoids the spamming which may occur.
    	if(TribesReplicationInfo(OtherPRI) == None || TribesReplicationInfo(PlayerReplicationInfo) == None)
    		return false;

    	return TribesReplicationInfo(OtherPRI).Team == TribesReplicationInfo(PlayerReplicationInfo).Team;
    }

    ///////////////////////////////////////////////////////////////////////////////
    //
    // check other actor for friendliness
    simulated function bool IsFriendly(Actor Other)
    {
    	local TribesReplicationInfo TRI;
    	local TeamInfo OtherTeam;

    	if(Other == None)
    		return true;

    	if(Other.IsA('TeamInfo'))
    		OtherTeam = TeamInfo(Other);
    	else if(Other.IsA('Rook'))
    		OtherTeam = Rook(Other).team();
    	else if(Other.IsA('TribesReplicationInfo'))
    		OtherTeam = TribesReplicationInfo(Other).team;
    	else if(Other.IsA('PlayerController'))
    		OtherTeam = TribesReplicationInfo(PlayerController(Other).PlayerReplicationInfo).team;

    	TRI = TribesReplicationInfo(PlayerReplicationInfo);

    	if(OtherTeam == None || TRI == None || OtherTeam.IsFriendly(TRI.team))
    		return true;

    	return false;
    }

    simulated function TeamInfo GetControllerTeam()
    {
    	if(TribesReplicationInfo(PlayerReplicationInfo) != None)
    		return TribesReplicationInfo(PlayerReplicationInfo).team;

    	return None;
    }

    ///////////////////////////////////////////////////////////////////////////////

    simulated function clientWeaponUseEnergy(float quantity)
    {
    	if (Character != None)
    		Character.clientWeaponUseEnergy(quantity);
    }

    // Calculates the rotations required for turret processing. Rotations are stored directly on turret
    // (worldSpaceNoRollRotation, worldSpaceRotation, vehicleSpaceRotation).
    static native function DynamicTurretRotationProcessingOutput dynamicTurretRotationProcessing(rotator moveRotation,
    		rotator mountRotation, float minimumPitch, float maximumPitch, bool yawConstrained,
    		optional bool yawPositiveDirection, optional float yawStart, optional float yawRange);

    function serverCommandHUDShown()
    {
    	commandHUDVisible = true;
    }

    function serverCommandHUDHidden()
    {
    	commandHUDVisible = false;
    }

    function serverSetRadarZoomScale(float newRadarZoomScale)
    {
    	radarZoomScale = newRadarZoomScale;
    }

    //******************************************
    // Useable object & prompt methods

    ///////////////////////////////////////////////////////////////////////////////
    //
    // Udpates the current useable object by cycling over all the touching UseableObjects
    // and checking for the highest priority one. Called every tick to ensure that the
    // current Object does not get lost.
    //
    // The CurrentUseableObject is the object that the user will actually use when they
    // press their use key. The PromptingUseableObject is the object which is presenting
    // a prompt to the user. This will usually be the same as the CurrentUseableObject, but
    // in situations where the user is getting a prompt from an object which they CANNOT use,
    // we do not want the
    //
    function UpdateUseableObject()
    {
    	local UseableObject TestUseableObject;

    	// don't do this on clients
    	if(Role < ROLE_Authority)
    		return;

    	// Always set these to none before we process. It's important that we
    	// don't have one of these on the client if the user is not standing in one
    	CurrentUseableInventoryAccess = None;
    	CurrentUseableObject = None;
    	PromptingUseableObject = None;
    	PromptingObjectClass = None;
    	PromptingObjectCanBeUsed = false;
    	PromptingDataClass = None;

    	if(Character(Pawn) != None)
    	{
    		// check for a Useable object first, and get the highest priority one
    		ForEach Pawn.TouchingActors(class'UseableObject', TestUseableObject)
    		{
    			if(TestUseableObject.CanBeUsedBy(Pawn) && TestUseableObject.getCorrespondingInventoryStation() != None)
    				CurrentUseableInventoryAccess = TestUseableObject.getCorrespondingInventoryStation();

    			// Handle use always objects
    			if(TestUseableObject.bAlwaysUse)
    			{
    				if(TestUseableObject.CanBeUsedBy(Pawn))
    				{
    					CurrentUseableObject = TestUseableObject;
    					PromptingUseableObject = TestUseableObject;
    					break;
    				}
    				else
    				{
    					if (!TestUseableObject.bDoNotPromptWhenNotUseable)
    						PromptingUseableObject = TestUseableObject;
    				}
    			}

    			if(TestUseableObject.CanBeUsedBy(Pawn) && (CurrentUseableObject == None || CurrentUseableObject.priority < TestUseableObject.priority))
    				CurrentUseableObject = TestUseableObject;
    			if((PromptingUseableObject == None || PromptingUseableObject.priority < TestUseableObject.priority) && !TestUseableObject.bDoNotPromptWhenNotUseable)
    				PromptingUseableObject = TestUseableObject;
    		}
    	}

    	// Set the current prompting object data. These values will be replicated to the client.
    	if(PromptingUseableObject != None)
    	{
    		PromptingObjectClass = PromptingUseableObject.class;
    		PromptingObjectLocation = PromptingUseableObject.GetUseablePoint();
    		PromptingObjectPromptIndex = PromptingUseableObject.GetPromptIndex(Character(Pawn));
    		PromptingObjectCanBeUsed = (PromptingUseableObject == CurrentUseableObject);
    		PromptingDataClass = PromptingUseableObject.GetPromptDataClass();
    	}
    }

    ///////////////////////////////////////////////////////////////////////////////
    //
    // Returns whether the PlayerController can currently use a quick inventory
    // loadout menu. This is called when the user presses the key bound to quick
    // loadouts, in order to establish whether they can actually use one before
    // showing the menu.
    //
    simulated function bool CanUseQuickInventoryLoadoutMenu()
    {
    	if( ! IsSinglePlayer() &&
    		bLoadoutSelection == 1 &&
    		CurrentUseableInventoryAccess != None)
    			return true;

    	return false;
    }

    // End useable Object methods
    //
    //******************************************

    //
    // analogueToDigital
    //
    simulated static function EDigitalAxisInput analogueToDigital(float analogueInput, float maxValue)
    {
    	if (analogueInput > maxValue * 0.5)
    		return DAI_Positive;
    	if (analogueInput < -maxValue * 0.5)
    		return DAI_Negative;
    	return DAI_Zero;
    }

    //
    // digitalToAnalogue
    //
    simulated static function float digitalToAnalogue(EDigitalAxisInput digitalInput, float maxValue)
    {
    	if (digitalInput == DAI_Positive)
    		return maxValue;
    	if (digitalInput == DAI_Negative)
    		return -maxValue;
    	return 0;
    }

    //
    // Resets the input values for the controller. Should be called whenever the player is doing
    // something which may result in input sticking (eg: opening an inventory station interface
    // while firing or skiing results in that input being stuck on when the player exits)
    //
    simulated function ResetInputState()
    {
    	// this list may not be complete, add any values
    	// which might need to be reset if they are missing
    	bSki = 0;
    	bJetpack = 0;
    	bJump = 0;
    	bFire = 0;
    	bAltFire = 0;
    	bQuickChat = 0;
    	bLoadoutSelection = 0;
    	if(character != None && character.motor != None)
    	{
    		character.motor.releaseFire();
    		character.motor.releaseAltFire();
    	}
    }

    function showTalkingHead(TalkingHeadCamera thc, Script requestingScript)
    {
    	if (currentTalkingHeadCam != None)
    		currentTalkingHeadCam.stop();

    	currentTalkingHeadCam = thc;
    	talkingHeadScript = requestingScript;

    	currentTalkingHeadCam.play();
    	clientSideChar.aHeadIsTalking = true;
    }

    function hideTalkingHead(Script requestingScript)
    {
    	if (talkingHeadScript != None && talkingHeadScript != requestingScript)
    		return;

    	if (currentTalkingHeadCam != None)
    		currentTalkingHeadCam.stop();

    	currentTalkingHeadCam = None;

    	clientSideChar.aHeadIsTalking = false;
    }

    // updateCasts
    // Do your derived-class casts here, or they will not update properly on network clients
    simulated function updateCasts()
    {
    	Rook = Rook(Pawn);

    	if (Rook != None)
    		Character = Rook.getControllingCharacter();
    }

    function playerDisconnected()
    {
    	if (character != None)
    		character.Died(None, class'DamageType', Vect(0,0,0));
    }

    // glenn: test

    /*
    exec function stop()
    {
        character.unifiedSetVelocity(vect(0,0,0));
    }
    */

    exec function Fire(optional float F)
    {
    	// code is here instead of TribesPlayerWalking to support flying state
    	if (character != None && character.motor != None)
    	{
    		character.motor.bFirePressed = true;
    		character.motor.fire();
    	}
    }

    // called when fire is released
    exec function releaseFire(optional float F)
    {
    	// code is here instead of TribesPlayerWalking to support flying state
    	if (character != None && character.motor != None)
    	{
    		character.motor.bFirePressed = false;
    		character.motor.releaseFire();
    	}
    }

    exec function AltFire(optional float F)
    {
    	// code is here instead of TribesPlayerWalking to support flying state
    	if (character != None && character.motor != None)
    	{
    		character.motor.altFire();
    	}
    }

    exec function releaseAltFire(optional float F)
    {
    	// code is here instead of TribesPlayerWalking to support flying state
    	if (character != None && character.motor != None)
    	{
    		character.motor.releaseAltFire();
    	}
    }

    // called when jetpack is pressed
    exec function Jetpack( optional float F )
    {
    }

    function SelectTeleport( )
    {
    	clientGotoState('PlayerTeleport');
    	GotoState('PlayerTeleport');
    }

    exec function Respawn( optional bool bAllowExit )
    {
    	local bool bAllowManualRespawn;

    	if (IsSinglePlayer())
    		bAllowManualRespawn = GameInfo(Level.Game).allowManualRespawn();
    	else
    		bAllowManualRespawn = true;

    	if (bAllowManualRespawn)
    	{
    		updateCachedKeyBindings();
    		SetForcedRespawn(bAllowExit);
    		bForcedRespawn = true;
    		ServerPlayerSelectRespawn();
    	}
    }

    simulated function initHUDObjects()
    {
    	if(HUDManager == None)
    	{
    		HUDManager = new class'TribesHUDManager';
    		HUDManager.Initialise(self);
    	}

    	if(clientSideChar == None)
    		clientSideChar = new class'ClientSideCharacter';
    }

    // PostBeginPlay
    simulated function PostBeginPlay()
    {
    	camera = new class'PlayerCamera';
    	camera.pcc = self;

    	if( Level.GetLocalPlayerController() == self )
    		initHUDObjects();

    	// cache localplayercontroller (as it's often used in native code)
    	Level.GetLocalPlayerController();

    	Super.PostBeginPlay();

    	// Spawn objective list on server
    	if (Level.NetMode != NM_CLIENT)
    		objectives = spawn(class'ObjectivesList');

    	updateCasts();

    	alertnessMode = AlertnessMode_Default;

        EnterCombat();
    }

    function PostLoadGame()
    {
    	super.PostLoadGame();
    	initHUDObjects();
    }

    // PostNetReceive
    simulated function PostNetReceive()
    {
    	super.PostNetReceive();

    	updateCasts();

    	// see comment in clientInventoryStationAccess
    	if (inventoryStationWaitingForCharacter && Character(Pawn) != None)
    	{
    		inventoryStationWaitingForCharacter = false;
    		clientInventoryStationAccess(inventoryStationWaitingForCharacterInput);
    	}
    }

    function bool HasCurrentLoadout()
    {
    	return (currentLoadout != None);
    }

    // newLoadout
    function newLoadout(Loadout l)
    {
    	if(currentLoadout == l)
    		return;

    	if (currentLoadout != None)
    		currentLoadout = None;

    	currentLoadout = l;
    }

    // equipCharacter
    function equipCharacter()
    {
    	if (currentLoadout != None && Character(Pawn) != None)
    		currentLoadout.equip(Character(Pawn));
    }

    function ClientRestart(Pawn aPawn, Name currentState)
    {
    	bJustRespawned = true;

    	//Log("Parent ClientRestart() called for "$self$" and pawn "$aPawn);
    	super.ClientRestart(aPawn, currentState);

    	updateCasts();
    }

    // Possess
    function Possess(Pawn aPawn)
    {
    	if ( PlayerReplicationInfo.bOnlySpectator )
    		return;

    	Pawn = aPawn;

    	updateCasts();

    	if (rook != None)
    	{
    		// need this to prevent incorrect stasis on player rooks
    		rook.AI_LOD_Level = AILOD_ALWAYS_ON;

    		if (!rook.isAlive())
    			GotoState('Dead');
    		else if (rook.playerControllerState != '')
    			GotoState(rook.playerControllerState);
    	}

    	// REMOVE
    	//Level.Game.SetGameSpeed(0.01);

    	ResetSpeedhack();

    	Super.Possess(aPawn);

    	serverSetRadarZoomScale(radarZoomScales[radarZoomIndex]);
    }

    // UnPossess
    function UnPossess()
    {
    	Super.UnPossess();

    	updateCasts();
    }

    // PawnDied
    function PawnDied(Pawn P)
    {
    	Super.PawnDied(P);

    	updateCasts();
    }

    simulated function Vector calculateScreenPosition(class objectClass, Vector objectPos)
    {
    	local Vector screenPos;

    	screenPos = objectPos;
    	if(ClassIsChildOf(objectClass, class'RadarInfo'))
    		screenPos += class<RadarInfo>(objectClass).default.markerOffset;

    	if(! WorldToScreen(screenPos))
    	{
    		// The vector is behind us
    		screenPos.x = -1;
    		screenPos.y = -1;
    	}

    	return screenPos;
    }

    //
    // Converts a vector from world space to screen space, but ensures
    // that the world position of the vector is actually in front of
    // the player first, and returns false if it wasnt.
    //
    simulated function bool WorldToScreen(out Vector inputVector)
    {
    	local Vector xAxis, yAxis, zAxis;
    	local Interaction interaction;

    	if(Player.LocalInteractions.Length <= 0)
    		return false;

    	interaction = Player.LocalInteractions[Player.LocalInteractions.Length - 1];
    	if(interaction != None && Rook != None)
    	{
    		// dont add anything behind us
    		GetAxes(Normalize(Rotation), xAxis, yAxis, zAxis);
    		if(((Rook.location - inputVector) Dot xAxis) < 0)
    		{
    			// its in front of us, now we can determine its height
    			// and convert it to screen space
    			inputVector = interaction.WorldToScreen(inputVector);
    			return true;
    		}
    	}

    	inputVector.X = -1;
    	inputVector.Y = -1;
    	return false;
    }

    // ClientSetHUD
    // Stores the HUD class so that the HUD can be restored when loading a saved game
    function ClientSetHUD(class<HUD> newHUDType, optional class<Scoreboard> newScoringType)
    {
    	LOG("ClientSetHUD deprecated: use clientTribesSetHUD");
    }

    function clientTribesSetHUD(string newHUDType)
    {
    	// just call the SetHUD() in the hudmanager and it handles the rest
    	if(HUDManager != None)
    		HUDManager.SetHUD(newHUDType);

    }

    // checkAutoWeaponSwitch
    // Check if a weapon needs to be automatically equipped or switched for any reason
    function checkAutoWeaponSwitch()
    {
    	if (character == None || character.motor == None)
    		return;

    	// check if the deployable we were using has been depleted
    	if (bWasUsingDeployable && (character.deployable == None || character.deployable.bDeployed))
    	{
    		serverSelectWeapon(character.motor.lastUsedWeapon);
    	}
    	else if (character.motor.switchToWeapon == None && character.weapon == None && character.deployable == None && character.motor.switchToDeployable == None)
    	{
    		// player should always be holding something
    		NextWeapon();

    		// If the player still has no weapon go to the fallback weapon
    		if (character.motor.switchToWeapon == None && character.weapon == None)
    			serverEquipFallbackWeapon();
    	}

    	bWasUsingDeployable = character.deployable != None && !character.deployable.bDeployed;
    }

    function serverEquipFallbackWeapon()
    {
    	character.equipFallbackWeapon();
    }

    // DisplayDebug
    simulated function DisplayDebug(Canvas Canvas, out float YL, out float YPos)
    {
    	local int i;

    	//Super.DisplayDebug(Canvas, YL, YPos);

    	YPos += YL;
    	YPos += YL;
    	Canvas.Style = ERenderStyle.STY_Normal;
    	Canvas.SetPos(4,YPos);
    	Canvas.DrawText("Playercontroller state: "$GetStateName());
    	YPos += YL;

    	for (i = max(0, TribesSavedMoves.Length - 10); i < TribesSavedMoves.Length; i++)
    	{
    		Canvas.DrawText(""$TribesSavedMoves[i].Timestamp$":  "$TribesSavedMoves[i].SavedLocation);
    	}
    }

    // voting console commands

    exec function kickvote(string name)
    {
        if (voteReplicationInfo!=None)
        {
            log("sending kick vote: "$name);
            voteReplicationInfo.SubmitKickVote(name);
        }
        else
            log("none voteReplicationInfo!");
    }

    exec function mapvote(string map, string gametype)
    {
        if (voteReplicationInfo!=None)
        {
            log("sending map vote: "$map$" ["$gametype$"]");
            voteReplicationInfo.SubmitMapVote(map, gametype);
        }
        else
            log("none voteReplicationInfo!");
    }

    exec function adminvote(string name)
    {
        if (voteReplicationInfo!=None)
        {
            log("sending admin vote: "$name);
            voteReplicationInfo.SubmitAdminVote(name);
        }
        else
            log("none voteReplicationInfo!");
    }

    exec function teamdamagevote(bool vote)
    {
        if (voteReplicationInfo!=None)
        {
            log("sending team damage vote: "$vote);
            voteReplicationInfo.SubmitTeamDamageVote(vote);
        }
        else
            log("none voteReplicationInfo!");
    }

    exec function tournamentvote(bool vote)
    {
        if (voteReplicationInfo!=None)
        {
            log("sending tournament vote: "$vote);
            voteReplicationInfo.SubmitTournamentVote(vote);
        }
        else
            log("none voteReplicationInfo!");
    }

    // force movement configuration (global)

    exec function Movement(String name)
    {
    	character.prefixMovement(name);
    	updatePhysicsConfiguration();
    }

    // force movement configuration (global)

    exec function Force(String name)
    {
    	character.forceMovement(name);
    	updatePhysicsConfiguration();
    }

    // debug hud functionality

    exec function toggleDebugHUD()
    {
    	HUDManager.showDebugHUD(!inDebugHud());
    }

    function setDebugHud(bool visible)
    {
        HUDManager.showDebugHUD(visible);
    }

    function bool inDebugHud()
    {
        return HUDManager.IsInState('ShowingDebugHUD');
    }

    exec function debugAnimation()
    {
        animationDebug();
    }

    exec function animationDebug()
    {
    	animationDebugCounter ++;

    	if (animationDebugCounter>2)
    	    animationDebugCounter = 0;

    	if (animationDebugCounter>0 && movementDebugCounter>0)
    	{
    	    character.debugMovement(false);
    	    movementDebugCounter = 0;
    	}

    	ClientSetBehindView(animationDebugCounter>0);

        setDebugHud(animationDebugCounter>0 || movementDebugCounter>0);
    }

    exec function debugMovement()
    {
        movementDebugCounter ++;

        if (movementDebugCounter>2)
            movementDebugCounter = 0;

        character.debugMovement(movementDebugCounter>0);

        if (movementDebugCounter>0)
        {
            animationDebugCounter = 0;
        	ClientSetBehindView(false);
        }

        setDebugHud(animationDebugCounter>0 || movementDebugCounter>0);
    }

    exec function movementDebug()
    {
        debugMovement();
    }

    // animation testing functions

    exec function playAnimation(string animation)
    {
        character.playAnimation(animation);
    }

    exec function loopAnimation(string animation)
    {
        character.loopAnimation(animation);
    }

    exec function stopAnimation()
    {
        character.stopAnimation();
    }

    exec function isPlayingAnimation()
    {
        log(character.isPlayingAnimation());
    }

    exec function isLoopingAnimation()
    {
        log(character.isLoopingAnimation());
    }

    exec function playFireAnimation(optional string weapon)
    {
        character.playFireAnimation(weapon);
    }

    exec function playUpperBodyAnimation(string animation)
    {
        character.playUpperBodyAnimation(animation);
    }

    exec function loopUpperBodyAnimation(string animation)
    {
        character.loopUpperBodyAnimation(animation);
    }

    exec function stopUpperBodyAnimation()
    {
        character.stopUpperBodyAnimation();
    }

    exec function isPlayingUpperBodyAnimation()
    {
        log(character.isPlayingUpperBodyAnimation());
    }

    exec function isLoopingUpperBodyAnimation()
    {
        log(character.isLoopingUpperBodyAnimation());
    }

    exec function loopArmAnimation(string animation)
    {
        character.loopArmAnimation(animation);
    }

    exec function stopArmAnimation()
    {
        character.stopArmAnimation();
    }

    exec function isLoopingArmAnimation()
    {
        log(character.isLoopingArmAnimation());
    }

    exec function playFlinchAnimation()
    {
        character.playFlinchAnimation();
    }

    exec function setAlertness(string mode)
    {
    	if (mode=="default")
    		alertnessMode = AlertnessMode_Default;
    	else if (mode=="combat")
    	{
    		alertnessMode = AlertnessMode_Combat;
    		character.alertness = Alertness_Combat;
    	}
    	else if (mode=="alert")
    	{
    		alertnessMode = AlertnessMode_Alert;
    		character.alertness = Alertness_Alert;
    	}
    	else if (mode=="neutral")
    	{
    		alertnessMode = AlertnessMode_Neutral;
    		character.alertness = Alertness_Neutral;
    	}
    }

    exec function setGroundMovement(string mode)
    {
    	if (mode~="stand")
    		groundMovementMode = GroundMovementMode_Stand;
    	else if (mode~="walk")
    		groundMovementMode = GroundMovementMode_Walk;
    	else if (mode~="run")
    		groundMovementMode = GroundMovementMode_Run;
    	else if (mode~="sprint")
    		groundMovementMode = GroundMovementMode_Sprint;
    	else
    		groundMovementMode = GroundMovementMode_Any;
    }

    exec function updatePhysicsConfiguration()
    {
    	level.UpdateMovementConfiguration();
    }

    // effect logging
    exec function effectLog()
    {
    	character.effectLogging = !character.effectLogging;
    }

    // whack off
    exec function whack()
    {
        character.addImpulse(Vect(250000, 0, 0) >> Rotation);
    }

    // UI
    function bool isSinglePlayer()
    {
    	return Level.Game != None && SinglePlayerGameInfo(Level.Game) != None;
    }

    exec function bool SkipOpeningCutscene()
    {
    	return false;
    }

    exec function showEscapeMenu()
    {
    	// try to escape any playing cutscenes

    	if (!Level.EscapeCutscene() && !SkipOpeningCutscene())
    	{
    		// force updateing of hotkeys, just incase they
    		// change their controls in the escape menu
    		if (isSinglePlayer())
    			Player.GUIController.OpenMenu(GUIPackage $ "." $ SPEscapeMenuClass, SPEscapeMenuClass);
    		else
    		// It's an MP game.
    			Player.GUIController.OpenMenu(GUIPackage $ "." $ MPEscapeMenuClass, MPEscapeMenuClass);
    	}
    }

    function toggleEscapePanel(string menuClass)
    {
    	local GUIController gc;

    	gc = GUIController(Player.GUIController);

    	if (!isSinglePlayer())
    	{
    		updateCachedKeyBindings();
    		//Log("Comparing "$gc.ActivePage.Class.Name$" to "$Name(MPEscapeMenuClass));
    		if (gc.ActivePage != None)
    			Player.GUIController.CloseMenu();
    		else
    			Player.GUIController.OpenMenu(GUIPackage $ "." $ MPEscapeMenuClass, MPEscapeMenuClass, menuClass);
    	}
    }

    exec function showMyStats()
    {
    	toggleEscapePanel(MPStatsClass);
    }

    exec function showWeaponStats()
    {
    	toggleEscapePanel(MPWeaponStatsClass);
    }

    exec function showGameStats()
    {
    	toggleEscapePanel(MPGameStatsClass);
    }

    exec function showAdmin()
    {
    	toggleEscapePanel(MPAdminClass);
    }

    // Character Movement state.
    // This is the state that an active moving player is in while in PHYS_Movement.

    simulated state CharacterMovement
    {
    	ignores SeePlayer, HearNoise, Bump;

    	exec function Fire( optional float F )
    	{
    		// freeze player during cutscenes
    		if (isInCutscene())
    			return;
    		Global.Fire(F);
    	}

    	exec function AltFire(optional float F)
    	{
    		// freeze player during cutscenes
    		if (isInCutscene())
    			return;
    		Global.AltFire(F);
    	}

    	function bool NotifyPhysicsVolumeChange( PhysicsVolume NewVolume )
    	{
    		return false;
    	}

    	exec function DropWeapon()
    	{
    		if (character != None)
    		{
    			character.dropWeapon();
    		}
    	}

    	///
    	/// ServerUse()
    	///
    	/// Called when the user presses the use button. Overriden here because we
    	/// want to ensure that we only use the objects of type 'UseableObject' when
    	/// it has the higher priority.
    	///
    	function ServerUse()
    	{
    		if ( Level.Pauser == PlayerReplicationInfo )
    		{
    			SetPause(false);
    			return;
    		}

    		if (Pawn==None)
    			return;

    		// if we have a useable object, then Use it & return
    		if(currentUseableObject != None)
    		{
    			currentUseableObject.UsedBy(Pawn);
    			return;
    		}
    		else if(character.potentialEquipment != None && !character.potentialEquipment.bDeleteMe)
    		{
    			character.switchEquipment();
    			return;
    		}
    	}

    	function ProcessMove(float DeltaTime, vector NewAccel, EDoubleClickDir DoubleClickMove, rotator DeltaRot)
    	{
    		Log("WARNING: PlayerCharacterController.CharacterMovement.ProcessMove has been deprecated");
    	}

    	function TribesProcessMove(float forward, float strafe, float jump, float ski, float thrust)
    	{
    		if (Character.motor != None)
    			Character.motor.moveCharacter(forward, strafe, jump, ski, thrust, GroundMovementLevels(groundMovementMode));
    	}

    	function PlayerMove(float DeltaTime)
    	{
    		local vector x,y,z;
    		local Rotator ViewRotation;
    		local float incYaw, incPitch;
    		local float jump, ski, thrust;

    		// Had problem where client would not change to PlayerUsingInventoryStation when using Buggy. They would occasionally be in the
    		// Buggy (PHYS_None) yet still be in this state. By adding the following code the server shall send down state updates meaning
    		// that the client is guaranteed to eventually go to PlayerUsingInventoryStation.
    		if (character.Physics == PHYS_None && Role < ROLE_Authority)
    			TribesStateServerMove(Level.TimeSeconds);

    		if (character == None || character.Physics != PHYS_Movement)
    			return;

    		// freeze player during cutscenes
    		if (isInCutscene())
    		{
    			releaseFire();
    			TribesProcessMove(0, 0, 0, 0, 0);
    			return;
    		}

    		GetAxes(Rotation,x,y,z);

    		Pawn.CheckBob(DeltaTime, y);

    		ViewRotation = character.motor.getViewRotation();
    		incYaw = 32.0 * DeltaTime * aTurn;
    		incPitch = 32.0 * DeltaTime * aLookUp;
    		if (character.isZoomed())
    		{
    			incYaw *= zoomedMouseScale[zoomLevel];
    			incPitch *= zoomedMouseScale[zoomLevel];
    		}

    		ViewRotation.Yaw += incYaw;
    		ViewRotation.Pitch += incPitch;

    		character.motor.setMoveRotation(ViewRotation);
    		character.motor.setViewRotation(ViewRotation);

    		// zoom
    		if (character.motor != None)
    			character.motor.setZoomed(bZoom != 0);

    		if (Role < ROLE_Authority)
    		{
    			TribesReplicateMove(aForward / 24000, aStrafe / 24000, bSki == 1 && character != None && !character.bDisableSkiing,
    					bJetpack == 1 && character != None && !character.bDisableJetting, bJump == 1);
    		}
    		else
    		{
    			if (bJump>0)
        			jump = 1.0;
    	   		else
    			    jump = 0.0;

    			if (bSki>0 && character != None && !character.bDisableSkiing)
    				ski = 1.0;
    			else
    				ski = 0.0;

    			if (bJetpack>0 && character != None && !character.bDisableJetting)
    				thrust = 1.0;
    			else
    				thrust = 0.0;

    			TribesProcessMove(aForward / 24000, aStrafe / 24000, jump, ski, thrust);
    		}
    	}

    	function BeginState()
    	{
    		CleanOutSavedMoves();

    		PlayerReplicationInfo.bWaitingPlayer = false;

    		ResetSpeedhack();

    		//if(Role == ROLE_Authority)
    		//	log("Server: Player put in CharacterMovement with pawn "$Pawn);
    		//else
    		//	log("Client: Player put in CharacterMovement with pawn "$Pawn);
    	}

    	function EndState()
    	{
    		GroundPitch = 0;

    		if (Character != None && Character.motor != None)
    			Character.motor.moveCharacter();

    		FOVAngle = DefaultFOV;
    	}

    	// client + listen-server
    	function PlayerTick(float Delta)
    	{
    		if (bJustRespawned && character.bZoomOutOnSpawn)
    		{
    			camera.firstToThirdTransition(0.1, 0.5, 0.5);
    		}

    		if (armorClassBeforeInventoryAccess != character.armorClass && !bBehindView)
    		{
    			armorClassBeforeInventoryAccess = character.armorClass;

    			if (!bJustRespawned && !camera.isTransitioning())
    				camera.firstToThirdTransition(0.1, 0.5, 0.5);
    		}

    		Global.PlayerTick(Delta);

            if (bZoom!=0)
                EnterCombat();

    		ProcessZoom(Delta, character);

    		// MJ:  This shouldn't be necessary...it was causing players to unpredictably go to PlayerRespawn state
    		//      Leaving it here in case it turns out it was necessary.
    		// go to spectator mode when pawn is destroyed
    		// if pawn is destroyed before bTearOff is checked, nothing takes the player controller to the dying state
    		//if (Level.NetMode != NM_Client && bIsPlayer && Pawn == None)
    		//{
    		//	GotoState(GameInfo(Level.Game).playerPawnDestroyedState());
    		//	ClientGotoState(GameInfo(Level.Game).playerPawnDestroyedState());
    		//}
    	}

    	// server-side only (clients use PlayerTick)
    	function Tick(float Delta)
    	{
    		Global.Tick(Delta);
    		checkAutoWeaponSwitch();

    		UpdateUseableObject();

    		// had a problem with characters being invisible and invulnerable - added this code to address the problem after it occurred
    		if (Pawn != None && Pawn.Physics == PHYS_Movement && (Level.NetMode == NM_ListenServer || Level.NetMode == NM_DedicatedServer))
    		{
    			if (Pawn.DrawType == DT_None)
    			{
    				warn(Pawn @ "controlled by" @ self @ "had draw type none despite being in the normal movement state");
    				Pawn.setDrawType(DT_Mesh);
    			}
    			if (Pawn.bHidden)
    			{
    				warn(Pawn @ "controlled by" @ self @ "was bHidden despite being in the normal movement state");
    				Pawn.bHidden = false;
    			}
    			if (character != None && character.bHiddenVehicleOccupant)
    			{
    				warn(character @ "controlled by" @ self @ "was bHiddenVehicleOccupant despite being in the normal movement state");
    				character.bHiddenVehicleOccupant = false;
    			}
    		}
    	}

    	function ServerMove
    		(
    		float TimeStamp,
    		vector InAccel,
    		vector ClientLoc,
    		bool NewbRun,
    		bool NewbDuck,
    		bool NewbJumpStatus,
    		bool NewbDoubleJump,
    		EDoubleClickDir DoubleClickMove,
    		byte ClientRoll,
    		int View,
    		bool NewbJetpack,
    		optional byte OldTimeDelta,
    		optional int OldAccel
    		)
    	{
    		// do nothing, occurs when character spawns on server and client continues to send spectator moves
    	}

    Begin:
    	// this fixes a network crash
    	// because of packetloss, it's possible for the state to be changed to CharacterMovement before the controller's
    	// 'Pawn' variable is received, potentially placing non-character objects in PHYS_Movement... fusion doesn't like that
        while (Character(Pawn) == None)
    		Sleep(0);
    	Pawn.SetPhysics(PHYS_Movement);

    	updateCasts();

    	clientTribesSetHUD(character.hudType);

    	character.wake();

    	character.resetMovementAnimations();
    }

    // PlayerTick
    event PlayerTick(float DeltaTime)
    {
    	Super.PlayerTick(DeltaTime);

    	if (lowPriorityPromptTimeout > 0)
    		lowPriorityPromptTimeout -= DeltaTime;

    	// duplicated in Tick for a reason
    	camera.update(DeltaTime);

    	ViewShake(DeltaTime);
    	ViewFlash(DeltaTime);

    	Rook = Rook(Pawn);
    	Character = Character(Pawn);

    	doIdentify(DeltaTime);

    	if (Pawn != None && Pawn.controller != None)
    		level.AI_Setup.doPlayerRelatedAIProcessing(DeltaTime, Pawn);

    	if(HUDManager != None && Level.GetLocalPlayerController() == self )
    		HUDManager.Update();

    	if (bCountDown)
    	{
    		if (countDown > 0.0)
    		{
    			countDown -= DeltaTime;

    			if (countDown <= 0.0)
    			{
    				Level.Game.dispatchMessage(new class'MessageCountDownExpired');
    				countDown = 0.0;
    			}
    		}
    	}

    	if(HUDManager != None)
    		HUDManager.UpdateHUDData();

    	// clear this array now, because we should be done with it.
    	RenderedRooks.remove(0, RenderedRooks.Length);

    	bJustRespawned = false;
    }

    //
    // GetIdentify
    // Return the actor data used for identifying a given actor, if any
    //
    simulated function Actor GetIdentify()
    {
    	if( (Character(lastIdentified) != None && Character(lastIdentified).isAlive()) ||
    		(lastIdentified != None && lastIdentified.IsA('SkelRookSatelliteDish') ) ||	// Super hack: the sat dishes for sp showed no health
    		(BaseDevice(lastIdentified) != None) ||
    		(Vehicle(lastIdentified) != None) ||
    		(AccessTerminal(lastIdentified) != None) ||
    		(MPActor(lastIdentified) != None))
    			return lastIdentified;

    	return None;
    }

    function UpdateScreenRes()
    {
    	local String CurrentRes;
    	local int i;

    	CurrentRes = ConsoleCommand("GETCURRENTRES");
    	if(CurrentRes != ResolutionString)
    	{
    		ResolutionString = CurrentRes;
    		i = InStr( ResolutionString, "x" );
    		if( i > 0 )
    		{
    			ResolutionX = int( Left ( ResolutionString, i )  );
    			ResolutionY = int( Mid( ResolutionString, i+1 ) );
    		}
    	}
    }

    // doIdentify
    simulated function doIdentify(float delta)
    {
    	local Vector startTrace, hitNormal, endTrace, ScreenPos, ScreenCenter;
    	local Actor hitTest, hit;
    	local float traceRange, ActorRadiusDistance, ShortestHitDistance, CurrentHitDistance;
    	local int i;

    	if(Pawn == None)
    		return;

    	m_identifyTime += delta;

    	if (m_identifyTime > m_identifyFrequency)
    	{
    		// Closest one yet: check it can be hit with a line check
    		// extend trace range while zoomed
    		traceRange = m_identifyRange;
    		if (bZoom != 0)
    			traceRange *= zoomLevel + 2;

    		startTrace = Pawn.Location + Pawn.EyePosition();
    		endTrace = startTrace + Vector(rotation) * traceRange;
    		hit = Pawn.Trace(lastIdentifiedHitLocation, hitNormal, endTrace, startTrace, true);

    		// init shortest hit to some massive value
    		ShortestHitDistance = 9999999999.0;
    		if(hit != None)
    			ShortestHitDistance = VSize(hit.Location - Location);

    		// this ensures the resolution is set
    		UpdateScreenRes();
    		// make a vector to represent the center of the screen
    		ScreenCenter.X = ResolutionX * 0.5;
    		ScreenCenter.Y = ResolutionY * 0.5;
    		ScreenCenter.Z = 0;

    		for(i = 0; i < RenderedRooks.Length; ++i)
    		{
    			ScreenPos = RenderedRooks[i].Location;
    			if(WorldToScreen(ScreenPos))
    			{
    				// The Actor is in front of the player, check if they are in the zone
    				ScreenPos.Z = 0;
    				ActorRadiusDistance = VSize2D(ScreenCenter - ScreenPos);

    				if(ActorRadiusDistance < IdentifyRadius)
    				{
    					CurrentHitDistance = VSize(RenderedRooks[i].Location - Pawn.Location);
    					// in the zone, see if its close than the last one
    					if(CurrentHitDistance < ShortestHitDistance)
    					{
    						// Closest one yet: check it can be hit with a line check
    						hitTest = Pawn.Trace(lastIdentifiedHitLocation, hitNormal, RenderedRooks[i].Location, Pawn.Location + Pawn.EyePosition(), true);
    						if(hitTest == RenderedRooks[i])
    						{
    							if(hitTest.IsA('InventoryStationPlatform'))
    								hit = hitTest.Base;
    							else
    								hit = hitTest;
    							ShortestHitDistance = CurrentHitDistance;
    						}
    					}
    				}
    			}
    		}

    		UpdateCasts();

    		// dont register our own stuff
    		if(hit == Pawn || hit == self || hit == character)
    			hit = None;

    		// update the duration this was displayed unchanged
    		if ( hit == lastIdentified )
    		{
    			lastIdentifiedDuration += m_identifyTime;
    		}
    		else
    		{
    			lastIdentified = hit;
    			lastIdentifiedDuration = 0;
    		}

    		m_identifyTime = 0;
    	}
    }

    // checkForFireButton
    function checkForFireButton()
    {
    }

    // AddCheats
    // spawn the cheat manager
    function AddCheats()
    {
    	if (CheatManager==None && Level.Game!=None)
    		CheatManager = new(self)GameInfo(Level.Game).CheatClass;
    }

    function clientSetCheats(class<CheatManager> c)
    {
    	if ( CheatManager == None )
    		CheatManager = new(self)c;
    }

    // Networking functions /////////////////////////////////////////////////////////////////////////////////////////////////////
    // TribesGetFreeMove
    // Returns a free move from the free move store, or allocates a new move
    function SavedMove TribesGetFreeMove()
    {
    	local SavedMove s;

    	if ( TribesFreeMoves.Length == 0 )
    	{
            // don't allow more than 100 saved moves
            if ( TribesSavedMoves.Length > 100 )
    		{
    			TribesFreeMoves = TribesSavedMoves;

    			while (TribesSavedMoves.Length > 0)
    			{
    				TribesSavedMoves[0].Clear();
    				PopSavedMove();
    			}
    		}
    		else
    		{
    			return new class'SavedMove';
    		}
    	}

    	s = TribesFreeMoves[0];
    	PopFreeMove();
    	return s;
    }

    // PopFreeMove
    function PopFreeMove()
    {
    	TribesFreeMoves.Remove(0, 1);
    }

    // AppendFreeMove
    function AppendFreeMove(SavedMove m)
    {
    	TribesFreeMoves[TribesFreeMoves.Length] = m;
    }

    // PopSavedMove
    function PopSavedMove()
    {
    	TribesSavedMoves.Remove(0, 1);
    }

    // AppendSavedMove
    function AppendSavedMove(SavedMove m)
    {
    	TribesSavedMoves[TribesSavedMoves.Length] = m;
    }

    // CleanOutSavedMoves
    function CleanOutSavedMoves()
    {
    	super.CleanOutSavedMoves();

    	// clean out saved moves
    	while ( TribesSavedMoves.Length > 0 )
    	{
    		TribesSavedMoves[0].Delete();
    		PopSavedMove();
    	}
    	if ( TribesPendingMove != None )
    	{
    		TribesPendingMove.Delete();
    		TribesPendingMove = None;
    	}
    }

    // TribesReplicateMove
    function TribesReplicateMove(float forward, float strafe, bool ski, bool thrust, bool jump)
    {
    	local int i;
    	local SavedMove NewMove, ImportantMove;
    	local float NetMoveDelta;
    	local byte ImportantTimeDelta;
    	local int ImportantData;
    	local vector MoveLoc;
    	local float DeltaTime;

    	if (bDemoOwner)
    		return;

    	// if first move, server will have no previous timestamp to form delta, so send Level.TimeSeconds to use as delta and don't move
    	if ( lastReplicationCallTime == 0 )
    	{
    		if (debugLogLevel > 0)
    			LOG("CLIENT FIRST MOVE!");
    		lastReplicationCallTime = Level.TimeSeconds;
    		TribesShortServerMove(Level.TimeSeconds, Vect(0,0,0), 0);
    		return;
    	}

    	DeltaTime = FMin(MaxResponseTime, Level.TimeSeconds - lastReplicationCallTime);
    	lastReplicationCallTime = Level.TimeSeconds;

    	// find the most recent important move
    	if ( TribesSavedMoves.Length > 0 )
    	{
    		for (i = TribesSavedMoves.Length - 1; i >= 0; i--)
    		{
    			// find most recent important move to send redundantly
    			if ( TribesSavedMoves[i].isImportant(Rotation, thrust, jump, ski, forward, strafe) )
    			{
    				ImportantMove = TribesSavedMoves[i];
    				break;
    			}
    		}
    	}

        // Get a SavedMove actor to store the movement in.
    	NewMove = TribesGetFreeMove();
    	if ( NewMove == None )
    		return;

    	if (bDebugSpeedhack)
    		NewMove.SetMoveFor(Level.TimeSeconds * 2, self, DeltaTime, forward, strafe);
    	else
    		NewMove.SetMoveFor(Level.TimeSeconds, self, DeltaTime, forward, strafe);

    	// Simulate the movement locally.
        TribesMoveAutonomous(NewMove.Delta, Rotation, forward, strafe, ski, thrust, jump);
        NewMove.PostUpdate(self);

    	// if the last move was held, see if that move and the current move could be combined
    	if ( TribesPendingMove != None )
    	{
    		if (NewMove.canCombine(Pawn, TribesPendingMove))
    		{
    			combinedMoves++;
    			NewMove.combine(TribesPendingMove);

    			TribesPendingMove.Clear();
    			AppendFreeMove(TribesPendingMove);
    			TribesPendingMove = None;
    		}
    	}

    	// stats
    	replicateMoveCalls++;

        // Decide whether to hold off on move
    	if (TribesPendingMove == None)
    	{
    		if ( (Player.CurrentNetSpeed > 10000) && (GameReplicationInfo != None) && (GameReplicationInfo.PRIArray.Length <= 10) )
    			NetMoveDelta = 0;	// full rate
    		else
    			NetMoveDelta = FMax(0.0222,2 * Level.MoveRepSize/Player.CurrentNetSpeed);

    		if ( Level.TimeSeconds - ClientUpdateTime < NetMoveDelta )
    		{
    			TribesPendingMove = NewMove;
    			return;
    		}
    	}

    	ClientUpdateTime = Level.TimeSeconds;

    	// check if there's an important move that we should compress and send redundantly
        if ( ImportantMove != None )
        {
            ImportantMove.encodeImportantData(Level.TimeSeconds, ImportantData, ImportantTimeDelta);
    		//ImportantMove.debugEncoding(ImportantData, ImportantTimeDelta);
        }

    	// get the physics object's current position
    	if (character!=None && character.movementObject!=None)
    		MoveLoc = character.movementObject.getEndPosition();
    	else if (Pawn!=None)
    		MoveLoc = pawn.Location;
    	else
    		MoveLoc = Location;

    	if (debugLogLevel > 1)
    		log(character.movementObject.getEndPosition());

    	// Send the movement to the server
    	CallServerMove(MoveLoc, NewMove, ImportantTimeDelta, ImportantData);
    	/*(32767 & (Rotation.Pitch/2)) * 32768 + (32767 & (Rotation.Yaw/2))*/
    }

    function CallServerMove
    (
    	Vector ClientLoc,
    	SavedMove NewMove,
        optional byte CompressedImportantTimeDelta,
    	optional int ImportantMoveData
    )
    {
    	local bool bCombine;
    	local EDigitalAxisInput digitalForward, digitalStrafe, pendingForward, pendingStrafe;
    	local byte buttonInput;

    	digitalForward = analogueToDigital(NewMove.forward, 1);
    	digitalStrafe = analogueToDigital(NewMove.strafe, 1);

    	// TribesPendingMove will be a move held from the frame before NewMove.
    	// if TribesPendingMove is not none, it means that it and NewMove could not be combined.
    	// if the moves were combined, the result is in NewMove only.

    	// if a move was held and not combined...
    	if ( TribesPendingMove != None  )
    	{
    		// TribesPendingMove will always be utilised at this point, so save it
    		AppendSavedMove(TribesPendingMove);

    		// send two moves simultaneously
    		// send short server move if velocity did not change
    		if ( !NewMove.changesAcceleration()
    			&& TribesPendingMove.StartVelocity == vect(0,0,0)
    			&& !TribesPendingMove.changesAcceleration() )
    		{
    			if ( Pawn == None )
    				bCombine = (Velocity == vect(0,0,0));
    			else
    				bCombine = (Pawn.Velocity == vect(0,0,0));

    			if ( bCombine )
    			{
    				TribesShortServerMove
    				(
    					NewMove.TimeStamp,
    					ClientLoc,
    					NewMove.compressedView()
    				);

    				AppendSavedMove(NewMove);
    				// no longer need pending move
    				TribesPendingMove = None;
    				return;
    			}
    		}

    		// un-combinable moves share a final ClientLoc to save bandwidth
    		dualMoves++;

    		pendingForward = analogueToDigital(TribesPendingMove.forward, 1);
    		pendingStrafe = analogueToDigital(TribesPendingMove.strafe, 1);

    		if (TribesPendingMove.bSki)
    			buttonInput = 1;
    		if (TribesPendingMove.bThrust)
    			buttonInput += 2;
    		if (TribesPendingMove.bJump)
    			buttonInput += 4;
    		if (NewMove.bSki)
    			buttonInput += 8;
    		if (NewMove.bThrust)
    			buttonInput += 16;
    		if (NewMove.bJump)
    			buttonInput += 32;

    		if ( CompressedImportantTimeDelta == 0 )
    		{
    			TribesDualServerMove
    			(
    				TribesPendingMove.TimeStamp,
    				buttonInput,
    				pendingForward,
    				pendingStrafe,
    				TribesPendingMove.compressedView(),
    				NewMove.TimeStamp,
    				digitalForward,
    				digitalStrafe,
    				NewMove.compressedView(),
    				ClientLoc
    			);
    		}
    		else
    		{
    			TribesDualServerMove
    			(
    				TribesPendingMove.TimeStamp,
    				buttonInput,
    				pendingForward,
    				pendingStrafe,
    				TribesPendingMove.compressedView(),
    				NewMove.TimeStamp,
    				digitalForward,
    				digitalStrafe,
    				NewMove.compressedView(),
    				ClientLoc,
    				CompressedImportantTimeDelta,
    				ImportantMoveData
    			);
    		}
    	}
        else if ( !NewMove.changesAcceleration() )
    	{
            TribesShortServerMove
            (
                NewMove.TimeStamp,
                ClientLoc,
    			NewMove.compressedView()
            );
    	}
        else if ( CompressedImportantTimeDelta == 0 )
    	{
            TribesServerMove
            (
                NewMove.TimeStamp,
                ClientLoc,
                NewMove.compressedView(),
                digitalForward,
                digitalStrafe,
    			NewMove.bSki,
    			NewMove.bThrust,
    			NewMove.bJump
            );
    	}
        else
    	{
            TribesServerMove
            (
                NewMove.TimeStamp,
                ClientLoc,
                NewMove.compressedView(),
                digitalForward,
                digitalStrafe,
    			NewMove.bSki,
    			NewMove.bThrust,
    			NewMove.bJump,
                CompressedImportantTimeDelta,
                ImportantMoveData
            );
    	}

    	AppendSavedMove(NewMove);

    	// no longer need pending move
    	TribesPendingMove = None;
    }

    /* TribesShortServerMove()
    - As with ServerMove but view and client loc only, to save bandwidth. Used when Pawn is stationary.
    */
    function TribesShortServerMove
    (
    	float TimeStamp,
    	Vector ClientLoc,
    	int View
    )
    {
    	TribesServerMove(TimeStamp, ClientLoc, View, DAI_Zero, DAI_Zero, false, false, false);
    }

    /* TribesDualServerMove()
    - replicated function sent by client to server - contains client movement info for two moves
    */
    function TribesDualServerMove
    (
    	float TimeStamp0,
    	byte ButtonInput,
    	EDigitalAxisInput forward0,
    	EDigitalAxisInput strafe0,
    	int View0,
        float TimeStamp,
    	EDigitalAxisInput forward,
    	EDigitalAxisInput strafe,
        int View,
        vector ClientLoc,
        optional byte CompressedImportantTimeDelta,
        optional int ImportantMoveData
    )
    {
    	local bool bSki0, bThrust0, bJump0, bSki, bThrust, bJump;

    	bSki0 = (ButtonInput & 1) != 0;
    	bThrust0 = (ButtonInput & 2) != 0;
    	bJump0 = (ButtonInput & 4) != 0;
    	bSki = (ButtonInput & 8) != 0;
    	bThrust = (ButtonInput & 16) != 0;
    	bJump = (ButtonInput & 32) != 0;

    	TribesServerMove(TimeStamp0,vect(0,0,0),View0,forward0,strafe0,bSki0,bThrust0,bJump0);

    	if ( ClientLoc == vect(0,0,0) )
    		ClientLoc = vect(0.1,0,0);

    	TribesServerMove(TimeStamp,ClientLoc,View,forward,strafe,bSki,bThrust,bJump,CompressedImportantTimeDelta,ImportantMoveData);
    }

    // TribesStateServerMove
    // Call this on the client when you just want to replicate state
    function TribesStateServerMove(float Timestamp)
    {
    	local float DeltaTime;

        DeltaTime = FMin(MaxResponseTime, TimeStamp - CurrentTimeStamp);

    	if (Timestamp - CurrentTimestamp > 0.3)
    	{
    		TribesAdjustState(Timestamp, GetStateName());
    		CurrentTimeStamp = TimeStamp;
    	}
    }

    /* TribesServerMove()
    - replicated function sent by client to server - contains client movement info
    Passes acceleration in components so it doesn't get rounded.
    */
    function TribesServerMove
    (
    	float TimeStamp,
    	Vector ClientLoc,
    	int View,
    	EDigitalAxisInput digitalForward,
    	EDigitalAxisInput digitalStrafe,
    	bool ski,
    	bool thrust,
    	bool jump,
        optional byte CompressedImportantTimeDelta,
    	optional int ImportantMoveData
    )
    {
    	local float DeltaTime, clientErr, ImportantTimeStamp;
    	local rotator Rot, ViewRot;
    	local vector LocDiff;
    	local int ViewPitch, ViewYaw;
    	local float analogueForward;
    	local float analogueStrafe;
    	local float importantStrafe, importantForward, importantDelta;
    	local int importantJump, importantSki, importantThrust;
    	local int importantPitch, importantYaw;

    	analogueForward = digitalToAnalogue(digitalForward, 1);
    	analogueStrafe = digitalToAnalogue(digitalStrafe, 1);

    	// first move will have no previous timestamp to form delta, so set CurrentTimeStamp to use as delta and that's all
    	if ( CurrentTimeStamp == 0 )
    	{
    		if (debugLogLevel > 0)
    			LOG("SERVER FIRST MOVE!");
    		CurrentTimeStamp = TimeStamp;
    		return;
    	}

    	// If this move is outdated, discard it.
    	if ( CurrentTimeStamp >= TimeStamp )
    	{
    		if (debugLogLevel > 0) LOG("Discarded");
    		return;
    	}

        // check if an important move was lost
        if ( CompressedImportantTimeDelta != 0 )
        {
    		class'SavedMove'.static.decodeImportantData(
    			ImportantMoveData,
    			CompressedImportantTimeDelta,
    			importantThrust,
    			importantSki,
    			importantJump,
    			importantForward,
    			importantStrafe,
    			importantPitch,
    			importantYaw,
    			importantDelta
    			);

    		// CurrentTimeStamp is time of last processed packet from client.
    		// Timestamp is time of incoming client packet and CurrentTimeStamp + [client delta] should equal Timestamp.
    		// If Timestamp - ImportantDelta is greater than CurrentTimeStamp, then a packet must have been lost
    		// before the current packet was received. Perform the important movement before the current movement for greater prediction accuracy
    		// on lossy connections.
            ImportantTimeStamp = TimeStamp - importantDelta - 0.001;
            if ( CurrentTimeStamp < ImportantTimeStamp - 0.001 )
            {
    			ViewRot.Roll = 0;
    			ViewRot.Pitch = importantPitch;
    			ViewRot.Yaw = importantYaw;

                ImportantTimeStamp = FMin(ImportantTimeStamp, CurrentTimeStamp + MaxResponseTime);
                TribesMoveAutonomous(ImportantTimeStamp - CurrentTimeStamp, ViewRot, importantForward, importantStrafe, importantSki != 0, importantThrust != 0, importantJump != 0);
    			CurrentTimeStamp = ImportantTimeStamp;
    		}
    	}

    	// View components
    	ViewPitch = class'SavedMove'.static.decodeViewPitch(View);
    	ViewYaw = class'SavedMove'.static.decodeViewYaw(View);

    	// Save move parameters.
        DeltaTime = FMin(MaxResponseTime, TimeStamp - CurrentTimeStamp);

    	if ( Pawn == None )
    		TimeMargin = 0;
    	else if ( !CheckSpeedHack(DeltaTime) )
    	{
    		DeltaTime = 0;
    		Pawn.unifiedSetVelocity(vect(0,0,0));
    	}

    	CurrentTimeStamp = TimeStamp;
    	ServerTimeStamp = Level.TimeSeconds;
    	ViewRot.Pitch = ViewPitch;
    	ViewRot.Yaw = ViewYaw;
    	ViewRot.Roll = 0;
    	SetRotation(ViewRot);

    	if ( Pawn != None )
    	{
    		Rot.Yaw = ViewYaw;
    		Pawn.SetRotation(Rot);
    	}

        // Perform actual movement
    	if ( (Level.Pauser == None) && (DeltaTime > 0) )
    	{
            TribesMoveAutonomous(DeltaTime, ViewRot, analogueForward, analogueStrafe, ski, thrust, jump);
    	}

    	if (debugLogLevel > 1)
    		log(character.movementObject.getEndPosition());

    	// Accumulate movement error.
        if ( ClientLoc == vect(0,0,0) )
    		return;		// first part of double servermove
    	else if ( Level.TimeSeconds - LastUpdateTime > 0.3 )
    		ClientErr = 10000;
    	else if ( Level.TimeSeconds - LastUpdateTime > 180.0/Player.CurrentNetSpeed )
    	{
    	    if (character!=None && character.movementObject!=None)
    		    LocDiff = character.movementObject.getEndPosition() - ClientLoc;
    		else if (Pawn!=None)
    			LocDiff = Pawn.Location - ClientLoc;
    		else
    			LocDiff = Location - ClientLoc;
    		ClientErr = LocDiff Dot LocDiff;
    	}

    	// If client has accumulated a noticeable positional error, correct him.
    	if ( ClientErr > 3 )
    	{
    		PendingAdjustment.Timestamp = Timestamp;
    		PendingAdjustment.newState = GetStateName();

            if (character!=None && Pawn != None)
            {
    			PendingAdjustment.energy = character.energy;
    			PendingAdjustment.NewVel = character.Velocity;
    			PendingAdjustment.movement = character.movement;

    			if (character.movementObject!=None)
    			{
    				PendingAdjustment.StartLoc = character.movementObject.getStartPosition();
    				PendingAdjustment.EndLoc = character.movementObject.getEndPosition();
    				PendingAdjustment.accumulator = character.movementObject.getAccumulator();
    			}
    		    else
    			{
    				PendingAdjustment.StartLoc = Location;
    				PendingAdjustment.EndLoc = Location;
    			}
            }
    		else if (Pawn!=None)
    		{
    			PendingAdjustment.StartLoc = Pawn.Location;
    			PendingAdjustment.EndLoc = Pawn.Location;
    			PendingAdjustment.NewVel = Pawn.Velocity;
    		}
    		else
    		{
    			PendingAdjustment.StartLoc = Location;
    			PendingAdjustment.EndLoc = Location;
    			PendingAdjustment.NewVel = Velocity;
    		}

    		if (debugLogLevel > 0 && ClientErr != 10000)
    			log("Client Error at "$TimeStamp$" is "$ClientErr$" LocDiff "$LocDiff$" Physics "$Pawn.Physics);
    	}

    	//log("Server moved stamp "$TimeStamp$" location "$Pawn.Location$" Acceleration "$Pawn.Acceleration$" Velocity "$Pawn.Velocity);
    }

    /* Called on server at end of tick when PendingAdjustment has been set.
    Done this way to avoid ever sending more than one ClientAdjustment per server tick.
    */
    event SendClientAdjustment()
    {
    	if ( PendingAdjustment.NewVel == vect(0,0,0) )
    	{
    		TribesShortClientAdjustPositionEx
    		(
    			PendingAdjustment.TimeStamp,
    			PendingAdjustment.accumulator,
    			PendingAdjustment.energy,
    			PendingAdjustment.newState,
    			PendingAdjustment.movement,
    			PendingAdjustment.StartLoc.X,
    			PendingAdjustment.StartLoc.Y,
    			PendingAdjustment.StartLoc.Z,
    			PendingAdjustment.EndLoc.X,
    			PendingAdjustment.EndLoc.Y,
    			PendingAdjustment.EndLoc.Z
    		);
    	}
    	else
    	{
    		TribesClientAdjustPositionEx
    		(
    			PendingAdjustment.TimeStamp,
    			PendingAdjustment.accumulator,
    			PendingAdjustment.energy,
    			PendingAdjustment.newState,
    			PendingAdjustment.movement,
    			PendingAdjustment.StartLoc.X,
    			PendingAdjustment.StartLoc.Y,
    			PendingAdjustment.StartLoc.Z,
    			PendingAdjustment.EndLoc.X,
    			PendingAdjustment.EndLoc.Y,
    			PendingAdjustment.EndLoc.Z,
    			PendingAdjustment.NewVel.X,
    			PendingAdjustment.NewVel.Y,
    			PendingAdjustment.NewVel.Z
    		);
    	}

    	LastUpdateTime = Level.TimeSeconds;
    	PendingAdjustment.TimeStamp = 0;
    }

    // TribesProcessMove
    // Implemented in state
    function TribesProcessMove(float forward, float strafe, float jump, float ski, float thrust)
    {
    }

    /* TribesShortClientAdjustPositionEx
    bandwidth saving version, when velocity is zeroed, includes state
    */
    function TribesShortClientAdjustPositionEx
    (
    	float TimeStamp,
    	float accumulator,
    	float energy,
    	name newState,
    	Character.MovementState movement,
    	float StartLocX,
    	float StartLocY,
    	float StartLocZ,
    	float EndLocX,
    	float EndLocY,
    	float EndLocZ
    )
    {
    	TribesLongClientAdjustPosition(TimeStamp,accumulator,energy,newState,movement,StartLocX,StartLocY,StartLocZ,EndLocX,EndLocY,EndLocZ,0,0,0);
    }

    /* TribesClientAdjustPositionEx
    - pass newloc and newvel in components so they don't get rounded, includes state
    */
    function TribesClientAdjustPositionEx
    (
    	float TimeStamp,
    	float accumulator,
    	float energy,
    	name newState,
    	Character.MovementState movement,
    	float StartLocX,
    	float StartLocY,
    	float StartLocZ,
    	float EndLocX,
    	float EndLocY,
    	float EndLocZ,
    	float NewVelX,
    	float NewVelY,
    	float NewVelZ
    )
    {
    	TribesLongClientAdjustPosition(TimeStamp,accumulator,energy,newState,movement,StartLocX,StartLocY,StartLocZ,EndLocX,EndLocY,EndLocZ,NewVelX,NewVelY,NewVelZ);
    }

    // CommonClientAdjustPosition
    // Code to be shared by all 'adjust position' functions
    function bool CommonClientAdjustPosition(float TimeStamp, Name NewState)
    {
        local float NewPing;

    	// update ping
    	if ( (PlayerReplicationInfo != None) && !bDemoOwner )
    	{
    		NewPing = FMin(1.5, Level.TimeSeconds - TimeStamp);

    		if ( ExactPing < 0.004 )
    			ExactPing = FMin(0.3,NewPing);
    		else
    		{
    			if ( NewPing > 2 * ExactPing )
    				NewPing = FMin(NewPing, 3*ExactPing);
    			ExactPing = FMin(0.99, 0.99 * ExactPing + 0.008 * NewPing); // placebo effect
    		}
    		PlayerReplicationInfo.Ping = 1000.0 * ExactPing;
    		PlayerReplicationInfo.bReceivedPing = true;
    		if ( Level.TimeSeconds - LastPingUpdate > 4 )
    		{
    			if ( bDynamicNetSpeed && (OldPing > DynamicPingThreshold * 0.001) && (ExactPing > DynamicPingThreshold * 0.001) )
    			{
    				if ( Level.MoveRepSize < 64 )
    					Level.MoveRepSize += 8;
    				else if ( Player.CurrentNetSpeed >= 6000 )
    					SetNetSpeed(Player.CurrentNetSpeed - 1000);
    				OldPing = 0;
    			}
    			else
    				OldPing = ExactPing;
    			LastPingUpdate = Level.TimeSeconds;
    			ServerUpdatePing(1000 * ExactPing);
    		}
    	}
    	if ( Pawn != None )
    	{
    		if ( Pawn.bTearOff )
    		{
    			Pawn = None;
    			if ( !IsInState('GameEnded') && !IsInState('Dead') )
    			    GotoState('Dead');
                return false;
    		}

    		if ( IsInState('PlayerWaitingInventoryStation') && NewState != 'PlayerWaitingInventoryStation' )
    			GotoState(NewState);
    		if ( IsInState('PlayerTurreting') && NewState != 'PlayerTurreting' )
    			GotoState(NewState);
    	}
    	else
        {
     	   	if( GetStateName() != newstate )
    		{
    		    if ( NewState == 'GameEnded' )
    			    GotoState(NewState);
    			else if ( IsInState('Dead') )
    			{
    		    	if ( (NewState != 'CharacterMovement') )
    		        {
    				    GotoState(NewState);
    		        }
    		        return false;
    			}
    			else if ( NewState == 'Dead' )
    				GotoState(NewState);
    			else if ( NewState == 'TribesSpectating' )
    				GotoState(NewState);
    		}
    	}
    	if ( CurrentTimeStamp > TimeStamp )
    		return false;
    	CurrentTimeStamp = TimeStamp;

    	return true;
    }

    // TribesAdjustState
    function TribesAdjustState(float Timestamp, Name newState)
    {
    	if (!CommonClientAdjustPosition(timeStamp, newState))
    		return;

    	if (GetStateName() != newState)
    		GotoState(newState);
    }

    /* TribesLongClientAdjustPosition
    long version, when care about pawn's floor normal
    */
    function TribesLongClientAdjustPosition
    (
    	float TimeStamp,
    	float accumulator,
    	float energy,
    	name newState,
    	Character.MovementState movement,
    	float StartLocX,
    	float StartLocY,
    	float StartLocZ,
    	float EndLocX,
    	float EndLocY,
    	float EndLocZ,
    	float NewVelX,
    	float NewVelY,
    	float NewVelZ
    )
    {
        local vector NewStartLocation, NewEndLocation, NewVelocity;
    	local Actor MoveActor;
        local SavedMove CurrentMove;

    	if (!CommonClientAdjustPosition(TimeStamp, NewState))
    		return;

    	if ( Pawn != None )
    	{
    		MoveActor = Pawn;
            if ( (ViewTarget != Pawn)
    			&& ((ViewTarget == self) || ((Pawn(ViewTarget) != None) && (Pawn(ViewTarget).Health <= 0))) )
    		{
    			SetViewTarget(Pawn);
    		}
    	}
    	else
        {
    		MoveActor = self;
    	}

    	if ( !bDemoOwner )
    	{
    		NewStartLocation.X = StartLocX;
    		NewStartLocation.Y = StartLocY;
    		NewStartLocation.Z = StartLocZ;
    		NewEndLocation.X = EndLocX;
    		NewEndLocation.Y = EndLocY;
    		NewEndLocation.Z = EndLocZ;
    		NewVelocity.X = NewVelX;
    		NewVelocity.Y = NewVelY;
    		NewVelocity.Z = NewVelZ;

    		// skip update if no error (key to client movement prediction)
    		while (TribesSavedMoves.Length > 0)
    		{
    			CurrentMove = TribesSavedMoves[0];
    			if ( CurrentMove.TimeStamp <= CurrentTimeStamp )
    			{
    				PopSavedMove();
    				AppendFreeMove(CurrentMove);
    				if ( CurrentMove.TimeStamp == CurrentTimeStamp )
    				{
    					// glenn: this if statement looks very strange, i think it can be simplified quite a bit

    					CurrentMove.Clear();	// SavedLocation is not cleared
    					if ( (VSize(CurrentMove.SavedLocation - NewEndLocation) < 3)
    						&& (GetStateName() == NewState)/* && (accumulator == CurrentMove.accumulator)*/ )
    					{
    						return;
    					}
    					break;
    				}
    				else
    				{
    					CurrentMove.Clear();
    				}
    			}
    			else
    				break;
    		}

    		correctedMoves++;

    		// update fusion movement state from server
    		if (debugLogLevel > 0) log("Client "$Role$" adjust stamp "$TimeStamp$" - "$CurrentMove.SavedLocation$" to "$NewEndLocation$" ("$NewEndLocation - CurrentMove.SavedLocation$"), client accum "$CurrentMove.accumulator$" / "$accumulator);

    		CurrentMove = None;	// no need to access this from here on
    	}

    	if( GetStateName() != newstate )
    		GotoState(newstate);

    	if (!bDemoOwner)
    	{
    		replayFromStartLocation = NewStartLocation;
    		replayFromEndLocation = NewEndLocation;
    		replayFromAccumulator = accumulator;
    		replayFromVelocity = NewVelocity;
    		replayFromEnergy = energy;
    		replayFromMovement = movement;
    		bUpdatePosition = true;
    	}
    }

    function LongClientAdjustPosition
    (
    	float TimeStamp,
    	name newState,
    	EPhysics newPhysics,
    	float NewLocX,
    	float NewLocY,
    	float NewLocZ,
    	float NewVelX,
    	float NewVelY,
    	float NewVelZ,
    	Actor NewBase,
    	float NewFloorX,
    	float NewFloorY,
    	float NewFloorZ
    )
    {
    	if (IsInState('BaseSpectating'))
    		Super.LongClientAdjustPosition(TimeStamp, newState, newPhysics, NewLocX, NewLocY, NewLocZ, NewVelX, NewVelY, NewVelZ, NewBase, NewFloorX, NewFloorY, NewFloorZ);
    }

    // ClientUpdatePosition
    // Replay moves from a received server position when player gets out of sync
    function ClientUpdatePosition()
    {
    	local SavedMove CurrentMove;
    	local int i;
    	local int restored;
    	local Rotator oldRotation;

    	bUpdatePosition = false;

    	if (character != None)
    	{
    		character.energy = replayFromEnergy;
    		character.unifiedSetVelocity(replayFromVelocity);
    		character.forceMovementState(replayFromMovement);

    		if (character.movementObject!=None)
    		{
    			character.movementObject.setStartPosition(replayFromStartLocation);
    			character.movementObject.setEndPosition(replayFromEndLocation);
    			character.movementObject.setAccumulator(replayFromAccumulator);
    		}
    	}
    	else if (Pawn == None)
    	{
    		super.ClientUpdatePosition();
    	}

    	oldRotation = Rotation;

    	bUpdating = true;
    	i = 0;
    	while ( i < TribesSavedMoves.Length )
    	{
    		CurrentMove = TribesSavedMoves[i];
    		// Discard moves older than the correction time stamp
    		// Also discard the move corresponding to the last received server move (as it's our starting point)
    		if ( CurrentMove.TimeStamp <= CurrentTimeStamp )
    		{
    			CurrentMove.Clear();
    			AppendFreeMove(CurrentMove);
    			PopSavedMove();
    		}
    		else
    		{
    			i++;
    			restored++;

    			TribesMoveAutonomous(CurrentMove.Delta, CurrentMove.rotation, CurrentMove.forward, CurrentMove.strafe, CurrentMove.bSki, CurrentMove.bThrust, CurrentMove.bJump);
    			CurrentMove.PostUpdate(self);
    		}
    	}
        if ( TribesPendingMove != None )
        {
    		restored++;
    		TribesMoveAutonomous(TribesPendingMove.Delta, TribesPendingMove.rotation, TribesPendingMove.forward, TribesPendingMove.strafe, TribesPendingMove.bSki, TribesPendingMove.bThrust, TribesPendingMove.bJump);
    		TribesPendingMove.PostUpdate(self);
        }

    	SetRotation(oldRotation);

    	if (restored > 0 && debugLogLevel > 0)
    		log("Client update position restored "$restored$" moves");

    	bUpdating = false;
    }

    // TribesMoveAutonomous
    function TribesMoveAutonomous
    (
    	float DeltaTime,
    	rotator moveRotation,
    	float forward,
    	float strafe,
    	bool ski,
    	bool thrust,
    	bool jump
    )
    {
    //	log(deltatime);
    	if (Pawn != None)
    	{
    		SetRotation(moveRotation);

    		TribesProcessMove(forward, strafe, float(jump), float(ski), float(thrust));
    		Pawn.AutonomousPhysics(DeltaTime);
    	}
    	else
    	{
    		AutonomousPhysics(DeltaTime);
    	}

    	//log("Role "$Role$" moveauto time "$100 * DeltaTime$" ("$Level.TimeDilation$")");
    }

    function ServerRestartPlayerInVehicle(int vehicleRespawnIndex, bool bKeepPawn)
    {
    	// Check to ensure that the vehicle is still available to spawn at
    	// if it isnt, we do nothing because the HUD will still be open on
    	// the client, and the can simply select from another spawn point.

    	// MJ:  Prevented this function from being called repeatedly by adding
    	//      check to TribesRespawnHUD's Tick() instead
    	// potentially already left PlayerRespawn state so ignore in that case
    	//if (!isInState('PlayerRespawn'))
    	//	return;

    	if(TribesReplicationInfo(PlayerReplicationInfo).team.validVehicleRespawnIndex(vehicleRespawnIndex))
    	{
    		// Alex: added this becuase I found an enemies spawn base would be set in the case a player had switched teams and wanted to
    		// immediately spawn at the Rover.
    		spawnBase = None;

    		if (!bKeepPawn)
    			GameInfo(Level.Game).tryRespawn(self);
    		else
    			GameInfo(Level.Game).respawnKeepPawn(self);

    		// snap player into respawn vehicle if necessary
    		if (pawn != None)
    				TribesReplicationInfo(PlayerReplicationInfo).team.respawnVehicles[vehicleRespawnIndex].spawnCharacter(Character(pawn));
    	}
    }

    // ServerRestartPlayer
    function ServerRestartPlayer()
    {
    	GameInfo(Level.Game).tryRespawn(self);
    }

    function ServerRestartPlayerKeepPawn()
    {
    	GameInfo(Level.Game).respawnKeepPawn(self);
    }

    function ServerRestartPlayerAtBase(BaseInfo Base, optional bool bKeepPawn)
    {
    	if(Base != None)
    		SpawnBase = Base;

    	if (bKeepPawn)
    		ServerRestartPlayerKeepPawn();
    	else
    		ServerRestartPlayer();
    }

    function ServerKillPlayer()
    {
    	local Vehicle vehicle;
    	local VehicleMountedTurret vehicleTurret;
    	local Turret turret;

    	//Log("ServerKillPlayer() called");

    	vehicle = Vehicle(Pawn);
    	vehicleTurret = VehicleMountedTurret(Pawn);
    	turret = Turret(Pawn);
    	if (vehicle != None)
    	{
    		// vehicle case
    		vehicle.positions[vehicle.driverIndex].occupant.KilledBy(Pawn);

    		// ... kick out dead body immediately
    		vehicle.driverLeave(true, vehicle.driverIndex);
    	}
    	else if (vehicleTurret != None)
    	{
    		// vehicle mounted turret case
    		vehicleTurret.ownerVehicle.positions[vehicleTurret.positionIndex].occupant.KilledBy(Pawn);

    		// ... kick out dead body immediately
    		vehicleTurret.ownerVehicle.driverLeave(true, vehicleTurret.positionIndex);
    	}
    	else if (turret != None)
    	{
    		// turret case
    		turret.driver.KilledBy(Pawn);

    		// ... kick out dead body immediately
    		turret.driverLeave(true);
    	}
    	else
    		Pawn.KilledBy(Pawn);

    	// MJ:  Don't send the client to dead since the server will determine which state
    	// the client goes to next
    	GotoState('Dead', 'Forced');
    }

    function ServerPlayerSelectRespawn()
    {
    	GotoState('PlayerRespawn', 'Forced');
    	ClientGotoState('PlayerRespawn', 'Forced');
    }

    function ServerCancelRespawn()
    {
    	if (bForcedRespawn)
    	{
    		GotoState(Rook(Pawn).playerControllerState);
    		ClientGotoState(Rook(Pawn).playerControllerState);
    	}
    }

    // serverSpectate
    function serverSpectate(optional string playerName)
    {
    	spectate(playerName);
    }

    //
    // State Respawn
    //
    // The player is viewing the respawn HUD, selecting a respawn point
    // Needs to be extended from Dead so that the player can rotate his viewpoint around the dead pawn.
    //
    simulated state PlayerRespawn extends Dead
    {
    	exec function Fire( optional float F )
    	{
    	}

    	exec function AltFire(optional float F)
    	{
    	}

    	exec function releaseFire(optional float F)
    	{
    	}

    	exec function releaseAltFire(optional float F)
    	{
    	}

    	exec function Jetpack( optional float F )
    	{
    	}

    	exec function Respawn( optional bool bAllowExit )
    	{
    	}

    	// The behaivour in the parent Engine.Controller 'Dead' state
    	// is not what we desire.
    	function ServerRestartPlayer()
    	{
    		Global.ServerRestartPlayer();
    	}

    	function BeginState()
    	{
    		// allows rotation around character
    		bFrozen = false;
    		DestroySensorLists();
    		ResetSpeedhack();
    	}

    	simulated function EndState()
    	{
    		//Log(self $ " exited PlayerRespawn state");
    		bBehindView = false;
    		bForcedRespawn = false;
    		releaseFire();

    		if (Level.NetMode != NM_DedicatedServer)
    		{
    			HUDManager.SetHUD("");
    		}
    	}

    	function PlayerTick(float Delta)
    	{
    		Global.PlayerTick(Delta);

    		// The view should be frozen when the hud map is shown
    		bFrozen = clientSideChar.bShowRespawnMap;
    	}

    	function Tick(float Delta)
    	{
    		Global.Tick(Delta);

    		if (respawnDelay > 0)
    			respawnDelay -= Delta;
    	}

    	exec function showEscapeMenu()
    	{
    		if (isSinglePlayer() || !bForcedRespawn)
    			Global.showEscapeMenu();
    	}

    	// Lock the player when looking at the respawn map
    	function playerMove(float deltaTime)
    	{
    		if (!clientSideChar.bShowRespawnMap)
    		{
    			Super.playerMove(deltaTime);
    			return;
    		}

    		if (pawn == none)
    			return;

    		// need to do this to handle case user is blown off
    		if (ROLE < ROLE_Authority)
    		{
    			tribesReplicateMove(0, 1, false, false, false);
    		}
    		else
    		{
    			tribesProcessMove(0, 0, 0, 0, 0);
    		}
    	}

    Forced:
    	bForcedRespawn = true;
    	respawnDelay = -1;

    Begin:
    	bBehindView = true;

    	//Log(self $ " entered PlayerRespawn state with bForced set to "$bForcedRespawn);

    	if (Level.NetMode != NM_DedicatedServer)
    		HUDManager.SetHUD(respawnHUDClass);
    }

    //
    // State PlayerTeleport
    //
    simulated state PlayerTeleport
    {
    	exec function Fire( optional float F )
    	{
    	}

    	exec function AltFire(optional float F)
    	{
    	}

    	exec function releaseFire(optional float F)
    	{
    	}

    	exec function releaseAltFire(optional float F)
    	{
    	}

    	exec function Jetpack( optional float F )
    	{
    	}

    	exec function activatePack()
    	{
    	}

    	exec function Respawn( optional bool bAllowExit )
    	{
    	}

    	exec function SwitchWeapon(byte F)
    	{
    	}

    	exec function equipCarryable()
    	{
    	}

    	exec function equipDeployable()
    	{
    	}

    	function BeginState()
    	{
    		// allows rotation around character
    		bFrozen = true;
    	}

    	simulated function PlayerTick(float Delta)
    	{
    		Global.PlayerTick(Delta);

    		// The view should be frozen when the hud map is shown
    		bFrozen = clientSideChar.bShowRespawnMap;
    	}

    	function EndState()
    	{
    		//Log(self $ " exited PlayerTeleport state");
    		bBehindView = false;
    		clientTribesSetHUD("");
    		bForcedRespawn = false;
    	}

    	function ServerRestartPlayer()
    	{
    	}

    Begin:
    	//Log(self $ " entered PlayerTeleport state");
    	bBehindView = true;
    	respawnDelay = -1;
    	bForcedRespawn = true;

    	if (Level.NetMode != NM_DedicatedServer)
    		HUDManager.SetHUD(respawnHUDClass);
    }

    // State Dead
    //
    // The player is dead
    //
    simulated state Dead
    {
    	exec function Fire( optional float F )
    	{
    		// respawn on fire
    		Global.ServerRestartPlayer();
    	}

    	exec function AltFire(optional float F)
    	{
    		// respawn on fire
    		Global.ServerRestartPlayer();
    	}

    	exec function releaseFire(optional float F)
    	{
    	}

    	exec function releaseAltFire(optional float F)
    	{
    	}

    	exec function Jetpack( optional float F )
    	{
    		// go to spectator mode when jetpack is pressed
    		serverSpectate();
    	}

    	// michaelj:  Multiplayer effectively bypasses the Dead state and goes to one of two possible states
    	//            1) PlayerRespawn, which lets the player choose a location, spawn, then play
    	//            2) AwaitingNextRound if the player doesn't have any lives left
    	function BeginState()
    	{
    		super.BeginState();

    		// enable rotation around the dead player.
    		bFrozen = false;

    		if(IsSinglePlayer())
    			ClientTribesSetHUD("");

    		//clientTribesSetHUD("");
    		if (character != None)
    			TriggerEffectEvent('Died');

    		// Notify the GameInfo of this player's death (decrements livesLeft if applicable)
    		if (Level.NetMode != NM_Client)
    			GameInfo(Level.Game).onDeath(self);

    		// If livesLeft is -1 (disabled) or greater than 0 (you have lives left), go to a regular
    		// destroyed state
    		if (livesLeft != 0)
    		{
    			if (Level.NetMode != NM_Client)
    			{
    				//Log("Sending "$self$" to "$GameInfo(Level.Game).playerPawnDestroyedState()$" from Dead with livesLeft = "$livesLeft);
    				GotoState(GameInfo(Level.Game).playerPawnDestroyedState());
    				ClientGotoState(GameInfo(Level.Game).playerPawnDestroyedState());
    			}
    		}
    		// Otherwise you can't respawn.  Game over in SP, wait for the next round in MP
    		else
    		{
    			if (Level.NetMode != NM_Client)
    			{
    				//Log("Sending "$self$" to "$GameInfo(Level.Game).playerPawnNoRespawnState()$" from Dead with livesLeft "$livesLeft);
    				GotoState(GameInfo(Level.Game).playerPawnNoRespawnState());
    				ClientGotoState(GameInfo(Level.Game).playerPawnNoRespawnState());
    			}
    		}
    	}

    Forced:
    	bForcedRespawn = true;

    Begin:
    //	clientTribesSetHUD(respawnHUDClass);
    //	clientTribesSetHUD("");
    }

    state BaseSpectating
    {
    	function BeginState()
    	{
    		super.BeginState();
    		DestroySensorLists();
    	}
    }

    // State TribesSpectating
    //
    // The player is spectating
    //
    simulated state TribesSpectating extends BaseSpectating
    {
    	function BeginState()
    	{
    		Super.BeginState();

    		bFrozen = false;
    		bCollideWorld = false;
    		PlayerReplicationInfo.bIsSpectator = true;
    		spawnBase = None;
    		//Log("Setting team of "$self$" to None in TribesSpectating BeginState()");
    		tribesReplicationInfo(playerReplicationInfo).setTeam(None);
    	}

    	exec function Fire( optional float F )
    	{
    		SetSpectateSpeed( 2000.0 );
    	}

    	exec function AltFire(optional float F)
    	{
    		// respawn on altfire
    		//Global.ServerRestartPlayer();
    	}

    	exec function releaseFire(optional float F)
    	{
    		SetSpectateSpeed( 1200.0 );
    	}

    	exec function releaseAltFire(optional float F)
    	{
    	}

    	exec function Jetpack( optional float F )
    	{
    		// select spectate target on jetpack key
    		ServerViewNextPlayer();
    	}

    	exec function NextWeapon()
    	{
    		camera.thirdPersonCameraDist = FMin(maxSpectatorZoom, camera.thirdPersonCameraDist + 1);
    		if (camera.thirdPersonCameraDist == minSpectatorZoom + 1)
    		{
    			// Switch to third-person
    			//bBehindView = true;
    			//bFreeCamera = true;
    		}
    	}

    	exec function PrevWeapon()
    	{
    		camera.thirdPersonCameraDist = FMax(minSpectatorZoom, camera.thirdPersonCameraDist - 1);
    		if (camera.thirdPersonCameraDist == minSpectatorZoom)
    		{
    			// Switch to first-person
    			//bBehindView = false;
    			//bFreeCamera = false;
    		}
    	}

    	exec function SwitchWeapon(byte F)
    	{
    		switch(F)
    		{
    		case 1: ServerViewNextMPObject(); break;
    		case 2: ServerViewNextSpectatorStart(); break;
    		}
    	}

    	function CalcFirstPersonView(Vector cameraLocation, Rotator cameraRotation)
    	{
    	}

    	function EndState()
    	{
    		Super.EndState();
    		bBehindView = false;
    		PlayerReplicationInfo.bIsSpectator = false;
    		camera.thirdPersonCameraDist = camera.default.thirdPersonCameraDist;
    		if (Level.NetMode != NM_DedicatedServer)
    			HUDManager.SetHUD("");
    	}

    	function ServerReStartPlayer()
    	{
    	}

    	exec function Respawn( optional bool bAllowExit )
    	{
    	}

    Begin:
    	CleanOutSavedMoves();
    	if (Level.NetMode != NM_DedicatedServer)
    		HUDManager.SetHUD(spectatorHUDClass);
    }

    // State TribesCountdown
    //
    // The player is in the countdown phase
    //
    simulated state TribesCountdown extends BaseSpectating
    {
    	exec function Suicide()
    	{
    	}

    	function LongClientAdjustPosition
    	(
    		float TimeStamp,
    		name newState,
    		EPhysics newPhysics,
    		float NewLocX,
    		float NewLocY,
    		float NewLocZ,
    		float NewVelX,
    		float NewVelY,
    		float NewVelZ,
    		Actor NewBase,
    		float NewFloorX,
    		float NewFloorY,
    		float NewFloorZ
    	)
    	{
    	}

    	function TurnAround()
    	{
    		// stop player turning
    	}

    	function ServerRestartPlayer()
    	{
    		//Global.ServerRestartPlayer();
    	}

    	exec function Fire( optional float F )
    	{
    		serverToggleReady();
    	}

    	exec function AltFire( optional float F )
    	{
    	}

    	exec function releaseFire( optional float F )
    	{
    	}

    	exec function releaseAltFire(optional float F)
    	{
    	}

    	exec function Jetpack( optional float F )
    	{
    	}

    	function BeginState()
    	{
    		local Rotator r;

    		super.BeginState();

    		r = character.Rotation;
    		r.Pitch = 0;
    		character.setRotation(r);

    		character.enterManualAnimationState();
    		character.bReplicateAnimations = true;
    		character.LoopAnim('start_round', 1.0);
    		bBehindView = true;
    		bFreeCamera = true;

    		camera.clearTransitions();
    	}

    	function EndState()
    	{
    		character.exitManualAnimationState();
    		character.bReplicateAnimations = false;
    		bFreeCamera = false;
    		clientTribesSetHUD("");
    		camera.doZoomIn(0.15);
    	}

    	// server-side only (clients use PlayerTick)
    	function Tick(float Delta)
    	{
    		Global.Tick(Delta);

    		checkAutoWeaponSwitch();
    	}

    	function ToggleBehindView()
    	{
    		// do nothing
    	}

    	exec function Respawn( optional bool bAllowExit )
    	{
    		// do nothing
    	}

    Begin:
    	//Log(self$" entered state TribesCountdown");
    	CleanOutSavedMoves();
    	clientTribesSetHUD(CountdownHUDClass);
    }

    //
    // State SPIntroduction
    //
    // The camera pans around the player and enters his head
    //
    state SPIntroduction
    {
    	function TurnAround()
    	{
    		// stop player turning
    	}

    	exec simulated function bool SkipOpeningCutscene()
    	{
    		if (introCameraScript != None)
    		{
    			introCameraScript.exit();
    			GotoState(introCameraOldState);
    			return true;
    		}

    		return false;
    	}

    	function serverSelectWeapon(Weapon w)
    	{
    		// do nothing
    	}

    	exec function Fire( optional float F )
    	{
    		serverToggleReady();
    	}

    	exec function AltFire( optional float F )
    	{
    	}

    	exec function releaseFire( optional float F )
    	{
    	}

    	exec function releaseAltFire(optional float F)
    	{
    	}

    	exec function Jetpack( optional float F )
    	{
    	}

    	function BeginState()
    	{
    		// this logic is for when triggered via test exec command (script calls camera.transition)
    		if (!camera.isTransitioning())
    			camera.transition('LevelStartPan', 4.5);

    		clientTribesSetHUD("");

    		SetCinematicMode(true);
    		class'ActionCinematicEnter'.static.cinematicEnter(Level);
    	}

    	function Tick(float delta)
    	{
    		if (!camera.isTransitioning())
    			GotoState(introCameraOldState);
    	}

    	function EndState()
    	{
    		camera.clearTransitions();
    		camera.GotoState('');
    		introCameraScript = None;
    		bBehindView = false;

    		SetCinematicMode(false);
    		class'ActionCinematicExit'.static.cinematicExit(Level);
    	}
    }

    function serverToggleReady()
    {
    	local TribesReplicationInfo TRI;

    	if (Role != ROLE_Authority)
    		return;

    	TRI = TribesReplicationInfo(PlayerReplicationInfo);

    	// Allow clicking to ready/unready if in tournament mode and the countdown hasn't started yet
    	if (GameReplicationInfo.bTournamentMode
    			&& TribesGameReplicationInfo(GameReplicationInfo).bAwaitingTournamentStart
    			&& TRI.numReadies < 10)
    	{
    		// Broadcast ready message
    		TRI.bReady = !TRI.bReady;
    		TRI.numReadies++;
    		if (TRI.bReady)
    			Level.Game.BroadcastLocalized(self, Level.Game.GameMessageClass, 20, PlayerReplicationInfo);
    		else
    			Level.Game.BroadcastLocalized(self, Level.Game.GameMessageClass, 21, PlayerReplicationInfo);
    	}
    }

    // State AwaitingNextRound
    //
    // The player waiting for the next round to begin
    //
    simulated state AwaitingNextRound extends TribesSpectating
    {
    	function BeginState()
    	{
    		bWaitingForRoundEnd = true;
    		bCollideWorld = true;
    	}

    	exec function AltFire( optional float F )
    	{
    	}

    	exec function releaseAltFire(optional float F)
    	{
    	}

    	function EndState()
    	{
    		Super.EndState();
    		//Log(self $" leaving state AwaitingNextRound");
    		if (Level.NetMode != NM_DedicatedServer)
    			HUDManager.SetHUD(respawnHUDClass);
    		bWaitingForRoundEnd = false;
    	}

    Begin:
    	bBehindView = true;
    	//Log(self $" entered state AwaitingNextRound");
    	//CleanOutSavedMoves();
    	if (Level.NetMode != NM_DedicatedServer)
    		HUDManager.SetHUD(waitRoundEndHUDClass);
    }

    // State AwaitingGameStart
    //
    // The player waiting for the game to start
    simulated state AwaitingGameStart extends TribesSpectating
    {
    	function BeginState()
    	{
    		bFrozen = true;
    		bCollideWorld = true;
    		PlayerReplicationInfo.bIsSpectator = true;
    	}

    	function ServerReStartPlayer()
    	{
    		//Log(self$" tried to restart in state AwaitingGameStart");
    	}

    	exec function AltFire( optional float F )
    	{
    	}

    	exec function releaseAltFire(optional float F)
    	{
    	}

    	function EndState()
    	{
    		if (Level.NetMode != NM_DedicatedServer)
    			HUDManager.SetHUD("");

    		PlayerReplicationInfo.bIsSpectator = false;
    	}

    Begin:
    	if (Level.NetMode != NM_DedicatedServer)
    		HUDManager.SetHUD(waitGameStartHUDClass);

    }

    // State GameEnded (overrides GameEnded in Controller)
    //
    // The game has ended
    //
    state GameEnded
    {
    	exec function Fire( optional float F )
    	{
    	}

    	exec function AltFire( optional float F )
    	{
    	}

    	exec function releaseFire( optional float F )
    	{
    	}

    	exec function releaseAltFire(optional float F)
    	{
    	}

    	exec function Jetpack( optional float F )
    	{
    	}

    	function BeginState()
    	{
    		CleanOutSavedMoves();
    		clientTribesSetHUD(gameEndHUDClass);
    		bBehindView = true;
    	}

    	function EndState()
    	{
    		clientTribesSetHUD("");
    		bBehindView = false;
    	}
    }

    // clientFinishInventoryStationAccess
    //
    // Does client side processing associated with a character ceasing usage of an inventory station.
    function clientFinishInventoryStationAccess()
    {
    	inventoryStation = None;

        character.StopMovementEffects();

    	// replicated from server but do here as well to guarantee it is done by now
    	GotoState('CharacterMovement');
    }

    // clientInventoryStationWait
    //
    // Does Client side processing for waiting for an inventory station.
    function clientInventoryStationWait()
    {
    	// replicated from server but do here as well to guarantee it is done by now
    	GotoState('PlayerWaitingInventoryStation');
    }

    // clientInventoryStationAccess
    //
    // Does client side processing for using an inventory station.
    function clientInventoryStationAccess(InventoryStationAccess inputInventoryStation)
    {
    	// If the player is entering an inventory station immediately after spawning it is possible that the player pawn has not been
    	// replicated yet. This situation is caught here and handled by simply delaying this call until the player pawn has been replicated.
    	// The function is re-called in PostNetReceive.

    	if (Level.NetMode == NM_Client && Character(Pawn) == None)
    	{
    		inventoryStationWaitingForCharacter = true;
    		inventoryStationWaitingForCharacterInput = inputInventoryStation;
    		return;
    	}

    	inventoryStation = inputInventoryStation;
    	inventoryStation.clientSetupInventoryStation(Character(Pawn));

    	Character(Pawn).unifiedSetVelocity(Vect(0,0,0));

    	// replicated from server but do here as well to guarantee it is done by now
    //	GotoState('PlayerUsingInventoryStation');
    }

    // serverTerminateInventoryStationAccess
    //
    // Abruptly stops inventory station usage.
    function serverTerminateInventoryStationAccess()
    {
    	inventoryStation.serverTerminateCharacterAccess();

    	clientTerminateInventoryStationAccess();
    }

    // clientTerminateInventoryStationAccess
    //
    // Does processing on client side associated with terminating a users access/
    function clientTerminateInventoryStationAccess()
    {
    	clientFinishInventoryStationAccess();
    }

    // serverFinishInventoryStationAccess
    //
    // Called from client when player finishes doing a quick loadout select
    //
    function serverFinishQuickInventoryStationAccess(
    	InventoryStationAccess inputInventoryStation,
    	class<CombatRole> selectedRole,
    	String userSkin,
    	int activeWeaponSlot,
    	optional class<Pack> selectedPack,
    	optional class<HandGrenade> grenades,
    	optional class<Weapon> weaponSlot1,
    	optional class<Weapon> weaponSlot2,
    	optional class<Weapon> weaponSlot3,
    	optional class<Weapon> weaponSlot4,
    	optional class<Weapon> weaponSlot5,
    	optional class<Weapon> weaponSlot6,
    	optional class<Weapon> weaponSlot7,
    	optional class<Weapon> weaponSlot8,
    	optional class<Weapon> weaponSlot9,
    	optional class<Weapon> weaponSlot10)
    {
    	local InventoryStationAccess.InventoryStationLoadout selectedLoadout;

    	if (character != None)
    		character.detachGrapple();

    	// rebuild loadout struct
    	selectedLoadout.role.combatRoleClass = selectedRole;
    	selectedLoadOut.userSkin = userSkin;
    	selectedLoadOut.activeWeaponSlot = activeWeaponSlot;
    	selectedLoadOut.pack.packClass = selectedPack;
    	selectedLoadout.grenades.grenadeClass = grenades;
    	selectedLoadout.weapons[0].weaponClass = weaponSlot1;
    	selectedLoadout.weapons[1].weaponClass = weaponSlot2;
    	selectedLoadout.weapons[2].weaponClass = weaponSlot3;
    	selectedLoadout.weapons[3].weaponClass = weaponSlot4;
    	selectedLoadout.weapons[4].weaponClass = weaponSlot5;
    	selectedLoadout.weapons[5].weaponClass = weaponSlot6;
    	selectedLoadout.weapons[6].weaponClass = weaponSlot7;
    	selectedLoadout.weapons[7].weaponClass = weaponSlot8;
    	selectedLoadout.weapons[8].weaponClass = weaponSlot9;
    	selectedLoadout.weapons[9].weaponClass = weaponSlot10;

    	inputInventoryStation.serverFinishCharacterAccess(selectedLoadout, true, character);
    }

    // serverFinishInventoryStationAccess
    //
    // Called from client when player finishes using an inventory station. The each component of the selected
    // load out is passed separately because Unreal does not like serialising structs.
    function serverFinishInventoryStationAccess(
    			InventoryStationAccess inputInventoryStation,
    			class<CombatRole> selectedRole,
    			String userSkin,
    			int activeWeaponSlot,
    			optional class<Pack> selectedPack,
    			optional class<HandGrenade> grenades,
    			optional class<Weapon> weaponSlot1,
    			optional class<Weapon> weaponSlot2,
    			optional class<Weapon> weaponSlot3,
    			optional class<Weapon> weaponSlot4,
    			optional class<Weapon> weaponSlot5,
    			optional class<Weapon> weaponSlot6,
    			optional class<Weapon> weaponSlot7,
    			optional class<Weapon> weaponSlot8,
    			optional class<Weapon> weaponSlot9,
    			optional class<Weapon> weaponSlot10)
    {
    	local InventoryStationAccess.InventoryStationLoadout selectedLoadout;

    	// rebuild loadout struct
    	selectedLoadout.role.combatRoleClass = selectedRole;
    	selectedLoadOut.userSkin = userSkin;
    	selectedLoadOut.activeWeaponSlot = activeWeaponSlot;
    	selectedLoadOut.pack.packClass = selectedPack;
    	selectedLoadout.grenades.grenadeClass = grenades;
    	selectedLoadout.weapons[0].weaponClass = weaponSlot1;
    	selectedLoadout.weapons[1].weaponClass = weaponSlot2;
    	selectedLoadout.weapons[2].weaponClass = weaponSlot3;
    	selectedLoadout.weapons[3].weaponClass = weaponSlot4;
    	selectedLoadout.weapons[4].weaponClass = weaponSlot5;
    	selectedLoadout.weapons[5].weaponClass = weaponSlot6;
    	selectedLoadout.weapons[6].weaponClass = weaponSlot7;
    	selectedLoadout.weapons[7].weaponClass = weaponSlot8;
    	selectedLoadout.weapons[8].weaponClass = weaponSlot9;
    	selectedLoadout.weapons[9].weaponClass = weaponSlot10;

    	// confirm that inventory station was actually being used
    	if (inputInventoryStation != inventoryStation)
    	{
    		log("WARNING: attempted to finish using an inventory station that was not being used");
    	}

    	inventoryStation.serverFinishCharacterAccess(selectedLoadout, true);
    }

    //
    // Updates current loadout and restarts the character
    //
    function serverFinishEquippingPreRestart(
    		class<CombatRole> selectedRole,
    		String userSkin,
    		int activeWeaponSlot,
    		optional class<Pack> selectedPack,
    		optional class<HandGrenade> grenades,
    		optional class<Weapon> weaponSlot1,
    		optional class<Weapon> weaponSlot2,
    		optional class<Weapon> weaponSlot3,
    		optional class<Weapon> weaponSlot4,
    		optional class<Weapon> weaponSlot5,
    		optional class<Weapon> weaponSlot6,
    		optional class<Weapon> weaponSlot7,
    		optional class<Weapon> weaponSlot8,
    		optional class<Weapon> weaponSlot9,
    		optional class<Weapon> weaponSlot10)
    {
    	local CustomPlayerLoadout selectedLoadout;
    	local CustomPlayerLoadout.WeaponInfo weaponInfo;
    	local CustomPlayerLoadout.GrenadeInfo grenadeInfo;

    	selectedLoadout = new class'CustomPlayerLoadout';

    	selectedLoadout.combatRoleClass = selectedRole;
    	selectedLoadout.packClass = selectedPack;

    	// add grenades
    	grenadeInfo.grenadeClass = grenades;
    	grenadeInfo.ammo = 0;
    	selectedLoadout.grenades = grenadeInfo;

    	// add weapon 1
    	weaponInfo.weaponClass = weaponSlot1;
    	weaponInfo.ammo = 0;
    	selectedLoadout.weaponList[0] = weaponInfo;
    	// add weapon 2
    	weaponInfo.weaponClass = weaponSlot2;
    	weaponInfo.ammo = 0;
    	selectedLoadout.weaponList[1] = weaponInfo;
    	// add weapon 3
    	weaponInfo.weaponClass = weaponSlot3;
    	weaponInfo.ammo = 0;
    	selectedLoadout.weaponList[2] = weaponInfo;
    	// add weapon 4
    	weaponInfo.weaponClass = weaponSlot4;
    	weaponInfo.ammo = 0;
    	selectedLoadout.weaponList[3] = weaponInfo;
    	// add weapon 5
    	weaponInfo.weaponClass = weaponSlot5;
    	weaponInfo.ammo = 0;
    	selectedLoadout.weaponList[4] = weaponInfo;
    	// add weapon 6
    	weaponInfo.weaponClass = weaponSlot6;
    	weaponInfo.ammo = 0;
    	selectedLoadout.weaponList[5] = weaponInfo;
    	// add weapon 7
    	weaponInfo.weaponClass = weaponSlot7;
    	weaponInfo.ammo = 0;
    	selectedLoadout.weaponList[6] = weaponInfo;
    	// add weapon 8
    	weaponInfo.weaponClass = weaponSlot8;
    	weaponInfo.ammo = 0;
    	selectedLoadout.weaponList[7] = weaponInfo;
    	// add weapon 9
    	weaponInfo.weaponClass = weaponSlot9;
    	weaponInfo.ammo = 0;
    	selectedLoadout.weaponList[8] = weaponInfo;
    	// add weapon 10
    	weaponInfo.weaponClass = weaponSlot10;
    	weaponInfo.ammo = 0;
    	selectedLoadout.weaponList[9] = weaponInfo;

    	currentLoadout = selectedLoadout;

    	GameInfo(Level.Game).RestartPlayer(self);
    }

    //
    // State the player is in when they are equpping at an inventory
    // screen before they spawn.
    //
    simulated state PlayerEquippingPreRestart
    {

    	function EndState()
    	{
    		ClientCloseMenu();
    	}

    	exec function Fire(optional float F)
    	{
    	}

    	exec function AltFire( optional float F )
    	{
    	}

    	exec function releaseFire(optional float F)
    	{
    	}

    	exec function releaseAltFire(optional float F)
    	{
    	}

    	exec function Jetpack(optional float F)
    	{
    	}

    	//
    	// Overriden to avoid access None on Pawn while in this state.
    	// I tried to do a Pawn != None check before it was called, but
    	// it didn't seem to work.
    	//
    	function CalcFirstPersonView(Vector cameraLocation, Rotator cameraRotation)
    	{
    	}

    	function LoadInventoryInterface()
    	{
    		local class<GameInfo> GameInfoClass;

    		GameInfoClass = class<GameInfo>(DynamicLoadObject(GameReplicationInfo.GameClass, class'Class'));
    		inventoryStation = new GameInfoClass.default.InventoryStationAccessClass; //class'InventoryStationStandaloneAccess';

    		// PROBLEM:  inventoryStation needs a currentUser, which is currently of type Character.  But before you spawn, you don't have
    		//           a Pawn.  Maybe change InventoryStationAccess to store the Controller instead?  And then pass the Controller in this
    		//           call to SetupAccessData().
    		InventoryStationStandaloneAccess(inventoryStation).SetupAccessData(TribesReplicationInfo(PlayerReplicationInfo).team);

    		OpenMenu(inventoryStationMenuClass);
    	}

    begin:
    	// hackity hack: waiting for the team to be set before we use it
    	while(TribesReplicationInfo(PlayerReplicationInfo).team == None)
    		sleep(0);

    	LoadInventoryInterface();
    }

    // State PlayerWaitingInventoryStation
    //
    // Player is currently accessing an Inventory Station using a specialised HUD.
    //
    simulated state PlayerWaitingInventoryStation
    {
    	exec function Fire(optional float F)
    	{
    	}

    	exec function AltFire( optional float F )
    	{
    	}

    	exec function releaseFire(optional float F)
    	{
    	}

    	exec function releaseAltFire(optional float F)
    	{
    	}

    	exec function Jetpack(optional float F)
    	{
    	}

    	// keep sending moves to the server so we get state updates
    	function PlayerMove( float DeltaTime )
    	{
    		if (Role < ROLE_Authority)
    			TribesReplicateMove(0, 0, false, false, false);
    	}

    	simulated function PlayerTick(float deltaSeconds)
    	{
    		Global.PlayerTick(deltaSeconds);

    		// check for user death
    		if (pawn == None || pawn.bTearOff)
    		{
    			Pawn = None;
    			if (!IsInState('GameEnded') && !IsInState('Dead'))
    			{
    				GotoState('Dead');
    			}
    			return;
    		}
    	}

    	function BeginState()
    	{
    		ResetSpeedhack();
    	}
    }

    // State PlayerUsingInventoryStation
    //
    // Player is currently accessing an Inventory Station using a specialised HUD.
    //
    state PlayerUsingInventoryStation
    {
    	function BeginState()
    	{
    		if(inventoryStation == None)
    		{
    			GotoState('CharacterMovement');
    			return;
    		}

    		if (character != None)
    		{
    			armorClassBeforeInventoryAccess = character.armorClass;

    			character.unifiedSetVelocity(Vect(0,0,0));
    			character.detachGrapple();
    			character.StopMovementEffects();
    		}

    		// probably a more appropriate place to put this - ideally at start up and after bindings change
    		updateCachedKeyBindings();

    		ResetInputState();
    		ResetSpeedhack();

    		myHud.bHideHud = true;
    		OpenMenu(inventoryStationMenuClass);
    	}

    	function EndState()
    	{
    		local Character user;

    		if (Player.GUIController.IsPageActive(inventoryStationMenuClass))
    			Player.GUIController.CloseMenu();
    		myHud.bHideHud = false;

    		// make sure excess health is not being applied to character
    		user = Character(pawn);
    		if (user != None)
    			user.clampHealthInjection();

    		ResetSpeedhack();

    		inventoryStation = None;
    	}

    	function Tick(float Delta)
    	{
    		// check for station death
    		if (inventoryStation == None || inventoryStation.bDeleteMe)
    		{
    			GotoState('CharacterMovement');
    		}
    	}

    	exec function Fire(optional float F)
    	{
    	}

    	exec function AltFire( optional float F )
    	{
    	}

    	exec function releaseFire(optional float F)
    	{
    	}

    	exec function releaseAltFire(optional float F)
    	{
    	}

    	exec function Jetpack(optional float F)
    	{
    	}

    	exec function inventoryStationSwitchVehiclePosition(byte position, InventoryStationAccess.InventoryStationLoadout selectedLoadout)
    	{
    		serverInventoryStationSwitchVehiclePosition(position, selectedLoadout);
    	}

    	function serverInventoryStationSwitchVehiclePosition(byte position, InventoryStationAccess.InventoryStationLoadout selectedLoadout)
    	{
    		local Vehicle vehicle;
    		local int positionIndex;

    		// get vehicle, if any, this inventory station is based on
    		vehicle = inventoryStation.getVehicleBase();

    		if (vehicle == None)
    			return;

    		// do nothing if cannot enter new position
    		if (!vehicle.canArmourBeDriver(selectedLoadout.role.combatRoleClass.default.armorClass))
    			return;

    		positionIndex = vehicle.getOccupantPositionIndex(Character(Pawn));

    		if (positionIndex < 0)
    		{
    			warn("inventory station user is not occupant of corresponding vehicle");
    			return;
    		}

    		if (!vehicle.canSwitchPosition(positionIndex, position))
    			return;

    		// do processing associated with finishing inventory station use
    		inventoryStation.serverFinishCharacterAccess(selectedLoadout, false);

    		vehicle.switchPosition(positionIndex, position);
    	}

    	function playerMove(float deltaTime)
    	{
    		// need to do this to handle case user is blown off
    		if (Role < ROLE_Authority)
    		{
    			TribesReplicateMove(0, 1, false, false, false);
    		}
    		else
    		{
    			TribesProcessMove(0, 0, 0, 0, 0);
    		}
    	}

    	exec function Suicide()
    	{
    		if (Level.NetMode == NM_Client)
    			return;

    		serverTerminateInventoryStationAccess();

    		super.Suicide();
    	}
    }

    // State PlayerUsingResupplyStation
    //
    // Player is currently accessing a Resupply Station.
    //
    simulated state PlayerUsingResupplyStation
    {
    	exec function Fire(optional float F)
    	{
    	}

    	exec function AltFire( optional float F )
    	{
    	}

    	exec function releaseFire(optional float F)
    	{
    	}

    	exec function releaseAltFire(optional float F)
    	{
    	}

    	exec function Jetpack(optional float F)
    	{
    	}

    	simulated function PlayerTick(float deltaSeconds)
    	{
    		Global.PlayerTick(deltaSeconds);

    		// check for user death
    		if (pawn == None || pawn.bTearOff)
    		{
    			Pawn = None;
    			if (!IsInState('GameEnded') && !IsInState('Dead'))
    			{
    				GotoState('Dead');
    			}
    			return;
    		}
    	}

    	function ServerUse()
    	{
    		currentResupply.access.UsedBy(Pawn);
    	}

    	function EndState()
    	{
    		currentResupply = None;
    	}
    }

    exec function inventoryStationSwitchVehiclePosition(byte position, InventoryStationAccess.InventoryStationLoadout selectedLoadout)
    {
    	// nothing
    }

    function serverInventoryStationSwitchVehiclePosition(byte position, InventoryStationAccess.InventoryStationLoadout selectedLoadout)
    {
    	// nothing
    }

    function processTurretMove(float DeltaTime, float aTurn, float aLookUp)
    {
    }

    function serverTurretMove(float timeStamp, float turn, float lookup, int clientPitch, int clientYaw, optional float importantDelta, optional float importantTurn, optional float importantLookup)
    {
    }

    function clientAdjustTurretPosition(float timeStamp, int serverPitch, int serverYaw, int serverTargetPitch, int serverTargetYaw, name newState)
    {
    	if (newState != GetStateName())
    		GotoState(newState);
    }

    function replicateTurretMove(float DeltaTime, float aTurn, float aLookup)
    {
    }

    // State PlayerTurreting
    //
    // Player controlling a Turret.
    //
    state PlayerTurreting
    {
    ignores SeePlayer, HearNoise, Bump;

    	function TribesServerMove
    	(
    		float TimeStamp,
    		Vector ClientLoc,
    		int View,
    		EDigitalAxisInput forward,
    		EDigitalAxisInput strafe,
    		bool ski,
    		bool thrust,
    		bool jump,
    	    optional byte CompressedImportantTimeDelta,
    		optional int ImportantMoveData
    	)
    	{
    		TribesShortClientAdjustPositionEx
    		(
    			TimeStamp, 0, 0, GetStateName(), MovementState_Stand, Location.X, Location.Y, Location.Z, Location.X, Location.Y, Location.Z
    		);
    	}

    	function PlayerTick(float Delta)
    	{
    		local Turret turret;

    		Global.PlayerTick(Delta);

    		Turret = Turret(Pawn);
    		if (Turret == None)
    			return;

    		// prevent weapons from firing after we leave
    		if (Turret.driver != None && Turret.driver.motor != None)
    			Turret.driver.motor.bFirePressed = false;

    		ProcessZoom(Delta, turret.driver);
    	}

    	function ProcessMove(float DeltaTime, vector NewAccel, EDoubleClickDir DoubleClickMove, rotator DeltaRot)
    	{
    	}

    	function PlayerMove( float DeltaTime )
    	{
    		local Turret turret;
    		local float turn, lookup;

    		turret = Turret(Pawn);
    		if (turret == None)
    			return;

    		// zoom
    		if (turret.motor != None)
    			turret.motor.setZoomed(bZoom != 0);

    		turn = 32.0 * aTurn;
    		lookup = 32.0 * aLookup;
    		if (turret.driver != None && turret.driver.isZoomed())
    		{
    			turn *= zoomedMouseScale[zoomLevel];
    			lookup *= zoomedMouseScale[zoomLevel];
    		}

    		// if a client, replicate the move to the server, else just do the move
    		if (Role < ROLE_Authority)
    			replicateTurretMove(DeltaTime, turn, lookup);
    		else
    			processTurretMove(DeltaTime, turn, lookup);
    	}

    	// Sets the view rotation for the turret based on the input provided.
    	// Used to update the authoritative turret position on the server, as well
    	// as the predicted location on the client.
    	function processTurretMove(float DeltaTime, float turn, float lookup)
    	{
    		local Turret Turret;
    		local Rotator newRot;

    		Turret = Turret(Pawn);
    		if (Turret == None)
    			return;

    		newRot = turret.motor.getViewRotation();

    		newRot.Yaw += turn * DeltaTime;
    		newRot.Pitch += lookUp * DeltaTime;

    		turret.motor.setViewTarget(newRot);

    		turret.updateAim(DeltaTime);
    	}

    	// Performs the actual turret movement locally, stores the result, then sends
    	// the movement to the server
    	function replicateTurretMove(float DeltaTime, float turn, float lookup)
    	{
    		local Turret Turret;
    		local SavedMove newMove;
    		local SavedMove importantMove;
    		local int i;
    		//local float NetMoveDelta;

    		Turret = Turret(Pawn);
    		if (Turret == None)
    			return;

    		// find the most recent important move
    		if ( TribesSavedMoves.Length > 0 )
    		{
    			for (i = TribesSavedMoves.Length - 1; i >= 0; i--)
    			{
    				// find most recent important move to send redundantly
    				if ( TribesSavedMoves[i].strafe != 0 || TribesSavedMoves[i].forward != 0)
    				{
    					importantMove = TribesSavedMoves[i];
    					break;
    				}
    			}
    		}

    		// do the turret move
    		processTurretMove(DeltaTime, turn, lookup);

    		// store the new turret state
    		newMove = TribesGetFreeMove();
    		newMove.Delta = DeltaTime;
    		newMove.strafe = turn;
    		newMove.forward = lookup;
    		newMove.Rotation = turret.motor.getViewRotation();
    		newMove.TimeStamp = Level.TimeSeconds;

    		AppendSavedMove(newMove);

    		// if the last move was held, combined it with this move
    		if ( TribesPendingMove != None )
    		{
    			combinedMoves++;

    			NewMove.combineTurret(TribesPendingMove);
    			TribesPendingMove = None;
    		}

    		// stats
    		replicateMoveCalls++;

    		// Decide whether to hold off on move
    		if (TribesPendingMove == None)
    		{
    			// temporarily disabled
    			/*if ( (Player.CurrentNetSpeed > 10000) && (GameReplicationInfo != None) && (GameReplicationInfo.PRIArray.Length <= 10) )
    				NetMoveDelta = 0;	// full rate
    			else
    				NetMoveDelta = FMax(0.0222,2 * Level.MoveRepSize/Player.CurrentNetSpeed);

    			if ( Level.TimeSeconds - ClientUpdateTime < NetMoveDelta )
    			{
    				TribesPendingMove = NewMove;
    				return;
    			}*/
    		}

    		ClientUpdateTime = Level.TimeSeconds;

    		//log("SENT "@newmove.Timestamp@newmove.strafe@newmove.forward@newmove.rotation.pitch@newmove.rotation.yaw);
    		if (importantMove != None)
    		{
    			serverTurretMove(newMove.TimeStamp, newMove.strafe, newMove.forward, newMove.Rotation.Pitch, newMove.Rotation.Yaw, importantMove.TimeStamp, importantMove.strafe, importantMove.forward);
    		}
    		else
    			serverTurretMove(newMove.TimeStamp, newMove.strafe, newMove.forward, newMove.Rotation.Pitch, newMove.Rotation.Yaw);
    	}

    	// Sends a turret move to the server.
    	// Once the move is received it is carried out in the authoritative gameworld.
    	// The result of the server's processing is sent back to the client to give it an
    	// opportunity to correct itself if needed.
    	function serverTurretMove(float timeStamp, float turn, float lookup, int clientPitch, int clientYaw, optional float importantTimestamp, optional float importantTurn, optional float importantLookup)
    	{
    		local Turret turret;
    		local Rotator viewTarget;
    		local Rotator viewRotation;

    		turret = Turret(Pawn);
    		if (turret == None || turret.motor == None)
    			return;

    		// If this move is outdated, discard it.
    		if ( CurrentTimeStamp >= TimeStamp )
    		{
    			return;
    		}

    		//log("RECEIVED "@Timestamp@turn@lookup@clientPitch@clientYaw);
    		// check if an important move was lost
    		if ( importantTimestamp != 0 )
    		{
    			//log(Timestamp@importantTimestamp@CurrentTimeStamp);
    			if ( CurrentTimeStamp < ImportantTimeStamp )
    			{
    				importantTimestamp = FMin(importantTimestamp, CurrentTimeStamp + MaxResponseTime);
    				processTurretMove(ImportantTimeStamp - CurrentTimeStamp, importantTurn, importantLookup);
    				CurrentTimeStamp = ImportantTimeStamp;
    			}
    		}

    		processTurretMove(FMin(MaxResponseTime, TimeStamp - CurrentTimeStamp), turn, lookup);

    		viewTarget = turret.motor.getViewTarget();
    		viewRotation = turret.motor.getViewRotation();

    		CurrentTimeStamp = timeStamp;

    		// If client has accumulated a noticeable error, correct him.
    		if (Abs(clientPitch - viewRotation.Pitch) > 16 || Abs(clientYaw - viewRotation.Yaw) > 16 || (Level.TimeSeconds - LastUpdateTime > 0.3))
    		{
    			clientAdjustTurretPosition(timeStamp, viewRotation.Pitch, viewRotation.Yaw, viewTarget.Pitch, viewTarget.Yaw, GetStateName());
    			LastUpdateTime = Level.TimeSeconds;
    		}
    	}

    	// Sent from the server to the client to ensure that the client is kept in sync
    	function clientAdjustTurretPosition(float timeStamp, int serverPitch, int serverYaw, int serverTargetPitch, int serverTargetYaw, name newState)
    	{
    		local Turret Turret;
    		local SavedMove	CurrentMove;

    		if (!CommonClientAdjustPosition(timeStamp, newState))
    			return;

    		Turret = Turret(Pawn);
    		if (Turret == None)
    			return;

    		if ( CurrentTimeStamp > TimeStamp )
    			return;		// ignore disordered adjust position message
    		CurrentTimeStamp = timeStamp;

    		while (TribesSavedMoves.Length > 0)
    		{
    			// Discard moves of an earlier timestamp than that sent by the server, and
    			// find the move corresponding to the server timestamp
    			CurrentMove = TribesSavedMoves[0];
    			if ( CurrentMove.TimeStamp <= CurrentTimeStamp )
    			{
    				PopSavedMove();
    				AppendFreeMove(CurrentMove);

    				if ( CurrentMove.TimeStamp == CurrentTimeStamp )
    				{
    					// found the given server move
    					if ( Abs(CurrentMove.rotation.Pitch - serverPitch) <= 16 &&
    						 Abs(CurrentMove.rotation.Yaw - serverYaw) <= 16)
    					{
    						CurrentMove.Clear();
    						return;
    					}

    					CurrentMove.Clear();
    					break;
    				}
    				else
    				{
    					CurrentMove.Clear();
    				}
    			}
    			else
    				break;
    		}

    		replayFromStartLocation.X = serverYaw;
    		replayFromStartLocation.Y = serverPitch;
    		replayFromEndLocation.X = serverTargetYaw;
    		replayFromEndLocation.Y = serverTargetPitch;

    		bUpdatePosition = true;
    	}

    	// Replay moves from a received server position when player gets out of sync
    	function ClientUpdatePosition()
    	{
    		local SavedMove CurrentMove;
    		local int i;
    		local int restored;
    		local Turret Turret;
    		local Rotator newRot;

    		bUpdatePosition = false;

    		Turret = Turret(Pawn);
    		if (Turret == None)
    			return;

    		newRot.Yaw = replayFromStartLocation.X;
    		newRot.Pitch = replayFromStartLocation.Y;
    		turret.overrideCurrentRotation(newRot);
    		newRot.Yaw = replayFromEndLocation.X;
    		newRot.Pitch = replayFromEndLocation.Y;
    		turret.motor.setViewTarget(newRot);

    		bUpdating = true;
    		i = 0;
    		while ( i < TribesSavedMoves.Length )
    		{
    			CurrentMove = TribesSavedMoves[i];
    			// Discard moves older than the correction time stamp
    			if ( CurrentMove.TimeStamp <= CurrentTimeStamp )
    			{
    				CurrentMove.Clear();
    				AppendFreeMove(CurrentMove);
    				PopSavedMove();
    			}
    			else
    			{
    				i++;
    				restored++;

    				processTurretMove(CurrentMove.Delta, CurrentMove.strafe, CurrentMove.forward);
    				CurrentMove.Rotation = turret.motor.getViewRotation();
    			}
    		}
    		if ( TribesPendingMove != None )
    		{
    			restored++;

    			processTurretMove(CurrentMove.Delta, CurrentMove.strafe, CurrentMove.forward);
    			CurrentMove.Rotation = turret.motor.getViewRotation();
    		}

    		if (restored > 0 && debugLogLevel > 0)
    			log("Client turret update position restored "$restored$" moves");

    		bUpdating = false;
    	}

    	exec function Fire(optional float F)
    	{
    		local Turret turret;

    		turret = Turret(Pawn);
    		if (turret != None)
    		{
    			turret.motor.fire();
    		}
    	}

    	exec function AltFire( optional float F )
    	{
    	}

    	exec function releaseFire(optional float F)
    	{
    		local Turret turret;

    		turret = Turret(Pawn);
    		if (turret != None)
    		{
    			turret.motor.releaseFire();
    		}
    	}

    	exec function releaseAltFire(optional float F)
    	{
    	}

    	// When you hit use inside the Turret, you get out.
    	function ServerUse()
    	{
    		local Turret Turret;

    		Turret = Turret(Pawn);
    		if (Turret != None)
    		{
    			Turret.bGetOut = true;
    		}
    	}

    	// player cannot use third person view while manning turrets
    	function ToggleBehindView()
    	{
    		// do nothing
    	}

    	function serverSelectWeapon(Weapon w)
    	{
    		// do nothing
    	}

      	function BeginState()
    	{
    		CleanOutSavedMoves();
    		clientTribesSetHUD(turretHUDClass);
    	}

    	function EndState()
    	{
    		CleanOutSavedMoves();
    		releaseFire();
    	}

    }

    function serverVehicleTurretMove(int packedMoveRotation, int packedVehicleSpaceRotation)
    {
    	local VehicleMountedTurret turret;

    	local rotator moveRotation;
    	local rotator vehicleSpaceRotation;

    	moveRotation = class'Vehicle'.static.unpackPitchAndYaw(packedMoveRotation);

    	vehicleSpaceRotation = class'Vehicle'.static.unpackPitchAndYaw(packedVehicleSpaceRotation);

    	turret = VehicleMountedTurret(Pawn);
    	if (turret == None)
    		return;

    	// client handled counter rotation so simply set it to 0
    	turret.processMove(moveRotation, vehicleSpaceRotation);

    	setRotation(moveRotation);
    }

    // State PlayerVehicleTurreting
    //
    // Player controlling a Turret.
    //
    state PlayerVehicleTurreting
    {
    	ignores SeePlayer, HearNoise, Bump;

    	function TribesServerMove
    	(
    		float TimeStamp,
    		Vector ClientLoc,
    		int View,
    		EDigitalAxisInput forward,
    		EDigitalAxisInput strafe,
    		bool ski,
    		bool thrust,
    		bool jump,
    		optional byte CompressedImportantTimeDelta,
    		optional int ImportantMoveData
    	)
    	{
    		TribesShortClientAdjustPositionEx
    		(
    			TimeStamp, 0, 0, GetStateName(), MovementState_Stand, Location.X, Location.Y, Location.Z, Location.X, Location.Y, Location.Z
    		);
    	}

    	function TribesLongClientAdjustPosition
    	(
    		float TimeStamp,
    		float accumulator,
    		float energy,
    		name newState,
    		Character.MovementState movement,
    		float StartLocX,
    		float StartLocY,
    		float StartLocZ,
    		float EndLocX,
    		float EndLocY,
    		float EndLocZ,
    		float NewVelX,
    		float NewVelY,
    		float NewVelZ
    	)
    	{
    		// do nothing
    	}

    	exec function SwitchWeapon(byte F)
    	{

    	}

    	exec function Suicide()
    	{
    		// suicide character instead of vehicle
    		local VehicleMountedTurret turret;
    		local Character occupant;
    		if (Level.NetMode == NM_Client)
    			return;
    		turret = VehicleMountedTurret(Pawn);
    		occupant = turret.ownerVehicle.positions[turret.positionIndex].occupant;
    		if ((occupant != None) && (Level.TimeSeconds - occupant.LastStartTime > 1))
    			occupant.TakeDamage(occupant.health + 1, None, vect(0.0, 0.0, 0.0), vect(0.0, 0.0, 0.0), class'DamageType');
    	}

    	exec function switchVehiclePosition(byte position)
    	{
    		local VehicleMountedTurret turret;
    		local Character occupant;

    		// handle case we are heavy and trying to switch to a pilot position
    		turret = VehicleMountedTurret(Pawn);
    		occupant = turret.ownerVehicle.positions[turret.positionIndex].occupant;
    		if (turret.ownerVehicle.getTargetPositionIndex(position) == turret.ownerVehicle.driverIndex &&
    				!turret.ownerVehicle.canArmorOccupy(VP_DRIVER, occupant))
    		{
    			lowPriorityPromptText = class'Vehicle'.default.heavyAttemptedToPilot;
    			lowPriorityPromptTimeout = class'Vehicle'.default.heavyAttemptedToPilotSwitchPromptDuration;
    			return;
    		}

    		serverSwitchVehiclePosition(position);
    	}

    	function stateServerSwitchVehiclePosition(byte position)
    	{
    		local VehicleMountedTurret turret;
    		turret = VehicleMountedTurret(Pawn);
    		turret.ownerVehicle.switchPosition(turret.positionIndex, position);
    	}

    	function ProcessMove(float DeltaTime, vector NewAccel, EDoubleClickDir DoubleClickMove, rotator DeltaRot)
    	{

    	}

    	function PlayerMove(float deltaTime)
    	{
    		local rotator moveRotation;
    		local VehicleMountedTurret turret;
    		local DynamicTurretRotationProcessingOutput output;
    		local float zoomScale;

    		turret = VehicleMountedTurret(Pawn);
    		if (turret == None)
    			return;

    		// use turret rotation as base rotation
    		moveRotation = turret.worldSpaceNoRollRotation;

    		// zoom
    		if (turret.getDriver() != None)
    			turret.getDriver().setZoomed(bZoom != 0);

    		zoomScale = 1;
    		if (bZoom != 0)
    			zoomScale = zoomedMouseScale[zoomLevel];

    		// apply user input (copy pasted from PlayerController.UpdateRotation)
    		moveRotation.Yaw += 32.0 * deltaTime * aTurn * zoomScale;
    		moveRotation.Pitch += 32.0 * deltaTime * aLookUp * zoomScale;

    		output = dynamicTurretRotationProcessing(moveRotation, turret.ownerVehicle.Rotation, turret.minimumPitch, turret.maximumPitch,
    				turret.yawConstrained, turret.yawPositiveDirection, turret.yawStart, turret.yawRange);
    		turret.worldSpaceNoRollRotation = output.worldSpaceNoRollRotation;
    		turret.vehicleSpaceRotation = output.vehicleSpaceRotation;

    		setRotation(turret.worldSpaceNoRollRotation);

    		// forward to result server
    		if (Role < ROLE_Authority)
    		{
    			serverVehicleTurretMove(class'Vehicle'.static.packPitchAndYaw(turret.worldSpaceNoRollRotation),
    					class'Vehicle'.static.packPitchAndYaw(turret.vehicleSpaceRotation));
    		}
    	}

    	function ViewShake(float deltaTime)
    	{
    		// ignored
    	}

    	exec function fire(optional float F)
    	{
    		local VehicleMountedTurret turret;

    		turret = VehicleMountedTurret(Pawn);
    		if (turret == None)
    			return;

    		turret.turretFire();
    	}

    	exec function AltFire( optional float F )
    	{
    	}

    	exec function releaseFire(optional float F)
    	{
    		local VehicleMountedTurret turret;

    		turret = VehicleMountedTurret(Pawn);
    		if (turret == None)
    			return;

    		turret.turretCeaseFire();
    	}

    	exec function releaseAltFire(optional float F)
    	{
    	}

    	// When you hit use inside the Turret, you get out.
    	function ServerUse()
    	{
    		local VehicleMountedTurret turret;

    		if (Role != ROLE_Authority)
    			return;

    		turret = VehicleMountedTurret(Pawn);
    		if (turret != None)
    		{
    			turret.getOut();
    		}
    	}

    	function BeginState()
    	{
    		local VehicleMountedTurret turret;

    		bOldBehindView = bBehindView;

    		CleanOutSavedMoves();
    		clientTribesSetHUD(vehicleHUDClass);

    		// set initial worldSpaceNoRollRotation as it is not updated when there is no occupant
    		turret = VehicleMountedTurret(Pawn);
    		if (turret != None)
    			turret.worldSpaceNoRollRotation = turret.getDefaultOccupantRotation();
    	}

    	function EndState()
    	{
    		CleanOutSavedMoves();
    		releaseFire();

    		bBehindView = bOldBehindView;
    	}

    	// player cannot use third person view while manning vehicle turrets
    	function ToggleBehindView()
    	{
    		// do nothing
    	}

    	event playerTick(float deltaTime)
    	{
    		local VehicleMountedTurret turret;

    		Global.playerTick(deltaTime);

    		turret = VehicleMountedTurret(Pawn);
    		if (turret != None)
    			ProcessZoom(deltaTime, turret.getDriver());
    	}

    	exec function NextWeapon()
    	{
    		// nothing
    	}

    	exec function PrevWeapon()
    	{
    		// nothing
    	}

    	exec function equipCarryable()
    	{
    	}

    	exec function equipDeployable()
    	{
    	}
    }

    exec function switchVehiclePosition(byte position)
    {
    	// nothing
    }

    function serverSwitchVehiclePosition(byte position)
    {
    	stateServerSwitchVehiclePosition(position);
    }

    // I originally simply implemented serverSwitchVehiclePosition in the appropriate states however I found that it would not correctly
    // replicate to one of the states. To work around this I replicate a global function, serverSwitchVehiclePosition, and then forward the
    // call to the states server side using stateServerSwitchVehiclePosition.
    function stateServerSwitchVehiclePosition(byte position)
    {

    }

    function tribesProcessDrive(float inForward, float inStrafe, rotator directionRotation, bool inThrust, bool inDive)
    {
    }

    function tribesServerDrive(EDigitalAxisInput inForward, EDigitalAxisInput inStrafe, int packedRotation, bool inThrust, bool inDive)
    {
    	local rotator directionRotation;
    	directionRotation = class'Vehicle'.static.unpackPitchAndYaw(packedRotation);
    	tribesProcessDrive(digitalToAnalogue(inForward, 24000), digitalToAnalogue(inStrafe, 24000), directionRotation, inThrust, inDive);
    }

    // State TribesPlayerDriving
    //
    // Player driving a vehicle.
    //
    state TribesPlayerDriving
    {
    ignores SeePlayer, HearNoise, Bump;

    	function TribesServerMove
    	(
    		float TimeStamp,
    		Vector ClientLoc,
    		int View,
    		EDigitalAxisInput forward,
    		EDigitalAxisInput strafe,
    		bool ski,
    		bool thrust,
    		bool jump,
    		optional byte CompressedImportantTimeDelta,
    		optional int ImportantMoveData
    	)
    	{
    		TribesShortClientAdjustPositionEx
    		(
    			TimeStamp, 0, 0, GetStateName(), MovementState_Stand, Location.X, Location.Y, Location.Z, Location.X, Location.Y, Location.Z
    		);
    	}

    	function TribesLongClientAdjustPosition
    	(
    			float TimeStamp,
    			float accumulator,
    			float energy,
    			name newState,
    			Character.MovementState movement,
    			float StartLocX,
    			float StartLocY,
    			float StartLocZ,
    			float EndLocX,
    			float EndLocY,
    			float EndLocZ,
    			float NewVelX,
    			float NewVelY,
    			float NewVelZ
    	)
    	{
    		if (!CommonClientAdjustPosition(timeStamp, newState))
    			return;
    	}

    	exec function SwitchWeapon(byte F)
    	{

    	}

    	exec function Suicide()
    	{
    		// suicide character instead of vehicle
    		local Vehicle vehicle;
    		local Character occupant;
    		if (Level.NetMode == NM_Client)
    			return;
    		vehicle = Vehicle(Pawn);
    		occupant = vehicle.positions[vehicle.driverIndex].occupant;
    		if ((occupant != None) && (Level.TimeSeconds - occupant.LastStartTime > 1))
    			occupant.TakeDamage(occupant.health + 1, None, vect(0.0, 0.0, 0.0), vect(0.0, 0.0, 0.0), class'DamageType');
    	}

    	exec function switchVehiclePosition(byte position)
    	{
    		serverSwitchVehiclePosition(position);
    	}

    	function stateServerSwitchVehiclePosition(byte position)
    	{
    		local Vehicle vehicle;
    		vehicle = Vehicle(Pawn);
    		vehicle.switchPosition(vehicle.driverIndex, position);
    	}

    	function ProcessMove(float DeltaTime, vector NewAccel, EDoubleClickDir DoubleClickMove, rotator DeltaRot)
    	{

    	}

        exec function fire(optional float F)
        {
    		local Vehicle drivenVehicle;

    		drivenVehicle = Vehicle(Pawn);
    		if (drivenVehicle != None)
    		{
    			drivenVehicle.vehicleFire();
    		}
        }

    	exec function releaseFire(optional float F)
    	{
    		local Vehicle drivenVehicle;

    		drivenVehicle = Vehicle(Pawn);
    		if (drivenVehicle != None)
    		{
    			drivenVehicle.vehicleCeaseFire();
    		}
    	}

        exec function altFire(optional float F)
        {

        }

    	exec function releaseAltFire(optional float F)
    	{

    	}

    	// When you hit use inside the SVehicle, you get out.
    	function ServerUse()
    	{
    		local Vehicle drivenVehicle;

    		if (Role != ROLE_Authority)
    			return;

    		drivenVehicle = Vehicle(Pawn);
    		if (drivenVehicle != None)
    		{
    			drivenVehicle.getOut(VP_DRIVER);
    		}
    	}

    	// Set the throttle, steering etc. for the vehicle based on the input provided
    	function tribesProcessDrive(float inForward, float inStrafe, rotator directionRotation, bool inThrust, bool inDive)
    	{
    		local Vehicle DrivenVehicle;

    		DrivenVehicle = Vehicle(Pawn);

    		drivenVehicle.motor.driveVehicle(inForward, inStrafe, directionRotation, inThrust, inDive);
    	}

        function PlayerMove( float DeltaTime )
    	{
    		local Vehicle drivenVehicle;
    		local float zoomScale;
    		local rotator newRotation;

    		drivenVehicle = Vehicle(Pawn);

    		if (drivenVehicle == None)
    			return;

    		// zoom
    		if (drivenVehicle.getDriver() != None)
    			drivenVehicle.getDriver().setZoomed(bZoom != 0);

    		zoomScale = 1;
    		if (bZoom != 0)
    			zoomScale = zoomedMouseScale[zoomLevel];

    		newRotation = Rotation;

    		// apply user input (copy pasted from PlayerController.UpdateRotation)
    		newRotation.Yaw += 32.0 * deltaTime * aTurn * zoomScale;
    		newRotation.Pitch += 32.0 * deltaTime * aLookUp * zoomScale;

    		newRotation = normalize(newRotation);
    		newRotation.Pitch = clamp(newRotation.Pitch, drivenVehicle.driverMinimumPitch, drivenVehicle.driverMaximumPitch);

    		setRotation(newRotation);

    		// give vehicle a chance to do any necessary processing
    		drivenVehicle.playerMoveProcessing(DeltaTime);

    		// only servers can actually do the driving logic
    		if (Role < ROLE_Authority)
    			tribesServerDrive(analogueToDigital(aForward, 24000), analogueToDigital(aStrafe, 24000), class'Vehicle'.static.packPitchAndYaw(Rotation), bJetpack == 1, bSki == 1);
    		else
    			tribesProcessDrive(aForward, aStrafe, Rotation, bJetpack == 1, bSki == 1);
    	}

    	event playerTick(float deltaTime)
    	{
    		local Vehicle drivenVehicle;

    		Global.playerTick(deltaTime);

    		drivenVehicle = Vehicle(Pawn);
    		if (drivenVehicle != None)
    			ProcessZoom(deltaTime, drivenVehicle.getDriver());
    	}

    	function ToggleBehindView()
    	{
    		// do nothing
    	}

    	function BeginState()
    	{
    		bOldBehindView = bBehindView;

    		CleanOutSavedMoves();
    		clientTribesSetHUD(vehicleHUDClass);
    	}

    	function EndState()
    	{
    		local Vehicle DrivenVehicle;

    		CleanOutSavedMoves();

    		bBehindView = bOldBehindView;

    		// turn vehicle off
    		DrivenVehicle = Vehicle(Pawn);
    		if (DrivenVehicle != None)
    			drivenVehicle.motor.driveVehicle(0, 0, Rotation, false, false);
    	}

    	function Pawn GetTravelPawn()
    	{
    		local Vehicle drivenVehicle;

    		drivenVehicle = Vehicle(Pawn);
    		if (drivenVehicle != None)
    			return drivenVehicle.getDriver();
    		else
    			return global.GetTravelPawn();
    	}

    	exec function NextWeapon()
    	{
    		// nothing
    	}

    	exec function PrevWeapon()
    	{
    		// nothing
    	}

    	exec function equipCarryable()
    	{
    	}

    	exec function equipDeployable()
    	{
    	}
    }

    // enter combat alertness.
    // alertness degrades over time, first to alert, then back down to neutral.

    function enterCombat()
    {
        character.setAlertnessLevel(ALERTNESS_Combat);
        SetTimer(alertnessDecayTime, false);

        if (character==None)
            return;

        if (alertnessMode!=AlertnessMode_Default)
            return;
    }

    function Timer()
    {
    	if (character==None)
    		return;

        if (alertnessMode!=AlertnessMode_Default)
            return;

        if (character.getAlertnessLevel()==ALERTNESS_Combat)
        {
            character.setAlertnessLevel(ALERTNESS_Alert);
            SetTimer(alertnessDecayTime, false);
        }
        else
            character.setAlertnessLevel(ALERTNESS_Neutral);
    }

    // serverSelectWeapon
    function serverSelectWeapon(Weapon w)
    {
    	if (character != None && character.motor != None)
    	{
    		character.motor.setWeapon(w);
    	}
    }

    // serverEquipDeployable
    function serverEquipDeployable()
    {
    	local Deployable d;

    	if (character == None)
    		return;

    	d = Deployable(character.nextEquipment(d, class'Deployable'));

    	if (character.deployable == d)
    		return;

    	if (d == None)
    	{
    //		ClientMessage("You do not have a deployable");
    		return;
    	}
    	else
    	{
    		if (character != None && character.motor != None)
    			character.motor.setDeployable(d);
    	}
    }

    // serverEquipCarryable
    function serverEquipCarryable()
    {
    	if (character == None)
    		return;

    	if (character != None && character.motor != None && character.carryableReference != None && character.carryableReference.bIsWeaponType &&
    		character.weapon != character.pseudoWeapon && character.numCarryables > character.numPermanentCarryables)
    		character.motor.setWeapon(character.pseudoWeapon);
    }

    // PrevWeapon
    exec simulated function PrevWeapon()
    {
    	serverPrevWeapon();
    }

    function serverPrevWeapon()
    {
    	local int i;
    	local Weapon w;

    	if (character == None)
    		return;

    	if (character.motor.switchToWeapon != None)
    		w = character.motor.switchToWeapon;
    	else
    		w = character.weapon;

    	if (w != None && w != character.fallbackWeapon && w != character.pseudoWeapon && character.deployable == None)
    	{
    		for (i = 0; i < class'Character'.const.NUM_WEAPON_SLOTS; ++i)
    			if (character.weaponSlots[i] == w)
    				break;

    		if (i < class'Character'.const.NUM_WEAPON_SLOTS)
    		{
    			--i;

    			if (i < 0)
    				i = class'Character'.const.NUM_WEAPON_SLOTS - 1;

    			while (character.weaponSlots[i] == None)
    			{
    				--i;

    				if (i < 0)
    					i = class'Character'.const.NUM_WEAPON_SLOTS - 1;
    			}

    			if (character.weaponSlots[i] != w)
    				serverSelectWeapon(character.weaponSlots[i]);
    		}
    	}
    	else // No current weapon so just find the last non-None weapon
    	{
    		for (i = class'Character'.const.NUM_WEAPON_SLOTS - 1; i >= 0 ; --i)
    		{
    			if (character.weaponSlots[i] != None)
    			{
    				serverSelectWeapon(character.weaponSlots[i]);
    				return;
    			}
    		}
    	}
    }

    // NextWeapon
    exec simulated function NextWeapon()
    {
    	serverNextWeapon();
    }

    function serverNextWeapon()
    {
    	local int i;
    	local Weapon w;

    	if (character == None)
    		return;

    	if (character.motor.switchToWeapon != None)
    		w = character.motor.switchToWeapon;
    	else
    		w = character.weapon;

    	if (w != None && w != character.fallbackWeapon && w != character.pseudoWeapon && character.deployable == None)
    	{
    		for (i = 0; i < class'Character'.const.NUM_WEAPON_SLOTS; ++i)
    			if (character.weaponSlots[i] == w)
    				break;

    		if (i < class'Character'.const.NUM_WEAPON_SLOTS)
    		{
    			i = (i + 1) % class'Character'.const.NUM_WEAPON_SLOTS;

    			while (character.weaponSlots[i] == None)
    				i = (i + 1) % class'Character'.const.NUM_WEAPON_SLOTS;

    			if (character.weaponSlots[i] != w)
    				serverSelectWeapon(character.weaponSlots[i]);
    		}
    	}
    	else // No current weapon so just find the first non-None weapon
    	{
    		for (i = 0; i < class'Character'.const.NUM_WEAPON_SLOTS; ++i)
    		{
    			if (character.weaponSlots[i] != None)
    			{
    				serverSelectWeapon(character.weaponSlots[i]);
    				return;
    			}
    		}
    	}
    }

    simulated function ShiftWeapon(int offset)
    {
    	local int i;
    	local Weapon w;

    	if (character == None)
    		return;

    	if (character.motor.switchToWeapon != None)
    		w = character.motor.switchToWeapon;
    	else
    		w = character.weapon;

    	if (w != None)
    	{
    		for (i = 0; i < class'Character'.const.NUM_WEAPON_SLOTS; ++i)
    			if (character.weaponSlots[i] == w)
    				break;

    		if (i < class'Character'.const.NUM_WEAPON_SLOTS)
    		{
    			i += offset;

    			if (i < 0)
    				i = class'Character'.const.NUM_WEAPON_SLOTS - 1;
    			else if (i >= class'Character'.const.NUM_WEAPON_SLOTS)
    				i = 0;

    			serverSelectWeapon(character.weaponSlots[i]);
    		}
    	}
    	else // There is no current weapon so the concept of next prev don't apply. Find the first non-None weapon
    	{
    		for (i = 0; i < class'Character'.const.NUM_WEAPON_SLOTS; ++i)
    			if (character.weaponSlots[i] != None)
    				break;

    		if (i < class'Character'.const.NUM_WEAPON_SLOTS)
    			serverSelectWeapon(character.weaponSlots[i]);
    	}
    }

    // SwitchWeapon
    exec function SwitchWeapon(byte F)
    {
    	//local int i;
    	local Weapon w;

    	if (character == None)
    		return;

    	w = character.weaponSlots[F - 1];

    	if (w != None)
    	{
    		if (bDropWeapon != 0)
    			w.drop();
    		else
    			serverSelectWeapon(w);
    	}
    }

    // Equips a particular weapon class
    exec function SetWeapon(class<Weapon> WeaponClass)
    {
    	local Weapon w;

    	w = Weapon(character.nextEquipment(w, WeaponClass));

    	if (w == None)
    		return;

    	if (bDropWeapon != 0)
    		w.drop();
    	else
    		serverSelectWeapon(w);
    }

    exec function SwitchToFallbackWeapon()
    {
    	if (character == None && character.motor != None)
    		return;

    	serverEquipFallbackWeapon();
    }

    // Allow zoom level changes when not zoomed
    exec simulated function forceCycleZoomLevel(optional bool bReverse)
    {
    	if (character == None)
    		return;

    	if (!bReverse)
    	{
    		zoomLevel = zoomLevel + 1;
    		if (zoomLevel == zoomedFOVs.Length)
    			zoomLevel = 0;
    	}
    	else
    	{
    		zoomLevel = zoomLevel - 1;
    		if (zoomLevel < 0)
    			zoomLevel = zoomedFOVs.Length - 1;
    	}
    }

    exec simulated function setZoomLevel(int index)
    {
    	if (character == None)
    		return;

    	zoomLevel = index;
    	if (zoomLevel >= zoomedFOVs.Length)
    		zoomLevel = zoomedFOVs.Length - 1;
    	else if (zoomLevel < 0)
    		zoomLevel = 0;
    }

    // cycleZoomLevel
    exec simulated function cycleZoomLevel(optional bool bReverse)
    {
    	if (character == None)
    		return;

    	if (character.isZoomed())
    	{
    		if (!bReverse)
    		{
    			zoomLevel = zoomLevel + 1;
    			if (zoomLevel == zoomedFOVs.Length)
    				zoomLevel = 0;
    		}
    		else
    		{
    			zoomLevel = zoomLevel - 1;
    			if (zoomLevel < 0)
    				zoomLevel = zoomedFOVs.Length - 1;
    		}
    	}
    }

    // CycleRadarZoomScale
    exec simulated function CycleRadarZoomScale()
    {
    	if(character == None)
    		return;

    	radarZoomIndex = (radarZoomIndex + 1) % radarZoomScales.Length;

    	serverSetRadarZoomScale(radarZoomScales[radarZoomIndex]);
    }

    // cycles the index into the size of the chat
    // window (ie: number of lines to display
    exec simulated function CycleChatWindowSize()
    {
    	if(IsSinglePlayer())
    		SPChatWindowSizeIndex = (SPChatWindowSizeIndex + 1) % SPChatWindowSizes.Length;
    	else
    		chatWindowSizeIndex = (chatWindowSizeIndex + 1) % chatWindowSizes.Length;
    }

    // Scrolls the chat window text by a specified numer of lines
    //
    exec simulated function ScrollChatWindow(int NumLines)
    {
    	clientSideChar.ChatScrollDelta += NumLines;
    }

    // equipDeployable
    exec simulated function equipDeployable()
    {
    	serverEquipDeployable();
    }

    // equipCarryable
    exec simulated function equipCarryable()
    {
    	serverEquipCarryable();
    }

    // called to talk
    exec function TribesTalk()
    {
    	// dont let SP players talk
    	if(! IsSinglePLayer())
    		clientSideChar.bTalk = true;
    	else
    		clientSideChar.bTeamTalk = false;
    }

    // called to teamtalk
    exec function TribesTeamTalk()
    {
    	// dont let SP players talk
    	if(! IsSinglePLayer())
    		clientSideChar.bTeamTalk = true;
    	else
    		clientSideChar.bTeamTalk = false;
    }

    function bool IsChatSpam()
    {
    	if(! ChatSpamGuardEnabled)
    		return false;

    	// still muted, return true instantly
    	if(Level.TimeSeconds < (ChatSpamMutedTime + ChatSpamMutePeriod))
    		return true;

    	if(Level.TimeSeconds > (LastValidChatTime + ChatSpamThresholdTime))
    	{
    		LastValidChatTime = Level.TimeSeconds;
    		ChatCount = 0;
    	}
    	else
    	{
    		ChatCount++;
    		if(ChatCount >= ChatSpamMaxMessages)
    		{
    			ChatCount = 0;
    			ChatSpamMutedTime = Level.TimeSeconds;
    		}
    	}

    	return false;
    }

    function ApplyMessageRestrictions(out String Msg)
    {
    	Msg = TribesReplicationInfo(PlayerReplicationInfo).stripCodes(Msg);
    	Msg = Repl(Msg, "¼", "", false);
    	if(Len(Msg) > MaxMessageTextLength)
    		Msg = Left(Msg, MaxMessageTextLength);
    }

    exec function Say(String Msg)
    {
    	if(IsChatSpam())
    		return;

    	ApplyMessageRestrictions(Msg);
    	super.Say(Msg);
    }

    exec function TeamSay(String Msg)
    {
    	if(IsChatSpam())
    		return;

    	ApplyMessageRestrictions(Msg);
    	super.TeamSay(Msg);
    }

    exec function QuickChat(String message, String ChatTag, optional bool bLocal, optional String animName)
    {
    	if(IsChatSpam())
    		return;

    	ApplyMessageRestrictions(message);

    	if(! bLocal)
    	{
    		Level.Game.Broadcast(self, ChatTag $"?" $message, 'QuickChat');
    		if(Character(Pawn) != None && animName != "")
    			Character(Pawn).PlayQCAnimation(animName);
    	}
    	else if(Character(Pawn) != None)
    	{
    		Character(Pawn).PlayQCSpeech(ChatTag);
    		if(animName != "")
    			Character(Pawn).PlayQCAnimation(animName);
    	}
    }

    exec function TeamQuickChat(String message, String ChatTag, optional bool bLocal, optional String animName)
    {
    	if(IsChatSpam())
    		return;

    	ApplyMessageRestrictions(message);

    	if(! bLocal)
    	{
    		Level.Game.BroadcastTeam(self, ChatTag $"?" $message, 'TeamQuickChat');
    		if(Character(Pawn) != None && animName != "")
    			Character(Pawn).PlayQCAnimation(animName);
    	}
    	else if(Character(Pawn) != None)
    	{
    		Character(Pawn).PlayQCSpeech(ChatTag);
    		if(animName != "")
    			Character(Pawn).PlayQCAnimation(animName);
    	}
    }

    exec function ShowHelpScreen()
    {
    	// uncomment when the menu is finished (needs Art)
    	MyHUD.bHideHud = true;
    	ClientOpenMenu(HelpScreenClass);
    }

    // ProcessZoom
    simulated function ProcessZoom(float Delta, Character c)
    {
    	if (c == None)
    		return;

    	if (c.bCanZoom)
    	{
    		if (c.isZoomed())
    		{
    			if (FOVAngle > zoomedFOVs[zoomLevel])
    				FOVAngle -= (FOVAngle - zoomedFOVs[zoomLevel]) * zoomSpeed;
    			else
    				FOVAngle = zoomedFOVs[zoomLevel];
    		}
    		else
    		{
    			if (FOVAngle < DefaultFOV)
    				FOVAngle += (DefaultFOV - FOVAngle) * zoomSpeed;
    			else
    				FOVAngle = DefaultFOV;
    		}
    	}
    	else
    	{
    		FOVAngle = DefaultFOV;
    	}
    }

    // setIsFemale
    function setIsFemale(bool b)
    {
    	PlayerReplicationInfo.bIsFemale = b;
    	MultiplayerGameInfo(Level.Game).SetPlayerMesh(self);
    }

    // changeTeam (replicated)
    function changeTeam(int i, optional bool bAdminOverride)
    {
    	local TeamInfo t;
    	local TribesReplicationInfo TRI;

    	// See if this switchteam is allowed, unless an admin has overridden it
    	if (!bAdminOverride)
    	{
    		if (!Level.Game.ChangeTeam(self, i, true))
    			return;
    	}

    	t = getTeamInfo(i);
    	TRI = TribesReplicationInfo(PlayerReplicationInfo);

    	if (t == None || TRI.team == t)
    		return;

    	if (character != None)
    	{
    		character.Died( None, class'DamageType', character.Location );
    	}

    	TRI.setTeam(t);
    	TRI.bTeamChanged = true;

    	GotoState('PlayerRespawn');
    	ClientGotoState('PlayerRespawn');
    }

    function TeamInfo getTeamInfo(int index)
    {
    	local TeamInfo t;

    	ForEach DynamicActors(class'TeamInfo', t)
    	{
    		if (t.TeamIndex == index)
                return t;
    	}

    	return None;
    }

    // switchTeam (replicated)
    function switchTeam(optional bool bAdminOverride)
    {
    	local TeamInfo t;
    	local bool bFoundTeam;
    	local TribesReplicationInfo TRI;

    	ForEach DynamicActors(class'TeamInfo', t)
    	{
    		if (bFoundTeam)
    			break;

    		if (TribesReplicationInfo(PlayerReplicationInfo).team == t)
                bFoundTeam = true;
    	}

    	if (t == None)
    		ForEach DynamicActors(class'TeamInfo', t)
    			break;

    	if (t == None)
    		return;

    	// See if this switchteam is allowed, unless an admin has overridden it
    	if (!bAdminOverride)
    	{
    		if (!Level.Game.ChangeTeam(self, t.TeamIndex, true))
    			return;
    	}

    	if (Pawn != None)
    	{
    		serverKillPlayer();
    	}

    	TRI = TribesReplicationInfo(PlayerReplicationInfo);
    	TRI.setTeam(t);
    	TRI.bTeamChanged = true;

    	GotoState('PlayerRespawn');
    	ClientGotoState('PlayerRespawn');
    }

    // spectate (replicated)
    function spectate(optional string playerName)
    {
    	if (PlayerReplicationInfo.bIsSpectator && playerName != "")
    	{
    		SpectatePlayer(playerName);
    		return;
    	}

    	if (PlayerReplicationInfo.bIsSpectator && playerName != "")
    	{
    		GameInfo(Level.Game).onUnspectate(self);
    	}
    	else
    		GameInfo(Level.Game).onSpectate(self);
    }

    function SpectatePlayer(string playerName)
    {
        local Controller C, Pick;
        local bool bFound, bRealSpec, bWasSpec;

        bRealSpec = PlayerReplicationInfo.bOnlySpectator;
        bWasSpec = !bBehindView && (ViewTarget != Pawn) && (ViewTarget != self);
        PlayerReplicationInfo.bOnlySpectator = true;

    	// view player
    	for ( C=Level.ControllerList; C!=None; C=C.NextController )
    	{
            if ( C.playerReplicationInfo != None && C.playerReplicationInfo.PlayerName == playerName && Level.Game.CanSpectate(self,true,C) )
    		{
    			if ( Pick == None )
                    Pick = C;
    			if ( bFound )
    			{
                    Pick = C;

    				// Don't allow spectating of spectators
    				if (Pick.playerReplicationInfo.bIsSpectator)
    					return;

    				break;
    			}
    			else
                    bFound = ( (RealViewTarget == C) || (ViewTarget == C) );
    		}
    	}

    	if (Pick == None)
    		return;

    	SetViewTarget(Pick);
        ClientSetViewTarget(Pick);
    	bBehindView = true; //bChaseCam;
        ClientSetBehindView(bBehindView);
        PlayerReplicationInfo.bOnlySpectator = bRealSpec;
    }

    exec function activatePack()
    {
    	serverActivatePack();

    	// forward to character
    	if (Level.NetMode != NM_Client && character != None)
    		character.activatePack();
    }

    function serverActivatePack()
    {
    	// forward to character
    	if (character != None)
    		character.activatePack();
    }

    ///////////////////////////////////////////////////////////////////////////////
    //
    // Adds a damage direction to the flags in the hud data
    //
    simulated function ClientDamagedFrom(EDirectionType direction, int DamageAmount)
    {
    	if(clientSideChar.DamageAmounts[direction] < DamageAmount)
    		clientSideChar.DamageAmounts[direction] = DamageAmount;
    }

    function NotifyTakeHit(pawn InstigatedBy, vector HitLocation, int Damage, class<DamageType> damageType, vector Momentum)
    {
    	local vector color;
    	local float damagePercentage, scale;

    	local vector direction, xAxis, yAxis, zAxis;
    	local float longDot, latDot;
    	local Rotator rotation;

    	color = damageFlashColor;

    	if (damageFlashColor.X != 0)
    		damageFlashColor.X += Damage * damageFlashMultiplier;
    	if (damageFlashColor.Y != 0)
    		damageFlashColor.Y += Damage * damageFlashMultiplier;
    	if (damageFlashColor.Z != 0)
    		damageFlashColor.Z += Damage * damageFlashMultiplier;

    	// scale should be maximum at maxFlashThreshold
    	// remember that with the scale, less is more
    	damagePercentage = fClamp((Damage / character.healthMaximum) / maxFlashThreshold, 0.0, 1.0);
    	scale = fClamp(1.0 - damagePercentage, 0.0, 1.0 - minFlashThreshold);

    	// Flash the screen
    //  if (myHUD.PlayerOwner.ViewTarget==Pawn)
    //		ClientFlash(scale, damageFlashColor);

    	if(Rook != None)
    	{
    		rotation = Normalize(Rook.Rotation);
    		if(InstigatedBy != None)
    			direction = Normal(Rook.Location - InstigatedBy.Location);
    		GetAxes(rotation, xAxis, yAxis, zAxis);
    		longDot = (direction Dot xAxis);

    		rotation.yaw += 16384;
    		GetAxes(rotation, xAxis, yAxis, zAxis);
    		latDot = (direction Dot xAxis);

    		// check if we are hurting ourselves (dumbass!)
    		if(longDot == 0 && latDot == 0)
    		{
    			ClientDamagedFrom(EDirectionType.DAMAGE_Front, Damage);
    			ClientDamagedFrom(EDirectionType.DAMAGE_Rear, Damage);
    			ClientDamagedFrom(EDirectionType.DAMAGE_Left, Damage);
    			ClientDamagedFrom(EDirectionType.DAMAGE_Right, Damage);
    		}

    		if(longDot > 0 && Abs(latDot) < 0.75)
    			ClientDamagedFrom(EDirectionType.DAMAGE_Rear, Damage);
    		if(Abs(longDot) < 0.75 && latDot < 0)
    			ClientDamagedFrom(EDirectionType.DAMAGE_Right, Damage);
    		if(Abs(longDot) < 0.75 && latDot > 0)
    			ClientDamagedFrom(EDirectionType.DAMAGE_Left, Damage);
    		if(longDot < 0 && Abs(latDot) < 0.75)
    			ClientDamagedFrom(EDirectionType.DAMAGE_Front, Damage);
    	}
    }

    // debug function for choosing a spawn base, multiplayer only
    exec function debugSwitchSpawnBase()
    {
    	local BaseInfo b;
    	local BaseInfo chosen;
    	local bool bFound;

    	ForEach DynamicActors(class'BaseInfo', b)
    	{
    		if (bFound && b.team == character.team())
    		{
    			chosen = b;
    			break;
    		}

    		if (b == spawnBase)
    		{
    			bFound = true;
    		}
    	}

    	if (chosen == None) // wrap around
    		ForEach DynamicActors(class'BaseInfo', b)
    			if (b.team == character.team())
    			{
    				chosen = b;
    				break;
    			}

    	spawnBase = chosen;

    	ClientMessage("New spawn base is "$b.label);
    }

    state CameraControlled
    {
    	exec function Fire( optional float F ) {}
    	exec function releaseFire( optional float F ) {}
    	exec function AltFire(optional float F) {}
    	exec function releaseAltFire(optional float F) {}
    	exec function Jetpack( optional float F ) {}

    	exec simulated function bool SkipOpeningCutscene()
    	{
    		if(CutsceneManager(Level.cutsceneManager).CancelOpeningCutscence())
    		{
    			// return control to the player camera:
    			controllingCamera.actionControlledReturn();
    			if (CinematicOverlay != None)
    				CinematicOverlay.ClearSubtitle();
    			return true;
    		}

    		return false;
    	}

    	exec function use()
    	{
    		// freeze player during cutscenes
    		if (isInCutscene())
    			return;

    		controllingCamera.playerControlledReturn();
    	}

    	function playerTick(float deltaSeconds)
    	{
    		// Not sure if we need these yet
    		//ViewShake(DeltaTime);
    		//ViewFlash(DeltaTime);
    	}
    }

    function TeamInfo getOwnTeam()
    {
    	// Figures out what team this controller is on, if applicable
    	return TribesReplicationInfo(PlayerReplicationInfo).team;
    }

    function TeamInfo getOtherTeam()
    {
    	local TeamInfo t;

    	// Returns the first team that isn't the same as this controller's
    	ForEach DynamicActors(class'TeamInfo', t)
    	{
    		if (t != getOwnTeam())
    			return t;
    	}

    	return None;
    }

    function class<Weapon> GetLastWeapon()
    {
    	if ( (Character == None) || (Character.Weapon == None) )
    		return lastWeaponClass;
    	return Character.Weapon.Class;
    }

    function Tick(Float Delta)
    {
    	Super.Tick(Delta);

    	// duplicated in PlayerTick
    	// Listen servers don't run this for the player's own controller, but run this for joined players.
    	camera.update(Delta);

    	// Update objectives every tick
    	if(PlayerReplicationInfo.IsA('TribesReplicationInfo'))
    		objectives.updateObjectives(objectivesUpdateRate, TribesReplicationInfo(PlayerReplicationInfo).team);
    	else
    		objectives.updateObjectives(objectivesUpdateRate, None);
    }

    exec function Use()
    {
    	if (bUseEnabled)
    		Super.Use();
    }

    // Player muting
    function bool IsMuted(String PlayerName)
    {
    	local int i;

    	for(i = 0; i < MutedPlayerList.Length; ++i)
    		if(MutedPlayerList[i] ~= PlayerName)
    			return true;

    	return false;
    }

    // toggles player muting
    exec function Mute(String PlayerName)
    {
    	local int i;
    	local bool found;

    	found = false;
    	for(i = 0; i < MutedPlayerList.Length; ++i)
    	{
    		if(MutedPlayerList[i] ~= PlayerName)
    		{
    			MutedPlayerList.Remove(i--, 1);
    			found = true;
    		}
    	}

    	if(! found)
    		MutedPlayerList[MutedPlayerList.Length] = PlayerName;
    }

    // will only switch it off
    exec function UnMute(String PlayerName)
    {
    	// if the player is muted, call Mute to toggle the mote to off.
    	if(IsMuted(PlayerName))
    		Mute(PlayerName);
    }

    exec function ToggleQuickChat()
    {
    	if(bQuickChat == 1)
    		bQuickChat = 0;
    	else
    		bQuickChat = 1;
    }

    function serverDebugMovementReplication(int level)
    {
    	if (class'GameEngine'.default.EnableDevTools)
    		debugLogLevel = level;
    }

    exec function debugMovementReplication(int level)
    {
    	if (class'GameEngine'.default.EnableDevTools)
    	{
    		debugLogLevel = level;
    		ClientMessage("Movement replication debug: "$debugLogLevel);
    		serverDebugMovementReplication(level);
    	}
    }

    exec function movementReport()
    {
        local float correctedPerc, combinedPerc, dualPerc;

    	correctedPerc = (float(correctedMoves) / float(replicateMoveCalls))*100.0;
    	combinedPerc = (float(combinedMoves) / float(replicateMoveCalls))*100.0;
    	dualPerc = (float(dualMoves) / float(replicateMoveCalls))*100.0;

    	// report stats
    	LOG("-- PlayerCharacterController Stats --");
    	LOG("ReplicateMove Calls : "$replicateMoveCalls);
    	LOG("Combined Moves      : "$combinedMoves$" ("$combinedPerc$"%)");
    	LOG("Corrections		 : "$correctedMoves$" ("$correctedPerc$"% if 0 loss)");
    	LOG("Dual Moves			 : "$dualMoves$" ("$dualPerc$"% if 0 loss)");
    }

    // use PlayerCamera class
    simulated event PlayerCalcView(out actor ViewActor, out vector CameraLocation, out rotator CameraRotation )
    {
    	// If desired, call the pawn's own special callview
    	if( Pawn != None && Pawn.bSpecialCalcView )
    	{
    		// try the 'special' calcview. This may return false if its not applicable, and we do the usual.
    		if( Pawn.SpecialCalcView(ViewActor, CameraLocation, CameraRotation) )
    			return;
    	}

    	if ( (ViewTarget == None) || ViewTarget.bDeleteMe )
    	{
    		if ( (Pawn != None) && !Pawn.bDeleteMe )
    			SetViewTarget(Pawn);
            else if ( RealViewTarget != None )
                SetViewTarget(RealViewTarget);
    		else
    			SetViewTarget(self);
    	}

    	ViewActor = ViewTarget;
    	CameraLocation = ViewTarget.Location;

    	if ( ViewTarget == self )
    	{
    		if ( bCameraPositionLocked )
    			CameraRotation = CheatManager.LockedRotation;
    		else
    			CameraRotation = Rotation;
    // IGA >>> Cinematic camera shake
    		CameraLocation = CameraLocation + CinematicShakeOffset;
    		CameraRotation = CameraRotation + CinematicShakeRotate;
    // IGA
    		return;
    	}
    	else
    		camera.calcView(CameraLocation, CameraRotation);
    }

    simulated function InventoryCalcView(out actor ViewActor, out vector CameraLocation, out rotator CameraRotation )
    {
    	local Rotator StationRotation;

    	if(Buggy(character.Base) != None)
    	{
    		// we are in a Rover Inv station...
    		Buggy(character.Base).InventoryCalcView(ViewActor, CameraLocation, CameraRotation);
    	}
    	else
    	{
    		// always third person
    		ViewActor = Pawn;

    		// calculate camera location
    		StationRotation.Yaw = inventoryStation.Rotation.Yaw + 16384;
    		CameraLocation = Pawn.Location + Pawn.EyePosition() + (InvExtCamOffset >> StationRotation);

    		// point the camera at the inventoryStationAccess
    		CameraRotation = Rotator(Normal(Pawn.Location + Pawn.EyePosition() - cameraLocation));
    	}
    }

    function ServerToggleBehindView()
    {
    	ClientSetBehindView(!bBehindView, true);

    	if (!bBehindView)
    		camera.doZoomOut(0.15);
    	else
    		camera.doZoomIn(0.15);
    }

    function ClientSetBehindView(bool B, optional bool bInteractive)
    {
    	if (bInteractive)
    	{
    		if (B)
    			camera.doZoomOut(0.15);
    		else
    			camera.doZoomIn(0.15);
    	}
    	else
    		bBehindView = B;
    }

    event ShowSubtitle(String Subtitle, float lifetime)
    {
    	if(CinematicOverlay != None
    		&& SingleplayerGameInfo(Level.Game) != None
    		&& SingleplayerGameInfo(Level.Game).default.bShowSubtitles)
    		CinematicOverlay.AddSubtitle(Subtitle, lifetime);
    }

    function SetCinematicMode(bool bCinematic)
    {
    	if(bCinematic)
    	{
    		if(Player.GUIController.OpenMenu("MojoCore.CinematicOverlay"))
    			CinematicOverlay = CinematicOverlay(GUIController(Player.GUIController).ActivePage);
    		else
    			Warn("Could not open cinematic overlay");
    	}
    	else
    	{
    		Player.GUIController.CloseMenu();
    		CinematicOverlay = None;
    	}
    }

    function GivePawn(Pawn NewPawn)
    {
    	//Log("GivePawn called in PCC with "$NewPawn$" for "$self$" in state "$GetStateName()$" and moveobj = "$character.movementObject);
    	if ( NewPawn == None )
    		return;

    	Pawn = NewPawn;
    	NewPawn.Controller = self;

    	ClientRestart(NewPawn, GetStateName());
    }

    function ServerViewNextMPObject()
    {
        local MPActor A, Pick;
        local bool bFound;

    	// view next mp object
    	ForEach Level.AllActors(class'MPActor', A)
    	{
            if ( Level.Game.CanSpectate(self,true,A) )
    		{
    			if ( Pick == None && A.bAllowSpectators )
                    Pick = A;
    			if ( bFound )
    			{
                    Pick = A;
    				break;
    			}
    			else
                    bFound = ( (RealViewTarget == A) || (ViewTarget == A) && A.bAllowSpectators );
    		}
    	}
    	SetViewTarget(Pick.getViewTarget());
        ClientSetViewTarget(Pick.getViewTarget());
        ClientSetBehindView(true);
    }

    function ServerViewNextSpectatorStart()
    {
    	// Not sure how to do this yet
    	// Need to cycle through all PlayerStarts that have bObserverStart set to true; unfortunately they're
    	// not pawns so you can't set them as viewtargets
    }

    function PlayPainSound(Character.EClientPainType type)
    {
    	if (character == None)
    		return;

    	switch (type)
    	{
    	case CLIENTPAIN_Hurt:
    		character.PlayMovementSpeech( 'Hurt' );
    		break;
    	case CLIENTPAIN_BigHurt:
    		character.PlayMovementSpeech( 'HurtLarge' );
    		break;
    	case CLIENTPAIN_Death:
    		character.PlayMovementSpeech( 'Death' );
    		break;
    	case CLIENTPAIN_Cratered:
    		character.PlayMovementSpeech( 'DeathCratered' );
    		break;
    	case CLIENTPAIN_Burnt:
    		character.PlayMovementSpeech( 'DeathScream' );
    		break;
    	}
    }

    function bool isInCutscene()
    {
    	return CutsceneManager(Level.cutsceneManager) != None
    			&& CutsceneManager(Level.cutsceneManager).playingCutscene != None
    			&& CutsceneManager(Level.cutsceneManager).playingCutscene.scriptType == TYPE_OpeningCutscene;
    }

    native function ResetSpeedhack();

    exec function dumpVehicleData()
    {
    	local Vehicle vehicle;

    	log("********** VEHICLE DUMP" @ Level.TimeSeconds @ "**********");
    	forEach DynamicActors(class'Vehicle', Vehicle)
    	{
    		log("==========" @ Vehicle @ "==========");
    		log("Physics:" @ Vehicle.Physics);
    		log("Havok Active:" @ Vehicle.HavokIsActive());
    		log("Havok Completely Initialised:" @ Vehicle.isHavokCompletelyInitialised());
    		log("Tick:" @ Vehicle.LastTick);
    		log("Last State Received Time:" @ Vehicle.lastStateReceiveTime);
    		log("Spawning:" @ Vehicle.spawning);
    		log("Role:" @ Vehicle.Role);
    		log("Tear Off:" @ Vehicle.bTearOff);
    		log("Team:" @ Vehicle.team());
    	}
    }

    defaultproperties
    {
    	// Important for net movement prediction -- MaxResponseTime should equal Fusion's delta clamp value
        MaxResponseTime=1.0
        MaxTimeMargin=1.0
    	TimeMarginSlack=0.001

    	// for PostNetReceive
    	bNetNotify					= true

    	CheatClass					= class'TribesCheatManager'
    	DefaultFOV					= 95

    	spectatorHUDClass			= "TribesGUI.TribesSpectatorHUD"
    	countdownHUDClass			= "TribesGUI.TribesCountdownHUD"
    	gameEndHUDClass				= ""
    	respawnHUDClass				= "TribesGUI.TribesRespawnHUD"
    	vehicleHUDClass				= "TribesGUI.TribesVehicleHUD"
    	turretHUDClass				= "TribesGUI.TribesTurretHUD"
    	inventoryStationMenuClass	= "TribesGUI.TribesInventorySelectionMenu"
    	waitRoundEndHUDClass		= "TribesGUI.TribesAwaitRoundEndHUD"
    	waitGameStartHUDClass		= "TribesGUI.TribesAwaitGameStartHUD"
    	commandHUDClass				= "TribesGUI.TribesCommandHUD"
    	HelpScreenClass				= "TribesGUI.TribesHelpScreen"
    	GUIPackage					= "TribesGUI"
    	SPEscapeMenuClass			= "TribesSPEscapeMenu"
    	MPEscapeMenuClass			= "TribesMPEscapeMenu"
    	MPStatsClass				= "TribesMPStatsPanel"
    	MPWeaponStatsClass			= "TribesMPWeaponStatsPanel"
    	MPGameStatsClass			= "TribesMPPlayersPanel"
    	MPAdminClass				= "TribesMPAdminPanel"

    	MovementObjectClass			= "Gameplay.CharacterPhysicsObject"

    	PlayerReplicationInfoClass	= class'Gameplay.TribesReplicationInfo'

    	m_identifyFrequency			= 0.1
    	m_identifyRange				= 5000

        alertnessMode               = AlertnessMode_Default;
        alertnessDecayTime          = 10

        groundMovementMode          = GroundMovementMode_Any;

    	damageFlashColor			= (X=900,Y=0,Z=0)
    	damageFlashScale			= 0.3
    	maxFlashThreshold			= 0.5
    	minFlashThreshold			= 0.1
    	damageFlashMultiplier		= 1

    	livesLeft				    = -1

    	IdentifyRadius				= 32

    	InvExtCamOffset				= (X=-200,Y=0,Z=210)

    	bUseEnabled					= true
    	debugLogLevel				= 0
        SpectateSpeed=+1200.0
    	maxSpectatorZoom			= 30
    	minSpectatorZoom			= 6

    	ChatSpamGuardEnabled		= true
    	ChatSpamMaxMessages			= 4
    	ChatSpamThresholdTime		= 4
    	ChatSpamMutePeriod			= 8
    	MaxMessageTextLength		= 196
    }

Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

Class file time: èt 9.9.2004 16:25:32.000 - Creation time: st 23.5.2018 00:10:46.430 - Created with UnCodeX