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

ROEngine.ROPlayer


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
//=============================================================================
// ROPlayer
//=============================================================================
// PlayerController class used by Red Orchestra
//=============================================================================
// Red Orchestra Source
// Copyright (C) 2003-2006 Tripwire Interactive LLC
// Created by John Gibson
// Additional code Erik Christensen
//=============================================================================

class ROPlayer extends xPlayer;

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

var		int								DesiredRole;		// Role the player wants to be
var		int								CurrentRole;		// Role the player is currently
var		int								PrimaryWeapon;		// Stores the weapon selections
var		int								SecondaryWeapon;
var		int								GrenadeWeapon;
var		bool							bWeaponsSelected;	// Player has all weapons selected?

var		int								NumVotes;			// Votes cast against this player
var		float							LastVoteTime;
var		array<PlayerReplicationInfo>	VotedBy;

var		bool							bCanRespawn;		// Added to prevent ability to respawn immediately after dying

var     bool                            bPendingMapDisplay;
var     bool                            bFirstRoleAndTeamChange;   // hax? used to detect first time player joins the game (to show map updated icon)
var		bool							bFirstObjectiveScreenDisplayed;
var 	config    	bool  				bShowMapOnFirstSpawn; // Whether or not we want to display the overhead map on the first spawn
var 	config    	bool  				bUseNativeRoleNames;  // Use the old native role names instead of translated role names

// Variables for fade-from-black effect
var     bool                            bDisplayedRoleSelectAtLeastOnce; // Used to do that nifty fade-from-black-after-joining-game effect
var     bool                            bDoFadeFromBlackEffect;
var     float                           FadeFromBlackCurrentOpacity;
var     float                           FadeFromBlackFadeSpeed;
var     float                           FadeFromBlackLastUpdateTime;

// spectating
enum ESpectatorMode
{
	SPEC_Self,
	SPEC_Roaming,
	SPEC_Players,
	SPEC_ViewPoints,
};
var		ESpectatorMode					SpecMode;			// The current view mode when spectating
var		byte							CurrentEntryCam;	// Stores the camera the players is currently viewing from in PlayerWaitng state
var		float							LastSpectateChangeTime; // used to limit how often the player can switch spectate view. Prevents the player from spamming the server

var	localized string 					SpectatingModeName[4]; // localized description of this spectating mode


// Free Aim Area variables

// new free-aim
var		rotator		RecoilRotator;					// Stores recoil added to the free-aim buffer
var		float		LastRecoilTime;                 // Last time we got recoil
var		float		RecoilSpeed;					// The amount of time it will take to process this recoil
var		int			FreeAimMaxYawLimit;				// Maximum yaw rotation of the weapon in free-aim mode
var		int			FreeAimMinYawLimit;             // Minimum yaw rotation of the weapon in free-aim mode
var		int			FreeAimMaxPitchLimit;           // Maximum pitch rotation of the weapon in free-aim mode
var		int			FreeAimMinPitchLimit;           // Minimum pitch rotation of the weapon in free-aim mode

var		float		FAAWeaponRotationFactor;		// FA rotation factor for weapons in their buffer box
var		float		LastFreeAimSuspendTime;			// Used in smoothing out transitions to/from free-aim

var		int 		YawTweenRate;					// Yaw return to center speed when not using free-aim  = FreeAimMaxYawLimit/NumSecondsToTween(0.25)
var		int 		PitchTweenRate;                 // Pitch return to center speed when not using free-aim  = FreeAimMaxPitchLimit/NumSecondsToTween(0.25)

// Weapon Sway
var		bool		bSway;	                        // Weapon sway is enabled
var     float       baseSwayYawAcc;                 // base rate of vertical sway acc
var     float       baseSwayPitchAcc;               // base rate of horizontal sway acc
var     float       SwayPitch;
var     float       SwayYaw;
var     float       WeaponSwayYawRate;
var     float       WeaponSwayPitchRate;
var     float       SwayTime;
var()	InterpCurve	SwayCurve;		 				// The amount of sway to apply based on an input time in ironsights
var 	float		SwayClearTime;
const   SwayElasticFactor = 3.0; 					// is ( 0.002 *   baseSwayYawAcc)
const   SwayDampingFactor = 0.1732;					// dampingFactor = 0.1*sqrt(elasticFactor); // underdamped damping, smoother sway; 0.5*sqrt(elasticFactor) is critically damped

var(Menu)	string	        ROMidGameMenuClass;		// Menu that is shown when Escape is pressed
//var ROCampaignData CampaignData;
var()       config int      GlobalDetailLevel;
var         int             ForcedTeamSelectOnRoleSelectPage;   // -5 == none, -1 = spectator

var vector SavedArtilleryCoords;					// The vector location saved for an artillery

// for switching roles
var     int        	DesiredPrimary;
var     int        	DesiredSecondary;
var     int        	DesiredGrenade;

// Motion blur
var		float		CurrentBlurAmount;				// how much we are blurred currently
var		float		CurrentFadeAmount;				// how much we are blurred currently
var		float		InitialBlurTime;  				// Saves the current blur time
var 	MotionBlur	ShellShockBlur;   				// The motion blur effect
var config    bool  bUseBlurEffect;   				// Wether or not the blur effect should be used
var		byte		AltBlurLevel;
var()	byte		MaxAltBlurLevel;  				// The max amount we want to darken the screen for the alternative blur effect

// Rally point vars
var	    float		LastRallyTime; 					// The last time this controller set a rally point

var	    float		LastPlayerListTime; 			// The last time this player requested the player list (limits how often the player can request the player list so they don't spam the server)

// Destroyable static meshes array
var     array<RODestroyableStaticMeshBase>      Destroyables;

// This is to capture mouse input on the situation map
var     bool        bHudCapturesMouseInputs;
var     bool        bHudLocksPlayerRotation;
var     vector      PlayerMouse;

// For hint management
var     ROHintManager   HintManager;
var     config  bool    bShowHints;

// Vehicle driving
var()	float			ThrottleChangeRate;  		// How quickly to raise/lower the interpolated throttle
var		config bool		bInterpolatedTankThrottle;  // Use an interpolated throttle for tanks. Will gradually increase the throttle while the forward/reverse buttons are pressed instead of the standard all or nothing throttle
var		config bool		bInterpolatedVehicleThrottle;// Use an interpolated throttle for non tank vehicles. Will gradually increase the throttle while the forward/reverse buttons are pressed instead of the standard all or nothing throttle
var     config bool     bManualTankShellReloading;   // Turn on/off automatic tank shell reloading(when off, allows for selection of ammo before loading round)

// Music settings
var     config bool     bDisableMusicInGame;

// Jarring
var     float           JarrMoveMag;                 // Magnitude to move the player
var     float           JarrMoveRate;                // Rate at which the player oscillates
var     float           JarrMoveDuration;            // scalar duration of the movement
var     float           JarrRotateMag;               // Magnitude the player 'rolls'
var     float           JarrRotateRate;              // Rate at which the player oscillates/rolls around
var     float           JarrRotateDuration;          // scalar duration of the roll

// Kill Info
var     ROPlayerReplicationInfo     LastFFKiller;       // PRI of the last person who TKed you
var     float                       LastFFKillAmount;   // The amount that the last person that TKed you was penalized(used to reverse the penalty in the Forgive system)


//=============================================================================
// replication
//=============================================================================

replication
{
	reliable if (bNetOwner && Role == ROLE_Authority)
		AddHudDeathMessage;

	reliable if (bNetOwner && bNetDirty && Role == ROLE_Authority)
		bWeaponsSelected, DesiredRole, SpecMode, SavedArtilleryCoords;

	// client to server functions
	reliable if (Role < ROLE_Authority)
		ServerLeanRight, ServerLeanLeft,
		ChangeRole, ChangeWeapons, ServerThrowMGAmmo, ServerRemoveWeapon,
		GetNorthDirection, ServerSaveArtilleryPosition,
		ServerSaveRallyPoint, ServerSaveRallyPointFromHud, ServerRequestDeadSpectating,
        ServerChangePlayerInfo, xServerSpeech, ServerCancelBehindview, ServerVerifyTeamVOIP,
		ServerListPlayers, ServerInfoQuery, ServerSetManualTankShellReloading;

	// unreliable client to server functions
	unreliable if (Role < ROLE_Authority)
		ServerChangeSpecMode, ServerNextViewPoint, SendVehicleVoiceMessage,
		ServerVehicleSay, VehicleMessage, ServerRequestPOVChange,
        ServerAutoSelectAndChangeTeam;

    //server to client functions
    reliable if (Role == ROLE_Authority)
		ClientLocationalVoiceMessage, SendNorthDirection, NotifyOfMapInfoChange,
        ClientChangePlayerInfoResult, ClientForcedTeamChange, PlayerJarred;
}

//=============================================================================
// Functions
//=============================================================================

//-----------------------------------------------------------------------------
// Empty
//-----------------------------------------------------------------------------

exec function CycleLoadout() {}
exec function ChangeLoadout(string LoadoutName) {}
simulated function PrecacheAnnouncements() {}
exec function Taunt(name Sequence) {}
exec function RandomTaunt() {}
function ServerTaunt(name AnimName) {}
function ServerSetAutoTaunt(bool Value) {}
exec function SetAutoTaunt(bool Value) {}
exec function L33TPhrase(int phraseNum) {} // No l33t players, kthnx :)
function AwardAdrenaline(float amount) {}
function LogMultiKills(float Reward, bool bEnemyKill) {}
function bool AutoTaunt() { return false; }
function bool DontReuseTaunt(int T) { return true; }
exec function DropFlag() {}
function ServerDropFlag() {}
exec function SetVoice(coerce string S) {}
function ServerChangeLoadout(string LoadoutName) {}
function PlayStartupMessage(byte StartupStage) {}
simulated function ClientReceiveLoginMenu(string MenuClass, bool bForce) {}
exec function PlayVehicleHorn( int HornIndex ){}

exec function InfoQuery()
{
	if( !class'ROEngine.ROLevelInfo'.static.RODebugMode() )
		return;

	log("*********************Client***********************");
	ServerInfoQuery();
}

function ServerInfoQuery()
{
	if( !class'ROEngine.ROLevelInfo'.static.RODebugMode() )
		return;

	log("*********************Server***********************");
}

// Implemented in certain states to switch between first and third person spectating
function HandlePOVChange(){}
function ServerRequestPOVChange()
{
	HandlePOVChange();
}
// Implemented in the dead state to switch to dead spectating mode
function ServerRequestDeadSpectating(){}

// When the client has requested a switch to behindview right before they spawn, the server can
// get the call before they spawn, but the return call to the client to switch the view can
// arrive after they spawn. When this happens, this is called to reset the user to not be in
// behindview on the server
function ServerCancelBehindview()
{
	bBehindview=false;
}

simulated function NotifySpeakingInTeamChannel()
{
	local int idx;
	local VoiceChatRoom VCR;

	if (VoiceReplicationInfo == None || !VoiceReplicationInfo.bEnableVoiceChat )
		return;

	if (PlayerReplicationInfo != None && PlayerReplicationInfo.Team != None)
		idx = PlayerReplicationInfo.Team.TeamIndex;

	// Check that we are a member of this room
	VCR = VoiceReplicationInfo.GetChannel("Team", idx);
	if (VCR == None)
	{
		return;
	}

	if (VCR.ChannelIndex >= 0)
	{
		//log("Client calling ServerVerifyTeamVOIP");
		ServerVerifyTeamVOIP(VCR.ChannelIndex);
	}
}

function ServerVerifyTeamVOIP(int TeamChannel)
{
	local VoiceChatRoom VCR;
	local int Index;

	//log(PlayerReplicationinfo.PlayerName$" ServerVerifyTeamVOIP");

	if (VoiceReplicationInfo == None)
		return;

	VCR = VoiceReplicationInfo.GetChannelAt(TeamChannel);
	if ( VCR == None )
	{
		return;
	}

	if ( !VCR.IsMember(PlayerReplicationInfo) )
	{
		//log(PlayerReplicationinfo.PlayerName$" ServerVerifyTeamVOIP");

		if ( ServerJoinVoiceChannel(TeamChannel, "") != JCR_Success )
			return;

		//log(PlayerReplicationinfo.PlayerName$" ServerVerifyTeamVOIP Set the player to the right channel");
	}

    //log(PlayerReplicationinfo.PlayerName$" ServerVerifyTeamVOIP probably in the right channel");

	if (ActiveRoom != VCR)
	{
		ActiveRoom = VCR;
		ClientSetActiveRoom(VCR.ChannelIndex);
		Index = VCR.ChannelIndex;

		if ( PlayerReplicationInfo != None )
			PlayerReplicationinfo.ActiveChannel = VCR.ChannelIndex;
	}
}

// this is used to build a list of destroyable static meshes in the level.
// that list is used in ROHud to draw destroyed/destroyable targets on the map
simulated event PostBeginPlay()
{
    local RODestroyableStaticMeshBase D;

	// Avoid calling all that Announcer crap
    super(PlayerController).PostBeginPlay();

    // Build destroyable actors reference list
    foreach DynamicActors(class'RODestroyableStaticMeshBase', D)
        if (D.bShowOnSituationMap)
            Destroyables[Destroyables.Length] = D;

    // Spawn hint manager (if needed)
    UpdateHintManagement(bShowHints);
}

simulated event PostNetBeginPlay()
{
	super.PostNetBeginPlay();
	if ( Role < ROLE_Authority )
        ServerSetManualTankShellReloading(bManualTankShellReloading);
}

event ClientReset()
{
    local Actor A;

	// Reset client special timed sounds on the client
	foreach AllActors(class'Actor', A)
	{
		if( A.IsA('ClientSpecialTimedSound') )
            A.Reset();
        else if( A.IsA('KrivoiPlaneController') )
            A.Reset();
	}

    super.ClientReset();
}


//Overridden to allow a setting that doesn't play music in game
function ClientSetMusic(string NewSong, EMusicTransition NewTransition)
{
    if ( !bDisableMusicInGame || Level.ZoneTag == 'ROEntry' )
        super.ClientSetMusic(NewSong, NewTransition);
}

// Overriden to get rid of some terrible UT2k4 VOIP behavior
function ServerSpeak(int ChannelIndex, optional string ChannelPassword)
{
	local VoiceChatRoom VCR;
	local int Index;//, IndexTwo;

	if (VoiceReplicationInfo == None)
		return;

	VCR = VoiceReplicationInfo.GetChannelAt(ChannelIndex);
	if ( VCR == None )
	{
		if ( VoiceReplicationInfo.bEnableVoiceChat )
			ChatRoomMessage(0, ChannelIndex);

		else ChatRoomMessage(15, ChannelIndex);
		return;
	}

	if ( !VCR.IsMember(PlayerReplicationInfo) )
	{
		if ( ServerJoinVoiceChannel(ChannelIndex, ChannelPassword) != JCR_Success )
			return;
	}

	Index = -1;
	if (ActiveRoom == VCR)
	{
//      	if ( (VCR.GetTitle() ~= "Public") )
//      	{
//      		if (PlayerReplicationInfo != None && PlayerReplicationInfo.Team != None)
//				IndexTwo = PlayerReplicationInfo.Team.TeamIndex;
//
//			// Just put us back in the team channel if we leave public
//			VCR = VoiceReplicationInfo.GetChannel("Team", IndexTwo);
//
//			if( VCR != none )
//			{
//				ActiveRoom = VCR;
//				ClientSetActiveRoom(VCR.ChannelIndex);
//				Index = (VCR.ChannelIndex);
//				ClientMessage( ChatRoomMessageClass.static.AssembleMessage(9, VCR.GetTitle(), PlayerReplicationInfo) );
//			}
//			else
//			{
//				ChatRoomMessage(0, ChannelIndex);
//				Index = -1;
//				ActiveRoom = None;
//				ClientSetActiveRoom(-1);
//			}
//      	}
//      	else
//      	{

			// This is gay, don't leave the channel if we press that channels button again FFS
	//		ChatRoomMessage(10, ChannelIndex);
	//		log(PlayerReplicationInfo.PlayerName@"no longer speaking on "$VCR.GetTitle(),'VoiceChat');
	//		ActiveRoom = None;
	//		ClientSetActiveRoom(-1);
			if ( (VCR.GetTitle() ~= "Team") || (VCR.GetTitle() ~= "Public") || (VCR.GetTitle() ~= "Local") )
			{
				ClientMessage( ChatRoomMessageClass.static.AssembleMessage(1, VCR.GetTitle(), PlayerReplicationInfo) );
			}

			return;
//		}

	}
	else
	{
		ActiveRoom = VCR;
		log(PlayerReplicationInfo.PlayerName@"speaking on"@VCR.GetTitle(),'VoiceChat');
		ChatRoomMessage(9, ChannelIndex);
		ClientSetActiveRoom(VCR.ChannelIndex);
		Index = VCR.ChannelIndex;

		if ( (VCR.GetTitle() ~= "Team") || (VCR.GetTitle() ~= "Public") || (VCR.GetTitle() ~= "Local") )
		{
			ClientMessage( ChatRoomMessageClass.static.AssembleMessage(9, VCR.GetTitle(), PlayerReplicationInfo) );
		}
	}

	if ( PlayerReplicationInfo != None )
		PlayerReplicationinfo.ActiveChannel = Index;
}

exec function ListPlayers()
{
	if( Level.TimeSeconds - LastPlayerListTime > 1.0 )
	{
   	   	LastPlayerListTime = Level.TimeSeconds;
	   	ServerListPlayers();
   	}
}

function ServerListPlayers()
{
	local array<PlayerReplicationInfo> AllPRI;
	local int i;

    if( Level.TimeSeconds - LastPlayerListTime < 0.9 )
    {
    	return;
    }

    LastPlayerListTime = Level.TimeSeconds;

	// Get the list of players to kick by showing their PlayerID
	Level.Game.GameReplicationInfo.GetPRIArray(AllPRI);
	for (i = 0; i<AllPRI.Length; i++)
	{
		if( PlayerController(AllPRI[i].Owner) != none && AllPRI[i].PlayerName != "WebAdmin")
		{
			//log(Right("   "$AllPRI[i].PlayerID, 3)$")"@AllPRI[i].PlayerName@" "$PlayerController(AllPRI[i].Owner).GetPlayerIDHash());
			ClientMessage(Right("   "$AllPRI[i].PlayerID, 3)$")"@AllPRI[i].PlayerName@" "$PlayerController(AllPRI[i].Owner).GetPlayerIDHash());
		}
		else
		{
			//log(Right("   "$AllPRI[i].PlayerID, 3)$")"@AllPRI[i].PlayerName);
			ClientMessage(Right("   "$AllPRI[i].PlayerID, 3)$")"@AllPRI[i].PlayerName);
		}
	}
}

//TEMP START

// 0 = bloom
// 1 = blur
// 2 = b&w

// Toggle the bloom on and off as well as the ini setting for it
exec function Bloom()
{
	local bool bBloom;

	bBloom = bool(ConsoleCommand("get ini:Engine.Engine.ViewportManager Bloom"));

    if( bBloom )
    {
    	PostFX_SetActive(0, false);
    	ConsoleCommand("set ini:Engine.Engine.ViewportManager Bloom"@False);
    }
    else
    {
    	PostFX_SetActive(0, true);
    	ConsoleCommand("set ini:Engine.Engine.ViewportManager Bloom"@True);
    }
}

// Debug tool for the black and white effect
exec function BWEffect(float NewAmount)
{
	if( NewAmount > 0 )
	{
		postfxon(2);
		postfxbw(NewAmount);
	}
	else
	{
		postfxoff(2);
	}
}

/*
exec function TestWhiz(float duration, float intensity)
{
	AddBlur(duration, Intensity/2);
}*/

// Bloom functions

simulated function postfxon(int i)
{
   	if( PostFX_IsReady() )
		PostFX_SetActive(i, true);
}

simulated function postfxoff(int i)
{
	if( PostFX_IsReady() )
		PostFX_SetActive(i, false);
}

simulated function postfxblur(float f)//0... 1
{
   	if( PostFX_IsReady() )
		PostFX_SetParameter(1, 0, f);
}

simulated function postfxbw(float f, optional bool bDoNotTurnOffFadeFromBlackEffect)	//0... 1
{
	if( !PostFX_IsReady() )
		return;

    if (!bDoNotTurnOffFadeFromBlackEffect)
        bDoFadeFromBlackEffect = false;

	PostFX_SetParameter(2, 0, f);
}

/*exec function postfxbloom(float f)	//0... 1 (default 0.7f)
{
	if( Level.NetMode != NM_Standalone )
		return;

	PostFX_SetParameter(0, 0, f);
}*/ // I'm not needed no more!

exec function postfxbloom_bpcontrast(float f)	//0.0f ... 4.0f (default 3.0f)
{
	if( Level.NetMode != NM_Standalone )
		return;

	PostFX_SetParameter(0, 2, f);
}

exec function postfxbloom_blurmult(float f)	//1.0f ... 2.0f (Default 1.5f)
{
	if( Level.NetMode != NM_Standalone )
		return;

	PostFX_SetParameter(0, 3, f);
}

exec function postfxbloom_ratiomin(float f) // 0.0f-1.0f (Default 0.0f)
{
     if( Level.NetMode != NM_Standalone )
         return;

     PostFX_SetParameter(0,4, f);
}

exec function postfxbloom_ratiomax(float f) // 0.0-1.0f (Default 0.5f)
{
     if( Level.NetMode != NM_Standalone )
         return;

     PostFX_SetParameter(0,5, f);
}

exec function postfxbloom_ratio(float f) // 0.0-1.0f (Default 0.5f)
{
     if( Level.NetMode != NM_Standalone )
         return;

     PostFX_SetParameter(0,6, f);
}

exec function postfxbloom_togglegpu()
{
     if( Level.NetMode != NM_Standalone )
         return;

     PostFX_SetParameter(0,7, 0);
}

exec function postfxbloom_gpucalcs()
{
     // 2000 is a hacked in number, using to determine if avgbloom calcs are done on the GPU
     self.Player.Console.Message("Doing GPU Calcs: "$PostFX_IsActive(2000),0);
}

//TEMP END

// emh: remove 'exec' from this line
/*
exec function StartFadeFromBlackEffect()
{
    FadeFromBlackCurrentOpacity = 1.0;
    FadeFromBlackLastUpdateTime = Level.TimeSeconds;
    postfxon(2);
    postfxbw(FadeFromBlackCurrentOpacity, true);
    bDoFadeFromBlackEffect = true;
}*/

function NotifyTakeHit(pawn InstigatedBy, vector HitLocation, int Damage, class<DamageType> damageType, vector Momentum)
{
	local int iDam;
	local vector AttackLoc;

//	log("Notifytakehit is screwing us");
//	return;

	super(Controller).NotifyTakeHit(InstigatedBy,HitLocation,Damage,DamageType,Momentum);

	// Don't damageshake in vehicles till we figure out why it is messing our view up - Ramm
	if( Vehicle(Pawn) == none )
	{
		DamageShake(Damage);
	}

	iDam = Clamp(Damage,0,250);
	if ( InstigatedBy != None )
		AttackLoc = InstigatedBy.Location;

	NewClientPlayTakeHit(AttackLoc, hitLocation - Pawn.Location, iDam, damageType);
}

simulated event RenderOverlays( Canvas Canvas )
{
	if((!bUseBlurEffect || !PostFX_IsReady()) && BlurTime > 0)
 	{
		Canvas.DrawColor.A = Min(MaxAltBlurLevel,AltBlurLevel) * (BlurTime/InitialBlurTime);
    	Canvas.Style = ERenderStyle.STY_Alpha;

    	Canvas.SetPos(0,0);
    	//Canvas.DrawTile( texture'Engine.BlackTexture', Canvas.SizeX, Canvas.SizeY, 0.0, 0.0, texture'Weapons1st_tex.zoomblur10'.USize, texture'Weapons1st_tex.zoomblur10'.VSize );
 	}

    if (bDoFadeFromBlackEffect)
    {
        FadeFromBlackCurrentOpacity -= (Level.TimeSeconds - FadeFromBlackLastUpdateTime) * FadeFromBlackFadeSpeed;
        FadeFromBlackLastUpdateTime = Level.TimeSeconds;
        if (FadeFromBlackCurrentOpacity < 0)
            postfxoff(2);
        else
            postfxbw(FadeFromBlackCurrentOpacity, true);
    }
}

