ACTOR SplayerPrimary : Ammo
{
  Inventory.Amount 1
  Inventory.MaxAmount 2
  Ammo.BackpackAmount 0
  Ammo.BackpackMaxAmount 2
  Inventory.Icon "SHELA0"
  +INVENTORY.IGNORESKILL
}

ACTOR SplayerSecondary : Ammo
{
  Inventory.PickupMessage "You picked up a drum of PPSH-41 ammunition." // "Picked up a clip."
  Inventory.PickupSound "bullpup/magin"
  Inventory.Amount 1
  Inventory.MaxAmount 80
  Ammo.BackpackAmount 20
  Ammo.BackpackMaxAmount 80
  Inventory.Icon "SHELA0"
  +INVENTORY.IGNORESKILL
  States
  {
  Spawn:
    CLIP A -1
    Stop
  }
}

ACTOR SplayerMuzzleFX
{
	+NOBLOCKMAP
	+CLIENTSIDEONLY
	Speed 40
	States
	{
	Spawn:
	TNT1 A 1
	TNT1 A 0 A_Stop
	TNT1 AAAA 0 A_SpawnItemEx("QExplosionSmoke",0,random(-2,2),random(-2,2),0,random(-3,3),random(-3,3))
	TNT1 AAAAAA 0 A_SpawnItemEx("CasingSpark",0,random(-3,3),random(-3,3),0,random(-8,8),random(-8,8))
	Stop
	}
}

