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

Engine.Pawn


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
//=============================================================================
// Pawn, the base class of all actors that can be controlled by players or AI.
// This is a built-in Unreal class and it shouldn't be modified.
//=============================================================================
class Pawn extends Actor 
    abstract
    native;

#exec Texture Import File=Textures\Pawn.pcx Name=S_Pawn Mips=Off Flags=2

//-----------------------------------------------------------------------------
// Pawn variables.

// General flags.
var bool        bBehindView;    // Outside-the-player view.
var bool        bIsPlayer;      // Pawn is a player or a player-bot.
var bool        bJustLanded;    // used by eyeheight adjustment
var bool        bUpAndOut;      // used by swimming 
var bool        bIsWalking;
var const bool  bHitSlopedWall; // used by Physics
var travel bool bNeverSwitchOnPickup;   // if true, don't automatically switch to picked up weapon
var bool        bWarping;       // Set when travelling through warpzone (so shouldn't telefrag)
var bool        bUpdatingDisplay; // to avoid infinite recursion through inventory setdisplay

//AI flags
var(Combat) bool    bCanStrafe;
var(Orders) bool    bFixedStart;
var const bool      bReducedSpeed;      //used by movement nativees
var     bool        bCanJump;
var     bool        bCanWalk;
var     bool        bCanSwim;
var     bool        bCanFly;
var     bool        bCanOpenDoors;
var     bool        bCanDoSpecial;
var     bool        bDrowning;
var const bool      bLOSflag;           // used for alternating LineOfSight traces
var     bool        bFromWall;
var     bool        bHunting;           // tells navigation code that pawn is hunting another pawn,
                                        //	so fall back to finding a path to a visible pathnode if none
                                        //	are reachable
var     bool        bAvoidLedges;       // don't get too close to ledges
var     bool        bStopAtLedges;      // if bAvoidLedges and bStopAtLedges, Pawn doesn't try to walk along the edge at all
var     bool        bJumpOffPawn;       
var     bool        bShootSpecial;
var     bool        bAutoActivate;
var     bool        bIsHuman;           // for games which care about whether a pawn is a human
var     bool        bIsFemale;
var     bool        bIsMultiSkinned;
var     bool        bCountJumps;

// Ticked pawn timers
var     float       SightCounter;   //Used to keep track of when to check player visibility
var     float       PainTime;       //used for getting PainTimer() messages (for Lava, no air, etc.)
var     float       SpeechTime; 

// Physics updating time monitoring (for AI monitoring reaching destinations)
var const   float       AvgPhysicsTime;

// Additional pawn region information.
var PointRegion FootRegion;
var PointRegion HeadRegion;

// Navigation AI
var     float       MoveTimer;
var     Actor       MoveTarget;     // set by movement natives
var     Actor       FaceTarget;     // set by strafefacing native
var     vector      Destination;    // set by Movement natives
var     vector      Focus;          // set by Movement natives
var     float       DesiredSpeed;
var     float       MaxDesiredSpeed;
var(Combat) float   MeleeRange; // Max range for melee attack (not including collision radii)

// Player and enemy movement.
var(Movement) float      GroundSpeed;     // The maximum ground speed.
var(Movement) float      WaterSpeed;      // The maximum swimming speed.
var(Movement) float      AirSpeed;        // The maximum flying speed.
var(Movement) float      AccelRate;       // max acceleration rate
var(Movement) float      JumpZ;             // vertical acceleration w/ jump
var(Movement) float      MaxStepHeight;   // Maximum size of upward/downward step.
var(Movement) float      AirControl;        // amount of AirControl available to the pawn

// AI basics.
var     float       MinHitWall;     // Minimum HitNormal dot Velocity.Normal to get a HitWall from the
                                    // physics
var()   byte        Visibility;      //How visible is the pawn? 0 = invisible. 
                                    // 128 = normal.  255 = highly visible.
var     float       Alertness; // -1 to 1 ->Used within specific states for varying reaction to stimuli 
var     float       Stimulus; // Strength of stimulus - Set when stimulus happens, used in Acquisition state 
var(AI) float       SightRadius;     //Maximum seeing distance.
var(AI) float       PeripheralVision;//Cosine of limits of peripheral vision.
var(AI) float       HearingThreshold;  //Minimum noise loudness for hearing
var     vector      LastSeenPos;        // enemy position when I last saw enemy (auto updated if EnemyNotVisible() enabled)
var     vector      LastSeeingPos;      // position where I last saw enemy (auto updated if EnemyNotVisible enabled)
var     float       LastSeenTime;
var     Pawn        Enemy;

// Player info.
var travel Weapon       Weapon;        // The pawn's current weapon.
var Weapon              PendingWeapon;  // Will become weapon once current weapon is put down
var travel Inventory    SelectedItem;   // currently selected inventory item

// Movement.
var rotator         ViewRotation;   // View rotation.
var vector          WalkBob;
var() float         BaseEyeHeight;  // Base eye height above collision center.
var float           EyeHeight;      // Current eye height, adjusted for bobbing and stairs.
var const   vector  Floor;          // Normal of floor pawn is standing on (only used
                                    //	by PHYS_Spider)
var float           SplashTime;     // time of last splash

// View
var float        OrthoZoom;     // Orthogonal/map view zoom factor.
var() float      FovAngle;      // X field of view angle in degrees, usually 90.

// Player game statistics.
var int         DieCount, ItemCount, KillCount, SecretCount, Spree;

//Health
var() travel int      Health;          // Health: 100 = normal maximum

// Inherent Armor (for creatures).
var() name  ReducedDamageType; //Either a damagetype name or 'All', 'AllEnvironment' (Burned, Corroded, Frozen)
var() float ReducedDamagePct;

// Inventory to drop when killed (for creatures)
var() class<inventory> DropWhenKilled;

// Zone pain
var(Movement) float     UnderWaterTime;     //how much time pawn can go without air (in seconds)

var(AI) enum EAttitude  //important - order in decreasing importance
{
    ATTITUDE_Fear,      //will try to run away
    ATTITUDE_Hate,      // will attack enemy
    ATTITUDE_Frenzy,    //will attack anything, indiscriminately
    ATTITUDE_Threaten,  // animations, but no attack
    ATTITUDE_Ignore,
    ATTITUDE_Friendly,
    ATTITUDE_Follow     //accepts player as leader
} AttitudeToPlayer; //determines how creature will react on seeing player (if in human form)

var(AI) enum EIntelligence //important - order in increasing intelligence
{
    BRAINS_NONE, //only reacts to immediate stimulus
    BRAINS_REPTILE, //follows to last seen position
    BRAINS_MAMMAL, //simple navigation (limited path length)
    BRAINS_HUMAN   //complex navigation, team coordination, use environment stuff (triggers, etc.)
}   Intelligence;

