#textdomain wesnoth-After_the_Storm

[scenario]
    id=09_New_Hive
    name= _ "New Hive"
    {MAP 09_New_Hive.map}
    {TURNS 43 42 41}
    next_scenario=10_The_Betrayal
    victory_when_enemies_defeated=no

    {E_DEATHS}

    {SCENARIO_MUSIC       "climactic_contemplation.ogg"}
    {EXTRA_SCENARIO_MUSIC "breaking_the_chains.ogg"}
    {EXTRA_SCENARIO_MUSIC "legends_of_the_north.ogg"}

    {STORYTXT_NEW_HIVE}

    {INDOORS_HIVE}

#define NH_SHARED_AI_ASPECTS
    {AI_SIMPLE_ALWAYS_ASPECT aggression 5.00}
    {AI_SIMPLE_ALWAYS_ASPECT caution    0.00}
    {AI_SIMPLE_ALWAYS_ASPECT grouping     no}
#enddef

    {SPAWN_CONTROLLER}

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

        {GOLD 120 110 100}
        {INCOME 8 6 5}

        shroud=yes

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

    #
    # Recruiting team
    #
    [side]
        side=2
        team_name=evil
        user_team_name= _ "team_name^Dark Hive"
        {CHAOS_FLAG}

        no_leader=yes # leader should be spawned in a event
        hidden=yes
        {NO_ECONOMY}

        recruit=Shaxthal Drone,Shaxthal Rayblade,Chaos Bowman

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression 0.90}
            {AI_SIMPLE_ALWAYS_ASPECT caution    0.10}
        [/ai]
    [/side]

    #
    # Hive spawns
    #
    [side]
        side=3
        team_name=evil
        user_team_name= _ "team_name^Dark Hive"
        {CHAOS_FLAG}
        color=white

        no_leader=yes
        hidden=yes
        {NO_ECONOMY}

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

    #
    # Hive worms
    #
    [side]
        side=4
        team_name=evil
        user_team_name= _ "team_name^Dark Hive"
        {CHAOS_FLAG}
        color=brown

        no_leader=yes
        hidden=yes
        {NO_ECONOMY}

        {IS_HOSTILE_NPC}
    [/side]

    #
    # Door controller
    #
    [side]
        side=5
        team_name=evil
        user_team_name= _ "team_name^Dark Hive"
        {CHAOS_FLAG}
        color=black

        no_leader=yes
        hidden=yes
        {NO_ECONOMY}
    [/side]

    {NPC_BIRD_BEHAVIOR_WHOLE_MAP 4}

#undef NH_SHARED_AI_ASPECTS

    # wmlindent: start ignoring

#ifdef EASY
#define NH_DRONE _RESPAWN_TURNS _X _Y
    # 1/6 sentry, 5/6 drone
    {TIMED_DRONE_SPAWNER ({_RESPAWN_TURNS}) (
        type=Shaxthal Sentry Drone,Shaxthal Drone,Shaxthal Drone,Shaxthal Drone,Shaxthal Drone,Shaxthal Drone
    ) 3 ({_X}) ({_Y})}
#enddef
#endif

#ifdef NORMAL
#define NH_DRONE _RESPAWN_TURNS _X _Y
    # 1/2 sentry, 1/2 drone
    {TIMED_DRONE_SPAWNER ({_RESPAWN_TURNS}) (
        type=Shaxthal Sentry Drone,Shaxthal Sentry Drone,Shaxthal Sentry Drone,Shaxthal Drone,Shaxthal Drone,Shaxthal Drone
    ) 3 ({_X}) ({_Y})}
#enddef
#endif

#ifdef HARD
#define NH_DRONE _RESPAWN_TURNS _X _Y
    # 1/2 sentry, 1/6 assaulter, 1/3 drone
    {TIMED_DRONE_SPAWNER ({_RESPAWN_TURNS}) (
        type=Shaxthal Sentry Drone,Shaxthal Sentry Drone,Shaxthal Sentry Drone,Shaxthal Assault Drone,Shaxthal Drone,Shaxthal Drone
    ) 3 ({_X}) ({_Y})}
#enddef
#endif

    # wmlindent: stop ignoring

#ifndef EASY
    {ONETIME_DRONE_SPAWNER (type=Shaxthal Drone) 3 20 3}
#endif

    {NH_DRONE 6 13 14}

    {NH_DRONE 7 10 24}
    {NH_DRONE 7 12 27}
    {NH_DRONE 7  4 29}
#ifndef EASY
    {NH_DRONE 9  8 25}
#endif
#ifdef HARD
    {NH_DRONE 10 2 28}
#endif

#ifndef EASY
    {ONETIME_DRONE_SPAWNER (type=Shaxthal Sentry Drone) 3 23 18}
#endif

    {NH_DRONE 10 21 24}
#ifndef EASY
    {NH_DRONE 8 18 28}
#endif
    {NH_DRONE 12 30 27}
    {NH_DRONE 12 31 27}

#ifndef EASY
    {NH_DRONE 8 33 21}
    {NH_DRONE 12 41 19}
    {NH_DRONE 12 28 16}
    {NH_DRONE 12 30 17}
#endif

    {NH_DRONE 6 30  7}
    {NH_DRONE 8 29  6}
#ifndef EASY
    {NH_DRONE 4 27  7}
#endif

#undef NH_DRONE

    {CAVE_WATER_SOUND_SOURCE 20  8}
    {CAVE_WATER_SOUND_SOURCE 28 13}
    {CAVE_WATER_SOUND_SOURCE 22 15}
    {CAVE_WATER_SOUND_SOURCE  6 12}

    {HIVE_NOISE_2_SOUND_SOURCE}

    [event]
        name=prestart

        [time_area]
            id=surface
            terrain=G*,G*^*
            [or]
                x=15-30
                y= 7-17
                terrain=W*,W*^*
            [/or]
            {DUSK2} {SCHEDULE_LIGHTING -40 -40 0}
        [/time_area]

        [item]
            image="items/gohere.png"
            x=39,40-41
            y= 4,    3
        [/item]

        # wmllint: recognize Anya
        {RECALL_ANYA}
        # wmllint: recognize Durvan
        {RECALL_DURVAN}

        {FACE_DIRECTION (side=1) ne}

#define NH_WORM _VARIATIONS _PALETTES _X _Y
    {VARIABLE_RANDOM temp_NH_WORM_palette   ({_PALETTES})}
    {VARIABLE_RANDOM temp_NH_WORM_variation ({_VARIATIONS})}

    [unit]
        side=4
        type=Shaxthal Worm
        upkeep=loyal
        x={_X}
        y={_Y}
        variation=$temp_NH_WORM_variation
        random_traits=yes
        generate_name=yes
        random_gender=yes
        [modifications]
            {UNIT_PALETTE_SWITCH () ("shaxthal_drone_base") ("shaxthal_drone_$temp_NH_WORM_palette")}
        [/modifications]
    [/unit]

    {CLEAR_VARIABLE temp_NH_WORM_palette,temp_NH_WORM_variation}
