// --------------------------------------------------------------------------
//
//	M40 Sniper Rifle
//
// --------------------------------------------------------------------------

Actor SniperRifle : BaseWeapon
{
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive1 5
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "Clip2"
	Weapon.AmmoType2 "SniperAmmo"
	Weapon.SelectionOrder 9500
	Weapon.Kickback 200
	-WEAPON.CHEATNOTWEAPON
	Inventory.PickupSound "revolver/draw"
	Inventory.PickupMessage "You got the Sniper Rifle!"
	Obituary "%o was shot down by %k's M40 Sniper Rifle."
	tag "Sniper rifle"
	Scale 0.8
	States
	{
	Spawn:
		SNPX A -1
		Stop
		
	Select:
		TNT1 A 0 A_JumpIfInventory("IsPlayingAsPurist", 1, "PuristGun")
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1001,4)==0, "PuristGun")
		TNT1 A 0 A_Giveinventory("GoSpecial",1)
		TNT1 A 0 A_TakeInventory("Unloading",1)
		TNT1 A 0 A_TakeInventory("Reloading",1)
		TNT1 A 0 A_TakeInventory("TossGrenade", 1)
		TNT1 A 0 A_TakeInventory("WeapSpecial",1)
		TNT1 A 0 A_TakeInventory("SwitchFlashlight",1)
		TNT1 A 0 A_TakeInventory("Taunting",1)
		TNT1 A 0 A_TakeInventory("IdleCounter",200)
		TNT1 A 5
		TNT1 A 0 A_Raise
		Wait
		
	Deselect:
		TNT1 A 0 A_ZoomFactor(1.0,ZOOM_INSTANT)
		TNT1 A 0 A_GunFlash("MudOff")
		TNT1 A 0 A_SetCrosshair(0)
		TNT1 A 0 A_PlaySound("weapons/changing")
		TNT1 A 0 A_TakeInventory("ADSmode",1)
		TNT1 A 0 A_JumpIfInventory("Zoomed", 1, 2)
		TNT1 A 0 A_Jump(256, 7)
		SNPZ YDCBA 1
		TNT1 A 0 A_TakeInventory("Zoomed", 1)
		SNPS ABCDE 1
		TNT1 A 0 A_Lower
		Wait
				
	Ready:
		TNT1 A 0 A_JumpIfInventory("GoFatality", 1, "Steady")
		TNT1 A 0 A_PlaySound("revolver/draw", 5)
	Ready1:
		SNPS EDCBA 1
	Ready2:
		TNT1 A 0 //A_GunFlash
	Ready3:
		TNT1 A 0 A_JumpIfInventory("Zoomed", 1, "ReadyZoom")
		TNT1 A 0 A_JumpIfInventory("Kicking",1,"DoKick")
		TNT1 A 0 A_JumpIfInventory("Taunting",1,"TauntR")
		TNT1 A 0 A_JumpIfInventory("Salute1",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("Salute2",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
		TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
		TNT1 A 0 A_JumpIfInventory("IdleCounter",200,"PlayerIsIdle")
		TNT1 A 0 A_TakeInventory("WeapSpecial",1)
		TNT1 A 0 A_TakeInventory("SwitchFlashlight",1)
		SNPF A 1 A_WeaponReady
		Loop
		
	ReadyZoom:
		TNT1 A 0 A_JumpIfInventory("Kicking",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("Taunting",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("Salute1",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("Salute2",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
		TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("WeapSpecial",1,"WeapSpecial")
		TNT1 A 0 A_JumpIfInventory("SwitchFlashlight",1,"WeapSpecial")
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1029)==1,2)
		SNPZ Y 1 A_WeaponReady
		Loop
		TNT1 A 0 A_JumpIfInventory("SniperAmmo",1,4)
		TNT1 A 0 A_JumpIfInventory("Clip2",1,3)
		SNPZ Y 1 A_WeaponReady(WRF_NOSECONDARY)
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,"ReadyZoom")
		Goto ZoomOut
		TNT1 A 0 A_WeaponReady(WRF_NOSECONDARY)
		SNPZ Y 1 A_JumpIfInventory("FiredPrimary",1,"Fire")
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,"ReadyZoom")
		Goto ZoomOut

// --------------------------------------------------------------------------
//
//	Fire
//
// --------------------------------------------------------------------------

	ZoomOutFire:
		TNT1 A 0 A_PlaySound("M40Rifle/Scope")
		TNT1 A 0 A_TakeInventory("Zoomed", 1)
		TNT1 A 0 A_TakeInventory("ADSmode",1)
		TNT1 A 0 A_Giveinventory("GoSpecial",1)
		SNPZ Y 1 A_ZoomFactor(1.0,ZOOM_INSTANT)
		TNT1 A 0 A_GunFlash("MudOff")
		TNT1 A 0 A_SetCrosshair(0)
		SNPZ DCBA 1
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",10,48)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",9,43)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",8,39)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",7,36)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",6,32)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",5,29)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",4,23)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",3,19)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",2,15)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",1,12)
		Goto Ready2
		
	Fire: //48 frames
		TNT1 A 0 A_JumpIfInventory("SniperAmmo",1,3)
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1)
		Goto DryFire
		TNT1 A 0
		Goto Reload
		TNT1 A 0 A_TakeInventory("SniperAmmo",1)
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_JumpIfInventory("Zoomed", 1, "FireZoom")
		TNT1 A 0 A_FireBullets(0.9, 0.9, -1, random(120,180), "HitPuff", FBF_NORANDOM)
		TNT1 A 0 A_PlaySound("M40Rifle/Fire", 1)
		TNT1 A 0 A_FireCustomMissile("ShakeYourAss", 0, 0, 0, 0)
		TNT1 A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,30)
		TNT1 A 0 A_SetPitch(Pitch-0.5)
		
		TNT1 a 0
		SNPF B 1 BRIGHT
		SNPF cDE 2
		SNPG aBC 2
		SNPG dEFH 1
		TNT1 A 0 A_PlaySound("M40Rifle/Bolt1", 5)
		SNPG iJk 2
		SNPG L 1
		TNT1 A 0 A_FireCustomMissile("RifleCaseSpawn",5,0,6,-10)
		SNPG l 2
		SNPG KjI 2
		TNT1 A 0 A_PlaySound("M40Rifle/Bolt2", 5)
		SNPG hFEDmNPO 2
		TNT1 A 0 A_TakeInventory("SniperAttackState",10)
		TNT1 A 0 A_StopSound(1)
		TNT1 A 0 A_TakeInventory("TossGrenade",1)
		Goto Ready2
		
	FireZoom://48 frames
		TNT1 A 0 A_FireBullets(0.1, 0.1, -1, random(120,180), "HitPuff", FBF_NORANDOM)
		TNT1 A 0 A_PlaySound("M40Rifle/Fire", 1)
		TNT1 A 0 A_FireCustomMissile("ShakeYourAss", 0, 0, 0, 0)
		TNT1 A 0 A_SpawnItemEx("PlayerMuzzle1",30,0,45)
		TNT1 A 0 A_SetPitch(Pitch-0.5)
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,"FireZoom2")
		
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//1
		SNPZ Y 1 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//2
		SNPZ YYY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//3
		SNPZ YYY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//4
		SNPZ YYYY 1 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_PlaySound("M40Rifle/Bolt1", 5)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//5
		
		SNPZ YY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//6
		SNPZ Y 3 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_FireCustomMissile("RifleCaseSpawn",5,0,6,-8)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//7
		
		SNPZ YY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//8
		SNPZ YY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_PlaySound("M40Rifle/Bolt2", 5)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//9
		
		SNPZ YYYY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//10
		SNPZ YYYY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_TakeInventory("SniperAttackState",10)
		TNT1 A 0 A_StopSound(1)
		TNT1 A 0 A_TakeInventory("WeapSpecial",1)
		TNT1 A 0 A_TakeInventory("SwitchFlashlight",1)
		TNT1 A 0 A_TakeInventory("TossGrenade",1)
		Goto ReadyZoom

	FireZoom2://48 frames
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//1
		SNPZ Y 1 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,1)
		Goto ZoomOutFire
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//2
		SNPZ YYY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,1)
		Goto ZoomOutFire
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//3
		SNPZ YYY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,1)
		Goto ZoomOutFire
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//4
		SNPZ YYYY 1 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,1)
		Goto ZoomOutFire
		TNT1 A 0 A_PlaySound("M40Rifle/Bolt1", 5)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//5
		
		SNPZ YY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,1)
		Goto ZoomOutFire
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//6
		SNPZ Y 3 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,1)
		Goto ZoomOutFire
		TNT1 A 0 A_FireCustomMissile("RifleCaseSpawn",5,0,6,-8)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//7
		
		SNPZ YY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,1)
		Goto ZoomOutFire
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//8
		SNPZ YY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,1)
		Goto ZoomOutFire
		TNT1 A 0 A_PlaySound("M40Rifle/Bolt2", 5)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//9
		
		SNPZ YYYY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,1)
		Goto ZoomOutFire
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)//10
		SNPZ YYYY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,1)
		Goto ZoomOutFire
		TNT1 A 0 A_TakeInventory("SniperAttackState",10)
		TNT1 A 0 A_StopSound(1)
		TNT1 A 0 A_TakeInventory("WeapSpecial",1)
		TNT1 A 0 A_TakeInventory("SwitchFlashlight",1)
		TNT1 A 0 A_TakeInventory("TossGrenade",1)
		Goto ReadyZoom

	AltFire:
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",1,"ZoomOutFire")
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,"ZoomOut")
		TNT1 A 0 A_GiveInventory("Zoomed",1)
		TNT1 A 0 A_Giveinventory("ADSmode",1)
		TNT1 A 0 A_Giveinventory("GoSpecial",1)
		SNPZ ABCD 1
		TNT1 A 0 A_GunFlash("MudOn")
		TNT1 A 0 A_SetCrosshair(41)
		TNT1 A 0 A_JumpIfInventory("SniperZoomFactor", 1, 2)
		SNPZ Y 2 A_ZoomFactor(4.0,ZOOM_INSTANT)
		Goto ReadyZoom
		TNT1 A 0 A_JumpIfInventory("SniperZoomFactor", 2, 2)
		SNPZ Y 2 A_ZoomFactor(8.0,ZOOM_INSTANT)
		Goto ReadyZoom
		SNPZ Y 2 A_ZoomFactor(16.0,ZOOM_INSTANT)
		Goto ReadyZoom
		
	ZoomOut:
		TNT1 A 0 A_TakeInventory("Zoomed",1)
		TNT1 A 0 A_TakeInventory("ADSmode",1)
		TNT1 A 0 A_Giveinventory("GoSpecial",1)
		SNPZ Y 1 A_ZoomFactor(1.0,ZOOM_INSTANT)
		TNT1 A 0 A_GunFlash("MudOff")
		TNT1 A 0 A_SetCrosshair(0)
		SNPZ DCBA 1
		Goto Ready2

