#textdomain wesnoth-After_the_Storm

[scenario]
    id=02_01_Return_to_Raelthyn
    name= _ "Return to Raelthyn"
    {MAP 02_01_Return_to_Raelthyn.map}
    next_scenario=02_02_Reckoning

    {F_DEATHS}

    {SCENARIO_MUSIC "heroes_rite.ogg"}

    {STORYTXT_RETURN_TO_RAELTHYN}

    # this scenario lasts one day plus most of the second day
    # until the short darkness begins, regardless of difficulty
    # level for story reasons
    turns=20
    {TWO_SUNS_DEFAULT_SCHEDULE}

    # Adavyan's keep location (SLF); this is used both by AI
    # code and event handlers.
#define R_ADAS_KEEP_SLF
    x=26,24-26,25,27
    y=18,19-20,21,21
#enddef

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

        {GOLD 200 190 180}
        {INCOME 4 3 2}

        fog=yes

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

#define R_INITIAL_UNIT _TYPE _X _Y _ID _NAME _MORE_WML
    [unit]
        type={_TYPE}
        x={_X}
        y={_Y}

        id={_ID}
        name={_NAME}

        random_gender=no
        random_traits=no
        generate_name=no

        upkeep=loyal

        {_MORE_WML}
    [/unit]
#enddef

    [side]
        side=2
        controller=human
        persistent=no
        team_name=good
        user_team_name= _ "team_name^Raelthyn"
        {ARAGWAITH_FLAG}

        {GOLD 270 260 240}
        {INCOME 6 5 4}
        recruit=Aragwaith Archer,Aragwaith Spearman,Aragwaith Witch,Aragwaith Scout,Aragwaith Swordsman,Aragwaith Eagle Rider

        # wmllint: recognize Torancyn
        {CHARACTER_STATS_TORANCYN}
        [+modifications]
            {TEAM_COLOR_OVERRIDE () orange}
        [/modifications]
        canrecruit=yes
        facing=sw

        [unit]
            # wmllint: recognize Valen
            {CHARACTER_STATS_VALEN}
            {IS_HERO}
            [+modifications]
                {TEAM_COLOR_OVERRIDE () teal}
                {MOD_LOYAL_HERO}
            [/modifications]
            facing=sw
            x,y=24,19
        [/unit]

        {R_INITIAL_UNIT (Aragwaith Longswordsman) 26 33 Boros   ( _ "Boros") (
            facing=sw
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_QUICK}
            [/modifications]
        )}
        {R_INITIAL_UNIT (Aragwaith Longswordsman) 34 28 Dereon  ( _ "Dereon") (
            facing=se
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_STRONG}
            [/modifications]
        )}
        {R_INITIAL_UNIT (Aragwaith Strongbow)     38 26 Valthyn ( _ "Valthyn") (
            facing=se
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_QUICK}
            [/modifications]
        )}
        {R_INITIAL_UNIT (Aragwaith Pikeman)       41 20 Pelarth ( _ "Pelarth") (
            facing=se
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_INTELLIGENT}
            [/modifications]
        )}
        {R_INITIAL_UNIT (Aragwaith Strongbow)     18 18 Fraldar ( _ "Fraldar") (
            facing=sw
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_INTELLIGENT}
            [/modifications]
        )}
        {R_INITIAL_UNIT (Aragwaith Eagle Master)  35 10 Rilbur  ( _ "Rilbur") (
            facing=ne
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_INTELLIGENT}
            [/modifications]
        )}

        # These two are from IftU scenario 14
        {R_INITIAL_UNIT (Aragwaith Strongbow)     16 23 Blynyr  ( _ "Blynyr") (
            facing=sw
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_QUICK}
            [/modifications]
        )}
        {R_INITIAL_UNIT (Aragwaith Longswordsman) 16 30 Zednal  ( _ "Zednal") (
            facing=nw
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_QUICK}
            [/modifications]
        )}
    [/side]
    # wmllint: validate-on

#define R_DRILLER _X _Y
    [unit]
        type=Shaxthal Demolisher Drone
        x={_X}
        y={_Y}
        upkeep=loyal

        overlays="misc/payload-icon.png"

        random_gender=no
        random_traits=no
        generate_name=no

        [modifications]
            {TRAIT_BIOMECHANICAL}
        [/modifications]
    [/unit]
#enddef

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

        no_leader=yes

        gold=0
        village_gold=0
        {NO_INCOME}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            # Try to not attack enemy units unless there is no
            # other option.
            {AI_SIMPLE_ALWAYS_ASPECT aggression      -1000.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution             0.00}
            {AI_SIMPLE_ALWAYS_ASPECT village_value       0.00}
            {AI_SIMPLE_ALWAYS_ASPECT grouping              no}

            #
            # Try to reach Advyan’s keep to deploy the payload.
            #

            [goal]
                name=target_location
                value=1000.0
                [criteria]
                    {R_ADAS_KEEP_SLF}
                [/criteria]
            [/goal]
        [/ai]

        {R_DRILLER  5 31} {FACING ne}
        {R_DRILLER 41 42} {FACING nw}
        {R_DRILLER 15  5} {FACING se}
#ifndef EASY
        {R_DRILLER 62  1} {FACING nw}
#endif
    [/side]

#undef R_DRILLER

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

        {GOLD 150 160 170}
        recruit=Chaos Gunner,Chaos Invoker,Chaos Invader,Chaos Raider

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

        canrecruit=yes
        type=Chaos Cataphract
        id=Daraes Pelnoth
        name= _ "Daraes Pelnoth"
        facing=nw
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_RESILIENT}
            {BOSS_BOOST 20% 0 0 2 0}
        [/modifications]

        {R_INITIAL_UNIT ("Chaos Magus") 56 37 Golgathar ( _ "Golgathar") (
            facing=nw
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_RESILIENT}
            [/modifications]
        )}
        {R_INITIAL_UNIT ("Dark Knight") 58 32 Merkal ( _ "Merkal") (
            facing=nw
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_STRONG}
            [/modifications]
        )}
    [/side]

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

        {GOLD 155 160 165}
        recruit=Imp,Demon,Chaos Bowman,Chaos Headhunter

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

        canrecruit=yes
        type=Armageddon Imp
        id="Demon Lord Rhalgar'agael"
        name= _ "Demon Lord Rhalgar’agael"
        facing=se
        [modifications]
            {TRAIT_SLOW}
            {TRAIT_INTELLIGENT}
            {BOSS_BOOST 12% 0 0 1 1}
        [/modifications]

        {R_INITIAL_UNIT ("Demon Stormtide")  8  4 Kretassal ( _ "Kretassal") (
            facing=se
            gender=female
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_INTELLIGENT}
            [/modifications]
        )}
        {R_INITIAL_UNIT ("Demon Stormtide") 13  7 Kilagor ( _ "Kilagor") (
            facing=se
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_STRONG}
            [/modifications]
        )}
        {R_INITIAL_UNIT ("Demon Zephyr") 18  3 Daenangor ( _ "Daenangor") (
            facing=se
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_DEXTROUS}
            [/modifications]
        )}
    [/side]

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

        {GOLD 160 170 180}
        recruit=Shaxthal Runner Drone,Chaos Invader,Chaos Bowman,Vampire Bat

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

        canrecruit=yes
        type=Ancient Lich
        id=Mal Sultaria
        name= _ "Mal Sultaria"
        facing=ne
        [modifications]
            {TRAIT_UNDEAD}
            {TRAIT_RESILIENT}
            {BOSS_BOOST 10% 0 0 0 0}
        [/modifications]

        {R_INITIAL_UNIT ("Blood Imp")  5 29 Thorkar ( _ "Thorkar") (
            facing=ne
            [modifications]
                {TRAIT_DIM}
                {TRAIT_STRONG}
            [/modifications]
        )}
        {R_INITIAL_UNIT ("Chaos Marauder") 3 18 Cergil ( _ "Cergil") (
            facing=se
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_INTELLIGENT}
            [/modifications]
        )}
    [/side]

    [side]
        side=7
        team_name=evil
        user_team_name= _ "team_name^Enemies"
        {CHAOS_FLAG}

        {GOLD 150 160 170}
        recruit=Demon,Ghoul,Skeleton Archer,Ghost

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

        canrecruit=yes
        type=Chaos Lorekeeper
        id=Morragor
        name= _ "Morragor"
        facing=nw
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_INTELLIGENT}
            {BOSS_BOOST 40% 1 1 0 1}
        [/modifications]

        {R_INITIAL_UNIT ("Demon Grunt") 60  9 Iralir  ( _ "Iralir") (
            facing=nw
            [modifications]
                {TRAIT_DEXTROUS}
                {TRAIT_QUICK}
            [/modifications]
        )}
        {R_INITIAL_UNIT ("Blood Imp") 55 15 Romoror ( _ "Romoror") (
            facing=nw
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_SLOW}
            [/modifications]
        )}
    [/side]

    [side]
        side=8
        team_name=good
        user_team_name= _ "team_name^Arphalad"
        {ARAGWAITH_FLAG}

        hidden=yes
        no_leader=yes

        controller=null

        {NO_INCOME}
        gold,village_gold=0,0
    [/side]

    [side]
        side=9
        team_name=good
        user_team_name= _ "team_name^Elves"
        {ELVISH_FLAG}

        hidden=yes
        no_leader=yes

        controller=null

        {NO_INCOME}
        gold,village_gold=0,0
    [/side]

