//This goes in frenzy_weapons. wad and it replaces the DW9 lump
ACTOR Grenade_Flinger
{
	Radius				16
	Height				8
	
	Speed				40
	Damage				80
	Gravity				1.0
	Mass				100
	bouncefactor                    0.8
	
	Obituary			"%0 was blowen to bits by %k's Flinger."

	DamageType			MarineFire2
	+NOBLOCKMAP
	+DROPOFF
	+MISSILE
	+ACTIVATEIMPACT
	+ACTIVATEPCROSS
	+DOOMBOUNCE
	+FORCERADIUSDMG
	+NODAMAGETHRUST
	+MTHRUSPECIES
	bouncecount 16
	
	SeeSound "w9/fire1"
	DeathSound "Flinger/Grenade/Booms"
	
	States
	{
		Spawn:
			GRNS ABA 3 bright
			GRNS B 3 bright A_PlaySound("w9/fire2")
			goto Spawn
		Death:
			TNT1 A 0 A_ChangeFlag("NoGravity", true)
			MISL B 8 bright A_Explode(75,256,0,0,16)
			MISL C 6 bright
			MISL D 4 bright
			stop
	}
}

Actor Grenade_Flinger_Contact : Grenade_Flinger
{
	-DOOMBOUNCE
	bouncefactor                    0.0
}

ACTOR Grenade_Expander
{
	Radius				16
	Height				8
	
	Speed				40
	Damage				80
	Gravity				1.0
	Mass				100
	DamageType			MarineFire2
	
	+DROPOFF
	+MISSILE
	+ACTIVATEIMPACT
	+ACTIVATEPCROSS
	+DOOMBOUNCE
	+MTHRUSPECIES
	bouncecount 16
	
	SeeSound "w9/fire1"
	DeathSound "Flinger/Grenade/Booms"
	
	States
	{
		Spawn:
			GRNS ABA 3 bright
			GRNS B 3 bright A_PlaySound("w9/fire2")
			goto Spawn
		Death:
			TNT1 A 0 A_ChangeFlag("NoGravity", true)
			TNT1 A 0 bright A_PlaySound("weapons/rocklx")
			TNT1 A 0 bright A_SpawnItemEx("Grenade_Expander_Spread",0,0,0,0,0,0,0,SXF_TransferPointers)
			TNT1 A 0 A_Explode(75,256,0,0,16)
			stop
	}
}

ACTOR Grenade_Expander_Alt : Grenade_Expander {
	Speed				60
	var int user_countme;
	states{
		Spawn:
			TNT1 A 0 A_JumpIf(user_countme >= 1, "Death")
			GRNS ABA 3 bright
			GRNS B 3 bright A_PlaySound("w9/fire2")
			TNT1 A 0 A_SetUserVar("user_countme", user_countme+1)
			loop
	}
}

Actor Grenade_Expander_Spread {
	radius 2
	height 4
	+NOINTERACTION
	var int user_drops;
	States
	{
		Spawn:// 16 mini grenades.
			MISL B 6 bright // 4 of them are constant and they will always fall in 1 place.
			TNT1 A 0 bright A_SpawnItemEx("Grenade_Expander_MiniGrenade", 0, 0, 10, 	2, 2,	5, 0, SXF_TransferPointers)
			TNT1 A 0 bright A_SpawnItemEx("Grenade_Expander_MiniGrenade", 0, 0, 10, 	2, -2, 	5, 0, SXF_TransferPointers)
			TNT1 A 0 bright A_SpawnItemEx("Grenade_Expander_MiniGrenade", 0, 0, 10, 	-2, 2,	5, 0, SXF_TransferPointers)
			TNT1 A 0 bright A_SpawnItemEx("Grenade_Expander_MiniGrenade", 0, 0, 10, 	-2, -2,	5, 0, SXF_TransferPointers)
			// The rest of them, drop them randomly on the floor
			TNT1 A 0 A_SetUserVar("user_drops", 0)
			goto Spawn.LetItRain
		Spawn.LetItRain:
			TNT1 A 0 A_JumpIf(user_drops >= 4, "Spawn.ImDone")
			MISL C 1 bright
			TNT1 AAA 0 bright A_SpawnItemEx("Grenade_Expander_MiniGrenade", 0, 0, 10, random(-5,5), random(-5,5),random(3, 10), 0, SXF_TransferPointers)
			TNT1 A 0 A_SetUserVar("user_drops", user_drops+1)
			loop
		Spawn.ImDone:
			MISL D 4 bright
			stop
	}
}