#enddef

        {NH_WORM a brown 11 6}
        {NH_WORM a brown 22 5}

        {NH_WORM a,b,c brown 3 11}

        {NH_WORM a,b,c brown,purple,cyan,base 2 20}
        {NH_WORM a,b,c brown,purple,cyan,base 27 20}
        {NH_WORM a,b,c brown,purple,cyan,base 29 26}
        {NH_WORM a,b,c brown,purple,cyan,base 29 25}
        {NH_WORM a,b,c brown,purple,cyan,base 32 13}

        {NH_WORM a,b,c brown 35 2}

#undef NH_WORM

        {OBJECTIVES (
            victory_string= _ "Current Objectives:"
            {OBJECTIVE_VICTORY ( _ "Proceed further underground with Elynia")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Anya")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Durvan")}

            {TURNS_RUN_OUT}
        )}
    [/event]

    [event]
        name=start
        [message]
            speaker=Anya
            message= _ "What is this place?"
        [/message]

        [message]
            speaker=Elynia
            message= _ "According to Unarye, the valley was only slightly habitable at first; the elves had to seek refuge in the caverns during the day, while they worked to adapt the surface land to their needs at night. It appears that the Chaos Empire saw fit to turn the place into a Shaxthal hive."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Although Shaxthal creatures are particularly weak against our fire, it’s essential that we remain together as we proceed further underground."
        [/message]
    [/event]

    {GATE_GLYPH 15  1 11  8}

    {GATE_GLYPH  4 21 15 18}

    {OBJ_HEALING_GLYPH 31 23}

    {GATE_GLYPH 36 14 35  9}

    {GATE_GLYPH 25  3 39  3}

    #
    # Activate guardian.
    #
    [event]
        name=moveto
        [filter]
            side=1
            x=32-42
            y=21-30
        [/filter]

        [store_starting_location]
            side=2
        [/store_starting_location]

        [unit]
            side=2
            canrecruit=yes
            type=Chaos Magus
            id=Kaceldyn
            name= _ "Kaceldyn"
            x,y=$location.x,$location.y
            facing=se
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_RESILIENT}
                {BOSS_BOOST 50% 1 1 1 0}
            [/modifications]
        [/unit]

        [modify_side]
            side=2
            {GOLD 60 75 90}
            income=0
            village_gold=1
            hidden=no
        [/modify_side]

        {CAPTURE_VILLAGES 2 $location.x $location.y 7}

        {CLEAR_VARIABLE location}

        [allow_undo][/allow_undo]
    [/event]

    #
    # Clear the invisible barriers around the central water pool. This
    # is intentionally done silently.
    #
    [event]
        name=moveto
        [filter]
            side=1
            x=28-42
            y=11-18
        [/filter]

        [allow_undo][/allow_undo]

        [remove_terrain_overlays]
            terrain="*^Xo"
        [/remove_terrain_overlays]

        [redraw][/redraw]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Elynia
            x=40-42, 39, 38,37,41-42,42
            y=  3-7,4-7,5-6, 6,    8, 2
        [/filter]

        {ENDLEVEL_QUIET}
    [/event]

    [event]
        name=time over

        {QUAKE (explosion-big.ogg)}

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Durvan
            message= _ "What was that?"
        [/message]

        [message]
            speaker=Elynia
            message= _ "I am not sure, but I fear we have wasted too much time in these caves. Whatever happens next is surely our fault."
        [/message]
    [/event]
[/scenario]

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


#textdomain wesnoth-After_the_Storm

[scenario]
    id=10_The_Betrayal
    name= _ "The Betrayal"
    {MAP 10_The_Betrayal.map}
    {TURNS 8 7 6}
    next_scenario=11_A_Final_Confrontation
    victory_when_enemies_defeated=no

    {E_DEATHS}

    {SCENARIO_MUSIC       "underground.ogg"} {CONTINUE_PLAYING_STORY_MUSIC_FIRST}

    {STORYTXT_THE_BETRAYAL}

    {INDOORS_HIVE}

#define TB_SHARED_AI_ASPECTS
    {AI_SIMPLE_ALWAYS_ASPECT aggression 5.00}
    {AI_SIMPLE_ALWAYS_ASPECT caution    0.00}
    {AI_SIMPLE_ALWAYS_ASPECT grouping     no}
