#textdomain wesnoth-After_the_Storm

[scenario]
    id=04_01_Outpost_of_Hell
    name= _ "Outpost of Hell"
    {MAP 04_01_Outpost_of_Hell.map}
    {TURNS 32 29 26}
    next_scenario=04_02_Gateway

    {G_DEATHS}

    {SCENARIO_MUSIC "underground.ogg"} {CONTINUE_PLAYING_STORY_MUSIC_FIRST}

    [event]
        name=reset playlist
        first_time_only=no

        # The actual playlist used in this scenario when
        # not running the start event or fighting the boss.

        {REPLACE_SCENARIO_MUSIC "legends_of_the_north.ogg"}
        {APPEND_MUSIC           "siege_of_laurelmor.ogg"}
        {APPEND_MUSIC           "casualties_of_war.ogg"}
        {APPEND_MUSIC           "the_city_falls.ogg"}
        {APPEND_MUSIC           "battle.ogg"}
    [/event]

#define OOH_RESET_PLAYLIST
    [fire_event]
        name=reset playlist
    [/fire_event]
#enddef

    {STORYTXT_OUTPOST_OF_HELL}

    {LONGDARK4}
    {DAWN1}
    {MORNING1}
    {MIDDAY1}
    {AFTERNOON1}
    {DUSK1}
    {SHORTDARK}
    {DAWN2}
    {MORNING2}
    {MIDDAY2}
    {AFTERNOON2}
    {DUSK2}
    {LONGDARK1}
    {LONGDARK2}
    {LONGDARK3}

    {SHAXTHAL_SET_SURFACE_VARIATIONS_FLAG}

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

        {GOLD 170 160 150}

        # 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 170 160 150}

        # wmllint: recognize General Bardyl
        {CHARACTER_STATS_GENERAL_BARDYL}
        facing=se
    [/side]
    # wmllint: validate-on

    [side]
        side=3
        team_name=evil
        user_team_name= _ "team_name^Aran-Balgur"
        {CHAOS_FLAG}

        {GOLD 160 170 180}
        recruit=Demon,Chaos Hound,Ghost,Chaos Bowman

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

        canrecruit=yes
        facing=nw
        type=Gutwrencher Imp
        id=Harakgros
        name= _ "Harakgros"
        [modifications]
            {TRAIT_SLOW}
            {TRAIT_INTELLIGENT}
        [/modifications]
    [/side]

    [side]
        side=4
        team_name=evil
        user_team_name= _ "team_name^Aran-Balgur"
        {CHAOS_FLAG}

        {GOLD 160 170 180}
        recruit=Young Ogre,Orcish Archer,Orcish Assassin,Saurian Augur

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

        canrecruit=yes
        facing=nw
        type=Chaos Lorekeeper
        id=Mal Arazuul
        name= _ "Mal Arazuul"
        [modifications]
            {TRAIT_INTELLIGENT}
            {TRAIT_RESILIENT}
        [/modifications]
    [/side]

    [side]
        side=5
        team_name=evil
        user_team_name= _ "team_name^Aran-Balgur"
        {CHAOS_FLAG}

        {GOLD 160 170 180}
        recruit=Chaos Gunner,Chaos Invoker,Chaos Invader,Chaos Headhunter

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

        canrecruit=yes
        facing=ne
        type=Demon Warrior
        id=Shergrel
        name= _ "Shergrel"
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_QUICK}
        [/modifications]
    [/side]

    [side]
        side=6
        team_name=evil
        user_team_name= _ "team_name^Aran-Balgur"
        {CHAOS_FLAG}

        {GOLD 190 200 210}
        recruit=Shaxthal Drone,Shaxthal Razorbird,Shaxthal Rayblade,Psy Crawler,Chaos Invader

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

        canrecruit=yes
        facing=nw
        type=Demon Stormtide
        id=Arighaphon
        name= _ "Arighaphon"
        [modifications]
            {TRAIT_QUICK}
            {TRAIT_RESILIENT}
        [/modifications]
    [/side]

    {LIMIT_RECRUITS 6 (Shaxthal Rayblade) ({DIFF 1 2 2})}

    [side]
        side=7
        team_name=evil
        user_team_name= _ "team_name^Aran-Balgur"
        {CHAOS_FLAG}

        {GOLD 190 200 210}
        recruit=Ixthala Fire Dancer,Demon,Chaos Headhunter,Orcish Grunt,Chaos Invoker

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

        canrecruit=yes
        facing=ne
        type=Demon Spelldancer
        gender=female
        id=Kryselgea
        name= _ "Kryselgea"
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_RESILIENT}
        [/modifications]
    [/side]

    {LIMIT_RECRUITS 7 (Ixthala Fire Dancer) ({DIFF 1 2 2})}

    [side]
        side=8
        team_name=evil
        user_team_name= _ "team_name^Aran-Balgur"
        {CHAOS_FLAG}

        {GOLD 180 190 200}
        recruit=Chaos Hound,Valdemon Basher,Blood Imp,Chaos Bowman,Shaxthal Runner Drone

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

        canrecruit=yes
        facing=nw
        type=Chaos Razerman
        id=Meryl Ben
        name= _ "Meryl Ben"
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_SLOW}
        [/modifications]
    [/side]

    {LIMIT_RECRUITS 8 (Valdemon Basher) ({DIFF 1 2 2})}

    [side]
        side=9
        team_name=evil
        user_team_name= _ "team_name^Aran-Balgur"
        {CHAOS_FLAG}

        {GOLD 150 160 170}
        {INCOME 6 8 10}
        recruit=Imp,Blood Imp,Valdemon Basher,Serpent Messenger,Demon Zephyr,Shaxthal Runner Drone,Shaxthal Protector Drone,Chaos Crossbowman,Chaos Bowman,Chaos Raider

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

        canrecruit=yes
        # Placeholder to enable this side to recruit normally
        # until the final boss is revealed along with the
        # associated help entry in an event.
        type=Verlissh Matrix Flow System

        [unit]
            type=Armageddon Imp
            id=Sherol
            name= _ "Sherol"
            x,y=15,27
            facing=nw
            ai_special=guardian
            upkeep=loyal
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_SLOW}
            [/modifications]
        [/unit]

        [unit]
            type=Gutwrencher Imp
            id=Kerberos
            name= _ "Kerberos"
            x,y=17,31
            facing=sw
            ai_special=guardian
            upkeep=loyal
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [unit]
            type=Armageddon Imp
            id=Amyat
            name= _ "Amyat"
            x,y=28,33
            facing=sw
            ai_special=guardian
            upkeep=loyal
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [unit]
            type=Armageddon Imp
            id=Pejlahn
            name= _ "Pejlahn"
            x,y=35,26
            facing=ne
            ai_special=guardian
            upkeep=loyal
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [unit]
            type=Shaxthal War Drone
            x,y=25,20
            facing=n
            ai_special=guardian
            upkeep=loyal
            [modifications]
                {TRAIT_BIOMECHANICAL}
                {TRAIT_ARMORED}
            [/modifications]
        [/unit]

        [unit]
            type=Shaxthal Enforcer Drone
            x,y=19,27
            facing=nw
            ai_special=guardian
            upkeep=loyal
            variation=surface
            [modifications]
                {TRAIT_BIOMECHANICAL}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [unit]
            type=Shaxthal Enforcer Drone
            x,y=32,28
            facing=nw
            ai_special=guardian
            upkeep=loyal
            variation=surface
            [modifications]
                {TRAIT_BIOMECHANICAL}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]
    [/side]

    # NOTE: yes, this limits these recruits as a set, not individually.
    {LIMIT_RECRUITS 9 (Valdemon Basher,Serpent Messenger,Demon Zephyr,Shaxthal Protector Drone) ({DIFF 3 3 4})}

    # Let side 9 recruit only every even turn.

    [event]
        name=side 9 turn
        first_time_only=no
        [filter_condition]
            {VARIABLE_BOOLEAN_EQUALS portal_access_open no}
        [/filter_condition]

        {VARIABLE_OP side_9_turn_test to_variable turn_number}
        {VARIABLE_OP side_9_turn_test modulo      2          }

        [if]
            {VARIABLE_NUMERICAL_NOT_EQUALS side_9_turn_test 0}
            [then]
                [store_side]
                    side=9
                    variable=side_9_state
                [/store_side]

                [modify_side]
                    side=9
                    {NO_INCOME}
                    gold,village_gold=0,0
                [/modify_side]
            [/then]
            [else]
                {BUG_ON ({VARIABLE_NUMERICAL_NOT_EQUALS side_9_state.side 9}) ("Side 9 economy state lost!")}

                [modify_side]
                    side=9
                    income=$side_9_state.income
                    gold=$side_9_state.gold
                    village_gold=$side_9_state.village_gold
                [/modify_side]

                {CLEAR_VARIABLE side_9_state}
            [/else]
        [/if]

        {CLEAR_VARIABLE side_9_turn_test}
    [/event]

    [side]
        side=10
        team_name=evil
        user_team_name= _ "team_name^Aran-Balgur"
        {CHAOS_FLAG}
        color=gold

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

        [unit]
            type=Verlissh Matrix Flow System
            x,y=25,23
            max_hitpoints=500
        [/unit]

        [unit]
            type=Verlissh Matrix Flow System
            x,y=28,24
            max_hitpoints=500
        [/unit]

        [unit]
            type=Verlissh Matrix Flow System
            x,y=28,27
            max_hitpoints=500
        [/unit]

        [unit]
            type=Verlissh Matrix Flow System
            x,y=25,29
            max_hitpoints=500
        [/unit]

        [unit]
            type=Verlissh Matrix Flow System
            x,y=22,27
            max_hitpoints=500
        [/unit]

        [unit]
            type=Verlissh Matrix Flow System
            x,y=22,24
            max_hitpoints=500
        [/unit]
    [/side]

    {FORCE_CHANCE_TO_HIT () (type=Verlissh Matrix Flow System) 0 ()}

    {STARTING_VILLAGES_ALL 9}

    {STARTING_VILLAGES 3 5}
    {STARTING_VILLAGES 4 5}
    {STARTING_VILLAGES 5 5}
    {STARTING_VILLAGES 6 5}
    {STARTING_VILLAGES 7 5}
    {STARTING_VILLAGES 8 5}

    #
    # [tunnel] is horribly broken on Wesnoth 1.10 for AI usage, so
    # we need to emulate some of that functionality by teleporting
    # side 9's recruits away on side 9 turn end. This isn't done
    # on recruit events to avoid an infinite recruitment sequence
    # given enough gold.
    #