#undef R_INITIAL_UNIT

    {STARTING_VILLAGES 4 9}
    {STARTING_VILLAGES 5 9}
    {STARTING_VILLAGES 6 9}
    {STARTING_VILLAGES 7 9}

    # NOTE: objects are shifted by x+12 and y+4 relative
    # to their locations in the standard Raelthyn map

    [label]
        x,y=45,8
        text= _ "Arphalad"
    [/label]

    [label]
        x,y=41,13
        text= _ "River Lorin"
    [/label]

    [label]
        x,y=29,30
        text= _ "Lake Wylven"
    [/label]

    [label]
        x,y=25,20
        text= _ "Adavyan’s Keep"
    [/label]

    [label]
        x,y=17,15
        text= _ "Danaerad"
    [/label]

    [label]
        x,y=35,10
        text= _ "Tower of Silence"
    [/label]

    # {PLACE_IMAGE scenery/leanto.png 17 9}
    {PLACE_IMAGE scenery/temple1.png 22 11}
    # {PLACE_IMAGE scenery/oak-leaning.png 30 21}
    # {PLACE_IMAGE scenery/oak-leaning.png 30 12}
    # {PLACE_IMAGE scenery/oak-leaning.png 22 12}
    # {PLACE_IMAGE items/archery-target-right.png 15 14}
    # {PLACE_IMAGE items/archery-target-right.png 25 18}

    # {PLACE_IMAGE "scenery/temple1.png"   42  5}
    # {PLACE_IMAGE "items/straw-bale1.png" 49  8}
    # {PLACE_IMAGE "items/straw-bale2.png" 47 26}
    # {PLACE_IMAGE "items/grain-sheaf.png" 50 34}
    # {PLACE_IMAGE "items/straw-bale1.png" 43 38}
    # {PLACE_IMAGE "items/straw-bale1.png" 51 26}

    # wmllint: whofield R_RAELTHYN_DEFENSE 4
#define R_RAELTHYN_DEFENSE _TYPE _X _Y _ID _NAME _TRAITS _FACING
    [unit]
        animate=yes
        side=2
        type={_TYPE}
        x={_X}
        y={_Y}
        unrenamable=yes

        id={_ID}
        name={_NAME}

        random_gender=no
        random_traits=no
        generate_name=no

        overlays="misc/loyal-icon.png"
        upkeep=loyal

        facing={_FACING}

        [modifications]
            {TRAIT_LOYAL}
            {_TRAITS}
        [/modifications]
    [/unit]
#enddef

    # wmllint: whofield R_ARPHALAD_MILITIA 4
#define R_ARPHALAD_MILITIA _TYPE _X _Y _ID _NAME _TRAITS _FACING
    [unit]
        animate=yes
        side=8
        type={_TYPE}
        x={_X}
        y={_Y}
        unrenamable=yes

        id={_ID}
        name={_NAME}

        random_gender=no
        random_traits=no
        generate_name=no

        overlays="misc/loyal-icon.png"
        upkeep=loyal

        facing={_FACING}

        [modifications]
            {TRAIT_LOYAL}
            {_TRAITS}
        [/modifications]
    [/unit]
#enddef

    [event]
        name=prestart

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

        {FACE_DIRECTION (side=1) sw}

        # This is the amount of load-bearing drones the player
        # has to take down. The exact count will vary according
        # to difficulty (see above), but to make it easier for
        # future balancing we'll determine it at runtime instead
        # of hardcoding numbers.

        [count_units]
            type=Shaxthal Demolisher Drone
            variable=payload_count
        [/count_units]

        [hide_unit]
            side=2
        [/hide_unit]

        [capture_village]
            side=2
            x=13-45,23
            y= 8-32,37
            terrain=*^V*
        [/capture_village]

        {UNIT_FROM_GLOBAL_STORE episode1_stats_igor}

        {UNIT_FROM_GLOBAL_STORE episode1_stats_fountain_faerie}

        [if]
            {VARIABLE_ARRAY_NOT_EMPTY episode1_stats_fountain_faerie}
            [then]
                # Make her loyal. Injecting the loyal trait is not precisely
                # trivial since we need to extract the contents of the [trait]
                # tag by force.

                [set_variables]
                    name=episode1_stats_fountain_faerie[0]
                    mode=merge
                    [literal]
                        side=8
                        upkeep=loyal
                        {IS_LOYAL}
                    [/literal]
                [/set_variables]

                [set_variables]
                    name=temp_trait_loyal_data
                    mode=replace
                    [literal]
                        {TRAIT_LOYAL}
                    [/literal]
                [/set_variables]

                [set_variables]
                    name=episode1_stats_fountain_faerie[0].modifications.trait[0]
                    mode=insert
                    to_variable=temp_trait_loyal_data.trait
                [/set_variables]

                {CLEAR_VARIABLE temp_trait_loyal_data}

                # The fountain faerie should be in the same state she was as
                # part of the player's recall list at the start of E1S11.2.
                # This means we don't need to clear statuses or heal her back
                # to full. Put her in the recall list so we can use [recall]
                # on her later.

                [unstore_unit]
                    variable="episode1_stats_fountain_faerie[0]"
                    x,y=recall,recall
                [/unstore_unit]
            [/then]
        [/if]
    [/event]

    #
    # The objectives in this scenario are rather unusually complicated, so
    # we update them in a single event that acts as a WML function of sorts
    # to make future code changes easier to accomplish.
    #

#define R_UPDATE_OBJECTIVES
    [fire_event]
        name=update player objectives
    [/fire_event]
#enddef

#define R_COMMON_OBJECTIVES
    {OBJECTIVE_VICTORY_END_OF_TURNS}
    {OBJECTIVE_OPTIONAL ( _ "Defeat all enemy leaders"+{EARLY_FINISH_BONUS_FOOTNOTE})}

    {OBJECTIVE_DEFEAT  ( _ "A Demolisher Drone explodes within range of Adavyan’s Keep")}
    {OBJECTIVE_SHOW_IF ({VARIABLE_NUMERICAL_GREATER_THAN payload_count 0})}
#enddef

