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
	//+INVENTORY.UNDROPPABLE
    Scale 0.3
	States
	{
		//***Che disabling player weapons for cutscenes and for the evacuation center
		HoldFire:
			GRHO C 0 offset(20,42) A_JumpIfInventory("Taunting",1,"Taunt")
			GRHO C 0 A_JumpIfInventory("Salute1", 1, "Salute")
			GRHO C 0 A_JumpIfInventory("Salute2", 1, "Salute")
			GRHO C 0 A_JumpIfInventory("IsRunning",1,"CheckSprint")
			GRHO C 1 offset(20,42) A_WeaponReady(WRF_NOBOB | WRF_NOFIRE)
			GRHO C 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire")
			Goto Ready	
		Ready:
		Ready3:
			TNT1 A 0
			TNT1 A 0 A_GunFlash
			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("DisablePlayerWeapons", 1, "HoldFire")
			TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
			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,"CheckSprint")
			Loop
		
		NoGrenades:
			TNT1 A 1 A_WeaponReady
			Goto Ready
		
		Deselect:
			TNT1 A 0
			TNT1 A 0 A_JumpIfInventory("FiredGrenade", 1, "DropGrenade")
			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:
			GRWG A 1 A_Raise
			Loop
		Fire:
			TNT1 A 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire")
			GRTH ABCD 1
			TNT1 A 0 A_GiveInventory ("PlayerIsFighting", 150) //***Che encourages the follower NPCs to get da fug out of your line of fire
			TNT1 A 0 A_GiveInventory("FiredGrenade", 1)
			TNT1 A 0 A_PLaySound ("GRNPIN")
			GRTH EEFG 1
			
		Hold:
			TNT1 A 1
			TNT1 A 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "Hold") // loop: pin already out, cannot do anything else
			TNT1 A 0 A_GiveInventory ("PlayerIsFighting", 20) //***Che encourages the follower NPCs to get da fug out of your line of fire			
			TNT1 A 1 A_Refire
			TNT1 A 0 A_PLaySound ("GRNTOSS")
			GRTH HI 1
			TNT1 A 0 A_FireCustomMissile("HandGrenade", random(-2,2), 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_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire")
			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 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "AltHold")
			TNT1 A 0 A_GiveInventory ("PlayerIsFighting", 20) //***Che encourages the follower NPCs to get da fug out of your line of fire
			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
			
		CheckSprint:
			GRHO A 1 A_WeaponReady(WRF_NOFIRE)
			GRND F 0 A_JumpIfInventory("IsStandingStill", 1, "Ready3")
			GRND F 0 A_JumpIfInventory("IsTacticalClass", 1, "StartSprint")
			Goto Ready
			
		StartSprint:
			GRHO A 1 A_WeaponReady(WRF_NOFIRE)
			GRND F 0 A_JumpIfInventory("UsedStamina", 40, "StopSprintTired")
			
		Sprinting:	
			PISP A 0 offset(-9,32) 
			GRND F 0 offset(-9,32) A_JumpIfInventory("IsStandingStill", 1, "Ready3")
			GRND F 0 offset(-9,32) A_JumpIfInventory("UsedStamina", 100, "StopSprintTired")
			PLAY A 0 offset(-9,32) ACS_ExecuteAlways(852, 0, 0, 0, 0)//Makes player faster.
			GRND F 0 offset(-9,32) A_JumpIfInventory("PowerStrength", 1, 2)
			GRND F 0 offset(-9,32) A_GiveInventory("UsedStamina", 2)
			GRND F 0 offset(-9,32)
			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)
			GRND F 0 offset(9,32) A_WeaponReady(WRF_NOBOB)
			GRND F 0 A_JumpIfInventory("Kicking",1,"DoKick")
			GRND F 0 A_JumpIfInventory("Taunting",1,"Taunt")
			GRND F 0 offset(-9,32) A_GiveInventory("UsedStamina", 3)
			GRND F 0 offset(9,33) A_SpawnItemEx("FootStep", 0, 0, 2, 0, 0, -4)
			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)
			GRND F 0 offset(-9,32) A_WeaponReady(WRF_NOBOB)
			GRND F 0 offset(-9,32) A_JumpIfInventory("IsRunning", 1, "Sprinting")
			
			Goto StopSprint
		StopSprintTired:
			GRHO A 1
			PLAY A 0 ACS_ExecuteAlways(853, 0, 0, 0, 0)//Makes player slower.
			GRND F 0 A_PlaySound("Tired", 2)
			GRND F 0 A_TakeInventory("UsedStamina", 2)
			GRND F 5 A_WeaponReady
			GRND F 0 A_TakeInventory("UsedStamina", 2)
			GRND F 5 A_WeaponReady
			GRND F 0 A_TakeInventory("UsedStamina", 2)
			GRND F 5 A_WeaponReady
			GRND F 0 A_TakeInventory("UsedStamina", 2)
			GRND F 5 A_WeaponReady
			GRND F 0 A_TakeInventory("UsedStamina", 2)
			GRND F 5 A_WeaponReady
			Goto Ready
		StopSprint:
			GRHO A 1
			GRND F 0 A_JumpIfInventory("UsedStamina", 60, "StopSprintTired")
			PLAY A 0 ACS_ExecuteAlways(853, 0, 0, 0, 0)//Makes player slower.
			Goto Ready		
	}
}


