// Flares -----------------------------------------------------------------------------------------

Actor TorchFlareBase
{
  +ForceXYBillboard
  +RelativeToFloor
  +NoGravity
  RenderStyle Add
  Height 2
  Radius 2
}

Actor RedFlare : TorchFlareBase
{
  Scale 0.3
  Alpha 0.5
  States
  {
  Spawn:
    RFLR A -1 Bright
    Stop
  }
}

Actor BlueFlare : RedFlare
{
  States
  {
  Spawn:
    RFLB A -1 Bright
    Stop
  }
}

Actor GreenFlare : RedFlare
{
  States
  {
  Spawn:
    RFLG B -1 Bright
    Stop
  }
}

Actor YellowFlare : RedFlare
{
  States
  {
  Spawn:
    RFLY A -1 Bright
    Stop
  }
}

Actor RedFlareFade : RedFlare
{
  Alpha 0
  States
  {
  Spawn:
    RFLR A 0 Bright
    Goto Fade
  Fade:
    "####" "##########" 1 Bright A_FadeIn(0.05)
    "####" "##########" 1 Bright A_FadeOut(0.05)
    Stop
  }
}

Actor BlueFlareFade : RedFlareFade
{
  States
  {
  Spawn:
    RFLB A 0 Bright
    Goto Fade
  Fade:
    "####" "##########" 1 Bright A_FadeIn(0.1) // blue is a bit too dark at 0.5
    "####" "##########" 1 Bright A_FadeOut(0.1)
    Stop
  }
}

Actor GreenFlareFade : RedFlareFade
{
  States
  {
  Spawn:
    RFLG B 0 Bright
    Goto Fade
  }
}

Actor YellowFlareFade : RedFlareFade
{
  States
  {
  Spawn:
    RFLY A 0 Bright
    Goto Fade
  }
}

