#textdomain wesnoth-Invasion_from_the_Unknown

[scenario]
    id=02_A_Real_Confrontation
    name= _ "A Real Confrontation"
    {MAP 02_A_Real_Confrontation.map}
    {TURNS 26 24 22}
    next_scenario=03_Memories_from_the_Depths
    victory_when_enemies_defeated=no

    {SCENARIO_MUSIC "underground.ogg"} {CONTINUE_PLAYING_STORY_MUSIC_FIRST}

    {STORYTXT_A_REAL_CONFRONTATION}

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

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        team_name=elves
        user_team_name= _ "team_name^Elves"

        {GOLD 120 110 100}

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

    [side]
        side=2
        team_name=elves
        user_team_name= _ "team_name^Elves"
        color=teal

        {GOLD 310 260 210}
        {INCOME 8 6 4}
        recruit=Elvish Fighter,Elvish Archer,Elvish Shaman,Elvish Hunter,Elvish Civilian

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT village_value       0.1}
            {AI_SIMPLE_ALWAYS_ASPECT passive_leader      yes}
            {AI_SIMPLE_ALWAYS_ASPECT passive_leader_shares_keep yes}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "fighter,fighter,archer,healer,healer,archer,archer,fighter,fighter,mixed fighter,mixed fighter"}
            {AI_NO_SCOUTS}
        [/ai]

        # wmllint: recognize Lédinor
        {CHARACTER_STATS_LEDINOR}
        overlays,ellipse="","" # Clobber hero overlay and hero ellipse
        facing=sw
        canrecruit=yes
    [/side]

#define ARC_AI_TARGETS
    [goal]
        [criteria]
            id=Lédinor
        [/criteria]
        {QUANTITY value 2.5 4.0 6.0}
    [/goal]
    [goal]
        [criteria]
            id=Galas
        [/criteria]
        {QUANTITY value 2.0 3.0 5.0}
    [/goal]
    [goal]
        [criteria]
            id=Anlindë
        [/criteria]
        {QUANTITY value 1.5 2.0 4.0}
    [/goal]
#enddef

    [side]
        side=3
        team_name=chaos
        user_team_name= _ "team_name^Humans"
        {CHAOS_FLAG}
        color=blue

        {GOLD 175 200 225}
        {INCOME 13 18 23}
#ifdef HARD
        recruit=Dark Knight,Chaos Bowman,Chaos Crossbowman,Demon,Chaos Raider,Chaos Hound,Chaos Invader,Chaos Invoker,Doom Guard
#else
        recruit=Dark Knight,Chaos Bowman,Chaos Crossbowman,Demon,Chaos Hound,Chaos Invader,Chaos Invoker,Doom Guard
#endif

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT village_value       0.2}
            {AI_SIMPLE_ALWAYS_ASPECT aggression          0.95}
            {AI_SIMPLE_ALWAYS_ASPECT caution             0.05}
#ifdef HARD
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "fighter,fighter,mixed fighter,archer,archer,fighter,mixed fighter,scout"}
#else
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "fighter,fighter,mixed fighter,archer,archer,fighter,mixed fighter"}
#endif
            {AI_NO_SCOUTS}
            {ARC_AI_TARGETS}
        [/ai]

        canrecruit=yes
        type=Chaos Heavy Longbowman
        id=Vorgewyn
        name= _ "Vorgewyn"
        unrenamable=yes
    [/side]

    [side]
        side=4
        team_name=chaos
        user_team_name= _ "team_name^Humans"
        {CHAOS_FLAG}
        color=green

        {GOLD 175 200 225}
        {INCOME 8 10 12}
        recruit=Chaos Headhunter,Chaos Bowman,Chaos Crossbowman,Demon,Chaos Hound,Chaos Invader,Chaos Invoker,Heavy Infantryman

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

        canrecruit=yes
        type=Iron Mauler
        id=Kalwen
        name= _ "Kalwen"
        unrenamable=yes
    [/side]

    [side]
        side=5
        team_name=chaos
        user_team_name= _ "team_name^Humans"
        {CHAOS_FLAG}
        color=purple

        {GOLD 175 200 225}
        {INCOME 6 12 18}
        recruit=Chaos Headhunter,Demon,Chaos Hound,Chaos Invader,Chaos Invoker

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

        canrecruit=yes
        type=Chaos Razerman
        id=Jurdaan
        name= _ "Jurdaan"
        unrenamable=yes
    [/side]
    # wmllint: validate-on

#undef ARC_AI_TARGETS

    {STARTING_VILLAGES_ALL 1}
    {STARTING_VILLAGES     2 6}
    {STARTING_VILLAGES     3 4}
    {STARTING_VILLAGES     4 4}
    {STARTING_VILLAGES     5 4}

    #
    # Campfire sound sources. Their coordinates point at the
    # enemy keeps instead of the surrounding campfire tiles.
    #
    {CONTINUOUS_SOUND_SOURCE blue 4 25 (ambient/campfire.ogg)}
    {CONTINUOUS_SOUND_SOURCE purple 12 29 (ambient/campfire.ogg)}
    {CONTINUOUS_SOUND_SOURCE green 26 28 (ambient/campfire.ogg)}

    [label]
        x,y=22,7
        text= _ "Telchior’s Hold"
    [/label]

    [label]
        x,y=19,1
        text= _ "River Toldrin" # wmllint: no spellcheck
    [/label]

    [label]
        x,y=15,27
        text= _ "Peak of the Beholder"
    [/label]

    [label]
        x,y=29,39
        text= _ "South-eastern Outpost"
    [/label]

    [event]
        name=prestart

        {FACE_DIRECTION id=Galas,Anlindë se}

        {ALLOW_RECRUIT 1 (Elvish Civilian)}

        # Initialize variables
        {VARIABLE essential_villages_count {DIFF 5 8 9} }
        {VARIABLE civ_spam_count 0}

        {OBJECTIVES (
            {OBJECTIVE_VICTORY   ( _ "Resist until turns run out")}
            {OBJECTIVE_OR}
            {OBJECTIVE_BONUS ( _ "Defeat all enemy leaders")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Lédinor")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Galas")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Anlindë")}

            # wmlindent: start ignoring
            {DIFF
                ({OBJECTIVE_DEFEAT  ( _ "Fewer than five elven villages under your or Lédinor’s control remain standing")})
                ({OBJECTIVE_DEFEAT  ( _ "Fewer than eight elven villages under your or Lédinor’s control remain standing")})
                ({OBJECTIVE_DEFEAT  ( _ "Fewer than nine elven villages under your or Lédinor’s control remain standing")})
            }
            # wmlindent: stop ignoring

            {OBJECTIVE_CARRYOVER_NO_BONUS}
        )}

        # wmllint: recognize Anlindë
        {RECALL_ANLINDE_AT 13 10}

#ifndef HARD
        # Try to recall a veteran warrior unit for free...
        {ELVISH_SUPPORTER_ROLE (supporter)}

        [recall]
            role=supporter
        [/recall]
#endif
        # If they could not be recalled, or we are playing
        # on HARD...
        [if]
            [not]
                [have_unit]
                    side=1
                    role=supporter
                [/have_unit]
            [/not]
            [then]
                {RANDOM "Archer,Fighter,Hunter"}
                # ... create a loyal supporter that is NOT controlled
                # by the player, to fill dialogues and aid the allies
                # a tad (Lédinor's units tend to act as kamikazes -
                # not a good help if player doesn't have veterans)
                [unit]
                    random_traits=yes
                    random_gender=yes
                    generate_name=yes
                    side=2
                    x,y=24,7
                    moves=0
                    resting=no
                    facing=sw
                    role=supporter
                    type="Elvish $random"
                    {IS_LOYAL}
                    [modifications]
                        {TRAIT_LOYAL}
                    [/modifications]
                [/unit]

                {CLEAR_VARIABLE random}
            [/then]
        [/if]
    [/event]

    [event]
        name=start

        [message]
            speaker=Lédinor
            message= _ "The patrol group that was sent to replace yours in the southern zone should have arrived this morning. I begin to worry about them."
        [/message]

        [delay]
            time=250
        [/delay]

        {REPLACE_SCENARIO_MUSIC "northerners.ogg"}
        {APPEND_MUSIC           "the_city_falls.ogg"}
        {APPEND_MUSIC           "casualties_of_war.ogg"}

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Galas
            message= _ "Fire! Fire on the horizon! Call out the fighters, invaders draw near!"
        [/message]

        [sound]
            name="horse-elf-canter.wav"
        [/sound]

        [move_unit_fake]
            side=1
#ifndef EASY
            type=Elvish Scout
#else
            type=Elvish Rider
#endif
            x=21,21,19,19,18,18,17,16
            y=17,15,14,12,11,10,10,10
        [/move_unit_fake]

        [unit]
            side=1
#ifndef EASY
            type=Elvish Scout
#else
            type=Elvish Rider
