// --------------------------------------------------------------------------
//
//	Rifle
//
// --------------------------------------------------------------------------

ACTOR DualURifle : BaseWeapon
{
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive1 10
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "Clip2"
	Weapon.AmmoType2 "DualRifleAmmo"
	Weapon.SelectionOrder 2500
	-WEAPON.CHEATNOTWEAPON
	+POWERED_UP
	Weapon.SisterWeapon "U_Rifle"
	Inventory.PickupSound "CLIPIN"
	Inventory.Pickupmessage "Y$GOTRIFLE"
	Obituary "%o was shot down by %k's assault rifles."
	tag "Dual Rifles"
	Scale 0.8
	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("SwitchFlashlight",1)
		TNT1 A 0 A_Takeinventory("Taunting",1)
		TNT1 A 0 A_Takeinventory("IdleCounter",200)
		TNT1 A 4
		TNT1 A 0 A_Raise
		Wait
		
	Deselect:
		TNT1 A 0 A_PlaySound("weapons/changing")
		DURS ABCDEF 1
		TNT1 A 0 A_Takeinventory("RifleSelected",1)
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1028)==2, 2)
		TNT1 A 0 A_Takeinventory("PowerWeaponLevel2",1)
		TNT1 A 0 A_Lower
		Wait
		
	Ready:
		TNT1 A 0 A_JumpIfInventory("GoFatality",1,"Steady")
		TNT1 A 0 A_PlaySound("CLIPIN")
	Ready1:
		DURS FEDCBA 1
	Ready2:
		TNT1 A 0 //A_GunFlash
		TNT1 A 0 A_JumpIfInventory("Kicking",1,"DoKick")
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
		TNT1 A 0 A_JumpIfInventory("Taunting",1,"Taunt")
		TNT1 A 0 A_JumpIfInventory("Salute1",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("Salute2",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
		//TNT1 A 0 A_JumpIfInventory("Unloading",1,"Unload")
		TNT1 A 0 A_JumpIfInventory("StartDualWield",1,"DualWield")
		TNT1 A 0 A_JumpIfInventory("IdleCounter",200,"PlayerIsIdle")
		DURI A 1 A_WeaponReady
		Goto Ready2
		
// --------------------------------------------------------------------------
//
//	Fire
//
// --------------------------------------------------------------------------

	Fire:
		DURI A 1
		TNT1 A 0 A_JumpIfInventory("DualRifleAmmo",2,1)
		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,5,0,0,0)
		TNT1 A 0 A_FireCustomMissile("YellowFlareSpawn",-5,0,15,0)
		TNT1 A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,30)
		TNT1 A 0 A_ZoomFactor(0.99)
		TNT1 A 0 A_JumpIfInventory("FireSeq",1,3)
		DURI B 1 BRIGHT A_FireBullets(3.2,3.2,-1,13,"HitPuff")
		TNT1 A 0 A_Jump(256,3)
		DURI H 1 BRIGHT A_FireBullets(3.2,3.2,-1,13,"HitPuff")
		TNT1 A 0 A_SetPitch(+0.1 + pitch)
		TNT1 A 0 A_FireCustomMissile("DecorativeTracer",frandom(-1,1),0,15,-6,0,frandom(-1,1))
		TNT1 A 0 A_Takeinventory("DualRifleAmmo",1)
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_SetPitch(-1.5 + pitch)
		DURI C 1 A_AlertMonsters
		TNT1 A 0 A_SetPitch(+0.5 + pitch)
		TNT1 A 0 A_FireCustomMissile("RifleCaseSpawn",5,0,21,-14)

		TNT1 A 0 A_PlaySound("weapons/rifle",5,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,-5,0,0,0)
		TNT1 A 0 A_FireCustomMissile("YellowFlareSpawn",-5,0,-15,0)
		TNT1 A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,30)
		TNT1 A 0 A_ZoomFactor(0.99)
		DURI D 1 BRIGHT A_FireBullets(3.2,3.2,-1,13,"HitPuff")
		TNT1 A 0 A_FireCustomMissile("DecorativeTracer",frandom(-1,1),0,-15,-6,0,frandom(-1,1))
		TNT1 A 0 A_Takeinventory("DualRifleAmmo",1)
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_SetPitch(-1.2 + pitch)
		DURI E 1 A_AlertMonsters
		TNT1 A 0 A_SetPitch(+0.6 + pitch)
		TNT1 A 0 A_FireCustomMissile("RifleCaseSpawn",5,0,-13,-14)

		DURI F 1 A_GiveInventory("FireSeq",1)
		TNT1 A 0 A_SetPitch(+0.3 + pitch)
		TNT1 A 0 A_Refire
		DURI G 1 A_TakeInventory("FireSeq",2)
		TNT1 A 0 A_FireCustomMissile("SmokeSpawner11",0,0,21,0)
		TNT1 A 0 A_FireCustomMissile("SmokeSpawner11",0,0,-21,0)
		TNT1 A 0 A_SetPitch(+0.1 + pitch)
		DURI A 1 A_WeaponReady
		Goto Ready2
		
		
