// --------------------------------------------------------------------------
//
//	Hand Grenades
//
// --------------------------------------------------------------------------

ACTOR U_HandGrenades : DoomWeapon
{
	Weapon.AmmoUse1 1
	Weapon.AmmoGive1 1
	Weapon.AmmoUse2 1
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "GrenadeAmmo"
	Weapon.AmmoType2 "GrenadeAmmo"
	Weapon.SelectionOrder 99999
	Obituary "%o was shreded by %k's grenade."
    AttackSound "None"
    Inventory.PickupSound "AmmoAPIN"
	Inventory.Pickupmessage "You got a Frag Grenade!"
    +WEAPON.NOAUTOAIM
    +WEAPON.NOALERT
	+WEAPON.NOAUTOFIRE
	+WEAPON.CHEATNOTWEAPON
    Scale 0.3
	tag "Hand Grenades"
	States
	{
	Ready:
		TNT1 A 0 A_JumpIfInventory("GrenadeAmmo", 1, 1)
		Goto NoGrenadesReady
		GRNS GFEDCBA 1
		Goto Steady
		
	Steady:
		GRHO C 1 A_WeaponReady
		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")
		TNT1 A 0 A_JumpIfInventory("Reloading", 1, "Roll") 
		TNT1 A 0 A_JumpIfInventory("WeapSpecial", 1, "Roll")
		Loop

	NoGrenadesReady:
		TNT1 A 1 A_WeaponReady
		Goto Ready
	
	Deselect:
		TNT1 A 0 A_JumpIfInventory("GrenadeAmmo", 1, 2)
		TNT1 A 0 A_jump(255, 8)
		GRNS ABCDEFG 1
		TNT1 A 0 A_JumpIfInventory("FiredGrenade", 1, "DropGrenade")
        TNT1 A 0 A_TakeInventory("Reloading", 1)
		TNT1 A 0 A_TakeInventory("Unloading", 1)
		TNT1 A 0 A_TakeInventory("TossGrenade", 1)
		TNT1 A 0 A_Lower
		Wait
	
	DropGrenade:
		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 A_JumpIfInventory("IsPlayingAsPurist", 1, "PuristGun")
		TNT1 A 0 A_Takeinventory("FistsSelected",1)
		TNT1 A 0 A_Takeinventory("SawSelected",1)
		TNT1 A 0 A_Takeinventory("ShotgunSelected",1)
		TNT1 A 0 A_Takeinventory("SSGSelected",1)
		TNT1 A 0 A_Takeinventory("MinigunSelected",1)
		TNT1 A 0 A_Takeinventory("PlasmaGunSelected",1)
		TNT1 A 0 A_Takeinventory("RocketLauncherSelected",1)
		TNT1 A 0 A_Takeinventory("GrenadeLauncherSelected",1)
		TNT1 A 0 A_Takeinventory("BFGSelected",1)
		TNT1 A 0 A_Takeinventory("BFG10kSelected",1)
		TNT1 A 0 A_Takeinventory("RailGunSelected",1)
		TNT1 A 0 A_Takeinventory("SubMachineGunSelected",1)
		TNT1 A 0 A_Takeinventory("RevenantLauncherSelected",1)
		TNT1 A 0 A_Takeinventory("LostSoulSelected",1)
		TNT1 A 0 A_Takeinventory("FlameCannonSelected",1)
		TNT1 A 0 A_Takeinventory("HasBarrel",1)
		TNT1 A 0 A_TakeInventory("TossGrenade", 1)
		TNT1 A 0 A_Takeinventory("WeapSpecial",1)
		TNT1 A 5
		TNT1 A 0 A_Raise
		Wait
		
	PuristGun:
		TNT1 A 0 A_TakeInventory("HandGrenades", 1)
		Goto Deselect
		
	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", frandom(-2,2), 1, 0, 0, 0, 0)
	    TNT1 A 0 A_TakeInventory("FiredGrenade", 1)
		GRTH JKLM 1
		TNT1 A 3 
		Goto Ready
		
	AltFire:
	    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	
		
	Roll:
	    GRTH ABCD 1
		TNT1 A 0 A_GiveInventory("FiredGrenade", 1)
		TNT1 A 0 A_PlaySound ("GRNPIN")
		GRTH EEFG 1
	    TNT1 A 5
		TNT1 A 0 A_PlaySound ("GRNTOSS")
		GRNX ABCD 1
		TNT1 A 0 A_FireCustomMissile("HandGrenadeRoll", frandom(-1,1), 1, 0, -15, 0, 0)
	    TNT1 A 0 A_TakeInventory("FiredGrenade", 1)
		GRNX EFGHIJK 1
		TNT1 A 3
		TNT1 A 0 A_TakeInventory("Reloading", 1)
		TNT1 A 0 A_Takeinventory("WeapSpecial",1)
		Goto Ready
		
 	Spawn:
		GRND H -1
		Stop
		
	KickFlash: //16
		GRNK ABCD 1
		GRNK D 8
		GRNK DCBA 1
	    Stop
		
	AirKickFlash: //18
		GRNK ABCD 1
		GRNK D 10
		GRNK DCBA 1
	    Stop
		
	TauntFlash: //33
		GRHO C 33
	    Stop
		
	DoKick:
		TNT1 A 0 A_JumpIf (momZ > 0, "AirKick")
		TNT1 A 0 A_JumpIf (momZ < 0, "AirKick")
		TNT1 A 0 A_GunFlash("KickFlash")
		TNT1 A 0 A_FireCustomMissile("KickAttackDetectDowned", 0, 0, 0, 0)
        TNT1 A 0 A_jumpifinventory("PowerStrength",1,"BerserkerKick")
		TNT1 A 0 A_PlaySound("KICK")
		TNT1 A 0 SetPlayerProperty(0,1,0)
		KICK BCD 1
		TNT1 A 0 A_FireCustomMissile("KickAttack", 0, 0, 0, -7)
        KICK H 4
		TNT1 A 0 A_Takeinventory("Kicking",1)
		KICK I 1
		KICK GFEDCBA 1 
		TNT1 A 0 SetPlayerProperty(0,0,0)
		TNT1 A 0 A_JumpIfInventory("GoFatality", 1, "Steady")
		Goto Steady
		
    BerserkerKick:
		TNT1 A 0 A_PlaySound("KICK")
		TNT1 A 0 SetPlayerProperty(0,1,0)
		KICK BCD 1
        TNT1 A 0 A_FireCustomMissile("SuperKickAttack", 0, 0, 0, -7)
        KICK H 4
		TNT1 A 0 A_Takeinventory("Kicking",1)
		KICK I 1
		KICK GFEDCBA 1 
		TNT1 A 0 SetPlayerProperty(0,0,0)
		TNT1 A 0 A_JumpIfInventory("GoFatality", 1, "Steady")
		Goto Steady
	
	AirKick:
		TNT1 A 0 A_GunFlash("AirKickFlash")
	    TNT1 A 0 A_jumpifinventory("PowerStrength",1,"SuperAirKick")
		TNT1 A 0 A_PlaySound("KICK")
		TNT1 A 0 A_Recoil (-6)
		KICK JKLMN 1
        TNT1 A 0 A_FireCustomMissile("AirKickAttack", 0, 0, 0, -31)
        KICK O 2
		KICK A 0 A_Takeinventory("Kicking",1)
		KICK PQRST 2
		TNT1 A 0 A_JumpIfInventory("GoFatality", 1, "Steady")
		Goto Steady
		
	SuperAirKick:
		TNT1 A 0 A_PlaySound("KICK")
		TNT1 A 0 A_Recoil (-6)
		KICK JKLMN 1
        TNT1 A 0 A_FireCustomMissile("SuperAirKickAttack", 0, 0, 0, -31)
        KICK O 2
		KICK A 0 A_Takeinventory("Kicking",1)
		KICK PQRST 2
		TNT1 A 0 A_JumpIfInventory("GoFatality", 1, "Steady")
		Goto Steady

    Taunt:
		TNT1 A 0 A_GunFlash("TauntFlash")
        TNT1 A 5
		TNT1 A 5 A_PlaySound("FUCK", 2)
		FUCK F 1
		TNT1 A 0 BRIGHT A_FireCustomMissile("Taunter", 0, 0, -1, 0)
		TNT1 A 0 BRIGHT A_FireCustomMissile("Taunter", -9, 0, -1, 0)
		TNT1 A 0 BRIGHT A_FireCustomMissile("Taunter", 9, 0, -1, 0)
        FUCK GHI 1 A_AlertMonsters
		FUCK J 14 A_Takeinventory("Taunting",1)
        FUCK IHGF 1
		Goto Steady
		
	Salute:
	    TNT1 A 0 SetPlayerProperty(0,1,0)
		TNT1 A 0 A_AlertMonsters
		SALU ABCDEDCDEDCDEDCBA 4
		TNT1 A 0 A_TakeInventory("Salute1",1)
		TNT1 A 0 A_TakeInventory("Salute2",1)
		TNT1 A 0 SetPlayerProperty(0,0,0)
		Goto Ready
	}
}