#endif
            x,y=16,10
            id=Vólrand
            name= _ "Vólrand"
            unrenamable=yes
            moves=0
            resting=no
            facing=nw
            {IS_LOYAL}
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_DEXTROUS}
            [/modifications]
        [/unit]

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Vólrand
            message= _ "Indeed, sir! It’s an entire human army burning forests and pillaging villages in the border hills! They have even impaled the skulls of our fallen kin on their banners!"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "An entire army? That’s impossible — humans are not capable of raising troops in such numbers!"
        [/message]

        [message]
            role=supporter
            message= _ "So that is what befell them... Those invaders will not go unpunished!"
        [/message]

        [message]
            speaker=Lédinor
            message= _ "We must prepare to fight. We will not allow even an army to dispossess us. Men, to arms!"
        [/message]

        # wmllint: local spelling patrollers

        [message]
            speaker=Galas
            message= _ "But my lord, if these invaders could trap our best patrollers, how can we prevail against them while so short of recruits and supplies?"
        [/message]

        [message]
            speaker=Lédinor
            message= _ "Young Galas, I understand your worries. But it is time for you to learn the first duty of a commander, which is to not be defeated in mind before you engage in battle."
        [/message]

        [message]
            speaker=Galas
            message= _ "I accept your instruction."
        [/message]

        {RECRUITMENT_HINT units/elves-wood/civilian.png
        ( _ "From the valley’s main keep you can recruit citizens to aid you in battle. Most of them have basic training in the use of the sword and the bow; however, they still lack the experience required to put them into effective use. But remember: they are not charging you for their services yet.")}
    [/event]

    [event]
        name=recruit
        [filter]
            side=3,4,5
            race=demon
        [/filter]

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

        [redraw][/redraw]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Lédinor
            message= _ "Bright Gods... what is that thing?"
            scroll=no
        [/message]
    [/event]

    [event]
        name=turn 3

        [role]
            role=scared_one
            race=elf
            [not]
                id=Anlindë
            [/not]
            [not]
                canrecruit=yes
            [/not]
        [/role]

        [message]
            role=scared_one
            message= _ "I don’t think we can resist them!"
        [/message]

        [message]
            speaker=Lédinor
            message= _ "So, there is yet human civilization on this continent. I wonder why we have not encountered them before?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "It must be that they are a new tribe, only recently come into its power... an evil power that is not from our world. Look!"
        [/message]

        {NAMED_UNIT 5 (Demon Zephyr)  5 33 Garya  ( _ "Garya")  (gender,upkeep,facing=female,free,ne)} # {NO_UPKEEP_NO_OVERLAY}
        {NAMED_UNIT 5 (Demon Zephyr)  4 32 Quiryn ( _ "Quiryn") (upkeep,facing=free,ne)}               # {NO_UPKEEP_NO_OVERLAY}
#ifdef HARD
        {NAMED_UNIT 5 (Demon Zephyr)  4 33 Nolok  ( _ "Nolok")  (upkeep,facing=free,ne)}               # {NO_UPKEEP_NO_OVERLAY}
#endif

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

        [redraw][/redraw]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Galas
            message= _ "Would that my fears had proven false..."
        [/message]
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            side=1
            type=Elvish Civilian
        [/filter]

        {VARIABLE_INC civ_spam_count}
    [/event]

    [event]
        name=die
        [filter]
            side=1
            type=Elvish Civilian
        [/filter]
        [filter_condition]
            {VARIABLE_NUMERICAL_GREATER_THAN civ_spam_count 7}
        [/filter_condition]

        # It is a perfectly legitimate tactic, but...

        [message]
            speaker=Anlindë
            message= _ "Galas, are you— Are you purposely sending civilians to their deaths?!"
        [/message]

        [message]
            speaker=Galas
            message= _ "Er... No! They are supposed to deliver supplies to the front line and tend to injured soldiers, not engage in combat! Somebody must have misunderstood my orders — I will ask our officials to put a halt to this egregious waste of precious elf lives immediately."
        [/message]

        [message]
            speaker=Anlindë
            message= _ "(<i>suspicious</i>) Very... well..."
        [/message]
    [/event]

    [event]
        name=enemies defeated

        {ENDLEVEL_VICTORY yes}
    [/event]

    [event]
        name=time over

        {ENDLEVEL_VICTORY no}
    [/event]

    [event]
        name=victory

        # Make the dialogue consistent for any triggering event. I could have moved the first dialog line to each
        # trigger, but that wouldn't cover the case of using :debug :n, or implementing a new victory goal later
        [if]
            [have_unit]
                canrecruit=yes
                [filter_side]
                    [enemy_of]
                        side=1
                    [/enemy_of]
                [/filter_side]
            [/have_unit]
            [then]
                [message]
                    speaker=Galas
                    message= _ "The humans are retreating, after having almost defeated us?"
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Galas
                    message= _ "Their remaining forces are retreating. It seems we have won, for now."
                [/message]
            [/else]
        [/if]

        [if]
            {VARIABLE_NUMERICAL_GREATER_THAN civ_spam_count 9}
            [then]
                [message]
                    speaker=Anlindë
                    message= _ "Would that it had not taken the lives of so many civilians that had no need to join the battle in the first place, huh, Galas?"
                [/message]
            [/then]
        [/if]

        {REPLACE_SCENARIO_MUSIC wanderer.ogg}

        [message]
            speaker=Lédinor
            message= _ "I hate to be the bearer of bad news, but some of the other patrol leaders claim that the invaders are merely regrouping and preparing to strike again with greater numbers. Many of your peers abandoned their posts, and Adel and his hunters have not returned from their expedition yet... This is no mere skirmish, Galas. I do not think we shall be able to hold against them."
        [/message]

        [message]
            speaker=Galas
            message= _ "Would it be possible to obstruct the valley entrances and repel them? How many more of those winged creatures could they have at their disposal?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "If we trust the scouts’ word, they could be hundreds. Perhaps thousands. Their own sorcerers would be able to bring down or bypass any sort of obstacle we might raise within the scarce time we have before their next assault. I would be inclined to suggest fleeing."
        [/message]

        [message]
            speaker=Galas
            message= _ "Do you say we should abandon our home? Where would we go? Our people are not as adept as those humans to surviving the desert’s perils!"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "We would certainly not survive the desert from whence the humans came, especially since we don’t know how many more warriors follow their back trail. However, we have no reports of enemies approaching from the north — we have not been menaced by anything from that direction in centuries. It may be that any possibility of escaping the imminent slaughter lies there. If our historical records are correct, the caverns should take us far from this valley. It is my hope that the humans and their fell allies are not informed of any of this."
        [/message]

        [message]
            speaker=Lédinor
            message= _ "North, you say... It is true that it has seemed more tranquil in my lifetime. Is it your intention to destroy any evidence of there being this underground escape route in the northern pass? Even if that worked... it would be a harsh, irrevocable choice."
        [/message]

        [message]
            speaker=Anlindë
            message= _ "The ancestors of our people spent much of their lives hiding beneath the surface when this valley was just barely apt for sustaining them. If we manage to survive, we might in time be fortunate enough to find a new home to settle in. If we fail, at least we will die with our heads held high."
        [/message]

        [message]
            speaker=Lédinor
            message= _ "You bring hard counsel, but I see its wisdom."
        [/message]

        [message]
            speaker=Anlindë
            message= _ "We are between a rock and a hard place — either death by the hands of the invaders, or the perils of the underground tunnels."
        [/message]

        [message]
            speaker=Galas
            message= _ "Most of our people lack experience traveling at night, let alone under the earth!"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "I fear we have no other alternatives left. Unless the civilians think it a better course to stand and fight to our death and be expunged from the green world without trace."
        [/message]

        [message]
            speaker=Lédinor
            message= _ "It will be necessary, however, to provide a distraction until we evacuate all of our people to the caves. Have you thought on that, my lady?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "I have, indeed. But..."
        [/message]

        [message]
            speaker=Lédinor
            message= _ "Some of us must stay here to spoil their attack. We shall do it."
        [/message]

        [message]
            speaker=Anlindë
            message= _ "But— my lord?"
        [/message]

        [message]
            speaker=Galas
            message= _ "My lord... Why?"
        [/message]

        [message]
            speaker=Lédinor
            message= _ "Because it is all I can do for our future. Many of us are too old to long survive the desert wastes, including myself — but here we can die well. Galas, you are a brave warrior, albeit unseasoned — and more to the point, you have the intelligence to lead brave warriors. I pass to you the war-leadership of the elves of the Valley of Elynia."
        [/message]

        [message]
            speaker=Galas
            message= _ "But I am simply a patrol leader! I ... I am not ready for such a responsibility!"
        [/message]

        [message]
            speaker=Lédinor
            message= _ "None of us are ever ready for such a burden, but we must bear it nevertheless. Now, go! May fate reunite us in time, young Galas."
        [/message]

        {CLEAR_VARIABLE essential_villages_count,civ_spam_count}
    [/event]

    #
    # Handle heroes' deaths manually here
    #

    [event]
        name=last breath
        [filter]
            id=Anlindë
        [/filter]

        [message]
            speaker=unit
            message= _ "Ugh. I am finished..."
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id=Anlindë
        [/filter]

        [message]
            speaker=Galas
            message= _ "Anlindë! No! We need you! Who will guide us with wisdom now?!"
        [/message]

        {ENDLEVEL_DEFEAT}
    [/event]

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

        [message]
            speaker=unit
            message= _ "It is my end..."
        [/message]

        [message]
            speaker=Anlindë
            message= _ "Galas? Galas, no!"
        [/message]
    [/event]

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

        {ENDLEVEL_DEFEAT}
    [/event]

    [event]
        name=last breath
        [filter]
            id=Lédinor
        [/filter]

        [message]
            speaker=unit
            message= _ "I have fallen this day. But, young Galas, you are the brightest of our young. Lead our people in my place!"
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id=Lédinor
        [/filter]

        [message]
            speaker=Galas
            message= _ "Lédinor, no!"
        [/message]

        {ENDLEVEL_DEFEAT}
    [/event]

    {ANLINDE_1ST_TIME_HELP}

    # Enemies may pillage and burn villages:
    [event]
        name=capture
        [filter]
            [not]
                side=1,2
            [/not]
            [filter_location]
                terrain=*^Ve
            [/filter_location]
        [/filter]
        [filter_condition]
            {VARIABLE_NUMERICAL_EQUALS owner_side 1}
            [or]
                {VARIABLE_NUMERICAL_EQUALS owner_side 2}
            [/or]
        [/filter_condition]

        [message]
            side=$unit.side
            canrecruit=yes
            message= _ "Leave nothing standing! Burn them alive with their villages!"
        [/message]
    [/event]

    [event]
        name=capture
        first_time_only=no
        [filter]
            [not]
                side=1,2
            [/not]
            [filter_location]
                terrain=*^Ve
            [/filter_location]
        [/filter]
        [filter_condition]
            {VARIABLE_NUMERICAL_EQUALS owner_side 1}
            [or]
                {VARIABLE_NUMERICAL_EQUALS owner_side 2}
            [/or]
        [/filter_condition]

        [sound]
            name="torch.ogg"
        [/sound]

        [delay]
            time=200
        [/delay]

        [sound]
            name="wose-die.ogg"
        [/sound]

        [terrain]
            x,y=$x1,$y1
            terrain=^Dr
            layer=overlay
        [/terrain]

        {ADD_GOLD $unit.side 9 14 20}

        [redraw][/redraw]

        [store_locations]
            terrain=*^Ve
            variable=village_tiles_probe
            [filter_owner]
                side=1,2
            [/filter_owner]
        [/store_locations]

        [if]
            {VARIABLE_NUMERICAL_LESS_THAN village_tiles_probe.length $essential_villages_count}
            [then]
                [message]
                    speaker=Galas
                    message= _ "We could not protect enough of our civilians. They have been burned alive with their villages!"
                [/message]

                [message]
                    speaker=Lédinor
                    message= _ "We have failed to protect our people and the legacy of our civilization."
                [/message]

                {ENDLEVEL_DEFEAT}
            [/then]
        [/if]

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

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


