#textdomain wesnoth-After_the_Storm

[scenario]
    id=11_Return_to_Wesmere_part_1
    name= _ "Return to Wesmere — Part 1"
    {MAP 11_Return_to_Wesmere_part_1.map}
    {TURNS 34 32 30}
    next_scenario="11_Return_to_Wesmere_part_1_cutscene"

    {B_DEATHS}

    {SCENARIO_MUSIC       "casualties_of_war.ogg"}
    {EXTRA_SCENARIO_MUSIC "battle.ogg"}
    {EXTRA_SCENARIO_MUSIC "siege_of_laurelmor.ogg"}

    {STORYTXT_RETURN_TO_WESMERE_PART_1}

    {SHAXTHAL_SET_SURFACE_VARIATIONS_FLAG}

    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {LONGDARK1}
    {LONGDARK1}
    {LONGDARK2}
    {LONGDARK2}
    {LONGDARK3}
    {LONGDARK3}
    {LONGDARK4}
    {LONGDARK4}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}
    {SHORTDARK}

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

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

        {GOLD 360 350 340}
        {INCOME 5 4 3}

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

#define RTW1_ENEMY_TARGETS
    [goal]
        [criteria]
            id=Elynia
        [/criteria]
        value=10.0
    [/goal]
    [goal]
        [criteria]
            id=Mal Keshar
        [/criteria]
        value=10.0
    [/goal]
#enddef

    [side]
        side=2
        recruit=Chaos Invoker,Chaos Invader,Chaos Raider,Chaos Cavalier
        {GOLD 170 195 210}
        {INCOME 0 2 4}
        team_name=evil
        user_team_name= _ "team_name^Enemies"
        {CHAOS_FLAG}

        #
        # Targeting appears to screw up the pathfinding for this side due
        # to the terrain features found around their starting area so we
        # are not using that here.
        #

        type=Chaos Cataphract
        id=Mendryr
        name= _ "Mendryr"
        canrecruit=yes
        unrenamable=yes
        facing=nw
        [modifications]
            {TRAIT_RESILIENT}
            {TRAIT_INTELLIGENT}
        [/modifications]

        {LOYAL_UNIT () (Chaos Crossbowman) 34 43} {FACING nw}
    [/side]

    [side]
        side=3
        recruit=Chaos Bowman,Chaos Crossbowman,Chaos Invader,Chaos Hound
        {GOLD 200 210 220}
        {INCOME 0 2 4}
        team_name=evil
        user_team_name= _ "team_name^Enemies"
        {CHAOS_FLAG}

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

        type=Chaos Soulhunter
        id=Haldaran
        name= _ "Haldaran"
        canrecruit=yes
        unrenamable=yes
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_QUICK}
        [/modifications]

        {LOYAL_UNIT () (Hellhound) 7 43} {FACING ne}
    [/side]

    [side]
        side=4
        recruit=Demon,Demon Zephyr,Chaos Invoker,Chaos Invader,Shaxthal Rayblade
        {GOLD 240 240 260}
        team_name=evil
        user_team_name= _ "team_name^Wesmere Defense"
        {CHAOS_FLAG}

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

        type=Hell Guardian
        id=Elgamal
        name= _ "Elgamal"
        canrecruit=yes
        unrenamable=yes
        [modifications]
            {TRAIT_RESILIENT}
            {TRAIT_STRONG}
        [/modifications]

        {GENERIC_UNIT () (Doom Guard) 18  8}        {GUARDIAN} {NO_UPKEEP_NO_OVERLAY} {FACING se}
        {GENERIC_UNIT () (Doom Guard) 26  8}        {GUARDIAN} {NO_UPKEEP_NO_OVERLAY} {FACING sw}
        {GENERIC_UNIT () (Doom Guard) 14  2}        {GUARDIAN} {NO_UPKEEP_NO_OVERLAY} {FACING se}
        {GENERIC_UNIT () (Doom Guard) 28  4}        {GUARDIAN} {NO_UPKEEP_NO_OVERLAY} {FACING sw}

        {GENERIC_UNIT () (Chaos Crossbowman) 14 19} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY} {FACING ne}
        {GENERIC_UNIT () (Chaos Crossbowman) 27 19} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY} {FACING nw}
        {GENERIC_UNIT () (Chaos Crossbowman) 12  6} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY} {FACING se}
        {GENERIC_UNIT () (Chaos Crossbowman) 24  7} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY} {FACING sw}
        {GENERIC_UNIT () (Chaos Crossbowman) 32  9} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY} {FACING sw}
        {GENERIC_UNIT () (Chaos Crossbowman)  6  4} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY} {FACING se}
    [/side]

    [side]
        side=5
        recruit=Shaxthal Runner Drone,Shaxthal Razorbird
        gold=0
        {NO_INCOME}
        no_leader=yes
        team_name=evil
        user_team_name= _ "team_name^Enemies"
        {CHAOS_FLAG}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT grouping     no}
            {AI_SIMPLE_ALWAYS_ASPECT aggression 1.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution    0.01}

            {RTW1_ENEMY_TARGETS}

            [goal]
                name=protect_location
                [criteria]
                    x=21
                    y=3
                [/criteria]
                value=5.0
                protect_radius=10
            [/goal]
        [/ai]

        {GENERIC_UNIT () (Verlissh Matrix Flow System)  3 12} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY}
        {GENERIC_UNIT () (Verlissh Matrix Flow System)  5  9} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY}
        {GENERIC_UNIT () (Verlissh Matrix Flow System) 33  4} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY}
        {GENERIC_UNIT () (Verlissh Matrix Flow System) 36  4} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY}
        {GENERIC_UNIT () (Verlissh Matrix Flow System) 10  1} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY}

        {GENERIC_UNIT () (Shaxthal Protector Drone) 12 13} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY} {FACING se}
        {GENERIC_UNIT () (Shaxthal Protector Drone) 24 10} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY} {FACING sw}

        #
        # The following are deliberately not spawned as guardians
        #

        {GENERIC_UNIT () (Shaxthal Sentry Drone)  5 11} {NO_UPKEEP_NO_OVERLAY} {VARIATION surface}

        {GENERIC_UNIT () (Psy Crawler)  4 13} {NO_UPKEEP_NO_OVERLAY}
        {GENERIC_UNIT () (Psy Crawler) 35  5} {NO_UPKEEP_NO_OVERLAY}
        {GENERIC_UNIT () (Psy Crawler)  7  8} {NO_UPKEEP_NO_OVERLAY}
    [/side]

    [side]
        side=6
        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)  5  3} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Razorbird) 23 13} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Razorbird)  3 11} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Razorbird) 27 11} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Razorbird) 10 35} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Razorbird) 27 23} {GUARDIAN}
    [/side]

