#textdomain wesnoth-tsg
[scenario]
    id=6b_The_Long_March

    name= _ "The Long March"
    next_scenario=7b_Pebbles_In_The_Flood
    [music]
        name=revelation.ogg
        ms_before=500
    [/music]
    [music]
        name=northerners.ogg
        ms_before=500
        append=yes
    [/music]

    map_data="{campaigns/The_South_Guard/maps/6b_The_Long_March.map}"

    {campaigns/The_South_Guard/utils/sg_deaths.cfg}

    {DUSK}
    {FIRST_WATCH}
    {SECOND_WATCH}
    {DAWN}
    {MORNING}
    {AFTERNOON}

    victory_when_enemies_defeated=no
    turns=40

    # The South Guard

    [side]
        side=1
        type=Horseman Commander
        description=Deoran
        user_description= _ "Deoran"
        unrenamable=yes
        team_name=South_Guard
        controller=human
        {CUSTOM_SG_FLAG}

        fog=no
        shroud=yes
        share_view=yes
        share_maps=yes

        {GOLD 125 100 80}
        {INCOME 6 4 2}

        canrecruit=yes
        recruit=Bowman, Spearman, Cavalryman, Thug, Footpad, Poacher
    [/side]

    # This is a side for the elvish ambushers, who are still in hiding and will
    # remain idle until discovered

    [side]
        side=2
        no_leader=yes
        
        # problem: they have to be on the same team
        # as the other elves, otherwise they get
        # slaughtered by the active ambusher
        #
        # but they also have to be on the undead team
        # otherwise they get slaughtered by those
        # 
        # but that means that the undead and elves are
        # all on the same side, which is a shame
        team_name=elves
        
        controller=ai

        [ai]
            ai_algorithm=idle_ai
        [/ai]
    [/side]

    # The Undead Hordes (Part II)

    [side]
        side=3
        no_leader=yes

        team_name=elves
        controller=ai

        {GOLD 10 20 30}
        {INCOME 1 2 3}

        canrecruit=yes
        [ai]
            recruitment_pattern=scout
            aggression=-0.25
            [target]
                side=1
                value=3.0
            [/target]
        [/ai]
        recruit=Vampire Bat
    [/side]
    
    # When discovering an ambusher, the ambusher will be moved to this side so
    # it may move and attack normally

    [side]
        side=4
        colour=blue
        no_leader=yes
        team_name=elves
        controller=ai

        [ai]
            aggression=0.7
            caution=0.4
            [target]
                side=1
                value=6.0
            [/target]
        [/ai]
    [/side]


    #prestart
    [event]
        name=prestart

        {PLACE_IMAGE (items/gohere.png) 16 3}

        {SG_GUARD (Naga Warrior) (Fssth) (_"Fssth") 4 9 14}

#ifdef NORMAL
        {SG_GUARD (Naga Fighter) (Wizzi) (_"Wizzi") 4 10 14}
#endif

#ifdef HARD
        {SG_GUARD (Naga Warrior) (Wizzi) (_"Wizzi") 4 10 14}
