#textdomain wesnoth-ei
[scenario]
    id=11_Captured
    name= _ "Captured"
    next_scenario=12_Evacuation
    map_data="{campaigns/Eastern_Invasion/maps/11_Captured.map}"
    victory_when_enemies_defeated=no
    turns=-1
    {UNDERGROUND}

    {INTRO_AND_SCENARIO_MUSIC northerners.ogg the_deep_path.ogg}
    {EXTRA_SCENARIO_MUSIC breaking_the_chains.ogg}
    {EXTRA_SCENARIO_MUSIC underground.ogg}

    {campaigns/Eastern_Invasion/utils/deaths.cfg}

    # wmllint: local spelling Dra-Nak
    [story]
        [part]
            story= _ "After reaching what they believed was safety, Gweddry and his men had been captured by northern orcs."
        [/part]
        [part]
            story= _ "Gweddry, Dacyn and Owaec were promptly taken before the orcish king, Dra-Nak, while the rest were thrown into the orcish prisons to await their turn..."
        [/part]
    [/story]

    [side]
        type=General
        id=Gweddry
        name= _ "Gweddry"
        side=1
        canrecruit=no
        controller=human
        team_name=good
        user_team_name=_"Wesnothians"
        shroud=yes
        gold=0
        {FLAG_VARIANT loyalist}
    [/side]

    [side]
        type=Orcish Warlord
        id=King Dra-Nak
        name= _ "King Dra-Nak"
        profile=portraits/orcs/transparent/grunt-5.png
        facing=sw
        side=2
        canrecruit=yes
        controller=ai
        recruit=
        gold=0
        [ai]
            passive_leader=yes
            grouping=no
            recruitment_ignore_bad_combat=yes
            aggression=0.4
            [aspect]
                id=attacks
                [facet]
                    invalidate_on_gamestate_change=yes
                    [filter_enemy]
                        [not]
                            [filter_wml]
                                [variables]
                                    undercover=yes
                                [/variables]
                            [/filter_wml]
                        [/not]
                    [/filter_enemy]
                [/facet]
            [/aspect]
        [/ai]
        team_name=bad
        user_team_name=_"Orcs"
        {FLAG_VARIANT ragged}
    [/side]

    [side]
        side=3
        no_leader=yes
        controller=ai
        team_name=good,bad
        user_team_name=_"Prisoners"
        share_vision=no
        share_maps=no
        [ai]
            ai_algorithm=idle_ai
        [/ai]
    [/side]

    {ANIMATED_BRAZIER 31 12}
    {ANIMATED_BRAZIER 27 18}
    {ANIMATED_BRAZIER 35 17}

    [event]
        name=prestart

        {PLACE_IMAGE items/burial.png 22 13}
        {PLACE_IMAGE items/burial.png 26 11}

        {PLACE_IMAGE scenery/gate-rusty-se.png 26 5}
        {PLACE_IMAGE scenery/gate-rusty-se.png 21 8}
        {PLACE_IMAGE scenery/gate-rusty-se.png 17 10}
        {PLACE_IMAGE scenery/gate-rusty-sw.png 29 9}

        {PLACE_IMAGE scenery/trash.png 22 2}

        {PLACE_IMAGE items/bones.png 10 2}
        {PLACE_IMAGE items/bones.png 10 4}

        {PLACE_IMAGE items/barrel.png 14 15}
        {PLACE_IMAGE items/box.png 15 15}
        {PLACE_IMAGE items/armor.png 16 15}
        {PLACE_IMAGE scenery/trash.png 16 16}

        {PLACE_IMAGE scenery/trash.png 30 24}

        [recall]
            id=Dacyn
            x,y=28,13
        [/recall]

        [recall]
            id=Owaec
            x,y=26,14
        [/recall]

        [role]
            side=1
            type=Royal Guard,Halberdier,Great Mage,Master Bowman,Arch Mage,Silver Mage,Mage of Light,Javelineer,Swordsman,Pikeman,Longbowman,Red Mage,White Mage,Mage,Spearman,Bowman,Iron Mauler,Shock Trooper,Heavy Infantryman,Cavalryman,Horseman
            role=escapee leader
            [not]
                id=Dacyn
            [/not]
        [/role]
        [if]
            [have_unit]
                role=escapee leader
                search_recall_list=yes
            [/have_unit]
            [else]
                {GENERIC_UNIT 1 "Mage" "recall" "recall"}
                [+unit]
                    role=escapee leader
                [/unit]
            [/else]
        [/if]
        [recall]
            role=escapee leader
            x,y=25,3
        [/recall]

        [role]
            side=1
            type=White Mage,Red Mage,Longbowman,Pikeman,Swordsman,Javelineer,Mage,Spearman,Bowman,Mage of Light,Arch Mage,Silver Mage,Master Bowman,Halberdier,Royal Guard,Great Mage,Iron Mauler,Shock Trooper,Heavy Infantryman,Cavalryman,Horseman
            role=escapee sidekick 1
            [not]
                id=Dacyn
            [/not]
            [not]
                role=escapee leader
            [/not]
        [/role]
        [if]
            [have_unit]
                role=escapee sidekick 1
                search_recall_list=yes
            [/have_unit]
            [else]
                {GENERIC_UNIT 1 "Spearman" "recall" "recall"}
                [+unit]
                    role=escapee sidekick 1
                [/unit]
            [/else]
        [/if]
        [recall]
            role=escapee sidekick 1
            x,y=24,3
        [/recall]

        [role]
            side=1
            type=Spearman,Mage,Bowman,Mage,Red Mage,Longbowman,Pikeman,Swordsman,Javelineer,Mage of Light,Arch Mage,Silver Mage,Master Bowman,Halberdier,Royal Guard,Great Mage,Iron Mauler,Shock Trooper,Heavy Infantryman,Cavalryman,Horseman
            role=escapee sidekick 2
            [not]
                id=Dacyn
            [/not]
            [not]
                role=escapee leader
            [/not]
            [not]
                role=escapee sidekick 1
            [/not]
        [/role]
        [if]
            [have_unit]
                role=escapee sidekick 2
                search_recall_list=yes
            [/have_unit]
            [else]
                {GENERIC_UNIT 1 "Bowman" "recall" "recall"}
                [+unit]
                    role=escapee sidekick 2
                [/unit]
            [/else]
        [/if]
        [recall]
            role=escapee sidekick 2
            x,y=25,4
        [/recall]

        [store_gold]
            side=1
            variable=stored_player_gold
        [/store_gold]

        [if]
            [variable]
                name=stored_player_gold
                greater_than_equal_to=1
            [/variable]

            [then]
                {PLACE_IMAGE items/chest-plain-closed.png 33 11}
            [/then]
        [/if]

        [modify_side]
            side=1
            gold=0
            income=-2
        [/modify_side]

        [remove_shroud]
            side=1
            x,y=26,5
        [/remove_shroud]

        # lvl4 units are stored first, then lvl3, then lvl2 and lastly lvl1:
        # this makes it easy to just keep recalling the first unit of the
        # array in order to ensure the prisoners are always the highest lvl
        # units possible

        [store_unit]
            [filter]
                side=1
                [not]
                    x,y=1-999,1-999
                [/not]
                level=4
            [/filter]

            kill=no
            variable=possible_prisoners
        [/store_unit]

        [store_unit]
            [filter]
                side=1
                [not]
                    x,y=1-999,1-999
                [/not]
                level=3
            [/filter]

            kill=no
            variable=possible_prisoners
            mode=append
        [/store_unit]

        [store_unit]
            [filter]
                side=1
                [not]
                    x,y=1-999,1-999
                [/not]
                level=2
            [/filter]

            kill=no
            variable=possible_prisoners
            mode=append
        [/store_unit]

        [store_unit]
            [filter]
                side=1
                [not]
                    x,y=1-999,1-999
                [/not]
                level=1
            [/filter]

            kill=no
            variable=possible_prisoners
            mode=append
        [/store_unit]

        [store_locations]
            x=15,20,31
            y=9,6,8
            radius=3

            [filter_radius]
                terrain=!,X*,*^X*
            [/filter_radius]

            variable=prisoner_locations
        [/store_locations]

        # for each prisoner location, we either recall the first unit of the
        # array (and then remove it from the array) or create a new unit if
        # the array is empty (meaning that the recall list had less than 13
        # units

        {FOREACH prisoner_locations i}
            [if]
                [variable]
                    name=possible_prisoners.length
                    greater_than=0
                [/variable]

                [then]
                    [unstore_unit]
                        variable=possible_prisoners[0]
                        x,y=$prisoner_locations[$i].x,$prisoner_locations[$i].y
                        find_vacant=yes
                    [/unstore_unit]

                    {CLEAR_VARIABLE possible_prisoners[0]}
                [/then]

                [else]
                    #{DEBUG_MSG "ran out of recallable prisoners, creating a new one"}

                    {RANDOM "Spearman,Cavalryman,Mage,Horseman,Heavy Infantryman"}

                    [unit]
                        side=1
                        type=$random
                        generate_name=yes
                        random_traits=yes
                        x,y=$prisoner_locations[$i].x,$prisoner_locations[$i].y
                    [/unit]
                [/else]
            [/if]
        {NEXT i}

        {CLEAR_VARIABLE possible_prisoners,prisoner_locations,new_prisoner}

        {LOYAL_UNIT 2 {ON_DIFFICULTY "Troll" "Troll" "Troll Warrior"} 23 10}
        {LOYAL_UNIT 2 {ON_DIFFICULTY "Troll" "Troll" "Troll Warrior"} 23 16}
        [+unit]
            # This one must not be quick, or it might see an escapee before the
            # escapee sees it... it still can, if the escapee is a non-quick HI
            # line unit, but it's unlikely the player will scout ahead with one
            random_traits=no
            [+modifications]
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]

        {LOYAL_UNIT 2 {ON_DIFFICULTY "Troll" "Troll Warrior" "Troll Warrior"} 28 18}
        {LOYAL_UNIT 2 {ON_DIFFICULTY "Troll" "Troll Warrior" "Troll Warrior"} 26 7}
        {LOYAL_UNIT 2 {ON_DIFFICULTY "Troll" "Troll Warrior" "Troll Warrior"} 19 12}

        {LOYAL_UNIT 2 "Orcish Warrior" 24 13}
        {LOYAL_UNIT 2 "Orcish Warrior" 26 12}

        {LOYAL_UNIT 2 "Orcish Warrior" 29 16}
        {LOYAL_UNIT 2 "Orcish Warrior" 31 15}

        {LOYAL_UNIT 2 "Orcish Warrior" 34 13}

        {GENERIC_UNIT 2 "Orcish Grunt" 11 4}

        {MODIFY_UNIT (
            side=1

            [filter_wml]
                upkeep=full
            [/filter_wml]
        ) variables.temporary_free_upkeep yes}

        {MODIFY_UNIT (
            side=1

            [filter_wml]
                upkeep=full
            [/filter_wml]
        ) upkeep loyal}

        {MODIFY_UNIT (
            side=1
            [not]
                role=escapee leader

                [or]
                    role=escapee sidekick 1
                [/or]

                [or]
                    role=escapee sidekick 2
                [/or]
            [/not]
        ) side 3}

        {MODIFY_UNIT side=1 canrecruit yes}

        {MODIFY_UNIT side=2 status.guardian yes}
    [/event]

    [event]
        name=start

        [message]
            speaker=narrator
            message= _ "Several of Gweddry's men find themselves locked away in a crude orcish cell."
            image=wesnoth-icon.png
        [/message]

        [message]
            role=escapee sidekick 1
            message= _ "We've got to get out of here!"
        [/message]

        [message]
            role=escapee sidekick 2
            message= _ "I'm sure the commander will come and save us!"
        [/message]

        [message]
            role=escapee sidekick 1
            message= _ "What? Didn't you see those huge trolls drag them away? It's hopeless!"
        [/message]

        [message]
            role=escapee leader
            message= _ "Be quiet, you two! There's something back here..."
        [/message]

        {MOVE_UNIT role="escapee leader" 22 2}

        [message]
            role=escapee leader
            message= _ "Look! There's a gap in the wall over here. I think I can slip through if I clear away some of these rocks..."
        [/message]

        [animate_unit]
            flag=attack

            [filter]
                role=escapee leader
            [/filter]

            [primary_attack]
                range=melee
            [/primary_attack]

            [facing]
                x,y=21,3
            [/facing]

            hits=yes
        [/animate_unit]

        [sound]
            name=cave-in.ogg
        [/sound]

        [terrain]
            x,y=21,3
            terrain=Uu^Dr
        [/terrain]

        [redraw]
            side=1
        [/redraw]

        [message]
            role=escapee leader
            message= _ "Come on! This way!"
        [/message]

        {MOVE_UNIT (role=escapee leader) 21 3}

        [objectives]
            side=1
            [objective]
                description= _ "Find Gweddry, Dacyn and Owaec"
                condition=win
            [/objective]
            [objective]
                description= _ "Release the other prisoners"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of the escapees"
                condition=lose
            [/objective]
        [/objectives]
    [/event]

    [event]
        name=moveto

        [filter]
            side=1
            x=25,26
            y= 5, 4
        [/filter]

        [message]
            speaker=unit
            message= _ "The door won't open from this side."
        [/message]
    [/event]

    [event]
        name=moveto

        [filter]
            side=1

            [filter_location]
                x,y=12,4
                radius=2
            [/filter_location]
        [/filter]

        [message]
            speaker=unit
            message= _ "There's strange noises coming from those pits. I don't like this."
        [/message]

        [event]
            name=new turn

            {LOYAL_UNIT 2 "Vampire Bat" 8 2}
            {LOYAL_UNIT 2 "Vampire Bat" 11 2}

            [message]
                side,race=2,bat
                message= _ "Neep! Neep!" # wmllint: no spellcheck
            [/message]

            [event]
                name=new turn

                {LOYAL_UNIT 2 "Vampire Bat" 8 2}
                {LOYAL_UNIT 2 "Vampire Bat" 11 2}

                [event]
                    name=new turn

                    {LOYAL_UNIT 2 "Vampire Bat" 8 2}
                [/event]
            [/event]
        [/event]
    [/event]

    [event]
        name=attack

        [filter]
            race=bat
        [/filter]

        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=second_unit
            message= _ "Ack! Get away from me!"
        [/message]
    [/event]

    [event]
        name=moveto

        [filter]
            side=1
            x=1-8
            y=5-8
        [/filter]

        [message]
            speaker=unit
            message= _ "This tunnel seems to go deeper into the caves. We can't go that way."
        [/message]
    [/event]

    [event]
        name=moveto

        [filter]
            side=1
            x=12-18
            y=15-19
        [/filter]

        [message]
            speaker=unit
            message= _ "There's a pile of orcish gear and trash here. The stench is wretched."
        [/message]
    [/event]

    [event]
        name=moveto

        [filter]
            side=1
        [/filter]

        [filter_condition]
            [have_unit]
                type=Troll,Troll Warrior
                [filter_vision]
                    side=1
                [/filter_vision]
            [/have_unit]
        [/filter_condition]

        [redraw]
            side=1
        [/redraw]

        [message]
            speaker=unit
            message= _ "The other prison cells should be to the north of that chamber. If we can get past those trolls we could free our comrades."
        [/message]

        [message]
            side=1
            [not]
                x,y=$x1,$y1
            [/not]
            message= _ "But there's too many of them!"
        [/message]

        [message]
            speaker=unit
            message= _ "Hmm... I have an idea."
        [/message]

        {VARIABLE unit.variables.undercover yes}
        {VARIABLE unit.profile "portraits/disguise.png"}

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

        {MOVE_UNIT id=$unit.id 15 16}

        [message]
            speaker=narrator
            message= _ "After a while..."
            image=wesnoth-icon.png
        [/message]

        [remove_item]
            x,y=16,15
        [/remove_item]

        [object]
            id=disguise
            silent=yes

            [filter]
                id=$unit.id
            [/filter]

            [effect]
                apply_to=image_mod
                add="O(0)~CROP(0,0,72,72)~BLIT(units/orcs/xbowman.png~TC(1,magenta),0,0)"
            [/effect]
        [/object]

        [if]
            [have_unit]
                side=1
                count=2-99
            [/have_unit]

            [then]
                [message]
                    id=$unit.id
                    message= _ "So, how do I look?"
                [/message]

                [message]
                    id=$unit.id
                    message= _ "I'll try to slip past the trolls. You wait here."
                [/message]
            [/then]
        [/if]
    [/event]

    [event]
        name=moveto

        [filter]
            side=1

            [filter_location]
                x=23,30
                y=11,14
                radius=6
            [/filter_location]
        [/filter]

        [remove_shroud]
            side=1
            x=17-36,12-33
            y= 5-18, 7-19
            [and]
                radius=20
            [/and]
            [not]
                terrain=X*
                [filter_adjacent_location]
                    terrain=X*
                    count=6
                [/filter_adjacent_location]
            [/not]
        [/remove_shroud]

        [message]
            speaker=King Dra-Nak
            message= _ "Ha-ha! These humans will make excellent slaves in my mines!"
        [/message]

        [message]
            speaker=unit
            message={WHISPER _"Opening the cells should confuse the guards for a moment. But I better not get too close to them..."}
        [/message]
    [/event]

    [event]
        name=attack

        [filter]
            side=1

            [filter_wml]
                [variables]
                    undercover=yes
                [/variables]
            [/filter_wml]
        [/filter]

        [fire_event]
            name=exposed

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

    [event]
        name=new turn

        [filter_condition]
            [have_unit]
                side=1

                [filter_wml]
                    [variables]
                        undercover=yes
                    [/variables]
                [/filter_wml]

                [filter_adjacent]
                    type=Troll Warrior,Orcish Warrior,Orcish Warlord
                [/filter_adjacent]
            [/have_unit]
        [/filter_condition]

        [fire_event]
            name=exposed

            [primary_unit]
                side=1

                [filter_wml]
                    [variables]
                        undercover=yes
                    [/variables]
                [/filter_wml]
            [/primary_unit]
        [/fire_event]
    [/event]

    [event]
        name=exposed

        [message]
            side=2
            [filter_adjacent]
                x,y=$x1,$y1
            [/filter_adjacent]
            message= _ "Eh?"
        [/message]

        [if]
            [variable]
                name=unit.gender
                equals=female
            [/variable]

            [then]
                [message]
                    speaker=King Dra-Nak
                    message= _ "Hey! Who are you? Get her!"
                [/message]
            [/then]

            [else]
                [message]
                    speaker=King Dra-Nak
                    message= _ "Hey! Who are you? Get him!"
                [/message]
            [/else]
        [/if]

        [message]
            x,y=$x1,$y1
            message= _ "Uh oh!"
        [/message]

        [fire_event]
            name=remove disguise

            [primary_unit]
                x,y=$x1,$y1
            [/primary_unit]
        [/fire_event]

        {MODIFY_UNIT side=2 status.guardian no}
    [/event]

    [event]
        name=moveto
        first_time_only=no

        [filter]
            side=1

            [filter_location]
                [filter_adjacent_location]
                    terrain=Re^Xo
                    adjacent=nw,n,ne
                [/filter_adjacent_location]
            [/filter_location]
        [/filter]

        [message]
            speaker=unit
            message= _ "Here's one of the prison cells! Let me open it..."
        [/message]

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

        [store_locations]
            terrain=Re^Xo

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

            variable=adjacent_gate_loc
        [/store_locations]

        [terrain]
            x,y=$adjacent_gate_loc.x,$adjacent_gate_loc.y
            terrain=Re
        [/terrain]

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

        [redraw]
        [/redraw]

        {MODIFY_UNIT (
            side=3

            [filter_location]
                x,y=$adjacent_gate_loc.x,$adjacent_gate_loc.y
                radius=5

                [filter_radius]
                    terrain=!,X*
                [/filter_radius]
            [/filter_location]
        ) side 1}

        {CLEAR_VARIABLE adjacent_gate_loc}
    [/event]

    [event]
        name=moveto

        [filter]
            side=1
            x=17,18
            y=11,10
        [/filter]

        {MODIFY_UNIT (side,x,y=3,13-16,8-10) side 1}

        [message]
            x=13-16
            y=8-10
            message= _ "Finally, we're rescued!"
        [/message]

        [fire_event]
            name=free heroes
        [/fire_event]
    [/event]

    [event]
        name=moveto

        [filter]
            side=1
            x=21,22
            y=9,8
        [/filter]

        {MODIFY_UNIT (side,x,y=3,18-22,6-8) side 1}

        [message]
            x=18-22
            y=6-8
            message= _ "At last!"
        [/message]

        [fire_event]
            name=free heroes
        [/fire_event]
    [/event]

    [event]
        name=moveto

        [filter]
            side=1
            x=28,29
            y=9,10
        [/filter]

        {MODIFY_UNIT (side,x,y=3,29-32,7-9) side 1}

        [message]
            x=29-32
            y=7-9
            message= _ "Now let's get out of here!"
        [/message]

        [fire_event]
            name=free heroes
        [/fire_event]
    [/event]

    [event]
        name=free heroes

        [message]
            speaker=King Dra-Nak
            message= _ "What? Who's there? Get them!"
        [/message]

        [fire_event]
            name=remove disguise

            [primary_unit]
                side=1
                [filter_wml]
                    [variables]
                        undercover=yes
                    [/variables]
                [/filter_wml]
            [/primary_unit]
        [/fire_event]

        {MODIFY_UNIT side=2 status.guardian no}

        {MODIFY_UNIT canrecruit,side=yes,1 canrecruit no}

        {MODIFY_UNIT (
            id=Gweddry

            [or]
                id=Dacyn
            [/or]

            [or]
                id=Owaec
            [/or]
        ) side 1}

        [redraw]
            side=1
        [/redraw]

        [message]
            speaker=Dacyn
            message= _ "The guards are distracted! Now is the time to escape!"
        [/message]

        [message]
            speaker=Owaec
            message= _ "The eastern entrance is teeming with orcs. We have to find another way to exit to the west!"
        [/message]

        [if]
            [variable]
                name=stored_player_gold
                greater_than_equal_to=1
            [/variable]

            [then]
                [message]
                    speaker=Gweddry
                    message= _ "We have to get our gold back first! It must have been taken to their treasury."
                [/message]

                {HIGHLIGHT_IMAGE 33 11 items/chest-plain-closed.png ()}
            [/then]
        [/if]

        [modify_turns]
            value="$($turn_number + 15)"
        [/modify_turns]

        [objectives]
            side=1
            [objective]
                description= _ "Gweddry reaches the western exit"
                condition=win
            [/objective]
            [objective]
                description= _ "Retrieve the stolen gold"
                condition=win
                [show_if]
                    [variable]
                        name=stored_player_gold
                        greater_than_equal_to=1
                    [/variable]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Release the remaining prisoners"
                condition=win
                [show_if]
                    [have_unit]
                        side=3
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Gweddry"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Dacyn"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Owaec"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

            [gold_carryover]
                carryover_percentage=100
            [/gold_carryover]
        [/objectives]

        [modify_side]
            side=2
            recruit=Orcish Grunt,Troll Whelp,Orcish Archer,Orcish Assassin
            {GOLD 40 50 60}
        [/modify_side]

        [event]
            name=new turn
            first_time_only=no

            {RANDOM "Orcish Warlord,Troll Warrior,Orcish Slurbow"}

            [if]
                [variable]
                    name=turn_number
                    less_than="$($turn_number + 2)"
                [/variable]

                [then]
                    {GENERIC_UNIT 2 $random 42 14}
                [/then]

                [else]
                    [if]
                        [variable]
                            name=turn_number
                            less_than="$($turn_number + 4)"
                        [/variable]

                        [then]
                            {GENERIC_UNIT 2 $random 41 14}
                            {GENERIC_UNIT 2 $random 42 14}
                        [/then]

                        [else]
                            {GENERIC_UNIT 2 $random 41 14}
                            {GENERIC_UNIT 2 $random 41 15}
                            {GENERIC_UNIT 2 $random 42 14}
                        [/else]
                    [/if]
                [/else]
            [/if]
        [/event]

        [event]
            name=new turn

            [remove_shroud]
                side=1
                x,y=41,15
                radius=2
            [/remove_shroud]

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

            [message]
                speaker=Gweddry
                message= _ "They have reinforcements pouring in from the eastern entrance! We have to get out of here quickly!"
            [/message]

            [place_shroud]
                side=1
                x,y=41,15
                radius=2
            [/place_shroud]
        [/event]
    [/event]

    [event]
        name=remove disguise

        {VARIABLE unit.variables.undercover was}
        {CLEAR_VARIABLE unit.profile}

        {FOREACH unit.modifications.object i}
            [if]
                [variable]
                    name=unit.modifications.object[$i].id
                    equals=disguise
                [/variable]

                [then]
                    {CLEAR_VARIABLE unit.modifications.object[$i]}
                [/then]
            [/if]
        {NEXT i}

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

    [event]
        name=moveto

        [filter]
            side=1
            x,y=33,11
        [/filter]

        [filter_condition]
            [variable]
                name=stored_player_gold
                greater_than_equal_to=1
            [/variable]
        [/filter_condition]

        [message]
            speaker=unit
            message= _ "All the gold the orcs took is in this chest!"
            sound=open-chest.wav
        [/message]

        [gold]
            side=1
            amount=$stored_player_gold
        [/gold]

        [message]
            speaker=narrator
            message= _ "You've regained $stored_player_gold gold!"
            image=wesnoth-icon.png
            sound=gold.ogg
        [/message]

        [remove_item]
            x,y=33,11
            image=items/chest-plain-closed.png
        [/remove_item]

        {PLACE_IMAGE items/chest-plain-open.png 33 11}

        {CLEAR_VARIABLE stored_player_gold}
    [/event]

    {PICKUPPABLE_ITEM holy_amulet 31 23 side=1 items/ankh-necklace.png
    _"Wearing this amulet will cause every blow you deal to inflict <i>arcane</i> damage!"
    _"holy amulet^Take it"
    _"holy amulet^Leave it"
    _"I am not suited to using this item! Let another take it." (
        [object]
            name= _ "Holy Amulet"
            image=items/ankh-necklace.png
            duration=forever

            [effect]
                apply_to=attack
                range=melee
                set_type=arcane
            [/effect]
            [effect]
                apply_to=attack
                range=ranged
                set_type=arcane
            [/effect]
        [/object]
    )}

    [event]
        name=moveto

        [filter]
            side=1
            x=1
            y=19-24
            [filter_wml]
                [variables]
                    undercover=yes
                [/variables]
            [/filter_wml]
        [/filter]

        [message]
            speaker=unit
            message= _ "Phew! I made it."
        [/message]

        [message]
            side=1
            [not]
                x,y=$x1,$y1
            [/not]
            message= _ "Where are you going?! Come back!"
        [/message]

        {FOREIGN_DEFEAT}

        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Gweddry
            x=1
            y=19-24
        [/filter]
        [message]
            speaker=Gweddry
            message= _ "Good! We have escaped these accursed caves!"
        [/message]

        [endlevel]
            result=victory
            bonus=yes
            {NEW_GOLD_CARRYOVER 100}
        [/endlevel]
    [/event]

    [event]
        name=victory

        {MODIFY_UNIT (
            side=1

            [filter_wml]
                [variables]
                    temporary_free_upkeep=yes
                [/variables]
            [/filter_wml]
        ) upkeep full}
    [/event]

    {FOREIGN_DEFEAT}
[/scenario]
