// --------------------------------------------------------------------------
//
//	SMG
//
// --------------------------------------------------------------------------

ACTOR U_SMG : BaseWeapon replaces BrutalSMG
{
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive1 30
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "Magazine9mm"
	Weapon.AmmoType2 "BDSMGAmmo"
	Weapon.SelectionOrder 5500
	-WEAPON.CHEATNOTWEAPON
	Weapon.SisterWeapon "DualUSMG"
	Inventory.PickupSound "CLIPIN"
	Inventory.Pickupmessage "You got the Submachine gun!"
	Obituary "%o was shot down by %k's SMG."
	Scale 0.9
	tag "Submachine gun"
	States
	{
 	Spawn:
		SMGZ A -1
		Stop

	Select:
		TNT1 A 0 A_JumpIfInventory("IsPlayingAsPurist",1,"PuristGun")
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1002,0)==0, "PuristGun")
		//TNT1 A 0 A_Giveinventory("SubMachineGunSelected",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 4
		TNT1 A 0 A_Raise
		Wait
		
	Deselect:
		TNT1 A 0 A_PlaySound("weapons/changing")
		TNT1 A 0 A_Takeinventory("Zoomed",1)
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_SetCrosshair(0)
		SMGS ABCDEF 1
		TNT1 A 0 A_Takeinventory("ADSmode",1)
		TNT1 A 0 A_Takeinventory("SubMachineGunSelected",1)
		TNT1 A 0 A_Lower
		Wait
		
	Ready:
		TNT1 A 0 A_JumpIfInventory("GoFatality",1,"Steady")
		TNT1 A 0 A_PlaySound("CLIPIN")
	Ready1:
		SMGS FEDCBA 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("Salute1",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("Salute2",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
		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")
		SMGG 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("TossGrenade",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("Unloading",1,"ZoomOut")
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1029)==1,2)
		SMGA A 1 A_WeaponReady
		Loop
		TNT1 A 0 A_JumpIfInventory("BDSMGAmmo",1,4)
		TNT1 A 0 A_JumpIfInventory("Magazine9mm",1,3)
		SMGA A 1 A_WeaponReady(WRF_NOSECONDARY)
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,"ReadyZoom")
		Goto ZoomOut
		TNT1 A 0 A_WeaponReady(WRF_NOSECONDARY)
		SMGA A 1 A_JumpIfInventory("FiredPrimary",1,"Fire")
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,"ReadyZoom")
		Goto ZoomOut
		
// --------------------------------------------------------------------------
//
//	Fire
//
// --------------------------------------------------------------------------

	Fire:
		TNT1 A 0 A_JumpIfInventory("BDSMGAmmo",1,3)
		TNT1 A 0 A_JumpIfInventory("Magazine9mm",1,1)
		Goto DryFire
		TNT1 A 0
		Goto Reload
		TNT1 A 0 A_PlaySound("SMGFIRE")
		TNT1 A 0 A_PlaySound("FARSHT",6)
		TNT1 A 0 A_FireCustomMissile("SmokeSpawner",0,0,0,5)
		TNT1 A 0 A_FireCustomMissile("YellowFlareSpawn",-5,0,0,0)
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,"FireZoom")
		TNT1 A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,30)
		TNT1 A 0 A_ZoomFactor(0.98)
		SMGF A 1 BRIGHT A_FireBullets(3.6, 3.6, -1, 8, "WeakPuff")
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_FireCustomMissile("Tracer", frandom(-3,3), 0, -1, 0, 0, frandom(-3,3))
		TNT1 A 0 A_Takeinventory("BDSMGAmmo",1)
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_SetPitch(-1.1 + pitch)
		SMGF B 1
		TNT1 A 0 A_SetPitch(+0.5 + pitch)
		SMGF C 1
		TNT1 A 0 A_SetPitch(+0.4 + pitch)
		TNT1 A 0 A_FireCustomMissile("9mmCaseSpawn",5,0,6,-7)
		TNT1 A 0 A_ReFire
		SMGG A 1 A_WeaponReady
		Goto Ready2
		
	FireZoom:
		TNT1 A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,45)
		TNT1 A 0 A_ZoomFactor(1.45)
		SMGA B 1 BRIGHT A_FireBullets(1.8, 1.8, -1, 8, "WeakPuff")
		TNT1 A 0 A_ZoomFactor(1.5)
		TNT1 A 0 A_FireCustomMissile("Tracer", frandom(-3,3), 0, -1, 0, 0, frandom(-3,3))
		TNT1 A 0 A_Takeinventory("BDSMGAmmo",1)
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_SetPitch(-1.1 + pitch)
		SMGA C 1
		TNT1 A 0 A_SetPitch(+0.5 + pitch)
		SMGA D 1
		TNT1 A 0 A_SetPitch(+0.4 + pitch)
		TNT1 A 0 A_FireCustomMissile("9mmCaseSpawn",5,0,4,-7)
		TNT1 A 0 A_ReFire
		SMGA 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)
		SMGW 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)
		SMGW CBA 1
		Goto Ready2
	
