#textdomain wesnoth-Invasion_from_the_Unknown

[scenario]
    id=05a_Crossfire
    name= _ "Crossfire"
    {MAP 05a_Crossfire.map}
    {TURNS 33 31 30}
    next_scenario=06_The_Moon_Valley
    victory_when_enemies_defeated=no

    {DEATHS_ACT_1}

    {SCENARIO_MUSIC       "loyalists.ogg"}
    {EXTRA_SCENARIO_MUSIC "revelation.ogg"}
    {EXTRA_SCENARIO_MUSIC "wanderer.ogg"}

    {STORYTXT_CROSSFIRE}

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

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

        shroud=yes

        {GOLD 210 200 190}

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

    [side]
        side=2
        team_name=undead
        user_team_name= _ "team_name^Undead"
        {RAGGED_FLAG}

        {GOLD 180 190 200}
        {INCOME 3 5 6}
        {QUANTITY recruit
        (Dark Adept,Skeleton Archer,Walking Corpse,Vampire Bat,Ghost)
        (Dark Adept,Skeleton Archer,Walking Corpse,Vampire Bat,Ghost,Soulless)
        (Dark Adept,Skeleton Archer,Walking Corpse,Vampire Bat,Ghost,Soulless)
        }

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT caution 0.2}

            [goal]
                [criteria]
                    side=1
                [/criteria]
                value=8.0
            [/goal]
            [goal]
                [criteria]
                    side=4
                [/criteria]
                value=6.0
            [/goal]
            [goal]
                [criteria]
                    side=3
                [/criteria]
                value=10.0
            [/goal]
        [/ai]

        canrecruit=yes
        type=Lich
        id=Jan-Belrid
        name= _ "Jan-Belrid"
        facing=ne
        [modifications]
            {TRAIT_UNDEAD}
            {TRAIT_STRONG}
        [/modifications]

        {SIDE_GENERIC_GUARD (Wraith) 27 27} {FACING ne}
        {SIDE_GENERIC_GUARD (Wraith) 31 31} {FACING ne}
        {SIDE_GENERIC_GUARD ({DIFF Wraith Spectre Spectre}) 27 31} {FACING ne}
        # Not guardians
        {SIDE_GENERIC_UNIT (Death Knight) 34 26} {FACING ne}
        {SIDE_GENERIC_UNIT (Deathblade)   35 28} {FACING ne}
        {SIDE_GENERIC_UNIT (Deathblade)   29 26} {FACING ne}
        {SIDE_GENERIC_UNIT (Bone Shooter) 33 27} {FACING ne}
    [/side]

    [side]
        side=3
        team_name=chaos
        user_team_name= _ "team_name^Chaos Empire"
        {CHAOS_FLAG}

        {GOLD 190 200 210}
        {INCOME 3 4 5}
#ifdef EASY
        recruit=Chaos Invoker,Demon,Chaos Invader,Chaos Raider
#else
        recruit=Chaos Invoker,Demon,Demon Zephyr,Chaos Invader,Chaos Raider
#endif

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT caution       0.25}
            {AI_SIMPLE_ALWAYS_ASPECT aggression    0.92}
            {AI_SIMPLE_ALWAYS_ASPECT leader_value  6.0}

            [goal]
                [criteria]
                    id=Mal Keshar
                [/criteria]
                value=8.0
            [/goal]
            [goal]
                [criteria]
                    id=Anlindë
                [/criteria]
                value=9.0
            [/goal]
            [goal]
                [criteria]
                    id=Galas
                [/criteria]
                value=10.0
            [/goal]
        [/ai]

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

        {NAMED_GENERIC_UNIT () (Demon Zephyr) 62 29 Syrith ( _ "Syrith")} {NO_UPKEEP_NO_OVERLAY} {FACING ne} {GENDER female}
        {NAMED_GENERIC_UNIT () (Demon Zephyr) 68 28 Korzan ( _ "Korzan")} {NO_UPKEEP_NO_OVERLAY} {FACING nw} {GENDER male}
        {NAMED_GENERIC_UNIT () (Demon Grunt)  60 27 Layran ( _ "Layran")} {NO_UPKEEP_NO_OVERLAY} {FACING ne} {GENDER female}

        {SIDE_GENERIC_UNIT (Chaos Hound)   62 23} {FACING ne}
        {SIDE_GENERIC_UNIT (Chaos Hound)   68 25} {FACING nw}
        {SIDE_GENERIC_UNIT (Demonic Hound) 59 30} {FACING ne}
    [/side]

    # Outlaws
    [side]
        side=4
        team_name=barbarians
        user_team_name= _ "team_name^Barbarians"
        {RAGGED_FLAG}

        {GOLD 200 210 220}
        {INCOME 3 4 5}
#ifdef EASY
        recruit=Footpad,Poacher,Thug
#else
        recruit=Footpad,Poacher,Thug,Bandit,Ruffian
#endif

        canrecruit=yes
        type=Fugitive
        id=Murlin
        name= _ "Murlin"
        facing=se
        [modifications]
            {TRAIT_QUICK}
            {TRAIT_STRONG}
            [object]
                [effect]
                    apply_to=new_ability
                    [abilities]
                        {ABILITY_REGENERATES4}
                    [/abilities]
                [/effect]
            [/object]
        [/modifications]

#ifndef EASY
        {SIDE_GENERIC_GUARD (Assassin) 21 10} {FACING se}
        {SIDE_GENERIC_GUARD (Assassin) 30  6} {FACING se}
#endif
        # wmllint: recognize Drel
        {NAMED_GENERIC_UNIT () (Highwayman) 34 14 Drel ( _ "Drel")} {NO_UPKEEP_NO_OVERLAY} {FACING nw} {GUARDIAN}

        {SIDE_GENERIC_GUARD (Highwayman) 25 13} {FACING se}
        {SIDE_GENERIC_GUARD (Highwayman) 33  9} {FACING se}

        {SIDE_GENERIC_GUARD (Outlaw) 33 17} {FACING se}
        {SIDE_GENERIC_GUARD (Outlaw) 39 15} {FACING se}

        {SIDE_GENERIC_GUARD (Trapper) 32 15} {FACING se}
        {SIDE_GENERIC_GUARD (Trapper) 36 13} {FACING se}

        {SIDE_GENERIC_UNIT     (Ogre) 32 12} {FACING se}
    [/side]

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

#define XF_OBJECTIVE_COND_HAVE _SUF
    {OBJECTIVE_SHOW_IF (
        [have_unit]
            {_SUF}
        [/have_unit]
    )}