#define OOH_RECRUITMENT_PORTAL _ID _SOURCE_X_Y _TARGET_X_Y
    [set_variables]
        name=recruitment_portals
        mode=append
        [value]
            id={_ID}
            [source]
                {_SOURCE_X_Y}
            [/source]
            [target]
                {_TARGET_X_Y}
            [/target]
        [/value]
    [/set_variables]
#enddef

    [event]
        name=side 9 turn end
        first_time_only=no
        [filter_condition]
            {VARIABLE_BOOLEAN_EQUALS portal_access_open no}
        [/filter_condition]

        [foreach]
            array=recruitment_portals
            variable=portal
            [do]
                [if]
                    [have_unit]
                        side=9
                        x=$portal.source.x
                        y=$portal.source.y
                    [/have_unit]
                    [then]
                        [teleport]
                            [filter]
                                x=$portal.source.x
                                y=$portal.source.y
                            [/filter]
                            x=$portal.target.x
                            y=$portal.target.y
                            check_passability=yes
                            animate=yes
                        [/teleport]

                        {LOG_ATS_DBG ("recruit teleported: ($portal.source.x, $portal.source.y) -> ($portal.target.x, $portal.target.y)")}
                    [/then]
                [/if]
            [/do]
        [/foreach]
    [/event]

    [event]
        name=prestart

        # This variable will be used in later scenarios.
        {VARIABLE waited_for_bardyl no}

        {VARIABLE portal_access_open no}

        {VARIABLE beams_remaining 6}

        # wmllint: recognize Anya
        {RECALL_ANYA_AT_LOCATION 57 8}
        # wmllint: recognize Durvan
        {RECALL_DURVAN_AT_LOCATION 53 9}
        # wmllint: recognize Irylean
        {RECALL_IRYLEAN_AT_LOCATION 53 7}
        # wmllint: recognize Igor
        {RECALL_IGOR_AT_LOCATION 59 9}
        # wmllint: recognize Kyara
        {RECALL_KYARA_AT_LOCATION 13 9}
        # wmllint: recognize Horo
        {RECALL_HORO_AT_LOCATION 10 9}

        {RECALL_SIDE_LOYALS 2 ()}

        {FACE_DIRECTION (id=Anya,Durvan,Irylean,Igor) sw}
        {FACE_DIRECTION (side=2) se}

        # Conceal the portal building in shroud.

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

        [remove_shroud]
            side=1,2
            [not]
                x,y=25,26
                radius=2
            [/not]
        [/remove_shroud]

        # Starting player villages.

        [capture_village]
            side=1
            terrain=*^V*
            x=45-62
            y= 1-13
        [/capture_village]

        [capture_village]
            side=2
            terrain=*^V*
            x=1-14
            y=1-8
        [/capture_village]

        # Access portals.

        {OOH_RECRUITMENT_PORTAL  n (x,y=25,25) (x,y=25,22)}

        {OOH_RECRUITMENT_PORTAL ne (x,y=26,25) (x,y=29,24)}

        {OOH_RECRUITMENT_PORTAL se (x,y=26,26) (x,y=29,28)}

        {OOH_RECRUITMENT_PORTAL  s (x,y=25,27) (x,y=25,30)}

        {OOH_RECRUITMENT_PORTAL sw (x,y=24,26) (x,y=21,28)}

        {OOH_RECRUITMENT_PORTAL nw (x,y=24,25) (x,y=21,24)}

        [teleport]
            [filter]
                id=Elynia
            [/filter]
            x,y=58,5
        [/teleport]

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

#define OOH_PRIMARY_OBJECTIVE
    [objective]
        description= _ "Deploy barrels of explosives to destroy the six structures supporting the central keep in Aran-Balgur"+" "+_"($beams_remaining structures remaining)"+""
        condition=win
        [show_if]
            {VARIABLE_NUMERICAL_GREATER_THAN beams_remaining 1}
        [/show_if]
    [/objective]
    [objective]
        description= _"Deploy barrels of explosives to destroy the six structures supporting the central keep in Aran-Balgur"+" "+_"(One structure remaining)"+""
        condition=win
        [show_if]
            {VARIABLE_NUMERICAL_EQUALS beams_remaining 1}
        [/show_if]
    [/objective]
#enddef

#define OOH_BARREL_COUNT_DEFEAT
    [objective]
        description= _ "Running out of barrels of explosives"
        condition=lose
        [show_if]
            {VARIABLE_NUMERICAL_GREATER_THAN beams_remaining 0}
        [/show_if]
    [/objective]