// --------------------------------------------------------------------------
//
//	Reload
//
// --------------------------------------------------------------------------

	Reload:
		TNT1 A 0 A_TakeInventory("Reloading",1)
		TNT1 A 0 A_JumpIfInventory("SniperAmmo",6,"Ready2")
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1)
		Goto DryFire
		TNT1 A 0 A_JumpIfInventory("TurboReload",1,"ReloadLoop")
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,2)
		TNT1 A 0 A_Jump(256, 10)
		TNT1 A 0 A_TakeInventory("Zoomed", 1)
		TNT1 A 0 A_PlaySound("M40Rifle/Scope")
		SNPZ Y 1 A_ZoomFactor(1.0,ZOOM_INSTANT)
		TNT1 A 0 A_GunFlash("MudOff")
		TNT1 A 0 A_SetCrosshair(0)
		SNPZ DCBA 1
		TNT1 A 0 A_JumpIfInventory("SniperAmmo",1,2)
		TNT1 A 0 A_FireCustomMissile("EmptyClipSpawn",-5,0,8,-4)
		SNPG ABC 2
		TNT1 A 0 A_PlaySound("Reload")
		SNPR ABBCDEFGHIJ 2
		TNT1 A 0 A_JumpIfInventory("SniperAmmo",1,15)
		SNPG FH 2
		TNT1 A 0 A_PlaySound("M40Rifle/Bolt1", 5)
		SNPG IJK 2
		SNPG L 3
		SNPG KJI 2
		TNT1 A 0 A_PlaySound("M40Rifle/Bolt2", 5)
		SNPG HFEDMNPO 2
		Goto ReloadLoop
		SNPG DCBAO 2
		Goto ReloadLoop2
		
	ReloadLoop:
		TNT1 A 0 A_JumpIfInventory("SniperAmmo",5,"ReloadDone")
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1)
		Goto ReloadDone
		TNT1 A 0 A_Giveinventory("SniperAmmo",1)
		TNT1 A 0 A_TakeInventory("Clip2",1)
		Goto ReloadLoop

	ReloadLoop2:
		TNT1 A 0 A_JumpIfInventory("SniperAmmo",6,"ReloadDone")
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1)
		Goto ReloadDone
		TNT1 A 0 A_Giveinventory("SniperAmmo",1)
		TNT1 A 0 A_TakeInventory("Clip2",1)
		Goto ReloadLoop

	ReloadDone:
		TNT1 A 0 A_Refire
		Goto Ready2