ACTOR Grenade_Expander_MiniGrenade
{
	health 2
	radius 1
	height 1
	scale 0.5
	Mass				100
	Gravity				0.5
	+Missile 
	// Instead of making them wait for something in their lives, let's make them explode on contact!
	+ACTIVATEIMPACT
	+ACTIVATEPCROSS
	+FORCERADIUSDMG
	+NODAMAGETHRUST
	+MTHRUSPECIES

	DamageType			MarineFire2
	
	States
	{
		Spawn:
			GRNS AB 4
			loop
		Death:
			MISL B 0 bright A_PlaySound("Flinger/Grenade/Booms")
			MISL B 0 A_Explode(25,64,0,0,16)
			MISL BCD 3
			stop
	}
}

ACTOR Grenade_NerveGas // Hm...
{
	Radius				16
	Height				8
	
	Speed				40
	Gravity				1.0
	Mass				100
	DamageType			MarineFire
	DamageFactor 		"MarineFire2", 0.0
	Health				1
	
	Obituary			"%0 smell the ass of %k's gas nade."
	
	+NOBLOCKMAP
	+DROPOFF
	+MISSILE
	+ACTIVATEIMPACT
	+ACTIVATEPCROSS
	+DOOMBOUNCE
	+MTHRUSPECIES
	+ThRUACTORS
	+ThruSPECIES
	+NODAMAGETHRUST

	+SHOOTABLE
	+NOBLOOD
	-NOBLOCKMAP
	+NOTARGETSWITCH

	bouncecount 16
	
	SeeSound "w9/fire1"
	DeathSound "w9_detonate"
	
	States
	{
		Spawn:
			GRE1 A 3 bright a_playSound("Flinger/Grenade/NerveGas")
			TNT1 A 0 A_SpawnItemEX("NerveGas_HurtQuick")
			TNT1 A 0 a_SpawnItem("NerveGas_GFX")
			GRE1 B 3 bright
			TNT1 A 0 A_SpawnItemEX("NerveGas_HurtQuick")
			TNT1 A 0 a_SpawnItem("NerveGas_GFX")
			GRE1 A 3 bright
			TNT1 A 0 A_SpawnItemEX("NerveGas_HurtQuick")
			TNT1 A 0 a_SpawnItem("NerveGas_GFX")
			GRE1 B 3 bright A_PlaySound("w9/fire2")
			TNT1 A 0 A_SpawnItemEX("NerveGas_HurtQuick")
			TNT1 A 0 a_SpawnItem("NerveGas_GFX")
			
			GRE1 C 3 bright a_playSound("Flinger/Grenade/NerveGas")
			TNT1 A 0 A_SpawnItemEX("NerveGas_HurtQuick")
			TNT1 A 0 a_SpawnItem("NerveGas_GFX")
			GRE1 B 3 bright
			TNT1 A 0 A_SpawnItemEX("NerveGas_HurtQuick")
			TNT1 A 0 a_SpawnItem("NerveGas_GFX")
			GRE1 C 3 bright
			TNT1 A 0 A_SpawnItemEX("NerveGas_HurtQuick")
			TNT1 A 0 a_SpawnItem("NerveGas_GFX")
			GRE1 B 3 bright A_PlaySound("w9/fire2")
			TNT1 A 0 A_SpawnItemEX("NerveGas_HurtQuick")
			TNT1 A 0 a_SpawnItem("NerveGas_GFX")
			
			TNT1 A 0 A_ChangeFlag("ThruActors",false)
			
			goto Spawn
		Death:
			TNT1 A 1 A_JumpIf(Health <= 0, "Death.Shot")
			GRE1 A 3 bright 
			GRE1 C 2 bright A_PlaySound("w9/fire2")
			GRE1 A 3 bright 
			GRE1 C 2 bright A_PlaySound("w9/fire2")
			GRE1 A 3 bright 
			GRE1 AAD 3
			TNT1 A 0 A_Explode(30,64,0,0,64)
			GRNS A 0 A_SpawnItemEX("NerveGas_Hurt", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
			TNT1 A 0 a_playSound("Flinger/Grenade/NerveGas")
			goto GasPasser

		Death.Shot:
			TNT1 A 0 A_ChangeFlag("NOGRAVITY", True)
			GRE1 AD 3 A_PlaySound("w9/fire2")
			TNT1 A 0 A_Scream
			TNT1 A 0 A_Explode(30,128,0,0,128)
			MISL B 4 bright
			MISL C 3 bright A_Fadeout(0.66)
			MISL D 2 bright A_Fadeout(0.33)
			TNT1 A 0 A_SpawnItemEX("NerveGas_Hurt_AirShot", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
			TNT1 A 0 a_playSound("Flinger/Grenade/NerveGas")
			goto GasPasserX

		GasPasserX:
			TNT1 A 0 bright a_SpawnItem("NerveGas_GFX_Air")
			TNT1 A 0 bright a_SpawnItem("NerveGas_GFX_Air")
			TNT1 A 4 bright 
			TNT1 A 0 A_SetArg(1, args[1] + 1)
			TNT1 A 0 A_JumpIf(args[1] > 35, "Gone")
			loop

		GasPasser:
			TNT1 A 0 bright a_SpawnItem("NerveGas_GFX")
			GRE1 D 4 bright 
			TNT1 A 0 A_SetArg(1, args[1] + 1)
			TNT1 A 0 A_JumpIf(args[1] > 35, "IDontFeelSoGood")
			loop
		IDontFeelSoGood:
			GRE1 A 4 bright a_fadeout(0.1)
			loop
		
		Gone:
			TNT1 A 1
			Stop
	}
}

const int NERVEGAS_RANGE = 64;

Actor NerveGas_GFX_Air
{
	states{
		Spawn:
		TNT1 A 1
		TNT1 A 0
		TNT1 A 0 bright a_SpawnItemEx("NerveGas_SteamUp",frandom(3.0,NERVEGAS_RANGE*1.0),frandom(3.0,NERVEGAS_RANGE*1.0),frandom(-NERVEGAS_RANGE*1.0,NERVEGAS_RANGE*1.0),0,0,0)
		TNT1 A 0 bright a_SpawnItemEx("NerveGas_SteamUp",frandom(-NERVEGAS_RANGE*1.0,-3.0),frandom(3.0,NERVEGAS_RANGE*1.0),frandom(-NERVEGAS_RANGE*1.0,NERVEGAS_RANGE*1.0),0,0,0)
		TNT1 A 0 bright a_SpawnItemEx("NerveGas_SteamUp",frandom(3.0,NERVEGAS_RANGE*1.0),frandom(-NERVEGAS_RANGE*1.0,-3.0),frandom(-NERVEGAS_RANGE*1.0,NERVEGAS_RANGE*1.0),0,0,0)
		TNT1 A 0 bright a_SpawnItemEx("NerveGas_SteamUp",frandom(-NERVEGAS_RANGE*1.0,-3.0),frandom(-NERVEGAS_RANGE*1.0,-3.0),frandom(-NERVEGAS_RANGE*1.0,NERVEGAS_RANGE*1.0),0,0,0)
		TNT1 A 0 bright a_SpawnItemEx("NerveGas_Fog",frandom(3.0,NERVEGAS_RANGE*1.0),frandom(3.0,NERVEGAS_RANGE*1.0),frandom(-NERVEGAS_RANGE*1.0,NERVEGAS_RANGE*1.0),0,0,0)
		TNT1 A 0 bright a_SpawnItemEx("NerveGas_Fog",frandom(-NERVEGAS_RANGE*1.0,-3.0),frandom(3.0,NERVEGAS_RANGE*1.0),frandom(-NERVEGAS_RANGE*1.0,NERVEGAS_RANGE*1.0),0,0,0)
		TNT1 A 0 bright a_SpawnItemEx("NerveGas_Fog",frandom(3.0,NERVEGAS_RANGE*1.0),frandom(-NERVEGAS_RANGE*1.0,-3.0),frandom(-NERVEGAS_RANGE*1.0,NERVEGAS_RANGE*1.0),0,0,0)
		TNT1 A 0 bright a_SpawnItemEx("NerveGas_Fog",frandom(-NERVEGAS_RANGE*1.0,-3.0),frandom(-NERVEGAS_RANGE*1.0,-3.0),frandom(-NERVEGAS_RANGE*1.0,NERVEGAS_RANGE*1.0),0,0,0)

		stop
	}
}

Actor NerveGas_GFX
{
	states{
		Spawn:
		TNT1 A 1
		TNT1 A 0
		TNT1 A 0 bright a_SpawnItemEx("NerveGas_SteamUp",0,0,0,0,0,frandom(2.5,5.0))
		TNT1 A 0 bright A_SpawnItemEx("NerveGas_Fog", 0.0, 0.1, 16.0, frandom(-2.0, 2.0), frandom(-2.0, 2.0), frandom(0.0, 2.0))
		stop
	}
}

//[Samu] Taken from alphahiatus dm!
// Thank you Hiimaura!
ACTOR NerveGas_Fog // Hm...
{
	Alpha 0.8
	RenderStyle Add
	Radius 2
	Height 2
	+NOBLOCKMAP
    +NOTELEPORT
    +DONTSPLASH
	+MISSILE
	+FORCEXYBILLBOARD
    +NOINTERACTION
	+NOGRAVITY
	+BOUNCEONCEILINGS
	+BOUNCEONWALLS
	+BOUNCEONFLOORS
	+THRUACTORS
	+MTHRUSPECIES
	Speed 10
	Scale 0.5
	
	States
	{
		Spawn:
			SMKG BCDEFGHIJKLM 4 bright 
			stop
	}
}

ACTOR NerveGas_SteamUp // Hm...
{

	Height 1
	Radius 1
	RenderStyle Add
	Scale 0.4
	Alpha 0.65
	+NOBLOCKMAP
    +NOTELEPORT
    +DONTSPLASH
	+MISSILE
	+FORCEXYBILLBOARD
    +NOINTERACTION
	+NOGRAVITY
	+BOUNCEONCEILINGS
	+BOUNCEONWALLS
	+BOUNCEONFLOORS
	+THRUACTORS
	+MTHRUSPECIES
	+ClientsideOnly
	Scale 0.5
	
	States
	{
		Spawn:
			STEM ABCDEFGHIJKL 1 bright 
			stop
	}
}

Actor NerveGas_Hurt
{
	//PoisonDamage 3, 15, 3
	+THRUACTORS
	+NOGRAVITY
	+NODAMAGETHRUST
	+DONTSPLASH
	+MTHRUSPECIES
	DamageType			MarineFire2
	Obituary "%o thought standing in %k's green gas cloud seemed smart."
	args 0, 0
	States
	{
	Spawn:
		TNT1 A 0 A_Explode(10, 32 + args[0], 0, true, 32 + args[0])
		TNT1 A 0 A_SetArg(0, args[0] + 2)
		TNT1 A 0 A_SetArg(1, args[1] + 1)
		TNT1 A 4 A_JumpIf(args[1] > 35, "Death")
		loop
	Death:
		TNT1 A 1
		Stop
	}
}

Actor NerveGas_Hurt_AirShot : NerveGas_Hurt
{
	States
	{
	Spawn:
		TNT1 A 0 A_Explode(10, NERVEGAS_RANGE + args[0], 0, true, NERVEGAS_RANGE + args[0])
		TNT1 A 0 A_SetArg(0, args[0] + 2)
		TNT1 A 0 A_SetArg(1, args[1] + 1)
		TNT1 A 4 A_JumpIf(args[1] > 35, "Death")
		loop
	Death:
		TNT1 A 1
		Stop
	}
}


Actor NerveGas_HurtQuick : NerveGas_Hurt
{
	DamageType MarineFire2
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 1 A_Explode(2, 32, 0, true, 32)
		TNT1 A 1 A_Explode(2, 48, 0, true, 48)
		TNT1 A 1 A_Explode(2, 64, 0, true, 64)
	Death:
		goto SUPER::DEATH
	}
}


ACTOR Grenade_MinePlacer
{
	Radius				16
	Height				8
	
	Speed				40
	Gravity				1.0
	Mass				100
	DamageType			MarineFire2
	
	Obituary			"%0 was blowen to bits by %k's Flinger."
	
	Projectile
	+NOBLOCKMAP
	+ACTIVATEIMPACT
	+ACTIVATEPCROSS
	+DOOMBOUNCE
	+MTHRUSPECIES
	+UseBounceState
	+SeekerMissile
	+SCREENSEEKER
	+DONTFALL //Stops it from falling after sticking to targets.
    -NOGRAVITY
	bouncecount 16
	
	SeeSound "w9/fire1"
	DeathSound "w9_detonate"
	
	var int user_x;
	var int user_y;
	var int user_z;
	
	States
	{
		Spawn:
			TNT1 A 0 NoDelay Thing_ChangeTiD(0, 30000 + ACS_NamedExecuteWithResult("PlayerId"))
			
			GRNS A 1 bright  A_SeekerMissile(0, 1, SMF_LOOK | SMF_PRECISE, 256, 1)
			GRNS AA 1 bright A_RearrangePointers(AAPTR_TARGET, AAPTR_NULL, AAPTR_NULL) // This should fix the flying grenade issue.
			GRNS B 1 bright  A_SeekerMissile(0, 1, SMF_LOOK | SMF_PRECISE, 256, 1)
			GRNS BB 1 bright A_RearrangePointers(AAPTR_TARGET, AAPTR_NULL, AAPTR_NULL)
			GRNS A 1 bright  A_SeekerMissile(0, 1, SMF_LOOK | SMF_PRECISE, 256, 1)
			GRNS AA 1 bright A_RearrangePointers(AAPTR_TARGET, AAPTR_NULL, AAPTR_NULL)
			TNT1 A 0 A_PlaySound("w9/fire2")
			GRNS B 1 bright  A_SeekerMissile(0, 1, SMF_LOOK | SMF_PRECISE, 256, 1)
			GRNS BB 1 bright A_RearrangePointers(AAPTR_TARGET, AAPTR_NULL, AAPTR_NULL)
			
			goto Spawn
		StickToEnemy:
			TNT1 A 0 A_SetUserVar("user_x", random(-5, 5))
			TNT1 A 0 A_SetUserVar("user_y", random(-5, 5))
			TNT1 A 0 A_SetUserVar("user_z", random(0, 10))
			TNT1 A 0 A_PlaySound("w9/fire2")
			GRNS A 1 bright  A_SeekerMissile(0, 1, SMF_LOOK | SMF_PRECISE, 256, 1)// One last chase before sticking.
		ImStuck:
			NULL A 0 A_Stop
			TNT1 A 0 Thing_ChangeTiD(0, 30000 + ACS_NamedExecuteWithResult("PlayerId"))
			TNT1 A 0 A_ChangeFlag("NoGRAVITY", false) // Preventing the flying grenade bug, though it feels a little hacky.
		Stuck:
			GRNS CCCDDD 1 Bright A_WARP(AAPTR_TRACER, 5.0 * user_x, 5.0 * user_y, 5.0 * user_z, 0, WARPF_NOCHECKPOSITION)
		goto Stuck
		
		Death:
			NULL A 0 A_Stop
			GRNS D 4 bright A_SpawnItem ("Grenade_Mine" , 0, 0, 20.0, 0)
			stop
		XDeath:
			TNT1 A 0 A_Stop
			goto StickToEnemy
		Bounce.Wall:
			NULL A 0 A_Stop
			GRNS D 1 A_SpawnItem ("Grenade_Mine" , 0, 0, 0, 0)
			stop
		Bounce.Ceiling:
			NULL A 0 A_Stop
			GRNS D 1 A_SpawnItem ("Grenade_Mine" , 0, 0, 0, 0)
			stop
		
		Kaboom:
			GRNS D 1 bright A_SpawnItem("Grenade_Mine_GoBoom")
			stop
	}
}

ACTOR Grenade_Mine
{
	Game Doom
	Health 20
	Radius 5
	Height 34
	Speed 0
	+NOBLOOD
	+MTHRUSPECIES
	+noclip
	DeathSound "world/barrelx"
	Obituary "$OB_BARREL" // "%o went boom."
	ExplosionRadius			128
	ExplosionDamage			32
	DamageType			MarineFire2
	projectile
	States
	{
		Spawn:
			GRNS CD 6 Thing_ChangeTiD(0, 30000 + ACS_NamedExecuteWithResult("PlayerId"))
			goto Spawn
		Death:
			GRNS C 5 BRIGHT A_PlaySound("w9_detonate")
			GRNS C 5 BRIGHT A_Scream
			MISL B 1 BRIGHT A_SpawnItem("Grenade_Mine_GoBoom")
			Stop
	}
}

ACTOR Grenade_Mine_GoBoom
{
	health 2
	radius 1
	height 1
	scale 0.5
	Mass				100
	Gravity				0.5
	
	+ACTIVATEIMPACT
	+ACTIVATEPCROSS
	+DOOMBOUNCE
	+FORCERADIUSDMG
	+MTHRUSPECIES
	+NODAMAGETHRUST
	bouncecount 16
	DamageType			MarineFire2
	
	States
	{
		Spawn:
			GRNS A 1
			MISL E 0 A_PlaySound("Flinger/Grenade/Booms")
			MISL E 0 A_Explode(60,192,0,0,96)
			MISL BCD 3
			stop
	}
}

ACTOR Grenade_GLauncher
{
	Radius				16
	Height				16
	Health 1
	Speed				40
	Damage				50
	Gravity				1.0
	Mass				100
	Obituary			"%0 was blowen to bits by %k's Grenade Launcher."
	DamageType			MarineFire

	+DROPOFF
	+MISSILE
	+ACTIVATEIMPACT
	+ACTIVATEPCROSS
	+DOOMBOUNCE
	+FORCERADIUSDMG
	+NODAMAGETHRUST
	+ThruSPECIES
	+MTHRUSPECIES

	+SHOOTABLE
	+NOBLOOD
	-NOBLOCKMAP
	+NOTARGETSWITCH

	bouncecount 16
	
	SeeSound "w9/fire1"
	DeathSound "Flinger/Grenade/Booms"
	
	States
	{
		Spawn:
			GRNS ABA 3 bright
			GRNS B 3 bright A_PlaySound("w9/fire2")
			loop
		Pain:
			TNT1 A 1
			Goto XDeath
		Death:
			TNT1 A 0 A_ChangeFlag("NOGRAVITY", True)
			TNT1 A 0 A_JumpIf(Health <= 0, "Death.Shot")
			TNT1 A 0 A_Explode(250,128,0,0,32)
			goto Rest
		Death.Shot:
			TNT1 AAAAA 0 A_SpawnItem("BulletPuff_Standard")
			TNT1 A 0 A_Explode(250,164,0,0,96)
			goto Rest
		Rest:
			MISL B 4 bright
			MISL C 3 bright
		Gone:
			MISL D 1 bright A_Fadeout(0.1)
			loop
	}
}

//////

//////

Actor Grenade_ShellBlast {
	Radius				8
	Height				16
	Health 1
	
	Speed				40
	Gravity				1.0
	Mass				100
	DamageType			MarineFire2
	Damage 30
	
	Obituary			"%o got a lot of lead by %k's shell grenade."
	
	Projectile
	-NOBLOCKMAP
	+DROPOFF
	+MISSILE
	+ACTIVATEIMPACT
	+ACTIVATEPCROSS
	+MTHRUSPECIES
	+ThruSPECIES
	+DOOMBOUNCE
	-NOGRAVITY
	+DONTGIB
	+SHOOTABLE
	+NoBLOOD

	bouncecount 16
	
	DeathSound "w2/fire"
	
	States
	{
		Spawn:
			GRE2 ABA 3 bright
			GRE2 B 3 bright A_PlaySound("w9/fire2")
			goto Spawn
		Death:
			TNT1 A 0 A_ChangeFlag("NoGRAVITY", True)
			TNT1 A 1 A_JumpIf(Health <= 0, "Death.Shot")
			PUFF B 1 A_Explode(30,108,0,0,64)
			TNT1 A 0 a_setScale(1.5, 1.5)
			PUFF B 1 A_SetArg(3, 0)
			goto ReleaseThePeels 
		Death.Shot:
			PUFF B 1 A_Explode(50,192,0,0,96)
			TNT1 A 0 a_setScale(1.5, 1.5)
			PUFF B 1 A_SetArg(3, 0)
			PUFF B 1 A_SetArg(2, 5)
			goto ReleaseThePeels_Y 
		ReleaseThePeels:
			TNT1 A 1 A_Jumpif(args[3] >= 5 + args[2], "ChangeTheWorld_MyFinalMessage_Goodbye")
			TNT1 A 0 A_SetArg(3, args[3] + 1)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner",0,0,0,0,0,0, 0,SXF_TransferPointers)
			loop
		ReleaseThePeels_Y:
			TNT1 A 1 A_Jumpif(args[3] >= 5 + args[2], "ChangeTheWorld_MyFinalMessage_Goodbye")
			TNT1 A 0 A_SetArg(3, args[3] + 1)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner_x4",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner_x4",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner_x4",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner_x4",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner_x4",0,0,0,0,0,0, 0,SXF_TransferPointers)
			loop
		ChangeTheWorld_MyFinalMessage_Goodbye:
			PUFF B 6 bright A_Scream
			PUFF C 6 bright
			PUFF D 4 bright
			stop
	}
}

ACTOR ShellBlast_PelletSpawner : BulletPuff_Standard
{
	+PUFFONACTORS
	states
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_SetArg(0, (frandom(29.0,60.0)) * (2*random(0,1) - 1))
		TNT1 A 0 A_SetArg(1, (frandom(29.0,60.0)) * (2*random(0,1) - 1))
		TNT1 A 0 A_SetArg(2, cos(angle) * (frandom(5.0,60.0)) * (2*random(0,1) - 1))
		TNT1 A 1 A_JumpIf((args[0] == 29.0) && (args[1] == 29.0), "Spawn.NorXY")
		goto Spawn.Pellet
	Spawn.NorXY:
		TNT1 A 1 A_Jump(128, 2)
		TNT1 A 0 A_SetArg(0, args[0]*0)
		goto Spawn.Pellet
		TNT1 A 0 A_SetArg(0, args[1]*0)
		goto Spawn.Pellet

	Spawn.Pellet:
		TNT1 A 0 A_SpawnitemEx("ShellBlast_Pellet", 0, 0, 0, args[0],args[1], 5.0 + args[2], 0,SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE | SXF_TransferPointers)
		TNT1 A 0
		Goto Super::Spawn
	}
}

