//=============================================================================
// RazorBlade.
//=============================================================================
class RazorBlade expands Projectile;
 
#exec MESH IMPORT MESH=razorb ANIVFILE=MODELS\razorb_a.3D DATAFILE=MODELS\razorb_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=razorb X=0 Y=0 Z=0 YAW=-64
#exec MESH SEQUENCE MESH=razorb SEQ=All    STARTFRAME=0   NUMFRAMES=15
#exec MESH SEQUENCE MESH=razorb SEQ=Spin  STARTFRAME=0   NUMFRAMES=15
#exec TEXTURE IMPORT NAME=Jrazor1 FILE=MODELS\razor.PCX 
#exec OBJ LOAD FILE=textures\FireEffect54.utx PACKAGE=UNREALI
#exec MESHMAP SCALE MESHMAP=razorb X=0.04 Y=0.04 Z=0.08
#exec MESHMAP SETTEXTURE MESHMAP=razorb NUM=1 TEXTURE=Jrazor1
#exec MESHMAP SETTEXTURE MESHMAP=razorb NUM=0 TEXTURE=FireEffect54

#exec AUDIO IMPORT FILE="Sounds\Razor\fly15.WAV" NAME="RazorHum" GROUP="RazorJack"
#exec AUDIO IMPORT FILE="Sounds\Razor\bladehit.wav" NAME="BladeHit" GROUP="RazorJack"
#exec AUDIO IMPORT FILE="Sounds\Razor\bladethunk.wav" NAME="BladeThunk" GROUP="RazorJack"
#exec AUDIO IMPORT FILE="Sounds\Razor\start9b.WAV" NAME="StartBlade" GROUP="RazorJack"

var int NumWallHits;
var bool bAltMode, bCanHitInstigator;
var int CurPitch,PitchStart,YawStart,CurYaw;
var rotation CurRotation;

/////////////////////////////////////////////////////
auto state Flying
{
	function ProcessTouch (Actor Other, Vector HitLocation)
	{
		if ( bCanHitInstigator || (Other != Instigator) ) 
		{
			if ( Other.IsA('Pawn') && (HitLocation.Z - Other.Location.Z > 0.6 * Other.CollisionHeight) )
				Other.Damage(2 * damage, instigator,HitLocation,
					(MomentumTransfer * Normal(Velocity)), 'decapitated' );
			else			 
				Other.Damage(damage, instigator,HitLocation,
					(MomentumTransfer * Normal(Velocity)), 'shredded' );
			PlaySound(MiscSound, SLOT_Misc, 1.0);
			destroy();
		}
	}

	function Timer()
	{
		local rotation newRot;

		newRot = instigator.Rotation;
		newRot.Roll += 12768;		
		SetRotation(newRot);	
		Velocity = Size(Velocity)*Vector(Rotation);		
	}


	function HitWall (vector HitNormal, actor Wall)
	{
		local rotation newRot;

		bCanHitInstigator = true;
		PlaySound(ImpactSound, SLOT_Misc, 0.2);
		if ( (Mover(Wall) != None) && Mover(Wall).bDamageTriggered )
		{
			Wall.Damage( Damage, instigator, Location, MomentumTransfer * Normal(Velocity), '');
			Destroy();
			return;
		}
		Velocity += ( Velocity dot HitNormal) * HitNormal * (-2.0) ;  // Projectile dies after hitting wall - Steve is fixing
		newRot = Rotation(Velocity);
		if (bAltMode)
			newRot.Roll += 12768;
		SetRotation(newRot);
		NumWallHits++;
		SetTimer(0, False);
		MakeNoise(0.3);
		LoopAnim('Spin',1.0);		
		if (NumWallHits > 5) Destroy();
	}

	function BeginState()
	{
		local vector X;

		X = vector(Rotation);	
		Velocity = Speed * X;     // Impart ONLY forward vel
		LoopAnim('Spin',1.0);
		Acceleration = X * 100.0;
		if ( bAltMode )
		{
			SetTimer(0.1,true);
			maxspeed = speed;
			PitchStart = Instigator.ViewRotation.Pitch;
			YawStart = Instigator.ViewRotation.Yaw;	
		}
		PlaySound(SpawnSound, SLOT_None,1.0);
		SoundPitch = 200 + 50 * FRand();	
	}

Begin:
	Sleep(0.2);
	bCanHitInstigator = true;
}