#define R_OBJECTIVES_SIDE_1_DEATHS
    {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
    {OBJECTIVE_DEFEAT  ( _ "Death of Anya")}
    {OBJECTIVE_DEFEAT  ( _ "Death of Durvan")}
    {OBJECTIVE_DEFEAT  ( _ "Death of Irylean")}
#enddef

#define R_OBJECTIVES_SIDE_2_DEATHS
    {OBJECTIVE_DEFEAT  ( _ "Death of Torancyn")}
    {OBJECTIVE_DEFEAT  ( _ "Death of Valen")}
#enddef

#define R_OBJECTIVE_NOTES
    {OBJECTIVE_NOTE ( _ "Adavyan’s Keep comprises the initial keep and castle tiles where Torancyn stands")}
    {OBJECTIVE_NOTE ( _ "Keep in mind Demolisher Drones destroy and kill everything within a one-hex radius when slain; you will need to sacrifice units to achieve your goals")}
#enddef

#define R_OBJECTIVE_NON_PERSISTENT_TEAM_WARNING
    {OBJECTIVE_NOTE ( _ "Torancyn and his units (blue team) will not be carried over to the next scenario")}
#enddef

#define R_OBJECTIVE_DRONES
    [objective]
        description= _ "Destroy the Demolisher Drones before they reach Adavyan’s Keep at the center of the city"+" "+_"($payload_count drones remaining)"+""
        condition=win
        [show_if]
            {VARIABLE_NUMERICAL_GREATER_THAN payload_count 1}
        [/show_if]
    [/objective]
    [objective]
        description= _"Destroy the Demolisher Drones before they reach Adavyan’s Keep at the center of the city"+" "+_"(One drone remaining)"+""
        condition=win
        [show_if]
            {VARIABLE_NUMERICAL_EQUALS payload_count 1}
        [/show_if]
    [/objective]
#enddef

    [event]
        name=update player objectives
        first_time_only=no

        [if]
            {VARIABLE_NUMERICAL_GREATER_THAN payload_count 0}
            [then]
                {OBJECTIVES (
                    side=1
                    silent=yes
                    {R_OBJECTIVE_DRONES}
                    {R_COMMON_OBJECTIVES}
                    {R_OBJECTIVES_SIDE_1_DEATHS}
                    {R_OBJECTIVE_NOTES}
                    {OBJECTIVE_CARRYOVER}
                )}

                {OBJECTIVES (
                    side=2
                    silent=yes
                    {R_OBJECTIVE_DRONES}
                    {R_COMMON_OBJECTIVES}
                    {R_OBJECTIVES_SIDE_2_DEATHS}
                    {R_OBJECTIVE_NON_PERSISTENT_TEAM_WARNING}
                    {R_OBJECTIVE_NOTES}
                )}
            [/then]
            [else]
                {OBJECTIVES (
                    side=1
                    {R_COMMON_OBJECTIVES}
                    {R_OBJECTIVES_SIDE_1_DEATHS}
                    {OBJECTIVE_CARRYOVER}
                )}

                {OBJECTIVES (
                    side=2
                    {R_COMMON_OBJECTIVES}
                    {R_OBJECTIVES_SIDE_2_DEATHS}
                    {R_OBJECTIVE_NON_PERSISTENT_TEAM_WARNING}
                )}
            [/else]
        [/if]
    [/event]

#undef R_COMMON_OBJECTIVES
#undef R_OBJECTIVES_SIDE_1_DEATHS
#undef R_OBJECTIVES_SIDE_2_DEATHS
#undef R_OBJECTIVE_DRONES
#undef R_OBJECTIVE_NOTES
#undef R_OBJECTIVE_NON_PERSISTENT_TEAM_WARNING

    [event]
        name=start

        [message]
            speaker=Durvan
            message= _ "I can barely see through this fog and smoke, but, those are the city walls."
        [/message]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=narrator
            image="misc/blank-hex.png"
            message= _ "Dispel the fog."
        [/message]

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

        [message]
            speaker=Durvan
            message= _ "Uh, I haven’t said anything..."
        [/message]

        [delay]
            time=750
        [/delay]

        [unit]
            animate=yes
            # wmllint: recognize Irylean
            {CHARACTER_STATS_IRYLEAN}
            side=8
            x,y=45,6
        [/unit]

        {LOYAL_UNIT 8 (Skeleton Archer) 44 5} {FACING ne}
        [+unit]
            [+modifications]
                {TEAM_COLOR_OVERRIDE () white}
            [/modifications]
        [/unit]
        {LOYAL_UNIT 8 (Skeleton Archer) 45 7} {FACING ne}
        [+unit]
            [+modifications]
                {TEAM_COLOR_OVERRIDE () white}
            [/modifications]
        [/unit]

        [message]
            speaker=Irylean
            message= _ "This has only just begun. Who are you and why have you come to this capital of destruction—"
        [/message]

        {FACE_DIRECTION (id=Elynia) se}

        [message]
            speaker=Elynia
            message=_ "I know you. Aren’t you—"
        [/message]

        [message]
            speaker=Irylean
            message= _ "The Lady of Light! We are saved! Hear, everyone, the gods have finally answered our prayers! She has returned!"
        [/message]

        {R_ARPHALAD_MILITIA (Aragwaith Swordsman) 47 8 Roeghar ( _ "Roeghar") ({TRAIT_RESILIENT})   (nw)}
        {R_ARPHALAD_MILITIA (Aragwaith Archer)    49 7 Avethan ( _ "Avethan") ({TRAIT_INTELLIGENT}) (nw)}

        [if]
            {VARIABLE_ARRAY_NOT_EMPTY episode1_stats_fountain_faerie}
            [then]
                [recall]
                    id="$episode1_stats_fountain_faerie[0].id"
                    x,y=47,6
                [/recall]

                [message]
                    speaker="$episode1_stats_fountain_faerie[0].id"
                    message= _ "My lady! I had long given up my search! But you are still alive, after all this time!"
                [/message]

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

        [message]
            speaker=Avethan
            message= _ "All hail the Lady of Light!"
        [/message]

        [message]
            speaker=Anya
            message= _ "You appear to be quite popular here."
        [/message]

        [message]
            speaker=Elynia
            message= _ "This is rather unexpected given the circumstances of my previous return, but that was a long time ago, after all. If I’m not mistaken you are Irylean, one of Galas’ old advisors?"
        [/message]

        [message]
            speaker=Irylean
            message= _ "Indeed I was, my lady, but ever since Lord Galas stepped down I retired to this once prosperous land. The demons’ assault was completely unexpected, but we are all doing our best to repel their forces. Sadly, there have been rumors that many members of the Grand Council were killed by the initial charges that destroyed the walls."
        [/message]

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

        [redraw]
            side=1 # refresh minimap
        [/redraw]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Anya
            message= _ "The fog has lifted!"
        [/message]

        [message]
            speaker=Durvan
            message= _ "Lords of Light, what has happened to the capital?"
        [/message]

        [message]
            speaker=narrator
            image="misc/blank-hex.png"
            message= _ "Look around."
        [/message]

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

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

        {FACE_DIRECTION (id=Elynia) sw}

        [delay]
            time=750
        [/delay]

        {R_BEHOLD_LOCATION 35 10}

        {R_BEHOLD_LOCATION 16  7}

        {R_BEHOLD_LOCATION 16 26}

        {R_BEHOLD_LOCATION 30 39}

        {R_BEHOLD_LOCATION 58 34}

        {R_BEHOLD_LOCATION 25 20}

#undef R_BEHOLD_LOCATION

        [move_unit_fake]
            type=Aragwaith Lancer
            side=2
            x=35,36,37,38,39,40,41
            y= 8, 7, 7, 6, 6, 5, 5
        [/move_unit_fake]

        {R_RAELTHYN_DEFENSE (Aragwaith Lancer) 41 5 Vaenceth ( _ "Vaenceth") ({TRAIT_INTELLIGENT}) ne}
        [+unit]
            animate=no
        [/unit]

        [message]
            speaker=Vaenceth
            message= _ "Lady of Light, the Grand Council—or what remains of it anyway—sent me with a message for you, from our seer."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Valen? Is she—"
        [/message]

        [message]
            speaker=Vaenceth
            message= _ "She’s alive and well, but she needs your help— we all need your help. Our highest walls were struck down by strange exploding creatures of the enemy — and our scouts have spotted more of the things approaching the capital."
        [/message]

        [store_locations]
            [filter]
                type=Shaxthal Demolisher Drone
            [/filter]
            variable=payload_locs
        [/store_locations]

        [foreach]
            array=payload_locs
            variable=loc
            [do]
                [scroll_to_unit]
                    x,y=$loc.x,$loc.y
                [/scroll_to_unit]

                {HIGHLIGHT_GOAL (x,y=$loc.x,$loc.y)}
            [/do]
        [/foreach]

        {CLEAR_VARIABLE payload_locs}

        [message]
            speaker=Vaenceth
            message= _ "If we are to defend Raelthyn, we must ensure they don’t reach and destroy the main keep where the remaining Grand Council members are. Should we lose the keep..."
        [/message]

        [message]
            speaker=Elynia
            message= _ "That would be a huge blow against everyone’s morale, I know."
        [/message]

        [message]
            speaker=Irylean
            message= _ "I didn’t expect more of them to be heading here! I saw them in action... Attempting to stop them might not have been my brightest plan."
        [/message]

        [message]
            speaker=Vaenceth
            message= _ "Lord Torancyn said we should take them down no matter the cost."
        [/message]

        [message]
            speaker=Elynia
            message= _ "What a suicidal approach. Of course this is hardly a problem when all involved are undead, but we’ll never reach the other drones before they get to the keep. I assume his plan is to sacrifice his own people; he should hope there are desperate souls willing to give up their lives for the city amongst his troops. Irylean?"
        [/message]

        [message]
            speaker=Irylean
            message= _ "I’m at your service, my lady. And I presume the good people of Arphalad are as well."
        [/message]

        [message]
            speaker=Elynia
            message= _ "I suggest you reconsider your retirement. If we succeed here, I may require your help for a personal quest of mine. But for now, we need to take down those creatures and force their leaders to retreat or else, and you will help us."
        [/message]

        {MODIFY_UNIT (side=8) side 1}

        [message]
            speaker=Irylean
            message= _ "Of course, my lady."
        [/message]

        [message]
            speaker=Elynia
            message= _ "It’s time to get moving."
        [/message]

        [if]
            {VARIABLE_ARRAY_NOT_EMPTY episode1_stats_igor}
            [then]
                [message]
                    speaker=narrator
                    caption= _ "unit_name^???"
                    image="$episode1_stats_igor.profile|~CS(-512,-512,-512)"
                    message= _ "Hold on!"
                [/message]

                [message]
                    speaker=Anya
                    message= _ "Huh?"
                [/message]

                [message]
                    speaker=Elynia
                    message= _ "That voice... is that..."
                [/message]

                [scroll_to]
                    x,y=34,8
                [/scroll_to]

                [delay]
                    time=750
                [/delay]

                [move_unit_fake]
                    type=$episode1_stats_igor.type
                    side=1
                    x=34-35,36-37,38-39,40,41-42
                    y=    8,    7,    6, 5,    6
                [/move_unit_fake]

                {VARIABLE episode1_stats_igor.facing ne}

                [unstore_unit]
                    variable=episode1_stats_igor
                    find_vacant=yes
                    x,y=42,6
                [/unstore_unit]

                {CLEAR_VARIABLE episode1_stats_igor}

                [delay]
                    time=500
                [/delay]

                [message]
                    speaker=Igor
                    message= _ "Lady Elynia! It’s been so long! The old lady has told me so many sad things and I... I..."
                [/message]

                [message]
                    speaker=Elynia
                    message= _ "Oh, Igor. I am so glad to see you are still alive after all the misfortune that’s befallen us, you have no idea. But there will be time to go over everything later. I hope Willow and you are up to the task, because we need all the help we can muster."
                [/message]

                [message]
                    speaker=Igor
                    message= _ "Of course, my lady, that’s why we waited here! We’re ready to go!"
                [/message]

                [message]
                    speaker=Anya
                    message= _ "(whispering) Psst, who is this little guy?"
                [/message]

                [message]
                    speaker=Durvan
                    message= _ "(whispering) I have no idea, but he really stinks..."
                [/message]
            [/then]
        [/if]

        [allow_recruit]
            side=1
            type=Vampire Bat,Ghost,Skeleton,Skeleton Archer,Walking Corpse
        [/allow_recruit]

        [transient_message]
            image="units/undead/zombie-wolf-attack.png~RC(magenta>red)"
            message= _ "You can once again recruit undead units. Additionally, Irylean and the surviving militiamen of Arphalad will follow you on your quest.

Irylean normally only raises the corpses of wild beasts unless she can get a direct kill on a unit vulnerable to plague with her melee weapon. This means that recruited Walking Corpses are always of the Gryphon, Wolf, or Bat variations."
        [/transient_message]

        [unhide_unit]
            side=2
        [/unhide_unit]

        [capture_village]
            side=1
            x=37-47
            y= 1-10
            terrain=*^V*
        [/capture_village]

        {MOVE_UNIT (id=Elynia) 41 3}

        {R_UPDATE_OBJECTIVES}

        # HACK: We need this here since we always set the initial objectives silent=yes
        # above to keep the code simple, causing them to not be shown at the start of
        # turn 1 like usual.
        [show_objectives][/show_objectives]
    [/event]

    [event]
        name=side 2 turn 1

        {REPLACE_SCENARIO_MUSIC ("casualties_of_war.ogg")}
        {APPEND_MUSIC           ("siege_of_laurelmor.ogg")}
        {APPEND_MUSIC           ("battle.ogg")}

        [message]
            speaker=Torancyn
            message= _ "Here they come."
        [/message]

        [message]
            speaker=Valen
            message= _ "Haven’t we lost enough soldiers and citizens defending the city yet? You should have rallied any necromancers you could find in the nearby towns instead."
        [/message]

        [message]
            speaker=Torancyn
            message= _ "The last one I trusted ended up betraying the Lady of Light, or that’s what you told us. What makes you think that we can ever accept their help again?"
        [/message]

        [message]
            speaker=Valen
            message= _ "The notion that not all of them are like-minded."
        [/message]

        # wmllint: local spelling Illana

        [message]
            speaker=Torancyn
            message= _ "I’m not taking my chances. Especially not now that Arnesius and Illana—"
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Torancyn
            message= _ "Let’s just proceed with the plan and be done with it."
        [/message]
    [/event]

#undef R_RAELTHYN_DEFENSE
#undef R_ARPHALAD_MILITIA

    [event]
        name=moveto
        [filter]
            x,y=25,11
            [and]
                side=1
                [or]
                    side=2
                [/or]
            [/and]
        [/filter]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "This is one of many statues found in the city, raised in honor of Adavyan of the Aragwaithi, a figure of legend and great importance to the peoples of the Far North.

It was only about two centuries ago that this sorceress incited a war which would, in time, lead to the unification of these lands. She founded Raelthyn and the Grand Council, and established this city as the definitive capital of the Far North. The central keep bearing her revered name became a sacred place much akin to the temples to the fabled Lords of Light.

Raelthyn, the capital of peace, built atop the corpses of all those who dared to oppose Adavyan’s cause. Not everyone is aware of the irony of all this, but if Adavyan’s Keep were to fall in the hands of the enemy—or worse, be completely obliterated—the morale of the northern army would be utterly crushed."
        [/message]
    [/event]

    [event]
        # 'die' is used by the Demolition ability, and we're not guaranteed
        # our handler here will execute before that one, so we need to make
        # sure to block the ability's event handler first by triggering our
        # player defeat path!
        name=last breath
        [filter]
            type=Shaxthal Demolisher Drone
            [filter_location]
                [filter_adjacent_location]
                    {R_ADAS_KEEP_SLF}
                [/filter_adjacent_location]
            [/filter_location]
        [/filter]

        [fire_event]
            name=destroy adas keep
            [primary_unit]
                x,y=$x1,$y1
            [/primary_unit]
        [/fire_event]
    [/event]

    [event]
        name=moveto
        [filter]
            type=Shaxthal Demolisher Drone
            {R_ADAS_KEEP_SLF}
        [/filter]

        [fire_event]
            name=destroy adas keep
            [primary_unit]
                x,y=$x1,$y1
            [/primary_unit]
        [/fire_event]
    [/event]

    [event]
        name=destroy adas keep

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

        {WHITE_SCREEN}

        # unceremoniously kill everyone in the keep without
        # giving them a chance to say their usual last words

        [kill]
            {R_ADAS_KEEP_SLF}
            animate=no
            fire_event=no
        [/kill]

        # TODO: also kill everyone adjacent

        # boom!

        [terrain]
            {R_ADAS_KEEP_SLF}
            terrain=Qxe
        [/terrain]

        {QUAKE "explosion-big.ogg"}

        [redraw][/redraw] # update terrain display

        {RESET_SCREEN}

        [delay]
            time=1000
        [/delay]

        [message]
            # try to locate a living hero unit
            id=Torancyn
            [or]
                id=Valen
            [/or]
            [or]
                id=Elynia
            [/or]
            [or]
                id=Anya
            [/or]
            [or]
                id=Durvan
            [/or]
            [or]
                id=Irylean
            [/or]
            # failing that, go for non-hero units
            [or]
                side=2
            [/or]
            [or]
                side=1
            [/or]
            message= _ "We have failed; Adavyan’s keep has been destroyed!"
        [/message]

        # signal defeat and get us out of whatever sequence led here
        # (i.e. so we don't get the Demolition ability's 'die' event handler
        # to run when the payload was activated near the keep)

        {ENDLEVEL_DEFEAT}
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            type=Shaxthal Demolisher Drone
            [not]
                [filter_location]
                    [filter_adjacent_location]
                        {R_ADAS_KEEP_SLF}
                    [/filter_adjacent_location]
                [/filter_location]
            [/not]
        [/filter]
        [filter_condition]
            {VARIABLE_NUMERICAL_GREATER_THAN payload_count 0}
        [/filter_condition]

        {VARIABLE_DEC payload_count}

        [fire_event]
            name=check payload status
        [/fire_event]
    [/event]

    [event]
        name=demolition complete
        [filter_condition]
            {VARIABLE_NUMERICAL_EQUALS payload_count 0}
        [/filter_condition]

        [message]
            speaker=Torancyn
            message= _ "Very well, the last one of those bastards is down!"
        [/message]
    [/event]

    [event]
        name=check payload status
        first_time_only=no

        {R_UPDATE_OBJECTIVES}
    [/event]

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

        [message]
            speaker=Valen
            message= _ "Lord Torancyn, please tell the Lady of Light... the journal... I’m sorry..."
        [/message]
    [/event]

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

        {ENDLEVEL_DEFEAT}
    [/event]

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

        [message]
            speaker=Torancyn
            message= _ "I never expected the heart of our country to be my last battlefield... Alas, Raelthyn will fall... without me..."
        [/message]
    [/event]

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

        [message]
            speaker=Irylean
            message= _ "Lord Torancyn was slain in battle. This is hopeless."
        [/message]

        {ENDLEVEL_DEFEAT}
    [/event]

    [event]
        name=die
        [filter_second]
            id=Igor
        [/filter_second]

        [message]
            speaker=Igor
            message= _ "I’m city goblin no more! Now I’m battle goblin! HAHA!!!"
        [/message]

        [message]
            speaker=Anya
            message= _ "... City goblin?"
        [/message]

        [message]
            speaker=Durvan
            message= _ "... Battle... goblin?"
        [/message]

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

    [event]
        name=enemies defeated
        {ENDLEVEL_VICTORY yes}

        [message]
            speaker=Torancyn
            message= _ "Do the rest of you fiends want to come and taste our steel?"
        [/message]

        [message]
            speaker=Valen
            message= _ "They appear to be retreating."
        [/message]
    [/event]

    [event]
        name=time over
        {ENDLEVEL_VICTORY no}

        [message]
            speaker=Durvan
            message= _ "The fiends retreat; that’s rather odd."
        [/message]
    [/event]

    [event]
        name=victory

        [kill]
            canrecruit=yes
            [filter_side]
                [enemy_of]
                    side=1
                [/enemy_of]
            [/filter_side]
            animate=no
            fire_event=no
        [/kill]

        # wmllint: recognize Unarye
        [unit]
            {CHARACTER_STATS_UNARYE}
            canrecruit=yes
            side=9
            x,y=56,2
            facing=sw
        [/unit]

        {GENERIC_UNIT 9 (Elvish Sharpshooter) 56 1} {FACING sw}
        {GENERIC_UNIT 9 (Elvish Champion) 57 2} {FACING sw}

        {GENERIC_UNIT 9 (Elvish Enchantress) 60 16} {FACING nw}
        {GENERIC_UNIT 9 (Elvish Marshal) 60 17} {FACING nw}
        {GENERIC_UNIT 9 (Elvish Fighter) 61 14} {FACING nw}
        {GENERIC_UNIT 9 (Elvish Outrider) 53 3} {FACING nw}
        {GENERIC_UNIT 9 (Elvish Fighter) 54 16} {FACING nw}
        {GENERIC_UNIT 9 (Elvish Archer) 59 9} {FACING sw}
        {GENERIC_UNIT 9 (Elvish Prowler) 57 5} {FACING sw}
        {GENERIC_UNIT 9 (Elvish Captain) 60 5} {FACING sw}
        {GENERIC_UNIT 9 (Elvish Marksman) 53 13} {FACING se}
        {GENERIC_UNIT 9 (Elvish Shyde) 61 10} {FACING nw}
        {GENERIC_UNIT 9 (Elvish Ascetic) 59 3} {FACING sw}

        [message]
            speaker=Anya
            message= _ "Look to the northeast!"
        [/message]

        [scroll_to_unit]
            id=Unarye
        [/scroll_to_unit]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Igor
            message= _ "It’s the other elf lady!"
        [/message]

        [message]
            speaker=Irylean
            message= _ "Ha! It was about time!"
        [/message]

        {CLEAR_VARIABLE payload_count}
    [/event]

#undef R_ADAS_KEEP_SLF
#undef R_UPDATE_OBJECTIVES
[/scenario]

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


#textdomain wesnoth-After_the_Storm

[scenario]
    id=02_02_Reckoning
    name= _ "Reckoning"
    {MAP 02_02_Reckoning.map}
    turns=-1
    next_scenario=03_Amidst_the_Ruins_of_Glamdrol
    victory_when_enemies_defeated=no

    {FULLSCREEN_CUTSCENE_UI}

    {SCENARIO_MUSIC "knolls.ogg"}

    {DUSK2}

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

        {NO_ECONOMY}

        shroud=yes # prevent map snapshot in Load Game dialog

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

    [side]
        side=2
        team_name=good
        user_team_name= _ "team_name^Raelthyn"
        {ARAGWAITH_FLAG}

        {NO_ECONOMY}

        # wmllint: recognize Torancyn
        {CHARACTER_STATS_TORANCYN}
        [+modifications]
            {TEAM_COLOR_OVERRIDE () orange}
        [/modifications]
        canrecruit=yes
        facing=sw

        [unit]
            # wmllint: recognize Valen
            {CHARACTER_STATS_VALEN}
            {IS_HERO}
            [+modifications]
                {TEAM_COLOR_OVERRIDE () teal}
                {MOD_LOYAL_HERO}
            [/modifications]
            facing=sw
            x,y=15,12
        [/unit]

        [unit]
            type=Aragwaith Guard
            id=Aranel
            name= _ "Aranel"
            upkeep=free
            {IS_HERO}
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_RESILIENT}
            [/modifications]
            facing=sw
            x,y=13,11
        [/unit]
    [/side]

    [side]
        side=3
        team_name=good
        user_team_name= _ "team_name^Elves"
        {ELVISH_FLAG}
        color=teal

        {NO_ECONOMY}

        # wmllint: recognize Unarye
        {CHARACTER_STATS_UNARYE}
        facing=nw

        [unit]
            type=Elvish Marshal
            id=Lorenel
            name= _ "Lorenel"
            x,y=14,13
            upkeep=free
            {IS_HERO}
            [modifications]
                {TRAIT_DEXTROUS}
                {TRAIT_QUICK}
            [/modifications]
            facing=nw
        [/unit]
    [/side]

    # wmllint: validate-on

    [event]
        name=prestart

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

        # wmllint: recognize Anya
        {RECALL_ANYA_AT_LOCATION 11 12}
        # wmllint: recognize Durvan
        {RECALL_DURVAN_AT_LOCATION 11 13}
        # wmllint: recognize Irylean
        {RECALL_IRYLEAN_AT_LOCATION 10 12}
        # wmllint: recognize Igor
        {RECALL_IGOR_AT_LOCATION 10 13}

        {FACE_DIRECTION (side=1) ne}

        [capture_village]
            side=2
            terrain=*^V*
        [/capture_village]

        {LOCK_VIEW}
    [/event]

    [event]
        name=start
        [message]
            speaker=Torancyn
            message= _ "I don’t think any number of words could suffice to express our gratitude for your intervention, Lady Unarye. I am glad the elves are soon to be united under a single banner again; perhaps the costs will be compensated before long."
        [/message]

        [message]
            speaker=Unarye
            message= _ "I would also hope so, my lord, but we have to be realistic: we cannot win this war, and our chances of survival don’t look good either now that our enemies are roaming and ravaging our lands unimpeded. According to Elynia we are running out of time — for all we know Uria could already be on Irdya."
        [/message]

        [message]
            speaker=Valen
            message= _ "I am truly sorry my vision can’t penetrate the veil beyond our frontiers with the old Chaos Empire."
        [/message]

        [message]
            speaker=Unarye
            message= _ "There’s no need to apologize, my lady. We are powerless against this creature and her minions."
        [/message]

        [message]
            speaker=Elynia
            message= _ "We might be powerless as you say, but there’s still something I want to try. Valen, you told me you had found something; is it the journal I asked you to search?"
        [/message]

        [message]
            speaker=Valen
            # po: The orc is Horo (male), the elf is Kyara (female).
            message= _ "Indeed it is, my lady. There is an orc, and an elf from the Vast Sea; they have spent a long time traveling through the chaotic southwestern region trying to reach us. We sent men in their aid, but the recent events within our borders have delayed their return. They found shelter in Fort Astar, near the now nonexistent Glamdrol Range. It is the location of our main southwestern host, which has been under constant attack by enemy forces as of late."
        [/message]

        [message]
            speaker=Torancyn
            message= _ "We were meant to send reinforcements to Astar. You can probably guess the rest."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Of course. Nevertheless, I shall go there with Irylean and whoever else is willing to join us along the way. That journal is far too important to lose."
        [/message]

        [message]
            speaker=Torancyn
            message= _ "I guess there’s no point in stopping you. But I would like to remind you that we need more men and women capable of defending this city, here. If Adavyan’s Keep falls..."
        [/message]

        [message]
            speaker=Elynia
            message= _ "... So does the Far North; I have heard the legend before. Consider this, though, what is the point of defending this place with a thousand swords if Uria can blast the entire fortress to smithereens in a blink?"
        [/message]

        [message]
            speaker=Torancyn
            message= _ "I’ll ponder that when I deem it convenient to do so, Lady of Light. I declare this council meeting over now. May the Lords of Light protect you on your way."
        [/message]

        {MOVE_UNIT (id=Torancyn) 19  9}

        # don't kill him, so that village ownership doesn't change

        [hide_unit]
            id=Torancyn
        [/hide_unit]

        {MOVE_UNIT (id=Aranel) 18  8}

        [kill]
            id=Aranel
        [/kill]

        {MOVE_UNIT (id=Valen) 17 11}

        [message]
            speaker=Igor
            message= _ "I really don’t like the heavy swords guy. Willow thinks he’s bad news too."
        [/message]

        [message]
            speaker=Unarye
            message= _ "Elynia, I fear I cannot be of much help at this time. My people are still fighting the Chaos armies and doing their best to keep them away from Raelthyn. I—"
        [/message]

        [message]
            speaker=Elynia
            message= _ "Don’t worry, Unarye. I understand. I am sure we’ll be able to do this without Raelthyn’s help."
        [/message]

        [message]
            speaker=Unarye
            message= _ "I’ll see you again soon then, friend."
        [/message]

        {MOVE_UNIT (id=Unarye) 18 14}

        [kill]
            id=Unarye
        [/kill]

        {MOVE_UNIT (id=Lorenel) 16 14}

        [kill]
            id=Lorenel
        [/kill]

        {FACE_DIRECTION (id=Elynia) sw}

        [message]
            speaker=Elynia
            message= _ "It is time for us to go."
        [/message]

        [message]
            speaker=Valen
            message= _ "Would that your demonic ally hadn’t been forced to leave us so soon, don’t you think?"
        [/message]

        {FACE_DIRECTION (id=Elynia) ne}

        [delay]
            time=750
        [/delay]

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

        {FACE_DIRECTION (id=Valen) sw}

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Valen
            message= _ "Elynia, I am a seer. As I said, my vision is limited and I can’t help you with what lies within enemy territory, but the Demon Lord who helped you through this young lady’s hands worked within our frontiers. I saw him, and I saw you."
        [/message]

        [message]
            speaker=Anya
            message= _ "Why didn’t you tell us this before? We thought—"
        [/message]

        {MOVE_UNIT (id=Valen) 16 11}

        [message]
            speaker=Valen
            message= _ "That the Grand Council wouldn’t understand? Yes, and that was a correct assessment, especially now that Torancyn is the Supreme Lord of the Aragwaith — he would certainly not permit this. But with Lord Arnesius dead, I no longer have any obligations to anybody, and most importantly, I no longer speak in the name of the law. There is something I must tell you before I depart from this doomed land."
        [/message]

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

        {MOVE_UNIT (id=Valen) 15 12}

        [message]
            speaker=Valen
            message= _ "The night before the demons attacked this region, someone communicated with me directly; someone by the name of Ergea, Demon Lord of the Storms. She warned me of what was about to take place in Raelthyn. She warned me of a portal to Kalari built in Aran-Balgur, a stronghold lost to the forces of Uria not long after the fall of the Emperor. And finally, she told me to instruct the Lady of Light to meet with her in the Pass of Sorrows, north from Kalari Peninsula."
        [/message]

        [message]
            speaker=Valen
            message= _ "She left my room as swiftly as she appeared and I haven’t heard of her since."
        [/message]

        {FACE_DIRECTION (id=Elynia) nw}

        [message]
            speaker=Elynia
            message= _ "Anya, do you know anything about this Ergea?"
        [/message]

        [message]
            speaker=Anya
            message= _ "No... I’m not sure. I think I heard Elorran mention a Demon Lord of the Storms once, but I don’t know anything about her faction or allegiances. There’s also this thing about working in secrecy since Uria has turned rebellious factions in her favor before — Elorran chose to work on his own to minimize the risk of betrayal."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Girl, if you had mentioned this before I might have outright refused to support him. Of course, he remained loyal to his cause until the very end. I guess... I never expected such heroism from a member of the species Uria uses to facilitate our destruction."
        [/message]

        [message]
            speaker=Valen
            message= _ "My lady, I fear it is not my place to tell you what you should do next, given that I lack further information and I haven’t been able to contact or see this demoness again. I advise you do what you feel is right; the future is not my domain, and anything beyond Irdya is beyond my reach."
        [/message]

        {FACE_DIRECTION (id=Elynia) ne}

        [message]
            speaker=Elynia
            message= _ "The last time I was told to do what I felt was right I ended up causing a catastrophe... Fair enough. Thank you for this information and your support, Valen. May the Lords of Light guide your path, wherever you plan to go next."
        [/message]

        [message]
            speaker=Valen
            message= _ "Farewell, Lady of Light. May you all find your destiny."
        [/message]

        {MOVE_UNIT (id=Valen) 20 9}

        [kill]
            id=Valen
        [/kill]

        [hide_unit][/hide_unit]

        {FADE_TO_BLACK}

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

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