#undef RTW1_ENEMY_TARGETS

    {NPC_BIRD_BEHAVIOR 6 1 36 1 46}

    {STARTING_VILLAGES_ALL 4}

    {STARTING_VILLAGES 1 4}
    {STARTING_VILLAGES 2 4}
    {STARTING_VILLAGES 3 4}

    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Chaos Cavalier"                 ({DIFF 2 3 4})}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 "Chaos Crossbowman"              ({DIFF 2 3 4})}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Demon Zephyr,Shaxthal Rayblade" ({DIFF 3 4 4})}

    [event]
        name=prestart

        # wmllint: recognize Mal Keshar
        {RECALL_MAL_KESHAR}
        # wmllint: recognize Horo
        {RECALL_HORO}
        # wmllint: recognize Kyara
        {RECALL_KYARA}

        {FACE_DIRECTION (side=1) s}

        {OBJECTIVES (
            {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}

            {OBJECTIVE_NOTE ( _ "Due to the Wesmere curse, the time of day is always chaotic during this scenario")}
        )}
    [/event]

    [event]
        name=start

        [message]
            speaker=Horo
            message= _ "There’s an alarming amount of movement in the southern hills. It would seem an entire battalion has been following our steps since we left Kalari Peninsula."
        [/message]

        [delay]
            time=750
        [/delay]

        [scroll_to_unit]
            id=Mendryr
        [/scroll_to_unit]

        [message]
            speaker=Mendryr
            # wmllint: local spelling Ænthal
            message= _ "The Council was right in their assessment of the situation. The elf witch and the lich have amassed an army of orcs and undead mercenaries to raid Fort Ænthal. It seems we arrived in the nick of time. To arms!"
        [/message]

        [message]
            speaker=Haldaran
            message= _"To arms! For the Dark Lady!"
        [/message]

        [scroll_to_unit]
            id=Elynia
        [/scroll_to_unit]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Mal Keshar
            message= _ "I sort of expected that. It might prove tricky to advance with those buffoons on our heels. On the other hand, the fortress ahead doesn’t seem to be very well guarded."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Very well, then. Let’s take them down."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "I do feel something is amiss, though. We should be cautious... especially since our leader appears to be giving us commands without thinking things through."
        [/message]

        [message]
            speaker=Elynia
            message= _ "If you think you could do a better job at leading the orcs..."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "It’s not my intention to have anything to do with them at all. I just want to make sure you keep your feet on the ground — well, whenever that is an appropriate thing to do, anyway."
        [/message]
    [/event]

    [event]
        name=turn 2
        [message]
            speaker=Kyara
            message= _ "What did you say about the fortress not being well guarded, lich?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "I stand corrected. We may need a better strategy."
        [/message]
    [/event]

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

        [message]
            speaker=unit
            message= _ "We have failed... H— how? *Ugh*"
        [/message]
    [/event]

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

        [message]
            speaker=unit
            message= _ "Forgive us, Lady..."
        [/message]
    [/event]

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

        [message]
            speaker=Mal Keshar
            message= _ "You are about to find out that Yechnagoth is no more, fool."
        [/message]

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

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

        [message]
            speaker=unit
            message= _ "I depart from this world to embrace the power of Uria..."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Not likely, but you will certainly embrace the cold touch of death on the other side, heh, heh."
        [/message]

        [message]
            speaker=Elgamal
            message= _ "You... You haven’t seen the full extent of her power... You haven’t seen the great things she’s done for us... You understand nothing... Nothing... at all..."
        [/message]
    [/event]

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

        [message]
            speaker=Mal Keshar
            message= _ "Now that you’re dead, all that has suddenly become irrelevant, hasn’t it?"
        [/message]
    [/event]

    [event]
        name=enemies defeated

        {ENDLEVEL_VICTORY yes} {NO_ENDLEVEL_MUSIC}
    [/event]

    [event]
        name=victory
        [if]
            [have_unit]
                side=2
                race=human
            [/have_unit]
            [or]
                [have_unit]
                    side=3
                    race=human
                [/have_unit]
            [/or]
            [or]
                [have_unit]
                    side=4
                    race=human
                [/have_unit]
            [/or]
            [then]
                [message]
                    speaker=Elynia
                    message= _ "It’s over now, fiends. Flee while you can, and make sure the Triad hears of your shameful defeat at our hands."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Elynia
                    message= _ "It’s over now. There’s nobody left to obstruct our path but those artificial abominations."
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Horo
            message= _ "(snicker)"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "So, Wesmere is just ahead. What are you going to do now, lass?"
        [/message]

        [message]
            speaker=Elynia
            message= _ "I want to discuss some plans with the three of you right now, in fact. Come with me."
        [/message]

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

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


