#textdomain wesnoth-After_the_Storm

[scenario]
    id=09_The_Triad_part_1
    name= _ "The Triad — Part 1"
    {MAP 09_The_Triad_part_1.map}
    turns=-1
    next_scenario="09_The_Triad_part_2"
    victory_when_enemies_defeated=no

    disallow_recall=yes

    {FULLSCREEN_CUTSCENE_UI}

    {A_DEATHS}

    {SCENARIO_MUSIC "the_dangerous_symphony.ogg"}

    {STORYTXT_THE_TRIAD}

    {INDOORS} {SCHEDULE_LIGHTING -30 -40 -20}

    # wmllint: validate-off

    [side]
        save_id=player

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

        {NO_ECONOMY}

        # wmllint: recognize Galas
        {CHARACTER_STATS_GALAS}
    [/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=sw
    [/side]

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

        {NO_ECONOMY}

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

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

        {NO_ECONOMY}

        canrecruit=yes
        # wmllint: recognize Nar-hamoth
        {CHARACTER_STATS_NAR_HAMOTH}
        facing=sw
    [/side]

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

        {NO_ECONOMY}

        canrecruit=yes
        # wmllint: recognize Mal Hekuba
        {CHARACTER_STATS_MAL_HEKUBA}
        facing=sw
    [/side]

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

        no_leader=yes
        {NO_ECONOMY}
    [/side]

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

        no_leader=yes
        {NO_ECONOMY}
    [/side]

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

        no_leader=yes
        {NO_ECONOMY}
    [/side]

    # wmllint: validate-on

    {ANIMATED_BRAZIER 4  4 }

    {ANIMATED_BRAZIER 20 9 }

    {ANIMATED_BRAZIER 14 12}

    {ANIMATED_BRAZIER 4  10}

    {PLACE_IMAGE scenery/banner-uria-standing.png        10  3}
    {PLACE_IMAGE scenery/banner-yechnagoth-standing.png   9  4}
    {PLACE_IMAGE scenery/banner-uria-standing.png         8  4}
    {PLACE_IMAGE scenery/banner-yechnagoth-standing.png   7  5}

    {PLACE_IMAGE scenery/banner-uria-standing.png        20  8}
    {PLACE_IMAGE scenery/banner-yechnagoth-standing.png  19  9}
    {PLACE_IMAGE scenery/banner-uria-standing.png        18  9}
    {PLACE_IMAGE scenery/banner-yechnagoth-standing.png  17 10}

    {PLACE_IMAGE scenery/banner-uria-standing-sw.png        8  7}
    {PLACE_IMAGE scenery/banner-yechnagoth-standing-sw.png 13 10}

    {FORCE_CHANCE_TO_HIT (side=1) () 100 ({VARIABLE_NUMERICAL_EQUALS turn_number 1})}

    {CAVE_NOISE_SOUND_SOURCE}

    [event]
        name=prestart

        [item]
            x,y=15,6
            image="items/staff-elynia-niryone.png"
        [/item]

        [store_side]
            side=1
            variable=main_side1_stats
        [/store_side]

        [modify_side]
            side=1
            gold=0
        [/modify_side]

        [disallow_recruit]
            side=1
            type=$main_side1_stats.recruit
        [/disallow_recruit]

        {FACE_DIRECTION (id=Galas) ne}

        # wmllint: recognize Elynia

        [if]
            {VARIABLE_NUMERICAL_EQUALS elynia_store.length 0}
            [then]
                {RECALL_ELYNIA}

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

        [set_variables]
            name=elynia_store
            mode=merge
            [value]
                x,y=14,6
                hitpoints="$($elynia_store.max_hitpoints * 0.75)"
                facing=ne
            [/value]
        [/set_variables]

        [unstore_unit]
            variable=elynia_store
        [/unstore_unit]

        [object]
            [filter]
                id=Elynia
            [/filter]
            [effect]
                apply_to=variation
                name=chained
            [/effect]
            silent=yes
        [/object]

        #
        # Apparently the variation switch resets current HP.
        #
        {MODIFY_UNIT id=Elynia hitpoints $elynia_store.hitpoints}

        [unit]
            side=6
            type=Chaos Invader
            x,y=10,6
            facing=se
        [/unit]
        [unit]
            side=6
            type=Chaos Invader
            x,y=11,6
            facing=se
        [/unit]
        [unit]
            side=6
            type=Chaos Invader
            x,y=12,5
            facing=se
        [/unit]
        [unit]
            side=6
            type=Chaos Invader
            x,y=13,5
            facing=se
        [/unit]

        [unit]
            side=6
            type=Chaos Invader
            x,y=17,7
            facing=nw
        [/unit]
        [unit]
            side=6
            type=Chaos Invader
            x,y=16,7
            facing=nw
        [/unit]
        [unit]
            side=6
            type=Chaos Invader
            x,y=15,8
            facing=nw
        [/unit]
        [unit]
            side=6
            type=Chaos Invader
            x,y=14,8
            facing=nw
        [/unit]

        [unit]
            side=6
            type=Chaos Razerman
            x,y=12,7
            facing=ne
            id=Aethercyn
            name= _ "Aethercyn"
        [/unit]

        [unit]
            side=6
            type=Hell Guardian
            x,y=20,12
            facing=nw
        [/unit]

        [unit]
            side=6
            type=Doom Guard
            x,y=7,5
            facing=ne
        [/unit]

        [unit]
            side=6
            type=Chaos Invader
            x,y=4,6
            facing=se
        [/unit]
        [unit]
            side=6
            type=Chaos Invader
            x,y=14,10
            facing=nw
        [/unit]
        [unit]
            side=6
            type=Chaos Invader
            x,y=6,10
            facing=ne
        [/unit]
        [unit]
            side=6
            type=Chaos Invoker
            x,y=6,11
            facing=ne
        [/unit]
        [unit]
            side=6
            type=Chaos Magus
            x,y=19,9
            facing=nw
        [/unit]
        [unit]
            side=6
            type=Chaos Lorekeeper
            x,y=16,6
            facing=sw
        [/unit]

        [unit]
            side=6
            type=Chaos Invoker
            x,y=6,6
            facing=se
        [/unit]

        [unit]
            side=6
            type=Chaos Bowman
            x,y=17,11
            facing=nw
        [/unit]

        [store_unit]
            [filter]
                id=Elyssa
            [/filter]
            kill,variable=yes,elyssa_store
        [/store_unit]

        [store_locations]
            x=2,10,24,10
            y=7,13, 6, 1
            variable=shaxthal_spawns
        [/store_locations]

        [store_locations]
            x=   24,    1
            y=13-15,13-15
            variable=chaos_spawns
        [/store_locations]

        {LOCK_VIEW}
    [/event]

    [event]
        name=start
        [message]
            speaker=Elynia
            message= _ "Galas... you too..."
        [/message]

        [message]
            speaker=Mal Hekuba
            message= _ "Well done, Kendria. Well done."
        [/message]

        [message]
            speaker=Nar-hamoth
            # po: “master” here is feminine
            message= _ "I see that the little vermin fell into the master’s trap as expected. And they brought the Ruby of Fire with them! Ha, ha!"
        [/message]

        [message]
            speaker=Galas
            message= _ "What are you talking about..."
        [/message]

        [animate_attack]
            [filter]
                id=Galas
            [/filter]
            [filter_second]
                x,y=12,7
            [/filter_second]
            [filter_attack]
                range=melee
            [/filter_attack]
            kill=no
            animate=yes
            fire_event=no
            amount=13
            #experience=no
        [/animate_attack]

        [message]
            x,y=12,7
            message= _ "Keep it shut, you fool!"
        [/message]

        [message]
            speaker=Mal Hekuba
            message= _ "Let him be. After all, it would be bad form to not tell them our plans before disposing of their souls, wouldn’t it?"
        [/message]

        [message]
            speaker=Nar-hamoth
            message= _ "We would have killed you on sight, rats, but our master greatly wanted to see your faces one last time."
        [/message]

        [message]
            speaker=Elynia
            message= _ "You... don’t have... a master... We killed... him..."
        [/message]

        [move_unit_fake]
            side=$elyssa_store.side
            type=$elyssa_store.type
            x=23,22,21,20
            y= 1, 1, 2, 2
        [/move_unit_fake]

        [unstore_unit]
            variable=elyssa_store
        [/unstore_unit]

        {CLEAR_VARIABLE elyssa_store}

        [message]
            speaker=Elyssa
            message= _ "We have reserves, my dear."
        [/message]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Galas
            message= _ "You...?!"
        [/message]

        [message]
            speaker=Elyssa
            message= _ "As you can see, I am in charge of this place and the Chaos Empire now. It is my intention to show you my gratitude for giving me this perfect opportunity to cleanse the path for Uria to do her will."
        [/message]

        [message]
            speaker=Elyssa
            message= _ "Irdya, like many other worlds, has certain anomalies which result in spatial connections forming between it and Inferno, where Uria and her subjects live. These anomalies are very well protected and guarded by ancient demons who do not allow anyone to traverse the breach in either direction."
        [/message]

        [message]
            speaker=Elyssa
            message= _ "Long ago, a group of sorcerers on this earth created a number of artifacts that could be used to open or close portals from one location of Irdya to another. Theoretically, those artifacts could also be used to create new, unguarded connections between Irdya and Inferno."
        [/message]

        [message]
            speaker=Elyssa
            message= _ "The artifacts were replicas of an original that was thought lost long ago. We learned that, after changing owners many times throughout its winding history, it came to be used as a symbol of the nation that would become responsible for creating Naia. At some point, somebody ordered its destruction so it would never again be misused by anyone in the land."
        [/message]

        [message]
            speaker=Elyssa
            message= _ "I literally wasted my life trying to find it. In the end, it found me instead, long after I gave up on my search! But of course, its bearer unwittingly brought it before my eyes while wielding a power I could not withstand, the power of the Union. Does this sound familiar to you?"
        [/message]

        [message]
            speaker=Elyssa
            message= _ "Had Argan known that the artifact existed, and that his companion had always carried it with her, we would have settled this matter long ago. There would have been no need to trace the rifts created by Naia and her fallen sister. Instead of searching for the Ruby of Fire, we should have searched for the staff that once belonged to the Enchantress Niryone of Wesmere!"
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "Well done... then... It’s... yours... now... What are you waiting for?"
        [/message]

        [message]
            speaker=Nar-hamoth
            message= _ "Now that we have the artifact, we can use it to merge this pitiful world with Inferno..."
        [/message]

        [message]
            speaker=Mal Hekuba
            message= _ "... dispel the curse of Iluvia..."
        [/message]

        [message]
            speaker=Mal Kendria
            message= _ "... and reunite Uria and the other Guardians..."
        [/message]

        [message]
            speaker=Elyssa
            message= _ "... to restore the Initial Order."
        [/message]

        [move_unit]
            id=Elyssa
            to_x=15
            to_y=6
        [/move_unit]

        [message]
            speaker=Elyssa
            message= _ "Give me this."
        [/message]

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

        [object]
            [filter]
                id=Elyssa
            [/filter]
            [effect]
                apply_to=variation
                name=e2s12_cutscene
            [/effect]
            silent=yes
        [/object]

        [redraw][/redraw]

        [move_unit]
            id=Elyssa
            to_x=16
            to_y=5
        [/move_unit]

        [message]
            speaker=Elyssa
            message= _ "Now this belongs to us."
        [/message]

        {FACE_DIRECTION (x,y=16,6) n}

        [message]
            speaker=Mal Kendria
            message= _ "Yes! It belongs to us! May I borrow it for a second, my lady?"
        [/message]

        [sound]
            name=magic-dark-big.ogg
        [/sound]

        {PLAY_LEVELOUT_ANIM (x,y=16,6)}

        [kill]
            x,y=16,6
        [/kill]

        # wmllint: recognize Mal Keshar

        {RECALL_MAL_KESHAR_AT_LOCATION 16 6}

        {FACE_DIRECTION (id=Mal Keshar) n}

        {PLAY_LEVELIN_ANIM (id=Mal Keshar)}

        [redraw][/redraw]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Mal Keshar
            message= _ "This is not over yet!"
        [/message]

        [sound]
            name=magic-dark-big.ogg
        [/sound]

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

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

        [hide_unit][/hide_unit]

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

#define TT_INFILTRATE X Y UNIT_ATTRS

    [kill]
        x,y={X},{Y}
    [/kill]

    [hidden_unit]
        {UNIT_ATTRS}
        x,y={X},{Y}
        side=1
        random_traits=yes
        generate_name=yes
        [modifications]
            {TRAIT_LOYAL}
        [/modifications]
    [/hidden_unit]
#enddef

        {TT_INFILTRATE 11  6 (
            facing=se
            type=Orcish Archer
        )}

        {TT_INFILTRATE 13  5 (
            facing=se
            type=Orcish Archer
        )}

        {TT_INFILTRATE 14  8 (
            facing=nw
            type=Skeleton
        )}

        {TT_INFILTRATE 16  7 (
            facing=nw
            type=Orcish Grunt
        )}

        {TT_INFILTRATE 17  7 (
            facing=nw
            type=Revenant
        )}

        {TT_INFILTRATE  6 10 (
            facing=ne
            type=Revenant
        )}

        {TT_INFILTRATE 14 10 (
            facing=nw
            type=Deathblade
        )}

        {TT_INFILTRATE  6  6 (
            facing=se
            type=Dark Adept
        )}

        {TT_INFILTRATE 17 11 (
            facing=nw
            type=Skeleton Archer
        )}

        {TT_INFILTRATE  4  6 (
            facing=se
            type=Orcish Grunt
        )}

        {TT_INFILTRATE 12 12 (
            facing=se
            type=Revenant
        )}

#undef TT_INFILTRATE

#define TT_WC X Y
    [hidden_unit]
        side=1
        type=Walking Corpse
        x,y={X},{Y}
        [modifications]
            {TRAIT_LOYAL}
            {TRAIT_UNDEAD}
        [/modifications]
    [/hidden_unit]
#enddef

        {TT_WC 17  9}
        {TT_WC  9  8}
        {TT_WC 10  5}
        {TT_WC  8  5}

#undef TT_WC

#define TT_FAERIE X Y
    [hidden_unit]
        side=1
        type=Faerie Sprite
        x,y={X},{Y}
        [modifications]
            {TRAIT_LOYAL}
        [/modifications]
    [/hidden_unit]
#enddef

        {TT_FAERIE  5 12}
        {TT_FAERIE  5  3}
        {TT_FAERIE  6  7}

#undef TT_FAERIE

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

        [unhide_unit][/unhide_unit]

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

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

        [animate_unit]
            [filter]
                id=Mal Keshar
            [/filter]

            hits=hit
            with_bars=yes
            flag=attack
            [primary_attack]
                range=ranged
            [/primary_attack]

            [animate]
                [filter]
                    id=Elyssa
                [/filter]

                text="26" # wmllint: ignore
                red=255
                with_bars=yes
                hits=hit
                flag=defend
            [/animate]
        [/animate_unit]

        [store_unit]
            [filter]
                id=Elyssa
            [/filter]
            variable=elyssa_store
        [/store_unit]

        {VARIABLE elyssa_store.hitpoints "$($elyssa_store.hitpoints - 26)"}

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

        {CLEAR_VARIABLE elyssa_store}

        {REPLACE_SCENARIO_MUSIC ("the_city_falls.ogg")}

        [object]
            [filter]
                id=Elyssa
            [/filter]
            [effect]
                apply_to=variation
                name=none
            [/effect]
            silent=yes
        [/object]

        [item]
            x,y=15,6
            image="items/staff-elynia-niryone.png~FL(horiz)"
        [/item]

        [message]
            speaker=Elyssa
            message= _ "AAAAAAAAAAH!" # wmllint: no spellcheck
        [/message]

#define TT_ELYSSA_STEP_BACK _TO_X _TO_Y
    [store_unit]
        [filter]
            id=Elyssa
        [/filter]
        variable=elyssa_store
        kill=yes
    [/store_unit]

    [move_unit_fake]
        type=$elyssa_store.type
        side=$elyssa_store.side
        # NOTE: this assumes that she will never get north-facing
        # frames.
        image_mods="FL(horiz)"
        x=$elyssa_store.x,{_TO_X}
        y=$elyssa_store.y,{_TO_Y}
    [/move_unit_fake]

    [set_variables]
        name=elyssa_store
        mode=merge
        [literal]
            facing=sw
            x={_TO_X}
            y={_TO_Y}
        [/literal]
    [/set_variables]

    [unstore_unit]
        variable=elyssa_store
    [/unstore_unit]

    {CLEAR_VARIABLE elyssa_store}
#enddef

        {TT_ELYSSA_STEP_BACK 17 5}

        [message]
            speaker=Elyssa
            message= _ "How did you—"
        [/message]

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

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

        {CLEAR_VARIABLE elynia_store}

        {TT_ELYSSA_STEP_BACK 19 4}

        {FACE_DIRECTION (id=Mal Kendria) sw}

        [message]
            speaker=Mal Kendria
            message= _ "Kill the intruders! Kill them all! NOW!"
        [/message]

        {TT_ELYSSA_STEP_BACK 20 2}

#undef TT_ELYSSA_STEP_BACK

        #
        # Protect the Triad leaders from the player.
        #

        [terrain]
            x=14, 15, 15, 15, 16, 17, 18, 19, 20, 21, 22
            y=3 , 2 , 3 , 4 , 4 , 5 , 5 , 6 , 5 , 5 , 5
            terrain=^Xo
            layer=overlay
        [/terrain]

        {OBJECTIVES (
            {OBJECTIVE_VICTORY ( _ "Defeat all enemy leaders")}

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

        {RESET_THEME}

        {UNLOCK_VIEW}
    [/event]

    [event]
        name=turn 2

        [message]
            speaker=Elyssa
            message= _ "By the power you have bestowed upon me, Uria, may the spells conferring life to the dead be canceled now!"
        [/message]

        {UNIT_SPELL_POPUP id=Elyssa _"dispel undead"}

        {FLASH_RED (
            [sound]
                name="lightning.ogg"
            [/sound]
            [sound]
                name="dragonstick.ogg"
            [/sound]
        )}

        [kill]
            race=undead
            side=1
            {NOT_ON_RECALL_LIST}
            [not]
                id=Mal Keshar
            [/not]
            animate=yes
            fire_event=yes
        [/kill]

        [harm_unit]
            [filter]
                id=Mal Keshar
            [/filter]
            kill=no
            animate=yes
            # 75% current HP damage
            amount="$($this_unit.hitpoints * 0.75)"
            [primary_attack]
                range=ranged
            [/primary_attack]
        [/harm_unit]

        [message]
            speaker=Mal Keshar
            message= _ "AGGGGGGGGGHHHHH!!!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "What is this...?!"
        [/message]

        {MODIFY_UNIT id=Elyssa level 6}

        [message]
            speaker=Elyssa
            message= _ "Unbind the dust from this world and smite the unworthy descendants of Xia’el!"
        [/message]

        {UNIT_SPELL_POPUP id=Elyssa _"dispel faerie"}

        {FLASH_RED (
            [sound]
                name="lightning.ogg"
            [/sound]
            [sound]
                name="magic-dark-big.ogg"
            [/sound]
        )}

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

        [harm_multiple_units]
            [filter]
                id=Galas,Elynia
            [/filter]
            kill=no
            animate=yes
            # Deal 40% max HP damage to Elynia, 30% max HP to Galas
            amount="$($this_unit.max_hitpoints * if('$this_unit.id' = 'Elynia', 0.40, 0.30))"
            [primary_attack]
                range=ranged
            [/primary_attack]
        [/harm_multiple_units]

        [message]
            speaker=Galas
            message= _ "This... is this the kind of powers possessed by Uria?!"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "We need to get out of this place, quickly!"
        [/message]

        [message]
            speaker=Elyssa
            message= _ "Kendria, call upon our new weapon."
        [/message]

        [message]
            speaker=Mal Kendria
            message= _ "But we... we haven’t finished—"
        [/message]

        [store_unit]
            [filter]
                id=Elyssa
            [/filter]
            kill,variable=yes,elyssa_store
        [/store_unit]

        [move_unit_fake]
            side=$elyssa_store.side
            type=$elyssa_store.type
            x=20-21,22-23
            y=    2,    1
        [/move_unit_fake]

        {CLEAR_VARIABLE elyssa_store}

        [message]
            speaker=Mal Hekuba
            message= _ "Reinforcements! Don’t allow them to escape!"
        [/message]

        [move_unit_fake]
            type=Doom Guard
            x= 1, 2, 3
            y=14,13,13
            side=8
        [/move_unit_fake]

        [unit]
            side=8
            type=Doom Guard
            x,y=3,13
            facing=ne
        [/unit]

        [move_unit_fake]
            type=Chaos Magus
            x= 1, 2, 2
            y=14,13,12
            side=8
        [/move_unit_fake]

        [unit]
            side=8
            type=Chaos Magus
            x,y=2,12
            facing=ne
        [/unit]

        [move_unit_fake]
            type=Chaos Razerman
            x=24,19
            y=14,13
            side=8
        [/move_unit_fake]

        [unit]
            side=8
            type=Chaos Razerman
            x,y=19,13
            facing=nw
        [/unit]

        [move_unit_fake]
            type=Doom Guard
            x=24,19
            y=14,12
            side=8
        [/move_unit_fake]

        [unit]
            side=8
            type=Doom Guard
            x,y=19,12
            facing=nw
        [/unit]

        [store_unit]
            [filter]
                id=Mal Kendria
            [/filter]
            kill,variable=yes,kendyare_store
        [/store_unit]

        [move_unit_fake]
            side=$kendyare_store.side
            type=$kendyare_store.type
            gender=female
            x=18,19,20,23
            y= 2, 3, 2, 1
        [/move_unit_fake]

        {CLEAR_VARIABLE kendyare_store}

        {DOOR_TILES_TO_UNITS 8}

        {HIGHLIGHT_IMAGE 1 1 "items/gohere.png" ()}

        [message]
            speaker=Galas
            message= _ "That corridor is clear! It’s our only hope!"
        [/message]

        [modify_turns]
            value=6
        [/modify_turns]

        {OBJECTIVES (
            victory_string= _ "Current Objectives:"
            {OBJECTIVE_VICTORY ( _ "Move Galas, Elynia or Mal Keshar to the exit location")}

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

            {TURNS_RUN_OUT}

            {NO_UNIT_CARRYOVER_NOTE}
        )}
    [/event]

    [event]
        name=side 2 turn end
        first_time_only=no
        [filter_condition]
            {VARIABLE_NUMERICAL_GREATER_THAN turn_number 1}
        [/filter_condition]

        [if]
            {VARIABLE_IS_EVEN turn_number}
            [then]
                {VARIABLE spawn_side 8}
                {VARIABLE spawn_types "Chaos Invoker,Chaos Invader,Chaos Invader,Chaos Soulhunter,Chaos Headhunter,Dark Knight,Doom Guard,Chaos Magus"}
                {VARIABLE_ARRAY_COPY locs chaos_spawns}
            [/then]
            [else]
                {VARIABLE spawn_side 2}
                {VARIABLE spawn_types "Shaxthal Drone,Shaxthal Drone,Shaxthal Runner Drone,Shaxthal Protector Drone,Shaxthal Assault Drone,Shaxthal Assault Drone"}
                {VARIABLE_ARRAY_COPY locs shaxthal_spawns}
            [/else]
        [/if]

        {VARIABLE_RANDOM spawn_count {DIFF 2..3 2..4 3..5}}

        [repeat]
            times=$spawn_count
            [do]
                # Somehow we tried to spawn too many units
                [if]
                    {VARIABLE_NUMERICAL_EQUALS locs.length 0}
                    [then]
                        [break][/break]
                    [/then]
                [/if]

                {VARIABLE_RANDOM spawn_type $spawn_types}
                {VARIABLE_RANDOM r          "0..$($locs.length - 1)"}

                [store_direction]
                    from_x,from_y=$locs[$r].x,$locs[$r].y
                    # map center, unlikely to change so we don't need store_map_dimensions
                    to_x,to_y=12,8
                [/store_direction]

                [unit]
                    animate=yes
                    side=$spawn_side
                    type=$spawn_type
                    random_traits=yes
                    generate_name=yes
                    random_gender=yes
                    x=$locs[$r].x
                    y=$locs[$r].y
                    facing=$direction
                    passable=yes
                [/unit]

                # Don't reuse the same location in this spawn cycle
                {CLEAR_VARIABLE locs[$r]}
            [/do]
        [/repeat]

        {CLEAR_VARIABLE spawn_side,spawn_types,spawn_type,spawn_count,locs,r,direction}
    [/event]

    [event]
        name=moveto
        [filter]
            x,y=1,1
            id=Galas,Elynia,Mal Keshar
        [/filter]

        {ENDLEVEL_QUIET}
    [/event]

    [event]
        name=victory
        [kill]
            side=1
            {NOT_ON_RECALL_LIST}
            [not]
                id=Elynia,Galas,Mal Keshar
            [/not]
            fire_event=no
            animate=no
        [/kill]

        {CLEAR_VARIABLE shaxthal_spawns,chaos_spawns}
    [/event]

    [event]
        name=time over

        [message]
            speaker=Mal Hekuba
            message= _ "More reinforcements! Strike down those heathens, now!"
        [/message]

        [message]
            speaker=Galas
            message= _ "We weren’t fast enough — now they are coming from that corridor as well!"
        [/message]
    [/event]
[/scenario]

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


#textdomain wesnoth-After_the_Storm

[scenario]
    id=09_The_Triad_part_2
    name= _ "The Triad — Part 2"
    {MAP 09_The_Triad_part_2.map}
    {TURNS 22 21 20}
    next_scenario="09_The_Triad_part_3"
    victory_when_enemies_defeated=no

    disallow_recall=yes

    {A_DEATHS}

    #
    # NOTE: the story screen does not have an initial music track
    # on purpose. This is intended to allow music to continue playing
    # as it was at the end of E1S9.1.
    #
    [event]
        name=prestart
        [music]
            name="the_city_falls.ogg"
            immediate=no
        [/music]
    [/event]

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

    {SPAWN_CONTROLLER}

    # wmllint: validate-off

    [side]
        save_id=player

        controller=human
        side=1
        team_name=player
        user_team_name= _ "team_name^Galas"
        shroud=yes

        {NO_ECONOMY}

        # wmllint: recognize Galas
        {CHARACTER_STATS_GALAS}
    [/side]

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

        {NO_ECONOMY}

        controller=null
    [/side]

    # wmllint: validate-on

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

        {NO_ECONOMY}

        {GOLD 120 100 90}

        canrecruit=no
        type=Shaxthal Stormblade Ivyel
        unrenamable=yes
        facing=sw
        [modifications]
            {TRAIT_BIOMECHANICAL}
            {TRAIT_RESILIENT}
        [/modifications]

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression 200.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution      0.00}
            {AI_SIMPLE_ALWAYS_ASPECT grouping       no}
            {AI_SIMPLE_ALWAYS_ASPECT passive_leader no}
        [/ai]
    [/side]

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

        no_leader=yes
        {NO_ECONOMY}
    [/side]

    #
    # Glyphs
    #

    {OBJ_HEALING_GLYPH 35 23}

    #
    # Enemy spawners
    #

#define TT_EASY_SPAWNS
    type="Shaxthal Drone"
#enddef

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

    {TIMED_DRONE_SPAWNER 5  ({TT_MEDIUM_SPAWNS})  3 34 28}
    {TIMED_DRONE_SPAWNER 3  ({TT_EASY_SPAWNS})    3 36 33}
    {TIMED_DRONE_SPAWNER 4  ({TT_EASY_SPAWNS})    3 31 29}
    {TIMED_DRONE_SPAWNER 8  ({TT_MEDIUM_SPAWNS})  3 31 35}
    {TIMED_DRONE_SPAWNER 7  ({TT_EASY_SPAWNS})    3 33 34}
    {TIMED_DRONE_SPAWNER 6  ({TT_EASY_SPAWNS})    3 25 27}
    {TIMED_DRONE_SPAWNER 10 ({TT_MEDIUM_SPAWNS})  3 25 29}
    {TIMED_DRONE_SPAWNER 9  ({TT_EASY_SPAWNS})    3 25 31}

#undef TT_EASY_SPAWNS
#undef TT_MEDIUM_SPAWNS

    {PLACE_IMAGE ("items/box.png") 32 20}

#define TT_FOG_DEFINITION _FLAG _OPACITY
    {COMPOSITE_OVERLAY_PL               *^&{_FLAG}             30 1         fog/fog1 ("O({_OPACITY})")}
    {COMPOSITE_OVERLAY_PL               *^&{_FLAG}             43 1         fog/fog2 ("O({_OPACITY})")}
    {COMPOSITE_OVERLAY_PL               *^&{_FLAG}            100 1         fog/fog3 ("O({_OPACITY})")}
    {COMPOSITE_TRANSITION_RESTRICTED_LF *^&{_FLAG} (!,*^&{_FLAG}) 1 overlay fog/fog  ("O({_OPACITY})")}
#enddef

    {TT_FOG_DEFINITION B 0.8}
    {TT_FOG_DEFINITION C 0.6}
    {TT_FOG_DEFINITION D 0.4}
    {TT_FOG_DEFINITION E 0.2}

#undef TT_FOG_DEFINITION

    {CAVE_NOISE_SOUND_SOURCE}

    [event]
        name=prestart

        [modify_side]
            side=1
            gold=0
        [/modify_side]

        # wmllint: recognize Elynia
        {RECALL_ELYNIA}
        # wmllint: recognize Mal Keshar
        {RECALL_MAL_KESHAR}

        {FACE_DIRECTION side=1 nw}

        {OBJECTIVES (
            victory_string= _ "Current Objectives:"
            {OBJECTIVE_VICTORY ( _ "Locate an exit")}

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

            {TURNS_RUN_OUT}

            {NO_UNIT_CARRYOVER_NOTE}
        )}

        [unit]
            side=3
            type=Shaxthal Rayblade
            x,y=29,22
            facing=sw
        [/unit]

#define TT_PALETTE_OVERRIDE
    [modifications]
        [object]
            [effect]
                apply_to="image_mod"
                add="PAL(shaxthal_drone_base>shaxthal_drone_brown)"
            [/effect]
        [/object]
    [/modifications]
#enddef

        [unit]
            side=3
            type=Shaxthal Drone
            x,y=29,21
            facing=sw
            {TT_PALETTE_OVERRIDE}
        [/unit]

        [unit]
            side=3
            type=Shaxthal Drone
            x,y=31,22
            facing=sw
            {TT_PALETTE_OVERRIDE}
        [/unit]

        [unit]
            side=3
            type=Shaxthal Sentry Drone
            x,y=28,22
            facing=sw
            {TT_PALETTE_OVERRIDE}
            [+modifications]
                {TRAIT_BIOMECHANICAL}
                {TRAIT_ARMORED}
            [/modifications]
        [/unit]

#undef TT_PALETTE_OVERRIDE

        # Some extra anim
        # FIXME: dispose of the extra animation at some point later

        [object]
            silent=yes
            [filter]
                id=Mal Keshar
            [/filter]
            [effect]
                apply_to=new_animation
                [extra_anim]
                    flag=void_recruiting
                    start_time=-300
                    [frame]
                        duration=100
                        image="units/undead-necromancers/ancient-lich-magic-1.png"
                    [/frame]
                    [frame]
                        duration=100
                        image="units/undead-necromancers/ancient-lich-magic-2.png"
                        sound=magic-dark-big.ogg
                    [/frame]
                    [frame]
                        duration=100
                        image="units/undead-necromancers/ancient-lich-magic-3.png"
                    [/frame]
                    [frame]
                        duration=100
                        image="units/undead-necromancers/ancient-lich-magic-1.png"
                    [/frame]
                    [frame]
                        duration=1
                        image="units/undead-necromancers/ancient-lich.png"
                    [/frame]
                [/extra_anim]
            [/effect]
        [/object]
    [/event]

    [event]
        name=DEBUG1

        [teleport]
            [filter]
                id=Galas
            [/filter]
            x,y=26,24
        [/teleport]
        [teleport]
            [filter]
                id=Elynia
            [/filter]
            x,y=26,25
        [/teleport]
        [teleport]
            [filter]
                id=Mal Keshar
            [/filter]
            x,y=27,25
        [/teleport]
    [/event]

    [event]
        name=DEBUG2

        [teleport]
            [filter]
                id=Galas
            [/filter]
            x,y=19,17
        [/teleport]
        [teleport]
            [filter]
                id=Elynia
            [/filter]
            x,y=20,16
        [/teleport]
        [teleport]
            [filter]
                id=Mal Keshar
            [/filter]
            x,y=20,17
        [/teleport]
    [/event]

    [event]
        name=start
        [message]
            speaker=Galas
            message= _ "We must make haste before their reinforcements catch up with us. Which direction should we go?"
        [/message]

        [message]
            speaker=Elynia
            message= _ "A slight breeze comes from the passage to our left; we should follow it."
        [/message]

        [message]
            speaker=Galas
            message= _ "These passages are eerily vacant. I feel we are being led into a trap of some sort..."
        [/message]
    [/event]

#define TT_REMOVE_SHROUD X Y RADIUS
    [remove_shroud]
        x={X}
        y={Y}
        radius={RADIUS}
        [filter_radius]
            [not]
                terrain=X*,*^X*
            [/not]
        [/filter_radius]
        side=1
    [/remove_shroud]
#enddef

    [event]
        name=moveto
        [filter]
            side=1
            x=1-52
            y=22-31
        [/filter]

        [fire_event]
            name=gauntlet1
        [/fire_event]
    [/event]

    [event]
        {SIGHTED_SUF_BY_PLAYER (side=3)}

        [fire_event]
            name=gauntlet1
        [/fire_event]
    [/event]

    [event]
        name=gauntlet1

        {CLEAR_CAVE_SHROUD (
            x,y=34,31
            radius=4
            [or]
                x,y=40,29
                radius=2
            [/or]
        )}

        [redraw]
            side=1
        [/redraw]

        [scroll_to]
            x,y=36,30
        [/scroll_to]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Galas
            message= _ "Mal Keshar, we’ll need some reinforcements to get through!"
        [/message]

        [animate_unit]
            [filter]
                id=Mal Keshar
            [/filter]
            flag=void_recruiting
        [/animate_unit]

        [s9_area_spawns]
            x=34-41
            y=29-31
            [not]
                [filter]
                [/filter]
            [/not]
            [not]
                terrain=Q*,X*,*^X*
            [/not]
            {QUANTITY skeletons 3 2 2}
            {QUANTITY ghosts    1 1 1}
        [/s9_area_spawns]

        [message]
            speaker=Mal Keshar
            message= _ "Things are looking rather grim... We have not fully recovered from that demon’s attack, and her guards are in hot pursuit. Our backup has most certainly been scattered or slaughtered by now. What do you plan to do now that this has turned into a suicide mission?"
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x=21,22,23,21,22,23,21,22,23
            y=21,20,20,22,21,21,23,22,22
        [/filter]

        [message]
            speaker=Galas
            message= _ "A gate! Let’s strike it down—"
        [/message]

        [sound]
            name="shaxthal-energy-prelude.ogg"
        [/sound]

        [delay]
            time=100
        [/delay]

        [scroll_to]
            x,y=30,21
            {WARP}
        [/scroll_to]

        [sound]
            name="shaxthal-energy-fire.ogg"
        [/sound]

        [delay]
            time=250
        [/delay]

        {QUAKE "explosion-big.ogg"}

        [terrain]
            x=26,26,27,27,28,29
            y=22,23,23,25,23,24
            terrain=Urb^Es
        [/terrain]

        {TT_REMOVE_SHROUD 30 21 4}

        [redraw]
            side=1
        [/redraw]

        {QUAKE "cave-in.ogg"}

        [delay]
            time=500
        [/delay]

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

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "It’s an ambush!"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Damn them all! I don’t know if I’ll be able to keep on with this for much longer."
        [/message]

        [animate_unit]
            [filter]
                id=Mal Keshar
            [/filter]
            flag=void_recruiting
        [/animate_unit]

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

        [s9_area_spawns]
            x=22,23,23,24,24,24,25,25,25,26,26,26,27,27,27,27,28,28,28,29,29
            y=23,23,24,22,23,24,23,24,25,23,24,25,24,25,26,27,24,25,26,25,26
            [not]
                [filter]
                [/filter]
            [/not]
            [not]
                terrain=Q*,X*,*^X*
            [/not]
            {QUANTITY skeletons 4 3 2}
            {QUANTITY ghosts    2 1 1}
        [/s9_area_spawns]
    [/event]

    [event]
        name=last breath
        [filter]
            type=Shaxthal Stormblade Ivyel
        [/filter]

        [message]
            speaker=Galas
            message= _ "It’s running away!"
        [/message]

        [store_unit]
            [filter]
                type=Shaxthal Stormblade Ivyel
            [/filter]
            kill=yes
            variable=ivyel_store
        [/store_unit]

        [move_unit_fake]
            type=$ivyel_store.type
            side=$ivyel_store.side
            x=$ivyel_store.x,31
            y=$ivyel_store.y,20
        [/move_unit_fake]

        # Ignore movement costs now

        [move_unit_fake]
            type=$ivyel_store.type
            side=$ivyel_store.side
            x=31,32,33,35
            y=20,17,15,14
        [/move_unit_fake]

        {CLEAR_VARIABLE ivyel_store}

        [message]
            speaker=Elynia
            message= _ "I just hope it’s sufficiently damaged so that it won’t attack us from behind again. We need to advance, quickly."
        [/message]

        {DOOR_TILES_TO_UNITS 4}

        [kill]
            type=Door
            x=30,31-32
            y=18,19
        [/kill]

        {CLEAR_CAVE_SHROUD (x,y,radius=22,20,1)}

        [redraw]
            side=1
        [/redraw]

        [scroll_to]
            x,y=22,19
        [/scroll_to]

        {HIGHLIGHT_GOAL x,y="21,22-23","20,19"}

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

    [event]
        name=die
        [filter]
            type=Door
            x=21,22,23
            y=20,19,19
        [/filter]

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

        {TT_REMOVE_SHROUD 20 18 3}

        {SCROLL_TO_LOCATION_AND_RETURN_TO_PRIMARY_UNIT 20 18}
    [/event]

#define TT_FOG_STEP _FLAG
    [terrain]
        [and]
            terrain=*^&*
            [or]
                terrain=*^Zow
            [/or]
        [/and]
        terrain=^&{_FLAG}
        layer=overlay
    [/terrain]

    [redraw][/redraw]

    [delay]
        time=50
    [/delay]
#enddef

#define TT_AURA _X _Y _OPACITY
    [item_fast]
        x={_X}
        y={_Y}
        image="misc/blank-hex.png"
        halo="halo/heart-aura.png~O("+{_OPACITY}+")"
    [/item_fast]
#enddef

#define TT_AURA_STEP _X _Y _OPACITY
    [remove_item]
        x={_X}
        y={_Y}
    [/remove_item]

    [item]
        x={_X}
        y={_Y}
        image="misc/blank-hex.png"
        halo="halo/heart-aura.png~O("+{_OPACITY}+")"
    [/item]
#enddef

#define TT_ELYSSA_STEP _OPACITY
    [object]
        silent=yes
        [filter]
            id=Elyssa
        [/filter]
        [effect]
            apply_to=image_mod
            replace="O("+{_OPACITY}+")"
        [/effect]
    [/object]
#enddef

#define TT_ELYSSA_RESET
    [object]
        silent=yes
        [filter]
            id=Elyssa
        [/filter]
        [effect]
            apply_to=image_mod
            replace="NOP()"
        [/effect]
    [/object]
#enddef

    [event]
        name=moveto
        [filter]
            side=1
            x=1-22
            y=1-15
            [and]
                id=Galas
                [or]
                    id=Mal Keshar
                [/or]
                [or]
                    id=Elynia
                [/or]
            [/and]
        [/filter]

        {LOCK_VIEW}

        [modify_side]
            side=2
            controller=ai
        [/modify_side]

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

        [foreach]
            array=side1_store
            [do]
                [set_variables]
                    name=this_item
                    mode=merge
                    [value]
                        moves=0
                        attacks_left=0
                        [status]
                            uncovered=yes
                            poisoned=no
                            slowed=no
                        [/status]
                    [/value]
                [/set_variables]

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

        {CLEAR_VARIABLE side1_store}

        [hide_unit][/hide_unit]

        {RED_SCREEN}

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

        [random_placement]
            [filter_location]
                x=16-23
                y= 5-10
                [not]
                    x,y=$location.x,$location.y
                [/not]
                [not]
                    terrain=X*,X*^*,*^X* # neither hive cells nor impassable overlay yeah
                [/not]
            [/filter_location]
            num_items=6
            variable=debris_loc
            min_distance=1
            allow_less=yes # just in case
            [command]
                {VARIABLE_RANDOM debris_image "castle-ruins,castle-ruins2,castle-ruins3"}

                [item]
                    x,y=$debris_loc.x,$debris_loc.y
                    image="scenery/$debris_image|.png"
                [/item]
            [/command]
        [/random_placement]

        {CLEAR_VARIABLE debris_loc,debris_image}

        [redraw][/redraw]

        {REPLACE_SCENARIO_MUSIC "silence.ogg"}

        [delay]
            time=100
        [/delay]

        [sound]
            name="explosion-big.ogg"
        [/sound]

        {CLEAR_CAVE_SHROUD (
            x,y=17,11
            radius=7
        )}

        [store_starting_location]
            side=2
        [/store_starting_location]

        {TT_AURA $location.x $location.y 0.8} # No redraw, see definition.

        {RESET_SCREEN}

        [unhide_unit][/unhide_unit]

        [redraw]
            side=1
        [/redraw]

        {QUAKE "cave-in.ogg"}

        [delay]
            time=500
        [/delay]

        #
        # Perform a regular non-warping scroll and display a character message
        # without scrolling. This is intentional.
        #

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

        [message]
            speaker=Mal Keshar
            scroll=no
            message= _ "What the—"
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "Amidst the smoke from the explosion, a pair of red glowing eyes could be seen..."
        [/message]

        [hidden_unit]
            [status]
                invulnerable=yes
            [/status]
            # wmllint: recognize Elyssa
            {CHARACTER_STATS_ELYSSA}
            canrecruit=yes
            side=2
            facing=s
            x,y=$location.x,$location.y
        [/hidden_unit]

        {TT_AURA_STEP $location.x $location.y 0.7}

        {TT_ELYSSA_STEP 0.2}

        [unhide_unit]
            id=Elyssa
        [/unhide_unit]

        {TT_FOG_STEP B}

        {TT_AURA_STEP $location.x $location.y 0.6}

        {TT_ELYSSA_STEP 0.4}

        {TT_AURA_STEP $location.x $location.y 0.5}

        {TT_ELYSSA_STEP 0.6}

        {TT_FOG_STEP C}

        {TT_AURA_STEP $location.x $location.y 0.4}

        {TT_ELYSSA_STEP 0.8}

        {REPLACE_SCENARIO_MUSIC ("vengeful.ogg")}

        {TT_AURA_STEP $location.x $location.y 0.3}

        {TT_ELYSSA_RESET}

        {TT_FOG_STEP D}

        {TT_AURA_STEP $location.x $location.y 0.2}

        {TT_FOG_STEP E}

        {TT_AURA_STEP $location.x $location.y 0.1}

        {TT_FOG_STEP F}

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

        [redraw][/redraw]

        [delay]
            time=750
        [/delay]

        {MOVE_UNIT (id=Elyssa) 18 11}

        [message]
            speaker=Elyssa
            message= _ "You fools thought you could escape <i>so</i> easily from us, didn’t you? I have not forgotten what you did to me. How does it feel to be at a disadvantage now?"
        [/message]

        [if]
            [not]
                [have_unit]
                    id=Elynia
                    x,y=18,12
                [/have_unit]
            [/not]
            [then]
                {MOVE_UNIT (id=Elynia) 18 12}
            [/then]
        [/if]

        [animate_attack]
            [filter]
                id=Elyssa
            [/filter]
            [filter_second]
                id=Elynia
            [/filter_second]
            [filter_attack]
                range=ranged
                name=ensnare
            [/filter_attack]
            kill=no
            animate=yes
            amount=4
            slowed=yes
        [/animate_attack]

        [redraw][/redraw]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Elyssa
            message= _ "It doesn’t have to be like this. Just give me the staff back and <b>I</b> will spare your life like you did with mine."
        [/message]

        [remove_shroud]
            x=1-11
            y=4-14
            [not]
                terrain=X*,*^X*
            [/not]
            side=1
        [/remove_shroud]

        [redraw][/redraw]

        {MOVE_UNIT (id=Mal Keshar) 12 12}

        {MOVE_UNIT (id=Galas) 16 13}

        [animate_attack]
            [filter]
                id=Elynia
            [/filter]
            [filter_second]
                id=Elyssa
            [/filter_second]
            [filter_attack]
                range=ranged
            [/filter_attack]
            kill=no
            animate=yes
            amount=5
        [/animate_attack]

        {FACE_DIRECTION (id=Mal Keshar) ne}

        [message]
            speaker=Galas
            message= _ "Elynia!"
        [/message]

        [animate_unit]
            [filter]
                id=Mal Keshar
            [/filter]
            flag=void_recruiting
        [/animate_unit]

        [store_locations]
            x=17   ,18,19
            y=11-12,10,11-12
            variable=spawn_locs
        [/store_locations]

        [foreach]
            array=spawn_locs
            variable=loc
            [do]
                [store_direction]
                    from_x,from_y=$loc.x,$loc.y
                    [to]
                        [filter]
                            id=Elyssa
                        [/filter]
                    [/to]
                [/store_direction]

                {RANDOM "Draug,Banebow,Bone Shooter,Bone Shooter,Revenant,Skeleton,Skeleton Archer"}

                [unit]
                    x,y=$loc.x,$loc.y
                    type=$random
                    facing=$direction
                    side=1
                    animate=yes
                    [modifications]
                        {TRAIT_LOYAL}
                    [/modifications]
                [/unit]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE spawn_locs,random,direction}

        {MOVE_UNIT (id=Elynia) 12 11}

        {MOVE_UNIT (id=Galas) 11 12}

        [message]
            speaker=Mal Keshar
            message= _ "Follow this rail, quickly!"
        [/message]

        {FACE_DIRECTION (id=Mal Keshar) nw}

        {CLEAR_CAVE_SHROUD (
            x=0-2
            y=6-7
        )}

        [redraw][/redraw]

        {HIGHLIGHT_IMAGE 1 7 "items/gohere.png" ()}

        {OBJECTIVES (
            victory_string= _ "Current Objectives:"
            {OBJECTIVE_VICTORY ( _ "Follow the underground rail and locate an exit")}

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

            {TURNS_RUN_OUT}

            {NO_UNIT_CARRYOVER_NOTE}
        )}

        {UNLOCK_VIEW}

        [end_turn][/end_turn]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x=1
            y=6-8
            [and]
                id=Elynia
                [or]
                    id=Galas
                [/or]
                [or]
                    id=Mal Keshar
                [/or]
            [/and]
        [/filter]

        {ENDLEVEL_QUIET}
    [/event]

    [event]
        name=victory
        [kill]
            side=1
            {NOT_ON_RECALL_LIST}
            [not]
                id=Elynia
                [or]
                    id=Galas
                [/or]
                [or]
                    id=Mal Keshar
                [/or]
            [/not]
            fire_event=no
            animate=no
        [/kill]
    [/event]

    [event]
        name=time over

        [message]
            speaker=Mal Keshar
            message= _ "There are more of those biomechanical creatures pursuing us now. Oh, well, this entire plan was doomed to failure from the very beginning — I don’t know what I was thinking!"
        [/message]
    [/event]

#undef TT_REMOVE_SHROUD
#undef TT_FOG_STEP
#undef TT_AURA
#undef TT_AURA_STEP
#undef TT_ELYSSA_STEP
#undef TT_ELYSSA_RESET
[/scenario]

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


#textdomain wesnoth-After_the_Storm

[scenario]
    id=09_The_Triad_part_3
    name= _ "The Triad — Part 3"
    {MAP 09_The_Triad_part_3.map}
    {TURNS 30 28 26}
    next_scenario="10_Tears"
    victory_when_enemies_defeated=no
    {DO_NOT_REMOVE_FROM_CARRYOVER_ON_DEFEAT}

    disallow_recall=yes

    {A_DEATHS}

    {SCENARIO_MUSIC "siege_of_laurelmor.ogg"}

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

    {SPAWN_CONTROLLER}

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

        controller=human
        side=1
        team_name=player
        user_team_name= _ "team_name^Galas"
        shroud=yes

        {NO_ECONOMY}

        # wmllint: recognize Galas
        {CHARACTER_STATS_GALAS}
    [/side]
    # wmllint: validate-on

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

        controller=null

        no_leader=yes
        {NO_ECONOMY}
    [/side]

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

        no_leader=yes
        {NO_ECONOMY}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression 200.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution      0.00}
            {AI_SIMPLE_ALWAYS_ASPECT grouping       no}
            {AI_SIMPLE_ALWAYS_ASPECT passive_leader no}
        [/ai]
    [/side]

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

        no_leader=yes
        {NO_ECONOMY}
    [/side]

    {FORCE_CHANCE_TO_HIT (side=1) (id=Elyssa) 0 ()}

    #
    # Glyphs
    #

    # NOTE: These are the same glyphs from E1S13, with events added.
    {OBJ_HEALING_GLYPH 25 12}
    {OBJ_HEALING_GLYPH 18 19}

    #
    # Enemy spawners
    #