ACTOR NewHandGrenade : HandGrenade replaces HandGrenade
{
	Damage (random(1,2))
	States
	{
	Spawn:
		GRND ABCDEFGH 2 A_JumpIf(waterlevel > 1, "UnderWater")
		TNT1 A 0 A_GiveInventory("GrenadeTime", 1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime", 3, "Explode")
		Loop
	UnderWater:
		TNT1 A 0 A_ScaleVelocity(0.2)
		TNT1 A 0 ThrustThingZ (0,7,1,0)
		GRND ABCD 4
		TNT1 A 0 A_SpawnItem("BUBULZ")
		TNT1 A 0 A_GiveInventory("GrenadeTime", 1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime", 3, "Explode")
		
		TNT1 A 0 A_ScaleVelocity(0.2)
		TNT1 A 0 ThrustThingZ (0,7,1,0)
		GRND EFGH 4
		TNT1 A 0 A_SpawnItem("BUBULZ")
		TNT1 A 0 A_GiveInventory("GrenadeTime", 1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime", 3, "Explode")
		Loop
	Death:
		TNT1 A 0 A_Jump(128, "Death2")
	Death1:
	    GRND D 16
		TNT1 A 0 A_GiveInventory("GrenadeTime", 1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime", 3, "Explode")
		Loop
	Death2:
	    GRND H 16
		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 A_SpawnItem("ExplosionLight")
		Stop
	}
}

Actor U_HandGrenadeDroped: NewHandGrenade replaces HandGrenadeDroped
{
	Speed 4
}

Actor U_HandGrenadeAlt: NewHandGrenade replaces HandGrenadeAlt
{
	Speed 8
}

Actor HandGrenadeRoll: NewHandGrenade
{
	MaxStepHeight 1
	Speed 22
	-DOOMBOUNCE
	States
	{
	Spawn:
		GRND HIJKHIJK 2 A_JumpIf(waterlevel > 1, "UnderWater")
		TNT1 A 0 A_GiveInventory("GrenadeTime", 1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime", 3, "Explode")
		Loop
	Death:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInventory("GrenadeTime", 1, "Bounce")
		TNT1 A 0 A_Recoil(-26)
//Using (ABS (MomY) < 1) is causing  error "Numeric type expected" in Zandronum 2.
//This part is so much better looking in the GZDOOM version. *sigh*
	Roll:
		GRND HIJKHIJK 2 A_JumpIf(((MomY) < 1) && ((MomY) > -1), "Roll2")
		TNT1 A 0 A_GiveInventory("GrenadeTime", 1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime", 3, "Explode")
		TNT1 A 0 A_JumpIf(waterlevel > 1, "UnderWater")
		Loop
	Roll2:
		GRND HIJKHIJK 2 A_JumpIf(((MomX) < 1) && ((MomX) > -1), "Death2")
		TNT1 A 0 A_GiveInventory("GrenadeTime", 1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime", 3, "Explode")
		TNT1 A 0 A_JumpIf(waterlevel > 1, "UnderWater")
		Loop
	Bounce:
		TNT1 A 0 A_CustomMissile ("HandGrenadeRoll2", 0, 0, 180, 16, 45)
		Stop
	}
}

Actor HandGrenadeRoll2: NewHandGrenade
{
	Speed 10
	States
	{
	Spawn:
		GRND ABCDEFGH 2
		TNT1 A 0 A_GiveInventory("GrenadeTime", 1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime", 2, "Explode")
		Loop
	}
}