//=============================================================================
// ExplodingWall.
//=============================================================================
class ExplodingWall expands Effects;

#exec Texture Import File=models\exp001.pcx  Name=s_Exp Mips=Off Flags=2

var() float ExplosionSize;
var() float ExplosionDimensions;
var() float WallParticleSize;
var() float WoodParticleSize;
var() float GlassParticleSize;
var() int NumWallChunks;
var() int NumWoodChunks;
var() int NumGlassChunks;
var() texture WallTexture;
var() texture WoodTexture;
var() texture GlassTexture;
var() int Health;
var() name ActivatedBy[5];
var bool bWasTriggered;

function PreBeginPlay()
{
	DrawType = DT_None;
}


Auto State Explode
{
	function Trigger( actor Other, pawn EventInstigator )
	{
		bOnlyTriggerable = False;
		bWasTriggered = True;
		Damage( 10, EventInstigator, Location, Vector(Rotation), 'detonated' );
	}

	function Damage( int NDamage, Pawn InstigatedBy, Vector HitLocation,
						Vector Momentum, name DamageType)
	{
		local int i;
		local Fragment s;
		local actor A;
		local bool bAbort;	
		
		if (!bOnlyTriggerable) 
		{		
			bAbort=True;				// if Damage type is correct, then proceed
			for (i=0; i<5; i++) 
				if (DamageType==ActivatedBy[i]) bAbort=False;
			if (bAbort && !bWasTriggered && DamageType!='All') Return;
			Health-=NDamage;
			if (Health<=0 || bWasTriggered) 
			{
				Instigator = InstigatedBy;
				if( Event != '' )
					foreach AllActors( class 'Actor', A, Event )
						A.Trigger( InstigatedBy, InstigatedBy );
			
				for (i=0 ; i<NumWallChunks ; i++) 
				{
					s = Spawn( class 'WallFragments',,,Location);
					s.CalcVelocity(vect(0,0,0),ExplosionSize,ExplosionDimensions);
					s.DrawScale = WallParticleSize;
					s.Skin = WallTexture;
				}
				for (i=0 ; i<NumWoodChunks ; i++) 
				{
					s = Spawn( class 'WoodFragments',,,Location);
					s.CalcVelocity(vect(0,0,0),ExplosionSize,ExplosionDimensions);
					s.DrawScale = WoodParticleSize;
					s.Skin = WoodTexture;
				}
				for (i=0 ; i<NumGlassChunks ; i++) 
				{
					s = Spawn( class 'GlassFragments',,,Location);
					s.CalcVelocity(vect(0,0,0),ExplosionSize,ExplosionDimensions);
					s.DrawScale = GlassParticleSize;
					s.Skin = GlassTexture;
				}			
				Destroy();
			}
		}
	}

Begin:
	bWasTriggered=False;
}