#endif

        [recall]
            description=Sir Gerrick
        [/recall]
        [recall]
            description=Minister Hylas
        [/recall]
        [recall]
            description=Jarek
        [/recall]
        [recall]
            description=Urza Afalas
        [/recall]
        
        
        # retrieve two units from the recall list
        # but with certain criteria
        # first: a swordsman
        
        [store_unit]
            variable=swordsman
            [filter]
                side=1
                # not on the map
                [not]
                    [filter_location]
                        x=1-36
                    [/filter_location]
                [/not]
                # a unit that can still advance
                [not]
                    level=3
                [/not]
                # whose first melee attack is "blade"
                [wml_filter]
                    [attack]
                        type="blade"
                    [/attack]
                [/wml_filter]
            [/filter]
        [/store_unit]
        
        # pick the "best" unit
        # that is, the one with the highest damage + xp/4
        # and a little random spice
        {VARIABLE best_score 0}
        {VARIABLE best_unit -1}
        {FOREACH swordsman i}
            {VARIABLE dam $swordsman[$i].attack[0].damage}
            {VARIABLE_OP dam multiply $swordsman[$i].attack[0].number}
            {VARIABLE xp $swordsman[$i].experience}
            {VARIABLE_OP xp divide 4}
            {VARIABLE_OP dam add xp}
            {RANDOM 0..6}
            {VARIABLE_OP dam add $random}
            [if]
                [variable]
                    name=dam
                    greater_than=$best_score
                [/variable]
                [then]
                    {VARIABLE best_score $dam}
                    {VARIABLE best_unit $i}
                [/then]
            [/if]
        {NEXT i}
        [recall]
            description=$swordsman[$best_unit].description
        [/recall]
        {CLEAR_VARIABLE swordsman}
        
        
        # now an archer
        
        [store_unit]
            variable=archer
            [filter]
                side=1
                # not on the map
                [not]
                    [filter_location]
                        x=1-36
                    [/filter_location]
                [/not]
                # who can still advance
                [not]
                    level=3
                [/not]
                # whose second attack is ranged pierce
                [wml_filter]
                    [attack]
                        type="pierce"
                        range="ranged"
                    [/attack]
                [/wml_filter]
            [/filter]
        [/store_unit]
        
        # pick the "best" unit
        # that is, the one with the highest damage + xp/4
        # and a little random spice
        {VARIABLE best_score 0}
        {VARIABLE best_unit -1}
        {FOREACH archer i}
            {VARIABLE dam $archer[$i].attack[1].damage}
            {VARIABLE_OP dam multiply $archer[$i].attack[1].number}
            {VARIABLE xp $archer[$i].experience}
            {VARIABLE_OP xp divide 4}
            {VARIABLE_OP dam add xp}
            {RANDOM 0..6}
            {VARIABLE_OP dam add $random}
            [if]
                [variable]
                    name=dam
                    greater_than=$best_score
                [/variable]
                [then]
                    {VARIABLE best_score $dam}
                    {VARIABLE best_unit $i}
                [/then]
            [/if]
        {NEXT i}
        [recall]
            description=$archer[$best_unit].description
        [/recall]
        {CLEAR_VARIABLE archer}
        
        
        # Note: the code for the ambushers is mostly identical to that of
        # Crossroads in HttT.

        # Here we set up an array that holds the possible ambusher unit types.
        # We do this instead of just using a random type when creating the
        # ambusher so that the even distribution of different types is
        # guaranteed.

        {VARIABLE random_ambusher_type_table[0].type "Elvish Hero"}
        {VARIABLE random_ambusher_type_table[1].type "Elvish Marksman"}
        {VARIABLE random_ambusher_type_table[2].type "Elvish Druid"}
        {VARIABLE random_ambusher_type_table[3].type "Elvish Fighter"}
        {VARIABLE random_ambusher_type_table[4].type "Elvish Archer"}
        {VARIABLE random_ambusher_type_table[5].type "Elvish Captain"}
        {VARIABLE random_ambusher_type_table[6].type "Elvish Ranger"}
        {VARIABLE random_ambusher_type_table[7].type "Elvish Hero"}
        {VARIABLE random_ambusher_type_table[8].type "Elvish Fighter"}

        {VARIABLE random_ambusher_type_i 0}
        

# place an elvish ambusher
# who hides in the forest until he changes side
        
#define ELVISH_AMBUSHER X Y SIDE TYPE
                    [unit]
                        x={X}
                        y={Y}
                        type={TYPE}
                        side={SIDE}
                        random_traits=yes
                        upkeep=loyal

                        [status]
                            hides=yes
                        [/status]
                    [/unit]

                    [object]
                        silent=yes

                        [filter]
                            x,y={X},{Y}
                        [/filter]

                        [effect]
                            apply_to=new_ability

                            [abilities]
                                [hides]
                                    id=elvish_ambush
                                    affect_self=yes

                                    [filter_self]
                                        # only effective as long as the unit
                                        # is on the ambusher side
                                        side={SIDE}

                                        [filter_location]
                                            terrain=Gs^Fp
                                        [/filter_location]
                                    [/filter_self]
                                [/hides]
                            [/abilities]
                        [/effect]
                    [/object]
