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

Gameplay.Character


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
class Character extends Ragdoll implements IVisionNotification
	native;

// --------------- movement system ----------------

// READ ONLY

var const float movementSpeed;		            // speed in kph
var const float movementVerticalSpeed;		    // vertical speed in kph
var const float movementHorizontalSpeed;	    // horizontal speed in kph
var const float movementTangentialSpeed;	    // tangential speed in kph
var const float movementDirectionalSpeed;	    // directional speed in kph

var const float movementAltitude;               // altitude in meters

var const bool movementCollided;                // true if collided last immediate update
var const bool movementClose;                   // true if close to a surface last update
var const bool movementTouching;                // true if recently collided
var const bool movementGrounded;                // true if touching a walkable slope
var const bool movementAirborne;                // true if not touching and not in water
var const bool movementWater;                   // true if in any part of character is touching water
var const bool movementUnderWater;              // true if character is entirely submerged in water
var const bool movementZeroGravity;             // true if character is in a zero gravity volume
var const bool movementElevator;                // true if character is in an elevator volume

var const bool movementResting;                 // true if currently resting
var const bool movementDynamic;                 // true if touching a dynamic object (cannot come to rest)
var const bool movementPushing; 		        // true if touching a pushable object (not allowed to apply smoothing)

var const Vector movementNormal;                // best floor normal last update relative to (0,0,1)

var const float movementWaterPenetration;       // water penetration [0,1]

var const float movementSplashChaos;            // splash chaos [0,1]
var const float movementImpulseChaos;           // impulse chaos [0,1]

var const float movementSphereRadius;           // radius of character's bounding sphere
var const float movementSphyllRadius;           // radius of the character's sphyll caps
var const float movementSphyllHalfHeight;       // half the height of the character's sphyll cylinder component

var const int movementGroundState;              // ground movement state (GroundMovement_Standing/Walking/Running/Sprinting/Any)

var const int movementCollisionMaterial;        // most recent movement collision material

var const bool movementThrusting;               // true if thrusting last update
var const bool movementOldThrusting;            // true if thrusting before last update

var const Vector movementDisplacement;          // change in position last movement update
var const float movementDisplacementRate;       // change in position rate last movement update
var const Vector movementStrafe;                // unit length strafe vector (zero if no strafe)

var const Vector movementOldVelocity;           // movement velocity for previous update (current is in "Velocity")

var const bool movementSkiInput;                // ski input state for previous update (true if enabled, false if not)

// READ/WRITE DATA

var (Movement) float movementKnockbackScale;            // scales knockback applied to characters from weapons only. defaults to 1. overridden by armor if wearing any.
var (Movement) float movementExtraMass;                 // extra mass passed into movement physics so you can simulate carrying heavy objects
var (Movement) bool movementFrozen;                     // if this is set to true, movement is frozen and the guy wont respond to knockback or be able to move at all

var float lastMovementDamageTime;                       // last time a movement damage event occured (used to filter damage effects occuring too closely together)
var float lastMovementCollisionTime;                    // last time a movement collision event occured (used to filter collision effects occuring too closely together)

var bool blockMovementDamage;                           // if this is set to true, movement damage is blocked for the next tick

// SIM PROXY DATA

var Material collisionMaterialObject;                   // most recent movement collision material object (for effect system)

enum MovementDirectionalInput
{
    MovementInput_Zero,
    MovementInput_Positive,
    MovementInput_Negative,
};

var const byte movementSimProxyPitch;                   // filled in native code from compressed position rotator

var const MovementDirectionalInput movementSimProxyInputX;
var const MovementDirectionalInput movementSimProxyInputY;
var const bool movementSimProxyInputThrust;
var const bool movementSimProxyInputJump;
var const bool movementSimProxyInputSki;

// -------------- animation system ----------------

enum AnimationStateEnum
{
    AnimationState_None,
	AnimationState_Stand,
	AnimationState_Walk,
	AnimationState_Run,
	AnimationState_Sprint,
	AnimationState_Ski,
	AnimationState_Slide,
	AnimationState_Stop,
	AnimationState_Airborne,
	AnimationState_AirControl,
	AnimationState_Thrust,
	AnimationState_Swim,
	AnimationState_Count,
};

var (Animation) float walkAnimationSpeed;           // walk animation speed in unreal units per second
var (Animation) float runAnimationSpeed;            // run animation speed in unreal units per second
var (Animation) float sprintAnimationSpeed;         // sprint animation speed in unreal units per second

var (Animation) Name neutralAimAnimationRootBone;   // root bone name for aiming animations in neutral pose
var (Animation) Name alertAimAnimationRootBone;     // root bone name for aiming animations in alert pose
var (Animation) Name combatAimAnimationRootBone;    // root bone name for aiming animations in combat pose
var (Animation) Name upperBodyAnimationRootBone;    // root bone name for upper body animations
var (Animation) Name armAnimationRootBone;          // root bone name for arm animations

var transient AnimationManager animationManager;              // animation manager performs the animation update method
var transient array<AnimationState> animationStates;          // each animation state corresponds to a movement state
var transient array<AnimationChannel> animationChannels;      // each animation channel corresponds to an AnimationChannel enum value
var transient AnimationLayer primaryAnimationLayer;           // primary animation layer
var transient AnimationLayer secondaryAnimationLayer;         // secondary animation layer

var transient AnimationSpring animationHeightSpring;          // height animation spring (for airborne up/down)
var transient AnimationSpring animationVelocitySpring;        // velocity animation spring (for ski up/down)

var private bool m_bManualAnimation;
var private bool m_bOldManualAnimation;

import enum AnimationChannelIndex from AnimationChannel;

// ------------------------------------------------

var (Damage) float vehicleTeamCrushingDamageModifier;         // multiplies the amount of crushing damage taken by a vehicle belonging to the same team

const DAMAGE_LARGE = 50.0f;		// how much damage constitutes

enum HitPosition
{
	HP_IGNORE,
	HP_HEAD,
	HP_FRONT,
	HP_BACK
};

// Speech Manager requires this characters VoiceSet
var(Speech)	String VoiceSetPackageName		    "Package name of the voice set for this character";
var(Speech) String CharacterNameLocalisationTag	"Localise tag for the character name";
var(Speech) String CharacterName				"Actual Character name used in speech subtitles";

// player name - caches TRI player name because the TRI may be set to None when player does certain things such as driving a vehicle
var String playerNameMP;

var() float packDrawScale;

var() Material invicibilityMaterial;

// effects system

var EPhysics previousPhysics;                       // previous physics mode (used to stop movement effects when you leave PHYS_Movement)


enum SkiCompetencyLevels
{
	SC_Default,				// use character's competency
	SC_None,
	SC_LevelNovice,
	SC_LevelMedium,
	SC_LevelExpert
};

enum JetCompetencyLevels
{
	JC_Default,				// use character's competency
	JC_None,
	JC_LevelNovice,
	JC_LevelMedium,
	JC_LevelExpert
};

enum GroundMovementLevels
{
    GM_Any,
	GM_Sprint,
	GM_Run,
	GM_Walk,
	GM_None
};

// hack to allow me to compare these enums to a int/float (which Unreal doesn't allow)
const GM_Any_Int = 0;
const GM_Sprint_Int = 1;
const GM_Run_Int = 2;
const GM_Walk_Int = 3;

var bool	bTempInvincible;
var bool	bLocalTempInvincible;

// this character is an occupant of a vehicle that cannot be seen - this is a special case as they collide with actors for the sake of triggers
// but should be invisible to everything else and thus not take damage
var bool	bHiddenVehicleOccupant;

// Replication Info
var TribesReplicationInfo tribesReplicationInfo;

// Motor
var CharacterMotor motor;

var Weapon	weapon;
var Name	weaponBone;

var bool weaponPlayingArmAnimation;         // true if playing an arm animation for weapon hold. eg. buckler
var float weaponNotHeldTime;                // amount of time in seconds since a weapon has been held (eg. seconds since weapon!=none)

var Weapon altWeapon;				// Grenades

var Weapon fallbackWeapon;

const NUM_WEAPON_SLOTS = 3;
var Weapon weaponSlots[NUM_WEAPON_SLOTS];

var Name            eyeBoneName;	// Where we "See" from
var const int       eyeBoneIndex;
var const vector	eyeBoneOffset;	// cached value for AI vision system

var Controller		lastPossessor; // the last controller to possess this pawn

var float			HeadHeight "The height above the pivot at which the character head starts";

// god mode
var bool	bGodMode;

// Loadout
var() editinlineuse class<Loadout>	loadoutClass	"What is this character's equipment loadout? (Singleplayer use, use class browser to select a class without inheriting)";
var() class<Armor>					armorClass		"What is this character's armor class?";

var Loadout loadout;

var() bool bDisallowEquipmentDropOnDeath;

// Equipment linked list
var private Equipment m_equipmentHead;
var Equipment potentialEquipment; // Used for prompting the player to pickup a piece of equipment, and picking it up if they want to

// MP objects
var() bool bDontAllowCarryablePickups				"If true, this character won't be able to pickup any carryables";
var() bool bDontInteractWithTerritories				"If true, this character won't interact with territories at all";
var MPCarryable carryableReference;					// An instance of the carryables being carried
var array<MPCarryable> carryables;					// Stores all carryables being carried
var int numCarryables;								// Used to replicate the length of the carryables array
var MPCarryableThrower pseudoWeapon;				// Used for throwing carryables
var int numPermanentCarryables;						// The player keeps this number of carryables at all times, except on death (i.e.
													// this number of carryables can't be thrown)
var int lastCarryableNumber;						// Used to restrict broadcast messages

// Zooming
var() bool bCanZoom;
var private bool bZoomed;

// Misc UI
var() bool bDontAllowCommandScreen					"If true, this character won't be able to use the command screen";

// Jetpacking and skiing competency
var(AI) JetCompetencyLevels jetCompetency "How well can this character jetpack";
var(AI) SkiCompetencyLevels skiCompetency "How well can this character ski";
var(AI) bool bApplyHealthFilter "If false, the health filter for the chosen difficulty level is not applied.";

var class<CombatRole> combatRole;
var class<CombatRole> localCombatRole;

var name needToPlayArmAnim; // Used to resync arms with weapons if an animation plays while the character has no arms

var() bool bDisableSkiing;

var() bool bDisableJetting;
var name jetpackBone;
var private Jetpack jetpack;

var Arms arms;

// functionality used by packs
var bool regenerationActive;
var int regenerationRateHealthPerSecond;

var bool shieldActive;
var float shieldFractionDamageBlocked;

var Pack pack;

var class<Pack> heldPackClass;
var class<Pack> localPackClass;

var name packLeftBone;
var name packRightBone;

var StaticMeshAttachment leftPack;
var StaticMeshAttachment rightPack;

// Pack effect flags
var bool bActivatingEffect;
var bool bLocalActivatingEffect;
var bool bActiveEffect;
var bool bLocalActiveEffect;
var bool bDeactivatingEffect;
var bool bLocalDeactivatingEffect;
var bool bActivatingEffectStarted;
var bool bLocalActivatingEffectStarted;
var bool bActiveEffectStarted;
var bool bLocalActiveEffectStarted;

var bool bUnactivatingEffect;
var bool bLocalUnactivatingEffect;
var bool bUnactiveEffect;
var bool bLocalUnactiveEffect;
var bool bUndeactivatingEffect;
var bool bLocalUndeactivatingEffect;
var bool bUnactivatingEffectStarted;
var bool bLocalUnactivatingEffectStarted;
var bool bUnactiveEffectStarted;
var bool bLocalUnactiveEffectStarted;

var bool bSpawningAtVehicle;

// deployables
var Deployable deployable;

var private float healthInjectionRatePerSecond;
var private float healthInjectionAmount;

// Character visualisation debug object
var CharacterVisualisation visualisation;

// Grappler related variables
const ROPE_MESH_LENGTH = 512;

var class<Grappler>			grapplerClass;

var GrapplerProjectile		proj;
var GrapplerRope			rope;
var float                   ropeNaturalLength;

var Array<Character>		grapplerCharacters; // Characters that are grappling this character

var bool					bAttached;
var bool					bLocalAttached;

var bool					bReelIn;
// End grappler related variables

// The last object hit by the character's weapon
var Pawn	lastHitObject;
var bool	bObjectHit;
var bool	bLocalObjectHit;
var bool	bHitRegistered;

var bool bIsLocalCharacter;

// character movement support

var String movementConfiguration;       // overridden by armor if wearing any

var float energy;                       // current energy - read/write
var float energyMinimum;                // minimum energy for jetpack - read only output from fusion
var float energyMaximum;                // maximum energy - read only output from fusion
var float energyRechargeRate;           // energy recharge rate - read only output from fusion, includes scale factor below
var float energyRechargeScale;          // energy recharge scale - read/write
var float energyWeaponDepleted;			// the amount of energy a weapon depleted in the last tick

// camera
var bool bZoomOutOnSpawn;

// Skins
var class<SkinInfo> userSkinClass; // for reference only, change in attached tribesReplicationInfo

// clientside pain sounds
enum EClientPainType
{
	CLIENTPAIN_Hurt,
	CLIENTPAIN_BigHurt,
	CLIENTPAIN_Death,
	CLIENTPAIN_Cratered,
	CLIENTPAIN_Burnt
};

var float localHealth;
var EClientPainType clientPainType;

struct native QuickChatInfo
{
	var bool bSwitch;
	var String TagID; 
};

// for animation
var QuickChatInfo QCAnimData;
var QuickChatInfo LocalQCAnimData;

// for speech
var QuickChatInfo QCTalkData;
var QuickChatInfo LocalQCTalkData;

// ***************************************************************************************

// dummy space for native csiro jetpack pointer - this must be the last data in character!

var transient const noexport byte dummy[4];

// ***************************************************************************************

