//=============================================================================
// GESBioRifle.
//=============================================================================
class GESBioRifle expands Weapon;


#exec MESH IMPORT MESH=BRifle ANIVFILE=MODELS\BRifle_a.3D DATAFILE=MODELS\BRifle_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=BRifle X=0 Y=0 Z=0 YAW=-64 ROLL=0 PITCH=0
#exec MESH SEQUENCE MESH=BRifle SEQ=All       STARTFRAME=0   NUMFRAMES=101
#exec MESH SEQUENCE MESH=BRifle SEQ=Select    STARTFRAME=0   NUMFRAMES=20 RATE=45 GROUP=Select
#exec MESH SEQUENCE MESH=BRifle SEQ=Still     STARTFRAME=20  NUMFRAMES=1
#exec MESH SEQUENCE MESH=BRifle SEQ=Walking   STARTFRAME=21  NUMFRAMES=20
#exec MESH SEQUENCE MESH=BRifle SEQ=Charging  STARTFRAME=41  NUMFRAMES=30
#exec MESH SEQUENCE MESH=BRifle SEQ=UnLoading STARTFRAME=71  NUMFRAMES=1
#exec MESH SEQUENCE MESH=BRifle SEQ=Fire      STARTFRAME=72  NUMFRAMES=9
#exec MESH SEQUENCE MESH=BRifle SEQ=Drip      STARTFRAME=81  NUMFRAMES=7
#exec MESH SEQUENCE MESH=BRifle SEQ=Down      STARTFRAME=88  NUMFRAMES=13
#exec TEXTURE IMPORT NAME=JBRifle1 FILE=MODELS\BRifle.PCX GROUP=Skins
#exec MESHMAP SCALE MESHMAP=BRifle  X=0.005 Y=0.005 Z=0.01
#exec MESHMAP SETTEXTURE MESHMAP=BRifle NUM=1 TEXTURE=JBRifle1

#exec MESH IMPORT MESH=BRiflePick ANIVFILE=MODELS\napick_a.3D DATAFILE=MODELS\napick_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=BRiflePick X=0 Y=0 Z=63 YAW=64
#exec MESH SEQUENCE MESH=BRiflepick SEQ=All    STARTFRAME=0   NUMFRAMES=1
#exec MESH SEQUENCE MESH=BRiflepick SEQ=Still  STARTFRAME=0   NUMFRAMES=1
#exec TEXTURE IMPORT NAME=JBRifle1 FILE=MODELS\BRifle.PCX GROUP=Skins
#exec MESHMAP SCALE MESHMAP=BRiflepick X=0.1 Y=0.1 Z=0.2
#exec MESHMAP SETTEXTURE MESHMAP=BRiflepick NUM=1 TEXTURE=JBRifle1

#exec MESH IMPORT MESH=BRifle3 ANIVFILE=MODELS\Napal3_a.3D DATAFILE=MODELS\Napal3_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=BRifle3 X=0 Y=-480 Z=-40 YAW=-64 ROLL=0
#exec MESH SEQUENCE MESH=BRifle3 SEQ=All  STARTFRAME=0  NUMFRAMES=15
#exec MESH SEQUENCE MESH=BRifle3 SEQ=Still  STARTFRAME=0  NUMFRAMES=1
#exec MESH SEQUENCE MESH=BRifle3 SEQ=Charging  STARTFRAME=1  NUMFRAMES=9 RATE=40.0
#exec MESH SEQUENCE MESH=BRifle3 SEQ=Fire  STARTFRAME=9  NUMFRAMES=5 RATE=40.0
#exec TEXTURE IMPORT NAME=JBRifle1 FILE=MODELS\BRifle.PCX GROUP="Skins"
#exec MESHMAP SCALE MESHMAP=BRifle3 X=0.03 Y=0.03 Z=0.06
#exec MESHMAP SETTEXTURE MESHMAP=BRifle3 NUM=1 TEXTURE=JBRifle1

#exec MESH NOTIFY MESH=BRifle SEQ=Drip TIME=0.4 FUNCTION=DripSound