#define TT_EASY_SPAWNS
    type="Shaxthal Drone"
#enddef

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

#define TT_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 Enforcer Drone,Shaxthal Drone")
    ("Shaxthal Drone,Shaxthal Drone,Shaxthal Sentry Drone,Shaxthal Sentry Drone,Shaxthal Sentry Drone,Shaxthal Enforcer Drone,Shaxthal Drone")
    }
#enddef

    # Initial area near Elyssa's chamber

    {TIMED_DRONE_SPAWNER 10 ({TT_HARD_SPAWNS})   3 31 25}
    {TIMED_DRONE_SPAWNER 4  ({TT_EASY_SPAWNS})   3 39 20}
    {TIMED_DRONE_SPAWNER 4  ({TT_EASY_SPAWNS})   3 42 21}
    {TIMED_DRONE_SPAWNER 4  ({TT_MEDIUM_SPAWNS}) 3 38 17}

    # Central respawn chamber

    {TIMED_DRONE_SPAWNER 6  ({TT_MEDIUM_SPAWNS}) 3 19 15}
    {TIMED_DRONE_SPAWNER 6  ({TT_MEDIUM_SPAWNS}) 3 31 15}
    {TIMED_DRONE_SPAWNER 6  ({TT_MEDIUM_SPAWNS}) 3 31 10}
    {TIMED_DRONE_SPAWNER 6  ({TT_MEDIUM_SPAWNS}) 3 25  7}

    # NW corridor adjacent to hive

    {TIMED_DRONE_SPAWNER 4  ({TT_EASY_SPAWNS})   3 19  5}
    {TIMED_DRONE_SPAWNER 6  ({TT_MEDIUM_SPAWNS}) 3 10  5}
    {TIMED_DRONE_SPAWNER 3  ({TT_EASY_SPAWNS})   3  5  5}
    {TIMED_DRONE_SPAWNER 5  ({TT_EASY_SPAWNS})   3  4  6}
    {TIMED_DRONE_SPAWNER 5  ({TT_MEDIUM_SPAWNS}) 3  3  8}

    # Artifical evolution laboratory - main pool (Kalari facility I)

    {ONETIME_DRONE_SPAWNER  ({TT_HARD_SPAWNS})   3 10 14}
    {ONETIME_DRONE_SPAWNER  ({TT_MEDIUM_SPAWNS}) 3 13 16}
    {ONETIME_DRONE_SPAWNER  ({TT_EASY_SPAWNS})   3 14 16}
    {ONETIME_DRONE_SPAWNER  ({TT_EASY_SPAWNS})   3 21 20}
    {ONETIME_DRONE_SPAWNER  ({TT_EASY_SPAWNS})   3 18 20}