// Estimate enough needed to jetpack between two points
native function float energyRequiredToJet(Vector a, Vector b, float velocity, bool jump);

// prefix movement configuration
native function prefixMovement(String name);

// Force movement configuration
native function forceMovement(String name);

// set debug movement flag
native function debugMovement(bool flag);

replication
{
	reliable if (ROLE == ROLE_Authority || bDemoRecording)
		combatRole, weapon, altWeapon, deployable, armorClass, carryableReference, numCarryables, pseudoWeapon, heldPackClass,
		m_bManualAnimation, proj, bAttached, bReelIn, ropeNaturalLength, lastHitObject, bObjectHit, bTempInvincible, HeadHeight,
		numPermanentCarryables, pack, bSpawningAtVehicle,
		QCTalkData, QCAnimData;

	// variables that are relevant only to owner
	unreliable if ((ROLE == ROLE_Authority && bNetOwner) || bDemoRecording)
		m_equipmentHead, weaponSlots, potentialEquipment, fallbackWeapon, healthInjectionAmount;

	// variables that are relevant only to others, not owner
	unreliable if ((ROLE == ROLE_Authority && !bNetOwner) || bDemoRecording)
		bActivatingEffect, bActiveEffect, bDeactivatingEffect, bActivatingEffectStarted, bActiveEffectStarted,
		bUnactivatingEffect, bUnactiveEffect, bUndeactivatingEffect, bUnactivatingEffectStarted, bUnactiveEffectStarted,
		clientPainType;

	// movement sim proxy data
	unreliable if ((ROLE == ROLE_Authority && !bNetOwner) || bDemoRecording)
        movementSimProxyInputX,
        movementSimProxyInputY,
        movementSimProxyInputThrust,
        movementSimProxyInputJump,
        movementSimProxyInputSki;

 	// replication from client to server
	reliable if (ROLE < ROLE_Authority)
		switchEquipment, serverDoInventoryRefill;
}

simulated function PrecacheSpeech(SpeechManager Manager)
{
	if (!self.IsA('AITalkingHead'))
		Manager.PrecacheAIVoiceSet(VoiceSetPackageName);
}


function destroyFallbackWeapon()
{
	if (fallbackWeapon != None)
	{
		fallbackWeapon.Destroy();
		fallbackWeapon = None;
	}
}

function spawnFallbackWeapon()
{
	if (armorClass != None && armorClass.default.fallbackWeaponClass != None)
	{
		fallbackWeapon = Spawn(armorClass.default.fallbackWeaponClass, self);
		fallbackWeapon.rookMotor = motor;
		fallbackWeapon.GotoState('Held');
	}
}

function equipFallbackWeapon()
{
	if (fallbackWeapon == None)
		spawnFallbackWeapon();

	motor.setWeapon(fallbackWeapon);
}

function bool canBeSensed()
{
	return bCanBeSensed && Controller != None;
}

simulated function String GetHumanReadableName()
{
	// handle MP case
	if (Level.NetMode != NM_StandAlone)
		return playerNameMP;

	if(CharacterName == "" && CharacterNameLocalisationTag != "")
		CharacterName = Localize("Names", CharacterNameLocalisationTag, "Localisation\\Speech\\CharacterNames");

	return CharacterName;
}

function Timer()
{
	removeTempInvincibility();
}

function removeTempInvincibility()
{
	UnTriggerEffectEvent('Invincible');
	bTempInvincible = false;
}

simulated function Material GetOverlayMaterial(int Index)
{
	local Material m;

	if (bTempInvincible)
		return invicibilityMaterial;
	else
	{
		if (pack != None)
		{
			m = pack.GetOverlayMaterialForOwner(Index);
			if (m != None)
				return m;
		}
	}

	return super.GetOverlayMaterial(Index);
}

simulated function PlayMovementSpeech(Name eventName)
{
	// ensure the voice set exists on the character
	if(Level.NetMode != NM_Standalone && TribesReplicationInfo != None)
		VoiceSetPackageName = TribesReplicationInfo.VoiceSetPackageName;

	if (VoiceSetPackageName != "")
		Level.speechManager.PlayMovementSpeech(self, eventName);
}

function serverDoInventoryRefill(float healthPerSecond)
{
	local Weapon w;

	if(health < HealthMaximum)
	{
		stopHealthInjection();
		healthInjection(healthPerSecond, HealthMaximum - Health);
	}

	w = Weapon( nextEquipment( None, class'Weapon' ));
	while(w != None)
	{
		w.increaseAmmo(w.getMaxAmmo() - w.AmmoCount);
		w = Weapon( nextEquipment( w, class'Weapon' ));
	}

	if(armorClass.static.getHandGrenadeClass() != None)
		newGrenades(armorClass.static.getHandGrenadeClass());
}

// healthInjection
// Adds a health injection to this character. The specified health amount shall be applied to this
// character at the specified rate.
function healthInjection(float healthPerSecond, float healthAmount)
{
	healthInjectionRatePerSecond = healthPerSecond;
	healthInjectionAmount += healthAmount; 
}

// clampHealthInjection
// Clamps current health injection such that it will not apply excess health.
function clampHealthInjection()
{
	if (healthInjectionAmount > (healthMaximum - health))
		healthInjectionAmount = healthMaximum - health;
}

function stopHealthInjection()
{
	healthInjectionAmount = 0;
}

function float getHealthInjectionAmount()
{
	return healthInjectionAmount;
}

simulated function IFiringMotor firingMotor()
{
	return motor;
}

// Returns the character (if it exists) that is controlling this rook (i.e. turret or vehicle)
simulated function Character getControllingCharacter()
{
	return self;
}

// getDrivenVehicle
// Returns None if no vehicle is begin driven.
simulated native function Vehicle getDrivenVehicle();

// get the vehicle or turret the character is in (or None)
simulated native function Rook getMount();

// try to exit a vehicle or turret (may not succeed)
function exitMount( Pawn vehicleOrTurret )
{
	local int i;
	local Vehicle vehicle;
	local Turret turret;

	vehicle = Vehicle( vehicleOrTurret );
	turret = Turret( vehicleOrTurret );

	// Vehicle
	if ( vehicle != None )
	{
		for ( i = 0; i < vehicle.positions.length; ++i )
		{
			if ( self == vehicle.positions[i].occupant )
				vehicle.positions[i].wantsToGetOut = true;
		}
	}
	// Turret
	else if ( turret != None )
	{
		if ( self == turret.Driver )
			turret.bGetOut = true;
	}
}

// is the character in a specified vehicle or turret?
function bool bIsInMount( Pawn vehicleOrTurret )
{
	local int i;
	local Vehicle vehicle;
	local Turret turret;

	vehicle = Vehicle( vehicleOrTurret );
	turret = Turret( vehicleOrTurret );

	// Vehicle
	if ( vehicle != None )
	{
		for ( i = 0; i < vehicle.positions.length; ++i )
		{
			if ( self == vehicle.positions[i].occupant )
				return true;
		}
	}
	// Turret
	else if ( turret != None )
	{
		if ( self == turret.Driver )
			return true;
	}
	return false;
}

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

// Destroyed
simulated function Destroyed()
{
	//log( name @ "DESTROYED CALLED" );

	detachGrapple();

	UnregisterVisionNotification(self);

	destroyEquipment();
	
	if (jetpack != None)
		jetpack.destroy();

	if (arms != None)
		arms.destroy();

	if (rope != None)
		rope.Destroy();

	destroyThirdPersonMesh();

    destroyAnimationSystem();
	
	if (motor != None)
		motor.Destroy();

    // todo: release animation states and channels

    // stop movement effects

    stopMovementEffects();

	UnTriggerEffectEvent('Invincible');
    
    // call super

	Super.Destroyed();
}

simulated function setJetpack(Jetpack newJetpack)
{
	if (jetpack != None)
	{
		jetpack.destroy();
		jetpack = None;
	}

	if (newJetpack != None)
	{
		jetpack = newJetpack;
		attachToBone(jetpack, jetpackBone);
	}
}

simulated function hideJetpack()
{
	if (jetpack != None)
		jetpack.bHidden = true;
}

simulated function showJetpack()
{
	if (jetpack != None)
		jetpack.bHidden = false;
}

function setArmsMesh(Mesh armsMesh)
{
	if (armsMesh == None)
		return;

	if (arms == None)
		arms = Spawn(class'Arms', self);

	arms.LinkMesh(armsMesh);
}

function OnViewerSawPawn(Pawn Viewer, Pawn Seen)
{

}

function OnViewerLostPawn(Pawn Viewer, Pawn Seen)
{

}

// OnHitObject
//
// Called when the character has hit an object with a weapon
// used for updating the HUD with feedback in PlayerCharacterController.
function OnHitObject(Pawn victim)
{
	lastHitObject = victim;
	bObjectHit = ! bObjectHit;
	// need to register a hit for the listen server
	bHitRegistered = true;
}

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

	//if (vision != None)
	//	vision.RegisterVisionNotification(self);

	updateCasts();
	
	Health = healthMaximum;
	
	debugMovement(false);

    wake();
}

// PostNetBeginPlay
simulated function PostNetBeginPlay()
{
	grapplerClass = class<Grappler>(DynamicLoadObject("EquipmentClasses.WeaponGrappler", class'Class'));

	if (grapplerClass == None)
		Log("Couldn't find EquipmentClasses.WeaponGrappler, grapplers will use default settings");

	motor = new class'CharacterMotor'(self);

	initialiseEquipment();

	super.PostNetBeginPlay();

    // Set ownership of TribesReplicationInfo
    if ( TribesReplicationInfo != None && TribesReplicationInfo.Owner == None )
	    TribesReplicationInfo.SetOwner(Controller);
    
    initializeAnimationSystem();
    
	collisionMaterialObject = new class'Material'();
	
	PlayEffect("CharacterStart");
	
	debugMovement(false);

	wake();
	
	// fill sim proxy data with initial position
	
	movementSimProxyPosition = Location;
	movementSimProxyVelocity = vect(0,0,0);
	movementSimProxyRotation = Rotation;
	movementSimProxyPending = true;
	
	// always holding a weapon in multiplayer
	
	weaponNotHeldTime = 0;
	
	// clear last collision time to ensure no crunch sound occurs first land
	
	lastMovementCollisionTime = 0;
}

simulated function PostLoadGame()
{
	super.PostLoadGame();

    initializeAnimationSystem();
	
	debugMovement(false);

	wake();
}

function initialiseEquipment()
{
	if ( loadoutClass != None )
	{
		loadout = new loadoutClass;
		loadout.equip( self );
		giveDefaultWeapon();
	}

	if ( armorClass != None )
	{
		armorClass.static.equip( self );

		// Reset the personalShield
		resetPersonalShield();
	}
}

function TravelPreAccept()
{
	destroyEquipment();
}

function TravelPostAccept()
{
	giveDefaultWeapon();
}

// PostNetReceive
simulated function PostNetReceive()
{
	updateCasts();

	// Just in case it breaks something important:
	//
	// I added check to ensure we don't try and do this until the 
	// TribesReplicationInfo is replicated. It seems that sometimes
	// the character doesn't have the replication info and thus may 
	// end up with the wrong jetpack.
	//
	if (combatRole != localCombatRole && tribesReplicationInfo != None) // detect combat role change
	{
		if (arms == None)
			arms = Spawn(class'Arms', self);

		arms.LinkMesh(m_team.getArmsMeshForRole(combatRole));

		if (needToPlayArmAnim != '')
			arms.PlayAnim(needToPlayArmAnim);

		setJetpack(m_team.getJetpackForRole(self, combatRole, tribesReplicationInfo.bIsFemale));

		localCombatRole = combatRole;
	}

	updatePackEffects();

	if (bAttached && !bLocalAttached)
		playAttachedAnim();

	bLocalAttached = bAttached;

	if(bObjectHit != bLocalObjectHit)
		bHitRegistered = true;

	bLocalObjectHit = bObjectHit;

	if (bTempInvincible != bLocalTempInvincible)
	{
		if (bTempInvincible)
			TriggerEffectEvent('Invincible');
		else
			UnTriggerEffectEvent('Invincible');

		bLocalTempInvincible = bTempInvincible;
	}

	if (localHealth != health && !bNetOwner)
	{
		if (health < localHealth)
		{
			switch(clientPainType)
			{
			case CLIENTPAIN_Hurt:
				PlayHurtSound(localHealth - health);
				break;
			case CLIENTPAIN_Death:
				PlayDeathSound(false, false);
				break;
			case CLIENTPAIN_Cratered:
				PlayDeathSound(true, false);
				break;
			case CLIENTPAIN_Burnt:
				PlayDeathSound(false, true);
				break;
			}
			
			PlayFlinchAnimation();
		}
		localHealth = health;
	}

	if(QCTalkData.bSwitch != LocalQCTalkData.bSwitch)
	{
		LocalQCTalkData.bSwitch = QCTalkData.bSwitch;
		if(TribesReplicationInfo != None)
			Level.speechManager.PlayQuickChatSpeech(TribesReplicationInfo, TribesReplicationInfo.VoiceSetPackageName, Name(QCTalkData.TagID), self);
	}

	if(QCAnimData.bSwitch != LocalQCAnimData.bSwitch)
	{
		LocalQCAnimData.bSwitch = QCAnimData.bSwitch;
		
		if (movementAirborne)
		{
		    if(!IsPlayingUpperBodyAnimation())
			    playUpperBodyAnimation(QCAnimData.TagID);
	    }
	    else
	    {
		    if(!IsPlayingAnimation())
			    playAnimation(QCAnimData.TagID);
	    }
	}

	checkManualAnimation();
}

