// --------------------------------------------------------------------------
//
//	C-4
//
// --------------------------------------------------------------------------

ACTOR C4Weapon : BaseWeapon
{
	Weapon.AmmoType1 "C4Ammo"
	Weapon.AmmoType2 "C4Ammo"
	Weapon.AmmoGive1 0
	Weapon.AmmoGive2 3
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.SelectionOrder 99999
	-WEAPON.CHEATNOTWEAPON
	Inventory.PickupMessage "You got some C-4 explosives and a detonator!"
	Obituary "%o got exploded into pieces by %k's C-4."
	AttackSound "None"
	Tag "C-4 Explosive"
	Scale 0.3
	States
	{
	Spawn:
		C4EW B -1
		Stop

	Select:
		TNT1 A 0 A_JumpIfInventory("IsPlayingAsPurist",1,"PuristGun")
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1001,6)==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 5
		TNT1 A 0 A_Raise
		Wait

	Deselect:
		TNT1 A 0 A_PlaySound("weapons/changing")
		TNT1 A 0 A_JumpIfInventory("C4Ammo",1,7)
		C4ES JIHGF 1	
		TNT1 A 0 A_Jump(256,6)
		C4ES EDCBA 1
		TNT1 A 0 A_Takeinventory("FistsSelected",1)
		TNT1 A 1 A_TakeInventory("GoThrowC4",1)
		TNT1 A 0 A_Lower
		Wait

	Ready:
		TNT1 A 0 A_JumpIfInventory("GoThrowC4",1,"Throw")
		TNT1 A 0 A_JumpIfInventory("GoFatality",1,"Steady")
	Ready1:
		TNT1 A 0 A_JumpIfInventory("C4Ammo",1,6)
		C4ES FGHIJ 1
		Goto Ready2
		C4ES ABCDE 1
		Goto Ready2
		
	Ready2:
		TNT1 A 0 //A_GunFlash
		TNT1 A 0 A_JumpIfInventory("C4Ammo",1,"ReadyAmmo")
		Goto ReadyNoAmmo

	ReadyNoAmmo:
		TNT1 A 0 A_JumpIfInventory("C4Ammo",1,"PickedUpAmmo")
		TNT1 A 0 A_JumpIfInventory("PlayerIsABot",1,"BotFire")//Bots should detonate charges and then stop using the weapon if there's no ammo left
		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("TossGrenade",1,"TossGrenade")
		C4ER FG 2 A_WeaponReady(WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory("C4Ammo",1,"PickedUpAmmo")
		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("TossGrenade",1,"TossGrenade")
		TNT1 A 0 A_JumpIfInventory("IdleCounter",200,"PlayerIsIdle")
		C4ER HG 2 A_WeaponReady(WRF_NOPRIMARY)
		Loop

	PickedUpAmmo:
		TNT1 A 0 A_GunFlash("PickedUpAmmoFlash")
		C4ER FGHG 2
	ReadyAmmo:
		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("TossGrenade",1,"TossGrenade")
		C4ER AB 2 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("TossGrenade",1,"TossGrenade")
		C4ER CD 2 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("TossGrenade",1,"TossGrenade")
		TNT1 A 0 A_JumpIfInventory("IdleCounter",200,"PlayerIsIdle")
		C4ER E 2 A_WeaponReady
		Loop

	PickedUpAmmoFlash:
		TNT1 AAA 1
		C4ES KLMNO 1
		C4ER A 1
		Stop

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

	Throw:
		TNT1 A 0 A_TakeInventory("GoThrowC4",1)
		TNT1 A 0 A_PlaySound("GRNTOSS")
		C4ET GHIJ 1
		TNT1 A 0 A_FireCustomMissile("ThrowedC4",0,1,0,6)
		TNT1 A 0 A_TakeInventory("C4Ammo",1)
		GRTH MNOPQ 1
		TNT1 A 3 
		Goto Ready1
		
	Fire: //Throw C-4
		TNT1 A 0 A_Jump(128,2)//50% chanse that a bot will detonate C-4 charges
		TNT1 A 0 A_JumpIfInventory("PlayerIsABot",1,"BotFire")
		C4ET ABCDE 1
		TNT1 A 3
		
	Hold:
		TNT1 A 1
		TNT1 A 0 A_JumpIfInventory("PlayerIsABot",1,2)
		TNT1 A 1 A_Refire
		TNT1 A 0 A_PlaySound("GRNTOSS")
		C4ET GHIJ 1
		TNT1 A 0 A_FireCustomMissile("ThrowedC4",0,1,0,6)
		TNT1 A 0 A_TakeInventory("C4Ammo",1)
		GRTH MNOPQ 1
		TNT1 A 3 
		Goto Ready1

	AltFire: //Explode C-4
		//TNT1 A 0 Thing_Projectile(1999,201,0,0,100)
		//TNT1 A 0 Thing_SpawnNoFog(1999,201,0,202)
		TNT1 A 0 A_PlayWeaponSound("BEP")
		TNT1 A 0 ACS_ExecuteAlways(1048,0,0,0,0)
		Goto Ready2
		
	BotFire:
		TNT1 AAAAA 5 A_Recoil(3)//Backoff, so bots don't hurt themself
		TNT1 A 0 A_PlayWeaponSound("BEP")
		TNT1 A 0 ACS_ExecuteAlways(1048,0,0,0,0)
		TNT1 A 0 A_JumpIfInventory("C4Ammo",1,"Ready2")//Check if any ammo left, otherwise bot should switch weapon
		TNT1 A 0 A_SelectWeapon("Rifle")
		TNT1 A 0 A_TakeInventory("C4Weapon",1)//Remove the weapon from bots inventory, so they don't switch back to the weapon
		Goto Ready

// --------------------------------------------------------------------------
//
//	Misc.
//
// --------------------------------------------------------------------------

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

// --------------------------------------------------------------------------
//
//	End stuff
//
// --------------------------------------------------------------------------

	TauntFlash:
		C4ER FGHGFGHGFGHGFGHGFGHFG 2
		Stop

	Taunt:
		TNT1 A 0 A_JumpIfInventory("C4Ammo",1,"Taunt2")
		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 A 1
		TNT1 A 0 A_FireCustomMissile("Taunter",0,0,-1,0)
		TNT1 A 0 A_FireCustomMissile("Taunter",-9,0,-1,0)
		TNT1 A 0 A_FireCustomMissile("Taunter",9,0,-1,0)
		FUCK BCD 1 A_AlertMonsters
		FUCK E 15
		FUCK DCBA 1
		TNT1 A 7
		TNT1 A 0 A_Takeinventory("Taunting",10)
		Goto Ready2

	Taunt2:
		TNT1 A 0 A_JumpIfInventory("GenderFemale",1,3)
		TNT1 A 0 A_PlaySound("FUCK",2)
		TNT1 A 0 A_Jump(256,2)
		TNT1 A 0 A_PlaySound("FTAUNT",2)
		C4FU ABCDE 1
		TNT1 A 0 A_FireCustomMissile("Taunter",0,0,-1,0)
		TNT1 A 0 A_FireCustomMissile("Taunter",-9,0,-1,0)
		TNT1 A 0 A_FireCustomMissile("Taunter",9,0,-1,0)
		TNT1 A 0 A_AlertMonsters
		C4FU FGHIJFGHIJ 2
		C4FU EDCBA 1
		TNT1 A 0 A_Takeinventory("Taunting",10)
		Goto Ready2

	KickFlash:
		TNT1 A 0 A_JumpIfInventory("C4Ammo",1,13)
		C4ES JIHGF 1
		TNT1 A 6
		C4ES FGHIJ 1
		C4ER F 1
		Stop
		C4ES EDCBA 1
		TNT1 A 6
		C4ES ABCDE 1
		C4ER A 1
		Stop

	AirKickFlash:
		TNT1 A 0 A_JumpIfInventory("C4Ammo",1,13)
		C4ES JIHGF 1
		TNT1 A 8
		C4ES FGHIJ 1
		C4ER F 1
		Stop
		C4ES EDCBA 1
		TNT1 A 8
		C4ES ABCDE 1
		C4ER A 1
		Stop

	SlideKickStartFlash:
		TNT1 A 0 A_JumpIfInventory("C4Ammo",1,7)
		C4ES JIHGF 1
		TNT1 A 16
		Stop
		C4ES EDCBA 1
		TNT1 A 16
		Stop

	SlideKickEndFlash:
		TNT1 A 0 A_JumpIfInventory("C4Ammo",1,7)
		C4ES FGHIJ 2
		C4ER F 1
		Stop
		C4ES ABCDE 2
		C4ER A 1
		Stop

	GrenadeFlash:
		TNT1 A 0 A_JumpIfInventory("C4Ammo",1,6)
		C4ES JIHGF 1
		Stop
		C4ES EDCBA 1
		Stop
   }
}

