// --------------------------------------------------------------------------
//
// HE Grenade (Demo weapon "Appears on weapons training")
//
// --------------------------------------------------------------------------

ACTOR "HE GRENADE" : CSDMOWeapon //5010
{
//	Weapon.SisterWeapon "HE Grenade_RAT"

	Weapon.SelectionOrder 1900
	Weapon.AmmoUse 1
	Weapon.AmmoGive 1
	Weapon.AmmoType "HEGRENADEAmmo"
	obituary "%k killed %o with HE Grenade."
	+WEAPON.WIMPY_WEAPON
	Inventory.Pickupmessage "Pickep up a HE Grenade."
	Tag "High Explosive Grenade"
	Weapon.UpSound "HEGRENADE/Ready"
	AttackSound "HEGRENADE/Fire" 
	Scale 0.2
	 +IGNORESKILL
	 +WEAPON.EXPLOSIVE
	//+NOAUTOFIRE

	States
	{
	Ready:
//    TNT1 A 0 A_JumpIfInventory("RipAndTear_Powerup",1, "QuickFire")
		W16B J 1 A_WeaponReady
		Loop
		




	Deselect:
TNT1 A 1 A_TakeInventory("Grenade_BlockMemo",1)
	TNT1 A 0 ACS_NamedExecuteAlways("HSPreviousWeapon", 0, 2, 0, 0)
    TNT1 A 0
	Goto DeselectLoop

		
	Select:
	TNT1 A 1 A_Raise
	TNT1 AA 0 A_Raise
	TNT1 A 0 ACS_ExecuteAlways(798, 0, 245, 0, 0)//Weapon Weight
	TNT1 A 1 A_TakeInventory("CrosshairType",2)

	TNT1 A 0 ACS_NamedExecuteAlways("HSPreviousWeapon", 0, 1, 0, 0)
//    TNT1 A 0 A_JumpIfInventory("RipAndTear_Powerup",1, "QuickFire")

		TNT1 A 7 A_WEAPONREADY(WRF_NOFIRE)
		W16A JKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W16B ABCDEFGHI 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto Ready

	SelectUsed:
TNT1 A 0 A_TakeInventory("Grenade_BlockMemo",1)
		TNT1 A 1 A_JumpIfNoAmmo("PreviousWeapon")
		TNT1 A 9 A_PlaySound("HEGRENADE/Ready")
		W16A JKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W16B ABCDEFGHI 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto Ready

//made it into 5 tics each fire state to don't spam that many fire states. A balance between code save and responsiveness
	Fire:
TNT1 A 0 A_GiveInventory("Grenade_BlockMemo",1)
	TNT1 A 0 A_JumpIfInventory("IsBot",1,"BotFire")
			TNT1 A 0 A_PlaySound("HEGRENADE/pinpull")
		W16D ABCDE 1 A_WEAPONREADY(WRF_NOFIRE)
		W16D F 1 A_Refire("Fire_2")
		Goto Throw




	Fire_2:
	/*
		W16D FGHIJ 1 A_WEAPONREADY(WRF_NOFIRE)
		W16D K 1 A_Refire("Fire_3")
		Goto Throw

	Fire_3:
		W16D KLMNO 1 A_WEAPONREADY(WRF_NOFIRE)
		W16D P 1 A_Refire("Fire_4")
		Goto Throw

	Fire_4:
		W16D PQRST 1 A_WEAPONREADY(WRF_NOFIRE)
		W16D U 1 A_Refire("Fire_5")
		Goto Throw

	Fire_5:
		W16D UVWXY 1 A_WEAPONREADY(WRF_NOFIRE)
		W16D Z 1 A_Refire("Fire_6")
		Goto Throw

	Fire_6:
		W16D Z 1 A_WEAPONREADY(WRF_NOFIRE)
		W16E ABCD 1 A_WEAPONREADY(WRF_NOFIRE)
		W16E E 1 A_Refire("Fire_7")
		Goto Throw

	Fire_7:
		W16E EFGH 1 A_WEAPONREADY(WRF_NOFIRE)
		W16E I 1 A_Refire("Fire_loop")
		Goto Throw
*/

//        W16D A 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
//        W16D B 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
//        W16D C 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
//        W16D D 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
//        W16D E 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D F 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D G 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D H 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D I 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D J 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D K 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D L 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D M 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D N 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D O 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D P 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D Q 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D R 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D S 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D T 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D U 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D V 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D W 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D X 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D Y 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16D Z 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw

        W16E A 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16E B 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16E C 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16E D 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16E E 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16E F 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W16E G 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw


	Fire_loop:
		W16E H 1 A_WEAPONREADY(WRF_NOFIRE)
		W16E H 1 A_Refire("Fire_loop")
		Goto Throw





/*
	Fire:
	TNT1 A 0 A_JumpIfInventory("IsBot",1,"BotFire")
		TNT1 A 4 A_FireCustomMissile(HEGRENADEPROJECTILE,0,1,0,3,0,4)//A_GunFlash
		W16F EFGH 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 3 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 1 A_JumpIfNoAmmo("SetWeapon")
		Goto SelectUsed
*/


	BotFire:
	Throw:
TNT1 A 0 A_JumpIf(CallACS("buckshotcheck")==1, "Throw_Infinite")
		TNT1 A 4 A_FireCustomMissile(HEGRENADEPROJECTILE,0,1,0,3,0,4)//A_GunFlash
		W16F EFGH 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOSWITCH)
		TNT1 A 3 A_WEAPONREADY(WRF_NOFIRE|WRF_NOSWITCH)
		TNT1 A 1 A_JumpIfNoAmmo("PreviousWeapon")
		Goto SelectUsed


	Throw_Infinite:
		TNT1 A 4 A_FireCustomMissile(HEGRENADEPROJECTILE,0,0,0,3,0,4)//A_GunFlash
		W16F EFGH 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 3 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 1 A_JumpIfNoAmmo("PreviousWeapon")
		Goto SelectUsed




             SetWeapon:  
        TNT1 A 1 A_WeaponReady(WRF_NOFIRE)//A_SelectWeapon("Knife")
        Goto Ready	






	QuickFire:
		TNT1 A 4 A_FireCustomMissile(HEGRENADEPROJECTILE,0,1,0,3,0,4)//A_GunFlash
		W16F EFGH 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 3 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 1 A_JumpIfNoAmmo("PreviousWeapon")
		Goto SelectUsed



	PreviousWeapon:
		TNT1 A 6 //A_PlaySound("HEGRENADE/Ready")
		TNT1 A 3 //A_PlaySound("HEGRENADE/Ready")
	TNT1 A 0 ACS_NamedExecuteAlways("HSPreviousWeapon", 0, 0, 0, 0)
TNT1 A 0 A_TakeInventory("Grenade_BlockMemo",1)
Goto SetWeapon





	Flash:
		TNT1 A 0 Bright //A_Light1
		TNT1 A 0 A_TakeInventory("Slot8Filled", 1)//A_AlertMonsters
		TNT1 A 2 A_FireCustomMissile(HEGRENADEPROJECTILE,0,1,0,3,0,4)
		Goto LightDone
 	Spawn:
		W16Z A -1
		Stop







	}
}