#enddef

    #
    # Don't allow enemy players to kill each other's leaders.
    #

    {FORCE_CHANCE_TO_HIT (
        [not]
            side=1
        [/not]
    ) (
        canrecruit=yes
        [not]
            side=1
        [/not]
    ) 0 ()}

    [event]
        name=prestart

        {VARIABLE ring_awaiting_pickup no}
        {VARIABLE drel_is_dead         no}

        [remove_shroud]
            side=1
            x=18-75
            y= 0-33
        [/remove_shroud]

        #
        # Recall heroes
        #

        # wmllint: recognize Anlindë
        {RECALL_ANLINDE_AT    59  6}
        # wmllint: recognize Mal Keshar
        {RECALL_MAL_KESHAR_AT 64  6}

        #{ELVISH_SUPPORTER (supporter)}

        {FACE_DIRECTION side=1 sw}

        [hide_unit]
            side=1,3
        [/hide_unit]

        {PLAYER_RECRUITMENT_SETUP_FOR_SCENARIO 5}

        {OBJECTIVES (
            {OBJECTIVE_VICTORY ( _ "Make sure no Chaos Empire units survive")} {XF_OBJECTIVE_COND_HAVE side=3}
            {OBJECTIVE_VICTORY ( _ "Destroy Jan-Belrid")}                      {XF_OBJECTIVE_COND_HAVE id=Jan-Belrid}
            {OBJECTIVE_VICTORY ( _ "Defeat the barbarian leader")}             {XF_OBJECTIVE_COND_HAVE id=Murlin}

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

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER}
        )}
    [/event]

    [event]
        name=start

        [message]
            speaker=Murlin
            message= _ "As if we didn’t have enough to worry about with the forest demons roaming about. What is it now, Drel? Another undead incursion?"
        [/message]

        [message]
            speaker=Drel
            message= _ "Yes, brother! It looks like the boys didn’t kill that necromancer quite right."
        [/message]

        [scroll_to_unit]
            id=Jan-Belrid
        [/scroll_to_unit]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Galas
            scroll=no
            message= _ "Drel and Murlin? The Eisenstone folk said they are the true leaders of the bandits. And now both that scum and that hostile lich are standing in our way, damn it."
        [/message]

        [message]
            speaker=Anlindë
            scroll=no
            message= _ "Frankly, I would be more concerned about the encampment to the south."
        [/message]

        [unhide_unit]
            side=3
        [/unhide_unit]

        [message]
            speaker=Falghur
            message= _ "There they are! Onwards, you pathetic vermin! The elves must not be allowed near the Heart Mountains before the Warlord arrives! For the glory of the Chaos Empire!"
        [/message]

        [unhide_unit]
            side=1
        [/unhide_unit]

        [message]
            speaker=Galas
            message= _ "It appears they are better informed of our movements than I imagined. No matter — their current numbers hardly pose a threat to our forces."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Galas
            message= _ "To arms."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Ah, so it is revenge that you seek now?"
        [/message]

        {ALLOW_RECRUIT 1 (Dark Adept)}

        {RECRUITMENT_HINT units/undead-necromancers/adept-magic-3.png
        ( _ "Humans of the sands, impressed with the power and might of the undead, have joined Mal Keshar and have become his apprentices. From now on you may recruit Dark Adepts!")}
    [/event]

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

        [message]
            speaker=Anlindë
            message= _ "Seeing as how every single one of our military leaders has fallen prey to the same thirst for demonic blood as you, Galas, I guess... (sighs) I hope your tactical judgment can still be trusted."
        [/message]

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

    [event]
        name=side 2 turn 1

        [message]
            speaker=Jan-Belrid
            message= _ "Ah, what do we have here? More fresh recruits for my army, yes... yes! The Chaos Empire and their demons have come to visit us! Yes! Such a marvelous occasion!"
        [/message]
    [/event]

    [event]
        name=attack
        [filter]
            side=1
            race=elf
        [/filter]
        [filter_second]
            side=3
        [/filter_second]

        [message]
            speaker=Galas
            message= _ "For our fallen comrades!"
        [/message]

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

    [event]
        name=last breath
        [filter]
            id=Jan-Belrid
        [/filter]

        [message]
            speaker=Jan-Belrid
            message= _ "The cold embrace of death... again..."
        [/message]
    [/event]

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

        [message]
            speaker=Falghur
            message= _ "Quickly, report back to the Warlord— Ack!"
        [/message]
    [/event]

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

        [move_unit_fake]
            side=3
            type=Demon Zephyr
            x=60,58,56
            y=28,30,31
        [/move_unit_fake]

        [redraw][/redraw]

        [delay]
            time=250
        [/delay]

        [message]
            #
            # Try to use an elf other than Galas or Anlindë to speak.
            # In the extremely unlikely case that isn't possible, use
            # Anlindë.
            #
            race=elf
            [not]
                id=Galas,Anlindë
            [/not]
            [or]
                id=Anlindë
            [/or]
            message= _ "One of those wretched creatures is escaping!"
        [/message]

        [message]
            speaker=Galas
            message= _ "It can’t be helped... The winged demons can fly high enough to remain out of our spellcasters’ and archers’ reach."
        [/message]

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

    [event]
        name=die
        first_time_only=no
        [filter]
            side=3
            [or]
                canrecruit=yes
                [not]
                    side=1
                [/not]
            [/or]
        [/filter]

        [if]
            [have_unit]
                side=3
                canrecruit=no
            [/have_unit]
            [not]
                [have_unit]
                    id=Falghur
                [/have_unit]
            [/not]
            #
            # The Chaos leader is dead but there are still Chaos units
            # to kill.
            #
            [then]
                [message]
                    speaker=Galas
                    scroll=no
                    message= _ "Don’t let any more of those fiends escape!"
                [/message]
            [/then]
            [else]
                #
                # Try to fire victory every time.
                #
                # This is done by Murlin's last breath event as well. We never really fire his die event
                # since he gets manually killed by WML first, hence this has to be done manually.
                #

                [fire_event]
                    name=check victory
                [/fire_event]
            [/else]
        [/if]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Drel
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=Drel
            # wmllint: local spelling frien
            message= _ "I won’t be captured by a bunch of forest demons and their skeletal frien— Aaaargh!!!"
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id=Drel
        [/filter]
        [filter_second]
            [not]
                side=1
            [/not]
        [/filter_second]

        {VARIABLE drel_is_dead yes}
    [/event]

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

        [if]
            {VARIABLE_BOOLEAN_EQUALS drel_is_dead yes}
            [then]
                [message]
                    speaker=Murlin
                    message= _ "No! W— Wait! I have something... so— something that could help you on your way! Just... please! Don’t kill me or the rest of us! Please!"
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Murlin
                    message= _ "No! W— Wait! I have something... so— something that could help you on your way! Just... please! Don’t kill me, or my brother, or the rest of us! Please!"
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Mal Keshar
            message= _ "Galas! Oh, leader! What is your decision on the matter of this vile human’s fate?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "Your sardonic remarks aren’t really appreciated, Mal Keshar."
        [/message]

        [message]
            speaker=Galas
            message="" # wmllint: ignore

            [option]
                label= _ "We shall hear your offer as long as you and your people swear to leave and never cause us trouble again."
                [command]
                    [fire_event]
                        name=murlin leaves artifact
                        [primary_unit]
                            x,y=$x1,$y1
                        [/primary_unit]
                    [/fire_event]
                [/command]
            [/option]

            [option]
                label= _ "Men of your ilk cannot be trusted. Any last words?"
                [command]
                    [fire_event]
                        name=murlin is executed
                    [/fire_event]
                [/command]
            [/option]
        [/message]
    [/event]

    [event]
        name=murlin leaves artifact

        [object]
            silent=yes
            [filter]
                id=Murlin
            [/filter]
            [effect]
                apply_to=remove_ability
                [abilities]
                    {ABILITY_REGENERATES4}
                [/abilities]
            [/effect]
        [/object]

        [message]
            speaker=Murlin
            message= _ "I swear! He— Here, take this!"
        [/message]

        [item]
            x,y=$x1,$y1
            image=items/ring-red.png
        [/item]

        #
        # Block victory until the ring is picked up.
        #
        {VARIABLE ring_awaiting_pickup yes}

        [event]
            delayed_variable_substitution=no
            name=moveto
            first_time_only=no
            [filter]
                side=1
                x,y=$x1,$y1
            [/filter]

            [fire_event]
                name=pickup ring of regeneration
                [primary_unit]
                    x,y=$x1,$y1
                [/primary_unit]
            [/fire_event]
        [/event]

        {RETRIEVE_GOLD {DIFF 70 60 50}}

        [message]
            speaker=Galas
            message= _ "You may go now."
        [/message]

        [delay]
            time=250
        [/delay]

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

        [redraw][/redraw]

        {HIGHLIGHT_GOAL x,y=$x1,$y1}

        [message]
            speaker=Anlindë
            message= _ "A ring of regeneration? That would explain why he was able to resist for so long in spite of his frail build. Well, it’s up to you to decide who should take it, Galas."
        [/message]

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

    [event]
        id=ring_regen_ctl
        name=pickup ring of regeneration
        first_time_only=no

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "Do you want this unit to pick up this item?"
            [option]
                label={I18N:YES}
                [command]
                    [object]
                        id=ring_regeneration
                        name= _ "Ring of Regeneration"
                        image=icons/ring-copper.png
                        duration=forever
                        description= _ "This ring heals the bearer by 4 HP each turn unless poisoned, removing the poison effect otherwise. Additionally, the unit’s physical strength is increased, dealing +1 damage with melee weapons and enjoying a permanent +5 HP increase."
                        cannot_use_message= _ "This ring may only be used by living creatures other than beasts or individuals with a close affinity to faerie."
                        [filter]
                            x,y=$x1,$y1
                            side=1
                            race=elf
                            [not]
                                type=Elvish Civilian,Elvish Shaman,Elvish Druid,Elvish Shyde,Elvish Sorceress,Elvish Enchantress,Elvish Sylph
                            [/not]
                            [not]
                                id=Anlindë
                            [/not]
                        [/filter]
                        [effect]
                            apply_to=new_ability
                            [abilities]
                                {ABILITY_REGENERATES4}
                            [/abilities]
                        [/effect]
                        [effect]
                            apply_to=attack
                            range=melee
                            increase_damage=1
                        [/effect]
                        [effect]
                            apply_to=hitpoints
                            increase_total=5
                            heal_full=yes
                        [/effect]
                        [then]
                            [remove_item]
                                x,y=$x1,$y1
                            [/remove_item]

                            {VARIABLE ring_awaiting_pickup no}

                            [fire_event]
                                name=check victory
                            [/fire_event]

                            #
                            # Never run this handler again.
                            #
                            [remove_event]
                                id=ring_regen_ctl
                            [/remove_event]
                        [/then]
                    [/object]
                [/command]
            [/option]
            [option]
                label={I18N:NO}
                [command]
                    [allow_undo][/allow_undo]
                [/command]
            [/option]
        [/message]
    [/event]

    [event]
        name=murlin is executed

        [message]
            speaker=Murlin
            message= _ "Fools! You are no better than the hounds of the Chaos Empire! You—"
        [/message]

        [kill]
            id=Murlin
            animate=yes
            fire_event=no
        [/kill]

        [redraw][/redraw]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Mal Keshar
            message= _ "Ah, well. You cannot make friends with every sand-dweller, Galas!"
        [/message]

        {RETRIEVE_GOLD {DIFF 90 80 70}}

        [fire_event]
            name=check victory
        [/fire_event]
    [/event]

    [event]
        name=check victory
        [filter_condition]
            {VARIABLE_BOOLEAN_EQUALS ring_awaiting_pickup no}
            [not]
                [have_unit]
                    side=3
                [/have_unit]
            [/not]
            [not]
                [have_unit]
                    canrecruit=yes
                    [not]
                        side=1
                    [/not]
                [/have_unit]
            [/not]
        [/filter_condition]

        {ENDLEVEL_VICTORY yes}
    [/event]

    [event]
        name=attack end
        [filter]
            race=undead
        [/filter]
        [filter_second]
            race=undead
        [/filter_second]

        [message]
            speaker=Galas
            scroll=no
            message= _ "Elves using the undead to fight the undead..."
        [/message]
    [/event]

    [event]
        name=victory

        {LOCK_VIEW}

        [message]
            speaker=Galas
            message= _ "It is all over, at last. Mal Keshar, those mountains...?"
        [/message]

        [scroll_to]
            x,y=15,7
        [/scroll_to]

        [message]
            speaker=Mal Keshar
            scroll=no
            message= _ "Our destination is close, Galas. You shall see soon enough."
        [/message]

        [kill]
            [not]
                side=1
            [/not]
        [/kill]

        {ELVISH_SUPPORTER supporter}

        [hide_unit][/hide_unit]

        {FADE_TO_BLACK}

        [place_shroud]
            side=1
        [/place_shroud]

        [redraw]
            side=1
        [/redraw]

        [fade_out_music][/fade_out_music]

        [scroll_to]
            x,y=8,13
            {WARP}
        [/scroll_to]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "The group rested for a while before continuing. After passing through the mountain wall west of the river’s keep, they were surprised to see fully-grown plants and animals again. They had left the desert."
        [/message]

        [delay]
            time=750
        [/delay]

        {FADE_IN}

        [remove_shroud]
            side=1
        [/remove_shroud]

        {MODIFY_UNIT (
            id=Galas,Mal Keshar,Anlindë
            [or]
                role=supporter
            [/or]
        ) facing sw}

        [teleport]
            [filter]
                id=Galas
            [/filter]
            x,y=8,13
        [/teleport]

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

        [teleport]
            [filter]
                id=Anlindë
            [/filter]
            x,y=9,13
        [/teleport]

        [teleport]
            [filter]
                role=supporter
            [/filter]
            x,y=8,12
        [/teleport]

        [unhide_unit][/unhide_unit]

        [redraw]
            side=1
        [/redraw]

        {REPLACE_SCENARIO_MUSIC elvish-theme.ogg}

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Galas
            message= _ "Everything in the distance seems so lush and alive!"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "It’s beautiful."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            role=supporter
            message= _ "Would that we could stay in these lands forever and make them our new home."
        [/message]

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Galas
            message= _ "The Chaos Empire lies south of here. (sighs) We had such an uplifting victory... Do we really need to find those two heroes to forge a new future for our race? Perhaps we have been merely misled by our misfortune and the grim stories told by the Eisenstone humans... We could find the ocean and sail towards the horizon and then..."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "... The Chaos humans and their demonic allies would find you one way or another."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Mal Keshar
            message= _ "The Moon Valley is only a few days away from us, young Galas!"
        [/message]

        [message]
            speaker=Galas
            message= _ "I know, I know..."
        [/message]

        {CLEAR_VARIABLE ring_awaiting_pickup,drel_is_dead}
    [/event]
