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

Gameplay.Explosion


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
///////////////////////////////////////////////////////////////////////////////
//
// Explosion
//

class Explosion extends Engine.Actor placeable;

// Physics & Force properties
var (Explosion) float RadialForce				"Force of explosion out radially from center";
var (Explosion) float LiftForce					"Force of explosion applied directly upwards";
var (Explosion) float ChaoticForce				"Chaotic force of explosion (random direction) *NOT CURRENTLY IMPLEMENTED*";
var (Explosion) float StartRadialVelocity		"Starting Radial velocity of explosion outwards";
var (Explosion) float RadialAcceleration		"Radial acceleration of explosion outwards";
var (Explosion) float RadialAccelerationChange	"Change in acceleration over time";
var (Explosion) bool AllowDownforce				"Whether to allow down forces on the explosion";
var (Explosion) bool AllowForceRepeat			"Whether to allow the force to be applied repeatedly to objects which remain in the explosion radius";

// Falloff properties
var (Explosion) float StartRadius				"What radius the explosion starts at (immediate area of effect)";
var (Explosion) float EndRadius					"The end radius of the explosion";
var (Explosion) float FalloffStartRadius		"At what radius the falloff begins";
var (Explosion) float LingerTime				"How long the explosion 'lingers' for after it reaches it's max radius";

// Damage properties
var (Explosion) float				MaxDamage			"The maximum amount of damage to apply to an affected object (changes with falloff)";
var (Explosion) class<DamageType>	DamageTypeClass		"The damage type infliced on victims of the explosion";

// FX properties
var (Explosion) float ShakeTime					"Duration of camera shake";
var (Explosion) float ShakeMagnitude			"Magnitude of camera shake";
var (Explosion) float ShakeRadius				"Radius to be added to the explosion area of effect";
var (Explosion) Name Effect						"Effect for explosion";

// Unaffected classes
var (Explosion) Array<Name>	UnaffectedActorTypes	"Array of class names which are unaffected by the explosion";

// Debug Properties
var (Explosion) bool DestroyOnFinish			"Whether to destroy the explosion when it has exploded";
var (Explosion) bool ShowVisualisation			"Show the debug explosion visualisation";

var float			Radius;				// current radius of explosion
var float			RadialVelocity;		// current velocity of explosion
var float			LingerCounter;		// how long we have been lingering for
var Array<Actor>	Affected;			// array of already affected actors
var Pawn			StoredEventInstigator;

var ExplosionVisualisation vis;	// debug vis object

function PostBeginPlay()
{
	super.PostBeginPlay();
}

function Trigger(Actor Other, Pawn EventInstigator)
{
	StoredEventInstigator = EventInstigator;
	GotoState('Exploding');
}

function DoExplosion()
{
}