ACTOR ShellBlast_PelletSpawner_x4 : ShellBlast_PelletSpawner
{
	states
	{
	Spawn.Pellet:
		TNT1 A 0 A_SpawnitemEx("ShellBlast_Pellet", 0, 0, 0, -args[0],-args[1],- (5.0 + args[2]), 0,SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE | SXF_TransferPointers)
		TNT1 A 0 A_SpawnitemEx("ShellBlast_Pellet", 0, 0, 0, -args[0],args[1],- (5.0 + args[2]), 0,SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE | SXF_TransferPointers)
		TNT1 A 0 A_SpawnitemEx("ShellBlast_Pellet", 0, 0, 0, args[0],args[1], 5.0 + args[2], 0,SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE | SXF_TransferPointers)
		TNT1 A 0 A_SpawnitemEx("ShellBlast_Pellet", 0, 0, 0, args[0],-args[1], 5.0 + args[2], 0,SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE | SXF_TransferPointers)
		TNT1 A 0
		Goto Super::Spawn
	}
}


Actor ShellBlast_PelletTracer
{
	Radius 0
	Height 0
	Renderstyle Add
	+FORCEXYBILLBOARD
  	+NOBLOCKMAP
	+FloorClip
	+SPECIALFLOORCLIP
	+NOGRAVITY
	+NOTELEPORT
	+ClientsideOnly
	States
	{
	Melee:
	Spawn:
		PUFF AA 1
		stop
	}
}