#textdomain wesnoth-Invasion_from_the_Unknown

[scenario]
    id=03_Memories_from_the_Depths
    name= _ "Memories from the Depths"
    {MAP 03_Memories_from_the_Depths.map}
    {TURNS 62 57 54}
    next_scenario=04_Over_the_Sands
    victory_when_enemies_defeated=no # to handle side 2 leader's death manually

    {DEATHS_ACT_0}

    {SCENARIO_MUSIC "underground.ogg"} {CONTINUE_PLAYING_STORY_MUSIC_FIRST}

    {STORYTXT_HORRORS_FROM_THE_DEPTHS}

    {UNDERGROUND}

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        team_name=elves
        user_team_name= _ "team_name^Elves"

        shroud=yes

        {GOLD 250 200 150}
        income=2

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

    [side]
        side=2
        team_name=enemies
        user_team_name= _ "team_name^Undead"

        hidden=yes

        {GOLD 100 125 150}
        income=-3
        {QUANTITY recruit
        ("Walking Corpse,Vampire Bat,Ghost,Skeleton Archer,Skeleton,Skeleton Rider")
        ("Soulless,Vampire Bat,Ghost,Skeleton Archer,Skeleton,Skeleton Rider,Ghoul")
        ("Soulless,Blood Bat,Wraith,Ghost,Skeleton Archer,Skeleton,Skeleton Rider,Ghoul")
        }

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT_VALUE avoid (
                x,y=24,39
            )}

            [goal]
                name=protect_unit
                [criteria]
                    id=Mal Keshar
                [/criteria]
                value=4.00
            [/goal]
        [/ai]

        {CHARACTER_STATS_MAL_KESHAR}
        overlays,ellipse="","" # Clobber hero overlay and hero ellipse
        canrecruit=yes

        {SIDE_GENERIC_GUARD (Skeleton)        39 40}
        {SIDE_GENERIC_GUARD (Soulless)        39 37}
        {SIDE_GENERIC_GUARD (Walking Corpse)  34 38}

        {SIDE_GENERIC_GUARD (Soulless)        22 35}

        {SIDE_GENERIC_GUARD (Skeleton)        16 33}
        {SIDE_GENERIC_GUARD (Skeleton Archer) 22 31}
        {SIDE_GENERIC_GUARD (Ghost)           24 28}

        {SIDE_GENERIC_GUARD (Walking Corpse)  13 35}
        {SIDE_GENERIC_GUARD (Walking Corpse)  14 38}

        {SIDE_GENERIC_GUARD (Revenant)        12 22}
        {SIDE_GENERIC_GUARD (Necrophage)      20 20}

        {SIDE_GENERIC_GUARD (Soulless)                         6 25}
        {SIDE_GENERIC_GUARD {DIFF (Soulless) (Ghoul) (Ghoul)}  5 23}
        {SIDE_GENERIC_GUARD (Ghoul)                            8 19}

        {SIDE_GENERIC_GUARD {DIFF (Skeleton) (Skeleton) (Revenant)}           29 17}
        {SIDE_GENERIC_GUARD {DIFF (Skeleton) (Revenant) (Deathblade)}         25 21}
        {SIDE_GENERIC_GUARD {DIFF (Skeleton) (Skeleton) (Deathblade)}         30 18}
        {SIDE_GENERIC_GUARD {DIFF (Skeleton Archer) (Bone Shooter) (Banebow)} 35  9}

        {SIDE_GENERIC_GUARD (Skeleton)        22 16}
        {SIDE_GENERIC_GUARD (Revenant)        31 22}
        {SIDE_GENERIC_GUARD (Revenant)        31 12}
        {SIDE_GENERIC_GUARD (Skeleton Archer) 33 11}

        {SIDE_GENERIC_GUARD (Necrophage)      24  9}
        {SIDE_GENERIC_GUARD (Banebow)         29  7}
        {SIDE_GENERIC_GUARD (Dread Bat)       26 11}
        {SIDE_GENERIC_GUARD (Soulless)        29 10}
        {SIDE_GENERIC_GUARD (Soulless)        29  8}
    [/side]

    [side]
        side=3
        team_name=enemies
        user_team_name= _ "team_name^Cave Creatures"

        hidden=yes
        no_leader=yes

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_NO_SCOUTS}
            {AI_SIMPLE_ALWAYS_ASPECT aggression 1.0}
            {AI_SIMPLE_ALWAYS_ASPECT caution    0.0}
        [/ai]

        {SIDE_GENERIC_GUARD (Blood Bat)   18 47}
        {SIDE_GENERIC_GUARD (Vampire Bat) 17 44}
        {SIDE_GENERIC_GUARD (Blood Bat)   30 36}
        {SIDE_GENERIC_GUARD (Fungoid)     11 46}
        {SIDE_GENERIC_GUARD (Fungoid)     31 45}
        {SIDE_GENERIC_GUARD (Fungoid)     36 43}
        {SIDE_GENERIC_GUARD (Fungoid)     27 46}
        {SIDE_GENERIC_GUARD (Fungoid)     14 50}
        {SIDE_GENERIC_GUARD (Fungoid)     17 49}
        {SIDE_GENERIC_GUARD (Dread Bat)   32 32}

        {SIDE_GENERIC_GUARD {DIFF (Vampire Bat) (Vampire Bat) (Blood Bat)} 27 43}
        {SIDE_GENERIC_GUARD {DIFF (Vampire Bat) (Vampire Bat) (Blood Bat)} 37 43}
        {SIDE_GENERIC_GUARD {DIFF (Vampire Bat) (Vampire Bat) (Blood Bat)} 28 34}

        {SIDE_GENERIC_GUARD (Blood Bat)                                     7 32}
        {SIDE_GENERIC_GUARD {DIFF (Vampire Bat) (Vampire Bat) (Blood Bat)} 11 25}

        {SIDE_GENERIC_GUARD {DIFF (Vampire Bat) (Vampire Bat) (Blood Bat)} 30 12}
        {SIDE_GENERIC_GUARD {DIFF (Vampire Bat) (Blood Bat) (Blood Bat)}   22  1}
        {SIDE_GENERIC_GUARD {DIFF (Vampire Bat) (Blood Bat) (Blood Bat)}    6 16}
        {SIDE_GENERIC_GUARD {DIFF (Vampire Bat) (Vampire Bat) (Blood Bat)}  2 22}
    [/side]
    # wmllint: validate-on

    {CAVE_NOISE_SOUND_SOURCE}

    {CAVE_WATER_SOUND_SOURCE 14 36}

    {CAVE_WATER_SOUND_SOURCE 11 26}

    {CAVE_WATER_SOUND_SOURCE 20 10}

    {CAVE_WATER_SOUND_SOURCE 27  4}

    [event]
        name=prestart

        # Keep Malin's backup in memory, just for debugging purposes
        # i.e., so that triggering victory via :n works right.
        [store_unit]
            [filter]
                id=Mal Keshar
            [/filter]
            variable=malin_store
            kill=no
        [/store_unit]

        # wmllint: recognize Anlindë
        {RECALL_ANLINDE}

        {ELVISH_SUPPORTER (supporter)}

        {OBJECTIVES (
            {OBJECTIVE_VICTORY ( _ "Explore the caves")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Galas")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Anlindë")}

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER}
        )}
    [/event]

    [event]
        name=start

        [message]
            speaker=Galas
            message= _ "We lost our home... many of our children and elders... and our lord, at the hands of those fiends... What will we do now? Where will we go?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "Don’t despair, Galas. This is not the first time our civilization has been through trials like this. Invaders may defile our lands, the suns may burn our forests to the ground, but as long as we stand we may be yet able to find a new place to call our home."
        [/message]

        [message]
            speaker=Galas
            message= _ "I profoundly hope so... Anlindë, you mentioned something about an evil force before counseling flight. What did you mean?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "There is some great evil aiding those humans. Not merely ordinary necromancers and war-beasts, but something worse... something I believed had been vanquished by our civilization before. I need to ponder this further. Now, I suggest we proceed as swiftly as we may. Our valley..."
        [/message]

        [message]
            speaker=Galas
            message= _ "I would prefer to not think about it."
        [/message]

        [message]
            role=supporter
            message= _ "Would that we had more experience at moving in this darkness. This will be a long march."
        [/message]

        {APPEND_MUSIC "into_the_shadows.ogg"}
        {APPEND_MUSIC "nunc_dimittis.ogg"}
    [/event]

    {FIRE_EVENT_ON_STUMBLE_UPON "found undead" side=2}

    [event]
        name=found undead

        {CLEAR_CAVE_SHROUD x,y,radius=$x2,$y2,1}

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

        [delay]
            time=750
        [/delay]

        [message]
            speaker=unit
            message= _ "Undead! There are undead here!"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "They must have settled in here only recently, or they would have surely announced their presence in our valley before."
        [/message]

        [message]
            speaker=Galas
            message= _ "If we press forward, we may be able to find and strike their master down. Not that we have much of a choice now, with everyone trapped underground."
        [/message]

        [modify_side]
            side=2
            hidden=no
        [/modify_side]

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

        {OBJECTIVES (
            {HEADER_NEW_OBJECTIVES}

            {OBJECTIVE_VICTORY ( _ "Find the source of the roaming undead")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Galas")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Anlindë")}

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER}
        )}
    [/event]

    {FIRE_EVENT_ON_STUMBLE_UPON "found malin" (id=Mal Keshar)}

    [event]
        name=found malin

        {CLEAR_CAVE_SHROUD (
            [filter]
                id=Mal Keshar
            [/filter]
            radius=1
        )}

        [redraw]
            side=1
        [/redraw]

        [message]
            speaker=Galas
            message= _ "Who is this foul enemy that seeks our death?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Have you elves not realized the folly of trifling with the forces that lay in the darkest depths of Irdya? I am Mal Keshar, and these caverns belong to me now. Leave at once or meet your doom!"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "Mal Keshar? That name..."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "I said, leave!"
        [/message]

        [message]
            speaker=Galas
            message= _ "Listen, necromancer. We seek no quarrel with you. We have lost our home to foes of a power possibly greater than yours. Returning is not an option. If you want us gone, you will have to allow us passage through these caves."
        [/message]

        [message]
            speaker=Anlindë
            message= _ "Galas, you are not expecting that to work, are you—"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Ha, ha, ha, ha! Greater than mine, you say? My, you are but a young little elf of the forests! I had thought your kind’s existence had ended for good after the Golden Age! I am truly amazed! Let us put an end to your aimless wandering, then. At least you shall perish at the hands of a figure of legend rather than savage orcs or humans of the sands!"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "His banter is truly obnoxious."
        [/message]

        [message]
            speaker=Galas
            message= _ "Anlindë, do you think we may be able to destroy this lich?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "Incapacitate, perhaps; but if it’s the same lich I am thinking of, it might not be within our power to banish him permanently from the physical realm."
        [/message]

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

        {OBJECTIVES (
            {HEADER_NEW_OBJECTIVES}

            {OBJECTIVE_VICTORY ( _ "Defeat Mal Keshar")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Galas")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Anlindë")}

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER}
        )}
    [/event]

    [event]
        name=attack
        [filter]
            id=Mal Keshar
        [/filter]

        [fire_event]
            name=malin fight begin
        [/fire_event]
    [/event]

    [event]
        name=attack
        [filter_second]
            id=Mal Keshar
        [/filter_second]

        [fire_event]
            name=malin fight begin
        [/fire_event]
    [/event]

    [event]
        name=malin fight begin

        [message]
            speaker=Anlindë
            message= _ "I have not employed this kind of magic in a lifetime, but as our young leader said, we do not have much of a choice now."
        [/message]

        [scroll_to_unit]
            id=Mal Keshar
        [/scroll_to_unit]

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

        {FLASH_PURPLE ()}

        [message]
            speaker=Mal Keshar
            sound={SOUND_LIST:LICH_HIT}
            message= _ "What— what is this curse?"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Mal Keshar
        [/filter]

        [message]
            speaker=Mal Keshar
            message= _ "I cannot... believe it..."
        [/message]

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

        {ENDLEVEL_VICTORY yes}
    [/event]

    [event]
        name=victory

        {LOCK_VIEW}

        {CLEAR_LABELS}

        #
        # Try to use the same supporter fellow who spoke at the beginning of scenario.
        # If they aren't alive, select another one and recall them; if that isn't possible either
        # (how did the player make it this far then?) create a generic supporter.
        #
        {ELVISH_SUPPORTER (supporter)}

        {VARIABLE malin_store.hitpoints 1}

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

        {REPLACE_SCENARIO_MUSIC "elvish-theme.ogg"}

        [redraw][/redraw]

        [message]
            speaker=Mal Keshar
            # po: The elf in question is Anlindë.
            message= _ "How can it be? I have been defeated... my long battle against the orcs is lost! What are you waiting for, elf?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "You are a relic from an era long gone, Mal Keshar, or should I say... Malin Keshar? The one who fell to the darkness fighting a noble cause with tainted means. Your life story has served as a cautionary tale for an eternity, and you are now the unliving proof that the glories of the Golden Age are dead. Yes, destroying you would rid this ruined land of a threat that pales in comparison to what roams above the surface as we speak..."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Anlindë
            message= _ "... Although I have to admit that the notion of allowing those fiends to fight you is more than a little amusing. It’s a pity that your existence is a crime... against nature... that we cannot let go unpunished."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "I sense hesitation in your words. Why is that? Does your kind still remember what Wesnoth did to us all?"
        [/message]

        [message]
            speaker=Galas
            message= _ "Wesnoth?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "The name of an empire long dead. It’s not important."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Are you not curious about what has transpired in the expanse it once covered? You came to me fleeing a mighty foe; did it come from those lands? South of the Swamps of Dread, and west of the Silver Lands?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "That is not important—"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "I know many things. I know your kind always punished necromancers for disturbing the dead. You thought us the foulest evil imaginable, but you were wrong. I have seen and learned of things that even I would consider abominable. For all this eternity after the Fall, I have been haunting the sands by night, slaughtering orcs in their sleep and hoarding every piece of information I can gather about the new empire that has arisen amidst the debris of the past epoch."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Alas, you have waited long enough to end this and it’s rather unmannerly of me to keep interrupting you. Go ahead, finish me once and for all!"
        [/message]

        [message]
            speaker=Galas
            message= _ "No. What do you know, necromancer? Tell us."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "It was a few centuries ago... A malign shadow emanating from the Vast Ocean covered the lands, and an evil presence infected every living creature. Humans from the coastal regions began raiding and destroying what human, elvish, and orcish settlements they could find that would not join them in alliance. In time, they would bring new allies from beyond this world — demons. Your people still remember them, don’t you?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "We... our sages do, but... How can this be possible? The Demon Lord was vanquished by the Lady of Light long ago!"
        [/message]

        [message]
            speaker=Galas
            message= _ "Lady of Light?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Ah, but that was a mere foretaste of our doom. Something or someone apparently opened a portal — a new one — to the very heart of Inferno, unleashing the forces of evil and allowing them to cross the barrier dividing our realm from theirs. This may have been done from our world, or it may not. Arrogant unscrupulous magi cast us into this chaotic future before when they raised the two unnatural suns, after all. But yes... the humans are building a new empire of blood and destruction, and from what I gather you are the victims of its northwards expansion."
        [/message]

        [message]
            speaker=Anlindë
            message= _ "Then these caves are definitely not safe anymore. We need to escape — but supposing we can, for how long will we be able to avoid our enemy?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "You would be killed, tortured, or converted by them in a matter of hours, perhaps minutes, even seconds. You are few to their many, and lack the power necessary to combat the demonic hordes. Not even I have that fabled power — but I care little about it. I do not fear an end to my undeath. I have nothing left; all that I once loved has been scoured away by pitiless time."
        [/message]

        [message]
            speaker=Galas
            message= _ "Anlindë, what is the point of fleeing from those fiends to a new and safe home like cowards if they will surely find us again? For how long can we delay our downfall? Why are we not fighting the enemy?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "Our kin tried before, Galas, and we became the witnesses to their failure. We have no aid or craft that they did not."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Perhaps this will interest you: the wielders of the Union did not die after that catastrophe you insist on only vaguely referencing throughout this conversation. Have you all forgotten that they roamed Irdya for many centuries before, even exceeding the notorious lifespan of your kind?"
        [/message]

        [message]
            speaker=Galas
            message= _ "The Union?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Your elder druids and sorceresses should remember that this Lady of Light did not save you from that evil unaided. What won your victory was nothing else than the power of the Union, at hands of the Master of Darkness and the Lady of Light — a human and an elven lady. And you should remember that they were blessed — or cursed — with eternal life."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Some sources say they descended deep into the very heart of the world... and vanished into eternal slumber. It is said that the bright presence of the Lady of Light still radiates from the earth where the two figures of legend now lie dormant. Some claim to have followed them before they both disappeared; if my memory still serves after all this time, I would probably be able to pinpoint their location if I had the chance to approach that region."
        [/message]

        [delay]
            time=1500
        [/delay]

        [message]
            speaker=Galas
            message= _ "Would you be willing to lead us there?"
        [/message]

        [message]
            role=supporter
            message= _ "What?! But my lord, he is a lich — a necromancer! We cannot have such an abomination on our side!"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "... Times have changed, and so have our needs and methods... If Galas thinks the necromancer can help us find the power that can protect the remains of our civilization..."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "He, he, he, he... yes... yes! I may be able to help you, as long as you abide by my conditions."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Galas
            message= _ "And what would those be?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Protection is all I want."
        [/message]

        [message]
            role=supporter
            message= _ "Some of us might oppose this. My lord, please think this through!"
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Mal Keshar
            message= _ "What do you think, Galas? You have lost everything — well, mostly. I lost everything too, except for my unfinished business with the orcs, and this knowledge that could be placed at your service on these very simple terms. It’s your decision to make, young boy."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Galas
            message= _ "I accept."
        [/message]

        [delay]
            time=750
        [/delay]

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

        [unit]
            id=Mal Keshar
            name= _  "Mal Keshar"
            type=Ancient Lich
            side=1
            {IS_HERO}
            unrenamable=yes
            canrecruit=no
            max_experience=$malin_store.max_experience
            experience=$malin_store.experience
            max_hitpoints=$malin_store.max_hitpoints
            hitpoints=$malin_store.hitpoints
            profile=$malin_store.profile
            x,y=$malin_store.x,$malin_store.y
            facing=$malin_store.facing
            upkeep=loyal
            [modifications]
                {TRAIT_UNDEAD}
            [/modifications]
        [/unit]

        {CLEAR_VARIABLE malin_store}

        [redraw][/redraw]

        {UNLOCK_VIEW}
    [/event]

    #
    # Secret room 1 objects
    #

    {HOLY_WATER 12 38}

    {HOLY_WATER 12 35}

    {ITEM_TOUCHPLATE 19 35}

    [event]
        name=moveto
        [filter]
            side=1
            x,y=19,35
        [/filter]

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

        [terrain]
            x,y=18,35
            terrain=Urb
        [/terrain]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "Touchplate triggered. A wall moves."
        [/message]

        [redraw]
            side=1
        [/redraw]
    [/event]

    #
    # Secret room 2 objects
    #

    {RING_SPEED 39 29}

    {ITEM_TOUCHPLATE 36 32}

    [event]
        name=moveto
        [filter]
            side=1
            x,y=36,32
        [/filter]

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

        [terrain]
            x=37
            y=32
            terrain=Urb
        [/terrain]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "Touchplate triggered. A wall moves."
        [/message]

        [redraw]
            side=1
        [/redraw]
    [/event]

    #
    # Secret room 3 objects
    #

    {HOLY_WATER 25 24}

    {ITEM_TOUCHPLATE 25 21}

    [event]
        name=moveto
        [filter]
            side=1
            x,y=25,21
        [/filter]

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

        [terrain]
            x,y=25,22
            terrain=Urb
        [/terrain]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "Touchplate triggered. A wall moves."
        [/message]

        [redraw]
            side=1
        [/redraw]
    [/event]

    #
    # Secret path 1
    #

    {ITEM_TOUCHPLATE 6 18}

    [event]
        name=moveto
        [filter]
            side=1
            x,y=6,18
        [/filter]

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

        [terrain]
            x,y=8,18
            terrain=Urb
        [/terrain]

        [terrain]
            x,y=17,16
            terrain=Re
        [/terrain]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "Touchplate triggered. Two walls move."
        [/message]

        [redraw]
            side=1
        [/redraw]
    [/event]

    #
    # Secret path 2
    #

    {ITEM_TOUCHPLATE 11 17}

    [event]
        name=moveto
        [filter]
            side=1
            x,y=11,17
        [/filter]

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

        {QUAKE (cave-in.ogg)}

        [terrain]
            x=33   ,34,35-36,36-37,36-35
            y=28-29,29,30   ,31   ,32
            terrain=Urb
        [/terrain]

        [terrain]
            x,y=23,9-10
            terrain=Re
        [/terrain]

        [remove_terrain_overlays]
            x=   34,35,36
            y=29-30,29,28
        [/remove_terrain_overlays]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "Touchplate triggered. A road rises from the depths, and a wall moves."
        [/message]

        [redraw]
            side=1
        [/redraw]
    [/event]

    #
    # Secret room 4 near Mal Keshar's keep
    #

    {CHEST_OF_GOLD 30 18 6}

    [item]
        x,y=20,2
        image=items/chest-plain-closed.png
    [/item]

    [event]
        name=moveto
        [filter]
            side=1
            x,y=20,2
        [/filter]

        [sound]
            name=open-chest.wav
        [/sound]

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

        [item]
            x,y=$x1,$y1
            image=items/chest-plain-open.png
        [/item]

        [redraw][/redraw]

        [message]
            speaker=unit
            message= _ "This chest is empty."
        [/message]
    [/event]
