
class Rifle_SG552 extends CSSWeapons;

//1st Person
#exec MESH MODELIMPORT MESH=SG552Mesh MODELFILE=ModelsSkeletal\Rifles\SG552\SG552Mesh.psk
#exec MESH ORIGIN MESH=SG552Mesh X=0 Y=0 Z=0 YAW=-64 PITCH=0 ROLL=0

//Pickup
#exec MESH IMPORT MESH=SG552FirstPick ANIVFILE=MODELS\Rifles\SG552\SG552FirstPick_a.3d DATAFILE=MODELS\Rifles\SG552\SG552FirstPick_d.3d X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=SG552FirstPick X=0 Y=0 Z=21.5

//3rd Person
#exec MESH IMPORT MESH=SG552First3rd ANIVFILE=MODELS\Rifles\SG552\SG552First3rd_a.3d DATAFILE=MODELS\Rifles\SG552\SG552First3rd_d.3d X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=SG552First3rd X=0 Y=0 Z=-9 Yaw=128

//Animations
//1st Person
#exec ANIM IMPORT ANIM=SG552MeshAnims ANIMFILE=ModelsSkeletal\Rifles\SG552\SG552MeshAnims.psa COMPRESS=1

#exec ANIM SEQUENCE ANIM=SG552MeshAnims SEQ=All STARTFRAME=0 NUMFRAMES=170
#exec ANIM SEQUENCE ANIM=SG552MeshAnims SEQ=Select STARTFRAME=0 NUMFRAMES=32
#exec ANIM SEQUENCE ANIM=SG552MeshAnims SEQ=Still STARTFRAME=33 NUMFRAMES=16
#exec ANIM SEQUENCE ANIM=SG552MeshAnims SEQ=Reload STARTFRAME=50 NUMFRAMES=103
#exec ANIM SEQUENCE ANIM=SG552MeshAnims SEQ=Fire STARTFRAME=154 NUMFRAMES=16
#exec ANIM SEQUENCE ANIM=SG552MeshAnims SEQ=AfterFire STARTFRAME=162 NUMFRAMES=8

#exec ANIM DIGEST ANIM=SG552MeshAnims
#exec MESH DEFAULTANIM MESH=SG552Mesh ANIM=SG552MeshAnims

//Pickup
#exec MESH SEQUENCE MESH=SG552FirstPick SEQ=All STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=SG552FirstPick SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=SG552FirstPick SEQ=Select STARTFRAME=0 NUMFRAMES=1

//3rd Person
#exec MESH SEQUENCE MESH=SG552First3rd SEQ=All STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=SG552First3rd SEQ=Still STARTFRAME=0 NUMFRAMES=1

//Scales
//1st Person
#exec MESHMAP SCALE MESHMAP=SG552Mesh X=1.0 Y=1.0 Z=1.0

//Pickup
#exec MESHMAP NEW MESHMAP=SG552FirstPick MESH=SG552FirstPick
#exec MESHMAP SCALE MESHMAP=SG552FirstPick X=0.07 Y=0.07 Z=0.17

//3rd Person
#exec MESHMAP NEW MESHMAP=SG552First3rd MESH=SG552First3rd
#exec MESHMAP SCALE MESHMAP=SG552First3rd X=0.1 Y=0.1 Z=0.2

//Textures
#exec TEXTURE IMPORT NAME=SG552MeshSkin00 FILE=Textures\Rifles\SG552\SG552Scope.bmp GROUP=SG552 LODSET=2
#exec TEXTURE IMPORT NAME=SG552MeshSkin01 FILE=Textures\Rifles\SG552\SG552Body.bmp GROUP=SG552 LODSET=2
#exec TEXTURE IMPORT NAME=SG552MeshSkin02 FILE=Textures\Generic\M3Arm.bmp GROUP=Generic LODSET=2
#exec TEXTURE IMPORT NAME=SG552MeshSkin03 FILE=Textures\Generic\M3Gloves.bmp GROUP=Generic LODSET=2
#exec TEXTURE IMPORT NAME=SG552MeshSkin04 FILE=Textures\Generic\M3Thumbs.bmp GROUP=Generic LODSET=2

#exec TEXTURE IMPORT NAME=SG552BodyPick FILE=Textures\Rifles\SG552\SG552BodyPick.bmp GROUP=SG552 LODSET=2