Actor ShellBlast_Pellet {
	Radius				8
	Height				8
	Speed				30
	Damage				(9)
	DamageType			MarineFire
	RenderStyle			Add
	Projectile
	+MTHRUSPECIES
	+NoBlood
	+Ripper
	+BLOODLESSIMPACT
	DeathSound "weapons/rico"
	Obituary			"%o ate some of %k's lead."
	BounceType HEXEN
	BounceFactor 1.5
	BounceCount 2
	States
	{
		Spawn:
			PUFF A 1 
			TNT1 A 0 A_SetArg(0, 175) // Limit to 3 seconds
		Loopme:
			TNT1 A 0 A_JumpIf(args[0] < 0, "Death")
			PUFF A 1 A_SpawnItem("ShellBlast_PelletTracer")
			TNT1 A 0 A_SetArg(0, args[0]-1)
			Loop
		Death:
			PUFF A 1 A_SpawnItem("Bulletpuff_Standard") 
			stop
	}
}


///////////////////
// hand grenades //
///////////////////

Actor HandGrenade_ShellBlast : Grenade_ShellBlast {
	Damage 50
	radius 16
	scale 0.75

	states {
		Death:
			TNT1 A 0 A_ChangeFlag("NoGRAVITY", True)
			TNT1 A 1 A_JumpIf(Health <= 0, "Death.Shot")
			PUFF B 1 A_Explode(70,192,0,192,64)
			TNT1 A 0 a_setScale(1.5, 1.5)
			PUFF B 1 A_SetArg(3, 0)
			goto ReleaseThePeels 
		Death.Shot:
			PUFF B 1 A_Explode(100,224,0,224,96)
			TNT1 A 0 a_setScale(1.5, 1.5)
			PUFF B 1 A_SetArg(3, 0)
			PUFF B 1 A_SetArg(2, 5)
			goto ReleaseThePeels_Y 
		
		ReleaseThePeels:
			PUFF B 1 A_Jumpif(args[3] >= 5 + args[2], "ChangeTheWorld_MyFinalMessage_Goodbye")
			TNT1 A 0 A_SetArg(3, args[3] + 1)
			TNT1 A 0 A_Explode(50,192,0,192,96)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner",0,0,0,0,0,0, 0,SXF_TransferPointers)
			loop
		ReleaseThePeels_Y:
			PUFF B 1 A_Jumpif(args[3] >= 5 + args[2], "ChangeTheWorld_MyFinalMessage_Goodbye")
			TNT1 A 0 A_SetArg(3, args[3] + 1)
			TNT1 A 0 A_Explode(80,224,0,224,96)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner_x4",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner_x4",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner_x4",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner_x4",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner_x4",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner_x4",0,0,0,0,0,0, 0,SXF_TransferPointers)
			TNT1 A 0 A_SpawnitemEx("ShellBlast_PelletSpawner_x4",0,0,0,0,0,0, 0,SXF_TransferPointers)
			loop
	}
}