[/scenario]

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


#textdomain wesnoth-Invasion_from_the_Unknown

[scenario]
    id=04_Over_the_Sands
    name= _ "Over the Sands"
    {MAP 04_Over_the_Sands.map}
    {TURNS 63 62 61}
    next_scenario=05a_Crossfire
    victory_when_enemies_defeated=no

    {DEATHS_ACT_1}

    {SCENARIO_MUSIC       "knolls.ogg"} {CONTINUE_PLAYING_STORY_MUSIC_FIRST}
    {EXTRA_SCENARIO_MUSIC "wanderer.ogg"}
    {EXTRA_SCENARIO_MUSIC "nunc_dimittis.ogg"}
    {EXTRA_SCENARIO_MUSIC "revelation.ogg"}

    {STORYTXT_OVER_THE_SANDS}

    {TWO_SUNS_DEFAULT_SCHEDULE}

    {DEHYDRATION_EVENTS}

    {SPAWN_CONTROLLER}

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        team_name=elves
        user_team_name= _ "team_name^Elves"

        shroud=yes
        fog=yes

        {GOLD 120 110 100}
        {INCOME 4 4 3}

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

    [side]
        side=2
        team_name=enemies
        user_team_name= _ "team_name^Orcs"
        {RAGGED_FLAG}

        {GOLD 180 190 220}
        recruit=Orcish Warrior,Wolf Rider,Orcish Archer,Orcish Slayer,Orcish Crossbowman

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

        canrecruit=yes
        type=Orcish Warlord
        id=Karun Baghar
        name= _ "Karun Baghar"
        [modifications]
            {TRAIT_INTELLIGENT}
            {TRAIT_QUICK}
        [/modifications]
        [variables]
            immune_to_dehydration=yes
        [/variables]

        {SIDE_GENERIC_GUARD (Orcish Crossbowman) 77 22}
        {SIDE_GENERIC_GUARD (Orcish Crossbowman) 82 20}
        {SIDE_GENERIC_GUARD (Orcish Crossbowman) 75 17}

        {SIDE_GENERIC_GUARD (Goblin Knight) 74 17}
    [/side]

