#textdomain wesnoth-utbs

[scenario]
    id=12_The_Final_Confrontation
    name= _ "The Final Confrontation"
    next_scenario=13_Epilogue

    {UTBS_MAP 12_The_Final_Confrontation.map}

    {STORY_THE_FINAL_CONFRONTATION}

    {SCENARIO_MUSIC "the_deep_path.ogg"}
    {EXTRA_SCENARIO_MUSIC "revelation.ogg"}
    {EXTRA_SCENARIO_MUSIC "the_city_falls.ogg"}

    victory_when_enemies_defeated=no
    turns="-1"

    {UNDERGROUND}

    #########################################################################################################
    #                   Events table (stuff that can be triggered with 'fire')                              #
    #########################################################################################################
    # eloh_death : causes the post-Eloh events to occur                                                     #
    # create_minion : spawns one of Yechnagoth's minions                                                   #
    # yechnagoth_regenerate : causes Yechnagoth to fully heal                                               #
    # yechnagoth_special_attack : trigger Yechnagoth's special slowing attack                               #
    # yechnagoth_vulnerate : vulnerates Yechnagoth                                                          #
    # yechnagoth_death : triggers Yechnagoth's death event                                                  #
    #########################################################################################################

    # Side 1: elves
    [side]
        side=1
        id=Kaleh
        type=Quenoth Youth
        canrecruit=yes
        gold=0
        {NO_INCOME}
        controller=human
        shroud=no
        fog=no
        {FLAG_VARIANT long}
        user_team_name= _ "team_name^Quenoth Elves"
    [/side]

    # Side 2: Eloh
    [side]
        side=2
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=eloh
        user_team_name=_"Eloh"
        {FLAG_VARIANT undead}
        [ai]
            aggression=0.95
            caution=0.1

            # change AI so that enemies target Kaleh's friends
            # more than Kaleh himself. I want to threaten
            # other units more, since Kaleh's death leads to
            # immediate defeat

            [goal]
                name=target
                [criteria]
                    id=Kaleh
                [/criteria]
                value=1
            [/goal]
            [goal]
                name=target
                [criteria]
                    id=Nym
                [/criteria]
                value=3
            [/goal]
            [goal]
                name=target
                [criteria]
                    id=Zhul
                [/criteria]
                value=3
            [/goal]

            [goal]
                name=target
                [criteria]
                    id=$ally_name
                [/criteria]
                value=3
            [/goal]
        [/ai]
    [/side]

    # Side 3: Brainwashed Elves
    [side]
        side=3
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=eloh
        user_team_name=_"Eloh"

        [ai]
            aggression=0.95
            caution=0.1

            [goal]
                name=target
                [criteria]
                    id=Kaleh
                [/criteria]
                value=1
            [/goal]
            [goal]
                name=target
                [criteria]
                    id=Nym
                [/criteria]
                value=3
            [/goal]
            [goal]
                name=target
                [criteria]
                    id=Zhul
                [/criteria]
                value=3
            [/goal]

            [goal]
                name=target
                [criteria]
                    id=$ally_name
                [/criteria]
                value=3
            [/goal]
        [/ai]
        {FLAG_VARIANT long}
    [/side]

    # Side 4: Pulsing Spires
    [side]
        side=4
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=eloh
        user_team_name=_"Eloh"
        {FLAG_VARIANT undead}

        [ai]
            aggression=-1.0
            caution=1.0

            [goal]
                name=target
                [criteria]
                    id=Kaleh
                [/criteria]
                value=1
            [/goal]
            [goal]
                name=target
                [criteria]
                    id=Nym
                [/criteria]
                value=3
            [/goal]
            [goal]
                name=target
                [criteria]
                    id=Zhul
                [/criteria]
                value=3
            [/goal]

            [goal]
                name=target
                [criteria]
                    id=$ally_name
                [/criteria]
                value=3
            [/goal]
        [/ai]
    [/side]

    # Prestart functions:
    # insert items onto map
    # place item images on map
    # recall main heroes
    # store/remove kaleh
    # initialize starting variables
    # set starting scenario objectives

    [event]
        name=prestart

        # add items to map

        {PLACE_IMAGE "items/kaleh-dead.png~NO_TOD_SHIFT()" 10 13}

        # recall heroes
        [recall]
            id=Nym
            x,y=10,16
        [/recall]

        [recall]
            id=Zhul
            x,y=11,17
        [/recall]

        # wmllint: unwho ALL

        # recall dwarf/troll
        [recall]
            id=$ally_name
            x,y=9,17
        [/recall]

        # wmllint: recognize Grog
        # wmllint: recognize Nog
        # wmllint: recognize Rogrimir
        # wmllint: recognize Jarl

        # store/remove kaleh

        [store_unit]
            [filter]
                id=Kaleh
            [/filter]
            kill=yes
            variable=stored_kaleh
        [/store_unit]

        #initialize starting variables

        {VARIABLE allies_killed 0}
        {VARIABLE ally_died_in_final_fight no}
        {VARIABLE number_minions_to_spawn 0}

        # set starting scenario objectives

        [objectives]
            [objective]
                description= _ "Defeat the false Eloh"
                condition=win
                [show_if]
                    [have_unit]
                        id=Eloh
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Defeat Yechnagoth"
                condition=win
                [show_if]
                    [have_unit]
                        id=Yechnagoth
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Kaleh"
                condition=lose
            [/objective]

            {IS_LAST_SCENARIO}
        [/objectives]
    [/event]

    # Event 1: Starting dialogue

    [event]
        name=start

        [scroll_to]
            x,y=10,13
        [/scroll_to]

        [redraw]
        [/redraw]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Nym
            message= _ "Kaleh! No!"
            image=portraits/nym_moody.png
        [/message]

        [redraw]
        [/redraw]

        [delay]
            time=500
        [/delay]

        # Nym runs to Kaleh's side

        {MOVE_UNIT id=Nym 10 14}

        [delay]
            time=300
        [/delay]

        # Zhul runs to Kaleh's side

        {MOVE_UNIT id=Zhul 11 14}
        {MODIFY_UNIT (id=Zhul) facing nw}

        [message]
            speaker=Zhul
            message= _ "He’s still breathing. Eloh, what grace I have, give unto him."
        [/message]

        [delay]
            time=300
        [/delay]

        [message]
            speaker=Nym
            message= _ "He’s stirring."
        [/message]

        # Ally runs to Kaleh's side

        {MOVE_UNIT id=$ally_name 9 14}

        [delay]
            time=300
        [/delay]

        [if]
            [variable]
                name=ally_race
                equals=dwarf
            [/variable]

            [then]
                [message]
                    speaker=$ally_name
                    message= _ "Aye, there’s still life in the boy. But where is the foul creature that did this to him?"
                [/message]
            [/then]

            [else]
                [message]
                    speaker=$ally_name
                    message= _ "The little one is not dead yet. But where is evil lady that did this to him?"
                [/message]
            [/else]
        [/if]

        [redraw]
        [/redraw]

        [delay]
            time=300
        [/delay]

        [unit]
            type=Divine Incarnation
            id=Eloh
            name= _ "Eloh"
            profile=portraits/eloh.png
            x,y=10,11
            upkeep=free
            side=2
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Eloh
            message= _ "So, the elf’s puny friends think they can save him. But you are too late. He is already mine!"
        [/message]

        [remove_item]
            x,y=10,13
        [/remove_item]

        {VARIABLE_OP stored_kaleh.hitpoints sub 10}
        {VARIABLE stored_kaleh.facing n}

        [unstore_unit]
            variable=stored_kaleh
            find_vacant=yes
        [/unstore_unit]

        [if]
            [have_unit]
                id=$ally_name
            [/have_unit]

            [then]
                {MESSAGE_DEPEND_ON_ALLY
                (
                    [message]
                        speaker=Kaleh
                        message= _ "Nym, Zhul, Grog, you shouldn’t have."
                    [/message]
                )
                (
                    [message]
                        speaker=Kaleh
                        message= _ "Nym, Zhul, Nog, you shouldn’t have."
                    [/message]
                )
                (
                    [message]
                        speaker=Kaleh
                        message= _ "Nym, Zhul, Rogrimir, you shouldn’t have."
                    [/message]
                )

                (
                    [message]
                        speaker=Kaleh
                        message= _ "Nym, Zhul, Jarl, you shouldn’t have."
                    [/message]
                )}
            [/then]

            [else]
                [message]
                    speaker=Kaleh
                    message= _ "Nym, Zhul, you shouldn’t have."
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Eloh
            message= _ "Your struggles were mildly entertaining, but futile in the end. For I am powerful beyond your imagining, and this is the seat of my power!"
        [/message]

        [message]
            speaker=Zhul
            message= _ "You are not Eloh. You are but a pitiful mockery of her power and glory!"
        [/message]

        [message]
            speaker=Eloh
            message= _ "Is that what you think? I shall prove you wrong. Look out upon your people and despair!"
        [/message]

        [move_unit_fake]
            type=Quenoth Fighter
            side=3
            x=9,8
            y=20,16
        [/move_unit_fake]

        [unit]
            type=Quenoth Fighter
            id=Anarion
            name= _ "Anarion"
            x=8
            y=16
            side=3
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [redraw]
        [/redraw]

        [delay]
            time=100
        [/delay]

        [move_unit_fake]
            type=Tauroch Rider
            side=3
            x=11,12
            y=20,16
        [/move_unit_fake]

        [unit]
            type=Tauroch Rider
            id=Zylea
            name= _ "Zylea"
            x=12
            y=16
            side=3
            [modifications]
                {TRAIT_DEXTROUS}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [message]
            speaker=Anarion
            message= _ "All hail Eloh!"
        [/message]

        [message]
            speaker=Zylea
            message= _ "Death to the heretics!"
        [/message]

        [message]
            speaker=Eloh
            message= _ "They worship their true god."
        [/message]

        [message]
            speaker=Eloh
            message= _ "Come and bow down before your true master, boy."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Your wish is my command."
        [/message]

        [redraw]
        [/redraw]

        [delay]
            time=300
        [/delay]

        # Kaleh moves over to Eloh

        {MOVE_UNIT id=Kaleh 10 12}

        [harm_unit]
            [filter]
                id=Eloh
            [/filter]

            [filter_second]
                id=Kaleh
            [/filter_second]

            [primary_attack]
                name=sword
            [/primary_attack]
            animate=yes
            # Do damage according to Kaleh's first, sword attack
            amount=$stored_kaleh.attack[0].damage
            alignment=lawful
            damage_type=blade
        [/harm_unit]

        {CLEAR_VARIABLE stored_kaleh}

        [redraw]
        [/redraw]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Eloh
            image=portraits/eloh_rage.png
            message= _ "Argh, you stabbed me!"
        [/message]

        [message]
            speaker=Kaleh
            # wmllint: local spelling Kalehssar
            message= _ "I have crossed deserts, mountains, and oceans and watched my people bleed every step of the way. I did not come all this way to give up now. I am tired of being called boy; I am Kalehssar, the leader of my people and I will fight you until my dying breath!"
        [/message]

        [message]
            speaker=Eloh
            image=portraits/eloh_rage.png
            message= _ "I command you to stop this foolishness!"
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Never!"
        [/message]

        [message]
            speaker=Nym
            message= _ "The shell brooches Melusand gave us, they’re glowing!"
        [/message]

        [message]
            speaker=Kaleh
            message= _ "You will never dominate us, not while hope survives!"
        [/message]

        [message]
            speaker=Eloh
            image=portraits/eloh_rage.png
            message= _ "So be it. You choose death? Then you shall receive it from those you hold most dear. Kill the unbelievers, let none survive!"
        [/message]

        [message]
            speaker=Anarion
            message= _ "Yes mistress."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Ignore our brethren, we must destroy her!"
        [/message]
    [/event]

    # Create an alien minion
    [event]
        name=create_minion
        first_time_only=no
        {SCATTER_UNITS 1 (Crawling Horror) 0 (
            x=6-14
            y=7-14
            terrain=Rr,Uu

            [not]
                [filter]
                [/filter]
            [/not]
        ) (
            side=2
            upkeep=free
        )}
    [/event]

    # Event 1: The Death of Eloh and the revealing of the true monster

    [event]
        name=last breath

        [filter]
            id=Eloh
        [/filter]

        [fire_event]
            name=eloh_death
        [/fire_event]
    [/event]

    [event]
        name=eloh_death

        [message]
            speaker=Eloh
            image=portraits/eloh_rage.png
            message= _ "You think you killed me? You have no idea what you are facing."
        [/message]

        [message]
            speaker=Nym
            message= _ "Who is she really? Could it be Zhangor, back to avenge his imprisonment?"
            image=portraits/nym_moody.png
        [/message]

        [message]
            speaker=Eloh
            image=portraits/eloh_rage.png
            message= _ "Nonsense. Unlike that fool, I do not care about petty things like revenge. Nor do I depend on mortals to enact my will. No, I shall destroy you myself!"
        [/message]

        [kill]
            id=Eloh
            animate=no
            fire_event=no
        [/kill]

        [modify_unit]
            [filter]
                side=3
            [/filter]
            side=1
        [/modify_unit]

        [message]
            type=Quenoth Fighter, Tauroch Rider
            message= _ "Huh? What happened?"
        [/message]

        [message]
            speaker=Zhul
            message= _ "Her spell has been broken. But I don’t think we have won yet. Come aid us!"
        [/message]

        [message]
            type=Quenoth Fighter, Tauroch Rider
            message= _ "Yes priestess."
        [/message]

        [scroll]
            x=25
        [/scroll]
        [scroll]
            x=-25
        [/scroll]
        [scroll]
            x=25
        [/scroll]
        [scroll]
            x=-25
        [/scroll]
        [scroll]
            x=25
        [/scroll]
        [scroll]
            x=-25
        [/scroll]

        [redraw]
        [/redraw]

        [delay]
            time=400
        [/delay]

        [color_adjust]
            red,green,blue=40,0,100
        [/color_adjust]

        [redraw]
        [/redraw]

        [delay]
            time=250
        [/delay]

        [color_adjust]
            red,green,blue=0,0,0
        [/color_adjust]

        [redraw]
        [/redraw]

        # main body appears

        [terrain]
            terrain=Urb # wmllint: ignore
            x,y=10,10
        [/terrain]

        # create main body unit here

        [unit]
            type=Central Body1
            id=Yechnagoth
            name= _ "Yechnagoth"
            side=2
            x,y=10,10
        [/unit]