#enddef

    {SPAWN_CONTROLLER}

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

        # We're working with AtS E2S9's carryover here
        gold=0
        {INCOME 4 3 2}

        shroud=yes

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

    [side]
        side=2
        team_name=evil
        user_team_name= _ "team_name^Dark Hive"
        {CHAOS_FLAG}

        recruit=Shaxthal Drone,Automaton,Chaos Headhunter
        {GOLD 75 80 95}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression 5.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution    0.00}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "fighter,mixed fighter,mixed fighter,fighter,scout"}
            {AI_SIMPLE_ALWAYS_ASPECT passive_leader yes}
        [/ai]

        # wmllint: recognize Lady of Light
        {CHARACTER_STATS_IVYEL}
        canrecruit=yes
        facing=se

        [village]
            x,y=24,32
        [/village]
        [village]
            x,y=19,32
        [/village]
    [/side]
    # wmllint: validate-on

    [side]
        side=3
        team_name=evil
        user_team_name= _ "team_name^Dark Hive"
        {CHAOS_FLAG}

        recruit=Chaos Invader,Chaos Invoker,Chaos Headhunter,Shaxthal Runner Drone
        {GOLD 120 130 150}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression           1.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution              0.00}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "archer,scout,scout,fighter,mixed fighter,archer"}
        [/ai]

        canrecruit=yes
        type=Hell Guardian
        id=Stalygvan
        name= _ "Stalygvan"
        facing=nw
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_RESILIENT}
        [/modifications]
    [/side]

    [side]
        side=4
        team_name=evil
        user_team_name= _ "team_name^Dark Hive"
        {CHAOS_FLAG}

        recruit=Shaxthal Drone,Automaton,Chaos Headhunter,Chaos Bowman
        {GOLD 140 150 160}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "archer,fighter,scout,mixed fighter,mixed fighter,fighter"}
        [/ai]

        canrecruit=yes
        type=Gutwrencher Imp
        id=Dorghazaquiel
        name= _ "Dorghazaquiel"
        facing=se
        [modifications]
            {TRAIT_SLOW}
            {TRAIT_STRONG}
        [/modifications]

        {GENERIC_UNIT () (Blood Imp) 14 38} {NO_UPKEEP_NO_OVERLAY} {FACING se} {GUARDIAN}
        {GENERIC_UNIT () (Blood Imp)  6 39} {NO_UPKEEP_NO_OVERLAY} {FACING s } {GUARDIAN}
        {GENERIC_UNIT () (Blood Imp) 19 42} {NO_UPKEEP_NO_OVERLAY} {FACING ne} {GUARDIAN}
    [/side]

    [side]
        side=5
        team_name=evil
        user_team_name= _ "team_name^Dark Hive"
        {CHAOS_FLAG}

        recruit=Demon,Shaxthal Rayblade,Chaos Invoker,Chaos Headhunter
        {GOLD 170 190 210}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "scout,mixed fighter,mixed fighter,archer,fighter,mixed fighter"}
        [/ai]

        canrecruit=yes
        type=Demon Warrior
        gender=female
        id=Elathea
        name= _ "Elathea"
        facing=sw
        [modifications]
            {TRAIT_INTELLIGENT}
            {TRAIT_RESILIENT}
            {BOSS_BOOST 10% 2 0 0 1}
        [/modifications]

        {GENERIC_UNIT () (Demon Zephyr) 60 50} {NO_UPKEEP_NO_OVERLAY} {FACING se} {GUARDIAN}
        {GENERIC_UNIT () (Demon Zephyr) 55 51} {NO_UPKEEP_NO_OVERLAY} {FACING sw} {GUARDIAN}
        {GENERIC_UNIT () (Demon Zephyr) 52 45} {NO_UPKEEP_NO_OVERLAY} {FACING nw} {GUARDIAN}
    [/side]

    [side]
        side=6
        team_name=evil
        user_team_name= _ "team_name^Dark Hive"
        {CHAOS_FLAG}

        recruit=Demon,Automaton,Chaos Headhunter,Chaos Invoker
        {GOLD 170 180 200}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "archer,fighter,mixed fighter,mixed fighter,scout,scout,fighter,archer,mixed fighter"}
        [/ai]

        canrecruit=yes
        type=Chaos Razerman
        id=Alareanthalcan
        name= _ "Alareanthalcan"
        facing=sw
        [modifications]
            {TRAIT_QUICK}
            {TRAIT_RESILIENT}
            {BOSS_BOOST 10% 1 0 0 0}
        [/modifications]

#ifndef EASY
        {GENERIC_UNIT () (Shaxthal Rayblade) 58 28} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Rayblade) 56 26} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
#endif
        {GENERIC_UNIT () (Demon Zephyr)      53 33} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
    [/side]

    #
    # Hive spawns
    #
    [side]
        side=7
        team_name=evil
        user_team_name= _ "team_name^Dark Hive"
        {CHAOS_FLAG}

        no_leader=yes
        hidden=yes
        {NO_ECONOMY}

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

        {GENERIC_UNIT () (Shaxthal Rayblade) 49 45} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Rayblade) 46 48} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}

        {GENERIC_UNIT () (Shaxthal Rayblade) 45 31} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}

        {GENERIC_UNIT () (Psy Crawler) 57 33} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Psy Crawler) 51 31} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Psy Crawler) 61 24} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Psy Crawler) 63 27} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}

        {GENERIC_UNIT () (Psy Mindraider) 32 16} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING se}

        {GENERIC_UNIT () (Psy Crawler) 34 18} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING se}
        {GENERIC_UNIT () (Psy Crawler) 36 17} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}

        {GENERIC_UNIT () (Verlissh Matrix Flow System) 55 28} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Verlissh Matrix Flow System) 58 30} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}

        {GENERIC_UNIT () (Giant Spider) 61 16} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING ne}

        {GENERIC_UNIT () (Giant Scorpion)  66 12} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Giant Scorpling) 64 12} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Giant Scorpling) 65 11} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}

        {GENERIC_UNIT () (Leech) 62 8} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}

        {GENERIC_UNIT () (Fungoid) 63 10} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Fungoid) 65  9} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Fungoid) 64  7} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
    [/side]

    #
    # Hive worms
    #
    [side]
        side=8
        team_name=evil
        user_team_name= _ "team_name^Dark Hive"
        {CHAOS_FLAG}

        no_leader=yes
        hidden=yes
        {NO_ECONOMY}

        {IS_HOSTILE_NPC}
    [/side]

#define TB_DOOR _X _Y
    {GENERIC_UNIT () Door ({_X}) ({_Y})} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
#enddef

    #
    # Door controller
    #
    [side]
        side=9
        team_name=evil
        user_team_name= _ "team_name^Dark Hive"
        {CHAOS_FLAG}
        color=black

        no_leader=yes
        hidden=yes
        {NO_ECONOMY}

        {TB_DOOR 63 46}
        {TB_DOOR 34 47}
        {TB_DOOR 11 48}
        {TB_DOOR 12 47}

        {TB_DOOR 62 12}
    [/side]

#undef TB_DOOR

    #
    # Boss controller
    #
    [side]
        side=10
        controller=null
        team_name=evil
        user_team_name= _ "team_name^Dark Hive"
        {CHAOS_FLAG}
        color=gold

        no_leader=yes
        hidden=yes
        {NO_ECONOMY}
    [/side]

#undef TB_SHARED_AI_ASPECTS

    {NPC_BIRD_BEHAVIOR 8 1 67 1 55}

#define TB_DRONE _TYPES _X _Y
    {ONETIME_DRONE_SPAWNER (type={_TYPES}) 7 ({_X}) ({_Y})}
#enddef

    {TB_DRONE (Shaxthal Sentry Drone) 61 32}
#ifndef EASY
    {TB_DRONE (Shaxthal Drone,Shaxthal Sentry Drone,Shaxthal Drone) 59 35}
#else
    {TB_DRONE (Shaxthal Drone) 59 35}
#endif
#ifdef HARD
    {TB_DRONE (Shaxthal Drone,Shaxthal Sentry Drone,Shaxthal Drone) 62 28}
#else
    {TB_DRONE (Shaxthal Drone) 62 28}
#endif

    {TB_DRONE (Shaxthal Drone) 56 21}
    {TB_DRONE (Shaxthal Drone) 58 20}
    {TB_DRONE (Shaxthal Drone) 62 36}
    {TB_DRONE (Shaxthal Drone) 64 35}

    {TB_DRONE (Shaxthal Sentry Drone) 45 25}

#ifdef NORMAL
    {TB_DRONE (Shaxthal Sentry Drone) 43 26}
#endif
#ifdef HARD
    {TB_DRONE (Shaxthal Enforcer Drone) 43 26}
#endif

