//=============================================================================
// ShockWave.
//=============================================================================
class ShockWave expands Effects;

#exec MESH IMPORT MESH=ShockWavem ANIVFILE=MODELS\SW_a.3D DATAFILE=MODELS\SW_d.3D X=0 Y=0 Z=0 
#exec MESH ORIGIN MESH=ShockWavem X=0 Y=0 Z=0 YAW=0 PITCH=64
#exec MESH SEQUENCE MESH=ShockWavem SEQ=All       STARTFRAME=0   NUMFRAMES=2
#exec MESH SEQUENCE MESH=ShockWavem SEQ=Explosion STARTFRAME=0   NUMFRAMES=2
#exec TEXTURE IMPORT NAME=Shockt1 FILE=MODELS\shockw.PCX GROUP="Skins"
#exec TEXTURE IMPORT NAME=Shockt1 FILE=TEXTURES\EXPLO\shock.PCX  GROUP="Skins"
#exec OBJ LOAD FILE=Textures\shockwave.utx PACKAGE=BotPack.Shockws
#exec MESHMAP SCALE MESHMAP=ShockWavem X=1.0 Y=1.0 Z=2.0 
#exec MESHMAP SETTEXTURE MESHMAP=ShockWavem NUM=1 TEXTURE=Shockt1

var float Count, OldShockDistance;
var int ICount;

simulated function Tick( float DeltaTime )
{
	if ( Level.NetMode != NM_DedicatedServer )
	{
		Count += DeltaTime*13.0;
		ScaleGlow = (Lifespan/Default.Lifespan);
		AmbientGlow = ScaleGlow * 255;
		DrawScale = Count + 3.5/(ScaleGlow+0.05);
	}
}


simulated function Timer()
{

	local actor Victims;
	local float damageScale, dist;
	local vector dir;

	if ( Level.NetMode != NM_DedicatedServer )
	{
		if (ICount==4) spawn(class'WarExplosion2',,,Location);
		ICount++;

		if ( Level.NetMode == NM_Client )
		{
			foreach VisibleCollidingActors( class 'Actor', Victims, DrawScale*29, Location )
				if ( Victims.Role == ROLE_Authority )
				{
					dir = Victims.Location - Location;
					dist = FMax(1,VSize(dir));
					dir = dir/dist +vect(0,0,0.3); 
					if (dist> OldShockDistance || (dir dot Victims.Velocity < 0))
					{
						if ( Victims.bIsPawn )
							Pawn(Victims).AddVelocity(dir * (ScaleGlow * 1000.0 + 20));
						else
							Victims.Velocity = Victims.Velocity + dir * (ScaleGlow * 1000.0 + 20);	
						Victims.TakeDamage
						(
							ScaleGlow*1000,
							Instigator, 
							Victims.Location - 0.5 * (Victims.CollisionHeight + Victims.CollisionRadius) * dir,
							(1000 * dir),
							'vaporized'
						);
					}
				}	
			return;
		}
	}

	foreach VisibleCollidingActors( class 'Actor', Victims, DrawScale*29, Location )
	{
		dir = Victims.Location - Location;
		dist = FMax(1,VSize(dir));
		dir = dir/dist +vect(0,0,0.3); 
		if (dist> OldShockDistance || (dir dot Victims.Velocity < 0))
		{
			if ( Victims.bIsPawn )
				Pawn(Victims).AddVelocity(dir * (ScaleGlow * 1000.0 + 20));
			else
				Victims.Velocity = Victims.Velocity + dir * (ScaleGlow * 1000.0 + 20);	
			Victims.TakeDamage
			(
				ScaleGlow*1000,
				Instigator, 
				Victims.Location - 0.5 * (Victims.CollisionHeight + Victims.CollisionRadius) * dir,
				(1000 * dir),
				'vaporized'
			);
		}
	}	
	OldShockDistance = DrawScale*29;	
}

simulated function PostBeginPlay()
{
	local PlayerPawn Victims;

	if ( Role == ROLE_Authority ) 
	{
		foreach VisibleCollidingActors( class 'PlayerPawn', Victims, 3000, Location )
			Victims.ShakeView(0.5, 600000.0/VSize(Victims.Location - Location), 10);

		if ( Instigator != None )
			MakeNoise(1.0);
	}

	SetTimer(0.1, True);

	if ( Level.NetMode != NM_DedicatedServer )
		SpawnEffects();
}

simulated function SpawnEffects()
{
	 PlaySound(Sound'Expl03',,6.0);
	 spawn(class'WarExplosion',,,Location);
}

defaultproperties
{
     RemoteRole=ROLE_SimulatedProxy
     LifeSpan=1.500000
     DrawType=DT_Mesh
     Style=STY_Translucent
     Mesh=Mesh'BotPack.ShockWavem'
     AmbientGlow=255
     bUnlit=True
}