#enddef

    [event]
        name=update player objectives
        first_time_only=no

        {VARIABLE temp_silent_objectives yes}

        [if]
            {VARIABLE_NUMERICAL_GREATER_THAN beams_remaining 0} # after destroying beams
            [or]
                {VARIABLE_NUMERICAL_EQUALS beams_remaining 6} # at the start of the scenario
            [/or]
            [then]
                {VARIABLE temp_silent_objectives no}
            [/then]
        [/if]

        {OBJECTIVES (
            side=1
            silent=$temp_silent_objectives
            {OOH_PRIMARY_OBJECTIVE}
            {OBJECTIVE_VICTORY ( _ "Secure the portal located within the central keep")}
            {OBJECTIVE_BONUS   ( _ "Defeat all enemy leaders"+{EARLY_FINISH_BONUS_FOOTNOTE})}

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

            {OBJECTIVE_CARRYOVER}
        )}

        {OBJECTIVES (
            side=2
            silent=$temp_silent_objectives
            {OOH_PRIMARY_OBJECTIVE}
            {OBJECTIVE_VICTORY ( _ "Secure the portal located within the central keep")}
            {OBJECTIVE_BONUS   ( _ "Defeat all enemy leaders"+{EARLY_FINISH_BONUS_FOOTNOTE})}

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

            {OBJECTIVE_CARRYOVER}
        )}

        {CLEAR_VARIABLE temp_silent_objectives}
    [/event]

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

    #
    # Initial dialog sequence.
    #

    [event]
        name=start

        {LOCK_VIEW}

        {MOVE_UNIT (id=Anya) 55 10}

        [message]
            speaker=Anya
            message= _ "Aran-Balgur is really impressive. How could it fall to Uria’s forces?"
        [/message]

        [message]
            speaker=Durvan
            message= _ "Some people say the lord of the stronghold was brutally killed by the Chaos thugs on the battlefield some time after their Emperor fell. The man left in charge in his place wasn’t very bright, and couldn’t stand a chance when the angry enemy troops arrived. Others say they found the descendant of the architect who helped build its walls a century ago, and forced him to reveal the plans with all the secret passages and weak points."
        [/message]

        [message]
            speaker=Durvan
            message= _ "Regardless of the rumors, the fact is that they killed everyone. See the stains on the exterior walls? Everyone says it’s the blood of the former occupants. Some believe that the General’s family was amongst them."
        [/message]

        [message]
            speaker=Anya
            message= _ "I guess... that explains why he’s such an unpleasant person."
        [/message]

        [unhide_unit]
            id=Elynia
        [/unhide_unit]

        [store_starting_location]
            side=1
        [/store_starting_location]

        {MOVE_UNIT (id=Elynia) ($location.x) ($location.y)}

        {FACE_DIRECTION (id=Elynia) sw}
        {FACE_DIRECTION (id=Anya,Durvan) ne}
        {FACE_DIRECTION (id=Irylean) se}

        [message]
            speaker=Elynia
            message= _ "I hope everyone is ready for the battle ahead of us."
        [/message]

        [message]
            speaker=Irylean
            message= _ "We are, my lady. What are your orders?"
        [/message]

        [message]
            speaker=Elynia
            message= _ "Just assist our allies with the siege and deal with whatever creatures guard the keep and the rumored portal. We ought to make this quick, for the demoness that awaits us at the other end might not be too patient, and this mission has delayed us too much already."
        [/message]

        [message]
            speaker=Anya
            message= _ "You haven’t changed your mind..."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Indeed, I have not."
        [/message]

        [scroll_to]
            x,y=25,26
            check_fogged=no
        [/scroll_to]

        {QUAKE rumble.ogg}

        [delay]
            time=500
        [/delay]

        [sound]
            name=dwarf-laugh.wav
        [/sound]

        {HIGHLIGHT_GOAL (
            [filter]
                side=10
            [/filter]
        )}

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

        {OOH_RESET_PLAYLIST}

        {INCIDENTAL_MUSIC battle-epic.ogg}

        {CLEAR_VARIABLE location}

        {OOH_UPDATE_OBJECTIVES}

        {UNLOCK_VIEW}
    [/event]

    [event]
        name=side 2 turn 1

        [message]
            speaker=General Bardyl
            message= _ "It is time. At last... I’ll have my revenge..."
        [/message]

        [message]
            speaker=Horo
            message= _ "And what about us?"
        [/message]

        [message]
            speaker=General Bardyl
            message= _ "You two shall be allowed to leave once the battle is over — that is, assuming you survive."
        [/message]

        [message]
            speaker=Kyara
            message= _ "What if we lose?"
        [/message]

        [message]
            speaker=General Bardyl
            message= _ "Should it come to that, you’d best hope those fiends will be swift to end your pitiful lives."
        [/message]

        [message]
            speaker=Kyara
            message= _ "That’s truly motivating..."
        [/message]
    [/event]

    [event]
        name=turn 2

        [message]
            speaker=Anya
            message= _ "Durvan, what are you going to do after this is over? You said earlier you had some doubts about Elynia’s plan, and you..."
        [/message]

        [message]
            speaker=Durvan
            message= _ "Yes, I won’t be going with you. Her plan just seems too risky... What the hell is she thinking? Didn’t you say Elorran himself knew his kinsmen couldn’t be trusted? Besides, I won’t be very useful once you arrive there. From what I’ve heard, the natives hate us, and motivating and talking to people is really all I have done ever since I joined Elynia."
        [/message]

        [message]
            speaker=Anya
            message= _ "But..."
        [/message]

        [message]
            speaker=Durvan
            # po: The other human is Erathan from IftU.
            message= _ "You two and the necromancer woman have all those magic abilities and powers I will never have. I’m tired of risking my life fighting alongside you against powerful demons and psychotic cultists. I just... I just want to live a longer life than the other human Elynia got killed in enemy territory, the poor bastard."
        [/message]

        [message]
            speaker=Anya
            message= _ "Heh, yes... But you were really brave in the valley..."
        [/message]

        [message]
            speaker=Durvan
            message= _ "I was really stupid! I hadn’t heard of that guy and his fate yet!"
        [/message]
    [/event]

    [event]
        name=side 1 turn 2 end

        [message]
            speaker=Anya
            scroll=no
            message= _ "I still think I will miss you... even if you only rarely start a conversation! And I’m sure Elynia will miss you as well."
        [/message]

        [message]
            speaker=Durvan
            scroll=no
            message= _ "Sure..."
        [/message]
    [/event]

    [event]
        name=side 2 turn 2 end
        [message]
            speaker=Durvan
            scroll=no
            message= _ "I wish you two all the luck in the world. You’ll surely need it."
        [/message]
    [/event]

    [event]
        name=side 1 turn 4 end
        [filter_condition]
            [have_unit]
                type=Wolf Rider,Goblin Knight,Goblin Pillager,Direwolf Rider
                side=1,2
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=Durvan
            message= _ "I want this to be over as soon as possible so I can bid farewell to the giant wolves."
        [/message]

        [message]
            speaker=Anya
            message= _ "Why? They are so cute!"
        [/message]

        [message]
            speaker=Durvan
            message= _ "Nope, they’re terrifying. And they smell."
        [/message]

        [if]
            [have_unit]
                id=Igor
            [/have_unit]
            [then]
                [message]
                    speaker=Anya
                    message= _ "What about Willow? She’s so fluffy and cuddly and..."
                [/message]

                [message]
                    speaker=Durvan
                    message= _ "I really don’t like her. She follows me around as though she knows I am terrified of her."
                [/message]

                [message]
                    speaker=Anya
                    message= _ "Awwww, but she just wants to be your friend! You should give her a chance!"
                [/message]

                [message]
                    speaker=Durvan
                    message= _ "(sighs) I don’t think this is the right time and place to practice shock therapy, Anya. Maybe when things have calmed down a little."
                [/message]
            [/then]
        [/if]
    [/event]

    {RING_OF_AGILITY 46 19}

    #
    # It's not currently possible to include auxiliary events for
    # dummy abilities in [effect]s, so we need to include the event
    # code once in the scenario first, and only provide the dummy
    # ability's text later.
    #

    {ABILITY_DEMOLITION_EVENTS}

#define OOH_CHARGE_ITEM
    image=items/barrel.png
#enddef

#define OOH_CHARGE_ITEM_ACTIVE
    image=items/barrel.png~CS(64,64,64)
#enddef

    #
    # Used when placing a charge, either at the start of the scenario or
    # when dropping/deploying charges during gameplay. Takes care of pushing
    # its state into the charges table.
    #
    #     _X, _Y:  Coordinates of the charge object so it can be picked
    #              up by another unit if not activated.
    #     _ACTIVE: Whether the charge is activated (boolean, "yes" or "no").
    #              Inactive charges can be picked up again.
    #
#define OOH_CHARGE_PLACE _X _Y _ACTIVE
    [set_variables]
        name=siege_charges
        mode=append
        [value]
            x={_X}
            y={_Y}
            active={_ACTIVE}
        [/value]
    [/set_variables]

    [if]
        {VARIABLE_BOOLEAN_EQUALS "siege_charges[$($siege_charges.length - 1)].active" yes}
        [then]
            [item]
                x={_X}
                y={_Y}
                {OOH_CHARGE_ITEM_ACTIVE}
            [/item]
        [/then]
        [else]
            [item]
                x={_X}
                y={_Y}
                {OOH_CHARGE_ITEM}
            [/item]
        [/else]
    [/if]
#enddef

#define OOH_PAYLOAD_OVERLAY
    image=misc/payload-icon.png
#enddef

    #
    # Used when a unit picks up a charge. The unit receives the Demolition
    # ability, so it can leave with a bang in the worst case. Picked up
    # charges are removed from the charges table.
    #
    #     _X, _Y: Coordinates of the charge object.
    #
#define OOH_CHARGE_PICK _X _Y
    [remove_item]
        x={_X}
        y={_Y}
        {OOH_CHARGE_ITEM}
    [/remove_item]

    [remove_item]
        x={_X}
        y={_Y}
        {OOH_CHARGE_ITEM_ACTIVE}
    [/remove_item]

    # Remove current charge from the table.

    {VARIABLE charge_pos 0}
    {VARIABLE continue_lookup yes}

    [while]
        {VARIABLE_NUMERICAL_LESS_THAN charge_pos $siege_charges.length}
        {VARIABLE_BOOLEAN_EQUALS continue_lookup yes}
        [do]
            [if]
                {VARIABLE_NUMERICAL_EQUALS siege_charges[$charge_pos].x ({_X})}
                {VARIABLE_NUMERICAL_EQUALS siege_charges[$charge_pos].y ({_Y})}
                [then]
                    {VARIABLE continue_lookup no}
                [/then]
                [else]
                    {VARIABLE_INC charge_pos}
                [/else]
            [/if]
        [/do]
    [/while]

    {CLEAR_VARIABLE continue_lookup}

    {BUG_ON ({VARIABLE_NUMERICAL_EQUALS charge_pos $siege_charges.length}) ("Could not find charge at ("+{_X}+", "+{_Y}+") in the charges table.")}

    {CLEAR_VARIABLE siege_charges[$charge_pos]}

    {CLEAR_VARIABLE charge_pos}

    [unit_overlay]
        x={_X}
        y={_Y}
        {OOH_PAYLOAD_OVERLAY}
    [/unit_overlay]

    {VARIABLE_INC payload_ability_id}

    [object]
        silent=yes
        # Ensure the id is always unique.
        id=payload_effect_set_$payload_ability_id
        duration=scenario
        [filter]
            x={_X}
            y={_Y}
        [/filter]
        [effect]
            apply_to=new_ability
            [abilities]
                {ABILITY_DEMOLITION_TEXT_ONLY}
            [/abilities]
        [/effect]
    [/object]

    [store_unit]
        [filter]
            x={_X}
            y={_Y}
        [/filter]
        variable=charge_unit_store
    [/store_unit]

    {VARIABLE charge_unit_store.variables.has_charge yes}

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

    {CLEAR_VARIABLE charge_unit_store}
