#textdomain wesnoth-After_the_Storm

[scenario]
    id=12_The_Queen
    name= _ "The Queen"
    {MAP 11_Return_to_Wesmere_part_2.map}
    turns=-1
    next_scenario="13_Death_and_Rebirth"
    victory_when_enemies_defeated=no

    {B_DEATHS}

    {SCENARIO_MUSIC       "weight_of_revenge.ogg"}
    {EXTRA_SCENARIO_MUSIC "northerners.ogg"}
    {EXTRA_SCENARIO_MUSIC "siege_of_laurelmor.ogg"}
    {EXTRA_SCENARIO_MUSIC "heroes_rite.ogg"}

    {INDOORS_HIVE} {SCHEDULE_LIGHTING -10 -50 10}

#define RTW_SHARED_AI_ASPECTS
    {AI_SIMPLE_ALWAYS_ASPECT aggression 200.00}
    {AI_SIMPLE_ALWAYS_ASPECT caution      0.00}
    {AI_SIMPLE_ALWAYS_ASPECT grouping       no}
#enddef

    [time_area]
        id=surface
        x=0-24,0-23,0-21,0-19,0-17,0-15
        y=0-10,  11,  12,  13,  14,  15
        {SHORTDARK} {SCHEDULE_LIGHTING -10 -50 10}
    [/time_area]

    {SPAWN_CONTROLLER}

    # wmllint: validate-off
    [side]
        save_id=player

        gold,village_gold=0,0
        {NO_INCOME}

        fog,shroud=yes,yes

        controller=human
        side=1
        team_name=player
        user_team_name= _ "team_name^Elynia"

        # wmllint: recognize Elynia
        {CHARACTER_STATS_ELYNIA_AS_LEADER}
    [/side]
    # wmllint: validate-on

#define RTW_MATRIX_PART_1 X Y
    {GENERIC_UNIT () (Verlissh Matrix Flow System) ({X}) ({Y})} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY}
#enddef

    [side]
        side=2
        team_name=hive
        user_team_name= _ "team_name^Wesmere Hive"
        {CHAOS_FLAG}
        hidden=yes
        color=orange

        no_leader=yes
        {NO_ECONOMY}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {RTW_SHARED_AI_ASPECTS}
        [/ai]

        {RTW_MATRIX_PART_1 57 19}
        {RTW_MATRIX_PART_1 44 18}

        {RTW_MATRIX_PART_1 62 24}
        {RTW_MATRIX_PART_1 63 24}

        {RTW_MATRIX_PART_1 68 22}
        {RTW_MATRIX_PART_1 69 24}

        {RTW_MATRIX_PART_1 72 13}
        {RTW_MATRIX_PART_1 69 14}
        {RTW_MATRIX_PART_1 74 12}
        {RTW_MATRIX_PART_1 66 15}
        {RTW_MATRIX_PART_1 71  2}

        {GENERIC_UNIT () (Psy Crawler) 67 24} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY}
        {GENERIC_UNIT () (Psy Crawler) 71 22} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY}
        {GENERIC_UNIT () (Psy Crawler) 71 15} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY}

        {GENERIC_UNIT () (Psy Crawler) 54  3} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY}
        {GENERIC_UNIT () (Psy Crawler) 49  7} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY}
        {GENERIC_UNIT () (Psy Crawler) 55 11} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY}
        {GENERIC_UNIT () (Psy Crawler) 60 10} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY}
    [/side]

#undef RTW_MATRIX_PART_1

    [side]
        side=3
        team_name=hive
        user_team_name= _ "team_name^Wesmere Hive"
        {CHAOS_FLAG}
        hidden=no
        color=brown

        no_leader=yes
        {NO_ECONOMY}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {RTW_SHARED_AI_ASPECTS}
        [/ai]
    [/side]

    [side]
        side=4
        team_name=hive
        user_team_name= _ "team_name^Wesmere Hive"
        {CHAOS_FLAG}
        hidden=yes
        color=black

        no_leader=yes
        {NO_ECONOMY}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {RTW_SHARED_AI_ASPECTS}
        [/ai]

        {GENERIC_UNIT () (Soulless) 66 19} {NO_UPKEEP_NO_OVERLAY} {FACING se} {GUARDIAN} {VARIATION swimmer}
        {GENERIC_UNIT () (Soulless) 70 18} {NO_UPKEEP_NO_OVERLAY} {FACING s } {GUARDIAN} {VARIATION swimmer}
        {GENERIC_UNIT () (Soulless) 74 20} {NO_UPKEEP_NO_OVERLAY} {FACING sw} {GUARDIAN} {VARIATION swimmer}
        {GENERIC_UNIT () (Soulless) 68 12} {NO_UPKEEP_NO_OVERLAY} {FACING sw} {GUARDIAN} {VARIATION swimmer}
        {GENERIC_UNIT () (Soulless) 72 10} {NO_UPKEEP_NO_OVERLAY} {FACING nw} {GUARDIAN} {VARIATION swimmer}
    [/side]

    [side]
        # Gates controller side
        side=5
        team_name=hive
        user_team_name= _ "team_name^Wesmere Hive"
        {CHAOS_FLAG}
        hidden=yes
        color=black
        controller=null

        no_leader=yes
        {NO_ECONOMY}
    [/side]

    [side]
        side=6
        team_name=hive
        user_team_name= _ "team_name^Wesmere Hive"
        color=white
        {CHAOS_FLAG}
        hidden=yes

        no_leader=yes
        {NO_ECONOMY}
    [/side]

    [side]
        side=7
        team_name=hive
        user_team_name= _ "team_name^Wesmere Hive"
        color=gold
        {CHAOS_FLAG}
        hidden=yes

        recruit=Shaxthal Worm

        no_leader=yes
        {NO_ECONOMY}
    [/side]

    [side]
        side=8
        team_name=player
        user_team_name= _ "team_name^Elynia"
        hidden=yes
        color=red
        controller=null
        share_vision=none

        no_leader=yes
        {NO_ECONOMY}
    [/side]

#undef RTW_SHARED_AI_ASPECTS

    [event]
        name=prerecruit
        first_time_only=no
        [filter]
            type=Shaxthal Worm
        [/filter]

        [object]
            silent=yes
            [filter]
                x,y=$x1,$y1
            [/filter]
            [effect]
                apply_to=variation
                name=b
            [/effect]
        [/object]
    [/event]

#define TQ_LIVING_NONHERO_UNIT
    side=1
    race=orc
    [or]
        race=goblin
    [/or]
    [or]
        race=faerie
    [/or]
    [or]
        race=human
    [/or]
    [or]
        race=elf
    [/or]
    [not]
        id=Elynia
    [/not]
#enddef

    #
    # Glyphs
    #

    {OBJ_HEALING_GLYPH 72 17}
    {OBJ_HEALING_GLYPH 74  1}

    #
    # Enemy spawners
    #

#define RTW_EASY_SPAWNS
    type="Shaxthal Drone"
#enddef

#define RTW_MEDIUM_SPAWNS
    {QUANTITY type
    ("Shaxthal Drone")
    ("Shaxthal Drone,Shaxthal Drone,Shaxthal Sentry Drone,Shaxthal Drone,Shaxthal Drone,Shaxthal Drone,Shaxthal Assault Drone")
    ("Shaxthal Drone,Shaxthal Drone,Shaxthal Sentry Drone,Shaxthal Assault Drone,Shaxthal Sentry Drone")
    }
#enddef

#define RTW_HARD_SPAWNS
    {QUANTITY type
    ("Shaxthal Drone,Shaxthal Drone,Shaxthal Sentry Drone,Shaxthal Drone,Shaxthal Drone")
    ("Shaxthal Drone,Shaxthal Drone,Shaxthal Sentry Drone,Shaxthal Drone,Shaxthal Drone,Shaxthal Drone,Shaxthal Assault Drone")
    ("Shaxthal Drone,Shaxthal Drone,Shaxthal Sentry Drone,Shaxthal Assault Drone,Shaxthal Sentry Drone,Shaxthal Sentry Drone")
    }
#enddef

    # D

    {TIMED_DRONE_SPAWNER 20 ({RTW_HARD_SPAWNS})   2 43 20}
    {TIMED_DRONE_SPAWNER  7 ({RTW_EASY_SPAWNS})   2 47 22}
    {TIMED_DRONE_SPAWNER  9 ({RTW_EASY_SPAWNS})   2 46 20}

    {TIMED_DRONE_SPAWNER 20 ({RTW_HARD_SPAWNS})   2 57 20}
    {TIMED_DRONE_SPAWNER  8 ({RTW_MEDIUM_SPAWNS}) 2 62 26}
    {TIMED_DRONE_SPAWNER  4 ({RTW_EASY_SPAWNS})   2 60 24}
    {TIMED_DRONE_SPAWNER  4 ({RTW_EASY_SPAWNS})   2 63 22}

    {TIMED_DRONE_SPAWNER  8 ({RTW_EASY_SPAWNS})   2 70 17}
    {TIMED_DRONE_SPAWNER 20 ({RTW_MEDIUM_SPAWNS}) 2 73 17}
    {TIMED_DRONE_SPAWNER  5 ({RTW_EASY_SPAWNS})   2 74 14}
    {TIMED_DRONE_SPAWNER  6 ({RTW_EASY_SPAWNS})   2 66 13}

    {TIMED_DRONE_SPAWNER 20 ({RTW_HARD_SPAWNS})   2 68  9}
    {TIMED_DRONE_SPAWNER  4 ({RTW_EASY_SPAWNS})   2 69  9}

    # E

    {ONETIME_DRONE_SPAWNER  ({RTW_HARD_SPAWNS})   6 74  3}
    {ONETIME_DRONE_SPAWNER  ({RTW_MEDIUM_SPAWNS}) 6 75  8}

#undef RTW_EASY_SPAWNS
#undef RTW_MEDIUM_SPAWNS
#undef RTW_HARD_SPAWNS

#define TQ_ENABLE_CAVE_WATER_SOUND_SOURCES
    {CAVE_WATER_SOUND_SOURCE 72 19}

    {CAVE_WATER_SOUND_SOURCE 74  4}

    {CAVE_WATER_SOUND_SOURCE 59  3}

    {CAVE_WATER_SOUND_SOURCE 40  5}
#enddef

    #
    # FIXME: Yes, the names are hardcoded because sound sources haven't
    #        received enough love from the developers and there isn't a lot
    #        that can be done with them in Lua/WML.
    #
#define TQ_DISABLE_CAVE_WATER_SOUND_SOURCES
    {REMOVE_SOUND_SOURCE __ss_cave_water_72_19}

    {REMOVE_SOUND_SOURCE __ss_cave_water_74_4}

    {REMOVE_SOUND_SOURCE __ss_cave_water_59_3}

    {REMOVE_SOUND_SOURCE __ss_cave_water_40_5}