#undef TB_DRONE

    {PLACE_IMAGE scenery/banner-uria-standing-sw.png 16 31}
    {PLACE_IMAGE scenery/banner-uria-standing-sw.png 19 33}
    {PLACE_IMAGE scenery/banner-uria-standing-sw.png 19 29}
    {PLACE_IMAGE scenery/banner-uria-standing-sw.png 22 30}
    {PLACE_IMAGE scenery/banner-uria-standing-sw.png 57 28}

    {PLACE_IMAGE scenery/whirlpool.png 63 33}
    {PLACE_IMAGE scenery/whirlpool.png 58  9}

    {PLACE_IMAGE items/altar.png 61 15}

    {HIVE_NOISE_2_SOUND_SOURCE}

    {CAVE_WATER_SOUND_SOURCE 57  9}
    {CAVE_WATER_SOUND_SOURCE 62 27}
    {CAVE_WATER_SOUND_SOURCE 59 36}
    {CAVE_WATER_SOUND_SOURCE 48 46}
    {CAVE_WATER_SOUND_SOURCE 62 52}
    {CAVE_WATER_SOUND_SOURCE 38 50}
    {CAVE_WATER_SOUND_SOURCE 27 53}

    [event]
        name=prestart

        {VARIABLE anya_has_mermaid_pendant no} # Must persist after scenario

        {VARIABLE control_glyphs_activated 0}

        [item]
            x=27,28,29
            y=12,11,11
            image="items/gohere.png"
        [/item]

        [remove_shroud]
            side=1
            x= 0-11,12-15
            y=17-30,22-28
            terrain=Qxu,Ur,Rr,X*
            [or]
                x= 9, 7,11,13, 9,12-13,14-15
                y=24,27,25,26,28,   29,   28
            [/or]
        [/remove_shroud]

        [hide_unit]
            id=Lady of Light
        [/hide_unit]

        {OBJECTIVES (
            {OBJECTIVE_VICTORY ( _ "Defeat the false Lady of Light")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Anya")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Durvan")}

            {TURNS_RUN_OUT}
        )}

        [deactivate_and_serialize_sides]
            side=3,4,5
            variable=enemy_sides
        [/deactivate_and_serialize_sides]

        [deactivate_and_serialize_sides]
            side=6
            variable=late_enemy_side
        [/deactivate_and_serialize_sides]
    [/event]

    [event]
        name=start

        {LOCK_VIEW}

        {MOVE_UNIT (id=Elynia) 13 28}

        [redraw]
            # clear shroud
            side=1
        [/redraw]

        [scroll_to_unit]
            id=Elynia
        [/scroll_to_unit]

        # wmllint: recognize Anya
        {RECALL_ANYA_AT_LOCATION   13 27}
        # wmllint: recognize Durvan
        {RECALL_DURVAN_AT_LOCATION 11 28}

        {FACE_DIRECTION (side=1) se}

        [redraw][/redraw]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Anya
            message= _ "Another gate..."
        [/message]

        [unit]
            x,y=14,28
            side=9
            type=Door
            upkeep=free
            max_hitpoints=8
        [/unit]

        [animate_attack]
            [filter]
                x,y=14,28
            [/filter]
            [filter_second]
                id=Elynia
            [/filter_second]
            [filter_attack]
                name=staff
            [/filter_attack]
            kill=yes
            animate=yes
            fire_event=no
            amount=8
            #experience=no
        [/animate_attack]

        [remove_terrain_overlays]
            x=13,14,15
            y=29,28,28
        [/remove_terrain_overlays]

        [redraw]
            # clear shroud
            side=1
        [/redraw]

        {MOVE_UNIT (id=Elynia) 16 29}
        {MOVE_UNIT (id=Anya) 16 28}
        {MOVE_UNIT (id=Durvan) 14 29}

        {MODIFY_UNIT (id=Elynia,Anya,Durvan) moves 0}

        [capture_village]
            side=1
            x=14,19
            y=29,30
        [/capture_village]

        [remove_shroud]
            side=1
            x,y=19,31
            radius=15
            [filter_radius]
                [not]
                    terrain=X*,X*^*,*^X*,Q*,*^Z*,*^P*
                [/not]
            [/filter_radius]
        [/remove_shroud]

        [redraw]
            # clear shroud
            side=1
        [/redraw]

        [delay]
            time=500
        [/delay]

        {REPLACE_SCENARIO_MUSIC "the_city_falls.ogg"}

        [message]
            speaker=Anya
            message= _ "Look! It’s the impostor again!"
        [/message]

        [unhide_unit]
            id=Lady of Light
        [/unhide_unit]

        [scroll_to_unit]
            id=Lady of Light
        [/scroll_to_unit]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Lady of Light
            message= _ "I have to destroy her... yes, I have to... I must not fail this time..."
        [/message]

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Elynia
            message= _ "So here you are, traitor."
        [/message]

        [scroll_to_unit]
            id=Lady of Light
        [/scroll_to_unit]

        {FACE_DIRECTION (id=Lady of Light) nw}

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Lady of Light
            message= _ "I AM NOT A TRAITOR! I’LL DESTROY YOU THIS TIME!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "I have had enough of this — surround her and strike her down! Do not let her get away!"
        [/message]

        [terrain]
            x=13,14,15
            y=29,28,28
            terrain=Uu^Xo
            layer=overlay
        [/terrain]

        [redraw][/redraw]

        {UNLOCK_VIEW}
    [/event]

    [event]
        name=turn 2
        {MODIFY_AI_DELETE_ASPECT 2 passive_leader always}
    [/event]

    [event]
        name=last breath
        [filter]
            id=Lady of Light
        [/filter]

        {LOCK_VIEW}

        {CLEAR_LABELS}

        [message]
            speaker=Lady of Light
            message= _ "No... Let me go!"
        [/message]

        # Stop any playing attack/defense animations
        [animate_unit]
            [filter]
                x,y=$x2,$y2
            [/filter]
            flag=standing
        [/animate_unit]

        [animate_unit]
            [filter]
                x,y=$x1,$y1
            [/filter]
            flag=standing
        [/animate_unit]

        {VARIABLE lolx $x1}
        {VARIABLE loly $y1}

        [message]
            speaker=Elynia
            message= _ "You and your accursed allies have been conspiring against us and the Grand Council of the Northern Peoples, sowing strife and destruction. Whoever you are, your heinous deeds make you unworthy of my mercy. You no longer deserve a place amongst elvenkind."
        [/message]

        [message]
            speaker=Lady of Light
            message= _ "... Elynia... please..."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Leave this world now, and never return again!"
        [/message]

        [scroll_to_unit]
            id=Lady of Light
        [/scroll_to_unit]

        {FLASH_RED (
            [animate_unit]
                [filter]
                    id=Lady of Light
                [/filter]
                flag=cutscene_burning
                with_bars=yes
            [/animate_unit]

            [transform_unit]
                id=Lady of Light
                transform_to=Shaxthal Infiltrator
            [/transform_unit]

            # wmllint: recognize Ivyel
            [modify_unit]
                [filter]
                    id=Lady of Light
                [/filter]
                hitpoints=1
                moves=0
                attacks_left=0
                id=Ivyel
                name= _ "Ivyel"
                [modifications]
                    {TRAIT_BIOMECHANICAL}
                    {TRAIT_RESILIENT}
                    {TRAIT_DEXTROUS}
                [/modifications]
            [/modify_unit]
        )}

        [scroll_to_unit]
            id=Ivyel
        [/scroll_to_unit]

        {REPLACE_SCENARIO_MUSIC "into_the_shadows.ogg"}
        {APPEND_MUSIC           "underground.ogg"}

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Elynia
            message= _ "(confused) What is this?"
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Ivyel
            message= _ "... Please... don’t... attack me..."
        [/message]

        [message]
            speaker=Elynia
            message= _ "But... how... how is this possible?"
        [/message]

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

        [move_unit_fake]
            x="$lolx|,24,27"
            y="$loly|,33,35"
            side=2
            type=Shaxthal Infiltrator
        [/move_unit_fake]

        [message]
            speaker=Elynia
            message= _ "This doesn’t make sense!"
        [/message]

        [delay]
            time=500
        [/delay]

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

        [message]
            speaker=Elynia
            message= _ "Who is that?!"
        [/message]

        [delay]
            time=250
        [/delay]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "(more cackling) What do you think of our first complete infiltrator? It took us great effort to design and build such perfection."
        [/message]

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Elynia
            message= _ "(angry) I know you... You are one of the members of the Iron Council, Mal Hekuba!"
        [/message]

        [store_direction]
            from_x,from_y=22,32
            [to]
                [filter]
                    id=Elynia
                [/filter]
            [/to]
        [/store_direction]

        # wmllint: recognize Mal Hekuba
        [unit]
            {CHARACTER_STATS_MAL_HEKUBA}
            canrecruit=yes
            {IS_BOSS}
            side=10
            x,y=22,32
            facing=$direction
            [+modifications]
                [object]
                    [effect]
                        apply_to="image_mod"
                        add="O(0.8)"
                    [/effect]
                [/object]
            [/modifications]
        [/unit]

        [message]
            speaker=Mal Hekuba
            message= _ "Did you miss me, Elynia?"
        [/message]