#textdomain wesnoth-After_the_Storm

[scenario]
    id=11_Return_to_Wesmere_part_1_cutscene
    name= _ "Departure"
    {MAP 11_Return_to_Wesmere_part_1_cutscene.map}
    turns=-1
    next_scenario="11_Return_to_Wesmere_part_2"
    victory_when_enemies_defeated=no

    {CUTSCENE_UI}

    {SCENARIO_MUSIC "harp.ogg"}

    # No storytext, this is a victory cutscene

    {LONGDARK2}

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

        controller=human
        side=1
        team_name=player
        user_team_name= _ "team_name^Elynia"
        gold=0
        {NO_INCOME}

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

    [event]
        name=prestart

        {FACE_DIRECTION (id=Elynia) sw}

        # wmllint: recognize Mal Keshar
        {RECALL_MAL_KESHAR_AT_LOCATION 15 5}
        {FACE_DIRECTION (id=Mal Keshar) sw}

        # wmllint: recognize Horo
        {RECALL_HORO_AT_LOCATION 12 3}
        {FACE_DIRECTION (id=Horo) se}

        # wmllint: recognize Kyara
        {RECALL_KYARA_AT_LOCATION 14 3}
        {FACE_DIRECTION (id=Kyara) sw}

        {LOCK_VIEW}
    [/event]

    [event]
        name=start

        [message]
            speaker=Mal Keshar
            message= _ "You seem even more upset than usual, Elynia. What would the matter be this time?"
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "I don’t think I could bear more losses after what happened to Galas. My plan was not to fight in enemy lands, but rather to infiltrate. This battle was not part of the plan — we were to part ways right before reaching this fort."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Wait... You planned to enter the hive on your own, without us? That’s just... stupid! You don’t know for sure what lurks beneath besides the Shaxthal creatures we have encountered so far! What if that woman or Mal Hekuba are awaiting there?!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "I was hoping you could provide me with a few of your best undead warriors, in fact."
        [/message]

        [message]
            speaker=Horo
            message= _ "Lady, that’s suicidal! From what we’ve heard, nobody could survive a confrontation with those horrors without support! Allow us to protect you until you reach the entrance to the caves at the very least!"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "I refuse to send any undead down there unless you allow me to go with you."
        [/message]

        [redraw][/redraw]

        [delay]
            time=1000
        [/delay]

        {FACE_DIRECTION (id=Elynia) ne}

        [redraw][/redraw]

        [fade_out_music]
            duration=1000
        [/fade_out_music]

        {REPLACE_SCENARIO_MUSIC "snowfall.ogg"}

        [message]
            speaker=Elynia
            message= _ "What’s your motivation, Malin? What makes you want to accompany me now that neither Galas nor Anlindë exist in this world?"
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Mal Keshar
            message= _ "I have been tempted to ask you the same question for a while, actually. I know you cared about the boy much like you cared about Argan, and I have sensed your grief following his death. And yet, somehow you have been in denial about it — perhaps afraid to admit that losing him had a greater effect on your self than losing Argan. I suppose it could just be a matter of time, seeing as how Argan disappeared from your life much longer ago."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "But even though you want to pretend none of this is the truth, your demeanor makes it all evident to us. Now you seem to seek vengeance against Uria’s followers, especially Elyssa. What’s the point of wasting the gift of eternal life to pursue such an ephemeral goal, I ask?"
        [/message]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Elynia
            message= _ "You have not answered... my question..."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Probably because I don’t need to. I don’t have a motive to do anything anymore. My foolish mission to erase the orcish species from Irdya failed too long ago!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "Is it redemption that you seek?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "I don’t know! That’s what you asked when I first met you, remember?"
        [/message]

        [redraw][/redraw]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Kyara
            message= _ "We aren’t accomplishing anything. My lady, please reconsider—"
        [/message]

        [message]
            speaker=Elynia
            message= _ "We’ll secure the hive entrance together, but from that point onwards it will be only Mal Keshar and I, and whoever wants to go with us except for you two."
        [/message]

        [message]
            speaker=Kyara
            # wmllint: local spelling Wh
            message= _ "Wh— Why would that be, my lady?"
        [/message]

        [message]
            speaker=Elynia
            message= _ "We are going to need some capable soldiers alive to alert the Grand Council if neither we nor our messengers make it back. I want you to immediately head back to the Far North should we not return to the surface within one day."
        [/message]

        [message]
            speaker=Horo
            message= _ "Very well, then. I am... unsure about what strategy — if any at all — you have in mind to defeat or destroy whatever you are going to face in that place, but... Your quest is noble. I wish you the best of luck to complete it."
        [/message]

        [message]
            speaker=Kyara
            message= _ "If I ever return to our island, I’ll make sure our people hear of your bravery and your many sacrifices. I am sure you’ll succeed in this last mission, my lady."
        [/message]

        [redraw][/redraw]

        [fade_out_music]
            time=1000
        [/fade_out_music]

        [message]
            speaker=Elynia
            message= _ "Thank you... It really means a lot to me."
        [/message]

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

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


