ACTOR HandGrenades : BrutalWeapon
{
	Weapon.AmmoUse1 1
	Weapon.AmmoGive1 1
	Weapon.SelectionOrder 99999
	Weapon.AmmoType1 "GrenadeAmmo"
	Obituary "%o was shreded by %k's grenade."
    AttackSound "None"
    Inventory.PickupSound "AmmoAPIN"
	Inventory.Pickupmessage "You got a Frag Grenade! (Slot 0)"
    +WEAPON.NOAUTOAIM
    +WEAPON.NOALERT
	+WEAPON.NOAUTOFIRE
	+WEAPON.EXPLOSIVE
	+WEAPON.WIMPY_WEAPON
    Scale 0.3
	Tag "Frag Grenade"
	States
	{

	Ready:
	Ready3:
	    TNT1 A 0
		TNT1 A 0 A_JumpIfInventory("GrenadeAmmo", 1, 1)
		Goto NoGrenades

		GRHO AB 1
		Goto Steady

	Steady:
		GRHO C 1 A_WeaponReady
		TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
		TNT1 A 0 A_JumpIfInventory("ExecuteDownedEnemy", 1, "DoExecution")
		TNT1 A 0 A_JumpIfInventory("Kicking",1,"DoKick")
        TNT1 A 0 A_JumpIfInventory("Taunting",1,"Taunt")
		TNT1 A 0 A_JumpIfInventory("Salute1", 1, "Salute")
		TNT1 A 0 A_JumpIfInventory("Salute2", 1, "Salute")
		RIFG A 0 A_JumpIfInventory("IsRunning",1,"StartSprint")
		Loop

	NoGrenades:
		TNT1 A 1 A_WeaponReady
		TNT1 A 0 A_JumpIfInventory("ExecuteDownedEnemy", 1, "DoExecution")
		TNT1 A 0 A_JumpIfInventory("Kicking",1,"DoKick")
        TNT1 A 0 A_JumpIfInventory("Taunting",1,"Taunt")
		TNT1 A 0 A_JumpIfInventory("Salute1", 1, "Salute")
		TNT1 A 0 A_JumpIfInventory("Salute2", 1, "Salute")
		RIFG A 0 A_JumpIfInventory("IsRunning",1,"StartSprintNoAmmo")
		Goto Ready

	Deselect:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInventory("FiredGrenade", 1, "DropGrenade")
		TNT1 A 0 A_TakeInventory("Unloading", 1)
		TNT1 A 0 A_TakeInventory("Reloading", 1)
		TNT1 A 0 A_TakeInventory("StartDualWield",1)
		TNT1 A 1 A_Lower
		Wait

	DropGrenade:
		TNT1 A 0
		TNT1 A 0 A_TakeInventory("FiredGrenade", 1)
		TNT1 A 0 A_FireCustomMissile("HandGrenadeDroped", random(-2,2), 1, 0, 0, 0, 0)
		Goto Deselect

	Select:
		TNT1 A 0
		TNT1 A 0 A_Giveinventory("GoSpecial",1)
		TNT1 A 0 A_Giveinventory("SwitchtoFist",1)
		TNT1 A 0 A_GiveInventory("FistsSelected", 1)
		TNT1 A 0 A_TakeInventory("ShotgunSelected", 1)
		TNT1 A 0 A_TakeInventory("MinigunSelected", 1)
		TNT1 A 0 A_TakeInventory("SSGSelected", 1)
		TNT1 A 0 A_TakeInventory("RocketLauncherSelected", 1)
		TNT1 A 0 A_TakeInventory("GrenadeLauncherSelected", 1)
		TNT1 A 0 A_TakeInventory("PlasmaGunSelected", 1)
		TNT1 A 0 A_TakeInventory("RailGunSelected", 1)
		TNT1 A 0 A_TakeInventory("RevenantLauncherSelected", 1)
		TNT1 A 0 A_TakeInventory("SubMachineGunSelected", 1)
		TNT1 A 0 A_TakeInventory("BFG10KSelected", 1)
		TNT1 A 0 A_TakeInventory("BFGSelected", 1)
		TNT1 A 0 A_TakeInventory("FlameCannonSelected", 1)
		TNT1 A 0 A_TakeInventory("SawSelected", 1)
		TNT1 A 0 A_Takeinventory("HasBarrel",1)
		TNT1 A 0 A_TakeInventory("TossGrenade", 1)
		TNT1 A 0 A_TakeInventory("StartDualWield", 1)
		TNT1 A 0 A_SetCrosshair(41)
		GRWG A 0 A_GunFlash
		GRWG A 1 A_Raise
		Goto Ready

	Fire:
	    GRTH ABCD 1
		TNT1 A 0 A_GiveInventory("FiredGrenade", 1)
		TNT1 A 0 A_PLaySound ("GRNPIN")
		GRTH EEFG 1

	Hold:
	    TNT1 A 1
		TNT1 A 1 A_Refire
		TNT1 A 0 A_PLaySound ("GRNTOSS")
		GRTH HI 1
		TNT1 A 0 A_FireCustomMissile("HandGrenade", 0, 1, 0, 0, 0, 0)
	    TNT1 A 0 A_TakeInventory("FiredGrenade", 1)
		GRTH JKLM 1
		TNT1 A 3
		Goto Ready

	AltFire:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInventory("GrenadeAmmo", 1, 1)
		Goto NoGrenades
		TNT1 A 0 A_TakeInventory("GrenadeAmmo", 1)
	    GRTH ABCD 1
		TNT1 A 0 A_GiveInventory("FiredGrenade", 1)
		TNT1 A 0 A_PLaySound ("GRNPIN")
		GRTH EEFG 1

	AltHold:
	    TNT1 A 1
		TNT1 A 1 A_Refire
		TNT1 A 0 A_PLaySound ("GRNTOSS")
		GRTH HI 1
		TNT1 A 0 A_FireCustomMissile("HandGrenadeAlt", 0, 1, 0, 0, 0, 0)
	    TNT1 A 0 A_TakeInventory("FiredGrenade", 1)
		GRTH JKLM 1
		TNT1 A 3
		Goto Ready

 	Spawn:
		GRND H -1
		Stop

	StartSprint:
		GRHO C 1 A_WeaponReady
		SHTN A 0 A_Takeinventory("Zoomed",1)
        SHTN A 0 A_ZoomFactor(1.0)
		SHTN A 0 A_Takeinventory("ADSmode",1)
		RIFG A 0 A_SetCrosshair(0)
		SHTN A 0 A_Giveinventory("GoSpecial",1)
		TNT1 A 0 ACS_NamedExecuteAlways("BDSprint", 0, 0, 0, 0)//Makes player faster.

	Sprinting:
		GRHO A 1 offset(-9,34) A_SetPitch(pitch -0.5)
		GRHO A 1 offset(-6,36) A_SetPitch(pitch -0.5)
		GRHO A 1 offset(-3,38) A_SetPitch(pitch -0.5)
		GRHO A 1 offset(0,38) A_SetPitch(pitch -0.5)
		GRHO A 1 offset(3,36) A_SetPitch(pitch -0.5)
		GRHO A 1 offset(6,34) A_SetPitch(pitch -0.5)
		GRHO A 1 offset(9,32) A_SetPitch(pitch -0.5)
		TNT1 A 0 A_GiveInventory("UsedStamina", 1)
		SMGG A 0 A_WeaponReady(WRF_NOBOB)
		SMGG A 0 A_JumpIfInventory("Kicking",1,"DoKick")
        SMGG A 0 A_JumpIfInventory("Taunting",1,"Taunt")

		GRHO A 1 offset(9,34) A_SetPitch(pitch +0.5)
		GRHO A 1 offset(6,36) A_SetPitch(pitch +0.5)
		GRHO A 1 offset(3,38) A_SetPitch(pitch +0.5)
		GRHO A 1 offset(0,38) A_SetPitch(pitch +0.5)
		GRHO A 1 offset(-3,36) A_SetPitch(pitch +0.5)
		GRHO A 1 offset(-6,34) A_SetPitch(pitch +0.5)
		GRHO A 1 offset(-9,32) A_SetPitch(pitch +0.5)
		TNT1 A 0 A_GiveInventory("UsedStamina", 1)
		SMGG A 0 A_WeaponReady(WRF_NOBOB)
		SMGG A 0 A_JumpIfInventory("Kicking",1,"DoKick")
        SMGG A 0 A_JumpIfInventory("Taunting",1,"Taunt")

		PLAY A 0 ACS_NamedExecuteAlways("BDSprint", 0, 0, 0, 0)//Makes player faster.
		SMGG A 0 A_JumpIfInventory("IsRunning", 1, "Sprinting")
		Goto StopSprint

	StopSprint:
		GRHO A 0 A_JumpIfInventory("PowerStrength", 1, 2)
		GRND F 0 A_JumpIfInventory("UsedStamina", 100, "StopSprintTired")
		GRHO A 1 ACS_NamedExecuteAlways("BDTacticalSpeed", 0, 0, 0, 0)//Makes player slower.
		Goto Ready

	StopSprintTired:
		GRHO A 1 ACS_NamedExecuteAlways("BDTacticalSpeed", 0, 0, 0, 0)//Makes player slower.
		GRND F 0 A_PlaySound("Tired", 2)
		Goto Ready

	StartSprintNoAmmo:
		TNT1 A 1 A_WeaponReady
		SHTN A 0 A_Takeinventory("Zoomed",1)
        SHTN A 0 A_ZoomFactor(1.0)
		SHTN A 0 A_Takeinventory("ADSmode",1)
		RIFG A 0 A_SetCrosshair(0)
		SHTN A 0 A_Giveinventory("GoSpecial",1)
		TNT1 A 0 ACS_NamedExecuteAlways("BDSprint", 0, 0, 0, 0)//Makes player faster.

	SprintingNoAmmo:
		TNT1 A 1 offset(-9,34) A_SetPitch(pitch -0.5)
		TNT1 A 1 offset(-6,36) A_SetPitch(pitch -0.5)
		TNT1 A 1 offset(-3,38) A_SetPitch(pitch -0.5)
		TNT1 A 1 offset(0,38) A_SetPitch(pitch -0.5)
		TNT1 A 1 offset(3,36) A_SetPitch(pitch -0.5)
		TNT1 A 1 offset(6,34) A_SetPitch(pitch -0.5)
		TNT1 A 1 offset(9,32) A_SetPitch(pitch -0.5)
		TNT1 A 0 A_GiveInventory("UsedStamina", 1)
		SMGG A 0 A_WeaponReady(WRF_NOBOB)
		SMGG A 0 A_JumpIfInventory("Kicking",1,"DoKick")
        SMGG A 0 A_JumpIfInventory("Taunting",1,"Taunt")

		TNT1 A 1 offset(9,34) A_SetPitch(pitch +0.5)
		TNT1 A 1 offset(6,36) A_SetPitch(pitch +0.5)
		TNT1 A 1 offset(3,38) A_SetPitch(pitch +0.5)
		TNT1 A 1 offset(0,38) A_SetPitch(pitch +0.5)
		TNT1 A 1 offset(-3,36) A_SetPitch(pitch +0.5)
		TNT1 A 1 offset(-6,34) A_SetPitch(pitch +0.5)
		TNT1 A 1 offset(-9,32) A_SetPitch(pitch +0.5)
		TNT1 A 0 A_GiveInventory("UsedStamina", 1)
		SMGG A 0 A_WeaponReady(WRF_NOBOB)
		SMGG A 0 A_JumpIfInventory("Kicking",1,"DoKick")
        SMGG A 0 A_JumpIfInventory("Taunting",1,"Taunt")

		PLAY A 0 ACS_NamedExecuteAlways("BDSprint", 0, 0, 0, 0)//Makes player faster.
		SMGG A 0 A_JumpIfInventory("IsRunning", 1, "SprintingNoAmmo")
		Goto StopSprintNoAmmo

	StopSprintNoAmmo:
		TNT1 A 0 A_JumpIfInventory("PowerStrength", 1, 2)
		TNT1 A 0 A_JumpIfInventory("UsedStamina", 100, "StopSprintTiredNoAmmo")
		TNT1 A 1 ACS_NamedExecuteAlways("BDTacticalSpeed", 0, 0, 0, 0)//Makes player slower.
		Goto Ready

	StopSprintTiredNoAmmo:
		TNT1 A 1 ACS_NamedExecuteAlways("BDTacticalSpeed", 0, 0, 0, 0)//Makes player slower.
		TNT1 A 0 A_PlaySound("Tired", 2)
		Goto Ready
	}
}

