//=============================================================================
// ASMD.
//=============================================================================
class ASMD expands Weapon;

#exec MESH IMPORT MESH=ASMD ANIVFILE=MODELS\ASMD_a.3D DATAFILE=MODELS\ASMD_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=ASMD X=0 Y=0 Z=0 YAW=-64 PITCH=0
#exec MESH SEQUENCE MESH=ASMD SEQ=All       STARTFRAME=0  NUMFRAMES=80
#exec MESH SEQUENCE MESH=ASMD SEQ=Select    STARTFRAME=0  NUMFRAMES=14 RATE=27 GROUP=Select
#exec MESH SEQUENCE MESH=ASMD SEQ=Still     STARTFRAME=14 NUMFRAMES=2
#exec MESH SEQUENCE MESH=ASMD SEQ=Down      STARTFRAME=16 NUMFRAMES=10
#exec MESH SEQUENCE MESH=ASMD SEQ=Still2    STARTFRAME=26 NUMFRAMES=2
#exec MESH SEQUENCE MESH=ASMD SEQ=Fire1     STARTFRAME=28 NUMFRAMES=9
#exec MESH SEQUENCE MESH=ASMD SEQ=Fire2     STARTFRAME=37 NUMFRAMES=10
#exec MESH SEQUENCE MESH=ASMD SEQ=Steam     STARTFRAME=47 NUMFRAMES=10
#exec MESH SEQUENCE MESH=ASMD SEQ=Cocking   STARTFRAME=57 NUMFRAMES=19
#exec MESH SEQUENCE MESH=ASMD SEQ=Sway      STARTFRAME=76 NUMFRAMES=4
#exec TEXTURE IMPORT NAME=ASMD1 FILE=MODELS\ASMD.PCX GROUP="Skins"
#exec OBJ LOAD FILE=Textures\SmokeEffect3.utx PACKAGE=UNREALI
#exec MESHMAP SCALE MESHMAP=ASMD X=0.005 Y=0.005 Z=0.01
#exec MESHMAP SETTEXTURE MESHMAP=ASMD NUM=1 TEXTURE=ASMD1
#exec MESHMAP SETTEXTURE MESHMAP=ASMD NUM=0 TEXTURE=SmokeEffect3

#exec MESH IMPORT MESH=ASMDPick ANIVFILE=MODELS\Tazlo_a.3D DATAFILE=MODELS\Tazlo_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=ASMDPick X=0 Y=-10 Z=-13 YAW=-64 PITCH=0
#exec MESH SEQUENCE MESH=ASMDPick SEQ=All   STARTFRAME=0  NUMFRAMES=6
#exec TEXTURE IMPORT NAME=ASMD1 FILE=MODELS\ASMD.PCX GROUP="Skins"
#exec MESHMAP SCALE MESHMAP=ASMDPick X=0.1 Y=0.1 Z=0.2
#exec MESHMAP SETTEXTURE MESHMAP=ASMDPick NUM=1 TEXTURE=ASMD1

#exec MESH IMPORT MESH=ASMD3 ANIVFILE=MODELS\Tazlo_a.3D DATAFILE=MODELS\Tazlo_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=ASMD3 X=0 Y=-190 Z=-50 YAW=-64 PITCH=0
#exec MESH SEQUENCE MESH=ASMD3 SEQ=All   STARTFRAME=0  NUMFRAMES=6
#exec MESH SEQUENCE MESH=ASMD3 SEQ=Still STARTFRAME=0  NUMFRAMES=1
#exec MESH SEQUENCE MESH=ASMD3 SEQ=Fire1 STARTFRAME=1  NUMFRAMES=5
#exec TEXTURE IMPORT NAME=ASMD1 FILE=MODELS\ASMD.PCX GROUP="Skins"
#exec MESHMAP SCALE MESHMAP=ASMD3 X=0.06 Y=0.06 Z=0.12
#exec MESHMAP SETTEXTURE MESHMAP=ASMD3 NUM=1 TEXTURE=ASMD1

#exec AUDIO IMPORT FILE="Sounds\Tazer\TSHOTA6.WAV" NAME="TazerFire" GROUP="ASMD"
#exec AUDIO IMPORT FILE="Sounds\Tazer\TSHOTB1.WAV" NAME="TazerAltFire" GROUP="ASMD"
#exec AUDIO IMPORT FILE="Sounds\Tazer\TPICKUP3.WAV" NAME="TazerSelect" GROUP="ASMD"

var() int HitDamage;
var Amplifier Amp;


function bool HandlePickupQuery( inventory Item )
{

	if (Amplifier(Item) != None) 
	{
		Amp = Amplifier(Item);
	}
	return CallParent.HandlePickupQuery(Item);	
}

function BecomePickup()
{
	Amp = None;
	CallParent.BecomePickup();
}