state Exploding
{
	function BeginState()
	{
		TriggerEffectEvent(Effect);

		Radius = StartRadius;
		RadialVelocity = StartRadialVelocity;
		LingerCounter = 0;
		if(Affected.Length > 0)
			Affected.Remove(0, Affected.Length);	// Clear the Affected Array

		// Init Debug visualisation
		if(vis == None && ShowVisualisation)
		{
			vis = spawn(class'ExplosionVisualisation', , , Location, Rot(0, 0, 0));
			vis.owner = self;
			vis.unifiedSetPosition(Location);
			vis.SetPhysics(PHYS_None);
		}
	}

	function Tick(float Delta)
	{
		local Vector Impulse;
		local Vector HitLocation;
		local Vector Direction;
		local Vector CenterOfMass;
		local Vector Offset;
		local Actor Object;
		local Controller C;
		local Pawn P;
		local float FalloffPercent;
		local float HitLocationRadius;
		local bool DontAffect;
		local int i;

		DontAffect = false;

		// Integrate values
		RadialAcceleration += RadialAccelerationChange * Delta;
		RadialVelocity += RadialAcceleration * Delta;
		Radius += RadialVelocity * Delta;

		// cap the Radius
		if(Radius > EndRadius)
			Radius = EndRadius;

		// Update debug visualisation
		if(ShowVisualisation)
		{
			vis.bHidden = false;
			vis.UpdateVis();
		}

		// find all objects in radius
		foreach VisibleCollidingActors(class'Actor', Object, Radius, Location, true, true, self, true)
		{
			if(IsAffected(Object))
			{
				// search the affected objects to ensure we arent 
				// applying explosive effects more than once
				for(i = 0; i < Affected.Length; i++)
				{
					if(Affected[i] == Object)
					{
						DontAffect = true;
						break;
					}
				}

				Affected.Length = Affected.Length + 1;
				Affected[Affected.Length - 1] = Object;

				// calculate the force to be applied
				CenterOfMass = Object.unifiedGetNaturalCOMPosition();

				Offset = VRand() * 5;
				HitLocation = Offset + CenterOfMass;

				// calc the falloff percentage based on the hit location
				FalloffPercent = 1.0;
				HitLocationRadius = VSize(HitLocation - Location);
				if(Radius > FalloffStartRadius)
					FalloffPercent = fClamp(1.0 - (HitLocationRadius - FalloffStartRadius) / (EndRadius - FalloffStartRadius), 0.0, 1.0);

				Direction = Normal(HitLocation - Location);
				Impulse += RadialForce * Direction;

				Impulse.Z += LiftForce;

				// restrict the downforce if configured so
				if(! AllowDownforce && Impulse.Z < 0)
					Impulse.Z = 0;
					
			    // respect character knockback scale
			    if (Character(object)!=None && object.Physics==PHYS_Movement)
			        Impulse *= Character(object).movementKnockbackScale;

				// apply impulse - respecing the AllowForceRepeat & DontAffect flags
				if(AllowForceRepeat)
					Object.unifiedAddImpulseAtPosition(Impulse * FalloffPercent, HitLocation);
				else if(! DontAffect)
					Object.unifiedAddImpulseAtPosition(Impulse * FalloffPercent, HitLocation);

				if(! DontAffect)
				{
					// apply damage if not in hurt radius family or parent of hurt radius family
					if (Object.getHurtRadiusParent() == None || Object.getHurtRadiusParent() == Object)
						Object.TakeDamage(MaxDamage * FalloffPercent, StoredEventInstigator, HitLocation, vect(0,0,0), DamageTypeClass);

					// shake camera view
					P = Pawn(Object);
					if (P!=None && P.Controller!=None)
					{
						for ( C=Level.ControllerList; C!=None; C=C.NextController )
							if ( (PlayerController(C) != None) && (VSize(Location - PlayerController(C).ViewTarget.Location) < ShakeRadius) )
								P.Controller.ShakeView(ShakeTime, 10 * ShakeMagnitude, ShakeMagnitude * vect(0.0,0.0,1.00000), 12000, ShakeMagnitude * vect(10,10,10), 1 + 0.1f * ShakeMagnitude);
					}
				}

				DontAffect = false;
			}
		}

		if(Radius >= EndRadius)
		{
			if(LingerCounter >= LingerTime)
			{
				// hide debug visualisation
				if(ShowVisualisation)
					vis.bHidden = true;
				GotoState('None');
				if(DestroyOnFinish)
				{
					if (vis != None)
						vis.Destroy();

					Destroy();
				}
			}
			else
			{
				LingerCounter += Delta;
			}
		}
	}
}

// returns whether the given object will be affected
// by the explosion
function bool IsAffected(Actor Object)
{
	local int i;

	// dont affect the explosion object - it's just wrong
	if(Object == self || Object == vis)
		return false;

	for(i = 0; i < UnaffectedActorTypes.Length; i++)
	{
		if(Object.IsA(UnaffectedActorTypes[i]))
		{
			return false;
		}
	}

	// only affect authorities
	if (Object.Role != ROLE_Authority)
		return false;

	return true;
}

defaultproperties
{
    DrawType = DT_None

	Physics = PHYS_None
	bCollideWorld = false
	bCollideActors = false
	bBlockActors = false
	bBlockPlayers = false

	RadialForce = 105000
	LiftForce = 105000
	ChaoticForce = 0
	StartRadialVelocity = 10
	RadialAcceleration = 10000
	RadialAccelerationChange = 0
	AllowDownforce = false
	AllowForceRepeat = false;

	StartRadius = 50
	EndRadius = 900
	FalloffStartRadius = 450
	LingerTime = 0.0

	MaxDamage = 10
	DamageTypeClass = class'ExplosionDamageType'

	ShakeMagnitude = 25
	ShakeTime = 15
	ShakeRadius = 1000

	DestroyOnFinish = true
	ShowVisualisation = false
	
    UnaffectedActorTypes(0) = "Projectile"
    
    Effect = "Exploded";

	RemoteRole = ROLE_None
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: ne 5.9.2004 15:53:20.000 - Creation time: st 23.5.2018 00:10:43.349 - Created with UnCodeX