actor G2_BaseTorch : G2_BaseLight {
	+SOLID
	+SHOOTABLE
	+NOBLOOD
	-NODAMAGE
	-NOGRAVITY

	+ISMONSTER

	health 99995
	painchance 255

	States {
		Spawn:
		Spawn_Server:
			TNT1 A 0
		On_Finish:
		Spawn_Event:
			TNT1 A 0 A_GiveInventory("G2_IsTorch", 1)
			TNT1 A 0 A_SetInvulnerable
			TNT1 A 0 Thing_ChangeTID(0, 3500 + ((random(x, x) + 10000) / 1000) + (((random(y, y) + 10000) / 1000) * 20))
			TNT1 A 0 ACS_NamedExecuteWithResult("light_spawnState")
			fail
		Flicker_Server:
		Flicker_Event:
			TNT1 A 0 Thing_ChangeTID(0, 3497)
			TNT1 A 0 ACS_NamedExecuteWithResult("light_flickerState")
			fail

		//Torches can't be broken
		Break_Server:
		Break_Event:
		Off_Server:
		Off_Event:
		TurnOff_Event:
		TurnOff_Server:
			TNT1 A 0 Thing_ChangeTID(0, 3496)
			TNT1 A 0 A_UnsetInvulnerable
			TNT1 A 0 ACS_NamedExecuteWithResult("light_offState")
			fail

		On_Server:
		On_Event:
			TNT1 A 0 A_SetInvulnerable
			TNT1 A 0 Thing_ChangeTID(0, 3500 + ((random(x, x) + 10000) / 1000) + (((random(y, y) + 10000) / 1000) * 20))
			TNT1 A 0 ACS_NamedExecuteWithResult("light_onState")
			fail

		Pain.Fire:
			TNT1 A 0 ACS_NamedExecuteWithResult("light_torchIgnite")
		Ignite_Server:
			TNT1 A 0 ACS_NamedExecuteWithResult("light_onTorchIgnite")
		Ignite_Event:
			TNT1 A 0 Thing_ChangeTID(0, 3500 + ((random(x, x) + 10000) / 1000) + (((random(y, y) + 10000) / 1000) * 20))
			TNT1 A 0 A_SetInvulnerable
			TNT1 A 0 ACS_NamedExecuteWithResult("light_igniteState")
			fail
	}
}

actor G2_RedTorch : G2_BaseTorch replaces RedTorch {
	radius 6
	height 46
	
	States {
		Ignite_Client:
			TRED F 0 A_PlaySound("vile/firestrt", CHAN_7)
			TRED FFFFFF 1 A_SpawnItemEx("G2_RedFlame", frandom(-0.5, 0.5), frandom(-0.5, 0.5), random(54,56), FRandom(-0.75, 0.75), FRandom(-0.75, 0.75), FRandom(1, 2), 0, SXF_CLIENTSIDE)
		Spawn_Client:
			TRED E 1 A_SetTics(Random(1, 8))
			TRED E 0 A_PlaySound("Global/Fire", CHAN_6, 1.0, true)
			TRED E 0 A_RemoveChildren(true)
			TRED E 0 A_JumpIf(ACS_NamedExecuteWithResult("g2_torchQuality") == 0, "Spawn_ClientPotato")
			TRED EE 16 A_SpawnItemEx("G2_RedTorchFlame", frandom(-0.5, 0.5), frandom(-0.5, 0.5), random(60,62),0,0, 0.25,0, SXF_CLIENTSIDE | SXF_NOCHECKPOSITION | SXF_SETMASTER)
			Goto Spawn_ClientLoop
		Spawn_ClientLoop:
			TRED F -1
			loop
		Spawn_ClientPotato:
			TRED E -1
			loop
		SpawnDistant_Client:
			TRED A 0 A_RemoveChildren(true)
			TRED A 0 bright A_StopSound(CHAN_6)
			TRED A 0 bright A_StopSound(CHAN_7)
			Goto Spawn_ClientPotato

		Flicker_Client:
			TRED F 0 A_RemoveChildren(true)
			TRED F 30 A_SpawnItemEx("G2_RedFlame", frandom(-0.5, 0.5), frandom(-0.5, 0.5), random(54,56),0,0,1,0, SXF_CLIENTSIDE)
			loop

		Break_Client:
		Off_Client:
			TRED F 0 A_RemoveChildren(true)
			TRED F 0 A_StopSound(CHAN_6)
			TRED F 0 A_PlaySound("vile/firestrt", CHAN_7)
			TRED FFFFFF 1 A_SpawnItemEx("G2_RedFlame", frandom(-0.5, 0.5), frandom(-0.5, 0.5), random(54,56), FRandom(-0.75, 0.75), FRandom(-0.75, 0.75), FRandom(1, 2), 0, SXF_CLIENTSIDE)
			TRED F -1
			loop

		On_Client:
			TRED F 0
			TRED F 0 A_RemoveChildren(true)
			goto On_Finish
	}
}