#undef TT_EASY_SPAWNS
#undef TT_MEDIUM_SPAWNS
#undef TT_HARD_SPAWNS

    {PLACE_IMAGE ("items/gohere.png") 13 20}
    {PLACE_IMAGE ("items/gohere.png") 14 20}

#define TT_ENABLE_SOUND_SOURCES
    {HIVE_NOISE_2_SOUND_SOURCE}

    {HIVE_NOISE_1_SOUND_SOURCE}
    [+sound_source]
        x,y=1,27
        full_range=1
        fade_range=30
    [/sound_source]

    {CAVE_WATER_SOUND_SOURCE  5 10}

    {CAVE_WATER_SOUND_SOURCE 25 12}

    {CAVE_WATER_SOUND_SOURCE  8 24}
#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 TT_DISABLE_SOUND_SOURCES
    {REMOVE_SOUND_SOURCE __ss_hive_noise_2_all}

    {REMOVE_SOUND_SOURCE __ss_hive_noise_1_all}

    {REMOVE_SOUND_SOURCE __ss_cave_water_5_10}

    {REMOVE_SOUND_SOURCE __ss_cave_water_25_12}

    {REMOVE_SOUND_SOURCE __ss_cave_water_8_24}
#enddef

    {TT_ENABLE_SOUND_SOURCES}

    [event]
        name=prestart

        [modify_side]
            side=1
            gold=0
        [/modify_side]

        # wmllint: recognize Elynia
        {RECALL_ELYNIA}
        # wmllint: recognize Mal Keshar
        {RECALL_MAL_KESHAR}

        {FACE_DIRECTION side=1 nw}

        {OBJECTIVES (
            victory_string= _ "Current Objectives:"
            {OBJECTIVE_VICTORY ( _ "Locate an exit")}

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

            {TURNS_RUN_OUT}

            {NO_UNIT_CARRYOVER_NOTE}
        )}

        #[remove_shroud]
        #    side=1
        #    x=13-14
        #    y=20
        #    radius=1
        #[/remove_shroud]
    [/event]

