// ------------------------------------------------------------
//   Hand Grenade
// ------------------------------------------------------------

actor HDFragGrenades : Weapon
{
	weapon.selectionorder 803
	+WEAPON.NO_AUTO_SWITCH
	+weapon.noalert
	+weapon.wimpy_weapon
	+weapon.ammo_optional
	+weapon.alt_ammo_optional
	+inventory.undroppable
	weapon.bobstyle Alpha
	weapon.bobspeed 2.4
	weapon.bobrangex 0.2
	weapon.bobrangey 0.8
	weapon.ammotype "HDFragGrenadeAmmo"
	weapon.ammotype2 "HDFragGrenadeAmmo"
	weapon.ammogive 0
	weapon.ammogive2 0
	weapon.ammouse 1
	weapon.ammouse2 1
	attacksound "*fist"
	states
	{
	select:
		TNT1 A 0 A_TakeInventory("FragTimer",999)
		TNT1 A 0 A_TakeInventory ("GrenadeForce", 999)
		TNT1 A 0 A_TakeInventory ("Reloading", 999)
		PUNG B 1 A_Raise
		PUNG BBBB 0 A_Raise
		loop
	deselect:
		TNT1 A 0 A_TakeInventory ("GrenadeForce", 999)
		TNT1 A 0 A_TakeInventory ("FragTimer", 999)
		TNT1 A 0 A_TakeInventory ("Reloading", 999)
		TNT1 A 0 A_JumpIfInventory("SpoonOff",1,"deselectoshi")
		TNT1 A 0 A_JumpIfInventory("FragOut",1,"deselectpinbackin")
	deselect2:
		PUNG A 1 A_Lower
		PUNG AAAA 0 A_Lower
		loop
	deselectpinbackin:
		TNT1 A 8 A_PlayWeaponSound ("weapons/fragpinin")
		PUNG A 0 A_TakeInventory ("FragOut", 999)
		PUNG A 0 A_TakeInventory ("SpoonOff", 999)
		PUNG A 0 A_TakeInventory ("ReallyPull", 999)
	deselectpinbackin2:
		TNT1 A 1 A_Lower
		TNT1 AAAA 0 A_Lower
		loop
	deselectoshi:
		TNT1 A 0 A_TakeInventory ("FragOut", 999)
		TNT1 A 0 A_TakeInventory ("SpoonOff", 999)
		TNT1 A 0 A_TakeInventory ("ReallyPull", 999)
		TNT1 A 0 A_TakeInventory ("Reloading", 999)
		TNT1 A 0 A_TakeInventory ("GrenadeForce", 999)
		TNT1 A 0 A_FireCustomMissile ("HDFragGrenade1", 0,1,0,-3)
		PUNG A 12 A_JumpIfHealthLower (1, "deselectpinbackin2")
	deselectoshi2:
		PUNG A 1 A_Lower
		PUNG AAAA 0 A_Lower
		loop
	ready:
		TNT1 A 0 A_JumpifInventory ("SpoonOff", 1, "cooking")
		TNT1 A 0 A_JumpifInventory ("FragOut", 1, "pinout")
		TNT1 A 0 A_TakeInventory ("GrenadeForce", 999)
		TNT1 A 0 A_TakeInventory ("FragTimer", 999)
		TNT1 A 0 A_TakeInventory ("ReallyPull", 999)
		TNT1 A 0 A_JumpIfInventory ("HDFragGrenadeAmmo", 1, 3)
		TNT1 A 1 A_WeaponReady
		TNT1 A 0 A_TakeInventory ("Reloading", 999)
		loop
		PUNG B 1 A_WeaponReady
		TNT1 A 0 A_TakeInventory ("Reloading", 999)
		loop

	pinout:
		PUNG A 0 A_WeaponReady(30)//JumpIfInventory ("Reloading", 1, "altpinbackin")
		TNT1 A 0 A_TakeInventory ("Reloading", 999)
		TNT1 A 1 A_WeaponReady(16)
		loop
	cooking:
		TNT1 A 0 A_TakeInventory ("Reloading", 999)
		TNT1 A 1 A_WeaponReady
		PUNG A 0 A_JumpIfInventory ("FragTimer", 136, "oshi")
		PUNG A 0 A_GiveInventory ("FragTimer", 1)
		loop

	altfire:
		TNT1 A 0 A_JumpIfInventory ("SpoonOff", 1, "altidle")
		TNT1 A 0 A_JumpIfInventory ("FragOut", 1, "startcooking")
		TNT1 A 0 A_JumpIfInventory ("HDFragGrenadeAmmo", 1, 1)
		goto punch
	althold:
		TNT1 A 0 A_JumpIfInventory ("SpoonOff", 1, "altidle")
		TNT1 A 0 A_JumpIfInventory ("FragOut", 1, "altidle")
		TNT1 A 0 A_JumpIfInventory ("HDFragGrenadeAmmo", 1, 1)
		goto punch
		TNT1 A 0
		goto startpull
	altidle:
		TNT1 A 0 A_JumpIfInventory ("SpoonOff", 1, 2)
		TNT1 A 0 A_Jump (256, 2)
		TNT1 A 0 A_GiveInventory ("FragTimer", 1)
		TNT1 A 0 A_JumpIfInventory ("FragTimer", 136, "oshi")
		TNT1 A 1
		TNT1 A 0 A_Refire
		goto ready
	startpull:
		TNT1 A 0 A_JumpifInventory ("ReallyPull", 26, "endpull")
		PUNG B 1 A_GiveInventory ("ReallyPull", 1)
		TNT1 A 0 A_Refire
		goto ready
	endpull:
		TNT1 A 0 A_TakeInventory ("ReallyPull", 999)
		TNT1 A 0 A_TakeInventory ("Reloading", 999)
		PUNG B 1 offset(0,34)
		PUNG B 1 offset(0,36)
		PUNG B 1 offset(0,38)
		TNT1 A 6
		TNT1 A 0 A_GiveInventory ("FragOut", 1)
		TNT1 A 3 A_PlayWeaponSound ("weapons/fragpinout")
		TNT1 A 0 A_Refire
		goto ready
	startcooking:
		TNT1 A 0 A_GiveInventory ("SpoonOff",1)
		TNT1 A 0 A_Print ("The fuze is lit! Remember to throw!")
		TNT1 A 6 A_PlayWeaponSound ("weapons/fragspoonoff")
		TNT1 A 0 A_Refire
		goto ready
	oshi:
		TNT1 A 0 A_GiveInventory("GrenadeForce", random(2,4))
		goto throw

	fire:
		TNT1 A 0 A_JumpIfInventory ("FragOut", 1, "hold2")
		TNT1 A 0 A_JumpIfInventory ("HDFragGrenadeAmmo", 1, 1)
		goto punch
		PUNG B 1 offset(0,34)
		PUNG B 1 offset(0,36)
		PUNG B 1 offset(0,38)
		TNT1 A 0 A_Refire
		goto ready
	punch:
		PUNG BC 2
		PUNG C 0 A_JumpIfInventory ("PowerStrength", 1, 2)
		PUNG C 0 A_Jump (256, 2)
		PUNG C 0 A_CustomPunch(27, 0, 0, "HDFistPuff", 42)
		PUNG CCC 0 A_CustomPunch(1, 0, 0, "HDNullPuff", 42)

		TNT1 A 0 A_JumpIfInventory ("Timer", 1, 2)
		TNT1 A 0 A_JumpIfHealthLower (40, "doubledamagepunch")
		TNT1 A 0 A_TakeInventory ("Timer", 999)

		PUNG C 0 A_CustomPunch(1, 0, 0, "HDFistPuff", 42)
		PUNG D 5
		PUNG C 4
		PUNG B 5 A_ReFire
		goto Ready
	doubledamagepunch:
		TNT1 A 0 A_GiveInventory ("Timer", 1)
		goto punch+2
	hold:
		TNT1 A 0 A_JumpIfInventory ("FragOut", 1, "hold2")
		TNT1 A 0 A_JumpIfInventory ("HDFragGrenadeAmmo", 1, 1)
		goto Punch

		PUNG B 0 A_JumpIfInventory ("GrenadeForce", 1, 5)
		TNT1 A 8 A_TakeInventory ("Reloading", 999)
		TNT1 A 0 A_GiveInventory ("FragOut", 1)
		TNT1 A 3 A_PlayWeaponSound ("weapons/rifleclick")

	hold2:
		PUNG A 0 A_JumpIfInventory ("FragTimer", 136, "oshi")
		PUNG A 0 A_JumpIfInventory ("SpoonOff", 1, 2)

		PUNG A 0 A_JumpIfInventory ("GrenadeForce", 5, "charge5")
		PUNG A 0 A_JumpIfInventory ("GrenadeForce", 4, "charge4")
		PUNG A 0 A_JumpIfInventory ("GrenadeForce", 3, "charge3")
		PUNG A 0 A_JumpIfInventory ("GrenadeForce", 2, "charge2")

	charge1:
		TNT1 A 0 A_GiveInventory ("GrenadeForce", 1)
		TNT1 AAAA 1 A_WeaponReady(31)
		goto hold3
	charge2:
		PUNG B 4 A_GiveInventory ("GrenadeForce", 1)
		PUNG BBBB 1 A_WeaponReady(31)
		goto hold3
	charge3:
		PUNG C 4 A_GiveInventory ("GrenadeForce", 1)
		PUNG CCCC 1 A_WeaponReady(31)
		goto hold3
	charge4:
		PUNG D 4 A_GiveInventory ("GrenadeForce", 1)
		PUNG DDDD 1 A_WeaponReady(31)
		goto hold3
	charge5:
		PUNG D 4 A_GiveInventory ("GrenadeForce", 1)
		PUNG DDDD 1 A_WeaponReady(31)
		goto hold3
	hold3:
		TNT1 A 0 A_JumpIfInventory ("SpoonOff", 1, 2)
		TNT1 A 0 A_Jump (256, 2)
		TNT1 A 0 A_GiveInventory ("FragTimer", 4)
		TNT1 A 0 A_Refire
		goto throw
	throw:
		PUNG A 0 A_JumpIfInventory ("GrenadeForce", 6, 6)
		PUNG A 0 A_JumpIfInventory ("GrenadeForce", 5, 6)
		PUNG A 0 A_JumpIfInventory ("GrenadeForce", 4, 6)
		PUNG A 0 A_JumpIfInventory ("GrenadeForce", 3, 6)
		PUNG A 0 A_JumpIfInventory ("GrenadeForce", 2, 6)
		PUNG A 0 A_JumpIfInventory ("GrenadeForce", 1, 6)
		goto ready

		PUNG A 2 A_FireCustomMissile ("HDFragGrenade6", 0,1,0,-3)
		goto followthrough
		PUNG A 2 A_FireCustomMissile ("HDFragGrenade5", 0,1,0,-3)
		goto followthrough
		PUNG A 2 A_FireCustomMissile ("HDFragGrenade4", 0,1,0,-3)
		goto followthrough
		PUNG A 2 A_FireCustomMissile ("HDFragGrenade3", 0,1,0,-3)
		goto followthrough
		PUNG A 2 A_FireCustomMissile ("HDFragGrenade2", 0,1,0,-3)
		goto followthrough
		PUNG A 2 A_FireCustomMissile ("HDFragGrenade1", 0,1,0,-3)
		goto followthrough
	followthrough:
		TNT1 A 0 A_TakeInventory ("FragOut", 999)
		TNT1 A 0 A_TakeInventory ("SpoonOff", 999)
		TNT1 A 0 A_TakeInventory ("ReallyPull", 999)
		TNT1 A 0 A_TakeInventory ("Reloading", 999)
		TNT1 A 0 A_TakeInventory ("GrenadeForce", 999)
		PUNG A 21
		PUNG A 0 A_Refire
		goto ready
	reload:
		TNT1 A 0 A_JumpIfInventory ("GrenadeForce", 1, "pinbackin")
		TNT1 A 0 A_JumpIfInventory ("FragOut", 1, "altpinbackin")
		goto Ready
	pinbackin:
		PUNG A 0 A_TakeInventory ("GrenadeForce", 999)
		PUNG A 0 A_TakeInventory ("Reloading", 999)
		PUNG B 1 offset (0,34)
		PUNG B 1 offset (0,36)
		PUNG B 1 offset (0,38)
	altpinbackin:
		TNT1 A 18 A_PlayWeaponSound ("weapons/shotgr")
//		TNT1 A 0 A_GiveInventory ("HDFragGrenadeAmmo", 1)
		PUNG A 0 A_TakeInventory ("FragOut", 999)
		PUNG A 0 A_TakeInventory ("SpoonOff", 999)
		PUNG A 0 A_TakeInventory ("ReallyPull", 999)
		TNT1 A 0 A_Refire
		PUNG B 1 offset (0,38)
		PUNG B 1 offset (0,36)
		PUNG B 1 offset (0,34)
		goto ready
	spawn:
		TNT1 A 0
		stop
	}
}
actor FragOut : InventoryFlag {}
actor SpoonOff : InventoryFlag {}
actor ReallyPull : InventoryFlag
{
	inventory.maxamount 28
}
actor FragTimer : InventoryFlag
{
	inventory.maxamount 140
}
actor HDFragGrenade
{
	game Doom
	projectile
	-nogravity
	bouncetype "doom"
	+canbouncewater
	+noexplodefloor
	+activatemcross
	-noteleport
	-noblockmap
	-floorclip
	+forcexybillboard
	bouncefactor 0.4
	pushfactor 3
	wallbouncefactor 0.4
	bouncesound "misc/fragknock"
	obituary "%o was fragged by %k."
	scale 0.6
	radius 2
	height 2
	damage 0
	states
	{
	spawn:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInTargetInventory ("FragTimer",1,1)
		goto spawn2
		TNT1 A 0 A_TakeFromTarget ("FragTimer",1)
		TNT1 A 0 A_GiveInventory ("FragTimer",1)
		loop
	spawn2:
		TNT1 A 0 A_JumpIf(z-floorz>1,2)
		TNT1 A 0 A_PlaySound ("misc/fragroll")
		FRAG B 2 A_JumpIfInventory ("FragTimer", 140, "death")
		TNT1 A 0 A_GiveInventory ("FragTimer", 2)
		FRAG C 2 A_JumpIfInventory ("FragTimer", 140, "death")
		TNT1 A 0 A_GiveInventory ("FragTimer", 2)
		FRAG D 2 A_JumpIfInventory ("FragTimer", 140, "death")
		TNT1 A 0 A_GiveInventory ("FragTimer", 2)
		FRAG E 2 A_JumpIfInventory ("FragTimer", 140, "death")
		TNT1 A 0 A_GiveInventory ("FragTimer", 2)
		TNT1 A 0 A_JumpIf(velz*velz<4,2)
		TNT1 A 0 A_JumpIf(velz>-2,1)
		loop
		TNT1 A 0 A_ChangeFlag ("hexenbounce",0)
		//TNT1 A 0 A_ChangeFlag ("doombounce",1)
		TNT1 A 0 A_JumpIf (velz<2,1)
		loop
		TNT1 A 0 A_ChangeFlag ("hexenbounce",1)
		//TNT1 A 0 A_ChangeFlag ("doombounce",0)
		TNT1 A 0 A_Jump (248,2)
		TNT1 A 0 ThrustThing(angle*256/360,velx*vely*velz*random(0,1)/100,0,0)
		TNT1 A 0 A_JumpIf (velx*velx+vely*vely+velz*velz<=4,"death")
		loop
	revive:
		TNT1 A 0 ThrustThing(random(0,256),random(0,1),0,0)
		goto spawn2
	death:
		TNT1 A 0 A_Jump (64, "revive")
		TNT1 A 0 A_ChangeFlag ("solid", 1)
		TNT1 A 0 A_ChangeFlag ("pushable", 1)
		TNT1 A 0 A_ChangeFlag ("doombounce", 0)
		TNT1 A 0 A_ChangeFlag ("hexenbounce", 0)
		TNT1 A 0 A_ChangeFlag ("missile", 0)
		TNT1 A 0 A_Jump (256, "death1", "death2", "death3", "death4", "death5")
	death1:
		FRAG A 4 A_JumpIfInventory ("FragTimer", 140, "explode")
		TNT1 A 0 A_GiveInventory ("FragTimer", 4)
		loop
	death2:
		FRAG B 4 A_JumpIfInventory ("FragTimer", 140, "explode")
		TNT1 A 0 A_GiveInventory ("FragTimer", 4)
		loop
	death3:
		FRAG C 4 A_JumpIfInventory ("FragTimer", 140, "explode")
		TNT1 A 0 A_GiveInventory ("FragTimer", 4)
		loop
	death4:
		FRAG D 4 A_JumpIfInventory ("FragTimer", 140, "explode")
		TNT1 A 0 A_GiveInventory ("FragTimer", 4)
		loop
	death5:
		FRAG E 4 A_JumpIfInventory ("FragTimer", 140, "explode")
		TNT1 A 0 A_GiveInventory ("FragTimer", 4)
		loop
	explode:
		TNT1 A 1 ThrustThingZ (0, random(4, 12), 0, 0)
		TNT1 A 0 A_SpawnItemEx ("HDExplosion", 0,0,0, 0,0,2, 0,32)
		TNT1 AAAAAAAAAAAA 0 A_SpawnItemEx ("HugeWallChunk", 0,0,0, random(-6,6),random(-6,6),random(6,18), random(0,360),160)
		TNT1 A 2 bright A_Explode (random(180,220),  random(160,220))
		TNT1 AAA 0 A_SpawnItemEx ("HDSmoke", random(-6,6),random(-6,6),random(-2,6),0,0,0,0,160)
		TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_SpawnItemEx ("BigWallChunk", 0, 0, 0, random(-4,4),random(-4,4),random(4,18),random(0,360),160)
	explode2:
		TNT1 A 0 A_SpawnItem ("DistantRocket", 1, 1, 0, 0)
		TNT1 A 0 A_AlertMonsters
		TNT1 AAAA 0 A_SpawnItemEx ("Frags", 0,0,0, 0,0,0, 0,32)
		TNT1 A 0 bright A_SpawnItemEx ("Frags", 0,0,0, 0,0,0, 0,32)
		TNT1 A 26 A_Quake(3,26,0,220,none)
		stop
	}
}
actor HDFragGrenade1 : HDFragGrenade
{
	speed 5
}
actor HDFragGrenade2 : HDFragGrenade
{
	speed 10
}
actor HDFragGrenade3 : HDFragGrenade
{
	speed 15
}
actor HDFragGrenade4 : HDFragGrenade
{
	speed 25
}
actor HDFragGrenade5 : HDFragGrenade
{
	speed 35
}
actor HDFragGrenade6 : HDFragGrenade
{
	speed 50
}
actor GrenadeForce : InventoryFlag
{
	inventory.maxamount 8
}
actor HDFragGrenadeAmmo : Ammo
{
	inventory.icon FRAGA0
	+inventory.undroppable
	inventory.amount 1
	inventory.maxamount 12
	ammo.backpackamount 2
	ammo.backpackmaxamount 24
}