#exec AUDIO IMPORT FILE="Sounds\BRifle\NPickup2.WAV" NAME="GelSelect" GROUP="BioRifle"
#exec AUDIO IMPORT FILE="Sounds\BRifle\NLoadp2.WAV" NAME="GelLoad" GROUP="BioRifle"
#exec AUDIO IMPORT FILE="Sounds\BRifle\NShot1.WAV" NAME="GelShot" GROUP="BioRifle"
#exec AUDIO IMPORT FILE="Sounds\BRifle\Drip1.WAV" NAME="GelDrip" GROUP="BioRifle"
#exec AUDIO IMPORT FILE="Sounds\BRifle\GelHit1.WAV" NAME="GelHit" GROUP="BioRifle"

var float ChargeSize,Count;

function PreBeginPlay()
{
	CallParent.PreBeginPlay();
	ProjectileClass = class'BioGel';
	ProjectileSpeed = biogel.default.speed;
	AltProjectileClass = class'BigBioGel';
	AltProjectileSpeed = BigBioGel.default.speed;
}

function AltFire( float Value )
{
	bFireMem = false;
	bAltFireMem = false;
	bPointing=True;
	if ( AmmoType.UseAmmo(1) ) 
	{
		CheckVisibility();
		GoToState('AltFiring');
	}
	else
		GoToState('Idle');		
}

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

	Owner.MakeNoise(1.0);
	GetAxes(Pawn(owner).ViewRotation,X,Y,Z);
	Start = Owner.Location + CalcDrawOffset() + FireOffset.X * X + FireOffset.Y * Y + FireOffset.Z * Z; 
	bWarn = ( bWarn || (FRand() < 0.3) );
	AdjustedAim = pawn(owner).AdjustToss(ProjSpeed, Start, 0, True, (bWarn || (FRand() < 0.3)));	
	return Projectile(Spawn(ProjClass,,, Start,AdjustedAim));	
}

///////////////////////////////////////////////////////
state AltFiring
{
	function Tick( float DeltaTime )
	{
		ChargeSize += DeltaTime;
		if( (pawn(Owner).bAltFire==0)) 
			GoToState('ShootLoad');
		Count += DeltaTime;
		if (Count > 1.0) 
		{
			Count = 0.0;
			If (!AmmoType.UseAmmo(1)) 
				GoToState('ShootLoad');
		}
	}

Begin:
	ChargeSize = 0.0;
	Count = 0.0;
	PlayAnim('Charging',0.2,0.05);
	FinishAnim();
	Owner.PlaySound(Misc1Sound, SLOT_None, Pawn(Owner).SoundDampening);	 //loading goop
	GotoState('ShootLoad');
}

state ShootLoad
{
	function Fire(float F) 
	{
		bFireMem = true;
	}
	function AltFire(float F) 
	{
		bAltFireMem = true;
	}

	function BeginState()
	{
		Local Projectile Gel;

		Gel = ProjectileFire(AltProjectileClass, AltProjectileSpeed, bAltWarnTarget);
		Gel.DrawScale = 0.5 + ChargeSize/4;
		Owner.PlaySound(FireSound, SLOT_None, Pawn(Owner).SoundDampening);	//shoot goop
		PlayAnim('Fire',0.4, 0.05);
	}

Begin:
	FinishAnim();
	Finish();
}


// Finish a firing sequence
function Finish()
{
	if ( bChangeWeapon )
		GotoState('DownWeapon');
	else if ( (AmmoType.AmmoAmount<=0) || (Pawn(Owner).Weapon != self) )
		GotoState('Idle');
	else if ( bFireMem || Pawn(Owner).bFire!=0 )
		CallGlobal.Fire(0);
	else 
		GotoState('Idle');
}


function PlayFiring()
{
	Owner.PlaySound(AltFireSound, SLOT_None, Pawn(Owner).SoundDampening);	//fast fire goop
	PlayAnim('Fire',1.1, 0.05);
}
///////////////////////////////////////////////////////////
function PlayIdleAnim()
{
	if (Size(Owner.Velocity) > 10)
		PlayAnim('Walking',0.3,0.3);
	else if (FRand() < 0.3 )
		PlayAnim('Drip', 0.1,0.3);
	else 
		TweenAnim('Still', 1.0);
	Enable('AnimEnd');
}

function DripSound()
{
	Owner.PlaySound(Misc2Sound, SLOT_None, Pawn(Owner).SoundDampening);	// Drip
}