#define ELYSSA_VOICE MSG
    [message]
        caption= _ "Elyssa"
        speaker=narrator
        #image="portraits/elyssa.png"
        image=wesnoth-icon.png
        message=""+{MSG}+"" # wmllint: ignore
    [/message]
#enddef

    [event]
        name=start
        [message]
            speaker=Mal Keshar
            message= _ "What now?"
        [/message]

        [message]
            speaker=Galas
            message= _ "Let’s keep moving. Hopefully there is an exit somewhere ahead. Elynia—"
        [/message]

        [message]
            speaker=Elynia
            # po: The otherwise intended end of the sentence is "don't worry about me".
            message= _ "I’m fine. Don’t worry—"
        [/message]

        {ELYSSA_VOICE ( _ "You haven’t escaped, you know.")}

        [message]
            speaker=Galas
            message= _ "MOVE!"
        [/message]
    [/event]

    [event]
        name=turn 2

        {ELYSSA_VOICE ( _ "It would have been so much better for all of you to give up...")}
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x=20-30
            y= 8-14
        [/filter]

        {MOVE_UNIT (id=Galas) 25 14}
        [redraw][/redraw]
        {MOVE_UNIT (id=Elynia) 24 13}
        [redraw][/redraw]
        {MOVE_UNIT (id=Mal Keshar) 26 13}
        [redraw][/redraw]

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

        [foreach]
            array=side1_store
            [do]
                [set_variables]
                    mode=merge
                    name=this_item
                    [value]
                        attacks_left="$this_item.max_attacks"
                        moves="$this_item.max_moves"
                    [/value]
                [/set_variables]

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

        {CLEAR_VARIABLE side1_store}

        [message]
            speaker=Galas
            message= _ "Uria be damned! It’s a dead end."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "It’s more like a trap—"
        [/message]

        {ELYSSA_VOICE ( _ "You cannot blame me. I gave you one opportunity to reconsider your actions — I’m not giving you another.")}

        {FACE_DIRECTION (x,y=19,15) ne}
        {FACE_DIRECTION (x,y=31,15) nw}
        {FACE_DIRECTION (x,y=31,10) sw}
        {FACE_DIRECTION (x,y=25, 7) se}

        {QUAKE "cave-in.ogg"}

        [terrain]
            x=30,25,20,20,30
            y=10, 8,10,14,14
            terrain=Ur
        [/terrain]

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

        [redraw]
            side=1
        [/redraw]

        {ELYSSA_VOICE ( _ "You made a big mistake in leaving the safety of the Northlands...")}

        [sound]
            name="cave-in.ogg"
        [/sound]

        [terrain]
            x,y=25,16
            terrain=Xuc
        [/terrain]

        [redraw]
            side=1
        [/redraw]

        {QUAKE "thunderstick.ogg"}

        [message]
            speaker=Mal Keshar
            message= _ "—I knew it. We are trapped."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Not quite — there seems to be a passage behind that crack on the wall!"
        [/message]

        [remove_shroud]
            x=17-18,19-20,21
            y= 8-10, 9-11,10-12
            side=1
        [/remove_shroud]

        [redraw]
            side=1
        [/redraw]

        {SCROLL_TO_LOCATION_AND_RETURN_TO_PRIMARY_UNIT 17 9}

        [redraw][/redraw]

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

            [message]
                speaker=Galas
                message= _ "Elynia, the teleportation spell you learned back in Zocthanol! Can you use it?"
            [/message]

            [message]
                speaker=Elynia
                message= _ "I— I don’t know, it wasn’t really made to transport more than one person, and I haven’t had a chance to try it myself."
            [/message]

            [message]
                speaker=Mal Keshar
                message= _ "This is probably not the best moment to fiddle with unpredictable kinds of magic like this. As I said before, many mages have disappeared attempting to master the power of teleportation."
            [/message]

            [message]
                speaker=Galas
                message= _ "It’s an option to consider, nonetheless..."
            [/message]
        [/event]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x= 7-14
            y=20-23
        [/filter]

        {ENDLEVEL_QUIET}
    [/event]

    [event]
        name=victory

        {LOCK_VIEW}

        {CLEAR_LABELS}

        #
        # This is it.
        #

        [fade_out_music]
            duration=250
        [/fade_out_music]

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

        {RESET_UNIT_STATUSES (
            side=1
            {NOT_ON_RECALL_LIST}
        )}

        [hide_unit]
            side=1
        [/hide_unit]

        [capture_village][/capture_village]

        [remove_item][/remove_item]

        {FADE_TO_BLACK}

        [place_shroud]
            side=1
        [/place_shroud]

        [redraw]
            side=1
        [/redraw]

        [scroll_to]
            x,y=6,23
            {WARP}
        [/scroll_to]

        [delay]
            time=1000
        [/delay]

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

        {FADE_IN}

        [teleport]
            [filter]
                id=Elynia
            [/filter]
            x=8
            y=22
        [/teleport]

        [teleport]
            [filter]
                id=Mal Keshar
            [/filter]
            x=9
            y=23
        [/teleport]

        [teleport]
            [filter]
                id=Galas
            [/filter]
            x=10
            y=22
        [/teleport]

        {FACE_DIRECTION (id=Galas,Elynia,Mal Keshar) sw}

        [unhide_unit]
            side=1
        [/unhide_unit]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Mal Keshar
            message= _ "This place stinks of blood. What’s with that water?"
        [/message]

        [message]
            speaker=Galas
            message= _ "I fear that it is blood, in fact. Something is really wrong. No single creature could contain so much of it. Who knows what kinds of twisted experiments these fiends do in here?"
        [/message]

        [message]
            speaker=Elynia
            message= _ "There truly appears to be no way out of this chamber. What do we do?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "I’ll tell you what: we shall create our own exit from this accursed place by tearing it all down from the inside!"
        [/message]

        [message]
            speaker=Galas
            # po: The otherwise intended end of the sentence is: "try that teleportation spell now!".
            message= _ "Or we could take the risk and—"
        [/message]

        # wmllint: recognize Elyssa
        [unit]
            animate=yes
            side=2
            facing=sw
            x,y=11,22
            canrecruit=yes
            {CHARACTER_STATS_ELYSSA}
        [/unit]

        [animate_attack]
            [filter]
                id=Galas
            [/filter]
            [filter_second]
                id=Elyssa
            [/filter_second]
            [filter_attack]
                range=melee
                name=sword
            [/filter_attack]
            kill=no
            animate=yes
            fire_event=no
            amount="$this_unit.hitpoints"
        [/animate_attack]

        [object]
            silent=yes
            [filter]
                id=Galas
            [/filter]
            [effect]
                apply_to=image_mod
                add="R(127)"
            [/effect]
        [/object]

        {MODIFY_UNIT (
            id=Elynia
            [or]
                id=Mal Keshar
            [/or]
        ) facing ne}

        [fade_out_sound_effects]
            duration=250
        [/fade_out_sound_effects]

        {TT_DISABLE_SOUND_SOURCES}

        #
        # Give sound source changes a chance to kick in.
        #

        [delay]
            time=10
        [/delay]

        [reset_sound_effects][/reset_sound_effects]

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

        [animate_attack]
            [filter]
                id=Galas
            [/filter]
            [filter_second]
                id=Elyssa
            [/filter_second]
            [filter_attack]
                range=melee
                name=sword
            [/filter_attack]
            kill=yes
            animate=yes
            fire_event=no
            amount="$this_unit.hitpoints"
        [/animate_attack]

        [if]
            [have_unit]
                id=Galas
            [/have_unit]
            [then]
                {BUG ()}

                [kill]
                    id=Galas
                    animate=yes
                    fire_event=no
                [/kill]
            [/then]
        [/if]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "NO!"
        [/message]

        [delay]
            time=500
        [/delay]

        {REPLACE_SCENARIO_MUSIC returning_in_time.ogg}

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Elyssa
            message= _ "You opted for doing this the hard way after all, didn’t you? The staff — hand it over now."
        [/message]

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

        [message]
            speaker=Mal Keshar
            message= _ "Elynia... we must..."
        [/message]

        {TT_ENABLE_SOUND_SOURCES}

        [fade_in_sound_effects]
            duration=1000
        [/fade_in_sound_effects]

        [message]
            speaker=Elynia
            message= _ "—I... I damn you, Elyssa... I damn you and your kind... for this..."
        [/message]

        #
        # Give sound source changes a chance to kick in.
        #

        [delay]
            time=10
        [/delay]

        [message]
            speaker=Elyssa
            message= _ "My dear, we were damned long ago by the First Gods. Your petty words are irrelevant in the grand scheme of things. Hand it over now."
        [/message]

        [message]
            speaker=Mal Keshar
            message=_ "Elynia, the spell!"
        [/message]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Elyssa
            message= _ "Don’t you see? We aren’t that different after all. You just lost your new beloved just like you lost Argan. I lost much more than that long ago. You think he was important because you never had to endure the cruelty and ruthlessness of the beasts that dare call themselves ‘humans’."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Stop listening to her, Elynia!"
        [/message]

        [delay]
            time=1000
        [/delay]

        {THUNDER (
            {PUT_TO_RECALL_LIST (
                id=Elynia
                [or]
                    id=Mal Keshar
                [/or]
            )}
        )}

        [delay]
            time=2000
        [/delay]

        [message]
            speaker=Elyssa
            message= _ "What a waste. Don’t think you’ll find anything of value in Wesmere."
        [/message]

        [delay]
            time=1000
        [/delay]

        {MOVE_UNIT (id=Elyssa) 14 20}

        [kill]
            id=Elyssa
            animate,fire_event=no,no
        [/kill]

        {FADE_TO_BLACK}

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

        [place_shroud]
            side=1
        [/place_shroud]

        [redraw]
            side=1
        [/redraw]

        [delay]
            time=1000
        [/delay]

        {UNLOCK_VIEW}
    [/event]

    [event]
        name=time over

        [message]
            speaker=Mal Keshar
            message= _ "That’s it. We are now utterly lost in these infested passages... and the worst part is that I was the one who devised this disastrous rescue plan."
        [/message]
    [/event]