// --------------------------------------------------------------------------
//
// Grenade -- Taken and adapted from Skulltag, with MBF stuff added to it
//
// --------------------------------------------------------------------------

ACTOR HEGrenadeProjectile
{
	Game Doom
	SpawnID 216
	Radius 8
	Height 8

	Damage 10
	Projectile
    BounceType "Hexen"
	-NOGRAVITY
	+RANDOMIZE
	+DEHEXPLOSION
+USEBOUNCESTATE
	//+GRENADETRAIL
//	+doombounce
	//BounceType "Doom"
//	Gravity 0.25
	SeeSound "HEGRENADE/BOUNCE"
	DeathSound "HEGRENADE/EXPLODE"
	//BounceSound "weapons/grbnce"
	Obituary "%k killed %o with HE Grenade."
	DamageType Grenade

scale 0.2

   ExplosionRadius 192
   ExplosionDamage 256
  Speed 35

	BounceFactor 0.4
WallBounceFactor 0.35
//BounceCount 2

//  BounceFactor 0.7
  ReactionTime 70


	States
	{
	Spawn:
		W16X AAABBBCCCDDDEEEFFFGGGHHH 1 Bright A_Countdown
		Loop

IdleSound:
tnt1 a 0 A_PlaySound("HEGRENADE/BOUNCE")
Goto Spawn


bounce.ceiling:
bounce.wall:
tnt1 a 0 A_PlaySound("HEGRENADE/BOUNCE")
Goto Spawn
bounce.floor:
TNT1 A 0 A_JumpIf(velz > 1, "IdleSound")
Goto BounceDed

BounceDed:
W16X C 1 BRIGHT A_CountDown
Loop


	Death:
	TNT1 A 1 A_NoGravity
MISL B 1 A_AlertMonsters
    TNT1 B 0 A_SpawnItemEx("NewExplosionMedium",0,0,0,0,0,0,0,32)//A_SpawnItemEx("NewExplosionMediumBig",0,0,0,0,0,0,0,32)
		TNT1 A 0 A_PlaySound("explode/Distant", 7)
		TNT1 B 7 Bright A_Explode
		TNT1 C 6 Bright
		TNT1 D 4 Bright
		Stop
	Grenade:
		MISL A 1000 A_Die
		Wait
	Detonate:
	TNT1 A 1 A_NoGravity
MISL B 1 A_AlertMonsters
    TNT1 B 0 A_SpawnItemEx("NewExplosionMedium",0,0,0,0,0,0,0,32)//A_SpawnItemEx("NewExplosionMediumBig",0,0,0,0,0,0,0,32)
		TNT1 A 0 A_PlaySound("explode/Distant", 7)
		TNT1 B 3 A_Scream
PLAY A 0 ACS_ExecuteAlways(807,0,0,0,0)
		TNT1 C 6 A_Detonate
		TNT1 D 10
		Stop
	Mushroom:
		MISL B 8 A_Mushroom
		Goto Death+1
	}
}






//Accurate aim
ACTOR AccurateGrenadeProjectile
{
	Game Doom
	SpawnID 216
	Radius 8
	Height 8
	Speed 25
	Damage 0
	Projectile
	-NOGRAVITY
	+RANDOMIZE
	//+DEHEXPLOSION
	//+GRENADETRAIL
	//+doombounce
	//BounceType "Doom"
//	Gravity 0.25
	//SeeSound "HEGRENADE/BOUNCE"
	//DeathSound "HEGRENADE/EXPLODE"
	//BounceSound "weapons/grbnce"
	Obituary "%o shouldn't have died."
	//DamageType Grenade
    scale 0.2
    Alpha 0.25
    Renderstyle Stencil
    stencilcolor RED
   //ExplosionRadius 192
   //ExplosionDamage 256
  Speed 35
  //BounceFactor 0.7
  ReactionTime 60


	States
	{
	Spawn:
		PLSS B 1 Bright 
		Loop
	Death:
		PLSS B 1 Bright 
		Stop
	}
}