#enddef

    {TQ_ENABLE_CAVE_WATER_SOUND_SOURCES}

    #
    # This sound source is not part of the macros because it is handled
    # specially.
    #

    {HIVE_NOISE_2_SOUND_SOURCE}
    [+sound_source]
        id=cave_sound_source # wmllint: ignore
    [/sound_source]

    [event]
        name=prestart

        {VARIABLE energy_supply_hidden no}

        # wmllint: recognize Mal Keshar

        [if]
            {VARIABLE_BOOLEAN_EQUALS rtw_gameplay_path yes}

            #
            # Came here from Return to Wesmere pt. 2
            #
            [then]
                [kill]
                    id=Elynia
                [/kill]

                [foreach]
                    array=rtw_end_gamestate.player_onmap_units
                    [do]
                        [unstore_unit]
                            variable=this_item
                            find_vacant=no
                        [/unstore_unit]
                    [/do]
                [/foreach]

                [foreach]
                    array=rtw_end_gamestate.ai_onmap_units
                    [do]
                        [unstore_unit]
                            variable=this_item
                            find_vacant=no
                        [/unstore_unit]
                    [/do]
                [/foreach]

                [modify_turns]
                    current=$rtw_end_gamestate.turn_number
                [/modify_turns]

                [modify_side]
                    side=1
                    gold=$rtw_end_gamestate.player_stats.gold
                [/modify_side]

                [set_shroud]
                    side=1
                    shroud_data=$rtw_end_gamestate.shroudmap
                [/set_shroud]
            [/then]

            #
            # Came here via :cl debug command
            #
            [else]
                [store_starting_location]
                    side=2
                [/store_starting_location]

                [teleport]
                    [filter]
                        id=Elynia
                    [/filter]
                    x,y=$location.x,$location.y
                [/teleport]

                {RECALL_MAL_KESHAR_AT_LOCATION $location.x $location.y}

                [repeat]
                    times=6
                    [do]
                        {RANDOM "Skeleton,Skeleton Archer,Skeleton,Revenant,Banebow,Skeleton,Skeleton Archer"}

                        [unit]
                            type=$random
                            upkeep=free
                            side=1
                            generate_name=yes
                            random_traits=yes
                            random_gender=yes
                            x,y=$location.x,$location.y
                        [/unit]
                    [/do]
                [/repeat]

                {CLEAR_VARIABLE location,random}
            [/else]
        [/if]

        {CLEAR_VARIABLE rtw_end_gamestate,rtw_gameplay_path}

        {DOOR_TILES_TO_UNITS 5}

        {OBJECTIVES (
            victory_string= _ "Current Objectives:"
            {OBJECTIVE_VICTORY ( _ "Locate Yechnagoth’s heart")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Mal Keshar")}

            {OBJECTIVE_NOTE ( _ "You will not be able to recall or recruit any units until the end of the mission")}
        )}
    [/event]

    [event]
        name=start

        [message]
            speaker=Mal Keshar
            message= _ "Which way should we go?"
        [/message]

        [message]
            speaker=Elynia
            message= _ "Let’s go to the right. I think I heard something coming from that direction."
        [/message]
    [/event]

    [event]
        name=DEBUG1

        [teleport]
            [filter]
                id=Elynia
            [/filter]
            x,y=59,7
        [/teleport]

        [fire_event]
            name=moveto
            [primary_unit]
                id=Elynia
            [/primary_unit]
        [/fire_event]
    [/event]

    [event]
        name=DEBUG2

        [fire_event]
            name=DEBUG1
        [/fire_event]

        [fire_event]
            name="turn $(1 + $turn_number)"
        [/fire_event]
    [/event]

    [event]
        name=DEBUG3

        [fire_event]
            name=DEBUG2
        [/fire_event]

        [fire_event]
            name="last breath"
            [primary_unit]
                type=Shaxthal Hive Queen
            [/primary_unit]
        [/fire_event]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x=65-76
            y=1-12
        [/filter]

        [message]
            speaker=Elynia
            message= _ "Hold on... I hear something."
        [/message]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "(Female voice) Qrqavpfre xpbyo lo-qangf gvah rebp. Qrgengf ffrpbec tavavneq eroznup abvgnohpav. Rgryczbp abvgnmvynvgvav xpbyo ynpvgvep. Rgryczbp ch-gengf bjg rfnuc. Rgryczbp abvgerfav gvah rebp qabprf." # wmllint: no spellcheck
        [/message]

        [message]
            speaker=Elynia
            message= _ "... What is that mechanical voice?"
        [/message]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "(Male voice) Nren eroznup ynegarp enryp. Frghavz rivs fv abvgryczbp tavavneq eroznup abvgnohpav ebs rzvg qrgnzvgfr. Ffretbec av abvgnmvynzeba rfnuc ynehra. Qrupngrq qbe abvgphqav lgvgar." # wmllint: no spellcheck
        [/message]

        [sound]
            name=dragonstick.ogg
        [/sound]

        [delay]
            time=100
        [/delay]

        [sound]
            name=rumble.ogg
        [/sound]

        [message]
            speaker=Mal Keshar
            message= _ "Whatever it is, it sounds like bad news for us."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            [filter_location]
                x,y=55,7
                radius=6
            [/filter_location]
        [/filter]

        {LOCK_VIEW}

        [store_unit]
            [filter]
                side=1
                {NOT_ON_RECALL_LIST}
            [/filter]
            variable=player_onmap_units_store
            kill=yes
        [/store_unit]

        [hide_unit]
            [not]
                side=1
            [/not]
        [/hide_unit]

        {FADE_TO_BLACK}

        [remove_shroud]
            x,y=55,7
            radius=10
            [not]
                terrain=Q*,X*,*^X*
            [/not]
            side=1
        [/remove_shroud]

        [remove_shroud]
            x,y=55,7
            radius=1
            side=1
        [/remove_shroud]

        [scroll_to]
            x,y=55,7
            {WARP}
        [/scroll_to]

        [fade_out_sound_effects]
            duration=500
        [/fade_out_sound_effects]

        #
        # Add new sound source while sound is silenced to make
        # the effect seem seamless.
        #

        {HIVE_NOISE_1_SOUND_SOURCE}
        [+sound_source]
            id=hive_sound_source # wmllint: ignore
        [/sound_source]

        #
        # Continue with music disabled until the boss appears.
        #

        [fade_out_music]
            duration=500
        [/fade_out_music]

        [fade_in_sound_effects]
            duration=500
        [/fade_in_sound_effects]

        {FADE_IN}

        [foreach]
            array=player_onmap_units_store
            [do]
                [set_variables]
                    mode=merge
                    name=this_item
                    [value]
                        x,y=60,6
                        hitpoints=$this_item.max_hitpoints
                        moves=$this_item.max_moves
                        attacks_left=$this_item.max_attacks
                        [status]
                            poisoned=no
                            slowed=no
                        [/status]
                    [/value]
                [/set_variables]

                [unstore_unit]
                    variable=this_item
                    find_vacant=yes
                [/unstore_unit]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE player_onmap_units_store}

        [unhide_unit]
            [not]
                side=1
            [/not]
        [/unhide_unit]

        [redraw][/redraw]

        [message]
            speaker=Mal Keshar
            message= _ "It’s a very large, suspiciously vacant chamber. He he, what do you think, Elynia?"
        [/message]

        {QUAKE (cave-in.ogg)}

        [scroll_to]
            x,y=71,2
        [/scroll_to]

        #
        # Remove all items everywhere, especially glyphs.
        # Their haloes glitch through shroud.
        #
        [remove_item][/remove_item]

        [redraw][/redraw]

        [kill]
            x=71,67,68
            y= 2, 5, 6
            [not]
                side=1
            [/not]
            animate,fire_event=no,no
        [/kill]

        [terrain]
            terrain=Xos
            x=71,67,68
            y= 2, 5, 6
        [/terrain]

        [place_shroud]
            side=1
            x=72-77,68-71,66-67,64-65
            y=0-40 , 5-40, 9-40,15-40
        [/place_shroud]

        [redraw]
            side=1
        [/redraw]

        {QUAKE (thunderstick.ogg)}

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Mal Keshar
            message= _ "... And, now we’re trapped. How predictable."
        [/message]

        [message]
            speaker=Elynia
            message= _ "I know. Let us be on guard for whatever those voices were talking about."
        [/message]

        {UNLOCK_VIEW}

        [event]
            delayed_variable_substitution=no
            name="turn $($turn_number + 1)"
            [fire_event]
                name=activate boss
            [/fire_event]
        [/event]

        [event]
            delayed_variable_substitution=no
            name="turn $($turn_number + 2)"
            [fire_event]
                name=reveal energy supply
            [/fire_event]
        [/event]
    [/event]

    [event]
        name=activate boss

        {LOCK_VIEW}

        [set_variables]
            name=location
            mode=replace
            [literal]
                x,y=55,7
            [/literal]
        [/set_variables]

        [scroll_to]
            x,y=$location.x,$location.y
            {WARP}
        [/scroll_to]

        [fade_out_music]
            duration=500
        [/fade_out_music]

        [terrain]
            x,y=$location.x,$location.y
            radius=1
            terrain=Yhl^Kov
        [/terrain]

        [modify_side]
            side=7
            gold=0
            {INCOME 6 8 10}
        [/modify_side]

        [modify_side]
            side=1
            fog=no
        [/modify_side]

        [place_shroud]
            side=1
            x=0-40,41-76
            y=0-40,18-40
        [/place_shroud]

        #
        # Refresh shroud.
        #

        [redraw]
            side=1
        [/redraw]

        [item]
            x,y=$location.x,$location.y
            image=misc/blank-hex.png
            halo=halo/lighthouse-aura.png
        [/item]

        [delay]
            time=500
        [/delay]

        #
        # Make a first living unit under the player's control face towards the
        # Queen's spawn location.
        #

        [store_unit]
            [filter]
                {TQ_LIVING_NONHERO_UNIT}
                {NOT_ON_RECALL_LIST}
            [/filter]
            kill=no
            variable=living_nonhero_units
        [/store_unit]

        [if]
            {VARIABLE_NUMERICAL_GREATER_THAN living_nonhero_units.length 0}
            [then]
                {VARIABLE_RANDOM n "0..$($living_nonhero_units.length - 1)"}

                [store_direction]
                    from_x,from_y=$living_nonhero_units[$n].x,$living_nonhero_units[$n].y
                    to_x,to_y=$location.x,$location.y
                    variable="living_nonhero_units[$n].facing"
                [/store_direction]

                [unstore_unit]
                    find_vacant=no
                    variable="living_nonhero_units[$n]"
                [/unstore_unit]

                [redraw][/redraw]

                #
                # Yes, the unit will not be shown changing facing unless the
                # screen is wide enough.
                #

                [message]
                    scroll=no
                    x,y=$living_nonhero_units[$n].x,$living_nonhero_units[$n].y
                    message= _ "What is that?"
                [/message]

                {CLEAR_VARIABLE n}
            [/then]
        [/if]

        {CLEAR_VARIABLE living_nonhero_units}

        #
        # Make all other side 1 units face towards the spawn location.
        #

        [store_unit]
            [filter]
                side=1
                {NOT_ON_RECALL_LIST}
            [/filter]
            variable=player_units
        [/store_unit]

        [foreach]
            array=player_units
            [do]
                [store_direction]
                    from_x,from_y=$this_item.x,$this_item.y
                    to_x,to_y=$location.x,$location.y
                    variable=this_item.facing
                [/store_direction]

                [unstore_unit]
                    find_vacant=no
                    variable=this_item
                [/unstore_unit]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE player_units}

        [redraw][/redraw]

        [delay]
            time=250
        [/delay]

        #
        # Enter the Queen.
        #

        [hide_unit][/hide_unit]

        {WHITE_SCREEN}

        [redraw][/redraw]

        [sound]
            name=ambient/shaxthal-roam-1.ogg
        [/sound]

        [sound]
            name=melee-fire.ogg
        [/sound]

        [delay]
            time=500
        [/delay]

        [store_direction]
            from_x,from_y=$location.x,$location.y
            [to]
                [filter]
                    id=Elynia
                [/filter]
            [/to]
        [/store_direction]

        #
        # Spawn the Queen's assistants.
        #

        [hidden_unit]
            side=7
            x,y=56,6
            type=Shaxthal Drone
            upkeep=free
            random_traits=yes
            facing=$direction
        [/hidden_unit]

        [hidden_unit]
            side=7
            x,y=54,7
            type=Shaxthal Drone
            upkeep=free
            random_traits=yes
            facing=$direction
        [/hidden_unit]

        [hidden_unit]
            side=7
            x,y=56,7
            type=Shaxthal Drone
            upkeep=free
            random_traits=yes
            facing=$direction
        [/hidden_unit]

        [hidden_unit]
            side=7
            x,y=54,6
            type=Shaxthal Drone
            upkeep=free
            random_traits=yes
            facing=$direction
        [/hidden_unit]

        #
        # The Queen.
        #

        [hidden_unit]
            # wmllint: recognize Shaxthal Hive Queen
            id=Shaxthal Hive Queen
            generate_name=no
            type=Shaxthal Hive Queen
            canrecruit=yes
            {IS_BOSS}
            side=7
            x,y=$location.x,$location.y
            facing=$direction
            [modifications]
                {TRAIT_BIOMECHANICAL}
                {TRAIT_RESILIENT}
            [/modifications]
        [/hidden_unit]

        {CLEAR_VARIABLE direction}

        [remove_item]
            x,y=$location.x,$location.y
        [/remove_item]

        #
        # Restore screen.
        #

        {RESET_SCREEN}

        [unhide_unit][/unhide_unit]

        {BOSS_AMBIENTANCE}

        [message]
            speaker=Elynia
            message= _ "—Uria be damned!"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Hey, that conspicuous glowing orb embedded in its torso seems important!"
        [/message]

        [scroll_to]
            x,y=$location.x,$location.y
        [/scroll_to]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Elynia
            message= _ "Yes. It must be the very thing we have been searching for. Our timing couldn’t be any worse... Destroy it! Destroy it at all costs!"
        [/message]

        {CLEAR_VARIABLE location}

        {VARIABLE energy_supply_hidden yes}

        {UNLOCK_VIEW}

        {OBJECTIVES (
            {OBJECTIVE_VICTORY ( _ "Destroy the Queen")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Mal Keshar")}

            {OBJECTIVE_NOTE ( _ "You will not be able to recall or recruit any units until the end of the mission")}
        )}
    [/event]

    [event]
        name=reveal energy supply

        {VARIABLE energy_supply_hidden no}

        [store_locations]
            terrain=X*^&A
            variable=supply_locs
        [/store_locations]

        {QUAKE "cave-in.ogg"}

        [foreach]
            array=supply_locs
            variable=loc
            [do]
                [terrain]
                    x,y=$loc.x,$loc.y
                    terrain=Yhl
                [/terrain]

                [unit]
                    side=7
                    canrecruit=no
                    upkeep=free
                    {IS_BOSS}
                    type=Verlissh Matrix Core
                    x,y=$loc.x,$loc.y
                    [modifications]
                        {BOSS_BOOST 10% 1 0 0 1}

                        [object]
                            [effect]
                                apply_to=attack
                                name=hot goo
                                set_range=melee
                            [/effect]

                            [effect]
                                apply_to=new_ability
                                [abilities]
                                    {ABILITY_EXTRA_HEAL}
                                [/abilities]
                            [/effect]

                            [effect]
                                apply_to=halo
                                halo="halo/heart-aura.png~CS(-80,100,120)~O(0.15)"
                            [/effect]
                        [/object]
                    [/modifications]
                [/unit]

                [scroll_to]
                    x,y=$loc.x,$loc.y
                    {WARP}
                [/scroll_to]

                [delay]
                    time=500
                [/delay]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE supply_locs}

        [delay]
            time=500
        [/delay]

        [message]
            scroll=no
            speaker=Elynia
            message= _ "We have found those things before, in the old capital! They must have something to do with the hive, and possibly this creature as well — perhaps some kind of power source? Try destroying them!"
        [/message]
    [/event]

    [event]
        name=attacker hits
        first_time_only=no
        [filter]
            side=1
        [/filter]
        [filter_second]
            id=Shaxthal Hive Queen
        [/filter_second]

        [fire_event]
            name=boss damaged
        [/fire_event]
    [/event]

    [event]
        name=defender hits
        first_time_only=no
        [filter_second]
            side=1
        [/filter_second]
        [filter]
            id=Shaxthal Hive Queen
        [/filter]

        [fire_event]
            name=boss damaged
        [/fire_event]
    [/event]

    [event]
        name=boss damaged
        first_time_only=no
        [filter_condition]
            [have_unit]
                type=Verlissh Matrix Core
                side=7
            [/have_unit]
            [or]
                {VARIABLE_BOOLEAN_EQUALS energy_supply_hidden yes}
            [/or]
        [/filter_condition]

        {BOSS_ABSORB_FULL_DAMAGE (id=Shaxthal Hive Queen)}
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            type=Verlissh Matrix Core
            side=7
        [/filter]

        # Increase the Queen's health pool by 16 for each energy unit up to a
        # total of 208 HP, and slow her down every time except the last.

        [object]
            [filter]
                id=Shaxthal Hive Queen
            [/filter]
            [effect]
                apply_to=hitpoints
                increase=16
                increase_total=16
            [/effect]
        [/object]

        [if]
            [have_unit]
                type=Verlissh Matrix Core
                side=7
                [not]
                    x,y=$x1,$y1
                [/not]
            [/have_unit]
            [then]
                [modify_unit]
                    [filter]
                        id=Shaxthal Hive Queen
                    [/filter]
                    [status]
                        slowed=yes
                    [/status]
                [/modify_unit]

                # FIXME: see BOSS_ABSORB_FULL_DAMAGE