// Overridden to support our autotrace select/use system
function ServerUse()
{
    local Actor A;
	local Vehicle DrivenVehicle, EntryVehicle;

	if ( Role < ROLE_Authority )
		return;

    if ( Level.Pauser == PlayerReplicationInfo )
    {
        SetPause(false);
        return;
    }

    if (Pawn == None || !Pawn.bCanUse)
        return;

	DrivenVehicle = Vehicle(Pawn);
	if( DrivenVehicle != None )
	{
		DrivenVehicle.KDriverLeave(false);
		return;
	}

    if( ROPawn(Pawn).AutoTraceActor != none )
    {
    	if( ROVehicle(ROPawn(Pawn).AutoTraceActor) != none )
    	{
			EntryVehicle = ROVehicle(ROPawn(Pawn).AutoTraceActor).FindEntryVehicle(Pawn);
        	if (EntryVehicle != None && EntryVehicle.TryToDrive(Pawn))
            	return;
    	}
    	else
    	{
			ROPawn(Pawn).AutoTraceActor.UsedBy( Pawn );
			return;
		}
    }

    // Send the 'DoUse' event to each actor player is touching.
    foreach Pawn.TouchingActors(class'Actor', A)
    {
        if( !A.bCanAutoTraceSelect )
			A.UsedBy(Pawn);
    }

	if ( Pawn.Base != None )
		Pawn.Base.UsedBy( Pawn );
}
//-----------------------------------------------------------------------------
// Crappy test execs - Remove later - Ramm
//-----------------------------------------------------------------------------
/*
exec function HitBone()
{
	local name HitBone;     	//the bone that was hit
	local float HitBoneDist;    //the dist to bone that was hit
	local vector X,Y,Z;

	local Vector End, HitLocation, HitNormal, Start ;
	local Actor Other;
	local vector LocDir, HitDir;
	local float HitAngle,Side;

	Start = Pawn.Location + Pawn.EyePosition();
	End = Start + 500 * vector(Pawn.Rotation);


	Other = Trace(HitLocation, HitNormal, End, Start, true);

    //log("Location = "$Location);
    //log("Vector(Rotation) = "$Vector(Rotation));
    LocDir = vector(Other.Rotation);
    Spawn(class 'RODebugTracer',self,,Other.Location,Rotator(LocDir));
    LocDir.Z = 0;
    HitDir =  Hitlocation - Other.Location;
    HitDir.Z = 0;
    HitAngle = Acos( Normal(LocDir) dot Normal(HitDir));


    HitAngle*=50;

    GetAxes(Other.Rotation,X,Y,Z);
    Side = Y dot HitDir;
    log("Side = "$Side);

    if( side >= 0)
    {
       HitAngle = 360 + (HitAngle* -1);//+= 180;
    }

    log("HitAngle = "$HitAngle);

     //Spawn(class 'RODebugTracer',self,,Hitlocation,Rotator(HitDir));
    Spawn(class 'RODebugTracerGreen',self,,Hitlocation,Rotator(HitDir));


    //log("Momentum = "$Momentum);
    log("Other = "$Other);

	HitBone = Other.GetClosestBone(HitLocation, vector(Pawn.Rotation), HitBoneDist); //, 'spine', 0.1);

	log("Hitbone = "$Hitbone);
}

exec function TestAngle()
{
    	local vector X,Y,Z;
	local Vector End, HitLocation, HitNormal, Start ;
    	local Actor Other;
 	local vector LocDir, HitDir;
	local float HitAngle, Inangle;

    	Start = Pawn.Location + Pawn.EyePosition();
    	End = Start + 500 * vector(Rotation);

        Other = Trace(HitLocation, HitNormal, End, Start, true);

    LocDir = vector(Other.Rotation);
    Spawn(class 'RODebugTracer',self,,Other.Location,Rotator(LocDir));
    LocDir.Z = 0;
    HitDir =  Hitlocation - Other.Location;
    HitDir.Z = 0;
    HitAngle = Acos( Normal(LocDir) dot Normal(HitDir));

    //Spawn(class 'RODebugTracerGreen',self,,Hitlocation,Rotator(-HitNormal));

    GetAxes(Other.Rotation,X,Y,Z);

    //Y.X = 0.0;
    HitDir = Hitlocation - Other.Location;
    //HitDir.X=0.0;

    InAngle= Acos(Normal(HitDir) dot Normal(Z));

    log("InAngle = "$InAngle);

    //log("PN= "$(12-((Fmin(InAngle,1.5)/1.5)*12)));


     //Spawn(class 'RODebugTracer',self,,Hitlocation,Rotator(HitDir));
    Spawn(class 'RODebugTracerGreen',self,,Hitlocation,Rotator(-HitDir));


    //log("Momentum = "$Momentum);
    log("Other = "$Other);
}
 */

 /*
exec function SpawnPronePawn()
{
	local ROPawn p;

	if( !class'ROEngine.ROLevelInfo'.static.RODebugMode() )
		return;

	p = Spawn( class 'ROPawn',,,Pawn.Location + 72 * Vector(Rotation) + vect(0,0,1) * 15 );
 	p.setphysics(PHYS_Falling);
    p.bWantsToProne = true;
}

exec function SpawnPawn()
{
	local ROPawn p;

	if( !class'ROEngine.ROLevelInfo'.static.RODebugMode() )
		return;

	p = Spawn( class 'ROPawn',,,Pawn.Location + 72 * Vector(Rotation) + vect(0,0,1) * 15 );

	p.LoopAnim('stand_idlehip_kar');

	p.setphysics(PHYS_Falling);
}

exec function SpawnRunningPawn()
{
	local ROPawn p;

	if( !class'ROEngine.ROLevelInfo'.static.RODebugMode() )
		return;

	p = Spawn( class 'ROPawn',,,Pawn.Location + 72 * Vector(Rotation) + vect(0,0,1) * 15 );

	p.LoopAnim('stand_sprintF_kar');
}

exec function ToggleXHair()
{
	if( !class'ROEngine.ROLevelInfo'.static.RODebugMode() )
		return;

	if ( myHUD.bCrosshairShow )
	{
		myHUD.bCrosshairShow = false;
	}
	else
	{
		// return to normal
		myHUD.bCrosshairShow = true;
	}
}   */

exec function Fade(float time)
{
	ROHud(MyHud).FadeToBlack(time, false);
}

exec function ShowDebugMap()
{
    ROHud(myHUD).bShowDebugInfoOnMap = !ROHud(myHUD).bShowDebugInfoOnMap;
}

exec function ShowNetDebugMap(optional int DebugMode)
{
    ROHud(myHUD).bShowRelevancyDebugOnMap = !ROHud(myHUD).bShowRelevancyDebugOnMap;

    if( ROHud(myHUD).bShowRelevancyDebugOnMap )
        ROHud(myHUD).SetNetDebugMode(DebugMode);
}

exec function ShowNetDebugOverlay(optional int DebugMode)
{
    ROHud(myHUD).bShowRelevancyDebugOverlay = !ROHud(myHUD).bShowRelevancyDebugOverlay;

    if( ROHud(myHUD).bShowRelevancyDebugOverlay )
        ROHud(myHUD).SetNetDebugMode(DebugMode);
}

/*
simulated exec function HitPoint()
{
   HitPointCheck();
}

function HitPointCheck()
{
 	local actor HitActor;
	local vector HitLocation, HitNormal, StartTrace;
	local int TraceDist;
	local rotator AimRot;
	local array<int> HitPoints;
	local rotator myrot;
	local ROPawn ROP;

	if( !class'ROEngine.ROLevelInfo'.static.RODebugMode() )
		return;

	myrot = rotation;

	MyRot.Roll += 16384;

  	TraceDist = GetMaxViewDistance();
  	StartTrace = Pawn.Location + Pawn.EyePosition();
  	AimRot = Rotation;

	ClearStayingDebugLines();
//	DrawStayingDebugLine( StartTrace, StartTrace + TraceDist*vector(AimRot),0, 255, 0);


	HitActor = HitPointTrace(HitLocation,HitNormal,StartTrace + TraceDist*vector(AimRot),HitPoints,StartTrace);

     ROP = ROPawn(HitActor);

    if( ROP != none )
    	ROP.ProcessLocationalDamage(0, Pawn, HitLocation, StartTrace + TraceDist*vector(AimRot), class'DamageType',HitPoints);
	//Spawn(class 'ROEngine.RODebugTracer',self,,HitLocation,AimRot);

	log("HitPoints.Length = "$HitPoints.Length);

}

exec function ClearLines()
{
	if( !class'ROEngine.ROLevelInfo'.static.RODebugMode() )
		return;

	ClearStayingDebugLines();
} */

/*
exec function RegularTrace()
{
 	local actor HitActor;
	local vector HitLocation, HitNormal, StartTrace;
	local int TraceDist;
	local ROGameReplicationInfo GRI;
	local rotator AimRot;
	local array<int> HitPoints;
	local rotator myrot;

	if( !class'ROEngine.ROLevelInfo'.static.RODebugMode() )
		return;


	myrot = rotation;

	MyRot.Roll += 16384;

  	TraceDist = GetMaxViewDistance();
  	StartTrace = Pawn.Location + Pawn.EyePosition();
  	AimRot = Rotation;

	ClearStayingDebugLines();
	DrawStayingDebugLine( StartTrace, StartTrace + TraceDist*vector(AimRot),0, 255, 0);


	HitActor = Trace(HitLocation,HitNormal,StartTrace + TraceDist*vector(AimRot),StartTrace,true);

	Spawn(class 'ROEngine.RODebugTracer',self,,HitLocation,AimRot);
}*/

/*
exec function DotTest()
{
	local pawn Victims;
	local vector dir, lookdir, RadiusHitLocation;

	if( !class'ROEngine.ROLevelInfo'.static.RODebugMode() )
		return;

	foreach VisibleCollidingActors( class 'Pawn', Victims, 50000 ) //, RadiusHitLocation
	{
		// don't let blast damage affect fluid - VisibleCollisingActors doesn't really work for them - jag
		if( Victims != Pawn)
		{
			lookdir = Normal(Vector(Rotation));
			DrawStayingDebugLine(Pawn.Location, Pawn.Location + lookdir * 100, 0,255,0);
			dir = Normal(Victims.Location - Pawn.Location);
			DrawStayingDebugLine(Pawn.Location, Pawn.Location + dir * 100, 0,0,255);

			log("We are "$(Vsize(Victims.Location - Pawn.Location)/60)$" Meters apart");

           	log(Instigator$" dot "$Victims$" = "$lookdir dot dir);
		}
	}
}*/

//-----------------------------------------------------------------------------
// End Crappy test execs
//-----------------------------------------------------------------------------

simulated exec function DriverCollisionDebug()
{
	if( !class'ROEngine.ROLevelInfo'.static.RODebugMode() )
		return;

	if( ROHud(myHUD).bDebugDriverCollision )
	{
		ROHud(myHUD).bDebugDriverCollision = false;
	}
	else
	{
		ROHud(myHUD).bDebugDriverCollision = true;
	}
}

simulated exec function PlayerCollisionDebug()
{
	if( !class'ROEngine.ROLevelInfo'.static.RODebugMode() )
		return;

	if( ROHud(myHUD).bDebugPlayerCollision )
	{
		ROHud(myHUD).bDebugPlayerCollision = false;
	}
	else
	{
		ROHud(myHUD).bDebugPlayerCollision = true;
	}
}

simulated exec function ROIronSights()
{
	if( Pawn != none && Pawn.Weapon != none)
	{
		Pawn.Weapon.ROIronSights();
	}
}

// Save the rally point vector
simulated function SaveRallyPoint()
{
	ServerSaveRallyPoint();
}

/* =================================================================================== *
* ServerSaveArtilleryPosition()
* 	Sends out a trace to find the saved artillery coordinates, then verifies that
* 	the coordinates are in a valid location. Sends a confirmation or denial
*	message to the player. Client calls this function on the server.
*
* modified by: Ramm 10/21/04
* =================================================================================== */
function ServerSaveRallyPoint()
{
	local actor HitActor;
	local vector HitLocation, HitNormal, StartTrace;
	local int TraceDist;
	local rotator AimRot;
    local ROPlayerReplicationInfo PRI;

	if( (Level.TimeSeconds - LastRallyTime) < ROTeamGame(Level.Game).LevelInfo.RallyPointInterval )
	{
		// Dont spam rally point messages
		ReceiveLocalizedMessage(class'RORallyMsg', 2, PlayerReplicationInfo);
		return;
	}

    // Only leaders can set rally points!
    PRI = ROPlayerReplicationInfo(PlayerReplicationInfo);
    if (PRI == none || PRI.RoleInfo == none || !PRI.RoleInfo.bIsLeader)
        return;

	// if you don't have binocs can't save rally points
	if ( Pawn.Weapon != none && Pawn.Weapon.IsA('BinocularsItem' ))
	{
	  	TraceDist = GetMaxViewDistance();
	  	StartTrace = Pawn.Location + Pawn.EyePosition();
	  	AimRot = Rotation;
	}
 	else if( Pawn.IsA('ROVehicleWeaponPawn') )
	{
		TraceDist = GetMaxViewDistance();
		AimRot = ROVehicleWeaponPawn(Pawn).CustomAim;
		StartTrace = ROVehicleWeaponPawn(Pawn).GetViewLocation() + 500 * vector(AimRot);
	}
	else
	{
	   return;
	}

	//StartTrace = Pawn.Location + Pawn.EyePosition();
	HitActor = trace(HitLocation,HitNormal,StartTrace + TraceDist*vector(AimRot),StartTrace,true);

    ServerSaveRallyPointNoTrace(HitLocation);
}

// Get the maximum possible view distance for this level
simulated function float GetMaxViewDistance()
{
	switch (Level.ViewDistanceLevel)
	{
    	case VDL_Default_1000m:
            return 65536;
    		break;

    	case VDL_Medium_2000m:
            return 131072;
    		break;

    	case VDL_High_3000m:
            return 196608;
    		break;

    	case VDL_Extreme_4000m:
            return 262144;
    		break;

    	default:
            return 65536;
	}
}

function ServerSaveRallyPointFromHud(vector RallyLocation)
{
    local ROPlayerReplicationInfo PRI;

    // Only leaders can set rally points!
    PRI = ROPlayerReplicationInfo(PlayerReplicationInfo);
    if (PRI == none || PRI.RoleInfo == none || !PRI.RoleInfo.bIsLeader)
        return;

    if( (Level.TimeSeconds - LastRallyTime) < ROTeamGame(Level.Game).LevelInfo.RallyPointInterval )
	{
		// Dont spam rally point messages
		ReceiveLocalizedMessage(class'RORallyMsg', 2, PlayerReplicationInfo);
		return;
	}

	ServerSaveRallyPointNoTrace(RallyLocation);
}

function ServerSaveRallyPointNoTrace(vector RallyLocation)
{
    local ROGameReplicationInfo GRI;

	GRI = ROGameReplicationInfo(GameReplicationInfo);

	// Rally point saved for yourself
    ReceiveLocalizedMessage(class'RORallyMsg', 0, PlayerReplicationInfo);

	// Tell the rest of the team the rally point is saved.
	BroadcastLocalizedMessage(class'RORallyMsg', 1, PlayerReplicationInfo);

	// Set this as the last rally point time
	LastRallyTime = Level.TimeSeconds;

 	GRI.AddRallyPoint(PlayerReplicationInfo, RallyLocation);

 	// Notify teammates that map has been updated
 	if (PlayerReplicationInfo.Team != none)
 	    ROTeamGame(Level.Game).NotifyPlayersOfMapInfoChange(PlayerReplicationInfo.Team.TeamIndex, self);
}

/* =================================================================================== *
* ServerSaveArtilleryPosition()
* 	Sends out a trace to find the saved artillery coordinates, then verifies that
* 	the coordinates are in a valid location. Sends a confirmation or denial
*	message to the player. Client calls this function on the server.
*
* modified by: Ramm 10/21/04
* =================================================================================== */
function ServerSaveArtilleryPosition()
{
	local actor HitActor;
	local vector HitLocation, HitNormal, StartTrace;
	local ROGameReplicationInfo GRI;
	local int TraceDist;
	local ROVolumeTest RVT;
	local rotator AimRot;
	local ROPlayerReplicationInfo PRI;
	local bool bFoundARadio;
	local int i;

    GRI = ROGameReplicationInfo(GameReplicationInfo);

    // Only leaders can set rally points!
    PRI = ROPlayerReplicationInfo(PlayerReplicationInfo);
    if (PRI == none || PRI.RoleInfo == none || !PRI.RoleInfo.bIsLeader)
        return;

	// If a player tries to mark artillery on a level with no arty for their team, give them a message
	if ( PlayerReplicationInfo.Team.TeamIndex == ALLIES_TEAM_INDEX )
	{
	    for ( i = 0; i < ArrayCount(GRI.AlliedRadios); i++)
		{
			if(GRI.AlliedRadios[i] != none)
			{
				bFoundARadio = true;
				break;
			}
		}
	}
	else if ( PlayerReplicationInfo.Team.TeamIndex == AXIS_TEAM_INDEX )
	{
	    for ( i = 0; i < ArrayCount(GRI.AxisRadios); i++)
		{
			if(GRI.AxisRadios[i] != none)
			{
				bFoundARadio = true;
				break;
			}
		}
	}

	if (!bFoundARadio)
	{
		ReceiveLocalizedMessage(class'ROArtilleryMsg', 9);
		return;
	}

	// if you don't have binocs can't call arty strike
	if ( Pawn.Weapon != none && Pawn.Weapon.IsA('BinocularsItem' ))
	{
	  	TraceDist = GetMaxViewDistance();
	  	StartTrace = Pawn.Location + Pawn.EyePosition();
	  	AimRot = Rotation;
	}
	else if( Pawn.IsA('ROVehicleWeaponPawn') )
	{
		TraceDist = GetMaxViewDistance();
		AimRot = ROVehicleWeaponPawn(Pawn).CustomAim;
		StartTrace = ROVehicleWeaponPawn(Pawn).GetViewLocation() + 500 * vector(AimRot);
	}
	else
	{
	   return;
	}

	//StartTrace = Pawn.Location + Pawn.EyePosition();
	HitActor = trace(HitLocation,HitNormal,StartTrace + TraceDist*vector(AimRot),StartTrace,true);

     RVT = Spawn(class'ROVolumeTest',self,,HitLocation);

     if ((RVT != none && RVT.IsInNoArtyVolume()) || HitActor == none)
     {
     	ReceiveLocalizedMessage(class'ROArtilleryMsg', 5);
		RVT.Destroy();
		return;
     }

     RVT.Destroy();

     ReceiveLocalizedMessage(class'ROArtilleryMsg', 0);

	SavedArtilleryCoords = HitLocation;

/*   if ( Pawn.GetTeamNum() == 0 )
     {
         ROGameReplicationInfo(GameReplicationInfo).AxisArtilleryCoords = HitLocation;
     }
     else
     {
         ROGameReplicationInfo(GameReplicationInfo).AlliedArtilleryCoords = HitLocation;
     }*/
}

/* =================================================================================== *
* ServerArtyStrike()
* 	Spawn the artillery strike at the appropriate position.
*
* modified by: Ramm 10/21/04
* =================================================================================== */
function ServerArtyStrike()
{
     local vector SpawnLocation;
     local ROGameReplicationInfo GRI;
     local ROArtillerySpawner Spawner;

     GRI = ROGameReplicationInfo(GameReplicationInfo);

/*     if ( Pawn.GetTeamNum() == 0 )
     {
         SpawnLocation = GRI.AxisArtilleryCoords;
     }
     else
     {
         SpawnLocation = GRI.AlliedArtilleryCoords;
     }*/


     SpawnLocation = SavedArtilleryCoords;

     SpawnLocation.Z = GRI.NorthEastBounds.Z;

     Spawner =  Spawn(class 'ROArtillerySpawner',self,, SpawnLocation, rotator(PhysicsVolume.Gravity));

     if (Spawner == none)
     {
         log("Error Spawning Artillery Shell Spawnner ");
     }
     else
     {
        Spawner.OriginalArtyLocation = SavedArtilleryCoords;
     }
}

/* For Debugging only
exec function HitIt()
{
     ServerArtyStrike();
}*/

/* =================================================================================== *
* ServerArtyStrike()
* 	Attempt to call in an artillery strike, and give approval/denial text and
*	voice messages to the player based on that.
*
* modified by: Ramm 10/21/04
* =================================================================================== */
function HitThis(ROArtilleryTrigger RAT)
{
    local ROGameReplicationInfo GRI;
    local int TimeTilNextStrike;
    local int PawnTeam;

    GRI = ROGameReplicationInfo(GameReplicationInfo);
    PawnTeam = Pawn.GetTeamNum();

    if (GRI.bArtilleryAvailable[Pawn.GetTeamNum()] == 1)
    {
	  ReceiveLocalizedMessage(class'ROArtilleryMsg', 3,,,self);

       if ( PawnTeam ==  0 )
       {
           RAT.PlaySound( RAT.GermanConfirmSound, Slot_None, 3.0, false, 100,1.0,true );
       }
       else
       {
           RAT.PlaySound( RAT.RussianConfirmSound, Slot_None, 3.0, false, 100,1.0,true );
       }

       GRI.LastArtyStrikeTime[PawnTeam] = GRI.ElapsedTime;
	  GRI.TotalStrikes[PawnTeam]++;
       ServerArtyStrike();
        ROTeamGame(Level.Game).NotifyPlayersOfMapInfoChange(PawnTeam, self);
    }
    else
    {
       if ( PawnTeam ==  0 )
       {
           RAT.PlaySound( RAT.GermanDenySound, Slot_None, 3.0, false, 100,1.0,true );
           //RAT.SetTimer(GetSoundDuration(RAT.GermanDenySound), false);
       }
       else
       {
           RAT.PlaySound( RAT.RussianDenySound, Slot_None, 3.0, false, 100,1.0,true );
       }


	  TimeTilNextStrike = (GRI.LastArtyStrikeTime[PawnTeam] + ROTeamGame(Level.Game).LevelInfo.GetStrikeInterval(PawnTeam)) - GRI.ElapsedTime;

 	  if (GRI.TotalStrikes[PawnTeam] >= GRI.ArtilleryStrikeLimit[PawnTeam])
 	  {
 	  	 ReceiveLocalizedMessage(class'ROArtilleryMsg', 6);
 	  }
 	  else if ( TimeTilNextStrike >= 20 )
 	  {
 	  	   ReceiveLocalizedMessage(class'ROArtilleryMsg', 7);
 	  }
 	  else if ( TimeTilNextStrike >= 0 )
 	  {
 	  	   ReceiveLocalizedMessage(class'ROArtilleryMsg', 8);
 	  }
 	  else
 	  {
 	  	   ReceiveLocalizedMessage(class'ROArtilleryMsg', 2);
 	  }
    }
}

/*
exec function PokeIt()
{
	local actor HitActor;
	local vector HitLocation, HitNormal;


	local vector StartTrace;

	local int TraceDist;

	local rotator AimRot;




	  	TraceDist = GetMaxViewDistance();
	  	StartTrace = Pawn.Location + Pawn.EyePosition();
	  	AimRot = Rotation;


	//StartTrace = Pawn.Location + Pawn.EyePosition();
	HitActor = trace(HitLocation,HitNormal,StartTrace + TraceDist*vector(AimRot),StartTrace,true);

//DistanceToTarget = VSize(Location - HitLocation);

//    log("HitActor = "$HitActor);

		if (  HitActor.IsA('TerrainInfo') )
		{

		   TerrainInfo(HitActor).PokeTerrain((HitLocation + 16 * HitNormal) , 25, 25);
		}


}


exec function UnPoke()
{
     local int i;
     local ROGameReplicationInfo GRI;

     GRI = ROGameReplicationInfo(GameReplicationInfo);

     for ( i=0; i<ArrayCount(GRI.SavedPoke); i++ )
     {
           if ( GRI.SavedPoke[i].PokeLocation != vect(0,0,0))
              GRI.SavedPoke[i].PokedTerrain.PokeTerrain(GRI.SavedPoke[i].PokeLocation , GRI.SavedPoke[i].PokeRadius, (GRI.SavedPoke[i].PokeDepth * -1));
		   //TerrainInfo(Wall).PokeTerrain((Location + 16 * HitNormal) , 100, 50);
     }
}  */