Actor RainbowFlare : RedFlare
{
  States
  {
  Spawn:
    TNT1 A 0 NoDelay A_Jump(256, 1, 2, 3, 4)
  Rrrrrrrrrrainbows:
    TNT1 A 10 Bright A_SpawnItemEx("RedFlareFade", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
    TNT1 A 10 Bright A_SpawnItemEx("BlueFlareFade", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
    TNT1 A 10 Bright A_SpawnItemEx("GreenFlareFade", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
    TNT1 A 10 Bright A_SpawnItemEx("YellowFlareFade", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
    Loop
  }
}

Actor Flare_Red_A1B : TorchFlareBase
{
  Scale 1.25
  States
  {
  Spawn:
    FLRE A -1 /*2*/ Bright
    Stop
  }
}

// Effect -----------------------------------------------------------------------------------------

Actor RedFire1
{
  +NoInteraction
  +ForceXYBillboard
  RenderStyle Add
  Scale 0.175
  States
  {
  Spawn:
    FIR1 A 0
    FIR1 A 0 A_Jump(128, "Spawn2")
    FIR1 ABCDEFG 1 Bright
    FIR1 HIJKL 1 Bright A_FadeOut(0.15)
    Stop
  Spawn2:
    FIR2 ABCDEFG 1 Bright
    FIR2 HIJKL 1 Bright A_FadeOut(0.15)
    Stop
  }
}

/* [Blue Shadow] Currently not used
Actor RedFire2
{
  +Missile
  +NoGravity
  +NoBlockmap
  +NoInteraction
  -Solid
  +ForceXYBillboard
  Radius 0
  Height 0
  RenderStyle Add
  Alpha 1.0
  States
  {
  Spawn:
    TNT1 A 0
    TNT1 A 0 ThrustThingZ(0, Random(6, 10), 0, 0)
    FIR3 AAABBBCCDDEEEEEEEEEEEEEEEEEEEEEEEEEEEE 1 Bright A_FadeOut(0.05)
    Stop
  }
}
*/

Actor BigRedFire
{
  +NoInteraction
  +ForceXYBillboard
  RenderStyle Add
  Scale 0.4
  States
  {
  Spawn:
    FIR1 A 0
    FIR1 A 0 A_Jump(128, "Spawn2", "Spawn3", "Spawn4", "Spawn5", "Spawn6")
    FLM1 ABCDEFG 1 Bright
    FLM1 HIJKL 1 Bright A_FadeOut(0.15)
    Stop
  Spawn2:
    FLM2 ABCDEFG 1 Bright
    FLM2 HIJKL 1 Bright A_FadeOut(0.15)
    Stop
  Spawn3:
    FLM3 ABCDEFG 1 Bright
    FLM3 HIJKL 1 Bright A_FadeOut(0.15)
    Stop
  Spawn4:
    FLM4 ABCDEFG 1 Bright
    FLM4 HIJKL 1 Bright A_FadeOut(0.15)
    Stop
  Spawn5:
    FLM5 ABCDEFG 1 Bright
    FLM5 HIJKL 1 Bright A_FadeOut(0.15)
    Stop
  Spawn6:
    FLM6 ABCDEFG 1 Bright
    FLM6 HIJKL 1 Bright A_FadeOut(0.15)
    Stop
  }
}

// ------------------------------------------------------------------------------------------------

ACTOR HPSwitchableLightSource : SwitchableDecoration
{
  +SOLID

  var int user_init;
  var int user_style;

  States
  {
  Spawn:
    // [Blue Shadow] Get the CVAR's value and store it in this variable. The variable will be
    // used below to jump to the correct state for the style.
    TNT1 A 0 NoDelay A_SetUserVar("user_style", CallACS("HPack_GetLightSourceStyle"))
    Goto ChooseStyle

  Active:
    TNT1 A 0 A_PlaySound("Torch/Light")

  ChooseStyle:
    // [Blue Shadow] Depending on what was stored in the variable, choose the style. 0 for
    // normal, sprite-based, and any non-zero value for particle-based.
    TNT1 A 0 A_JumpIf(user_style, "Particles")
    TNT1 A 0 A_Jump(256, "Normal")

  Inactive:
    // [Blue Shadow] This is needed so the that the torch skips playing the below sound if it
    // was set to spawn unlit (by setting the "Dormant" flag via the map editor). The sound
    // skipping is only done once, of course, when the torch first spawns.
    "####" "#" 0 A_JumpIf(!user_init, 2)

    "####" "#" 0 A_PlaySound("Torch/Die")

    // [Blue Shadow] When spawned unlit, the Inactive state is entered immediately, thus the
    // CVAR's value cannot be checked and stored in the variable from the Spawn state. This is
    // why this is here.
    "####" "#" 0 A_SetUserVar("user_style", CallACS("HPack_GetLightSourceStyle"))

    // [Blue Shadow] Removes the flare when deactivated.
    "####" "#" 0 A_RemoveChildren(TRUE, RMVF_MISC)

    "####" "#" -1
    Stop
  }
}

Actor ToTLBrassTorch : HPSwitchableLightSource replaces BrassTorch
{
  Radius 6
  Height 35
  States
  {
  Normal:
    BRTR ABCDEFGHIJKLM 4 Bright Light("BRASSTORCH")
    Loop
  Particles:
    // [Blue Shadow] The flare only needs to be spawned once.
    BRTR N 0 A_SpawnItemEx("RedFlare", 0, 0, 38, 0, 0, 0, 0, SXF_SETMASTER | SXF_CLIENTSIDE)
  SpawnFire:
    BRTR N 1 Light("BRASSTORCH") A_SpawnItemEx("RedFire1", Random(-2, 2), Random(-2, 2), Random(34, 36), 0.001 * Random(10, 200), 0.001 * Random(10, 200), 0.001 * Random(1000, 2000), 0, SXF_CLIENTSIDE)
    Loop
  Inactive:
    BRTR N 0
    Goto Super::Inactive
  }
}

Actor TOTLTwinedTorch : HPSwitchableLightSource replaces ZTwinedTorch
{
  Radius 10
  Height 64
  States
  {
  Normal:
    TWTR ABCDEFGH 4 Bright Light("TWINETORCH")
    Loop
  Particles:
    TWTR J 0 A_SpawnItemEx("RedFlare", 0, 0, 64, 0, 0, 0, 0, SXF_SETMASTER | SXF_CLIENTSIDE)
  SpawnFire:
    TWTR J 1 Light("TWINETORCH") A_SpawnItemEx("RedFire1", Random(-2, 2), Random(-3, 3), Random(58, 60), 0.001 * Random(10, 200), 0.001 * Random(10, 200), 0.001 * Random(1000, 2000), 0, SXF_CLIENTSIDE)
    Loop
  Inactive:
    TWTR I 0
    Goto Super::Inactive
  }
}

ACTOR TOTLTwinedTorchUnlit : TOTLTwinedTorch replaces ZTwinedTorchUnlit
{
  States
  {
  Spawn:
    TWTR A 0 // [Blue Shadow] Needed for the whole codepointer not being called on the first tic thing.
    Goto Super::Inactive
  }
}

Actor ToTLSkullTorch : HPSwitchableLightSource replaces FireThing
{
  Radius 5
  Height 28
  States
  {
  Normal:
    FSKL A 4 Bright Light("BRASSTORCH")
    FSKL B 3 Bright Light("BRASSTORCH")
    FSKL C 4 Bright Light("BRASSTORCH")
    FSKL D 3 Bright Light("BRASSTORCH")
    FSKL E 4 Bright Light("BRASSTORCH")
    FSKL F 3 Bright Light("BRASSTORCH")
    FSKL G 4 Bright Light("BRASSTORCH")
    FSKL H 3 Bright Light("BRASSTORCH")
    FSKL I 4 Bright Light("BRASSTORCH")
    Loop
  Particles:
    FSKL J 0 A_SpawnItemEx("RedFlare", 0, 0, 27, 0, 0, 0, 0, SXF_SETMASTER | SXF_CLIENTSIDE)
  SpawnFire:
    FSKL J 1 Light("BRASSTORCH") A_SpawnItemEx("RedFire1", Random(-2, 2), Random(-2, 2), Random(26, 28), 0.001 * Random(10, 200), 0.001 * Random(10, 200), 0.001 * Random(1000, 2000), 0, SXF_CLIENTSIDE)
    Loop
  Inactive:
    FSKL J 0
    Goto Super::Inactive
  }
}

Actor TOTLFireBrazier : HPSwitchableLightSource replaces FireBrazier
{
  Radius 16
  Height 44
  States
  {
  Normal:
    KFR1 ABCDEFGH 3 Bright Light("FIREBRAZ")
    Loop
  Particles:
    KFR1 I 0 A_SpawnItemEx("RedFlare", 0, 0, 45, 0, 0, 0, 0, SXF_SETMASTER | SXF_CLIENTSIDE)
  SpawnFire:
    KFR1 I 1 Light("FIREBRAZ") A_SpawnItemEx("RedFire1", Random(-2, 2), Random(-2, 2), Random(43, 45), 0.001 * Random(10, 200), 0.001 * Random(10, 200), 0.001 * Random(1000, 2000), 0, SXF_CLIENTSIDE)
    //KFR1 I 1 Light("FIREBRAZ") A_SpawnItemEx("RedFire2", Random(-3, 3), Random(-3, 3), Random(48, 50), 0, 0, 0, 0, 128)
    Loop
  Inactive:
    KFR1 I 0
    Goto Super::Inactive
  }
}

Actor ToTLSerpentTorch : HPSwitchableLightSource replaces SerpentTorch
{
  Radius 12
  Height 54
  States
  {
  Normal:
    SRTC ABC 4 /*Bright*/ Light("SERPTORCH")
    Loop
  Particles:
    SRTC D 0 A_SpawnItemEx("RedFlare", 0, 0, 54, 0, 0, 0, 0, SXF_SETMASTER | SXF_CLIENTSIDE)
  SpawnFire:
    SRTC D 1 Light("SERPTORCH") A_SpawnItemEx("RedFire1", Random(-2, 2), Random(-2, 2), Random(50, 52), 0.001 * Random(10, 200), 0.001 * Random(10, 200), 0.001 * Random(1000, 2000), 0, SXF_CLIENTSIDE)
    Loop
  Inactive:
    SRTC D 0
    Goto Super::Inactive
  }
}

Actor SnakeBrazierBrass : HPSwitchableLightSource 32484
{
  //$Category Lights
  //$Title Snake Brazier (Brass)
  Radius 12
  Height 56
  States
  {
  Normal:
    BNAK ABCDEFG 3 Bright Light("SNAKETORCH")
    Loop
  Particles:
    BNAK H 0 A_SpawnItemEx("RedFlare", 0, 0, 62, 0, 0, 0, 0, SXF_SETMASTER | SXF_CLIENTSIDE)
  SpawnFire:
    BNAK H 1 Light("SNAKETORCH") A_SpawnItemEx("RedFire1", Random(-2, 2), Random(-2, 2), Random(58, 60), 0.001 * Random(10, 200), 0.001 * Random(10, 200), 0.001 * Random(1000, 2000), 0, SXF_CLIENTSIDE)
    //BNAK H 1 Light("SNAKETORCH") A_SpawnItemEx("RedFire2", Random(-3, 3), Random(-3, 3), Random(68, 70), 0, 0, 0, 0, 128)
    Loop
  Inactive:
    BNAK H 0
    Goto Super::Inactive
  }
}

Actor SnakeBrazierGold : HPSwitchableLightSource 32485
{
  //$Category Lights
  //$Title Snake Brazier (Gold)
  Radius 12
  Height 56
  States
  {
  Normal:
    YNAK ABCDEFG 3 Bright Light("SNAKETORCH")
    Loop
  Particles:
    YNAK H 0 A_SpawnItemEx("RedFlare", 0, 0, 62, 0, 0, 0, 0, SXF_SETMASTER | SXF_CLIENTSIDE)
  SpawnFire:
    YNAK H 1 Light("SNAKETORCH") A_SpawnItemEx("RedFire1", Random(-2, 2), Random(-2, 2), Random(58, 60), 0.001 * Random(10, 200), 0.001 * Random(10, 200), 0.001 * Random(1000, 2000), 0, SXF_CLIENTSIDE)
    //YNAK H 1 Light("SNAKETORCH") A_SpawnItemEx("RedFire2", Random(-3, 3), Random(-3, 3), Random(68, 70), 0, 0, 0, 0, 128)
    Loop
  Inactive:
    YNAK H 0
    Goto Super::Inactive
  }
}

Actor SnakeBrazierJade : HPSwitchableLightSource 32486
{
  //$Category Lights
  //$Title Snake Brazier (Jade)
  Radius 12
  Height 56
  States
  {
  Normal:
    GNAK ABCDEFG 3 Bright Light("SNAKETORCH")
    Loop
  Particles:
    GNAK H 0 A_SpawnItemEx("RedFlare", 0, 0, 62, 0, 0, 0, 0, SXF_SETMASTER | SXF_CLIENTSIDE)
  SpawnFire:
    GNAK H 1 Light("SNAKETORCH") A_SpawnItemEx("RedFire1", Random(-2, 2), Random(-2, 2), Random(58, 60), 0.001 * Random(10, 200), 0.001 * Random(10, 200), 0.001 * Random(1000, 2000), 0, SXF_CLIENTSIDE)
    //GNAK H 1 Light("SNAKETORCH") A_SpawnItemEx("RedFire2", Random(-3, 3), Random(-3, 3), Random(68, 70), 0, 0, 0, 0, 128)
    Loop
  Inactive:
    GNAK H 0
    Goto Super::Inactive
  }
}

Actor TOTLWallTorch : HPSwitchableLightSource replaces WallTorch
{
  Radius 6
  Height 16
  +NoGravity
  +FixMapThingPos
  -Solid
  States
  {
  Normal:
    WTRH ABC 6 Bright Light("WALLTORCH")
    Loop
  Particles:
    WTRH D 0 A_SpawnItemEx("RedFlare", 0, 0, 72, 0, 0, 0, 0, SXF_SETMASTER | SXF_CLIENTSIDE)
  SpawnFire:
    WTRH D 1 Light("WALLTORCH") A_SpawnItemEx("RedFire1", Random(-2, 2), Random(-2, 2), Random(71, 73), 0.001 * Random(10, 200), 0.001 * Random(10, 200), 0.001 * Random(1000, 2000), 0, SXF_CLIENTSIDE)
    Loop
  Inactive:
    WTRH D 0
    Goto Super::Inactive
  }
}

Actor ZWallTorchNew : HPSwitchableLightSource replaces ZWallTorch 16106
{
  //$Category Lights
  //$Title Wall Torch (Hexen, Lit)
  //$Sprite WLTRA0
  Radius 6
  Height 16
  +NoGravity
  +FixMapThingPos
  -Solid
  States
  {
  Normal:
    WLTR ABCDEFGH 5 Bright Light("WALLTORCH")
    Loop
  Particles:
    WLTR I 0 A_SpawnItemEx("RedFlare", 0, 0, 72, 0, 0, 0, 0, SXF_SETMASTER | SXF_CLIENTSIDE)
  SpawnFire:
    WLTR I 1 Light("WALLTORCH") A_SpawnItemEx("RedFire1", Random(-2, 2), Random(-2, 2), Random(71, 73), 0.001 * Random(10, 200), 0.001 * Random(10, 200), 0.001 * Random(1000, 2000), 0, SXF_CLIENTSIDE)
    Loop
  Inactive:
    WLTR I 0
    Goto Super::Inactive
  }
}

Actor ZWallTorchUnlitNew : ZWallTorchNew replaces ZWallTorchUnlit 16107
{
  //$Category Lights
  //$Title Wall Torch (Hexen, Unlit)
  //$Sprite WLTRI0
  //$Obsolete Use "Wall Torch (Hexen, Lit)" in conjunction with the "Dormant" flag
  States
  {
  Spawn:
    WLTR A 0
    Goto Super::Inactive
  }
}

// Based on the Minotaur torch from TCotD2
Actor ZFireBullNew : HPSwitchableLightSource Replaces ZFireBull 16110
{
  //$Category Lights
  //$Title Maulotaur Brazier (Lit)
  //$Sprite FBULA0
  Radius 20
  Height 80
  States
  {
  Normal:
    FBUL ABCDEFG 4 Bright Light("FIREBULL")
    Loop
  Particles:
    FBUL K 0 A_SpawnItemEx("Flare_Red_A1B", 0, 0, 40, 0, 0, 0, 0, SXF_SETMASTER | SXF_CLIENTSIDE)
  SpawnFire:
    FBUL K 1 Light("FIREBULL") A_SpawnItemEx("BigRedFire", Random(-2, 2), Random(-2, 2), Random(38, 40), 0.001 * Random(10, 200), 0.001 * Random(10, 200), 0.001 * Random(2500, 3000), 0, SXF_CLIENTSIDE)
    Loop
  Inactive:
    FBUL H 0
    Goto Super::Inactive
  }
}

Actor ZFireBullUnlitNew : ZFireBullNew replaces ZFireBullUnlit 16111
{
  //$Category Lights
  //$Title Maulotaur Brazier (Unlit)
  //$Sprite FBULH0
  //$Obsolete Use "Maulotaur Brazier (Lit)" in conjunction with the "Dormant" flag
  States
  {
  Spawn:
    FBUL A 0
    Goto Super::Inactive
  }
}

// HEXEN WALL TORCH
/*
ACTOR HPZWallTorch : RandomSpawner
{
	//$Category Lights
	//$Title Wall Torch (Hexen, Lit)
	//$Sprite WLTRI0
	DropItem "ZWallTorchNew"
}
ACTOR HPZWallTorchUnlit : RandomSpawner
{
	//$Category Lights
	//$Title Wall Torch (Hexen, Unlit)
	//$Sprite WLTRI0
	DropItem "ZWallTorchUnlitNew"
}

ACTOR HPZFireBull : RandomSpawner
{
	//$Category Lights
	//$Title Maulotaur Brazier (Lit)
	//$Sprite FBULI0
	DropItem "ZFireBullNew"
}
ACTOR HPZFireBullUnlit : RandomSpawner
{
	//$Category Lights
	//$Title Maulotaur Brazier (Unlit)
	//$Sprite FBULH0
	DropItem "ZFireBullUnlitNew"
}
*/

// ye olde magick torche

actor TorchStarGreen {
  +MISSILE
  +NOGRAVITY
  +NOBLOCKMAP
  +NOINTERACTION
  +FORCEXYBILLBOARD
  -SOLID
  Radius 0
  Height 0
  RenderStyle Add
  Alpha 1.0
  Scale 0.2
  States
  {
  Spawn:
    SKFX A 1 Bright A_FadeOut(0.1)
    SKFX A 1 Bright A_SetScale(scalex + 0.033)
    Loop
  }
}

actor TorchStarBlue   : TorchStarGreen { translation "209:224=185:200" }
actor TorchStarWhite  : TorchStarGreen { translation "209:224=0:35"    }
actor TorchStarRed    : TorchStarGreen { translation "209:224=145:159" }
actor TorchStarOrange : TorchStarGreen { translation "209:224=112:127" }
actor TorchStarPurple : TorchStarGreen { translation "209:224=169:176" }

actor TorchStarRandom : TorchStarGreen {
  States
  {
  Spawn:
    TNT1 A 0 NoDelay A_Jump(256, 1, 2, 3, 4, 5, 6)
    TNT1 A 1 A_SpawnItemEx ("TorchStarGreen" , 0, 0, 0, velx, vely, velz, angle, SXF_CLIENTSIDE) Stop
    TNT1 A 1 A_SpawnItemEx ("TorchStarBlue"  , 0, 0, 0, velx, vely, velz, angle, SXF_CLIENTSIDE) Stop
    TNT1 A 1 A_SpawnItemEx ("TorchStarWhite" , 0, 0, 0, velx, vely, velz, angle, SXF_CLIENTSIDE) Stop
    TNT1 A 1 A_SpawnItemEx ("TorchStarRed"   , 0, 0, 0, velx, vely, velz, angle, SXF_CLIENTSIDE) Stop
    TNT1 A 1 A_SpawnItemEx ("TorchStarOrange", 0, 0, 0, velx, vely, velz, angle, SXF_CLIENTSIDE) Stop
    TNT1 A 1 A_SpawnItemEx ("TorchStarPurple", 0, 0, 0, velx, vely, velz, angle, SXF_CLIENTSIDE) Stop
  }
}

Actor HPMagicWallTorch : HPSwitchableLightSource 16131
{
  //$Category Lights
  //$Title Wall Torch (Magic)
  //$Sprite WTRHD0
  Radius 6
  Height 16
  +NoGravity
  +FixMapThingPos
  -Solid
  States
  {
  Normal:
    WTRH ABC 6 Bright // [XA] TODO: this, I guess. :P
    Loop
  Particles:
    WTRH D 0 A_SpawnItemEx("RainbowFlare", 0, 0, 72, 0, 0, 0, 0, SXF_SETMASTER | SXF_CLIENTSIDE)
  SpawnFire:
    WTRH D 1 A_SpawnItemEx("TorchStarRandom", frandom(-2, 2), frandom(-2, 2), frandom(67, 69), 0.001 * Random(10, 200), 0.001 * Random(10, 200), 0.001 * Random(1000, 2000), 0, SXF_CLIENTSIDE)
    Loop
  Inactive:
    WTRH D 0
    Goto Super::Inactive
  }
}

ACTOR HPZCandleFloating : ZCandle 16125
{
  +FLOATBOB
  +NOGRAVITY
  -SOLID
  States
  {
  Spawn:
    CNDF ABC 4 Bright
    Loop
  }
}