[/scenario]

#undef XF_OBJECTIVE_COND_HAVE

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


#textdomain wesnoth-Invasion_from_the_Unknown

[scenario]
    id=05b_Cursed_Plateau
    name= _ "Cursed Plateau"
    {MAP 05b_Cursed_Plateau.map}
    {TURNS 60 56 52} # NOTE: turn limit must be divisible by 4 (see prestart)
    next_scenario=06_The_Moon_Valley
    victory_when_enemies_defeated=no

    {DEATHS_ACT_1}

    {SCENARIO_MUSIC       "nunc_dimittis.ogg"}
    {EXTRA_SCENARIO_MUSIC "revelation.ogg"}
    {EXTRA_SCENARIO_MUSIC "into_the_shadows.ogg"}

    {STORYTXT_CURSED_PLATEAU}

    {NEUTRAL_TOD}

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

        shroud=yes
        fog=yes

        {GOLD 210 200 190}

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

    [side]
        side=2
        team_name=evil
        user_team_name= _ "team_name^Chaos Empire"
        {CHAOS_FLAG}

        hidden=yes
        {GOLD 100 125 130}
        {INCOME 1 2 3}
        recruit=Chaos Invoker,Chaos Invader,Chaos Headhunter

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression             0.95}
            {AI_SIMPLE_ALWAYS_ASPECT caution                0.10}
        [/ai]

        canrecruit=yes
        type=Chaos Razerman
        id=Igrim-Gaher
        name= _ "Igrim-Gaher"
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_INTELLIGENT}
        [/modifications]

        {SIDE_GENERIC_GUARD (Dark Knight) 40 32} {FACING nw}

        {SIDE_GENERIC_GUARD (Doom Guard) 38 12} {FACING se}
        {SIDE_GENERIC_GUARD (Doom Guard) 41 12} {FACING sw}

        {SIDE_GENERIC_GUARD (Chaos Invoker)    25 15}
        {SIDE_GENERIC_GUARD (Chaos Headhunter) 26 17}
        {SIDE_GENERIC_GUARD (Chaos Headhunter) 27 19}
        {SIDE_GENERIC_GUARD (Chaos Invader)    23 18}
        {SIDE_GENERIC_GUARD (Chaos Invader)    19 18}

        {SIDE_GENERIC_GUARD (Chaos Invader)    21 23}
        {SIDE_GENERIC_GUARD (Chaos Raider)     24 23}

        {SIDE_GENERIC_GUARD (Chaos Raider)     27 30}
    [/side]

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

        hidden=yes
        no_leader=yes
        {NO_ECONOMY}
        # This is intentionally a red herring side with an unreachable leader
        # and initially-controlled villages.
        defeat_condition=never

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

        {SIDE_GENERIC_GUARD (Psy Crawler) 49 35}
        {SIDE_GENERIC_GUARD (Psy Crawler) 34 28}

        {SIDE_GENERIC_GUARD (Psy Crawler) 44 16}
        {SIDE_GENERIC_GUARD (Psy Crawler) 36 10}
        {SIDE_GENERIC_GUARD (Psy Crawler) 43  5}
        {SIDE_GENERIC_GUARD (Psy Crawler) 30 11}
        {SIDE_GENERIC_GUARD (Psy Crawler)  3 45}
    [/side]

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

        hidden=yes
        gold=0
        {INCOME 2 4 5}
        recruit=Shadow Minion,Vampire Bat,Chaos Invader,Chaos Bowman,Psy Crawler,Demon Zephyr

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression             1.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution                0.25}

            {AI_RECRUITMENT_ALWAYS_ASPECT ({AI_RECRUIT_LIMIT "Chaos Bowman" 3})}
        [/ai]

        canrecruit=yes
        type=Shadow Courier
        id=Isselial
        name= _ "Isselial"
        [modifications]
            {TRAIT_RESILIENT}
            {TRAIT_QUICK}
        [/modifications]

        {SIDE_GENERIC_GUARD (Demon Zephyr) 35  7} {FACING se}
        {SIDE_GENERIC_GUARD (Demon Zephyr) 42 14} {FACING sw}

        {SIDE_GENERIC_GUARD (Chaos Crossbowman) 19 25}
        {SIDE_GENERIC_GUARD (Chaos Bowman)      18 22}
        {SIDE_GENERIC_GUARD (Chaos Bowman)      23 29}
    [/side]

    [side]
        side=5
        team_name=evil
        user_team_name= _ "team_name^Cave Creatures"
        {RAGGED_FLAG}

        hidden=yes
        no_leader=yes
        {NO_ECONOMY}

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

        {SIDE_GENERIC_GUARD ({DIFF (Blood Bat) (Dread Bat) (Dread Bat)})  3 53}

        {SIDE_GENERIC_GUARD (Vampire Bat)  4 51}
        {SIDE_GENERIC_GUARD (Vampire Bat)  5 54}

        {SIDE_GENERIC_GUARD (Vampire Bat) 47 20}
        {SIDE_GENERIC_GUARD (Vampire Bat) 43 17}
        {SIDE_GENERIC_GUARD (Vampire Bat) 42  8}
        {SIDE_GENERIC_GUARD (Vampire Bat) 43  4}
        {SIDE_GENERIC_GUARD (Vampire Bat) 19  4}
        {SIDE_GENERIC_GUARD (Vampire Bat) 19  5}
        {SIDE_GENERIC_GUARD (Vampire Bat) 18  4}
        {SIDE_GENERIC_GUARD (Vampire Bat) 21 13}

        {SIDE_GENERIC_GUARD (Vampire Bat) 51 32}
        {SIDE_GENERIC_GUARD (Blood Bat)   40 34}
        {SIDE_GENERIC_GUARD (Vampire Bat) 41 31}

        {SIDE_GENERIC_GUARD (Vampire Bat) 51 42}
        {SIDE_GENERIC_GUARD (Vampire Bat) 20 54}
        {SIDE_GENERIC_GUARD (Vampire Bat) 20 44}
        {SIDE_GENERIC_GUARD (Blood Bat)   20 42}
        {SIDE_GENERIC_GUARD (Vampire Bat) 17 44}

        {SIDE_GENERIC_GUARD (Giant Scorpion) 17 17}
        {SIDE_GENERIC_GUARD (Giant Scorpion) 27 28}
        {SIDE_GENERIC_GUARD (Giant Scorpion) 12 37}
        {SIDE_GENERIC_GUARD (Giant Scorpion) 13 40}

        {SIDE_GENERIC_GUARD (Giant Scorpion) 23 53}
        {SIDE_GENERIC_GUARD (Giant Scorpion) 27 41}
    [/side]

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

    {ITEM_TOUCHPLATE                          7 50}

    {PLACE_IMAGE items/parchment.png         13 58}
    {PLACE_IMAGE items/gold-coins-medium.png 48 34}
    {PLACE_IMAGE items/gold-coins-medium.png 43  4}
    {PLACE_IMAGE items/gold-coins-small.png  48 20}

    {PLACE_IMAGE items/burial.png            34 13}
    {PLACE_IMAGE items/burial.png            32 15}
    {PLACE_IMAGE items/burial.png            20 31}
    {PLACE_IMAGE items/burial.png            23 35}
    {PLACE_IMAGE items/burial.png             9  5}
    {PLACE_IMAGE items/burial.png            10  8}

    {PLACE_IMAGE items/bonestack.png         42 28}
    {PLACE_IMAGE items/bonestack.png         38  9}
    {PLACE_IMAGE items/bonestack.png         20  5}

    {PLACE_IMAGE scenery/rock-cairn.png      41 14}

    {PLACE_IMAGE items/altar-evil.png        35  8}

    {PLACE_IMAGE "items/bones.png~FL()"      25 40}
    {PLACE_IMAGE items/bones.png              9 28}
    {PLACE_IMAGE items/bones.png             18 16}

    {PLACE_IMAGE scenery/trash.png           20 10}
    {PLACE_IMAGE scenery/trash.png            6 26}

    # Magic circle WML by zookeeper
    [terrain_graphics]
        # Center coordinates relative to map grid
        x=6
        y=26
        [tile]
            x=0
            y=0
            set_flag=circle
        [/tile]
    [/terrain_graphics]
    [terrain_graphics]
        map="
, *
* , *
, 1
* , *
, *"
        [tile]
            pos=1
            has_flag=circle
        [/tile]
        [image]
            layer=0
            center=90,144
            # wmlscope: start ignoring
            name="../scenery/circle-magic.png"
            # wmlscope: stop ignoring
        [/image]
    [/terrain_graphics]

#define CUP_END_AREA_SLF
    x=1-13
    y=1-14
