#textdomain wesnoth-l
[scenario]
    id=05_Hide_and_Seek
    next_scenario=06_The_Grey_Woods
    victory_when_enemies_defeated=no
    name= _ "Hide and Seek"
    map_data="{campaigns/Liberty/maps/05_Hide_and_Seek.map}"
    {TURNS 34 30 26}

    [time]
        id=midnight
        name= _ "Midnight"
        image=schedule-midnight.png
        lawful_bonus=-25
    [/time]

    {INTRO_AND_SCENARIO_MUSIC wanderer.ogg underground.ogg}
    {EXTRA_SCENARIO_MUSIC revelation.ogg}
    {EXTRA_SCENARIO_MUSIC nunc_dimittis.ogg}
    # the music will change if the guards see you

    {LIBERTY_BIGMAP {JOURNEY_05_NEW} }

    [side]
        type=Bandit
        id=Baldras
        side=1
        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
        canrecruit=yes
        controller=ai
        user_team_name=_"Asheviere"
        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=blue
        controller=ai
        team_name=bad_guys
        user_team_name=_"Asheviere"
        [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=green
        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= _ "Take Baldras to meet the leader of the insurgency"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Baldras"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Harper"
                condition=lose
            [/objective]

            [note]
                description= _ "Remember that 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 11 36}

        {PLACE_IMAGE items/scarecrow.png 15 22}

        {PLACE_IMAGE items/straw-bale1.png 1 22}
        {PLACE_IMAGE "items/straw-bale2.png~FL(horiz)" 2 22}
        {PLACE_IMAGE "items/straw-bale1.png~FL(horiz)" 1 23}
        {PLACE_IMAGE items/straw-bale1.png 31 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 his men traveled unseen along the swampy banks of the Great River to the city of Carcyn."
            image="wesnoth-icon.png"
        [/message]
        [message]
            speaker=narrator
            message= _ "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=Baldras
            message= _ "I’m not sure where we’re supposed to go now. If we go into town we can start asking around for information."
        [/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= _ "Who are you?"
        [/message]
        [message]
            speaker=Link
            message= _ "I have come to find you. You must make it through the city without being seen. The soldiers are normally out hunting for my kind, but a company of heavy infantry arrived three days ago and took over the patrols."
        [/message]
        [message]
            speaker=Harper
            message= _ "They’re looking for us."
        [/message]
        [message]
            speaker=Link
            message= _ "Well, good thing I found you first. 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 is waiting for you there and will take you to our master. Try to 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 hold stationary posts, so if we’re careful enough we should be able to slip our way around them unnoticed."
        [/message]
        [message]
            speaker=Baldras
            message= _ "Harper, you younger and faster folks need to be our eyes now. Scout ahead and try to find a way for us to get past the guards, but make sure to not stay where they can see you or we’re all in big trouble..."
        [/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]

        {INCIDENTAL_MUSIC vengeful.ogg}

        [message]
            speaker=Harper
            message= _ "They’ve seen us! <i>Run</i>!"
        [/message]
    [/event]

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

        {IF_VAR $second_unit.hitpoints greater_than 0 (
            [then]
                [message]
                    speaker=Baldras
                    message= _ "Fall back, quickly! Maybe we can yet lose them!"
                [/message]
            [/then]
        )}
    [/event]

    [event]
        name=sighted
        [filter]
            id=Hans
        [/filter]
        [filter_second]
            side=1
        [/filter_second]
        [message]
            speaker=unit
            message= _ "Gentlemen, please come this way and follow the path into the forest. Our leader is anxious to meet you."
        [/message]
        [message]
            speaker=second_unit
            message= _ "As soon as we escape the Wesnoth death squad, we will be happy to oblige."
        [/message]
        [message]
            speaker=Baldras
            message= _ "I haven’t run this much in years. If you were to ask me to infiltrate a heavily guarded city relying on nothing but the cover of darkness and my wits, I would say you were crazy."
        [/message]
        [message]
            speaker=Baldras
            message= _ "As it turns out, I’m the crazy one. Let’s finish this folly."
        [/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 the leader is only 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=Hans
            message= _ "Fly, and we may yet evade them in the Grey Woods."
        [/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= _ "We have spent too much time here. Surely the Queen’s forces have returned to Dallben. Our mission is unfinished, but we must return to fight a suicide battle."
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    {LIBERTY_DEATHS}

    {VILLAGE_BURNED}
[/scenario]

#undef SEEKER