var(AI) float       Skill;          // skill, scaled by game difficulty (add difficulty to this value)	
var     actor       SpecialGoal;    // used by navigation AI
var     float       SpecialPause;

// Sound and noise management
var const   vector      noise1spot;
var const   float       noise1time;
var const   pawn        noise1other;
var const   float       noise1loudness;
var const   vector      noise2spot;
var const   float       noise2time;
var const   pawn        noise2other;
var const   float       noise2loudness;
var         float       LastPainSound;

// chained pawn list
var const   pawn        nextPawn;

// Common sounds
var(Sounds) sound   HitSound1;
var(Sounds) sound   HitSound2;
var(Sounds) sound   Land;
var(Sounds) sound   Die;
var(Sounds) sound   WaterStep;

// Input buttons.
var input byte
    bZoom, bRun, bLook, bDuck, bSnapLevel,
    bStrafe, bFire, bAltFire, bFreeLook, 
    bExtra0, bExtra1, bExtra2, bExtra3;

var(Combat) float CombatStyle; // -1 to 1 = low means tends to stay off and snipe, high means tends to charge and melee
var NavigationPoint home; //set when begin play, used for retreating and attitude checks
 
var name NextState; //for queueing states
var name NextLabel; //for queueing states

var float SoundDampening;
var float DamageScaling;

var(Orders) name AlarmTag; // tag of object to go to when see player
var(Orders) name SharedAlarmTag;
var Decoration  carriedDecoration;

var Name PlayerReStartState;

var() localized  string MenuName; //Name used for this pawn type in menus (e.g. player selection) 
var() localized  string NameArticle; //article used in conjunction with this class (e.g. "a", "an")

var() byte VoicePitch; //for speech
var() class<VoicePack> VoiceType; //for speech
var float OldMessageTime; //to limit frequency of voice messages

// Route Cache for Navigation
var NavigationPoint RouteCache[16];

// Replication Info
var() class<PlayerReplicationInfo> PlayerReplicationInfoClass;
var PlayerReplicationInfo PlayerReplicationInfo;

replication
{
    // Variables the server should send to the client.
    reliable if( Role==ROLE_Authority )
        Weapon, PlayerReplicationInfo, Health;
    reliable if( Role==ROLE_Authority && bNetOwner )
         bIsPlayer, CarriedDecoration, SelectedItem,
         GroundSpeed, WaterSpeed, AirSpeed, AccelRate, JumpZ, MaxStepHeight, AirControl,
         bBehindView;
    unreliable if( (Role==ROLE_Authority && bNetOwner && bIsPlayer && bNetInitial) || bDemoRecording )
        ViewRotation;
    unreliable if( Role==ROLE_Authority && bNetOwner )
         MoveTarget;
    unreliable if( Role==ROLE_Authority )
         bCanFly;
    reliable if( bDemoRecording )
        EyeHeight;

    // Functions the server calls on the client side.
    reliable if( Role==ROLE_Authority && RemoteRole==ROLE_AutonomousProxy )
        ClientDying, ClientReStart, ClientGameEnded, ClientSetRotation, ClientSetLocation;
    unreliable if( Role==ROLE_Authority && !bDemoRecording )
        ClientHearSound;
    reliable if ( Role == ROLE_Authority && !bDemoRecording )
        ClientMessage, TeamMessage, ClientVoiceMessage;
    unreliable if( Role<ROLE_Authority )
        SendVoiceMessage, NextItem, SwitchToBestWeapon, bExtra0, bExtra1, bExtra2, bExtra3, TeamBroadcast;

    // Input sent from the client to the server.
    unreliable if( Role<ROLE_AutonomousProxy )
        bZoom, bRun, bLook, bDuck, bSnapLevel, bStrafe;
}

// Latent Movement.
//Note that MoveTo sets the actor's Destination, and MoveToward sets the
//actor's MoveTarget.  Actor will rotate towards destination

native(500) final latent function MoveTo( vector NewDestination, optional float speed);
native(502) final latent function MoveToward(actor NewTarget, optional float speed);
native(504) final latent function StrafeTo(vector NewDestination, vector NewFocus);
native(506) final latent function StrafeFacing(vector NewDestination, actor NewTarget);
native(508) final latent function TurnTo(vector NewFocus);
native(510) final latent function TurnToward(actor NewTarget);

// native AI functions
//LineOfSightTo() returns true if any of several points of Other is visible 
// (origin, top, bottom)
native(514) final function bool LineOfSightTo(actor Other); 
// CanSee() similar to line of sight, but also takes into account Pawn's peripheral vision
native(533) final function bool CanSee(actor Other); 
native(518) final function Actor FindPathTo(vector aPoint, optional bool bSinglePath, 
                                                optional bool bClearPaths);
native(517) final function Actor FindPathToward(actor anActor, optional bool bSinglePath, 
                                                optional bool bClearPaths);

native(525) final function NavigationPoint FindRandomDest(optional bool bClearPaths);

native(522) final function ClearPaths();
native(523) final function vector EAdjustJump();

//Reachable returns what part of direct path from Actor to aPoint is traversable
//using the current locomotion method
native(521) final function bool pointReachable(vector aPoint);
native(520) final function bool actorReachable(actor anActor);

/* PickWallAdjust()
Check if could jump up over obstruction (only if there is a knee height obstruction)
If so, start jump, and return current destination
Else, try to step around - return a destination 90 degrees right or left depending on traces
out and floor checks
*/
native(526) final function bool PickWallAdjust();
native(524) final function int FindStairRotation(float DeltaTime);
native(527) final latent function WaitForLanding();
native(540) final function actor FindBestInventoryPath(out float MinWeight, bool bPredictRespawns);

native(529) final function AddPawn();
native(530) final function RemovePawn();

// Pick best pawn target
native(531) final function pawn PickTarget(out float bestAim, out float bestDist, vector FireDir, vector projStart);
native(534) final function actor PickAnyTarget(out float bestAim, out float bestDist, vector FireDir, vector projStart);

// Force end to sleep
native function StopWaiting();

event MayFall(); //return true if allowed to fall - called by engine when pawn is about to fall

simulated event RenderOverlays( canvas Canvas )
{
    if ( Weapon != None )
        Weapon.RenderOverlays(Canvas);
}

function String GetHumanName()
{
    if ( PlayerReplicationInfo != None )
        return PlayerReplicationInfo.PlayerName;
    return NameArticle$MenuName;
}

function SetDisplayProperties(ERenderStyle NewStyle, texture NewTexture, bool bLighting, bool bEnviroMap )
{
    Style = NewStyle;
    texture = NewTexture;
    bUnlit = bLighting;
    bMeshEnviromap = bEnviromap;

    if ( !bUpdatingDisplay && (Inventory != None) )
    {
        bUpdatingDisplay = true;
        Inventory.SetOwnerDisplay();
    }
    if ( Weapon != None )
        Weapon.SetDisplayProperties(Style, Texture, bUnlit, bMeshEnviromap);
    bUpdatingDisplay = false;
}