#textdomain wesnoth-After_the_Storm

[scenario]
    id=11_Return_to_Wesmere_part_2
    name= _ "Return to Wesmere — Part 2"
    {MAP 11_Return_to_Wesmere_part_2.map}
    turns=-1
    next_scenario="12_The_Queen"
    victory_when_enemies_defeated=no
    {DO_NOT_REMOVE_FROM_CARRYOVER_ON_DEFEAT}

    {B_DEATHS}

    {SCENARIO_MUSIC       "weight_of_revenge.ogg"} {CONTINUE_PLAYING_STORY_MUSIC_FIRST}
    {EXTRA_SCENARIO_MUSIC "northerners.ogg"}
    {EXTRA_SCENARIO_MUSIC "suspense.ogg"}
    {EXTRA_SCENARIO_MUSIC "heroes_rite.ogg"}

    {STORYTXT_RETURN_TO_WESMERE_PART_2}

    {INDOORS_HIVE} {SCHEDULE_LIGHTING -10 -50 10}

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

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

    {SPAWN_CONTROLLER}

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

        gold=200

        {NO_INCOME}
        village_gold=0
        recall_cost=0

        fog,shroud=yes,yes

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

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

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

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

        no_leader=yes
        {NO_ECONOMY}

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

            {AI_SIMPLE_ALWAYS_ASPECT passive_leader no}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "archer,archer,mixed fighter,archer"}
        [/ai]

        {RTW_MATRIX_PART_1 29 32}
        {RTW_MATRIX_PART_1 47 29}
        {RTW_MATRIX_PART_1 50 29}
        {RTW_MATRIX_PART_1 53 31}
        {RTW_MATRIX_PART_1 55 33}

        {RTW_MATRIX_PART_1 26 24}
        {RTW_MATRIX_PART_1 28 25}
        {RTW_MATRIX_PART_1 24 25}
        {RTW_MATRIX_PART_1 35 26}

        {RTW_MATRIX_PART_1 27 21}
    [/side]

