// --------------------------------------------------------------------------
//
//	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 99990
	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
	{
 	Spawn:
		GRND H -1
		Stop
	
	Select:
		TNT1 A 0 A_JumpIfInventory("IsPlayingAsPurist",1,"PuristGun")
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1002,11)==0,"PuristGun")
		TNT1 A 0 A_Giveinventory("FistsSelected",1)
		TNT1 A 0 A_Giveinventory("GoSpecial",1)
		TNT1 A 0 A_Takeinventory("Unloading",1)
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_TakeInventory("TossGrenade",1)
		TNT1 A 0 A_Takeinventory("WeapSpecial",1)
		TNT1 A 0 A_Takeinventory("SwitchFlashlight",1)
		TNT1 A 0 A_Takeinventory("Taunting",1)
		TNT1 A 0 A_Takeinventory("IdleCounter",200)
		TNT1 A 0 ACS_NamedExecuteAlways("TE_WeaponSprites")
		TNT1 A 3
		TNT1 A 0 A_Raise
		Wait

	Deselect:
		TNT1 A 0 A_JumpIfInventory("GrenadeAmmo",1,2)
		TNT1 A 0 A_Jump(256,15)
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,8)
		GRNS BCDEFG 1
		TNT1 A 0 A_Jump(256,7)
		GRDS BCDEFG 1
		TNT1 A 0 A_JumpIfInventory("FiredGrenade",1,"DropGrenade")
		TNT1 A 0 A_TakeInventory("FistsSelected",1)
		TNT1 A 0 A_TakeInventory("BD21graphics",1)
		TNT1 A 0 A_Lower
		Wait

	Ready:
		TNT1 A 0 A_JumpIfInventory("GoFatality",1,"Steady")
		TNT1 A 0 A_JumpIfInventory("GrenadeAmmo",1,1)
		Goto NoGrenadesReady
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,10)
		TNT1 A 0
		GRNS GFEDCBA 1
		TNT1 A 0 A_Jump(256,8)
		GRDS GFEDCBA 1
		TNT1 A 0 A_TakeInventory("Reloading",1)
		Goto Steady

	Steady:
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,3)
		GRNR A 1 A_WeaponReady
		TNT1 A 0 A_Jump(256,2)
		GRDR A 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")
		TNT1 A 0 A_JumpIfInventory("SwitchFlashlight",1,"Roll")
		Loop

	NoGrenadesReady:
		TNT1 A 1 A_WeaponReady
		Goto Ready

	DropGrenade:
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,3)
		TNT1 A 0 A_FireCustomMissile("U_HandGrenadeDroped",random(-2,2),1,0,0,0,0)
		TNT1 A 0 A_Jump(256,2)
		TNT1 A 0 A_FireCustomMissile("U_NewHandGrenadeDroped",random(-2,2),1,0,0,0,0)
		TNT1 A 0 A_TakeInventory("FiredGrenade",1)
		Goto Deselect

	PuristGun:
		TNT1 A 0 A_TakeInventory("U_HandGrenades",1)
		Goto Deselect

// --------------------------------------------------------------------------
//
//	Fire
//
// --------------------------------------------------------------------------

	Fire:
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,6)
		GRTH ABCD 1
		TNT1 A 0 A_Jump(256,5)
		GRDH ABCD 1
		TNT1 A 0 A_GiveInventory("FiredGrenade",1)
		TNT1 A 0 A_PlaySound("GRNPIN")
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,8)
		GRTH EEFGHI 1
		TNT1 A 0 A_Jump(256,7)
		GRDH EEFGHI 1

	Hold:
		TNT1 A 1
		TNT1 A 1 A_Refire
		TNT1 A 0 A_PlaySound("GRNTOSS")
		GRTH JKL 1
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,3)
		TNT1 A 0 A_FireCustomMissile("U_HandGrenade",frandom(-2,2),1,0,0,0,0)
		TNT1 A 0 A_Jump(256,2)
		TNT1 A 0 A_FireCustomMissile("U_NewHandGrenade",frandom(-2,2),1,0,0,0,0)
		TNT1 A 0 A_TakeInventory("FiredGrenade",1)
		GRTH MNOPQ 1
		TNT1 A 3 
		Goto Ready

	AltFire:
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,6)
		GRTH ABCD 1
		TNT1 A 0 A_Jump(256,5)
		GRDH ABCD 1
		TNT1 A 0 A_GiveInventory("FiredGrenade",1)
		TNT1 A 0 A_PlaySound("GRNPIN")
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,8)
		GRTH EEFGHI 1
		TNT1 A 0 A_Jump(256,7)
		GRDH EEFGHI 1

	AltHold:
		TNT1 A 1
		TNT1 A 1 A_Refire
		TNT1 A 0 A_PlaySound("GRNTOSS")
		GRTH JKL 1
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,3)
		TNT1 A 0 A_FireCustomMissile("U_HandGrenadeAlt",0,1,0,0,0,0)
		TNT1 A 0 A_Jump(256,2)
		TNT1 A 0 A_FireCustomMissile("U_NewHandGrenadeAlt",0,1,0,0,0,0)
		TNT1 A 0 A_TakeInventory("FiredGrenade",1)
		GRTH MNOPQ 1
		TNT1 A 3 
		Goto Ready

	Roll:
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,6)
		GRTH ABCD 1
		TNT1 A 0 A_Jump(256,5)
		GRDH ABCD 1
		TNT1 A 0 A_GiveInventory("FiredGrenade",1)
		TNT1 A 0 A_PlaySound("GRNPIN")
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,8)
		GRTH EEFGHI 1
		TNT1 A 0 A_Jump(256,7)
		GRDH EEFGHI 1
		TNT1 A 5
		TNT1 A 0 A_PlaySound("GRNTOSS")
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,7)
		GRNX ABCD 1
		TNT1 A 0 A_FireCustomMissile("HandGrenadeRoll",frandom(-1,1),1,0,-15,0,0)
		TNT1 A 0 A_Jump(256,6)
		GRDX ABCD 1
		TNT1 A 0 A_FireCustomMissile("NewHandGrenadeRoll",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)
		TNT1 A 0 A_Takeinventory("SwitchFlashlight",1)
		Goto Ready