#enddef

#define ELVISH_AMBUSH_AREA SIDE X_SPAN Y_SPAN NUMBER
    {VARIABLE ambushers 0}

    [while]
        [variable]
            name=ambushers
            less_than={NUMBER}
        [/variable]

        [do]
            [store_locations]
                x={X_SPAN}
                y={Y_SPAN}
                terrain=Gs^Fp

                [not]
                    [filter]
                    [/filter]
                [/not]
                
                # not too close to the starting area
                [not]
                    x=21-36
                    y=43-50
                [/not]
                
                # not too close to the fixed ambush
                [not]
                    x=12-14
                    y=33-35
                [/not]

                [filter_adjacent_location]
                        terrain=Rp,Rd,Re
                [/filter_adjacent_location]

                [not]
                    [filter_adjacent_location]
                        [filter]
                        [/filter]
                    [/filter_adjacent_location]
                [/not]

                variable=possible_ambush_locations
            [/store_locations]

            [if]
                [variable]
                    name=possible_ambush_locations.length
                    greater_than=0
                [/variable]

                [then]
                    {RANDOM 0..$possible_ambush_locations.length}

                    # Check if the random location picked already contains an ambusher
                    # and if it does, we loop again to pick another one until an empty
                    # one is found.

                    {VARIABLE_OP random_ambusher_type_i add 1}

                    [if]
                        [variable]
                            name=random_ambusher_type_i
                            equals=$random_ambusher_type_table.length
                        [/variable]

                        [then]
                            {VARIABLE random_ambusher_type_i 0}
                        [/then]
                    [/if]

                    # And here we place an ambusher of a type specified by the
                    # random_ambusher_type_table and random_ambusher_type_i
                    # variables, thus always having the same ratio of different
                    # types.

                    {ELVISH_AMBUSHER ($possible_ambush_locations[$random].x) ($possible_ambush_locations[$random].y) ({SIDE}) ($random_ambusher_type_table[$random_ambusher_type_i].type)}

                    {VARIABLE_OP ambushers add 1}
                [/then]

                [else]
                    # If no possible ambush locations were found, we terminate the loop

                    {VARIABLE ambushers 999}
                [/else]
            [/if]
        [/do]
    [/while]
#enddef

        
        # undead spawn types depend on difficulty
        # number of elven ambushers, too
        # and place different types of Elvish Ambushers
        # in the fixed central valley ambush
        
#ifdef EASY
        {VARIABLE undead_spawn_types "Ghost,Wraith,Shadow,Skeleton Archer,Revenant,Deathblade,Blood Bat,Ghoul,Ghost,Wraith,Shadow"}
        {VARIABLE ambushing_elves 32}
        {ELVISH_AMBUSHER 12 34 2 "Elvish Archer"}
        {ELVISH_AMBUSHER 13 33 2 "Elvish Fighter"}
        {ELVISH_AMBUSHER 14 30 2 "Elvish Archer"}
#endif
        
#ifdef NORMAL
        {VARIABLE undead_spawn_types "Wraith,Shadow,Bone Shooter,Revenant,Deathblade,Blood Bat,Ghoul,Wraith,Shadow"}
        {VARIABLE ambushing_elves 40}
        {ELVISH_AMBUSHER 12 34 2 "Elvish Archer"}
        {ELVISH_AMBUSHER 13 33 2 "Elvish Hero"}
        {ELVISH_AMBUSHER 14 30 2 "Elvish Ranger"}
#endif