#undef RTW_MATRIX_PART_1

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

        no_leader=yes
        {NO_ECONOMY}

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

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

        no_leader=yes
        {NO_ECONOMY}

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

        {GENERIC_UNIT () (Shaxthal Rayblade) 27 16} {NO_UPKEEP_NO_OVERLAY} {FACING nw} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Rayblade) 38 28} {NO_UPKEEP_NO_OVERLAY} {FACING n } {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Rayblade) 15 33} {NO_UPKEEP_NO_OVERLAY} {FACING ne} {GUARDIAN}

        {GENERIC_UNIT () (Walking Corpse) 24 18} {NO_UPKEEP_NO_OVERLAY} {FACING ne} {GUARDIAN} {VARIATION swimmer}
        {GENERIC_UNIT () (Walking Corpse) 29 17} {NO_UPKEEP_NO_OVERLAY} {FACING nw} {GUARDIAN} {VARIATION swimmer}

        {GENERIC_UNIT () (Soulless) 25 26} {NO_UPKEEP_NO_OVERLAY} {FACING se} {GUARDIAN} {VARIATION swimmer}
        {GENERIC_UNIT () (Soulless) 13 37} {NO_UPKEEP_NO_OVERLAY} {FACING nw} {GUARDIAN} {VARIATION saurian}
        {GENERIC_UNIT () (Soulless) 23 36} {NO_UPKEEP_NO_OVERLAY} {FACING nw} {GUARDIAN} {VARIATION swimmer}
    [/side]

#undef RTW_SHARED_AI_ASPECTS

    #
    # Glyphs
    #

    {OBJ_HEALING_GLYPH 38 27}
    {OBJ_HEALING_GLYPH 14 29}
    {OBJ_HEALING_GLYPH 28 32}
    {OBJ_HEALING_GLYPH 46 30}
    {OBJ_HEALING_GLYPH 57 31}

    #
    # Enemy spawners
    #

#define RTW_SURFACE_SPAWNS
    type="Shaxthal Drone,Shaxthal Sentry Drone,Shaxthal Sentry Drone"
    variation=surface
    max_moves=4
#enddef

#define RTW_EASY_SPAWNS
    type="Shaxthal Drone"