#textdomain wesnoth-After_the_Storm

[scenario]
    id=03_Amidst_the_Ruins_of_Glamdrol
    name= _ "Amidst the Ruins of Glamdrol"
    {MAP 03_Amidst_the_Ruins_of_Glamdrol.map}
    {TURNS 26 24 22}
    next_scenario=04_01_Outpost_of_Hell

    {G_DEATHS}

    {SCENARIO_MUSIC       "climactic_contemplation.ogg"}
    {EXTRA_SCENARIO_MUSIC "western_theme2.ogg"}
    {EXTRA_SCENARIO_MUSIC "loyalists.ogg"}
    {EXTRA_SCENARIO_MUSIC "breaking_the_chains.ogg"}

    {STORYTXT_AMIDST_THE_RUINS_OF_GLAMDROL}

    {TWO_SUNS_DEFAULT_SCHEDULE}

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

        {GOLD 155 145 140}

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

    [side]
        side=2
        controller=human
        persistent=yes
        save_id=second_player
        team_name=good
        user_team_name= _ "team_name^General Bardyl"
        {ALLIANCE_FLAG}

        {GOLD 210 200 190}
        recruit=Aragwaith Spearman,Aragwaith Archer,Aragwaith Scout,Orcish Grunt,Orcish Archer,Wolf Rider,Orcish Assassin

        # wmllint: recognize General Bardyl
        {CHARACTER_STATS_GENERAL_BARDYL}

        [unit]
            x,y=18,13
            experience=97
            # wmllint: recognize Kyara
            {CHARACTER_STATS_KYARA}
        [/unit]

        [unit]
            x,y=19,13
            experience=142
            # wmllint: recognize Horo
            {CHARACTER_STATS_HORO}
        [/unit]

        [unit]
            x,y=20,15
            id=Vernar
            name= _ "Vernar"
            type=Wolf Rider
            upkeep=loyal
            {IS_LOYAL}
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [unit]
            x,y=24,12
            id=Relmanyr
            name= _ "Relmanyr"
            type=Aragwaith Spearman
            upkeep=loyal
            {IS_LOYAL}
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]

        [village]
            x,y=33,16
        [/village]

        [village]
            x,y=17,30
        [/village]

        [village]
            x,y=27,5
        [/village]

        [village]
            x,y=12,3
        [/village]
    [/side]