#define OTS_AVOID_LOCATIONS
    # Try to not move human units to the eastern side of the map.
    {AI_SIMPLE_ALWAYS_ASPECT_VALUE avoid
    (
        x=60-100
        y=1-40
    )}
#enddef

    [side]
        side=3
        team_name=enemies
        user_team_name= _ "team_name^Barbarians"
        {RAGGED_FLAG}

        {GOLD 110 120 140}
        recruit=Thief,Footpad,Poacher

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression 1.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution    0.10}
            {AI_SIMPLE_ALWAYS_ASPECT grouping   no}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "fighter,scout,archer"}
            {OTS_AVOID_LOCATIONS}
        [/ai]

        canrecruit=yes
        type=Huntsman
        id=Garren
        name= _ "Garren"
        [modifications]
            {TRAIT_RESILIENT}
            {TRAIT_STRONG}
        [/modifications]

        {NAMED_GENERIC_UNIT () (Outlaw) 35 32 Jurd   ( _ "Jurd")} {NO_UPKEEP_NO_OVERLAY} {FACING ne} {GUARDIAN} {GENDER male}
        {NAMED_GENERIC_UNIT () (Ranger) 31 38 Urthos ( _ "Urthos")} {NO_UPKEEP_NO_OVERLAY} {FACING ne} {GUARDIAN}

        {SIDE_GENERIC_GUARD (Footpad) 35 36} {FACING ne}
        {SIDE_GENERIC_GUARD (Rogue) 34 34} {FACING ne}

#ifndef EASY
        {SIDE_GENERIC_GUARD (Assassin) 25 31} {FACING se} {GENDER male}
#endif

        {SIDE_GENERIC_GUARD (Thief) 21 33} {GENDER male}
        {SIDE_GENERIC_GUARD (Thief) 25 29} {GENDER female}

        {SIDE_GENERIC_GUARD (Bandit) 28 30}
#ifndef EASY
        {SIDE_GENERIC_GUARD (Bandit) 19 31}
#endif
        {SIDE_GENERIC_GUARD (Thug)   25 33}
        {SIDE_GENERIC_GUARD (Thug)   23 27}
    [/side]

    [side]
        side=4
        team_name=elves
        user_team_name= _ "team_name^Neutral Humans"
        {RAGGED_FLAG}

        {GOLD 180 190 200}
        recruit=Thug,Footpad,Dark Adept,Vampire Bat

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

        canrecruit=yes
        type=Fugitive
        id=Neryan
        name= _ "Neryan"
        gender=female
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_INTELLIGENT}
        [/modifications]

        {SIDE_GENERIC_GUARD (Skeleton Archer) 20 4} {FACING se}
#ifndef EASY
        {SIDE_GENERIC_GUARD (Skeleton Archer) 14 8} {FACING se}
#endif
        {SIDE_GENERIC_GUARD (Skeleton Archer) 17 5} {FACING sw}
        {SIDE_GENERIC_GUARD (Skeleton Archer)  5 6} {FACING se}
        {SIDE_GENERIC_GUARD (Skeleton Archer) 13 3} {FACING sw}

        {SIDE_GENERIC_GUARD (Revenant) 27 11} {FACING sw}
        {SIDE_GENERIC_GUARD (Revenant) 25 16} {FACING se}

        {SIDE_GENERIC_GUARD (Highwayman)  18 8} {FACING se}
#ifndef EASY
        {SIDE_GENERIC_GUARD (Bandit)      15 6} {FACING se}