#enddef

    [event]
        name=prestart

        {VARIABLE keys_acquired   0}
        {VARIABLE acquired_secret no}

        [time_area]
            {UNDERGROUND}
            # Not Q*^X*, those are surface cliffs
            terrain=Cu*,Ku*,W*,R*,R*^*,U*,U*^*,Y*,Y*^*,Q*,Q*^*,Xu*
            [not]
                terrain=Q*^X*,Rd,Rd^*
            [/not]
            [not]
                {CUP_END_AREA_SLF}
                terrain=R*,R*^*
            [/not]
            [not]
                # Starting keep for side 1
                x,y,radius=39,51,6
            [/not]
            [not]
                # Secret passage B
                x= 6,    5
                y=18,19-21
            [/not]
        [/time_area]

        #
        # Generate uniform time schedule for the current turn limit.
        #

        [set_variables]
            name=cup_schedule
            mode=replace
            [literal]
                # Skeleton for a [replace_schedule] command.
                current_time=0
                [template]
                    {LONGDARK1}
                    {LONGDARK2}
                    {LONGDARK3}
                    {LONGDARK4}
                [/template]
            [/literal]
        [/set_variables]

        [store_turns][/store_turns]

        {VARIABLE turns_are_even "$($turns % 4)"}

        {BUG_ON ({VARIABLE_NUMERICAL_NOT_EQUALS turns_are_even 0}) ()}
        {BUG_ON ({VARIABLE_NUMERICAL_LESS_THAN_OR_EQUAL turns $cup_schedule.template.time.length}) ()}

        {VARIABLE repeat_times "$($turns / 4)"}

        #{LOG_IFTU "ToD length $repeat_times over $turns turns"}

        [foreach]
            array=cup_schedule.template.time
            [do]
                [repeat]
                    times=$repeat_times
                    [do]
                        [set_variables]
                            name=cup_schedule.time
                            mode=append
                            to_variable=this_item
                        [/set_variables]
                    [/do]
                [/repeat]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE cup_schedule.template}

        [insert_tag]
            name=replace_schedule
            variable=cup_schedule
        [/insert_tag]

        {CLEAR_VARIABLE cup_schedule,repeat_times,turns_are_even,turns}

        # wmllint: recognize Anlindë
        {RECALL_ANLINDE_AT    39 50}
        # wmllint: recognize Mal Keshar
        {RECALL_MAL_KESHAR_AT 38 51}

        {ELVISH_SUPPORTER (supporter)}

        {FACE_DIRECTION side=1 nw}

        {PLAYER_RECRUITMENT_SETUP_FOR_SCENARIO 5}

        {OBJECTIVES (
            {OBJECTIVE_VICTORY ( _ "Galas, Anlindë, or Mal Keshar must reach the northwest corner of the map")}

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

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER_NO_BONUS}
        )}
    [/event]

    [event]
        name=start

        [message]
            speaker=Galas
            message= _ "(shivering slightly) I’m beginning to regret my choice. It gets colder and darker the further we proceed, and our people are nearly starving."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "It is far too late to turn back, young leader! Besides, we are mere hours away from the edge of the plateau, if I’m not mistaken. "
        [/message]

        [message]
            speaker=Galas
            message= _ "Hard to tell with this fog. Incidentally, are you absolutely certain there is nothing we can do about that, Anlindë?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "I would greatly prefer if our spell casters saved their energies for fending off any hostile creatures we may come across—"
        [/message]

        [sound]
            name={SOUND_LIST:BIOMECHANICAL_ROAM}
        [/sound]

        [message]
            speaker=Galas
            message= _ "Well, I don’t recognize that creature, but it sure sounded hostile to me! Shall we keep moving?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "I support the motion..."
        [/message]

        {ALLOW_RECRUIT 1 (Dark Adept)}

        {RECRUITMENT_HINT units/undead-necromancers/adept-magic-3.png
        ( _ "Humans of the sands, impressed with the power and might of the undead, have joined Mal Keshar and have become his apprentices. From now on you may recruit Dark Adepts!")}
    [/event]

    [event]
        name=side 2 turn 1 end

        [message]
            role=supporter
            message= _ "Sir, our scouts report human settlements ahead. Judging by their banners and equipment, they must be forces loyal to that so-called Chaos Empire."
        [/message]

        [message]
            speaker=Anlindë
            message= _ "Mal Keshar, you did not say at any point that we were walking straight into enemy territory!"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Huh? Indeed, I did not. This region was completely uninhabited last time my minions surveyed it."
        [/message]

        [message]
            speaker=Anlindë
            message= _ "And when... exactly... was that?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "... A hundred years ago, perhaps? It’s hard to tell when you have dwelt underground for thousands of years in solitude— Why are you looking at me like that?"
        [/message]

        [message]
            role=supporter
            message= _ "Thus far our evidence suggests it’s but a border outpost manned by a skeleton crew. Personally, I doubt they will prove to be little more than a minor nuisance."
        [/message]

        [message]
            speaker=Galas
            message= _ "If you say so. Backtracking at this point might not be the wisest choice, after all."
        [/message]

        [modify_side]
            side=2,4
            hidden=no
        [/modify_side]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x=1-100
            y=1-38
        [/filter]

        [event]
            name=side 1 turn end

            [message]
                speaker=Isselial
                message= _ "The elves from the desert sanctuary are intruding in our domain? Then what are you waiting for, fools? Get them!"
            [/message]

            [unit]
                side=4
                placement=leader
                type=Chaos Heavy Longbowman
                id=Skaellar
                name= _ "Skaellar"
                upkeep=free
                [modifications]
                    {TRAIT_RESILIENT}
                    {TRAIT_QUICK}
#ifdef EASY
                    {BOSS_BOOST 20% 0 0 1 0}
#else
                    {BOSS_BOOST 40% 1 0 1 1}
#endif
                [/modifications]
            [/unit]

            [message]
                speaker=Skaellar
                message= _ "As you command, sir."
            [/message]

            {NAMED_GENERIC_UNIT 4 (Demon Grunt)   () () Erighael ( _ "Erighael")} {PLACEMENT leader} {NO_UPKEEP_NO_OVERLAY} {GENDER male}
            {NAMED_GENERIC_UNIT 4 (Demon Warrior) () () Zillias  ( _ "Zillias")}  {PLACEMENT leader} {NO_UPKEEP_NO_OVERLAY} {GENDER male}
            {NAMED_GENERIC_UNIT 4 (Demon Zephyr)  () () Avalis   ( _ "Avalis")}   {PLACEMENT leader} {NO_UPKEEP_NO_OVERLAY} {GENDER male}
#ifndef EASY
            {NAMED_GENERIC_UNIT 4 (Hellhound)     () () Ker      ( _ "Ker")}      {PLACEMENT leader} {NO_UPKEEP_NO_OVERLAY}