function PlayQCSpeech(String Tag)
{
	QCTalkData.bSwitch = ! QCTalkData.bSwitch;
	QCTalkData.TagID = Tag;

	if(Level.NetMode == NM_ListenServer && TribesReplicationInfo != None)
		Level.speechManager.PlayQuickChatSpeech(TribesReplicationInfo, TribesReplicationInfo.VoiceSetPackageName, Name(QCTalkData.TagID), self);
}

function PlayQCAnimation(String AnimationName)
{
	QCAnimData.bSwitch = ! QCAnimData.bSwitch;
	QCAnimData.TagID = AnimationName;

	if(Level.NetMode == NM_ListenServer)
	{
		if (movementAirborne)
		{
		    if(!IsPlayingUpperBodyAnimation())
			    playUpperBodyAnimation(QCAnimData.TagID);
	    }
	    else
	    {
		    if(!IsPlayingAnimation())
			    playAnimation(QCAnimData.TagID);
	    }
	}
}

simulated function updatePackEffects()
{
	if (heldPackClass != localPackClass) // detect pack change
	{
		destroyThirdPersonMesh();

		if (heldPackClass != None)
			createThirdPersonMesh(heldPackClass);

		localPackClass = heldPackClass;
	}

	if (heldPackClass != None)
	{
		// play pack effects
		if (bActivatingEffect != bLocalActivatingEffect)
		{
			playPackEffect(heldPackClass.default.activatingEffectName);
			bLocalActivatingEffect = bActivatingEffect;
		}

		if (bActiveEffect != bLocalActiveEffect)
		{
			playPackEffect(heldPackClass.default.activeEffectName);
			bLocalActiveEffect = bActiveEffect;
		}

		if (bDeactivatingEffect != bLocalDeactivatingEffect)
		{
			playPackEffect(heldPackClass.default.deactivatingEffectName);
			bLocalDeactivatingEffect = bDeactivatingEffect;
		}

		if (bActivatingEffectStarted != bLocalActivatingEffectStarted)
		{
			playPackEffect(heldPackClass.default.activatingEffectStartedName);
			bLocalActivatingEffectStarted = bActivatingEffectStarted;
		}

		if (bActiveEffectStarted != bLocalActiveEffectStarted)
		{
			playPackEffect(heldPackClass.default.activeEffectStartedName);
			bLocalActiveEffectStarted = bActiveEffectStarted;
		}

		// Stop pack effects
		if (bUnactivatingEffect != bLocalUnactivatingEffect)
		{
			stopPackEffect(heldPackClass.default.activatingEffectName);
			bLocalUnactivatingEffect = bUnactivatingEffect;
		}

		if (bUnactiveEffect != bLocalUnactiveEffect)
		{
			stopPackEffect(heldPackClass.default.activeEffectName);
			bLocalUnactiveEffect = bUnactiveEffect;
		}

		if (bUndeactivatingEffect != bLocalUndeactivatingEffect)
		{
			stopPackEffect(heldPackClass.default.deactivatingEffectName);
			bLocalUndeactivatingEffect = bUnactiveEffect;
		}

		if (bUnactivatingEffectStarted != bLocalUnactivatingEffectStarted)
		{
			stopPackEffect(heldPackClass.default.activatingEffectStartedName);
			bLocalUnactivatingEffectStarted = bUnactivatingEffectStarted;
		}

		if (bUnactiveEffectStarted != bLocalUnactiveEffectStarted)
		{
			stopPackEffect(heldPackClass.default.activeEffectStartedName);
			bLocalUnactiveEffectStarted = bUnactiveEffectStarted;
		}
	}
}

simulated function playPackEffect(Name effectEvent)
{
	if (leftPack != None)
		leftPack.TriggerEffectEvent(effectEvent);

	if (rightPack != None)
		rightPack.TriggerEffectEvent(effectEvent);
}

simulated function stopPackEffect(Name effectEvent)
{
	if (leftPack != None)
		leftPack.UnTriggerEffectEvent(effectEvent);

	if (rightPack != None)
		rightPack.UnTriggerEffectEvent(effectEvent);
}

simulated function destroyThirdPersonMesh()
{
	if (leftPack != None)
		leftPack.destroy();
	if (rightPack != None)
		rightPack.destroy();
}

simulated function createThirdPersonMesh(class<Pack> packClass)
{
	if (packClass != None && packClass.default.thirdPersonMesh != None)
	{
		leftPack = new class'StaticMeshAttachment';
		leftPack.SetStaticMesh(packClass.default.thirdPersonMesh);
		leftPack.setDrawScale(packDrawScale);
		leftPack.CullDistance = packClass.default.CullDistance;
		attachToBone(leftPack, packLeftBone);

		rightPack = new class'StaticMeshAttachment';
		rightPack.SetStaticMesh(packClass.default.thirdPersonMesh);
		rightPack.setDrawScale(packDrawScale);
		rightPack.CullDistance = packClass.default.CullDistance;
		attachToBone(rightPack, packRightBone);
	}
}

// Tick
simulated function Tick(float Delta)
{
    local string configuration;
	local float tickHealthInjectionAmount;

	Super.Tick(Delta);

	if (!bIsLocalCharacter && Owner == Level.GetLocalPlayerController())
		bIsLocalCharacter = true;

	// kill ourselves if we are outside the boundary volume
	if ((Level.NetMode == NM_ListenServer || Level.NetMode == NM_DedicatedServer) && Level.game.boundaryVolume != None &&
			!Level.game.boundaryVolume.encompasses(self))
		TakeDamage(health + 1, None, vect(0.0, 0.0, 0.0), vect(0.0, 0.0, 0.0), class'DamageType');

	// update MP player name
	if (Level.NetMode != NM_StandAlone && tribesReplicationInfo != None)
		playerNameMP = tribesReplicationInfo.playerName;
	
	tickGrappler(Delta);

    // update critical movement values from armor if wearing any

    if (armorClass!=None)
    {
        if (pack!=none && SpeedPack(pack)!=none)
        {
            // speed pack movement configurations specific to armor
            
            if (SpeedPack(pack).IsInState('Active'))
                configuration = armorClass.default.movementConfigurationFastActive;
            else
                configuration = armorClass.default.movementConfigurationFastPassive;
        }
        else
        {        
            // standard armor movement configuration
        
            configuration = armorClass.default.movementConfiguration;
        }
        
        // armor specific knockback scale

        movementKnockBackScale = armorClass.default.knockBackScale;
    }
    else
    {
        // default movement configuration and knockback scale
    
        configuration = default.movementConfiguration;
        movementKnockBackScale = default.movementKnockBackScale;
    }
    
    if (configuration!=movementConfiguration)
    {
        //log("switching movement configuration: "$movementConfiguration$" -> "$configuration);

        movementConfiguration = configuration;
    }
    
    // apply current weapon arm animation loop
    
    if (weapon!=none && animationManager!=none)
    {
        if (weapon.equippedArmAnim!="")
        {
            if (!isLoopingArmAnimation() || getArmAnimation()!=weapon.equippedArmAnim)
            {
                loopArmAnimation(weapon.equippedArmAnim);
                weaponPlayingArmAnimation = true;
            }
        }
        else if (weaponPlayingArmAnimation)
        {
            stopArmAnimation();
            weaponPlayingArmAnimation = false;
        }
    }
	else if (weaponPlayingArmAnimation)
    {
        stopArmAnimation();
        weaponPlayingArmAnimation = false;
    }
    
    // update weapon not held time
    
    if (weapon==none)
    {
        weaponNotHeldTime += delta;
    }
    else
    {
        weaponNotHeldTime = 0;
    }

    // save for ragdoll velocity inheritance
    
    ragdollInheritedVelocity = velocity;

	// stop movement effects when we leave movement physics
	
	if (previousPhysics==PHYS_Movement && Physics!=PHYS_Movement)
	    stopMovementEffects();
	    
	previousPhysics = Physics;

    // setup last movement collision time to avoid crunch landing sound right after spawning
    
    if (lastMovementCollisionTime==0)
        lastMovementCollisionTime = level.timeSeconds + 1.0;
        
    // make sure that arms are hidden if not holding a weapon

	if (weapon == None && arms != None)
		arms.bHidden = true;

	// **** anything below this line will not get called when you are dead! ****
	    
    if (!isAlive())
        return;

	// **** server code ****
	
	if (Level.NetMode != NM_Client)
	{
        checkManualAnimation();

		if (tribesReplicationInfo != None)
		{
			tribesReplicationInfo.health = Health;
		}
		
		// clear blocked movement damage flag if set
		
		blockMovementDamage = false;

		// do regeneration functionality if necessary
		if (regenerationActive)
		{
			health += regenerationRateHealthPerSecond * Delta;
			if (health > healthMaximum)
				health = healthMaximum;
		}

		// do health injection functionality
		if (healthInjectionAmount > 0)
		{
			tickHealthInjectionAmount = Delta * healthInjectionRatePerSecond;

			// update total health injection amount
			if (tickHealthInjectionAmount > healthInjectionAmount)
			{
				tickHealthInjectionAmount = healthInjectionAmount;
				healthInjectionAmount = 0;
			}
			else
			{
				healthInjectionAmount -= tickHealthInjectionAmount;
			}

			health += tickHealthInjectionAmount;
			if (health > healthMaximum)
				health = healthMaximum;
		}
	}

	// **** client and server code ****

	// update skin
	updateUserSkin();

	// update animation springs

    animationHeightSpring.target = Location.z;
    animationVelocitySpring.target = Velocity.z;

    animationHeightSpring.Update(delta);
    animationVelocitySpring.Update(delta);
}

native simulated function checkManualAnimation();

function PossessedBy(Controller C)
{
	Super.PossessedBy(C);
	
	// Setup Vision Bone
    setupVisionBone();

	lastPossessor = C;

	updateCasts();
}

function Unpossessed()
{
	Super.Unpossessed();

	if (arms != None)
		arms.bHidden = true;
}

// Sets the eyeBoneIndex to the correct bone index for the bone set in eyeBoneName
native function setupVisionBone();

native function bool isInAir();

native function float getAirSpace();

// use energy.
// returns true if enough energy was available,
// false if not enough energy is available.

function bool useEnergy(float quantity)
{
	if (quantity>energy)
		return false;

	energy -= quantity;

	return true;
}

function changeEnergy(float delta)
{
	energy += delta;

	// Clamp
	if (energy < 0)
		energy = 0;
	if (energy > energyMaximum)
		energy = energyMaximum;
}

function changeHealth(float delta)
{
	health += delta;

	// Clamp
	if (health < 0)
		health = 0;
	if (health > healthMaximum)
		health = healthMaximum;
}

// Special weapon useEnergy variant to pass data down
// to the client side character class for display
function bool weaponUseEnergy(float quantity)
{
	if(useEnergy(quantity))
	{
		PlayerCharacterController(Controller).clientWeaponUseEnergy(quantity);
		return true;
	}

	return false;
}

simulated function clientWeaponUseEnergy(float quantity)
{
	if (Level.NetMode == NM_Client)
	{
		energy -= quantity;

		if (energy < 0.0)
			energy = 0.0;
	}

	energyWeaponDepleted += quantity;
}

simulated function useHealthKit()
{
	local HealthKit hk;

	hk = HealthKit(nextEquipment(None, class'HealthKit'));

	if (hk != None)
	{
	    PlayEffect("CharacterUseHealthKit");
		hk.use();
	}
	else
		ClientMessage("You don't have a health kit");
}

// if a pseudoweapon is attached to a carryable that the player has picked up, then pass "Alt Weapon Fire" function to that.
// Otherwise, pass it to the standard alt weapon.
// MJ edit:  We'll never allow carryables to be thrown via alt fire
simulated event Weapon GetAltWeapon()
{
//	if(carryableReference != None && !carryableReference.Class.default.bIsWeaponType)
//		return pseudoWeapon;
//	else
		return altWeapon;
}

simulated function dropWeapon()
{
	local Rotator droppedRotation;

	droppedRotation.yaw = rotation.yaw;

	if(deployable != None)
	{
		// rotate deployables to be upright for visibility
		deployable.SetRotation(droppedRotation);
		deployable.drop();
	}

	if (Weapon != None)
	{
	    PlayEffect("CharacterDropWeapon");
		weapon.SetRotation(droppedRotation);
		weapon.drop();
	}
}

function switchEquipment()
{
	if (potentialEquipment != None)
	{
	    PlayEffect("CharacterSwitchEquipment");
		potentialEquipment.doSwitch(self);
	}
}

function dropCarryables()
{
	local int i;

	if (carryableReference == None)
		return;

	// Before dropping all the carryables, compose them into the largest possible denominations (if applicable)
	composeCarryables(true);

	// Drop the rest with random spread
	for (i=1; i<carryables.Length; i++)
	{
		carryables[i].drop(true);
	}

	// Drop the first carryable without random spread
	carryables[0].drop(false);

	clearCarryables();
}

function pickupCarryable(MPCarryable c)
{
	carryables[carryables.Length] = c;
	numCarryables = numCarryables + 1;

	movementExtraMass += c.extraMass;

	// If this is the first pickup, remember the instance for replication purposes
	if (carryableReference == None)
	{
		// pickup() returns an instance, which is self in the case of regular MPCarryables or
		// the first instance in the case of metacarryables
		carryableReference = c;

		// Also create a new pseudoWeapon for it, which is used for throwing the carryable
		pseudoWeapon = new carryableReference.carriedObjectClass();
		pseudoWeapon.setCarryable(carryableReference);
		pseudoWeapon.SetOwner(self);
		pseudoWeapon.rookOwner = self;
		pseudoWeapon.rookMotor = motor;
		pseudoweapon.GotoState('Held');

		// We want this carryable to work just like a weapon does.
		if (carryableReference.bIsWeaponType)
		{
			// add pseudoweapon to inventory
			addEquipment(pseudoWeapon);
		}
		else
		{
			//pseudoweapon.equip();
		}
	}
}