// --------------------------------------------------------------------------
//
//	Misc.
//
// --------------------------------------------------------------------------

	DryFire:
		TNT1 A 0 A_PlaySound("weapons/empty")
		Goto Ready2

	WeapSpecial:
		TNT1 A 0 A_TakeInventory("WeapSpecial",1)
		TNT1 A 0 A_TakeInventory("SwitchFlashlight",1)
		TNT1 A 0 A_JumpIfInventory("SniperZoomFactor", 1, 5)
		//TNT1 A 0 A_GunFlash("ChangeZoom")
		TNT1 A 0 A_GiveInventory("SniperZoomFactor", 1)
		TNT1 A 0 A_PlaySound("M40Rifle/Scope")
		TNT1 A 0 A_ZoomFactor(8.0,ZOOM_INSTANT)
		SNPZ Z 2
		Goto ReadyZoom
		TNT1 A 0 A_JumpIfInventory("SniperZoomFactor", 2, 5)
		//TNT1 A 0 A_GunFlash("ChangeZoom")
		TNT1 A 0 A_GiveInventory("SniperZoomFactor", 1)
		TNT1 A 0 A_PlaySound("M40Rifle/Scope")
		TNT1 A 0 A_ZoomFactor(16.0,ZOOM_INSTANT)
		SNPZ Z 2
		Goto ReadyZoom
		//TNT1 A 0 A_GunFlash("ChangeZoom")
		TNT1 A 0 A_TakeInventory("SniperZoomFactor", 2)
		TNT1 A 0 A_PlaySound("M40Rifle/Scope")
		TNT1 A 0 A_ZoomFactor(4.0,ZOOM_INSTANT)
		SNPZ Z 2
		Goto ReadyZoom

	ChangeZoom:
		SNPZ W 2
	MudOn:
		SNPZ X 1
		loop
	MudOff:
		TNT1 A 1
		Stop

	PuristGun:
		TNT1 A 0 A_TakeInventory("SniperRifle", 1)
		Goto Deselect