actor C4Explosion
{
	Radius 2
	Height 2
	Speed 0
	SpawnID 201
	+NOBLOCKMAP
	+THRUACTORS
	+MISSILE
	Damagetype ExplosiveImpact
	Obituary "%o got exploded into pieces by %k's C-4."
	States
	{
	Spawn:
		TNT1 A 1
		TNT1 A 0 A_Explode(200,300)
		TNT1 A 0 A_Explode(200,150,0)
		TNT1 A 0 A_SpawnItem("ExplosionLight")
		TNT1 A 0 A_CustomMissile("ExplosionSplashSpawner")
		TNT1 A 0 A_SpawnItemEx("DetectFloorCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_SpawnItemEx("DetectCeilCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_SpawnItemEx("UnderwaterExplosion",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_SpawnItemEx("ExplosionFlareSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_SpawnItemEx("WhiteShockwaveBig",0,0,30,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_SpawnItemEx("C4ExplosionFlame",0,0,30,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_SpawnItemEx("LiquidExplosionEffectSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 AAA 0 A_CustomMissile("ExplosionFlames",0,0,random (0,360),2,random (0,360))
		TNT1 AAAAAAAAAAAAAAAAAAAAAA 0 A_CustomMissile("ExplosionParticleHeavy",0,0,random (0,360),2,random (0,180))
		TNT1 AAAAAA 0 A_CustomMissile("ExplosionParticleHeavy",0,0,random (0,360),2,random (0,180))
		TNT1 A 0 A_CustomMissile("MetalShardz1",5,0,random (0,360),2,random (30,160))
		TNT1 A 0 A_CustomMissile("MetalShardz2",5,0,random (0,360),2,random (30,160))
		TNT1 A 0 A_CustomMissile("MetalShardz3",5,0,random (0,360),2,random (30,160))
		TNT1 A 0 Radius_Quake (4,12,0,15,0)
		TNT1 A 0 A_PlaySound("Explosion",1)
		TNT1 A 0 A_SpawnItem("MonsterAlert",0,-15)
		TNT1 A 0 Thing_ReMove(1999)
		TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_CustomMissile("C4ShrapnelParticle",0,0,random (0,360),2,random (5,90))
		TNT1 A 0 A_PlaySound("FAREXPL",3)
		TNT1 A 0 A_SpawnItem("BarrelExplosionSmokeColumn")
		TNT1 AAAAAAAAAAAAAAA 8 A_CustomMissile("ExplosionSmoke",1,0,random (0,360),2,random (50,130))
		Stop
	}
}

ACTOR C4ExplosionFlame
{
	Scale 2.5
	Radius 0
	Height 0
	RenderStyle Add
	+NOBLOCKMAP
	+NOTELEPORT
	+DONTSPLASH
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 AA 2 A_SpawnItem("RedFlare",0,0)
		BEXP FGHIJKLMNOPQ 1 BRIGHT
		Stop
	}
}

Actor MonsterAlert
{
	Speed 2
	PROJECTILE
	+NOCLIP
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 1 A_AlertMonsters
		Stop
	}
}

ACTOR ThrowedC4 : SwitchableDecoration
{
	Radius 4
	Height 4
	Speed 30
	Gravity 0.7
	Activation THINGSPEC_Activate
	+USESPECIAL
	+MISSILE
	-NOGRAVITY
	-BLOODSPLATTER
	-EXTREMEDEATH
	+EXPLODEONWATER
	+SKYEXPLODE
	+DOOMBOUNCE
	BounceFactor 0.1
	WallBounceFactor 0.1
	Health 5
	SeeSound "GRNBNCE"
	DeathSound "none"
	Obituary "%o got %k's C-4 thrown in his face."
	Damage (random(1,2))
	Scale 0.25
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 Thing_ChangeTid(0,1999)
	Fly:
		C4EP ABCDEFGH 2 BRIGHT A_JumpIf(waterlevel > 1,"UnderWater")
		Loop
	UnderWater:
		TNT1 A 0 A_ChangeVelocity(VelX*0.5,VelY*0.5,VelZ,CVF_REPLACE)
		C4EP ABCD 4 BRIGHT ThrustThingZ(0,5,1,0)
		TNT1 A 0 A_SpawnItem("BUBULZ")
		TNT1 A 0 A_ChangeVelocity(VelX*0.5,VelY*0.5,VelZ,CVF_REPLACE)
		C4EP EFGH 4 BRIGHT ThrustThingZ(0,5,1,0)
		TNT1 A 0 A_SpawnItem("BUBULZ")
		Loop
	Death:
		C4EI ABCDE 2 BRIGHT
		Loop
	Active:
		C4EI ABCDE 2 BRIGHT
		TNT1 A 0 A_SpawnItem("C4Ammo")
		Stop
	Explode:
		TNT1 A 0 A_SpawnItem("C4Explosion")
		C4EP A 1
		Stop
	}
}

ACTOR C4ShrapnelParticle: ExplosionParticleHeavy
{
	speed 20
	Gravity 0.0
	+NOGRAVITY
	Scale 1.0
	radius 10
	height 10
	-DOOMBOUNCE
	Damage 0
	alpha 1.0
	States
	{
	Spawn:
		SPKO BBBBBBBBBBBBBBBBBBBB 1 Bright A_FadeOut(0.05)
		Stop
	Death:
		TNT1 A 0
		Stop
	}
}

Actor GoThrowC4 : Inventory
{
inventory.maxamount 1
}