
Class HeavyRifle_M60 extends CSSWeapons;

//1st Person
#exec MESH IMPORT MESH=M60 ANIVFILE=MODELS\HeavyRifles\M60\M60_a.3d DATAFILE=MODELS\HeavyRifles\M60\M60_d.3d X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=M60 X=0 Y=0 Z=0 YAW=-64 PITCH=0 ROLL=0

//Pickup
#exec MESH IMPORT MESH=M60FirstPick ANIVFILE=MODELS\HeavyRifles\M60\M60Pick_a.3d DATAFILE=MODELS\HeavyRifles\M60\M60Pick_d.3d X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=M60FirstPick X=0 Y=0 Z=18
  
//3rd Person
#exec MESH IMPORT MESH=M60First3rd ANIVFILE=MODELS\HeavyRifles\M60\M603rd_a.3d DATAFILE=MODELS\HeavyRifles\M60\M603rd_d.3d X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=M60First3rd X=0 Y=0 Z=-9 Yaw=64

//Animations
//1st Person
#exec MESH SEQUENCE MESH=M60 SEQ=All 		STARTFRAME=0 	NUMFRAMES=446
#exec MESH SEQUENCE MESH=M60 SEQ=Select 	STARTFRAME=223 NUMFRAMES=31 	RATE=31
#exec MESH SEQUENCE MESH=M60 SEQ=Still 	STARTFRAME=444 NUMFRAMES=2 	RATE=2
#exec MESH SEQUENCE MESH=M60 SEQ=Reload 	STARTFRAME=270 NUMFRAMES=174 	RATE=20
#exec MESH SEQUENCE MESH=M60 SEQ=Fire 		STARTFRAME=254 NUMFRAMES=16 	RATE=11

//Pickup
#exec MESH SEQUENCE MESH=M60FirstPick SEQ=All STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=M60FirstPick SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=M60FirstPick SEQ=Select STARTFRAME=0 NUMFRAMES=1
  
//3rd Person
#exec MESH SEQUENCE MESH=M60First3rd SEQ=All STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=M60First3rd SEQ=Still STARTFRAME=0 NUMFRAMES=1

//Scales
//1st Person
#exec MESHMAP NEW MESHMAP=M60 MESH=M60
#exec MESHMAP SCALE MESHMAP=M60 X=0.1 Y=0.1 Z=0.2

//Pickup
#exec MESHMAP NEW MESHMAP=M60FirstPick MESH=M60FirstPick
#exec MESHMAP SCALE MESHMAP=M60FirstPick X=0.1 Y=0.1 Z=0.2
  
//3rd Person
#exec MESHMAP NEW MESHMAP=M60First3rd MESH=M60First3rd
#exec MESHMAP SCALE MESHMAP=M60First3rd X=0.1 Y=0.1 Z=0.2
  
//Textures
#exec TEXTURE IMPORT NAME=v-m60-1 		FILE=Textures\HeavyRifles\M60\v-m60-1.bmp 		GROUP=M60 LODSET=2
#exec TEXTURE IMPORT NAME=p-m60-2_2 	FILE=Textures\HeavyRifles\M60\p-m60-2_2.bmp 		GROUP=M60 LODSET=2
#exec TEXTURE IMPORT NAME=v-m60-2 		FILE=Textures\HeavyRifles\M60\v-m60-2.bmp 		GROUP=M60 LODSET=2
#exec TEXTURE IMPORT NAME=v-m60-3 		FILE=Textures\HeavyRifles\M60\v-m60-3.bmp 		GROUP=M60 LODSET=2
#exec TEXTURE IMPORT NAME=handfinal256 FILE=Textures\HeavyRifles\M60\handfinal256.bmp 	GROUP=M60 LODSET=2

//1st Person
#exec MESHMAP SETTEXTURE MESHMAP=M60 NUM=1 TEXTURE=handfinal256
#exec MESHMAP SETTEXTURE MESHMAP=M60 NUM=2 TEXTURE=v-m60-2
#exec MESHMAP SETTEXTURE MESHMAP=M60 NUM=3 TEXTURE=v-m60-3
#exec MESHMAP SETTEXTURE MESHMAP=M60 NUM=4 TEXTURE=v-m60-1

//Pickup
#exec MESHMAP SETTEXTURE MESHMAP=M60FirstPick NUM=0 TEXTURE=p-m60-2_2
#exec MESHMAP SETTEXTURE MESHMAP=M60FirstPick NUM=1 TEXTURE=v-m60-1

//3rd Person
#exec MESHMAP SETTEXTURE MESHMAP=M60First3rd NUM=0 TEXTURE=p-m60-2_2
#exec MESHMAP SETTEXTURE MESHMAP=M60First3rd NUM=1 TEXTURE=v-m60-1

//Sounds
#exec AUDIO IMPORT NAME="M60Shot" FILE=Sounds\HeavyRifles\M60\M60Shot.wav GROUP="M60"

//Icon
#exec TEXTURE IMPORT NAME=M60Icon FILE=Textures\Icons\M60Icon.bmp GROUP=M60 MIPS=OFF