#endif

            {ADD_GOLD 4 175 200 225}
            {ADD_GOLD 2 100 120 140}

            [disallow_recruit]
                side=2
                type=Chaos Invoker
            [/disallow_recruit]

            [allow_recruit]
                side=2
                type=Psy Crawler
            [/allow_recruit]

            [modify_side]
                side=4
                {INCOME 3 4 5}
            [/modify_side]
        [/event]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            type=Vampire Bat,Blood Bat,Dread Bat,Ghost,Wraith,Spectre,Shadow,Nightgaunt
            [filter_location]
                time_of_day_id=long_dark1,long_dark2,long_dark3,long_dark4
                [filter_adjacent_location]
                    terrain=Q*^X*
                [/filter_adjacent_location]
            [/filter_location]
        [/filter]

        [message]
            speaker=Galas
            message= _ "Mal Keshar, why are your bats and spirits being completely useless around these cliffs? We need to cover as much ground as possible and you aren’t precisely helping."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Have you ever tried flying during a storm? Perhaps you should give that a try one day so you learn to leave these things to me instead of spouting orders like a spoiled brat."
        [/message]

        [message]
            speaker=Galas
            message= _ "... Fair enough."
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            type=Psy Crawler
        [/filter]

        [message]
            speaker=second_unit
            {UNIT_SPEAKS_FOR_UNDEAD_MINION (id=Mal Keshar)}
            message= _ "What was that thing?"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Igrim-Gaher
        [/filter]

        [message]
            speaker=Igrim-Gaher
            message= _ "Why... Yechnagoth will avenge me! Just you wait— Ack—"
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            [filter_location]
                x,y,radius=31,8,5
            [/filter_location]
        [/filter]

        [message]
            speaker=Isselial
            message= _ "Y— you dare step on s— sacred soil! You sh— shall pay dearly for this t— transgression, unworthy heathens!"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Not if we take you out first!"
        [/message]
    [/event]

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

        [message]
            speaker=Isselial
            message= _ "N— no... M— my project... incomplete... F— forgive me, Uria..."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x,y=43,4
        [/filter]

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

        {RETRIEVE_GOLD {DIFF 90 80 70}}
    [/event]

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

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

        {RETRIEVE_GOLD {DIFF 50 40 25}}
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x,y=48,34
        [/filter]

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

        {RETRIEVE_GOLD {DIFF 84 72 65}}
    [/event]

    ############################################################################
    #                                                                          #
    #                      SECRET GATE KEY CONTROL EVENTS                      #
    #                                                                          #
    ############################################################################

    [event]
        name=die
        first_time_only=no
        [filter]
            canrecruit=yes
            [not]
                side=1
            [/not]
        [/filter]

        {VARIABLE x $x1}
        {VARIABLE y $y1}

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

        {PLACE_IMAGE items/key.png $x $y}

        [switch]
            variable=keys_acquired
            [case]
                value=0
                [message]
                    speaker=second_unit
                    {UNIT_SPEAKS_FOR_UNDEAD_MINION (id=Mal Keshar)}
                    message= _ "What is this? It looks like he was carrying a key."
                [/message]
            [/case]
            [case]
                value=1
                [message]
                    speaker=second_unit
                    {UNIT_SPEAKS_FOR_UNDEAD_MINION (id=Mal Keshar)}
                    message= _ "I found another key!"
                [/message]
            [/case]
            [else]
                [transient_message]
                    message="Winners don’t use cheats." # wmllint: ignore
                [/transient_message]
            [/else]
        [/switch]

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

        [transient_message]
            caption= _ "Rusted Key"
            image=icons/key_silver.png
            message= _ "A key, presumably for a gate somewhere around."
        [/transient_message]

        {VARIABLE_INC keys_acquired}

        {CLEAR_VARIABLE x,y}
    [/event]

    #
    # Secret passage A
    #

    [event]
        name=moveto
        [filter]
            side=1
            x,y=7,50
        [/filter]

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

        [terrain]
            x,y=6,50
            terrain=Re
        [/terrain]

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

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

    [event]
        name=moveto
        [filter]
            side=1
            x,y=13,58
        [/filter]

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

        [remove_terrain_overlays]
            x,y=8,17
        [/remove_terrain_overlays]

        [message]
            speaker=unit
            {UNIT_SPEAKS_FOR_UNDEAD_MINION (id=Mal Keshar)}
            message= _ "It’s an old parchment, with a crudely-drawn map on it. It appears to point to a location north from here."
        [/message]

        [remove_shroud]
            side=1
            x,y,radius=8,17,2
        [/remove_shroud]

        {CLEAR_FOG 1  8 17 2}

        [redraw]
            side=1
        [/redraw]

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

        {HIGHLIGHT_GOAL x,y=8,17}

        [message]
            scroll=no
            speaker=unit
            {UNIT_SPEAKS_FOR_UNDEAD_MINION (id=Mal Keshar)}
            message= _ "Interesting."
        [/message]

        {UNCLEAR_FOG}

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

    #
    # Secret passage B
    #

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

        [switch]
            variable=keys_acquired
            [case]
                value=0
                [message]
                    speaker=unit
                    {UNIT_SPEAKS_FOR_UNDEAD_MINION (id=Mal Keshar)}
                    message= _ "This metal gate glimmers with a magical force that will not let me force it open. There are two keyholes on it. Should we search for the keys? On the other hand, I can hear strange sounds coming from below... Perhaps we should just leave it be."
                [/message]
            [/case]
            [case]
                value=1
                [message]
                    speaker=unit
                    {UNIT_SPEAKS_FOR_UNDEAD_MINION (id=Mal Keshar)}
                    message= _ "This metal gate glimmers with a magical force that will not let me force it open. There are two keyholes on it. The one key we have in our possession seems to fit in neatly, but it doesn’t seem enough to unlock the gate. Should we search for the other key? On the other hand, I can hear strange sounds coming from below... Perhaps we should just leave it be."
                [/message]
            [/case]
            [else]
                [message]
                    speaker=unit
                    {UNIT_SPEAKS_FOR_UNDEAD_MINION (id=Mal Keshar)}
                    message= _ "This metal gate glimmers with a magical force that will not let me force it open. There are two keyholes on it. Both of the keys in our possession fit right in, so I should be able to unlock the gate. On the other hand, I can hear strange sounds coming from below... Perhaps we should just leave it be."
                [/message]
            [/else]
        [/switch]

        [message]
            speaker=Anlindë
            message= _ "I wonder what manner of hideous creature those miscreants might be keeping inside. Perhaps it’s worth investigating."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x,y=5,21
        [/filter]
        [filter_condition]
            {VARIABLE_NUMERICAL_GREATER_THAN_OR_EQUAL keys_acquired 2}
        [/filter_condition]

        [message]
            speaker=unit
            {UNIT_SPEAKS_FOR_UNDEAD_MINION (id=Mal Keshar)}
            message= _ "All right, let us see what it is they are hiding in here."
        [/message]

        [message]
            speaker=narrator
            sound=gate.ogg
            image=wesnoth-icon.png
            message= _ "The gate is unlocked."
        [/message]

        [remove_terrain_overlays]
            x,y=5,22
        [/remove_terrain_overlays]

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

    # Ambience.

    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            x= 1-11
            y=22-33
        [/filter]

        [lua]
            code=<<
                local rumble_seed = unsynced_random(1, 100)

                if rumble_seed % 23 == 0 then -- 4.34% chance
                    wesnoth.wml_actions.sound { name = (...).sound }
                end
            >>
            [args]
                sound={SOUND_LIST:BIOMECHANICAL_ROAM}
            [/args]
        [/lua]

        [allow_undo][/allow_undo]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            [filter_location]
                x,y,radius=6,26,1
            [/filter_location]
        [/filter]

        [allow_undo][/allow_undo]

        [message]
            speaker=unit
            {UNIT_SPEAKS_FOR_UNDEAD_MINION (id=Mal Keshar)}
            message= _ "A magic circle, apparently used not very long ago. There are ashes and charred bones from a creature I can’t identify, at the center. We probably should leave that alone."
        [/message]
    [/event]

    #
    # The secret item.
    #

    # wmlindent: start ignoring

    {PICK_UP (items/chest-plain-closed.png)  8 32
    (type=Elvish Hunter,Elvish Trapper,Elvish Prowler,Elvish Fighter,Elvish Hero,Elvish Champion,Elvish Captain,Elvish Marshal)
    ( _ "There is a chest with a note in it, as well as a chain weapon with two weighty ends— Woah! They are surprisingly hot to the touch! According to the note, this artifact used to belong to a powerful priest who imbued it with fire magic and wielded it against the Chaos Empire’s forces before his defeat. By the looks of it, no-one else ever tried wielding it in combat again. Perhaps we should hand it to one of our finest hunters or fighters and see if they can figure out how to use it effectively.")
    ( _ "I am not suited to use this weapon! Let someone else pick it up.")
    (
        {VARIABLE acquired_secret yes}

        [object]
            image=attacks/meteor-hammer.png
            duration=forever
            name= _ "Shardia’s Meteor"
            description= _ "This legendary chain-and-ball weapon was imbued with a powerful ever-burning flame which strikes fear into the hearts of lesser creatures, reducing their effectiveness in combat. Additionally, it increases the wielder’s resistance to fire damage by 20%."
            [filter]
                x,y=$x1,$y1
            [/filter]
            [effect]
                apply_to=new_ability
                [abilities]
                    {ABILITY_INTIMIDATES}
                [/abilities]
            [/effect]
            [effect]
                apply_to=resistance
                replace=false
                [resistance]
                    fire=-20
                [/resistance]
            [/effect]
            [effect]
                apply_to=new_attack
                name=meteor hammer
                description= _ "shardia’s meteor"
                icon=attacks/meteor-hammer.png
                type=fire
                range=ranged
                damage=15
                number=2
                [specials]
                    {WEAPON_SPECIAL_FIRSTSTRIKE}
                    {WEAPON_SPECIAL_SLOW}
                [/specials]
            [/effect]
            [effect]
                apply_to=new_animation
                [attack_anim]
                    [filter_attack]
                        name=meteor hammer
                    [/filter_attack]

                    {MISSILE_FRAME_BOLAS}

                    start_time=-300
                    [if]
                        hits=yes
                        [frame]
                            duration=100
                            sound=hatchet.wav
                        [/frame]
                        [frame]
                            duration=100
                        [/frame]
                        [frame]
                            duration=50
                            sound=mace.wav
                        [/frame]
                        [frame]
                            duration=100
                            sound=torch.ogg
                        [/frame]
                    [/if]
                    [else]
                        hits=no
                        [frame]
                            duration=275
                            sound=hatchet-miss.wav
                        [/frame]
                        [frame]
                            duration=100
                            sound=torch-miss.ogg
                        [/frame]
                    [/else]
                [/attack_anim]
            [/effect]
            [then]
                # wmllint: local spelling Eäroldil
                [message]
                    speaker=unit
                    message= _ "It’s somewhat heavier than the weapons we used to train with before Eäroldil’s accident, but I think I will manage somehow. Now, could we please leave this cavern before whatever is making those unnerving noises decides it’s time for dinner?"
                [/message]
            [/then]
        [/object]
    )}

    # wmlindent: stop ignoring

    ############################################################################
    #                                                                          #
    #                                  VICTORY                                 #
    #                                                                          #
    ############################################################################

    [event]
        name=moveto
        [filter]
            id=Galas,Anlindë #,Mal Keshar <-- nope, doesn't suit his character
            {CUP_END_AREA_SLF}
        [/filter]

        [message]
            speaker=unit
            message= _ "Whoah. The view here is amazing. You all have to see this!"
        [/message]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Galas,Anlindë,Mal Keshar
            x=1
            y=1-11
        [/filter]

        [if]
            {VARIABLE_BOOLEAN_EQUALS acquired_secret no}
            [then]
                [message]
                    speaker=unit
                    message= _ "Are we done exploring this region?"

                    [option]
                        label= _ "Yes."
                        [command]
                            {ENDLEVEL_VICTORY no}
                        [/command]
                    [/option]

                    [option]
                        label= _ "No."
                        [command]
                            [allow_undo][/allow_undo]
                        [/command]
                    [/option]
                [/message]
            [/then]
            [else]
                {ENDLEVEL_VICTORY no}
            [/else]
        [/if]
    [/event]

    [event]
        name=victory

        [store_unit]
            [filter]
                id=Galas,Mal Keshar,Anlindë
                [not]
                    {CUP_END_AREA_SLF}
                [/not]
            [/filter]
            kill=no
            variable=teleport_heroes
        [/store_unit]

        [foreach]
            array=teleport_heroes
            [do]
                [teleport]
                    [filter]
                        id=$this_item.id
                    [/filter]
                    x,y=4,4
                    clear_shroud=yes
                [/teleport]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE teleport_heroes}

        [redraw]
            side=1
        [/redraw]

        [scroll_to_unit]
            id=Galas
        [/scroll_to_unit]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Galas
            message= _ "Everything in the distance seems so lush and alive!"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "It’s beautiful."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Galas
            message= _ "Do we really need to find those two heroes to forge a new future for our race? Perhaps there is another option. We could find the ocean and sail towards the horizon and then..."
        [/message]

        [message]
            speaker=Anlindë
            message= _ "... No matter how far away we get from this continent, it will only be a matter of time before the Chaos Empire extends its reaches and wages genocide on us again. Our descendants would not be particularly accepting of our decision knowing that we had the choice to prevent their downfall."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Galas
            message= _ "I know... It was just wishful thinking. Let us continue and find that valley."
        [/message]

        {CLEAR_VARIABLE acquired_secret,keys_acquired}
    [/event]
[/scenario]

#undef CUP_END_AREA_SLF

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


#textdomain wesnoth-Invasion_from_the_Unknown

