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

UTGame.UTProj_StingerShard


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
/**
 * Copyright 1998-2008 Epic Games, Inc. All Rights Reserved.
 */

class UTProj_StingerShard extends UTProjectile;

/** We need a pointer to our mesh component so we can switch collision when we create the constraint */
var StaticMeshComponent MyMesh;

/** This holds a link to our Constraint Actor */
var RB_ConstraintActor ShardVictimConstraint;

/** This is true if this projectile is currently spiking a victim */
var bool bSpiked;

/** Used to keep track of what actor to base ourselves on */
var Actor BaseActor;

var vector OldLocation;

var() float SpikeVictimVelFactor;

/** Used to prevent rare infinite recursion when spiking overlapping dead bodies */
var bool bCanCreateSpike;

simulated function PostBeginPlay()
{
	Super.PostBeginPlay();
	bCanCreateSpike = true;
}

/**
 * Insure that our constraint is destroyed when we are destroyed
 */
simulated event Destroyed()
{
	if (ShardVictimConstraint != none)
	{
		ShardVictimConstraint.Destroy();
	}

	Super.Destroyed();
}

static function bool FindNearestBone(UTPawn DeadPawn, vector InitialHitLocation, out name BestBone, out vector BestHitLocation)
{
	local int i, dist, BestDist;
	local vector BoneLoc;
	local name BoneName;

	if (DeadPawn.Mesh.PhysicsAsset != none)
	{
		for (i=0;i<DeadPawn.Mesh.PhysicsAsset.BodySetup.Length;i++)
		{
			BoneName = DeadPawn.Mesh.PhysicsAsset.BodySetup[i].BoneName;
			// If name is not empty and bone exists in this mesh
			if ( BoneName != '' && DeadPawn.Mesh.MatchRefBone(BoneName) != INDEX_NONE)
			{
				BoneLoc = DeadPawn.Mesh.GetBoneLocation(BoneName);
				Dist = VSize(InitialHitLocation - BoneLoc);
				if ( i==0 || Dist < BestDist )
				{
					BestDist = Dist;
					BestBone = DeadPawn.Mesh.PhysicsAsset.BodySetup[i].BoneName;
					BestHitLocation = BoneLoc;
				}
			}
		}

		if (BestBone != '')
		{
			return true;
		}
	}
	return false;
}


/**
 * This function creates the actual spike in the world.  A duplicate Shard projectile is spawned
 * and that projectile is used to spike the pawn.  We use a secondary actor in order to avoid
 * having to wait for replication to occur since this actor is spawned client-side
 */
static function bool CreateSpike(UTPawn DeadPawn, vector InitialHitLocation, vector Direction)
{
	local UTProj_StingerShard Shard;
	local vector BoneLoc;
	local name	 BoneName;
	local TraceHitInfo 	HitInfo;
	local vector Start, End, HitLocation, HitNormal;

	if ( DeadPawn != None && !class'GameInfo'.static.UseLowGore(DeadPawn.WorldInfo) && !DeadPawn.bDeleteMe && DeadPawn.Health <= 0 && DeadPawn.Physics == PHYS_RigidBody
		&& DeadPawn.Mesh != None && DeadPawn.Mesh.PhysicsAssetInstance != None )
	{
		Start = InitialHitLocation - (256.0 * Normal(Direction));
		End = Start + (512.0 * Normal(Direction));

		if ( DeadPawn.WorldInfo.TraceComponent(HitLocation, HitNormal, DeadPawn.Mesh, End, Start, vect(0,0,0), HitInfo) )
		{
			if (HitInfo.BoneName != '')
			{
				BoneLoc  = DeadPawn.Mesh.GetBoneLocation(HitInfo.BoneName);
				BoneName = HitInfo.BoneName;
			}
		}

		// Begin by tracing towards just this component, looking for the nearest bone it collides with (if any)
		if ( BoneName != '' || FindNearestBone(DeadPawn, InitialHitLocation, BoneName, BoneLoc) )
		{
			// Spawn a shard
			BoneLoc -= (32 * Direction);

			Shard = DeadPawn.Spawn(class'UTProj_StingerShard',,, BoneLoc, rotator(Direction));
			if (Shard != None)
			{
				// Give this shard a push
				Shard.bCanCreateSpike = false;
				Shard.Speed = 800;
				Shard.AccelRate = 0.0f;
				Shard.Init(Direction);

				// Attach the victim to this shard
				Shard.SpikeVictim(DeadPawn,BoneName);

				return true;
			}
		}
	}

	return false;
}

