#textdomain wesnoth-l
[scenario]
    id=05_Hide_and_Seek
    next_scenario=06_The_Hunters
    victory_when_enemies_defeated=no
    name= _ "Hide and Seek"
    map_file=05_Hide_and_Seek.map
    turns=28

    {MIDNIGHT}
    {MIDNIGHT}
    {MIDNIGHT}
    {MIDNIGHT}
    {MIDNIGHT}
    {MIDNIGHT}
    {MIDNIGHT}
    {MIDNIGHT}
    {MIDNIGHT}
    {MIDNIGHT}
    {MIDNIGHT}
    {MIDNIGHT}
    {MIDNIGHT}
    {MIDNIGHT}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {DAWN}

    {INTRO_AND_SCENARIO_MUSIC knolls.ogg underground.ogg}
    {EXTRA_SCENARIO_MUSIC the_deep_path.ogg}
    {EXTRA_SCENARIO_MUSIC nunc_dimittis.ogg}

    [story]
        [part]
            story= _ "22 Deeproot, 501 YW

Been a tough few days since we left Elensefar with all them patrols running around. Going by boat along the Great River, we has been managing to avoid them Wesnothians, but being constantly on the lookout be real taxing. I truly be starting to feel that tiredness in my bones... old men like me should be sitting back at home, resting our grey bodies and watchin’ over them younger folk growing up. I don’t got no business here, running around as some outlaw. Maybe if I was ten years younger..."
            background=story/frontier.webp
        [/part]
        [part]
            story= _ "Anyway, the messenger I sent back to Relana should be in Delwyn already. We should be arriving to Carcyn soon too, to where that coward Maddock said his ‘contact’ be. Truths be told, I don’t know how this’ll be turning out, especially since I don’t be no social butterfly like sis were. Don’t like me no city folk really. But I’ll deal with them if I gots to."
            background=story/frontier.webp
        [/part]
    [/story]

    {LIBERTY_BIGMAP {JOURNEY_05_NEW} }

    [side]
        type=Bandit
        id=Baldras
        side=1
        color=black
        canrecruit=yes
        controller=human
        recruit=Thug,Footpad,Poacher
        gold=0
        income=-2
        village_gold=0
        team_name=good_guys
        user_team_name=_"Rebels"
        shroud=no
        fog=yes
        share_vision=none
    [/side]

    [side]
        type=Master Bowman
        id=Quentin
        name= _ "Quentin"
        side=2
        color=red
        canrecruit=yes
        controller=ai
        user_team_name=_"Weldyn"
        team_name=bad_guys
        [ai]
            ai_algorithm=idle_ai
            passive_leader=yes
        [/ai]
        shroud=no
        fog=yes
    [/side]

    [side]
        no_leader=yes
        side=3
        color=red
        controller=ai
        team_name=bad_guys
        user_team_name=_"Weldyn"
        [ai]
            aggression=1.0
            caution=0.0
            grouping=no
            simple_targeting=yes
        [/ai]
        shroud=no
        fog=yes
        {FLAG_VARIANT loyalist}
    [/side]

    {STARTING_VILLAGES_ALL 2}

    [side]
        type=Rogue
        id=Hans
        name= _ "Hans"
        side=4
        color=purple
        canrecruit=yes
        controller=ai
        facing=sw
        [ai]
            passive_leader=yes
        [/ai]
        team_name=good_guys
        user_team_name=_"Rebels"
        shroud=no
        fog=yes
        share_vision=none
        {FLAG_VARIANT6 ragged}
    [/side]

    #
    # Prestart events
    #
    [event]
        name=prestart

        {PLACE_IMAGE "scenery/oak-leaning.png~FL(horiz)" 12 37}

        [store_side]
            side=1
            variable=stored_side_1
        [/store_side]

        [objectives]
            side=1
            [objective]
                description= _ "Enter the Grey Woods with Hans"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Baldras"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Harper"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Hans"
                condition=lose
            [/objective]

            [note]
                description= _ "In fog, units always see one hex further than they can move."
            [/note]

            {TURNS_RUN_OUT}
        [/objectives]

        #some various city props
        {PLACE_IMAGE scenery/well.png 10 36}

        {PLACE_IMAGE items/scarecrow.png 15 22}

        {PLACE_IMAGE items/straw-bale1.png 3 23}
        {PLACE_IMAGE "items/straw-bale2.png~FL(horiz)" 4 23}
        {PLACE_IMAGE "items/straw-bale1.png~FL(horiz)" 4 22}
        {PLACE_IMAGE items/straw-bale1.png 32 27}

        {PLACE_IMAGE "items/archery-target-right.png~FL(horiz)" 4 44}
        {PLACE_IMAGE "items/archery-target-right.png~FL(horiz)" 6 45}
        {PLACE_IMAGE "items/archery-target-right.png~FL(horiz)" 5 47}

        # Here we preplace a few guards