[scenario]
    id=06_The_Moon_Valley
    name= _ "The Moon Valley"
    {MAP 06_The_Moon_Valley.map}
    {TURNS 40 37 34}
    next_scenario=07_Goliath

    {DEATHS_ACT_1}

    {SCENARIO_MUSIC "revelation.ogg"}

    {STORYTXT_THE_MOON_VALLEY}

    {TWO_SUNS_DEFAULT_SCHEDULE}

    [time_area]
        {UNDERGROUND}
        x=1-16,1-15,1-13 ,1-12,1-11
        y=1-8 ,9   ,10-11,12  ,13-14
    [/time_area]

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

        {GOLD 275 250 240}

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

    [side]
        side=2
        team_name=orcs
        user_team_name= _ "team_name^Orcs"

        {GOLD 200 230 260}
        recruit=Orcish Grunt,Wolf Rider,Orcish Archer,Orcish Assassin,Orcish Warrior

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT grouping   no}
            {AI_SIMPLE_ALWAYS_ASPECT caution    0.50}
        [/ai]

        canrecruit=yes
        type=Orcish Warrior
        id=Durbaghar
        name= _ "Durbaghar"
        profile=portraits/orcs/grunt-2.png
    [/side]

    [side]
        side=3
        team_name=orcs
        user_team_name= _ "team_name^Orcs"

        {GOLD 250 275 300}
        {QUANTITY recruit
        (Orcish Grunt,Wolf Rider,Orcish Archer,Orcish Assassin,Orcish Warrior)
        (Orcish Grunt,Orcish Warrior,Wolf Rider,Orcish Archer,Orcish Slayer,Orcish Crossbowman)
        (Orcish Warrior,Wolf Rider,Orcish Slayer,Orcish Crossbowman)
        }

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT grouping   no}
            {AI_SIMPLE_ALWAYS_ASPECT caution    0.10}
        [/ai]

        canrecruit=yes
        type=Orcish Sovereign
        id=Kal Magar
        name= _ "Kal Magar"
    [/side]

    [side]
        side=4
        team_name=orcs
        user_team_name= _ "team_name^Orcs"

        {GOLD 150 175 200}
        recruit=Goblin Spearman,Wolf Rider,Orcish Archer,Orcish Grunt

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT grouping   defensive}
            {AI_SIMPLE_ALWAYS_ASPECT caution    0.90}
        [/ai]

        canrecruit=yes
        type=Orcish Slurbow
        id=Barglor
        name= _ "Barglor"
        profile=portraits/orcs/grunt-2.png
    [/side]

    [side]
        side=5
        team_name=orcs
        user_team_name= _ "team_name^Orcs"

        {GOLD 175 200 225}
        recruit=Goblin Spearman,Wolf Rider,Orcish Archer,Orcish Grunt,Goblin Rouser,Orcish Assassin

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT grouping   defensive}
            {AI_SIMPLE_ALWAYS_ASPECT caution    0.50}
        [/ai]

        canrecruit=yes
        type=Orcish Crossbowman
        id=Diglet
        name= _ "Diglet"
        profile=portraits/orcs/grunt-3.png
    [/side]

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

    [event]
        name=prestart

        {PLAYER_RECRUITMENT_SETUP_FOR_SCENARIO 6}

        #
        # Recall heroes
        #

        # wmllint: recognize Anlindë
        {RECALL_ANLINDE}
        # wmllint: recognize Mal Keshar
        {RECALL_MAL_KESHAR}

        {ELVISH_SUPPORTER (supporter)}

        {FACE_DIRECTION side=1 nw}

        {PLACE_IMAGE scenery/mine-abandoned.png 2 34}
        {PLACE_IMAGE items/orcish-flag.png 42 12}
        {PLACE_IMAGE "items/orcish-flag.png~FL(horiz)" 20 20}
        {PLACE_IMAGE items/orcish-flag.png 14 13}
        {PLACE_IMAGE items/orcish-flag.png 17 10}
        {PLACE_IMAGE "items/orcish-banner.png~RC(magenta>green)" 12 7}
        {PLACE_IMAGE "items/orcish-banner.png~RC(magenta>green)~FL(horiz)" 10 10}
        {PLACE_IMAGE "items/orcish-banner.png~RC(magenta>purple)" 18 15}
        {PLACE_IMAGE "items/orcish-banner.png~RC(magenta>purple)" 23 11}
        {PLACE_IMAGE "items/orcish-banner.png~RC(magenta>blue)" 39 9}
        {PLACE_IMAGE "items/orcish-banner.png~FL(horiz)~RC(magenta>blue)" 45 9}
        {PLACE_IMAGE "items/orcish-banner.png~FL(horiz)~RC(magenta>brown)" 37 21}
        {PLACE_IMAGE "items/orcish-banner.png~RC(magenta>brown)" 34 23}
        {PLACE_IMAGE "items/orcish-banner.png~RC(magenta>brown)" 39 32}
        {PLACE_IMAGE "items/orcish-banner.png~RC(magenta>black)" 28 29}
        {PLACE_IMAGE "items/orcish-banner.png~RC(magenta>black)" 19 30}
        {PLACE_IMAGE "items/orcish-banner.png~RC(magenta>brown)" 36 34}
        {PLACE_IMAGE "items/orcish-banner.png~RC(magenta>purple)" 14 23}
        {PLACE_IMAGE "items/orcish-banner.png~RC(magenta>green)" 22 5}
        {PLACE_IMAGE items/scarecrow.png 28 9}
        {PLACE_IMAGE "items/scarecrow.png~FL(horiz)" 15 16}
        {PLACE_IMAGE "items/scarecrow.png~FL(horiz)" 19 17}
        {PLACE_IMAGE items/scarecrow.png 31 25}
        {PLACE_IMAGE items/scarecrow.png 40 28}
        {PLACE_IMAGE items/straw-bale1.png 41 30}
        {PLACE_IMAGE items/straw-bale2.png 44 27}
        {PLACE_IMAGE "items/grain-sheaf.png~FL(horiz)" 31 24}
        {PLACE_IMAGE items/grain-sheaf.png 22 17}
        {PLACE_IMAGE "items/straw-bale2.png~FL(horiz)" 16 14}
        {PLACE_IMAGE "items/straw-bale1.png~FL(horiz)" 27 9}
        {PLACE_IMAGE scenery/berry.png 26 8}
        {PLACE_IMAGE scenery/berry.png 28 12}
        {PLACE_IMAGE scenery/berry.png 29 24}
        {PLACE_IMAGE scenery/berry.png 17 17}
        {PLACE_IMAGE scenery/berry.png 16 20}
        {PLACE_IMAGE scenery/berry.png 44 29}

        {OBJECTIVES (
            {OBJECTIVE_VICTORY ( _ "Defeat all enemy leaders to secure the valley")}

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

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER}
        )}
    [/event]

    [event]
        name=start

        [message]
            speaker=Mal Keshar
            message= _ "The valley of the Moon. Thousands of years ago, the people then living near here believed the end of the world had come. Rocks fell from the sky, which was dark for many days thereafter. There were earthquakes and other signs. When the sun returned, there being at that time only one, they found a vast smoking crater here; and that night there was blood on the face of the Greater Moon—"
        [/message]

        {REPLACE_SCENARIO_MUSIC "northerners.ogg"}

        [message]
            speaker=Anlindë
            message= _ "Orcs! This valley is infested with orcs!"
        [/message]

        [message]
            speaker=Diglet
            message= _ "Intruders! Alert the chieftain!"
        [/message]

        [message]
            role=supporter
            message= _ "Did you hear that?"
        [/message]

        [message]
            speaker=Galas
            message= _ "So, this was your cunning plan all along, Mal Keshar? To lead us to orcish territory and use us as fodder for their grunts? To expand your undead army?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Ha, ha, ha! I could have killed you all in your sleep had that been my intention! What would be the point of bringing you to this place when ancient dead warriors abound nowadays? Speak, elf!"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "Control your temper, you two! Those orcs should be our only concern right now. We have come this far and the sands we left behind hold no promise. If we want to lead our people to a new and hopeful future, we must fight. Unless Mal Keshar knows an alternate route?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "There certainly are other ways to reach the depths if you search for them amidst the tall cliffs of this region, but we will invariably come across unwelcoming natives who will not think twice before killing you and your subjects. Your people are not accustomed to the cold and steep heights of Irdya. If you were to ask me, I’d say you could use this valley to your advantage. Let the orcs fall and perish under the might of the last forest elves of the Great Continent!"
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Galas
            message= _ "I do understand that this is our best option for now — it is to be expected from such a desperate and foolish quest. Let us prepare for battle, then. To arms!"
        [/message]

        [message]
            role=supporter
            message= _ "To arms!"
        [/message]

        {APPEND_MUSIC "battle.ogg"}
        {APPEND_MUSIC "loyalists.ogg"}
        {APPEND_MUSIC "legends_of_the_north.ogg"}
        {APPEND_MUSIC "casualties_of_war.ogg"}
        {APPEND_MUSIC "western_theme2.ogg"}

        [message]
            speaker=Kal Magar
            message= _ "Intruders, you say? What have the scouts been up to all this time, that this was allowed to happen? Get rid of them now!"
        [/message]
    [/event]

    [event]
        name=side 1 turn 1 end

        [message]
            speaker=Anlindë
            message= _ "That did sound very convincing and leader-like, Mal Keshar. I am impressed."
        [/message]

        [message]
            speaker=Anlindë
            message={ASIDE ( _ "But trust me, nothing of this would work if it weren’t my goal to find them as well.")}
        [/message]

        [message]
            speaker=Mal Keshar
            message={ASIDE ( _ "Of course it wouldn’t. He, he.")}
        [/message]
    [/event]

#ifdef 0
    [event]
        name=turn 6

        [message]
            speaker=Galas
            message= _ "The Short Darkness begins to shroud the land, giving the orcs a new advantage."
        [/message]

        [message]
            speaker=Anlindë
            message= _ "The combination of the might of the undead and the effectiveness of our hunters will be a great help in surviving the darkness."
        [/message]
    [/event]

    [event]
        name=turn 11

        [message]
            speaker=Mal Keshar
            message= _ "Ahh, the Long Darkness approaches, at last! The undead hordes shall rise and crush these repulsive orcs!"
        [/message]
    [/event]
#endif

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

        [redraw][/redraw]

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

        [delay]
            time=300
        [/delay]

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

        [delay]
            time=300
        [/delay]

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

        [delay]
            time=300
        [/delay]

        [message]
            speaker=Galas
            scroll=no
            message= _ "Those towers seem vacant, but there is something about them I mistrust. Be careful; it may be a trap of the orcs."
        [/message]

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

    [event]
        name=moveto
        [filter]
            x=1-21
            y=1-15
            side=1
        [/filter]

        [message]
            speaker=Kal Magar
            message= _ "So, our best warriors were unable to repel you, little elves? No matter — my bodyguards will send you to hell! Haw, haw, haw!"
        [/message]

        {ADD_GOLD 2 50  75 100}

        {ADD_GOLD 3 90 130 170}

        {ADD_GOLD 4 50  75 100}

        {ADD_GOLD 5 50  75 100}

        {NAMED_LOYAL_UNIT 3 (Orcish Crossbowman) 13 11 Vagkar ( _ "Vagkar")}

        {NAMED_LOYAL_UNIT 3 (Orcish Warrior) 14  9 Krislo ( _ "Krislo")}
        {NAMED_LOYAL_UNIT 3 (Orcish Warrior) 13  7 Urdo ( _ "Urdo")}

        {NAMED_LOYAL_UNIT 3 (Orcish Slayer) 9 12 Gremle ( _ "Gremle")}

        {NAMED_LOYAL_UNIT 3 (Orcish Warrior) 18  8 Fir ( _ "Fir")}
        {NAMED_LOYAL_UNIT 3 (Orcish Warrior) 13 15 Ewurk ( _ "Ewurk")}

        {NAMED_LOYAL_UNIT 3 ({DIFF (Orcish Crossbowman) (Orcish Crossbowman) (Orcish Slurbow)}) 17 13 Ceel ( _ "Ceel")}

        {SCROLL_TO 18 8}

        [redraw][/redraw]

        [delay]
            time=300
        [/delay]

        {SCROLL_TO 13 15}

        [redraw][/redraw]

        [delay]
            time=300
        [/delay]

        {SCROLL_TO 17 13}

        [redraw][/redraw]

        [delay]
            time=300
        [/delay]

        [message]
            speaker=Galas
            message= _ "Uh-oh."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Ah, the boy was right. It was a trap, and look — the orcs are calling upon reinforcements!"
        [/message]

#ifndef EASY
        {NAMED_UNIT 3 (Orcish Assassin) 14 12 Turgan ( _ "Turgan") (upkeep=free)}           # {NO_UPKEEP_NO_OVERLAY}
        {NAMED_UNIT 3 (Orcish Assassin) 21  9 Akir   ( _ "Akir")   (upkeep,facing=free,sw)} # {NO_UPKEEP_NO_OVERLAY}