var Texture RandFlash[6];
var int Count; //Tracer rounds every few shots

simulated event RenderOverlays(canvas Canvas)
{
	MFTexture = RandFlash[Rand(6)];
	Super.RenderOverlays(Canvas);
}

function float RateSelf(out int bUseAltMode)
{
	if (AmmoType.AmmoAmount <=0)
		return -2;
	
	bUseAltMode = 0;

	return AIRating;
}

simulated function PlaySelect()
{
	PlayAnim('Select', 0.7, 0.04);
}

simulated function JustFire()
{
	SpawnShellCase(vect(10,-500,1));
	PlayOwnedSound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);
	PlayAnim('Fire', 12.5, 0.04);

	AddRecoil();

	ClipCount--;

	if ((PlayerPawn(Owner) != None))
	{
		bMuzzleFlash++;
	}
}

function Fire(float Value)
{
	if ((AmmoType == None) && (AmmoName != None))
   {
       GiveAmmo(Pawn(Owner));
   }

	if(ClipCount>0 && AmmoType.UseAmmo(1))
	{
		TraceFire(6.0);

		bPointing=True;
		PlayFire();
		Spawn(Class'CSSWeaponsLight',,,Owner.Location,rot(0,0,0));
		bCanClientFire = true;
        ClientFire(Value);
		if(!bRapidFire && (FiringSpeed>0))
			Pawn(Owner).PlayRecoil(FiringSpeed);

		GotoState('NormalFire');
	}
	else if(ClipCount <= 0 && AmmoType.AmmoAmount > 0)
	{
		Reload();
	}
	else if(!IsInState('Idle'))
		GoToState('Idle');
}

//Added this to put a tracer every few shots
function TraceFire(float Accuracy)
{
   local vector HitLocation, HitNormal, StartTrace, EndTrace, X,Y,Z, AimDir;
   local actor Other;
   local float Penetration;
   local Pawn PawnOwner;
	local GunSmokePuff U;

   PawnOwner = Pawn(Owner);
   Owner.MakeNoise(Pawn(Owner).SoundDampening);
   GetAxes(Pawn(owner).ViewRotation,X,Y,Z);
   StartTrace = Owner.Location + CSSCalcDrawOffset() + FireOffset.Y * Y + FireOffset.Z * Z; 
   AdjustedAim = pawn(owner).AdjustAim(1000000, StartTrace, 2.75*AimError, False, False);
   EndTrace = StartTrace + Accuracy * (FRand() - 0.5)* Y * 1000+ Accuracy * (FRand() - 0.5) * Z * 1000;
   AimDir = vector(AdjustedAim);
   EndTrace += (100000 * AimDir); 
   Other = Pawn(Owner).TraceShot(HitLocation,HitNormal,EndTrace,StartTrace);
	//Tracers
	Count++;
   if (Count == 2)
   {
      Count = 0;
      if (VSize(HitLocation - StartTrace) > 250)
         Spawn(class'MTracer',,, StartTrace + 96 * AimDir,rotator(EndTrace - StartTrace));
   }
   ProcessTraceHit(Other, HitLocation, HitNormal, vector(AdjustedAim),Y,Z);
	U = spawn(class'GunSmokePuff',Pawn(Owner), '',Owner.Location + CSSCalcDrawOffset() + (45 * X) + (10 * Z)); //rifle barrel smoke effect
   if(bBulletPenetration)
   {
      if(Other.IsA('Pawn'))
         Penetration = PawnPenetrationValue;
      else
         Penetration = WallPenetrationValue;

      StartTrace = HitLocation + HitNormal + (Penetration * X);
      EndTrace = StartTrace + Accuracy * (FRand() - 0.5)* Y * 1000 + Accuracy * (FRand() - 0.5) * Z * 1000;
      EndTrace += (100000 * X);
      Other = PawnOwner.TraceShot(HitLocation, HitNormal, EndTrace, StartTrace);

      ProcessTraceHit(Other, HitLocation, HitNormal, X,Y,Z);
   }
}

state NormalFire
{
	function AnimEnd()
	{
		if(Pawn(Owner) != None)
		{
			if(Pawn(Owner).bFire == 0)
				GoToState('Idle');
			else if(Pawn(Owner).bFire != 0)
				Global.Fire(0.0);
		}
	}

Begin:
	FlashCount++;
	FinishAnim();
	Finish();
}

state ClientFiring
{
	ignores AltFire;

	simulated function AnimEnd()
	{
		if(Pawn(Owner) != None)
		{
			if(Pawn(Owner).bFire == 0)
				GoToState('Idle');
			else if(Pawn(Owner).bFire != 0)
				Global.Fire(0.0);
		}
	}
}

function Reload()
{
   if ((AmmoType.AmmoAmount>0) && (ClipCount < Default.ClipCount))
   {
      GoToState('NewClip');
      PlayReloading();
      ClientReload();
   }
}

simulated function ClientReload()
{
   if ((Role < ROLE_Authority) && (ClipCount < Default.ClipCount) && (AmmoType.AmmoAmount>0))
   {
      GoToState('ClientReloading');
      PlayReloading();
   }
}

