const int RiotGun_Reload = 985;

Actor RiotGun : Weapon
{
   +NOALERT
   Weapon.AmmoUse 1
   Weapon.AmmoGive1 8
   Weapon.SelectionOrder 400
   Weapon.AmmoType "RiotGunShell" 
   Inventory.PickupMessage "RiotGun"
   Inventory.PickupSound "SWITEMUP"
   Obituary "%o was mowed down by %k's RiotGun..."
   States
   {
   Ready:
     RIOT A 0 A_CheckReload
     RIOT B 0 A_JumpIfInventory("RiotGunReload", 4, "Reload")
     RIOT A 0 A_JumpIfInventory("RiotGunFireMode", 1, "Ready2")
     RIOT A 1 A_WeaponReady
     Loop
   Ready2:
     RIOT G 1 A_WeaponReady
	 Loop
   Deselect: 
     RIOT A 0 A_Lower
     RIOT A 1 A_Lower
     Loop
   Select:
     RIOT A 1 A_playsound ("SHOTG1R")
	 RIOT A 0 A_Raise
     RIOT A 1 A_Raise
	 goto select+1
   Fire:
    RIOT B 0 A_JumpIfInventory("RiotGunFireMode", 1, "Fire2")
    RIOT B 0 A_CheckReload
    RIOT B 0 A_playsound("SHOTGUN", 1)
	RIOT B 0 A_AlertMonsters
    RIOT B 1 Bright A_FireBullets(4, 4, 9, 7, "SWPuffOne")
	TNT1 A 0 A_GiveInventory("LoWangPunchTaunt", 1)
	RIOT C 1 Bright ACS_Execute(987,0,5,0)  
	RIOT D 1 ACS_Execute(987,0,10,0)
	RIOT D 0 A_SpawnItemEx("RiotGunCasingSpawner",cos(-pitch)*30-8,11,25+sin(-pitch)*30)
	RIOT D 1 offset(7, 39)ACS_Execute(987,0,15,0) 
	RIOT D 1 offset(15,47)ACS_Execute(987,0,20,0)
	RIOT D 1 offset(7, 39)ACS_Execute(987,0,25,0)
	RIOT D 1 offset(-1, 32) 
	
	RIOT D 1 offset(-1, 32)ACS_Execute(987,0,-25,0) 
	RIOT D 1 offset(-1, 32)ACS_Execute(987,0,-20,0)
	RIOT D 1 offset(-1, 32)ACS_Execute(987,0,-15,0) 
	RIOT D 1 offset(-1, 32)ACS_Execute(987,0,-10,0) 
	RIOT D 1 offset(-1, 32)ACS_Execute(987,0,-5,0)
	
	RIOT E 1 offset(-1, 32)
	RIOT F 5 offset(-1, 32)
	RIOT A 5 offset(-1, 32)
	RIOT B 0 bright A_JumpIf(ACS_ExecuteWithResult(RiotGun_Reload,0,0,0) == 1, "Reload")
	RIOT A 0 A_CheckReload
	Goto Ready
	
	
   Fire2:
    RIOT H 0 A_CheckReload
    RIOT H 0 A_playsound("SHOTGUN", 1)
	RIOT H 0 A_AlertMonsters
	RIOT H 2 Bright A_FireBullets (8, 8, 6, 7, "SWPuffOne")
	TNT1 A 0 A_GiveInventory("LoWangPunchTaunt", 1)
	RIOT D 0 A_SpawnItemEx("RiotGunCasingSpawner",cos(-pitch)*30-8,11,25+sin(-pitch)*30)
	RIOT G 1 offset(6, 39) ACS_Execute(987,0,15,0)
	RIOT G 1 offset(0, 32) ACS_Execute(987,0,20,0)
	RIOT G 1 offset(0, 32) ACS_Execute(987,0,-35,0)
	RIOT B 0  A_JumpIf(ACS_ExecuteWithResult(RiotGun_Reload,0,0,0) == 1, "Reload2")
	
	
	
	RIOT H 0 A_CheckReload
	RIOT H 0 A_playsound("SHOTGUN", 1)
	RIOT H 0 A_AlertMonsters
	RIOT H 2 Bright A_FireBullets (8, 8, 6, 7, "SWPuffOne")
	TNT1 A 0 A_GiveInventory("LoWangPunchTaunt", 1)
	RIOT D 0 A_SpawnItemEx("RiotGunCasingSpawner",cos(-pitch)*30-8,11,25+sin(-pitch)*30)
	RIOT G 1 offset(6, 39) ACS_Execute(987,0,15,0)
	RIOT G 1 offset(0, 32) ACS_Execute(987,0,20,0)
	RIOT G 1 offset(0, 32) ACS_Execute(987,0,-35,0)
	RIOT B 0 A_JumpIf(ACS_ExecuteWithResult(RiotGun_Reload,0,0,0) == 1, "Reload2")
	
	
	RIOT H 0 A_CheckReload
	RIOT H 0 A_playsound("SHOTGUN", 1)
	RIOT H 0 A_AlertMonsters
	RIOT H 2 Bright A_FireBullets (8, 8, 6, 7, "SWPuffOne")
	TNT1 A 0 A_GiveInventory("LoWangPunchTaunt", 1)
	RIOT D 0 A_SpawnItemEx("RiotGunCasingSpawner",cos(-pitch)*30-8,11,25+sin(-pitch)*30)
	RIOT G 1 offset(6, 39) ACS_Execute(987,0,15,0)
	RIOT G 1 offset(0, 32) ACS_Execute(987,0,20,0)
	RIOT G 1 offset(0, 32) ACS_Execute(987,0,-35,0)
	RIOT B 0 A_JumpIf(ACS_ExecuteWithResult(RiotGun_Reload,0,0,0) == 1, "Reload2")
	
	
	RIOT H 0 A_CheckReload
	RIOT H 0 A_playsound("SHOTGUN", 1)
	RIOT H 0 A_AlertMonsters
	RIOT H 2 Bright A_FireBullets (8, 8, 6, 7, "SWPuffOne")
	TNT1 A 0 A_GiveInventory("LoWangPunchTaunt", 1)
	RIOT D 0 A_SpawnItemEx("RiotGunCasingSpawner",cos(-pitch)*30-8,11,25+sin(-pitch)*30)
	RIOT G 1 offset(6, 39) ACS_Execute(987,0,15,0)
	RIOT G 1 offset(0, 32) ACS_Execute(987,0,20,0)
	RIOT G 1 offset(0, 32) ACS_Execute(987,0,-35,0)
	RIOT B 0 A_JumpIf(ACS_ExecuteWithResult(RiotGun_Reload,0,0,0) == 1, "Reload2")
	Goto Ready
    
	Reload:
		RIOT A 0 A_CheckReload
		RIOT A 0 A_playsound("BOLT1R")
		RIOT A 1 offset(0, 50)
		RIOT A 1 offset(0, 59)
		RIOT A 1 offset(0, 68)
		RIOT A 16 offset (0, 71)
		RIOT A 1 offset(0, 62)
		RIOT A 1 offset(0, 44)
		RIOT A 0 A_playsound("SHOTG1R")
		RIOT A 1 offset(0, 35)
		RIOT A 1 offset(0, 32)
        Goto Ready
	Reload2:
		RIOT G 0 A_CheckReload
		RIOT G 0 A_playsound("BOLT1R")
		RIOT G 1 offset(1, 50)
		RIOT G 1 offset(1, 59)
		RIOT G 1 offset(1, 68)
		RIOT G 16 offset(1, 71)
		RIOT G 1 offset(1, 62)
		RIOT G 1 offset(1, 44)
		RIOT G 0 A_playsound("SHOTG1R")
		RIOT G 1 offset(1, 35)
		RIOT G 1 offset(1, 32)
        Goto Ready
	AltFire:
	   RIOT G 0 A_JumpIfInventory("RiotGunFireMode", 1, "AltFire2")
	   RIOT G 2 A_WeaponReady
	   RIOT G 0 A_GiveInventory("RiotGunFireMode", 1)
	   RIOT G 0 A_playsound("SHOTG1R")
	   Goto Ready
	AltFire2:
	   RIOT A 2 A_WeaponReady
	   RIOT A 0 A_TakeInventory("RiotGunFireMode", 1)
	   RIOT A 0 A_playsound("SHOTG1R")
	   Goto Ready
    Spawn:
     RIOT I -1
     Stop
   }
}