// --------------------------------------------------------------------------
//
//	End Stuff
//
// --------------------------------------------------------------------------

	KickFlash:
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,11)
		GRNK ABCD 1
		GRNK D 8
		GRNK DCBA 1
		GRNR A 1
		Stop
		GRDK ABCD 1
		GRDK D 8
		GRDK DCBA 1
		GRDR A 1
		Stop

	AirKickFlash:
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,11)
		GRNK ABCD 1
		GRNK D 10
		GRNK DCBA 1
		GRNR A 1
		Stop
		GRDK ABCD 1
		GRDK D 10
		GRDK DCBA 1
		GRDR A 1
		Stop

	TauntFlash:
		TNT1 A 0 A_JumpIfInventory("BD21graphics",1,2)
		GRNR A 34
		Stop
		GRDR A 34
		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 5
		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 5
		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 3
		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 3
		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 0 A_JumpIfInventory("GenderFemale",1,3)
		TNT1 A 5 A_PlaySound("FUCK",2)
		TNT1 A 0 A_Jump(256,2)
		TNT1 A 5 A_PlaySound("FTAUNT",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 15 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 U_HandGrenade replaces HandGrenade
{
	Radius 4
	Height 4
	Projectile
	Speed 30
	Damage 0
	Gravity 0.7
	Scale 0.2
	Projectile
	+MISSILE
	-NOGRAVITY
	-BLOODSPLATTER
	-EXTREMEDEATH
	+EXPLODEONWATER
	+SKYEXPLODE
	+DOOMBOUNCE
	BounceFactor 0.5
	WallBounceFactor 0.25
	Health 5
	SeeSound "GRNBNCE"
	DeathSound "none"
	Obituary "%o ate %k grenade."
	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(256,"Death1","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_NewHandGrenade : U_HandGrenade
{
	Scale 0.4
	States
	{
	Spawn:
		GRDD 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)
		GRDD 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)
		GRDD EFGH 4
		TNT1 A 0 A_SpawnItem("BUBULZ")
		TNT1 A 0 A_GiveInventory("GrenadeTime",1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime",3,"Explode")
		Loop
	Death1:
		GRDD D 16
		TNT1 A 0 A_GiveInventory("GrenadeTime",1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime",3,"Explode")
		Loop
	Death2:
		GRDD H 16
		TNT1 A 0 A_GiveInventory("GrenadeTime",1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime",3,"Explode")
		Loop
	}
}

Actor U_HandGrenadeDroped: U_HandGrenade replaces HandGrenadeDroped
{
	Speed 4
}

Actor U_NewHandGrenadeDroped: U_NewHandGrenade
{
	Speed 4
}

Actor U_HandGrenadeAlt: U_HandGrenade replaces HandGrenadeAlt
{
	Speed 8
}

Actor U_NewHandGrenadeAlt: U_NewHandGrenade
{
	Speed 8
}

Actor HandGrenadeRoll: U_HandGrenade
{
	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)
	Roll:
		GRND HIJKHIJK 2 A_JumpIf((ABS (VelY) < 1) && (ABS (VelX) < 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 NewHandGrenadeRoll: U_NewHandGrenade
{
	MaxStepHeight 1
	Speed 24
	-DOOMBOUNCE
	States
	{
	Spawn:
		GRDD 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(-24)
	Roll:
		GRDD HIJKHIJK 2 A_JumpIf((ABS (VelY) < 1) && (ABS (VelX) < 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("NewHandGrenadeRoll2",0,0,180,16,45)
		Stop
	}
}

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

Actor NewHandGrenadeRoll2: U_NewHandGrenade
{
	Speed 10
	States
	{
	Spawn:
		GRDD ABCDEFGH 2
		TNT1 A 0 A_GiveInventory("GrenadeTime",1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime",2,"Explode")
		Loop
	}
}