// --------------------------------------------------------------------------
//
//	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("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_Takeinventory("WeapSpecial",1)
		TNT1 A 0 A_Takeinventory("TossGrenade",1)
		TNT1 A 1 A_Takeinventory("Unloading",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_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)
		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")
		SNPZ Y 1 A_WeaponReady
		Loop

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

	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,46)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",9,41)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",8,37)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",7,34)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",6,30)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",5,27)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",4,21)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",3,17)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",2,13)
		TNT1 A 0 A_JumpIfInventory("SniperAttackState",1,10)
		Goto Ready2
		
	Fire:
		TNT1 A 0 A_JumpIfInventory("Zoomed", 1, "FireZoom")
        TNT1 A 0 A_JumpIfInventory("SniperAmmo",1,1)
        Goto Reload
        TNT1 A 0 A_Takeinventory("SniperAmmo",1)
		TNT1 A 0 A_AlertMonsters
		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)
		
		SNPF 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("WeapSpecial",1)
		TNT1 A 0 A_Takeinventory("TossGrenade",1)
		Goto Ready2
		
	FireZoom:
        TNT1 A 0 A_JumpIfInventory("SniperAmmo",1,1)
        Goto Reload
        TNT1 A 0 A_Takeinventory("SniperAmmo",1)
		TNT1 A 0 A_AlertMonsters
		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_Giveinventory("SniperAttackState",1)
		SNPZ Y 1 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)
		SNPZ YYY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)
		SNPZ YYY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)
		SNPZ YYYY 1 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_PlaySound("M40Rifle/Bolt1", 5)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)
		
		SNPZ YY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)
		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)
		
		SNPZ YY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)
		SNPZ YY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_PlaySound("M40Rifle/Bolt2", 5)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)
		
		SNPZ YYYY 2 A_WeaponReady(WRF_NOSWITCH|WRF_NOPRIMARY)
		TNT1 A 0 A_Giveinventory("SniperAttackState",1)
		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("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

	WeapSpecial:
		TNT1 A 0 A_Takeinventory("WeapSpecial",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)
		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)
		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)
		Goto ReadyZoom

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

	DryFire:
		TNT1 A 0 A_PlaySound("weapons/empty")
		Goto Ready2
		
    Reload:
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_JumpIfInventory("SniperAmmo",5,"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_FireCustomMissile("EmptyClipSpawn",-5,0,8,-4)
		SNPG ABC 2
		TNT1 A 0 A_PlaySound("Reload")
		SNPR ABBCDEFGHIJ 2
		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
		
	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

	ReloadDone:
		TNT1 A 0 A_Refire
		Goto Ready2

	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
		
	TauntFlash:
		SNPK ABCD 1
		SNPK E 35
		SNPK DCBA 1
		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 5
	Ammo.BackpackAmount 0
	Ammo.BackpackMaxAmount 5
   	Inventory.Icon "SNPXD0"
}