function SetDefaultDisplayProperties()
{
    Style = Default.Style;
    texture = Default.Texture;
    bUnlit = Default.bUnlit;
    bMeshEnviromap = Default.bMeshEnviromap;

    if ( !bUpdatingDisplay && (Inventory != None) )
    {
        bUpdatingDisplay = true;
        Inventory.SetOwnerDisplay();
    }
    if ( Weapon != None )
        Weapon.SetDisplayProperties(Style, Texture, bUnlit, bMeshEnviromap);
    bUpdatingDisplay = false;
}

//
// Client gateway functions.
//
event ClientMessage( coerce string S, optional name Type, optional bool bBeep );
event TeamMessage( PlayerReplicationInfo PRI, coerce string S, name Type );

event FellOutOfWorld()
{
    Health = -1;
    SetPhysics(PHYS_None);
    Died(None, 'fell', Location);
}

function PlayRecoil(float Rate);

function SpecialFire();

function bool CheckFutureSight(float DeltaTime)
{
    return true;
}

function RestartPlayer();

//
// Broadcast a message to all players, or all on the same team.
//
function TeamBroadcast( coerce string Msg)
{
    local Pawn P;
    local bool bGlobal;

    if ( Left(Msg, 1) ~= "@" )
    {
        Msg = Right(Msg, Len(Msg)-1);
        bGlobal = true;
    }

    if ( Left(Msg, 1) ~= "." )
        Msg = "."$VoicePitch$Msg;

    if ( bGlobal || !Level.Game.bTeamGame )
    {
        if ( Level.Game.AllowsBroadcast(self, Len(Msg)) )
            for( P=Level.PawnList; P!=None; P=P.nextPawn )
                if( P.bIsPlayer )
                    P.TeamMessage( PlayerReplicationInfo, Msg, 'Say' );
        return;
    }
        
    if ( Level.Game.AllowsBroadcast(self, Len(Msg)) )
        for( P=Level.PawnList; P!=None; P=P.nextPawn )
            if( P.bIsPlayer && (P.PlayerReplicationInfo.Team == PlayerReplicationInfo.Team) )
            {
                if ( P.IsA('PlayerPawn') )
                    P.TeamMessage( PlayerReplicationInfo, Msg, 'TeamSay' );
            }
}

//------------------------------------------------------------------------------
// Speech related

function SendVoiceMessage(PlayerReplicationInfo Sender, PlayerReplicationInfo Recipient, name messagetype, byte messageID, name broadcasttype)
{
    local Pawn P;
    local bool bNoSpeak;

    if ( Level.TimeSeconds - OldMessageTime < 2.5 )
        bNoSpeak = true;
    else
        OldMessageTime = Level.TimeSeconds;

    for ( P=Level.PawnList; P!=None; P=P.NextPawn )
    {
        if ( P.IsA('PlayerPawn') )
        {  
            if ( !bNoSpeak )
            {
                if ( (broadcasttype == 'GLOBAL') || !Level.Game.bTeamGame )
                    P.ClientVoiceMessage(Sender, Recipient, messagetype, messageID);
                else if ( Sender.Team == P.PlayerReplicationInfo.Team )
                    P.ClientVoiceMessage(Sender, Recipient, messagetype, messageID);
            }
        }
        else if ( (P.PlayerReplicationInfo == Recipient) || ((messagetype == 'ORDER') && (Recipient == None)) )
            P.BotVoiceMessage(messagetype, messageID, self);
    }
}

function ClientVoiceMessage(PlayerReplicationInfo Sender, PlayerReplicationInfo Recipient, name messagetype, byte messageID);
function BotVoiceMessage(name messagetype, byte MessageID, Pawn Sender);

//***************************************************************
function HandleHelpMessageFrom(Pawn Other);

function FearThisSpot(Actor ASpot);

function float GetRating()
{
    return 1000;
}

function AddVelocity( vector NewVelocity)
{
    if (Physics == PHYS_Walking)
        SetPhysics(PHYS_Falling);
    if ( (Velocity.Z > 380) && (NewVelocity.Z > 0) )
        NewVelocity.Z *= 0.5;
    Velocity += NewVelocity;
}

function ClientSetLocation( vector NewLocation, rotator NewRotation )
{
    local Pawn P;

    ViewRotation      = NewRotation;
    NewRotation.Pitch = 0;
    NewRotation.Roll  = 0;
    SetRotation( NewRotation );
    SetLocation( NewLocation );
}

function ClientSetRotation( rotator NewRotation )
{
    local Pawn P;

    ViewRotation      = NewRotation;
    NewRotation.Pitch = 0;
    NewRotation.Roll  = 0;
    SetRotation( NewRotation );
}

function ClientDying(name DamageType, vector HitLocation)
{
    PlayDying(DamageType, HitLocation);
    GotoState('Dying');
}

function ClientReStart()
{
    //log("client restart");
    Velocity = vect(0,0,0);
    Acceleration = vect(0,0,0);
    BaseEyeHeight = Default.BaseEyeHeight;
    EyeHeight = BaseEyeHeight;
    PlayWaiting();

    if (Region.Zone.bWaterZone)
    {
        if (HeadRegion.Zone.bWaterZone)
                PainTime = UnderWaterTime;
        setPhysics(PHYS_Swimming);
        GotoState('PlayerSwimming');
    }
    else
        GotoState(PlayerReStartState);
}

function ClientGameEnded()
{
    GotoState('GameEnded');
}

//=============================================================================
// Inventory related functions.

function float AdjustDesireFor(Inventory Inv)
{
    return 0;
}

// toss out the weapon currently held
function TossWeapon()
{
    local vector X,Y,Z;
    if ( Weapon == None )
        return;
    GetAxes(Rotation,X,Y,Z);
    Weapon.DropFrom(Location + 0.8 * CollisionRadius * X + - 0.5 * CollisionRadius * Y); 
}   

// The player/bot wants to select next item
exec function NextItem()
{
    local Inventory Inv;

    if (SelectedItem==None) {
        SelectedItem = Inventory.SelectNext();
        Return;
    }
    if (SelectedItem.Inventory!=None)
        SelectedItem = SelectedItem.Inventory.SelectNext(); 
    else
        SelectedItem = Inventory.SelectNext();

    if ( SelectedItem == None )
        SelectedItem = Inventory.SelectNext();
}

// FindInventoryType()
// returns the inventory item of the requested class
// if it exists in this pawn's inventory 