ACTOR HandGrenade
{
	Radius 4
	Height 4
	Projectile
	Speed 30
    Damage (random (2, 2))
	DamageType "HardGrenade3" // zombiemen and imps use this to determine catching chance and time to explosion  
    Gravity 0.7
	Scale 0.4
	Projectile
	+MISSILE
    -NOGRAVITY
    -BLOODSPLATTER
	-EXTREMEDEATH
	+NOEXTREMEDEATH
	+EXPLODEONWATER
	+SKYEXPLODE
	+BOUNCEONFLOORS
	+BOUNCEONWALLS
	+BOUNCEONCEILINGS
	-NOTELEPORT
	+THRUSPECIES
	Species "Marines"
	BounceFactor 0.5
	WallBounceFactor 0.25
    Health 5
    SeeSound "GRNBNCE"
	DeathSound "none"
	Obituary "%o ate %k grenade."
	-NOBLOCKMAP // without this, A_RadiusGive does not see them
	States
	{
		Spawn:
			TNT1 A 0
		Fly:
			GRND ABCDEFGH 2
			TNT1 A 0 A_GiveInventory("GrenadeTime", 1)
			TNT1 A 0 A_SetDamageType("FireInTheHole")
			TNT1 A 0 A_Explode(2, 200)
			TNT1 A 0 A_SetDamageType("HardGrenade2")
			GRND ABCDEFGH 2
			TNT1 A 0 A_GiveInventory("GrenadeTime", 1)
			TNT1 A 0 A_SetDamageType("FireInTheHole")
			TNT1 A 0 A_Explode(2, 200)
			TNT1 A 0 A_SetDamageType("HardGrenade1") // will explode in the catching zombieman's hand
			GRND ABCDEFGH 2
			TNT1 A 0 A_GiveInventory("GrenadeTime", 1)
			TNT1 A 0 A_JumpIfInventory("GrenadeTime", 3, "Explode")
			Goto Explode
		Death:
			TNT1 A 0
			TNT1 A 0 A_AlertMonsters(200)
			GRND HHHH 1 A_JumpIfInventory("GrenadeSomeoneHasCaughtYou", 1, "Vanish")
			TNT1 A 0 A_SetDamageType("FireInTheHole")
			TNT1 A 0 A_Explode(2, 200)
		Lay:	
			GRND HHHHHHHHHHHHHHHH 1 A_JumpIfInventory("GrenadeSomeoneHasCaughtYou", 1, "Vanish")
			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_SpawnItemEx("FragGrenadeExplosion",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION)
			TNT1 AA 0
			Stop
		Vanish:
			TNT1 A 0 A_NoBlocking
			TNT1 A 30
			Stop
	}
}


Actor EnemyGrenade : HandGrenade 
{
	Species None
	-THRUSPECIES
	+THRUACTORS
	+GHOST
	+THRUGHOST
	DamageType "Normal" // NOT catchable by monsters: we don't want this degenerating into a hot potato clown show
	States
	{
		Spawn:
			TNT1 A 0
		Fly:
			GRND AB 2
			TNT1 A 0 A_ChangeFlag("THRUACTORS", 0)
		FlyContinue:
			GRND CDEFGHAB 2
			TNT1 A 0 A_GiveInventory("GrenadeTime", 1)
			TNT1 A 0 A_JumpIfInventory("GrenadeTime", 3, "Explode")
			Loop
	}
}


Actor EnemyGrenadeDropped: EnemyGrenade
{
	Speed 4
}


Actor EnemyGrenade1Time: EnemyGrenade
{
	States
	{
		Spawn:
			TNT1 A 0
			TNT1 A 0 A_GiveInventory("GrenadeTime", 2)	
			Goto Fly
	}
}


Actor EnemyGrenade1TimeDropped: EnemyGrenade1Time
{
	Speed 4
}


Actor EnemyGrenade2Time: EnemyGrenade1Time
{
	States
	{
		Spawn:
			TNT1 A 0
			TNT1 A 0 A_GiveInventory("GrenadeTime", 1)		
			Goto Fly
	}
}


Actor EnemyGrenade2TimeDropped: EnemyGrenade2Time
{
	Speed 4
}


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

			//***Che: ridiculously OP, this one was.
			// Always nerf it, wanted I.
			//TNT1 A 0 A_Explode(100,500)
			
			TNT1 A 0 A_Explode(60,250,1,1,128)
			TNT1 A 0 A_Explode(40,400,1,1,250)
			
			// can afford it, there are so *few* grenades -- only the players use them
			TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_CustomMissile("FragGrenadeTracer", 0, 0, random(0,360), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, random(-70, 70)) 
			// max range of FragGrenadeTracer is 560, DamageType Shotgun, damage (random(12,12)) -- weak monsters are extra vulnerable
			// 30 pieces, total damage = 360, *but* realistically less than half would hit one target
			
			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, 24, 0, 15, 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
	}
}
		