//-----------------------------------------------------------------------------
// Set the NorthEast map bound to the player's current location
//-----------------------------------------------------------------------------
exec function SetNE()
{
	if ( Level.NetMode != NM_Standalone )
		return;

    ROTeamGame(Level.Game).SetNEBound(Pawn.Location);

    if( class'ROEngine.ROLevelInfo'.static.RODebugMode() )
    {
    	log("Setting NE Corner Location to: "$Pawn.Location);
	}
}

//-----------------------------------------------------------------------------
// Set the SouthWest map bound to the player's current location
//-----------------------------------------------------------------------------
exec function SetSW()
{
	if ( Level.NetMode != NM_Standalone )
		return;

	ROTeamGame(Level.Game).SetSWBound(Pawn.Location);

    if( class'ROEngine.ROLevelInfo'.static.RODebugMode() )
    {
		log("Setting SW Corner Location to: "$Pawn.Location);
	}
}

//-----------------------------------------------------------------------------
// Turn sway on and off -- for debug use only
//-----------------------------------------------------------------------------
exec function Sway( bool B )
{
	if( class'ROEngine.ROLevelInfo'.static.RODebugMode() )
	{
		bSway = B;
	}
}

function GetNorthDirection()
{
	if( ROTeamGame(Level.Game).LevelInfo != none )
	{
		//log("at SendNorthDirection, north is "$ROTeamGame(Level.Game).LevelInfo.Rotation);
    	SendNorthDirection(ROTeamGame(Level.Game).LevelInfo.Rotation.Yaw);
	}
}

simulated function SendNorthDirection(int North)
{
	if( ROHud(myHud) != none )
		ROHud(myHud).NorthDirection.Yaw = North;
}

simulated function ResetFreeAimValues()
{
   WeaponBufferRotation = rot(0,0,0);
}

//-----------------------------------------------------------------------------
// AddHudDeathMessage - Replicated function that adds a death message to the HUD
//-----------------------------------------------------------------------------

function AddHudDeathMessage(PlayerReplicationInfo Killer, PlayerReplicationInfo Victim, class<DamageType> DamageType)
{
	if (ROHud(myHud) == None)
		return;

	ROHud(myHud).AddDeathMessage(Killer, Victim, DamageType);

	if (!class'RODeathMessage'.default.bNoConsoleDeathMessages && (Player != None) && (Player.Console != None))
		Player.Console.Message(class'RODeathMessage'.Static.GetString(0, Killer, Victim, DamageType),0 );
}


/* InitInputSystem()
Spawn the appropriate class of PlayerInput
Only called for playercontrollers that belong to local players
Modified to use our PlayerInput class - Ramm 10/26/03
*/
event InitInputSystem()
{
	InputClass = class'ROEngine.ROPlayerInput';
	//SaveConfig();  UT2k4Merge - Ramm

	Super.InitInputSystem();
}

// These is an accessor for the ROPlayerInput class. It looks here to see what to set the mouse sensitivy to.
// Used primarily for lowering the mouse sensitivity while sniping. Returning -1 will do no modification at all.
// Ramm - 10/27/03
function float GetMouseModifier()
{
	local ROWeapon weap;

	if (Pawn == none || Pawn.Weapon == none)
		return -1.0;

	weap = ROWeapon(Pawn.Weapon);

	if (weap== none )
		return -1.0;


	if(weap.ScopeDetail == RO_ModelScope && weap.ShouldDrawPortal())
	{
		return 24;
	}
	else if(weap.ScopeDetail == RO_ModelScopeHigh && weap.ShouldDrawPortal())
	{
		return 24;
	}
	else
	{
		return -1.0;
	}

}

// Update the blur amount for this player
simulated function UpdateBlurEffect(float DeltaTime)
{
	if( BlurTime > 0 )
	{
		 BlurTime -= DeltaTime;

		 if( bUseBlurEffect )
		 {
			 if( InitialBlurTime > 0 )
			 {
			 	//ShellShockBlur.BlurAlpha = 255 - ((BlurTime/InitialBlurTime) * 255);
			 	CurrentBlurAmount = BlurTime/InitialBlurTime;
			 }
			 else
			 {
			 	//ShellShockBlur.BlurAlpha = 255;
			 	CurrentBlurAmount = 0;
			 }
			postfxblur(CurrentBlurAmount);
		 }
	}

	if( ColorFadeTime > 0 )
	{
		 ColorFadeTime -= DeltaTime * 2;

		 if( bUseBlurEffect )
		 {
			 if( InitialBlurTime > 0 )
			 {
			 	CurrentFadeAmount = ColorFadeTime/InitialBlurTime;
			 }
			 else
			 {
			 	CurrentFadeAmount = 0;
			 }

			postfxbw(CurrentFadeAmount);
		 }
	}

	if( ColorFadeTime <= 0 )
	{
        CurrentFadeAmount = 0;
		postfxbw(CurrentFadeAmount);

		postfxoff(2);
	}

	if( BlurTime <= 0 )
	{
		BlurTime=0;
		AltBlurLevel = 0;

        CurrentBlurAmount = 0;
        //CurrentFadeAmount = 0;
 		postfxblur(CurrentBlurAmount);
		//postfxbw(CurrentFadeAmount);

		postfxoff(1);
		//postfxoff(2);
	}
}

// Cause the player's view to be blurred for a specified time
simulated function AddBlur(float NewBlurTime, float NewBlurScale)
{
	if( bUseBlurEffect )
	{
		if( CurrentBlurAmount < NewBlurScale)
		{
			CurrentBlurAmount = NewBlurScale;
			CurrentFadeAmount = NewBlurScale/2;
		}

		postfxblur(CurrentBlurAmount);
		postfxon(1);

		// Don't do the black and white effect if the detail settings are low
		if ( !Level.bDropDetail && (Level.DetailMode != DM_Low) )
		{
			postfxbw(CurrentFadeAmount);
			postfxon(2);
		}


//		if (ShellShockBlur == None)
//		{
//			ShellShockBlur = new(None) class'MotionBlur';
//		}
//		if( ShellShockBlur.BlurAlpha > (255 - (255 * NewBlurScale)))
//			ShellShockBlur.BlurAlpha = 255 - (255 * NewBlurScale);//0;
//
//		AddCameraEffect(ShellShockBlur, true);
	}

	if( (MaxAltBlurLevel * NewBlurScale) > AltBlurLevel )
    	AltBlurLevel = MaxAltBlurLevel * NewBlurScale;

    if( NewBlurTime > BlurTime )
    {
	    BlurTime = NewBlurTime;
	    ColorFadeTime = NewBlurTime/2;
	    InitialBlurTime = NewBlurTime;
    }
}

// reset the motion blur vars
simulated function ResetBlur()
{
	BlurTime = 0.0;
	ColorFadeTime = 0.0;

    CurrentFadeAmount = 0;
	AltBlurLevel = 0;
    CurrentBlurAmount = 0;

	if( PostFX_IsReady() )
	{
		postfxbw(CurrentFadeAmount);
		postfxoff(2);
		postfxblur(CurrentBlurAmount);
		postfxoff(1);
	}
}

// Overriden to support resetting motion blur before switching maps and cleaning
// up weapons that aren't properly garbage collected under normal circumstances
event PreClientTravel()
{
	super.PreClientTravel();

	if( Level.NetMode != NM_DedicatedServer )
	{
		ResetBlur();

		if( Pawn != none)
		{
			if( Vehicle(Pawn) != none && Vehicle(Pawn).Driver != none && ROPawn(Vehicle(Pawn).Driver) != none )
			{
				ROPawn(Vehicle(Pawn).Driver).PreTravelCleanUp();
			}
			else if ( ROPawn(Pawn) != none )
			{
				ROPawn(Pawn).PreTravelCleanUp();
			}
		}
	}
}

// Give the player a quick blur effect
simulated function PlayerWhizzed(float DistSquared)
{
	local float Intensity;

    //log("DistSquared of whiz is "$DistSquared);

	Intensity = 1.0 - ((FMin(DistSquared,22500))/22500);  // 22500 = (150*150) = Radius of bullet whiz cylinder squared

	//log("Intensity of whiz is "$Intensity);

	AddBlur(0.15, Intensity/2);
}

// Jarr the player's vision as if they were bumped by something
// such as the butt of a gun. The HitDirection must be
// passed in screen-space rotation.
simulated function PlayerJarred(vector HitDirection, float JarrScale)
{
    local vector localShakeMoveMag;
    local vector localShakeMoveRate;
    local vector localShakeRotateMag;
    local vector localShakeRotateRate;

    // Shake Moving
    //
    localShakeMoveMag = HitDirection * JarrMoveMag;
    //
    localShakeMoveRate.X = JarrMoveRate;
    localShakeMoveRate.Y = JarrMoveRate;
    localShakeMoveRate.Z = JarrMoveRate;
    //
    // Unfortunately, the HitDirection
    // only transfers maximum offsets to
    // the shake offset max. I have to
    // check it's sign and move that into
    // the rate so it moves the right direction.
    if ( HitDirection.X < 0 )
        localShakeMoveRate.X *= -1;
    if ( HitDirection.Y < 0 )
        localShakeMoveRate.Y *= -1;
    if ( HitDirection.Z < 0 )
        localShakeMoveRate.Z *= -1;

    // Shake Rotation
    //
    localShakeRotateMag.X = JarrRotateMag*-HitDirection.X;
    localShakeRotateMag.Z = JarrRotateMag*HitDirection.Y;
    //
    localShakeRotateRate.X = JarrRotateRate*-HitDirection.X;
    localShakeRotateRate.Z = JarrRotateRate*HitDirection.Y;

    ShakeView(localShakeRotateMag*JarrScale,
              localShakeRotateRate*(2.0f-JarrScale),
              JarrRotateDuration,
              localShakeMoveMag*JarrScale,
              localShakeMoveRate*(2.0f-JarrScale),
              JarrMoveDuration);
    AddBlur(0.5f+JarrScale,1.0f);
}

function UpdateRotation(float DeltaTime, float maxPitch)
{
    local rotator newRotation, ViewRotation;
    local ROVehicle ROVeh;
    local ROPawn ROPwn;
    local ROWeapon ROWeap;

	// Lets avoid casting 20 times every tick - Ramm
    ROPwn = ROPawn(Pawn);
    if(Pawn != none)
    	ROWeap = ROWeapon(Pawn.Weapon);

    if( bSway && (Pawn != none)
          && !Pawn.bBipodDeployed
		  && Pawn.Weapon != none
		  && Pawn.Weapon.bCanSway
		  && Pawn.Weapon.bUsingSights)
    {
		SwayHandler(DeltaTime);
    }
    else
    {
        SwayYaw = 0.0;
        SwayPitch = 0.0;
        WeaponSwayYawRate = 0.0;
        WeaponSwayPitchRate = 0.0;
        SwayTime = 0.0;
    }


    if ( bInterpolating || ((Pawn != None) && Pawn.bInterpolating) )
    {
        ViewShake(deltaTime);
        return;
    }

    // Added FreeCam control for better view control
    if (bFreeCam == True)
    {
        if (bHudLocksPlayerRotation)
        {
            // No camera change if we're locking rotation
        }
        else if (bFreeCamZoom == True)
        {
            CameraDeltaRad += DeltaTime * 0.25 * aLookUp;
        }
        else if (bFreeCamSwivel == True)
        {
            CameraSwivel.Yaw += 16.0 * DeltaTime * aTurn;
            CameraSwivel.Pitch += 16.0 * DeltaTime * aLookUp;
        }
        else
        {
            CameraDeltaRotation.Yaw += 32.0 * DeltaTime * aTurn;
            CameraDeltaRotation.Pitch += 32.0 * DeltaTime * aLookUp;
        }
    }
    else
    {
	    ViewRotation = Rotation;

		if(Pawn != none && Pawn.Physics != PHYS_Flying) // mmmmm
		{
			// Ensure we are not setting the pawn to a rotation beyond its desired
			if(	Pawn.DesiredRotation.Roll < 65535 &&
				(ViewRotation.Roll < Pawn.DesiredRotation.Roll || ViewRotation.Roll > 0))
				ViewRotation.Roll = 0;
			else if( Pawn.DesiredRotation.Roll > 0 &&
				(ViewRotation.Roll > Pawn.DesiredRotation.Roll || ViewRotation.Roll < 65535))
				ViewRotation.Roll = 0;
		}

        DesiredRotation = ViewRotation; //save old rotation

        if ( bTurnToNearest != 0 )
            TurnTowardNearestEnemy();
        else if ( bTurn180 != 0 )
            TurnAround();
        else
        {
            TurnTarget = None;
            bRotateToDesired = false;
            bSetTurnRot = false;

            if (bHudLocksPlayerRotation)
            {
                // No camera change if we're locking rotation
            }
            else if( ROPwn!= none && ROPwn.bRestingWeapon )
            {
	           	ViewRotation.Yaw += 16.0 * DeltaTime * aTurn;
		       	ViewRotation.Pitch += 16.0 * DeltaTime * aLookUp;
            }
            else
            {
	           	ViewRotation.Yaw += 32.0 * DeltaTime * aTurn;
		       	ViewRotation.Pitch += 32.0 * DeltaTime * aLookUp;
	       	}

			if( (Pawn != none ) && (Pawn.Weapon != none) && (ROPwn != none))
			{
				ViewRotation = FreeAimHandler(ViewRotation, DeltaTime);
            }
        }

        if( ROPwn != none )
        	ViewRotation.Pitch = ROPwn.LimitPitch(ViewRotation.Pitch,DeltaTime); //amb

        if( (ROPwn != none) && (ROPwn.bBipodDeployed) )
		{
            ROPwn.LimitYaw(ViewRotation.Yaw);
        }

        // Limit Pitch and yaw for the ROVehicles - Ramm
        if ( Pawn != none )
        {
             if( Pawn.IsA('ROVehicle'))
             {
                  ROVeh = ROVehicle(Pawn);

                  ViewRotation.Yaw = ROVeh.LimitYaw(ViewRotation.Yaw);
                  ViewRotation.Pitch = ROVeh.LimitPawnPitch( ViewRotation.Pitch );
             }
        }

// TODO: Fix and Optimize this when the weapons are converted over
//        if(  bSway && (Pawn != none)
//              && (ROProjectileWeapon(Pawn.Weapon) != none)
//			  && ROProjectileWeapon(Pawn.Weapon).bUsingSights)
//        {
            ViewRotation.Yaw += SwayYaw;
            ViewRotation.Pitch += SwayPitch;
 //       }

		SetRotation(ViewRotation);

        ViewShake(deltaTime);
        ViewFlash(deltaTime);

		NewRotation = ViewRotation;

        NewRotation.Roll = Rotation.Roll;

        if ( !bRotateToDesired && (Pawn != None) && (!bFreeCamera || !bBehindView) )
            Pawn.FaceRotation(NewRotation, deltatime);
    }
}

simulated function SetRecoil(rotator NewRecoilRotation, float NewRecoilSpeed)
{
	RecoilRotator += NewRecoilRotation;
	LastRecoilTime = Level.TimeSeconds;
	RecoilSpeed = NewRecoilSpeed;

}

// Calculate the weapon sway
simulated function SwayHandler(float DeltaTime)
{
     local float WeaponSwayYawAcc;
     local float WeaponSwayPitchAcc;
     local float DeltaSwayYaw;
     local float DeltaSwayPitch;
     local float timeFactor;
     local float staminaFactor;
     local ROPawn P;
     //local float zoomFactor;

	 P = ROPawn(Pawn);

	 if (P == None )
		return;

     StaminaFactor = (P.default.Stamina - P.Stamina)/(P.default.Stamina*0.5);

     SwayTime += DeltaTime;

     if( SwayClearTime > 0.05 )
     {
 		SwayClearTime = 0.0;
		WeaponSwayYawAcc = RandRange( -baseSwayYawAcc, baseSwayYawAcc );
        WeaponSwayPitchAcc = RandRange( -baseSwayPitchAcc, baseSwayPitchAcc );
     }
     else
     {
		WeaponSwayYawAcc = 0.0;
        WeaponSwayPitchAcc = 0.0;
        SwayClearTime += DeltaTime;
     }

     timeFactor = InterpCurveEval(SwayCurve,SwayTime);

     // weapon acceleration (sway) is based on time in iron sights and
     // on lost stamina
     WeaponSwayYawAcc =  (timeFactor * WeaponSwayYawAcc) + (staminaFactor * WeaponSwayYawAcc);
     WeaponSwayPitchAcc =  (timeFactor * WeaponSwayPitchAcc) + (staminaFactor * WeaponSwayPitchAcc);

     // Sway reduction for crouching, prone, and resting the weapon
     if (P.bRestingWeapon)
     {
         WeaponSwayYawAcc *= 0.1;
         WeaponSwayPitchAcc *= 0.1;
     }
	 else if (P.bIsCrouched)
     {
         WeaponSwayYawAcc *= 0.5;
         WeaponSwayPitchAcc *= 0.5;
     }
     else if (P.bIsCrawling)
     {
         WeaponSwayYawAcc *= 0.15;
         WeaponSwayPitchAcc *= 0.15;
     }

     if( P.LeanAmount != 0)
     {
 		 WeaponSwayYawAcc *= 1.45;
         WeaponSwayPitchAcc *= 1.45;
     }

     // added a elastic factor to get sway near the original aim-point
     // added a damping factor to keep the elastic factor from causing wild oscillations
     WeaponSwayYawAcc = WeaponSwayYawAcc - (SwayElasticFactor*SwayYaw) - (SwayDampingFactor*WeaponSwayYawRate);
     WeaponSwayPitchAcc = WeaponSwayPitchAcc - (SwayElasticFactor*SwayPitch) - (SwayDampingFactor*WeaponSwayPitchRate);

     // basic equation of motion (deltaX = vt + 1/2*a*t^2)
     DeltaSwayYaw = (WeaponSwayYawRate * DeltaTime) + (0.5*WeaponSwayYawAcc*DeltaTime*DeltaTime);
     DeltaSwayPitch = (WeaponSwayPitchRate * DeltaTime) + (0.5*WeaponSwayPitchAcc*DeltaTime*DeltaTime);
     SwayYaw += DeltaSwayYaw;
     SwayPitch += DeltaSwayPitch;

	 if (P.bRestingWeapon)
     {
         SwayYaw = 0;
         SwayPitch = 0;
     }

	// Maybe re-add this when we get the scoped weapons in
//    // Adjust by zoom factor of weapon
//    zoomFactor =0.65;//0.65*(DefaultFOV/ROWeapon(P.Weapon).ROPlayerFOVZoom);
//
//     // Sway reduction for crouching and prone - lets add this for snipers too!!! - Ramm
//	if (P.bIsCrouched)
//	{
//		FOVSwayYaw = 0.5*zoomFactor*(DeltaSwayYaw + SwayYawFraction);
//		FOVSwayPitch = 0.5*zoomFactor*(DeltaSwayPitch + SwayPitchFraction);
//	}
//	else if (P.bIsCrawling)
//	{
//		FOVSwayYaw = 0.35*zoomFactor*(DeltaSwayYaw + SwayYawFraction);
//		FOVSwayPitch = 0.35*zoomFactor*(DeltaSwayPitch + SwayPitchFraction);
//	}
//	else
//	{
//        FOVSwayYaw = zoomFactor*(DeltaSwayYaw + SwayYawFraction);
//        FOVSwayPitch = zoomFactor*(DeltaSwayPitch + SwayPitchFraction);
//    }

	// update new sway velocity
	WeaponSwayYawRate += WeaponSwayYawAcc*DeltaTime;
	WeaponSwayPitchRate += WeaponSwayPitchAcc*DeltaTime;
}

// Need to reset the sway when you switch stances so you don't retain the worse
// sway state when switching to a better sway state.
simulated function ResetSwayValues()
{
	WeaponSwayYawRate = 0;
	WeaponSwayPitchRate = 0;
}

//------------------------------------------------------------------------------
//	FreeAimHandler
// Calculate free-aim and process recoil
//------------------------------------------------------------------------------
simulated function rotator FreeAimHandler(rotator NewRotation, float DeltaTime)
{
	// try to move these to class variables so they aren't created every tick
	local rotator NewPlayerRotation;
    local int YawAdjust;
    local int PitchAdjust;
    local float	FreeAimBlendAmount;
    local rotator AppliedRecoil;

	if( Pawn == none || ROProjectileWeapon(Pawn.Weapon) == none ||
		!ROProjectileWeapon(Pawn.Weapon).ShouldUseFreeAim() )
	{
		LastFreeAimSuspendTime=Level.TimeSeconds;

		if( WeaponBufferRotation.Yaw != 0 )
		{
			if( WeaponBufferRotation.Yaw > 32768 )
			{
				WeaponBufferRotation.Yaw +=	YawTweenRate * deltatime;

				if( WeaponBufferRotation.Yaw > 65536 )
				{
					WeaponBufferRotation.Yaw = 0;
				}
			}
			else
			{
				WeaponBufferRotation.Yaw -=	YawTweenRate * deltatime;

				if( WeaponBufferRotation.Yaw <  0)
				{
					WeaponBufferRotation.Yaw = 0;
				}
			}
		}

		if( WeaponBufferRotation.Pitch != 0 )
		{
			if( WeaponBufferRotation.Pitch > 32768 )
			{
				WeaponBufferRotation.Pitch += PitchTweenRate * deltatime;

				if( WeaponBufferRotation.Pitch > 65536 )
				{
					WeaponBufferRotation.Pitch = 0;
				}
			}
			else
			{
				WeaponBufferRotation.Pitch -= PitchTweenRate * deltatime;

				if( WeaponBufferRotation.Pitch <  0)
				{
					WeaponBufferRotation.Pitch = 0;
				}
			}
		}

		// Process recoil
		// Handle recoil if the framerate is really low causing deltatime to be really high
/*		if( deltatime >= RecoilSpeed && ((Level.TimeSeconds - LastRecoilTime) <= (deltatime + (deltatime * 0.03))))
		{
			NewRotation += (RecoilRotator/RecoilSpeed) * deltatime/(deltatime/RecoilSpeed);
		}
		// Standard recoil
        else*/ if( Level.TimeSeconds - LastRecoilTime <= RecoilSpeed )
        {
			NewRotation += (RecoilRotator/RecoilSpeed) * deltatime;
        }
        else
        {
			RecoilRotator = rot(0,0,0);
        }

		return NewRotation;
	}

	NewPlayerRotation = NewRotation;

//	if( Level.TimeSeconds - LastFreeAimSuspendTime < 0.5 )
//	{
//		FreeAimBlendAmount = (Level.TimeSeconds - LastFreeAimSuspendTime)/0.5;
//	}
//	else
//	{
		FreeAimBlendAmount = 1;
//	}

	// Add the freeaim movement in
	if (!bHudLocksPlayerRotation)
	{
    	WeaponBufferRotation.Yaw += (FAAWeaponRotationFactor * DeltaTime * aTurn) * FreeAimBlendAmount;
    	WeaponBufferRotation.Pitch += (FAAWeaponRotationFactor * DeltaTime * aLookUp) * FreeAimBlendAmount;
    }

	// Process recoil
	// Handle recoil if the framerate is really low causing deltatime to be really high
/*	if( deltatime >= RecoilSpeed && ((Level.TimeSeconds - LastRecoilTime) <= (deltatime + (deltatime * 0.03))))
	{
	    AppliedRecoil = (RecoilRotator/RecoilSpeed) * deltatime/(deltatime/RecoilSpeed);
		WeaponBufferRotation += AppliedRecoil;
	}
	// standard recoil
    else*/ if( Level.TimeSeconds - LastRecoilTime <= RecoilSpeed )
    {
	    AppliedRecoil = (RecoilRotator/RecoilSpeed) * deltatime;
		WeaponBufferRotation += AppliedRecoil;
    }
    else
    {
		RecoilRotator = rot(0,0,0);
    }

	// Add recoil from a weapon that has been fired
	//WeaponBufferRotation += RecoilRotator;

	// Do the pitch and yaw limitation
    YawAdjust = WeaponBufferRotation.Yaw & 65535;

    if (YawAdjust > FreeAimMaxYawLimit && YawAdjust < FreeAimMinYawLimit)
    {
        if (YawAdjust - FreeAimMaxYawLimit < FreeAimMinYawLimit - YawAdjust)
            YawAdjust = FreeAimMaxYawLimit;
        else
            YawAdjust = FreeAimMinYawLimit;

       	NewPlayerRotation.Yaw += AppliedRecoil.Yaw;
    }

    WeaponBufferRotation.Yaw = YawAdjust;

    PitchAdjust = WeaponBufferRotation.Pitch & 65535;

    if (PitchAdjust > FreeAimMaxPitchLimit && PitchAdjust < FreeAimMinPitchLimit)
    {
        if (PitchAdjust - FreeAimMaxPitchLimit < FreeAimMinPitchLimit - PitchAdjust)
            PitchAdjust = FreeAimMaxPitchLimit;
        else
            PitchAdjust = FreeAimMinPitchLimit;

        NewPlayerRotation.Pitch += AppliedRecoil.Pitch;
    }

    WeaponBufferRotation.Pitch = PitchAdjust;

    //RecoilRotator = rot(0,0,0);

	return NewPlayerRotation;
}

