//=============================================================================
// Stinger.
//=============================================================================
class Stinger expands Weapon;

#exec MESH IMPORT MESH=Stinger ANIVFILE=MODELS\aniv51.3D DATAFILE=MODELS\data51.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=Stinger X=0 Y=0 Z=0 YAW=64
#exec MESH SEQUENCE MESH=Stinger SEQ=All  STARTFRAME=0  NUMFRAMES=44
#exec MESH SEQUENCE MESH=Stinger SEQ=Select  STARTFRAME=0  NUMFRAMES=21 GROUP=Select
#exec MESH SEQUENCE MESH=Stinger SEQ=Still STARTFRAME=21  NUMFRAMES=1
#exec MESH SEQUENCE MESH=Stinger SEQ=Down  STARTFRAME=22  NUMFRAMES=11
#exec MESH SEQUENCE MESH=Stinger SEQ=FireOne STARTFRAME=33  NUMFRAMES=3
#exec MESH SEQUENCE MESH=Stinger SEQ=FireThree STARTFRAME=36  NUMFRAMES=7

#exec TEXTURE IMPORT NAME=SpikHand1 FILE=MODELS\Spikegun.PCX GROUP="Skins"
#exec OBJ LOAD FILE=Textures\FireEffect18.utx PACKAGE=UNREALI
#exec MESHMAP SCALE MESHMAP=Stinger X=0.005 Y=0.005 Z=0.01
#exec MESHMAP SETTEXTURE MESHMAP=Stinger NUM=1 TEXTURE=SpikHand1
#exec MESHMAP SETTEXTURE MESHMAP=Stinger NUM=0 TEXTURE=FireEffect18
 
#exec MESH IMPORT MESH=StingerPickup ANIVFILE=MODELS\aniv55.3D DATAFILE=MODELS\data55.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=StingerPickup X=100 Y=-100 Z=0 YAW=0 PITCH=0
#exec MESH SEQUENCE MESH=StingerPickup SEQ=All  STARTFRAME=0  NUMFRAMES=1
#exec MESH SEQUENCE MESH=StingerPickup SEQ=Still STARTFRAME=0  NUMFRAMES=1
#exec TEXTURE IMPORT NAME=Sting1 FILE=MODELS\spikegun.PCX GROUP="Skins"
#exec MESHMAP SCALE MESHMAP=StingerPickup X=0.03 Y=0.03 Z=0.06
#exec MESHMAP SETTEXTURE MESHMAP=StingerPickup NUM=1 TEXTURE=Sting1

#exec MESH IMPORT MESH=Stinger3rd ANIVFILE=MODELS\Sting3_a.3D DATAFILE=MODELS\Sting3_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=Stinger3rd X=0 Y=350 Z=-15 YAW=-64 ROLL=128 PITCH=128
#exec MESH SEQUENCE MESH=Stinger3rd SEQ=All  STARTFRAME=0  NUMFRAMES=6
#exec MESH SEQUENCE MESH=Stinger3rd SEQ=Still  STARTFRAME=0  NUMFRAMES=1
#exec MESH SEQUENCE MESH=Stinger3rd SEQ=FireOne  STARTFRAME=1  NUMFRAMES=5
#exec TEXTURE IMPORT NAME=JSting2 FILE=MODELS\sting3.PCX GROUP="Skins"
#exec OBJ LOAD FILE=textures\FireEffect18.utx PACKAGE=UNREALI
#exec MESHMAP SCALE MESHMAP=Stinger3rd X=0.03 Y=0.03 Z=0.06
#exec MESHMAP SETTEXTURE MESHMAP=Stinger3rd NUM=1 TEXTURE=JSting2
#exec MESHMAP SETTEXTURE MESHMAP=Stinger3rd NUM=0 TEXTURE=FireEffect18

#exec AUDIO IMPORT FILE="Sounds\stinger\sshot10d.WAV" NAME="StingerFire" GROUP="Stinger"
#exec AUDIO IMPORT FILE="Sounds\stinger\sshot20d.WAV" NAME="StingerTwoFire" GROUP="Stinger"
#exec AUDIO IMPORT FILE="Sounds\stinger\saltf1.WAV" NAME="StingerAltFire" GROUP="Stinger"
#exec AUDIO IMPORT FILE="Sounds\stinger\load1.WAV" NAME="StingerLoad" GROUP="Stinger"

var bool bAlreadyFiring;

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

function PlayFiring()
{
	local WeaponLight W;

	if ( bAlreadyFiring )
		Owner.PlaySound(sound'StingerTwoFire', SLOT_None,0.6*Pawn(Owner).SoundDampening);
	else
		Owner.PlaySound(FireSound, SLOT_None,0.6*Pawn(Owner).SoundDampening);
	bAlreadyFiring = true;
	bWarnTarget = (FRand() < 0.2);
	LoopAnim( 'FireOne', 0.7);
	W=Spawn(class'WeaponLight');		
	W.LightHue = 200;
}

function PlayAltFiring()
{
	local WeaponLight W;

	Owner.PlaySound(AltFireSound, SLOT_None,0.6*Pawn(Owner).SoundDampening);	
	W=Spawn(class'WeaponLight');		
	W.LightHue = 200;		
	PlayAnim( 'FireOne', 0.6 );
}

///////////////////////////////////////////////////////
state NormalFire
{
	function EndState()
	{
		bAlreadyFiring = false;
		CallParent.EndState();
	}
			
Begin:
	Sleep(0.2);
	Finish();
}

///////////////////////////////////////////////////////////////
state AltFiring
{
	function Projectile ProjectileFire(class ProjClass, float ProjSpeed, bool bWarn)
	{
		local Projectile S;
		local int i;
		local vector Start,X,Y,Z;
		local Rotation StartRot, AltRotation;

		S = CallGlobal.ProjectileFire(ProjClass, ProjSpeed, bWarn);
		StartRot = S.Rotation;
		Start = S.Location;
		for (i = 0; i< 4; i++)
		{
			if (AmmoType.UseAmmo(1)) 
			{
				AltRotation = StartRot;
				AltRotation.Pitch += FRand()*3000-1500;
				AltRotation.Yaw += FRand()*3000-1500;
				AltRotation.Roll += FRand()*9000-4500;				
				S = Projectile(Spawn(AltProjectileClass,,, Start - 2 * VRand(), AltRotation));
			}
		}
		StingerProjectile(S).bLighting = True;
	}

Begin:
	FinishAnim();	
	PlayAnim('Still');
	Sleep(1.0);
	Finish();			
}

///////////////////////////////////////////////////////////
function PlayIdleAnim()
{
	PlayAnim('Still');
}

