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

# Gameplay.MPCarryable

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

    class MPCarryable extends MPActor
    	native
    	dependsOn(ObjectiveInfo)
    	dependsOn(Vehicle);

    cpptext
    {
    	virtual void TickSimulated( FLOAT DeltaSeconds );
    	virtual void TickAuthoritative( FLOAT DeltaSeconds );

    	virtual bool HavokInitActor();
    	virtual void HavokQuitActor();

    	class HkClientInterpolationControl* clientInterpolationControl;
    }

    const MPC_LINEAR_VELOCITY_ACCURACY_FACTOR = 100;
    const MPC_LINEAR_VELOCITY_INVERSE_ACCURACY_FACTOR = 0.01;

    const MPC_ANGULAR_VELOCITY_ACCURACY_FACTOR = 1000;
    const MPC_ANGULAR_VELOCITY_INVERSE_ACCURACY_FACTOR = 0.001;

    // Notes
    // Characters can only carry MPCarryables of a particular class (and its subclasses).
    // Characters can pickup individual MPCarryables but they cannot drop individual MPCarryables.
    // In other words, characters always drop or throw all MPCarryables that are being carried.
    // When multiple carryables are carried, only a single instance is stored and the rest get deleted.
    // Carryables get dropped at their largest possible denominations.
    // For example, if dropping 16 carryables with 1, 5, 10 denominations, one of each denomination is spawned and dropped.

    // Denominations
    var(MPCarryable) int			maxCarried					"The maximum number of carryables of this type that you can carry at a time";
    var(MPCarryable) array< class<MPMetaCarryable> > denominations	"If maxCarried > 0, you can add denominations in order to group numerous carryables together.  A denomination is an MPMetaCarryable class.";
    var(MPCarryable) float			returnTime					"How long this carryable takes to return when it is dropped.  -1 to disable.";
    var(MPCarryable) float			minRespawnTime				"The minimum time it takes for the carryable to respawn after it has been returned.";
    var(MPCarryable) float			maxRespawnTime				"The maximum time it takes for the carryable to respawn after it has been returned.";
    var(MPCarryable) float			existenceTime				"How long this carryable will remain in existence after being picked up from its home location.  0 or less to disable.";
    var(MPCarryable) config Material		hudIcon						"The icon displayed in the player's hud while this object is held";
    var(MPCarryable) config MatCoords		hudIconCoords				"UV coordinates of the hud icon space in the hudIcon material";
    var(MPCarryable) float			selfPickupTimeout			"Number of seconds before you can pickup this object after dropping it";
    var(MPCarryable) int			stopSpeed					"Speed at which this object will stop moving";
    var(MPCarryable) float			elasticity					"How much the object bounces";
    var(MPCarryable) float			spread						"The degree to which multiple carryables will randomly spread";
    var(MPCarryable) EPhysics		droppedPhysics				"The physics state when dropped";
    var(MPCarryable) bool			bRandomizeStartingRotation	"Should the yaw of this object be randomized?";
    var(MPCarryable) float			maxTimeCarried				"The maximum number of seconds this carryable can be held.  0 or less disables the limit.";
    var(MPCarryable) float			damagePerSecondAfterMaxTimeCarried		"After maxTimeCarried expires, this amount of damage is applied to the carrier per second.  If 0, it's disabled and the player will simply drop the carryable instead.";
    var(MPCarryable) array<Vector> randomStartingLocations		"Put extra locations in this array if you want the carryable to respawn at them randomly. (NOT FULLY IMPLEMENTED)";
    var(MPCarryable) Name			attachmentSocket			"The name of the socket where this carryable should be attached when carried.";
    var(MPCarryable) Vector			offsetCOM					"Offset the center of mass when using Havok";
    var(MPCarryable) bool			bIsWeaponType				"If true, the carryable is carried and selected like a weapon and thrown when the weapon is fired as normal. If false, the carryable is not part of the player's inventory and is thrown with the alt-fire key.";
    var(MPCarryable) bool			bAllowThroughEnergyBarriers	"If true, you can carry or throw this carryable through friendly energy barriers.";
    var(MPCarryable) StaticMesh		staticMeshWhileCarried		"If set, use this static mesh when carried.";
    var(MPCarryable) Mesh			meshWhileCarried			"If set, use this mesh when carried.";
    var(MPCarryable) name			carriedAnimation			"Anim to play while carried. Not applicable for static meshes.";
    var(MPCarryable) bool			bCanBeGrappledInField		"If true, you can pickup this carryable in the field by grappling it.";
    var(MPCarryable) bool			bCanBeGrappledAtHome		"If true, you can pickup this carryable at its home by grappling it.";
    var(MPCarryable) bool			bDontReplicateEffects		"If true, no effects will be replicated to clients.  Useful if there are many instances";
    var(MPCarryable) bool			bCanBringIntoVehicle		"If true, players carrying this carryable can enter vehicles.";
    var(MPCarryable) float			extraMass					"If used, adds this many kilograms to the player when picked up.";
    var(MPCarryable) bool			bBlockActorsWhenDropped		"If true will be set bBlockActors to true when dropped.";
    var(MPCarryable) float			inheritedVelocityFactor		"Percentage of velocity the carryable will inherit when dropped after carrier death.";
    var(LocalMessage) class<Engine.LocalMessage>	CarryableMessageClass "The class used for displaying messages and playing effects related to carryables.";

    // Stats
    var(Stats) class<Stat>	pickupStat					"The stat awarded for picking up this carryable";
    var(Stats) class<Stat>	carrierKillStat				"The stat awarded for killing the carrier of this carryable";

    var (EffectEvents)	Name	pickupEffectEvent		"The name of an effect event that plays once on the carryable when picked up";
    var (EffectEvents)	Name	dropEffectEvent			"The name of an effect event that plays once on the carryable when dropped";
    var (EffectEvents)	Name	thrownEffectEvent		"The name of an effect event that plays once on the carryable when thrown";
    var (EffectEvents)	Name	returnedHomeEffectEvent	"The name of an effect event that plays once on the carryable after it returns home";
    var (EffectEvents)	Name	preReturnEffectEvent	"The name of an effect event that plays once on the carryable just before it returns home";
    var (EffectEvents)	Name	carryingEffectEvent		"The name of an effect event that loops on the carryable while carried";
    var (EffectEvents)	Name	idlingEffectEvent		"The name of an effect event that loops on the carryable when it is in the world";
    var (EffectEvents)	Name	throwingEffectEvent		"The name of an effect event that loops on the carryable when the throw button is held";
    var (EffectEvents)	Name	idlingHomeEffectEvent	"The name of an effect event that loops on the carryable when it is idling at its home location";

    var int				numCarried;
    var Vector			homeLocation;
    var Rotator			homeRotation;
    var Character		carrier;
    var Character		lastCarrier;
    var Controller		carrierController;
    var float			timeDropped;
    var float			timePickedUp;
    var bool			bHome;
    var Timer			existenceTimer;
    var bool			bHotPotato;
    var MPCarryableContainer homeContainer;
    var float			lastEnergyBarrierCollisionTime;
    var float			timeBetweenEnergyBarrierCollisions;
    var Rotator			pickupRotation;

    // Effect bools
    var bool			bInitialization;
    var bool			bCarriedEffect;
    var bool			bLocalCarriedEffect;
    var bool			bHomeEffect;
    var bool			bPreReturnEffect;
    var bool			bLocalPreReturnEffect;
    var bool			bLocalHomeEffect;
    var bool			bThrowingEffect;
    var bool			bLocalThrowingEffect;
    var bool			bWasDropped; // for client physics
    var bool			bOldWasDropped;

    var() class<MPCarryableThrower>	carriedObjectClass			"This class gets carried while the player is holding the object";

    // Havok
    struct native HavokCarryableReplicationState
    {
    	var vector  Position;
    	var quat	Rotation;
    	var vector	LinVel;
    	var vector	AngVel;
    	var bool bNewState;
    };

    var (Havok)	float maximumNetUpdateInterval;
    var (Havok) float minimumNetUpdateInterval;
    // latest time we should force an update of vehicles state
    var float maximumNextNetUpdateTime;
    // earliest time we shoudl force an update of vehicles state
    var float minimumNextNetUpdateTime;
    var	HavokCarryableReplicationState ReplicationState;
    var float lastStateReceiveTime;
    var bool bInitialized;

    var Vehicle.DesiredHavokState currentDesiredHavokState;

    // controls how quickly the client side object interpolates to the server side state
    var (Havok)	float clientInterpolationPeriod;

    // when the client side object deviates this distance from the server it shall be snapped
    var (Havok)	float clientInterpolationSnapDistance;

    var transient noexport private const int padding[1];

    replication
    {
    	reliable if (!bDontReplicateEffects && Role == ROLE_Authority)
    		bCarriedEffect, bHomeEffect, bThrowingEffect;
    	reliable if (Role == ROLE_Authority)
    		ReplicationState, bWasDropped, timeDropped;
    }

    native function forceNetDirty();

    // PostBeginPlay
    simulated function PostBeginPlay()
    {
    	local Rotator newRotation;

    	Super.PostBeginPlay();

    	if (Level.NetMode != NM_Client)
    	{
    		// Add the starting location to the list of possible random locations and choose a random starting location
    		randomStartingLocations[randomStartingLocations.Length] = Location;
    		homeLocation = chooseHomeLocation();

    		homeRotation = Rotation;
    		SetOwner(None);

    		if (bRandomizeStartingRotation)
    		{
    			newRotation = Rotation;
    			newRotation.Yaw = Rand(65535);
    			homeRotation = newRotation;
    		}
    		bHome = true;

    		if (existenceTime > 0)
    		{
    			existenceTimer = Spawn(class'Timer');
    			existenceTimer.TimerDelegate = existenceTimerExpired;
    		}
    	}

    	if (Physics == PHYS_Havok || droppedPhysics == PHYS_Havok)
    	{
    		bUpdateSimulatedPosition = false;
    		bUseCompressedPosition=false;
    		HavokSetCOM(offsetCOM);
    	}
    }

    simulated function PostNetReceive()
    {
    	local Name oldAttachmentBone;
    	local Actor oldBase;

    	super.PostNetReceive();
    	updateCarryableEffects();

    	if (bWasDropped != bOldWasDropped)
    	{
    		oldAttachmentBone = AttachmentBone;
    		oldBase = Base;

    		if (bWasDropped)
    			SetPhysics(droppedPhysics);
    		else
    			SetPhysics(default.Physics);

    		oldBase.AttachToBone(self, oldAttachmentBone);

    		bOldWasDropped = bWasDropped;
    	}

    	if (Physics == PHYS_Havok)
    	{
    		updateHavok();
    	}
    }

    // Re-trigger necessary effects on coming into relevancy
    simulated function PostNetBeginPlay()
    {
    	super.PostNetBeginPlay();

    	if (Level.NetMode == NM_Client && !bInitialization)
    	{
    		if (bHomeEffect)
    		{
    			TriggerEffectEvent(idlingHomeEffectEvent);
    		}
    		else if (bCarriedEffect)
    		{
    			TriggerEffectEvent(carryingEffectEvent);
    		}
    		else
    		{
    			TriggerEffectEvent(idlingEffectEvent);
    		}
    	}
    }

    simulated function Destroyed()
    {
    	if (Level.NetMode == NM_Client)
    	{
    		if (bCarriedEffect)
    		{
    			UnTriggerEffectEvent(carryingEffectEvent);
    		}
    		else
    		{
    			UnTriggerEffectEvent(idlingEffectEvent);
    			UnTriggerEffectEvent(idlingHomeEffectEvent);
    		}
    	}

    	super.Destroyed();
    }

    simulated function updateCarryableEffects()
    {
    	if (bCarriedEffect != bLocalCarriedEffect)
    	{
    		bLocalCarriedEffect = bCarriedEffect;
    		if (bCarriedEffect)
    		{
    			// The Carryable has started to be carried
    			UnTriggerEffectEvent(idlingEffectEvent);
    			UnTriggerEffectEvent(idlingHomeEffectEvent);
    			if (!bInitialization)
    				TriggerEffectEvent(pickupEffectEvent);
    			TriggerEffectEvent(carryingEffectEvent);
    		}
    		else
    		{
    			// The Carryable has been dropped
    			UnTriggerEffectEvent(carryingEffectEvent);
    			if (!bInitialization)
    				TriggerEffectEvent(dropEffectEvent);
    			TriggerEffectEvent(idlingEffectEvent);
    		}

    	}

    	if (bHomeEffect != bLocalHomeEffect)
    	{
    		bLocalHomeEffect = bHomeEffect;

    		if (bHomeEffect)
    		{
    			// The Carryable has been returned home
    			UnTriggerEffectEvent(idlingEffectEvent);
    			if (!bInitialization)
    				TriggerEffectEvent(returnedHomeEffectEvent);
    			TriggerEffectEvent(idlingHomeEffectEvent);
    		}
    	}

    	if (bThrowingEffect != bLocalThrowingEffect)
    	{
    		bLocalThrowingEffect = bThrowingEffect;

    		if (bThrowingEffect)
    		{
    			// The carryable has started to be thrown
    			if (!bInitialization)
    				TriggerEffectEvent(throwingEffectEvent);
    		}
    		else
    		{
    			// The carryable has stopped being thrown
    			UnTriggerEffectEvent(throwingEffectEvent);
    			if (!bInitialization)
    				TriggerEffectEvent(thrownEffectEvent);
    		}
    	}

    	if (bPreReturnEffect != bLocalPreReturnEffect)
    	{
    		bLocalPreReturnEffect = bPreReturnEffect;

    		if (!bInitialization)
    			TriggerEffectEvent(preReturnEffectEvent);
    	}

    	bInitialization = false;
    }

    function cleanup()
    {
    	Super.cleanup();

    	if (existenceTimer != None)
    		existenceTimer.destroy();
    }

    function setMovementReplication(bool replicate)
    {
    	// MJ TEMP:  Disable this to see if it fixes the phantom fuel bug
    	return;

    	bUpdateSimulatedPosition = replicate;
    }

    function registerStats(StatTracker tracker)
    {
    	Super.registerStats(tracker);

    	tracker.registerStat(pickupStat);
    	tracker.registerStat(carrierKillStat);
    }

    function Vector chooseHomeLocation()
    {
    	local int i;

    	if (randomStartingLocations.Length == 0)
    		return homeLocation;

    	i = Rand(randomStartingLocations.Length-1);

    	return randomStartingLocations[i];
    }

    function onPickedUp(Character c)
    {
    }

    function onDropped(Controller c)
    {
    }

    function onCharacterPassedThrough(Character c)
    {
    }

    function onCarrierDeath(Controller Killer)
    {
    	if (PlayerController(carrierController) == None || PlayerController(Killer) == None)
    		return;

    	if (carrierKillStat != None && ModeInfo(Level.Game) != None && carrierController != Killer
    		&& Killer != None && !PlayerController(carrierController).isFriendly(Killer))
    	{
    		ModeInfo(Level.Game).Tracker.awardStat(Killer, carrierKillStat, carrierController);
    	}
    }

    function onDropTimerExpired()
    {
    }

    function onExistenceTimerExpired()
    {
    }

    // return
    function returnToHome(optional bool bSignificant)
    {
    	if (carrier != None)
    		carrier.clearCarryables();

    	clearCarrier();

    	if (minRespawnTime > 0)
    		GotoState('Respawning');
    	else if (bSignificant)
    		GotoState('Home', 'SignificantReturn');
    	else
    		GotoState('Home');
    }

    // This is called when the carrier dies
    function drop(optional bool bSpread)
    {
    	local vector newLocation, newVelocity;

    	if (carrier != None)
    		newLocation = carrier.Location;
    	else
    		newLocation = Location;

    	newLocation.z += CollisionHeight;

    	if (bSpread)
    	{
    		newVelocity.X = 500*Frand() - 250;
    		newVelocity.Y = 500*Frand() - 250;
    		newVelocity.Z = 200;
    	}

    	if (carrier != None)
    		newVelocity += inheritedVelocityFactor * carrier.ragdollInheritedVelocity;

    	SetPhysics(droppedPhysics);
    	bWasDropped = true;

    	unifiedSetPosition(newLocation);
    	unifiedSetVelocity(newVelocity);

    	//Log(self$" dropped at "$newLocation);
    	GotoState('Dropped');
    }

    simulated event toss()
    {
    	carrier.pseudoWeapon.Fire();
    }

    function existenceTimerExpired()
    {
    	onExistenceTimerExpired();
    	returnToHome();
    }

    // MJ:  No longer use this
    //function Landed( vector HitNormal )
    //{
    //	if (Physics == PHYS_Havok)
    //		return;
    //
    //	Velocity = vect(0, 0, 0);
    //	SetPhysics(default.Physics);
    //}

    simulated function HitWall (vector HitNormal, actor Wall)
    {
    	if (Physics == PHYS_Havok)
    		return;

    	if (Level.TimeSeconds - timeDropped < default.selfPickupTimeout)
    		return;

    	Velocity = elasticity*(( Velocity dot HitNormal ) * HitNormal * (-2.0) + Velocity);

    	TriggerEffectEvent('Bounced');

    	//if (VSize(Velocity) < stopSpeed)
        //    Landed(HitNormal);
    }

    function bool isReplicatedInstance()
    {
    	// Returns true if this carryable is the carrier's replicated instance
    	return carrier != None && carrier.carryableReference == self;
    }

    function bool validCarrier(Character c, optional bool ignoreLastCarrierCheck)
    {
    	if (c == None || !c.isAlive() || c.team() == None || c.Controller.IsInState('PlayerTeleport'))
    	{
    		//Log(c$" wasn't a valid carrier for "$self$" due to level 1 check");
    		return false;
    	}

    	if (c.isTouchingEnergyBarrier())
    		return false;

    	// Check for self collision (quickly drop and touch it again)
    	if (!ignoreLastCarrierCheck && c == lastCarrier && Level.TimeSeconds - timeDropped < selfPickupTimeout)
    	{
    		//Log(c$" wasn't a valid carrier for "$self$" due to level 2 check");
    		return false;
    	}
    	// If not carrying any, then allow the pickup
    	if (c.carryableReference == None)
    	{
    		return true;
    	}
    	// Otherwise, enforce carryable exclusivity (can only carry carryables of a single type)
    	else if (!canCombineWith(c.carryableReference.Class))
    	{
    		//Log(c$" wasn't a valid carrier for "$self$" due to level 3 check, ref = "$c.carryableReference);
    		return false;
    	}
    	// Check to see how many of this carryable you're allowed to pickup
    	else if (c.numCarryables - c.numPermanentCarryables >= getMaxCarried())
    	{
    		//Log(c$" wasn't a valid carrier for "$self$" due to level 4 check");
    		return false;
    	}

    	return true;
    }

    function bool canCombineWith(class<MPCarryable> targetClass)
    {
    	return Class == targetClass || ClassIsChildOf(targetClass, class'MPMetaCarryable');
    }

    function clearCarrier()
    {
    	SetOwner(None);

    	if (carrier == None)
    		return;

    	lastCarrier = carrier;

    	dispatchMessage(new class'MessageDroppedGameObject'(label, carrier.label));
    	carrier = None;
    	carrierController = None;
    }

    function pickup(Character c)
    {
    	c.pickupCarryable(self);

    	if (pickupStat != None)
    		awardStat(pickupStat, c);
    	GotoState('Held');
    }

    function setCarrier(Character c)
    {
    	carrier = c;
    	carrierController = c.Controller;
    	setOwner(carrier);

    	dispatchMessage(new class'MessagePickedUpGameObject'(label, carrier.label));
    }

    function onGrappled(Character c)
    {
    	if (bHome)
    	{
    		if (!bCanBeGrappledAtHome)
    		{
    			c.receiveLocalizedMessage( CarryableMessageClass, 11 );
    			return;
    		}
    	}
    	else
    	{
    		if (!bCanBeGrappledInField)
    		{
    			c.receiveLocalizedMessage( CarryableMessageClass, 12 );
    			return;
    		}
    	}

    	if (c == None || c.controller == None || bHidden || !c.controller.IsInState('CharacterMovement') || carrier != None)
    		return;

    	attemptPickup(c, true);
    }

    singular function Touch(Actor Other)
    {
    	local Character c;
    	local GrapplerProjectile p;
    	local vector hitLoc, hitNormal, startLoc, testLoc;

    	p = GrapplerProjectile(Other);
    	if (p != None)
    	{
    		Character(p.Instigator).detachGrapple();
    		onGrappled(Character(p.instigator));
    		return;
    	}

    	c = Character(Other);

    	if (c == None || c.controller == None || bHidden || !c.isAlive() || carrier != None
    		|| c.bDontAllowCarryablePickups || c.Physics == PHYS_None || !bInitialized)
    	{
    		//Log("Unable to pickup "$self$" probably due to "$bInitialized);
    		return;
    	}

    	// Don't allow picking up through geometry
    	// TODO:  Unfortunately this doesn't fully solve the case of energy barriers where
    	// the player can be standing inside one
    	startLoc = c.Location - Normal(c.Location - Location) * 10;
    	testLoc = Location;
    	testLoc.z += CollisionHeight;
    	if (Trace(hitLoc, hitNormal, startLoc, testLoc, false) != None)
    	{
    		//Log("Not allowing pickup of "$self$" due to Trace");
    		return;
    	}

    	//Log(self$" attempting pickup by "$c);
    	attemptPickup(c);
    }

    function bool attemptPickup(Character c, optional bool ignoreLastCarrierCheck)
    {
    	if (ValidCarrier(c, ignoreLastCarrierCheck))
    	{
    		setCarrier(c);
    		pickup(c);
    		return true;
    	}

    	onCharacterPassedThrough(c);
    	return false;
    }

    // Initialization state
    auto simulated state Initialization
    {
    	simulated function BeginState()
    	{
    		bInitialization = true;
    	}

    Begin:
    	if (Level.NetMode == NM_Client)
    		GotoState('');
    	else
    		GotoState('Home');
    }

    // Home state
    state Home
    {
    	function returnToHome(optional bool bSignificant)
    	{
    		// Already home
    	}

    	function CheckTouching()
    	{
    		local Character c;

    		ForEach TouchingActors(class'Character',c)
    		{
    			if ( ValidCarrier(c) )
    			{
    				setCarrier(c);
    				pickup(c);
    				return;
    			}
    		}
    	}

    	function BeginState()
    	{
    		bWasDropped = false;

    		SetRelativeLocation(Vect(0,0,0));
    	    SetRelativeRotation(Rot(0,0,0));
    		unifiedSetVelocity(Vect(0,0,0));
    		unifiedSetAngularVelocity(Rot(0,0,0));

    		SetBase(None);

    		SetPhysics(default.Physics);
    		bHome = true;

    		// If a homeContainer is specified, use its location instead and send to Locked
    		if (homeContainer != None)
    		{
    			//Log("homeContainer for "$self$" detected as "$homeContainer$"; adding and sending to Locked");
    			homeContainer.addCarryable(self);
    			unifiedSetPosition(homeContainer.Location);
    			GotoState('Locked');
    			return;
    		}

    		unifiedSetPosition(homeLocation);
    		unifiedSetRotation(homeRotation);
    		//Enable('Touch');

    		bHomeEffect = true;
    		updateCarryableEffects();
    		bInitialized = true;
    	}

    	function EndState()
    	{
    		bHome = false;
    		bHomeEffect = false;
    		updateCarryableEffects();

    		if (existenceTimer != None)
    			existenceTimer.StartTimer(existenceTime);
    	}

    SignificantReturn:
    	if (CarryableMessageClass != None)
    		Level.Game.BroadcastLocalized(self, CarryableMessageClass, 2, team());

    Begin:
    	// After setting to its home location, see if anyone is touching it
    	CheckTouching();
    }

    // Pawn version of this will set PHY_Falling if Physics is None and Base is None.
    singular event BaseChange();

    // Locked state
    // When a carryable is locked, it is hidden and can't be picked up.
    // Needed, for example, when it is stored in a container or metacarryable.
    state Locked
    {
    	function BeginState()
    	{
    		bHidden = true;
    		bInitialized = true;
    		setMovementReplication(false);
    	}

    	function EndState()
    	{
    		bHidden = false;
    	}

    Begin:
    	clearCarrier();
    }

    // Dropped state
    state Dropped
    {
    	// return timer
    	function Timer()
    	{
    		dispatchMessage(new class'MessageCarryableReturned'(label));

    		onDropTimerExpired();
    		returnToHome(true);
    	}

    	function BeginState()
    	{
    		// set collision consistent with a physical object in the world
    		SetCollision(true, bBlockActorsWhenDropped, false);
    		bCollideWorld = true;

    		onDropped(carrierController);
    		bWasDropped = true;
    		//Log(self$" entered Dropped state");

           // SetRelativeLocation(Vect(0,0,0));
            //SetRelativeRotation(Rot(0,0,0));
    		timeDropped = Level.TimeSeconds;

    		bHidden = false;
    		setMovementReplication(true);

    		// Set the carryable to return based on the returnTime, if applicable
    		if (returnTime >= 0)
    			SetTimer(returnTime, false);

    		//carrier.ReceiveLocalizedMessage(CarryableMessageClass, 1);
    		if (CarryableMessageClass != None)
    			Level.Game.BroadcastLocalized(self, CarryableMessageClass, 1, team());

    		if (SecondaryMessageClass != None)
    		{
    			//Log("Sending dropped message with carrier = "$carrier$" and lastCarrier = "$lastCarrier$" and PRI = "$carrier.playerReplicationInfo);
    			Level.Game.BroadcastLocalized(self, SecondaryMessageClass, 1, carrierController.playerReplicationInfo);
    		}

    		clearCarrier();
    	}

    	function EndState()
    	{
    		bWasDropped = false;

    		SetTimer(0, false);

    		// turn off block actors
    		SetCollision(true, false, false);
    	}
    }

    function unsetup()
    {
    	if (isReplicatedInstance())
    	{
    		// Detach it
    		carrier.DetachFromBone(self);
    	}
    	else
    	{
    		bHidden = false;
    	}

    	// Reset StaticMesh if applicable
    	if (default.staticMeshWhileCarried != None || default.meshWhileCarried != None)
    	{
    		if (default.StaticMesh != None)
    		{
    			SetStaticMesh(default.StaticMesh);
    			SetDrawType(DT_StaticMesh);
    		}
    		else
    		{
    			LinkMesh(default.Mesh);
    			SetDrawType(DT_Mesh);
    		}
    	}
    }

    // moved this out of 'Held' state code due to
    // states not being replicated
    simulated function Vector GetObjectiveLocation()
    {
    	if(bCarriedEffect)
    	{
    		if(carrier != None)
    			return carrier.Location;
    		else if(base != None)
    			return base.Location;
    	}
    	else
    		return Super.GetObjectiveLocation();
    }

    // Held state
    state Held
    {
    	function BeginState()
    	{
    		bCarriedEffect = true;
    		updateCarryableEffects();
    		timePickedUp = Level.TimeSeconds;
    		//bOnlyDrawIfAttached = true;
            SetCollision(false, false, false);
            bCollideWorld = false;
    //		bBlockPlayers = false;
    		SetPhysics(default.Physics);
    		bHome = false;
    		unifiedSetVelocity(Vect(0, 0, 0));
            SetRelativeLocation(Vect(0,0,0));
    		pickupRotation = Rotation;
            //SetRelativeRotation(Rot(0,0,0));

    		// Set all spectators to view the carrier instead
    		setSpectatorViewTarget(carrier);

    		setup();

    		onPickedUp(carrier);
    		//carrier.ReceiveLocalizedMessage(CarryableMessageClass, 0);
    		if (CarryableMessageClass != None)
    			Level.Game.BroadcastLocalized(self, CarryableMessageClass, 0, team());

    		if (SecondaryMessageClass != None)
    			Level.Game.BroadcastLocalized(self, SecondaryMessageClass, 0, carrier.playerReplicationInfo);

    		// Set maxTimeCarried timer if applicable
    		if (maxTimeCarried > 0)
    			SetTimer(maxTimeCarried, false);
    	}

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

    		// MJ TODO:  Carrier shouldn't be None here...need to look into this
    		if (carrier != None)
    			Move(carrier.Location - Location);
    	}

    	function setup()
    	{
    		SetLocation(carrier.Location);

    		if (denominations.Length > 0 && !isReplicatedInstance())
    			attachDenomination();
    		else
    		{
    			if (isReplicatedInstance())
    				attachToCarrier();
    			else
    			{
    				bHidden = true;
    			}
    		}
    	}

    	function Timer()
    	{
    		// Timer called due to hotPotato.  A second has passed...inflict damage
    		if (bHotPotato)
    		{
    			carrier.TakeDamage(damagePerSecondAfterMaxTimeCarried, self, vect(0, 0, 0), vect(0, 0, 0), class'DamageType');
    		}
    		// Timer called due to maxTimeCarried.
    		// If damage is to be applied, start hotPotato
    		else if (damagePerSecondAfterMaxTimeCarried != 0)
    		{
    			bHotPotato = true;
    			SetTimer(1, true);
    		}
    		// Otherwise, just force it to drop
    		else
    			drop();
    	}

    	function Pawn getViewTarget()
    	{
    		if (carrier != None)
    			return carrier;

    		return self;
    	}

    	function EndState()
    	{
    		bCarriedEffect = false;
    		updateCarryableEffects();
            SetCollision(true, false, false);
            bCollideWorld = true;
    		bHidden = false;

    		resetSpectatorViewTarget();

    		unsetup();

    	    SetRelativeLocation(vect(0,0,0));
            //SetRelativeRotation(rot(0,0,0));
    		unifiedSetRotation(pickupRotation);

    		SetTimer(0, false);
    		bHotPotato = false;
    	}
    }

    // In the Respawning state, the carryable is in a state of limbo waiting to spawn
    // at its home location
    state Respawning
    {
    	function BeginState()
    	{
    		local int respawnTime;

    		bHidden = true;
    		respawnTime = Rand(maxRespawnTime - minRespawnTime);
    		SetTimer(respawnTime + minRespawnTime, false);
    	}

    	function Timer()
    	{
    		SetTimer(0, false);
    		GotoState('Home', 'SignificantReturn');
    	}

    	function EndState()
    	{
    		bHidden = false;
    	}
    }

    // attachToCarrier
    function attachToCarrier()
    {
    	if (getCarriedMesh() != None)
    	{
    		//Log(self$" attaching "$default.staticMeshWhileCarried$" to socket "$attachmentSocket);
    		unifiedSetMesh(getCarriedMesh());
    	}

    	if (!carrier.AttachToBone(self, attachmentSocket))
    		carrier.AttachToBone(self, 'Bip01 Spine');
    }

    function attachDenomination()
    {
    	local int i;

    	i = 0;

    	// Find the denomination to use, if any;  search backwards
    	for (i=denominations.Length - 1; i>=0; i--)
    	{
    		if (carrier.numDroppableCarryables() >= denominations[i].default.maxCarryables)
    		{
    			// Found it
    			break;
    		}
    	}

    	// Found a denomination if i is valid
    	if (i >= 0)
    	{
    		if (denominations[i].static.getCarriedMesh() != None)
    			carrier.carryableReference.unifiedSetMesh(denominations[i].static.getCarriedMesh());
    		else
    			carrier.carryableReference.unifiedSetMesh(denominations[i].default.StaticMesh);

    		//Log("AttachDenomination() called, set "$carrier.carryableReference$" static mesh to "$carrier.carryableReference.StaticMesh);
    	}
    	else
    	{
    		if (getCarriedMesh() != None)
    			unifiedSetMesh(getCarriedMesh());
    		else
    			unifiedSetMesh(default.StaticMesh);
    	}

    	if (self != carrier.carryableReference)
    	{
    		bHidden = true;
    		setMovementReplication(false);
    	}
    }

    // Havok
    simulated event Tick(float Delta)
    {
    	super.tick(Delta);

    	// return if outside boundary volume
    	if (Role == ROLE_Authority
    		&& !IsInState('Held')
    		&& !IsInState('Locked')
    		&& (Level.Game.BoundaryVolume != None && !Level.Game.BoundaryVolume.encompasses(self)))
    	{
    		dispatchMessage(new class'MessageCarryableReturned'(label));
    		returnToHome(true);
    	}

    	if (Physics != PHYS_Havok)
    		return;

    	// if server process input and pack output for replication
    	if (Role == ROLE_Authority)
    	{
    		//processInput();
    		if ( (Level.TimeSeconds > minimumNetUpdateInterval) &&
    				((Level.TimeSeconds > maximumNextNetUpdateTime) || needToPushStateToClient()))
    		{
    			minimumNextNetUpdateTime = Level.TimeSeconds + minimumNetUpdateInterval;
    			maximumNextNetUpdateTime = Level.TimeSeconds + maximumNetUpdateInterval;
    			pushStateToClient();
    		}
    	}
    }

    function bool needToPushStateToClient()
    {
    	local vector oldPos;
    	local vector oldLinVel;
    	local vector chassisPos, chassisLinVel, chassisAngVel;
    	local HavokRigidBodyState chassisState;

    	// see if state has changed enough, or enough time has passed, that we
    	// should send out another update by updating the state struct

    	// never send updates if physics is at rest
    	if (!HavokIsActive())
    		return false;

    	// get chassis state
    	HavokGetState(ChassisState);

    	chassisPos = ChassisState.Position;
    	chassisLinVel = ChassisState.LinVel;
    	chassisAngVel = ChassisState.AngVel;

    	// last position we sent
    	oldPos = ReplicationState.Position;
    	oldLinVel = ReplicationState.LinVel;

    	if(VSize(oldPos - chassisPos) > 2 || VSize(oldLinVel - chassisLinVel) > 0.5)
    	{
    		return true;
    	}

    	return false;
    }

    function pushStateToClient()
    {
    	local HavokRigidBodyState ChassisState;

    	HavokGetState(ChassisState);
    	//Log("Pushing state to client with position "$ChassisState.position);

    	ReplicationState.position = ChassisState.position;
    	ReplicationState.linVel = ChassisState.linVel * MPC_LINEAR_VELOCITY_ACCURACY_FACTOR;
    	ReplicationState.rotation = ChassisState.quaternion;
    	ReplicationState.angVel = ChassisState.angVel * MPC_ANGULAR_VELOCITY_ACCURACY_FACTOR;

    	// this flag lets the client know this data is new
    	ReplicationState.bNewState = true;

    	forceNetDirty();
    }

    simulated function updateHavok()
    {
    	if (!ReplicationState.bNewState)
    	{
    		Log("updateHavok() called without newState");
    		return;
    	}
    	lastStateReceiveTime = level.timeSeconds;

    	// update desired state
    	currentDesiredHavokState.position = ReplicationState.position;
    	currentDesiredHavokState.velocity = ReplicationState.linVel * MPC_LINEAR_VELOCITY_INVERSE_ACCURACY_FACTOR;
    	currentDesiredHavokState.angularVelocity = ReplicationState.angVel * MPC_ANGULAR_VELOCITY_INVERSE_ACCURACY_FACTOR;
    	currentDesiredHavokState.rotation = ReplicationState.rotation;
    	currentDesiredHavokState.newState = true;

    	// update flags
    	ReplicationState.bNewState = false;

    	//Log("Client called updateHavok()");
    }

    function int getNumCarryables()
    {
    	// This instance is 1 carryable.  MetaCarryables override this function and use it recursively.
    	return 1;
    }

    function int getMaxCarried()
    {
    	// Overriden by MetaCarryables
    	return maxCarried;
    }

    event EnergyBarrierCollision()
    {
    	if (Level.TimeSeconds - lastEnergyBarrierCollisionTime < timeBetweenEnergyBarrierCollisions)
    		return;

    	lastEnergyBarrierCollisionTime = Level.TimeSeconds;
    	if (carrier != None)
    	{
    		if (CarryableMessageClass != None)
    			carrier.receiveLocalizedMessage( CarryableMessageClass, 10 );
    	}
    	else if (lastCarrier != None)
    	{
    		if (CarryableMessageClass != None)
    			lastCarrier.receiveLocalizedMessage( CarryableMessageClass, 10 );
    	}
    }

    simulated static function Object getCarriedMesh()
    {
    	if (default.meshWhileCarried != None)
    		return default.meshWhileCarried;
    	else
    		return default.staticMeshWhileCarried;
    }

    simulated function unifiedSetMesh(Object m)
    {
    	if (StaticMesh(m) != None)
    	{
    		SetStaticMesh(StaticMesh(m));
    		SetDrawType(DT_StaticMesh);
    	}
    	else
    	{
    		LinkMesh(Mesh(m));
    		SetDrawType(DT_Mesh);
    		if (carriedAnimation != '' && HasAnim(carriedAnimation))
    			LoopAnim(carriedAnimation);
    	}
    }

    defaultproperties
    {
        NetUpdateFrequency			= 100
    	RemoteRole					= ROLE_SimulatedProxy

    	DrawType					= DT_StaticMesh
    	StaticMesh					= StaticMesh'MPGameObjects.MPFlag'
    	Physics						= PHYS_None
    	droppedPhysics				= PHYS_Falling
    	CollisionRadius				= 30
    	CollisionHeight				= 30
    	stopSpeed					= 40
        bUseCylinderCollision		= true
    	bCollideActors				= true
    	bCollideWorld				= true
    	bBounce						= true
    	bStatic						= false
    	bStasis						= false
    	bBlockActors				= false
    	bBlockPlayers				= false
    	bNetNotify					= true
    	bNeedLifetimeEffectEvents	= true
    	bUseCompressedPosition		= false

    	bProjTarget					= false
    	selfPickupTimeout			= 0.4
    	elasticity					= 0.2
    	GravityScale				= 1.0
    	Mass						= 100
    	bRotateToDesired			= false
    	maxCarried					= 1
    	returnTime					= 20
    	spread						= 500
    	bHardAttach					= true
    	bOwnerNoSee					= true
    	bBlockKarma					= false
    	bRandomizeStartingRotation	= false
    	bCanBeGrappledInField		= true
    	bCanBeGrappledAtHome		= false
    	maxTimeCarried				= -1
    	damagePerSecondAfterMaxTimeCarried	= 0
    	timeBetweenEnergyBarrierCollisions	= 3

    	pickupEffectEvent			= PickedUp
    	dropEffectEvent				= Dropped
    	thrownEffectEvent			= Thrown
    	carryingEffectEvent			= Carrying
    	idlingEffectEvent			= Idling
    	throwingEffectEvent			= Throwing
    	idlingHomeEffectEvent		= IdlingHome
    	returnedHomeEffectEvent		= Returned
    	preReturnEffectEvent		= PreReturned

    	carriedObjectClass			= class'MPCarryableThrower'
    	CarryableMessageClass		= class'MPCarryableMessages'

    	primaryFriendlyObjectiveDesc	= "Defend your team's carryable"
    	primaryEnemyObjectiveDesc		= "Get the enemy carryable"
    	primaryNeutralObjectiveDesc		= "Get the carryable"
    	attachmentSocket				= "flag"

    	maximumNetUpdateInterval=0.5
    	minimumNetUpdateInterval=0.2

    	bNetInitialRotation=true

    	NetPriority=3.0

    	bBlockHavok 					= false

    	// default icon for help screen
    	hudIcon				= texture'HUD.HelpTab'
    	hudIconCoords		= (U=0,V=14,UL=80,VL=40)

    	bBlockActorsWhenDropped		= true
    	inheritedVelocityFactor		= 0.85

    	clientInterpolationPeriod = 0.1
    	clientInterpolationSnapDistance = 50
    }

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

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