#define SEEKER X Y TYPE
    [unit]
        type={TYPE}
        generate_name=yes
        x,y={X},{Y}
        side=2
        random_traits=yes
    [/unit]
#enddef

        {SEEKER 2 45 (Bowman)}
        {SEEKER 3 47 (Bowman)}

        {RANDOM "a,b,c"}
        [switch]
            variable=random

            [case]
                value=a

                [store_locations]
                    x= 7,19,24,30,17,25, 2, 6,18, 2,24,13,16, 3,15,17,30,19, 3,27, 9
                    y=13, 9,10,13,18,21,22,23,27,28,30,32,32,37,37,38,38,41,42,43,47
                    variable=guard_locs
                [/store_locations]
            [/case]

            [case]
                value=b

                [store_locations]
                    x= 2,25,14,30, 5,16,25, 6, 2,33,16,22,13, 3,15,17,28, 3, 7,21
                    y=10,10,13,13,19,20,21,23,28,28,31,31,32,37,37,38,39,42,48,48
                    variable=guard_locs
                [/store_locations]
            [/case]

            [case]
                value=c

                [store_locations]
                    x=22, 7,16,26,15, 4,31,19,15,30, 5, 4, 8,15,17,27,19, 3,20
                    y=12,13,13,15,18,22,23,26,27,29,32,35,35,37,38,39,41,42,46
                    variable=guard_locs
                [/store_locations]
            [/case]
        [/switch]

        [for]
            array=guard_locs
            # The guard positions are designed to work with 4MP guards only, so
            # we need to make sure the guards cannot get the quick trait, and we
            # do this by randomizing their traits manually.
            [do]
                [set_variables]
                    name=traits_without_quick

                    [value]
                        {TRAIT_STRONG}
                    [/value]
                    [value]
                        {TRAIT_RESILIENT}
                    [/value]
                    [value]
                        {TRAIT_FEARLESS}
                    [/value]
                    [value]
                        {TRAIT_INTELLIGENT}
                    [/value]
                [/set_variables]

                {VARIABLE_OP first_trait rand "0..3"}
                [set_variables]
                    name=this_guard_traits
                    to_variable=traits_without_quick[$first_trait].trait
                [/set_variables]

                # To prevent the same trait from being picked twice, we need to find
                # and remove the first picked trait from the array.
                [for]
                    array=traits_without_quick
                    variable=j
                    [do]
                        [if]
                            [variable]
                                name=traits_without_quick[$j].trait.id
                                equals=$traits_without_quick[$first_trait].trait.id
                            [/variable]

                            [then]
                                {CLEAR_VARIABLE traits_without_quick[$first_trait]}
                            [/then]
                        [/if]
                    [/do]
                [/for]

                {VARIABLE_OP second_trait rand "0..2"}
                [set_variables]
                    name=this_guard_traits
                    mode=append
                    to_variable=traits_without_quick[$second_trait].trait
                [/set_variables]

                {RANDOM "Shock Trooper,Iron Mauler"}

                [unit]
                    type=$random
                    side=2
                    x,y=$guard_locs[$i].x,$guard_locs[$i].y
                    generate_name=yes
                    random_traits=no
                    [modifications]
                        [insert_tag]
                            name=trait
                            variable=this_guard_traits
                        [/insert_tag]
                    [/modifications]
                [/unit]

                {CLEAR_VARIABLE this_guard_traits}
            [/do]
        [/for]

        {CLEAR_VARIABLE guard_locs,traits_without_quick,first_trait,second_trait,random}

        [store_unit]
            [filter]
                id=Baldras
            [/filter]

            kill=yes
            variable=stored_Baldras
        [/store_unit]

        [unit]
            side=1
            type=Boat
            id=Boat
            x,y=1,4
        [/unit]

        [hide_unit]
            x,y=1,4
        [/hide_unit]

        [item]
            x,y=1,4
            image=units/transport/boat.png
        [/item]
    [/event]

    #
    # Starting conversation and actions
    #
    [event]
        name=start

        [message]
            speaker=narrator
            message= _ "Relentlessly pursued by riders patrolling the road to Elensefar, Baldras and the villagers traveled unseen along the swampy banks of the Great River to the city of Carcyn. They hid until nightfall, then crept out to find the help Lord Maddock hinted was here."
            image="wesnoth-icon.png"
        [/message]

        [kill]
            x,y=1,4
            animate=no
            fire_event=no
        [/kill]

        [remove_item]
            x,y=1,4
        [/remove_item]

        [move_unit_fake]
            side=1
            type=Boat
            x=1,7
            y=4,5
        [/move_unit_fake]

        [item]
            x,y=7,5
            image=units/transport/boat.png
        [/item]

        [move_unit_fake]
            side=1
            type=$stored_Baldras.type
            x=7,7
            y=5,6
        [/move_unit_fake]

        [unstore_unit]
            variable=stored_Baldras
        [/unstore_unit]

        [redraw]
            side=1
        [/redraw]

        [recall]
            id=Harper
            x,y=8,5
        [/recall]

        [message]
            speaker=Harper
            message= _ "Wow, is that Carcyn in the distance? Look at how grand some of them spires be!"
        [/message]

        [message]
            speaker=Baldras
            message= _ "Not since I were a young lad did I come this far south. Maybe it looks impressive now, but city life weren’t never something real nice. Them city folk be real impatient and mean. Always wantin’ some price for their help, too."
        [/message]

        [message]
            speaker=Harper
            message= _ "Well, we need their help now, don’t we? So we got to figure out a way to get to Lord Maddock’s friend. But he didn’t say anything about who that was."
        [/message]

        [message]
            speaker=Baldras
            message= _ "Harper, when a noble lord says he don’t want some kind of relationship known, it means some kind o’ connection with the black market. We be looking for criminals, probably some thieves’ den. Or, maybe they be looking for us."
        [/message]

        [move_unit_fake]
            type=Thief
            side=4
            x=7,6
            y=9,6
        [/move_unit_fake]

        [unit]
            type=Thief
            side=4
            x,y=6,6
            random_traits=yes
            id=Link
            name= _ "Link"
        [/unit]

        [message]
            speaker=Baldras
            message= _ "Right on time."
        [/message]

        [message]
            speaker=Harper
            message= _ "How do we know we can trust him?"
        [/message]

        [message]
            speaker=Link
            message= _ "If you were one of my quarries, your throat would be slit by now. As it is, you two are still in imminent danger. Just a week ago, the Crown sent a contingent of heavy infantry here to supervise the city. They’re patrolling the streets and forests for us."
        [/message]

        [message]
            speaker=Baldras
            message= _ "I be assuming they’ll also try to stop us if they see us."
        [/message]

        [message]
            speaker=Link
            message= _ "Very likely. Now hurry, you must make it past the city into the Grey Woods. There is a small path in the southeast that leads into the forest. Look for the signpost. My brother Hans will guide you from there. Avoid the soldiers if you can."
        [/message]

        {HIGHLIGHT_IMAGE 26 48 scenery/signpost.png ()}

        [scroll_to_unit]
            id=Baldras
        [/scroll_to_unit]

        {MOVE_UNIT id=Link 5 8}

        [kill]
            id=Link
            animate=no
            fire_event=no
        [/kill]

        [redraw]
        [/redraw]

        {CLEAR_VARIABLE stored_Baldras}
    [/event]

    [event]
        name=sighted
        [filter]
            side=2
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [redraw]
            side=1
        [/redraw]

        [message]
            speaker=second_unit
            message= _ "Looks like these guards be holding stationary posts. If we’re careful, we can get ourselves around them unnoticed."
        [/message]
        [message]
            speaker=Baldras
            message= _ "Harper, you younger and faster folks needs to be our eyes. Scout ahead and find a way past them guards, but make sure ya don’t get yourselves spotted..."
        [/message]
    [/event]

    [event]
        name=side 2 turn
        first_time_only=no

        [if]
            [have_unit]
                side=1

                [filter_vision]
                    visible=yes
                    side=2
                [/filter_vision]

                [or]
                    side=1

                    [filter_vision]
                        visible=yes
                        side=3
                    [/filter_vision]
                [/or]
            [/have_unit]

            [then]
                # if player is visible to enemies, flip all nearby enemies to side 3,
                # which is the aggressive side and thus the nearby enemies will begin
                # to pursue the player

                [modify_unit]
                    [filter]
                        side=2

                        [filter_location]
                            [filter]
                                side=1
                            [/filter]

                            {QUANTITY radius 8 11 13}
                        [/filter_location]
                    [/filter]

                    side=3
                [/modify_unit]
            [/then]

            [else]
                # if player isn't seen by enemies anymore, make all enemies idle again

                [modify_unit]
                    [filter]
                        side=3
                    [/filter]

                    side=2
                [/modify_unit]
            [/else]
        [/if]
    [/event]

    [event]
        name=moveto
        [filter]
            side=3
        [/filter]

        [message]
            speaker=unit
            message= _ "Who goes there? Halt!"
        [/message]
        [message]
            speaker=Harper
            message= _ "They’ve seen us! <i>Run</i>!"
        [/message]
    [/event]

    [event]
        name=attack_end
        [filter]
            side=3
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        {IF_VAR second_unit.hitpoints greater_than 0 (
            [then]
                [message]
                    speaker=Baldras
                    message= _ "Quick, back into the shadows! Maybe we can still lose them!"
                [/message]
            [/then]
        )}
    [/event]

    [event]
        name=die
        [filter]
            type=Iron Mauler
        [/filter]
        [filter_second]
            id=Harper
        [/filter_second]

        [message]
            speaker=Harper
            #po: Harper defeats an Iron Mauler
            message= _ "Uncle, we did it! We beat one of them iron monsters!"
        [/message]
        [message]
            speaker=Baldras
            message= _ "A fine job lass, but more sure gots to be coming. Let’s keep movin’."
        [/message]

        [set_achievement]
            content_for=liberty
            id="liberty_iron"
        [/set_achievement]
    [/event]

    [event]
        name=sighted
        [filter]
            id=Hans
        [/filter]
        [filter_second]
            side=1
        [/filter_second]
        [message]
            speaker=unit
            message= _ "This way, into the forest! We’ll be able to lose them in the Grey Woods."
        [/message]
    [/event]

    #
    # Special event - if someone besides Baldras goes to the end, you get a
    # message
    #
    [event]
        name=moveto

        [filter]
            side=1

            [filter_adjacent]
                id=Hans
            [/filter_adjacent]

            [not]
                id=Baldras
            [/not]
        [/filter]

        [message]
            speaker=Hans
            message= _ "You can come if you wish, but we are mostly interested in speaking to Baldras."
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    #
    # Victory
    #
    [event]
        name=moveto

        [filter]
            x=26
            y=48
            id=Baldras
        [/filter]

        [message]
            speaker=Baldras
            message= _ "I haven’t run so much in years. Feels like I be a real outlaw now, infiltrating a heavily guarded city relyin’ on nothing but the cover of darkness and my wits."
        [/message]

        [message]
            speaker=Harper
            message= _ "It was fun, wasn’t it?"
        [/message]

        [message]
            speaker=Baldras
            message= _ "Perhaps a little."
        [/message]

        [message]
            speaker=Hans
            message= _ "Enough chatter, you still have some guards on your tail. We need to head deeper into the Grey Woods to lose them."
        [/message]

        [message]
            speaker=Baldras
            message= _ "Lead the way."
        [/message]

        [modify_side]
            side=1
            gold=$stored_side_1.gold
        [/modify_side]

        {CLEAR_VARIABLE stored_side_1}

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

    #
    # Loss conditions - turns run out
    #
    [event]
        name=time over
        [message]
            speaker=Baldras
            message= _ "Blast it, we was too slow! With the sun rising already, them guards will have no trouble spotting us now..."
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    #
    # Death of Hans
    #
    [event]
        name=last breath
        [filter]
            id=Hans
        [/filter]
        [message]
            speaker=Hans
            message= _ "You fools! You weren’t supposed to lead them to me..."
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    {LIBERTY_DEATHS}
[/scenario]

#undef SEEKER