#ifdef 0
                # Block BOSS_ABSORB_FULL_DAMAGE from unslowing her if the player
                # attacks her during the same turn
                [object]
                    duration=turn
                    [filter]
                        id=Shaxthal Hive Queen
                    [/filter]

                    [effect]
                        apply_to=status
                        add=slowed_by_api
                    [/effect]
                [/object]
#endif

                [floating_text]
                    [filter]
                        id=Shaxthal Hive Queen
                    [/filter]
                    #textdomain wesnoth
                    text=""+_"female^slowed"+""
                    #textdomain wesnoth-After_the_Storm
                [/floating_text]
            [/then]
        [/if]

        [harm_unit]
            [filter]
                id=Shaxthal Hive Queen
            [/filter]
            amount=16
            kill=no
            fire_event=no
            animate=yes
        [/harm_unit]
    [/event]

    [event]
        name=die
        [filter]
            type=Verlissh Matrix Core
            side=7
        [/filter]

        [message]
            speaker=Elynia
            message= _ "This appears to be causing some damage to the beast!"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Very well — let’s do some more!"
        [/message]

        {OBJECTIVES (
            {OBJECTIVE_VICTORY ( _ "Destroy the energy supply units in the Queen’s chamber")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Mal Keshar")}

            {OBJECTIVE_NOTE ( _ "You will not be able to recall or recruit any units until the end of the mission")}
        )}
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            type=Verlissh Matrix Core
            side=7
        [/filter]

        [kill]
            x,y=$x1,$y1
            fire_event,animate=no,no
        [/kill]

        [if]
            [not]
                [have_unit]
                    type=Verlissh Matrix Core
                    side=7
                [/have_unit]
            [/not]
            [then]
                [object]
                    silent=yes
                    [filter]
                        id=Shaxthal Hive Queen
                    [/filter]

                    [effect]
                        apply_to=remove_ability
                        [abilities]
                            {ABILITY_ABSORB_DAMAGE}
                        [/abilities]
                    [/effect]

                    [effect]
                        apply_to=attack
                        range=melee
                        increase_damage=5
                    [/effect]

                    [effect]
                        apply_to=attack
                        name=energy burst
                        set_type=arcane
                        increase_damage=2
                    [/effect]
                [/object]

                [delay]
                    time=1000
                [/delay]

                [message]
                    speaker=Elynia
                    message= _ "It’s working! Strike it down now!"
                [/message]

                {OBJECTIVES (
                    {OBJECTIVE_VICTORY ( _ "Destroy the Queen")}

                    {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
                    {OBJECTIVE_DEFEAT  ( _ "Death of Mal Keshar")}

                    {OBJECTIVE_NOTE ( _ "You will not be able to recall or recruit any units until the end of the mission")}
                )}
            [/then]
        [/if]
    [/event]

    #
    # Verlissh Crawlers respawn logic
    #

    [event]
        name=side 7 turn refresh
        first_time_only=no
        [filter_condition]
            [have_unit]
                type=Verlissh Matrix Core
                side=7
            [/have_unit]

            [not]
                [have_unit]
                    type=Psy Crawler
                    side=7
                    count={DIFF 2 3 4}+"-99999"
                [/have_unit]
            [/not]
        [/filter_condition]

        [store_locations]
            [filter]
                type=Verlissh Matrix Core
                side=7
            [/filter]
            variable=respawn_locs
        [/store_locations]

        {VARIABLE_RANDOM respawn_count {DIFF 1..2 1..3 2..4} }

        [repeat]
            times=$respawn_count
            [do]
                {VARIABLE_RANDOM respawn_loc_index "0..$($respawn_locs.length - 1)"}

                {GENERIC_UNIT (7) (Psy Crawler) $respawn_locs[$respawn_loc_index].x $respawn_locs[$respawn_loc_index].y}
                {NO_UPKEEP_NO_OVERLAY}
                [+unit]
                    animate=yes
                [/unit]

                {CLEAR_VARIABLE respawn_loc_index}
            [/do]
        [/repeat]

        {CLEAR_VARIABLE respawn_locs,respawn_count}
    [/event]

    #
    # Mal Keshar deterioration logic
    #

    [event]
        name=new turn
        first_time_only=no
        [filter_condition]
            [have_unit]
                id=Shaxthal Hive Queen
            [/have_unit]
        [/filter_condition]

        {RANDOM {DIFF 1..3 2..6 3..8}}

        [harm_unit]
            [filter]
                id=Mal Keshar
            [/filter]
            amount=$random
            kill=no
            animate=yes
        [/harm_unit]

        {CLEAR_VARIABLE random}
    [/event]

    [event]
        name=new turn
        [filter_condition]
            [have_unit]
                id=Shaxthal Hive Queen
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=Mal Keshar
            sound={SOUND_LIST:LICH_HIT}
            message= _ "*Uurgh*" # wmllint: ignore no spellcheck
        [/message]

        [message]
            speaker=Elynia
            message= _ "—Malin? Are you all right?"
        [/message]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Mal Keshar
            message= _ "This... this place is not doing me any good... There is a greater force at work in here, pulling our souls into it..."
        [/message]

        [message]
            speaker=Elynia
            message= _ "I should be able to heal you, just—"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "I don’t think that will help for long. I’m going to lend you a hand while I can..."
        [/message]

        {VARIABLE_RANDOM random_spawn_count {DIFF 4..6 3..5 2..5} }

        [store_locations]
            x,y=55,7
            radius=4
            [not]
                terrain=Q*,X*,*^X*
            [/not]
            [not]
                [filter]
                [/filter]
            [/not]
            variable=spawn_locs
        [/store_locations]

        [if]
            {VARIABLE_NUMERICAL_EQUALS spawn_locs.length 0}
            [then]
                [set_variables]
                    mode=replace
                    name=spawn_locs
                    [literal]
                        x,y=55,7
                    [/literal]
                [/set_variables]
            [/then]
        [/if]

        [repeat]
            times=$random_spawn_count
            [do]
                {VARIABLE_RANDOM random_type (Skeleton,Skeleton,Skeleton,Skeleton,Skeleton Archer,Revenant,Deathblade,Banebow,Soulless,Walking Corpse,Walking Corpse)}
                {VARIABLE_RANDOM random_loc "0..$($spawn_locs.length - 1)"}

                #
                # This animation only works after scenario 9.2
                #
                [animate_unit]
                    [filter]
                        id=Mal Keshar
                    [/filter]
                    flag=void_recruiting
                [/animate_unit]

                {GENERIC_UNIT 1 $random_type $spawn_locs[$random_loc].x $spawn_locs[$random_loc].y} {NO_UPKEEP_NO_OVERLAY}
                [+unit]
                    animate=yes
                [/unit]
            [/do]
        [/repeat]

        {CLEAR_VARIABLE random_spawn_count,random_type,random_loc,spawn_locs}
    [/event]

    [event]
        name=last breath
        [filter]
            id=Shaxthal Hive Queen
        [/filter]

        {LOCK_VIEW}

        {CLEAR_LABELS}

        [message]
            speaker=narrator
            message= _ "The unsightly behemoth let out a terrifying loud screech with its dying breath. As the creature collapsed, the alien core in its chest shattered, and burst, releasing a great amount of energy that enveloped all in ghostly red tendrils..."
            image=wesnoth-icon.png
        [/message]

        {FLASH_RED (
            [kill]
                fire_event=no
                x,y=$x1,$y1
                animate=yes
            [/kill]
        )}

        [kill]
            fire_event=no
            type=Psy Crawler
            [or]
                type=Shaxthal Drone
            [/or]
            animate=yes
        [/kill]

        [fire_event]
            name=begin final cutscene
        [/fire_event]

        {UNLOCK_VIEW}
    [/event]

#define TQ_PETRIFY_STORED_UNIT _UNIT_STORE_NAME
    [set_variables]
        mode=merge
        name={_UNIT_STORE_NAME}
        [value]
            side=8
            experience=0
            hitpoints=1
            max_hitpoints=1
            moves=1
            max_moves=1
            ellipse=none # wmllint: no ellipsecheck
            [status]
                petrified=yes
                slowed=no
                poisoned=no
                uncovered=yes
            [/status]
        [/value]
    [/set_variables]
#enddef

#define TQ_PETRIFY_ONE_RANDOM_UNDEAD
    [if]
        [have_unit]
            side=1
            race=undead
            [not]
                id=Mal Keshar
            [/not]
        [/have_unit]
        [then]
            [store_unit]
                [filter]
                    side=1
                    race=undead
                    [not]
                        id=Mal Keshar
                    [/not]
                [/filter]
                variable=undead_fossil_store
            [/store_unit]

            {VARIABLE_RANDOM fossil_index "0..$($undead_fossil_store.length - 1)"}

            {TQ_PETRIFY_STORED_UNIT undead_fossil_store[$fossil_index]}

            [sound]
                name=petrified.ogg
            [/sound]

            [unstore_unit]
                find_vacant=no
                variable="undead_fossil_store[$fossil_index]"
            [/unstore_unit]

            [scroll_to]
                x,y=$undead_fossil_store[$fossil_index].x,$undead_fossil_store[$fossil_index].y
            [/scroll_to]

            {CLEAR_VARIABLE undead_fossil_store,fossil_index} #,petrified_label}
        [/then]
    [/if]
#enddef

#define TQ_PETRIFY_ALL_REMAINING_UNDEAD
    [store_unit]
        [filter]
            side=1
            race=undead
            {NOT_ON_RECALL_LIST}
        [/filter]
        variable=undead_fossil_store
    [/store_unit]

    [foreach]
        array=undead_fossil_store
        [do]
            {TQ_PETRIFY_STORED_UNIT this_item}

            [sound]
                name=petrified.ogg
            [/sound]

            [unstore_unit]
                find_vacant=no
                variable=this_item
            [/unstore_unit]

            [scroll_to]
                x,y=$this_item.x,$this_item.y
            [/scroll_to]
        [/do]
    [/foreach]

    {CLEAR_VARIABLE undead_fossil_store}
#enddef

    [event]
        name=begin final cutscene

        {LOCK_VIEW}

        {CLEAR_LABELS}

        {TQ_DISABLE_CAVE_WATER_SOUND_SOURCES}

        {REPLACE_SCENARIO_MUSIC "silence.ogg"}

        {QUAKE "rumble.ogg,cave-in.ogg"}

        [if]
            [have_unit]
                {TQ_LIVING_NONHERO_UNIT}
            [/have_unit]
            [then]
                [message]
                    {TQ_LIVING_NONHERO_UNIT}
                    message= _ "The energy is filling the place!"
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Elynia
                    message= _ "The energy is filling the place!"
                [/message]
            [/else]
        [/if]

        {QUAKE "rumble.ogg,cave-in.ogg"}

        [message]
            speaker=narrator
            message= _ "... an energy of a kind unknown to either Elynia or the lich."
            image=wesnoth-icon.png
        [/message]

        {FLASH_RED (
            {QUAKE "rumble.ogg,cave-in.ogg"}
        )}

        [harm_unit]
            [filter]
                race=undead
            [/filter]
            amount=8
            kill=no
            animate=yes
        [/harm_unit]

        [fade_out_sound_effects]
            duration=500
        [/fade_out_sound_effects]

        #
        # Disable background sound sources permanently, just for artsy effect.
        # The water sound sources are disabled only temporarily.
        #

        {REMOVE_SOUND_SOURCE cave_sound_source,hive_sound_source}

        {TQ_DISABLE_CAVE_WATER_SOUND_SOURCES}

        #
        # Give UI a chance to run to update sound sources and stuff.
        #

        [delay]
            time=1000
        [/delay]

        # wmllint: local spellings plural_you singular_you

        [if]
            [have_unit]
                {TQ_LIVING_NONHERO_UNIT}
            [/have_unit]
            [then]
                [message]
                    speaker=Mal Keshar
                    # po: Condenser/capacitor.
                    message= _ "plural_you^... It’s clear now that those power condensers were essential for running something else here. All of you, make haste and return to the surface before the hive collapses."
                [/message]

                [message]
                    speaker=Elynia
                    message= _ "We? What about you?!"
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Mal Keshar
                    # po: Condenser/capacitor.
                    message= _ "singular_you^... It’s clear now that those power condensers were essential for running something else here. You must make haste and return to the surface before the hive collapses."
                [/message]

                [message]
                    speaker=Elynia
                    message= _ "I? What about you?!"
                [/message]
            [/else]
        [/if]

        #
        # Reset SFX volume.
        #

        [reset_sound_effects][/reset_sound_effects]

        {QUAKE "rumble.ogg,cave-in.ogg"}

        [message]
            speaker=Mal Keshar
            message= _ "Surely you realize that I am well past my time to roam this earth — I am as old as a fossil, and our little fight with Elyssa and Argan in the frontier between Inferno and Irdya has truly had a long-lasting effect on my powers... The power that’s consuming this place now is tearing into my very soul... It hurts."
        [/message]

        [message]
            speaker=Elynia
            message= _ "But—"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "You and I... we have many followers from diverse backgrounds. I am sure that, should you need a new necromancer to help you, many will be willing to take up my position. Just make sure to not get yourself killed and don’t forget that you are here fighting for a greater cause, one that transcends the fate of Irdya."
        [/message]

        {TQ_PETRIFY_ONE_RANDOM_UNDEAD}

        [message]
            speaker=Elynia
            message= _ "(in tears) Argan’s journal... Where is it?"
        [/message]

        {TQ_PETRIFY_ONE_RANDOM_UNDEAD}
        {TQ_PETRIFY_ONE_RANDOM_UNDEAD}

        [message]
            speaker=Mal Keshar
            message= _ "Kyara—"
        [/message]

        {TQ_PETRIFY_ALL_REMAINING_UNDEAD}

        {REPLACE_SCENARIO_MUSIC "the_king_is_dead.ogg"}
        {APPEND_MUSIC           "transience.ogg"}

        {INCIDENTAL_MUSIC       "sad.ogg"}

        [message]
            speaker=Elynia
            message= _ "Malin..."
        [/message]

        [redraw][/redraw]

        [delay]
            time=2000
        [/delay]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "(Tears.)"
        [/message]

        [delay]
            time=2000
        [/delay]

        [message]
            speaker=Elynia
            message= _ "How could I let this happen? NO!"
        [/message]

        {QUAKE "rumble.ogg,cave-in.ogg"}

        [if]
            [have_unit]
                {TQ_LIVING_NONHERO_UNIT}
            [/have_unit]
            [then]
                [message]
                    {TQ_LIVING_NONHERO_UNIT}
                    message= _ "My lady, we cannot spend any more time here!"
                [/message]

                [sound]
                    name={SOUND_LIST:COLLAPSING_FACILITY}
                [/sound]

                [delay]
                    time=1000
                [/delay]

                [message]
                    speaker=Elynia
                    message= _ "..."
                [/message]

                [delay]
                    time=1000
                [/delay]

                [message]
                    {TQ_LIVING_NONHERO_UNIT}
                    message= _ "Lady!"
                [/message]
            [/then]
        [/if]

        [delay]
            time=1000
        [/delay]

        [sound]
            name={SOUND_LIST:COLLAPSING_FACILITY}
        [/sound]

        [message]
            speaker=narrator
            image= # wmllint: ignore
            message= _ "... Don’t forget that you are here fighting for a greater cause, one that transcends the fate of Irdya."
        [/message]

        [delay]
            time=1000
        [/delay]

        [if]
            [have_unit]
                {TQ_LIVING_NONHERO_UNIT}
            [/have_unit]
            [then]
                [message]
                    speaker=Elynia
                    message= _ "We must get out of here."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Elynia
                    message= _ "I must get out of here."
                [/message]
            [/else]
        [/if]

        [store_locations]
            [filter]
                id=Elynia
            [/filter]
            variable=elynia_loc
        [/store_locations]

        [if]
            {VARIABLE_NUMERICAL_GREATER_THAN elynia_loc.x 50}
            [then]
                {MOVE_UNIT (id=Elynia) 50 6}
            [/then]
        [/if]

        [time_area]
            id=surface
            remove=yes
        [/time_area]

        [terrain_mask]
            x,y=1,1
            border=yes
            {MASK 12_The_Queen_1.mask}
        [/terrain_mask]

        [kill]
            x=1-34,35-76
            y=1-39,17-39
            animate=no
            fire_event=no
        [/kill]

        [remove_shroud]
            side=1
            x=37-52,41-58
            y=  0-9,10-14
            #[not]
            #    terrain=Q*,X*,*^X*
            #[/not]
        [/remove_shroud]

        [redraw][/redraw]

        {HIGHLIGHT_IMAGE 39 6 "items/gohere.png" ()}

        [remove_item]
            x,y=39,6
        [/remove_item]

        [message]
            speaker=Elynia
            message= _ "That way..."
        [/message]

        {OBJECTIVES (
            victory_string= _ "Current Objectives:"
            {OBJECTIVE_VICTORY ( _ "Find an alternate exit to the surface")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}

            {OBJECTIVE_NOTE ( _ "You will not be able to recall or recruit any units until the end of the mission")}
        )}

        #
        # Re-enable regular sound sources (not background ambience).
        #

        {TQ_ENABLE_CAVE_WATER_SOUND_SOURCES}

        {VARIABLE end_of_scenario_turn_number "$($turn_number + 3)"}

        {CLEAR_VARIABLE elynia_loc}

        {UNLOCK_VIEW}

        #
        # Make sure Elynia can't be hit, we don't want her dying at this point.
        #

        {FORCE_CHANCE_TO_HIT () (id=Elynia) 0 ()}

        #
        # Elynia deterioration logic
        #

        [event]
            name=new turn
            first_time_only=no
            [filter_condition]
                {VARIABLE_NUMERICAL_LESS_THAN turn_number $end_of_scenario_turn_number}
            [/filter_condition]

            {RANDOM 8..18}

            [harm_unit]
                [filter]
                    id=Elynia
                [/filter]
                amount=$random
                kill=no
                animate=yes
            [/harm_unit]

            {CLEAR_VARIABLE random}
        [/event]

        #
        # Critters deterioration logic
        #

        [event]
            name=new turn
            first_time_only=no

            {RANDOM 8..16}

            # Visible units are animated and may get less damage,
            # but they may also die.

            [harm_unit]
                [filter]
                    [filter_vision]
                        visible=yes
                        side=1
                    [/filter_vision]
                    [not]
                        side=1
                    [/not]
                    [not]
                        side=8
                    [/not]
                [/filter]
                amount=$random
                kill=yes
                animate=yes
            [/harm_unit]

            {RANDOM 12..60}

            # Units out of the player's reach are not animated but
            # may get more damage. However, they may *not* die.

            [harm_unit]
                [filter]
                    [filter_vision]
                        visible=no
                        side=1
                    [/filter_vision]
                    [not]
                        side=1
                    [/not]
                    [not]
                        side=8
                    [/not]
                [/filter]
                amount=$random
                kill=no
                animate=no
            [/harm_unit]

            {CLEAR_VARIABLE random}
        [/event]

        [event]
            name=moveto
            first_time_only=no

            {RANDOM 0..16}

            [if]
                {VARIABLE_NUMERICAL_GREATER_THAN random 6}
                [then]
                    {QUAKE {SOUND_LIST:COLLAPSING_FACILITY} }
                [/then]
            [/if]

            {CLEAR_VARIABLE random}
        [/event]

        [event]
            delayed_variable_substitution=no
            name="turn $($turn_number + 1)"

            [message]
                speaker=narrator
                image= # wmllint: ignore
                message= _ "... I have always been alone..."
            [/message]

            {QUAKE {SOUND_LIST:COLLAPSING_FACILITY} }

            [kill]
                animate=yes
                fire_event=no
                side=7
                [filter_vision]
                    visible=yes
                    side=1
                [/filter_vision]
            [/kill]

            [kill]
                animate=no
                fire_event=no
                side=7
            [/kill]

            [terrain]
                x=61,58,52,58,62
                y= 7,10, 8, 4, 6
                terrain=Xu
            [/terrain]

            [redraw][/redraw]

            {QUAKE {SOUND_LIST:COLLAPSING_FACILITY} }
        [/event]

        [event]
            delayed_variable_substitution=no
            name="turn $($turn_number + 2)"

            [message]
                speaker=narrator
                image= # wmllint: ignore
                message= _ "... I’ll be alone again..."
            [/message]

            {QUAKE {SOUND_LIST:COLLAPSING_FACILITY} }

            [kill]
                animate=yes
                fire_event=no
                side=1
                {NOT_ON_RECALL_LIST}
                [not]
                    id=Elynia
                [/not]
            [/kill]

            {QUAKE {SOUND_LIST:COLLAPSING_FACILITY} }
        [/event]

        [event]
            delayed_variable_substitution=no
            name="turn $end_of_scenario_turn_number"

            [fire_event]
                name=the end
            [/fire_event]
        [/event]
    [/event]

    [event]
        name=new turn
        first_time_only=no
        [filter_condition]
            [have_unit]
                side=8
                [not]
                    id=Mal Keshar
                [/not]
            [/have_unit]
        [/filter_condition]

        [store_unit]
            [filter]
                side=8
                [not]
                    id=Mal Keshar
                [/not]
            [/filter]
            kill=no
            variable=side8_store
        [/store_unit]

        [kill]
            animate,fire_event=yes,no
            x,y=$side8_store[0].x,$side8_store[0].y
        [/kill]

        {CLEAR_VARIABLE side8_store}
    [/event]

#define TQ_ELYNIA_FADE_STEP _RGB_SHIFT _ALPHA _MAX_HP_CHANGE
    [object]
        silent=yes
        [filter]
            id=Elynia
        [/filter]
        [effect]
            apply_to=image_mod
            replace="CS("+{_RGB_SHIFT}+","+{_RGB_SHIFT}+","+{_RGB_SHIFT}+")~O("+{_ALPHA}+")"
        [/effect]
        [effect]
            apply_to=zoc
            value=no
        [/effect]
        [effect]
            apply_to=hitpoints
            increase_total={_MAX_HP_CHANGE}
        [/effect]
        [effect]
            apply_to=max_experience
            increase={_MAX_HP_CHANGE}
        [/effect]
    [/object]

    [redraw][/redraw]
#enddef

    [event]
        name=the end

        {LOCK_VIEW}

        {CLEAR_LABELS}

        {VARIABLE_DEFAULT swam_in_fountain_of_courage no}

        {GLOBAL_TABLE:OPEN NAMESPACE={PERSISTENT_NS_ATS}}
        {GLOBAL_TABLE:WRITE swam_in_fountain_of_courage}
        {GLOBAL_TABLE:CLOSE}

        #
        # Store Elynia for use in E2.
        #

        {UNIT_TO_GLOBAL_STORE Elynia episode1_stats_elynia}

        # These sound sources are only running when this event is thrown out
        # of sequence (debug mode)...

        {REMOVE_SOUND_SOURCE cave_sound_source,hive_sound_source}

        {TQ_DISABLE_CAVE_WATER_SOUND_SOURCES}

        [message]
            speaker=Elynia
            message= _ "The spell... I must use the spell..."
        [/message]

        [delay]
            time=500
        [/delay]

        {QUAKE {SOUND_LIST:COLLAPSING_FACILITY} }

        [delay]
            time=500
        [/delay]

        [message]
            speaker=narrator
            image= # wmllint: ignore
            message= _ "... I lost much more than that long ago..."
        [/message]

        {QUAKE {SOUND_LIST:COLLAPSING_FACILITY} }

        {QUAKE {SOUND_LIST:COLLAPSING_FACILITY} }

        [message]
            speaker=narrator
            image= # wmllint: ignore
            message= _ "... We aren’t that different after all..."
        [/message]

        {QUAKE {SOUND_LIST:COLLAPSING_FACILITY} }

        [delay]
            time=500
        [/delay]

        [message]
            speaker=narrator
            image= # wmllint: ignore
            message= _ "... a greater cause, one that transcends the fate of Irdya..."
        [/message]

        [delay]
            time=500
        [/delay]

        {QUAKE {SOUND_LIST:COLLAPSING_FACILITY} }

        [message]
            speaker=Elynia
            message= _ "I..."
        [/message]

        [harm_unit]
            [filter]
                id=Elynia
            [/filter]
            amount="$($this_unit.hitpoints - 1)"
            kill=no
            animate=yes
        [/harm_unit]

        [fade_out_music]
            duration=500
        [/fade_out_music]

        [message]
            speaker=narrator
            caption= _ "Uria"
            message= _ "Do you truly think you can fight me?"
            image=wesnoth-icon.png
        [/message]

        {FADE_STEP 8 250}

        {TQ_ELYNIA_FADE_STEP -8 0.98 -5%}

        {FADE_STEP 16 250}

        {TQ_ELYNIA_FADE_STEP -16 0.94 -5%}

        {FADE_STEP 24 250}

        {TQ_ELYNIA_FADE_STEP -24 0.90 -10%}

        {QUAKE {SOUND_LIST:COLLAPSING_FACILITY} }

        [message]
            speaker=narrator
            caption= _ "Uria"
            message= _ "You don’t have the power of the Union to help you anymore. Your friends are gone. Our power is unlimited. You cannot win."
            image=wesnoth-icon.png
        [/message]

        {TQ_ELYNIA_FADE_STEP -32 0.86 -10%}

        {FADE_STEP 32 250}

        {TQ_ELYNIA_FADE_STEP -64 0.82 -20%}

        {FADE_STEP 64 250}

        [sound]
            name={SOUND_LIST:COLLAPSING_FACILITY}
        [/sound]

        {TQ_ELYNIA_FADE_STEP -96 0.76 -20%}

        {FADE_STEP 96 250}

        {TQ_ELYNIA_FADE_STEP -128 0.72 -40%}

        {FADE_STEP 128 250}

        [message]
            speaker=Elynia
            message= _ "... must..."
        [/message]

        {TQ_ELYNIA_FADE_STEP -196 0.65 -60%}

        [sound]
            name=rumble.ogg
        [/sound]

        [remove_item][/remove_item]

        {FADE_STEP 160 250}

        {TQ_ELYNIA_FADE_STEP -196 0.50 -80%}

        [sound]
            name={SOUND_LIST:COLLAPSING_FACILITY}
        [/sound]

        {FADE_STEP 192 250}

        #
        # NOTE: This kills Elynia too. We don't need her anymore past this
        #       point.
        #

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

        [sound]
            name={SOUND_LIST:COLLAPSING_FACILITY}
        [/sound]

        {FADE_STEP 224 250}

        [replace_schedule]
            {NEUTRAL_TOD} {SCHEDULE_LIGHTING 0 -20 -20}
        [/replace_schedule]

        {SET_THEME {FULLSCREEN_CUTSCENE_UI}}

        {FADE_STEP 500 250}

        [terrain]
            # Everywhere.
            terrain=Xv
        [/terrain]

        [redraw][/redraw]

        [modify_side]
            side=1
            fog,shroud=no,no
        [/modify_side]

        [delay]
            time=6000
        [/delay]

        [terrain]
            # Everywhere.
            terrain=Gll^Fp
        [/terrain]

        {FADE_STEP 224 250}
        {FADE_STEP 208 250}
        {FADE_STEP 192 250}
        {FADE_STEP 176 250}
        {FADE_STEP 160 250}
        {FADE_STEP 144 250}
        {FADE_STEP 128 250}
        {FADE_STEP 112 250}
        {FADE_STEP 96  250}
        {FADE_STEP 80  250}
        {FADE_STEP 64  250}
        {FADE_STEP 48  250}
        {FADE_STEP 32  250}
        {FADE_STEP 16  250}
        {FADE_STEP 0   250}

        [delay]
            time=6000
        [/delay]

        [message]
            speaker=narrator
            image= # wmllint: ignore
            message= _ "... Where am I?"
        [/message]

        [delay]
            time=2000
        [/delay]

        {FADE_TO_BLACK}

        {ENDLEVEL_QUIET}
    [/event]

    [event]
        name=victory

        {CLEAR_VARIABLE energy_supply_hidden,end_of_scenario_turn_number}
    [/event]

#undef TQ_ELYNIA_FADE_STEP

#undef TQ_LIVING_NONHERO_UNIT

#undef TQ_PETRIFY_STORED_UNIT
#undef TQ_PETRIFY_ONE_RANDOM_UNDEAD
#undef TQ_PETRIFY_ALL_REMAINING_UNDEAD

#undef TQ_ENABLE_CAVE_WATER_SOUND_SOURCES
#undef TQ_DISABLE_CAVE_WATER_SOUND_SOURCES
[/scenario]

# kate: indent-mode normal; encoding utf-8; space-indent on;


#textdomain wesnoth-After_the_Storm

[scenario]
    id=13_Death_and_Rebirth
    name= _ "Death and Rebirth"
    {MAP 13_Death_and_Rebirth.map}
    turns=-1
    next_scenario="null"
    victory_when_enemies_defeated=no

    {FULLSCREEN_CUTSCENE_UI}

    {SCENARIO_MUSIC "silence.ogg"}

    {INDOORS} {SCHEDULE_LIGHTING -40 -40 -10}

    # wmllint: validate-off

    [side]
        save_id=player

        {NO_ECONOMY}

        controller=human
        side=1
        team_name=player
        user_team_name= _ "team_name^Elynia"
        hidden=yes
        # This is solely to prevent a map snapshot from being used in the
        # Load Game menu when all terrain grahics are loaded. The shroud
        # is disabled later during prestart.
        shroud=yes

        # wmllint: recognize Elynia
        {CHARACTER_STATS_ELYNIA_AS_LEADER}
    [/side]

    [side]
        side=2
        team_name=foe
        user_team_name= _ "team_name^Enemies"
        {CHAOS_FLAG}
        color=gold

        {NO_ECONOMY}

        canrecruit=yes
        # wmllint: recognize Elyssa
        {CHARACTER_STATS_ELYSSA}
        facing=ne
    [/side]

    [side]
        side=3
        team_name=foe
        user_team_name= _ "team_name^Enemies"
        {CHAOS_FLAG}
        hidden=yes

        {NO_ECONOMY}

        canrecruit=yes
        # wmllint: recognize Mal Kendria
        {CHARACTER_STATS_MAL_KENDRIA}
        facing=ne
    [/side]

    # wmllint: validate-on

    [side]
        side=4
        team_name=foe
        user_team_name= _ "team_name^Enemies"
        {CHAOS_FLAG}
        hidden=yes

        {NO_ECONOMY}
        no_leader=yes
    [/side]

    [side]
        side=5
        team_name=foe
        user_team_name= _ "team_name^Enemies"
        {CHAOS_FLAG}
        hidden=yes

        {NO_ECONOMY}
        no_leader=yes
    [/side]

    # NOTE: These are the same glyphs from E1S9.3, sans events.
    {ITEM_CRYSTAL_GLYPH 55 12}
    {ITEM_CRYSTAL_GLYPH 48 19}

    {HIVE_NOISE_1_SOUND_SOURCE}
    [+sound_source]
        id=ss1 # wmllint: ignore
    [/sound_source]

    {HIVE_NOISE_2_SOUND_SOURCE}
    [+sound_source]
        id=ss2 # wmllint: ignore
    [/sound_source]

    [event]
        name=prestart

        [modify_side]
            side=1
            shroud=no
        [/modify_side]

        [hide_unit]
            id=Elynia
        [/hide_unit]

        {BLACK_SCREEN}

        {LOCK_VIEW}
    [/event]

    [event]
        name=start

        [delay]
            time=1000
        [/delay]

        {FADE_IN}

        [message]
            speaker=narrator
            caption= _ "Mal Kendria"
            image=wesnoth-icon.png
            message= _ "My lady?"
        [/message]

        [scroll_to]
            x,y=55,17
        [/scroll_to]

        [delay]
            time=750
        [/delay]

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

        [delay]
            time=750
        [/delay]

        [message]
            speaker=narrator
            caption= _ "Mal Kendria"
            image=wesnoth-icon.png
            message= _ "Where are you?"
        [/message]

        [scroll_to]
            x,y=38,4
        [/scroll_to]

        [delay]
            time=750
        [/delay]

        [scroll_to]
            x,y=38,15
        [/scroll_to]

        [delay]
            time=750
        [/delay]

        [scroll_to]
            x,y=37,23
        [/scroll_to]

        [delay]
            time=750
        [/delay]

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

        [delay]
            time=1000
        [/delay]

        {MOVE_UNIT (id=Mal Kendria) 10 32}

        [message]
            speaker=Mal Kendria
            message= _ "My lady, we have been looking for you! We have just received excellent news—"
        [/message]

        [message]
            speaker=Elyssa
            message= _ "She’s not dead."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Mal Kendria
            message= _ "B— but, the Wesmere facility was vaporized after the destruction of the core!"
        [/message]

        [message]
            speaker=Elyssa
            message= _ "That’s right, but she is not dead. I can feel her. I don’t know where she is, but she’s certainly not dead."
        [/message]

        [unit]
            side=5
            # wmllint: recognize Mal Hekuba
            {CHARACTER_STATS_MAL_HEKUBA}
            canrecruit=yes
            facing=ne
            x,y=1,37
        [/unit]

        [message]
            speaker=Mal Hekuba
            scroll=no
            message= _ "But not in Irdya either, or is she?"
        [/message]

        {FACE_DIRECTION (id=Elyssa) sw}

        {MOVE_UNIT (id=Mal Hekuba)  9 33}

        [message]
            speaker=Elyssa
            message= _ "She’s not."
        [/message]

        [message]
            speaker=Mal Hekuba
            # po: The lackey in question is Mal Keshar
            message= _ "Good. Wherever she is, she can’t bother us anymore, and her lackey was destroyed in the explosion. It’s a pity that we lost the experimental core units along with such a very strategic location, but we can do without them anyway. I feel the need to ask, however, why install the third unit on our new weapon when any of us could make a better use of it?"
        [/message]

        [message]
            speaker=Elyssa
            message= _ "I believe the Norsulans haven’t resolved the contamination issue yet. It’s not the best moment to make risky choices like that with our limited resources; we need to reclaim some land and complete the construction of the other hives."
        [/message]

        [message]
            speaker=Mal Hekuba
            message= _ "As for the original..."
        [/message]

        [message]
            speaker=Elyssa
            message= _ "She said we should not do anything with it yet."
        [/message]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Mal Hekuba
            message= _ "I see. Well, that’s all I wanted to know."
        [/message]

        {MOVE_UNIT (id=Mal Hekuba)  6 34}

        [message]
            speaker=Elyssa
            message= _ "Don’t forget that you have a mission to carry out, too."
        [/message]

        [delay]
            time=500
        [/delay]

        {FACE_DIRECTION (id=Mal Hekuba) ne}

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Mal Hekuba
            message= _ "I am aware, my lady. I am well aware."
        [/message]

        [delay]
            time=500
        [/delay]

        {MOVE_UNIT (id=Mal Hekuba)  1 37}

        [kill]
            [not]
                side=1
            [/not]
            fire_event,animate=no,no
        [/kill]

        #
        # Remove glyphs, otherwise their halos may glitch through shroud due
        # to a bug in the game.
        #

        [remove_item][/remove_item]

        [redraw][/redraw]

        {FADE_TO_BLACK}

        [modify_side]
            side=1
            shroud=yes
        [/modify_side]

        [place_shroud]
            side=1
        [/place_shroud]

        [redraw]
            side=1
        [/redraw]

        # Well, no music fade-out because we don't even use music in this
        # scenario.

        #[fade_out_music][/fade_out_music]

        [fade_out_sound_effects][/fade_out_sound_effects]

        {REMOVE_SOUND_SOURCE ss1,ss2}

        [delay]
            time=10
        [/delay]

        [reset_sound_effects][/reset_sound_effects]

        [delay]
            time=1000
        [/delay]

        {REPLACE_SCENARIO_MUSIC "snowfall.ogg"}
        {APPEND_MUSIC           "nunc_dimittis.ogg"}
        {APPEND_MUSIC           "heroes_rite.ogg"}
        {APPEND_MUSIC           "weight_of_revenge.ogg"}

        {ENDLEVEL_QUIET} {NO_START_OF_SCENARIO_SAVE} {NO_REPLAY_SAVE}
    [/event]
[/scenario]

# kate: indent-mode normal; encoding utf-8; space-indent on;


#textdomain wesnoth-After_the_Storm

#define CHARACTER_STATS_ELYNIA
    id=Elynia
    name= _ "Elynia"
    type=Sylvan Warden
    profile="portraits/elynia.png"
    canrecruit=yes
    unrenamable=yes
    [modifications]
        {TRAIT_RESILIENT}
        {TRAIT_DEXTROUS}
    [/modifications]
#enddef

#define CHARACTER_STATS_ELYNIA_AS_NON_LEADER
    id=Elynia
    name= _ "Elynia"
    type=Sylvan Warden
    profile="portraits/elynia.png"
    {IS_HERO}
    unrenamable=yes
    [modifications]
        {TRAIT_RESILIENT}
        {TRAIT_DEXTROUS}
        {MOD_LOYAL_HERO}
    [/modifications]
#enddef

#define CHARACTER_STATS_DURVAN
    id=Durvan
    name= _ "Durvan"
    type=Poacher
    #profile="portraits/durvan.png"
    {IS_HERO}
    unrenamable=yes
    [modifications]
        {TRAIT_RESILIENT}
        {TRAIT_STRONG}
        {MOD_LOYAL_HERO}
    [/modifications]
#enddef

#define CHARACTER_STATS_ANYA
    id=Anya
    name= _ "Anya"
    type=Dusk Faerie
    gender=female
    #profile="portraits/anya.png"
    {IS_HERO}
    unrenamable=yes
    [modifications]
        {TRAIT_QUICK}
        {TRAIT_RESILIENT}
        {MOD_LOYAL_HERO}
    [/modifications]
#enddef

#define CHARACTER_STATS_ALLYNA
    id=Allyna
    name= _ "Allyna"
    type=Civilian
    #gender=female
    #profile="portraits/allyna.png"
    {IS_HERO}
    unrenamable=yes
    [modifications]
        {TRAIT_QUICK}
        {TRAIT_RESILIENT}
        {MOD_LOYAL_HERO}
    [/modifications]
#enddef

#define CHARACTER_STATS_ZYNARA
    id=Zynara
    name= _ "Zynara"
    type=Dark Sorcerer
    advances_to=Necromancer
    gender=female
    profile="portraits/humans/dark-adept+female.png"
    #profile="portraits/zynara.png"
    {IS_HERO}
    unrenamable=yes
    [modifications]
        {TRAIT_STRONG}
        {TRAIT_QUICK}
        {MOD_LOYAL_HERO}
    [/modifications]
#enddef

#define CHARACTER_STATS_TARA
    id=Tara
    name= _ "Tara"
    type=Faerie Dryad
    variation=tara
    #gender=female
    #profile="portraits/tara.png"
    unrenamable=yes
    [modifications]
        {TRAIT_QUICK}
        {TRAIT_RESILIENT}
    [/modifications]
#enddef

#define CHARACTER_STATS_ELORRAN
    id=Elorran
    name= _ "Elorran"
    type=Errant Executor
    #gender=male
    #profile="portraits/elorran.png"
    unrenamable=yes
    [modifications]
        {TRAIT_INTELLIGENT}
        {TRAIT_STRONG}
    [/modifications]
#enddef

#define CHARACTER_STATS_UNARYE
    id=Unarye
    name= _ "Unarye"
    type=Elvish Avatar
    #profile="portraits/unarye.png"
    profile="portraits/elves/sylph.png~RIGHT()"
    unrenamable=yes
    [modifications]
        {TRAIT_DEXTROUS}
        {TRAIT_INTELLIGENT}
    [/modifications]
#enddef

#define CHARACTER_STATS_IVYEL
    type=Faerie Avatar
    id=Lady of Light
    name= _ "Lady of Light"
    #profile="portraits/ivyel.png"
    unrenamable=yes
    [modifications]
        {TRAIT_RESILIENT}
        {TRAIT_DEXTROUS}
    [/modifications]
#enddef

#define RECALL_DURVAN
    {RECALL_CHARACTER ({CHARACTER_STATS_DURVAN})}
#enddef
#define RECALL_DURVAN_AT_LOCATION _X _Y
    {RECALL_CHARACTER_AT ({CHARACTER_STATS_DURVAN}) ({_X}) ({_Y})}
#enddef

#define RECALL_ALLYNA
    {RECALL_CHARACTER ({CHARACTER_STATS_ALLYNA})}
#enddef
#define RECALL_ALLYNA_AT_LOCATION _X _Y
    {RECALL_CHARACTER_AT ({CHARACTER_STATS_ALLYNA}) ({_X}) ({_Y})}
#enddef

#define RECALL_ANYA
    {RECALL_CHARACTER ({CHARACTER_STATS_ANYA})}
#enddef
#define RECALL_ANYA_AT_LOCATION _X _Y
    {RECALL_CHARACTER_AT ({CHARACTER_STATS_ANYA}) ({_X}) ({_Y})}
#enddef

#define RECALL_ZYNARA
    {RECALL_CHARACTER ({CHARACTER_STATS_ZYNARA})}
#enddef
#define RECALL_ZYNARA_AT_LOCATION _X _Y
    {RECALL_CHARACTER_AT ({CHARACTER_STATS_ZYNARA}) ({_X}) ({_Y})}
#enddef

#define AMLA_MENU_HINT
    {AMLA_MENU_HINT:BASE ( _ "As a high-level unit under your control, Elynia has special After Maximum Level Advancements (AMLAs). You can learn more about those by right-clicking her and choosing the Unit Advancements option.")}
#enddef

# kate: indent-mode normal; encoding utf-8; space-indent on;


#textdomain wesnoth-After_the_Storm

#define C_DEATHS
    {C_DEATH_ELYNIA}
#enddef

#define D_DEATHS
    {C_DEATH_ELYNIA}
    {D_DEATH_DURVAN}
    {D_DEATH_ANYA}
    {D_DEATH_ZYNARA}
#enddef

#define E_DEATHS
    {C_DEATH_ELYNIA}
    {D_DEATH_DURVAN}
    {D_DEATH_ANYA}
#enddef

#define C_DEATH_ELYNIA
    {HERO_DEATH_BASE
    (Elynia)
    (
        [message]
            speaker=unit
            message= _ "I... fall to the darkness."
        [/message]
    ) ()}
#enddef

#define D_DEATH_DURVAN
    {HERO_DEATH_BASE
    (Durvan)
    (
        [message]
            speaker=unit
            message= _ "No! My mission isn’t over yet!"
        [/message]
    ) ()}
#enddef

#define D_DEATH_ANYA
    {HERO_DEATH_BASE
    (Anya)
    (
        [message]
            speaker=unit
            message= _ "Augh! Elynia, save me—"
        [/message]
    ) ()}
#enddef

#define D_DEATH_ZYNARA
    {HERO_DEATH_BASE
    (Zynara)
    (
        [message]
            speaker=unit
            message= _ "I’ve fallen before completing my mission. Forgive me..."
        [/message]
    ) ()}
#enddef

# kate: indent-mode normal; encoding utf-8; space-indent on;


#textdomain wesnoth-After_the_Storm

[campaign]
    id=After_the_Storm_II
    {ATS_SHARED_ATTRIBUTES II}

    abbrev= _ "AtS-2"
    name=_"After the Storm"+"
"+_"Episode II: Fate"
    icon="data/add-ons/After_the_Storm/images/campaign-icon-episode2.png"
    image="data/add-ons/After_the_Storm/images/campaign-logo-episode2.jpg"
    background="story/landscape-hills-01.jpg"
    first_scenario=00_Transience

    description= _ "Time passes, and the Chaos Empire still manages to make a stand against its enemies. While the Grand Council is preoccupied with more pressing matters, the fragile alliance of the peoples of the Far North is threatened by a new, mysterious leader who seeks to invade their defenseless lands."+"

"+_"(Intermediate level, 13 scenarios.)"+{ATS_SHARED_DESCRIPTION_FOOTER}

    {ATS_DIFFICULTY_MENU
    (_"difficulty_menu^Footpad")    ("units/human-outlaws/footpad-melee-3.png")
    (_"difficulty_menu^Trapper")    ("units/human-outlaws/trapper-bow-attack4.png")
    (_"difficulty_menu^Highwayman") ("units/human-outlaws/highwayman-melee-5.png")
    }

    end_text= _ "To be continued..."

    {ATS_CREDITS_BACKGROUND "maps/background.jpg~GS()~O(0.2)~BG()"}
[/campaign]

# kate: indent-mode normal; encoding utf-8; space-indent on;


#textdomain wesnoth-After_the_Storm

#define STORYTXT_INIT_WARNING
    [story]
        [part]
            music="data/core/sounds/ambient/wardrums.ogg"

            {CAMPAIGN_INTRO_HEADER}

            story={CAMPAIGN_INTRO_WARNING_TITLE}+{CAMPAIGN_INTRO_GAMEPLAY_WARNING}+{CAMPAIGN_INTRO_PADDING}+{CAMPAIGN_INTRO_CONTENT_WARNING}+{CAMPAIGN_INTRO_PADDING}+_"If you have not completed Episode I of After the Storm, you definitely should not play this episode yet."+{CAMPAIGN_INTRO_PADDING}+{CAMPAIGN_INTRO_OPTIONS_WARNING}
        [/part]
    [/story]
#enddef

#define STORYTXT_BY_THE_MOONLIGHT
    [story]
        [part]
            music=silence.ogg
            # po: The lines consisting of a single em dash represent a long pause.
            story= _ "—

—

—"
        [/part]
        [part]
            story= _ "—

—

“The light..."
        [/part]
        [part]
            music=enchanted_forest.ogg
            # po: Warm as in warm colors.
            story= _ "A familiar light...

It was the warm light of the second sunset."
        [/part]
        [part]
            story= _ "Where was I?

I found myself in the middle of a glade, lying on the ground. My entire body was in pain and my clothes were considerably scorched, but somehow... I had survived."
        [/part]
        [part]
            story= _ "It took me some time to recover from the initial stupor and remember what had happened moments before. The terrifying feeling of my soul fading away, the crumbling underground hive, my despair as I struggled to find a way back to the surface... and my only remaining friend..."
        [/part]
        [part]
            story= _ "Malin Keshar.

His dark existence full of resentment and spite, an eternity spent as a harbinger of death and destruction... an eternity at long last come to an end, but not without first proving his worth against the Chaos Emperor and the creature in possession of Yechnagoth’s heart.

Oh, who would have ever thought that I would grieve for he whom I was once destined to eliminate, or that his final death would be one befitting a hero?"
        [/part]
        [part]
            {STORYTXT_TITLE_CARD_SIMPLE E2S1 _"By the Moonlight"}
            story= _ "As my memory became clearer, I realized I had cast the teleport spell at the last moment, as if by instinct, in a desperate attempt to escape to the surface. However, a quick glance at my surroundings revealed that it didn’t work quite as I had intended; instead, it had taken me far away from the cursed plains of Wesmere.

But how far, exactly?"
        [/part]
    [/story]
#enddef

#define STORYTXT_THE_HEART_FOREST
    [story]
        [part]
            music=a_land_of_adventure.ogg
            {STORYTXT_TITLE_CARD_SIMPLE E2S2 _"The Heart Forest"}
            story= _ "There were very few friendly faces amongst the villagers. From what I heard during my stay, they feel forsaken by the Grand Council, which has been kept too preoccupied by the war against the Chaos Empire to heed the demands of the civilians. The unforgiving weather and the growing scarcity of resources to sustain their settlement has made these men and women increasingly bitter about the state of affairs.

I can’t help but wonder how the Alliance has fared in battle ever since we left their lands."
        [/part]
    [/story]
#enddef

#define STORYTXT_UNREST_IN_RAELTHYN
    [story]
        [part]
            music=loyalists.ogg
            story= _ "This Allyna girl seems oddly over-enthusiastic about everything in spite of the difficulties she encountered before we found her. To say that it has been a long time since I last had the opportunity to talk to someone like that would be a great understatement.

Sadly, her cheerful demeanor is not enough to dispel the shadows that have followed me wherever I go since Galas’ death; nor does it do anything to keep me from remembering Malin and his habit of trying to make the most fun of any situation."
        [/part]
        [part]
            story= _ "For somebody who has lived for so long, it’s hard to see the world in the same light as young people do. Nowadays I can barely remember those times of blithe disregard for responsibility, my romantic escapades, and the misguided notion that we had all the time of the world for ourselves.

Sometimes, I wish I could get rid of this burden."
        [/part]
        [part]
            {STORYTXT_TITLE_CARD E2S3 _"Unrest in Raelthyn" _"Revelations"}
            story= _ "Before dying, my master told me that the true power of the Ruby of Fire would become crucial for the fate of our world, and that I must make sure it’s never misused by anyone again. It never occurred to me that her words could turn out to be more than a pain-induced delusion."
        [/part]
    [/story]
#enddef

#define STORYTXT_SHIFTING_ALLEGIANCES
    [story]
        [part]
            music=underground.ogg
            story= _ "And so we left for the eastern marches, with a renewed and clear purpose.

Surprisingly enough, Durvan and some of the other hunters from the Heart Forest agreed to participate in our expedition. Allyna offered her help as well, providing us with a safe route to follow, incidentally crossing through her village."
        [/part]
        [part]
            {STORYTXT_TITLE_CARD_SIMPLE E2S4 _"Shifting Allegiances"}
            story= _ "We proceeded as swiftly as we could, hoping for an uneventful journey — given the nature of our mission, expending our energy before reaching the elves could prove disastrous later on."
        [/part]
    [/story]
#enddef

#define STORYTXT_THE_EASTERN_FRONT
    [story]
        [part]
            music=knolls.ogg
            story= _ "Had the circumstances been only slightly different, I would have been much more reluctant to converse with the outcast demon lord; in fact, I would have been more likely to attack without even giving him a chance to speak.

That girl, Anya. It was her curious personality, and her sincerity and admiration for me that led me to try my late friend’s approach to dealing with a similarly unusual enemy. I thought that such a person could not possibly side with the cruel creatures working for Uria — not that faeries of the deep forest like her are known to side with anyone at all."
        [/part]
        [part]
            story= _ "But, did I make that choice for her or for me? Perhaps I merely wanted someone by my side to whom I could relate, someone who personified the bright and hopeful part of me that died with Argan.

Perhaps... I didn’t want to face the possibility of having to kill that part of me a second time."
        [/part]
        [part]
            story= _ "All this seems so absurd as I write it. Sometimes I wonder why I let Galas convince me to write another journal."
        [/part]
        [part]
            {STORYTXT_TITLE_CARD E2S5 _"The Eastern Front" _"The Plan"}
            story= _ "After a couple of days, we finally arrived at the frontier. Unfortunately, we’d soon learn that the Council’s fears had become more than mere speculations."
        [/part]
    [/story]
#enddef

#define STORYTXT_THE_PLAN
    [story]
        [part]
            music=heroes_rite.ogg
            story= _ "Unarye told us to follow her guards into a nearby forest where some of the allied elves had just set up camp. I could tell by her grave expression that she bore bad news. It took her almost the entire afternoon to make time for speaking to us."
        [/part]
    [/story]
#enddef

#define STORYTXT_THE_VOYAGE_HOME
    [story]
        [part]
            music=knolls.ogg
            story= _ "I continued to feel uneasy about the decision for some time. Leaving both the Grand Council and Elorran awaiting our return for so long...

According to Valen, the Council understood the urgency of the situation and the importance of our mission for the elves. Unfortunately, the same couldn’t be said for the demon lord; it took Anya her best effort to persuade him to let us take the Ruby of Fire to enemy territory."
        [/part]
        [part]
            story= _ "It is decidedly not easy to deal with both the Council and my people without telling them of our pact with Elorran. What concerns me the most is the possibility that one of our men might accidentally or deliberately divulge information pertaining to the subject. This is not like every other time I have had to keep a secret for a greater good — alone.

It does raise the question of whether I have chosen my allies prudently or am making a big mistake."
        [/part]
        [part]
            {STORYTXT_TITLE_CARD_SIMPLE E2S6 _"The Voyage Home"}
            story= _ "Then again, Malin would insist that the existence of that accursed artifact is a big mistake by itself."
        [/part]
    [/story]
#enddef

#define STORYTXT_PROXIMUS
    [story]
        [part]
            music=weight_of_revenge.ogg
            story= _ "After the events in Gralseth, the journey across the desert turned into a nightmare. We had to be wary of every single thing we saw, no matter how small or innocuous it seemed. Our enemies could be anywhere, everywhere. We were walking into a trap by our own choice... No, it was my choice.

Even without taking our enemies into account, traversing the vast dry plains was a highly dangerous thing to do. While it wasn’t possible for us to lose track of our destination for long with our maps and Valen’s indications, the stifling heat during the day, frequent sandstorms, and lack of water sources could have resulted in catastrophic losses."
        [/part]
        [part]
            story= _ "Eventually, it became evident that our enemies didn’t want to take risks in the hostile sands either. Aside from a few armed encounters with the natives, we found very little opposition on our way.

At the end, we reached a small oasis near some ruins."
        [/part]
        [part]
            {STORYTXT_TITLE_CARD_SIMPLE E2S7 _"Proximus"}
            story= _ "We had reached the northern defense line of the valley Telchior named after me."
        [/part]
    [/story]
#enddef

#define STORYTXT_AND_THEN_THERE_WAS_CHAOS
    [story]
        [part]
            music=underground.ogg
            # po: Condenser/capacitor.
            story= _ "The Ruby of Fire. A great energy condenser of uncertain origin, used by humans throughout Irdya’s history as both a symbol of power and a catalyst to exert control over all within their reach, and beyond. Through abuse of this artifact, our world was made susceptible to corrupting influences from other realms.

Now that we are without a necromancer, using its dangerous power to command the undead minions left behind by Zynara is the only option we have left if we want to have a chance to vanquish the impostor despite our small numbers. But, who is she in truth?"
        [/part]
        [part]
            story= _ "Up to this point I have broken more rules than is acceptable for any elf, or human.

First, the Ruby. Then I chose Argan, of all people, to be my ally and lover, and asked him to help me learn to use the artifact’s power more effectively. I asked him to teach me the basics of this forbidden magic, and only my fear deterred me from delving deeper — had it not, I probably wouldn’t be here writing these words."
        [/part]
        [part]
            story= _ "Then, I joined the Empire of Wesnoth as an advisor, against the wishes of the Ka’lian, who only realized the benefits much later. But eventually, I was betrayed by the humans; I turned my back on the world and unknowingly left my kinsmen in Wesmere to be caught in Zhangor’s trap at the onset of the end.

Perhaps if I hadn’t broken so many rules before, none of that would have ever come to pass."
        [/part]
        [part]
            story= _ "Our alliance with Mal Keshar in this era was not my choice, however. Galas and Anlindë knew well what it entailed, and opted for a desperate solution to a desperate situation. But now... I appear to be following the same logic, commanding the dead with a power that was meant to be purged from this world long ago. It seems selfish, and others could misinterpret my actions."
        [/part]
        [part]
            story= _ "I no longer command the Union, and now I am about to confront our enemy while leading my own army of darkness.

It would be no exaggeration to say that the true Lady of Light is, in fact, another impostor."
        [/part]
        [part]
            {STORYTXT_TITLE_CARD_SIMPLE E2S8 _"And then there was Chaos"}
            story= _ "Some day all this will be over, and I will be able to distance myself from civilization again.

But for now, I must fight. And afterwards, I must recover that journal."
        [/part]
    [/story]
#enddef

#
# The lack of storyscreen text for the following sections is by design.
#

#define STORYTXT_NEW_HIVE
    [story]
        [part]
            music=underground.ogg
            {STORYTXT_TITLE_CARD_SIMPLE E2S9 _"New Hive"}
        [/part]
    [/story]
#enddef

#define STORYTXT_THE_BETRAYAL
    [story]
        [part]
            music=underground.ogg
            {STORYTXT_TITLE_CARD_SIMPLE E2S10 _"The Betrayal"}
        [/part]
    [/story]
#enddef

#define STORYTXT_A_FINAL_CONFRONTATION
    [story]
        [part]
            music=suspense.ogg
            {STORYTXT_TITLE_CARD_SIMPLE E2S11 _"A Final Confrontation"}
        [/part]
    [/story]
#enddef

# kate: indent-mode normal; encoding utf-8; space-indent on;


#textdomain wesnoth-After_the_Storm

[scenario]
    id=00_Transience
    name= _ "Transience"
    {MAP 00_Transience.map}
    turns=-1
    next_scenario=01_By_the_Moonlight
    victory_when_enemies_defeated=no
    {DO_NOT_REMOVE_FROM_CARRYOVER_ON_DEFEAT}

    {FULLSCREEN_CUTSCENE_UI}

    {SCENARIO_MUSIC "silence.ogg"}

    {STORYTXT_INIT_WARNING}

    {INDOORS} {SCHEDULE_LIGHTING -40 -40 -10}

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        save_id=player
        {NO_ECONOMY}
        team_name=good
        user_team_name= _ "team_name^Elynia"

        hidden=yes

        shroud=yes

        # wmllint: recognize Elynia
        {CHARACTER_STATS_ELYNIA}
    [/side]
    # wmllint: validate-on

    [event]
        name=prestart

        [store_unit]
            [filter]
                id=Elynia
            [/filter]
            kill=yes
            variable=elynia_store
        [/store_unit]

        {BLACK_SCREEN}

        {LOCK_VIEW}
    [/event]

    [event]
        name=start

        [store_starting_location]
            side=1
        [/store_starting_location]

        [remove_shroud]
            side=1
            x,y=$location.x,$location.y
            radius=10
            [not]
                terrain=Q*,X*,*^X*
            [/not]
        [/remove_shroud]

        [redraw][/redraw]

        [mute_sound_effects][/mute_sound_effects]

        {CAVE_NOISE_SOUND_SOURCE}
        [+sound_source]
            id=cave_sound_source # wmllint: ignore
        [/sound_source]

        [fade_in_sound_effects]
            duration=500
        [/fade_in_sound_effects]

        {FADE_IN}

        # wmllint: recognize Galas
        [unit]
            side,x,y=1,$location.x,$location.y
            {CHARACTER_STATS_GALAS}
            experience=64
            hitpoints=38
            facing=nw
        [/unit]

        # wmllint: recognize Mal Keshar
        [unit]
            side,x,y=1,$location.x,$location.y
            {CHARACTER_STATS_MAL_KESHAR}
            experience=88
            hitpoints=71
            facing=nw
        [/unit]

        [unit]
            side,x,y=1,$location.x,$location.y
            {CHARACTER_STATS_ELYNIA_AS_NON_LEADER}
            experience=112
            hitpoints=59
            facing=nw
        [/unit]

        [redraw][/redraw]

        {CLEAR_VARIABLE location}

        [message]
            speaker=Mal Keshar
            message= _ "I remember hearing of the mandate issued to destroy the Sceptre of Fire back in the day..."
        [/message]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Mal Keshar
            message= _ "I’m curious about why you decided to betray your people by keeping the Sceptre’s core to yourself, Elynia."
        [/message]

        [message]
            speaker=Elynia
            message= _ "That’s nothing of your concern."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "It is not, really? Because to me, it seems that you carry with you a dangerous artifact that these people need for some vaguely-defined purpose that will most certainly bring no good to this world! Destroying it would be the most logical choice right now."
        [/message]

        [message]
            speaker=Elynia
            message= _ "... I beg to differ, but with the Union gone it may well be the only great power remaining on Irdya that we could use to fight Uria and the Iron Triad, unless you know something I am not aware of — which I find unlikely."
        [/message]

        [message]
            speaker=Galas
            message= _ "This isn’t the best moment to argue over this."
        [/message]

        [delay]
            time=1500
        [/delay]

        [message]
            speaker=narrator
            caption= _ "Elyssa"
            image=wesnoth-icon.png
            message= _ "Where are you?"
        [/message]

        [delay]
            time=750
        [/delay]

        [kill]
        [/kill]

        {FADE_TO_BLACK}

        [place_shroud]
            side=1
        [/place_shroud]

        [redraw]
            side=1
        [/redraw]

        [fade_out_sound_effects][/fade_out_sound_effects]

        {REMOVE_SOUND_SOURCE cave_sound_source}

        [reset_sound_effects][/reset_sound_effects]

        {VARIABLE elynia_store.x recall}
        {VARIABLE elynia_store.y recall}

        [unstore_unit]
            variable=elynia_store
            find_vacant=no
        [/unstore_unit]

        {CLEAR_VARIABLE elynia_store}

        {ENDLEVEL_QUIET} {NO_REPLAY_SAVE}
    [/event]
[/scenario]

# kate: indent-mode normal; encoding utf-8; space-indent on;