/**
 * This function is called when the touch occurs locally in a remote client.  It checks
 * to see if the pawn is already ragdolling and if so, spikes it again
 */
simulated function ClientSideTouch(Actor Other, Vector HitLocation)
{
	local UTPawn DeadPawn;

	DeadPawn = UTPawn(Other);

	if ( bCanCreateSpike && CreateSpike(DeadPawn, HitLocation, Normal(Vector(Rotation))))
	{
		Destroy();
	}
	else
	{
		Other.TakeDamage(Damage, InstigatorController, Location, MomentumTransfer * Normal(Velocity), MyDamageType,, self);
	}
}

/**
 * We have to override HitWall in order to store a pointer to the actor
 * that we hit (in the case of non-world geometry).  This way we can
 * be stuck to tanks, etc.
 */
simulated singular function HitWall(vector HitNormal, actor Wall, PrimitiveComponent WallComp)
{
	if (Wall != Instigator)
	{
		if (!Wall.bStatic && !Wall.bWorldGeometry)
		{
			if (DamageRadius == 0)
			{
				Wall.TakeDamage(Damage, InstigatorController, Location, MomentumTransfer * Normal(Velocity), MyDamageType,, self);
			}
			ImpactedActor = Wall;
		}
		else
		{
			BaseActor = Wall;
		}

		Explode(Location, HitNormal);
		ImpactedActor = None;
	}

	// If we are already spiked, stick in to the wall
	if (bSpiked)
	{
		// can't stick to blocking volumes
		if (BlockingVolume(Wall) != None)
		{
			Destroy();
		}
		else
		{
			Velocity = vect(0,0,0);
			SetBase(Wall);
			SetPhysics(PHYS_None);
		}
	}
}

/**
 * This function is responsible for creating the constraint between the projectile
 * and the victim.
 */
simulated function SpikeVictim(UTPawn Victim, name VictimBone)
{
	local UTProj_StingerShard OtherShard;

	// destroy any previous shards on the victim so we don't get nasty fighting between the two constraints
	foreach DynamicActors(class'UTProj_StingerShard', OtherShard)
	{
		if (OtherShard.ShardVictimConstraint != None && OtherShard.ShardVictimConstraint.ConstraintActor2 == Victim)
		{
			OtherShard.Destroy();
		}
	}

	CollisionComponent = MyMesh;

	// give projectile extent so that it collides the same way the pawn does
	// (so we don't get the ragdoll stuck in a blocking volume, etc)
	bSwitchToZeroCollision = false;
	CylinderComponent.SetCylinderSize(1.0, 1.0);
	CylinderComponent.SetActorCollision(true, false);

	SetLocation(Victim.Mesh.GetBoneLocation(VictimBone));

	ShardVictimConstraint = Spawn(class'RB_ConstraintActorSpawnable',,,Location);
	ShardVictimConstraint.SetBase(self);
	ShardVictimConstraint.InitConstraint( self, Victim, '', VictimBone, 2000.f);
	ShardVictimConstraint.LifeSpan = 8.0;

	// Add some velocity to the victim overall, to avoid the spike having to do all the work of pulling them
	Victim.Mesh.SetRBLinearVelocity(Velocity*SpikeVictimVelFactor, TRUE);

	if (WorldInfo.NetMode != NM_DedicatedServer)
	{
		Victim.LifeSpan += 8.0;
	}

	LifeSpan = 8.0;
	bSpiked = true;
	AdjustPhysicsForHit();

}

