
//***Che lights are switched by map scripts changing actor states by TID.
// On their own the traffic lights spawn always off


ACTOR TrafficLightPole: LightPosts3 17898 // sprite only, no 3D model
{
	-FORCEXYBILLBOARD
	+FORCEYBILLBOARD
	Radius 4
	Height 96
	Scale 1.0
	States
	{
		Spawn:
			KYTL J 1
			KYTL J -1
			Loop
		Death.Stomp:
			TNT1 A 0
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_SetAngle(angle-180)
		Death:
			TNT1 A 0
			TNT1 A 0 A_PlaySound("POSTFAL", 1)
			TNT1 A 0 A_NoBlocking
			
			// Ugly, yes, but I don't have strength left to make it a normal death like the light posts
			TNT1 AAAA 0 A_CustomMissile ("MetalShard1", random (0, 96), 0, random (0, 360), 2, random (30, 60))
			TNT1 AAAA 0 A_CustomMissile ("MetalShard2", random (0, 96), 0, random (0, 360), 2, random (30, 60))
			TNT1 AAAA 0 A_CustomMissile ("MetalShard3", random (0, 96), 0, random (0, 360), 2, random (30, 60))
			
			TNT1 A -1
			Stop
	}
}


ACTOR TrafficLight 17899
{
	+SOLID
	+SHOOTABLE
	+NOBLOOD
	+NOGRAVITY
	Mass 10000000
	Health 50
	Radius 12
	Height 48
	
	//$Arg1 Pole Tag
	//$Arg1Type 14
	
	/*
    0 = Integer (default)
    4 = Action special
    5 = Sector effect
    8 = Angle in degrees
    10 = XXRRGGBB color
    11 = Enum option
    12 = Enum bits
    13 = Sector tag
    14 = Thing tag
    15 = Linedef tag
    22 = Byte angle
    23 = Thing Radius
    24 = Thing Height
	*/	
	
	States
	{
		Spawn:
		Off:
			KYTL A 1 A_JumpIf(CallAcs("TrafficLightStatterOnPoleDestroyed", args[1]), "Shatter")
				// stoopid Cheb! if you *jump* to death it does not lose health so the switching script
				// keeps resurrecting it because that script check the health!
				//, "Death")
			Loop
// gee thanks for breaking backward compatibility:
// https://forum.drdteam.org/viewtopic.php?f=22&t=6320&hilit=brightmaps			
		RedGzdoom:
			KYTL B 1 A_JumpIf(CallAcs("TrafficLightStatterOnPoleDestroyed", args[1]), "Shatter")
			Loop
		RedZandronum:
			KYTL K 1 A_JumpIf(CallAcs("TrafficLightStatterOnPoleDestroyed", args[1]), "Shatter")
			Loop			
		YellowGzdoom:
			KYTL C 1 A_JumpIf(CallAcs("TrafficLightStatterOnPoleDestroyed", args[1]), "Shatter")
			Loop
		YellowZandronum:
			KYTL L 1 A_JumpIf(CallAcs("TrafficLightStatterOnPoleDestroyed", args[1]), "Shatter")
			Loop			
		GreenGzdoom:
			KYTL D 1 A_JumpIf(CallAcs("TrafficLightStatterOnPoleDestroyed", args[1]), "Shatter")
			Loop
		GreenZandronum:
			KYTL M 1 A_JumpIf(CallAcs("TrafficLightStatterOnPoleDestroyed", args[1]), "Shatter")
			Loop
		DoDie:
			TNT1 A 0 A_Die
		Death:
			// note does NOT stop being solid!
			TNT1 AA 0 A_CustomMissile ("SFXGlassParticle1", random (10, 38), 0, random (-65, 65), 2, random (30, 60))
			TNT1 AA 0 A_CustomMissile ("SFXGlassParticle2", random (10, 38), 0, random (-65, 65), 2, random (30, 60))
			TNT1 AA 0 A_CustomMissile ("SFXGlassParticle3", random (10, 38), 0, random (-65, 65), 2, random (30, 60))
			TNT1 AA 0 A_CustomMissile ("SFXGlassParticle4", random (10, 38), 0, random (-65, 65), 2, random (30, 60))
			TNT1 A 0 A_PlaySound("GLSFAL", 1)
			TNT1 A 0 A_ChangeFlag("NOGRAVITY", 1) // death auto-clears it!
		StayDead:
			KYTL E 1 A_JumpIf(CallAcs("TrafficLightStatterOnPoleDestroyed", args[1]), "Shatter")
			Loop
		Shatter:	
			TNT1 A 0
			TNT1 A 0 A_NoBlocking
			TNT1 AAAAAAAA 0 A_CustomMissile ("MetalShard1", random (0, 32), 0, random (0, 360), 2, random (30, 60))
			TNT1 AAAAAAAA 0 A_CustomMissile ("MetalShard2", random (0, 32), 0, random (0, 360), 2, random (30, 60))
			TNT1 AAAAAAAA 0 A_CustomMissile ("MetalShard3", random (0, 32), 0, random (0, 360), 2, random (30, 60))
			TNT1 A 0 A_PlaySound("DSBRK2", 2)
			TNT1 A 60
			Stop
	}
}


