
final class TurokFusionCannon : TurokWeapon
{
	TurokFusionCannon( kWeapon@ a )
	{
		super( a );
		BobDamping = 0.975f;
	}

	void AnimProperties( int&out first, int&out last, float&out rate, bool&out bLoop )
	{
		rate = 60; bLoop = false;
		switch ( PlayingID() )
		{
			case anim_weaponSwapIn:  first =  0; last = 28; break;
			case anim_weaponSwapOut: first = 28; last = 41; break;
			case anim_weaponFire:    first = 42; last = 86; break;
			default: /* idle */      first = 28; last = 28; bLoop = true; break;
		}
	}

	void AnimEnd()
	{
		if ( self.GetTarget() is null )
			TurokWeapon::AnimEnd();
	}

	bool Refire()
	{
		return IsPlaying( anim_weaponFire );
	}

	void OnBeginFire()
	{
		PlayAnim( anim_weaponFire );
		self.PlaySound( "UT/sounds/Redeemer/Fire.ksnd" );

//		kVec3 v = EyePos() + kVec3( 1, 60, -5 ) * OwnerP().Rotation(); // UT weapon offset
		kVec3 v = EyePos() + kVec3( 0, 60, -7.5f ) * OwnerP().Rotation(); // weapon less in your face offset
		v = CheckPosition( v );
		if ( !bFire2 )
			ActorFactory.Spawn( "RedeemerMissile", v.x, v.y, v.z, OwnerP().Yaw(), OwnerP().SectorIndex() );
		else
			self.SetTarget( ActorFactory.Spawn( "RedeemerMissile_Guided", v.x, v.y, v.z, OwnerP().Yaw(), OwnerP().SectorIndex() ) );

		UseAmmo( 1 );
	}

	void OnTick()
	{
		if ( self.GetTarget() !is null && self.GetTarget().IsStale() )
			self.SetTarget( null );

		TurokWeapon::OnTick();

//		if ( !IsPlaying(anim_weaponFire) || PlayTime() >= 0.5f )
//			return;
//		float f = 1 - PlayTime() / 0.5f;
//		f *= f;
//		OwnerP().RecoilPitch() = Math::Sin(   Math::pi * f ) * f * -0.05f;
//		OwnerP().Roll()        = Math::Sin( 2*Math::pi * f ) * f *  0.05f;
//		OwnerP().RecoilPitch() = Math::Sin(   Math::pi * f ) * f * -0.06f;
//		OwnerP().Roll()        = Math::Sin( 2*Math::pi * f ) * f *  0.06f;
		if ( !IsPlaying(anim_weaponFire) || PlayTime() > 0.73f )
			return;
		float f = 1 - PlayTime() / 0.73f;
		OwnerP().RecoilPitch() = Math::Sin(   Math::pi * f*f   ) * f*f   * -0.075f;
		OwnerP().Roll()        = Math::Sin( 3*Math::pi * f*f*f ) * f*f*f * -0.05f;
	}
}
