//=============================================================================
// ChainSaw.
//=============================================================================
class ChainSaw expands Weapon;

#exec MESH IMPORT  MESH=chainsaw ANIVFILE=MODELS\chains_a.3D DATAFILE=MODELS\chains_d.3D X=0 Y=0 Z=0 
#exec MESH ORIGIN MESH=chainsaw X=0 Y=0 Z=0 YAW=0 PITCH=0  ROLL=0
#exec MESH SEQUENCE MESH=chainsaw SEQ=All       STARTFRAME=0   NUMFRAMES=70
#exec MESH SEQUENCE MESH=chainsaw SEQ=Select    STARTFRAME=0   NUMFRAMES=17
#exec MESH SEQUENCE MESH=chainsaw SEQ=Idle      STARTFRAME=17  NUMFRAMES=10
#exec MESH SEQUENCE MESH=chainsaw SEQ=Swipe     STARTFRAME=27  NUMFRAMES=15
#exec MESH SEQUENCE MESH=chainsaw SEQ=Jab       STARTFRAME=42  NUMFRAMES=20
#exec MESH SEQUENCE MESH=chainsaw SEQ=Jab2      STARTFRAME=52  NUMFRAMES=9
#exec MESH SEQUENCE MESH=chainsaw SEQ=Down      STARTFRAME=62  NUMFRAMES=10
#exec TEXTURE IMPORT NAME=Jchainsaw1  FILE=MODELS\chain1.PCX GROUP=Skins
#exec TEXTURE IMPORT NAME=Jchainsaw2 FILE=MODELS\chain2.PCX GROUP=Skins
#exec TEXTURE IMPORT NAME=Jchainsaw3 FILE=MODELS\chain3.PCX GROUP=Skins
#exec TEXTURE IMPORT NAME=Jchainsaw4 FILE=MODELS\chain4.PCX GROUP=Skins
#exec MESHMAP SCALE MESHMAP=chainsaw X=0.004 Y=0.006 Z=0.012
#exec MESHMAP SETTEXTURE MESHMAP=chainsaw NUM=0 TEXTURE=Jchainsaw1
#exec MESHMAP SETTEXTURE MESHMAP=chainsaw NUM=1 TEXTURE=Jchainsaw2
#exec MESHMAP SETTEXTURE MESHMAP=chainsaw NUM=2 TEXTURE=Jchainsaw3
#exec MESHMAP SETTEXTURE MESHMAP=chainsaw NUM=3 TEXTURE=Jchainsaw4

#exec MESH IMPORT MESH=ChainSawPick ANIVFILE=MODELS\chainpick_a.3D DATAFILE=MODELS\chainpick_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=ChainSawPick X=150 Y=-10 Z=0 YAW=0 ROLL=-64
#exec MESH SEQUENCE MESH=ChainSawPick SEQ=All         STARTFRAME=0   NUMFRAMES=1
#exec MESH SEQUENCE MESH=ChainSawPick SEQ=Still       STARTFRAME=0   NUMFRAMES=1
#exec TEXTURE IMPORT NAME=JChainSawPick1 FILE=MODELS\ChainSaw.PCX GROUP=Skins
#exec MESHMAP SCALE MESHMAP=ChainSawPick X=0.1 Y=0.1 Z=0.2
#exec MESHMAP SETTEXTURE MESHMAP=ChainSawPick NUM=1 TEXTURE=JChainSawPick1

#exec MESH IMPORT MESH=CSHand ANIVFILE=MODELS\ChainS_a.3D DATAFILE=MODELS\ChainS_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=CSHand X=-150 Y=-110 Z=0 YAW=0 ROLL=-64
#exec MESH SEQUENCE MESH=CSHand SEQ=All         STARTFRAME=0   NUMFRAMES=1
#exec MESH SEQUENCE MESH=CSHand SEQ=Still       STARTFRAME=0   NUMFRAMES=1
#exec MESHMAP SCALE MESHMAP=CSHand X=0.07 Y=0.07 Z=0.14
#exec MESHMAP SETTEXTURE MESHMAP=CSHand NUM=1 TEXTURE=JChainSawPick1

function Fire( float Value )
{
	GotoState('NormalFire');
	if ( PlayerPawn(Owner) != None )
		PlayerPawn(Owner).ShakeView(ShakeTime, ShakeMag, ShakeVert);
	bPointing=True;
	PlayFiring();
}

function PlayFiring()
{
	PlayAnim( 'Jab', 0.7 );
}

function AltFire( float Value )
{
	GotoState('AltFiring');
	if ( PlayerPawn(Owner) != None )
		PlayerPawn(Owner).ShakeView(ShakeTime, ShakeMag, ShakeVert);
	bPointing=True;
	PlayAltFiring();
}

function PlayAltFiring()
{
	if ( PlayerPawn(Owner) != None )
	{
		PlayerPawn(Owner).ClientInstantFlash( -0.4, vect(950, 650, 290));
		PlayerPawn(Owner).ShakeView(ShakeTime, ShakeMag, ShakeVert);
	}
	PlayAnim( 'Swipe', 0.6 );
}

state Idle
{
	function bool PutDown()
	{
		GotoState('DownWeapon');
		return True;
	}

Begin:
	bPointing=False;
	if ( (AmmoType != None) && (AmmoType.AmmoAmount<=0) ) 
		Pawn(Owner).SwitchToBestWeapon();  //Goto Weapon that has Ammo
	if ( Pawn(Owner).bFire!=0 ) 
		Fire(0.0);
	if ( Pawn(Owner).bAltFire!=0 ) 
		AltFire(0.0);
	FinishAnim();
	AnimFrame=0;
	PlayIdleAnim();
	Goto('Begin');
}

function PlayIdleAnim()
{
	PlayAnim( 'Idle', 1.0, 0.0 );
}

// Finish a firing sequence
function Finish()
{
	if ( bChangeWeapon )
	{
		GotoState('DownWeapon');
		return;
	}

	if ( PlayerPawn(Owner) == None )
	{
		if ( (Pawn(Owner).bFire != 0) && (FRand() < RefireRate) )
			Global.Fire(0);
		else if ( (Pawn(Owner).bAltFire != 0) && (FRand() < AltRefireRate) )
			Global.AltFire(0);	
		else 
		{
			Pawn(Owner).StopFiring();
			GotoState('Idle');
		}
		return;
	}
	if ( Pawn(Owner).bFire!=0 )
		Global.Fire(0);
	else if ( Pawn(Owner).bAltFire!=0 )
		Global.AltFire(0);
	else 
		GotoState('Idle');
}

function Tick(float Delta)
{
	Super.Tick(Delta);
	
	Log(AnimSequence);
	Log(AnimFrame);
}

defaultproperties
{
     PickupMessage="You got the Chainsaw."
     ItemName="Chainsaw"
     PlayerViewOffset=(X=2.000000,Y=-1.100000,Z=-0.900000)
     PlayerViewMesh=Mesh'Botpack.ChainSaw'
     PickupViewMesh=Mesh'Botpack.ChainSawPick'
     ThirdPersonMesh=Mesh'Botpack.CSHand'
     Mesh=Mesh'Botpack.ChainSawPick'
	 DeathMessage="%k ripped into %o with his blood soaked %w."
}