// --------------------------------------------------------------------------
//
//	Reload and unload
//
// --------------------------------------------------------------------------
		
	Reload:
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_JumpIfInventory("DualRifleAmmo",62,"Ready2")
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1)
		Goto DryFire
		TNT1 A 0 A_GiveInventory("Pumping",1)
		TNT1 A 0 A_JumpIfInventory("TurboReload",1,"TurboReload")
		DURS ABCDEF 1
		TNT1 A 5
		TNT1 A 0 A_PlaySound("RELOAD", 1)
		TNT1 A 0 A_JumpIfInventory("DualRifleAmmo",1,3)
		TNT1 A 0 A_JumpIfInventory("HasUnloaded_DualRifle",1,2)
		TNT1 A 0 A_FireCustomMissile("EmptyClipSpawn",185,0,8,-4)
		R2RR ABCDDDDDDEFGHIIJJKLMNO 1
		TNT1 A 10
		TNT1 A 0 A_PlaySound("RELOAD", 1)
		TNT1 A 0 A_JumpIfInventory("DualRifleAmmo",1,3)
		TNT1 A 0 A_JumpIfInventory("HasUnloaded_DualRifle",1,2)
		TNT1 A 0 A_FireCustomMissile("EmptyClipSpawn",-5,0,8,-4)
		R2RL ABCDDDDDDEFGHIIJJKLMNO 1
		TNT1 A 0 A_TakeInventory("StopDualWield", 1)
		TNT1 A 0 A_TakeInventory("FiredPrimary", 1)
		TNT1 A 0 A_TakeInventory("FiredSecondary", 1)
		TNT1 A 5
		
	TurboReload:
		TNT1 A 0 A_Takeinventory("HasUnloaded",1)
		Goto ReloadLoop
		
	ReloadLoop:
		TNT1 A 0 A_JumpIfInventory("DualRifleAmmo",62,"ReloadDone")
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1)
		Goto ReloadDone
		TNT1 A 0 A_Giveinventory("DualRifleAmmo",1)
		TNT1 A 0 A_Takeinventory("Clip2",1)
		Loop

	ReloadDone:
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_TakeInventory("HasUnloaded_DualRifle",1)
		TNT1 A 0 A_JumpIfInventory("TurboReload",1,1)
		Goto Ready1
		TNT1 A 0 A_Refire
		Goto Ready2

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

	DualWield:
		TNT1 A 0 A_Takeinventory("StartDualWield",1)
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1028)==2, "Ready2")
		TNT1 A 0 A_Takeinventory("PowerSphere2",1)
		Goto Deselect

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

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

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

	Taunt:
		DURI A 5
		TNT1 A 0 A_PlaySound("FUCK",2)
		TNT1 A 0 A_FireCustomMissile("Taunter",0,0,-1,0)
		TNT1 A 0 A_FireCustomMissile("Taunter",-9,0,-1,0)
		TNT1 A 0 A_FireCustomMissile("Taunter",9,0,-1,0)
		TNT1 A 0 A_AlertMonsters
		DURI A 20
		TNT1 A 0 A_Takeinventory("Taunting",1)
		Goto Ready2

	KickFlash:
		DURK ABCDE 1
		DURK F 6
		DURK EDCBA 1
		DURI A 1
		Stop
		
	AirKickFlash:
		DURK ABCDE 1
		DURK F 8
		DURK EDCBA 1
		DURI A 1
		Stop
		
	GrenadeFlash:
		DURS ABCDEF 1
		Stop
	}
}

ACTOR HasUnloaded_DualRifle : Inventory { Inventory.MaxAmount 1 }

ACTOR DualRifleAmmo: Ammo
{
	+INVENTORY.IGNORESKILL
	Inventory.Amount 0
	Inventory.MaxAmount 62
	Ammo.BackpackAmount 0
	Ammo.BackpackMaxAmount 62
	Inventory.Icon "RIFLA0"
}