#enddef

    #
    # Removes a unit's Demolition ability and its siege charge flag.
    #
#define OOH_REMOVE_UNITS_CHARGE _SUF
    [remove_unit_overlay]
        {_SUF}
        {OOH_PAYLOAD_OVERLAY}
    [/remove_unit_overlay]

    [store_unit]
        [filter]
            {_SUF}
        [/filter]
        variable=charge_units_store
    [/store_unit]

    [foreach]
        array=charge_units_store
        variable=charge_unit
        [do]
            [for]
                array=charge_units_store.abilities.dummy
                reverse=yes
                [do]
                    [if]
                        {VARIABLE_LEXICAL_EQUALS charge_unit.abilities.dummy[$i].id "demolition"}
                        [then]
                            {CLEAR_VARIABLE charge_unit.abilities.dummy[$i]}
                        [/then]
                    [/if]
                [/do]
            [/for]

            [for]
                array=charge_units_store.modifications.object
                reverse=yes
                [do]
                    [if]
                        {VARIABLE_LEXICAL_CONTAINS charge_unit.modifications.object[$i].id "payload_effect_set_"}
                        [then]
                            {CLEAR_VARIABLE charge_unit.modifications.object[$i]}
                        [/then]
                    [/if]
                [/do]
            [/for]

            {CLEAR_VARIABLE charge_unit.variables.has_charge}

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

    {CLEAR_VARIABLE charge_units_store}
#enddef

    #
    # Used when a unit drops the charge it is carrying. The unit loses its
    # Demolition ability, and the charge is inserted in the charges
    # table again.
    #
    #     _X, _Y: Coordinates of the unit and resultant charge object.
    #
#define OOH_CHARGE_DEPLOY _X _Y _ACTIVE
    # Remove the unit's payload icon overlay and the Demolition ability.

    {OOH_REMOVE_UNITS_CHARGE (
        x={_X}
        y={_Y}
    )}

    # Place the item and update the charge table.

    {OOH_CHARGE_PLACE ({_X}) ({_Y}) ({_ACTIVE})}
#enddef

    #
    # Auxiliary events for siege charges-related menu items.
    #

    [event]
        name=wme_siege_charge_help
        first_time_only=no

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            caption= _ "Help: Using Charges"
            message= _ "In this scenario, most units under your control can carry barrels of explosives, which can be used to destroy structures and other units.

To get a barrel, move a unit over it. You will be given the choice to grab the barrel or leave it for another unit. Once a unit gets the barrel, it will gain the Demolition ability, allowing it to destroy everything within a one-hex radius upon death. The unit will also be able to drop the barrel for another unit to pick it up, or deploy an activated charge. Once a barrel is deployed, it will destroy everything within a one-hex radius at the start of the next first-player turn, so you want to make sure your unit has enough movement points left to get away before deploying.

Units lose the Demolition ability after dropping or deploying barrels.

Use these barrels wisely! You start with a limited number, and you need at least six to complete the main objective!"
        [/message]
    [/event]

    [event]
        name=wme_siege_charge_drop
        first_time_only=no

        {OOH_CHARGE_DEPLOY $x1 $y1 no}
    [/event]

    [event]
        name=wme_siege_charge_deploy
        first_time_only=no

        {VARIABLE temp_location_is_suitable no}

        [if]
            [have_unit]
                x,y=$x1,$y1
                [filter_location]
                    find_in=charge_forbidden_locs
                [/filter_location]
            [/have_unit]
            [then]
                [message]
                    speaker=narrator
                    image=wesnoth-icon.png
                    message= _ "Deploying these explosives so close to your encampment would be an incredibly ill-advised idea!"
                [/message]
            [/then]
            [else]
                [if]
                    [have_unit]
                        x,y=$x1,$y1
                        [filter_location]
                            find_in=charge_immune_locs
                            [or]
                                find_in=siege_charges
                            [/or]
                            [or]
                                [filter_adjacent_location]
                                    find_in=siege_charges
                                [/filter_adjacent_location]
                            [/or]
                        [/filter_location]
                    [/have_unit]
                    [then]
                        [message]
                            speaker=narrator
                            image=wesnoth-icon.png
                            message= _ "That is not an appropriate location for deploying these explosives. Try elsewhere."
                        [/message]
                    [/then]
                    [else]
                        {VARIABLE temp_location_is_suitable yes}
                    [/else]
                [/if]
            [/else]
        [/if]

        [if]
            {VARIABLE_BOOLEAN_EQUALS temp_location_is_suitable yes}
            [then]
                {OOH_CHARGE_DEPLOY $x1 $y1 yes}
            [/then]
            [else]
                [allow_undo][/allow_undo]
            [/else]
        [/if]

        {CLEAR_VARIABLE temp_location_is_suitable}
    [/event]

    #
    # Initial siege charges, and other charge-related configuration.
    #

    [event]
        name=prestart

        {VARIABLE payload_ability_id 0}

        {VARIABLE charge_usage_hint_shown no}

        # Forbid deploying charges if their effect
        # area overlaps the player's starting keeps.

        [store_locations]
            [filter]
                side=1
                canrecruit=yes
            [/filter]
            radius=1
            [or]
                [filter]
                    side=2
                    canrecruit=yes
                [/filter]
                radius=1
            [/or]
            variable=charge_forbidden_locs
        [/store_locations]

        # The goal building cannot be completely
        # destroyed by deployed charges.

        [store_locations]
            terrain=X*,X*^*,*^X*
            [not]
                [filter]
                    side=10
                [/filter]
            [/not]
            variable=charge_immune_locs
        [/store_locations]

        [set_menu_item]
            id=wmi_siege_charge_help
            description= _ "Help: Using Charges"
            image="icons/menu-book.png"
            [show_if]
                {VARIABLE_BOOLEAN_NOT_EQUALS portal_access_open yes}
            [/show_if]
            [command]
                [fire_event]
                    name=wme_siege_charge_help
                [/fire_event]
            [/command]
        [/set_menu_item]

        [set_menu_item]
            id=wmi_siege_charge_deploy
            description= _ "Deploy Charge"
            image="icons/menu-bomb.png"
            [show_if]
                [have_unit]
                    x,y=$x1,$y1
                    side=$side_number
                    [filter_wml]
                        [variables]
                            has_charge=yes
                        [/variables]
                    [/filter_wml]
                [/have_unit]
            [/show_if]
            [command]
                [fire_event]
                    name=wme_siege_charge_deploy
                    [primary_unit]
                        x,y=$x1,$y1
                    [/primary_unit]
                [/fire_event]
            [/command]
        [/set_menu_item]

        [set_menu_item]
            id=wmi_siege_charge_drop
            description= _ "Drop Charge"
            image="icons/menu-barrel.png"
            [show_if]
                [have_unit]
                    x,y=$x1,$y1
                    side=$side_number
                    [filter_wml]
                        [variables]
                            has_charge=yes
                        [/variables]
                    [/filter_wml]
                [/have_unit]
            [/show_if]
            [command]
                [fire_event]
                    name=wme_siege_charge_drop
                    [primary_unit]
                        x,y=$x1,$y1
                    [/primary_unit]
                [/fire_event]
            [/command]
        [/set_menu_item]

        # Bardyl's encampment.

        {OOH_CHARGE_PLACE  5  3 no}
        {OOH_CHARGE_PLACE  8  2 no}
        {OOH_CHARGE_PLACE  5  6 no}
        {OOH_CHARGE_PLACE 14  4 no}
        {OOH_CHARGE_PLACE 13  1 no}

        # Elynia's encampment.

        {OOH_CHARGE_PLACE 53  4 no}
        {OOH_CHARGE_PLACE 51  7 no}
        {OOH_CHARGE_PLACE 57 10 no}
        {OOH_CHARGE_PLACE 60  6 no}

        # Aran-Balgur.

#ifdef EASY
        {OOH_CHARGE_PLACE 36 33 no}
        {OOH_CHARGE_PLACE 13 28 no}
#endif
#ifndef HARD
        {OOH_CHARGE_PLACE 37 33 no}
        {OOH_CHARGE_PLACE 13 27 no}