#enddef

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

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

    # Initial area (surface)

    {TIMED_DRONE_SPAWNER 4 ({RTW_SURFACE_SPAWNS}) 4  3  9}
    {TIMED_DRONE_SPAWNER 4 ({RTW_SURFACE_SPAWNS}) 4 21  2}
    {TIMED_DRONE_SPAWNER 2 ({RTW_SURFACE_SPAWNS}) 4 11 13}

    # A

    {TIMED_DRONE_SPAWNER 6 ({RTW_EASY_SPAWNS})   3 27 13}
    {TIMED_DRONE_SPAWNER 4 ({RTW_EASY_SPAWNS})   3 27 14}
    {TIMED_DRONE_SPAWNER 8 ({RTW_MEDIUM_SPAWNS}) 3 30 18}
    {TIMED_DRONE_SPAWNER 5 ({RTW_EASY_SPAWNS})   3 25 21}
    {TIMED_DRONE_SPAWNER 7 ({RTW_EASY_SPAWNS})   3 25 22}
    {TIMED_DRONE_SPAWNER 3 ({RTW_EASY_SPAWNS})   3 38 18}
    {TIMED_DRONE_SPAWNER 6 ({RTW_MEDIUM_SPAWNS}) 3 39 24}
    {TIMED_DRONE_SPAWNER 5 ({RTW_EASY_SPAWNS})   3 36 25}
    {TIMED_DRONE_SPAWNER 8 ({RTW_EASY_SPAWNS})   3 24 27}
    {TIMED_DRONE_SPAWNER 8 ({RTW_EASY_SPAWNS})   3 26 26}
    {TIMED_DRONE_SPAWNER 9 ({RTW_EASY_SPAWNS})   3 27 27}

    # B

    {TIMED_DRONE_SPAWNER 10 ({RTW_MEDIUM_SPAWNS}) 3 18 33}
    {TIMED_DRONE_SPAWNER  4 ({RTW_EASY_SPAWNS})   3 20 33}
    {TIMED_DRONE_SPAWNER  6 ({RTW_EASY_SPAWNS})   3 21 35}
    {TIMED_DRONE_SPAWNER 10 ({RTW_EASY_SPAWNS})   3 26 34}
    {TIMED_DRONE_SPAWNER  4 ({RTW_EASY_SPAWNS})   3 26 35}
    {TIMED_DRONE_SPAWNER 10 ({RTW_HARD_SPAWNS})   3 29 39}
    {TIMED_DRONE_SPAWNER 10 ({RTW_HARD_SPAWNS})   3 34 31}
    {TIMED_DRONE_SPAWNER  8 ({RTW_EASY_SPAWNS})   3 31 36}
    {TIMED_DRONE_SPAWNER  5 ({RTW_EASY_SPAWNS})   3 36 32}

    # C

    {TIMED_DRONE_SPAWNER 20 ({RTW_HARD_SPAWNS})   2 43 35}
    {TIMED_DRONE_SPAWNER 20 ({RTW_EASY_SPAWNS})   2 42 32}

    {TIMED_DRONE_SPAWNER 20 ({RTW_EASY_SPAWNS})   2 52 29}
    {TIMED_DRONE_SPAWNER 20 ({RTW_EASY_SPAWNS})   2 52 32}
    {TIMED_DRONE_SPAWNER 20 ({RTW_EASY_SPAWNS})   2 49 31}
    {TIMED_DRONE_SPAWNER 20 ({RTW_EASY_SPAWNS})   2 49 26}