simulated function DisplayDebug(Canvas Canvas, out float YL, out float YPos)
{
	Super.DisplayDebug(Canvas, YL, YPos);

	Canvas.SetDrawColor(255,255,255);

/*	Canvas.DrawText("PlayerController Rotation is "@Rotation);
	YPos += YL;
	Canvas.SetPos(4,YPos);*/

	Canvas.DrawText("bCrawl: "@bCrawl);
	YPos += YL;
	Canvas.SetPos(4,YPos);

	Canvas.DrawText(PlayerReplicationInfo.PlayerName$" bOnlySpectator: "$PlayerReplicationInfo.bOnlySpectator$" in state: "$GetStateName());
	YPos += YL;
	Canvas.SetPos(4,YPos);
}

// overload function and set flag to always false
// to prevent idle animation from playing while typing
// Puma 5-15-2004
function Typing( bool bTyping )
{
    bIsTyping = false;
    if ( (Pawn != None) )
        Pawn.bIsTyping = bIsTyping;
}


// Added this here so we could have bob in the textured scopes - Ramm
// Added AmbientShake functionality from UT2004 - Erik
function CalcFirstPersonView( out vector CameraLocation, out rotator CameraRotation )
{
	local vector x, y, z, AmbShakeOffset;
	local rotator AmbShakeRot, RollMod;
	local float FalloffScaling;
	local ROWeapon weap;
	local ROPawn rpawn;

    GetAxes(Rotation, x, y, z);

	if(bEnableAmbientShake)
	{
		if (AmbientShakeFalloffStartTime > 0 && Level.TimeSeconds - AmbientShakeFalloffStartTime > AmbientShakeFalloffTime)
			bEnableAmbientShake = false;
		else
		{
			if (AmbientShakeFalloffStartTime > 0)
			{
				FalloffScaling = 1.0 - ((Level.TimeSeconds - AmbientShakeFalloffStartTime) / AmbientShakeFalloffTime);
				FalloffScaling = FClamp(FalloffScaling, 0.0, 1.0);
			}
			else
				FalloffScaling = 1.0;

			AmbShakeOffset = AmbientShakeOffsetMag * FalloffScaling *
				sin(Level.TimeSeconds * AmbientShakeOffsetFreq * 2 * Pi);

			AmbShakeRot = AmbientShakeRotMag * FalloffScaling *
				sin(Level.TimeSeconds * AmbientShakeRotFreq * 2 * Pi);
		}
	}

	weap = ROWeapon(Pawn.Weapon);

    RollMod = Rotation;

	// Make the texture scope shake too
	// WeaponTODO: Add this scope stuff back in
	if ( (weap != none) && (weap.bUsingSights) && (weap.ScopeDetail == RO_TextureScope)
		&& weap.ShouldDrawPortal())
	{
		// First-person view
		CameraRotation = Normalize(RollMod/*Rotation*/ + ShakeRot); // amb
		CameraLocation = CameraLocation + Pawn.EyePosition() + Pawn.WalkBob + (Pawn.WeaponBob(Pawn.Weapon.BobDamping) * 25) +
					 	ShakeOffset.X * x +
					 	ShakeOffset.Y * y +
					 	ShakeOffset.Z * z +
						AmbShakeOffset;
	}
	else
	{
		// First-person view.
		CameraRotation = Normalize(RollMod/*Rotation*/ + ShakeRot + AmbShakeRot); // amb
		CameraLocation = CameraLocation + Pawn.EyePosition() + Pawn.WalkBob +
                     ShakeOffset.X * x +
                     ShakeOffset.Y * y +
                     ShakeOffset.Z * z +
					 AmbShakeOffset;
	}

	//Adjust camera roll for lean
	rpawn=ROPawn(pawn);
	if (rpawn != none && rpawn.LeanAmount != 0)
	{
		CameraRotation.Roll += rpawn.LeanAmount;
	}
}

//-----------------------------------------------------------------------------
// AskForPawn - Don't let the player restart on his own
//-----------------------------------------------------------------------------

function AskForPawn()
{
	if ( IsInState('GameEnded') )
		ClientGotoState('GameEnded', 'Begin');
	else if ( Pawn != None )
		GivePawn(Pawn);
	/*else
	{
		bFrozen = false;
		ServerRestartPlayer();
	}*/
}

//-----------------------------------------------------------------------------
// PawnDied - Change to desired role after death
//-----------------------------------------------------------------------------

function PawnDied(Pawn P)
{
    local ROTeamGame ROTeamGame;

	if ( P != Pawn )
		return;

    EndZoom();

    if ( Pawn != None )
        Pawn.RemoteRole = ROLE_SimulatedProxy;

    //if ( ViewTarget == Pawn )
    //    bBehindView = true;

	LastKillTime = -5.0;

    if (Pawn != None && bBehindView)
    {
        curcam = -1;
        SetLocation(FindFloatingCam(Pawn));
        SetRotation(CameraTrack(Pawn, 0));
    }

    Super(Controller).PawnDied(P);

    ROTeamGame = ROTeamGame(Level.Game);
	if (ROTeamGame != None && Role == ROLE_Authority)
    {
		if (!ROTeamGame.HandleDeath(self) && CurrentRole != DesiredRole)
		{
//			ROTeamGame.ChangeRole(self, DesiredRole, true);
			ROTeamGame.ChangeRole(self, DesiredRole, false);
 		    ROTeamGame.ChangeWeapons(self, DesiredPrimary, DesiredSecondary, DesiredGrenade);
		}
	}
}

simulated function ClientForcedTeamChange(int NewTeamIndex, int NewRoleIndex)
{
    //Store the new team and role info
    ForcedTeamSelectOnRoleSelectPage = NewTeamIndex;
    DesiredRole = NewRoleIndex;

    //Open the Role Selection Window
    ClientOpenMenu("ROInterface.ROGUIRoleSelection");
}

//-----------------------------------------------------------------------------
// GetRoleInfo - Returns the current RORoleInfo
//-----------------------------------------------------------------------------

function RORoleInfo GetRoleInfo()
{
	return ROPlayerReplicationInfo(PlayerReplicationInfo).RoleInfo;
}

//-----------------------------------------------------------------------------
// GetPrimaryWeapon
//-----------------------------------------------------------------------------

function string GetPrimaryWeapon()
{
	local RORoleInfo RI;

	RI = GetRoleInfo();

	if (RI == None || PrimaryWeapon < 0)
	{
		return "";
	}

	return string(RI.PrimaryWeapons[PrimaryWeapon].Item);
}

//-----------------------------------------------------------------------------
// GetPrimaryAmmo
//-----------------------------------------------------------------------------

function int GetPrimaryAmmo()
{
	local RORoleInfo RI;

	RI = GetRoleInfo();

	if (RI == None || PrimaryWeapon < 0)
		return -1;

	return RI.PrimaryWeapons[PrimaryWeapon].Amount;
}

//-----------------------------------------------------------------------------
// GetSecondaryWeapon
//-----------------------------------------------------------------------------

function string GetSecondaryWeapon()
{
	local RORoleInfo RI;

	RI = GetRoleInfo();

	if (RI == None || SecondaryWeapon < 0)
		return "";

	return string(RI.SecondaryWeapons[SecondaryWeapon].Item);
}

//-----------------------------------------------------------------------------
// GetSecondaryAmmo
//-----------------------------------------------------------------------------

function int GetSecondaryAmmo()
{
	local RORoleInfo RI;

	RI = GetRoleInfo();

	if (RI == None || SecondaryWeapon < 0)
		return -1;

	return RI.SecondaryWeapons[SecondaryWeapon].Amount;
}

//-----------------------------------------------------------------------------
// GetGrenadeWeapon
//-----------------------------------------------------------------------------

function string GetGrenadeWeapon()
{
	local RORoleInfo RI;

	RI = GetRoleInfo();

	if (RI == None || GrenadeWeapon < 0)
		return "";

	return string(RI.Grenades[GrenadeWeapon].Item);
}

//-----------------------------------------------------------------------------
// GetGrenadeAmmo
//-----------------------------------------------------------------------------

function int GetGrenadeAmmo()
{
	local RORoleInfo RI;

	RI = GetRoleInfo();

	if (RI == None || GrenadeWeapon < 0)
		return -1;

	return RI.Grenades[GrenadeWeapon].Amount;
}

//-----------------------------------------------------------------------------
// HasSelectedTeam
//-----------------------------------------------------------------------------

function bool HasSelectedTeam()
{
	return PlayerReplicationInfo.Team != none && PlayerReplicationInfo.Team.TeamIndex < 2;
}

//-----------------------------------------------------------------------------
// HasSelectedRole
//-----------------------------------------------------------------------------

function bool HasSelectedRole()
{
	return GetRoleInfo() != None;
}

//-----------------------------------------------------------------------------
// HasSelectedWeapons
//-----------------------------------------------------------------------------

function bool HasSelectedWeapons()
{
	return bWeaponsSelected;
}

//-----------------------------------------------------------------------------
// CanRestartPlayer - Returns true if the player is allowed to spawn
//-----------------------------------------------------------------------------

function bool CanRestartPlayer()
{
	if (PlayerReplicationInfo.bOnlySpectator || !bCanRespawn)
		return false;
	else if (!HasSelectedTeam() || !HasSelectedRole() || !HasSelectedWeapons())
		return false;

	return true;
}

//-----------------------------------------------------------------------------
// ChangeWeapons - Allows selection of all weapons
//-----------------------------------------------------------------------------

exec function ChangeWeapons(int Primary, int Secondary, int Grenade)
{
	if (Role == ROLE_Authority && ROTeamGame(Level.Game) != None)
	{
		if (CurrentRole != DesiredRole)
		{
            DesiredPrimary = Primary;
            DesiredSecondary = Secondary;
            DesiredGrenade = Grenade;
	    }
	    else
	    {
       		ROTeamGame(Level.Game).ChangeWeapons(self, Primary, Secondary, Grenade);
   		}
	}
}

//-----------------------------------------------------------------------------
// NewRole - Console command to change role by number
//-----------------------------------------------------------------------------

exec function ChangeRole(int i)
{
	if (Role == ROLE_Authority && ROTeamGame(Level.Game) != None)
		ROTeamGame(Level.Game).ChangeRole(self, i);
}

//-----------------------------------------------------------------------------
// ChangeCharacter - Subclassed to allow for setting the correct team or role specific model in ROTeamgame - Ramm
//-----------------------------------------------------------------------------
function ChangeCharacter(string newCharacter, optional string inClass)
{
	if( inClass != "")
	{
		SetPawnClass(inClass, newCharacter);
	}
	else
	{
		SetPawnClass(string(PawnClass), newCharacter);
	}

	UpdateURL("Character", newCharacter, true);
	SaveConfig();

	// Send the info to the client now!
	NetUpdateTime = Level.TimeSeconds - 1;
}

// Overriden to allow for setting the correct RO-specific pawn class
function SetPawnClass(string inClass, string inCharacter)
{
    local class<ROPawn> pClass;

    if ( inClass != "" )
	{
		pClass = class<ROPawn>(DynamicLoadObject(inClass, class'Class'));
		if ( (pClass != None) && pClass.Default.bCanPickupInventory )
			PawnClass = pClass;
	}

    PawnSetupRecord = class'xUtil'.static.FindPlayerRecord(inCharacter);
    PlayerReplicationInfo.SetCharacterName(inCharacter);
}

//-----------------------------------------------------------------------------
// ServerChangePlayerInfo - client to server function used to change player's
// team, role and weapons. Calls back a function on the client to confirm
// success or failure.
// Variable constants:
// 255 == no change
// 254 == switch to spectator
//-----------------------------------------------------------------------------
// Return values:
// 0 - all is well
// 97 - successfully switched to axis team
// 98 - successfully switched to allies team
// everything else - error
//-----------------------------------------------------------------------------

function ServerChangePlayerInfo(byte newTeam, byte newRole, byte newWeapon1, byte newWeapon2)
{
    // Attempt to change teams
    if (newTeam != 255)
    {
        //log("changing team...");
        // Try to switch teams
        if (newTeam == 254) // spectate
        {
            BecomeSpectator();

            // Check if change was successfull
            if (!PlayerReplicationInfo.bOnlySpectator)
            {
                if (PlayerReplicationInfo == none)
                    ClientChangePlayerInfoResult(01);
                else if (Level.Game.NumSpectators >= Level.Game.MaxSpectators)
                    ClientChangePlayerInfoResult(02);
                else if (IsInState('GameEnded'))
                    ClientChangePlayerInfoResult(03);
                else if (IsInState('RoundEnded'))
                    ClientChangePlayerInfoResult(04);
                else
                    ClientChangePlayerInfoResult(99);
                return;
            }
        }
        else
        {
            if (PlayerReplicationInfo == none || PlayerReplicationInfo.bOnlySpectator)
                BecomeActivePlayer();

            if (newTeam == 250) // auto select
                newTeam = ServerAutoSelectAndChangeTeam();
            else
                ServerChangeTeam(newTeam);

            // Check if change was successfull
            if (PlayerReplicationInfo == none || PlayerReplicationInfo.Team == none ||
                PlayerReplicationInfo.Team.TeamIndex != newTeam)
            {
                if (PlayerReplicationInfo == none)
                    ClientChangePlayerInfoResult(10);
                else if (Level.Game.bMustJoinBeforeStart)
                    ClientChangePlayerInfoResult(11);
                else if (Level.Game.NumPlayers >= Level.Game.MaxPlayers)
                    ClientChangePlayerInfoResult(12);
                else if (Level.Game.MaxLives > 0)
                    ClientChangePlayerInfoResult(13);
                else if (IsInState('GameEnded'))
                    ClientChangePlayerInfoResult(14);
                else if (IsInState('RoundEnded'))
                    ClientChangePlayerInfoResult(15);
                else if (Level.Game.bMustJoinBeforeStart && Level.Game.GameReplicationInfo.bMatchHasBegun)
                    ClientChangePlayerInfoResult(16);
                else if (ROTeamGame(Level.Game) != none && ROTeamGame(Level.Game).PickTeam(newTeam, self) != newTeam)
                {
                    if (ROTeamGame(Level.Game).bPlayersVsBots && (Level.NetMode != NM_Standalone))
                        ClientChangePlayerInfoResult(17);
                    else
                        ClientChangePlayerInfoResult(18);
                }
                else
                    ClientChangePlayerInfoResult(99);

                return;
            }
        }
    }

    // Attempt to change role
    if (newRole != 255)
    {
        //log("changing role...");
        ChangeRole(newRole);

        // Check if change was successfull
        if (DesiredRole != newRole)
        {
            if (ROTeamGame(Level.Game) != none &&
                PlayerReplicationInfo != none &&
                PlayerReplicationInfo.Team != none &&
                ROTeamGame(Level.Game).RoleLimitReached(PlayerReplicationInfo.Team.TeamIndex, newRole))
            {
                ClientChangePlayerInfoResult(100);
            }
            else
                ClientChangePlayerInfoResult(199);
            return;
        }
    }

    // Attempt to change weapons
    //if (newWeapon1 != 255)
    //{
        //log("Changing weapons...");
        ChangeWeapons(newWeapon1, newWeapon2, 0);

        // No success check here, let's just assume it worked :)
    //}

    // Success!
    if (newTeam == AXIS_TEAM_INDEX)
        ClientChangePlayerInfoResult(97); // successfully picked axis team
    else if (newTeam == ALLIES_TEAM_INDEX)
        ClientChangePlayerInfoResult(98); // successfully picked allies team
    else
        ClientChangePlayerInfoResult(00);
}

//-----------------------------------------------------------------------------
// ClientChangePlayerInfoResult - server to client function called after
// attempting to change a player's team, role and weapons.
// Valid result codeS:
// 0 - all ok! w00t.
// 1 - unable to change team
// 2 - unable to change role (role is full)
// 3 - unable to chaneg weapons (wtf?)
//-----------------------------------------------------------------------------

function ClientChangePlayerInfoResult(byte result)
{
    local UT2K4GUIController c;
    local GUIPage page;
    local class<GUIPage> page_class;

    // Update state of hint manager (if needed)
    // This is done here so that we still have a hint manager even if
    // we joined game as spectator and later joined an active team.
    UpdateHintManagement(bShowHints);

    // Find the currently open ROGUIRoleSelection menu and notify it
    c = UT2K4GUIController(Player.GUIController);

    if (c == none)
    {
        warn("Unable to cast guicontroller to UT2K4GUIController.");
        return;
    }

    //page_class = class<GUIPage>(DynamicLoadObject("ROInterface.ROGUIRoleSelection", class'class'));
    page_class = class'GUIPage';
    if (page_class != none)
    {
        page = c.FindMenuByClass(page_class);
        if (page != none)
            page.OnMessage("notify_gui_role_selection_page", result);
    }
    else
        warn("Unable to dynamically load RoleSelection menu class: ROInterface.ROGUIRoleSelection");
}

//-----------------------------------------------------------------------------
// Overide code to prevent glowing emitter which leads to objectives
// inherited from UT
//-----------------------------------------------------------------------------
function ServerShowPathToBase(int TeamNum)
{
   // allow functionality in single player
   if ( Level.NetMode == NM_Standalone )
   {
        Super.ServerShowPathToBase(TeamNum);
   }
}

//-----------------------------------------------------------------------------
// ServerSay
//-----------------------------------------------------------------------------
function ServerSay(string Msg)
{
    if ( ROTeamGame(Level.Game) != none && ROTeamGame(Level.Game).bForgiveFFKillsEnabled && LastFFKiller != none &&
        (Msg ~= "np" || Msg ~= "forgive" || Msg ~= "no prob" || Msg ~= "no problem") )
    {
		Level.Game.BroadcastLocalizedMessage(Level.Game.default.GameMessageClass, 19, LastFFKiller, PlayerReplicationInfo);
        LastFFKiller.FFKills -= LastFFKillAmount;
        LastFFKiller = none;
    }

    super.ServerSay(Msg);
}

//-----------------------------------------------------------------------------
// ServerTeamSay
//-----------------------------------------------------------------------------
function ServerTeamSay( string Msg )
{
    if ( ROTeamGame(Level.Game) != none && ROTeamGame(Level.Game).bForgiveFFKillsEnabled && LastFFKiller != none &&
        (Msg ~= "np" || Msg ~= "forgive" || Msg ~= "no prob" || Msg ~= "no problem") )
    {
		Level.Game.BroadcastLocalizedMessage(Level.Game.default.GameMessageClass, 19, LastFFKiller, PlayerReplicationInfo);
        LastFFKiller.FFKills -= LastFFKillAmount;
        LastFFKiller = none;
    }

	LastActiveTime = Level.TimeSeconds;
    Level.Game.BroadcastTeam( self, Level.Game.ParseMessageString( Level.Game.BaseMutator , self, Msg ) , 'TeamSay');
}

//-----------------------------------------------------------------------------
// ServerVehicleSay - Added to incorporate VehicleSay - MrMethane 01/10/2005
//-----------------------------------------------------------------------------
function ServerVehicleSay( string Msg )
{
    local ROPlayer ROP;
    local int i;
    local array<PlayerController> vehicleOccupants;

    if ( ROTeamGame(Level.Game) != none && ROTeamGame(Level.Game).bForgiveFFKillsEnabled && LastFFKiller != none &&
        (Msg ~= "np" || Msg ~= "forgive" || Msg ~= "no prob" || Msg ~= "no problem") )
    {
		Level.Game.BroadcastLocalizedMessage(Level.Game.default.GameMessageClass, 19, LastFFKiller, PlayerReplicationInfo);
        LastFFKiller.FFKills -= LastFFKillAmount;
        LastFFKiller = none;
    }

    LastActiveTime = Level.TimeSeconds;
    vehicleOccupants = GetVehicleOccupants(self);

    for ( i =0; i<vehicleOccupants.length; i++ )
	{
	    ROP =  ROPlayer(vehicleOccupants[i]);

		if ( ROP != None )
		{
			if((Pawn != none) )
			{
               ROP.VehicleMessage(self.PlayerReplicationInfo, Msg);
			}
		}
	}
}

//========================================================================================
// VehicleMessage - new function to send message to individual player MrMethane 01/10/2005
//========================================================================================
function VehicleMessage(PlayerReplicationInfo Sender, string Msg )
{
    local ROBroadCastHandler handler;

    if(Level.Game.BroadcastHandler.IsA('ROBroadcastHandler'))
    {
       handler = ROBroadCastHandler(Level.Game.BroadcastHandler);
       handler.BroadcastText(Sender,self ,Msg,'VehicleSay');
    }
    else
    {
       //Log("Server not using ROBroadcastHandler");
       // In case for some reason game isn't using ROBroadCastHandler just use TeamSay
       ServerTeamSay(Msg);
    }
}

//-----------------------------------------------------------------------------
// TeamSay - Spectators can only do say messages
//-----------------------------------------------------------------------------

exec function TeamSay(string Msg)
{
	if (PlayerReplicationInfo.bOnlySpectator || (PlayerReplicationInfo.Team != None && PlayerReplicationInfo.Team.TeamIndex == 2))
	{
		Say( Msg );
		return;
	}

	Msg = Left(Msg,128);
	if ( AllowTextMessage(Msg) )
		ServerTeamSay(Msg);
}

//-----------------------------------------------------------------------------
// VehicleSay - Added for vehicle communitcatoin -MrMethane 01/10/2005
//-----------------------------------------------------------------------------

exec function VehicleSay(string Msg)
{
	if (PlayerReplicationInfo.bOnlySpectator || (PlayerReplicationInfo.Team != None && PlayerReplicationInfo.Team.TeamIndex == 2))
	{
		Say( Msg );
		return;
	}

	Msg = Left(Msg,128);
	if ( AllowTextMessage(Msg) )
		ServerVehicleSay(Msg);
}

//-----------------------------------------------------------------------------
// PlayerMenu - Menu for the player's entire selection process
//-----------------------------------------------------------------------------

exec function PlayerMenu(optional int Tab)
{
	/*
    if (Tab == 2)
		ClientReplaceMenu("ROInterface.ROUT2K4PlayerSetupPage",, "Role");
	else if (Tab == 3)
		ClientReplaceMenu("ROInterface.ROUT2K4PlayerSetupPage",, "Weapons");
	else
		ClientReplaceMenu("ROInterface.ROUT2K4PlayerSetupPage");
	*/

	// new menu code :)

    bPendingMapDisplay = false;

	// If we havn't picked a team, role and weapons yet, open the team pick menu
	if (!bWeaponsSelected)
	    ClientReplaceMenu("ROInterface.ROGUITeamSelection");
	else
	    ClientReplaceMenu("ROInterface.ROGUIRoleSelection");
}

//-----------------------------------------------------------------------------
// ShowMidGameMenu - Eliminated LoginMenu getting shown here
//-----------------------------------------------------------------------------

