// ------------------------------------------------------------------------------------------------
//
//  Fire SFX
//    - Original code by Solarsnowfall, Tormentor667 and Ghastly.
//    - Code clean-up for HPack by Blue Shadow.
//
// ------------------------------------------------------------------------------------------------

Actor FireSpawner : SwitchableDecoration 10000
{
    //$Category HPack_SpecialEffects
    //$Title Fire
    //$Sprite FLM1A0

    //$NotAngled

    //$Arg0 Size
    //$Arg0Type 11
    //$Arg0Enum { 0 = "Small"; 1 = "Medium"; 2 = "Large"; }

    //$Arg1 Sound
    //$Arg1Type 11
    //$Arg1Enum { 0 = "Yes"; 1 = "No"; }

    Height 40
    Radius 30
    +CLIENTSIDEONLY
    +NOINTERACTION
    var int user_init;
    const int ARG_SIZE = 0;
    const int ARG_SOUND = 1;

    States
    {
    Spawn:
        TNT1 A 0 NoDelay A_SetUserVar("user_init", TRUE)

    Active:
    SoundControl:
        TNT1 A 0 A_JumpIf(Args[ARG_SOUND] > 0, "SizeControl")
        TNT1 A 0 A_PlaySound("SFX/FireStart", CHAN_7)

    SizeControl:
        TNT1 A 0 A_JumpIf(Args[ARG_SIZE] >= 2, "Large")
        TNT1 A 0 A_JumpIf(Args[ARG_SIZE] >= 1, "Medium")

    Small:
        TNT1 A 0 A_JumpIf(Args[ARG_SOUND] > 0, 2)
        TNT1 A 0 A_PlaySound("SFX/FireLoop1", CHAN_6, 1.0, TRUE)
        TNT1 A 1 Light("FireSpawnerSmall") A_GiveInventory("HPSpawnSmallFire")
        Wait

    Medium:
        TNT1 A 0 A_JumpIf(Args[ARG_SOUND] > 0, 2)
        TNT1 A 0 A_PlaySound("SFX/FireLoop2", CHAN_6, 1.0, TRUE)
        TNT1 A 1 Light("FireSpawnerMedium") A_GiveInventory("HPSpawnMediumFire")
        Wait

    Large:
        TNT1 A 0 A_JumpIf(Args[ARG_SOUND] > 0, 2)
        TNT1 A 0 A_PlaySound("SFX/FireLoop3", CHAN_6, 1.0, TRUE)
        TNT1 A 1 Light("FireSpawnerLarge") A_GiveInventory("HPSpawnLargeFire")
        Wait

    Inactive:
        // [Blue Shadow]
        //   If user_init equals 0, it means that the spawner was set to spawn inactive via the
        //   map editor (by setting the "Dormant" flag), and so, skip playing the sound, as it's
        //   undesirable in this case. The sound skipping is only done once, of course, when the
        //   spawner first spawns.
        TNT1 A 0 A_JumpIf(user_init, "FireDie")
        TNT1 A 0 A_SetUserVar("user_init", TRUE)
        Goto Stay
    FireDie:
        TNT1 A 0 A_JumpIf(Args[ARG_SOUND] > 0, "Stay")
        TNT1 A 0 A_PlaySound("SFX/FireDie", CHAN_6)
    Stay:
        TNT1 A -1
        Stop
    }
}

// ------------------------------------------------------------------------------------------------
//
//   Flame particles spawn "functions"
//
//   [Blue Shadow]
//     These were originally part of the spawner's code, but they got moved out so that they can be
//     easily used by or integrated into other actors, if need be. Currently, aside from
//     FireSpawner, the only other actor that uses these (or at least one of them) is FirePodGoo
//     (actors/misc/prop_podvariants.txt).
//
// ------------------------------------------------------------------------------------------------