#define UTBS_YECH_CS
        CS(-240,30,20)#enddef
        [item]
            halo=halo/illuminates-aura.png~{UTBS_YECH_CS}
            x,y=10,10
        [/item]

        # add roots around central body

        #{PLACE_IMAGE scenery/castle-ruins.png 9 11}
        #{PLACE_IMAGE scenery/castle-ruins.png 10 11}
        #{PLACE_IMAGE scenery/castle-ruins.png 11 11}
        #{PLACE_IMAGE scenery/castle-ruins.png 9 10}
        #{PLACE_IMAGE scenery/castle-ruins.png 10 9}
        #{PLACE_IMAGE scenery/castle-ruins.png 11 10}

        # Pulsing Spires appear

        {RANDOM 0..1}

        [if]
            [variable]
                name=random
                numerical_equals=1
            [/variable]

            [then]
                [terrain]
                    terrain=Uu
                    x=8,8,14
                    y=7,13,10
                [/terrain]

                # create Pulsing Spires at:
                # (8,7) (8,13) (14,10)

                [unit]
                    type=Pulsing Spire
                    side=4
                    x,y=8,7
                [/unit]

                [unit]
                    type=Pulsing Spire
                    side=4
                    x,y=8,13
                [/unit]

                [unit]
                    type=Pulsing Spire
                    side=4
                    x,y=14,10
                [/unit]
            [/then]

            [else]
                [terrain]
                    terrain=Uu
                    x=6,12,12
                    y=10,7,13
                [/terrain]

                # create Pulsing Spires at:
                # (6,10) (12,7) (12,13)

                [unit]
                    type=Pulsing Spire
                    side=4
                    x,y=6,10
                [/unit]

                [unit]
                    type=Pulsing Spire
                    side=4
                    x,y=12,7
                [/unit]

                [unit]
                    type=Pulsing Spire
                    side=4
                    x,y=12,13
                [/unit]
            [/else]
        [/if]

        [redraw]
        [/redraw]

        [message]
            speaker=Nym
            message= _ "What is that thing?!"
            image=portraits/nym_moody.png
        [/message]

        [message]
            speaker=Zhul
            message= _ "Eloh protect us!"
        [/message]

        [color_adjust]
            red,green,blue=33,181,140
        [/color_adjust]

        [redraw]
        [/redraw]

        [delay]
            time=250
        [/delay]

        [color_adjust]
            red,green,blue=0,0,0
        [/color_adjust]

        [redraw]
        [/redraw]

        # create 3 bugs
        [fire_event]
            name=create_minion
        [/fire_event]
        [fire_event]
            name=create_minion
        [/fire_event]
        [fire_event]
            name=create_minion
        [/fire_event]

        [redraw]
        [/redraw]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Zhul
            message= _ "Curse Uria, more abominations!"
        [/message]

        [message]
            speaker=Nym
            message= _ "Is it even possible to kill this thing? It’s huge!"
            image=portraits/nym_moody.png
        [/message]

        [message]
            speaker=Kaleh
            message= _ "It must have some sort of weak point. Look at those pulsing spires, I thought they were stone, but they seem to be alive. Maybe if we destroy them it will weaken the creature. No matter what horrors appear, we must keep attacking it. We can’t stop now!"
        [/message]

        [show_objectives]
        [/show_objectives]

        # Start spawning minions, increasing the number each turn.
        {VARIABLE number_minions_to_spawn 1}
        [event]
            name="turn $($turn_number+{ON_DIFFICULTY 2 2 1})"
            delayed_variable_substitution=no
            {VARIABLE number_minions_to_spawn 2}
        [/event]
        [event]
            name="turn $($turn_number+{ON_DIFFICULTY 4 3 3})"
            delayed_variable_substitution=no
            {VARIABLE number_minions_to_spawn 3}
        [/event]
        [event]
            name="turn $($turn_number+{ON_DIFFICULTY 6 5 5})"
            delayed_variable_substitution=no
            {VARIABLE number_minions_to_spawn 4}
        [/event]
    [/event]

    [event]
        name=new turn
        first_time_only=no

        [filter_condition]
            [have_unit]
                id=Yechnagoth
            [/have_unit]
        [/filter_condition]

        {VARIABLE helper_level 4}
        [while]
            [variable]
                name=helper_level
                greater_than=0
            [/variable]
            [variable]
                name=possible_helpers.length
                equals=0
            [/variable]
            [do]
                [store_unit]
                    [filter]
                        side=1
                        level=$helper_level
                        x,y=recall,recall
                    [/filter]

                    kill=no
                    variable=possible_helpers
                [/store_unit]
                {VARIABLE_OP helper_level sub 1}
            [/do]
        [/while]
        {CLEAR_VARIABLE helper_level}

        [if]
            [variable]
                name=possible_helpers.length
                greater_than=0
            [/variable]

            [then]
                {VARIABLE_OP random_helper_i rand "1..$possible_helpers.length"}
                {VARIABLE_OP random_helper_i sub 1}

                [move_unit_fake]
                    type=$possible_helpers[$random_helper_i].type
                    side=1
                    x=10,10
                    y=20,18
                [/move_unit_fake]

                [recall]
                    id=$possible_helpers[$random_helper_i].id
                    x,y=10,18
                    show=no
                [/recall]

                {CLEAR_VARIABLE random_helper_i}
            [/then]
        [/if]
        {CLEAR_VARIABLE possible_helpers}
    [/event]

    # Event 2: New minions are created each turn
    [event]
        name=new turn
        first_time_only=no

        {VARIABLE i 0}
        [while]
            [variable]
                name=i
                less_than=$number_minions_to_spawn
            [/variable]
            [do]
                [fire_event]
                    name=create_minion
                [/fire_event]
                {VARIABLE_OP i add 1}
            [/do]
        [/while]
        {CLEAR_VARIABLE i}
    [/event]

    # Event 3: Central Body heals fully each turn
    # let's move this to the unit type, rather than an event, so there are some indications for the player that tactics like poison won't work.

    [event]
        name=new turn
        first_time_only=no

        [filter_condition]
            [have_unit]
                type=Central Body
            [/have_unit]
        [/filter_condition]

        [fire_event]
            name=yechnagoth_regenerate
        [/fire_event]
    [/event]

    [event]
        name=yechnagoth_regenerate
        first_time_only=no

        [store_unit]
            [filter]
                type=Central Body
            [/filter]
            variable=stored_alien
        [/store_unit]

        [set_variable]
            name=temp
            value=$stored_alien.hitpoints
        [/set_variable]

        #        [modify_unit]
        #            [filter]
        #                type=Central Body
        #            [/filter]
        #            hitpoints=$this_unit.max_hitpoints
        #        [/modify_unit]

        [if]
            [variable]
                name=temp
                less_than=$stored_alien.max_hitpoints
            [/variable]

            [then]
                [fire_event]
                    name=invulnerable_comment
                [/fire_event]
            [/then]
        [/if]

        {CLEAR_VARIABLE (temp,stored_alien)}
    [/event]

    [event]
        name=invulnerable_comment

        [message]
            speaker=Kaleh
            message= _ "That central body is healing faster than we can damage it. It’s almost as if our attacks are doing no damage at all. We got to try another tactic, and fast!"
        [/message]
    [/event]

    # Event 4: Special attack by Central Body each turn

    [event]
        name=new turn
        first_time_only=no

        [filter_condition]
            [have_unit]
                id=Yechnagoth
            [/have_unit]
        [/filter_condition]

        [fire_event]
            name=yechnagoth_special_attack
        [/fire_event]
    [/event]

    [event]
        name=yechnagoth_special_attack
        first_time_only=no

        [store_unit]
            [filter]
                side=1
                {EVERYWHERE}
            [/filter]

            kill=no
            variable=elf_list
        [/store_unit]

        {VARIABLE_OP victim_i rand "1..$elf_list.length"}
        {VARIABLE_OP victim_i sub 1}

        {VARIABLE victim_id $elf_list[$victim_i].id}
        {CLEAR_VARIABLE (elf_list,victim_i)}

        #used to be 140,255,247

        [color_adjust]
            red,green,blue=40,0,100
        [/color_adjust]

        [redraw]
        [/redraw]

        [delay]
            time=250
        [/delay]

        [color_adjust]
            red,green,blue=0,0,0
        [/color_adjust]

        [redraw]
        [/redraw]

        [delay]
            time=100
        [/delay]

        # Add two effects slow unit and damage it
        # 1: do damage to unit (8/9/10 based on difficulty?-stops healing)
        # 2: slow unit
        [sound]
            name=squishy-strike.wav
        [/sound]

        [harm_unit]
            [filter]
                id=$victim_id
            [/filter]

            amount={ON_DIFFICULTY 10 11 12}
            alignment=chaotic
            damage_type=fire
            kill=yes
            slowed=yes
        [/harm_unit]

        [if]
            [variable]
                name=hit_by_special_attack
                not_equals=yes
            [/variable]

            [then]
                {VARIABLE hit_by_special_attack yes}

                [message]
                    speaker=$victim_id
                    message= _ "What the heck? That central creature just hit me with some sort of slime. It hurts and I— I’m stuck!"
                [/message]
            [/then]

            [else]
                [message]
                    speaker=$victim_id
                    message= _ "Ow, I’m stuck!"
                [/message]
            [/else]
        [/if]

        {CLEAR_VARIABLE victim_id}
    [/event]

    # Event 5: When player destroys all 3 Pulsing Spires, Central Body is weakened

    [event]
        name=die
        first_time_only=no

        [filter]
            type=Pulsing Spire
        [/filter]

        [filter_condition]
            [have_unit]
                type=Pulsing Spire
                count=2
            [/have_unit]
        [/filter_condition]

        [remove_item]
            x,y=10,10
        [/remove_item]
        [item]
            halo=halo/illuminates-aura.png~{UTBS_YECH_CS}:500,halo/illuminates-aura.png~{UTBS_YECH_CS}~O(0.6):100
            x,y=10,10
        [/item]
    [/event]

    [event]
        name=die
        first_time_only=no

        [filter]
            type=Pulsing Spire
        [/filter]

        [filter_condition]
            [have_unit]
                type=Pulsing Spire
                count=1
            [/have_unit]
        [/filter_condition]

        [remove_item]
            x,y=10,10
        [/remove_item]
        [item]
            halo=halo/illuminates-aura.png~{UTBS_YECH_CS}~O(0.6):200,halo/illuminates-aura.png~{UTBS_YECH_CS}~O(0.2):400
            x,y=10,10
        [/item]
    [/event]

    [event]
        name=die
        first_time_only=no

        [filter]
            type=Pulsing Spire
        [/filter]

        [filter_condition]
            [have_unit]
                type=Pulsing Spire
                count=0
            [/have_unit]
        [/filter_condition]

        [remove_item]
            x,y=10,10
        [/remove_item]
        [fire_event]
            name=yechnagoth_vulnerate
        [/fire_event]
    [/event]

    [event]
        name=yechnagoth_vulnerate

        # when all 3 spires are destroyed, weaken main body
        [kill]
            type=Pulsing Spire
            fire_event=no
            animate=no
        [/kill]

        [scroll]
            x=20
        [/scroll]
        [scroll]
            x=-20
        [/scroll]
        [scroll]
            x=20
        [/scroll]
        [scroll]
            x=-20
        [/scroll]
        [scroll]
            x=20
        [/scroll]
        [scroll]
            x=-20
        [/scroll]

        [message]
            speaker=narrator
            message= _ "<big><b>Aaaurrgghh!!</b></big>"
            image= # wmllint: no-icon
        [/message]

        [kill]
            type=Central Body1
            animate=no
            fire_event=no
        [/kill]

        [unit]
            type=Central Body2
            id=Yechnagoth
            name= _ "Yechnagoth"
            side=2
            x,y=10,10
        [/unit]

        [redraw]
        [/redraw]

        [message]
            speaker=Kaleh
            message= _ "I think we’re finally doing some damage. We must attack the central body, while it remains vulnerable!"
        [/message]
    [/event]

    # Event 6: Death of weakened Central Body

    [event]
        name=last breath

        [filter]
            type=Central Body2
        [/filter]

        # shake cavern

        [scroll]
            x=40
        [/scroll]
        [scroll]
            x=-40
        [/scroll]
        [scroll]
            x=40
        [/scroll]
        [scroll]
            x=-40
        [/scroll]
        [scroll]
            x=40
        [/scroll]
        [scroll]
            x=-40
        [/scroll]

        # flash dark blue, light blue, very light blue,

        # dark blue

        [color_adjust]
            red,green,blue=40,0,100
        [/color_adjust]

        [redraw]
        [/redraw]

        [delay]
            time=300
        [/delay]

        #light blue

        [color_adjust]
            red,green,blue=33,181,140
        [/color_adjust]

        [redraw]
        [/redraw]

        [delay]
            time=300
        [/delay]

        # very light blue

        [color_adjust]
            red,green,blue=140,255,247
        [/color_adjust]

        [redraw]
        [/redraw]

        [delay]
            time=300
        [/delay]

        # back to normal

        [color_adjust]
            red,green,blue=0,0,0
        [/color_adjust]

        [redraw]
        [/redraw]
    [/event]

    [event]
        name=die

        [filter]
            type=Central Body2
        [/filter]

        [fire_event]
            name=yechnagoth_death
        [/fire_event]
    [/event]

    [event]
        name=yechnagoth_death

        # have a minion scream

        [message]
            type=Crawling Horror
            message= _ "Aiiee!!"    # wmllint: no spellcheck
        [/message]

        [redraw]
        [/redraw]

        # kill minions

        [kill]
            type=Crawling Horror,Pulsing Spire
            animate=yes
            fire_event=no
        [/kill]

        [redraw]
        [/redraw]

        # wait
        [delay]
            time=2500
        [/delay]

        #ending conversation

        [message]
            speaker=Kaleh
            message= _ "At last. It is finished."
        [/message]

        [if]
            [have_unit]
                id=Nym
            [/have_unit]

            [then]
                [message]
                    speaker=Nym
                    message= _ "Is Yechnagoth really dead?"
                    image=portraits/nym_moody.png
                [/message]

                [message]
                    speaker=Kaleh
                    message= _ "Yes, she’s dead Nym."
                [/message]

                [message]
                    speaker=Nym
                    message= _ "I almost can’t believe it."
                [/message]
            [/then]
        [/if]

        [message]
            speaker=Zhul
            message= _ "Behold, the pretender has been defeated. Eloh’s might has prevailed."
        [/message]

        {MESSAGE_DEPEND_ON_ALLY
        (
            [message]
                speaker=Grog
                message= _ "Ugh. Grog is covered in blood and guts and nasty blue goo. Whatever creature was, she doesn’t smell any better dead than she did alive."
            [/message]
        )
        (
            [message]
                speaker=Nog
                message= _ "Ugh. Nog is covered in blood and guts and nasty blue goo. Whatever creature was, she doesn’t smell any better dead than she did alive."
            [/message]
        )
        (
            [message]
                speaker=Rogrimir
                message= _ "Ugh. I’m covered in blood and guts, and this nasty blue stuff. I don’t know what in the nine hells we were fighting, but she doesn’t smell any better dead than she did alive."
            [/message]
        )
        (
            [message]
                speaker=Jarl
                message= _ "Ugh. I’m covered in blood and guts, and this nasty blue stuff. I don’t know what in the nine hells we were fighting, but she doesn’t smell any better dead than she did alive."
            [/message]
        )}

        [if]
            [have_unit]
                id=Nym,Zhul,$ally_name
            [/have_unit]

            [then]
                [message]
                    speaker=Kaleh
                    message= _ "Let’s get out of here."
                [/message]
            [/then]
        [/if]

        {CLEAR_VARIABLE number_minions_to_spawn}
        {CLEAR_VARIABLE hit_by_special_attack}

        [endlevel]
            result=victory
            bonus=no
            carryover_report=no
            linger_mode=no
            {NEW_GOLD_CARRYOVER 0}
        [/endlevel]
    [/event]

#define UTBS_IN_FINAL_FIGHT
#enddef
    {UTBS_INCLUDE utils/deaths.cfg}
#undef UTBS_IN_FINAL_FIGHT
[/scenario]
