// TIMED C4
actor TimedC4 : InventoryItem {
	Tag "Timed C4"
	Inventory.MaxAmount 4
	Inventory.Icon "TMC4ICON"
	states {
	Use:
		TNT1 A 0 A_JumpIfInventory ("IsMech", 1, "Use.Mech")
		TNT1 A 0 A_JumpIf (!ACS_ExecuteWithResult(830), "Failure")
		TNT1 A 0 A_JumpIfInventory ("IsInSpawnRoom", 1, "Failure")
		TNT1 A 0 A_JumpIfInventory ("PowerBerserk", 1, "Failure")
		TNT1 A 0 A_JumpIfInventory ("StealthMode", 1, "Destealth")
		TNT1 A 0 A_PlaySound ("c4/use", CHAN_AUTO)
		TNT1 A 0 A_JumpIfInventory ("EnhancedTimedC4", 1, "UseEnhanced")
		TNT1 A 0 A_JumpIfInventory ("IsBlue", 1, "UseBlue")
		TNT1 A 0 A_FireCustomMissile ("TimedC4Thrown", 0, 0)
		stop
	UseEnhanced:
		TNT1 A 0 A_JumpIfInventory ("IsBlue", 1, "UseEnhancedBlue")
		TNT1 A 0 A_FireCustomMissile ("TimedC4ThrownE", 0, 0)
		stop
	UseBlue:
		TNT1 A 0 A_FireCustomMissile ("TimedC4ThrownBlue", 0, 0)
		stop
	UseEnhancedBlue:
		TNT1 A 0 A_FireCustomMissile ("TimedC4ThrownEBlue", 0, 0)
		stop
	}
}

actor TimedC4Thrown {
	PROJECTILE
	-NOGRAVITY
	+THRUGHOST
	Radius 6
	Height 8
	Speed 30
	Damage 0
	Gravity 0.5
	Scale 0.114
	Translation "112:127=224:246"
	States {
	Spawn:
		TC4T R 2 A_JumpIf (waterlevel > 1, "Water")
		wait
	Death:
		TNT1 A 0
		TNT1 A 0 A_SpawnItemEx("TimedC4Armed", 0,0,0, 0,0,0, 0, SXF_TRANSFERPOINTERS|SXF_NOCHECKPOSITION|SXF_TRANSFERTRANSLATION)
		TNT1 A 4
		stop
	Water:
		TC4T R 35 A_PlaySound("c4/disarm")
		TC4T R 1 A_Fadeout(0.1) 
		Wait
	}
}

actor TimedC4ThrownBlue : TimedC4Thrown {
	Translation "112:127=192:207"
	states {
	Spawn:
		TC4T B 2 A_JumpIf (waterlevel > 1, "Water")
		wait
	Death:
		TNT1 A 0
		TNT1 A 0 A_SpawnItemEx("TimedC4ArmedBlue", 0,0,0, 0,0,0, 0, SXF_TRANSFERPOINTERS|SXF_NOCHECKPOSITION|SXF_TRANSFERTRANSLATION)
		TNT1 A 4
		stop
	Water:
		TC4T B 35 A_PlaySound("c4/disarm")
		TC4T B 1 A_Fadeout(0.1) 
		Wait
	}
}