#define GLAM_BODYGUARD _TYPE _X _Y _FACING _TRAIT
    [unit]
        type={_TYPE}
        x={_X}
        y={_Y}
        upkeep=loyal
        ai_special=guardian
        facing={_FACING}
        # For sentry drones
        variation=surface
        [modifications]
            {TRAIT_BIOMECHANICAL}
            {_TRAIT}
            {UNIT_PALETTE_SWITCH () shaxthal_drone_surface shaxthal_drone_brown}
        [/modifications]
        [variables]
            bodyguard=yes
        [/variables]
    [/unit]
#enddef

    [side]
        side=3
        team_name=evil
        user_team_name= _ "team_name^Nar-hamoth"
        {CHAOS_FLAG}

        {GOLD 180 190 200}
        recruit=Demon,Demon Zephyr,Shaxthal Rayblade,Shaxthal Protector Drone,Chaos Invader,Chaos Headhunter,Chaos Invoker

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

        canrecruit=yes
        facing=ne
        type=Chaos Soulhunter
        id=Karathas
        name= _ "Karathas"
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_RESILIENT}
        [/modifications]

        {GENERIC_UNIT () (Chocobone) 15 31} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING ne}
        {GENERIC_UNIT () (Chocobone) 13 27} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING nw}
        {GENERIC_UNIT () (Chocobone) 19 35} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}

        {GLAM_BODYGUARD ("Shaxthal Protector Drone") 12 33 ne ({TRAIT_QUICK})}
        {GLAM_BODYGUARD ("Shaxthal Protector Drone") 19 37 ne ({TRAIT_QUICK})}