function Inventory FindInventoryType( class DesiredClass )
{
    local Inventory Inv;

    for( Inv=Inventory; Inv!=None; Inv=Inv.Inventory )   
        if ( Inv.class == DesiredClass )
            return Inv;
    return None;
} 

// Add Item to this pawn's inventory. 
// Returns true if successfully added, false if not.
function bool AddInventory( inventory NewItem )
{
    // Skip if already in the inventory.
    local inventory Inv;
    
    // The item should not have been destroyed if we get here.
    assert(NewItem!=None);

    for( Inv=Inventory; Inv!=None; Inv=Inv.Inventory )
        if( Inv == NewItem )
            return false;

    // Add to front of inventory chain.
    NewItem.SetOwner(Self);
    NewItem.Inventory = Inventory;
    Inventory = NewItem;

    return true;
}

// Remove Item from this pawn's inventory, if it exists.
// Returns true if it existed and was deleted, false if it did not exist.
function bool DeleteInventory( inventory Item )
{
    // If this item is in our inventory chain, unlink it.
    local actor Link;
    if ( Item == Weapon )
        Weapon = None;
    if ( Item == SelectedItem )
        SelectedItem = None;
    for( Link = Self; Link!=None; Link=Link.Inventory )
    {
        if( Link.Inventory == Item )
        {
            Link.Inventory = Item.Inventory;
            break;
        }
    }
    Item.SetOwner(None);
}

// Just changed to pendingWeapon
function ChangedWeapon()
{
    local Weapon OldWeapon;

    OldWeapon = Weapon;

    if (Weapon == PendingWeapon)
    {
        if ( Weapon == None )
            SwitchToBestWeapon();
        else if ( Weapon.GetStateName() == 'DownWeapon' ) 
            Weapon.BringUp();
        PendingWeapon = None;
        return;
    }
    if ( PendingWeapon == None )
        PendingWeapon = Weapon;
    PlayWeaponSwitch(PendingWeapon);
    if ( (PendingWeapon != None) && (PendingWeapon.Mass > 20) && (carriedDecoration != None) )
        DropDecoration();
    if ( Weapon != None )
        Weapon.SetDefaultDisplayProperties();
    Weapon = PendingWeapon;
    Inventory.ChangedWeapon(); // tell inventory that weapon changed (in case any effect was being applied)
    if ( Weapon != None )
    {
        Weapon.RaiseUp(OldWeapon);
        if ( (Level.Game != None) && (Level.Game.Difficulty > 1) )
            MakeNoise(0.1 * Level.Game.Difficulty);     
    }
    PendingWeapon = None;
}

//==============
// Encroachment
event bool EncroachingOn( actor Other )
{
    if ( (Other.Brush != None) || (Brush(Other) != None) )
        return true;
        
    if ( (!bIsPlayer || bWarping) && (Pawn(Other) != None))
        return true;
        
    return false;
}

event EncroachedBy( actor Other )
{
    if ( Pawn(Other) != None )
        gibbedBy(Other);
        
}

function gibbedBy(actor Other)
{
    local pawn instigatedBy;

    instigatedBy = pawn(Other);
    if (instigatedBy == None)
        instigatedBy = Other.instigator;
    health = -1000; //make sure gibs
    Died(instigatedBy, 'gibbed', Location);
}

event PlayerTimeOut()
{
    if (Health > 0)
        Died(None, 'suicided', Location);
}

//Base change - if new base is pawn or decoration, damage based on relative mass and old velocity
// Also, non-players will jump off pawns immediately
function JumpOffPawn()
{
    Velocity += 60 * VRand();
    Velocity.Z = 180;
    SetPhysics(PHYS_Falling);
}

function UnderLift(Mover M);

singular event BaseChange()
{
    local float decorMass;

    if ( (base == None) && (Physics == PHYS_None) )
        SetPhysics(PHYS_Falling);
    else if (Pawn(Base) != None)
    {
        Base.TakeDamage( (1-Velocity.Z/400)* Mass/Base.Mass, Self,Location,0.5 * Velocity , 'stomped');
        JumpOffPawn();
    }
    else if ( (Decoration(Base) != None) && (Velocity.Z < -400) )
    {
        decorMass = FMax(Decoration(Base).Mass, 1);
        Base.TakeDamage((-2* Mass/decorMass * Velocity.Z/400), Self, Location, 0.5 * Velocity, 'stomped');
    }
}

event LongFall();

//=============================================================================
// Network related functions.


event Destroyed()
{
    local Inventory Inv;

    RemovePawn();

    for( Inv=Inventory; Inv!=None; Inv=Inv.Inventory )   
        Inv.Destroy();
    if ( bIsPlayer && (Level.Game != None) )
        Level.Game.logout(self);
    if ( PlayerReplicationInfo != None )
        PlayerReplicationInfo.Destroy();
    Super.Destroyed();
}

//=============================================================================
// functions.

//
// native client-side functions.
//
native simulated event ClientHearSound ( 
    actor Actor, 
    int Id, 
    sound S, 
    vector SoundLocation, 
    vector Parameters 
);

//
// Called immediately before gameplay begins.
//
event PreBeginPlay()
{
    AddPawn();
    Super.PreBeginPlay();
    if ( bDeleteMe )
        return;

    // Set instigator to self.
    Instigator = Self;
    DesiredRotation = Rotation;
    SightCounter = 0.2 * FRand();  //offset randomly 
    if ( Level.Game != None )
        Skill += Level.Game.Difficulty; 
    Skill = FClamp(Skill, 0, 3);
    PreSetMovement();
    
    if ( DrawScale != Default.Drawscale )
    {
        SetCollisionSize(CollisionRadius*DrawScale/Default.DrawScale, CollisionHeight*DrawScale/Default.DrawScale);
        Health = Health * DrawScale/Default.DrawScale;
    }
    
    if (bIsPlayer)
    {
        if (PlayerReplicationInfoClass != None)
            PlayerReplicationInfo = Spawn(PlayerReplicationInfoClass, Self,,vect(0,0,0),rot(0,0,0));
        else
            PlayerReplicationInfo = Spawn(class'PlayerReplicationInfo', Self,,vect(0,0,0),rot(0,0,0));
        InitPlayerReplicationInfo();
    }

    if (!bIsPlayer) 
    {
        if ( BaseEyeHeight == 0 )
            BaseEyeHeight = 0.8 * CollisionHeight;
        EyeHeight = BaseEyeHeight;
        if (Fatness == 0) //vary monster fatness slightly if at default
            Fatness = 120 + Rand(8) + Rand(8);
    }

    if ( menuname == "" )
        menuname = GetItemName(string(class));
}

event PostBeginPlay()
{
    Super.PostBeginPlay();
    SplashTime = 0;
}