#endif
        {SIDE_GENERIC_GUARD (Bandit)      8  4} {FACING se}
    [/side]

    [side]
        side=5
        team_name=enemies
        user_team_name= _ "team_name^Desert Creatures"

        hidden=yes
        no_leader=yes

        {NO_ECONOMY}

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

        {SIDE_GENERIC_GUARD (Wolf) 81 28} {FACING se}
        {SIDE_GENERIC_GUARD (Wolf) 80 29} {FACING se}
        {SIDE_GENERIC_GUARD (Wolf) 81 29} {FACING se}

        {SIDE_GENERIC_GUARD (Wolf) 93 26}       {FACING sw}
        {SIDE_GENERIC_GUARD (Great Wolf) 92 25} {FACING sw}

        {SIDE_GENERIC_GUARD (Wolf) 96 12} {FACING sw}
        {SIDE_GENERIC_GUARD (Wolf) 96 11} {FACING sw}
        {SIDE_GENERIC_GUARD (Wolf) 97 12} {FACING sw}

        {SIDE_GENERIC_GUARD (Wolf) 61 27}       {FACING sw}
        {SIDE_GENERIC_GUARD (Wolf) 62 27}       {FACING sw}
        {SIDE_GENERIC_GUARD (Great Wolf) 61 28} {FACING sw}

        {SIDE_GENERIC_GUARD (Direwolf)   82  1} {FACING se}
        {SIDE_GENERIC_GUARD (Wolf)       81  2} {FACING se}
        {SIDE_GENERIC_GUARD (Great Wolf) 86  1} {FACING sw}

        {SIDE_GENERIC_GUARD (Great Wolf) 49 38} {FACING nw}
        {SIDE_GENERIC_GUARD (Great Wolf) 50 38} {FACING nw}
        {SIDE_GENERIC_GUARD (Wolf)       49 39} {FACING nw}

        {SIDE_GENERIC_GUARD (Giant Scorpion) 56 14}
        {SIDE_GENERIC_GUARD (Giant Scorpion) 55 17}
        {SIDE_GENERIC_GUARD (Giant Scorpion) 58 16}

        {SIDE_GENERIC_GUARD (Giant Scorpion) 59  2}
        {SIDE_GENERIC_GUARD (Giant Scorpion) 61  3}
        {SIDE_GENERIC_GUARD (Giant Scorpion) 67  2}
    [/side]

    [side]
        side=6
        team_name=enemies
        user_team_name= _ "team_name^Errant Souls"

        hidden=yes
        no_leader=yes

        {NO_ECONOMY}

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

    {STARTING_VILLAGES 1 4}
    {STARTING_VILLAGES 2 8}

    {PLACE_IMAGE "items/bones.png"           48 24}
    {PLACE_IMAGE "items/bones.png~FL(horiz)" 42 14}
    {PLACE_IMAGE "items/bones.png~FL(horiz)" 63 40}

    {PLACE_IMAGE "scenery/signpost.png" 32 32}

    #
    # Errant Souls
    #

#define OTS_SOUL _RESPAWN_TURNS _X _Y
#ifdef EASY
    {TIMED_DRONE_SPAWNER {_RESPAWN_TURNS} (type=Errant Soul) 6 {_X} {_Y}}
#endif
#ifdef NORMAL
    {TIMED_DRONE_SPAWNER {_RESPAWN_TURNS} (type=Errant Soul,Errant Soul,Errant Soul,Ghost) 6 {_X} {_Y}}
#endif
#ifdef HARD
    {TIMED_DRONE_SPAWNER {_RESPAWN_TURNS} (type=Errant Soul,Errant Soul,Errant Soul,Ghost,Ghost) 6 {_X} {_Y}}
#endif
#enddef

    # NE region
    {OTS_SOUL 6 90  3}
    {OTS_SOUL 6 97  3}
    {OTS_SOUL 6 93  9}
    {OTS_SOUL 6 94  4}
    {OTS_SOUL 6 94  6}
    {OTS_SOUL 6 87  4}

    # Road
    {OTS_SOUL 6 55  6}
    {OTS_SOUL 6 56  9}
    {OTS_SOUL 6 53  8}
    {OTS_SOUL 6 59  8}
    {OTS_SOUL 6 60  5}
    {OTS_SOUL 6 57  7}

    # S oasis
    {OTS_SOUL 6 58 31}
    {OTS_SOUL 6 58 34}
    {OTS_SOUL 6 62 39}
    {OTS_SOUL 6 67 38}
    {OTS_SOUL 6 63 31}
    {OTS_SOUL 6 61 37}

    [event]
        name=prestart

        [deactivate_and_serialize_sides]
            side=3
            variable=late_side_barbarians
        [/deactivate_and_serialize_sides]

        [deactivate_and_serialize_sides]
            side=4
            variable=late_side_neutral
        [/deactivate_and_serialize_sides]

        #
        # Recall heroes
        #

        # wmllint: recognize Anlindë
        {RECALL_ANLINDE_AT    91 35}
        # wmllint: recognize Mal Keshar
        {RECALL_MAL_KESHAR_AT 92 36}

        {ELVISH_SUPPORTER (supporter)}

        {FACE_DIRECTION side=1 nw}

        [remove_shroud]
            side=1
            x=68-101
            y=12-41
        [/remove_shroud]

        {PLAYER_RECRUITMENT_SETUP_FOR_SCENARIO 4}

        {OBJECTIVES (
            {OBJECTIVE_VICTORY ( _ "Defeat the orcs controlling the oasis")}

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

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER}

            {OBJECTIVE_NOTE ( _ "Straying too far from the road is probably not the best thing to do")}
            {OBJECTIVE_NOTE ( _ "Sources of income are very rare in the desert; choose your recruits and recalls carefully")}
            {DEHYDRATION_NOTE}
        )}
    [/event]

    [event]
        name=start

        {LOCK_VIEW}

        [message]
            speaker=Mal Keshar
            message= _ "Ah, the surface! And the sunlight! Scorching hot sand everywhere as usual — how unpleasant."
        [/message]

        [message]
            role=supporter
            message= _ "This environment is even more unfavorable for us than the caves. My lord, there is an oasis north from here. If we want to advance across the sands we will need to make sure our people can rest and replenish supplies there. The problem is..."
        [/message]

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

        [message]
            speaker=Galas
            scroll=no
            message= _ "I heard the rumors already. The oasis appears to be controlled by orcs. Is there any other way through?"
        [/message]

        {HIGHLIGHT_GOAL (x,y=77,19)}

        [message]
            speaker=Mal Keshar
            message= _ "Definitely not, unless your intention is to retrace your steps across the surface... and risk facing the demons again without the tactical advantage of your towers and forests. Small orcish tribes like the one ahead generally lack any proper military discipline. Your forest-loving kin should be able to crush them with ease."
        [/message]

        [message]
            speaker=Galas
            message= _ "That isn’t exactly motivating. They have lived in these sands for an epoch or more. They are not the intruders."
        [/message]

        [message]
            speaker=Anlindë
            message= _ "Galas, if you want to lead our people... you will need to become accustomed to making hard decisions like this. There is much at stake — either the lives of a few orcs who would have no qualms about murdering us in our sleep, or the lives of our civilians and children, and our hope of protecting and rebuilding our civilization."
        [/message]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Galas
            message= _ "I would never choose the orcs’ lives over ours... Let us prepare for the assault, then."
        [/message]

        [message]
            role=supporter
            message= _ "It is only going to become increasingly difficult and expensive to sustain our mounts in this hostile environment. Would that we could replace them with desert beasts."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "If it is your wish to ride sand lions, so be it. I’m sure you won’t mind if I dispatch a few bats and possibly one or two skeletal riders to scout ahead."
        [/message]

        [message]
            speaker=Anlindë
            message= _ "Our agreement did not include allowing you to make use of your foul sorcery in our presence."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Did it include forbidding me from doing so, though?"
        [/message]

        [message]
            speaker=Galas
            message= _ "Let him do as he wishes."
        [/message]

        {ALLOW_RECRUIT 1 ("Skeleton,Skeleton Archer,Skeleton Rider,Ghost,Vampire Bat,Walking Corpse")}

        [transient_message]
            message= _ "You can now recruit undead units.