actor TimedC4Armed 
{
	+NOEXTREMEDEATH
	+NOGRAVITY
	+SHOOTABLE
	+THRUGHOST
	+NOBLOOD
	+NOTARGETSWITCH
	Radius 12
	Height 18
	Scale 0.114
	Health 500
	Mass 0x7FFFFFFF
	DamageType "Explosion"

	DamageFactor "Flash",			0.0
	DamageFactor "Fist",			0.0
	DamageFactor "Knife",			0.5
	DamageFactor "Bullet",			0.0
	DamageFactor "Rifle",			0.0
	DamageFactor "Explosion",		0.0
	DamageFactor "MassDriver",		0.0
	DamageFactor "AntiArmor",		0.0
	DamageFactor "Mine",			0.0
	DamageFactor "Fire",			0.0
	DamageFactor "FireSpecial",		0.0
	DamageFactor "Chemical",		0.0
	DamageFactor "ChemicalSpecial",	0.0
	DamageFactor "Energy",			0.0
	DamageFactor "Plasma",			0.0
	DamageFactor "EnergyDecay",		0.0
	DamageFactor "Ice",				0.0
	DamageFactor "Time",			0.0
	DamageFactor "Suicide",         0.0
	DamageFactor "Superweapon",		0.0
	DamageFactor "Disarm",			1.0
	DamageFactor "Deconstruction",	0.0
	DamageFactor "Mechstomp",		0.0
	DamageFactor "Monster",			0.0

	DamageFactor "Terrorist", 0.0 // Its still used?
	obituary "%o was too close %k Timed C4."
	
	states {
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_JumpIf (waterlevel > 1, "Death.Disarm")
		TNT1 A 0 A_JumpIf (!ACS_ExecuteWithResult(831, 1), "Death.Disarm")
		TC4T R 35 Thing_SetSpecial (0, 226, 328, 0, 1)
		goto Idle
	Idle:
		"----" RRRRRRRRRRRRRRR 35 A_PlaySound ("c4/beep2")
		"----" R 0 A_JumpIf (waterlevel > 1, "Death.Disarm")
		"----" RRRRRRRRRRRRR 35 A_PlaySound ("c4/beep2")
		"----" R 0 A_PlaySound ("c4/detonate", CHAN_WEAPON)
		"----" R 50 A_PlaySound ("c4/detonate")
		//"----" R 0 A_Die
		Goto Death
	Death:
		TNT1 A 0 A_NoBlocking
		TNT1 A 0 A_SpawnItemEx ("ExplosionMainLarge")
		TNT1 A 0 A_PlaySound ("weapons/rocklx")
		TNT1 A 0 A_PlaySound ("weapons/rocklx", CHAN_WEAPON)
		TNT1 AAAA 0 A_SpawnItemEx ("FlameWallDecay", random(-48,48), random(-48,48), 4, 0, 0, 0, 0, SXF_TRANSFERPOINTERS) // [TT] No more team damage from C4 flames
		
		TNT1 A 0 bright A_Explode (500, 256)
		TNT1 A 0 bright A_Explode (800, 64)
		TNT1 A 0 bright A_Explode (700, 128)
		TNT1 A 0 bright A_Explode (700, 256)
		
		TNT1 AAAAAAAAAAAAAAAAAAAA 0 bright A_Explode (5, 16)
		/*TNT1 A 0 A_PlaySound("fire/fire", 4, 1, TRUE) // [TT] Sound fixer
		TNT1 A 0 A_PlaySound("fire/fire", 5, 1, TRUE) // [TT] Sound fixer
		TNT1 A 0 A_PlaySound("fire/fire", 6, 1, TRUE) // [TT] Sound fixer
		TNT1 A 0 A_PlaySound("fire/fire", 7, 1, TRUE) // [TT] Sound fixer
		TNT1 A 0 a_changeflag("NODAMAGETHRUST", TRUE)
		//TNT1 AAAAAAAAAAAAAAAAAAAAAA 16 A_Explode (20, 200, 1) // [TT] Damage comes from the c4 itself now, not the flame class
		TNT1 A 0 a_stopsound(4)
		TNT1 A 0 a_stopsound(5)
		TNT1 A 0 a_stopsound(6)
		TNT1 A 0 a_stopsound(7)*/
		stop
	Death.Knife:
	Death.Disarm:
		TC4T R 35 A_PlaySound ("c4/disarm")
		TC4T R 1 A_Fadeout (0.1) 
		wait
	}
}

actor TimedC4ArmedBlue : TimedC4Armed 
{
	states 
	{
		Spawn:
			TC4T BB 0 A_JumpIf (waterlevel > 1, "Death.Disarm")
			TNT1 A 0 A_JumpIf (!ACS_ExecuteWithResult(831, 0), "Death.Disarm")
			TC4T B 35 Thing_SetSpecial (0, 226, 328, 0, 0)
			goto Idle
		Death:
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItemEx ("ExplosionMainLarge")
			TNT1 A 0 A_PlaySound ("weapons/rocklx")
			TNT1 A 0 A_PlaySound ("weapons/rocklx", CHAN_WEAPON)
			TNT1 AAAA 0 A_SpawnItemEx ("FlameWallDecay", random(-48,48), random(-48,48), 4, 0, 0, 0, 0, SXF_TRANSFERPOINTERS) // [TT] No more team damage from C4 flames
			
			TNT1 A 0 bright A_Explode (500, 256)
			TNT1 A 0 bright A_Explode (800, 64)
			TNT1 A 0 bright A_Explode (700, 128)
			TNT1 A 0 bright A_Explode (700, 256)
			
			TNT1 AAAAAAAAAAAAAAAAAAAA 0 bright A_Explode (5, 16)
			/*TNT1 A 0 A_PlaySound("fire/fire", 4, 1, TRUE) // [TT] Sound fixer
			TNT1 A 0 A_PlaySound("fire/fire", 5, 1, TRUE) // [TT] Sound fixer
			TNT1 A 0 A_PlaySound("fire/fire", 6, 1, TRUE) // [TT] Sound fixer
			TNT1 A 0 A_PlaySound("fire/fire", 7, 1, TRUE) // [TT] Sound fixer
			TNT1 A 0 a_changeflag("NODAMAGETHRUST", TRUE)
			//TNT1 AAAAAAAAAAAAAAAAAAAAAA 16 A_Explode (20, 200, 1) // [TT] Damage comes from the c4 itself now, not the flame class
			TNT1 A 0 a_stopsound(4)
			TNT1 A 0 a_stopsound(5)
			TNT1 A 0 a_stopsound(6)
			TNT1 A 0 a_stopsound(7)*/
			stop
		Death.Disarm:  
			TC4T B 35 A_PlaySound ("c4/disarm")
			TC4T B 1 A_Fadeout (0.1) 
			wait
	}
}