#undef ELYSSA_VOICE
#undef TT_ENABLE_SOUND_SOURCES
#undef TT_DISABLE_SOUND_SOURCES
[/scenario]

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


#textdomain wesnoth-After_the_Storm

[scenario]
    id=10_Tears
    name= _ "Tears"
    {MAP 10_Tears.map}
    {TURNS 34 32 30}
    next_scenario="11_Return_to_Wesmere_part_1"
    victory_when_enemies_defeated=no

    {B_DEATHS}

    #{SCENARIO_MUSIC "returning_in_time.ogg"} {CONTINUE_PLAYING_STORY_MUSIC_FIRST}

    #
    # NOTE: the story screen does not have an initial music track
    # on purpose. This is intended to allow music to continue playing
    # as it was at the end of E1S9.3.
    #
    [event]
        name=prestart
        [music]
            name="returning_in_time.ogg"
            immediate=no
        [/music]
    [/event]

    {STORYTXT_TEARS}

    {TWO_SUNS_DEFAULT_SCHEDULE}

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

        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

    [side]
        side=2
        recruit=Chaos Invoker,Chaos Invader,Chaos Headhunter,Chaos Hound
        {GOLD 230 250 270}
        team_name=evil
        user_team_name= _ "team_name^Enemies"
        {CHAOS_FLAG}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            [goal]
                [criteria]
                    id=Elynia
                [/criteria]
                value=9.00
            [/goal]
            [goal]
                [criteria]
                    id=Mal Keshar
                [/criteria]
                value=9.00
            [/goal]

            {AI_SIMPLE_ALWAYS_ASPECT aggression 1.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution    0.05}
        [/ai]

        type=Chaos Lorekeeper
        id=Grulock
        name= _ "Grulock"
        canrecruit=yes
        unrenamable=yes
        [modifications]
            {TRAIT_RESILIENT}
            {TRAIT_STRONG}
        [/modifications]

        {GENERIC_UNIT () (Shaxthal Assault Drone) 29 10} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Assault Drone) 21  2} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Assault Drone) 14  4} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Assault Drone) 14 10} {GUARDIAN}

        {GENERIC_UNIT () (Shaxthal Assault Drone) 17 21} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Assault Drone) 26 24} {GUARDIAN}
    [/side]

    [side]
        side=3
        recruit=Chaos Raider,Chaos Bowman,Chaos Invader
        {GOLD 220 230 240}
        team_name=evil
        user_team_name= _ "team_name^Enemies"
        {CHAOS_FLAG}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            [goal]
                [criteria]
                    id=Elynia
                [/criteria]
                value=9.00
            [/goal]
            [goal]
                [criteria]
                    id=Mal Keshar
                [/criteria]
                value=9.00
            [/goal]

            {AI_SIMPLE_ALWAYS_ASPECT aggression 1.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution    0.05}
        [/ai]

        type=Chaos Razerman
        id=Zygred
        name= _ "Zygred"
        canrecruit=yes
        unrenamable=yes
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_SLOW} # NOTE: deliberate choice for now; not a mistake!
        [/modifications]
    [/side]

    [side]
        side=4
        team_name=evil
        user_team_name= _ "team_name^Enemies"

        no_leader=yes
        hidden=yes
        gold=0
        {NO_INCOME}

        {IS_HOSTILE_NPC}

        {GENERIC_UNIT () (Shaxthal Razorbird) 11 22} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Razorbird) 29 26} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Razorbird) 11  8} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Razorbird) 30  3} {GUARDIAN}
    [/side]

    {NPC_BIRD_BEHAVIOR 4 1 35 1 38}

    {STARTING_VILLAGES_ALL 2}

    {STARTING_VILLAGES 3 6}

    [event]
        name=prestart

        {UNMAKE_HERO (Elynia)}
        {MODIFY_UNIT (id=Elynia) canrecruit yes}
        {FACE_DIRECTION (id=Elynia) sw}

        {VARIABLE_OP original_recruit_list_strlen string_length $main_side1_stats.recruit}

        [if]
            {VARIABLE_NUMERICAL_GREATER_THAN original_recruit_list_strlen 0}
            [then]
                [allow_recruit]
                    side=1
                    type=$main_side1_stats.recruit
                [/allow_recruit]
            [/then]
            [else]
                {LOG_ATS "Resetting recruit list to fallback values (did you use debug-mode to get here?)"}

                [allow_recruit]
                    side=1
                    type=Dark Adept,Faerie Sprite,Ghost,Goblin Spearman,Orcish Archer,Orcish Grunt,Skeleton,Skeleton Archer,Vampire Bat,Walking Corpse
                [/allow_recruit]
            [/else]
        [/if]

        # Make sure main_side1_stats.gold is numeric even when it originally
        # didn't exist.
        {VARIABLE_MUL main_side1_stats.gold 1}

        [modify_side]
            side=1
            gold="$("+{DIFF 240 220 200}+" + $main_side1_stats.gold)"
        [/modify_side]

        {CLEAR_VARIABLE main_side1_stats,original_recruit_list_strlen}

        {VARIABLE enemies_defeated no}

        # wmllint: recognize Mal Keshar
        {RECALL_MAL_KESHAR_AT_LOCATION 10 35}
        {FACE_DIRECTION (id=Mal Keshar) ne}

        # wmllint: recognize Horo
        {RECALL_HORO_AT_LOCATION 11 36}
        {FACE_DIRECTION (id=Horo) sw}

        # wmllint: recognize Kyara
        {RECALL_KYARA_AT_LOCATION 12 34}
        {FACE_DIRECTION (id=Kyara) nw}

        {OBJECTIVES (
            {OBJECTIVE_VICTORY ( _ "Move Elynia to the top edge of the map")}
            {OBJECTIVE_VICTORY ( _ "Defeat all enemy leaders")}

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

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER}
        )}

        [hide_unit]
            id=Elynia
        [/hide_unit]
    [/event]

    #
    # Since Elynia isn’t originally canrecruit=yes, we have to do this *later*
    # so village ownership has an effect at all.
    #

    {STARTING_VILLAGES 1 5}

    [event]
        name=start

        [message]
            speaker=Kyara
            message= _ "She hasn’t wanted to talk to us for days. Is our destination...?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Yes, I gather that her plan is still to strike at Wesmere before the Northlanders have an opportunity to launch a proper offensive or even hear of our situation. Damn, for all I know our messengers and their ship could have been destroyed by the enemy already."
        [/message]

        [message]
            speaker=Horo
            message= _ "I heard that the Grand Council has been hesitant about pressing on this war ever since your victory in the Empire’s so-called capital. They think they’ve won already."
        [/message]

        [fade_out_music]
            time=500
        [/fade_out_music]

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

        [unhide_unit]
            id=Elynia
        [/unhide_unit]

        [redraw][/redraw]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Elynia
            message= _ "Is everyone ready for battle?"
        [/message]

        [message]
            speaker=Kyara
            # wmllint: local spelling Er
            message= _ "Er, battle?"
        [/message]

        [message]
            speaker=Elynia
            message= _ "Our scouts didn’t go unnoticed, and they found a couple of well-armed enemy outposts ahead. This will most certainly not be a safe journey across the dry remains of Wesmere."
        [/message]

        [scroll_to_unit]
            side=3
            canrecruit=yes
        [/scroll_to_unit]

        [delay]
            time=500
        [/delay]

        [scroll_to_unit]
            side=2
            canrecruit=yes
        [/scroll_to_unit]

        [delay]
            time=500
        [/delay]

        [scroll_to_unit]
            side=1
            canrecruit=yes
        [/scroll_to_unit]

        [message]
            speaker=Mal Keshar
            message= _ "Has it even occurred to you that our little struggle in their headquarters on that accursed peninsula has put their forces in motion again to protect what little remains of Yechnagoth?"
        [/message]

        {FACE_DIRECTION (id=Elynia) ne}

        [message]
            speaker=Elynia
            message= _ "Of course it has. But there’s no time to discuss this now. Let’s move out."
        [/message]
    [/event]

    [event]
        name=enemies defeated

        {VARIABLE enemies_defeated yes}

        [message]
            speaker=Kyara
            message= _ "These disgusting demons are vanquished at last!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "Yes, but we must proceed quickly and cautiously to the northeast nevertheless. More troops will come if we give them the opportunity to regroup."
        [/message]

        [if]
            [have_unit]
                id=Elynia
                x=1-100
                y=1
            [/have_unit]
            [then]
                [fire_event]
                    name=objectives completed
                [/fire_event]
            [/then]
            [else]
                {OBJECTIVES (
                    {OBJECTIVE_VICTORY ( _ "Move Elynia to the top edge of the map")}

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

                    {TURNS_RUN_OUT}

                    {OBJECTIVE_CARRYOVER}
                )}
            [/else]
        [/if]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Elynia
            x=1-100
            y=1
        [/filter]
        [filter_condition]
            {VARIABLE_BOOLEAN_EQUALS enemies_defeated yes}
        [/filter_condition]

        [message]
            speaker=Elynia
            message= _ "Onwards we go, now!"
        [/message]

        [fire_event]
            name=objectives completed
        [/fire_event]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Elynia
            x=1-100
            y=1
        [/filter]
        [filter_condition]
            {VARIABLE_BOOLEAN_EQUALS enemies_defeated no}
        [/filter_condition]

        [message]
            speaker=Mal Keshar
            message= _ "We cannot advance without securing our path first!"
        [/message]

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

    [event]
        name=objectives completed

        {ENDLEVEL_VICTORY yes} {NO_ENDLEVEL_MUSIC}
    [/event]

    [event]
        name=victory
        [message]
            speaker=Mal Keshar
            message= _ "It’s still my opinion that we are running a large risk with your current plan."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Was it any better to not take risks at all in that fortress, though?"
        [/message]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Mal Keshar
            message= _ "I don’t know what you are trying to imply, but I may as well remind you that I wasn’t the only one to hesitate and that he would not have survived the attempt without his lower half like I did. It was your assigned task to practice that spell beforehand and you failed to do so — don’t involve me in your mistakes."
        [/message]

        [message]
            speaker=Elynia
            message= _ "(glaring at Mal Keshar) ..."
        [/message]

        [message]
            speaker=Horo
            # wmllint: local spelling Pagh
            message= _ "Pagh, let’s get on with this, everybody! We haven’t got much time!"
        [/message]

        [fade_out_music]
            duration=250
        [/fade_out_music]
    [/event]
[/scenario]

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