// --------------------------------------------------------------------------
//
// Flashbang (Demo weapon "Appears on weapons training")
//
// --------------------------------------------------------------------------

ACTOR "Flashbang" : CSDMOWeapon //5010
{

//	+WEAPON.CHEATNOTWEAPON

	Weapon.SelectionOrder 1900
	Weapon.AmmoUse 1
	Weapon.AmmoGive 1
	Weapon.AmmoType "FlashbangAmmo"
	obituary "%k killed %o with Flashbang."
	+WEAPON.WIMPY_WEAPON
	Inventory.Pickupmessage "Picked up a Flashbang."
	Tag "Flashbang"
	Weapon.UpSound "HEGRENADE/Ready"
	AttackSound "HEGRENADE/Fire" 
	Scale 0.2
	 +IGNORESKILL
	 +WEAPON.EXPLOSIVE
	//+NOAUTOFIRE

	States
	{
	Ready:
		W12B I 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 1 A_Print("Test Animation", 0.5)
		TNT1 A 7 A_WEAPONREADY(WRF_NOFIRE)
		W12A JKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W12B ABCDEFGH 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto Ready

	SelectUsed:
TNT1 A 0 A_TakeInventory("Grenade_BlockMemo",1)
		TNT1 A 9 A_PlaySound("HEGRENADE/Ready")
		W12A JKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W12B ABCDEFGH 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")
		W12D ABCDE 1 A_WEAPONREADY(WRF_NOFIRE)
		W12D F 1 A_Refire("Fire_2")
		Goto Throw

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

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

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

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

	Fire_6:
		W12D Z 1 A_WEAPONREADY(WRF_NOFIRE)
		W12E ABCD 1 A_WEAPONREADY(WRF_NOFIRE)
		W12E E 1 A_Refire("Fire_7")
		Goto Throw

	Fire_7:
		W12E EFGH 1 A_WEAPONREADY(WRF_NOFIRE)
		W12E 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
        W12D F 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D G 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D H 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D I 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D J 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D K 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D L 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D M 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D N 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D O 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D P 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D Q 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D R 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D S 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D T 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D U 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D V 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D W 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D X 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D Y 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw
        W12D Z 1 A_WeaponReady(WRF_NOFIRE)		TNT1 A 0 A_Refire(1)		Goto Throw

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

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




	BotFire:
	Throw:
		TNT1 A 4 A_FireCustomMissile(FlashbangProjectile,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


//	AltFire:
//		TNT1 A 0 A_FireCustomMissile(AccurateGRENADEPROJECTILE,0,0,0,3,0,4)
//		W16B J 16 A_WeaponReady
//		Goto Ready


//		W16F ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)



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



	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(FlashbangProjectile,0,1,0,3,0,4)
		Goto LightDone
 	Spawn:
		W12Z A -1
		Stop
	}
}





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




ACTOR FlashbangProjectile
{
	Game Doom
//	SpawnID 216
	Radius 8
	Height 8
	Speed 25
	Damage 2
	Projectile
    BounceType "Hexen"
+USEBOUNCESTATE
+BOUNCEONACTORS
	-NOGRAVITY
//	+RANDOMIZE
  +FORCERADIUSDMG
  +FORCEPAIN
//  	DamageType FLASHBANGFREEZE

//  +DEHEXPLOSION
//	+GRENADETRAIL
//	+doombounce
	//BounceType "Doom"
//	Gravity 0.25
	

	SeeSound "HEGRENADE/BOUNCE"
	DeathSound "flashbang/EXPLODE"
	//BounceSound "weapons/grbnce"
	Obituary "%k killed %o with Flashbang."


scale 0.2

   ExplosionRadius 768
   ExplosionDamage 1
  Speed 35
//  BounceFactor 0.7
  ReactionTime 70

	BounceFactor 0.4
WallBounceFactor 0.35
//BounceCount 2


	States
	{
	Spawn:
		W12X 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:
W12X C 1 BRIGHT A_CountDown
Loop




	Death:
	TNT1 A 1 Light("WhiteSmallPoint3") A_NoGravity
TNT1 A 1 Light("WhiteSmallPoint2") A_AlertMonsters

TNT1 A 0 A_SpawnItemEx("ThrowableFlashbangVisualGFX",0,0,0,0,0,0,0,32)
//TNT1 A 0 A_SpawnItemEx("ThrowableFlashbangVisualGFX",0,0,0,0,0,0,0,32)

		TNT1 A 0 A_PlaySound("flashbangxp/Distant", 7)
		TNT1 B 6 Bright //A_Explode(1,760,XF_HURTSOURCE,0,1520)
		TNT1 C 6 Bright Light("Flashbang")
		TNT1 D 1 Light("WhiteBigPoint1")
		TNT1 D 1 Light("WhiteMediumPoint1")
		TNT1 D 1 Light("WhiteSmallPoint1")
		Stop
	Grenade:
		MISL A 1000 A_Die
		Wait
	Detonate:
	TNT1 A 1 Light("WhiteSmallPoint3") A_NoGravity
TNT1 A 1 Light("WhiteSmallPoint2") A_AlertMonsters


TNT1 A 0 A_SpawnItemEx("ThrowableFlashbangVisualGFX",0,0,0,0,0,0,0,32)
//TNT1 A 0 A_SpawnItemEx("ThrowableFlashbangVisualGFX",0,0,0,0,0,0,0,32)

//    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("flashbangxp/Distant", 7)
		TNT1 B 6 A_Scream
//PLAY A 0 ACS_ExecuteAlways(807,0,0,0,0)
		TNT1 C 6 Light("Flashbang")//A_Explode(1,760,XF_HURTSOURCE,0,1520)

		TNT1 D 1 Light("WhiteBigPoint1")
		TNT1 D 1 Light("WhiteMediumPoint1")
		TNT1 D 1 Light("WhiteSmallPoint1")
		Stop
	Mushroom:
		MISL B 8 A_Mushroom
		Goto Death+1
	}
}







Actor ThrowableFlashbangVisualGFX
{
    SpawnID 201
//    +NOINTERACTION
  +FORCERADIUSDMG
  +FORCEPAIN
  	DamageType FLASHBANGFREEZE
   ExplosionRadius 768
   ExplosionDamage 1

    Radius 11
    Height 8
    RenderStyle Add
    Alpha 1.0
    Scale 0.1
    States
    {
    Spawn:

		tnt1 a 0 //A_SetScale(1.0)
		TNT1 A 0 A_Explode(1,760,XF_HURTSOURCE,0,1520)

		M12P C 0 Bright Light("WhiteSmallPoint1")	A_SetScale(scalex+0.072)
		M12P A 1 Bright Light("WhiteSmallPoint1")	A_FadeOut(0.0725)
		M12P C 0 Bright Light("WhiteMediumpoint1")	A_SetScale(scalex+0.072)
		M12P A 1 Bright Light("WhiteMediumPoint1")	A_FadeOut(0.0725)
		M12P C 0 Bright Light("WhiteMediumPoint1")	A_SetScale(scalex+0.152)
		M12P C 1 Bright Light("WhiteMediumPoint1")	A_FadeOut(0.0725)
		M12P C 0 Bright Light("WhiteMediumPoint1")	A_SetScale(scalex+0.152)
		M12P C 1 Bright Light("WhiteMediumPoint1")	A_FadeOut(0.1725)

		M12P D 0 Bright Light("WhiteBigPoint1") A_SetScale(scalex+0.152)
		M12P C 1 Bright Light("WhiteBigPoint1") A_FadeOut(0.2755)
		M12P D 0 Bright Light("WhiteBigPoint1") A_SetScale(scalex+0.222)
		M12P D 1 Bright Light("WhiteBigPoint1") A_FadeOut(0.2755)
		M12P D 0 Bright Light("WhiteBigPoint1") A_SetScale(scalex+0.222)
		M12P D 1 Bright Light("WhiteBigPoint1") A_FadeOut(0.2755)
		Stop

    }
}




  ACTOR W83GRENADE
{
  Radius 4
  Height 9
  Health 40
   ExplosionRadius 768
   ExplosionDamage 1
  Speed 35
  +FORCERADIUSDMG
  +FORCEPAIN
  	DamageType FLASHBANGFREEZE
  Mass 0
  BounceFactor 0.7
  +DoomBounce
	SeeSound "HEGRENADE/BOUNCE"
	DeathSound "flashbang/EXPLODE"
   //RenderStyle ADD
   //Alpha 1.0
  PROJECTILE
  +CANBOUNCEWATER
  -NOGRAVITY
  ReactionTime 60
  +NOBLOCKMAP 
  +MISSILE 
  Scale 0.5
  States
  {
  Spawn:
    W83I AAAAAA 1 A_Countdown
    Loop
   Death:
   		XP00 A 0 A_NoGravity
		XP00 A 0 A_SetTranslucent(0.9)
		XP00 A 0 A_AlertMonsters
		NGXP A 0 Radius_Quake(4,4,0,16,0)
		TNT1 A 0 A_PlaySound("flashbangxp/Distant", 7)
		//MISL B 0 A_SpawnItemEx("NewExplosionMedium",0,0,0,0,0,0,0,32)
		TNT1 A 4 Bright A_Explode
		//XP00 BCDEFGHIJKLMNOPQRSTU 1 Bright A_FadeOut(0.04)
    Stop
   }
}