actor TimedC4Count : Inventory {inventory.maxamount 4}
actor EnhancedTimedC4 : Inventory {}

actor TimedC4ThrownE : TimedC4Thrown {
	Translation "1:32=16:32", "112:127=224:246"
	states {
	Death:
		TC4T A 0
		TC4T A 0 A_SpawnItemEx ("TimedC4ArmedE", 0,0,0, 0,0,0, 0,
			SXF_NOCHECKPOSITION|SXF_TRANSFERTRANSLATION|SXF_TRANSFERPOINTERS)
		TNT1 A 4 bright 
		stop
	}
}

actor TimedC4ArmedE : TimedC4Armed
{
	Health 700
	
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_JumpIf (waterlevel > 1, "Death.Disarm")
		TNT1 A 0 A_JumpIf (!ACS_ExecuteWithResult(831, 1), "Death.Disarm")
		TC4T R 35 Thing_SetSpecial (0, 226, 328, 0, 1)
		goto Idle
	Idle:
		"----" RRRRRRRRRRRRRRR 35 A_PlaySound ("c4/beep2")
		"----" R 0 A_JumpIf (waterlevel > 1, "Death.Disarm")
		"----" RRRRRRRRRRRRR 35 A_PlaySound ("c4/beep2")
		"----" R 0 A_PlaySound ("c4/detonate", CHAN_WEAPON)
		"----" R 50 A_PlaySound ("c4/detonate")
		//"----" R 0 A_Die
		Goto Death
	Death:
		TNT1 A 0 A_NoBlocking
		TNT1 A 0 A_SpawnItemEx ("ExplosionMainLarge")
		TNT1 A 0 A_PlaySound ("weapons/rocklx")
		TNT1 A 0 A_PlaySound ("weapons/rocklx", CHAN_WEAPON)
		TNT1 AAAA 0 A_SpawnItemEx ("FlameWallDecay", random(-48,48), random(-48,48), 4, 0, 0, 0, 0, SXF_TRANSFERPOINTERS) // [TT] No more team damage from C4 flames
		
		TNT1 A 0 bright A_Explode (600, 256)
		TNT1 A 0 bright A_Explode (850, 64)
		TNT1 A 0 bright A_Explode (800, 128)
		TNT1 A 0 bright A_Explode (750, 256)
		
		TNT1 AAAAAAAAAAAAAAAAAAAA 0 bright A_Explode (5, 16)
		Stop
	}
}

actor TimedC4ThrownEBlue : TimedC4ThrownBlue {
	Translation "1:39=16:39", "112:127=192:207"
	States {
	Death:
		TNT1 A 0
		TNT1 A 0 A_SpawnItemEx ("TimedC4ArmedEBlue", 0,0,0, 0,0,0, 0,
			SXF_NOCHECKPOSITION|SXF_TRANSFERTRANSLATION|SXF_TRANSFERPOINTERS)
		TNT1 A 4
		stop
	}
}

actor TimedC4ArmedEBlue : TimedC4ArmedBlue
{
	Health 700
	
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_JumpIf (waterlevel > 1, "Death.Disarm")
		TNT1 A 0 A_JumpIf (!ACS_ExecuteWithResult(831, 0), "Death.Disarm")
		TC4T B 35 Thing_SetSpecial (0, 226, 328, 0, 1)
		goto Idle
	Idle:
		"----" BBBBBBBBBBBBBBB 35 A_PlaySound ("c4/beep2")
		"----" R 0 A_JumpIf (waterlevel > 1, "Death.Disarm")
		"----" BBBBBBBBBBBBB 35 A_PlaySound ("c4/beep2")
		"----" R 0 A_PlaySound ("c4/detonate", CHAN_WEAPON)
		"----" B 50 A_PlaySound ("c4/detonate")
		//"----" R 0 A_Die
		Goto Death
	Death:
		TNT1 A 0 A_NoBlocking
		TNT1 A 0 A_SpawnItemEx ("ExplosionMainLarge")
		TNT1 A 0 A_PlaySound ("weapons/rocklx")
		TNT1 A 0 A_PlaySound ("weapons/rocklx", CHAN_WEAPON)
		TNT1 AAAA 0 A_SpawnItemEx ("FlameWallDecay", random(-48,48), random(-48,48), 4, 0, 0, 0, 0, SXF_TRANSFERPOINTERS) // [TT] No more team damage from C4 flames
		
		TNT1 A 0 bright A_Explode (600, 256)
		TNT1 A 0 bright A_Explode (850, 64)
		TNT1 A 0 bright A_Explode (800, 128)
		TNT1 A 0 bright A_Explode (750, 256)
		
		TNT1 AAAAAAAAAAAAAAAAAAAA 0 bright A_Explode (5, 16)
		Stop
	}
}
