// --------------------------------------------------------------------------
//
//	Rifle
//
// --------------------------------------------------------------------------
	
ACTOR U_Rifle : BaseWeapon replaces Rifle
{
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive1 10
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "Clip2"
	Weapon.AmmoType2 "RifleAmmo"
	Weapon.SelectionOrder 2500
	-WEAPON.CHEATNOTWEAPON
	Weapon.SisterWeapon "DualURifle"
	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("StartDualWield",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_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_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,"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("StartDualWield",1,"DualWield")
		TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
		TNT1 A 0 A_JumpIfInventory("IdleCounter",200,"PlayerIsIdle")
		RIFG 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("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")
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1029)==1,2)
		RI2G A 1 A_WeaponReady
		Loop
		TNT1 A 0 A_JumpIfInventory("RifleAmmo",1,4)
		TNT1 A 0 A_JumpIfInventory("Clip2",1,3)
		RI2G A 1 A_WeaponReady(WRF_NOSECONDARY)
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,"ReadyZoom")
		Goto ZoomOut
		TNT1 A 0 A_WeaponReady(WRF_NOSECONDARY)
		RI2G A 1 A_JumpIfInventory("FiredPrimary",1,"Fire")
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,"ReadyZoom")
		Goto ZoomOut
		
// --------------------------------------------------------------------------
//
//	Fire
//
// --------------------------------------------------------------------------
		
	Fire:
		TNT1 A 0 A_JumpIfInventory("RifleAmmo",1,3)
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1)
		Goto DryFire
		TNT1 A 0
		Goto Reload
		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, 13, "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, 13, "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 1 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 ABCD 1
		TNT1 A 0 A_SetCrosshair(41)
		Goto ReadyZoom

	ZoomOut:
		TNT1 A 0 A_ClearReFire
		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 DCBA 1
		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 FGGGGGHIKLMMMNO 1
		RIFT A 5
		TNT1 A 0 A_PlaySound("SLAPBABY")
		RIFT BCD 1
		RIFT E 4
		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_TakeInventory("HasUnloaded_Rifle", 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

// --------------------------------------------------------------------------
//
//	Misc.
//
// --------------------------------------------------------------------------
	
	DualWield:
		TNT1 A 0 A_Takeinventory("StartDualWield",1)
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1028)==0, "NoDualWield")
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1028)==2, "Ready2")
		TNT1 A 0 A_JumpIfInventory("TE_Rifles",2,2)
		TNT1 A 0 A_Print("You must have two rifles to dual wield.")
		Goto Ready2
		RIFS ABCDE 1
		TNT1 A 6
		TNT1 A 0 A_Takeinventory("StartDualWield",1)
		TNT1 A 0 A_Giveinventory("PowerSphere2",1)
		Goto Ready

	NoDualWield:
		TNT1 A 0 A_Print("Dual wielding is disabled.")
		Goto Ready2

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

	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

	Execution2:
		TNT1 A 0 A_ZoomFactor(1.1)
		RIBB A 1 A_Stop
        RIBB B 1 A_PlaySound("skeleton/swing")
		RIBB C 1 A_FireCustomMissile("ExecutionAttackMelee", 0, 0, 0, 0)
		RIBB D 6 A_Stop
		RIBB CBA 2 A_Stop
		RIBB A 1 A_Stop
        RIBB B 1 A_PlaySound("skeleton/swing")
		RIBB C 1 A_FireCustomMissile("ExecutionAttackMelee", 0, 0, 0, 0)
		RIBB D 6 A_Stop
		RIBB CBA 2 A_Stop
		RIBB A 1 A_Stop
        RIBB B 1 A_PlaySound("skeleton/swing")
		RIBB C 1 A_FireCustomMissile("ExecutionAttackKick", 0, 0, 0, 0)
		RIBB D 6 A_Stop
		RIBB CBA 2 A_Stop
		TNT1 A 5
		Goto FinishExecution	

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

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

	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
		
	SlideKickStartFlash:
		RIFK ABCD 1
		RIFK E 17
		Stop
	
	SlideKickEndFlash:
		RIFK EDCBA 2
		RIFG A 1
		Stop

	GrenadeFlash:
		RIFS ABCDE 1
		Stop
	}
}

ACTOR HasUnloaded_Rifle : Inventory { Inventory.MaxAmount 1 }