actor G2_SmallRedTorch : G2_BaseTorch replaces ShortRedTorch
{
	radius 5
	height 40

	States {
		Ignite_Client:
			SMRT F 0 A_PlaySound("vile/firestrt", CHAN_7)
			SMRT FFFFFF 1 A_SpawnItemEx("G2_RedFlame", FRandom(-0.5, 0.5), FRandom(-0.5, 0.5), random(32,36), FRandom(-0.75, 0.75), FRandom(-0.75, 0.75), FRandom(1, 2), 0, SXF_CLIENTSIDE)
		Spawn_Client:
			SMRT E 1 A_SetTics(Random(1, 8))
			SMRT E 0 A_PlaySound("Global/Fire", CHAN_6, 1.0, true)
			SMRT E 0 A_RemoveChildren(true)
			SMRT E 0 A_JumpIf(ACS_NamedExecuteWithResult("g2_torchQuality") == 0, "Spawn_ClientPotato")
			SMRT EE 16 A_SpawnItemEx("G2_RedTorchFlame", frandom(-0.5, 0.5), frandom(-0.5, 0.5), random(37,39),0,0, 0.25,0, SXF_CLIENTSIDE | SXF_NOCHECKPOSITION | SXF_SETMASTER)
			Goto Spawn_ClientLoop
		Spawn_ClientLoop:
			SMRT F -1
			loop
		Spawn_ClientPotato:
			SMRT E -1
			loop
		SpawnDistant_Client:
			SMRT E 0 A_RemoveChildren(true)
			SMRT E 0 bright A_StopSound(CHAN_6)
			SMRT E 0 bright A_StopSound(CHAN_7)
			Goto Spawn_ClientPotato

		Flicker_Client:
			SMRT F 0 A_RemoveChildren(true)
			SMRT F 30 A_SpawnItemEx("G2_RedFlame", FRandom(-0.5, 0.5), FRandom(-0.5, 0.5), random(32,36),0,0,1,0, SXF_CLIENTSIDE)
			loop

		Break_Client:
		Off_Client:
			SMRT F 0 A_RemoveChildren(true)
			SMRT F 0 A_StopSound(CHAN_6)
			SMRT F 0 A_PlaySound("vile/firestrt", CHAN_7)
			SMRT FFFFFF 1 A_SpawnItemEx("G2_RedFlame", FRandom(-0.5, 0.5), FRandom(-0.5, 0.5), random(32,36), FRandom(-0.75, 0.75), FRandom(-0.75, 0.75), FRandom(1, 2), 0, SXF_CLIENTSIDE)
			SMRT F -1
			loop

		On_Client:
			SMRT F 0
			SMRT F 0 A_RemoveChildren(true)
			goto On_Finish
	}
}


actor G2_BlueTorch : G2_RedTorch replaces BlueTorch {
	radius 6
	height 46
	
	States {
		Ignite_Client:
			TRED F 0 A_PlaySound("vile/firestrt", CHAN_7)
			TRED FFFFFF 1 A_SpawnItemEx("G2_BlueFlame", frandom(-0.5, 0.5), frandom(-0.5, 0.5), random(54,56), FRandom(-0.75, 0.75), FRandom(-0.75, 0.75), FRandom(1, 2), 0, SXF_CLIENTSIDE)
		Spawn_Client:
			TRED E 1 A_SetTics(Random(1, 8))
			TRED E 0 A_PlaySound("Global/Fire", CHAN_6, 1.0, true)
			TRED E 0 A_RemoveChildren(true)
			TRED E 0 A_JumpIf(ACS_NamedExecuteWithResult("g2_torchQuality") == 0, "Spawn_ClientPotato")
			TRED EE 16 A_SpawnItemEx("G2_BlueTorchFlame", frandom(-0.5, 0.5), frandom(-0.5, 0.5), random(60,62),0,0, 0.25,0, SXF_CLIENTSIDE | SXF_NOCHECKPOSITION | SXF_SETMASTER)
			Goto Spawn_ClientLoop
		Spawn_ClientLoop:
			TRED F -1
			loop
		Spawn_ClientPotato:
			TRED E -1
			loop
		SpawnDistant_Client:
			TRED A 0 A_RemoveChildren(true)
			TRED A 0 bright A_StopSound(CHAN_6)
			TRED A 0 bright A_StopSound(CHAN_7)
			Goto Spawn_ClientPotato

		Flicker_Client:
			TRED F 0 A_RemoveChildren(true)
			TRED F 30 A_SpawnItemEx("G2_BlueFlame", frandom(-0.5, 0.5), frandom(-0.5, 0.5), random(54,56),0,0,1,0, SXF_CLIENTSIDE)
			loop

		Break_Client:
		Off_Client:
			TRED F 0 A_RemoveChildren(true)
			TRED F 0 A_StopSound(CHAN_6)
			TRED F 0 A_PlaySound("vile/firestrt", CHAN_7)
			TRED FFFFFF 1 A_SpawnItemEx("G2_BlueFlame", frandom(-0.5, 0.5), frandom(-0.5, 0.5), random(54,56), FRandom(-0.75, 0.75), FRandom(-0.75, 0.75), FRandom(1, 2), 0, SXF_CLIENTSIDE)
			TRED F -1
			loop

		On_Client:
			TRED F 0
			TRED F 0 A_RemoveChildren(true)
			goto On_Finish
	}
}