function clearCarryables()
{
	// Make sure it hasn't already been cleared (can be called twice if, for example, a ball
	// is thrown and a goal is scored in the same tick)
	if (carryableReference == None)
		return;

	movementExtraMass -= numCarryables * carryableReference.extraMass;
	carryableReference = None;
	carryables.Length = 0;
	numCarryables = 0;

	// Remove pseudoweapon from player's inventory
	pseudoWeapon.GotoState('Dropped');

	// Destroy it since it is no longer needed
	pseudoWeapon.Destroy();
}

// If current carryable class has denominations, compose all carryables into largest denominations
function composeCarryables(optional bool bDropAll)
{
	local int i, j;
	local array<MPCarryable> newArray;
	local MPMetaCarryable metaCarryable;
	local int numToDrop;

	if (carryableReference == None || carryableReference.denominations.Length == 0)
		return;

	if (bDropAll)
		numToDrop = numCarryables;
	else
		numToDrop = numDroppableCarryables();

	// Start at the largest denomination.  For each denomination, try to compose a metacarryable
	for (i=carryableReference.denominations.Length-1; i>=0; i--)
	{
		// If there are enough carryables to compose a denomination
		while (numToDrop / carryableReference.denominations[i].default.maxCarryables > 0)
		{
			//Log("Creating denomination of size "$carryableReference.denominations[i].default.maxCarryables);
			// Spawn a new metaCarryable and assign its data; make sure not to spawn it on the character otherwise
			// it gets picked up again immediately
			metaCarryable = spawn(carryableReference.denominations[i],,,Location + Normal(Vector(Rotation)) * pseudoWeapon.extraSpawnDistance);

			if (metaCarryable == None)
			{
				Log("MetaCarryable composition error:  could not spawn metaCarryable of type "$carryableReference.denominations[i]);
				return;
			}

			// Add enough carryables to fill up the denomination
			for (j=0; j<carryableReference.denominations[i].default.maxCarryables; j++)
			{
				//Log("Added "$carryables[j]$" to "$metaCarryable);
				metaCarryable.add(carryables[j]);
			}
			metaCarryable.bInitialized = true;

			// Put the metaCarryable in a new array to be copied later
			newArray[newArray.Length] = metaCarryable;

			// Remove the carryables that were transferred to the metaCarryable
			carryables.Remove(0, j);
			numCarryables = numCarryables - j;
			numToDrop = numToDrop - j;

			// After removal, this while loop will repeat if there are still enough carryables to
			// fill the current denomination
		}
	}

	// Copy the newArray to the rest of the character's carryables array
	for (i=0; i<newArray.Length; i++)
	{
		carryables[carryables.Length] = newArray[i];
	}

	//Log("Contents of carryables array after composition:");
	//for (i=0; i<carryables.Length; i++)
	//	Log("  carryables array: "$carryables[i]);
}

simulated function int numDroppableCarryables()
{
	return numCarryables - numPermanentCarryables;
}

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

	Canvas.SetDrawColor(255,255,255);
	Canvas.Style = ERenderStyle.STY_Normal;
	Canvas.SetPos(4,YPos);
	if (Weapon != None)
		Canvas.DrawText("Weapon State: "$Weapon.GetStateName());
	else
		Canvas.DrawText("Weapon State: no weapon");
	YPos += YL;

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

function Died(Controller Killer, class<DamageType> damageType, vector HitLocation)
{
	local MPAreaTrigger areaTrigger;
	local Name squadLabel;
	local Rook killerRook;

	if (!bDisallowEquipmentDropOnDeath)
		dropEquipment();

	destroyEquipment();

    Super.Died( Killer, damageType, HitLocation );

	detachGrapple();

	if (squad() != None)
		squadLabel = squad().Label;

	if ( Killer!= None && Killer.Pawn != None)
	{
		killerRook = Rook(Killer.Pawn);
		if (killerRook != None)
			dispatchMessage(new class'MessageDeath'(killerRook.getKillerLabel(), label, Killer.Pawn.PlayerReplicationInfo, PlayerReplicationInfo, squadLabel));
		else
			dispatchMessage(new class'MessageDeath'(Killer.Pawn.label, label, Killer.Pawn.PlayerReplicationInfo, PlayerReplicationInfo, squadLabel));
	}
	else
		dispatchMessage(new class'MessageDeath'(self.label, label, PlayerReplicationInfo, PlayerReplicationInfo, squadLabel));
		
	PlayEffect("CharacterDied");

	if (PlayerCharacterController(Controller) != None)
	{
		if (weapon != None)
			PlayerCharacterController(Controller).lastWeaponClass = weapon.Class;
		else
			PlayerCharacterController(Controller).lastWeaponClass = None;
	}

	if (carryableReference != None)
		carryableReference.onCarrierDeath(Killer);

	// Force immediate UnTouch on MPAreaTriggers
	ForEach TouchingActors(class'MPAreaTrigger', areaTrigger)
	{
		areaTrigger.UnTouch(self);
	}

	dropCarryables();

	if (arms != None)
		arms.bHidden = true;
}

// return gravity in Unreal units
native function float gravity();

// effect system code

simulated function StopMovementEffects()
{
    // stop movement looping effects
    
	StopLoopingEffect("MovementWater");

	StopLoopingEffect("MovementSki");
	StopLoopingEffect("MovementSkiGrounded");
	StopLoopingEffect("MovementSkiAirborne");

	StopLoopingEffect("MovementThrust");
	StopLoopingEffect("MovementThrustUnderWater");
	StopLoopingEffect("MovementThrustAboveWater");

	StopLoopingEffect("MovementStand");
	StopLoopingEffect("MovementStop");
	StopLoopingEffect("MovementWalk");
	StopLoopingEffect("MovementRun");
	StopLoopingEffect("MovementSprint");
	StopLoopingEffect("MovementSlide");
	StopLoopingEffect("MovementSwim");
	StopLoopingEffect("MovementFloat");
	StopLoopingEffect("MovementAirborne");
	StopLoopingEffect("MovementAirControl");
	StopLoopingEffect("MovementZeroGravity");
	StopLoopingEffect("MovementElevator");
}

simulated function string VelocityTag(Vector velocity)
{
    local float scale;

    scale = VSize(velocity) / 80;
    
    //log("scale: "$scale);

	if (scale<10)
    	return "Tiny";
	else if (scale<20)
    	return "Small";
    else if (scale<30)
    	return "Medium";
    else if (scale<40)
    	return "Large";
    else
    	return "Extreme";
}

simulated function string DamageTag(float damage)
{
	if (damage<2.5)
	    return "Tiny";
	else if (damage<5)
	    return "Small";
    else if (damage<10)
        return "Medium";
    else if (damage<25)
        return "Large";
    else
        return "Extreme";
}

simulated function StartGroundBasedLoopingEffect(String EffectName, optional String Tag)
{   
	StartLoopingEffect(EffectName, Tag, None, collisionMaterialObject);
}

// on movement collision.
// this method is called by fusion whenever a collision occurs

simulated event OnMovementCollision(Vector point, Vector normal, Vector impulse, int material)
{
    local bool feet;
    local string tag;
    
    if (level.timeSeconds<lastMovementCollisionTime+0.25)
        return;
        
    lastMovementCollisionTime = level.timeSeconds;
    
    tag = VelocityTag(impulse / Mass);

    if (point.z<location.z-CollisionHeight/2)
        feet = true;

    collisionMaterialObject.MaterialSoundType = material;
    collisionMaterialObject.MaterialVisualType = EMaterialVisualType(material);
    
    if (feet && movement!=MovementState_Ski)
    {
        if (movementTouching)
            return;
    
	    if (PlayEffect("MovementCollisionFeet", tag, None, collisionMaterialObject, point, Rotator(normal)))
            return;
    }

    if (movement==MovementState_Ski && tag=="Tiny")
        return;
    
   	PlayEffect("MovementCollision", tag, None, collisionMaterialObject, point, Rotator(normal));
}

// on movement collision damage.
// this method is called by fusion whenever a collision in the movement
// is suffiently large as to cause damage to the character.

simulated event OnMovementCollisionDamage(float damage)
{
    local class<MovementCollisionDamageType> collisionDamageType;

    if (blockMovementDamage)
        return;

    if (level.timeSeconds<lastMovementDamageTime+0.1)
        return;
        
    if (movement==MovementState_Elevator)       // no damage in elevator volumes
        return;
    
    // determine collision damage type
    
    collisionDamageType = class'MovementCollisionDamageType';
                                                                                                            
    if (armorClass!=None && armorClass.default.movementDamageTypeClass!=none)
        collisionDamageType = armorClass.default.movementDamageTypeClass; 
	
	TakeDamage(damage, self, vect(0,0,0), vect(0,0,0), collisionDamageType);

    PlayEffect("MovementCollisionDamage", DamageTag(damage));

    lastMovementDamageTime = level.timeSeconds;
}

// on movement crushing damage.
// this method is called by fusion when a heavy object such as a vehicle
// applies crushing the character by pushing into it.

simulated event OnMovementCrushingDamage(float damage, Pawn source)
{
    local Vehicle vehicle;
    local class<MovementCrushingDamageType> crushingDamageType;
    
    // determine crushing damage type
    
    crushingDamageType = class'MovementCrushingDamageType';
                                                                                                            
    if (armorClass!=None && armorClass.default.movementCrushingDamageTypeClass!=none)
        crushingDamageType = armorClass.default.movementCrushingDamageTypeClass; 
    
    if (source.IsA('Vehicle'))
    {
        // vehicle crushing damage

        vehicle = Vehicle(source);

        if (vehicle.CrushingDamageTypeClass!=None)
            crushingDamageType = vehicle.CrushingDamageTypeClass;
            
        if (vehicle.getControllingCharacter()!=None)
            source = vehicle.getControllingCharacter();
    }
    else
    {
        // crushed by havok object
        
        source = self;
    }

    // apply damage

    TakeDamage(damage, source, vect(0,0,0), vect(0,0,0), crushingDamageType);

    // play crushing damage effect

    PlayEffect("MovementCrushingDamage", DamageTag(damage));
}

// called when a movement jump occurs.

simulated event OnMovementJump()
{
    if (!movementSimProxyInputThrust)
        PlayEffect("MovementJump");
}

// on change airborne.
// called when a character's airborne state changes.

simulated event OnChangeAirborne(bool previous, bool current)
{
    if (previous==current)
    {
        log("*** on change airborne: no state change detected! ***");
        return;
    }

    //log("change airborne: "$previous$"->"$current);
}

// on change water.
// called when a character's water state changes.

simulated event OnChangeWater(bool previous, bool current)
{
    if (previous==current)
    {
        log("*** on change water: no state change detected! ***");
        return;
    }

    //log("change water: "$previous$"->"$current);
}

// on change underwater.
// called when a character's underwater state changes.

simulated event OnChangeUnderwater(bool previous, bool current)
{
    if (previous==current)
    {
        log("*** on change underwater: no state change detected! ***");
        return;
    }

    //log("change underwater: "$previous$"->"$current);
}

// on change collision material.
// called when the collision material changes.

simulated event OnChangeCollisionMaterial(int previous, int current)
{
    if (previous==current)
    {
        log("*** on change collision material: no state change detected! ***");
        return;
    }

    //log("change collision material: "$previous$"->"$current);
}

// on change ski input.
// called when the ski input changes.

simulated event OnChangeSkiInput(bool previous, bool current)
{
    if (previous==current)
    {
        log("*** on change collision material: no state change detected! ***");
        return;
    }

    //log("change ski input: "$previous$"->"$current);
}

// on change movement.
// This method is called when the character movement state changes

simulated event OnChangeMovement(MovementState previous, MovementState current)
{
    if (previous==current)
    {
        log("*** on change movement: no state change detected! ***");
        return;
    }

	// movement state change occured

	//log("movement state change: "$previous$" -> "$current);
}                            

// on change effects.
//
// called when one or more of the following states change:
// 
// 1. movement state (walk, run, thrust etc...)
// 2. airborne (true/false)
// 3. underwater (true/false)
// 4. water (true/false)
// 5. collision material (enum)
// 6. ski input (true/false)