ACTOR HPSpawnSmallFire : CustomInventory
{
    States
    {
    Pickup:
        TNT1 A 0 A_Jump(216, 3)
        TNT1 A 0 A_SpawnItemEx("Ember1", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        TNT1 A 0 A_SpawnItemEx("Flame1A", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
        TNT1 A 0 A_Jump(176, 2)
        TNT1 A 0 A_SpawnItemEx("Flame1B", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
        TNT1 A 0 A_Jump(136, 2)
        TNT1 A 0 A_SpawnItemEx("Flame2A", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
        TNT1 A 0 A_Jump(96, 2)
        TNT1 A 0 A_SpawnItemEx("Flame2B", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
        TNT1 A 0 A_Jump(56, 2)
        TNT1 A 0 A_SpawnItemEx("Flame3A", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
        TNT1 A 0 A_SpawnItemEx("Flame3B", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
    }
}

ACTOR HPSpawnMediumFire : CustomInventory
{
    States
    {
    Pickup:
        TNT1 A 0 A_Jump(216, 3)
        TNT1 A 0 A_SpawnItemEx("Ember2", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        TNT1 A 0 A_SpawnItemEx("Flame4A", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
        TNT1 A 0 A_Jump(176, 2)
        TNT1 A 0 A_SpawnItemEx("Flame4B", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
        TNT1 A 0 A_Jump(136, 2)
        TNT1 A 0 A_SpawnItemEx("Flame5A", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
        TNT1 A 0 A_Jump(96, 2)
        TNT1 A 0 A_SpawnItemEx("Flame5B", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
        TNT1 A 0 A_Jump(56, 2)
        TNT1 A 0 A_SpawnItemEx("Flame6A", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
        TNT1 A 0 A_SpawnItemEx("Flame6B", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
    }
}

ACTOR HPSpawnLargeFire : CustomInventory
{
    States
    {
    Pickup:
        TNT1 A 0 A_Jump(216, 3)
        TNT1 A 0 A_SpawnItemEx("Ember2", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        TNT1 A 0 A_SpawnItemEx("Flame7A", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
        TNT1 A 0 A_Jump(176, 2)
        TNT1 A 0 A_SpawnItemEx("Flame7B", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
        TNT1 A 0 A_Jump(136, 2)
        TNT1 A 0 A_SpawnItemEx("Flame8A", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
        TNT1 A 0 A_Jump(96, 2)
        TNT1 A 0 A_SpawnItemEx("Flame8B", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
        TNT1 A 0 A_Jump(56, 2)
        TNT1 A 0 A_SpawnItemEx("Flame9A", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
        TNT1 A 0 A_SpawnItemEx("Flame9B", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
        Stop
    }
}

// ------------------------------------------------------------------------------------------------
//
//   Flames and particles
//
// ------------------------------------------------------------------------------------------------

// [Blue Shadow]
//   Base class for the flame actors. It's also the base class for Ember1, at the very bottom.
ACTOR HPFlameBase
{
    Alpha 0.8
    RenderStyle "Add"
    +BRIGHT
    +FORCEXYBILLBOARD
    +NOINTERACTION
}

Actor Flame1A : HPFlameBase
{
    Scale 0.35

    States
    {
    Spawn:
        // [Blue Shadow]
        //   To make sure that child actors Flame4A and Flame7A use their own Thrust state instead
        //   of their parent's, we cannot use a static jump ('Goto <state>'), here. We need a
        //   virtual jump with A_Jump.
        FLM1 A 0 NoDelay A_Jump(256, "Thrust")

    Thrust:
        "####" A 0 ThrustThingZ(0, Random(2, 6), 0, 0)
        "####" A 0 ThrustThing(Random(0, 255), Random(0, 1), 0, 0)

    FadeOut:
        "####" ABCDE 2
        "####" FFGGHHIIJJKKLL 1 A_FadeOut(0.05)
        Stop
    }
}

Actor Flame1B : Flame1A
{
    States
    {
    Spawn:
        FLM2 A 0
        Goto Super::Thrust
    }
}

Actor Flame2A : Flame1A
{
    States
    {
    Spawn:
        FLM3 A 0
        Goto Super::Thrust
    }
}

Actor Flame2B : Flame1A
{
    States
    {
    Spawn:
        FLM4 A 0
        Goto Super::Thrust
    }
}

Actor Flame3A : Flame1A
{
    States
    {
    Spawn:
        FLM5 A 0
        Goto Super::Thrust
    }
}

Actor Flame3B : Flame1A
{
    States
    {
    Spawn:
        FLM6 A 0
        Goto Super::Thrust
    }
}

Actor Flame4A : Flame1A
{
    Scale 0.7

    States
    {
    Thrust:
        "####" A 0 ThrustThingZ(0, Random(4, 12), 0, 0)
        "####" A 0 ThrustThing(Random(0, 255), Random(0, 2), 0, 0)
        Goto Super::FadeOut
    }
}

Actor Flame4B : Flame4A
{
    States
    {
    Spawn:
        FLM2 A 0
        Goto Super::Thrust
    }
}

Actor Flame5A : Flame4A
{
    States
    {
    Spawn:
        FLM3 A 0
        Goto Super::Thrust
    }
}

Actor Flame5B : Flame4A
{
    States
    {
    Spawn:
        FLM4 A 0
        Goto Super::Thrust
    }
}

Actor Flame6A : Flame4A
{
    States
    {
    Spawn:
        FLM5 A 0
        Goto Super::Thrust
    }
}

Actor Flame6B : Flame4A
{
    States
    {
    Spawn:
        FLM6 A 0
        Goto Super::Thrust
    }
}

Actor Flame7A : Flame1A
{
    Scale 1.4

    States
    {
    Thrust:
        "####" A 0 ThrustThingZ(0, Random(8, 24), 0, 0)
        "####" A 0 ThrustThing(Random(0, 255), Random(0, 4), 0, 0)
        Goto Super::FadeOut
    }
}

Actor Flame7B : Flame7A
{
    States
    {
    Spawn:
        FLM2 A 0
        Goto Super::Thrust
    }
}

Actor Flame8A : Flame7A
{
    States
    {
    Spawn:
        FLM3 A 0
        Goto Super::Thrust
    }
}

Actor Flame8B : Flame7A
{
    States
    {
    Spawn:
        FLM4 A 0
        Goto Super::Thrust
    }
}

Actor Flame9A : Flame7A
{
    States
    {
    Spawn:
        FLM5 A 0
        Goto Super::Thrust
    }
}

Actor Flame9B : Flame7A
{
    States
    {
    Spawn:
        FLM6 A 0
        Goto Super::Thrust
    }
}

Actor Ember1 : HPFlameBase
{
    Scale 0.1

    States
    {
    Spawn:
        EMBR A 0 NoDelay ThrustThingZ(0, Random(4, 16), 0, 0)
        EMBR A 0 ThrustThing(Random(0, 255), Random(0, 1), 0, 0)

        // [Blue Shadow]
        //   To make sure that child actor Ember2 uses its own Spawn2 state instead of its
        //   parent's, we cannot use a static jump ('Goto <state>'), here. We need a virtual jump
        //   with A_Jump.
        EMBR A 0 A_Jump(256, "Spawn2")

    Spawn2:
        EMBR A 32

    FadeOut:
        EMBR A 2 A_FadeOut
        Loop
    }
}

Actor Ember2 : Ember1
{
    States
    {
    Spawn2:
        EMBR A 64
        Goto Super::FadeOut
    }
}