#ifdef HARD
        {VARIABLE undead_spawn_types "Wraith,Shadow,Bone Shooter,Revenant,Deathblade,Necrophage,Wraith,Shadow,Shadow"}
        {VARIABLE ambushing_elves 48}
        {ELVISH_AMBUSHER 12 34 2 "Elvish Ranger"}
        {ELVISH_AMBUSHER 13 33 2 "Elvish Hero"}
        {ELVISH_AMBUSHER 14 30 2 "Elvish Ranger"}
#endif

        {ELVISH_AMBUSHER 12 33 2 "Elvish Sorceress"}
        {ELVISH_AMBUSHER 14 33 2 "Elvish Captain"}

        {TIME_ACTIONS (
            {ELVISH_AMBUSH_AREA 2 1-29 23-50 $ambushing_elves}
        )}

        {CLEAR_VARIABLE possible_ambush_locations}
        {CLEAR_VARIABLE random_ambusher_type_table}
        {CLEAR_VARIABLE random_ambusher_type_i}
        {CLEAR_VARIABLE ambusher}
        {CLEAR_VARIABLE ambushing_elves}
        
        # set ambush dialog variables
        {VARIABLE ambush 0}
        {VARIABLE ambush_x 99}
        {VARIABLE ambush_y 99}
        {VARIABLE ambush_distance 80}
        

        # store the secret paths and cover them with forest
        # Rp -> Re covered by forest
        
        [store_locations]
            variable=secret_path
            terrain=Rp
        [/store_locations]
        {FOREACH secret_path i}
            {MODIFY_TERRAIN Gs^Fp $secret_path[$i].x $secret_path[$i].y}
        {NEXT i}
        
        # Rd -> Gg covered by forest
        [store_locations]
            variable=secret_track
            terrain=Rd
        [/store_locations]
        {FOREACH secret_track i}
            {MODIFY_TERRAIN Gs^Fp $secret_track[$i].x $secret_track[$i].y}
        {NEXT i}
        
        # urza dialogue variables
        # coordinates of last dialogue
        {VARIABLE urza_x 24}
        {VARIABLE urza_y 46}
        {VARIABLE urza_dialogue_num 0}
        
        # the various messages
        {VARIABLE urza_dialogue[0].msg ( _ "We have to go even further west. There are elves living to the north, and I don't think they'll receive us too kindly!")}
        {VARIABLE urza_dialogue[1].msg ( _ "Come on! Hurry!")}
        {VARIABLE urza_dialogue[2].msg ( _ "Keep moving!")}
        {VARIABLE urza_dialogue[3].msg ( _ "We're almost there!")}
        {VARIABLE urza_dialogue[4].msg ( _ "Just a little further!")}
        
    [/event]
    
    [event]
        name=moveto
        first_time_only=no
        
        # reveal all hidden paths within 3 hexes
        # of where Urza moves
        
        [filter]
            description=Urza Afalas
            [filter_location]
                terrain=Gg,Hh,Re,Gs^Fp
                # do the radius checking here, too
                # so the dialogue only displays when
                # Urza is actually "continuing" on the path
                [and]
                    radius=3
                    find_in=secret_path
                    [or]
                        radius=3
                        find_in=secret_track
                    [/or]
                [/and]
            [/filter_location]
        [/filter]
        [store_locations]
            variable=uncover
            terrain=Gs^Fp
            find_in=secret_path
            [and]
                x,y=$x1,$y1
                radius=3
            [/and]
        [/store_locations]
        {FOREACH uncover i}
            {MODIFY_TERRAIN Re $uncover[$i].x $uncover[$i].y}
        {NEXT i}
        [store_locations]
            variable=uncover
            terrain=Gs^Fp
            find_in=secret_track
            [and]
                x,y=$x1,$y1
                radius=3
            [/and]
        [/store_locations]
        {FOREACH uncover i}
            {MODIFY_TERRAIN Gg $uncover[$i].x $uncover[$i].y}
        {NEXT i}
        
        # check if a new dialogue part is needed
        # do that if the distance between this event and the 
        # last dialogue is more than 8 hexes
        
        {VARIABLE x_delta $urza_x}
        {VARIABLE_OP x_delta add -$x1}
        {VARIABLE_OP x_delta multiply $x_delta}
        {VARIABLE y_delta $urza_y}
        {VARIABLE_OP y_delta add -$y1}
        {VARIABLE_OP y_delta multiply $y_delta}
        
        [if]
            [variable]
                name=x_delta
                greater_than=80
            [/variable]
            [or]
                [variable]
                    name=y_delta
                    greater_than=80
                [/variable]
            [/or]
            [then]
                {VARIABLE urza_x $x1}
                {VARIABLE urza_y $y1}
                [if]
                    [variable]
                        name=urza_dialogue_num
                        less_than=$urza_dialogue.length
                    [/variable]
                    [then]
                        [message]
                            speaker=Urza Afalas
                            message= $urza_dialogue[$urza_dialogue_num].msg
                        [/message]
                        {VARIABLE_OP urza_dialogue_num add 1}
                    [/then]
                [/if]
            [/then]
        [/if]
        
        # we'll allow undo even if terrain was uncovered
        # the dialogue will break undoing, anyway
        [allow_undo]
        [/allow_undo]
    [/event]
    
    # elven ambush event
    [event]
        name=moveto
        first_time_only=no

        [filter]
            side=1

            [filter_adjacent]
                side=2
            [/filter_adjacent]
        [/filter]
        
        # swap all elves within 5 hexes to the active side
        # they effectively join the ambush
        {MODIFY_UNIT (
            side=2
            [filter_location]
                terrain=Gs^Fp
                [and]
                    x,y=$x1,$y1
                    radius=5
                [/and]
            [/filter_location]
        ) side 4}

        [redraw][/redraw]
        
        # do a dialog if the last ambush was far enough away
        # we just want to prevent triggering all the dialogue in
        # the first part of the journey!
        # (...not that there is that much dialogue here...)
        
        {VARIABLE x_delta $ambush_x}
        {VARIABLE_OP x_delta add -$x1}
        {VARIABLE_OP x_delta multiply $x_delta}
        {VARIABLE y_delta $ambush_y}
        {VARIABLE_OP y_delta add -$y1}
        {VARIABLE_OP y_delta multiply $y_delta}
        
        # if the last ambush dialogue was 9 hexes or more 
        # distant, do another one
        [if]
            [variable]
                name=x_delta
                greater_than=$ambush_distance
            [/variable]
            [or]
                [variable]
                    name=y_delta
                    greater_than=$ambush_distance
                [/variable]
            [/or]
            [then]
                {VARIABLE_OP ambush add 1}
                {VARIABLE ambush_x $x1}
                {VARIABLE ambush_y $y1}
                [if]
                    [variable]
                        name=ambush
                        equals=1
                    [/variable]
                    [then]
                        [message]
                            race=elf
                            side=4
                            message= _"You humans have kidnaped Mebrin the Sage. You will pay for your crimes."
                        [/message]
                        [message]
                            description=Deoran
                            message= _"Your sage Mebrin is the criminal. He practices necromancy and has turned himself into Lich. By the laws of Wesnoth, the punnishment for his crimes is death!"
                        [/message]
                        [message]
                            race=elf
                            side=4
                            message= _"It is you who is a criminal and who is in a company of criminals. We will not let you kill Mebrin!"
                        [/message]
                        [message]
                            description=Deoran
                            message= _"I was a fool to waste my words on you. Prepare to meet your beloved Mebrin or should I say Mal M'brin in hell, elves !"
                        [/message]
                    [/then]
                    [else]
                        [if]
                            [variable]
                                name=ambush
                                greater_than=1
                            [/variable]
                            [then]
                                [message]
                                    race=elf
                                    side=4
                                    message= _ "Get them !"
                                [/message]
                                {VARIABLE_OP ambush_distance add 40}
                            [/then]
                        [/if]
                    [/else]
                [/if]
            [/then]
        [/if]
    [/event]

    [event]
        name=start

        [message]
            speaker=narrator
            message= _ "Deoran and Urza Afalas led their men quickly from the ruins of Mal M'brin's fortress..."
            image=wesnoth-icon.png
        [/message]

        [message]
            speaker=Deoran
            message= _ "Will this forest ever end? How can we know what path to take?!"
        [/message]
        [message]
            speaker=Urza Afalas
            message= _ "You have to follow me! There are many false paths in these woods. Some are dead ends, others are even worse!"
        [/message]
        [message]
            speaker=Sir Gerrick
            message= _ "Can we trust him? His people are murderers and thieves!"
        [/message]
        [message]
            speaker=Minister Hylas
            message= _ "Do we have any choice? Our food is running out, and it will be winter soon..."
        [/message]

        {MOVE_UNIT (description=Urza Afalas) 24 46}
        
        # reveal the first bit of path
        
        {MODIFY_TERRAIN Gg 23 47}
        # note: the following is NOT supposed to be supplied as a RANGE!
        # change the individual coordinates 22,47 and 21,48 !
        {MODIFY_TERRAIN Re 22,21 47,48}
        [remove_shroud]
            side=1
            x=19-22
            y=46-49
        [/remove_shroud]
        [redraw]
        [/redraw]
        
        [message]
            speaker=Urza Afalas
            message= _ "This way! The only ford is a bit west of here, and the path to the north will lead you into trouble!"
        [/message]
        
        [message]
            speaker=Sir Gerrick
            message= _ "I think we should head north. The road leads north, and the ford is north. Why does he want us to head west?"
        [/message]
        [message]
            speaker=Minister Hylas
            message= _ "Beware! I sense that there are undead monsters who have escaped Mal M'brin's control running around in that area."
        [/message]

        [objectives]
            side=1
            [objective]
                description= _ "Make your way to the north edge of the woods"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Deoran"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Sir Gerrick"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Minister Hylas"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Urza Afalas"
                condition=lose
            [/objective]
            [objective]
                description= _ "Time runs out"
                condition=lose
            [/objective]
        [/objectives]
    [/event]

    [event]
        name=die
        [filter]
            description=Urza Afalas
        [/filter]
        [message]
            speaker=unit
            image=portraits/urza-afalas.png
            message= _ "Now I pay for my crimes. But how many others will also suffer for them?"
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]


    # re-spawn some undead after turn 2
    # up to a maximum number depending on the turn
    # place them slightly east of the mountain range
    [event]
        name=turn 2

        [event]
            name=new turn
            first_time_only=no

            {VARIABLE undead_spawns $turn_number}
            {VARIABLE_OP undead_spawns add -2}
            
            # we'll subtract the number of undead that already exist
            [store_unit]
                [filter]
                    race=undead
                [/filter]
                variable=undead
            [/store_unit]        

            [if]
                [variable]
                    name=undead_spawns
                    greater_than=4
                [/variable]

                [then]
                    {VARIABLE undead_spawns 5}
                [/then]

                [else]
                    {VARIABLE undead_spawns $turn_number}
                [/else]
            [/if]
            
            {VARIABLE_OP undead_spawns add -$undead.length}

            {REPEAT $undead_spawns (
                {VARIABLE_OP undead_spawn_y random "19..34"}

                {VARIABLE_OP undead_spawn_type random $undead_spawn_types}

                [unit]
                    side=3
                    type=$undead_spawn_type
                    x,y=19,$undead_spawn_y
                [/unit]
            )}
        [/event]
    [/event]

    [event]
        name=moveto
        [filter]
            x,y=1-18,1-28
            description=Urza Afalas
        [/filter]

        {MOVE_UNIT (description=Urza Afalas) 9 25}
        [message]
            speaker=Urza Afalas
            message= _ "Hurry! There are bandits in these woods!"
        [/message]
        [message]
            speaker=Deoran
            message= _ "Why should that worry us?! Aren't you their leader?"
        [/message]
        [message]
            speaker=Urza Afalas
            message= _ "We're bandits, after all. Not all of them are loyal to me."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            x,y=7-11,1-27
            description=Deoran
        [/filter]

        {MOVE_UNIT (description=Urza Afalas) 10 18}
        [message]
            speaker=Urza Afalas
            message= _ "The river is just ahead!"
        [/message]