actor G2_SmallBlueTorch : G2_SmallRedTorch replaces ShortBlueTorch
{
	radius 5
	height 40

	States {
		Ignite_Client:
			SMRT F 0 A_PlaySound("vile/firestrt", CHAN_7)
			SMRT FFFFFF 1 A_SpawnItemEx("G2_BlueFlame", FRandom(-0.5, 0.5), FRandom(-0.5, 0.5), random(32,36), FRandom(-0.75, 0.75), FRandom(-0.75, 0.75), FRandom(1, 2), 0, SXF_CLIENTSIDE)
		Spawn_Client:
			SMRT E 1 A_SetTics(Random(1, 8))
			SMRT E 0 A_PlaySound("Global/Fire", CHAN_6, 1.0, true)
			SMRT E 0 A_RemoveChildren(true)
			SMRT E 0 A_JumpIf(ACS_NamedExecuteWithResult("g2_torchQuality") == 0, "Spawn_ClientPotato")
			SMRT EE 16 A_SpawnItemEx("G2_BlueTorchFlame", frandom(-0.5, 0.5), frandom(-0.5, 0.5), random(37,39),0,0, 0.25,0, SXF_CLIENTSIDE | SXF_NOCHECKPOSITION | SXF_SETMASTER)
			Goto Spawn_ClientLoop
		Spawn_ClientLoop:
			SMRT F -1
			loop
		Spawn_ClientPotato:
			SMRT E -1
			loop
		SpawnDistant_Client:
			SMRT E 0 A_RemoveChildren(true)
			SMRT E 0 bright A_StopSound(CHAN_6)
			SMRT E 0 bright A_StopSound(CHAN_7)
			Goto Spawn_ClientPotato

		Flicker_Client:
			SMRT F 0 A_RemoveChildren(true)
			SMRT F 30 A_SpawnItemEx("G2_BlueFlame", FRandom(-0.5, 0.5), FRandom(-0.5, 0.5), random(32,36),0,0,1,0, SXF_CLIENTSIDE)
			loop

		Break_Client:
		Off_Client:
			SMRT F 0 A_RemoveChildren(true)
			SMRT F 0 A_StopSound(CHAN_6)
			SMRT F 0 A_PlaySound("vile/firestrt", CHAN_7)
			SMRT FFFFFF 1 A_SpawnItemEx("G2_BlueFlame", FRandom(-0.5, 0.5), FRandom(-0.5, 0.5), random(32,36), FRandom(-0.75, 0.75), FRandom(-0.75, 0.75), FRandom(1, 2), 0, SXF_CLIENTSIDE)
			SMRT F -1
			loop

		On_Client:
			SMRT F 0
			SMRT F 0 A_RemoveChildren(true)
			goto On_Finish
	}
}

//
// White torch
//