/* PreSetMovement()
default for walking creature.  Re-implement in subclass
for swimming/flying capability
*/
function PreSetMovement()
{
    if (JumpZ > 0)
        bCanJump = true;
    bCanWalk = true;
    bCanSwim = false;
    bCanFly = false;
    MinHitWall = -0.6;
    if (Intelligence > BRAINS_Reptile)
        bCanOpenDoors = true;
    if (Intelligence == BRAINS_Human)
        bCanDoSpecial = true;
}

//=============================================================================
// Multiskin support
static function SetMultiSkin( actor SkinActor, string SkinName, string FaceName, byte TeamNum )
{
    local Texture NewSkin;

    if(SkinName != "")
    {
        NewSkin = texture(DynamicLoadObject(SkinName, class'Texture'));
        if ( NewSkin != None )
            SkinActor.Skin = NewSkin;
    }
}

static function GetMultiSkin( Actor SkinActor, out string SkinName, out string FaceName )
{
    SkinName = String(SkinActor.Skin);
    FaceName = "";
}

static function bool SetSkinElement(Actor SkinActor, int SkinNo, string SkinName, string DefaultSkinName)
{
    local Texture NewSkin;

    NewSkin = Texture(DynamicLoadObject(SkinName, class'Texture'));
    if ( NewSkin != None )
    {
        SkinActor.Multiskins[SkinNo] = NewSkin;
        return True;
    }
    else
    {
        if(DefaultSkinName != "")
        {
            NewSkin = Texture(DynamicLoadObject(DefaultSkinName, class'Texture'));
            SkinActor.Multiskins[SkinNo] = NewSkin;
        }
        return False;
    }
}

//=============================================================================
// Replication
function InitPlayerReplicationInfo()
{
    if (PlayerReplicationInfo.PlayerName == "")
        PlayerReplicationInfo.PlayerName = "Player";
}
    
//=============================================================================
// Animation playing - should be implemented in subclass, 
//
// PlayWaiting, PlayRunning, and PlayGutHit, PlayMovingAttack (if used)
// and PlayDying are required to be implemented in the subclass

function PlayRunning()
{
    ////log("Error - PlayRunning should be implemented in subclass of"@class);
}

function PlayWalking()
{
    PlayRunning(); 
}

function PlayWaiting()
{
    ////log("Error - PlayWaiting should be implemented in subclass");
}

function PlayMovingAttack()
{
    ////log("Error - PlayMovingAttack should be implemented in subclass");
    //Note - must restart attack timer when done with moving attack
    PlayRunning();
}

function PlayWaitingAmbush()
{
    PlayWaiting();
}

function TweenToFighter(float tweentime)
{
}

function TweenToRunning(float tweentime)
{
    TweenToFighter(0.1);
}

function TweenToWalking(float tweentime)
{
    TweenToRunning(tweentime);
}

function TweenToPatrolStop(float tweentime)
{
    TweenToFighter(tweentime);
}

function TweenToWaiting(float tweentime)
{
    TweenToFighter(tweentime);
}

function PlayThreatening()
{
    TweenToFighter(0.1);
}

function PlayPatrolStop()
{
    PlayWaiting();
}

function PlayTurning()
{
    TweenToFighter(0.1);
}

function PlayBigDeath(name DamageType);
function PlayHeadDeath(name DamageType);
function PlayLeftDeath(name DamageType);
function PlayRightDeath(name DamageType);
function PlayGutDeath(name DamageType);

function PlayDying(name DamageType, vector HitLoc)
{
    local vector X,Y,Z, HitVec, HitVec2D;
    local float dotp;

    if ( Velocity.Z > 250 )
    {
        PlayBigDeath(DamageType);
        return;
    }
    
    if ( DamageType == 'Decapitated' )
    {
        PlayHeadDeath(DamageType);
        return;
    }
            
    GetAxes(Rotation,X,Y,Z);
    X.Z = 0;
    HitVec = Normal(HitLoc - Location);
    HitVec2D= HitVec;
    HitVec2D.Z = 0;
    dotp = HitVec2D dot X;

    //first check for head hit
    if ( HitLoc.Z - Location.Z > 0.5 * CollisionHeight )
    {
        if (dotp > 0)
            PlayHeadDeath(DamageType);
        else
            PlayGutDeath(DamageType);
        return;
    }
    
    if (dotp > 0.71) //then hit in front
        PlayGutDeath(DamageType);
    else
    {
        dotp = HitVec dot Y;
        if (dotp > 0.0)
            PlayLeftDeath(DamageType);
        else
            PlayRightDeath(DamageType);
    }
}

function PlayGutHit(float tweentime)
{
    log("Error - play gut hit must be implemented in subclass of"@class);
}

function PlayHeadHit(float tweentime)
{
    PlayGutHit(tweentime);
}

function PlayLeftHit(float tweentime)
{
    PlayGutHit(tweentime);
}

function PlayRightHit(float tweentime)
{
    PlayGutHit(tweentime);
}

function FireWeapon();

/* TraceShot - used by instant hit weapons, and monsters 
*/
function actor TraceShot(out vector HitLocation, out vector HitNormal, vector EndTrace, vector StartTrace)
{
    local vector realHit;
    local actor Other;
    Other = Trace(HitLocation,HitNormal,EndTrace,StartTrace,True);
    if ( Pawn(Other) != None )
    {
        realHit = HitLocation;
        if ( !Pawn(Other).AdjustHitLocation(HitLocation, EndTrace - StartTrace) )
            Other = Pawn(Other).TraceShot(HitLocation,HitNormal,EndTrace,realHit);
    }
    return Other;
}

/* Adjust hit location - adjusts the hit location in for pawns, and returns
true if it was really a hit, and false if not (for ducking, etc.)
*/
function bool AdjustHitLocation(out vector HitLocation, vector TraceDir)
{
    local float adjZ, maxZ;

    TraceDir = Normal(TraceDir);
    HitLocation = HitLocation + 0.4 * CollisionRadius * TraceDir;

    if ( (GetAnimGroup(AnimSequence) == 'Ducking') && (AnimFrame > -0.03) )
    {
        maxZ = Location.Z + 0.25 * CollisionHeight;
        if ( HitLocation.Z > maxZ )
        {
            if ( TraceDir.Z >= 0 )
                return false;
            adjZ = (maxZ - HitLocation.Z)/TraceDir.Z;
            HitLocation.Z = maxZ;
            HitLocation.X = HitLocation.X + TraceDir.X * adjZ;
            HitLocation.Y = HitLocation.Y + TraceDir.Y * adjZ;
            if ( VSize(HitLocation - Location) > CollisionRadius )  
                return false;
        }
    }
    return true;
}
            