simulated event OnChangeEffects( MovementState previousMovementState, MovementState currentMovementState, 
                                 bool previousAirborne, bool currentAirborne, 
                                 bool previousWater, bool currentWater, 
                                 bool previousUnderWater, bool currentUnderWater,
                                 int previousMaterial, int currentMaterial,
                                 bool previousSkiInput, bool currentSkiInput )
{
    if (previousMovementState==currentMovementState &&
        previousAirborne==currentAirborne &&
        previousWater==currentWater &&
        previousUnderWater==currentUnderWater &&
        previousMaterial==currentMaterial && 
        previousSkiInput==currentSkiInput)
    {
        log("*** on change effects: no state change detected! ***");
        return;
    }

    // ski input changes

    if (previousSkiInput==false && currentSkiInput==true)
	    StartLoopingEffect("MovementSki");
	else if (previousSkiInput==true && currentSkiInput==false)
	    StopLoopingEffect("MovementSki");

    // airborne changes

    if (previousAirborne==false && currentAirborne==true)
    {
        // not airborne -> airborne
        
        if (currentMovementState==previousMovementState && currentMovementState==MovementState_Ski)
            StopLoopingEffect("MovementSkiGrounded");
    }
    else
    {
        // airborne -> not airborne    

        if (currentMovementState==previousMovementState && currentMovementState==MovementState_Ski)
    		StartGroundBasedLoopingEffect("MovementSkiGrounded");
    }    

    // material changes
    
    if (previousMaterial!=currentMaterial)
    {
        if (currentMovementState==previousMovementState && currentMovementState==MovementState_Ski && previousAirborne==currentAirborne)
        {
            StopLoopingEffect("MovementSkiGrounded");
            StartGroundBasedLoopingEffect("MovementSkiGrounded");
        }
    }

    // movement state changes
    
    if (previousMovementState!=currentMovementState)
    {
	    // stop previous movement state effects
    	
	    switch (previousMovementState)
	    {
		    case MovementState_Thrust:
		        StopLoopingEffect("MovementThrust");
			    break;
			    
 		    case MovementState_Ski:
			    StopLoopingEffect("MovementSkiGrounded");
			    break;

		    case MovementState_Stand:
			    StopLoopingEffect("MovementStand");
			    break;

		    case MovementState_Stop:
			    StopLoopingEffect("MovementStop");
			    break;

		    case MovementState_Walk:
			    StopLoopingEffect("MovementWalk");
			    break;			
			    
		    case MovementState_Run:
			    StopLoopingEffect("MovementRun");
			    break;
			    
		    case MovementState_Sprint:
			    StopLoopingEffect("MovementSprint");
			    break;
			    
 		    case MovementState_Slide:
			    StopLoopingEffect("MovementSlide");
			    break;
			    
 		    case MovementState_Swim:
			    StopLoopingEffect("MovementSwim");
			    break;
			    
 		    case MovementState_Float:
			    StopLoopingEffect("MovementFloat");
			    break;
			    
 		    case MovementState_Skim:
			    StopLoopingEffect("MovementSkim");
			    break;
			    
		    case MovementState_Airborne:		
			    StopLoopingEffect("MovementAirborne");
			    break;			

		    case MovementState_AirControl:		
			    StopLoopingEffect("MovementAirControl");
			    break;			

		    case MovementState_ZeroGravity:		
			    StopLoopingEffect("MovementZeroGravity");
			    break;			

		    case MovementState_Elevator:		
			    StopLoopingEffect("MovementElevator");
			    break;			
	    }

        // start effects for current movement state
        
        if (currentMovementState==MovementState_Ski && !currentAirborne)
    		StartGroundBasedLoopingEffect("MovementSkiGrounded");
    	else if (currentMovementState==MovementState_Thrust)
    	    StartLoopingEffect("MovementThrust");

	    switch (currentMovementState)
	    {
		    case MovementState_Stand:
		        StartGroundBasedLoopingEffect("MovementStand");
		        break;

		    case MovementState_Stop:
		        StartGroundBasedLoopingEffect("MovementStop");
		        break;

		    case MovementState_Walk:
		        StartGroundBasedLoopingEffect("MovementWalk");
			    break;
    			
		    case MovementState_Run:
		        StartGroundBasedLoopingEffect("MovementRun");
			    break;
    			
		    case MovementState_Sprint:
		        StartGroundBasedLoopingEffect("MovementSprint");
			    break;
    			
		    case MovementState_Slide:
    		    StartGroundBasedLoopingEffect("MovementSlide");
			    break;
    			
		    case MovementState_Airborne:
    		    StartLoopingEffect("MovementAirborne");
			    break; 
    			
		    case MovementState_AirControl:
    		    StartLoopingEffect("MovementAirControl");
			    break; 
    			
		    case MovementState_Swim:
		        StartLoopingEffect("MovementSwim");
			    break;
    			
		    case MovementState_Float:
		        StartLoopingEffect("MovementFloat");
			    break;
    			
		    case MovementState_Skim:
		        StartLoopingEffect("MovementSkim");
			    break;
    			
		    case MovementState_ZeroGravity:
		        StartLoopingEffect("MovementZeroGravity");
			    break;
    			
		    case MovementState_Elevator:
		        StartLoopingEffect("MovementElevator");
			    break;
        }
    }

    // water changes

    if (currentWater && !previousWater)
    {
        // start water loop
    
        StartLoopingEffect("MovementWater");
        
    	PlayEffect("MovementEnterWater", VelocityTag(Velocity));
    }
    else if (!currentWater && previousWater)
    {
        // leave water
    
        StopLoopingEffect("MovementWater");
        
        PlayEffect("MovementLeaveWater", VelocityTag(Velocity));
    }

    // underwater changes

    if (currentUnderWater && !previousUnderWater)
    {
        // start UnderWater loop
    
        StartLoopingEffect("MovementUnderWater");
        
    	PlayEffect("MovementEnterUnderWater", VelocityTag(Velocity));
    }
    else if (!currentUnderWater && previousUnderWater)
    {
        // leave UnderWater
    
        StopLoopingEffect("MovementUnderWater");
        
        PlayEffect("MovementLeaveUnderWater", VelocityTag(Velocity));
    }
}

// enterManualAnimationState
// Call this function to disable the automatic movement animations
// This will allow you to play any animation you like on the character without interruption
function enterManualAnimationState()
{
	m_bManualAnimation = true;
}

// exitManualAnimationState
// Call this function to re-enable the automatic movement animations
function exitManualAnimationState()
{
	m_bManualAnimation = false;
}

simulated function initializeAnimationSystem()
{
    setupAnimationManager();
	setupAnimationStates();
	setupAnimationChannels();
	setupAnimationLayers();
	setupAnimationSprings();

	checkManualAnimation();
}

simulated function destroyAnimationSystem()
{
    local int i;

    if (animationManager!=None)
    {
        animationManager.delete();
        animationManager = None;
	}
	
	for (i=0; i<animationStates.Length; i++)
	    animationStates[i].delete();
	animationStates.length = 0;
	
	for (i=0; i<animationChannels.Length; i++)
	    animationChannels[i].delete();
	animationChannels.length = 0;
	
	if (primaryAnimationLayer!=none)
	{
	    primaryAnimationLayer.delete();
	    primaryAnimationLayer = none;
	}
	
	if (secondaryAnimationLayer!=none)
	{
	    secondaryAnimationLayer.delete();
	    secondaryAnimationLayer = none;
	}

    if (animationHeightSpring!=none)
    {
        animationHeightSpring.delete();
        animationHeightSpring = none;
    }
    
    if (animationVelocitySpring!=none)
    {
        animationVelocitySpring.delete();
        animationVelocitySpring = none;	
    }
}

simulated function setupAnimationManager()
{
	animationManager = new class'AnimationManager'();

    StopAnimating();
}

simulated function setupAnimationStates()
{
    local AnimationState animation;

    allocateAnimationStates(AnimationState_Count);
    
    // none
    
    animation = new class'AnimationState'();
    
    animation.name = "none";
    animation.type = AnimationType_IdleWithTurn;
    animation.blendInTime = 0.1;
    animation.blendTightness = 0.1;
    animation.centre = "";
    animation.forward = "";
    animation.back = "";
    animation.left = "";
    animation.right = "";
    animation.up = "";
    animation.down = "";
    
    setAnimationState(AnimationState_None, animation);
    
    // stand
    
    animation = new class'AnimationState'();
    
    animation.name = "stand";
    animation.type = AnimationType_IdleWithTurn;
    animation.blendInTime = 0.25;
    animation.blendTightness = 0.1;
    animation.centre = "stand";
    animation.forward = "";
    animation.back = "";
    animation.left = "turn_left";
    animation.right = "turn_right";
    animation.up = "";
    animation.down = "stand_down";
    
    setAnimationState(AnimationState_Stand, animation);
    
    // walk    
    
    animation = new class'AnimationState'();
    
    animation.name = "walk";
    animation.type = AnimationType_DisplacementDirectional;
    animation.blendInTime = 0.25;
    animation.blendTightness = 0.1;
    animation.centre = "stand";
    animation.forward = "walk_forward";
    animation.back = "walk_back";
    animation.left = "walk_left";
    animation.right = "walk_right";
    animation.up = "";
    animation.down = "";
    animation.speed = walkAnimationSpeed;
    
    setAnimationState(AnimationState_Walk, animation);

    // run
    
    animation = new class'AnimationState'();
    
    animation.name = "run";
    animation.type = AnimationType_DisplacementDirectional;
    animation.blendInTime = 0.25;
    animation.blendTightness = 0.1;
    animation.centre = "stand";
    animation.forward = "run_forward";
    animation.back = "run_back";
    animation.left = "run_left";
    animation.right = "run_right";
    animation.up = "";
    animation.down = "";
    animation.speed = runAnimationSpeed;
    
    setAnimationState(AnimationState_Run, animation);

    // sprint
    
    animation = new class'AnimationState'();
    
    animation.name = "sprint";
    animation.type = AnimationType_DisplacementDirectional;
    animation.blendInTime = 0.25;
    animation.blendTightness = 0.1;
    animation.centre = "stand";
    animation.forward = "sprint_forward";
    animation.back = "sprint_back";
    animation.left = "sprint_left";
    animation.right = "sprint_right";
    animation.up = "";
    animation.down = "";
    animation.speed = sprintAnimationSpeed;
    
    setAnimationState(AnimationState_Sprint, animation);

    // ski
    
    animation = new class'AnimationState'();
    
    animation.name = "ski";
    animation.type = AnimationType_VelocitySpringAndAirborneUpDown;
    animation.blendInTime = 0.3;
    animation.blendTightness = 0.1;
    animation.centre = "ski";
    animation.forward = "";
    animation.back = "";
    animation.left = "ski_airborne_up";
    animation.right = "ski_airborne_down";
    animation.up = "ski_up";
    animation.down = "ski_down";
    
    setAnimationState(AnimationState_Ski, animation);

    // slide
    
    animation = new class'AnimationState'();
    
    animation.name = "slide";
    animation.type = AnimationType_DisplacementDirectional;
    animation.blendInTime = 0.1;
    animation.blendTightness = 0.2;
    animation.centre = "slide";
    animation.forward = "slide_forward";
    animation.back = "slide_back";
    animation.left = "slide_left";
    animation.right = "slide_right";
    animation.up = "";
    animation.down = "";
    
    setAnimationState(AnimationState_Slide, animation);

    // stop
    
    animation = new class'AnimationState'();
    
    animation.name = "stop";
    animation.type = AnimationType_DisplacementDirectional;
    animation.blendInTime = 0.1;
    animation.blendTightness = 0.1;
    animation.centre = "stop";
    animation.forward = "stop_forward";
    animation.back = "stop_back";
    animation.left = "stop_left";
    animation.right = "stop_right";
    animation.up = "";
    animation.down = "stop_down";
    
    setAnimationState(AnimationState_Stop, animation);

    // airborne
    
    animation = new class'AnimationState'();
    
    animation.name = "airborne";
    animation.type = AnimationType_AirborneUpDown;
    animation.blendInTime = 0.3;
    animation.blendTightness = 0.1;
    animation.centre = "airborne";
    animation.forward = "airborne_forward";
    animation.back = "airborne_back";
    animation.left = "airborne_left";
    animation.right = "airborne_right";
    animation.up = "airborne_up";
    animation.down = "airborne_down";
    
    setAnimationState(AnimationState_Airborne, animation);

    // air control
    
    animation = new class'AnimationState'();
    
    animation.name = "aircontrol";
    animation.type = AnimationType_StrafeDirectional;
    animation.blendInTime = 0.3;
    animation.blendTightness = 0.25;
    animation.centre = "airborne";
    animation.forward = "thrust_forward";
    animation.back = "thrust_back";
    animation.left = "thrust_left";
    animation.right = "thrust_right";
    animation.up = "";
    animation.down = "";
    
    setAnimationState(AnimationState_AirControl, animation);

    // thrust
    
    animation = new class'AnimationState'();
    
    animation.name = "thrust";
    animation.type = AnimationType_StrafeDirectional;
    animation.blendInTime = 0.3;
    animation.blendTightness = 0.25;
    animation.centre = "thrust";
    animation.forward = "thrust_forward";
    animation.back = "thrust_back";
    animation.left = "thrust_left";
    animation.right = "thrust_right";
    animation.up = "";
    animation.down = "";
    
    setAnimationState(AnimationState_Thrust, animation);

    // swim
    
    animation = new class'AnimationState'();
    
    animation.name = "swim";
    animation.type = AnimationType_DisplacementDirectional;
    animation.blendInTime = 0.3f;
    animation.blendTightness = 0.25;
    animation.centre = "thrust";
    animation.forward = "thrust_forward";
    animation.back = "thrust_back";
    animation.left = "thrust_left";
    animation.right = "thrust_right";
    animation.up = "";
    animation.down = "";
    
    setAnimationState(AnimationState_Swim, animation);
}

simulated function setupAnimationChannels()
{
    allocateAnimationChannels(AnimationChannel_Count);
}

simulated function setupAnimationLayers()
{
    primaryAnimationLayer = new class'AnimationLayer'();
    secondaryAnimationLayer = new class'AnimationLayer'();
}

simulated function setupAnimationSprings()
{
    animationHeightSpring = new class'AnimationSpring'(0.001,100);
    animationVelocitySpring = new class'AnimationSpring'(0.0001,500);
}

// allocate animation states.
// workaround because you cannot assign an enum as the length of an array directly.

simulated function allocateAnimationStates(AnimationStateEnum size)
{
    local int count;
    count = int(size);
    animationStates.Length = count;
}

// set animation state.
// workaround because enums cannot currently be used as array index

simulated function setAnimationState(AnimationStateEnum slot, AnimationState state)
{
    local int index;
    index = int(slot);
    animationStates[index] = state;
}

// allocate animation channels.
// workaround because you cannot assign an enum as the length of an array directly.

simulated function allocateAnimationChannels(AnimationChannelIndex size)
{
    local int i;
    local int count;
    
    count = int(size);
    
    animationChannels.Length = count;

    for (i=0; i<count; i++)
        animationChannels[i] = new class'AnimationChannel'();
}

// reset movement animations

simulated function resetMovementAnimations()
{
    if (animationManager!=None)
    {
        animationManager.stopAnimating(self);
        animationManager.startAnimating(self);
    }
}

// extra animation channel

simulated function playAnimation(string animation)
{
    if (animationManager!=None)
        animationManager.playAnimation(animation);
}