#ifndef EASY
        {GLAM_BODYGUARD ("Shaxthal Enforcer Drone")  4 37 ne ({TRAIT_INTELLIGENT})}
        {GLAM_BODYGUARD ("Shaxthal Enforcer Drone") 10 42 ne ({TRAIT_STRONG})}
#endif

        [unit]
            type=Chaos Headhunter
            id=Meryrcor
            name= _ "Meryrcor"
            x,y=7,33
            upkeep=loyal
            ai_special=guardian
            facing=ne
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        [unit]
            type=Chaos Headhunter
            id=Delvryd
            name= _ "Delvryd"
            x,y=15,41
            upkeep=loyal
            ai_special=guardian
            facing=se
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

#ifndef EASY
        [unit]
            type=Chaos Marauder
            id=Cervan
            name= _ "Cervan"
            x,y=6,42
            upkeep=loyal
            #ai_special=guardian
            facing=ne
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]
#endif

        [unit]
            type=Chaos Marksman
            x,y=16,35
            upkeep=loyal
            #ai_special=guardian
            facing=ne
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]

        [unit]
            type=Chaos Marksman
            x,y=14,34
            upkeep=loyal
            #ai_special=guardian
            facing=ne
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

#ifndef EASY
        [unit]
            type=Demon Warrior
            id=Borothas
            name= _ "Borothas"
            gender=male
            x,y=10,35
            upkeep=loyal
            ai_special=guardian
            facing=ne
            [modifications]
                {TRAIT_DEXTROUS}
                {TRAIT_FEARLESS}
            [/modifications]
        [/unit]
#endif

        [unit]
            type=Demon Warrior
            id=Galthera-Irul
            name= _ "Galthera-Irul"
            gender=male
            x,y=17,38
            upkeep=loyal
            ai_special=guardian
            facing=nw
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [unit]
            type=Demon Zephyr
            gender=female
            id=Zilrynea
            name= _ "Zilrynea"
            x,y=15,28
            upkeep=loyal
            ai_special=guardian
            facing=ne
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [unit]
            type=Demon Zephyr
            gender=female
            id=Igryella
            name= _ "Igryella"
            x,y=8,26
            upkeep=loyal
            ai_special=guardian
            facing=ne
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]
    [/side]
    # wmllint: validate-on

#undef GLAM_BODYGUARD

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

        {GOLD 175 180 185}
        recruit=Chaos Bowman,Chaos Raider,Chaos Invader,Shaxthal Runner Drone

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

        canrecruit=yes
        type=Chaos Heavy Longbowman
        id=Loras-Chalzerg
        name= _ "Loras-Chalzerg"
        facing=nw
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_DEXTROUS}
        [/modifications]

        [unit]
            type=Shaxthal Assault Drone
            x,y=44,31
            upkeep=loyal
            ai_special=guardian
            facing=sw
            [modifications]
                {TRAIT_BIOMECHANICAL}
                {TRAIT_ARMORED}
            [/modifications]
        [/unit]

        [unit]
            type=Doom Guard
            x,y=38,31
            id=Sargan
            name= _ "Sargan"
            upkeep=loyal
            ai_special=guardian
            facing=se
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [unit]
            type=Doom Guard
            x,y=40,36
            id=Rohalar
            name= _ "Rohalar"
            upkeep=loyal
            ai_special=guardian
            facing=nw
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]

#ifndef EASY
        [unit]
            type=Chaos Arbalestier
            x,y=47,36
            id=Vryncthan
            name= _ "Vryncthan"
            upkeep=loyal
            ai_special=guardian
            facing=nw
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [unit]
            type=Dark Knight
            x,y=47,31
            id=Gellerdyl
            name= _ "Gellerdyl"
            upkeep=loyal
            ai_special=guardian
            facing=sw
            [modifications]
                {TRAIT_FEARLESS}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]
#endif

        [unit]
            type=Chaos Magus
            id="Kri'tan"
            name= _ "Kri’tan"
            x,y=42,29
            upkeep=loyal
            ai_special=guardian
            facing=sw
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [unit]
            type=Demon Zephyr
            gender=female
            id=Therelei
            name= _ "Therelei"
            x,y=34,22
            upkeep=loyal
            ai_special=guardian
            facing=nw
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

#ifndef EASY
        [unit]
            type=Demon Zephyr
            gender=male
            id=Avralereon
            name= _ "Avralereon"
            x,y=46,18
            upkeep=loyal
            ai_special=guardian
            facing=ne
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_DEXTROUS}
            [/modifications]
        [/unit]