ACTOR "Splayer SSG" : Weapon
{
  +WEAPON.NOAUTOAIM
  Weapon.SelectionOrder 1300
  Weapon.AmmoUse 0
  Weapon.AmmoUse2 0
  Weapon.AmmoGive2 8
  Weapon.AmmoType "SplayerPrimary"
  Weapon.AmmoType2 "SplayerSecondary"
  Inventory.PickupMessage "You picked up the Splayer SSG."
  Obituary "%o was eviscerated by %k's Splayer."
  Tag "Splayer SSG"
  Weapon.BobStyle Smooth
  Weapon.BobSpeed 2.5
  Weapon.BobRangeX 0.5
  Weapon.BobRangeY 0.3
  +WEAPON.NOAUTOFIRE
  States
  {
  Ready:
	SLSG Z 0 A_JumpIfInventory("IsReloading",1,"ToReload")
	SLSG Z 0 A_JumpIfInventory("PendingQuickness",1,"ToQuick")
	SLSG Z 0 A_JumpIfInventory("DoBlocking",1,"QuickMelee")
    SLSG Z 1 A_WeaponReady
    Loop
  ToQuick:
	TNT1 A 0 ACS_NamedExecute("ProcessQuick",0,0,0,0)
	GoTo Ready+2
  QuickMelee:
	SLSD DCBA 1
	TNT1 AAA 3
	MCFI E 1
	MCFI E 0 A_PlaySoundEx("machete/fire","Weapon")
	MCFI FG 1
    MCFI H 0 A_CustomPunch(2*random(1, 10), TRUE, 0, "ZTMeleePuff")
	MCFI HIJ 1
	MCFI K 2
	TNT1 AAA 3
	SLSD ABCD 1
	TNT1 A 0 A_TakeInventory("DoBlocking",1)
	Goto Ready
	
  Deselect:
	SLSD DCBA 1
	TNT1 AAAAAAAAAA 0 A_Lower
    TNT1 A 1 A_Lower
    Goto Deselect+4
  Select:
	TNT1 A 0 A_Raise
	TNT1 A 1 A_WeaponReady
    Goto SelectAnim
  SelectAnim:
	PPSS A 0 A_PlaySoundEx("splayer/select","SoundSlot6")
	SLSD ABCD 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	Goto Ready
	
  Dryfire:
	TNT1 A 0 A_PlaySoundEx("orderpistol/dryfire","SoundSlot6")
	Goto Ready
	
  // Single shell
  Fire:
	PPFI A 0 A_JumpIfInventory("SplayerPrimary",1,1)
	Goto DryFire
	PPFI A 0 A_TakeInventory("SplayerPrimary",1)
	Goto FireFX
	
	// Don't gib if we're using one barrel
	// PPFI A 0 A_FireBullets (0, 0, 3, 17, "BP_TorsoGib",0,90)
  FireFX:
	PPFI A 0 A_FireBullets (8.2, 5.1, 10, 4, "BP_Shotgun")
	PPFI A 0 A_PlaySound("splayer/fire", CHAN_WEAPON)
	PPFI A 0 A_FireCustomMissile("ShakeYourAssDouble",0,0)
	PPFI A 0 A_FireCustomMissile("SplayerMuzzleFX",0,0,8)
	TNT1 A 0 A_SpawnItemEx("ShooterLight",0,0,0)
	PPFI A 0 A_Recoil(1)
	PPFI A 0 A_SetPitch(pitch-2.5)
	PPFI A 0 A_JumpIfInventory("SplayerPrimary",1,"FireL")
	Goto FireR
  FireL:
	SLSG X 1 bright A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	Goto PostFire
  FireR:
	SLSG Y 1 bright A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	Goto PostFire
  PostFire:
	SLSG F 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSG G 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSG A 0 A_JumpIfInventory("SplayerPrimary",1,1)
	Goto ReloadFromFire
	TNT1 A 0
    Goto Ready
	
  // Double shell
  AltFire:
	PPFI A 0 A_JumpIfInventory("SplayerPrimary",2,1)
	Goto Fire
	PPFI A 0 A_TakeInventory("SplayerPrimary",2)
	
	// Gib if we shoot up close
	PPFI A 0 A_FireBullets (0, 0, 3, 17, "BP_TorsoGib",0,90)
	
	PPFI A 0 A_FireBullets (8.2, 5.1, 20, 4, "BP_Shotgun")
	PPFI A 0 A_PlaySound("splayer/firedual", CHAN_WEAPON)
	PPFI A 0 A_FireCustomMissile("ShakeYourAssQuad",0,0)
	PPFI A 0 A_FireCustomMissile("SplayerMuzzleFX",0,0,8)
	TNT1 A 0 A_SpawnItemEx("ShooterLight",0,0,0)
	PPFI A 0 A_Recoil(8)
	PPFI A 0 A_SetPitch(pitch-12.5)
	SLSG A 1 bright A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSG A 0 A_SetPitch(Pitch+1.0)
	SLSG B 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSG A 0 A_SetPitch(Pitch+0.5)
	SLSG C 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSG C 0 A_SetPitch(Pitch+0.5)
	SLSG C 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSG D 3 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSG E 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSG FG 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	Goto ReloadFromFire
	
  // Out of ammo, try to automatically reload
  ReloadFromFire:
	TNT1 A 0 A_JumpIfInventory("SplayerSecondary",1,"ToReload")
	Goto Ready

 // Actually try to reload
 ToReload:
	SLSR A 0 A_TakeInventory("IsReloading",1)
	TNT1 A 0 A_JumpIfInventory("SplayerPrimary",2,"Open2")
	TNT1 A 0 A_JumpIfInventory("SplayerSecondary",1,1)
	Goto Ready
	SLSR A 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSR A 0 A_PlaySoundEx("splayer/cockback","SoundSlot5")
	// Pick an open anim
	TNT1 A 0 A_JumpIfInventory("SplayerPrimary",2,"Open2")
	TNT1 A 0 A_JumpIfInventory("SplayerPrimary",1,"Open1")
	Goto Open0
 
  // OPEN: Two shells (Not even possible, maybe in gun check)
  Open2:
	SLSR A 0 A_PlaySoundEx("splayer/cockback","SoundSlot5")
	SLS1 ABCDEF 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	Goto Close2
  // OPEN: One shell
  Open1:
	SLS2 ABCDEF 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	Goto InsertTwo
  // OPEN: Zero shells
  Open0:
	SLSR BCDEFG 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	Goto InsertOne
	
  // INSERT: First shell (left)
  InsertOne:
	SLSR A 0 A_JumpIfInventory("SplayerSecondary",1,1)
	Goto Close0
	SLSR H 6 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSR IJK 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSR K 0 A_PlaySoundEx("splayer/insert","SoundSlot5")
	SLSR K 0 A_TakeInventory("SplayerSecondary",1)
	SLSR K 0 A_GiveInventory("SplayerPrimary",1)
	SLSR L 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSR M 3 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSR OPQ 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	Goto InsertTwo

  // INSERT: Second shell (right)
  InsertTwo:
    SLSR A 0 A_JumpIfInventory("SplayerSecondary",1,1)
	Goto Close1
    SLSR R 6 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSR STU 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSR K 0 A_PlaySoundEx("splayer/insert","SoundSlot5")
	SLSR K 0 A_TakeInventory("SplayerSecondary",1)
	SLSR K 0 A_GiveInventory("SplayerPrimary",1)
	SLSR V 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSR W 3 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSR XYZ 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSS A 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	Goto Close2
	
  // CLOSE: Two shells
  Close2:
	SLSS B 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSS C 0 A_PlaySoundEx("splayer/cockforward","SoundSlot5")
	SLSS B 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSS C 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	Goto PostClose
	
  // CLOSE: One shells
  Close1:
	SLSR R 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLS1 Z 0 A_PlaySoundEx("splayer/cockforward","SoundSlot5")
	SLSR R 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLS1 Z 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	Goto PostClose
	
  // CLOSE: No shells
  Close0:
	SLSR H 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLS2 Z 0 A_PlaySoundEx("splayer/cockforward","SoundSlot5")
	SLSR H 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLS2 Z 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	Goto PostClose

  // Finish closing
  PostClose:
	SLSS D 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSS E 3 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSS FG 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	SLSR A 0 A_TakeInventory("IsReloading",1)
	Goto Ready
	
  Spawn:
    SPLY P -1
    Stop
  }
}