#define TB_FIX_ELYNIA_FACING
    {FACE_UNIT (id=Elynia) (id=Mal Hekuba)}
#enddef

        {TB_FIX_ELYNIA_FACING}

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Elynia
            message= _ "... I couldn’t possibly wish harder for you and your friends’ destruction."
        [/message]

        [message]
            speaker=Mal Hekuba
            message= _ "Ha, ha, but that’s not going to happen in your lifetime, or is it?"
        [/message]

#define TB_BOSS_TELEHIDE
    [scroll_to_unit]
        id=Mal Hekuba
    [/scroll_to_unit]

    [animate_unit]
        [filter]
            id=Mal Hekuba
        [/filter]
        flag=pre_teleport
        with_bars=yes
    [/animate_unit]

    [store_unit]
        [filter]
            id=Mal Hekuba
        [/filter]
        kill=yes
        variable=boss_store
    [/store_unit]
#enddef

#define TB_BOSS_TELESHOW _X _Y
    [scroll_to]
        x={_X}
        y={_Y}
    [/scroll_to]

    {VARIABLE boss_store.x ({_X})}
    {VARIABLE boss_store.y ({_Y})}

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

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

    [animate_unit]
        [filter]
            id=Mal Hekuba
        [/filter]
        flag=post_teleport
        with_bars=yes
    [/animate_unit]
#enddef

        {TB_BOSS_TELEHIDE}

        # TODO: move Elynia around as if she were searching for Hekuba

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Elynia
            message= _ "Where are you? Stop fooling around and show yourself, you—"
        [/message]

        {TB_BOSS_TELESHOW 14 32}

        [message]
            speaker=Mal Hekuba
            message= _ "I understand that you must be confused and enraged after losing your friends to such a pointless cause, and traveling so far only to slaughter the same people whom you once vowed to protect!"
        [/message]

        {TB_FIX_ELYNIA_FACING}

        # TODO: move Elynia around, trying to attack Hekuba

        {TB_BOSS_TELEHIDE}

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Anya
            message= _ "It appears to be just an illusion..."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Destroying you is NOT a pointless cause!"
        [/message]

#define TB_VOICE _MESSAGE
    [message]
        speaker=narrator
        caption= _ "Mal Hekuba"
        image=wesnoth-icon.png
        message=""+{_MESSAGE}+"" # wmllint: ignore
    [/message]
#enddef

        {TB_VOICE ( _ "But of course it is! You cannot destroy us! Not without the power of the Union, anyway, which you left behind in Uria’s sacred domain when you destroyed your beloved Argan.")}

        [message]
            speaker=Elynia
            message= _ "I still have the Ruby of Fire!"
        [/message]

        # po: "Argan’s treacherous little girl" refers to Elyssa.
        {TB_VOICE ( _ "That understandably attractive relic is not important for me. Argan’s treacherous little girl likes to think of it as if it were unique and irreplaceable, and convinced Uria of that — but in truth, it is not.")}

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "What are you babbling about?"
        [/message]

        # po: "Her finding out" refers to Elyssa.
        {TB_VOICE ( _ "The first set of replicas of Yechnagoth’s heart were lost when you and your pathetic lackey destroyed our base in Wesmere, but I have had plenty of time to create more here without her finding out. I am sure that together, they are as good or better than the original, and they might even be a superior substitute for your precious gem.")}

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Elynia
            message= _ "Are you working against Uria’s will, then?"
        [/message]

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

        {TB_BOSS_TELESHOW $elynia_loc.x $elynia_loc.y}

        {CLEAR_VARIABLE elynia_loc}

        {TB_FIX_ELYNIA_FACING}

        [message]
            speaker=Mal Hekuba
            message= _ "(losing his temper) We cannot speak to her directly! We can only do so through that treacherous wench, who keeps the Dark Lady’s heart within her for her own purposes!"
        [/message]

        {TB_BOSS_TELEHIDE}

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Elynia
            message= _ "... We... We destroyed Wesmere... Yechnagoth’s heart wasn’t there?! What did we destroy when we..."
        [/message]

        {TB_VOICE ( _ "The energy that should have destroyed you was released from the second replica of her heart, and various experimental units stored in the same place. The third one still exists within our infiltrator, imbuing her with Yechnagoth’s grace and might — which is why your power is no match for hers.")}

        # po: "Argan’s pet" is Elyssa.
        {TB_VOICE ( _ "Nevertheless, I do not have time to continue talking to you. Right now, I need to go to tend to some... rituals. Ivyel was created to destroy both you and Argan’s pet. Take a good glance at her perfection once she returns, for it will be your last opportunity.")}

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

