// --------------------------------------------------------------------------
//
//	AutoShotgun
//
// --------------------------------------------------------------------------

ACTOR AutoShotgun : BaseWeapon
{
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive1 8
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "2Shell"
	Weapon.AmmoType2 "M1014Ammo"
	Weapon.SelectionOrder 300
	-WEAPON.CHEATNOTWEAPON
	Inventory.PickupSound "M1014RE"
	Inventory.Pickupmessage "You got the M1014 Automatic Shotgun!"
	Obituary "%o got shot into pieces by %k's M1014"
    AttackSound "None"
	Tag "Automatic Shotgun"
	Scale 0.9
	States
	{
	Spawn:
		M4SH A -1
		Stop

	Ready:
		TNT1 A 0 A_JumpIfInventory("GoFatality", 1, "Steady")
		TNT1 A 0 A_PlaySound("M1014RE", 5)
	Ready1:
		M4SR ABCD 1
		Goto Ready2

	Ready2:
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,"ReadyZoom")
        TNT1 A 0 A_JumpIfInventory("Kicking",1,"DoKick")
        TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
        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("TossGrenade",1,"TossGrenade")
		//TNT1 A 0 A_JumpIfInventory("Unloading",1,"Unload")
		M4SR E 1 A_WeaponReady
		Loop

	ReadyZoom:
		TNT1 A 0 A_JumpIfInventory("Kicking",1,"AltFire")
		TNT1 A 0 A_JumpIfInventory("Taunting",1,"AltFire")
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
		TNT1 A 0 A_JumpIfInventory("Salute1",1,"AltFire")
		TNT1 A 0 A_JumpIfInventory("Salute2",1,"AltFire")
		TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"AltFire")
		//TNT1 A 0 A_JumpIfInventory("Unloading",1,"AltFire")
		M4SZ E 1 A_WeaponReady
		Loop
	
	Select:
		TNT1 A 0 A_JumpIfInventory("IsPlayingAsPurist", 1, "PuristGun")
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1003)==0, "PuristGun")
		TNT1 A 0 A_Takeinventory("FistsSelected",1)
		TNT1 A 0 A_Takeinventory("SawSelected",1)
		TNT1 A 0 A_Giveinventory("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_PlaySound("weapons/changing")
		TNT1 A 0 A_Takeinventory("Zoomed",1)
		TNT1 A 0 A_Takeinventory("HasUnloaded",1)
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_Takeinventory("ADSmode",1)
		M4SR DCBA 1
		TNT1 A 0 A_Takeinventory("WeapSpecial",1)
		TNT1 A 0 A_Takeinventory("TossGrenade",1)
		TNT1 A 0 A_Takeinventory("Unloading",1)
		TNT1 A 1
		TNT1 A 0 A_Lower
		Wait

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

    Fire:
		TNT1 A 0 A_JumpIfInventory("ReloadingAutoShotty",2,"ReloadDone2")
		TNT1 A 0 A_JumpIfInventory("ReloadingAutoShotty",1,"ReloadDone1")
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,"Fire2")
		TNT1 A 0 A_JumpIfInventory("M1014Ammo",1,1)
		Goto NoAmmo
		TNT1 A 0 A_FireCustomMissile("SmokeSpawner",0,0,0,5)
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_PlaySound("M1014FI", 1)
		TNT1 A 0 A_FireCustomMissile("YellowFlareSpawn",0,0,0,0)
		TNT1 AAA 0 A_FireCustomMissile("Tracer", random(-5,5), 0, -1, -12, 0, random(-5,5))
		TNT1 A 0 A_FireCustomMissile("ShakeYourAss", 0, 0, 0, 0)
		TNT1 A 0 A_Takeinventory("M1014Ammo",1)		
		M4SF A 1 BRIGHT A_FireBullets (3.5, 3.5, 6, 15, "ShotgunPuff")
		TNT1 A 0 A_SetPitch(-7.0 + pitch)
		M4SF B 1 BRIGHT A_SetPitch(2.2 + pitch)
		M4SF CD 1 A_SetPitch(2.2 + pitch)
		TNT1 A 0 A_FireCustomMissile("AutoShotCaseSpawn",5,0,6,-14)
		M4SR E 5
		M4SR E 1 A_ReFire
		Goto Ready2

	Fire2:
		TNT1 A 0 A_JumpIfInventory("M1014Ammo",1,1)
		Goto NoAmmo
		TNT1 AA 0 A_FireCustomMissile("SmokeSpawner",0,0,0,5)
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_PlaySound("M1014FI", 1)
		TNT1 A 0 A_FireCustomMissile("YellowFlareSpawn",0,0,0,0)
		TNT1 AAA 0 A_FireCustomMissile("Tracer", random(-5,5), 0, -1, -12, 0, random(-5,5))
		TNT1 A 0 A_FireCustomMissile("ShakeYourAss", 0, 0, 0, 0)
		TNT1 A 0 A_Takeinventory("M1014Ammo",1)
		M4SF E 1 BRIGHT A_FireBullets (2.5, 2.5, 6, 15, "ShotgunPuff")
		TNT1 A 0 A_SetPitch(-7.0 + pitch)
		M4SF F 1 BRIGHT A_SetPitch(2.3 + pitch)
		M4SF GH 1 A_SetPitch(2.3 + pitch)
		TNT1 A 0 A_FireCustomMissile("AutoShotCaseSpawn",5,0,4,-4)
		M4SZ E 5
		M4SZ E 1 A_ReFire
		Goto ReadyZoom

	AltFire:
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,8)
		TNT1 A 0 A_Giveinventory("Zoomed",1)
		TNT1 A 0 A_ZoomFactor(1.5)
		TNT1 A 0 A_Giveinventory("ADSmode",1)
		M4SZ ABCD 1
		Goto ReadyZoom
		TNT1 A 0 A_Takeinventory("Zoomed",1)
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_Takeinventory("ADSmode",1)
		M4SZ DCBA 1
		Goto Ready2

    NoAmmo:
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,3)
        M4SR E 4 A_PlaySound("weapons/empty", 2)
		TNT1 A 0 A_JumpIfInventory("2Shell", 1, "Reload")
        Goto Ready2
		M4SZ E 4 A_PlaySound("weapons/empty", 2)
		TNT1 A 0 A_JumpIfInventory("2Shell", 1, "Reload")
        Goto Ready2

    Reload:
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_JumpIfInventory("2Shell",1,1) //Do we have any spare ammo?
		Goto Ready2
		TNT1 A 0 A_JumpIfInventory("M1014Ammo",8,"Ready2") //Is weapon full?
        TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_Takeinventory("Zoomed",1)
		TNT1 A 0 A_Takeinventory("ADSmode",1)
		TNT1 A 0 A_GiveInventory("Pumping", 1)
		M4SR E 1
		M4SG CDEFGH 1
		TNT1 A 0 A_GiveInventory("ReloadingAutoShotty", 1)
		TNT1 A 0 A_JumpIfInventory("M1014Ammo",1,2)
		TNT1 A 0 A_GiveInventory("ReloadingAutoShotty", 1)
		Goto ReloadLoop2
		
	ReloadLoop1: //Weapon contains ammo when starting reload
        TNT1 A 0 A_JumpIfInventory("2Shell",1,1)
        Goto ReloadDone1
		TNT1 A 0 A_JumpIfInventory("M1014Ammo",8,"ReloadDone1")
		
		TNT1 A 0 A_GiveInventory("Pumping", 1)
        M4HR ABC 1
        M4HR D 1 A_PlaySound("insertshell")
		TNT1 A 0 A_Takeinventory("2Shell",1)
		TNT1 A 0 A_Giveinventory("M1014Ammo",1)
        M4HR EFGHI 1
        M4HR A 1 A_Refire
		TNT1 A 0 A_JumpIfInventory("Kicking",1,"ReloadKick")
        Loop

	ReloadLoop2: //Weapon was empty when starting reload
        TNT1 A 0 A_JumpIfInventory("2Shell",2,1)
        Goto ReloadDone2
		TNT1 A 0 A_JumpIfInventory("M1014Ammo",7,"ReloadDone2")
		
		TNT1 A 0 A_GiveInventory("Pumping", 1)
        M4HR ABC 1
        M4HR D 1 A_PlaySound("insertshell")
		TNT1 A 0 A_Takeinventory("2Shell",1)
		TNT1 A 0 A_Giveinventory("M1014Ammo",1)
        M4HR EFGHI 1
        M4HR A 1 A_Refire
		TNT1 A 0 A_JumpIfInventory("Kicking",1,"ReloadKick")
        Loop

	ReloadDone1:
		M4SG HGFEDC 1
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_TakeInventory("ReloadingAutoShotty", 2)
		TNT1 A 0 A_Refire
		Goto Ready2

	ReloadDone2:	
		TNT1 A 0 A_GiveInventory("Pumping", 1)
		M4ZR ABCD 2
		TNT1 A 0 A_PlaySound("M1014RE", 5)
		TNT1 A 0 A_Takeinventory("2Shell",1)
		TNT1 A 0 A_Giveinventory("M1014Ammo",1)
		M4ZR EEFA 2
		M4SG HGFEDC 1
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_TakeInventory("ReloadingAutoShotty", 2)
		TNT1 A 0 A_Refire
		Goto Ready2

	ReloadKick:
		TNT1 A 0 A_JumpIfInventory("ReloadingAutoShotty",2,1)
		Goto ReloadKickAlt
		TNT1 A 0 A_GiveInventory("Pumping", 1)
		M4ZR ABCD 1
		TNT1 A 0 A_PlaySound("M1014RE", 5)
		TNT1 A 0 A_Takeinventory("2Shell",1)
		TNT1 A 0 A_Giveinventory("M1014Ammo",1)
		M4ZR EEFA 1
	ReloadKickAlt:
		M4HR A 2
		TNT1 A 0 A_GunFlash("ReloadKickFlash")
		TNT1 A 0 A_PlaySound("KICK")
		TNT1 A 0 SetPlayerProperty(0,1,0)
		KICK BCD 1
		TNT1 A 0 A_Jumpifinventory("PowerStrength",1,3)
		TNT1 A 0 A_FireCustomMissile("KickAttack", 0, 0, 0, -7)
		TNT1 A 0 A_Jump(256,2)
		TNT1 A 0 A_FireCustomMissile("SuperKickAttack", 0, 0, 0, -7)
		KICK H 5
		KICK IGFEDCBA 1 
		TNT1 A 0 SetPlayerProperty(0,0,0)
		TNT1 A 0 A_Takeinventory("Kicking",1)
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_TakeInventory("ReloadingAutoShotty", 2)
		TNT1 A 0 A_JumpIfInventory("GoFatality", 1, "Steady")
		Goto Ready2

	ReloadKickFlash:
		M4SG HG 2
		M4SG F 9
		M4SG EDC 1
		Stop

	KickFlash:
		M4SG CDE 1
		M4SG F 10
		M4SG EDC 1
		Stop

	AirKickFlash:
		M4SG CDEF 1
		M4SG G 10
		M4SG FEDC 1
		Stop

	TauntFlash:
		M4SG CDE 1
		M4SG F 37
		M4SG EDC 1
		Stop

	GrenadeFlash:
		M4SR DCBA 1	
		Stop
	}
}

ACTOR M1014Ammo: Ammo
{
	+INVENTORY.IGNORESKILL
	Inventory.Amount 0
	Inventory.MaxAmount 8
	Ammo.BackpackAmount 0
	Ammo.BackpackMaxAmount 8
   	Inventory.Icon "M4SHA0"
}

Actor ReloadingAutoShotty : Inventory
{
inventory.maxamount 2
}