//--------------------------------------------------------------------------
//
// UAC-Fragmentation Grenades
//
//--------------------------------------------------------------------------

ACTOR GetOnWithIt : Inventory { Inventory.MaxAmount 100 }

ACTOR D64Grenades: D64Weapon
{
	+WEAPON.EXPLOSIVE
	+INVENTORY.UNDROPPABLE
	Weapon.AmmoType "GrenadeAmmo"
	Weapon.AmmoUse 1
	Weapon.AmmoGive 0
	Inventory.Pickupmessage "You got the UAC-Fragmentation Grenade!"
	Scale 0.9
	Tag "UAC-Fragmentation Grenades"
	States
	{
	Ready:
		TNT1 A 0 A_JumpIfInventory("IsKicking", 1, "DoKick")
		TNT1 A 0 A_JumpIf(waterlevel>2,"ReadyNoAmmo")
		TNT1 A 0 A_JumpIfNoAmmo("ReadyNoAmmo")
		GREN A 1 A_WeaponReady
		TNT1 A 0 A_JumpifInventory("IsKicking", 1, "DoKick")
		Goto TrueReady
	TrueReady:
		TNT1 A 0 A_JumpIfInventory("IsKicking", 1, "DoKick")
		GREN A 1 A_WeaponReady
		TNT1 A 0 A_JumpIf(waterlevel>2,"ReadyNoAmmo")
		TNT1 A 0 A_JumpifInventory("IsKicking", 1, "DoKick")
		Loop
	ReadyNoAmmo:
		TNT1 A 1 A_WeaponReady
		TNT1 A 0 A_JumpifInventory("IsKicking", 1, "DoKick")
		Loop
	Deselect:
		TNT1 A 0 A_JumpIfInventory("GrenadeAmmo",1,1)
		Goto Drylower
		TNT1 A 0 A_PlaySound("weapons/weaponholster",3)
		GREN A 1 Offset (8, 0) A_Lower
		TNT1 A 0 A_Lower
		GREN A 1 Offset (16, 0) A_Lower
		TNT1 A 0 A_Lower
		GREN A 1 Offset (24, 0) A_Lower
		TNT1 A 0 A_Lower
		GREN A 1 Offset (32, 0) A_Lower
		TNT1 A 0 A_Lower
		GREN A 1 Offset (40, 0) A_Lower
		TNT1 A 0 A_Lower
		GREN A 1 Offset (48, 0) A_Lower
		TNT1 A 0 A_Lower
		GREN A 1 Offset (56, 0) A_Lower
		TNT1 A 0 A_Lower
		GREN A 1 Offset (64, 0) A_Lower
		TNT1 A 1 A_Lower
		Wait
	DryLower:
		TNT1 A 1 A_Lower
		Wait
	Select:
		TNT1 A 0 A_JumpIf(waterlevel>2,"ReadyNoAmmo")
		TNT1 A 0 A_JumpIfInventory("GrenadeAmmo",1,1)
		Goto ReadyNoAmmo
		TNT1 A 0 A_PlaySound("Weapons/Grenade/Up",5)
		GREN A 1 Offset (64, 0) A_Raise
		TNT1 A 0 A_Raise
		GREN A 1 Offset (56, 0) A_Raise
		TNT1 A 0 A_Raise
		GREN A 1 Offset (48, 0) A_Raise
		TNT1 A 0 A_Raise
		GREN A 1 Offset (40, 0) A_Raise
		TNT1 A 0 A_Raise
		GREN A 1 Offset (32, 0) A_Raise
		TNT1 A 0 A_Raise
		GREN A 1 Offset (24, 0) A_Raise
		TNT1 A 0 A_Raise
		GREN A 1 Offset (16, 0) A_Raise
		TNT1 A 0 A_Raise
		GREN A 1 Offset (8, 0) A_Raise
		TNT1 A 0 A_Raise
		Wait
	Fire:
		TNT1 A 0 A_JumpIf(waterlevel>2,"ReadyNoAmmo")
		TNT1 A 0 A_JumpIfInventory("GrenadeAmmo",1,1)
		Goto Dryfire
		GREN A 1 Offset (5, 40)
		GREN A 1 Offset (15, 56)
		GREN A 1 Offset (25, 72)
		GREN A 1 Offset (35, 88)
		GREN A 1 Offset (45, 104)
		GREN A 1 Offset (55, 120)
		GREN A 1 Offset (65, 136)
		GREN A 1 Offset (75, 152)
		GREN A 6 A_PlaySound("Weapons/Grenade/PickUp",7)
		TNT1 A 1 A_ReFire("Hold")
		Goto Realfire
	Hold:
		TNT1 A 0 A_JumpIf(waterlevel>2,"ReadyNoAmmo")
		TNT1 A 0 A_JumpIfInventory("GetOnWithIt", 100, "Realfire")
		TNT1 A 1 A_GiveInventory("GetOnWithIt",1)
		TNT1 A 0 A_Refire
	Realfire:
		TNT1 A 0 A_JumpIf(waterlevel>2,"ReadyNoAmmo")
		TNT1 A 0 A_StopSound(1)
		TNT1 A 0 Offset(-20,32)
		TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSecondary|WRF_NoSwitch)
		MAND A 2
		TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSecondary|WRF_NoSwitch)
		MAND B 2
		TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSecondary|WRF_NoSwitch)
		MAND C 2
		TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSecondary|WRF_NoSwitch)
		MAND D 2 A_PlaySound("Weapons/Grenade/Throw")
		TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSecondary|WRF_NoSwitch)
		TNT1 A 0 A_SpawnItemEx("RealGrenade",0,1,24,cos(pitch)*40,0,sin(-pitch)*40,3,SXF_TRANSFERPITCH|SXF_NOCHECKPOSITION)
		TNT1 A 0 A_TakeInventory("GrenadeAmmo",1)
		MAND E 2
		TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSecondary|WRF_NoSwitch)
		MAND F 2
		TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSecondary|WRF_NoSwitch)
		TNT1 A 0 A_TakeInventory("GetOnWithIt", 100)
		TNT1 A 0 A_JumpIfNoAmmo("Dryfire")
		TNT1 A 1 Offset (75, 152)
		GREN A 1 Offset (75, 152)
		GREN A 1 Offset (65, 136)
		GREN A 1 Offset (55, 120)
		GREN A 1 Offset (45, 104)
		GREN A 1 Offset (35, 88)
		GREN A 1 Offset (25, 72)
		GREN A 1 Offset (15, 56)
		GREN A 1 Offset (5, 40)
		Goto Ready
	DryFire:
		TNT1 A 1 A_Print("No grenades left.",1)
		TNT1 A 1 A_WeaponReady
		Loop
		