Elvish units become gradually more expensive to recruit (but not recall) as you progress through scenarios."
        [/transient_message]

        {SHOW_DEHYDRATION_HELP}

        {UNLOCK_VIEW}
    [/event]

    {MAL_KESHAR_1ST_TIME_HELP}

    [event]
        name=side 1 turn 1 end

        # The supporter really shouldn't die before the first turn is over,
        # but one can never be too safe.
        {ELVISH_SUPPORTER (supporter)}

        [message]
            speaker=Anlindë
            message={ASIDE ( _ "Galas, it’s not even midday — has the heat atrophied your senses already?")}
        [/message]

        [message]
            speaker=Galas
            message={ASIDE ( _ "You defeated him once. Surely you could do it again if worst comes to worst. I need to know to what extent we can trust him.")}
        [/message]

        [message]
            role=supporter
            message={ASIDE ( _ "My lord, if you allow me to say so... he is a damned soul, a necromancer! You absolutely cannot place any trust in his words!")}
        [/message]

        [message]
            speaker=Galas
            message={ASIDE ( _ "I need to know his motives for offering us his help. If his intention is to strike us down and raise an army with our corpses, I would rather find out sooner than later.")}
        [/message]
    [/event]

    [event]
        name=turn 2

        [message]
            speaker=Mal Keshar
            # wmllint: local spelling Aaaand
            message= _ "Aaaand, the suns continue their journey through the skies! Hopefully your elves will withstand it long enough to reach the oasis, young leader!"
        [/message]

        {ELVISH_SUPPORTER (supporter)}

        [message]
            role=supporter
            message= _ "Will he ever stop mocking us?"
        [/message]
    [/event]

    #
    # Dialogue about water
    #

    [event]
        name=moveto
        first_time_only=yes
        [filter]
            side=1
            # Any unit with partially or completely uncovered feet
            type=Elvish Druid,Elvish Shyde
            [filter_location]
                terrain=W*
            [/filter_location]
        [/filter]

        [message]
            speaker=unit
            message= _ "female^Ahhh, the refreshing feeling of my feet in the water... I miss our peaceful valley..."
        [/message]
    [/event]

    ############################################################################
    #                                                                          #
    #                                ERRANT SOULS                              #
    #                                                                          #
    ############################################################################

    {FIRE_EVENT_ON_STUMBLE_UPON "found soul" (side=6)}

    [event]
        name=found soul

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

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Galas
            message= _ "Those hostile spirits... Is this a trick of yours, Mal Keshar?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "No. They are corrupted souls who have haunted the desert for an eternity, victims of the destruction that turned Irdya into an endless desert. Physical weapons are of little use against them and they always find a way back — unless, of course, they are banished from our world by spellcasters capable of wielding the arcane fire... or possibly, a necromancer and his minions."
        [/message]

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

    [event]
        name=last breath
        [filter]
            side=6
        [/filter]
        [filter_second]
            side=1
        [/filter_second]
        [filter_second_attack]
            type=arcane
        [/filter_second_attack]

        [message]
            speaker=second_unit
            {UNIT_SPEAKS_FOR_UNDEAD_MINION_STRICT (id=Mal Keshar)}
            message= _ "Return to the darkness from whence you came!"
        [/message]
    [/event]

    [event]
        name=last breath
        first_time_only=no
        [filter]
            side=6
        [/filter]
        [filter_second]
            side=1
        [/filter_second]
        [filter_second_attack]
            type=arcane
        [/filter_second_attack]

        #
        # Bypass the die event defined by the SPAWN_CONTROLLER macro.
        #

        [floating_text]
            [filter]
                x,y=$x1,$y1
            [/filter]
            text=""+_"banished"+"" # wmllint: ignore
        [/floating_text]

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

    ############################################################################
    #                                                                          #
    #                                 ORCS STAGE                               #
    #                                                                          #
    ############################################################################

    {FIRE_EVENT_ON_STUMBLE_UPON "found orc" (side=2)}

    [event]
        name=found orc

        [message]
            speaker=second_unit
            message= _ "Hah, the scouts weren’t hallucinating after all! It’s a party of bold little elves heading for our precious oasis. Go get them!"
        [/message]

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

    [event]
        name=die
        [filter]
            race=orc
        [/filter]
        [filter_second]
            race=undead
        [/filter_second]

        [message]
            speaker=Mal Keshar
            message= _ "Yes, yes, this is more like old times!"
        [/message]
    [/event]

    [event]
        name=attack
        [filter]
            id=Karun Baghar
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [fire_event]
            name=attacked orc leader
        [/fire_event]
    [/event]

    [event]
        name=attack
        [filter_second]
            id=Karun Baghar
        [/filter_second]
        [filter]
            side=1
        [/filter]

        [fire_event]
            name=attacked orc leader
        [/fire_event]
    [/event]

    [event]
        name=attacked orc leader

        [message]
            speaker=Karun Baghar
            message= _ "Elves in my oasis... And you brought a necromancer with you, no less! Begone!"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Karun Baghar
        [/filter]
        [filter_second]
            race=undead
        [/filter_second]

        [message]
            speaker=Mal Keshar
            message= _ "Any last words, orc?"
        [/message]

        [message]
            speaker=Karun Baghar
            message= _ "Damn... you—"
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id=Karun Baghar
        [/filter]

        [if]
            [have_unit]
                x,y=$x2,$y2
                [and]
                    race=bats
                    [or]
                        race=undead
                    [/or]
                [/and]
            [/have_unit]
            [then]
                [message]
                    speaker=Mal Keshar
                    message= _ "The chieftain kept a small hoard of gold in his tent. We shall surely find a use for it."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=second_unit
                    message= _ "The chieftain kept a small hoard of gold in his tent. We shall surely find a use for it."
                [/message]
            [/else]
        [/if]

        {RETRIEVE_GOLD {DIFF 60 55 50} }

        [fire_event]
            name=stage 2
        [/fire_event]
    [/event]

    ############################################################################
    #                                                                          #
    #                                 MAIN STAGE                               #
    #                                                                          #
    ############################################################################

    [event]
        name=stage 2

        {LOCK_VIEW}

        #
        # Create the barbarian scouts
        #

        {NAMED_GENERIC_UNIT 3 (Bandit)   47 24 Aetheran ( _ "Aetheran")} {NO_UPKEEP_NO_OVERLAY} {FACING ne}
        {NAMED_GENERIC_UNIT 3 (Trapper)  45 25 Mur      ( _ "Mur")}      {NO_UPKEEP_NO_OVERLAY} {FACING ne}
        {NAMED_GENERIC_UNIT 3 (Trapper)  46 22 Gaether  ( _ "Gaether")}  {NO_UPKEEP_NO_OVERLAY} {FACING sw}
        {NAMED_GENERIC_UNIT 3 (Fugitive) 45 20 Merghyn  ( _ "Merghyn")}  {NO_UPKEEP_NO_OVERLAY} {FACING ne} {GENDER male}

        [store_starting_location]
            side=2
        [/store_starting_location]

        [remove_terrain_overlays]
            terrain=*^Xo
            x=67-101
            y= 0-41
        [/remove_terrain_overlays]

        [remove_shroud]
            side=1
            x,y=$location.x,$location.y
            radius=16
        [/remove_shroud]

        [redraw]
            side=1
        [/redraw]

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Anlindë
            message= _ "The oasis is ours now, but we may not tarry long. Our people can replenish supplies and grab anything of value left behind by the orcs, but it is imperative that we continue scouting ahead and clearing the path."
        [/message]

        [message]
            speaker=Galas
            message= _ "Is this what we have been reduced to? Looters and scavengers?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "Mal Keshar, where should we head now?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "West."
        [/message]

        [message]
            race=elf
            [not]
                id=Galas,Anlindë
            [/not]
            message= _ "I thought we were supposed to head northwest!"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "First west, then we can resume traveling northwest. The sands north of here are especially unpleasant, with absolutely no sources of water or food for your troops for miles and miles. Your people would surely starve and perish. On the other hand, the sands and mountains to the west are all that stands between us and a river, and then a green valley leading to the very heart of Irdya."
        [/message]

        [message]
            speaker=Galas
            message= _ "The sooner we find land that isn’t completely covered in sand and infested with orcs..."
        [/message]

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

        {CLEAR_VARIABLE location}

        {OBJECTIVES (
            {OBJECTIVE_VICTORY ( _ "Proceed with Galas to the mountain range on the western side of the map")}

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

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER}

            {OBJECTIVE_NOTE ( _ "Straying too far from the road is probably not the best thing to do")}
            {OBJECTIVE_NOTE ( _ "Sources of income are very rare in the desert; choose your recruits and recalls carefully")}
            {DEHYDRATION_NOTE}
        )}

        {UNLOCK_VIEW}
    [/event]

#define OTS_CAPTURE_VILLAGES _SIDE _RADIUS
    [store_starting_location]
        side={_SIDE}
    [/store_starting_location]

    [capture_village]
        x,y=$location.x,$location.y
        radius={_RADIUS}
        side={_SIDE}
    [/capture_village]

    {CLEAR_VARIABLE location}