function PlayTakeHit(float tweentime, vector HitLoc, int damage)
{
    local vector X,Y,Z, HitVec, HitVec2D;
    local float dotp;
    
    GetAxes(Rotation,X,Y,Z);
    X.Z = 0;
    HitVec = Normal(HitLoc - Location);
    HitVec2D= HitVec;
    HitVec2D.Z = 0;
    dotp = HitVec2D dot X;

    //first check for head hit
    if ( HitLoc.Z - Location.Z > 0.5 * CollisionHeight )
    {
        if (dotp > 0)
            PlayHeadHit(tweentime);
        else
            PlayGutHit(tweentime);
        return;
    }
    
    if (dotp > 0.71) //then hit in front
        PlayGutHit( tweentime);
    else if (dotp < -0.71) // then hit in back
        PlayHeadHit(tweentime);
    else
    {
        dotp = HitVec dot Y;
        if (dotp > 0.0)
            PlayLeftHit(tweentime);
        else
            PlayRightHit(tweentime);
    }
}

function PlayVictoryDance()
{
    TweenToFighter(0.1);
}

function PlayOutOfWater()
{
    TweenToFalling();
}

function PlayDive();
function TweenToFalling();
function PlayInAir();
function PlayDuck();
function PlayCrawling();

function PlayLanded(float impactVel)
{
    local float landVol;
    //default - do nothing (keep playing existing animation)
    landVol = impactVel/JumpZ;
    landVol = 0.005 * Mass * landVol * landVol;
    PlaySound(Land, SLOT_Interact, FMin(20, landVol));
}

function PlayFiring();
function PlayWeaponSwitch(Weapon NewWeapon);
function TweenToSwimming(float tweentime);


//-----------------------------------------------------------------------------
// Sound functions
function PlayTakeHitSound(int Damage, name damageType, int Mult)
{
    if ( Level.TimeSeconds - LastPainSound < 0.25 )
        return;

    if (HitSound1 == None)return;
    LastPainSound = Level.TimeSeconds;
    if (FRand() < 0.5)
        PlaySound(HitSound1, SLOT_Pain, FMax(Mult * TransientSoundVolume, Mult * 2.0));
    else
        PlaySound(HitSound2, SLOT_Pain, FMax(Mult * TransientSoundVolume, Mult * 2.0));
}

function Gasp();

function DropDecoration()
{
    if (CarriedDecoration != None)
    {
        CarriedDecoration.bWasCarried = true;
        CarriedDecoration.SetBase(None);
        CarriedDecoration.SetPhysics(PHYS_Falling);
        CarriedDecoration.Velocity = Velocity + 10 * VRand();
        CarriedDecoration.Instigator = self;
        CarriedDecoration = None;
    }
}

function GrabDecoration()
{
    local vector lookDir, HitLocation, HitNormal, T1, T2, extent;
    local actor HitActor;

    if ( carriedDecoration == None )
    {
        //first trace to find it
        lookDir = vector(Rotation);
        lookDir.Z = 0;
        T1 = Location + BaseEyeHeight * vect(0,0,1) + lookDir * 0.8 * CollisionRadius;
        T2 = T1 + lookDir * 1.2 * CollisionRadius;
        HitActor = Trace(HitLocation, HitNormal, T2, T1, true);
        if ( HitActor == None )
        {
            T1 = T2 - (BaseEyeHeight + CollisionHeight - 2) * vect(0,0,1);
            HitActor = Trace(HitLocation, HitNormal, T1, T2, true);
        }
        else if ( HitActor == Level )
        {
            T2 = HitLocation - lookDir;
            T1 = T2 - (BaseEyeHeight + CollisionHeight - 2) * vect(0,0,1);
            HitActor = Trace(HitLocation, HitNormal, T1, T2, true);
        }   
        if ( (HitActor == None) || (HitActor == Level) )
        {
            extent.X = CollisionRadius;
            extent.Y = CollisionRadius;
            extent.Z = CollisionHeight;
            HitActor = Trace(HitLocation, HitNormal, Location + lookDir * 1.2 * CollisionRadius, Location, true, extent);
        }

        if ( Mover(HitActor) != None )
        {
            if ( Mover(HitActor).bUseTriggered )
                HitActor.Trigger( self, self );
        }       
        else if ( (Decoration(HitActor) != None)  && ((weapon == None) || (weapon.Mass < 20)) )
        {
            CarriedDecoration = Decoration(HitActor);
            if ( !CarriedDecoration.bPushable || (CarriedDecoration.Mass > 40) 
                || (CarriedDecoration.StandingCount > 0) )
            {
                CarriedDecoration = None;
                return;
            }
            lookDir.Z = 0;              
            if ( CarriedDecoration.SetLocation(Location + (0.5 * CollisionRadius + CarriedDecoration.CollisionRadius) * lookDir) )
            {
                CarriedDecoration.SetPhysics(PHYS_None);
                CarriedDecoration.SetBase(self);
            }
            else
                CarriedDecoration = None;
        }
    }
}
    
function StopFiring();

/* AdjustAim()
ScriptedPawn version does adjustment for non-controlled pawns. 
PlayerPawn version does the adjustment for player aiming help.
Only adjusts aiming at pawns
allows more error in Z direction (full as defined by AutoAim - only half that difference for XY)
*/

function rotator AdjustAim(float projSpeed, vector projStart, int aimerror, bool bLeadTarget, bool bWarnTarget)
{
    return ViewRotation;
}

function rotator AdjustToss(float projSpeed, vector projStart, int aimerror, bool bLeadTarget, bool bWarnTarget)
{
    return ViewRotation;
}

function WarnTarget(Pawn shooter, float projSpeed, vector FireDir)
{
    // AI controlled creatures may duck
    // if not falling, and projectile time is long enough
    // often pick opposite to current direction (relative to shooter axis)
}

function SetMovementPhysics()
{
    //implemented in sub-class
}

function PlayHit(float Damage, vector HitLocation, name damageType, float MomentumZ)
{
}

function PlayDeathHit(float Damage, vector HitLocation, name damageType)
{
}