ACTOR DeadTrafficLight: TrafficLight 17940	
{
	Health 500
	States
	{
		Spawn:
			KYTL E 1
			Goto StayDead
		Death:
			KYTL E 0
			KYTL E 0 A_ChangeFlag("NOGRAVITY", 1)
			KYTL E 1 A_NoBlocking
			Goto Shatter
	}	
}

ACTOR PedestrianLight: TrafficLight 17941
{
	Height 35
	States {
		Spawn:
		Off:
		YellowGzdoom:
		YellowZandronum:
			KYTL F 1 A_JumpIf(CallAcs("TrafficLightStatterOnPoleDestroyed", args[1]), "DoDie")
			Loop
		RedGzdoom:
			KYTL G 1 A_JumpIf(CallAcs("TrafficLightStatterOnPoleDestroyed", args[1]), "DoDie")
			Loop
		RedZandronum:	
			KYTL N 1 A_JumpIf(CallAcs("TrafficLightStatterOnPoleDestroyed", args[1]), "DoDie")
			Loop		
		GreenGzdoom:
			KYTL H 1 A_JumpIf(CallAcs("TrafficLightStatterOnPoleDestroyed", args[1]), "DoDie")
			Loop
		GreenZandronum:
			KYTL O 1 A_JumpIf(CallAcs("TrafficLightStatterOnPoleDestroyed", args[1]), "DoDie")
			Loop			
		Death:
			// note does NOT stop being solid!
			TNT1 AA 0 A_CustomMissile ("SFXGlassParticle1", random (10, 25), 0, random (-65, 65), 2, random (30, 60))
			TNT1 AA 0 A_CustomMissile ("SFXGlassParticle2", random (10, 25), 0, random (-65, 65), 2, random (30, 60))
			TNT1 AA 0 A_CustomMissile ("SFXGlassParticle3", random (10, 25), 0, random (-65, 65), 2, random (30, 60))
			TNT1 AA 0 A_CustomMissile ("SFXGlassParticle4", random (10, 25), 0, random (-65, 65), 2, random (30, 60))
			TNT1 A 0 A_PlaySound("GLSFAL", 1)
			TNT1 A 0 A_ChangeFlag("NOGRAVITY", 1)
		StayDead:
			KYTL I 1 A_JumpIf(CallAcs("TrafficLightStatterOnPoleDestroyed", args[1]), "Shatter")
			Loop			
		
	}
}

ACTOR DeadPedestrianLight: PedestrianLight 17942	
{
	Health 500
	States
	{
		Spawn:
			KYTL I 1
			Goto StayDead
		Death:
			KYTL I 0
			KYTL I 0 A_ChangeFlag("NOGRAVITY", 1)
			KYTL I 1 A_NoBlocking
			Goto Shatter
	}	
}