#ifdef HARD
        {GENERIC_UNIT 4 Bandit 5 28}
#else
        {GENERIC_UNIT 4 Thug 5 28}
#endif

#ifdef EASY
        {GENERIC_UNIT 4 Thief 6 28}
#else
        {GENERIC_UNIT 4 Rogue 6 28}
#endif

#ifdef EASY
        {GENERIC_UNIT 4 Footpad 5 32}
#else
        {GENERIC_UNIT 4 Outlaw 5 32}
#endif
#ifdef HARD
        {GENERIC_UNIT 4 Trapper 5 31}
#else
        {GENERIC_UNIT 4 Poacher 5 31}
#endif
        [message]
            type=Trapper
            message= _ "The elves payed us well to kill you."
        [/message]
        [message]
            type=Poacher
            message= _ "The elves payed us well to kill you."
        [/message]
        [message]
            description=Urza Afalas
            message= _ "You bastards!"
        [/message]
        [message]
            type=Thief
            message= _ "You would have done the same to us if you were in our place!"
        [/message]
        [message]
            type=Rogue
            message= _ "You would have done the same to us if you were in our place!"
        [/message]
        [message]
            description=Urza Afalas
            message= _ "I probably would have..."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            x,y=5-14,1-19
            description=Deoran
        [/filter]

        [message]
            speaker=Urza Afalas
            message= _ "From here you can see the banks of the river! Across it we will find the sun again, and an end to these cursed trees!"
        [/message]
    [/event]

    # Elvish Ambush

    [event]
        name=moveto
        [filter]
            side=1
            x,y=12-15,31-33
        [/filter]

        {SG_GUARD (Elvish Fighter) (Urien) (_"Urien") 4 12 34}
        {SG_GUARD (Elvish Archer) (Jesa) (_"Jesa") 4 15 31}
        {SG_GUARD (Elvish Archer) (Plinth) (_"Plinth") 4 15 34}

        [message]
            speaker=Plinth
            message= _ "We cannot allow you bandits and criminals to pass through our lands!"
        [/message]
        [message]
            speaker=Urza Afalas
            message= _ "But we have slain the undead - we wish only to return to our homes!"
        [/message]
        [message]
            speaker=Plinth
            message= _ "Nevertheless, we will have vengeance for Mebrin!!"
        [/message]
    [/event]

    # Deoran exits the forest.

    [event]
        name=moveto
        [filter]
            description=Deoran
            x,y=16,3
        [/filter]
        [message]
            speaker=Deoran
            message= _ "Thank heaven we have escaped that awful forest!"
        [/message]
        [message]
            speaker=Sir Gerrick
            message= _ "Indeed, Afalas, you've earned my trust today."
        [/message]
        [message]
            speaker=Urza Afalas
            message= _ "I can only hope for mercy when I return to Westin."
        [/message]

        [message]
            speaker=narrator
            message= _ "But there was a dark cloud looming behind Deoran and his men..."
            image=wesnoth-icon.png
        [/message]
        
        {CLEAR_VARIABLE secret_path}
        {CLEAR_VARIABLE secret_track}
        {CLEAR_VARIABLE urza_dialogue}
        {CLEAR_VARIABLE ambush}
        {CLEAR_VARIABLE ambush_x}
        {CLEAR_VARIABLE ambush_y}
        {CLEAR_VARIABLE urza_x}
        {CLEAR_VARIABLE urza_y}
        {CLEAR_VARIABLE urza_dialogue_num}
        {CLEAR_VARIABLE x_delta}
        {CLEAR_VARIABLE y_delta}

        [endlevel]
            bonus=yes
            result=victory
        [/endlevel]
        
    [/event]
[/scenario]