#endif
#ifdef HARD
        {NAMED_UNIT 3 (Orcish Assassin) 19 13 Khur   ( _ "Khur")   (upkeep,facing=free,sw)} # {NO_UPKEEP_NO_OVERLAY}
#endif
    [/event]

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

        [message]
            speaker=Barglor
            message= _ "Ouch! I’m vanquished..."
        [/message]
    [/event]

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

        [message]
            speaker=Durbaghar
            message= _ "Help!! Ack—"
        [/message]
    [/event]

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

        [message]
            speaker=Diglet
            message= _ "Nooo!! Why nobody protects mee..." # wmllint: no spellcheck
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Kal Magar
        [/filter]

        [message]
            speaker=Kal Magar
            message= _ "... My guards... are a bunch of incompetent... idiotic... fools... Argghhh—"
        [/message]
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            [not]
                side=1
            [/not]
            canrecruit=yes
        [/filter]

        {RANDOM "25,30,35,40,45,50,55"}

        {RETRIEVE_GOLD $random}

        {CLEAR_VARIABLE random}
    [/event]

    [event]
        name=enemies defeated

        {ENDLEVEL_VICTORY yes}
    [/event]

    [event]
        name=victory

        [message]
            speaker=Galas
            message= _ "Our job here is finished. To the caves!"
        [/message]
    [/event]
[/scenario]

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


#textdomain wesnoth-Invasion_from_the_Unknown

[scenario]
    id=07_Goliath
    name= _ "scenario_name^Goliath"
    {MAP 07_Goliath.map}
    {TURNS 48 45 42}
    next_scenario=08_Errand_of_Hope
    victory_when_enemies_defeated=no

    {DEATHS_ACT_1}

    {SCENARIO_MUSIC       "climactic_contemplation.ogg"}
    {EXTRA_SCENARIO_MUSIC "heroes_rite.ogg"}
    {EXTRA_SCENARIO_MUSIC "the_deep_path.ogg"}

    {STORYTXT_THE_GOLIATH}

    {UNDERGROUND}

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

        shroud=yes
        fog=yes

        {NO_ECONOMY}
        gold=100 # For initial recruitment

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

    # Boss
    [side]
        side=2
        team_name=foes
        user_team_name= _ "team_name^Chaos Empire"
        {CHAOS_FLAG}
        color=gold

        hidden=yes
        no_leader=yes
        {NO_ECONOMY}

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

            # Needed for the boss to actually try attacking the player.
            {AI_SIMPLE_ALWAYS_ASPECT leader_ignores_keep yes}

            # Can't use this here; see IftU issue #5.
            #{AI_BOSS_TARGETING_ENGINE <<{"Galas","Anlindë","Mal Keshar"}>>}
        [/ai]
    [/side]

    # Boss supporters
    [side]
        side=3
        team_name=foes
        user_team_name= _ "team_name^Chaos Empire"
        {CHAOS_FLAG}
        color=orange

        hidden=yes
        no_leader=yes
        {NO_ECONOMY}

        {TEAM_AI_KAMIKAZE}
    [/side]

    [side]
        side=4
        team_name=foes
        user_team_name= _ "team_name^Cave Creatures"
        color=teal

        hidden=yes
        no_leader=yes
        {NO_ECONOMY}

        {SIDE_GENERIC_GUARD (Vampire Bat) 34 21} {FACING sw}
        {SIDE_GENERIC_GUARD (Vampire Bat) 29 25}
        {SIDE_GENERIC_GUARD (Vampire Bat) 31 21}
        {SIDE_GENERIC_GUARD (Vampire Bat) 10  8}
        {SIDE_GENERIC_GUARD (Vampire Bat) 11 33}
        {SIDE_GENERIC_GUARD (Blood Bat)    2 10}
#ifndef EASY
        {SIDE_GENERIC_GUARD (Blood Bat)   22  1}
        {SIDE_GENERIC_GUARD (Vampire Bat) 22  9}
        {SIDE_GENERIC_GUARD (Blood Bat)   32 33}
        {SIDE_GENERIC_GUARD (Blood Bat)   10 40}
#else
        {SIDE_GENERIC_GUARD (Vampire Bat) 22  1}
#endif
    [/side]

    [side]
        side=5
        team_name=foes
        user_team_name= _ "team_name^Chaos Empire"
        {CHAOS_FLAG}
        color=green

        hidden=yes
        {NO_ECONOMY}
        recruit=Chaos Invoker,Chaos Invader,Chaos Headhunter

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression          0.99}
            {AI_SIMPLE_ALWAYS_ASPECT caution             0.01}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern scout,fighter,scout,archer}
        [/ai]

        canrecruit=yes
        type=Chaos Lorekeeper
        id=Verne
        name= _ "Verne"
        facing=sw
        [modifications]
            {TRAIT_INTELLIGENT}
            {TRAIT_STRONG}
        [/modifications]
    [/side]

#define G_SUPPORT_AUTOMATON X Y
    {RANDOM n,ne,nw,s,se,sw}
    [unit]
        facing=$random
        side=3
        x={X}
        y={Y}
        ai_special=guardian
        type=Automaton
        upkeep=loyal
        random_traits=yes
        generate_name=yes
    [/unit]
#enddef

#define G_SUPPORT_DEMON X Y
    {VARIABLE_RANDOM random_facing "n,ne,nw,s,se,sw"}
    {VARIABLE_RANDOM random_type   "Demon,Demon Grunt,Demon Zephyr"}
    [unit]
        facing=$random_facing
        side=3
        x={X}
        y={Y}
        ai_special=guardian
        type=$random_type
        upkeep=loyal
        random_gender=yes
        random_traits=yes
        generate_name=yes
    [/unit]
    {CLEAR_VARIABLE random_facing,random_type}
#enddef

#define G_SUPPORT_GOLEM X Y
    {RANDOM n,ne,nw,s,se,sw}
    [unit]
        facing=$random
        side=3
        x={X}
        y={Y}
        ai_special=guardian
        type=Iron Golem
        upkeep=loyal
        random_traits=yes
        generate_name=yes
    [/unit]
#enddef

#define G_BOSS_AUTOMATON X Y
    {RANDOM n,ne,nw,s,se,sw}
    [unit]
        facing=$random
        side=2
        x={X}
        y={Y}
        ai_special=guardian
        type=Automaton
        upkeep=loyal
        random_traits=yes
        generate_name=yes
    [/unit]
#enddef

    {BOSS_SCENARIO_PLAYER_RECRUITMENT}

    {CAVE_NOISE_SOUND_SOURCE}

    {CAVE_WATER_SOUND_SOURCE  7  7}

    {CAVE_WATER_SOUND_SOURCE 23 32}

    [event]
        name=prestart

        {PLAYER_RECRUITMENT_SETUP_FOR_SCENARIO 7}

        #
        # Recall heroes
        #

        # wmllint: recognize Anlindë
        {RECALL_ANLINDE_AT    35 2}
        # wmllint: recognize Mal Keshar
        {RECALL_MAL_KESHAR_AT 34 2}

        #
        # Guards in the hallway
        #
        {G_SUPPORT_AUTOMATON 2 15}
        {G_SUPPORT_AUTOMATON 7 16}
        {G_SUPPORT_AUTOMATON 3 19}
        {G_SUPPORT_AUTOMATON 25 3}
        {G_SUPPORT_AUTOMATON 23 5}
#ifndef EASY
        {G_SUPPORT_AUTOMATON 22 12}
#endif
        {G_SUPPORT_DEMON 12 5}
        {G_SUPPORT_DEMON 5 5}
        {G_SUPPORT_AUTOMATON 13 2}
        {G_SUPPORT_AUTOMATON 13 4}
        {G_SUPPORT_AUTOMATON 10 6}
        {G_SUPPORT_DEMON 4 8}
        {G_SUPPORT_AUTOMATON 6 13}
        {G_SUPPORT_AUTOMATON 7 22}
        {G_SUPPORT_DEMON 13 17}

        #
        # Boss antechamber guards
        #
        {G_SUPPORT_AUTOMATON 14 10}
        {G_SUPPORT_AUTOMATON 24 17}
        {G_SUPPORT_AUTOMATON 10 19}
        {G_SUPPORT_AUTOMATON 12 5}

        #
        # Boss Chamber entrance guards
        #
#ifndef EASY
        {G_SUPPORT_AUTOMATON 19 20}
        {G_SUPPORT_AUTOMATON 23 20}
#endif
        [unit]
            side=3
#ifndef HARD
            type=Doom Guard
#else
            type=Hell Guardian
#endif
            x,y=21,20
            generate_name=yes
            ai_special=guardian
            upkeep=free
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        {G_SUPPORT_AUTOMATON 21 26}
        {G_SUPPORT_AUTOMATON 24 24}
        {G_SUPPORT_DEMON 22 25}
        {G_SUPPORT_DEMON 23 25}

        #
        # Boss Chamber guards
        #
        {G_BOSS_AUTOMATON 20 31}
        {G_BOSS_AUTOMATON 28 31}
        {G_BOSS_AUTOMATON 26 38}
        {G_BOSS_AUTOMATON 20 36}
        {G_BOSS_AUTOMATON 15 30}
        {G_BOSS_AUTOMATON 16 37}

        {G_SUPPORT_AUTOMATON 14 33}
        {G_SUPPORT_AUTOMATON 29 37}
        {G_SUPPORT_AUTOMATON 29 23}

        {G_SUPPORT_AUTOMATON 24 10}
        {G_SUPPORT_AUTOMATON 26 11}
#ifndef EASY
        {G_SUPPORT_AUTOMATON 24 12}