function ShowMidGameMenu(bool bPause)
{
	// Pause if not already
	if(Level.Pauser == None)
		SetPause(true);

	if ( Level.NetMode != NM_DedicatedServer )
		StopForceFeedback();  // jdf - no way to pause feedback

	// Open menu
	if (bDemoOwner)
		ClientOpenMenu(DemoMenuClass);
	else
	{
	    // renamed this from MidGameMenuClass because I could not change the value - Puma
		ClientOpenMenu(ROMidGameMenuClass);
	}
}

//-----------------------------------------------------------------------------
// ShowLoginMenu - Modified to always show menu if called
//-----------------------------------------------------------------------------


simulated function ShowLoginMenu()
{
	if (Level.NetMode == NM_DedicatedServer )
	{
		return;
	}

	ClientReplaceMenu("ROInterface.ROUT2K4PlayerSetupPage");
}


//-----------------------------------------------------------------------------
// Prone - Toggles the bCrawl flag client side so the player will attempt to
// transition prone states
//-----------------------------------------------------------------------------
exec function Prone()
{
	if( Pawn != none && Pawn.CanProneTransition() )
	{
		if( bCrawl == 0 )
		{
			bCrawl = 1;
		}
		else
		{
			bCrawl = 0;
		}
	}
}

//-----------------------------------------------------------------------------
// Prone - Toggles the bCrawl flag client side so the player will attempt to
// transition prone states
//-----------------------------------------------------------------------------
exec function ToggleDuck()
{
	if( Pawn != none && Pawn.CanCrouchTransition())
	{
		if( bDuck == 0 )
		{
			bDuck = 1;
		}
		else
		{
			bDuck = 0;
		}
	}
}

exec function Crouch()
{
	if( Pawn != none && Pawn.CanCrouchTransition())
	{
		bDuck = 1;
	}
}

exec function UnCrouch()
{
	if( Pawn != none && Pawn.CanCrouchTransition())
	{
		bDuck = 0;
	}
}

//==================================================================
// FOV(UT) - Put here to make sure people can't mess with the FOV
//	while playing online
//==================================================================
exec function FOV(float F)
{
    if( Level.Netmode==NM_Standalone )
    {
        DefaultFOV = FClamp(F, 1, 170);
        DesiredFOV = DefaultFOV;
        // Lets not save this to config. This allows poeple to cheat
        //SaveConfig    ();
    }
}

//-----------------------------------------------------------------------------
// Possess - No voice setup here
//-----------------------------------------------------------------------------

function Possess(Pawn aPawn)
{
	local ROPawn xp;

	Super(PlayerController).Possess(aPawn);

	StopViewShaking();

	ClientResetMovement();

	xp = ROPawn(aPawn);
	if(xp != None)
		xp.Setup(PawnSetupRecord, true);
}

// Overidden to support resetting shake and blur values when you posses the pawn
function AcknowledgePossession(Pawn P)
{
	if( P != none )
	{
		StopViewShaking();
		if( Level.NetMode != NM_DedicatedServer )
		{
			ResetBlur();
		}
	}

	if ( Viewport(Player) != None )
	{
		AcknowledgedPawn = P;
		if ( P != None )
			P.SetBaseEyeHeight();
		ServerAcknowledgePossession(P, Handedness, bAutoTaunt);
	}
}

// Overriden to clear up view shake issues on respawn
simulated function StopViewShaking()
{
    ShakeRotMax  = vect(0,0,0);
    ShakeRotRate = vect(0,0,0);
    ShakeRotTime = vect(0,0,0);
	ShakeOffsetMax  = vect(0,0,0);
    ShakeOffsetRate = vect(0,0,0);
    ShakeOffsetTime = vect(0,0,0);

// if _RO_
	ShakeOffset = vect(0,0,0);
	ShakeRot = Rot(0,0,0);
// end _RO_
}

//-----------------------------------------------------------------------------
// AllowWeaponSwitch
//-----------------------------------------------------------------------------

simulated function bool AllowWeaponSwitch()
{
	// See if the pawn can switch

	if (SVehicle(Pawn) != none || VehicleWeaponPawn(Pawn) != none)
       return true;

	if (ROPawn(Pawn) == None || !ROPawn(Pawn).CanSwitchWeapon()  && !ROPawn(Pawn).CanBusySwitchWeapon() ||
		((ROPawn(Pawn).bIsSprinting && Pawn.Acceleration != vect(0,0,0)) && !ROPawn(Pawn).CanBusySwitchWeapon()))
		return false;


	return true;
}

//-----------------------------------------------------------------------------
// SwitchToBestWeapon
//-----------------------------------------------------------------------------

exec function SwitchToBestWeapon()
{
	if (AllowWeaponSwitch())
		Super.SwitchToBestWeapon();
}

//-----------------------------------------------------------------------------
// SwitchWeapon
//-----------------------------------------------------------------------------

exec function SwitchWeapon(byte F)
{
	// allow switching if
	//	1. player has a ROWeapon
	//	2. player is manning a SVehicle
	//	3. player is manning a ONSWeaponPawn
	// we might need to remove 2 and 3 if we don't want to let players switch positions
	if( AllowWeaponSwitch() || (SVehicle(Pawn) != none) || (VehicleWeaponPawn(Pawn) != none) )
		Super.SwitchWeapon(F);

	if( class'ROEngine.ROLevelInfo'.static.RODebugMode() && ((SVehicle(Pawn) != none) || (VehicleWeaponPawn(Pawn) != none) ))
		super.SwitchWeapon(F);
}

//-----------------------------------------------------------------------------
// NextWeapon
//-----------------------------------------------------------------------------

exec function NextWeapon()
{
    if (AllowWeaponSwitch())
		Super.NextWeapon();
}

//-----------------------------------------------------------------------------
// PrevWeapon
//-----------------------------------------------------------------------------

exec function PrevWeapon()
{
	if (AllowWeaponSwitch())
		Super.PrevWeapon();
}

//-----------------------------------------------------------------------------
// GetWeapon
//-----------------------------------------------------------------------------

exec function GetWeapon(class<Weapon> NewWeaponClass)
{
	if (AllowWeaponSwitch())
		Super.GetWeapon(NewWeaponClass);
}

//
// AddWeapon - attempts to add the specified weapon to the player's inventory
exec function AddWeapon( string NewWeaponStr )
{
	local	class<ROWeapon>	NewWeaponClass;
	local	ROWeapon      	NewWeapon;
	local	ROPawn			PlayerPawn;

	PlayerPawn = ROPawn(Pawn);

	if( (Level.NetMode != NM_StandAlone) || (PlayerPawn == none)
		|| !class'ROEngine.ROLevelInfo'.static.RODebugMode() )
		return;

	NewWeaponClass = class<ROWeapon>(DynamicLoadObject(NewWeaponStr, class'Class'));
	if( NewWeaponClass == none )
	{
		NewWeaponStr = "ROInventory." $ NewWeaponStr;
		NewWeaponClass = class<ROWeapon>(DynamicLoadObject(NewWeaponStr, class'Class'));
	}

	if( NewWeaponClass != none )
	{
     	NewWeapon = Spawn(NewWeaponClass, PlayerPawn);
     	NewWeapon.GiveTo( PlayerPawn );
     	Pawn.Weapon = none;
		NewWeapon.BringUp();
		Pawn.Weapon = NewWeapon;
		log("AddWeapon Command Was Used for " $ NewWeaponStr);
	}
}

//-----------------------------------------------------------------------------
// ThrowMGAmmo(RO) - Throws the MG ammo in the default inventory of all players
//-----------------------------------------------------------------------------
exec function ThrowMGAmmo()
{
    if( ROPawn(Pawn) == none )
        return;

		//log("Attempted to throw MG Ammo");
	if( (ROHud(myHud).NamedPlayer != none) && ROPawn(Pawn).bCanResupply
		&& !ROPawn(Pawn).bUsedCarriedMGAmmo )
	{
     	ServerThrowMGAmmo( ROHud(myHud).NamedPlayer );
	}
}

function ServerThrowMGAmmo(Pawn Gunner)
{
	//log("ROPlayer::ServerThrowMGAmmo");
	// do a check to see if we're in a state where we can throw ammo
    //if( Pawn.CanThrowWeapon() )
    //{
        ROPawn(Pawn).TossMGAmmo(Gunner);
    //}
}

//------------------------------------------------------------------------------
// ServerRemoveWeapon(RO) - Removes a weapon from a players inventory without
//	spawning a pickup and sets the client to bring up the next best weapon.
//	Used for destroying grenades
//------------------------------------------------------------------------------
// WeaponTODO: reimplement this if needed
function ServerRemoveWeapon()
{
	if( ROPawn(Pawn) == none )
		return;
//
//    ROPawn(Pawn).RemoveWeapon();
//    ClientSwitchToBestWeapon();
}

//-----------------------------------------------------------------------------
// ServerViewNextPlayer - Switches the next player
//-----------------------------------------------------------------------------
function ServerViewNextPlayer()
{
    local Controller C, Pick;
    local bool bFound, bRealSpec, bWasSpec;
	local TeamInfo RealTeam;

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

    // view next player
    for ( C=Level.ControllerList; C!=None; C=C.NextController )
    {
		if ( bRealSpec && (C.PlayerReplicationInfo != None) ) // hack fix for invasion spectating
			PlayerReplicationInfo.Team = C.PlayerReplicationInfo.Team;
        if ( Level.Game.CanSpectate(self,bRealSpec,C) )
        {
            if ( Pick == None )
                Pick = C;
            if ( bFound )
            {
                Pick = C;
                break;
            }
            else
                bFound = ( (RealViewTarget == C) || (ViewTarget == C) );
        }
    }
    PlayerReplicationInfo.Team = RealTeam;
    SetViewTarget(Pick);
    ClientSetViewTarget(Pick);

    if( Vehicle(ViewTarget) != none ) // First person view doesn't look right for these
    	bBehindView = true;
    else if ((ViewTarget == self) || bWasSpec || ROTeamGame(Level.Game).bSpectateFirstPersonOnly )
        bBehindView = false;
    else
        bBehindView = true; //bChaseCam;
    ClientSetBehindView(bBehindView);
    PlayerReplicationInfo.bOnlySpectator = bRealSpec;
}

// Overriden because we don't want to view the next player ffs
function ServerSpectate()
{
	// Proper fix for phantom pawns

	if (Pawn != none && !Pawn.bDeleteMe)
	{
		Pawn.Died(self, class'DamageType', Pawn.Location);
	}

	GotoState('Spectating');
}

// get the next valid spectator mode based on the servers settings
function ESpectatorMode GetNextValidSpecMode()
{
	local ROTeamGame ROG;

	ROG = ROTeamGame(Level.Game);

	if(  SpecMode == SPEC_Self )
	{
		if( PlayersToSpectate() )
		{
			return SPEC_Players;
		}
		else if( ROG.bSpectateAllowViewPoints && ROG.ViewPoints.Length > 0)
		{
			return SPEC_ViewPoints;
		}
		else if( ROG.bSpectateAllowRoaming )
		{
			return SPEC_Roaming;
		}
		else
		{
			return SPEC_Self;
		}
	}
	else if ( SpecMode == SPEC_Players )
	{
		if( ROG.bSpectateAllowViewPoints && ROG.ViewPoints.Length > 0)
		{
			return SPEC_ViewPoints;
		}
		else if( ROG.bSpectateAllowRoaming )
		{
			return SPEC_Roaming;
		}
		else if( !ROG.bSpectateAllowRoaming && PlayersToSpectate() )
		{
			return SPEC_Players;
		}
		else
		{
			return SPEC_Self;
		}
	}
	else if ( SpecMode == SPEC_ViewPoints )
	{
		if( ROG.bSpectateAllowRoaming )
		{
			return SPEC_Roaming;
		}
		else
		{
			return SPEC_Self;
		}
	}
 	else if ( SpecMode == SPEC_ViewPoints )
	{
		return SPEC_Self;
	}

	return SPEC_Self;
}

// Returns the string representation of the spectating mode
simulated function string GetSpecModeDescription()
{
	Switch(SpecMode)
	{
		case SPEC_Self: return SpectatingModeName[0];
		case SPEC_Roaming: return SpectatingModeName[1];
		case SPEC_Players: return SpectatingModeName[2];
		case SPEC_ViewPoints: return SpectatingModeName[3];
	}

	return "Spectating Mode Not Set";
}

// Returns true if there are players to spectate
function bool PlayersToSpectate()
{
	local Controller C;
	local bool bFound;

	// Make sure there are players we can spectate.  if not, leave the players looking at their corpse.
	for (C = Level.ControllerList; C != None; C = C.NextController)
	{
		if (C != self && Level.Game.CanSpectate(self, PlayerReplicationInfo.bOnlySpectator, C.Pawn))
		{
			bFound = true;
			break;
		}
	}

	return bFound;
}

// Used to limit the number of client side called to spectating views.
// this will prevent clients from overloading the server
simulated function bool CanRequestSpectateChange()
{
	if((Level.TimeSeconds -	LastSpectateChangeTime) > 0.25 )
	{
		LastSpectateChangeTime = Level.TimeSeconds;
		return true;
	}

	return false;
}
//-----------------------------------------------------------------------------
// ServerChangeSpecMode - Tells the server to switch between modes available
//-----------------------------------------------------------------------------
function ServerChangeSpecMode()
{
	local ESpectatorMode NewMode;

	if (Role < ROLE_Authority)
		return;

    NewMode = GetNextValidSpecMode();

    if (NewMode == SPEC_Self)
    {
    	SpecMode = SPEC_Self;
		ServerViewSelf();
    }
    else if (NewMode == SPEC_Roaming)
    {
    	SpecMode = SPEC_Roaming;
		ServerViewSelf();
    }
 	else if (NewMode == SPEC_Players)
	{
 		SpecMode = SPEC_Players;
		ServerViewNextPlayer();
	}
 	else if (NewMode == SPEC_ViewPoints)
	{
		SpecMode = SPEC_ViewPoints;
 		ServerNextViewPoint();
	}
}

// Switch to the next viewpoint in the level
function ServerNextViewPoint()
{
	local ROTeamGame G;

	if (Role < ROLE_Authority)
		return;

	G = ROTeamGame(Level.Game);

	if (G == None || G.ViewPoints.Length == 0)
		return;

	CurrentEntryCam++;

	if (CurrentEntryCam > (G.ViewPoints.Length - 1))
		CurrentEntryCam = 0;

	SetViewTarget(G.ViewPoints[CurrentEntryCam]);
	ClientSetViewTarget(G.ViewPoints[CurrentEntryCam]);
}

//-----------------------------------------------------------------------------
// CalcBehindView - Move in the camera with the locked view
//-----------------------------------------------------------------------------

function CalcBehindView(out vector CameraLocation, out rotator CameraRotation, float Dist)
{
	local vector View,HitLocation,HitNormal;
	local float ViewDist,RealDist;
	local vector globalX,globalY,globalZ;
	local vector localX,localY,localZ;
	// dead behindview locked stuff
	local ROPawn rpawn;
	local rotator ViewRot;
	local coords C;

	// Red Orchestra stuff to prevent players from looking around when this is the enforced view mode
	if (IsSpectating() && bLockedBehindView)
	{
		CameraRotation = ViewTarget.Rotation;

		RPawn = ROPawn(ViewTarget);

		if( RPawn != none )
		{
			CameraRotation.Pitch = RPawn.SmoothViewPitch;
			CameraRotation.Yaw = RPawn.SmoothViewYaw;
		}
		//Dist *= 0.5;
	}
	else if ( IsInState('Dead') && bLockedBehindView )
	{
		RPawn = ROPawn(ViewTarget);

		if( RPawn != none )
		{
            C = ViewTarget.GetBoneCoords(RPawn.HeadBone);

            // Rotate the view the proper direction
            ViewRot = OrthoRotation( -C.YAxis, -C.ZAxis, C.XAxis );

			CameraRotation = ViewRot;
		}
		else
		{
			CameraRotation = Rotation;
		}
	}
	else
	{
		CameraRotation = Rotation;
	}

	CameraRotation.Roll = 0;
	CameraLocation.Z += 12;

	// add view rotation offset to cameraview (amb)
	CameraRotation += CameraDeltaRotation;

	View = vect(1,0,0) >> CameraRotation;

	// add view radius offset to camera location and move viewpoint up from origin (amb)
	RealDist = Dist;
	Dist += CameraDeltaRad;

	if( Trace( HitLocation, HitNormal, CameraLocation - Dist * vector(CameraRotation), CameraLocation,false,vect(10,10,10) ) != none )
		ViewDist = FMin( (CameraLocation - HitLocation) dot View, Dist );
	else
		ViewDist = Dist;

	if ( !bBlockCloseCamera || !bValidBehindCamera || (ViewDist > 10 + FMax(ViewTarget.CollisionRadius, ViewTarget.CollisionHeight)) )
	{
		//Log("Update Cam ");
		bValidBehindCamera = true;
		OldCameraLoc = CameraLocation - ViewDist * View;
		OldCameraRot = CameraRotation;
	}
	else
	{
		//Log("Dont Update Cam "$bBlockCloseCamera@bValidBehindCamera@ViewDist);
		SetRotation(OldCameraRot);
	}

	CameraLocation = OldCameraLoc;
	CameraRotation = OldCameraRot;

	// add view swivel rotation to cameraview (amb)
	GetAxes(CameraSwivel,globalX,globalY,globalZ);
	localX = globalX >> CameraRotation;
	localY = globalY >> CameraRotation;
	localZ = globalZ >> CameraRotation;
	CameraRotation = OrthoRotation(localX,localY,localZ);
}

//-----------------------------------------------------------------------------
// HandleWalking - Slightly more complicated walk conditions
//-----------------------------------------------------------------------------
// new handlewalking
function HandleWalking()
{
	local ROPawn P;

	P = ROPawn(Pawn);

	if (P == None)
		return;

	if (P.bIsCrawling)
		P.SetWalking(false);
	else if (P.bIronSights)
		P.SetWalking(true);
	else
		P.SetWalking(bRun != 0);

// MergeTODO: this could probably be handled better
	P.SetSprinting(bSprint != 0);
}

//-----------------------------------------------------------------------------
// override so that dead players cannot send voice messages
//-----------------------------------------------------------------------------