//Kick
	DoKick:
		TNT1 A 0 A_JumpIf (momZ > 0, "AirBorne")
		TNT1 A 0 A_JumpIf (momZ < 0, "AirBorne")
		TNT1 A 0 A_JumpIfInventory("BerserkStrength",1,"BerserkKick")
		KICK A 1 Offset(0,32)
		TNT1 A 0 A_SetPitch(Pitch-1)
		KICK B 1 A_ZoomFactor(0.99)
		TNT1 A 0 A_SetPitch(Pitch-1)
		KICK C 1 A_ZoomFactor(0.98)
		TNT1 A 0 A_SetPitch(Pitch-1)
		KICK D 1 A_ZoomFactor(0.97)
		TNT1 A 0 A_SetPitch(Pitch-1)
		KICK E 1 A_ZoomFactor(0.96)
		TNT1 A 0 A_SetPitch(Pitch-1)
		KICK F 1 A_ZoomFactor(0.95)
		TNT1 A 0 A_CustomPunch(2 * random(1, 10),0,0,"KickPuff") 
		Goto FireEnd
		BerserkKick:
		KICK A 1 Offset(0,32)
		TNT1 A 0 A_SetPitch(Pitch-1)
		KICK B 1 A_ZoomFactor(0.99)
		TNT1 A 0 A_SetPitch(Pitch-1)
		KICK C 1 A_ZoomFactor(0.98)
		TNT1 A 0 A_SetPitch(Pitch-1)
		KICK D 1 A_ZoomFactor(0.97)
		TNT1 A 0 A_SetPitch(Pitch-1)
		KICK E 1 A_ZoomFactor(0.96)
		TNT1 A 0 A_SetPitch(Pitch-1)
		KICK F 1 A_ZoomFactor(0.95)
		TNT1 A 0 A_CustomPunch(20 * random(5, 10),0,0,"KickPuff")
		Goto FireEnd
		FireEnd:
		KICK GHIH 1
		TNT1 A 0 A_SetPitch(Pitch+1)
		KICK G 1 A_ZoomFactor(0.96)
		TNT1 A 0 A_SetPitch(Pitch+1)
		KICK F 1 A_ZoomFactor(0.97)
		TNT1 A 0 A_SetPitch(Pitch+1)
		KICK E 1 A_ZoomFactor(0.98)
		TNT1 A 0 A_SetPitch(Pitch+1)
		KICK D 1 A_ZoomFactor(0.99)
		TNT1 A 0 A_SetPitch(Pitch+1)
		KICK C 1 A_ZoomFactor(1.00)
		TNT1 A 3
		KICK BA 1
		Goto Ready
		AirBorne:
		TNT1 A 0 A_JumpIfInventory("BerserkStrength",1,"AirBerserk")
		TNT1 A 0 Offset(-1,32)
		KIKK ABCDE 1 A_Recoil(-2)
		KIKK F 3 A_CustomPunch (15,0,0,"KickPuff") 
		Goto EndFire
		AirBerserk:
		TNT1 A 0 Offset(-1,32)
		KIKK ABCDE 1 A_Recoil(-2)
		KIKK F 3 A_CustomPunch (25 * random(5, 10),0,0,"KickPuff")
		Goto EndFire
		EndFire:
		KIKK GHIJK 2 
		Goto Ready
		
	Spawn:
		GREP A -1
		Stop
	}
}

