//=============================================================================
// ImpactHammer.
//=============================================================================
class ImpactHammer expands Weapon;

#exec MESH IMPORT  MESH=ImpactHammer ANIVFILE=MODELS\impact_a.3D DATAFILE=MODELS\impact_d.3D X=0 Y=0 Z=0 
#exec MESH ORIGIN MESH=ImpactHammer X=0 Y=0 Z=0 YAW=64 PITCH=0 ROLL=-56
#exec MESH SEQUENCE MESH=ImpactHammer SEQ=All         STARTFRAME=0   NUMFRAMES=56
#exec MESH SEQUENCE MESH=ImpactHammer SEQ=Select      STARTFRAME=0   NUMFRAMES=17
#exec MESH SEQUENCE MESH=ImpactHammer SEQ=Still       STARTFRAME=17  NUMFRAMES=1
#exec MESH SEQUENCE MESH=ImpactHammer SEQ=Pull        STARTFRAME=17  NUMFRAMES=5
#exec MESH SEQUENCE MESH=ImpactHammer SEQ=Shake       STARTFRAME=22  NUMFRAMES=10
#exec MESH SEQUENCE MESH=ImpactHammer SEQ=Fire        STARTFRAME=35  NUMFRAMES=16
#exec MESH SEQUENCE MESH=ImpactHammer SEQ=Down        STARTFRAME=51  NUMFRAMES=6
#exec TEXTURE IMPORT NAME=JImpactHammer1 FILE=MODELS\imp1.PCX GROUP=Skins
#exec TEXTURE IMPORT NAME=JImpactHammer2 FILE=MODELS\imp2.PCX GROUP=Skins
#exec TEXTURE IMPORT NAME=JImpactHammer3 FILE=MODELS\imp3.pCX GROUP=Skins
#exec TEXTURE IMPORT NAME=JImpactHammer4 FILE=MODELS\imp4.PCX GROUP=Skins
#exec MESHMAP SCALE MESHMAP=ImpactHammer X=0.006 Y=0.006 Z=0.007
#exec MESHMAP SETTEXTURE MESHMAP=ImpactHammer NUM=0 TEXTURE=JImpactHammer1
#exec MESHMAP SETTEXTURE MESHMAP=ImpactHammer NUM=1 TEXTURE=JImpactHammer2
#exec MESHMAP SETTEXTURE MESHMAP=ImpactHammer NUM=2 TEXTURE=JImpactHammer3
#exec MESHMAP SETTEXTURE MESHMAP=ImpactHammer NUM=3 TEXTURE=JImpactHammer4

#exec MESH IMPORT MESH=ImpPick ANIVFILE=MODELS\imppick_a.3D DATAFILE=MODELS\imppick_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=ImpPick X=0 Y=0 Z=0 YAW=0 ROLL=-64
#exec MESH SEQUENCE MESH=ImpPick SEQ=All         STARTFRAME=0   NUMFRAMES=1
#exec MESH SEQUENCE MESH=ImpPick SEQ=Still       STARTFRAME=0   NUMFRAMES=1
#exec TEXTURE IMPORT NAME=JImpPick1 FILE=MODELS\imp0.PCX GROUP=Skins
#exec MESHMAP SCALE MESHMAP=ImpPick X=0.1 Y=0.1 Z=0.2
#exec MESHMAP SETTEXTURE MESHMAP=ImpPick NUM=1 TEXTURE=JImpPick1

#exec MESH IMPORT MESH=WHHand ANIVFILE=MODELS\imppick_a.3D DATAFILE=MODELS\imppick_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=WHHand X=0 Y=0 Z=0 YAW=0 ROLL=-64
#exec MESH SEQUENCE MESH=WHHand SEQ=All         STARTFRAME=0   NUMFRAMES=1
#exec MESH SEQUENCE MESH=WHHand SEQ=Still       STARTFRAME=0   NUMFRAMES=1
#exec MESHMAP SCALE MESHMAP=WHHand X=0.07 Y=0.07 Z=0.14
#exec MESHMAP SETTEXTURE MESHMAP=WHHand NUM=1 TEXTURE=JImpPick1

var float ChargeSize,Count;
var() sound AltFireSound;
var() sound TensionSound;

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

function PlayFiring()
{
	if ( PlayerPawn(Owner) != None )
	{
		Owner.PlaySound(FireSound, SLOT_Misc, 1.7*Pawn(Owner).SoundDampening,,,);
		PlayerPawn(Owner).ClientInstantFlash( -0.4, vect(950, 650, 290));
		PlayerPawn(Owner).ShakeView(ShakeTime, ShakeMag, ShakeVert);
	}
	PlayAnim( 'Pull', 0.9 );
}