#endif
    [/side]

    {STARTING_VILLAGES 1 6}
    {STARTING_VILLAGES 2 6}
    {STARTING_VILLAGES 3 8}
    {STARTING_VILLAGES 4 6}

    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 ("Demon Zephyr")                        1 }
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 ("Shaxthal Rayblade")        {DIFF 1 2 2} }
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 ("Shaxthal Protector Drone")            1 }

    [event]
        name=prestart

        {INCIDENTAL_MUSIC "enchanted_forest.ogg"}

        {VARIABLE boss_attack_count 0}

        [teleport]
            [filter]
                id=Elynia
            [/filter]
            x,y=43,9
        [/teleport]

        # wmllint: recognize Anya
        {RECALL_ANYA_AT_LOCATION    43  8}
        # wmllint: recognize Durvan
        {RECALL_DURVAN_AT_LOCATION  45  9}
        # wmllint: recognize Irylean
        {RECALL_IRYLEAN_AT_LOCATION 44  9}
        # wmllint: recognize Igor
        {RECALL_IGOR_AT_LOCATION    44  7}

        {FACE_DIRECTION (side=1)    sw}
        {FACE_DIRECTION (id=Elynia) ne}
        {FACE_DIRECTION (side=2)    se}

        [hide_unit]
            id=Elynia
        [/hide_unit]

        #
        # Grant Kyara and Horo default AMLAs according
        # to the time they have supposedly spent scurrying
        # around.
        #

        [set_variables]
            name=temp_amla_default
            mode=replace
            [value]
                {AMLA_DEFAULT}
            [/value]
        [/set_variables]

        [repeat]
            times={DIFF 3 3 2}
            [do]
                [apply_amlas]
                    id="Kyara"
                    [insert_tag]
                        name="advancement"
                        variable="temp_amla_default.advancement"
                    [/insert_tag]
                [/apply_amlas]
            [/do]
        [/repeat]

        [repeat]
            times={DIFF 2 2 1}
            [do]
                [apply_amlas]
                    id="Horo"
                    [insert_tag]
                        name="advancement"
                        variable="temp_amla_default.advancement"
                    [/insert_tag]
                [/apply_amlas]
            [/do]
        [/repeat]

        {CLEAR_VARIABLE temp_amla_default}

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

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

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER}
        )}

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

            {OBJECTIVE_DEFEAT  ( _ "Death of General Bardyl")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Horo")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Kyara")}

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER}

            {OBJECTIVE_NOTE ( _ "You’ll continue to control General Bardyl and his troops until the end of the next scenario")}
        )}
    [/event]

    [event]
        name=start

        {LOCK_VIEW}

        [message]
            speaker=Anya
            message= _ "This is taking too long — I begin to worry for Elynia..."
        [/message]

        # wmllint: local spelling Nah

        [message]
            speaker=Durvan
            message= _ "Nah, there she comes."
        [/message]

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

        [move_unit_fake]
            type=$elynia_store.type
            side=1
            x=35,35,38,38,39-41,$elynia_store.x
            y=15,12,10, 9,    9,$elynia_store.y
        [/move_unit_fake]

        {CLEAR_VARIABLE elynia_store}

        [unhide_unit]
            id=Elynia
        [/unhide_unit]

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Anya
            message= _ "Elynia, you are back! Is that... the journal?"
        [/message]

        [message]
            speaker=Elynia
            message= _ "That’s correct."
        [/message]

        [message]
            speaker=Durvan
            message= _ "So, is that General Bardyl fellow going to help us assault Aran-Balgur then?"
        [/message]

        [message]
            speaker=Elynia
            message= _ "Indeed he is, but not specifically because of my advice; he was already giving consideration to the idea because of a rumor that’s been running through his troops as of late. It appears someone successfully ‘interrogated’ a captured enemy soldier and got some information about the source of the local raids and the ongoing invasion. What they know suggests that there is indeed a portal in Aran-Balgur."
        [/message]

        [message]
            speaker=Elynia
            message= _ "I shudder to wonder exactly how this information was obtained. I know from experience that the men in the service of the Empire are either completely ignorant of their superiors’ plans, or instructed to commit suicide before being captured, and the sorcerers and demons are too powerful to contain."
        [/message]

        [message]
            speaker=Anya
            message= _ "I guess now we should all advance towards Aran-Balgur?"
        [/message]

        [message]
            speaker=Elynia
            message= _ "Exactly. And we should be careful."
        [/message]

        [scroll_to]
            x,y=11,38
            check_fogged=no
        [/scroll_to]

        {HIGHLIGHT_GOAL (x,y=11,38)}

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Elynia
            scroll=no
            message= _ "The road to the south leading to Aran-Balgur is said to be well protected by powerful demons, and there’s also an enemy guard post obstructing our path. Furthermore, we may stumble upon their main invasion army at some point. The only reason Fort Astar still stands is that they don’t perceive Bardyl’s forces as a threat stationed here. However, the moment they see his little army marching towards their territory, they will not be as merciful."
        [/message]

        [message]
            speaker=Durvan
            message= _ "So it rests on us and our followers, I take it."
        [/message]

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

        {MOVE_UNIT   (id=Elynia)      44 8}
        {FACE_DIRECTION (id=Elynia) sw}

        {UNLOCK_VIEW}
    [/event]

    [event]
        name=DEBUG1

        [fire_event]
            name=enemy speech 2
        [/fire_event]

        [fire_event]
            name=new turn
        [/fire_event]

        {VARIABLE boss_attack_count 2}
    [/event]

    [event]
        name=side 2 turn 1 refresh
        [message]
            speaker=General Bardyl
            message= _ "And so, it begins."
        [/message]
    [/event]

    [event]
        name=side 2 turn 1 end
        [message]
            speaker=Kyara
            message= _ "If you don’t mind me asking, sir, are you sure about this?"
        [/message]

        [message]
            speaker=General Bardyl
            message= _ "Of course I am. The Grand Council has neglected us for long enough, and those damned bastards from hell are getting increasingly bored of playing with us. As much as I find her kind disgusting, if the faerie’s troops and power are as impressive as she promised we’ll recover Aran-Balgur before long. And if there’s a portal in there and we can destroy it, we’ll regain the Council’s blessing as well."
        [/message]
    [/event]

    {OBSIDIAN_BATTLE_AXE 35 24}

    {POTION_OF_BLOODLUST 42 21}

    [event]
        name=turn 3
        [filter_condition]
            [have_unit]
                id=Igor
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=Igor
            message= _ "Time to tear those evil creatures to bits! We will make them pay, oh yes..."
        [/message]

        [message]
            speaker=Durvan
            message= _ "This goblin fellow seems really invested into this, doesn’t he?"
        [/message]

        [message]
            speaker=Anya
            message= _ "Apparently he was close friends with Lord Galas and Mal Keshar, and also someone else... Elynia hasn’t told me much about that woman in particular, which is saying something considering how difficult it is to get her to talk about the others in the first place."
        [/message]

        [message]
            speaker=Durvan
            message= _ "Are you sure you should be prying that much, though? It sounds like a very personal subject for her."
        [/message]

        [message]
            speaker=Anya
            message= _ "I know, I know... I just wish she would open up and not shoulder so much grief alone when we are all in this together. But perhaps you are right, it’s not my place to intrude."
        [/message]
    [/event]

    #
    # After turn 3, shit gets real.
    #

    [event]
        name=attack
        [filter]
            [filter_side]
                team_name=evil
            [/filter_side]
            race=human,demon,imp
        [/filter]
        [filter_second]
            [filter_side]
                team_name=good
            [/filter_side]
        [/filter_second]
        [filter_condition]
            {VARIABLE_NUMERICAL_GREATER_THAN_OR_EQUAL turn_number 3}
        [/filter_condition]

        [fire_event]
            name=enemy speech 1
            [primary_unit]
                x,y=$x1,$y1
            [/primary_unit]
        [/fire_event]
    [/event]

    [event]
        name=attack
        [filter]
            [filter_side]
                team_name=good
            [/filter_side]
        [/filter]
        [filter_second]
            [filter_side]
                team_name=evil
            [/filter_side]
            race=human,demon,imp
        [/filter_second]
        [filter_condition]
            {VARIABLE_NUMERICAL_GREATER_THAN_OR_EQUAL turn_number 3}
        [/filter_condition]

        [fire_event]
            name=enemy speech 1
            [primary_unit]
                x,y=$x2,$y2
            [/primary_unit]
        [/fire_event]
    [/event]

    [event]
        name=enemy speech 1
        [message]
            speaker=unit
            message= _ "Lord Nar-hamoth demands the blood of the northern scum! Charge!"
        [/message]

        [event]
            name=attack end
            [fire_event]
                name=enemy speech 2
            [/fire_event]
        [/event]
    [/event]

    [event]
        name=enemy speech 2
        [message]
            speaker=Elynia
            message= _ "I remember that name — I believe it’s one of the fiends of the Iron Triad."
        [/message]

        [message]
            speaker=Anya
            message= _ "So the rumors Elorran heard are true? That guy is said to be the least competent Demon Lord of all, and yet Uria trusts him over most for some reason."
        [/message]

        [message]
            speaker=Elynia
            message= _ "We’ll soon see how competent he is on the battlefield, then."
        [/message]

        #
        # Make Nar-hamoth’s Shaxthal bodyguards active on the battlefield
        # if they aren't already.
        #

        {MOBILIZE_GUARDIANS (
            side=3
            [filter_wml]
                [variables]
                    bodyguard=yes
                [/variables]
            [/filter_wml]
        )}

        # Nar-hamoth enters the battlefield on the next turn.

        [event]
            name=new turn
            # wmllint: recognize Nar-hamoth
            [unit]
                side=3
                x,y=9,40
                {CHARACTER_STATS_NAR_HAMOTH}
                facing=nw
                {IS_BOSS}
                [+modifications]
                    {MOD_LOYAL_HERO}
                [/modifications]
            [/unit]
        [/event]
    [/event]

    #
    # Nar-hamoth wants a challenge.
    #

    [event]
        name=attack
        [filter]
            [filter_side]
                team_name=good
            [/filter_side]
        [/filter]
        [filter_second]
            id=Nar-hamoth
        [/filter_second]

        [fire_event]
            name=narhamoth intro
        [/fire_event]
    [/event]

    [event]
        name=attack
        [filter]
            id=Nar-hamoth
        [/filter]
        [filter_second]
            [filter_side]
                team_name=good
            [/filter_side]
        [/filter_second]

        [fire_event]
            name=narhamoth intro
        [/fire_event]
    [/event]

    [event]
        name=narhamoth intro

        [message]
            speaker=Nar-hamoth
            message= _ "So you finally decided to challenge me directly? Hopefully this will be an entertaining fight! For the glory of the mother of Urvatha!"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            [filter_side]
                team_name=good
            [/filter_side]
        [/filter]
        [filter_second]
            id=Nar-hamoth
        [/filter_second]

        [message]
            speaker=Nar-hamoth
            message= _ "Die, pathetic Irdyan rats! DIE!"
        [/message]
    [/event]

    [event]
        name=narhamoth heal
        first_time_only=no

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

        [delay]
            time=500
        [/delay]

        [heal_unit]
            [filter]
                id=Nar-hamoth
            [/filter]
            amount=full
            animate=yes
            # We don't want him to unexpectedly deal full damage mid-turn after
            # being slowed, that would be extremely unfair
            restore_statuses=no
            restore_attacks=no
            moves=0
        [/heal_unit]
    [/event]