function TakeDamage( int Damage, Pawn instigatedBy, Vector hitlocation, 
                        Vector momentum, name damageType)
{
    local int actualDamage;
    local bool bAlreadyDead;

    //log(self@"take damage in state"@GetStateName());	
    bAlreadyDead = (Health <= 0);

    if (Physics == PHYS_None)
        SetMovementPhysics();
    if (Physics == PHYS_Walking)
        momentum.Z = FMax(momentum.Z, 0.4 * VSize(momentum));
    if ( instigatedBy == self )
        momentum *= 0.6;
    momentum = momentum/Mass;
    AddVelocity( momentum ); 

    actualDamage = Level.Game.ReduceDamage(Damage, DamageType, self, instigatedBy);
    if ( bIsPlayer )
    {
        if (ReducedDamageType == 'All') //God mode
            actualDamage = 0;
        else if (Inventory != None) //then check if carrying armor
            actualDamage = Inventory.ReduceDamage(actualDamage, DamageType, HitLocation);
        else
            actualDamage = Damage;
    }
    else if ( (InstigatedBy != None) &&
                (InstigatedBy.IsA(Class.Name) || self.IsA(InstigatedBy.Class.Name)) )
        ActualDamage = ActualDamage * FMin(1 - ReducedDamagePct, 0.35); 
    else if ( (ReducedDamageType == 'All') || 
        ((ReducedDamageType != '') && (ReducedDamageType == damageType)) )
        actualDamage = float(actualDamage) * (1 - ReducedDamagePct);
    
    Health -= actualDamage;
    if (CarriedDecoration != None)
        DropDecoration();
    if ( HitLocation == vect(0,0,0) )
    {
        //FIXEM@ log("Zero hit loc instigated by"@Instigator@"with weapon"@Instigator.weapon); //FIXME remove
        HitLocation = Location;
    }
    if (Health > 0)
    {
        if (instigatedBy != None)
            damageAttitudeTo(instigatedBy);
        PlayHit(actualDamage, hitLocation, damageType, Momentum.Z);
    }
    else if ( !bAlreadyDead )
    {
        //log(self$" died");
        NextState = '';
        PlayDeathHit(actualDamage, hitLocation, damageType);
        if ( actualDamage > mass )
            Health = -1 * actualDamage;
        Enemy = instigatedBy;
        Died(instigatedBy, damageType, HitLocation);
    }
    else
    {
        //Warn(self$" took regular damage while already dead");
        SpawnGibbedCarcass();
        if ( bIsPlayer )
        {
            HidePlayer();
            GotoState('Dying');
        }
        else
            Destroy();
    }
    MakeNoise(1.0); 
}

function Died(pawn Killer, name damageType, vector HitLocation)
{
    local pawn OtherPawn;
    local actor A;

    if ( bDeleteMe )
        return; //already destroyed
    Health = Min(0, Health);
    for ( OtherPawn=Level.PawnList; OtherPawn!=None; OtherPawn=OtherPawn.nextPawn )
        OtherPawn.Killed(Killer, self, damageType);
    if ( CarriedDecoration != None )
        DropDecoration();
    level.game.Killed(Killer, self, damageType);
    //log(class$" dying");
    if( Event != '' )
        foreach AllActors( class 'Actor', A, Event )
            A.Trigger( Self, Killer );
    Level.Game.DiscardInventory(self);
    Velocity.Z *= 1.3;
    if ( Gibbed(damageType) )
    {
        SpawnGibbedCarcass();
        if ( bIsPlayer )
            HidePlayer();
        else
            Destroy();
    }
    PlayDying(DamageType, HitLocation);
    if ( Level.Game.bGameEnded )
        return;
    if ( RemoteRole == ROLE_AutonomousProxy )
        ClientDying(DamageType, HitLocation);
    GotoState('Dying');
}

function bool Gibbed(name damageType)
{
    return false;
}

function Carcass SpawnCarcass()
{
    log(self$" should never call base spawncarcass");
    return None;
}

function SpawnGibbedCarcass()
{
}
    
function HidePlayer()
{
    SetCollision(false, false, false);
    TweenToFighter(0.01);
    bHidden = true;
}

event HearNoise( float Loudness, Actor NoiseMaker);
event SeePlayer( actor Seen );
event UpdateEyeHeight( float DeltaTime );
event EnemyNotVisible();

function Killed(pawn Killer, pawn Other, name damageType)
{
    //implemented in subclass
}

//Typically implemented in subclass
function string KillMessage( name damageType, pawn Other )
{
    local string message;

    message = Level.Game.CreatureKillMessage(damageType, Other);
    return (message$namearticle$menuname);
}

function damageAttitudeTo(pawn Other);

function Falling()
    {
        //SetPhysics(PHYS_Falling); //Note - physics changes type to PHYS_Falling by default
        //log(class$" Falling");
        PlayInAir();
    }

//MWP:begin
// Pawn interface called while PHYS_Walking and PHYS_Swimming to update the pawn with 
// the latest information about the walk surface
event WalkTexture( texture Texture, vector StepLocation, vector StepNormal );
//MWP:end

event Landed(vector HitNormal)
{
    SetMovementPhysics();
    if ( !IsAnimating() )
        PlayLanded(Velocity.Z);
    if (Velocity.Z < -1.4 * JumpZ)
        MakeNoise(-0.5 * Velocity.Z/(FMax(JumpZ, 150.0)));
    bJustLanded = true;
}

event FootZoneChange(ZoneInfo newFootZone)
{
    local actor HitActor;
    local vector HitNormal, HitLocation;
    local float splashSize;
    local actor splash;
    
    if ( Level.NetMode == NM_Client )
        return;
    if ( Level.TimeSeconds - SplashTime > 0.25 ) 
    {
        SplashTime = Level.TimeSeconds;
        if (Physics == PHYS_Falling)
            MakeNoise(1.0);
        else
            MakeNoise(0.3);
        if ( FootRegion.Zone.bWaterZone )
        {
            if ( !newFootZone.bWaterZone && (Role==ROLE_Authority) )
            {
                if ( FootRegion.Zone.ExitSound != None )
                    PlaySound(FootRegion.Zone.ExitSound, SLOT_Interact, 1); 
                if ( FootRegion.Zone.ExitActor != None )
                    Spawn(FootRegion.Zone.ExitActor,,,Location - CollisionHeight * vect(0,0,1));
            }
        }
        else if ( newFootZone.bWaterZone && (Role==ROLE_Authority) )
        {
            splashSize = FClamp(0.000025 * Mass * (300 - 0.5 * FMax(-500, Velocity.Z)), 1.0, 4.0 );
            if ( newFootZone.EntrySound != None )
            {
                HitActor = Trace(HitLocation, HitNormal, 
                        Location - (CollisionHeight + 40) * vect(0,0,0.8), Location - CollisionHeight * vect(0,0,0.8), false);
                if ( HitActor == None )
                    PlaySound(newFootZone.EntrySound, SLOT_Misc, 2 * splashSize);
                else 
                    PlaySound(WaterStep, SLOT_Misc, 1.5 + 0.5 * splashSize);
            }
            if( newFootZone.EntryActor != None )
            {
                splash = Spawn(newFootZone.EntryActor,,,Location - CollisionHeight * vect(0,0,1));
                if ( splash != None )
                    splash.DrawScale = splashSize;
            }
            //log("Feet entering water");
        }
    }
    
    if (FootRegion.Zone.bPainZone)
    {
        if ( !newFootZone.bPainZone && !HeadRegion.Zone.bWaterZone )
            PainTime = -1.0;
    }
    else if (newFootZone.bPainZone)
        PainTime = 0.01;
}
    