#enddef

    {FIRE_EVENT_ON_STUMBLE_UPON "found barbarians" (side=3)}

    [event]
        name=found barbarians

        #
        # Activate side 3.
        #

        [unserialize_and_activate_sides]
            side=3
            variable=late_side_barbarians
        [/unserialize_and_activate_sides]

        {CLEAR_VARIABLE late_side_barbarians}

        {OTS_CAPTURE_VILLAGES 3 6}

        [if]
            [have_unit]
                race=elf
                x,y=$x1,$y1
            [/have_unit]
            [then]
                [message]
                    speaker=unit
                    message= _ "Humans ahead. They appear to be bandits— Oh, damn it, they spotted us!"
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Galas
                    message= _ "There are bandits ahead—"
                [/message]
            [/else]
        [/if]

        [message]
            speaker=second_unit
            message= _ "What is this? Are those... elves? Like in the stories?"
        [/message]

        [message]
            speaker=Aetheran
            message= _ "Undead! They have brought the damned spawns of darkness with them!"
        [/message]

        [message]
            speaker=Merghyn
            message= _ "Come on, men, it’s time to smash some bones!"
        [/message]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Galas
            message= _ "I don’t suppose we would make a much better impression without the necromancer’s minions marching amongst us, would we?"
        [/message]

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

        {OBJECTIVES (
            {HEADER_NEW_OBJECTIVES}

            {OBJECTIVE_VICTORY ( _ "Defeat the leader of the barbarians controlling the mountain pass")}

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

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER}

            {OBJECTIVE_NOTE ( _ "Straying too far from the road is probably not the best thing to do")}
            {OBJECTIVE_NOTE ( _ "Sources of income are very rare in the desert; choose your recruits and recalls carefully")}
            {DEHYDRATION_NOTE}
        )}
    [/event]

    [event]
        name=last breath
        [filter]
            id=Garren
        [/filter]
        [filter_second]
            race=elf
        [/filter_second]

        [message]
            speaker=Garren
            message= _ "Damn you... pointy-eared demons... ack—"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Garren
        [/filter]
        [filter_second]
            [not]
                race=elf
            [/not]
        [/filter_second]

        [message]
            speaker=Garren
            message= _ "(spits blood) Go to hell, necromancer... ack—"
        [/message]

        [if]
            [have_unit]
                race=undead
                x,y=$x2,$y2
            [/have_unit]

            [then]
                [message]
                    speaker=Mal Keshar
                    message= _ "Now, don’t make this more difficult than it needs to be. You are a strong man — I would hate to waste your useful build tearing you to pieces before dealing the killing blow."
                [/message]

                [message]
                    speaker=Galas
                    message= _ "Mal Keshar, stop it. You are not allowed to torture our opponents... or... raise them as undead, for that matter."
                [/message]

                [message]
                    speaker=Mal Keshar
                    message= _ "What does it matter? These are merely barbarians. They know no laws and no honor."
                [/message]

                [message]
                    speaker=Anlindë
                    message= _ "Allow him to die in peace."
                [/message]

                [scroll_to_unit]
                    id=Mal Keshar
                [/scroll_to_unit]

                [delay]
                    time=750
                [/delay]

                [message]
                    speaker=Mal Keshar
                    message= _ "Pah, let one of your own finish the job instead. Such a waste."
                [/message]
            [/then]
        [/if]
    [/event]

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

        [fire_event]
            name=stage 3
        [/fire_event]
    [/event]

    [event]
        name=moveto
        first_time_only=yes
        [filter]
            side=1
            x,y=32,32
        [/filter]

        [redraw][/redraw]

        [allow_undo][/allow_undo]

        # wmllint: local spelling Arhaghen

        [message]
            speaker=narrator
            image=scenery/signpost.png
            message= _ "Eisenstone Clan — South Arhaghen Hills Fortress"
        [/message]
    [/event]

    ############################################################################
    #                                                                          #
    #                                FINAL STAGE                               #
    #                                                                          #
    ############################################################################

    [event]
        name=stage 3

        {LOCK_VIEW}

        {REPLACE_SCENARIO_MUSIC "revelation.ogg"}

        #
        # Activate side 4.
        #

        [unserialize_and_activate_sides]
            side=4
            variable=late_side_neutral
        [/unserialize_and_activate_sides]

        {CLEAR_VARIABLE late_side_neutral}

        {OTS_CAPTURE_VILLAGES 4 14}

        [teleport]
            [filter]
                id=Neryan
            [/filter]
            x,y=29,18
        [/teleport]

        [message]
            speaker=Galas
            message= _ "(sighs) Orcs, humans... Would that we weren’t forced to kill everything in our way."
        [/message]

        [message]
            speaker=Neryan
            message= _ "Hey, elves."
        [/message]

        [remove_terrain_overlays]
            terrain=*^Xo
            x=19-34
            y=21-24
        [/remove_terrain_overlays]

        [remove_shroud]
            side=1
            x,y=28,22
            radius=4
        [/remove_shroud]

        [redraw]
            side=1
        [/redraw]

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

        {MOVE_UNIT id=Neryan 28 23}

        [unit]
            type=Highwayman
            x,y=27,23
            side=4
            id=cutscene_bodyguard1
        [/unit]

        [unit]
            type=Bandit
            x,y=29,23
            side=4
            id=cutscene_bodyguard2
        [/unit]

        [unit]
            type=Dark Adept
            gender=male
            x,y=28,22
            side=4
            id=cutscene_bodyguard3
        [/unit]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Neryan
            message= _ "Ha, ha... Great job, disposing of those invaders was taking us a bit too long. Ahhhh... How may we repay you? Where is your leader?"
        [/message]

        [message]
            speaker=Galas
            message= _ "That would be me, lord Galas of the elves of the Valley of Elynia. Your men control this pass, I presume?"
        [/message]

        [message]
            speaker=Neryan
            message= _ "Yes... yes, we do. These lands belong to my people, the Eisenstone clan. We do not normally allow visitors in our territory because of... reasons... but perhaps we could make an exception for you and your advisor."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "(coughs)"
        [/message]

        [message]
            speaker=Neryan
            message= _ "... And the necromancer too, of course. We can provide you with food and water for your soldiers at affordable prices... if you are interested, that is!"
        [/message]

        [message]
            speaker=Galas
            message= _ "Thanks for the offer, but we will need supplies and safe passage for a much larger number of people... through your lands, if you don’t mind."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Neryan
            message= _ "... Lord Galas of the elves! Yes, yes, well... we have heard the rumors. Your people hunt down every human who approaches your sacred valley seeking shelter from the demons... You hunt our species like animals, yes, you do. What makes you think we will allow your army to take our lands and lives now, huh? Isn’t that what you came here for?"
        [/message]

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Galas
            message= _ "Our intentions are not..."
        [/message]

        [modify_side]
            side=4
            team_name=enemies
        [/modify_side]

        [redraw][/redraw]

        [message]
            speaker=Neryan
            message= _ "Enough! If you know what’s good for you and your kind, you will turn back now or leave through the southwestern pass. Come on, men."
        [/message]

        [kill]
            id=cutscene_bodyguard1,cutscene_bodyguard2,cutscene_bodyguard3
        [/kill]

        {MOVE_UNIT id=Neryan 29 18}

        [store_starting_location]
            side=4
        [/store_starting_location]

        [teleport]
            [filter]
                id=Neryan
            [/filter]
            x,y=$location.x,$location.y
        [/teleport]

        {CLEAR_VARIABLE location}

        [redraw][/redraw]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Anlindë
            message= _ "Their intentions are more transparent than they realize — of course they were trying to set a trap for us. Well... Although they have a few necromancers on their side, getting rid of them should be relatively easy."
        [/message]

        [message]
            speaker=Galas
            message= _ "What other options do we have, Mal Keshar?"
        [/message]

        #[remove_terrain_overlays]
        #    terrain=*^Xo
        #    x= 9-17
        #    y=33-40
        #[/remove_terrain_overlays]

        [remove_shroud]
            side=1
            x,y=17,35
            radius=7
        [/remove_shroud]

        [redraw]
            side=1
        [/redraw]

        [scroll_to]
            x,y=13,37
        [/scroll_to]

        [message]
            speaker=Mal Keshar
            scroll=no
            message= _ "The southwestern pass they mentioned, well, it leads to a completely uninhabited plateau, so it is a valid alternative if you want to avoid fighting the humans. Just note that there are barely any sources of water in that direction — your people would only be able to march at night."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Choosing that option would do little good for your popularity after accepting my offer, he, he."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Galas
            message= _ "Well..."

            [option]
                label= _ "Let us confront the humans."
                [command]
                    [message]
                        speaker=Mal Keshar
                        message= _ "Ha ha ha ha ha! I knew you wouldn’t turn down the possibility of a good fight, boy!"
                    [/message]

                    [message]
                        speaker=Galas
                        message= _ "We shall do this on my terms, though. That means: no killing unless strictly necessary, no torturing captured enemies, and no raising corpses. In particular, no harm must come to the clan leader. We may only assume control of their lands temporarily in order to allow our people through."
                    [/message]

                    [message]
                        speaker=Anlindë
                        message= _ "A sound plan, young leader, but... proving a point to those barbarians, is it really worth it?"
                    [/message]

                    [message]
                        speaker=Galas
                        message= _ "Only time will tell for sure."
                    [/message]

                    [fire_event]
                        name=stage 3 setup
                    [/fire_event]

                    {REPLACE_SCENARIO_MUSIC "loyalists.ogg"}
                    {APPEND_MUSIC           "wanderer.ogg"}
                    {APPEND_MUSIC           "breaking_the_chains.ogg"}
                [/command]
            [/option]

            [option]
                label= _ "All this fighting is leading us nowhere. Let us proceed through the southwestern pass."
                [command]
                    [message]
                        speaker=Anlindë
                        message= _ "That is an ill-advised choice, Galas. Proving a point to those barbarians isn’t really worth it."
                    [/message]

                    [message]
                        speaker=Galas
                        message= _ "Only time will tell for sure."
                    [/message]

                    {ENDLEVEL_VICTORY yes} {OVERRIDE_NEXT_SCENARIO 05b_Cursed_Plateau}
                [/command]
            [/option]
        [/message]

        [scroll_to_unit]
            id=Galas
        [/scroll_to_unit]

        {UNLOCK_VIEW}
    [/event]

#define OTS_MAKE_IMMUNE_TO_UNDEAD_SPECIALS _SUF
    [object]
        silent=yes
        [filter]
            {_SUF}
        [/filter]
        [effect]
            apply_to=status
            add=undrainable
        [/effect]
        [effect]
            apply_to=status
            add=unplagueable
        [/effect]
    [/object]
#enddef

    [event]
        name=stage 3 setup

        #
        # Prevent side 4 units from being plagued or drained.
        #

        [store_unit_ids]
            [filter]
                side=4
                race=human
            [/filter]
            variable=side_4_living_units
        [/store_unit_ids]

        [foreach]
            array=side_4_living_units
            [do]
                {OTS_MAKE_IMMUNE_TO_UNDEAD_SPECIALS id=$this_item.id}
            [/do]
        [/foreach]

        {CLEAR_VARIABLE side_4_living_units}

        [event]
            name=prerecruit
            first_time_only=no
            [filter]
                side=4
                race=human
            [/filter]

            {OTS_MAKE_IMMUNE_TO_UNDEAD_SPECIALS x,y=$x1,$y1}
        [/event]

        {OBJECTIVES (
            {HEADER_NEW_OBJECTIVES}

            {OBJECTIVE_VICTORY ( _ "Capture the leader of the Eisenstone clan by reducing her to 0 hitpoints or lower")}

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

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER}

            {OBJECTIVE_NOTE ( _ "Plague and drain weapon specials have no effect on the Eisenstone clan humans for the remainder of this scenario")}
            {OBJECTIVE_NOTE ( _ "Straying too far from the road is probably not the best thing to do")}
            {OBJECTIVE_NOTE ( _ "Sources of income are very rare in the desert; choose your recruits and recalls carefully")}
            {DEHYDRATION_NOTE}
        )}
    [/event]

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

        [message]
            speaker=Neryan
            message= _ "All right, elf lord! You got me and my people... Go ahead and serve us to your starving subjects, what do I care."
        [/message]

        [message]
            speaker=Galas
            message= _ "Of course... It didn’t occur to me that we could deal with our food shortage by feeding upon our prisoners. Sadly, I had a different fate in mind for you and your people, and honestly, I have to wonder where the absurd notion of elves hunting humans for food originated in the first place. Unarye, take this woman and the local necromancers to our camp."
        [/message]

        [hidden_unit]
            # wmllint: recognize Unarye
            {CHARACTER_STATS_UNARYE}
            side=1
            x,y=$x1,$y1
        [/hidden_unit]

        [message]
            speaker=Unarye
            message= _ "Yes, my lord."
        [/message]

        [message]
            speaker=Galas
            message= _ "Let us prepare things for the arrival of our main host."
        [/message]

        [kill]
            id=Unarye,Neryan
        [/kill]

        {ENDLEVEL_VICTORY yes}
    [/event]
[/scenario]

#undef OTS_SOUL
#undef OTS_MAKE_IMMUNE_TO_UNDEAD_SPECIALS
#undef OTS_AVOID_LOCATIONS
#undef OTS_CAPTURE_VILLAGES

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