//1st Person
#exec MESHMAP SETTEXTURE MESHMAP=SG552Mesh NUM=0 TEXTURE=SG552MeshSkin00
#exec MESHMAP SETTEXTURE MESHMAP=SG552Mesh NUM=1 TEXTURE=SG552MeshSkin01
#exec MESHMAP SETTEXTURE MESHMAP=SG552Mesh NUM=2 TEXTURE=SG552MeshSkin02
#exec MESHMAP SETTEXTURE MESHMAP=SG552Mesh NUM=3 TEXTURE=SG552MeshSkin03
#exec MESHMAP SETTEXTURE MESHMAP=SG552Mesh NUM=4 TEXTURE=SG552MeshSkin04

//Pickup
#exec MESHMAP SETTEXTURE MESHMAP=SG552FirstPick NUM=1 TEXTURE=SG552BodyPick

//3rd Person
#exec MESHMAP SETTEXTURE MESHMAP=SG552First3rd NUM=1 TEXTURE=SG552BodyPick

//Sounds
#exec AUDIO IMPORT NAME="SG552Fire" FILE=Sounds\Rifles\SG552\SG552_fire.wav GROUP="SG552"
#exec AUDIO IMPORT NAME="SG552ClipOut" FILE=Sounds\Rifles\SG552\SG552_clipout.wav GROUP="SG552"
#exec AUDIO IMPORT NAME="SG552ClipIn" FILE=Sounds\Rifles\SG552\SG552_clipin.wav GROUP="SG552"
#exec AUDIO IMPORT NAME="SG552BoltPull" FILE=Sounds\Rifles\SG552\SG552_boltpull.wav GROUP="SG552"

#exec TEXTURE IMPORT NAME=SG552Icon FILE=Textures\Icons\SG552Icon.bmp GROUP=SG552 MIPS=OFF

var Texture RandFlash[6];
var float NFlashO, NFlashY;
var float FireRate;
var byte PZoomLevel;

replication
{
	Reliable if(bNetOwner && Role==ROLE_Authority)
		FireRate, PZoomLevel;
}

function DropFrom(vector StartLocation)
{
	Super.DropFrom(StartLocation);
	FlashO = default.FlashO;
	FlashY = default.FlashY;
	PZoomLevel = 0;
	FireRate = Default.FireRate;
}

simulated function TweenDown()
{
	PZoomLevel = 0;
	FireRate = Default.FireRate;
}

State DownWeapon
{
	ignores Fire, AltFire;

Begin:
	PZoomLevel = 0;
	FireRate = Default.FireRate;
	if(Pawn(Owner) != None)
		Pawn(Owner).ChangedWeapon();
	if (Owner.IsA('PlayerPawn'))
	{
		PlayerPawn(Owner).DodgeClickTime = PlayerPawn(Owner).Default.DodgeClickTime;
		PlayerPawn(Owner).bRun = 0;
 		bDrawMuzzleFlash = True;
	}
}