function TracePFire()
{
	local vector HitLocation, HitNormal, StartTrace, EndTrace, X, Y, Z;
	local actor Other;

	Owner.MakeNoise(Pawn(Owner).SoundDampening);
	GetAxes(Pawn(owner).ViewRotation, X, Y, Z);
	StartTrace = Owner.Location + CalcDrawOffset() + FireOffset.X * X + FireOffset.Y * Y + FireOffset.Z * Z; 
	AdjustedAim = pawn(owner).AdjustAim(1000000, StartTrace, 2.75*AimError, False, False);	
	EndTrace = StartTrace + (100 * vector(AdjustedAim)); 
	Other = Pawn(Owner).TraceShot(HitLocation, HitNormal, EndTrace, StartTrace);
	ProcessTraceHit(Other, HitLocation, HitNormal, vector(AdjustedAim), Y, Z);
}

function ProcessTraceHit(Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)
{
	local vector realLoc;

	realLoc = Owner.Location + CalcDrawOffset();
	if (Other == Level)
	{
		Owner.TakeDamage(0.0, Pawn(Owner), HitLocation, -10000.0 * X, 'impact');
		Spawn(class'WallHitEffect',,, HitLocation+HitNormal*9, Rotator(HitNormal));
	}
	else if ((Other != self) && (Other != Owner) && (Other != None) )
	{
		Other.TakeDamage(10.0, Pawn(Owner), HitLocation, 10000.0 * X, 'impact');
		if ( !Other.IsA('Pawn') && !Other.IsA('Carcass') )
			spawn(class'SpriteSmokePuff',,,HitLocation+HitNormal*9);
	}
}

function AltFire( float Value )
{
	bPointing=True;
	GoToState('AltFiring');
}

state AltFiring
{
	function Tick( float DeltaTime )
	{
		ChargeSize += DeltaTime;
		if( (pawn(Owner).bAltFire==0)) 
			GoToState('AltFireBlast');
		Count += DeltaTime;
		if (Count > 1.0) 
		{
			Count = 1.0;
			ChargeSize = 1.0;
		}
	}

Begin:
	ChargeSize = 0.0;
	Count = 0.0;
	Owner.PlaySound(Misc1Sound, SLOT_Misc, 1.3*Pawn(Owner).SoundDampening);
	PlayAnim('Pull', 0.2, 0.05);
	FinishAnim();
	AmbientSound = TensionSound;
	SoundVolume = 255*Pawn(Owner).SoundDampening;		
	LoopAnim('Shake', 0.9);
}

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

	function BeginState()
	{
		// Big Hit
		TraceAltFire();
		Owner.PlaySound(AltFireSound, SLOT_Misc, 1.7*Pawn(Owner).SoundDampening,,,fMax(0.5,1.35-ChargeSize/8.0) );
		PlayAnim('Fire', 0.4, 0.05);
	}

Begin:
	AmbientSound = None;
	FinishAnim();
	Finish();
}

function TraceAltFire()
{
	local vector HitLocation, HitNormal, StartTrace, EndTrace, X, Y, Z;
	local actor Other;

	Owner.MakeNoise(Pawn(Owner).SoundDampening);
	GetAxes(Pawn(owner).ViewRotation, X, Y, Z);
	StartTrace = Owner.Location + CalcDrawOffset() + FireOffset.X * X + FireOffset.Y * Y + FireOffset.Z * Z; 
	AdjustedAim = pawn(owner).AdjustAim(1000000, StartTrace, 2.75*AimError, False, False);	
	EndTrace = StartTrace + (100 * vector(AdjustedAim)); 
	Other = Pawn(Owner).TraceShot(HitLocation, HitNormal, EndTrace, StartTrace);
	ProcessAltTraceHit(Other, HitLocation, HitNormal, vector(AdjustedAim), Y, Z);
}

function ProcessAltTraceHit(Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)
{
	local vector realLoc;

	realLoc = Owner.Location + CalcDrawOffset();
	if (Other == Level)
	{
		Owner.TakeDamage(40.0, Pawn(Owner), HitLocation, -150000.0 * ChargeSize * X, 'impact');
		Spawn(class'WallHitEffect',,, HitLocation+HitNormal*9, Rotator(HitNormal));
	}
	else if ((Other != self) && (Other != Owner) && (Other != None) )
	{
		Other.TakeDamage(150.0 * ChargeSize, Pawn(Owner), HitLocation, 100000.0 * ChargeSize * X, 'impact');
		if ( !Other.IsA('Pawn') && !Other.IsA('Carcass') )
			spawn(class'SpriteSmokePuff',,,HitLocation+HitNormal*9);
	}
}

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

defaultproperties
{
	 ItemName="Nut Buster"
     AltFireSound=Sound'UnrealI.flak.Hidraul2'
     TensionSound=Sound'UnrealI.Minigun.RegF1'
     FireSound=Sound'UnrealShare.flak.shot1'
     Misc1Sound=Sound'UnrealI.BioRifle.GelLoad'
     PickupMessage="You got the Nut Buster"
     PlayerViewOffset=(X=3.800000,Y=-1.600000,Z=-1.800000)
     PlayerViewMesh=Mesh'Botpack.ImpactHammer'
     PickupViewMesh=Mesh'Botpack.ImpPick'
     ThirdPersonMesh=Mesh'Botpack.WHHand'
     PickupSound=Sound'UnrealShare.Pickups.WeaponPickup'
     bMeshCurvy=False
	 DeathMessage="%k smeared %o with his piston of love."
}