simulated function loopAnimation(string animation)
{
    if (animationManager!=None)
        animationManager.loopAnimation(animation);
}

simulated function bool isPlayingAnimation()
{
    if (animationManager!=None)
        return animationManager.isPlayingAnimation();
    return false;
}

simulated function bool isLoopingAnimation()
{
    if (animationManager!=None)
        return animationManager.isLoopingAnimation();
    return false;
}

simulated function stopAnimation()
{
    if (animationManager!=None)
        animationManager.stopAnimation();
}

// fire animation

simulated function playFireAnimation(string weapon)
{
	if (PlayerCharacterController(controller)!=none)
	    PlayerCharacterController(controller).enterCombat();
	
    if (animationManager!=None)
        animationManager.playFireAnimation(weapon);
}

// upper body animation

simulated function playUpperBodyAnimation(string animation)
{
    if (animationManager!=None)
        animationManager.playUpperBodyAnimation(animation);
}

simulated function loopUpperBodyAnimation(string animation)
{
    if (animationManager!=None)
        animationManager.loopUpperBodyAnimation(animation);
}

simulated function bool isPlayingUpperBodyAnimation()
{
    if (animationManager!=None)
        return animationManager.isPlayingUpperBodyAnimation();
    return false;
}

simulated function bool isLoopingUpperBodyAnimation()
{
    if (animationManager!=None)
        return animationManager.isLoopingUpperBodyAnimation();
    return false;
}

simulated function stopUpperBodyAnimation()
{
    if (animationManager!=None)
        animationManager.stopUpperBodyAnimation();
}

// arm animation

simulated function loopArmAnimation(string animation)
{
    if (animationManager!=None)
        animationManager.loopArmAnimation(animation);
}

simulated function bool isLoopingArmAnimation()
{
    if (animationManager!=None)
        return animationManager.isLoopingArmAnimation();
    return false;
}

simulated function string getArmAnimation()
{
    if (animationManager!=None)
        return animationManager.getArmAnimation();
    return "";
}

simulated function stopArmAnimation()
{
    if (animationManager!=None)
        animationManager.stopArmAnimation();
}

// flinch animation

simulated function playFlinchAnimation()
{
    if (animationManager!=None)
        animationManager.playFlinchAnimation();
}

// force movement state.
// sets the character and fusion movement state to a specific value.
// this method should be used only for network replication, as the movement
// state is automatically updated as a result of the physics simulation.

simulated function forceMovementState(MovementState state)
{
   	movementObject.forceMovementState(state);

    //log("force movement: "$state);

	movement = state;
}   

// wake movement physics

simulated function wake()
{
    if (movementObject!=None)
        movementObject.wake();
}

// tell movement object to recalculate its extents

simulated function calculateExtents()
{
    movementObject.calculateExtents();
}

// bump notification

simulated function Bump(Actor other)
{
	local float combinedVelocity;
	local float impactDamage;
	local Buckler buckler;
	local Vector bucklerDir;

    //log(Name$" bumped by "$other.Name);

	if (Role == ROLE_Authority)
	{
		buckler = Buckler(weapon);

		if (buckler != None && buckler.hasAmmo() &&
			Level.TimeSeconds - buckler.lastCheckTime > buckler.default.minCheckRate)
		{
			combinedVelocity = VSize(Velocity) + VSize(other.Velocity);

			if (combinedVelocity < buckler.default.minCheckVelocity)
				return;

			bucklerDir = Normal(Vector(motor.GetViewRotation()));

			if ((bucklerDir Dot Normal(other.Location - Location)) > buckler.cosDeflectionAngle)
			{
				buckler.lastChecktime = Level.TimeSeconds;

				impactDamage = buckler.checkingDamage + buckler.checkingDmgVelMultiplier * combinedVelocity;

				if (Character(Other) != None)
					Character(Other).blockMovementDamage = true;

				Other.TakeDamage(impactDamage, self, other.Location, bucklerDir * buckler.checkingMultiplier * combinedVelocity, class'DamageType');
				buckler.TriggerEffectEvent('BucklerCheck');
			}
		}
	}
}

// add impulse to character - only works when in fusion physics
// note: impulse is an instantaneous change in momentum, ie. its units are mass*velocity

simulated function addImpulse(Vector impulse)
{
    if (Physics==PHYS_Movement)
        movementObject.addImpulse(impulse);
}

simulated function setVelocity(Vector newVelocity)
{
	if (Physics==PHYS_Movement)
		movementObject.setVelocity(newVelocity);
}


// updated view bob for fusion movement

function CheckBob(float DeltaTime, vector Y)
{
	local float Speed;

    if (physics!=PHYS_Movement)
        super.CheckBob(DeltaTime, Y);

    if( !bWeaponBob )
    {
		BobTime = 0;
		WalkBob = Vect(0,0,0);
        return;
    }
 	Bob = FClamp(Bob, -0.01, 0.01);

	speed = vsize(velocity);

	if (movement==MovementState_SPRINT || Movement==MovementState_RUN || Movement==MovementState_WALK || Movement==MovementState_SLIDE || Movement==MovementState_STOP  || Movement==MovementState_STAND)
	{
		if ( speed < 10 )
			BobTime += 0.2 * DeltaTime;
		else
			BobTime += DeltaTime * (0.3 + 0.7 * speed/GroundSpeed);
		WalkBob = Y * Bob * speed * sin(8 * BobTime);
		AppliedBob = AppliedBob * (1 - FMin(1, 16 * deltatime));
		WalkBob.Z = AppliedBob;
		if ( speed > 10 )
			WalkBob.Z = WalkBob.Z + 0.75 * Bob * speed * sin(16 * BobTime);
		if ( LandBob > 0.01 )
		{
			AppliedBob += FMin(1, 16 * deltatime) * LandBob;
			LandBob *= (1 - 8*Deltatime);
		}
	}
	else if (movement==MovementState_SWIM || movement==MovementState_FLOAT)
	{
		WalkBob = Y * Bob *  0.5 * speed * sin(4.0 * Level.TimeSeconds);
		WalkBob.Z = Bob * 1.5 * speed * sin(8.0 * Level.TimeSeconds);
	}
	else
	{
		BobTime = 0;
		WalkBob = WalkBob * (1 - FMin(1, 8 * deltatime));
	}
}

// team
// Get the Character's team object
simulated function TeamInfo team()
{
	if (tribesReplicationInfo == None)
		return Super.team();
	else
		return tribesReplicationInfo.team;
}

function class<TeamInfo> teamClass()
{
	local TeamInfo ti;
	ti = team();

	if (ti == None)
		return None;
	else
		return ti.class;
}

// setTeam
// Sets the Character's team object
function setTeam(TeamInfo info)
{
	local PlayerCharacterController pcc;

	pcc = PlayerCharacterController(Controller);
	if (tribesReplicationInfo != None)
	{
		tribesReplicationInfo.setTeam(info);
		if (tribesReplicationInfo.bTeamChanged)
		{
			tribesReplicationInfo.bTeamChanged = false;
			dispatchMessage(new class'MessageClientChangedTeam'(pcc, info, m_team));
			BroadcastLocalizedMessage(Level.Game.GameMessageClass, 3, playerReplicationInfo,, info);
		}
	}

	Super.setTeam(info);
}

// DAMAGE FUNCTIONS

function bool InGodMode()
{
	return bGodMode || Super.InGodMode();
}

function float getTeamDamagePercentage()
{
	// The Character's teamDamagePercentage overrides value set in TeamInfo if it's anytying
	// other than 0%
	if (self.teamDamagePercentage != 0.0)
		return self.teamDamagePercentage;
	
	return GameInfo(Level.Game).playerTeamDamagePercentage;
}

function HitPosition CalculateHitPosition(Vector HitLocation)
{
	if ((HitLocation.Z - Location.Z) >= HeadHeight)
		return HP_HEAD;

	if (motor != None)
	{
		if (((Location - HitLocation) Dot Vector(Rotation)) < 0)
			return HP_FRONT;
		else
			return HP_BACK;
	}

	return HP_IGNORE;
}

function PostTakeDamage( float Damage, Pawn instigatedBy, Vector hitlocation, 
						 Vector momentum, class<DamageType> damageType, optional float projectileFactor)
{
	local float actualDamage;
	local bool bAlreadyDead;
	local Controller Killer;
	local Rook attackerRook;
	local HitPosition hp;
	local int minimumTeamDamageHealth;
	local float positiveDamageAmount;
	local ModeInfo mode;
	local Vehicle vehicle;
	local Rook mount;
	
	local class<ProjectileDamageType> projectileDamageType;

	if ( Role < ROLE_Authority )
	{
		//log(self$" client damage type "$damageType$" by "$instigatedBy);
		return;
	}

    // scale crushing damage from same team vehicles

    vehicle = Vehicle(instigatedBy);

    if (class<MovementCrushingDamageType>(damageType)!=none && vehicle!=None)
    {
        // check if vehicle on same team and scale crushing damage by modifier
        
        if (vehicle.lastOccupantTeam!=None && team()!=none && vehicle.lastOccupantTeam==team())
            damage *= VehicleTeamCrushingDamageModifier;    
    }
	
	// do nothing if a hidden vehicle occupant
	if (bHiddenVehicleOccupant)
		return;
		
	bAlreadyDead = (Health <= 0);
	mode = ModeInfo(Level.Game);
	actualDamage = Damage;

	if (damageType.static.doesPositionDamage())
	{
		hp = CalculateHitPosition(hitlocation);

		switch (hp)
		{
		case HP_HEAD:
			actualDamage *= damageType.static.getHeadDamageModifier();

			if (mode != None)
				mode.OnHeadShot(instigatedBy, self, damageType, actualDamage);
			break;
		case HP_BACK:
			actualDamage *= damageType.static.getBackDamageModifier();

			if (mode != None)
				mode.OnBackstab(instigatedBy, self, damageType, actualDamage);
			break;	
		}
	}

	if (shieldActive)
		actualDamage = actualDamage * (1.0 - shieldFractionDamageBlocked);

	if (personalShieldActive())
	{
		actualDamage = personalShield.applyDamage(actualDamage, health);
	}

	attackerRook = Rook(instigatedBy);

	if (instigatedBy == self)
		removeTempInvincibility();

	if (!InGodMode() && !bTempInvincible)
	{
		// Enforce team damage exclusivity (if specified, only someone on a certain team can affect this Character)
		if (attackerRook != None && team() != None && attackerRook.team() != None && (team().onlyDamagedByTeam == None || attackerRook.team() == team().onlyDamagedByTeam))
		{
			minimumTeamDamageHealth = healthMaximum * getTeamDamagePercentage();
			// Apply damage if it's enemy damage or self-inflicted
			if (!team().isFriendlyRook(attackerRook) || attackerRook == self)
			{
				ApplyDamage(instigatedBy, actualDamage);

				if (attackerRook != self && mode != None)
				{
					positiveDamageAmount = actualDamage;

					// Only report the amount of damage above what it took to kill
					if (Health < 0)
						positiveDamageAmount += Health;
					mode.OnPlayerDamage(instigatedBy, self, damageType, positiveDamageAmount);
				}
			}
			// Otherwise, only apply damage if health is above the minimum percentage
			else if (Health > minimumTeamDamageHealth)
			{
				ApplyDamage(instigatedBy, actualDamage);

				// If the friendly fire is not self-inflicted, clamp health if applicable
				if (self != attackerRook)
				{
					// Enforce team damage percentage by clamping
					if (Health / healthMaximum < getTeamDamagePercentage())
						Health = minimumTeamDamageHealth;
				}
			}
		}
		else if (team()!=none && team().onlyDamagedByTeam != None && !bAlreadyDead)     // glenn: safe to push around team ragdolls for fun
		{
			// Otherwise, if onlyDamagedByTeam has been set, get rid of momentum to prevent people from affecting this
			// Character at all
			
			momentum = vect(0,0,0);
		}
		else
			ApplyDamage(instigatedBy, actualDamage);
	}

	if ( HitLocation == vect(0,0,0) )
		HitLocation = Location;
	if ( bAlreadyDead )
	{
		Warn(self$" took regular damage "$damagetype$" from "$instigatedby$" while already dead at "$Level.TimeSeconds);
		ChunkUp(Rotation, DamageType);
		return;
	}

	if ( damageType == None )
		Warn(self @ "damageType is None; applying" @ actualDamage @ "damage from" @ InstigatedBy @ "at" @ Level.TimeSeconds);
	else
		PlayHit(actualDamage,InstigatedBy, hitLocation, damageType, Momentum);
	if ( Health <= 0 )
	{
		// give vehicle an opportunity to boot us before we ragdoll
		mount = getMount();
		if (mount != None)
		{
			vehicle = Vehicle(mount);
			if (vehicle != None)
			{
				vehicle.driverLeave(true, vehicle.getOccupantPositionIndex(self));

				// user tear off location as client may still think we are in the vehicle when we die
				TearOffLocation = Location;
				bTearOffLocationValid = true;
			}
		}

		// Set TRI health here since it won't get properly set in Tick() on death
		if (tribesReplicationInfo != None)
		{
			tribesReplicationInfo.health = Health;
		}

        // glenn: remove fusion collision response for movement damage to ensure correct ragdoll impact

        if ( ClassIsChildOf(damageType, class'MovementCollisionDamageType'))
            momentum = movementOldVelocity - Velocity;

		// pawn died
		if (instigatedBy!=None)
			Killer = instigatedBy.GetKillerController();
			
		TearOffMomentum = momentum;
			
		Died(Killer, damageType, HitLocation);

		// play death sound
		PlayDeathSound( ClassIsChildOf( damageType, class'MovementCollisionDamageType' ), flameDamagePerSecond > 0 );
	}
	else
	{
	    // knockback without death
	
	    // scale knockback in movement physics
    	
	    if (Physics==PHYS_Movement)
    	    momentum *= movementKnockbackScale;
        	
        // scale based on projectile alive knockback scale
        	
	    projectileDamageType = class<ProjectileDamageType>(damageType);

	    if (projectileDamageType!=none)
	        momentum *= 1.0 - projectileFactor;
	
		unifiedAddImpulse(momentum);
		
		if ( Controller != None )
			Controller.NotifyTakeHit(instigatedBy, HitLocation, actualDamage, DamageType, Momentum);

		// play hurt sounds
		PlayHurtSound(actualDamage);
	}
	MakeNoise(1.0);

	// Hit feedback for character objects
	if(Character(instigatedBy) != None && Character(instigatedBy) != self && ! bAlreadyDead)
		Character(instigatedBy).OnHitObject(self);

	generateAISpeechEvents( attackerRook );
}

