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

Actor SniperRifle : BaseWeapon
{
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive1 5
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "SniperMagazine"
	Weapon.AmmoType2 "SniperAmmo"
	Weapon.SelectionOrder 9500
	Weapon.Kickback 200
	-WEAPON.CHEATNOTWEAPON
    Inventory.PickupSound "CLIPIN"
	Inventory.PickupMessage "You got the M40 Sniper Rifle!"
	Obituary "%o was shot down by %k's Sniper Rifle"
	tag "Sniper rifle"
    Scale 0.8
	States
	{
	Spawn:
		SNPX A -1
		Stop
		
	Ready:
        TNT1 A 0 A_JumpIfInventory("GoFatality", 1, "Steady")
		TNT1 A 0 A_PlaySound("revolver/draw", 5)
	Ready1:
        SNPS EDCBA 1
		Goto Ready2

	Ready2:
        TNT1 A 0 A_JumpIfInventory("Zoomed", 1, "ScopedReady")
        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_Takeinventory("WeapSpecial",1)
		SNPF A 1 A_WeaponReady
		Loop
		
	ScopedReady:
		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
				
	Select:
		TNT1 A 0 A_JumpIfInventory("IsPlayingAsPurist", 1, "PuristGun")
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1004)==0, "PuristGun")
		TNT1 A 0 A_Takeinventory("FistsSelected",1)
		TNT1 A 0 A_Takeinventory("SawSelected",1)
		TNT1 A 0 A_Takeinventory("ShotgunSelected",1)
		TNT1 A 0 A_Takeinventory("SSGSelected",1)
		TNT1 A 0 A_Takeinventory("MinigunSelected",1)
		TNT1 A 0 A_Takeinventory("PlasmaGunSelected",1)
		TNT1 A 0 A_Takeinventory("RocketLauncherSelected",1)
		TNT1 A 0 A_Takeinventory("GrenadeLauncherSelected",1)
		TNT1 A 0 A_Takeinventory("BFGSelected",1)
		TNT1 A 0 A_Takeinventory("BFG10kSelected",1)
		TNT1 A 0 A_Takeinventory("RailGunSelected",1)
		TNT1 A 0 A_Takeinventory("SubMachineGunSelected",1)
		TNT1 A 0 A_Takeinventory("RevenantLauncherSelected",1)
		TNT1 A 0 A_Takeinventory("LostSoulSelected",1)
		TNT1 A 0 A_Takeinventory("FlameCannonSelected",1)
		TNT1 A 0 A_Takeinventory("HasBarrel",1)
		TNT1 A 0 A_TakeInventory("TossGrenade", 1)
		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 0 A_Takeinventory("Unloading",1)
		TNT1 A 0 A_Lower
		Wait
		
	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)
		SNPZ Y 1 A_ZoomFactor(1.0,ZOOM_INSTANT)
		TNT1 A 0 A_GunFlash("MudOff")
		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, "ScopedFire")
        TNT1 A 0 A_JumpIfInventory("SniperAmmo",1,1)
        Goto NoAmmo
        TNT1 A 0 A_Takeinventory("SniperAmmo",1)
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_FireBullets (0.9, 0.9, -1, random(100,150), "HitPuff", FBF_NORANDOM)
		//TNT1 A 0 A_FireCustomMissile("Tracer", frandom(-1,1), 0, -1, -12, 0, frandom(-1,1))
		TNT1 A 0 A_PlaySound("M40Rifle/Fire", 1)
		TNT1 A 0 A_FireCustomMissile("ShakeYourAss", 0, 0, 0, 0)
		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("SniperCaseSpawn",5,0,6,-6)
		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
		
	ScopedFire:
        TNT1 A 0 A_JumpIfInventory("SniperAmmo",1,1)
        Goto NoAmmo
        TNT1 A 0 A_Takeinventory("SniperAmmo",1)
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_FireBullets (0.1, 0.1, -1, random(100,150), "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_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("SniperCaseSpawn",5,0,6,-6)
		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 ScopedReady

	NoAmmo:
		TNT1 A 0 A_PlaySound("weapons/empty")
    Reload:
		TNT1 A 0 A_JumpIfInventory("SniperAmmo",5,2)
		TNT1 A 0 A_JumpIfInventory("SniperMagazine",1,2)
		TNT1 A 0 A_Takeinventory("Reloading",1)
		Goto Ready2
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,2)
		TNT1 A 0 A_Jump(256, 9)
		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")
		SNPZ DCBA 1
		TNT1 A 0 A_Takeinventory("Reloading",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
		TNT1 A 0 A_Takeinventory("Reloading",1)
		Goto InsertBullets
	InsertBullets:
		TNT1 A 0 A_JumpIfInventory("SniperAmmo",5,2)
		TNT1 A 0 A_JumpIfInventory("SniperMagazine",1,2)
		TNT1 A 0 A_Takeinventory("Reloading",1)
		Goto Ready2
		TNT1 A 0 A_Giveinventory("SniperAmmo",1)
		TNT1 A 0 A_Takeinventory("SniperMagazine",1)
		Goto InsertBullets
		
	AltFire:
		TNT1 A 0 A_JumpIfInventory("SniperAttackState", 1, "ZoomOutFire")
		TNT1 A 0 A_JumpIfInventory("Zoomed", 1, "ZoomOut")
		//TNT1 A 0 A_PlaySound("M40Rifle/Scope")
		TNT1 A 0 A_GiveInventory("Zoomed", 1)
		TNT1 A 0 A_Giveinventory("ADSmode",1)
		SNPZ ABCD 1
		TNT1 A 0 A_GunFlash("MudOn")
		TNT1 A 0 A_SetCrosshair(99)
		TNT1 A 0 A_JumpIfInventory("SniperZoomFactor", 1, 2)
		SNPZ Y 2 A_ZoomFactor(4.0,ZOOM_INSTANT)
		Goto ScopedReady
		TNT1 A 0 A_JumpIfInventory("SniperZoomFactor", 2, 2)
		SNPZ Y 2 A_ZoomFactor(8.0,ZOOM_INSTANT)
		Goto ScopedReady
		SNPZ Y 2 A_ZoomFactor(16.0,ZOOM_INSTANT)
		Goto ScopedReady
		
	ZoomOut:
		//TNT1 A 0 A_PlaySound("M40Rifle/Scope")
		TNT1 A 0 A_TakeInventory("Zoomed", 1)
		TNT1 A 0 A_Takeinventory("ADSmode",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 ScopedReady
		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 ScopedReady
		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 ScopedReady

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

	KickFlash:
		SNPK ABCD 1
		SNPK E 8
		SNPK DCBA 1
		Stop
		
	AirKickFlash:
		SNPK ABCD 1
		SNPK E 10
		SNPK DCBA 1
		Stop
		
	TauntFlash:
		SNPK ABCD 1
		SNPK E 35
		SNPK DCBA 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"
}