#endif

        [unit]
            side=3
            type=Blood Imp
            id=Gurglo
            name=_"Gurglo"
            x,y=5,16
            ai_special=guardian
            upkeep=free
            [modifications]
                {TRAIT_DIM}
                {TRAIT_SLOW}
            [/modifications]
        [/unit]

        {G_SUPPORT_GOLEM 15 14}
        {G_SUPPORT_GOLEM 15 16}

        {CLEAR_VARIABLE random}

        {FACE_DIRECTION side=1 sw}

        {OBJECTIVES (
            {OBJECTIVE_VICTORY ( _ "Investigate the cave")}

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

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER_NO_BONUS}

            {BOSS_SCENARIO_NOTE}
        )}

        #
        # Ensure Verne won't go away or try to attack the player
        # causing the 'sighted' even to not be ever triggered.
        #

        [modify_side]
            side=5
            controller=null
        [/modify_side]
    [/event]

    [event]
        name=start

        [message]
            speaker=Anlindë
            message= _ "I feel some kind of strong presence in this place. We should determine its nature before we allow our people to follow."
        [/message]

        [message]
            speaker=Galas
            message= _ "Wait, I hear steps..."
        [/message]

        [move_unit_fake]
            type=Demon Grunt
            gender=female
            side=3
            x=24,30
            y=3 ,5
        [/move_unit_fake]

        {NAMED_UNIT 3 (Demon Grunt) 30  5 Kyra  ( _ "Kyra")  ()} {NO_UPKEEP_NO_OVERLAY} {GENDER female} {FACING ne}

        [move_unit_fake]
            type=Demon
            side=3
            gender=female
            x=24,31
            y=3 ,6
        [/move_unit_fake]

        {NAMED_UNIT 3 (Demon) 31  6 Zilla ( _ "Zilla") ()} {NO_UPKEEP_NO_OVERLAY} {GENDER female} {FACING ne}

        [move_unit_fake]
            type=Demon Grunt
            side=3
            gender=male
            x=24,30
            y=3 ,6
        [/move_unit_fake]

        {NAMED_UNIT 3 (Demon Grunt) 31  6 Kairus ( _ "Kairus") ()} {NO_UPKEEP_NO_OVERLAY} {GENDER male} {FACING ne}

        [message]
            speaker=Kyra
            message= _ "Surprise, forest dwellers. Didn’t expect us here, uh?"
        [/message]

        [message]
            speaker=Kairus
            message= _ "Kill them! It’s the Emperor’s command!"
        [/message]

        [message]
            speaker=Galas
            # po: 'Them' being the Lady of Light and the Master of Darkness.
            message= _ "Damn it, it’s just as I feared! These vile creatures are intent on getting to them before us!"
        [/message]
    [/event]

    [event]
        name=DEBUG1
        first_time_only=no

        [while]
            [have_unit]
                side=1
                x=29-42
                y=  1-8
            [/have_unit]
            [do]
                [teleport]
                    [filter]
                        side=1
                        x=29-42
                        y=  1-8
                    [/filter]
                    x,y=21,31
                [/teleport]
            [/do]
        [/while]

        [redraw]
            side=1
        [/redraw]

        [scroll_to]
            x,y=21,31
        [/scroll_to]
    [/event]

    {FIRE_EVENT_ON_STUMBLE_UPON "found verne" (id=Verne)}

    [event]
        name=found verne

        #
        # Make his side active.
        #
        [modify_side]
            side=5
            controller=ai
            {GOLD 60 70 80}
            income=0
        [/modify_side]

        {FAKE_RECRUIT 5 (Chaos Invader) 11  3}
        {FAKE_RECRUIT 5 (Chaos Invoker) 11  4}
        {FAKE_RECRUIT 5 (Chaos Invader)  9  3}
        {FAKE_RECRUIT 5 (Chaos Invader)  9  4}

        [message]
            speaker=Verne
            message= _ "You, elves! If you still place any value on your lives you shall stop and leave now!"
        [/message]
    [/event]

    ##################### Touch-gem that opens the boss antechamber #####################

    {PLACE_IMAGE (items/ball-blue.png) 3 22}

    {ITEM_TOUCHPLATE 3 22}

    [event]
        name=prestart

        {VARIABLE door_1 no}
    [/event]

    [event]
        name=victory

        {CLEAR_VARIABLE door_1}
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            x,y=3,22
        [/filter]

        [if]
            {VARIABLE_BOOLEAN_EQUALS door_1 no}
            [then]
                {VARIABLE door_1 yes}

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

                {PLACE_IMAGE items/ball-green.png $x1 $y1}

                [redraw][/redraw]

                {QUAKE (rumble.ogg)}

                [terrain]
                    x=9-10,9-10,9-10
                    y=12,  14,  16
                    terrain=Urb
                [/terrain]

                [remove_shroud]
                    side=1
                    x= 8-11
                    y=11-17
                [/remove_shroud]

                [redraw]
                    side=1
                [/redraw]

                [scroll_to]
                    x,y=9,15
                [/scroll_to]

                {HIGHLIGHT_GOAL (
                    x=9,9,9
                    y=12,14,16
                )}

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

                [scroll_to]
                    x,y=$x1,$y1
                [/scroll_to]
            [/then]
            [else]
                [allow_undo][/allow_undo]

                [message]
                    speaker=narrator
                    image=wesnoth-icon.png
                    message= _ "Touchgem already activated."
                [/message]
            [/else]
        [/if]
    [/event]

    ##################### Secret eastern passage #####################

    {OBJ_VOID_ARMOR 31 24 armor_void}

    ##################### Touch-plate at 10,19 which opens the room with the final touch-plate and a bonus #####################

    # Touchplate 10 19

    {ITEM_TOUCHPLATE 10 19}

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

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

        [terrain]
            x,y=14,14-15
            terrain=Ur
        [/terrain]

        {PLACE_IMAGE (scenery/rubble.png) 14 14-15}

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

        {REVEAL_AREA 13 14 15 16}
    [/event]

    ##################### Final touch-plate and a bonus; tp opens the final boss chamber #####################

    # Bonus - a strength potion (WML from /data/core/macros/items.cfg, modified)

    {PICK_UP (items/potion-red.png) 17 15 (
        [not]
            status=not_living
        [/not]
        [not]
            race=bats
        [/not]
    )
    ( _ "This small flask contains some potion of strength, said to be able to turn mere weaklings into formidable fighters! Let us choose who shall drink it.")
    ( _ "This potion can only be used by living beings other than beasts. Let another take it.")
    (
        [sound]
            name=potion.ogg
        [/sound]

        [object]
            id=e1l7_strength_potion
            name= _ "Potion of Strength"
            image=icons/potion-red-4.png
            duration=scenario
            description= _ "The drinker’s strength is increased for the remainder of the scenario, adding 2 damage points to their melee attacks, and adding 8 points to their total HP."
            [filter]
                x,y=$x1,$y1
            [/filter]
            [effect]
                apply_to=attack
                range=melee
                increase_damage=2
            [/effect]
            [effect]
                apply_to=hitpoints
                increase_total=8
                heal_full=yes
            [/effect]
        [/object]
    )}

    # Touchplate 16 14

    {ITEM_TOUCHPLATE 16 14}

    [event]
        name=moveto
        [filter]
            side=1
            x,y=16,14
        [/filter]

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

        {QUAKE (cave-in.ogg)}

        [terrain]
            x=19,21,23
            y=19,19,19
            terrain=Urb
        [/terrain]

        {PLACE_IMAGE (scenery/rubble.png) 19,21,23 19,19,19}

        [redraw]
            side=1
        [/redraw]

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

        {REVEAL_AREA 18 18 24 20}
    [/event]

    ##################### Boss events #####################

    [event]
        name=moveto
        [filter]
            side=1
            x=18-26
            y=32-38
        [/filter]

        [store_starting_location]
            side=2
        [/store_starting_location]

        [store_direction]
            from_x,from_y=$location.x,$location.y
            to_x,to_y=$x1,$y1
        [/store_direction]

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

        {QUAKE (cave-in.ogg)}

        {QUAKE (rumble.ogg)}

        # Boss appears

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

        [unit]
            canrecruit=yes
            side=2
            type=Goliath
            id=Goliath
            name= _ "Goliath"
            x,y=$location.x,$location.y
            facing=$direction
            level=4
            {IS_BOSS}
            [modifications]
                {TRAIT_MECHANICAL}
                {BOSS_BOOST 110% 0 1 5 0}
                [object]
                    [effect]
                        apply_to=attack
                        range=melee
                        [set_specials]
                            mode=append
                            {WEAPON_SPECIAL_SLOW}
                        [/set_specials]
                    [/effect]
                [/object]
            [/modifications]
        [/unit]

        {CLEAR_VARIABLE location,direction}

        # A few sidekicks

        [repeat]
            times={DIFF 2 3 4}
            [do]
                [unit]
                    type=Automaton
                    side=2
                    placement=leader
                    generate_name=yes
                    upkeep=free
                    [modifications]
                        {TRAIT_MECHANICAL}
                    [/modifications]
                [/unit]
            [/do]
        [/repeat]

        {BOSS_AMBIENTANCE}

        [redraw]
            side=1
        [/redraw]

        [scroll_to_unit]
            id=Goliath
        [/scroll_to_unit]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Goliath
            message= _ "Puny elves and undead! Have you come to challenge me?"
        [/message]

        [message]
            speaker=Galas
            message= _ "Eh... Those fists seem very strong! (looks aside) What is this thing, Anlindë?"
        [/message]

        [message]
            speaker=Anlindë
            message= _ "Some kind of dwarvish warrior — at least, judging by the runes engraved on its armor. Stay back!"
        [/message]

        [message]
            speaker=Goliath
            message= _ "The Master says you must all die! For the Chaos Empire!"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Argh, just what we need — a massive metal foe. It will surely crush us if we don’t act fast!"
        [/message]

        {OBJECTIVES (
            {OBJECTIVE_VICTORY ( _ "Destroy the Goliath")}

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

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER_NO_BONUS}

            {BOSS_SCENARIO_NOTE}
        )}
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            side=1
        [/filter]
        [filter_second]
            id=Goliath
        [/filter_second]

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

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

        [kill]
            type=Automaton,Iron Golem,Goliath
            [not]
                id=Goliath
            [/not]
            animate=yes
        [/kill]

        [kill]
            side=3
        [/kill]

        [fade_out_music][/fade_out_music]

        [message]
            speaker=Galas
            message= _ "At last, it’s over."
        [/message]

        [delay]
            time=250
        [/delay]

        {ENDLEVEL_VICTORY no}
    [/event]

    [event]
        name=victory

        {REPLACE_SCENARIO_MUSIC "underground.ogg"}

        [remove_terrain_overlays]
            x,y=11,36-37
        [/remove_terrain_overlays]

        [message]
            speaker=Anlindë
            message= _ "That was a close call. But who knows how many other metallic giants might have been brought to this place by the enemy? Let us leave this chamber and continue exploring, but be on your keenest guard."
        [/message]

        [remove_shroud]
            side=1
            x,y,radius=12,36,2
            [or]
                x,y,radius=15,35,4
            [/or]
        [/remove_shroud]

        [redraw]
            side=1
        [/redraw]

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

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Galas
            scroll=no
            message= _ "Onwards we go, then..."
        [/message]

        [scroll_to_unit]
            id=Galas
        [/scroll_to_unit]
    [/event]
[/scenario]

#undef G_SUPPORT_AUTOMATON
#undef G_SUPPORT_DEMON
#undef G_SUPPORT_GOLEM
#undef G_BOSS_AUTOMATON

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