actor RiotGunReload : inventory 
{
   Inventory.MaxAmount 4
   +INVENTORY.UNDROPPABLE
   -INVENTORY.INVBAR
   States
   {
   Spawn:
      TNT1 A 1
      Stop
   }
   
}

actor RiotGunFireMode : inventory 
{
   Inventory.MaxAmount 1
   +INVENTORY.UNDROPPABLE
   -INVENTORY.INVBAR
   States
   {
   Spawn:
      TNT1 A 1
      Stop
   }
   
}

ACTOR RiotGunCasingSpawner
{
+NOCLIP
+MISSILE
+NOBLOCKMAP
+NOGRAVITY
+DROPOFF
+NOTELEPORT
+CLIENTSIDEONLY
States
    {
    Spawn:
      TNT1 A 0
      TNT1 A 0 A_CustomMissile("RiotGunCasing",0,0,random(0,360),2,random(100,80))
	TNT1 A 1
	Stop
    }
}


ACTOR RiotGunCasing
{
	Height 2
	Radius 2
	Speed 4
	Scale 0.15	
	BounceFactor 0.4
	Gravity 0.23
	Projectile
	+DOOMBOUNCE
	+DROPOFF
	+NOTELEPORT
	-NOGRAVITY
	+CLIENTSIDEONLY
	Seesound "SHELL1"
	States
	{
	Spawn:
	   MGCA A 0 
	   MGCA A 0 A_Jump(256,1,2,3,4,5,6,7)
	   MGCA ABCDEFGH 2 
	   Goto Spawn+2
	Death:
	   MGCA A 0 A_Playsound("SHELL1")
	   MGCA A 0 A_Jump(256, "Death1", "Death2", "Death3", "Death4","Death5","Death6","Death7","Death8")
	   stop
	   Death1:
	   MGCA A 600
	   Stop
	   Death2:
	   MGCA B 600
	   Stop
	   Death3:
	   MGCA C 600
	   Stop
	   Death4:
	   MGCA D 600
	   Stop
	   Death5:
	   MGCA E 600
	   Stop
	   Death6:
	   MGCA F 600
	   Stop
	   Death7:
	   MGCA G 600
	   Stop
	   Death8:
	   MGCA H 600
	   Stop
	}
} 