actor G2_WhiteTorch : G2_BaseTorch 28010 {
	radius 6
	height 46
	
	States {
		Ignite_Client:
			TRED F 0 A_PlaySound("vile/firestrt", CHAN_7)
			TRED FFFFFF 1 A_SpawnItemEx("G2_WhiteFlame", frandom(-0.5, 0.5), frandom(-0.5, 0.5), random(54,56), FRandom(-0.75, 0.75), FRandom(-0.75, 0.75), FRandom(1, 2), 0, SXF_CLIENTSIDE)
		Spawn_Client:
			TRED E 1 A_SetTics(Random(1, 8))
			TRED E 0 A_PlaySound("Global/Fire", CHAN_6, 1.0, true)
			TRED E 0 A_RemoveChildren(true)
			TRED E 0 A_JumpIf(ACS_NamedExecuteWithResult("g2_torchQuality") == 0, "Spawn_ClientPotato")
			TRED EE 16 A_SpawnItemEx("G2_WhiteTorchFlame", frandom(-0.5, 0.5), frandom(-0.5, 0.5), random(60,62),0,0, 0.25,0, SXF_CLIENTSIDE | SXF_NOCHECKPOSITION | SXF_SETMASTER)
			Goto Spawn_ClientLoop
		Spawn_ClientLoop:
			TRED F -1
			loop
		Spawn_ClientPotato:
			TRED E -1
			loop
		SpawnDistant_Client:
			TRED A 0 A_RemoveChildren(true)
			TRED A 0 bright A_StopSound(CHAN_6)
			TRED A 0 bright A_StopSound(CHAN_7)
			Goto Spawn_ClientPotato

		Flicker_Client:
			TRED F 0 A_RemoveChildren(true)
			TRED F 30 A_SpawnItemEx("G2_WhiteFlame", frandom(-0.5, 0.5), frandom(-0.5, 0.5), random(54,56),0,0,1,0, SXF_CLIENTSIDE)
			loop

		Break_Client:
		Off_Client:
			TRED F 0 A_RemoveChildren(true)
			TRED F 0 A_StopSound(CHAN_6)
			TRED F 0 A_PlaySound("vile/firestrt", CHAN_7)
			TRED FFFFFF 1 A_SpawnItemEx("G2_WhiteFlame", frandom(-0.5, 0.5), frandom(-0.5, 0.5), random(54,56), FRandom(-0.75, 0.75), FRandom(-0.75, 0.75), FRandom(1, 2), 0, SXF_CLIENTSIDE)
			TRED F -1
			loop

		On_Client:
			TRED F 0
			TRED F 0 A_RemoveChildren(true)
			goto On_Finish
	}
}

actor G2_SmallWhiteTorch : G2_BaseTorch 28011
{
	radius 5
	height 40

	States {
		Ignite_Client:
			SMRT F 0 A_PlaySound("vile/firestrt", CHAN_7)
			SMRT FFFFFF 1 A_SpawnItemEx("G2_WhiteFlame", FRandom(-0.5, 0.5), FRandom(-0.5, 0.5), random(32,36), FRandom(-0.75, 0.75), FRandom(-0.75, 0.75), FRandom(1, 2), 0, SXF_CLIENTSIDE)
		Spawn_Client:
			SMRT E 1 A_SetTics(Random(1, 8))
			SMRT E 0 A_PlaySound("Global/Fire", CHAN_6, 1.0, true)
			SMRT E 0 A_RemoveChildren(true)
			SMRT E 0 A_JumpIf(ACS_NamedExecuteWithResult("g2_torchQuality") == 0, "Spawn_ClientPotato")
			SMRT EE 16 A_SpawnItemEx("G2_WhiteTorchFlame", frandom(-0.5, 0.5), frandom(-0.5, 0.5), random(37,39),0,0, 0.25,0, SXF_CLIENTSIDE | SXF_NOCHECKPOSITION | SXF_SETMASTER)
			Goto Spawn_ClientLoop
		Spawn_ClientLoop:
			SMRT F -1
			loop
		Spawn_ClientPotato:
			SMRT E -1
			loop
		SpawnDistant_Client:
			SMRT E 0 A_RemoveChildren(true)
			SMRT E 0 bright A_StopSound(CHAN_6)
			SMRT E 0 bright A_StopSound(CHAN_7)
			Goto Spawn_ClientPotato

		Flicker_Client:
			SMRT F 0 A_RemoveChildren(true)
			SMRT F 30 A_SpawnItemEx("G2_WhiteFlame", FRandom(-0.5, 0.5), FRandom(-0.5, 0.5), random(32,36),0,0,1,0, SXF_CLIENTSIDE)
			loop

		Break_Client:
		Off_Client:
			SMRT F 0 A_RemoveChildren(true)
			SMRT F 0 A_StopSound(CHAN_6)
			SMRT F 0 A_PlaySound("vile/firestrt", CHAN_7)
			SMRT FFFFFF 1 A_SpawnItemEx("G2_WhiteFlame", FRandom(-0.5, 0.5), FRandom(-0.5, 0.5), random(32,36), FRandom(-0.75, 0.75), FRandom(-0.75, 0.75), FRandom(1, 2), 0, SXF_CLIENTSIDE)
			SMRT F -1
			loop

		On_Client:
			SMRT F 0
			SMRT F 0 A_RemoveChildren(true)
			goto On_Finish
	}
}