// Grenade -------------------------------------------------------------

ACTOR RealGrenade
{
	Radius 2
	Height 2
	Speed 35
	Damage 0
	Projectile
	-NOGRAVITY
	-GRENADETRAIL
	+RANDOMIZE
	+DEHEXPLOSION
	+SHOOTABLE
	+SKYEXPLODE
	+CANBOUNCEWATER
	Obituary "Rest in pieces."
	BounceType "Doom"
	BounceFactor 0.5
	WallBounceFactor 0.4
	DeathSound "Sounds/Effects/Explo1"
	BounceSound "Weapons/Grenade/Bounce"
	DamageType Explosive
	Obituary "%k played some hot potato toss at %o."
	Decal Scorch
	Gravity 0.85
	Scale 0.5
	States
	{
	Spawn:
		TNT1 A 0 A_JumpIf(waterlevel>2,"Waterdeath")
		TNT1 A 0 A_PlaySound("weapons/grenades/see",6,1,1)
	    GREB A 2 A_SpawnItemEx("GunSmokeSpawner2",0,0,0,0,0,1,0,128)
		GREB B 2 A_SpawnItemEx("GunSmokeSpawner2",0,0,0,0,0,1,0,128)
		GREB C 2 A_SpawnItemEx("GunSmokeSpawner2",0,0,0,0,0,1,0,128)
		GREB D 2 A_SpawnItemEx("GunSmokeSpawner2",0,0,0,0,0,1,0,128)
		GREB E 2 A_SpawnItemEx("GunSmokeSpawner2",0,0,0,0,0,1,0,128)
		GREB F 2 A_SpawnItemEx("GunSmokeSpawner2",0,0,0,0,0,1,0,128)
		GREB G 2 A_SpawnItemEx("GunSmokeSpawner2",0,0,0,0,0,1,0,128)
		GREB H 2 A_SpawnItemEx("GunSmokeSpawner2",0,0,0,0,0,1,0,128)
		Loop
	Death: 
		TNT1 A 0 A_StopSound(6)
		TNT1 A 0 A_JumpIf(waterlevel>2,"Waterdeath")
		TNT1 A 1 A_Explode(156,156)
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 Radius_Quake (2, 36, 0, 15, 0)
		TNT1 A 0 A_NoBlocking
		TNT1 A 0 A_Scream
		TNT1 AAAAAAAAAAAAAAA 0 A_SpawnDebris("BulletSparks")
		TNT1 A 0 A_SetScale(1.0)
		TNT1 A 0 A_SetTranslucent(0.65, 1)
		BLAM ABCDEFGHIJKLMNOP 1 BRIGHT
		Stop	
	WaterDeath:
		TNT1 A 1 A_SpawnItem("NJWaterSplashChunk")
		Stop
	}
}