simulated event RenderOverlays(canvas Canvas)
{
	local rotator NewRot;
	local bool bPlayerOwner;
	local int Hand;
	local PlayerPawn PlayerOwner;

	MFTexture = RandFlash[Rand(5)];

	if (Owner.IsA('PlayerPawn'))
	{
		if(bHideWeapon || (Owner==None))
			return;
		PlayerOwner = PlayerPawn(Owner);
		if(PlayerOwner!=None)
		{
			bPlayerOwner = true;
			Hand = PlayerOwner.Handedness;
		}

		if((Level.NetMode == NM_Client) && (Hand == 2))
		{
			bHideWeapon = true;
			return;
		}
	
		if(!bPlayerOwner || (PlayerOwner.Player == None))
			Pawn(Owner).WalkBob = vect(0,0,0);
	
		if(bMuzzleFlash>0 && bDrawMuzzleFlash && (MFTexture != None))
		{
			MuzzleScale = Default.MuzzleScale*(Canvas.ClipX/640.0);
			if(!bSetFlashTime)
			{
				bSetFlashTime = true;
				FlashTime = Level.TimeSeconds+FlashLength;
			}
			else if(FlashTime<Level.TimeSeconds)
				bMuzzleFlash = 0;
		
			if(bMuzzleFlash > 0)
			{
				MFTexture = RandFlash[Rand(6)];
				if (Hand == 0)
                	Canvas.SetPos(Canvas.ClipX/2 - 0.5 * MuzzleScale * FlashS + Canvas.ClipX * (-0.2 * Default.MuzzleOffset.Y * FlashO), Canvas.ClipY/2 - 0.5 * MuzzleScale * FlashS + Canvas.ClipY * (FlashY + FlashC));
          	  	else
                	Canvas.SetPos(Canvas.ClipX/2 - 0.5 * MuzzleScale * FlashS + Canvas.ClipX * (Hand * Default.MuzzleOffset.Y * FlashO), Canvas.ClipY/2 - 0.5 * MuzzleScale * FlashS + Canvas.ClipY * FlashY);
				Canvas.Style = 3;
				Canvas.DrawIcon(MFTexture, MuzzleScale);
				Canvas.Style = 1;
			}
		}
	else
		bSetFlashTime = false;

	SetLocation(Owner.Location + CSSCalcDrawOffset());
	NewRot = Pawn(Owner).ViewRotation;
	if(Hand==0)
		newRot.Roll = -2*Default.Rotation.Roll;
	else
		newRot.Roll = Default.Rotation.Roll*Hand;
	setRotation(newRot);
	Canvas.DrawActor(self, false);
	}
}

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

	return AIRating;
}

simulated function PlaySelect()
{
	PlayAnim('Select', 1.1, 0.04);
	FlashO = default.FlashO;
	FlashY = default.FlashY;
}

simulated function SetZoom()
{
	if (Owner.IsA('PlayerPawn'))
	{
		if (PlayerPawn(Owner).Player.IsA('ViewPort'))
		{
			if (PlayerPawn(Owner) != None && AmmoType.AmmoAmount > 0)
			{
				if (PlayerPawn(Owner).DesiredFOV == PlayerPawn(Owner).DefaultFOV)
				{
					PlayerPawn(Owner).DesiredFOV = 50.0;
					FlashO = default.NFlashO;
					FlashY = default.NFlashY;
				}
				else
				{
					PlayerPawn(Owner).DesiredFOV = PlayerPawn(Owner).DefaultFOV;
					FlashO = default.FlashO;
					FlashY = default.FlashY;
				}
			}
		}
	}
}

simulated function JustFire()
{
	SpawnShellCase(vect(10,-500,1));
	PlayOwnedSound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);
	PlayAnim('Fire', FireRate, 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(4.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');
}

state NormalFire
{
	function AnimEnd()
	{
		if(Pawn(Owner) != None)
		{
			if(Pawn(Owner).bFire == 0)
			{
				PlayAfterFire();
				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)
			{
				PlayAfterFire();
				GoToState('Idle');
			}
			else if(Pawn(Owner).bFire != 0)
			{
				Global.Fire(0.0);
			}
		}
	}
}

simulated function PlayAfterFire()
{
	PlayAnim('AfterFire', 0.7, 0.04);
}

function AltFire(float Value)
{
	if(PZoomLevel == 0)
	{
		PZoomLevel = 1;			//Zoomed
		FireRate = 4.0;
	}
	else if(PZoomLevel == 1)
	{
		PZoomLevel = 0;			//UnZoomed
		FireRate = Default.FireRate;
	}
	ClientAltFire(Value);
}

simulated function bool ClientAltFire(float Value)
{
	SetZoom();
	GotoState('Idle');
	return true;
}

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

      if(Owner.IsA('PlayerPawn'))
		{
			if (PlayerPawn(Owner).Player.IsA('ViewPort'))
			{
				if(PlayerPawn(Owner).DesiredFOV != PlayerPawn(Owner).DefaultFOV)
				{
					PlayerPawn(Owner).DesiredFOV = PlayerPawn(Owner).DefaultFOV;
					PlayerPawn(Owner).FOVAngle = PlayerPawn(Owner).DesiredFOV;
					FlashO = default.FlashO;
					FlashY = default.FlashY;
					MuzzleScale = default.MuzzleScale;
				}
			}
		}
   }
}

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

      if(Owner.IsA('PlayerPawn'))
		{
			if (PlayerPawn(Owner).Player.IsA('ViewPort'))
			{
				if(PlayerPawn(Owner).DesiredFOV != PlayerPawn(Owner).DefaultFOV)
				{
					PlayerPawn(Owner).DesiredFOV = PlayerPawn(Owner).DefaultFOV;
					PlayerPawn(Owner).FOVAngle = PlayerPawn(Owner).DesiredFOV;
					FlashO = default.FlashO;
					FlashY = default.FlashY;
					MuzzleScale = default.MuzzleScale;
				}
			}
		}
   }
}

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