#undef TB_VOICE
#undef TB_BOSS_TELEHIDE
#undef TB_BOSS_TELESHOW
#undef TB_FIX_ELYNIA_FACING

        [redraw][/redraw]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Anya
            message= _ "What are we going to do now?"
        [/message]

        [message]
            speaker=Durvan
            message= _ "Those bastards can’t get away with this! My lady, we must do something!"
        [/message]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Elynia
            message= _ "I don’t think we have the power necessary to destroy the artifacts that Mal Hekuba is going to use to..."
        [/message]

        [message]
            speaker=Anya
            message= _ "Of course we do! We didn’t come all the way from the northern lands risking that blasted Ruby for nothing! Whatever that lich is going to do, it will destroy us all if we don’t stop him now!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "The last time we fought against that power, I lost a friend, and the vast plains of Wesmere vanished with his remains..."
        [/message]

        [message]
            speaker=Anya
            message= _ "Any course of action at this point will inevitably lead to someone’s destruction, but I’m sure we can do it this time! If the lich is going to create a... path to Inferno, as Elorran said, perhaps we can cause it to collapse at the other side!"
        [/message]

        [message]
            speaker=Durvan
            message= _ "I don’t truly understand most of this nonsense about hearts and Yechnagoth, but I reckon we need to destroy the lich and the impostor — and we can’t do that without your help, Elynia."
        [/message]

        [message]
            speaker=Anya
            message= _ "We don’t have much time! That thing we just fought could be back at any moment!"
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "I appreciate your support... I don’t think I could have come this far alone. And I don’t want to force you to follow me..."
        [/message]

        [message]
            speaker=Anya
            message= _ "Of course not! We are your friends!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "Let’s find that foul fiend and destroy him once and for all."
        [/message]

        {OBJECTIVES (
            victory_string= _ "Current Objectives:"
            {OBJECTIVE_VICTORY ( _ "Proceed further underground with Elynia to find Mal Hekuba")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Anya")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Durvan")}

            {TURNS_RUN_OUT}
        )}

        [fire_event]
            name=activate enemy sides
        [/fire_event]

#define TB_GATE_LOCS
    x=23,24,25
    y=34,33,33
#enddef

        [remove_terrain_overlays]
            {TB_GATE_LOCS}
        [/remove_terrain_overlays]

        [remove_shroud]
            side=1
            {TB_GATE_LOCS}
        [/remove_shroud]

        [redraw]
            side=1
        [/redraw]

        [scroll_to]
            x,y=24,33
        [/scroll_to]

        {HIGHLIGHT_GOAL ({TB_GATE_LOCS})}

#undef TB_GATE_LOCS

        [scroll_to_unit]
            id=Elynia
        [/scroll_to_unit]

        [redraw][/redraw]

        {REPLACE_SCENARIO_MUSIC "knalgan_theme.ogg"}
        {APPEND_MUSIC           "the_deep_path.ogg"}
        {APPEND_MUSIC           "heroes_rite.ogg"  }
        {APPEND_MUSIC           "western_theme2.ogg"}

        {CLEAR_VARIABLE direction,boss_store,lolx,loly}

        {UNLOCK_VIEW}
    [/event]

#define TB_CAPTURE_STARTING_VILLAGES _SIDE _RADIUS
    [store_starting_location]
        side={_SIDE}
        variable=temp_TB_CAPTURE_STARTING_VILLAGES
    [/store_starting_location]

    {CAPTURE_VILLAGES_OF_TYPE (*^V*) {_SIDE} $temp_TB_CAPTURE_STARTING_VILLAGES.x $temp_TB_CAPTURE_STARTING_VILLAGES.y {_RADIUS}}

    {CLEAR_VARIABLE temp_TB_CAPTURE_STARTING_VILLAGES}
#enddef

    [event]
        name=activate enemy sides

        [unserialize_and_activate_sides]
            variable=enemy_sides
        [/unserialize_and_activate_sides]

        {CLEAR_VARIABLE enemy_sides}

        {TB_CAPTURE_STARTING_VILLAGES 3 12}

        {TB_CAPTURE_STARTING_VILLAGES 4 6}

        {TB_CAPTURE_STARTING_VILLAGES 5 12}

        [modify_turns]
            {QUANTITY value 62 60 58}
        [/modify_turns]

        [redraw][/redraw]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x=40   ,41-58
            y=23-32,23-34
        [/filter]

        [fire_event]
            name=activate late enemy side
            [primary_unit]
                x,y=$x1,$y1
            [/primary_unit]
        [/fire_event]
    [/event]

    [event]
        name=activate late enemy side

        [unserialize_and_activate_sides]
            variable=late_enemy_side
        [/unserialize_and_activate_sides]

        {CLEAR_VARIABLE late_enemy_side}

        {TB_CAPTURE_STARTING_VILLAGES 6 10}

#define TB_WORM _X _Y
    {VARIABLE_RANDOM temp_TB_WORM_palette   brown,purple,cyan,base}
    {VARIABLE_RANDOM temp_TB_WORM_variation a,b,c}

    [unit]
        side=8
        type=Shaxthal Worm
        upkeep=loyal
        x={_X}
        y={_Y}
        variation=$temp_TB_WORM_variation
        random_traits=yes
        generate_name=yes
        random_gender=yes
        [modifications]
            {UNIT_PALETTE_SWITCH () ("shaxthal_drone_base") ("shaxthal_drone_$temp_TB_WORM_palette")}
        [/modifications]
    [/unit]

    {CLEAR_VARIABLE temp_TB_WORM_palette,temp_TB_WORM_variation}
#enddef

        {TB_WORM 57 40}
        {TB_WORM 69 34}
        {TB_WORM 68 26}
        {TB_WORM 49 17}
        {TB_WORM 60 11}
        {TB_WORM 39  5}
        {TB_WORM 21 19}

#undef TB_WORM

        [redraw][/redraw]

        [allow_undo][/allow_undo]

        [message]
            speaker=Alareanthalcan
            message= _ "They are getting closer to the control chamber! Get them, quickly!"
        [/message]

        [message]
            speaker=Anya
            message= _ "I don’t like the sound of that..."
        [/message]

        [scroll_to]
            x,y=$x1,$y1
        [/scroll_to]
    [/event]

#undef TB_CAPTURE_STARTING_VILLAGES