simulated function PlayHurtSound(int actualDamage)
{
	if (Level.NetMode != NM_Client)
		clientPainType = CLIENTPAIN_Hurt;

	if ( actualDamage > 0 )
	{
		if ( actualDamage >= DAMAGE_LARGE )
		{
			if (Level.NetMode != NM_Standalone && Level.NetMode != NM_Client)
			{
				if (PlayerCharacterController(Controller) != None)
					PlayerCharacterController(Controller).PlayPainSound(CLIENTPAIN_BigHurt);
			}

			PlayMovementSpeech( 'HurtLarge' );
		}
		else
		{
			if (Level.NetMode != NM_Standalone && Level.NetMode != NM_Client)
			{
				if (PlayerCharacterController(Controller) != None)
					PlayerCharacterController(Controller).PlayPainSound(CLIENTPAIN_Hurt);
			}

			PlayMovementSpeech( 'Hurt' );
		}
	}
}

simulated function PlayDeathSound(bool bCratered, bool bFlame)
{
	if ( bFlame )
	{
		PlayMovementSpeech( 'DeathScream' );

		if (Level.NetMode != NM_Standalone && Level.NetMode != NM_Client)
		{
			if (PlayerCharacterController(Controller) != None)
				PlayerCharacterController(Controller).PlayPainSound(CLIENTPAIN_Burnt);
			
			clientPainType = CLIENTPAIN_Burnt;
		}
	}
	else if ( bCratered )
	{
		PlayMovementSpeech( 'DeathCrater' );

		if (Level.NetMode != NM_Standalone && Level.NetMode != NM_Client)
		{
			if (PlayerCharacterController(Controller) != None)
				PlayerCharacterController(Controller).PlayPainSound(CLIENTPAIN_Cratered);

			clientPainType = CLIENTPAIN_Cratered;
		}
	}
	else
	{
		PlayMovementSpeech( 'Death' );

		if (Level.NetMode != NM_Standalone && Level.NetMode != NM_Client)
		{
			if (PlayerCharacterController(Controller) != None)
				PlayerCharacterController(Controller).PlayPainSound(CLIENTPAIN_Death);

			clientPainType = CLIENTPAIN_Death;
		}
	}
}

//---------------------------------------------------------------------
// Equipment functions

// equipmentHead
function Equipment equipmentHead()
{
	return m_equipmentHead;
}

// equipmentTail
function Equipment equipmentTail()
{
	local Equipment e;

	e = m_equipmentHead;
	while (e != None && e.next != None)
		e = e.next;

	return e;
}

function HandGrenade newGrenades(class<HandGrenade> grenadeClass)
{
	if (altWeapon != None)
		altWeapon.Destroy();

	addGrenades(new grenadeClass(self));

	return HandGrenade(altWeapon);
}

function addGrenades(HandGrenade newGrenades)
{
	altWeapon = newGrenades;

	if (altWeapon == None)
		return;

	if (altWeapon.Owner != self)
		altWeapon.SetOwner(self);

	altWeapon.Instigator = self;

	altWeapon.gotoHeldState();

	dispatchMessage(new class'MessageEquipmentPickedUp'(newGrenades.Label, newGrenades.class));
}

// newPack
function Pack newPack(class<Pack> packClass)
{
	local Pack result;
	
	result = Pack(newEquipment(packClass));
	pack = result;

	if (pack != None)
		heldPackClass = pack.class;
	else
		heldPackClass = None;

	return result;
}

// addPack
function addPack(Pack newPack)
{	
	addEquipment(newPack);
	pack = newPack;

	if (pack != None)
		heldPackClass = pack.class;
	else
		heldPackClass = None;

	PlayEffect("CharacterAddPack");
}

simulated function putInWeaponSlot(Weapon w)
{
	local int i;

	if (w == altWeapon || w == fallbackWeapon)
		return;

	// Check if the weapon is already in a slot
	for (i = 0; i < NUM_WEAPON_SLOTS; ++i)
		if (weaponSlots[i] == w)
			return;

	for (i = 0; i < NUM_WEAPON_SLOTS; ++i)
	{
		if (weaponSlots[i] == None)
		{
			weaponSlots[i] = w;
			return;
		}
	}
}

simulated function removeFromWeaponSlot(Weapon w)
{
	local int i;

	if (w == altWeapon || w == fallbackWeapon)
		return;

	for (i = 0; i < NUM_WEAPON_SLOTS; ++i)
	{
		if (weaponSlots[i] == w)
		{
			weaponSlots[i] = None;
			return;
		}
	}
}

// newEquipment
function Equipment newEquipment(class<Equipment> itemClass)
{
	local Equipment item;

	item = spawn(itemClass, self);

	addEquipment(item);

	return item;
}

// addEquipment
function addEquipment(Equipment item)
{
	if (item.Owner != self)
		item.SetOwner(self);

	item.Instigator = self;

	item.next = m_equipmentHead;
	item.prev = None;

	if (m_equipmentHead != None)
		m_equipmentHead.prev = item;

	m_equipmentHead = item;

	item.startHeldByCharacter(self);

	item.gotoHeldState();

	PlayEffect("CharacterAddEquipment");

	dispatchMessage(new class'MessageEquipmentPickedUp'(item.Label, item.class));
}

// removeEquipment
function removeEquipment(Equipment item)
{
	local Equipment e;

	e = m_equipmentHead;
	while (e != None)
	{
		if (e == item)
		{
			if (e.prev != None)
				e.prev.next = item.next;
			else
				m_equipmentHead = item.next;

			if (e.next != None)
				e.next.prev = item.prev;

			if (item == weapon)
				weapon = None;
			if (item == altWeapon)
				altWeapon = None;

			item.endHeldByCharacter(self);

			dispatchMessage(new class'MessageEquipmentDropped'(item.Label, item.class));

			return;
		}

		e = e.next;
	}

	PlayEffect("CharacterRemoveEquipment");
}

// nextEquipment
// Returns the next piece of equipment of the given type, or returns None if no more equipment.
// Searches from the actor referenced by 'from', or if 'from' is None, searches from the start of the list.
function Equipment nextEquipment(Equipment from, optional class<Equipment> type)
{
	local Equipment e;

	if (from == None)
	{
		// start at beginning of list
		e = m_equipmentHead;
	}
	else
	{
		e = from.next;
	}

	while (e != None)
	{
		if (type == None || e.IsA(type.name))
		{
			// HACK: MPCarryableThower is not really a weapon
			if(! (type == class'Weapon' && e.IsA('MPCarryableThrower')))
				return e;
		}

		e = e.next;
	}

	return None;
}

// prevEquipment
// Returns the previous piece of equipment of the given type, or returns None if no more equipment.
// Searches from the actor referenced by 'from', or if 'from' is None, searches from the end of the list.
function Equipment prevEquipment(Equipment from, optional class<Equipment> type)
{
	local Equipment e;

	if (from == None)
	{
		// start at end of list
		e = equipmentTail();
	}
	else
	{
		e = from.prev;
	}

	while (e != None)
	{
		if (type == None || e.IsA(type.name))
		{
			// HACK: MPCarryableThower is not really a weapon
			if(! (type == class'Weapon' && e.IsA('MPCarryableThrower')))
				return e;
		}

		e = e.prev;
	}

	return None;
}

function dropEquipment()
{
	local Array<Equipment> droppables;
	local Equipment e;
	local int i;
	local Vector zAxis;
	local Vector baseVector;
	local float angle;

	e = m_equipmentHead;

	while (e != None)
	{
		if (e.bCanDrop)
			droppables[droppables.length] = e;

		e = e.next;
	}

	if (altWeapon != None)
	{
		if (altWeapon.bCanDrop)
			droppables[droppables.length] = altWeapon;

		altWeapon = None;
	}

	zAxis.Z = 1.0;
	baseVector.X = 300.0;
	angle = (2 * Pi) / droppables.length;

	for (i = 0; i < droppables.length; ++i)
	{
		droppables[i].GotoState('Dropped');
		droppables[i].Velocity += QuatRotateVector(QuatFromAxisAndAngle(zAxis, angle * i), baseVector);
		removeEquipment(droppables[i]);
	}
}

// destroyEquipment
function destroyEquipment()
{
	local Equipment e, d;

	e = m_equipmentHead;
	while (e != None)
	{
		d = e;
        e = e.next;

		d.endHeldByCharacter(self);

		d.Destroy();
	}
	m_equipmentHead = None;

	weapon = None;
	pack = None;
	deployable = None;

	if (altWeapon != None)
	{
		altWeapon.Destroy();
		altWeapon = None;
	}

	destroyFallbackWeapon();
}

function int numWeaponsCarried()
{
	local int count;
	local int i;

	count = 0;

	for (i = 0; i < NUM_WEAPON_SLOTS; ++i)
		if (weaponSlots[i] != None)
			++count;

	return count;
}

function int numHealthKitsCarried()
{
	local int count;
	local Equipment e;

	count = 0;
	e = m_equipmentHead;

	while (e != None)
	{
		if (e.IsA('HealthKit'))
			++count;

		e = e.next;
	}

	return count;
}

// give default weapon to AI
function giveDefaultWeapon()
{
	local Weapon w;

	w = Weapon( nextEquipment( None, class'Spinfusor' ));	// for now: just pick spinfusor if it's available

	if ( w == None )
		w = Weapon( nextEquipment( None, None ));			// and pick the first weapon in the list if not

	//w = Weapon( nextEquipment( None, class'Chaingun' ));	// debug
	//w = Weapon( nextEquipment( None, class'GrenadeLauncher' ));	//debug

	if ( w != None )
	{
		motor.setWeapon(w);
	}
}

// GetKillerController
function Controller GetKillerController()
{
	return lastPossessor;
}

function activatePack()
{
	local Pack workPack;

	// get pack
	workPack = Pack(nextEquipment(None, class'Gameplay.Pack'));

	// do nothing if no pack is carried
	if (workPack == None)
		return;

	PlayEffect("CharacterActivatePack");

	workPack.activate();
}

singular event BaseChange()
{
    // stub it out to do nothing
}

// Set Acceleration
simulated function unifiedSetAcceleration(Vector newAcceleration)
{
    if (movementFrozen && health>0)
        return;

	if (Physics==PHYS_Movement)
		movementObject.setAcceleration(newAcceleration);
    else
        Super.unifiedSetAcceleration(newAcceleration);
}

// Set Position
simulated function unifiedSetPosition(Vector newPosition)
{
    if (movementFrozen && health>0)
        return;

	if (Physics==PHYS_Movement)
	{
		movementObject.setPosition(newPosition);
		setLocation(newPosition);
	}
	else
	    Super.unifiedSetPosition(newPosition);
}

// Set Velocity
simulated function unifiedSetVelocity(Vector newVelocity)
{
    if (movementFrozen && health>0)
        return;

	if (Physics==PHYS_Movement)
	{
		setVelocity(newVelocity);
		Velocity = newVelocity;
	}
	else
	    Super.unifiedSetVelocity(newVelocity);
}

// Add velocity
simulated function unifiedAddVelocity(Vector deltaVelocity)
{
    if (movementFrozen && health>0)
        return;

	if (Physics==PHYS_Movement)
	{
		movementObject.addVelocity(deltaVelocity);
		Velocity += deltaVelocity;
	}
	else
	    Super.unifiedAddVelocity(deltaVelocity);
}

// Add Impulse
simulated function unifiedAddImpulse(Vector impulse)
{
    if (movementFrozen && health>0)
        return;

	if (Physics==PHYS_Movement)
	{
		addImpulse(impulse);
		velocity += impulse / unifiedGetMass();
	}
	else
	    Super.unifiedAddImpulse(impulse);
}

simulated function unifiedAddImpulseAtPosition(Vector impulse, Vector position)
{
    if (movementFrozen && health>0)
        return;

	// calls the existing implementation in Character
	// position is ignored for fusion physics at the moment
	if (Physics==PHYS_Movement)
	{
		addImpulse(impulse);
		velocity += impulse / unifiedGetMass();
	}
	else
	    Super.unifiedAddImpulseAtPosition(impulse, position);
}

// Add Force
simulated function unifiedAddForce(Vector force)
{
    if (movementFrozen && health>0)
        return;

	if (Physics==PHYS_Movement)
		movementObject.addForce(force);        // note: the effect of the force wont be seen until next update
	else
	    Super.unifiedAddForce(force);
}

simulated function unifiedAddForceAtPosition(Vector force, Vector position)
{
    if (movementFrozen && health>0)
        return;

	// position is ignored for fusion physics at the moment
	if (Physics==PHYS_Movement)
		movementObject.addForce(force);        // note: the effect of the force wont be seen until next update
	else
	    Super.unifiedAddForce(force);
}

simulated function float unifiedGetGravity()
{
	if (Physics==PHYS_Movement)
		return gravity();
	else
	    return Super.unifiedGetGravity();
}                                      