function PreBeginPlay()
{
	CallParent.PreBeginPlay();
	AltProjectileClass = class'TazerProj';
	AltProjectileSpeed = TazerProj.Default.speed;
}
 

function Timer()
{
	local actor targ;
	local float bestAim, bestDist;
	local vector FireDir;

	bestAim = 0.95;
	if ( Pawn(Owner) == None )
	{
		GotoState('');
		return;
	}
	FireDir = vector(Pawn(Owner).ViewRotation);
	targ = Pawn(Owner).PickTarget(bestAim, bestDist, FireDir, Owner.Location);
	if ( Pawn(targ) != None )
	{
		bPointing = true;
		Pawn(targ).WarnTarget(Pawn(Owner), 300, FireDir);
	}
	else 
		bPointing = false;
}	

function Finish()
{
	if ( (bFireMem || (Pawn(Owner).bFire!=0)) && (FRand() < 0.6) )
		Timer();
	CallParent.Finish();
}

///////////////////////////////////////////////////////
function PlayFiring()
{
	Owner.PlaySound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);
	PlayAnim('Fire1', 0.5,0.05);
}

function Projectile ProjectileFire(class ProjClass, float ProjSpeed, bool bWarn)
{
	local Vector Start, X,Y,Z;
	local float Mult;
	local Projectile t;

	if (Amp!=None) Mult = Amp.UseCharge(80);
	else Mult=1.0;

	Owner.MakeNoise(1.0);
	GetAxes(Pawn(owner).ViewRotation,X,Y,Z);
	Start = Owner.Location + CalcDrawOffset() + FireOffset.X * X + FireOffset.Y * Y + FireOffset.Z * Z; 
	AdjustedAim = pawn(owner).AdjustAim(ProjSpeed, Start, AimError, True, bWarn);	
	t = Projectile(Spawn(ProjClass,,, Start,AdjustedAim));	
	t.Damage = t.Damage*Mult;
}


function ProcessTraceHit(Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)
{
	local RingExplosion4 Smoke;
	local vector SmokeLocation,DVector;
	local rotation SmokeRotation;
	local float NumPoints,Mult;
	local int i;

	if (Amp!=None) Mult = Amp.UseCharge(100);
	else Mult=1.0;

	if ( TazerProj(Other)!=None ) 
		TazerProj(Other).SuperExplosion();
	else
	{
		if (Mult>1.5) Spawn(class'RingExplosion3',,, HitLocation+HitNormal*8,Rotation(HitNormal));
		else Spawn(class'RingExplosion',,, HitLocation+HitNormal*8,Rotation(HitNormal));
		Spawn(class'EffectLight',,, HitLocation+HitNormal*8);
	}

	SmokeLocation = Owner.Location + CalcDrawOffset() + FireOffset.X * X + FireOffset.Y * 3.3 * Y + FireOffset.Z * Z * 3.0;
	DVector = HitLocation - SmokeLocation;
	NumPoints = Size(DVector)/70.0;
	SmokeLocation += DVector/NumPoints;
	SmokeRotation = Rotation(HitLocation-Pawn(Owner).Location);
	if (NumPoints>15) NumPoints=15;
	if (NumPoints>1.0 && Level.Netmode!=NM_Server)
	{
//		For (i=0 ; i<int(NumPoints) ; i++) 
//		{
			Smoke = Spawn(class'RingExplosion4',, '', SmokeLocation,SmokeRotation);
			Smoke.MoveAmount = DVector/NumPoints;
			Smoke.NumPuffs = NumPoints;
//			if (FRand()<0.5) Smoke.PuffNum=1;
//			else  Smoke.PuffNum=2;
//			SmokeLocation += DVector/NumPoints;
//		}
	}
	
	if ( (Other != self) && (Other != Owner) ) 
		Other.Damage(HitDamage*Mult, Pawn(Owner), HitLocation, 60000.0*X, 'jolted');
}

function PlayAltFiring()
{
	Owner.PlaySound(AltFireSound, SLOT_None,Pawn(Owner).SoundDampening*3.0);
	PlayAnim('Fire1',0.8,0.05);
}

function PlayIdleAnim()
{
	if ( AnimSequence == 'Fire1' )
		PlayAnim('Steam',0.1,0.4);
	else if ( Size(Owner.Velocity) > 20 )
	{
		if ( AnimSequence=='Still' )
			LoopAnim('Sway',0.1,0.3);
	}
	else if ( AnimSequence!='Still' ) 
	{
		if (FRand()<0.5) PlayAnim('Steam',0.1,0.4);
		else LoopAnim('Still',0.04,0.3);
	}
	Enable('AnimEnd');
}

state Idle
{

	function BeginState()
	{
		bPointing = false;
		SetTimer(0.4 + 1.8 * FRand(), true);
		CallParent.BeginState();
	}

	function EndState()
	{
		SetTimer(0.0, false);
		CallParent.EndState();
	}
}