simulated function PlayReloading()
{
   if ((Owner == None))
      return;
   PlayAnim('Reload',1.9, 0.05);
}

simulated State NewClip
{
	ignores Fire, AltFire, Reload;

Begin:
	Sleep(0.4);
	Owner.PlaySound(ReloadSounds[0], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(1.46);
	Owner.PlaySound(ReloadSounds[1], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(1.1);
	Owner.PlaySound(ReloadSounds[2], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(0.7);
	Owner.PlaySound(ReloadSounds[3], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(1.26);
	Owner.PlaySound(ReloadSounds[4], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(0.40);
	FinishAnim();
	ClipCount=Min(Default.ClipCount,AmmoType.AmmoAmount);
	Finish();
}

state ClientReloading
{
	simulated function bool ClientFire(float Value)
   {
      return false;
   }

   simulated function bool ClientAltFire(float Value)
   {
      return false;
   }

Begin:
   Sleep(0.4);
	Owner.PlaySound(ReloadSounds[0], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(1.46);
	Owner.PlaySound(ReloadSounds[1], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(1.1);
	Owner.PlaySound(ReloadSounds[2], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(0.7);
	Owner.PlaySound(ReloadSounds[3], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(1.26);
	Owner.PlaySound(ReloadSounds[4], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(0.40);
	FinishAnim();
	ClipCount=Min(Default.ClipCount,AmmoType.AmmoAmount);
	Finish();
}

defaultproperties
{
	Knockback=3000
	RandFlash(0)=Texture'BRUT.MuzzleFlashes.CSSRifleMuzz1'
	RandFlash(1)=Texture'BRUT.MuzzleFlashes.CSSRifleMuzz2'
	RandFlash(2)=Texture'BRUT.MuzzleFlashes.CSSRifleMuzz3'
	RandFlash(3)=Texture'BRUT.MuzzleFlashes.CSSRifleMuzz4'
	RandFlash(4)=Texture'BRUT.MuzzleFlashes.CSSRifleMuzz5'
	RandFlash(5)=Texture'BRUT.MuzzleFlashes.CSSRifleMuzz6'
	HeadShotMultiplier=1.50
	PawnPenetrationValue=366.00
	WallPenetrationValue=360.00
	ShellCaseType=Class'BRUT.CSSHeavyRifleShellCase'
	ShellCaseScale=0.800000
	ReloadSounds(0)=Sound'BRUT.M249.M249BoxOut'
	ReloadSounds(1)=Sound'BRUT.M249.M249CoverUp'
	ReloadSounds(2)=Sound'BRUT.M249.M249BoxIn'
	ReloadSounds(3)=Sound'BRUT.M249.M249Chain'
	ReloadSounds(4)=Sound'BRUT.M249.M249CoverDown'
	PickupSound=Sound'UnrealShare.Pickups.WeaponPickup'
	FireSound=Sound'BRUT.M60Shot'
	EjectOffset=(X=25.000000,Y=17.000000,Z=-10.000000)
	HitDamage=38
	ClipCount=50
	PickupAmmoCount=200
	Recoil=(Vertical=0.220000,Horizontal=1.020000,duration=0.100000)
	AmmoName=Class'BRUT.AmmoMachine'
	bInstantHit=True
	FireOffset=(Y=0.000000)
	MuzzleOffset=(Y=-7.200000)
	MyDamageType=shot
	AltDamageType=Decapitated
	AIRating=0.880000
	RefireRate=0.990000
	AltRefireRate=0.990000
	AimError=700.000000
	bDrawMuzzleFlash=True
	MuzzleScale=1.200000
	FlashY=0.085000
	FlashO=0.011000
	FlashC=0.031000
	FlashLength=0.013000
	FlashS=256
	BobDamping=2.65
	MFTexture=Texture'BRUT.MuzzleFlashes.CSSRifleMuzz1'
	AutoSwitchPriority=8
	InventoryGroup=8
	PickupMessage="You got an M60!"
	ItemName="M60"
	Physics=PHYS_Falling
	PlayerViewOffset=(X=5.000000,Y=-1.600000,Z=-1.700000)
	PlayerViewMesh=LodMesh'M60'
	PlayerViewScale=1.000000
	PickupViewMesh=LodMesh'M60FirstPick'
	PickupViewScale=1.60
	ThirdPersonMesh=LodMesh'M60First3rd'
	ThirdPersonScale=1.00
	bMuzzleFlashParticles=False
	MuzzleFlashStyle=STY_Translucent
	MuzzleFlashMesh=LodMesh'BRUT.M249RifleMuzzle'
	MuzzleFlashScale=0.900000
	bNoSmooth=False
	Mesh=LodMesh'BRUT.M60FirstPick'
	DrawScale=4.000000
	Icon=Texture'BRUT.M60.M60Icon'
	StatusIcon=Texture'BRUT.M60.M60Icon'
	CollisionRadius=32.000000
	CollisionHeight=8.000000
	LODBias=20.00
}