/**
 * We only want to process the touch if we are not spike and we are not a remote client.  In the case of
 * a remote client, ClientTouch should be used.
 */
simulated function ProcessTouch(Actor Other, Vector HitLocation, Vector HitNormal)
{
	local UTPawn P;

	if (!bSpiked && Role == ROLE_Authority)
	{
		if ( Other != Instigator )
		{
			P = UTPawn(Other);
			Other.TakeDamage(Damage, InstigatorController, HitLocation, MomentumTransfer * Normal(Velocity), MyDamageType,, self);
			if (P != None && (WorldInfo.NetMode == NM_DedicatedServer || !bCanCreateSpike || !CreateSpike(P, HitLocation, Normal(Velocity))))
			{

				if (P != None && P.Health <= 0)
				{
					P.TearOffMomentum = Velocity;
					if (WorldInfo.NetMode != NM_DedicatedServer && bCanCreateSpike)
					{
						CreateSpike(P, HitLocation, Normal(Velocity));
					}
				}
			}
			Shutdown();
		}
	}

	if ( (Role < ROLE_Authority) && (Other.Role == ROLE_Authority) )
	{
		ClientSideTouch(Other, HitLocation);
	}
}

/**
 * Make sure to set our base properly
 */
simulated function Shutdown()
{
	if (BaseActor != none)
	{
		SetBase(BaseActor);
	}

	if (!bSpiked)
	{
		Super.ShutDown();
	}
}

/**
 * Setup this projectile's physics after it has spiked a victim
 */
simulated function AdjustPhysicsForHit()
{
	Velocity = Speed * Normal(vector(Rotation));
	Velocity.Z += 100.0;
	SetPhysics(PHYS_Falling);
	Acceleration = vect(0,0,0);
	CustomGravityScaling = 0.5;
}

defaultproperties
{
   Begin Object Class=StaticMeshComponent Name=ProjectileMesh ObjName=ProjectileMesh Archetype=StaticMeshComponent'Engine.Default__StaticMeshComponent'
      StaticMesh=StaticMesh'WP_Stinger.Mesh.S_WP_StingerShard'
      CullDistance=12000.000000
      CachedCullDistance=12000.000000
      bUseAsOccluder=False
      CastShadow=False
      bAcceptsLights=False
      CollideActors=False
      BlockActors=False
      BlockRigidBody=False
      Scale=1.500000
      Name="ProjectileMesh"
      ObjectArchetype=StaticMeshComponent'Engine.Default__StaticMeshComponent'
   End Object
   MyMesh=ProjectileMesh
   SpikeVictimVelFactor=0.500000
   ProjExplosionTemplate=ParticleSystem'WP_Stinger.Particles.P_WP_Stinger_AltFire_Surface_Impact'
   MaxEffectDistance=7000.000000
   AccelRate=4500.000000
   CheckRadius=27.000000
   Speed=2500.000000
   MaxSpeed=4000.000000
   Damage=38.000000
   MomentumTransfer=70000.000000
   MyDamageType=Class'UTGame.UTDmgType_StingerShard'
   Begin Object Class=CylinderComponent Name=CollisionCylinder ObjName=CollisionCylinder Archetype=CylinderComponent'UTGame.Default__UTProjectile:CollisionCylinder'
      ObjectArchetype=CylinderComponent'UTGame.Default__UTProjectile:CollisionCylinder'
   End Object
   CylinderComponent=CollisionCylinder
   Components(0)=CollisionCylinder
   Components(1)=ProjectileMesh
   LifeSpan=10.000000
   CollisionComponent=CollisionCylinder
   Name="Default__UTProj_StingerShard"
   ObjectArchetype=UTProjectile'UTGame.Default__UTProjectile'
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: tr 31-1-2018 17:18:44.000 - Creation time: sk 18-3-2018 10:01:24.285 - Created with UnCodeX