// --------------------------------------------------------------------------
//
//	Unload and reload
//
// --------------------------------------------------------------------------
		
	Reload:
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_JumpIfInventory("BDSMGAmmo",40,"Ready2") //Check if weapon is full already.
		TNT1 A 0 A_JumpIfInventory("Magazine9mm",1,1) //Check if we have spare ammo.
		Goto Ready2
		TNT1 A 0 A_JumpIfInventory("TurboReload",1,"ReloadLoop")
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,2) //Check if zoomed
		TNT1 A 0 A_Jump(256, 7)
		SMGW 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_GiveInventory("Pumping", 1)
		TNT1 A 0 A_JumpIfInventory("BDSMGAmmo",1,3)
		TNT1 A 0 A_JumpIfInventory("HasUnloaded_SMG",1,2)
		TNT1 A 0 A_FireCustomMissile("EmptyMag9mm",-5,0,8,-4)
		TNT1 A 0 A_PlaySound("reload")
		SMGR ABCDEEEFGHIJKKKKKKKKKKKKK 1
		SMGR LMNOPQEEEEDCBA 1
			
	ReloadLoop:
		TNT1 A 0 A_JumpIfInventory("BDSMGAmmo",40,"ReloadDone")
		TNT1 A 0 A_JumpIfInventory("Magazine9mm",1,1)
		Goto ReloadDone
		TNT1 A 0 A_Giveinventory("BDSMGAmmo",1)
		TNT1 A 0 A_Takeinventory("Magazine9mm",1)
		Loop

	ReloadDone:
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_Takeinventory("HasUnloaded_SMG",1)
		TNT1 A 0 A_Refire
		Goto Ready2

	Unload:
		SMGG A 1
		TNT1 A 0 A_Takeinventory("ADSmode",1)
		TNT1 A 0 A_Takeinventory("Unloading",1)
		TNT1 A 0 A_JumpIfInventory("BDSMGAmmo",1,1)
		Goto Ready2
		TNT1 A 0 A_Takeinventory("Zoomed",1)
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_GiveInventory("Pumping", 1)
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_PlaySound("reload")
		TNT1 A 0 A_Giveinventory("HasUnloaded_SMG",1)
		SMGR ABCDEEEFGHIJKKKKKKKKKK 1
		
	RemoveBullets:
		TNT1 A 0 A_JumpIfInventory("BDSMGAmmo",1,1)
		Goto Ready2
		TNT1 A 0 A_Takeinventory("BDSMGAmmo",1)
		TNT1 A 0 A_Takeinventory("BDDualSMGAmmo",1)
		TNT1 A 0 A_Giveinventory("Magazine9mm",1)
		Goto RemoveBullets
	
// --------------------------------------------------------------------------
//
//	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_SMGs",2,2)
		TNT1 A 0 A_Print("You must have two submachine guns to dual wield.")
		Goto Ready2
		SMGS ABCDEF 1
		TNT1 A 5
		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")
		Goto Ready2
	
	PuristGun:
		TNT1 A 0 A_TakeInventory("U_SMG", 1)
		Goto Deselect
	
// --------------------------------------------------------------------------
//
//	End Stuff
//
// --------------------------------------------------------------------------

	TauntFlash:
		SMGS ABCDEF 1
		TNT1 A 31
		SMGS FEDCBA 1
		SMGG A 1
		Stop

	KickFlash:
		SMGK ABCDE 1
		SMGK F 7
		SMGK EDCBA 1
		Stop

	AirKickFlash:
		SMGK ABCDE 1
		SMGK F 9
		SMGK EDCBA 1
		Stop

	SlideKickStartFlash:
		SMGK ABCDE 1
		SMGK F 16
		Stop

	SlideKickEndFlash:
		SMGK FEDCB 2
		SMGK A 1
		Stop

	GrenadeFlash:
		SMGS ABCDEF 1
		Stop
	}
}

ACTOR HasUnloaded_SMG : Inventory { Inventory.MaxAmount 1 }