#endif
    [/event]

    #
    # Also show help once at the start of the scenario.
    #

    [event]
        name=start
        [scroll_to_unit]
            id=Elynia
        [/scroll_to_unit]

        [fire_event]
            name=wme_siege_charge_help
        [/fire_event]
    [/event]

    #
    # Charge pick-up handler.
    #

    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            [or]
                side=2
            [/or]
            [not]
                [filter_wml]
                    [variables]
                        has_charge=yes
                    [/variables]
                [/filter_wml]
            [/not]
            [and]
                [filter_location]
                    find_in=siege_charges
                [/filter_location]
            [/and]
        [/filter]

        {VARIABLE unit_can_carry_payload yes}

        [if]
            [have_unit]
                x,y=$x1,$y1
                id=Elynia,Anya,Durvan,Irylean,General Bardyl,Kyara,Horo,Igor
            [/have_unit]
            [then]
                {VARIABLE unit_can_carry_payload no}

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

                # The message shown is stored in a variable according to the following
                # logic so I don't have to keep increasing the indentation level towards
                # unreadability. -- shadowm

                [switch]
                    variable=unit.id
                    [case]
                        value=Elynia
                        # po: This message is used when the unit attempting to pick up the barrel
                        # po: is Elynia.
                        {VARIABLE unit_message (_"elynia^You silently consider the possibility of rushing into the battlefield carrying this heavy barrel of explosives all by yourself. You wonder whether your comrades would regard your action as heroic or foolish.

The thought of leaving this world with yet another explosion is inviting at this point, but you have been through that in three different occasions already, and survived to get this far. What would the point be? Perhaps Anya is right, and there is still much more left to do before your time comes. You want to find that demoness in the Pass of Sorrows first, after all.")}
                    [/case]
                    [case]
                        value=Anya
                        # po: This message is used when the unit attempting to pick up the barrel
                        # po: is Anya.
                        {VARIABLE unit_message (_"anya^You silently consider the possibility of rushing into the battlefield carrying this heavy barrel of explosives all by yourself. You wonder whether your comrades would regard your action as heroic or foolish.

That sure was a silly thought to entertain! But your hope has not waned just yet, and Elynia needs your help. You are determined to stay at her side until it is all over. She is all you have left, and perhaps more than you will ever have.")}
                    [/case]
                    [case]
                        value=Kyara
                        # po: This message is used when the unit attempting to pick up the barrel
                        # po: is Kyara.
                        {VARIABLE unit_message (_"kyara^You silently consider the possibility of rushing into the battlefield carrying this heavy barrel of explosives all by yourself. You wonder whether your comrades would regard your action as heroic or foolish.

That pointless exercise of thought promptly leaves way for recalling the stories of your people’s arrival to Quenoth Isle. Many say they were assisted in their journey by dwarves, underground dwellers with an inclination to devise this kind of evil artifact. You decide it may be for the best that a civilization with such destructive potential confined itself to the caverns beneath the surface.")}
                    [/case]
                    [case]
                        value=Durvan
                        # po: This message is used when the unit attempting to pick up the barrel
                        # po: is Durvan.
                        {VARIABLE unit_message (_"durvan^You silently consider the possibility of rushing into the battlefield carrying this heavy barrel of explosives all by yourself. You wonder whether your comrades would regard your action as heroic or foolish.

But you would not be caught dead carrying such dangerous materials. As everyone knows, your craft is hunting prey; you ain’t anybody’s transport man.")}
                    [/case]
                    [case]
                        value=Igor
                        # po: This message is used when the unit attempting to pick up the barrel
                        # po: is Igor.
                        {VARIABLE unit_message (_"igor^You silently consider the possibility of rushing into the battlefield carrying this heavy barrel of “boom” artifacts all by yourself. You wonder whether Elynia and her new friends would regard your action as heroic or foolish.

Upon further thought, however, you realize that giving up on the peaceful street perform life to become fireworks goblin is probably not quite what people mean when they talk about “going out with a bang”. Not to mention you could not possibly bring yourself to leaving poor Willow alone in this nasty, cruel world. Perhaps you will look into procuring a safer source of “boom” at a later time, you think to yourself — something like one of those fire sticks that high-ranked Chaos officers carry around these days. Your mighty steed gives you an approving nod.")}
                    [/case]
                    [case]
                        value=General Bardyl
                        # po: This message is used when the unit attempting to pick up the barrel
                        # po: is the General Bardyl.
                        {VARIABLE unit_message (_"bardyl^You contemplate one of the barrels of explosives your superiors sent from Fort Rylgur before the Far North fell to those infernal bastards. You feel glad that you are not one of the poor nameless soldiers who were charged with the task of carrying these to Aran-Balgur’s main keep!")}
                    [/case]
                    [else]
                        [if]
                            {VARIABLE_LEXICAL_EQUALS unit.gender female}
                            [then]
                                # po: This message is used when the unit attempting to pick up a barrel
                                # po: is one of the other female heroines.
                                {VARIABLE unit_message (_"female^You silently consider the possibility of rushing into the battlefield carrying this heavy barrel of explosives all by yourself. You wonder whether your comrades would regard your actions as heroic or foolish.

In any case, you are not so stupid as to attempt such a pointless move now.")}
                            [/then]
                            [else]
                                # po: This message is used when the unit attempting to pick up a barrel
                                # po: is one of the other male heroes.
                                {VARIABLE unit_message (_"You silently consider the possibility of rushing into the battlefield carrying this heavy barrel of explosives all by yourself. You wonder whether your comrades would regard your actions as heroic or foolish.

In any case, you are not so stupid as to attempt such a pointless move now.")}
                            [/else]
                        [/if]
                    [/else]
                [/switch]

                [message]
                    speaker=narrator
                    image=$unit_portrait
                    message=$unit_message
                [/message]

                {CLEAR_VARIABLE unit_message,unit_portrait}

                [allow_undo][/allow_undo]
            [/then]
            [else]
                [if]
                    [have_unit]
                        x,y=$x1,$y1
                        [not]
                            race=human
                        [/not]
                        [not]
                            race=elf
                        [/not]
                        [not]
                            race=orc
                        [/not]
                        [not]
                            race=aragwaith
                        [/not]
                        [not]
                            race=faerie
                        [/not]
                        [not]
                            type=Skeleton,Skeleton Archer,Revenant,Draug,Deathblade,Bone Shooter,Banebow,Aragwaith Scout,Aragwaith Lancer,Aragwaith Silver Shield,Elvish Scout,Elvish Rider,Elvish Outrider,Aragwaith Eagle Rider,Aragwaith Eagle Master,Wolf Rider,Goblin Knight,Goblin Pillager,Direwolf Rider
                        [/not]
                    [/have_unit]
                    [then]
                        {VARIABLE unit_can_carry_payload no}

                        [message]
                            speaker=narrator
                            image=wesnoth-icon.png # keeps wmllint happy, the fucking POS
                            {OOH_CHARGE_ITEM}
                            message= _ "The unit you have chosen for this task is not able to lift the weight! Try with another unit."
                        [/message]

                        [allow_undo][/allow_undo]
                    [/then]
                [/if]
            [/else]
        [/if]

        [message]
            [show_if]
                {VARIABLE_BOOLEAN_EQUALS unit_can_carry_payload yes}
            [/show_if]
            speaker=narrator
            {OOH_CHARGE_ITEM}
            message= _ "Should this unit carry the barrel of explosives?"
            [option]
                label= _ "Yes, pick up the barrel."
                [command]
                    {OOH_CHARGE_PICK $x1 $y1}

                    [message]
                        [show_if]
                            {VARIABLE_BOOLEAN_EQUALS charge_usage_hint_shown no}
                        [/show_if]
                        speaker=narrator
                        image="wesnoth-icon.png"
                        message= _ "To drop or deploy the charge, right-click on the unit and choose the desired option from the context menu."
                    [/message]

                    {VARIABLE charge_usage_hint_shown yes}
                [/command]
            [/option]
            [option]
                label= _ "No, let someone else do it."
                [command]
                    [allow_undo][/allow_undo]
                [/command]
            [/option]
        [/message]

        {CLEAR_VARIABLE unit_can_carry_payload}
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            [or]
                side=2
            [/or]
            [and]
                [filter_wml]
                    [variables]
                        has_charge=yes
                    [/variables]
                [/filter_wml]
                [filter_location]
                    find_in=siege_charges
                [/filter_location]
            [/and]
        [/filter]

        [message]
            speaker=narrator
            image="wesnoth-icon.png"
            message= _ "You cannot carry more than one barrel at once!"
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    #
    # Activated charges handler.
    #

#define OOH_KEEP_SLF
    find_in=charge_immune_locs
#enddef

    [event]
        name=new turn
        first_time_only=no

        {VARIABLE activated_charge_message_used no}

        [for]
            array=siege_charges
            variable=k
            reverse=yes
            [do]
                [if]
                    {VARIABLE_BOOLEAN_EQUALS siege_charges[$k].active no}
                    [then]
                        [continue][/continue]
                    [/then]
                [/if]

                [scroll_to]
                    x,y=$siege_charges[$k].x,$siege_charges[$k].y
                [/scroll_to]

                {RANDOM 1,2}

                [message]
                    side=$random
                    race=human,orc,wolf,goblin,faerie,elf
                    message= _ "Fire in the hole!"
                    scroll=no
                    [show_if]
                        {VARIABLE_BOOLEAN_EQUALS activated_charge_message_used no}
                    [/show_if]
                [/message]

                {VARIABLE activated_charge_message_used yes}

                {CLEAR_VARIABLE random}

                # Blow some shit up.

                [remove_item]
                    x,y=$siege_charges[$k].x,$siege_charges[$k].y
                    {OOH_CHARGE_ITEM}
                [/remove_item]

                [remove_item]
                    x,y=$siege_charges[$k].x,$siege_charges[$k].y
                    {OOH_CHARGE_ITEM_ACTIVE}
                [/remove_item]

                # The demolition code event may trigger the boss event,
                # which clears the siege charges table. We need to pass
                # a copy of the siege charge location to that event to
                # avoid spamming the log with invalid variable access
                # warnings and potentially do something stupid; and then,
                # we must abort this loop.

                {VARIABLE demolition_target_x $siege_charges[$k].x}
                {VARIABLE demolition_target_y $siege_charges[$k].y}

                # Do not allow terraforming to extend into the location set
                # stored in charge_immune_locs.
                {ABILITY_DEMOLITION_AUXILIARY_EVENT_DESTRUCTION_IMPLEMENTATION $demolition_target_x $demolition_target_y EXCLUDE_SLF={OOH_KEEP_SLF} HANDLE_AS_UNIT_ATTACK=no}

                {CLEAR_VARIABLE demolition_target_x,demolition_target_y}

                [if]
                    {VARIABLE_BOOLEAN_EQUALS portal_access_open yes}
                    [then]
                        # Abort.
                        [break][/break]
                    [/then]
                    [else]
                        # Continue, removing this charge from the table forever.
                        {CLEAR_VARIABLE siege_charges[$k]}
                    [/else]
                [/if]
            [/do]
        [/for]

        {CLEAR_VARIABLE activated_charge_message_used}

        # Check whether there are still enough barrels around to win.

        [fire_event]
            name=check barrel count
        [/fire_event]
    [/event]

    #
    # Terraform the siege targets manually.
    #
    [event]
        name=last breath
        first_time_only=no
        [filter]
            side=10
            type=Verlissh Matrix Flow System
        [/filter]

        [terrain]
            x,y=$x1,$y1
            terrain=Re^Es
        [/terrain]

        [redraw][/redraw]
    [/event]

    #
    # Handling defeat by losing barrels.
    #
    [event]
        name=die
        first_time_only=no
        [filter]
            [filter_wml]
                [variables]
                    has_charge=yes
                [/variables]
            [/filter_wml]
        [/filter]

        [fire_event]
            name=check barrel count
        [/fire_event]
    [/event]

    [event]
        name=check barrel count
        first_time_only=no
        [filter_condition]
            # Skip this rather expensive check when the boss is
            # active on the map.
            {VARIABLE_BOOLEAN_EQUALS portal_access_open no}
        [/filter_condition]

        #
        # Count charges currently acquired by units.
        #

        [count_units]
            [filter_wml]
                [variables]
                    has_charge=yes
                [/variables]
            [/filter_wml]
            [not]
                x,y=$x1,$y1
            [/not]
            variable=available_charges_count
        [/count_units]

        #
        # Count inactive charges, plus charges that are active and adjacent
        # to the mission targets.
        #

        [foreach]
            array=siege_charges
            variable=siege_charge
            [do]
                [if]
                    {VARIABLE_BOOLEAN_EQUALS siege_charge.active no}
                    [then]
                        {VARIABLE_INC available_charges_count}
                    [/then]
                    [elseif]
                        [have_unit]
                            side=10
                            [filter_location]
                                [filter_adjacent_location]
                                    x,y=$siege_charge.x,$siege_charge.y
                                [/filter_adjacent_location]
                            [/filter_location]
                        [/have_unit]
                        [then]
                            {VARIABLE_INC available_charges_count}
                        [/then]
                    [/elseif]
                [/if]
            [/do]
        [/foreach]

        [if]
            {VARIABLE_NUMERICAL_LESS_THAN available_charges_count $beams_remaining}
            [then]
                [message]
                    speaker=General Bardyl
                    message= _ "Blast it, we have wasted our explosives on the battlefield instead of saving them for the main keep! We can’t continue like this — retreat!"
                [/message]

                {ENDLEVEL_DEFEAT}
            [/then]
        [/if]

        {CLEAR_VARIABLE available_charges_count}
    [/event]

    #
    # Cleanup on exit.
    #

    [event]
        name=victory

        {REMOVE_MENU_ITEM wmi_siege_charge_deploy}
        {REMOVE_MENU_ITEM wmi_siege_charge_drop}
        {REMOVE_MENU_ITEM wmi_siege_charge_help}

        {CLEAR_VARIABLE siege_charges,charge_usage_hint_shown,charge_forbidden_locs,charge_immune_locs,payload_ability_id}
    [/event]

    #
    # Boss events.
    #

    [event]
        name=die
        first_time_only=no
        [filter]
            side=10
        [/filter]

        {VARIABLE_DEC beams_remaining}

        {OOH_UPDATE_OBJECTIVES}

        [fire_event]
            name=check remaining beams
        [/fire_event]
    [/event]

    [event]
        name=check remaining beams
        [filter_condition]
            {VARIABLE_NUMERICAL_LESS_THAN beams_remaining 1}
        [/filter_condition]

        {LOCK_VIEW}

        {VARIABLE portal_access_open yes}

        [store_starting_location]
            side=9
            variable=boss_location
        [/store_starting_location]

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

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

        #
        # Remove charges from remaining units and get rid
        # of the barrels.
        #
        # This is necessary to prevent the player using them
        # to insta-kill the boss unit.
        #

        {OOH_REMOVE_UNITS_CHARGE (
            side=1,2
            [filter_wml]
                [variables]
                    has_charge=yes
                [/variables]
            [/filter_wml]
        )}

        [foreach]
            array=siege_charges
            variable=siege_charge
            [do]
                [remove_item]
                    x=$siege_charge.x
                    y=$siege_charge.y
                    {OOH_CHARGE_ITEM}
                [/remove_item]

                [remove_item]
                    x=$siege_charge.x
                    y=$siege_charge.y
                    {OOH_CHARGE_ITEM_ACTIVE}
                [/remove_item]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE siege_charges}

        {QUAKE ({SOUND_LIST:COLLAPSING_FACILITY})}

        [hide_unit][/hide_unit]

        {WHITE_SCREEN}

        #
        # Place the real boss unit.
        #

        [kill]
            side=9
            canrecruit=yes
        [/kill]

        [hidden_unit]
            canrecruit=yes
            side=9
            # wmllint: recognize Portal Custodian
            id=Portal Custodian
            type=Shaxthal Custodian Drone
            {IS_BOSS}
            x,y=$boss_location.x,$boss_location.y
            [modifications]
                {TRAIT_BIOMECHANICAL}
                {TRAIT_INTELLIGENT}
                {BOSS_BOOST 25% 0 0 0 0}
            [/modifications]
        [/hidden_unit]

        #
        # Give it some gold.
        #

        [gold]
            side=9
            {QUANTITY amount 80 90 100}
        [/gold]

        #
        # Open the portal access.
        #

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

        [redraw][/redraw]

        [delay]
            time=750
        [/delay]

        {RESET_SCREEN}

        [unhide_unit][/unhide_unit]

        [redraw][/redraw]

        {BOSS_AMBIENTANCE_LOOPING}

        {QUAKE ({SOUND_LIST:EXPLOSION})}

        [scroll_to_unit]
            id=Portal Custodian
        [/scroll_to_unit]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=General Bardyl
            scroll=no
            message= _ "Destroy that enormous monster before it gets a chance to rain its fire upon our troops!"
        [/message]

        {HIGHLIGHT_GOAL (x,y=$boss_location.x,$boss_location.y)}

        [if]
            {VARIABLE_NUMERICAL_EQUALS side_9_state.side 9}
            [then]
                #
                # Restore side 9's state and let it recruit normally
                # until it's defeated. If the state is missing (the
                # test above fails), that means its state was already
                # restored by the cyclic turn event.
                #

                [modify_side]
                    side=9
                    income=$side_9_state.income
                    gold=$side_9_state.gold
                    village_gold=$side_9_state.village_gold
                [/modify_side]

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

        {CLEAR_VARIABLE boss_location}

        {UNLOCK_VIEW}
    [/event]

    [event]
        name=victory

        {CLEAR_VARIABLE portal_access_open,recruitment_portals,beams_remaining}
    [/event]

    #
    # Shapeshifters stuff.
    #

    [event]
        name=prestart

        {VARIABLE shapeshifter_count 0}
    [/event]

    [event]
        name=victory

        {CLEAR_VARIABLE shapeshifter_count}
    [/event]

#define OOH_SHAPESHIFTER_ELIGIBLE_UNITS
    type=Chaos Invader,Chaos Raider
    [not]
        [filter_wml]
            [variables]
                is_shapeshifter=yes
            [/variables]
        [/filter_wml]
    [/not]
#enddef

    [event]
        name=prerecruit
        first_time_only=no
        [filter]
            {OOH_SHAPESHIFTER_ELIGIBLE_UNITS}
        [/filter]
        [filter_condition]
            {VARIABLE_NUMERICAL_GREATER_THAN shapeshifter_count 0}
        [/filter_condition]

        {VARIABLE_RANDOM shapeshifter_flag 1..9001}
        # Easier difficulties have smaller chances of getting
        # shapeshifters, probably.
        {VARIABLE_MOD shapeshifter_flag ({DIFF 5 3 2})}

        # Don't allow more than a certain amount of shapeshifters
        # to exist on map at the same time.
        [count_units]
            type=Demon Shapeshifter
            [or]
                [filter_wml]
                    [variables]
                        is_shapeshifter=yes
                    [/variables]
                [/filter_wml]
            [/or]
            variable=shapeshifter_onmap_count
        [/count_units]

        [if]
            {VARIABLE_NUMERICAL_EQUALS shapeshifter_flag 0}
            {VARIABLE_NUMERICAL_LESS_THAN shapeshifter_onmap_count ({DIFF 2 4 6})}
            [then]
                [fire_event]
                    name=turn shapeshifter
                    [primary_unit]
                        x,y=$x1,$y1
                    [/primary_unit]
                [/fire_event]
            [/then]
        [/if]

        {CLEAR_VARIABLE shapeshifter_flag,shapeshifter_onmap_count}
    [/event]

    [event]
        name=prerecruit
        [filter]
            {OOH_SHAPESHIFTER_ELIGIBLE_UNITS}
        [/filter]

        # Ensure there's always at least one
        # Shapeshifter spawned per scenario!

        [fire_event]
            name=turn shapeshifter
            [primary_unit]
                x,y=$x1,$y1
            [/primary_unit]
        [/fire_event]
    [/event]

    # Event for turning a recruited unit into a
    # disguised shapeshifter.

    [event]
        name=turn shapeshifter
        first_time_only=no

        {VARIABLE unit.variables.is_shapeshifter yes}

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

        [object]
            silent=yes
            [filter]
                x,y=$x1,$y1
            [/filter]
            [effect]
                apply_to=image_mod
                add="CS(16,0,16)" # Add a little purpleish tint.
            [/effect]
        [/object]

        {VARIABLE_INC shapeshifter_count}
    [/event]

    # Handle death of disguised shapeshifters.
    [event]
        name=die
        first_time_only=no
        [filter]
            [filter_wml]
                [variables]
                    is_shapeshifter=yes
                [/variables]
            [/filter_wml]
        [/filter]

        [fire_event]
            name=reveal shapeshifter
            [primary_unit]
                x,y=$x1,$y1
            [/primary_unit]
        [/fire_event]
    [/event]

    # Event for revealing a disguised shapeshifter.

    [event]
        name=reveal shapeshifter
        first_time_only=no

        [set_variable]
            name=shapeshifter_previous_side
            to_variable=unit.side
        [/set_variable]

        [set_variable]
            name=shapeshifter_previous_facing
            to_variable=unit.facing
        [/set_variable]

        [set_variables]
            name=shapeshifter_previous_traits
            mode=replace
            to_variable=unit.modifications.trait
        [/set_variables]

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

        [unit]
            animate=yes
            moves=0
            attacks_left=0
            side=$shapeshifter_previous_side
            facing=$shapeshifter_previous_facing
            x,y=$x1,$y1
            type=Demon Shapeshifter
            generate_name=yes
            random_gender=yes
            random_traits=no
            # Inherit its previous form's traits. By design,
            # these are always compatible with the Shapeshifter
            # unit.
            [modifications]
                [insert_tag]
                    name=trait
                    variable=shapeshifter_previous_traits
                [/insert_tag]
            [/modifications]
        [/unit]

        {CLEAR_VARIABLE shapeshifter_previous_side,shapeshifter_previous_traits,shapeshifter_previous_facing}

        [fire_event]
            name=explain shapeshifter
            [primary_unit]
                x,y=$x1,$y1
            [/primary_unit]
        [/fire_event]
    [/event]

    # Anya explaining shapeshifter stuff (only once).

    [event]
        name=explain shapeshifter
        first_time_only=yes

        [scroll_to]
            x,y=$x1,$y1 # ensure the view is focused on the demon
        [/scroll_to]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Durvan
            message= _ "But... how?"
        [/message]

        [message]
            speaker=Anya
            message= _ "Shapeshifters. They are somewhat different to other demons in that the more mature individuals are much harder to kill without arcane magic than the rest. (disgusted) It’s said they are basically extinct, but some demon lords still keep them as slaves."
        [/message]

        [message]
            speaker=Elynia
            message= _ "How do you know that?"
        [/message]

        [message]
            speaker=Anya
            message= _ "Well, Elorran did tell me a lot of things about them..."
        [/message]

        [event]
            name=side 1 turn,side 1 turn end,side 2 turn,side 2 turn end
            first_time_only=yes

            [message]
                speaker=Anya
                message= _ "(muttering to herself, aside) ... mainly because I am one of them."
            [/message]
        [/event]
    [/event]

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

        [message]
            speaker=Igor
            message= _ "Battle goblin strikes again, yes! Take that, wretched scum!!!"
        [/message]

        [message]
            speaker=Durvan
            message= _ "He’s got an endearing quality to him most of the time, but I’m still not quite sure whether I should be concerned about his more bloodthirsty side...?"
        [/message]

        [message]
            speaker=Anya
            message= _ "Nah, I think he’s all right. You too have your moments despite being cute most of the time, after all."
        [/message]

        [message]
            speaker=Durvan
            message= _ "(blushing) Well... thanks, I guess."
        [/message]

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

    #
    # Victory choice event.
    #

    [event]
        name=die
        [filter]
            id=Portal Custodian
        [/filter]

        {OOH_RESET_PLAYLIST}

        [message]
            speaker=Elynia
            message= _ "Finally, that thing was a real nuisance."
        [/message]

        [if]
            [have_unit]
                canrecruit=yes
                [not]
                    side=1,2,9
                [/not]
            [/have_unit]
            [then]
                [message]
                    speaker=Durvan
                    message= _ "Are you leaving now, Elynia?"
                [/message]

                [message]
                    speaker=Elynia
                    message= _ "Well..."
                    [option]
                        label= _ "Yes, I think it is the right time."
                        [command]
                            [message]
                                speaker=Durvan
                                message= _ "All right, then."
                            [/message]

                            {ENDLEVEL_VICTORY no}
                        [/command]
                    [/option]
                    [option]
                        label= _ "No. Our allies still need our help."
                        [command]
                            [message]
                                speaker=Elynia
                                message= _ "As much as I dislike General Bardyl and his people, we wouldn’t have achieved this victory without them. I think it’s best to assist them until the battle is over. But I’ll keep the portal in mind if things don’t go as planned later."
                            [/message]

                            [set_menu_item]
                                id=wmi_leave_battle
                                description= _ "Leave Battle"
                                image="icons/menu-book.png"
                                [show_if][/show_if]
                                [command]
                                    [fire_event]
                                        name=wme_leave_battle
                                    [/fire_event]
                                [/command]
                            [/set_menu_item]

                            [event]
                                name=victory

                                {REMOVE_MENU_ITEM wmi_leave_battle}
                            [/event]

                            [fire_event]
                                name=leave battle hint
                            [/fire_event]

                            [scroll_to]
                                x,y=$x1,$y1
                            [/scroll_to]
                        [/command]
                    [/option]
                [/message]
            [/then]
            # [else]
            # Do nothing. "enemies defeated" should trigger
            # victory for us!
            #[/else]
        [/if]
    [/event]

    [event]
        name=leave battle hint
        first_time_only=no
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "If you change your mind later, you can choose the Leave Battle option in the context menu by right-clicking on any unit or vacant hex."
        [/message]
    [/event]

    [event]
        name=wme_leave_battle
        first_time_only=no

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "Do you really wish to leave the battle?"

            [option]
                label= _ "Yes."
                [command]
                    {ENDLEVEL_VICTORY no}
                [/command]
            [/option]
            [option]
                label= _ "No."
                [command]
                    [fire_event]
                        name=leave battle hint
                    [/fire_event]
                [/command]
            [/option]
        [/message]
    [/event]

    #
    # Since there's always an unkillable side 9 canrecruit=yes unit
    # around when the boss isn't, this shouldn't happen unless the
    # boss has already been defeated.
    #
    [event]
        name=enemies defeated

        {VARIABLE waited_for_bardyl yes}

        {ENDLEVEL_VICTORY yes}
    [/event]

#define OOH_EXTRA_GOLD _SIDE _GOLD
    [if]
        [have_unit]
            canrecruit=yes
            side={_SIDE}
        [/have_unit]
        [then]
            [store_gold]
                side={_SIDE}
            [/store_gold]

            [if]
                {VARIABLE_NUMERICAL_LESS_THAN gold ({_GOLD})}
                [then]
                    [modify_side]
                        side={_SIDE}
                        gold={_GOLD}
                    [/modify_side]
                [/then]
            [/if]

            {CLEAR_VARIABLE gold}
        [/then]
    [/if]
#enddef

    #
    # Give a little more gold to enemy sides on turn 10.
    #

    [event]
        name=turn 10

        [message]
            canrecruit=yes
            [filter_side]
                [not]
                    side=1,2,9
                [/not]
            [/filter_side]
            message= _ "Call more reinforcements! We can’t afford to lose control of this region to these wretches!"
        [/message]

        {OOH_EXTRA_GOLD 3 {DIFF 50 60 80} }
        {OOH_EXTRA_GOLD 4 {DIFF 50 60 80} }
        {OOH_EXTRA_GOLD 5 {DIFF 50 60 80} }
        {OOH_EXTRA_GOLD 6 {DIFF 50 60 80} }
        {OOH_EXTRA_GOLD 7 {DIFF 50 60 80} }
        {OOH_EXTRA_GOLD 8 {DIFF 50 60 80} }
        {OOH_EXTRA_GOLD 9 {DIFF 50 60 80} }
    [/event]

    #
    # Victory dialog.
    #

    [event]
        name=victory

        [message]
            speaker=Elynia
            message= _ "Let us find that portal."
        [/message]
    [/event]

#undef OOH_CHARGE_ITEM
#undef OOH_CHARGE_ITEM_ACTIVE
#undef OOH_CHARGE_PLACE
#undef OOH_CHARGE_DEPLOY
#undef OOH_REMOVE_UNITS_CHARGE
#undef OOH_RESET_PLAYLIST
#undef OOH_PRIMARY_OBJECTIVE
#undef OOH_CHARGE_PICK
#undef OOH_PAYLOAD_OVERLAY
#undef OOH_UPDATE_OBJECTIVES
#undef OOH_EXTRA_GOLD
#undef OOH_SHAPESHIFTER_ELIGIBLE_UNITS
#undef OOH_BARREL_COUNT_DEFEAT
#undef OOH_RECRUITMENT_PORTAL
#undef OOH_KEEP_SLF
[/scenario]

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


#textdomain wesnoth-After_the_Storm

[scenario]
    id=04_02_Gateway
    name= _ "Gateway"
    {MAP 04_02_Gateway.map}
    turns=-1
    next_scenario=05_Pass_of_Sorrows
    victory_when_enemies_defeated=no

    {FULLSCREEN_CUTSCENE_UI}

    {SCENARIO_MUSIC "snowfall.ogg"} {CONTINUE_PLAYING_STORY_MUSIC_FIRST}

    {STORYTXT_GATEWAY}

    {INDOORS}

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

        {GOLD 170 160 150}

        shroud=yes
        share_vision=all

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

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

        {GOLD 160 150 140}

        shroud=yes
        share_vision=all

        # wmllint: recognize General Bardyl
        {CHARACTER_STATS_GENERAL_BARDYL}
    [/side]
    # wmllint: validate-on

    [event]
        name=prestart

        [if]
            {VARIABLE_BOOLEAN_EQUALS waited_for_bardyl yes}
            [then]
                [store_side]
                    side=2
                    variable=bardyl_side_state
                [/store_side]

                [store_unit]
                    [filter]
                        side=2
                        [not]
                            # wmllint: recognize Kyara
                            # wmllint: recognize Horo
                            id=General Bardyl,Kyara,Horo
                        [/not]
                    [/filter]
                    variable=bardyl_side_units
                [/store_unit]
            [/then]
        [/if]

        [kill]
            side=2
            [not]
                id=Kyara,Horo
            [/not]
        [/kill]

        # wmllint: recognize Anya
        {RECALL_ANYA_AT_LOCATION 11 10}
        # wmllint: recognize Durvan
        {RECALL_DURVAN_AT_LOCATION 13 10}
        # wmllint: recognize Irylean
        {RECALL_IRYLEAN_AT_LOCATION 12 10}
        # wmllint: recognize Igor
        {RECALL_IGOR_AT_LOCATION 12 11}
        # wmllint: recognize Kyara
        {RECALL_KYARA_AT_LOCATION 15 8}
        # wmllint: recognize Horo
        {RECALL_HORO_AT_LOCATION 11 7}

        [store_unit]
            [filter]
                id=Durvan
            [/filter]
            variable=durvan_store
            kill=no
        [/store_unit]

        [store_unit]
            [filter]
                {NOT_ON_RECALL_LIST}
            [/filter]
            variable=on_map_units_store
        [/store_unit]

        #
        # Set everyone on-map to face Elynia.
        #

        [foreach]
            array=on_map_units_store
            [do]
                [store_direction]
                    from_x,from_y=$this_item.x,$this_item.y
                    [to]
                        [filter]
                            id=Elynia
                        [/filter]
                    [/to]
                [/store_direction]

                {VARIABLE this_item.facing $direction}

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

                {CLEAR_VARIABLE direction}
            [/do]
        [/foreach]

        {CLEAR_VARIABLE on_map_units_store}

        {MODIFY_UNIT (id=Durvan) side 2}

        {FACE_DIRECTION (id=Elynia) ne}

        [hide_unit][/hide_unit]

        {BLACK_SCREEN}

        {LOCK_VIEW}
    [/event]

    [event]
        name=start

        [place_shroud]
            side=1,2
        [/place_shroud]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "I guess I have to admit I am hesitant to continue..."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "He said it was a greater cause, after all. I fear that once we step into this portal... We might never come back to these lands alive."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Why do you want to come, anyway? Haven’t all my decisions led to awful disasters since we began? All our victories have been small in the grand scheme of things, and many have died because of my desire for answers... and revenge."
        [/message]

        [remove_shroud]
            side=1,2
            terrain=!,X*,X*^*,*^X*
            [or]
                [filter_adjacent_location]
                    terrain=!,X*,X*^*,*^X*
                [/filter_adjacent_location]
            [/or]
        [/remove_shroud]

        [redraw]
            side=1
        [/redraw]

        {FADE_IN}

        [unhide_unit][/unhide_unit]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Anya
            message= _ "Elynia... While all that is true, you can’t deny you have helped us all do more good than any of us alone could otherwise. No-one is perfect..."
        [/message]

        [message]
            speaker=Elynia
            message= _ "... not even gods, as it turns out."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Anya
            message= _ "... But most importantly, we work as a team! I for one promise I won’t give up in the face of danger."
        [/message]

        [message]
            speaker=Igor
            message= _ "Neither will I, my lady!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "Yes, I know. Galas never gave up either..."
        [/message]

        [message]
            speaker=Kyara
            message= _ "Nor did Mal Keshar."
        [/message]

        [message]
            speaker=Elynia
            message= _ "... That is true... too true."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "I understand that you won’t be joining us in this suicidal mission, Durvan, so... What will you do?"
        [/message]

        [message]
            speaker=Durvan
            message= _ "Eh, I will just stay safe and sound here and help defend the castle until I find a way to return home. Maybe try to convince that general or Lord Torancyn—"
        [/message]

        [message]
            speaker=Irylean
            message= _ "Supreme Lord Torancyn. (snickers)"
        [/message]

        [message]
            speaker=Durvan
            message= _ "... They might be willing to send someone to check the situation in Kalari if you can secure the portal from the other side."
        [/message]

        [if]
            {VARIABLE_BOOLEAN_EQUALS waited_for_bardyl yes}
            [then]
                [message]
                    speaker=Elynia
                    message= _ "I hope that is the case, yes. Bardyl seemed rather grateful for our assistance at the end of the day."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Elynia
                    message= _ "I doubt Bardyl will understand that I simply could not tarry here for longer than strictly necessary, especially since ‘my’ little band failed to live up to his expectations. And Torancyn... I wouldn’t bet on his support at this point."
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Durvan
            message= _ "Many of our men seem willing to follow you. I just don’t know what their motivation is — money, bloodshed, adventure? It’s rather strange, really. But I’m sure you could use their help."
        [/message]

        [message]
            speaker=Elynia
            message= _ "What will you do, Horo, Kyara?"
        [/message]

        [message]
            speaker=Horo
            message= _ "Well, returning home is out of the question for me with Tirigaz gone. Those vermin will surely head back here as soon as they hear of our victory, presumably led by that hideous demon midget... Right now, there’d be nothing more satisfying for me than breaking his stumpy neck and wearing his hollow skull as a helmet."
        [/message]

        [message]
            speaker=Kyara
            message= _ "As soon as I may, I’m returning to Quenoth Isle to spread the word about all these events... Perhaps, if the war comes to an end first, we could even send some people back here, to trade with the humans and orcs... I know that’s all very unlikely with the current state of things, but... (shrugs) dreaming never hurt anybody."
        [/message]

        [delay]
            time=750
        [/delay]

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

        [delay]
            time=750
        [/delay]

        [hide_unit][/hide_unit]

        [kill]
            side=2
        [/kill]

        {FADE_TO_BLACK}

        {BLACK_SCREEN}

        [place_shroud]
            side=1
        [/place_shroud]

        [delay]
            time=750
        [/delay]

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

        [delay]
            time=250
        [/delay]

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

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

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