#define GLAM_NARHAMOTH_HEALTH_THRESHOLD _FACTOR _DISPATCH_EVENT
    [event]
        name=attacker hits
        [filter_second]
            id=Nar-hamoth
        [/filter_second]

        [filter_condition]
            {VARIABLE_NUMERICAL_LESS_THAN_OR_EQUAL "second_unit.hitpoints" "$({_FACTOR} * $second_unit.max_hitpoints)"}
        [/filter_condition]

        [fire_event]
            name={_DISPATCH_EVENT}
            [primary_unit]
                id=Nar-hamoth
            [/primary_unit]
            [secondary_unit]
                x,y=$x1,$y1
            [/secondary_unit]
        [/fire_event]
    [/event]

    [event]
        name=defender hits
        [filter]
            id=Nar-hamoth
        [/filter]

        [filter_condition]
            {VARIABLE_NUMERICAL_LESS_THAN_OR_EQUAL "unit.hitpoints" "$({_FACTOR} * $unit.max_hitpoints)"}
        [/filter_condition]

        [fire_event]
            name={_DISPATCH_EVENT}
            [primary_unit]
                id=Nar-hamoth
            [/primary_unit]
            [secondary_unit]
                x,y=$x2,$y2
            [/secondary_unit]
        [/fire_event]
    [/event]
#enddef

#define GLAM_NARHAMOTH_REGEN
    [fire_event]
        name=narhamoth heal
    [/fire_event]
#enddef

    {GLAM_NARHAMOTH_HEALTH_THRESHOLD 0.75 "narhamoth round 2"}

    {GLAM_NARHAMOTH_HEALTH_THRESHOLD 0.60 "narhamoth round 3"}

    {GLAM_NARHAMOTH_HEALTH_THRESHOLD 0.50 "narhamoth round 4"}

    {GLAM_NARHAMOTH_HEALTH_THRESHOLD 0.30 "narhamoth flees"}

    [event]
        name=narhamoth round 2

        [message]
            speaker=Nar-hamoth
            message= _ "Ha! Not bad, but I was just warming up! Now, let us see if you can handle THIS!"
        [/message]

        {GLAM_NARHAMOTH_REGEN}

        [object]
            [filter]
                id=Nar-hamoth
            [/filter]

            [effect]
                apply_to=attack
                name=sword
                increase_damage=1
            [/effect]

            [effect]
                apply_to=attack
                name=ethereal blast
                increase_damage=1
            [/effect]
        [/object]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Anya
            scroll=no
            message= _ "Oh, come on! That’s just cheating!"
        [/message]
    [/event]

    [event]
        name=narhamoth round 3

        {GLAM_NARHAMOTH_REGEN}

        [message]
            speaker=Nar-hamoth
            message= _ "You do not tire of combat easily, eh? I’m impressed! Shall we have a third round then?"
        [/message]

        [message]
            speaker=Durvan
            scroll=no
            message= _ "Will you stop doing that, you fiend?!"
        [/message]
    [/event]

    [event]
        name=narhamoth round 4

        [message]
            speaker=Nar-hamoth
            message= _ "Ha! Your strength and resourcefulness have not gone unnoticed by the Guardian of Life! I too can respect an enemy that perseveres against impossible odds, Elynia-Thanadria."
        [/message]

        {GLAM_NARHAMOTH_REGEN}

        [object]
            [filter]
                id=Nar-hamoth
            [/filter]

            [effect]
                apply_to=attack
                name=sword
                increase_damage=1
            [/effect]

            [effect]
                apply_to=attack
                name=ethereal blast
                increase_damage=1
                increase_attacks=1
            [/effect]
        [/object]

        [message]
            speaker=Nar-hamoth
            message= _ "Alas, that stubbornness of yours shall be your and your kind’s undoing!"
        [/message]
    [/event]

    [event]
        name=narhamoth flees

        {GLAM_NARHAMOTH_REGEN}

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Nar-hamoth
            message= _ "Hm. Very impressive, indeed. Despite being such lowly rats, you sure seem to be capable of grand feats when given the right motivation. Ahh, yes, as that hapless bastard Argan found out the hard way. Would that we had not met each other as enemies in a never-ending war, don’t you agree? It is just as unfortunate that my presence is currently required elsewhere..."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Stop him before he escapes!"
        [/message]

        [message]
            speaker=Nar-hamoth
            message= _ "I shall eagerly await the day we meet again!"
        [/message]

        [delay]
            time=250
        [/delay]

        [animate_unit]
            [filter]
                id=Nar-hamoth
            [/filter]
            flag=pre_teleport
            with_bars=yes
        [/animate_unit]

        [kill]
            id=Nar-hamoth
            fire_event=no
            animate=no
        [/kill]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Igor
            message= _ "Come back here, you coward!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "... Fleeing the battlefield seems a conventional tactic for the highest-ranking servants of Uria. Mal Hekuba did so in both of our previous face-to-face encounters as well. I don’t think we ever got a taste of his true might before he decided to fuse his own putrid body with those artifacts."
        [/message]

        [message]
            speaker=Anya
            message= _ "That may have been for the best, though."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Perhaps. Still, I would be grateful if I never had to deal with their limitless arrogance again."
        [/message]

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

    [event]
        name=enemies defeated

        {ENDLEVEL_VICTORY yes}
    [/event]

    [event]
        name=time over
        [message]
            speaker=General Bardyl
            message= _ "This operation was a disastrous mistake. Their shock troops are heading here now, and the faerie’s reinforcements are all but useless. Perhaps if we surrender they’ll at least spare our lives."
        [/message]
    [/event]

    [event]
        name=victory

        # The player may manage to avoid killing Nar-hamoth before the enemy leaders. In this case
        # we want to finish the scenario anyway so he can't get milked excessively, but we need to
        # trigger the flight sequence so his exit is actually acknowledged.

        [if]
            [have_unit]
                id=Nar-hamoth
            [/have_unit]
            [then]
                [fire_event]
                    name=narhamoth flees
                    [primary_unit]
                        id=Nar-hamoth
                    [/primary_unit]
                    [secondary_unit]
                        id=Elynia
                    [/secondary_unit]
                [/fire_event]
            [/then]
        [/if]

        [message]
            speaker=General Bardyl
            message= _ "Well played, faerie. Not only you deliberately misled us about your numbers, but you also omitted the fact that you consort with necromancers. This changes everything."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Not necessarily. Today’s events would indicate that together we can build a formidable opposition force. Is this not what you wanted? An opportunity to retake Aran-Balgur, your former home? Is it not what your men desire as well? Or would you prefer to stay here and defend Astar against an enemy with a plan? Tell me, how many soldiers have deserted since the Glamdrol incident?"
        [/message]

        [message]
            speaker=General Bardyl
            message= _ "I specifically pointed out your deception; I did not say I would retract, and that’s not an option at this point unless I were looking for a mutiny. I’m done speaking to you for now."
        [/message]

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Anya
            message= _ "Elynia, are you sure about this? You did admit before that your judgment might not be—"
        [/message]

        [message]
            speaker=Elynia
            message= _ "I’m not really heeding my judgment anymore, girl. It’s just a hunch I have... I have to return to Kalari and find this Demon Lord of the Storms, if it’s the last thing I do."
        [/message]

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

#undef GLAM_NARHAMOTH_REGEN
#undef GLAM_NARHAMOTH_HEALTH_THRESHOLD