#define TB_DETECT_GLYPH_STATE _X _Y
    [event]
        name=moveto
        [filter]
            side=1
            x={_X}
            y={_Y}
        [/filter]

        {VARIABLE_INC control_glyphs_activated}

        [fire_event]
            name=check objective change
        [/fire_event]
    [/event]
#enddef

    {GATE_GLYPH 65 47 39 35}
    {TB_DETECT_GLYPH_STATE 65 47}

    {GATE_GLYPH  6 35 41 34}
    {TB_DETECT_GLYPH_STATE  6 35}

    {GATE_GLYPH 48 46 37 36}
    {TB_DETECT_GLYPH_STATE 48 46}

#undef TB_DETECT_GLYPH_STATE

    {GATE_GLYPH 62 25 36 19}

    {OBJ_HEALING_GLYPH 58 22}

    {OBJ_HEALING_GLYPH 59 29}

    {OBJ_HEALING_GLYPH 52 32}

    [event]
        name=last breath
        [filter]
            id=Stalygvan
        [/filter]

        [message]
            speaker=Stalygvan
            message= _ "You! You can’t stop our master! You can’t—"
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id=Stalygvan
        [/filter]

        [hide_unit]
            x,y=$x1,$y1
        [/hide_unit]

        # wmllint: recognize Kardas
        {UNIT 1 (Elvish Fighter) 35 39 (
            id=Kardas
            name= _ "Kardas"
            unrenamable=yes
            upkeep=free
            {IS_LOYAL}
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_INTELLIGENT}
            [/modifications]
        )}

        {MOVE_UNIT (id=Kardas) 36,36 39,40}

        [message]
            speaker=Kardas
            message= _ "My lady! At last, I found you! I know where the lich is!"
        [/message]

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

        [remove_shroud]
            side=1
            x=35,35,36,36,36,37,37,37,37,38,38,38,38,38,39,39,39,39,39,39,40,40,40,40,41,41,41,42,42,43
            y=35,36,34,35,36,34,35,36,37,33,34,35,36,37,33,34,35,36,37,38,33,34,35,36,34,35,36,34,35,35
        [/remove_shroud]

        [redraw]
            side=1
        [/redraw]

        [scroll_to]
            x,y=39,35
        [/scroll_to]

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Kardas
            message= _ "The catacombs below guard an artifact of some sort. Nobody knows exactly what it is, but we know the entrance is protected by a gate controlled by three crystals found near this guard post."
        [/message]

        [simplify_location_filter]
            x=33-44
            y=31-38
            terrain="*^Zz\,*^Zz/,*^Zz|"
            variable=glyph_gate_locs
        [/simplify_location_filter]

        [repeat]
            times=3
            [do]
                [remove_terrain_overlays]
                    x=$glyph_gate_locs.x
                    y=$glyph_gate_locs.y
                [/remove_terrain_overlays]

                [redraw][/redraw]

                [delay]
                    time=300
                [/delay]

                [terrain]
                    x=$glyph_gate_locs.x
                    y=$glyph_gate_locs.y
                    terrain="Uu^Zz\" # \"" calm vscode down
                    layer=overlay
                [/terrain]

                [redraw][/redraw]

                [delay]
                    time=300
                [/delay]
            [/do]
        [/repeat]

        {CLEAR_VARIABLE glyph_gate_locs}

        [message]
            speaker=Elynia
            message= _ "Let’s find those crystals, then."
        [/message]

        [scroll_to]
            x,y=$x2,$y2
        [/scroll_to]

        {OBJECTIVES (
            victory_string= _ "Current Objectives:"
            {OBJECTIVE_VICTORY ( _ "Locate and activate the three control crystals to open the central gates")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Anya")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Durvan")}

            {TURNS_RUN_OUT}
        )}
    [/event]

    [event]
        name=last breath
        [filter]
            id=Elathea
        [/filter]

        [message]
            speaker=Elathea
            message= _ "May Uria punish you all for this—"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Dorghazaquiel
        [/filter]

        [message]
            speaker=Dorghazaquiel
            message= _ "Nooooaaagh... it hurts!!!"
        [/message]

        [message]
            x,y=$x2,$y2
            [and]
                race=human
                [or]
                    race=faerie
                [/or]
                [or]
                    race=elf
                [/or]
            [/and]
            [or]
                id=Anya
            [/or]
            message= _ "The beast’s body is dissolving into slime!"
        [/message]

        [scroll_to]
            x,y=$x1,$y1
        [/scroll_to]
    [/event]

    [event]
        name=die
        [filter]
            id=Dorghazaquiel
        [/filter]

        [repeat]
            times={DIFF 2 4 4}
            [do]
                [unit]
                    side=4
                    type=Mudcrawler
                    random_gender=yes
                    random_traits=yes
                    generate_name=yes
                    upkeep=loyal
                    x,y=$x1,$y1
                    animate=yes
                [/unit]
            [/do]
        [/repeat]
    [/event]

    [event]
        name=check objective change
        [filter_condition]
            {VARIABLE_NUMERICAL_GREATER_THAN_OR_EQUAL control_glyphs_activated 3}
        [/filter_condition]

        {OBJECTIVES (
            victory_string= _ "Current Objectives:"
            {OBJECTIVE_VICTORY ( _ "Proceed further underground with Elynia to find Mal Hekuba")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Anya")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Durvan")}

            {TURNS_RUN_OUT}
        )}
    [/event]

    [event]
        name=last breath
        [filter]
            id=Alareanthalcan
        [/filter]

        [message]
            speaker=Alareanthalcan
            message= _ "Even though I have fallen, you are no match for my master’s power!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "We’ll see about that very soon."
        [/message]

        [scroll_to]
            x,y=$x1,$y1
        [/scroll_to]
    [/event]

    {FIRE_EVENT_ON_STUMBLE_UPON (found mindraider) (type=Psy Mindraider)}

    [event]
        name=found mindraider
        [redraw]
            side=1
        [/redraw]

        [scroll_to]
            x,y=$x2,$y2
        [/scroll_to]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Durvan
            message= _ "What in blazes is that creature?!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "Don’t meet its gaze! It will drain your life force!"
        [/message]

        [scroll_to]
            x,y=$x1,$y1
        [/scroll_to]
    [/event]

    [event]
        id=whirlpool_hint
        name=moveto
        first_time_only=no
        [filter]
            side=1
            x,y=63,33
            [not]
                id=Anya
            [/not]
        [/filter]

        [allow_undo][/allow_undo]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "The whirlpool is overflowing with an unusual energy.