function bool AllowVoiceMessage(name MessageType)
{
    if(Pawn == None)
    {
       return false;
    }

    return super.AllowVoiceMessage(MessageType);
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function SendVoiceMessage(PlayerReplicationInfo Sender,
                          PlayerReplicationInfo Recipient,
                          name messagetype,
                          byte messageID,
                          name broadcasttype,
                          optional Pawn soundSender,
                          optional vector senderLocation)
{
	local Controller P;
    local ROPlayer ROP;
    local ROBot ROB;
    //local string msg;
    local float distanceToOther;
    // Bot vehicle message stuff
	local array<Controller> vehicleOccupants;
    local int i;

    //log("ROPlayer::SendVoiceMessage()");
	if ( !AllowVoiceMessage(MessageType) )
		return;

    if(messagetype == 'VEH_ORDERS' || messagetype == 'VEH_ALERTS' || messagetype == 'VEH_GOTO')
    {
      SendVehicleVoiceMessage(Sender,Recipient,messagetype,messageID,broadcasttype);

	    ROP = ROPlayer(Sender.Owner);
	    vehicleOccupants = GetBotVehicleOccupants(ROP);

	    for ( i =0; i<vehicleOccupants.length; i++ )
		{
		    ROB =  ROBot(vehicleOccupants[i]);

			if ( ROB != None )
			{
			    ROB.BotVoiceMessage(messagetype, messageID, self);
			}
		}
      return;
    }

	for ( P=Level.ControllerList; P!=None; P=P.NextController )
	{
	    ROP =  ROPlayer(P);

		if ( ROP != None )
		{
			if((Pawn != none) )
			{
				// do we want people who are dead to hear voice commands? - Antarian
                if( (ROP.Pawn != none) && (Pawn != ROP.Pawn) )
                {//other player
			        distanceToOther = VSize(Pawn.Location-ROP.Pawn.Location);
			        if(class'ROVoicePack'.static.isValidDistanceForMessageType(messagetype,distanceToOther))
			        {
			           //log("ROPlayer::SendVoiceMessage(), other player in range");

			           if (ROP.PlayerReplicationInfo.Team.TeamIndex == PlayerReplicationInfo.Team.TeamIndex)
			           {
			               // Same team; no need to send sender pawn
			               ROP.ClientLocationalVoiceMessage(Sender, Recipient, messagetype,
                                                  messageID, none, senderLocation);
			           }
			           else
                           ROP.ClientLocationalVoiceMessage(Sender, Recipient, messagetype,
                                                  messageID, soundSender, senderLocation);
			        }

                }
                else //sending to self
                {
                   ROP.ClientLocationalVoiceMessage(Sender, Recipient, messagetype,
                                                  messageID, soundSender, senderLocation);
                }


       //dead men can't speak

            }
		}
		else if (((messagetype == 'ORDER') || (messagetype == 'ATTACK') || (messagetype == 'DEFEND'))
			 && ((Recipient == None) || (Recipient == P.PlayerReplicationInfo) ||
                 ( Bot(P) != none && Bot(P).Squad != none && Bot(P).Squad.SquadLeader != none &&
                   Bot(P).Squad.SquadLeader.PlayerReplicationInfo == Recipient)  ))
		{
			//log("Bot message area, messagetype = "$messagetype$" messageID = "$messageID);
			P.BotVoiceMessage(messagetype, messageID, self);
	    }
	}

	// Lets make the bots attack/defend particular objectives
    if ((messagetype == 'ATTACK') || (messagetype == 'DEFEND'))
    {
 		//TellBotsTo(messageID);
 		if (Recipient == none)
 		    ROTeamGame(Level.Game).SetTeamAIObjectives(messageID, PlayerReplicationInfo.Team.TeamIndex);
 		else
 		    ROTeamGame(Level.Game).SetSquadObjectives(messageID, PlayerReplicationInfo.Team.TeamIndex, Recipient);
 	}

    // Add to 'help request' array if needed
 	if (messagetype == 'ATTACK')
 	    AttemptToAddHelpRequest(PlayerReplicationInfo, messageID, 1, getObjectiveLocation(messageID)); // Send locations all the time (easier on hud drawing code)
 	else if (messagetype == 'DEFEND')
 	    AttemptToAddHelpRequest(PlayerReplicationInfo, messageID, 2, getObjectiveLocation(messageID)); // Ditto
 	else if (messagetype == 'HELPAT')
 	    AttemptToAddHelpRequest(PlayerReplicationInfo, messageID, 0, getObjectiveLocation(messageID)); // Idem
 	else if (messagetype == 'SUPPORT' && messageID == 0) // need help at coords
 	{
 	    if (Pawn != none)
 	        AttemptToAddHelpRequest(PlayerReplicationInfo, messageID, 4, Pawn.location);
 	}
 	else if (messagetype == 'SUPPORT' && messageID == 2) // need mg ammo
 	{
 	    if (Pawn != none)
 	        AttemptToAddHelpRequest(PlayerReplicationInfo, messageID, 3, Pawn.location);
 	}



	/*if(Sender.Team.TeamIndex == Level.GetLocalPlayerController().PlayerReplicationInfo.Team.TeamIndex)
    {
          msg = class'ROVoicePack'.static.getMessagePhraseFor(messagetype,messageID);
          TeamMessage(Sender,msg,'TEAMSAY');
    } */
}

// called server-side by SendVoiceMessage()
function AttemptToAddHelpRequest(PlayerReplicationInfo PRI, int objID, int requestType, optional vector requestLocation)
{
    local ROGameReplicationInfo GRI;
    local ROPlayerReplicationInfo RO_PRI;

    RO_PRI = ROPlayerReplicationInfo(PRI);
    if (RO_PRI == none || RO_PRI.RoleInfo == none)
        return;

    // Check if caller is a leader
    if (!RO_PRI.RoleInfo.bIsLeader)
    {
        // If not, check if we're a MG requesting ammo
        if (requestType != 3 || !RO_PRI.RoleInfo.bIsGunner)
            return;
    }

    GRI = ROGameReplicationInfo(GameReplicationInfo);
    if (GRI != none)
    {
        GRI.AddHelpRequest(PRI, objID, requestType, requestLocation);

        // Notify team members to check their map
        if (RO_PRI.Team != none)
            ROTeamGame(Level.Game).NotifyPlayersOfMapInfoChange(RO_PRI.Team.TeamIndex, self);
    }
}

// Return a vector corresponding to the specified objective's position
function vector getObjectiveLocation(int id)
{
    local ROGameReplicationInfo GRI;
    GRI = ROGameReplicationInfo(GameReplicationInfo);
    if (GRI == none)
        return vect(0,0,0);

    if (GRI.Objectives[id] != none) // Shouldn't be needed but you never know..
        return GRI.Objectives[id].Location;
    else
        return vect(0,0,0);
}

//===============================================================================
// SendVehicleVoiceMessage - new function to handle voice message send only
// to occupants of the same vehicle - MrMethane 01/10/2005
//===============================================================================
function SendVehicleVoiceMessage(PlayerReplicationInfo Sender,
                          PlayerReplicationInfo Recipient,
                          name messagetype,
                          byte messageID,
                          name broadcasttype)
{
    local ROPlayer ROP,P;
    local int i;
    local array<PlayerController> vehicleOccupants;

    P = ROPlayer(Sender.Owner);
    vehicleOccupants = GetVehicleOccupants(P);

    for ( i =0; i<vehicleOccupants.length; i++ )
	{
	    ROP =  ROPlayer(vehicleOccupants[i]);

		if ( ROP != None )
		{
               ROP.ClientLocationalVoiceMessage(Sender,Recipient,messagetype,messageID,Pawn);
		}
	}
}

//======================================================================================
// GetVehicleOccupants - Get all players in current vehicle - MrMethane 01/10/2005
//=====================================================================================
function array<PlayerController> GetVehicleOccupants(Controller Sender)
{
    local int i;
    local array<VehicleWeaponPawn> passengers;
    local ROVehicle v;
    local VehicleWeaponPawn weaponPawn;
    local PlayerController playerC,driver;
    local Pawn senderPawn;

    local array<PlayerController> allOccupants;

	senderPawn = PlayerController(Sender).Pawn;

    if(senderPawn != none && senderPawn.isA('ROVehicle'))
    {
        v = ROVehicle(senderPawn);
    }
    else if(senderPawn != none && senderPawn.isA('VehicleWeaponPawn'))
    {
        weaponPawn = VehicleWeaponPawn(Sender.Pawn);
        v = ROVehicle(weaponPawn.GetVehicleBase()); // get vehicle weapon pawn is attached to
    }

    if(v != None)
    {
        driver = PlayerController(v.Controller); // get vehicle controller

        if(driver != none)
        {
           AllOccupants[AllOccupants.length] = driver; // add driver
        }

        passengers = v.WeaponPawns;

        // get all passengers
        for(i=0; i < passengers.Length; i++)
        {
           playerC = PlayerController(passengers[i].Controller);

           if(playerC != none)
           {
              AllOccupants[AllOccupants.length] = playerC; // add driver
           }
        }
     }

     return AllOccupants;
}

//======================================================================================
// GetBotVehicleOccupants - Get all bots in current vehicle - Ramm
//=====================================================================================

function array<ROBot> GetBotVehicleOccupants(Controller Sender)
{
    local int i;
    local array<VehicleWeaponPawn> passengers;
    local ROVehicle v;
    local VehicleWeaponPawn weaponPawn;
    local ROBot driver, botC;
    local Pawn senderPawn;

    local array<ROBot> allOccupants;

	senderPawn = PlayerController(Sender).Pawn;

    if(senderPawn.isA('ROVehicle'))
    {
        v = ROVehicle(senderPawn);
    }
    else if(senderPawn.isA('VehicleWeaponPawn'))
    {
        weaponPawn = VehicleWeaponPawn(Sender.Pawn);
        v = ROVehicle(weaponPawn.GetVehicleBase()); // get vehicle weapon pawn is attached to
    }

    if(v != None)
    {
        driver = ROBot(v.Controller); // get vehicle controller

        if(driver != none)
        {
           AllOccupants[AllOccupants.length] = driver; // add driver
        }

        passengers = v.WeaponPawns;

        // get all passengers
        for(i=0; i < passengers.Length; i++)
        {
           botC = ROBot(passengers[i].Controller);

           if(botC != none)
           {
              AllOccupants[AllOccupants.length] = botC; // add driver
           }
        }
     }

     return AllOccupants;
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function ClientLocationalVoiceMessage(PlayerReplicationInfo Sender,
                                      PlayerReplicationInfo Recipient,
                                      name messagetype, byte messageID,
                                      optional Pawn senderPawn, optional vector senderLocation)
{
    local VoicePack voice;
    local ROVoicePack V;
    local bool isTeamVoice;
    local class<ROVoicePack> rov;
    local ROPlayerReplicationInfo playerRepInfo;

    isTeamVoice = false;

    if ( (Sender == None) || (Sender.voicetype == None) || (Player.Console == None) )
        return;

    if (//Level.NetMode ==  NM_ListenServer ||
        Level.NetMode ==  NM_DedicatedServer)
    {
          return;
    }

    //if the sender is receiving the sound then allow them to hear the
    //voicepack from their settings instead of the regular voicepack
    playerRepInfo = ROPlayerReplicationInfo(Sender);
    if(playerRepInfo != none && playerRepInfo.RoleInfo != none)
    {
        if( Level.GetLocalPlayerController().PlayerReplicationInfo.Team == none ||
			Sender.Team.TeamIndex == Level.GetLocalPlayerController().PlayerReplicationInfo.Team.TeamIndex)
        {
            rov = class<ROVoicePack>(DynamicLoadObject(playerRepInfo.RoleInfo.AltVoiceType,class'Class'));
            isTeamVoice = true;
            V = Spawn(rov, self);
        }
        else
        {
            rov = class<ROVoicePack>(DynamicLoadObject(playerRepInfo.RoleInfo.VoiceType,class'Class'));
            //log("different team, send native voice");
            V = Spawn(rov, self);
            if (V != none)
            {
                v.bUseLocationalVoice = true;
                v.bIsFromDifferentTeam = true;
            }
        }

        if(V != none)
        {
            V.ClientInitializeLocational(Sender, Recipient, messagetype, messageID, senderPawn, senderLocation);
            if(isTeamVoice)
            {
                if(MessageType == 'VEH_ORDERS' || MessageType == 'VEH_ALERTS' || MessageType == 'VEH_GOTO')
                    VehicleMessage(Sender, V.getClientParsedMessage());
                else if (MessageType == 'TAUNT')
                    TeamMessage(Sender,V.getClientParsedMessage(),'SAY');
                    //ServerSay(V.getClientParsedMessage());
                else
                    TeamMessage(Sender,V.getClientParsedMessage(),'TEAMSAY');
            }
        }

    }
    else
    {
       voice = Spawn(Sender.voicetype, self);
       if ( voice != None )
       {
          log("Fallback: voice.ClientInitialize(Sender, Recipient, messagetype, messageID);");
          voice.ClientInitialize(Sender, Recipient, messagetype, messageID);
       }
    }
}

/* ThrowWeapon()
Throw out current weapon, and switch to a new weapon
*/
// Overload to allow reverting FOV back to default
exec function ThrowWeapon()
{
    //Ramm: Refactor
    // The way this works stinks, lets replace it with something good
    //local RORocketWeapon myRocket;

    // Dont reset the FOV if the player is in a vehicle
    //log("Pawn is  "$pawn);
/*    if( Pawn.IsA('ROVehicleWeaponPawn'))
    {
        //log("Returning because Pawn.IsA ROVehicleWeaponPawn");
        return;
    }*/

    if ((SVehicle(Pawn) != none) || (VehicleWeaponPawn(Pawn) != none) )
    {
       //log("Returning because you can't throw out your vehicle weapon");
       return;
    }

    ResetFOV();  // resets the FOV if weapon was zoomed

    if ( (Pawn == None) || (Pawn.Weapon == None) )
        return;


    // this is a special check just for panzerfausts
    // it may need to be moved but I think it needs to be
    // done on the client before going to the server

    //Ramm: Refactor
    // The way this works stinks, lets replace it with something good
	/*
    if( (RORocketWeapon(Pawn.Weapon) != None) )
    {
         myRocket = RORocketWeapon(Pawn.Weapon);
         if((myRocket.RocketAttachment == None) && (myRocket.AmmoAmount(0) > 0))
         {
             Pawn.NextWeapon();
             return;
         }
    }
	*/
    ServerThrowWeapon();
}

// mostly same as ShowMenu in PlayerController, but added support for closing situation map
exec function ShowMenu()
{
	local bool bCloseHUDScreen;

	if ( MyHUD != None )
	{
		bCloseHUDScreen = MyHUD.bShowScoreboard || MyHUD.bShowLocalStats ||
            (ROHud(MyHUD) != none && ROHud(MyHUD).bShowObjectives);
		if ( MyHUD.bShowScoreboard )
			MyHUD.bShowScoreboard = false;
		if ( MyHUD.bShowLocalStats )
			MyHUD.bShowLocalStats = false;
		if ( ROHud(MyHUD) != none && ROHud(MyHUD).bShowObjectives )
		    ROHud(MyHUD).HideObjectives();

		if ( bCloseHUDScreen )
			return;
	}

	ShowMidGameMenu(true);
}

/*function ClientSetBehindView(bool B)
{
    //If we're driving a vehicle and we're switching to the behind view, show the exterior mesh
    if ( ROVehicle(Pawn) != none )
    	ROVehicle(Pawn).SwitchToExteriorMesh();

    //If we're a gunner in a vehicle and we're switching to the behind view, show the exterior mesh
    else if ( ROVehicleWeaponPawn(Pawn) != none )
    	ROVehicleWeaponPawn(Pawn).SwitchToExteriorMesh();

    super.ClientSetBehindView(B);
}*/

//=============================================================================
// States
//=============================================================================

//-----------------------------------------------------------------------------
// PlayerWalking
//-----------------------------------------------------------------------------
state PlayerWalking
{
	ignores SeePlayer, HearNoise, Bump;

	// Prevent spectating changes after the players spawns. Fixes the "Spectating Bug"
    function ServerViewNextPlayer(){}
    function ServerNextViewPoint(){}
    function ServerChangeSpecMode(){}
	function ServerRequestPOVChange(){/*log("ServerRequestPOVChange in state "$GetStateName());*/}
	function HandlePOVChange(){}

	function ClientSetBehindView(bool B)
	{
		if( B && Role < ROLE_Authority )
		{
			ServerCancelBehindview();
			return;
		}

		super.ClientSetBehindView(B);
	}


	function bool NotifyPhysicsVolumeChange( PhysicsVolume NewVolume )
	{
		if ( NewVolume.bWaterVolume )
			GotoState(Pawn.WaterMovementState);
		return false;
	}

	exec function Fire( optional float F )
	{
	    if (bHudCapturesMouseInputs)
	        HandleMouseClick();
	    else
	        super.Fire(F);
	}

	// Client side
	function PlayerMove( float DeltaTime )
	{
        local vector X,Y,Z, NewAccel;
        local eDoubleClickDir DoubleClickMove;
        local rotator OldRotation, ViewRotation;
        local bool  bSaveJump;
		local ROPawn P;

		P = ROPawn(Pawn);

        if (P == None)
        {
            GotoState('Dead'); // this was causing instant respawns in mp games
            return;
        }

        if (bHudCapturesMouseInputs)
            HandleMousePlayerMove(DeltaTime);

        GetAxes(Pawn.Rotation,X,Y,Z);

        // Update acceleration.
        NewAccel = aForward*X + aStrafe*Y;
        NewAccel.Z = 0;
        if ( VSize(NewAccel) < 1.0 )
            NewAccel = vect(0,0,0);

		//DoubleClickMove = PlayerInput.CheckForDoubleClickMove(1.1*DeltaTime/Level.TimeDilation);

        GroundPitch = 0;
        ViewRotation = Rotation;

        if ( Pawn.Physics == PHYS_Walking )
        {
			// Take the bipod weapon out of deployed if the player tries to move
 			if( Pawn.bBipodDeployed && NewAccel != vect(0,0,0) )
 			{
 				ROBipodWeapon(Pawn.Weapon).ForceUndeploy();
 			}

            // tell pawn about any direction changes to give it a chance to play appropriate animation
            //if walking, look up/down stairs - unless player is rotating view
             if ( (bLook == 0)
                && (((Pawn.Acceleration != Vect(0,0,0)) && bSnapToLevel) || !bKeyboardLook) )
            {
                if ( bLookUpStairs || bSnapToLevel )
                {
                    GroundPitch = FindStairRotation(deltaTime);
                    ViewRotation.Pitch = GroundPitch;
                }
            }
        }

        Pawn.CheckBob(DeltaTime, Y);

        // Update rotation.
        SetRotation(ViewRotation);
        OldRotation = Rotation;
        UpdateRotation(DeltaTime, 1);
		bDoubleJump = false;

        if ( bPressedJump && Pawn.CannotJumpNow() )
        {
            bSaveJump = true;
            bPressedJump = false;
        }
        else
            bSaveJump = false;

        if ( Role < ROLE_Authority ) // then save this move and replicate it
            ReplicateMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
        else
            ProcessMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
        bPressedJump = bSaveJump;
	}

	function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
	{
		local vector OldAccel;
		local ROPawn P;

		P = ROPawn(Pawn);

		if (P == None)
			return;

		OldAccel = Pawn.Acceleration;

        // WeaponTODO: Bipod system
//		if ((ROMasterWeapon(Pawn.Weapon) != None) && ROMasterWeapon(Pawn.Weapon).IsMounted())
//		{
//			NewAccel = vect(0,0,0);
//		}

		if (Pawn.Acceleration != NewAccel)
			Pawn.Acceleration = NewAccel;

		// Take away stamina from jumping
		if (bPressedJump)
		{
			P.DoJump(bUpdating);
		}

		Pawn.SetViewPitch(Rotation.Pitch);

		if ( Pawn.Physics != PHYS_Falling )
		{
			if (bDuck == 0 )
				Pawn.ShouldCrouch(false);
			else if ( Pawn.bCanCrouch )
				Pawn.ShouldCrouch(true);

			if (bCrawl == 0)
				Pawn.ShouldProne(false);
			else if ( Pawn.bCanProne )
				Pawn.ShouldProne(true);
		}
	}

	function BeginState()
	{
	   	DoubleClickDir = DCLICK_None;
	   	bPressedJump = false;
	   	GroundPitch = 0;
		if ( Pawn != None )
		{
			if ( Pawn.Mesh == None )
				Pawn.SetMesh();
			Pawn.ShouldCrouch(false);

			// Not sure if we need this or not - Ramm
			Pawn.ShouldProne(false);

			if (Pawn.Physics != PHYS_Falling && Pawn.Physics != PHYS_Karma) // FIXME HACK!!!
				Pawn.SetPhysics(PHYS_Walking);
		}

		// This is the magic right here. This can fix the player view bug where you are stuck view someone else
	    if( Role==ROLE_Authority )
	    {
		    if( Pawn!=none )
		    {
				SetViewTarget(Pawn);
				ClientSetViewTarget(Pawn);
			}
			else
			{
				SetViewTarget(self);
				ClientSetViewTarget(self);
			}

		    ClientSetBehindView(false);
	    }

	    // Hint!
	    CheckForHint(0); // player respawned
	 }

	function EndState()
	{

		GroundPitch = 0;
		if ( Pawn != None )
		{
			if( bDuck==0 )
				Pawn.ShouldCrouch(false);

			// Not sure if we need this or not - Ramm
			if( bCrawl==0 )
				Pawn.ShouldProne(false);
		}
	}
}

state Spectating
{
    ignores SwitchWeapon, RestartLevel, ClientRestart, Suicide,
     ThrowWeapon, NotifyPhysicsVolumeChange, NotifyHeadVolumeChange;

    // Return to spectator's own camera.
    exec function Jump( optional float F )
    {
		if( ViewTarget != self && CanRequestSpectateChange() )
		{
	    	ServerViewSelf();
    	}
    }

    event PlayerTick( float DeltaTime )
    {
        super.PlayerTick( DeltaTime );

        if ( Level.NetMode != NM_DedicatedServer && ViewTarget != none && !bBehindView)
        {
           if ( Pawn(ViewTarget) != none && Pawn(ViewTarget).IsA('Vehicle') )
           {
                bBehindView = true;
                super.ClientSetBehindView(bBehindView);
           }
        }
    }

    // Cycle view positions
	exec function Fire( optional float F )
    {
    	if ( bFrozen )
		{
			if ( (TimerRate <= 0.0) || (TimerRate > 1.0) )
				bFrozen = false;
			return;
		}

		if (SpecMode == SPEC_Players)
		{
	 		 if ( CanRequestSpectateChange() )
			 	ServerViewNextPlayer();
		}
	 	else if (SpecMode == SPEC_ViewPoints)
		{
	 		 if ( CanRequestSpectateChange() )
			 	ServerNextViewPoint();
		}

		if ( Pawn(ViewTarget) != none && Pawn(ViewTarget).IsA('Vehicle') )
		{
        	bBehindView = true;
            super.ClientSetBehindView(bBehindView);
		}
    }

    // switch spectating modes
    exec function AltFire( optional float F )
    {
    	if ( CanRequestSpectateChange() )
			ServerChangeSpecMode();

		if ( Pawn(ViewTarget) != none && Pawn(ViewTarget).IsA('Vehicle') )
		{
        	bBehindView = true;
            super.ClientSetBehindView(bBehindView);
		}
    }

	simulated exec function ROIronSights()
	{
		if ( CanRequestSpectateChange() )
		{
			ServerRequestPOVChange();
		}
	}

    function Timer()
    {
    	bFrozen = false;
    }

	function HandlePOVChange()
	{
		if( Role == ROLE_Authority && !ROTeamGame(Level.Game).bSpectateFirstPersonOnly && Pawn(ViewTarget) != none)
		{
			bBehindView = !bBehindView;
			ClientSetBehindView(bBehindView);
		}

		if ( Pawn(ViewTarget) != none && Pawn(ViewTarget).IsA('Vehicle') )
		{
        	bBehindView = true;
            super.ClientSetBehindView(bBehindView);
		}
	}

    function PlayerMove(float DeltaTime)
    {

        local vector X,Y,Z;

        if( SpecMode == SPEC_ViewPoints )
        {
	        if ( ViewTarget != None )
	            SetRotation(ViewTarget.Rotation);
	    }
	    else
	    {
			if ( (Pawn(ViewTarget) != None) && (Level.NetMode == NM_Client) )
			{
				if ( Pawn(ViewTarget).bSimulateGravity )
					TargetViewRotation.Roll = 0;
				BlendedTargetViewRotation.Pitch = BlendRot(DeltaTime, BlendedTargetViewRotation.Pitch, TargetViewRotation.Pitch & 65535);
				BlendedTargetViewRotation.Yaw = BlendRot(DeltaTime, BlendedTargetViewRotation.Yaw, TargetViewRotation.Yaw & 65535);
				BlendedTargetViewRotation.Roll = BlendRot(DeltaTime, BlendedTargetViewRotation.Roll, TargetViewRotation.Roll & 65535);
			}
	        GetAxes(Rotation,X,Y,Z);

	        Acceleration = 0.02 * (aForward*X + aStrafe*Y + aUp*vect(0,0,1));

	        UpdateRotation(DeltaTime, 1);
    	}

        if( SpecMode == SPEC_Self || SpecMode == SPEC_ViewPoints || !bAllowRoamWhileSpectating )
        {
	        if ( Role < ROLE_Authority ) // then save this move and replicate it
	            ReplicateMove(DeltaTime, vect(0,0,0), DCLICK_None, rot(0,0,0));
	        else
	            ProcessMove(DeltaTime, vect(0,0,0), DCLICK_None, rot(0,0,0));
		}
		else
		{
	        if ( Role < ROLE_Authority ) // then save this move and replicate it
	            ReplicateMove(DeltaTime, Acceleration, DCLICK_None, rot(0,0,0));
	        else
	            ProcessMove(DeltaTime, Acceleration, DCLICK_None, rot(0,0,0));
        }
    }

    function BeginState()
    {
        if ( Pawn != None )
        {
            SetLocation(Pawn.Location);
            UnPossess();
        }
        bCollideWorld = true;
		CameraDist = Default.CameraDist;
    }

    function EndState()
    {
        PlayerReplicationInfo.bIsSpectator = false;
        bCollideWorld = false;
    }
}

state Dead
{
ignores SeePlayer, HearNoise, KilledBy, SwitchWeapon, NextWeapon, PrevWeapon;

	function bool IsSpectating()
	{
		return false;
	}

	// new calcview stuff to handle our death camera
	event PlayerCalcView(out actor ViewActor, out vector CameraLocation, out rotator CameraRotation )
	{
		if ( ROPawn(ViewTarget) != none && !bBehindView )
	    {
			ViewActor = ViewTarget;

            CalcFirstPersonView( CameraLocation, CameraRotation );

			CacheCalcView(ViewActor,CameraLocation,CameraRotation);
	        return;
	    }
	    else
	    {
			super.PlayerCalcView( ViewActor, CameraLocation, CameraRotation);
		}
	}

    // New calcview stuff to handle our death camera
	function CalcFirstPersonView( out vector CameraLocation, out rotator CameraRotation )
	{
		local ROPawn rpawn;
		local rotator ViewRot;
		local coords C;

		RPawn = ROPawn(ViewTarget);

		if( RPawn != none )
		{
            C = ViewTarget.GetBoneCoords(RPawn.HeadBone);

            // Rotate the view the proper direction
            ViewRot = OrthoRotation( -C.YAxis, -C.ZAxis, C.XAxis );

			CameraRotation = ViewRot;
			CameraLocation = ViewTarget.GetBoneCoords(RPawn.HeadBone).Origin;
		}
	}

	function ServerRequestDeadSpectating()
	{
      	GotoState('DeadSpectating');
	}

	exec function ThrowWeapon()
	{
		//clientmessage("Throwweapon while dead, pawn "$Pawn$" health "$Pawn.health);
	}

	function bool IsDead()
	{
		return true;
	}

	function ServerReStartPlayer()
	{
		if ( !Level.Game.PlayerCanRestart( Self ) )
			return;

		super.ServerRestartPlayer();
	}

    exec function Fire( optional float F )
    {
		if ( myHUD != None )
			myHUD.bShowScoreBoard = false;
		if( !bBehindView && !bFirstPersonSpectateOnly)
		{
			if (ROHud(myHud) != None)
				ROHud(myHud).StopFadeEffect();

 			if (Pawn(ViewTarget) != None)
 			{
				Pawn(ViewTarget).SetHeadScale(Pawn(ViewTarget).default.HeadScale);
				ViewTarget.bHidden = false;
			}

		  	bBehindView = true;
		  	bBlockCloseCamera = true;
		  	bValidBehindCamera = false;
		  	FindGoodView();
		}
		else if ( CanRequestSpectateChange() && (!bFirstPersonSpectateOnly || VSizeSquared(ViewTarget.Velocity) <= 2.0))
		{
			ServerRequestDeadSpectating();
		}

		if ( bFrozen )
		{
			if ( (TimerRate <= 0.0) || (TimerRate > 1.0) )
				bFrozen = false;
			return;
		}
           /*
        LoadPlayers();

        if (bMenuBeforeRespawn)
        {
        	bMenuBeforeRespawn = false;
       		ShowMidGameMenu(false);
        }
        else
	        ServerReStartPlayer();*/
    }

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

    exec function Use()
    {
		if ( bFrozen )
		{
			if ( (TimerRate <= 0.0) || (TimerRate > 1.0) )
				bFrozen = false;
			return;
		}
		if ( Level.Game != None )
			Level.Game.DeadUse(self);
    }

	function ServerMove
	(
	    float TimeStamp,
	    vector InAccel,
	    vector ClientLoc,
		byte NewActions,
	    eDoubleClickDir DoubleClickMove,
	    byte ClientRoll,
	    int View,
	    optional int FreeAimRot,
	    optional byte OldTimeDelta,
	    optional int OldAccel
	)
    {
        Global.ServerMove(
                    TimeStamp,
                    InAccel,
                    ClientLoc,
                    0,
                    DoubleClickMove,
                    ClientRoll,
                    View);
    }

    function PlayerMove(float DeltaTime)
    {
        local vector X,Y,Z;
        local rotator ViewRotation;

        if ( !bFrozen )
        {
            if ( bPressedJump )
            {
                Fire(0);
                bPressedJump = false;
            }
            GetAxes(Rotation,X,Y,Z);
            // Update view rotation.
            ViewRotation = Rotation;
            ViewRotation.Yaw += 32.0 * DeltaTime * aTurn;
            ViewRotation.Pitch += 32.0 * DeltaTime * aLookUp;
            if (Pawn != None)
	            ViewRotation.Pitch = Pawn.LimitPitch(ViewRotation.Pitch, DeltaTime);
            SetRotation(ViewRotation);
            if ( Role < ROLE_Authority ) // then save this move and replicate it
                ReplicateMove(DeltaTime, vect(0,0,0), DCLICK_None, rot(0,0,0));
        }
        else if ( (TimerRate <= 0.0) || (TimerRate > 1.0) )
			bFrozen = false;

        ViewShake(DeltaTime);
        ViewFlash(DeltaTime);
    }

    function FindGoodView()
    {
        local vector cameraLoc;
        local rotator cameraRot, ViewRotation;
        local int tries, besttry;
        local float bestdist, newdist;
        local int startYaw;
        local actor ViewActor;

        ////log("Find good death scene view");
        ViewRotation = Rotation;
        ViewRotation.Pitch = 56000;
        tries = 0;
        besttry = 0;
        bestdist = 0.0;
        startYaw = ViewRotation.Yaw;

        for (tries=0; tries<16; tries++)
        {
            cameraLoc = ViewTarget.Location;
			SetRotation(ViewRotation);
            PlayerCalcView(ViewActor, cameraLoc, cameraRot);
            newdist = VSize(cameraLoc - ViewTarget.Location);
            if (newdist > bestdist)
            {
                bestdist = newdist;
                besttry = tries;
            }
            ViewRotation.Yaw += 4096;
        }

        ViewRotation.Yaw = startYaw + besttry * 4096;
        SetRotation(ViewRotation);
    }

    function Timer()
    {
        if (!bFrozen)
            return;

        bFrozen = false;
        bPressedJump = false;
    }

    function BeginState()
    {
		local Actor A;

		if ( (Pawn != None) && ((Pawn.Controller == self) || (Pawn.Controller == None)) )
			Pawn.Controller = None;
		EndZoom();
		CameraDist = Default.CameraDist;
		FOVAngle = DesiredFOV;
		Pawn = None;
        Enemy = None;
        //bBehindView = true;
        bFrozen = true;
		bJumpStatus = false;
        bPressedJump = false;
        //bBlockCloseCamera = true;
		//bValidBehindCamera = false;
		bFreeCamera = False;
		if ( Viewport(Player) != None )
			foreach DynamicActors(class'Actor',A)
				A.NotifyLocalPlayerDead(self);
        //FindGoodView();
        SetTimer(1.0, false);
		StopForceFeedback();
		ClientPlayForceFeedback("Damage");  // jdf
		CleanOutSavedMoves();

		if( Pawn(ViewTarget) != none && Pawn(ViewTarget).IsA('Vehicle') )
		{
		    bBehindView = true;
		    bValidBehindCamera = false;
		    FindGoodView();
		}

		// First person death
		// View your own body during first person death. Have to scale the head down so
		// you don't see the back of your face
		if (!bBehindView && Level.NetMode != NM_DedicatedServer )
		{
			if ( Pawn(ViewTarget) != none && !Pawn(ViewTarget).IsA('Vehicle'))
			{
				ViewTarget.bOwnerNoSee = false;
				Pawn(ViewTarget).SetHeadScale(0.1);
			}
		}

        // Check hint
        CheckForHint(5);

		if (ROHud(myHud) != None)
			ROHud(myHud).StartFadeEffect();
    }

    function EndState()
    {
		StopForceFeedback();
		bBlockCloseCamera = false;
		CleanOutSavedMoves();
        Velocity = vect(0,0,0);
        Acceleration = vect(0,0,0);
        if ( !PlayerReplicationInfo.bOutOfLives )
			bBehindView = false;
        bPressedJump = false;
        if ( myHUD != None )
			myHUD.bShowScoreBoard = false;

		StopViewShaking();

		if (Pawn(ViewTarget) != None)
			Pawn(ViewTarget).SetHeadScale(Pawn(ViewTarget).default.HeadScale);

		if (!bBehindView && Level.NetMode != NM_DedicatedServer)
		{
			if (Pawn(ViewTarget) != None)
				ViewTarget.bHidden = false;
		}

		if (ROHud(myHud) != None)
			ROHud(myHud).StopFadeEffect();

    }

Begin:
    if( Level.NetMode != NM_DedicatedServer)
    {
	    Sleep(3.0);
		if ( (ViewTarget == None) || (ViewTarget == self) && (VSizeSquared(ViewTarget.Velocity) > 2.0) )
		{
			Sleep(1.0);
			if ( myHUD != None )
				myHUD.bShowScoreBoard = true;
		}
		else if ( VSizeSquared(ViewTarget.Velocity) <= 2.0)
		{
			ServerRequestDeadSpectating();
		}
		else
			Goto('Begin');
	}
	else
	{
		Sleep(10.0);
		GotoState('DeadSpectating');
	}
}

state DeadSpectating extends Spectating
{
    ignores SwitchWeapon, RestartLevel, ClientRestart, Suicide,
     ThrowWeapon, NotifyPhysicsVolumeChange, NotifyHeadVolumeChange;

	function bool IsDead()
	{
		return true;
	}

    event PlayerTick( float DeltaTime )
    {
        super.PlayerTick( DeltaTime );

        if( Level.NetMode != NM_DedicatedServer && !bViewBlackWhenDead && bViewBlackOnDeadNotViewingPlayers)
        {
            if ( Pawn(ViewTarget) == none )
            {
        		if (ROHud(myHud) != None)
        			ROHud(myHud).ForceFadeEffect();
            }
            else
            {
        		if (ROHud(myHud) != None)
        			ROHud(myHud).StopFadeEffect();
            }
        }
    }

    // return to spectator's own camera.
    exec function Jump( optional float F )
    {
		if( ViewTarget != self && CanRequestSpectateChange())
		{
	    	ServerViewSelf();
    	}
    }

    // Cycle view positions
	exec function Fire( optional float F )
    {
    	if ( bFrozen )
		{
			if ( (TimerRate <= 0.0) || (TimerRate > 1.0) )
				bFrozen = false;
			return;
		}

		if (SpecMode == SPEC_Players)
		{
	 		 if ( CanRequestSpectateChange() )
			 	ServerViewNextPlayer();
		}
	 	else if (SpecMode == SPEC_ViewPoints)
		{
	 		 if ( CanRequestSpectateChange() )
			 	ServerNextViewPoint();
		}

		if ( Pawn(ViewTarget) != none && Pawn(ViewTarget).IsA('Vehicle') )
		{
        	bBehindView = true;
            super.ClientSetBehindView(bBehindView);
		}
    }

    // switch spectating modes
    exec function AltFire( optional float F )
    {
    	if ( CanRequestSpectateChange() )
			ServerChangeSpecMode();

        if ( Pawn(ViewTarget) != none && Pawn(ViewTarget).IsA('Vehicle') )
		{
        	bBehindView = true;
            super.ClientSetBehindView(bBehindView);
		}
    }

	simulated exec function ROIronSights()
	{
		if ( CanRequestSpectateChange() )
		{
			ServerRequestPOVChange();
		}
	}

	function ServerViewSelf()
	{
		// Don't allow the player to start roaming if they aren't supposed to roam
		if( (!ROTeamGame(Level.Game).bSpectateAllowRoaming || !ROTeamGame(Level.Game).bSpectateAllowDeadRoaming )
            && PlayersToSpectate() )
		{
			return;
		}

		SetLocation(ViewTarget.Location);
		ClientSetLocation(ViewTarget.Location, Rotation);

	    bBehindView = false;
	    SetViewTarget(self);
	    ClientSetViewTarget(self);
	    ClientMessage(OwnCamera, 'Event');
	}


    function Timer()
    {
    	bFrozen = false;
    }

	function HandlePOVChange()
	{
		if( Role == ROLE_Authority && !ROTeamGame(Level.Game).bSpectateFirstPersonOnly && Pawn(ViewTarget) != none)
		{
			bBehindView = !bBehindView;
			ClientSetBehindView(bBehindView);
		}

		if ( Pawn(ViewTarget) != none && Pawn(ViewTarget).IsA('Vehicle') )
		{
        	bBehindView = true;
            super.ClientSetBehindView(bBehindView);
		}
	}

    function PlayerMove(float DeltaTime)
    {

        local vector X,Y,Z;

        if( SpecMode == SPEC_ViewPoints )
        {
	        if ( ViewTarget != None )
	            SetRotation(ViewTarget.Rotation);
	    }
	    else
	    {
			if ( (Pawn(ViewTarget) != None) && (Level.NetMode == NM_Client) )
			{
				if ( Pawn(ViewTarget).bSimulateGravity )
					TargetViewRotation.Roll = 0;
				BlendedTargetViewRotation.Pitch = BlendRot(DeltaTime, BlendedTargetViewRotation.Pitch, TargetViewRotation.Pitch & 65535);
				BlendedTargetViewRotation.Yaw = BlendRot(DeltaTime, BlendedTargetViewRotation.Yaw, TargetViewRotation.Yaw & 65535);
				BlendedTargetViewRotation.Roll = BlendRot(DeltaTime, BlendedTargetViewRotation.Roll, TargetViewRotation.Roll & 65535);
			}

	        GetAxes(Rotation,X,Y,Z);

	        Acceleration = 0.02 * (aForward*X + aStrafe*Y + aUp*vect(0,0,1));

	        UpdateRotation(DeltaTime, 1);
    	}

        if( SpecMode == SPEC_Self || SpecMode == SPEC_ViewPoints || !bAllowRoamWhileSpectating || !bAllowRoamWhileDeadSpectating)
        {
	        if ( Role < ROLE_Authority ) // then save this move and replicate it
	            ReplicateMove(DeltaTime, vect(0,0,0), DCLICK_None, rot(0,0,0));
	        else
	            ProcessMove(DeltaTime, vect(0,0,0), DCLICK_None, rot(0,0,0));
		}
		else
		{
	        if ( Role < ROLE_Authority ) // then save this move and replicate it
	            ReplicateMove(DeltaTime, Acceleration, DCLICK_None, rot(0,0,0));
	        else
	            ProcessMove(DeltaTime, Acceleration, DCLICK_None, rot(0,0,0));
        }
    }

    function BeginState()
    {
		if( Role == ROLE_Authority )
		{
			bBehindView = false;
			ClientSetBehindView(bBehindView);

		   	SpecMode = SPEC_Self;
			ServerChangeSpecMode();
		}

        bCollideWorld = true;
		CameraDist = Default.CameraDist;

        if( bViewBlackWhenDead )
        {
    		if (ROHud(myHud) != none)
    		{
    			ROHud(myHud).ForceFadeEffect();
    		}
		}

		if( Pawn(ViewTarget) != none && Pawn(ViewTarget).IsA('Vehicle') )
		{
		    bBehindView = true;
		    bValidBehindCamera = false;
		}
    }

    function EndState()
    {
        PlayerReplicationInfo.bIsSpectator = false;
        bCollideWorld = false;

		if (ROHud(myHud) != None)
		{
			ROHud(myHud).StopFadeEffect();
		}


    }
}

//-----------------------------------------------------------------------------
// PlayerWaiting - Don't allow fire to respawn
//-----------------------------------------------------------------------------

auto state PlayerWaiting
{
ignores SeePlayer, HearNoise, NotifyBump, TakeDamage, PhysicsVolumeChange, /*NextWeapon, PrevWeapon,*/ SwitchToBestWeapon;

	//Return to spectator's own camera.
    exec function Jump( optional float F )
    {
		if( ViewTarget != self && CanRequestSpectateChange() )
		{
	    	ServerViewSelf();
    	}
    }

    exec function Suicide()
    {
    }

    function ServerRestartPlayer()
    {
        if ( Level.TimeSeconds < WaitDelay )
            return;
        if ( Level.NetMode == NM_Client )
            return;
        if ( Level.Game.bWaitingToStartMatch )
            PlayerReplicationInfo.bReadyToPlay = true;
        else
            Level.Game.RestartPlayer(self);
    }

    exec function Fire( optional float F )
    {
		if (SpecMode == SPEC_Players)
		{
	 		 if ( CanRequestSpectateChange() )
			 	ServerViewNextPlayer();
		}
	 	else if (SpecMode == SPEC_ViewPoints)
		{
	 		 if ( CanRequestSpectateChange() )
			 	ServerNextViewPoint();
		}
    }

    // Return to spectator's own camera.
    exec function AltFire( optional float F )
    {
    	if ( CanRequestSpectateChange() )
			ServerChangeSpecMode();
    }

	simulated exec function ROIronSights()
	{
		if ( CanRequestSpectateChange() )
		{
			ServerRequestPOVChange();
		}
	}

	function HandlePOVChange()
	{
		if( Role == ROLE_Authority && ViewTarget != self && !ROTeamGame(Level.Game).bSpectateFirstPersonOnly && Pawn(ViewTarget) != none )
		{
			bBehindView = !bBehindView;
			ClientSetBehindView(bBehindView);
		}
	}

	function bool CanRestartPlayer()
    {
    	return Global.CanRestartPlayer();
    }

    function PlayerMove(float DeltaTime)
    {

        local vector X,Y,Z;

        if( SpecMode == SPEC_ViewPoints )
        {
	        if ( ViewTarget != None )
	            SetRotation(ViewTarget.Rotation);
	    }
	    else
	    {
			if ( (Pawn(ViewTarget) != None) && (Level.NetMode == NM_Client) )
			{
				if ( Pawn(ViewTarget).bSimulateGravity )
					TargetViewRotation.Roll = 0;
				BlendedTargetViewRotation.Pitch = BlendRot(DeltaTime, BlendedTargetViewRotation.Pitch, TargetViewRotation.Pitch & 65535);
				BlendedTargetViewRotation.Yaw = BlendRot(DeltaTime, BlendedTargetViewRotation.Yaw, TargetViewRotation.Yaw & 65535);
				BlendedTargetViewRotation.Roll = BlendRot(DeltaTime, BlendedTargetViewRotation.Roll, TargetViewRotation.Roll & 65535);
			}
	        GetAxes(Rotation,X,Y,Z);

	        Acceleration = 0.02 * (aForward*X + aStrafe*Y + aUp*vect(0,0,1));

	        UpdateRotation(DeltaTime, 1);
    	}

        if( SpecMode == SPEC_Self || SpecMode == SPEC_ViewPoints || !bAllowRoamWhileSpectating )
        {
	        if ( Role < ROLE_Authority ) // then save this move and replicate it
	            ReplicateMove(DeltaTime, vect(0,0,0), DCLICK_None, rot(0,0,0));
	        else
	            ProcessMove(DeltaTime, vect(0,0,0), DCLICK_None, rot(0,0,0));
		}
		else
		{
	        if ( Role < ROLE_Authority ) // then save this move and replicate it
	            ReplicateMove(DeltaTime, Acceleration, DCLICK_None, rot(0,0,0));
	        else
	            ProcessMove(DeltaTime, Acceleration, DCLICK_None, rot(0,0,0));
        }
    }

    simulated function Timer()
    {
        if (!bPendingMapDisplay || bDemoOwner)
        {
            SetTimer(0, false);
        }
        else if(Player != None && GUIController(Player.GUIController) != None && !GUIController(Player.GUIController).bActive)
	    {
		    bPendingMapDisplay = false;
		    SetTimer(0, false);
            PlayerMenu();

            // We init the hint manager here because it needs to be
            // initialized after the Player variables has been set
            UpdateHintManagement(bShowHints);
		}
    }

    function EndState()
    {
        bFrozen = false;
		if ( Pawn != None )
            Pawn.SetMesh();
        if ( PlayerReplicationInfo != None )
			PlayerReplicationInfo.SetWaitingPlayer(false);
        bCollideWorld = false;
    }

    // hax to open menu when player joins the game
    simulated function BeginState()
    {
        if (Role == Role_Authority)
        {
    		CameraDist = Default.CameraDist;
            if ( PlayerReplicationInfo != None )
                PlayerReplicationInfo.SetWaitingPlayer(true);
            bCollideWorld = true;
            bFrozen = true;
        }

		if( Level.NetMode != NM_DedicatedServer )
		{
			ResetBlur();
		}

        if (Level.NetMode != NM_DedicatedServer && bPendingMapDisplay)
        {
            SetTimer(0.1, true);
            Timer();
        }
    }
}


//-----------------------------------------------------------------------------
// GameEnded
//-----------------------------------------------------------------------------

state GameEnded
{
ignores SeePlayer, HearNoise, KilledBy, NotifyBump, HitWall, NotifyHeadVolumeChange, NotifyPhysicsVolumeChange, Falling, TakeDamage, Suicide;

	function ServerReStartPlayer()
	{
	}

	function bool IsSpectating()
	{
		return true;
	}

    exec function ThrowWeapon()
    {
    }

    function ServerReStartGame()
    {
        Level.Game.RestartGame();
    }

    exec function Fire( optional float F )
    {
        if ( Role < ROLE_Authority)
            return;
        if ( !bFrozen )
            ServerReStartGame();
        //else if ( TimerRate <= 0 )
         //   SetTimer(1.5, false);
    }

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

    function PlayerMove(float DeltaTime)
    {
        local vector X,Y,Z;
       // local Rotator ViewRotation;

        GetAxes(Rotation,X,Y,Z);
        // Update view rotation.

        /*if ( !bFixedCamera )
        {
            ViewRotation = Rotation;
            ViewRotation.Yaw += 32.0 * DeltaTime * aTurn;
            ViewRotation.Pitch += 32.0 * DeltaTime * aLookUp;
            ViewRotation.Pitch = LimitPitch(ViewRotation.Pitch,DeltaTime); //amb
            SetRotation(ViewRotation);
        }
        else*/ if ( ViewTarget != None )
            SetRotation(ViewTarget.Rotation);

        ViewShake(DeltaTime);
        ViewFlash(DeltaTime);

        if ( Role < ROLE_Authority ) // then save this move and replicate it
            ReplicateMove(DeltaTime, vect(0,0,0), DCLICK_None, rot(0,0,0));
        else
            ProcessMove(DeltaTime, vect(0,0,0), DCLICK_None, rot(0,0,0));
        bPressedJump = false;
    }

	function ServerMove
	(
	    float TimeStamp,
	    vector InAccel,
	    vector ClientLoc,
		byte NewActions,
	    eDoubleClickDir DoubleClickMove,
	    byte ClientRoll,
	    int View,
	    optional int FreeAimRot,
	    optional byte OldTimeDelta,
	    optional int OldAccel
	)
    {
        Global.ServerMove(TimeStamp, InAccel, ClientLoc, NewActions,
                            DoubleClickMove, ClientRoll, (32767 & (Rotation.Pitch/2)) * 32768 + (32767 & (Rotation.Yaw/2)) );
    }

    function FindGoodView()
    {
        /*local vector cameraLoc;
        local rotator cameraRot, ViewRotation;
        local int tries, besttry;
        local float bestdist, newdist;
        local int startYaw;
        local actor ViewActor;

        ViewRotation = Rotation;
        ViewRotation.Pitch = 56000;
        tries = 0;
        besttry = 0;
        bestdist = 0.0;
        startYaw = ViewRotation.Yaw;

        for (tries=0; tries<16; tries++)
        {
            cameraLoc = ViewTarget.Location;
			SetRotation(ViewRotation);
            PlayerCalcView(ViewActor, cameraLoc, cameraRot);
            newdist = VSize(cameraLoc - ViewTarget.Location);
            if (newdist > bestdist)
            {
                bestdist = newdist;
                besttry = tries;
            }
            ViewRotation.Yaw += 4096;
        }

        ViewRotation.Yaw = startYaw + besttry * 4096;
        SetRotation(ViewRotation);*/
    }

    function Timer()
    {
        bFrozen = false;
    }

	/*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 BeginState()
    {
        local Pawn P;

        EndZoom();
        FOVAngle = DesiredFOV;
        bFire = 0;
        bAltFire = 0;
        if ( Pawn != None )
        {
			Pawn.Velocity = vect(0,0,0);
			Pawn.SetPhysics(PHYS_None);
			Pawn.AmbientSound = None;
			Pawn.bSpecialHUD = false;
 			Pawn.bNoWeaponFiring = true;
            Pawn.SimAnim.AnimRate = 0;
            Pawn.bPhysicsAnimUpdate = false;
            Pawn.bIsIdle = true;
            Pawn.bWaitForAnim = false;
            Pawn.StopAnimating();
            Pawn.SetCollision(true,false,false);
            if ( Pawn.Weapon != None )
            {
				Pawn.Weapon.StopFire(0);
				Pawn.Weapon.StopFire(1);
				Pawn.Weapon.ClientState = WS_Hidden;
			}
 			Pawn.bIgnoreForces = true;
       }
        bFrozen = true;
        /*if ( !bFixedCamera )
        {
            FindGoodView();
            bBehindView = true;
        }*/
        SetTimer(5, false);
        foreach DynamicActors(class'Pawn', P)
        {
			if ( P.Role == ROLE_Authority )
				P.RemoteRole = ROLE_DumbProxy;
			P.SetCollision(true,false,false);
			P.AmbientSound = None;
 			P.bNoWeaponFiring = true;
            P.Velocity = vect(0,0,0);
            P.SetPhysics(PHYS_None);
            P.bPhysicsAnimUpdate = false;
            P.bIsIdle = true;
            P.bWaitForAnim = false;
            P.StopAnimating();
            P.bIgnoreForces = true;
        }
    }

Begin:
    if ( myHUD != None )
	    myHUD.bShowScoreBoard = true;
}

//-----------------------------------------------------------------------------
// PlayerTurreting - Overriden to allow yaw limitation
//-----------------------------------------------------------------------------

state PlayerTurreting
{
ignores SeePlayer, HearNoise, Bump;

	function CallServerMove
	(
	    float TimeStamp,
	    vector InAccel,
	    vector ClientLoc,
	    bool NewbRun,
	    bool NewbDuck,
	    bool NewbPendingJumpStatus,
	    bool NewbJumpStatus,
	    bool NewbSprint,
		bool NewbCrawl,
	    eDoubleClickDir DoubleClickMove,
	    byte ClientRoll,
	    int View,
	    optional int FreeAimRot,
	    optional byte OldTimeDelta,
	    optional int OldAccel
	)
	{

		if ( PendingMove != None )
		{
			DualTurretServerMove
			(
				PendingMove.TimeStamp,
				PendingMove.bDuck,
		        ((PendingMove.Rotation.Roll >> 8) & 255),
				(32767 & (PendingMove.Rotation.Pitch/2)) * 32768 + (32767 & (PendingMove.Rotation.Yaw/2)),
				TimeStamp,
				ClientLoc,
				NewbDuck,
				ClientRoll,
				View,
				FreeAimRot
			);
		}
		else
			TurretServerMove
			(
				TimeStamp,
				ClientLoc,
				NewbDuck,
				ClientRoll,
				View,
				FreeAimRot
			);
	}

	/* ServerMove()
	- replicated function sent by client to server - contains client movement and firing info
	Passes acceleration in components so it doesn't get rounded.
	IGNORE VANILLA SERVER MOVES
	*/
	function ServerMove
	(
	    float TimeStamp,
	    vector InAccel,
	    vector ClientLoc,
		byte NewActions,
	    eDoubleClickDir DoubleClickMove,
	    byte ClientRoll,
	    int View,
	    optional int FreeAimRot,
	    optional byte OldTimeDelta,
	    optional int OldAccel
	)
	{
		// If this move is outdated, discard it.
		if ( CurrentTimeStamp >= TimeStamp )
			return;

		if ( AcknowledgedPawn != Pawn )
		{
			OldTimeDelta = 0;
			InAccel = vect(0,0,0);
		}

		if ( AcknowledgedPawn == Pawn && CurrentTimeStamp < TimeStamp )
	       Pawn.AutonomousPhysics(TimeStamp - CurrentTimeStamp);
		CurrentTimeStamp = TimeStamp;
		ServerTimeStamp = Level.TimeSeconds;
	}

	function TurretServerMove
	(
		float	TimeStamp,
		vector	ClientLoc,
		bool	NewbDuck,
		byte	ClientRoll,
		int		View,
		optional int FreeAimRot
	)
	{
		local byte NewActions;
		local int FreeAimPitch, FreeAimYaw;
		local rotator NewFreeAimRot;

		if( Pawn != none )
		{
		    // Free-aim vars
		    FreeAimPitch = FreeAimRot/32768;
			FreeAimYaw = 2 * (FreeAimRot - 32768 * FreeAimPitch);
			FreeAimPitch *= 2;

			NewFreeAimRot.Pitch  = FreeAimPitch;
			NewFreeAimRot.Yaw  = FreeAimYaw;

	        if( Pawn.IsA('VehicleWeaponPawn'))
	        {
	            VehicleWeaponPawn(Pawn).CustomAim = NewFreeAimRot;
	        }
		}

		// Put together new actions to send (compressed into one byte)
		if (NewbDuck)
			NewActions += 2;

		Global.ServerMove(TimeStamp,Vect(0,0,0),ClientLoc,NewActions, DCLICK_NONE,ClientRoll,View,FreeAimRot);
	}

	/* DualTurretServerMove()
	compressed version of server move for PlayerTurreting state
	*/
	function DualTurretServerMove
	(
		float	TimeStamp0,
		bool	NewbDuck0,
		byte	ClientRoll0,
		int		View0,
		float	TimeStamp,
		vector	ClientLoc,
		bool	NewbDuck,
		byte	ClientRoll,
		int		View,
		optional int FreeAimRot
	)
	{
		local byte NewActions, NewActions0;
		local int FreeAimPitch, FreeAimYaw;
		local rotator NewFreeAimRot;

		if( Pawn != none )
		{
		    // Free-aim vars
		    FreeAimPitch = FreeAimRot/32768;
			FreeAimYaw = 2 * (FreeAimRot - 32768 * FreeAimPitch);
			FreeAimPitch *= 2;

			NewFreeAimRot.Pitch  = FreeAimPitch;
			NewFreeAimRot.Yaw  = FreeAimYaw;

	        if( Pawn.IsA('VehicleWeaponPawn'))
	        {
	            VehicleWeaponPawn(Pawn).CustomAim = NewFreeAimRot;
	        }
		}

		// Put together new actions to send (compressed into one byte)
		if (NewbDuck)
			NewActions += 2;

		if (NewbDuck0)
			NewActions0 += 2;

		Global.ServerMove(TimeStamp0,Vect(0,0,0),vect(0,0,0),NewActions0, DCLICK_NONE,ClientRoll0,View0,FreeAimRot);
		Global.ServerMove(TimeStamp,Vect(0,0,0),ClientLoc,NewActions, DCLICK_NONE,ClientRoll,View,FreeAimRot);
	}

	exec function Fire( optional float F )
	{
	    if (bHudCapturesMouseInputs)
	        HandleMouseClick();
	    else
	        super.Fire(F);
	}

    function PlayerMove(float DeltaTime)
    {
        local Vehicle CurrentVehicle;
        local rotator TempRot;
        local ROVehicleWeapon VehWep;

		if ( Pawn == None )
		{
			GotoState('dead');
			return;
		}

		if (bHudCapturesMouseInputs)
            HandleMousePlayerMove(DeltaTime);

		Pawn.UpdateRocketAcceleration(DeltaTime, aTurn, aLookUp);
		Pawn.HandleTurretRotation(DeltaTime, aStrafe, aForward);
		// RO - We don't allow freecamera suckaz.
		// This bit here is for limiting MG/Turret rotation
		if ( !bFreeCamera )
		{
			TempRot =  Pawn.Rotation;

	        if( Pawn.IsA('VehicleWeaponPawn'))
	        {
	            VehWep = ROVehicleWeapon(VehicleWeaponPawn(Pawn).Gun);

	            if ( VehWep !=none )
	            {
	                TempRot.Yaw = VehWep.LimitYaw(TempRot.Yaw);
	                Pawn.SetRotation( TempRot );
	            }
	        }
			SetRotation( TempRot );
		}

		ViewShake( deltaTime );
        ViewFlash( deltaTime );

        if ( Role < ROLE_Authority ) // then save this move and replicate it
            ReplicateMove(DeltaTime, Pawn.Acceleration, DCLICK_None, rot(0,0,0));
        else
            ProcessMove(DeltaTime, Pawn.Acceleration, DCLICK_None, rot(0,0,0));

		CurrentVehicle = Vehicle(Pawn);
		if ( CurrentVehicle != None )
		{
			if ( bFire == 0 && CurrentVehicle.bWeaponIsFiring )
				CurrentVehicle.ClientVehicleCeaseFire( false );

			if ( bAltFire == 0 && CurrentVehicle.bWeaponIsAltFiring )
				CurrentVehicle.ClientVehicleCeaseFire( true );
		}
    }

	function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
    {
		if ( Pawn == None )
			return;

		Pawn.Acceleration = newAccel;
	}

    function BeginState()
    {
		if ( Pawn != None )
		{
			Pawn.SetPhysics( PHYS_Flying );
		}

		RotationRate.Pitch	= 16384; // extending pitch limit (limits network weapon aiming)

		// Check for hint
		CheckForHint(3);
    }

    function EndState()
    {
		RotationRate.Pitch = default.RotationRate.Pitch; // restoring pitch limit
	}

Begin:
}

//-----------------------------------------------------------------------------
// PlayerPlayerDriving - Overriden to allow throttle limitation
//-----------------------------------------------------------------------------
state PlayerDriving
{
ignores SeePlayer, HearNoise, Bump;

    function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
    {
    }
	// Set the throttle, steering etc. for the vehicle based on the input provided
	function ProcessDrive(float InForward, float InStrafe, float InUp, bool InJump)
	{
		local Vehicle CurrentVehicle;
		local ROVehicle ROVeh;
		local ROTreadCraft ROTank;

	    CurrentVehicle = Vehicle(Pawn);
	    ROVeh = ROVehicle(Pawn);
	    ROTank = ROTreadCraft(Pawn);

        if(CurrentVehicle == None)
            return;

        // Prevent the vehicles from moving without a crew/or if they haven't waited long enough
        if (ROVeh != none && ROVeh.bDisableThrottle)
        {
           	if(ROTreadCraft(CurrentVehicle) != none)
           	{
		   		if( (FClamp( InForward/5000.0, -1.0, 1.0 )) > 0)
					ROTreadCraft(CurrentVehicle).bWantsToThrottle = true;//IntendedThrottle = FClamp( InForward/5000.0, -1.0, 1.0 );
				else
					ROTreadCraft(CurrentVehicle).bWantsToThrottle = false;//.IntendedThrottle = 0;
			}

		   return;
        }

		//log("ProcessDrive Forward:"@InForward@" Strafe:"@InStrafe@" Up:"@InUp);

		CurrentVehicle.Throttle = FClamp( InForward/5000.0, -1.0, 1.0 );
		CurrentVehicle.Steering = FClamp( -InStrafe/5000.0, -1.0, 1.0 );
		CurrentVehicle.Rise = FClamp( InUp/5000.0, -1.0, 1.0 );
	}

	exec function Fire( optional float F )
	{
	    if (bHudCapturesMouseInputs)
	        HandleMouseClick();
	    else
	        super.Fire(F);
	}

    function PlayerMove( float DeltaTime )
    {
		local Vehicle CurrentVehicle;
		local float NewPing;
		local ROTreadCraft ROTank;
		local float AppliedThrottle;

		CurrentVehicle = Vehicle(Pawn);
		ROTank = ROTreadCraft(Pawn);

		if (bHudCapturesMouseInputs)
            HandleMousePlayerMove(DeltaTime);

		// update 'looking' rotation
        UpdateRotation(DeltaTime, 2);

        // TODO: Don't send things like aForward and aStrafe for gunners who don't need it
		// Only servers can actually do the driving logic.
        if (Role < ROLE_Authority )
        {
			if ( (Level.TimeSeconds - LastPingUpdate > 4) && (PlayerReplicationInfo != None) && !bDemoOwner )
			{
				LastPingUpdate = Level.TimeSeconds;
				NewPing = float(ConsoleCommand("GETPING"));
				if ( ExactPing < 0.006 )
					ExactPing = FMin(0.1,0.001 * NewPing);
				else
					ExactPing = 0.99 * ExactPing + 0.0001 * NewPing;
				PlayerReplicationInfo.Ping = Min(250.0 * ExactPing, 255);
				PlayerReplicationInfo.bReceivedPing = true;
				OldPing = ExactPing;
				ServerUpdatePing(1000 * ExactPing);
			}
            if (!bSkippedLastUpdate &&                              // in order to skip this update we must not have skipped the last one
                (Player.CurrentNetSpeed < 10000) &&                 // and netspeed must be low
                (Level.TimeSeconds - ClientUpdateTime < 0.0222) &&  // and time since last update must be short
                bPressedJump == bLastPressedJump &&                 // and update must not contain major changes
                aUp - aLastUp < 0.01 &&                             // "
                aForward - aLastForward < 0.01 &&                   // "
                aStrafe - aLastStrafe < 0.01                        // "
               )
            {
//                log("!bSkippedLastUpdate: "$!bSkippedLastUpdate);
//                log("(Player.CurrentNetSpeed < 10000): "$(Player.CurrentNetSpeed < 10000));
//                log("(Level.TimeSeconds - ClientUpdateTime < 0.0222): "$(Level.TimeSeconds - ClientUpdateTime < 0.0222)$"  - "$Level.TimeSeconds - ClientUpdateTime);
//                log("bPressedJump == bLastPressedJump: "$bPressedJump == bLastPressedJump);
//                log("aUp - aLastUp < 0.01: "$aUp - aLastUp < 0.01);
//                log("aForward - aLastForward < 0.01: "$aForward - aLastForward < 0.01);
//                log("aStrafe - aLastStrafe < 0.01: "$aStrafe - aLastStrafe < 0.01);

                bSkippedLastUpdate = True;
                return;
            }
            else
            {
                bSkippedLastUpdate = False;
                ClientUpdateTime = Level.TimeSeconds;

                // Save Move
                bLastPressedJump = bPressedJump;
                aLastUp = aUp;
                aLastForward = aForward;
                aLastStrafe = aStrafe;

                //log("PlayerMove Forward:"@aForward@" Strafe:"@aStrafe@" Up:"@aUp);

	    		if( CurrentVehicle != none && (bInterpolatedVehicleThrottle || (ROTank != none && bInterpolatedTankThrottle)))
	            {
					if( aForward > 0 )
					{
						CurrentVehicle.ThrottleAmount += DeltaTime * ThrottleChangeRate;
					}
					else if ( aForward < 0 )
					{
						CurrentVehicle.ThrottleAmount -= DeltaTime * ThrottleChangeRate;
					}

					CurrentVehicle.ThrottleAmount = FClamp( CurrentVehicle.ThrottleAmount, -6000.0, 6000.0 );

	                AppliedThrottle = CurrentVehicle.ThrottleAmount;

					// Stop if the throttle is below this amount
					if( Abs(AppliedThrottle) < 500 )
					{
						AppliedThrottle = 0;
					}

					// Brakes are on, so zero the throttle
					if( aUp > 0 )
					{
					 	AppliedThrottle = 0;
					 	CurrentVehicle.ThrottleAmount = 0;
					}

                    CurrentVehicle.Throttle = FClamp( AppliedThrottle/5000.0, -1.0, 1.0 );
                    CurrentVehicle.Steering = FClamp( -aStrafe/5000.0, -1.0, 1.0 );
                    CurrentVehicle.Rise = FClamp( aUp/5000.0, -1.0, 1.0 );

	                ServerDrive(AppliedThrottle, aStrafe, aUp, bPressedJump, (32767 & (Rotation.Pitch/2)) * 32768 + (32767 & (Rotation.Yaw/2)));
				}
				else
				{
	                if (CurrentVehicle != None)
	                {
	                    CurrentVehicle.Throttle = FClamp( aForward/5000.0, -1.0, 1.0 );
	                    CurrentVehicle.Steering = FClamp( -aStrafe/5000.0, -1.0, 1.0 );
	                    CurrentVehicle.Rise = FClamp( aUp/5000.0, -1.0, 1.0 );
	                }

	                ServerDrive(aForward, aStrafe, aUp, bPressedJump, (32767 & (Rotation.Pitch/2)) * 32768 + (32767 & (Rotation.Yaw/2)));
				}
            }
        }
		else
		{
    		if(CurrentVehicle != none && (bInterpolatedVehicleThrottle || (ROTank != none && bInterpolatedTankThrottle)))
            {
				if( aForward > 0 )
				{
					CurrentVehicle.ThrottleAmount += DeltaTime * ThrottleChangeRate;
				}
				else if ( aForward < 0 )
				{
					CurrentVehicle.ThrottleAmount -= DeltaTime * ThrottleChangeRate;
				}

				CurrentVehicle.ThrottleAmount = FClamp( CurrentVehicle.ThrottleAmount, -6000.0, 6000.0 );

                AppliedThrottle = CurrentVehicle.ThrottleAmount;

				// Stop if the throttle is below this amount
				if( Abs(AppliedThrottle) < 500 )
				{
					AppliedThrottle = 0;
				}

				// Brakes are on, so zero the throttle
				if( aUp > 0 )
				{
				 	AppliedThrottle = 0;
				 	CurrentVehicle.ThrottleAmount = 0;
				}

				ProcessDrive(AppliedThrottle, aStrafe, aUp, bPressedJump);
			}
			else
			{
				ProcessDrive(aForward, aStrafe, aUp, bPressedJump);
			}
		}

		// If the vehicle is being controlled here - set replicated variables.
		if (CurrentVehicle != None)
		{
			if(bFire == 0 && CurrentVehicle.bWeaponIsFiring)
				CurrentVehicle.ClientVehicleCeaseFire(False);

			if(bAltFire == 0 && CurrentVehicle.bWeaponIsAltFiring)
				CurrentVehicle.ClientVehicleCeaseFire(True);
		}
    }

	function BeginState()
	{
		PlayerReplicationInfo.bReceivedPing = false;
		CleanOutSavedMoves();

		// Check for hint
		CheckForHint(3);
	}

	function EndState()
	{
		CleanOutSavedMoves();
	}
}

//=============================================================================
// Lean functions
//=============================================================================

exec function LeanRight()
{
	if( Pawn != none && ROPawn(Pawn) != none && !Pawn.bBipodDeployed)
		ROPawn(pawn).LeanRight();
	ServerLeanRight(true);
}

exec function LeanRightReleased()
{
	if( Pawn != none && ROPawn(Pawn) != none )
	{
		ROPawn(pawn).LeanRightReleased();
		ServerLeanRight(false);
	}
}

function ServerLeanRight(bool leanstate)
{
	if( Pawn != none )
	{
 		if( ROPawn(Pawn) != none )
		{
			if (leanstate)
			{
				if( !Pawn.bBipodDeployed )
					ROPawn(pawn).LeanRight();
			}
			else
				ROPawn(pawn).LeanRightReleased();
		}
		else if ( leanstate && VehicleWeaponPawn(Pawn) != none )
		{
			VehicleWeaponPawn(Pawn).IncrementRange();
		}
	}
}

exec function LeanLeft()
{
	if( Pawn != none && ROPawn(Pawn) != none && !Pawn.bBipodDeployed)
		ROPawn(pawn).LeanLeft();
	ServerLeanLeft(true);
}

exec function LeanLeftReleased()
{
	if( Pawn != none && ROPawn(Pawn) != none )
	{
		ROPawn(pawn).LeanLeftReleased();
		ServerLeanLeft(false);
	}
}

function ServerLeanLeft(bool leanstate)
{
	if( Pawn != none )
	{
 		if( ROPawn(Pawn) != none )
		{
			if (leanstate)
			{
				if( !Pawn.bBipodDeployed )
					ROPawn(pawn).LeanLeft();
			}
			else
				ROPawn(pawn).LeanLeftReleased();
		}
		else if ( leanstate && VehicleWeaponPawn(Pawn) != none )
		{
			VehicleWeaponPawn(Pawn).DecrementRange();
		}
	}
}

simulated function NotifyOfMapInfoChange()
{
    if (ROHud(myHUD) != none)
        ROHud(myHUD).ShowMapUpdatedIcon();

    // Check for hint
    CheckForHint(15);
}

// most of this code comes from UDN:
// https://udn.epicgames.com/Two/MouseCursorInterface
simulated function HandleMousePlayerMove(float DeltaTime)
{
    local vector MouseV;

    // calc mouse position offset
    MouseV.X = DeltaTime * aMouseX / (InputClass.default.MouseSensitivity * DesiredFOV * 0.01111);
    MouseV.Y = DeltaTime * aMouseY / (InputClass.default.MouseSensitivity * DesiredFOV * -0.01111);

    // update mouse position
    PlayerMouse += MouseV;

    // notify hud of new mouse position
    ROHud(myHUD).MouseInterfaceUpdatePosition(PlayerMouse);
}

simulated function HandleMouseClick()
{
    ROHud(myHUD).MouseInterfaceClick();
}

simulated function MouseInterfaceSetMousePos(vector newPos)
{
    PlayerMouse = newPos;
}

simulated function MouseInterfaceSetRotationLock(bool bLocked)
{
    bHudLocksPlayerRotation = bLocked;
}

// omg hax
// same as function in PlayerController, but doesn't pick a team automatically
// when switching from spectator to active player.
function BecomeActivePlayer()
{
	if (Role < ROLE_Authority)
		return;

	if ( !Level.Game.AllowBecomeActivePlayer(self) )
		return;

	bBehindView = false;
	SetViewDistance();
	FixFOV();
	ServerViewSelf();
	PlayerReplicationInfo.bOnlySpectator = false;
	PlayerReplicationInfo.bOutOfLives = false;
	Level.Game.NumSpectators--;
	Level.Game.NumPlayers++;
	PlayerReplicationInfo.Reset();
	Adrenaline = 0;
	BroadcastLocalizedMessage(Level.Game.GameMessageClass, 1, PlayerReplicationInfo);
	//if (Level.Game.bTeamGame)
	//	Level.Game.ChangeTeam(self, Level.Game.PickTeam(int(GetURLOption("Team")), None), false);
	if (!Level.Game.bDelayedStart)
    {
		// start match, or let player enter, immediately
		Level.Game.bRestartLevel = false;  // let player spawn once in levels that must be restarted after every death
		if (Level.Game.bWaitingToStartMatch)
			Level.Game.StartMatch();
		else
			Level.Game.RestartPlayer(PlayerController(Owner));
		Level.Game.bRestartLevel = Level.Game.Default.bRestartLevel;
    }
    else
        GotoState('PlayerWaiting');

    ClientBecameActivePlayer();
}

function Reset()
{
    super.Reset();

    // Reset the artillery coords when the round resets
	SavedArtilleryCoords = vect(0,0,0);
}

// Hint management functions
simulated function NotifyHintRenderingDone()
{
    if (HintManager != none)
        HintManager.NotifyHintRenderingDone();
}

simulated function UpdateHintManagement(bool bUseHints)
{
    if (Level.GetLocalPlayerController() == self)
    {
        if (bUseHints && HintManager == none)
        {
            HintManager = spawn(class'ROHintManager', self);
            if (HintManager == none)
                warn("Unable to spawn hint manager");
        }
        else if (!bUseHints && HintManager != none)
        {
            HintManager.Destroy();
            HintManager = none;
        }

        if (!bUseHints)
            if (ROHud(myHUD) != none)
                ROHud(myHUD).bDrawHint = false;
    }
}

simulated function CheckForHint(int hintType)
{
    if (HintManager != none)
        HintManager.CheckForHint(hintType);
}

// For debug
exec function DumpHints()
{
    if (HintManager != none)
        HintManager.DumpHints();
    else
        log("No HintManager present in ROPlayer. Are hints enabled?");
}

exec function Jump( optional float F )
{
    super.jump(f);
    CheckForHint(1);
}

exec function xSpeech(name Type, int Index, PlayerReplicationInfo SquadLeader)
{
    xServerSpeech(Type, Index, SquadLeader);
}

function xServerSpeech(name Type, int Index, PlayerReplicationInfo SquadLeader)
{
	if (PlayerReplicationInfo.VoiceType != None)
		PlayerReplicationInfo.VoiceType.static.xPlayerSpeech(Type, Index, SquadLeader, self);
}

function int ServerAutoSelectAndChangeTeam()
{
    local int tempTeam;

    tempTeam = Level.Game.PickTeam(rand(2), self);
    ServerChangeTeam(tempTeam);

    return tempTeam;
}

function ServerSetManualTankShellReloading(bool bUseManualReloading)
{
    //If the cannon is waiting to reload, force a reload on the client
    if( bUseManualReloading == false && Pawn != none && VehicleWeaponPawn(Pawn) != none &&
        VehicleWeaponPawn(Pawn).Gun != none && ROTankCannon(VehicleWeaponPawn(Pawn).Gun) != none &&
        ROTankCannon(VehicleWeaponPawn(Pawn).Gun).CannonReloadState == CR_Waiting)
    {
        ROTankCannon(VehicleWeaponPawn(Pawn).Gun).ServerManualReload();
    }

    bManualTankShellReloading = bUseManualReloading;
}

simulated function SetManualTankShellReloading(bool bUseManualReloading)
{
    bManualTankShellReloading = bUseManualReloading;

    //Replicate the new setting to the server
    ServerSetManualTankShellReloading(bManualTankShellReloading);
}

//=============================================================================
// defaultproperties
//=============================================================================

defaultproperties
{
     DesiredRole=-1
     CurrentRole=-1
     PrimaryWeapon=-1
     SecondaryWeapon=-1
     GrenadeWeapon=-1
     bCanRespawn=True
     bPendingMapDisplay=True
     bFirstRoleAndTeamChange=True
     bShowMapOnFirstSpawn=True
     FadeFromBlackFadeSpeed=0.150000
     SpectatingModeName(0)="Viewing Self"
     SpectatingModeName(1)="Roaming"
     SpectatingModeName(2)="Viewing Players"
     SpectatingModeName(3)="Spectating Viewpoints"
     FreeAimMaxYawLimit=2000
     FreeAimMinYawLimit=63535
     FreeAimMaxPitchLimit=1500
     FreeAimMinPitchLimit=64035
     FAAWeaponRotationFactor=8.000000
     YawTweenRate=8000
     PitchTweenRate=6000
     bSway=True
     baseSwayYawAcc=100.000000
     baseSwayPitchAcc=200.000000
     SwayCurve=(Points=(,(InVal=0.750000,OutVal=0.100000),(InVal=1.500000,OutVal=0.250000),(InVal=3.000000,OutVal=0.500000),(InVal=10.000000,OutVal=1.000000),(InVal=1000000000.000000,OutVal=1.000000)))
     ROMidGameMenuClass="ROInterface.ROGUIRoleSelection"
     GlobalDetailLevel=-1
     ForcedTeamSelectOnRoleSelectPage=-5
     bUseBlurEffect=True
     MaxAltBlurLevel=215
     bShowHints=True
     ThrottleChangeRate=2200.000000
     bInterpolatedTankThrottle=True
     JarrMoveMag=40.000000
     JarrMoveRate=200.000000
     JarrMoveDuration=3.000000
     JarrRotateMag=2000.000000
     JarrRotateRate=10000.000000
     JarrRotateDuration=4.000000
     AutoJoinMask=7
     VehicleCheckRadius=350.000000
     DesiredFOV=85.000000
     DefaultFOV=85.000000
     InputClass=Class'ROEngine.ROPlayerInput'
     PlayerReplicationInfoClass=Class'ROEngine.ROPlayerReplicationInfo'
     PawnClass=Class'ROEngine.ROPawn'
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Fri 13-10-2023 03:17:28.000 - Creation time: Fri 13-10-2023 03:19:07.324 - Created with UnCodeX