event HeadZoneChange(ZoneInfo newHeadZone)
{
    if ( Level.NetMode == NM_Client )
        return;
    if (HeadRegion.Zone.bWaterZone)
    {
        if (!newHeadZone.bWaterZone)
        {
            if ( bIsPlayer && (PainTime > 0) && (PainTime < 8) )
                Gasp();
            if ( Inventory != None )
                Inventory.ReduceDamage(0, 'Breathe', Location); //inform inventory of zone change
            bDrowning = false;
            if ( !FootRegion.Zone.bPainZone )
                PainTime = -1.0;
        }
    }
    else
    {
        if (newHeadZone.bWaterZone)
        {
            if ( !FootRegion.Zone.bPainZone )
                PainTime = UnderWaterTime;
            if ( Inventory != None )
                Inventory.ReduceDamage(0, 'Drowned', Location); //inform inventory of zone change
            //log("Can't breathe");
        }
    }
}

event SpeechTimer();

//Pain timer just expired.
//Check what zone I'm in (and which parts are)
//based on that cause damage, and reset PainTime
    
event PainTimer()
{
    local float depth;

    //log("Pain Timer");
    if ( (Health < 0) || (Level.NetMode == NM_Client) )
        return;
        
    if ( FootRegion.Zone.bPainZone )
    {
        depth = 0.4;
        if (Region.Zone.bPainZone)
            depth += 0.4;
        if (HeadRegion.Zone.bPainZone)
            depth += 0.2;

        if (FootRegion.Zone.DamagePerSec > 0)
        {
            if ( IsA('PlayerPawn') )
                Level.Game.SpecialDamageString = FootRegion.Zone.DamageString;
            TakeDamage(int(float(FootRegion.Zone.DamagePerSec) * depth), None, Location, vect(0,0,0), FootRegion.Zone.DamageType); 
        }
        else if ( Health < Default.Health )
            Health = Min(Default.Health, Health - depth * FootRegion.Zone.DamagePerSec);

        if (Health > 0)
            PainTime = 1.0;
    }
    else if ( HeadRegion.Zone.bWaterZone )
    {
        TakeDamage(5, None, Location, vect(0,0,0), 'drowned'); 
        if ( Health > 0 )
            PainTime = 2.0;
    }
}       

function bool CheckWaterJump(out vector WallNormal)
{
    local actor HitActor;
    local vector HitLocation, HitNormal, checkpoint, start, checkNorm, Extent;

    if (CarriedDecoration != None)
        return false;
    checkpoint = vector(Rotation);
    checkpoint.Z = 0.0;
    checkNorm = Normal(checkpoint);
    checkPoint = Location + CollisionRadius * checkNorm;
    Extent = CollisionRadius * vect(1,1,0);
    Extent.Z = CollisionHeight;
    HitActor = Trace(HitLocation, HitNormal, checkpoint, Location, true, Extent);
    if ( (HitActor != None) && (Pawn(HitActor) == None) )
    {
        WallNormal = -1 * HitNormal;
        start = Location;
        start.Z += 1.1 * MaxStepHeight;
        checkPoint = start + 2 * CollisionRadius * checkNorm;
        HitActor = Trace(HitLocation, HitNormal, checkpoint, start, true);
        if (HitActor == None)
            return true;
    }

    return false;
}

function bool SwitchToBestWeapon()
{
    local float rating;
    local int usealt;

    if ( Inventory == None )
        return false;

    PendingWeapon = Inventory.RecommendWeapon(rating, usealt);

    if ( PendingWeapon == None )
        return false;

    if ( Weapon == None )
        ChangedWeapon();
    else if ( Weapon != PendingWeapon )
        Weapon.PutDown();

    return (usealt > 0);
}

State Dying
{
ignores SeePlayer, EnemyNotVisible, HearNoise, KilledBy, Trigger, Bump, HitWall, HeadZoneChange, FootZoneChange, ZoneChange, Falling, WarnTarget, Died, LongFall, PainTimer;

    function TakeDamage( int Damage, Pawn instigatedBy, Vector hitlocation, 
                            Vector momentum, name damageType)
    {
        if ( bDeleteMe )
            return;
        Health = Health - Damage;
        Momentum = Momentum/Mass;
        AddVelocity( momentum ); 
        if ( !bHidden && Gibbed(damageType) )
        {
            bHidden = true;
            SpawnGibbedCarcass();
            if ( bIsPlayer )
                HidePlayer();
            else
                Destroy();
        }
    }

    function Timer()
    {
        if ( !bHidden )
        {
            bHidden = true;
            SpawnCarcass();
            if ( bIsPlayer )
                HidePlayer();
            else
                Destroy();
        }
    }

    event Landed(vector HitNormal)
    {
        SetPhysics(PHYS_None);
    }

    function BeginState()
    {
        SetTimer(0.3, false);
    }
}

state GameEnded
{
ignores SeePlayer, HearNoise, KilledBy, Bump, HitWall, HeadZoneChange, FootZoneChange, ZoneChange, Falling, TakeDamage, WarnTarget;

    function BeginState()
    {
        SetPhysics(PHYS_None);
        HidePlayer();
    }
}

defaultproperties
{
     AvgPhysicsTime=0.100000
     MaxDesiredSpeed=1.000000
     GroundSpeed=320.000000
     WaterSpeed=200.000000
     AccelRate=500.000000
     JumpZ=325.000000
     MaxStepHeight=25.000000
     AirControl=0.050000
     Visibility=128
     SightRadius=2500.000000
     HearingThreshold=1.000000
     OrthoZoom=40000.000000
     FovAngle=90.000000
     Health=100
     AttitudeToPlayer=ATTITUDE_Hate
     Intelligence=BRAINS_MAMMAL
     noise1time=-10.000000
     noise2time=-10.000000
     SoundDampening=1.000000
     DamageScaling=1.000000
     PlayerReStartState=PlayerWalking
     NameArticle=" a "
     PlayerReplicationInfoClass=Class'Engine.PlayerReplicationInfo'
     bCanTeleport=True
     bIsKillGoal=True
     bStasis=True
     bIsPawn=True
     RemoteRole=ROLE_SimulatedProxy
     AnimSequence=Fighter
     bDirectional=True
     Texture=Texture'Engine.S_Pawn'
     SoundRadius=9
     SoundVolume=240
     TransientSoundVolume=2.000000
     bCollideActors=True
     bCollideWorld=True
     bBlockActors=True
     bBlockPlayers=True
     bProjTarget=True
     bRotateToDesired=True
     RotationRate=(Pitch=4096,Yaw=50000,Roll=3072)
     NetPriority=4.000000
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: za 22-4-2006 13:27:48.000 - Creation time: za 22-4-2006 13:29:29.406 - Created with UnCodeX