A dark energy."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Anya
            x,y=63,33
        [/filter]

        [remove_event]
            id=whirlpool_hint
        [/remove_event]

        [message]
            speaker=Anya
            message= _ "Hm, what is this? There seems to be something at the bottom..."
        [/message]

        [message]
            speaker=Durvan
            message= _ "I wouldn’t get too close if I were you. It could be another one of those biomechanical abominations."
        [/message]

        [message]
            speaker=Anya
            message= _ "I mean, it doesn’t look like there are any creatures in the water anyway. (touches the water)"
        [/message]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Elynia
            message= _ "Anya, what are you doing?"
        [/message]

        [message]
            speaker=Anya
            message= _ "Er, ummm... nothing! I just— AAAAAAAAAAAHHHH!!!"
        [/message]

        [store_unit]
            [filter]
                id=Anya
            [/filter]
            variable=anya_store
            kill=no
        [/store_unit]

        # TODO: proper animation

        [kill]
            id=Anya
            fire_event=no
            animate=yes
        [/kill]

        [message]
            speaker=Elynia
            caption= _ "Elynia and Durvan"
            scroll=no
            message=""+_"ANYA!!!"+""
        [/message]

        [delay]
            time=750
        [/delay]

        {VARIABLE anya_store.x 58}
        {VARIABLE anya_store.y  9}

        [unstore_unit]
            variable=anya_store
        [/unstore_unit]

        {CLEAR_VARIABLE anya_store}

        [message]
            speaker=Elynia
            scroll=no
            message= _ "No... please don’t do this to me—"
        [/message]

        [message]
            speaker=Anya
            scroll=no
            message= _ "I am all right!"
        [/message]

        [message]
            speaker=Elynia
            scroll=no
            message= _ "... Anya? Where are you???"
        [/message]

        [delay]
            time=750
        [/delay]

        [redraw]
            side=1
        [/redraw]

        [scroll_to_unit]
            id=Anya
            {WARP}
        [/scroll_to_unit]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Anya
            message= _ "I don’t really know? The current dragged me into a small chamber that seems to be right below where you are. I think I may be able to get back to you? Good thing I can swim."
        [/message]

        [scroll_to_unit]
            id=Elynia
            {WARP}
        [/scroll_to_unit]

        [message]
            speaker=Elynia
            message= _ "Yes, you can swim... but I cannot. You should return to us before anything happens to you down there."
        [/message]

        [scroll_to_unit]
            id=Anya
            {WARP}
        [/scroll_to_unit]

        [message]
            speaker=Anya
            message= _ "Nah, it will be fine. Don’t worry about me. I am just going to do a little exploring down here and come back."
        [/message]

        # I will be seriously disappointed if someone gets to this point with
        # Anya still under level 3.

        [transient_message]
            image=units/faeries/nightshade-fire.png
            message= _ "Anya can return to the main area by going back through the whirlpool, in a similar fashion to how units can teleport between villages they already control."
        [/transient_message]

        [tunnel]
            [filter]
                id=Anya
            [/filter]

            [source]
                x,y=63,33
            [/source]
            [target]
                x,y=58,9
            [/target]
            bidirectional=yes
        [/tunnel]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Anya
            x,y=61,15
        [/filter]

        {VARIABLE anya_has_mermaid_pendant yes}

        # You may have seen this name in a different game before. But where?

        [transient_message]
            caption= _ "Mermaid’s Pendant"
            image=icons/jewelry_ring_prismatic.png
            # po: The sudden shift to second person narration is quite
            # po: intentional. You will see more of this throughout Episode 3.
            message= _ "This beautiful pendant made from an iridescent conch shines all the colors of the rainbow under the light cast on the altar. The spectacle is absolutely mesmerizing, but you figure you need to find out what uses this marvelous item has.

Unfortunately, there is absolutely nothing engraved on it or the altar that could possibly be of help to you. How disappointing, you think. Maybe this little adventure was an absolute waste of time. But something in your mind tells you that perhaps you are supposed to wait for the right person and the right opportunity to make use of the artifact. When is that going to be, you wonder? The answer eludes you.

You should probably go back to Elynia for the time being."
        [/transient_message]

        #
        # Have Anya and Elynia converse next time they are next to each other.
        #

        [event]
            name=moveto
            [filter]
                id=Anya
                [filter_adjacent]
                    id=Elynia
                [/filter_adjacent]
                [or]
                    id=Elynia
                    [filter_adjacent]
                        id=Anya
                    [/filter_adjacent]
                [/or]
            [/filter]

            [allow_undo][/allow_undo]

            [message]
                speaker=Elynia
                message= _ "So, how was your little adventure?"
            [/message]

            [message]
                speaker=Anya
                message= _ "Well, I found this on an altar! It’s so shiny!"
            [/message]

            [message]
                speaker=Elynia
                message= _ "... A seashell pendant? How did it find its way here, so far from the ocean?"
            [/message]

            [message]
                speaker=Durvan
                message= _ "It could be some kind of keepsake the elves brought here when they first arrived?"
            [/message]

            [message]
                speaker=Elynia
                message= _ "That is the most likely answer, yes."
            [/message]

            [message]
                speaker=Anya
                message= _ "Do you think it has magical properties? Maybe I can summon water creatures! Or water... projectiles of some kind? Perhaps I can shoot bubbles!"
            [/message]

            [delay]
                time=750
            [/delay]

            [message]
                speaker=Elynia
                message= _ "No... I am afraid there is no magic in this pendant at all."
            [/message]

            [message]
                speaker=Anya
                message= _ "Wh... what."
            [/message]

            [delay]
                time=750
            [/delay]

            [message]
                speaker=Anya
                message= _ "Did I actually just risk my life fighting that... giant... spider... to obtain a completely mundane pendant?"
            [/message]

            [message]
                speaker=Elynia
                message= _ "So it would seem."
            [/message]

            [delay]
                time=750
            [/delay]

            [message]
                speaker=Anya
                message= _ "... Oh well... At least it’s pretty! I’m going to keep it if you don’t mind."
            [/message]

            [message]
                speaker=Elynia
                message= _ "Sure. Just... don’t do that again, please? You had us really worried for a moment there."
            [/message]

            [message]
                speaker=Anya
                message= _ "I know, I’m sorry..."
            [/message]
        [/event]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x=23-31,26-29,27
            y= 1-10,   11,12
        [/filter]

        {ENDLEVEL_QUIET}
    [/event]

    [event]
        name=time over

        {QUAKE "rumble.ogg"}

        {QUAKE "explosion-big.ogg"}

        [message]
            speaker=Anya
            message= _ "It is probably too late to stop that lich by now..."
        [/message]
    [/event]

    [event]
        name=victory

        {QUAKE "rumble.ogg"}

        [message]
            speaker=Elynia
            message= _ "Make haste!"
        [/message]

        {CLEAR_VARIABLE control_glyphs_activated}
    [/event]
[/scenario]

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