ACTOR HandGrenade
{
	Radius 4
	Height 4
	Projectile
	Speed 30
    Damage (random (2, 2))
    Gravity 0.7
	Scale 0.4
	Projectile
	+MISSILE
    -NOGRAVITY
    -BLOODSPLATTER
	-EXTREMEDEATH
	+EXPLODEONWATER
	+SKYEXPLODE
	+BOUNCEONFLOORS
	+BOUNCEONWALLS
	+BOUNCEONCEILINGS
	-NOTELEPORT
	+MTHRUSPECIES
	+THRUSPECIES
	Species "Marines"
	BounceFactor 0.5
	WallBounceFactor 0.25
    Health 5
    SeeSound "GRNBNCE"
	DeathSound "none"
	Obituary "%o ate %k grenade."
	States
	{
	Spawn:
		GRND ABCDEFGH 2
		TNT1 A 0 A_SpawnItem("GrenadeAlerter")
		TNT1 A 0 A_GiveInventory("GrenadeTime", 1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime", 3, "Explode")
		Loop
	Death:
		TNT1 A 0
		TNT1 A 0 A_AlertMonsters(160)
	    GRND H 16 A_SpawnItem("GrenadeAlerter")
		TNT1 A 0 A_GiveInventory("GrenadeTime", 1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime", 3, "Explode")
		Loop
	Explode:
		TNT1 A 0 A_NoBlocking
		TNT1 A 0 A_SpawnItem("FragGrenadeExplosion")
		TNT1 A 0
		Stop
	}
}


Actor FakeGrenade: HandGrenade
{
SeeSound "None"
Damage (random (5, 5))
	States
	{
Spawn:
		TNT1 ABCDEFGH 2
		Loop
	Death:
		TNT1 A 0
		Stop
	}
}

Actor HandGrenadeDroped: HandGrenade
{
Speed 4
}

Actor HandGrenadeAlt: HandGrenade
{
Speed 8
}

actor FragGrenadeExplosion
{
+NOBLOCKMAP
+MISSILE
+DONTSPLASH
Damagetype "Shrapnel"
DeathSound "Explosion"
Height 32
States
{
    Spawn:
	TNT1 A 0
	TNT1 A 0 A_Explode(67, 160)
	TNT1 A 0 A_Explode(53, 240)
	TNT1 A 0 A_Explode(40, 320)
	TNT1 A 0 A_Explode(27, 400)
	TNT1 A 0 A_Explode(13, 480)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSplashSpawner", 0, 0, -20)
	TNT1 A 0 A_SpawnItemEx ("DetectFloorCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
	TNT1 A 0 A_SpawnItemEx ("DetectCeilCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionFlareSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
	TNT1 A 0 A_SpawnItemEx ("UnderwaterExplosion",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)

	TNT1 AAAAAAAAAA 0 A_CustomMissile ("BDExplosionparticlesBig", 0, 0, random (0, 360), 2, random (0, 360))
	TNT1 AAAAA 0 A_CustomMissile ("BDExplosionparticles2", 0, 0, random (0, 360), 2, random (0, 90))
	TNT1 AAAA 0 A_CustomMissile ("SmallExplosionFlames", 0, 0, random (0, 360), 2, random (0, 360))
	EXPL A 0 Radius_Quake (2, 35, 0, 5, 0)
	BEXP B 0 BRIGHT A_Scream
	TNT1 A 0 A_ALertMonsters
	TNT1 A 0 A_PlaySound("FAREXPL", 3)
	TNT1 A 0 A_SpawnItem("BarrelExplosionSmokeColumn")
	TNT1 AAAAA 12 //A_CustomMissile ("ExplosionSmoke", 1, 0, random (0, 360), 2, random (50, 130))
	Stop
	}
}

actor GrenadeAlerter : FragGrenadeExplosion
{
	+NODAMAGETHRUST
	DamageType "Avoid"
	DeathSound "none"
	States
	{
		Spawn:
		TNT1 A 0
		TNT1 A 4 A_Explode(2,240)
		TNT1 A 0 A_NoBlocking
		Stop
	}
}