simulated State NewClip
{
	ignores Fire, AltFire, Reload;

Begin:
	PZoomLevel = 0;
	FireRate = Default.FireRate;
	Sleep(0.45);
	Owner.PlaySound(ReloadSounds[0], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(1.1);
	Owner.PlaySound(ReloadSounds[1], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(0.8);
	Owner.PlaySound(ReloadSounds[2], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(0.35);
	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:
   PZoomLevel = 0;
   FireRate = Default.FireRate;
	Sleep(0.45);
	Owner.PlaySound(ReloadSounds[0], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(1.1);
	Owner.PlaySound(ReloadSounds[1], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(0.8);
	Owner.PlaySound(ReloadSounds[2], SLOT_None, Pawn(Owner).SoundDampening * 1.0);
	Sleep(0.35);
	FinishAnim();
	ClipCount=Min(Default.ClipCount,AmmoType.AmmoAmount);
	Finish();
}

defaultproperties
{
	FireRate=7.00
	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=236.00
	WallPenetrationValue=220.00
	ShellCaseType=Class'BRUT.CSSShellCaseSniper'
	ShellCaseScale=0.600000
	ReloadSounds(0)=Sound'BRUT.SG552.SG552ClipOut'
	ReloadSounds(1)=Sound'BRUT.SG552.SG552ClipIn'
   ReloadSounds(2)=Sound'BRUT.SG552.SG552BoltPull'
   PickupSound=Sound'UnrealShare.Pickups.WeaponPickup'
   FireSound=Sound'BRUT.SG552.SG552Fire'
   EjectOffset=(X=25.000000,Y=17.000000,Z=-10.000000)
   HitDamage=38
   ClipCount=30
   PickupAmmoCount=120
   Recoil=(Vertical=0.220000,Horizontal=1.020000,duration=0.100000)
   AmmoName=Class'BRUT.AmmoRifles'
   bInstantHit=True
   FireOffset=(Y=0.000000)
   MuzzleOffset=(Y=-7.200000)
   MyDamageType=shot
   AltDamageType=Decapitated
   AIRating=0.800000
   RefireRate=0.990000
   AltRefireRate=0.990000
   AimError=700.000000
   bDrawMuzzleFlash=True
   MuzzleScale=0.700000
   NFlashY=0.225000
   NFlashO=0.031000
   FlashY=0.110000
   FlashO=0.013700
   FlashC=0.031000
   FlashLength=0.013000
   FlashS=256
   BobDamping=2.65
   MFTexture=Texture'BRUT.MuzzleFlashes.CSSRifleMuzz1'
   AutoSwitchPriority=6
   InventoryGroup=6
   PickupMessage="You got the Swiss Army SG-552 Commando"
   ItemName="SG-552"
   Physics=PHYS_Falling
   PlayerViewOffset=(X=5.000000,Y=-1.600000,Z=-1.700000)
   PlayerViewMesh=SkeletalMesh'SG552Mesh'
   PlayerViewScale=7.000000
   PickupViewMesh=LodMesh'SG552FirstPick'
   PickupViewScale=3.00
   ThirdPersonMesh=LodMesh'SG552First3rd'
   ThirdPersonScale=1.85
   bMuzzleFlashParticles=False
   MuzzleFlashStyle=STY_Translucent
   MuzzleFlashMesh=LodMesh'BRUT.FamasRifleMuzzle'
   MuzzleFlashScale=0.750000
   Mesh=LodMesh'BRUT.SG552FirstPick'
   bNoSmooth=False
   DrawScale=3.000000
   Icon=Texture'BRUT.SG552.SG552Icon'
   StatusIcon=Texture'BRUT.SG552.SG552Icon'
   CollisionRadius=32.000000
   CollisionHeight=8.000000
   LODBias=20.00
}