// --------------------------------------------------------------------------
//
//	End stuff
//
// --------------------------------------------------------------------------

	TauntFlash:
		SNPK ABCD 1
		SNPK E 35
		SNPK DCBA 1
		SNPF A 1
		Stop

	KickFlash:
		SNPK ABCD 1
		SNPK E 8
		SNPK DCBA 1
		SNPF A 1
		Stop

	AirKickFlash:
		SNPK ABCD 1
		SNPK E 10
		SNPK DCBA 1
		SNPF A 1
		Stop

	SlideKickStartFlash:
		SNPK ABCD 1
		SNPK E 17
		Stop
	
	SlideKickEndFlash:
		SNPK EDCBA 2
		SNPF A 1
		Stop

	GrenadeFlash:
		SNPS ABCDE 1
		Stop
	}
}

ACTOR SniperAttackState : Inventory { Inventory.MaxAmount 10 }
ACTOR SniperZoomFactor : Inventory { Inventory.MaxAmount 2 }

ACTOR SniperAmmo : Ammo
{
	+INVENTORY.IGNORESKILL
	Inventory.Amount 0
	Inventory.MaxAmount 6
	Ammo.BackpackAmount 0
	Ammo.BackpackMaxAmount 6
   	Inventory.Icon "SNPXD0"
}