#undef RTW_SURFACE_SPAWNS
#undef RTW_EASY_SPAWNS
#undef RTW_MEDIUM_SPAWNS
#undef RTW_HARD_SPAWNS

    {CAVE_WATER_SOUND_SOURCE 28 17}

    {CAVE_WATER_SOUND_SOURCE 26 25}

    {CAVE_WATER_SOUND_SOURCE 10 33}

    {CAVE_WATER_SOUND_SOURCE 25 36}

    [event]
        name=prestart

        [item]
            [not]
                [filter][/filter]
            [/not]
            [and]
                [filter]
                    id=Elynia
                [/filter]
                radius=1
            [/and]
            image="items/gohere.png"
        [/item]

        #
        # Remove Kyara and Horo from the recall list
        #

        # wmllint: recognize Kyara
        # wmllint: recognize Horo

        [kill]
            id=Kyara
            [or]
                id=Horo
            [/or]
        [/kill]

        {DISALLOW_END_TURN}

        {FACE_DIRECTION (id=Elynia) se}

        # wmllint: recognize Mal Keshar
        {RECALL_MAL_KESHAR_AT_LOCATION 10 4}
        {FACE_DIRECTION (id=Mal Keshar) se}

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

        [if]
            {VARIABLE_NUMERICAL_LESS_THAN side1_info.gold 200}
            [then]
                [modify_side]
                    side=1
                    gold=200
                [/modify_side]
            [/then]
        [/if]

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

        [store_unit]
            [filter]
                id=Mal Keshar
            [/filter]
            variable=malin_store
        [/store_unit]

        {VARIABLE elynia_store.moves        0 }
        {VARIABLE elynia_store.attacks_left 0 }

        {VARIABLE malin_store.moves         0 }
        {VARIABLE malin_store.attacks_left  0 }

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

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

        {CLEAR_VARIABLE side1_info}

        {OBJECTIVES (
            victory_string= _ "Current Objectives:"
            {OBJECTIVE_VICTORY ( _ "Recruit and/or recall six units")}

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

            {OBJECTIVE_NOTE ( _ "You cannot end your first turn until you have recruited or recalled six units")}
            {OBJECTIVE_NOTE ( _ "You can recruit or recall from your starting location (you do <b>not</b> need a castle or a keep)")}
            {OBJECTIVE_NOTE ( _ "You will not be able to recall or recruit any units later until the end of the mission")}
        )}

        #
        # Configure an initial faded hive ambience sound source.
        #

        [lua]
            code= <<
                local w, h, b = wesnoth.get_map_size()
                wml.variables["w"] = w
                wml.variables["h"] = h
                -- The map diagonal used to calculate the sound source fade radius.
                -- We don't need an accurate value, so it's not a problem that we are
                -- ignoring hex ordinate shift.
                wml.variables["r"] = (w^2 + h^2)^0.5
            >>
        [/lua]

        {HIVE_NOISE_2_SOUND_SOURCE}
        [+sound_source]
            id=hive_sound_source # wmllint: ignore
            x,y=$w,$h
            fade_range=$($r * 0.75)
            full_range=1
        [/sound_source]

        {CLEAR_VARIABLE w,h,r}
    [/event]

    [event]
        name=prerecruit
        first_time_only=no
        [filter]
            side=1
        [/filter]

        [gold]
            side=1
            amount=$unit.cost
        [/gold]
    [/event]

    [event]
        name=prerecruit,prerecall
        first_time_only=no
        [filter]
            side=1
        [/filter]

        [object]
            silent=yes
            # Necessary due to the transition to scenario 12. These units are
            # disposable anyway and are never coming back.
            duration=forever
            [filter]
                x,y=$x1,$y1
            [/filter]
            [effect]
                apply_to=loyal
            [/effect]
        [/object]
    [/event]

    [event]
        name=prerecruit,prerecall
        first_time_only=no
        [filter]
            side=1
        [/filter]
        [filter_condition]
            {VARIABLE_NUMERICAL_EQUALS turn_number 1}
        [/filter_condition]

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

    [event]
        name=recruit,recall
        first_time_only=no
        [filter]
            side=1
        [/filter]
        [filter_condition]
            {VARIABLE_NUMERICAL_EQUALS turn_number 1}
            [and]
                [have_unit]
                    side=1
                    [not]
                        id=Elynia
                    [/not]
                    [not]
                        id=Mal Keshar
                    [/not]
                    count=6
                [/have_unit]
            [/and]
        [/filter_condition]

        [fire_event]
            name=begin mission
        [/fire_event]
    [/event]

    [event]
        name=begin mission

        {OBJECTIVES (
            victory_string= _ "Current Objectives:"
            {OBJECTIVE_VICTORY ( _ "Find the Shaxthal hive entrance and proceed underground")}

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

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

        {ALLOW_END_TURN}

        {VARIABLE elynia_store.moves        $elynia_store.max_moves   }
        {VARIABLE elynia_store.attacks_left $elynia_store.max_attacks }

        {VARIABLE malin_store.moves         $malin_store.max_moves    }
        {VARIABLE malin_store.attacks_left  $malin_store.max_attacks  }

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

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

        {CLEAR_VARIABLE elynia_store,malin_store}

        [store_unit]
            [filter]
                side=1
                race=faerie
                # If the unit is recalled it doesn't count, it just dies
                # underground instead.
                x,y=recall,recall
                [not]
                    id=Elynia
                [/not]
            [/filter]
            kill=no
            variable=faerie_store
        [/store_unit]

        {VARIABLE faerie_found no}

        [foreach]
            array=faerie_store
            variable=faerie
            [do]
                [foreach]
                    array=faerie.modifications.object
                    [do]
                        [if]
                            {VARIABLE_LEXICAL_EQUALS this_item.id fountain_of_courage}
                            [then]
                                {UNIT_TO_GLOBAL_STORE "$faerie.id" episode1_stats_fountain_faerie}

                                {VARIABLE faerie_found yes}

                                [break][/break]
                            [/then]
                        [/if]
                    [/do]
                [/foreach]

                [if]
                    {VARIABLE_BOOLEAN_EQUALS faerie_found yes}
                    [then]
                        [break][/break]
                    [/then]
                [/if]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE faerie_found,faerie_store}

        [kill]
            side=1
            x,y=recall,recall
            animate=no
            fire_event=no
        [/kill]

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

        {REMOVE_RECRUIT_LIST 1}
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            [filter_location]
                time_of_day_id=indoors_hive
            [/filter_location]
        [/filter]

        #
        # Reconfigure the hive ambience sound source so it is heard everywhere
        # regardless of distance.
        #

        # FIXME: Maybe? It doesn't sound that good in practice. Better leave
        #        the transition to the E1S11.2 -> E1S12 progression.

        #{REMOVE_SOUND_SOURCE hive_sound_source}

        #{HIVE_NOISE_2_SOUND_SOURCE}

        [redraw][/redraw]

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

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

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

    [event]
        name=moveto
        [filter]
            side=1
            x=1-76
            y=17-39
        [/filter]

        [message]
            speaker=Elynia
            message= _ "This putrid place seems much larger than it was the last time we set foot on it."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Clearly, our ‘friends’ have been busy at work here — it’s quite a maze. It will be no easy task to find Yechnagoth’s heart, whatever it looks like. Of course, I imagine it must give off an evil presence of some kind."
        [/message]

        [message]
            speaker=Elynia
            message= _ "I’m certain we’ll be able to tell once we find it."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x=24-76
            y=31-39
        [/filter]

        [store_starting_location]
            side=2
        [/store_starting_location]

        [unit]
            canrecruit=yes
            #id=Central Chamber Sentinel
            type=Shaxthal Enforcer Drone
            side=2
            x,y=$location.x,$location.y
            [modifications]
                {TRAIT_BIOMECHANICAL}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [modify_side]
            side=2
            {GOLD 140 160 175}
            {INCOME 2 4 8}
            recruit=Psy Crawler,Shaxthal Drone
        [/modify_side]

        {CLEAR_VARIABLE location}
    [/event]

    [event]
        name=die
        [filter]
            side=2
            canrecruit=yes
        [/filter]

        {ENDLEVEL_QUIET}
    [/event]

    [event]
        name=victory

        # HACK: workaround a warning about "retrieving member of non-exist WML container"
        # caused by the next [store_side] action on 1.10.x and 1.11.x.
        {VARIABLE rtw_end_gamestate.non_existent_wml_container_warning_workaround yes}

        [store_side]
            side=1
            variable=rtw_end_gamestate.player_stats
        [/store_side]

        [store_shroud]
            side=1
            variable=rtw_end_gamestate.shroudmap
        [/store_shroud]

        [store_unit]
            [filter]
                side=1
                {NOT_ON_RECALL_LIST}
            [/filter]
            variable=rtw_end_gamestate.player_onmap_units
            kill=yes
        [/store_unit]

        [store_unit]
            [filter]
                side=2,3,4
            [/filter]
            variable=rtw_end_gamestate.ai_onmap_units
            kill=yes
        [/store_unit]

        {VARIABLE rtw_end_gamestate.turn_number $turn_number}

        {VARIABLE rtw_gameplay_path yes}
    [/event]
[/scenario]

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