// Speech system
function playScriptedSpeech(Name lipsyncLocTag, Name dialogueLocTag, optional bool bPositional)
{
	Level.speechManager.PlayScriptedSpeech(self, lipsyncLocTag, bPositional);
/*
	local Name intLipsyncAnimName;
	local String intDialogue;

	intLipsyncAnimName = Name(LocalizeMapText("LipSync", String(lipsyncLocTag)));

	if (HasLIPSincAnim(intLipsyncAnimName))
		PlayLIPSincAnim(intLipsyncAnimName);

	intDialogue = LocalizeMapText("Dialogue", String(dialogueLocTag));
	// TODO: Send subtitle dialogue to message window in the HUD, for now just log it
	Log(intDialogue);
*/
}

function playPlayerScriptedSpeech(Sound scriptedSpeech, Name dialogueLocTag)
{
	local String intDialogue;

	PlaySound(scriptedSpeech, 1.0,,, 1000);

	intDialogue = LocalizeMapText("Dialogue", String(dialogueLocTag));
	// TODO: Send subtitle dialogue to message window in the HUD, for now just log it
	Log(intDialogue);
}

function playDynamicSpeech(Sound dynamicSpeech, Name dialogueLocTag)
{
	local String intDialogue;

	PlaySound(dynamicSpeech, 1.0,,, 1000);

	intDialogue = Localize("DynamicSpeech", String(dialogueLocTag), "Gameplay");
	// TODO: Send subtitle dialogue to message window in the HUD, for now just log it
	Log(intDialogue);
}

function playQuickChatSpeech()
{
}

// End speech system


// Grappler related stuff

function addGrapplerCharacter(Character c)
{
	local int i;

	for (i = 0; i < grapplerCharacters.length; ++i)
		if (grapplerCharacters[i] == c)
			return;

	grapplerCharacters[grapplerCharacters.length] = c;
}

function removeGrapplerCharacter(Character c)
{
	local int i;

	for (i = 0; i < grapplerCharacters.length; ++i)
	{
		if (grapplerCharacters[i] == c)
		{
			grapplerCharacters.remove(i, 1);
			return;
		}
	}
}

simulated function tickGrappler(float Delta)
{
	if (proj != None)
	{
		if (rope == None)
			createRope();

		updateGrapplerRopeThirdPerson();

		if (!shouldBreakRope())
		{
			if (bAttached && bReelIn)
				ropeNaturalLength = FMax(0.0, ropeNaturalLength - grapplerClass.default.reelinLengthRate * Delta);
		}
		else 
			breakGrapple();
	}
	else if (rope != None)
	{
		rope.Destroy();
		rope = None;
	}
}

simulated function updateGrapplerRopeEquippedFirstPerson()
{
	if (proj != None)
	{
		if (rope == None)
			createRope();

		if (rope != None)
		{
			rope.Move(weapon.GetBoneCoords(weapon.projectileSpawnBone).origin - rope.Location);
			rope.SetRotation(Rotator(proj.Location - rope.Location));
			updateRopeDrawScale();
		}
	}
}

simulated function updateGrapplerRopeThirdPerson()
{
	local Vector locationOffset;

	if (rope != None)
	{
		if (weapon == None || !weapon.bIsFirstPerson || Grappler(weapon) == None)
		{
			locationOffset = Location;
			locationOffset.Z += 20;
			rope.Move(locationOffset - rope.Location);
		}

		rope.SetRotation(Rotator(proj.Location - rope.Location));

		updateRopeDrawScale();
	}
}

simulated function createRope()
{
	rope = new grapplerClass.default.ropeClass;

	if (bAttached)
	{
		rope.PlayAnim('Straight');
	}
	else
	{
		rope.AnimBlendParams(1, 0.0);
		rope.AnimBlendToAlpha(1, 1.0, 2.0);

		rope.PlayAnim('Flap', 2.0);
		rope.PlayAnim('Straight',,,1);
	}
}

function bool shouldBreakRope()
{
	local float ropeLength;

	if (Level.NetMode == NM_Client)
		return false;

	ropeLength = VSize(proj.Location - rope.Location);

	if (Controller == None)
	{
		//Log("!!!!!!!!Break grapple: Controller was None");
		return true;
	}

	if (bAttached && (proj.Base == None || proj.Base.bDeleteMe))
	{
		//Log("!!!!!!!!Break grapple: Projectiles base was None or destroyed");
		return true;
	}

	if (ropeLength > grapplerClass.default.maxRopeLength)
	{
		//Log("!!!!!!!!Break grapple: Rope got too long");
		return true;
	}

	if (ropeObstructionTrace(ropeLength - grapplerClass.default.ropeNonCollisionLength))
	{
		//Log("!!!!!!!!Break grapple: Rope was obstructed");
		return true;
	}

	return false;
}

// Returns true if the rope is obstructed, false otherwise
native function bool ropeObstructionTrace(float traceLength);

simulated function updateRopeDrawScale()
{
	local Vector newDrawScale3D;

	newDrawScale3D = grapplerClass.default.ropeClass.default.DrawScale3D;
	newDrawScale3D.X = VSize(rope.Location - proj.Location) / ROPE_MESH_LENGTH;

	rope.SetDrawScale3D(newDrawScale3D);
}

function attachGrapple()
{
	bAttached = true;
	playAttachedAnim();

	if (rope != None)
		ropeNaturalLength = VSize(proj.Location - rope.Location);
	else
		ropeNaturalLength = 0.0;
}

simulated function PlayDying(class<DamageType> DamageType, vector HitLoc)
{	
	// remove third person packs
	if (Level.NetMode == NM_Client)
		destroyThirdPersonMesh();

	super.PlayDying(DamageType, HitLoc);
}

simulated function playAttachedAnim()
{
	if (rope != None)
	{
		rope.StopAnimating(true);
		rope.PlayAnim('Straight');
	}

	if (Grappler(weapon) != None)
		grapplerClass.default.animClass.static.playEquippableAnim(weapon, 'Attach');
}

simulated event BreakGrapple()
{
    // call this when the grapple breaks because it will play the breaking sound
    
    detachGrapple();
}

simulated function detachGrapple(optional bool bNoRemove)
{
	if (bAttached && Grappler(weapon) != None)
		grapplerClass.default.animClass.static.playEquippableAnim(weapon, 'Deattach');

	bAttached = false;

	if (proj != None)
	{
		if (Character(proj.Base) != None && !bNoRemove)
			Character(proj.Base).removeGrapplerCharacter(self);

		if (Level.NetMode != NM_Client)
			proj.Destroy();

		proj = None;
	}

	if (rope != None)
	{
		rope.Destroy();
		rope = None;
	}
}

simulated event bool GetGrappleData(out Actor attachedTo, out Vector attachedPoint, out float naturalLength)
{
	if (bAttached && proj != None && proj.Base != None)
	{
		if (proj.Base.bWorldGeometry || MPCarryableContainer(proj.Base) != None)
		{
			attachedTo = None;
			attachedPoint = proj.Location;
		}
		else
		{
			attachedTo = proj.Base;
			attachedPoint = Vect(0.0, 0.0, 0.0);
		}

        naturalLength = ropeNaturalLength;

		return true;
	}

	return false;
}

simulated event GetOtherGrappleCount(out int count)
{
    count = grapplerCharacters.length;
}

simulated event GetOtherGrappleData(int index, out Character other, out float naturalLength)
{
    // note: other will always be a character (only characters can be the source of a grapple!)

    other = grapplerCharacters[index];

	if (other != None)
		naturalLength = other.ropeNaturalLength;
}

simulated event SetNaturalRopeLength(float length)
{
    ropeNaturalLength = length;
}

// End grappler related stuff

//
// This is the main version of GetRadarInfoClass, because most items to be 
// displayed on the radar will be of type rook
//
simulated function class GetRadarInfoClass()
{
	if(armorClass != None)
		return armorClass.default.radarInfoClass;

	return super.GetRadarInfoClass();
}

// updateUserSkin
// sets the skin on the character specified in the tribesReplicationInfo
simulated function updateUserSkin()
{
	// apply skin
	if (tribesReplicationInfo != None)
	{
		if (tribesReplicationInfo.userSkinClass != userSkinClass)
		{
			userSkinClass = tribesReplicationInfo.userSkinClass;
			userSkinClass.static.applyToCharacter(self);
		}

		if (jetpack != None && tribesReplicationInfo.userSkinClass != jetpack.userSkinClass)
		{
			jetpack.userSkinClass = tribesReplicationInfo.userSkinClass;
			jetpack.userSkinClass.static.applyToJetpack(jetpack);
		}

		if (arms != None && tribesReplicationInfo.userSkinClass != arms.userSkinClass)
		{
			arms.userSkinClass = tribesReplicationInfo.userSkinClass;
			arms.userSkinClass.static.applyToArms(arms);
		}
	}
}

// projectiles should not hit us if shot by a turret we are driving
simulated event bool ShouldProjectileHit(Actor projInstigator)
{
	local Turret t;
	local Vehicle vehicle;
	local VehicleMountedTurret vehicleTurret;

	if (!Super.ShouldProjectileHit(projInstigator))
		return false;

	t = Turret(projInstigator);
	if (t != None)
	{
		if (t.driver == self)
			return false;
	}

	// handle case character is an occupant of a vehicle
	vehicle = Vehicle(projInstigator);
	if (vehicle == None)
	{
		vehicleTurret = VehicleMountedTurret(projInstigator);
		if (vehicleTurret != None)
			vehicle = vehicleTurret.ownerVehicle;
	}
	if (vehicle != None && vehicle.isOccupant(self))
		return false;

	return true;
}

simulated function Touch(Actor other)
{
    if (other.bBlockPlayers)
        wake();
}

simulated function UnTouch(Actor other)
{
    if (other.bBlockPlayers)
        wake();
}

simulated function bool isZoomed()
{
	return bZoomed && bCanZoom;
}

simulated function setZoomed(bool b)
{
	bZoomed = b;
}

simulated event bool isFemale()
{
    local PlayerCharacterController player;

    player = PlayerCharacterController(controller);

    if (player==none)
        return false;
        
    if (player.isSinglePlayer())
        return bIsFemale;
    else
        return TribesReplicationInfo.bIsFemale;
}

simulated function int getModifiedAmmo(int baseAmmo)
{
	return baseAmmo;
}

simulated function int getMaxAmmo(class<Weapon> wc)
{
	return getModifiedAmmo(armorClass.static.maxAmmo(wc));
}

native function bool isTouchingEnergyBarrier();

simulated event bool ShouldActorsBlockSplash()
{
	return Turret(getMount()) != None;
}

function KilledBy( pawn EventInstigator )
{
	local Controller Killer;

	Health = 0;
	if ( EventInstigator != None )
		Killer = EventInstigator.Controller;

	if( armorClass != None && armorClass.default.suicideDamageTypeClass != None )
		Died( Killer, armorClass.default.suicideDamageTypeClass, Location );
	else
		Died( Killer, class'Suicided', Location );
}

function teleportTo(Vector newLoc, Rotator newRot)
{
	// un-grapple if we're grappled
	while (grapplerCharacters.length > 0)
	{
		grapplerCharacters[0].detachGrapple(true);
		grapplerCharacters.remove(0, 1);
	}
	detachGrapple();

	unifiedSetPosition(newLoc);
	unifiedSetRotation(newRot);
}

defaultproperties
{
	bNetNotify					    = true
	bPhysicsAnimUpdate			    = true
	bNoRepMesh					    = false

	energy						    = 100
	energyMinimum				    = 10
	energyMaximum				    = 100
	energyRechargeScale             = 1
	
	weaponBone					    = "bip01 r hand"

	Mesh						    = SkeletalMesh'LightArmour.PhoenixLight'

	hudType						    = "TribesGUI.TribesCharacterHUD"

	CharacterName					= ""

	bActorShadows				    = 1
	bWeaponBob					    = 1

	Physics						    = PHYS_Movement
 
	MovementObjectClass			    = "Gameplay.CharacterMovementObject"

    eyeBoneName                     = "BIP01 HEAD"

	alertness					    = Alertness_Combat

	jetpackBone					    = jetpack

	regenerationActive			    = false

	regenerationRateHealthPerSecond	= 5

	packLeftBone				    = packLeft
	packRightBone				    = packRight

	shieldActive				    = false
	
    peripheralVision                = 0.5           // 60 degrees either side for a total of 120 degrees
	SightRadius						= 6000.0
	VisionUpdateRange			    = (Min=0.6,Max=0.8)

    effectLogging                   = false
    
	playerControllerState			= "CharacterMovement"

	grapplerClass					= class'Gameplay.Grappler'
	grapplerRetentionScale			= 0.2

	walkAnimationSpeed              = 100
	runAnimationSpeed               = 300
	sprintAnimationSpeed            = 500
	
	neutralAimAnimationRootBone     = "BIP01 HEAD"
	alertAimAnimationRootBone       = "BIP01 HEAD"
	combatAimAnimationRootBone      = "BIP01 NECK"
	upperBodyAnimationRootBone      = "BIP01 SPINE1"
	armAnimationRootBone            = "BIP01 R CLAVICLE"
	
	bApplyHealthFilter				= true	

	bTriggerEffectEventsBeforeGameStarts	= true
	
	bBlockHavok = true
	bCollideActors = true

	bDisableHavokCollisionWhenAttached = false

	bHavokCharacterCollisions=true
	bHavokCharacterCollisionExtraRadius=75
	
	movement = MovementState_Stand

	invicibilityMaterial = Shader'FX.ScreenShader'

	packDrawScale = 1

	bNeedPostRenderCallback = true	// required for DoIdentify to work
	
	movementKnockbackScale = 1.0
	
	vehicleTeamCrushingDamageModifier = 0
	
	weaponNotHeldTime = 1.0         // required for initial not holding weapon in SP
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: �t 9.9.2004 16:25:32.000 - Creation time: st 23.5.2018 00:10:42.723 - Created with UnCodeX