// --------------------------------------------------------------------------
//
//	Rifle
//
// --------------------------------------------------------------------------
	
ACTOR U_Rifle : BaseWeapon replaces Rifle
{
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive1 30
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "Clip2"
	Weapon.AmmoType2 "RifleAmmo"
	Weapon.SelectionOrder 2500
	-WEAPON.CHEATNOTWEAPON
    Inventory.PickupSound "CLIPIN"
	Inventory.Pickupmessage "$GOTRIFLE"
	Obituary "%o was shot down by %k's assault rifle."
	Scale 0.8
	tag "Rifle"
	States
	{
 	Spawn:
		RIFL A -1
		Stop

	Select:
		TNT1 A 0 A_JumpIfInventory("IsPlayingAsPurist", 1, "PuristGun")
		TNT1 A 0 A_Giveinventory("RifleSelected",1)
		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_SetCrosshair(0)
		TNT1 A 0 A_Takeinventory("Zoomed",1)
		TNT1 A 0 A_Takeinventory("ADSmode",1)
		TNT1 A 0 A_ZoomFactor(1.0)
		RIFS ABCDE 1
		TNT1 A 1 A_TakeInventory("RifleSelected", 1)
		TNT1 A 0 A_Lower
		Wait
	
	Ready:
		TNT1 A 0 A_JumpIfInventory("JustStartedGame",1,"WarmUp")
		TNT1 A 0 A_JumpIfInventory("GoFatality",1,"Steady")
		TNT1 A 0 A_PlaySound("CLIPIN")
	Ready1:
		RIFS 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,"TauntL")
        TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
		TNT1 A 0 A_JumpIfInventory("Salute1",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("Salute2",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("Unloading",1,"Unload")
		TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
		TNT1 A 0 A_JumpIfInventory("IdleCounter",200,"PlayerIsIdle")
		RIFG A 1 A_WeaponReady
		Goto Ready2

	ReadyZoom:
        TNT1 A 0 A_JumpIfInventory("Kicking",1,"ZoomOut")
        TNT1 A 0 A_JumpIfInventory("Taunting",1,"ZoomOut")
        TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
		TNT1 A 0 A_JumpIfInventory("Salute1",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("Salute2",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("Unloading",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"ZoomOut")
		RI2G A 1 A_WeaponReady
		Goto ReadyZoom

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

	WarmUp:
		TNT1 A 0 A_TakeInventory("JustStartedGame", 1)
		TNT1 A 10 A_WeaponReady
		PUNS ABCD 1 A_WeaponReady
		TNT1 A 0 A_PlaySound("Knuckled")
		PUNS E 7 A_WeaponReady
		PUNS FGFE 3 A_WeaponReady
		PUNS DCB 1 A_WeaponReady
		TNT1 A 10 A_WeaponReady
		Goto Ready
		
// --------------------------------------------------------------------------
//
//	Fire
//
// --------------------------------------------------------------------------
		
    Fire:
		TNT1 A 0 A_JumpIfInventory("RifleAmmo",1,1)
		Goto DryFire
		TNT1 A 0 A_PlaySound("weapons/rifle",1,0.8)
		TNT1 A 0 A_FireCustomMissile("DistantFireSoundRifle", random(-1,1), 0, 0, -12, 0, random(-1,1))
		TNT1 A 0 A_FireCustomMissile("GunFireSmoke", 0, 0, 0, 0, 0, 0)
		TNT1 A 0 A_FireCustomMissile("YellowFlareSpawn",-5,0,0,0)
		TNT1 A 0 A_Takeinventory("RifleAmmo",1)
		TNT1 A 0 A_AlertMonsters		
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,"FireZoom")
		RIFF A 1 BRIGHT A_FireBullets(1.6, 1.6, -1, 12, "HitPuff")
		TNT1 A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,30)
		TNT1 A 0 A_FireCustomMissile("DecorativeTracer", frandom(-1,1), 0, 0, -6, 0, frandom(-1,1))
		TNT1 A 0 A_SetPitch(-1.5 + pitch)
		RIFF B 1 A_ZoomFactor(0.99)
		TNT1 A 0 A_SetPitch(+0.5 + pitch)
		RIFF C 1 A_FireCustomMissile("RifleCaseSpawn",5,0,4,-14)
		TNT1 A 0 A_SetPitch(+0.3 + pitch)
		RIFG A 1 A_ZoomFactor(1.0)
		TNT1 A 0 A_SetPitch(+0.1 + pitch)
		RIFG A 1
		TNT1 A 0 A_Refire
		TNT1 A 0 A_FireCustomMissile("SmokeSpawner11",0,0,0,0)
		RIFG A 1 A_WeaponReady
		Goto Ready2

     FireZoom:
		RI2F A 1 BRIGHT A_FireBullets (0.8, 0.8, -1, 12, "HitPuff")
		TNT1 A 0 A_SpawnItemEx("PlayerMuzzle1",30,0,45)
		TNT1 A 0 A_FireCustomMissile("DecorativeTracer", frandom(-0.5,0.5), 0, 0, -6, 0, frandom(-0.5,0.5))
		TNT1 A 0 A_SetPitch(-1.5 + pitch)
		RI2F B 1 A_ZoomFactor(1.48)
		TNT1 A 0 A_SetPitch(+0.5 + pitch)
		RI2F C 1 A_FireCustomMissile("RifleCaseSpawn",5,0,4,-4)
		TNT1 A 0 A_SetPitch(+0.3 + pitch)
		RI2G A 1 A_ZoomFactor(1.5)
		TNT1 A 0 A_SetPitch(+0.1 + pitch)
		RI2G A 1
        TNT1 A 0 A_ReFire
		TNT1 A 0 A_FireCustomMissile("SmokeSpawner11",0,0,0,0)
		RI2G A 2 A_WeaponReady
		Goto ReadyZoom

	AltFire:
		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)
		TNT1 A 0 A_ZoomFactor(1.5)
		RIFZ ABC 1
		TNT1 A 0 A_SetCrosshair(41)
		Goto ReadyZoom

	ZoomOut:
		TNT1 A 0 A_Takeinventory("Zoomed",1)
		TNT1 A 0 A_Takeinventory("ADSmode",1)
		TNT1 A 0 A_Giveinventory("GoSpecial",1)
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_SetCrosshair(0)
		RIFZ CBA 1
		Goto Ready2

	DryFire:
		TNT1 A 0 A_JumpIfInventory("Clip2",1,"Reload")
		RIFG A 3 A_PlaySound("weapons/empty", 5)
		Goto Ready2

// --------------------------------------------------------------------------
//
//	Reload n Unload
//
// --------------------------------------------------------------------------

    Reload:
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_JumpIfInventory("RifleAmmo",31,"Ready2") //Check if weapon is full already.
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1) //Check if we have spare ammo.
		Goto Ready2
		TNT1 A 0 A_JumpIfInventory("TurboReload",1,"TurboReloadLoop")
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,2) //Check if zoomed
		TNT1 A 0 A_Jump(256, 7)
		RIFZ CBA 1
		TNT1 A 0 A_Takeinventory("Zoomed",1)
        TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_SetCrosshair(0)
		TNT1 A 0 A_Takeinventory("ADSmode",1)
        TNT1 A 0 A_PlaySound("Reload")
		TNT1 A 0 A_GiveInventory("Pumping", 1)
        RIFR ABCDE 1
		TNT1 A 0 A_JumpIfInventory("RifleAmmo",1,"Reload2") //Check if there is any bullet left in the magazine.
		TNT1 A 0 A_JumpIfInventory("HasUnloaded_Rifle", 1, 2) //Check if weapon has a magazine.
		TNT1 A 0 A_FireCustomMissile("EmptyClipSpawn",-5,0,8,-4)
        RIFR FGGGGGGHIKLMMMMMNO 1
		RIFT A 4
		TNT1 A 0 A_PlaySound("SLAPBABY")
		RIFT BCD 1
		RIFT E 3
		RIFT FGHIJK 2
		RIFR RST 1
		Goto ReloadLoop
	Reload2:
		RIFR FGGGGGGHIKLMMMMMNOPQRST 1
		Goto ReloadLoop2

	TurboReloadLoop:
	ReloadLoop:
		TNT1 A 0 A_JumpIfInventory("RifleAmmo",30,"ReloadDone")
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1)
		Goto ReloadDone
		TNT1 A 0 A_Giveinventory("RifleAmmo",1)
		TNT1 A 0 A_Takeinventory("Clip2",1)
		Loop

	ReloadLoop2:
		TNT1 A 0 A_JumpIfInventory("RifleAmmo",31,"ReloadDone")
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1)
		Goto ReloadDone
		TNT1 A 0 A_Giveinventory("RifleAmmo",1)
		TNT1 A 0 A_Takeinventory("Clip2",1)
		Loop
		
	ReloadDone:
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_Refire
		Goto Ready2
		
	Unload:
		TNT1 A 0 A_Takeinventory("Unloading",1)
        TNT1 A 0 A_JumpIfInventory("RifleAmmo",1,1)
        Goto Ready2
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,2) //Check if zoomed
		TNT1 A 0 A_Jump(256, 7)
		RIFZ CBA 1
		TNT1 A 0 A_Takeinventory("Zoomed",1)
        TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_SetCrosshair(0)
		TNT1 A 0 A_Takeinventory("ADSmode",1)
		RIFG A 1
		RIFR TSRQPO 1
        TNT1 A 0 A_PlaySound("Reload")
		TNT1 A 0 A_GiveInventory("Pumping", 1)
		Goto UnloadLoop

	UnloadLoop:
		TNT1 A 0 A_JumpIfInventory("RifleAmmo",1,1)
		Goto UnloadDone
		TNT1 A 0 A_Takeinventory("RifleAmmo",1)
		TNT1 A 0 A_Giveinventory("Clip2",1)
		Loop

	UnloadDone:
		RIFR NMLKIGHGFEDCBA 1
		TNT1 A 0 A_GiveInventory("HasUnloaded_Rifle", 1)
		Goto Ready2
		
		
// --------------------------------------------------------------------------
//
//	End stuff
//
// --------------------------------------------------------------------------

	KickFlash:
		RIFK ABCD 1
		RIFK E 8
		RIFK DCBA 1
		RIFG A 1
		Stop

	AirKickFlash:
		RIFK ABCD 1
		RIFK E 10
		RIFK DCBA 1
		RIFG A 1
		Stop

	TauntFlash:
		RIFR ABCDEF 1
		RIFK F 31
		RIFR FEDCBA 1
		RIFG A 1
		Stop

	GrenadeFlash:
		RIFS ABCDE 1
		Stop
	}
}

ACTOR HasUnloaded_Rifle : Inventory { Inventory.MaxAmount 1 }