#textdomain wesnoth-httt
[scenario]
    id=07_Crossroads
    name= _ "Crossroads"
    map_data="{campaigns/Heir_To_The_Throne/maps/07_Crossroads.map}"
    {SCENARIO_MUSIC "knolls.ogg"}
    {EXTRA_SCENARIO_MUSIC "wanderer.ogg"}
    {TURNS 37 34 31}

    next_scenario=08_The_Princess_of_Wesnoth

    #wmllint: local spelling Kojun Herolm NE SE
    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description= _ "Defeat Kojun Herolm"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Konrad"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Delfador"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Kalenz"
                condition=lose
            [/objective]

            note={EARLY_FINISH_BONUS_NOTE}+{NEW_GOLD_CARRYOVER_NOTE_40}
        [/objectives]
    [/event]

    [story]
        [part]
            story= _ "Konrad, Delfador, and Kalenz swiftly rode east through the wilderlands of Wesnoth."
            background="maps/wesnoth.png"
            show_title=no
        [/part]
        [part]
            story= _ "The queen's agents were still scouring the coastal regions, for news of Elensefar's rescue had not yet reached her."
            background="maps/wesnoth.png"
            show_title=no
        [/part]
        [part]
            story= _ "Small as it was, Konrad's army avoided the notice of hostile eyes in the sparsely populated western countryside for a time. However, their luck did not hold."
            background="maps/wesnoth.png"
            show_title=no
        [/part]
    [/story]

    {BIGMAP_CROSSROADS}

    {DEFAULT_SCHEDULE}

    [side]
        type=Commander
        id=Konrad
        name= _ "Konrad"
        unrenamable=yes
        profile=portraits/konrad.png
        side=1
        canrecruit=yes
        controller=human
        team_name=rebels
        user_team_name=_"Rebels"
        {GOLD 300 200 200}
#ifdef EASY
        {INCOME 10 0 0}
#endif
        [ai]
            passive_leader="yes"
            grouping="offensive"
            aggression="0.0"
            caution="-0.75"
            [protect_location]
                x=20
                y=28
                radius="12"
                value="20.0"
            [/protect_location]
            [protect_location]
                x=16
                y=17
                radius="12"
                value="10.0"
            [/protect_location]
            [protect_location]
                x=25
                y=10
                radius="10"
                value="10.0"
            [/protect_location]
            [target]
                id=Delfador
                value=3.0
            [/target]
            [protect_unit]
                id=Delfador
                radius=6
                value=20.0
            [/protect_unit]
            [protect_unit]
                id=Konrad
                radius=10
                value=20.0
            [/protect_unit]
            [target]
                id=Kalenz
                value=3.0
            [/target]
            [protect_unit]
                id=Kalenz
                radius=4
                value=20.0
            [/protect_unit]

            [avoid]
                x="9-23"
                y="1-9"
            [/avoid]
            [avoid]
                x="14-19"
                y="10-14"
            [/avoid]
            [avoid]
                x="20-40"
                y="16-24"
            [/avoid]
            {ATTACK_DEPTH 5 5 5}
        [/ai]

        [village]
            x,y=3,5
        [/village]
    [/side]

#define CROSSROADS_AI_PARAMS
    [ai]
        caution=1.0
        aggression=0.3
        passive_leader=yes
        {ATTACK_DEPTH 1 3 5}
    [/ai]
    [ai]
        time_of_day=dusk
        turns=8-100
        caution=0.25
        aggression=0.6
    [/ai]
    [ai]
        time_of_day=first_watch,second_watch
        caution=0.0
        aggression=1.0
        grouping=no
    [/ai]
#enddef

    [side]
        type=Orcish Warlord
        id=Kojun Herolm
        name= _ "Kojun Herolm"
        experience=0
        side=2
        controller=ai
        canrecruit=yes
        recruit=Orcish Grunt,Wolf Rider,Orcish Archer,Troll Whelp
        {GOLD 70 130 190}
        team_name=orcs
        user_team_name=_"Orcs"
        {CROSSROADS_AI_PARAMS}
    [/side]

    {STARTING_VILLAGES 2 18}

    [side]
        type=Orcish Warrior
        id=Mokho Kimer
        name= _ "Mokho Kimer"
        experience=0
        side=3
        controller=ai
        canrecruit=yes
        recruit=Orcish Grunt,Wolf Rider,Orcish Archer,Troll Whelp
        {GOLD 40 90 150}
        team_name=orcs
        user_team_name=_"Orcs"
        {CROSSROADS_AI_PARAMS}

        [village]
            x,y=39,27
        [/village]
    [/side]

    {STARTING_VILLAGES 3 17}

    #signs at the crossroads for decoration
    {PLACE_IMAGE scenery/signpost.png 16 16}

    [event]
        name=start
        [recall]
            id=Delfador
        [/recall]
        [recall]
            id=Kalenz
        [/recall]
        [message]
            speaker=Delfador
            message= _ "Here we come to the great cross-roads. We should go northeast."
        [/message]
        [message]
            speaker=Kalenz
            message= _ "Beware! These hills are not safe! The roads are important to Asheviere's strategy, and she has hired orcs to guard them. We shall have to fight to travel through."
        [/message]
        [message]
            speaker=Konrad
            message= _ "Then fight we shall. Fortunately, now that we have liberated Elensefar, they are providing what gold they can spare to help us swell our ranks with new recruits. Let it begin!"
        [/message]
    [/event]

    [event]
        name=prestart

        # 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. For now, Orcish Archer is listed twice, so they appear
        # more often than the other types.

        {VARIABLE random_ambusher_type_table[0].type "Orcish Grunt"}
        {VARIABLE random_ambusher_type_table[1].type "Orcish Archer"}
        {VARIABLE random_ambusher_type_table[2].type "Orcish Archer"}
        {VARIABLE random_ambusher_type_table[3].type "Orcish Assassin"}
        {VARIABLE random_ambusher_type_table[4].type "Goblin Spearman"}

        {VARIABLE random_ambusher_type_i 0}

        # With this macro we place a set number of ambushers (from the above list) to a
        # given rectangular area. We do this in blocks so that we can guarantee that
        # every major area has at least some ambushers: if we randomized the ambush
        # locations across all possible locations at once, the RNG could theoretically
        # clump all the ambushers into a single corner of the map.

#define ORC_AMBUSH_AREA SIDE X_SPAN Y_SPAN NUMBER
    # Any hill that's completely surrounded by other hills, mountains or
    # forest is eligible as an ambush location.

    [store_locations]
        x={X_SPAN}
        y={Y_SPAN}
        terrain=Hh

        [not]
            [filter_adjacent_location]
                [not]
                    terrain=Hh*,Mm*,*^F*
                [/not]
            [/filter_adjacent_location]
        [/not]

        variable=possible_ambush_locations
    [/store_locations]

    {VARIABLE ambusher 0}

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

        [do]
            {RANDOM 1..$possible_ambush_locations.length}
            {VARIABLE_OP random add -1}

            # 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.

            [if]
                [have_unit]
                    x,y=$possible_ambush_locations[$random].x,$possible_ambush_locations[$random].y
                [/have_unit]

                [else]
                    # random_ambusher_type_i is just a counter variable with
                    # which we point to a given element of the
                    # random_ambusher_type_table array. Here we make it loop
                    # over the array continuously.

                    [if]
                        [variable]
                            name=random_ambusher_type_i
                            less_than=4
                        [/variable]

                        [then]
                            {VARIABLE_OP random_ambusher_type_i add 1}
                        [/then]

                        [else]
                            {VARIABLE random_ambusher_type_i 0}
                        [/else]
                    [/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.

                    [unit]
                        x,y=$possible_ambush_locations[$random].x,$possible_ambush_locations[$random].y
                        type=$random_ambusher_type_table[$random_ambusher_type_i].type
                        side={SIDE}
                        facing=sw
                        role=ambusher
                        random_traits=yes

                        [modifications]
                            {TRAIT_LOYAL}
                        [/modifications]
                        {IS_LOYAL}
                    [/unit]

                    [object]
                        silent=yes

                        [filter]
                            x,y=$possible_ambush_locations[$random].x,$possible_ambush_locations[$random].y
                        [/filter]

                        [effect]
                            apply_to=new_ability

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

                                    [filter_self]
                                        role=ambusher

                                        [filter_location]
                                            terrain=Hh,Mm
                                        [/filter_location]
                                    [/filter_self]
                                [/hides]
                            [/abilities]
                        [/effect]
                    [/object]

                    {VARIABLE_OP ambusher add 1}
                [/else]
            [/if]
        [/do]
    [/while]
#enddef

        # Only the number of ambushers differs by difficulty here.

#ifdef EASY
        {ORC_AMBUSH_AREA 2 5-35 1-7 5}
        {ORC_AMBUSH_AREA 2 9-24 8-15 5}
        {ORC_AMBUSH_AREA 3 1-17 17-24 9}
        {ORC_AMBUSH_AREA 3 18-26 16-23 5}
        {ORC_AMBUSH_AREA 3 26-40 16-23 5}
#endif
#ifdef NORMAL
        {ORC_AMBUSH_AREA 2 5-35 1-7 6}
        {ORC_AMBUSH_AREA 2 9-24 8-15 6}
        {ORC_AMBUSH_AREA 3 1-17 17-24 10}
        {ORC_AMBUSH_AREA 3 18-26 16-23 6}
        {ORC_AMBUSH_AREA 3 26-40 16-23 6}
#endif
#ifdef HARD
        {ORC_AMBUSH_AREA 2 5-35 1-7 7}
        {ORC_AMBUSH_AREA 2 9-24 8-15 7}
        {ORC_AMBUSH_AREA 3 1-17 17-24 11}
        {ORC_AMBUSH_AREA 3 18-26 16-23 7}
        {ORC_AMBUSH_AREA 3 26-40 16-23 7}
#endif

        {CLEAR_VARIABLE possible_ambush_locations}
        {CLEAR_VARIABLE random_ambusher_type_table}
        {CLEAR_VARIABLE random_ambusher_type_i}
        {CLEAR_VARIABLE ambusher}
    [/event]

    [event]
        name=turn refresh
        first_time_only=no

        [if]
            [variable]
                name=side_number
                numerical_equals=2
            [/variable]

            [or]
                [variable]
                    name=side_number
                    numerical_equals=3
                [/variable]
            [/or]

            [then]
                {MODIFY_UNIT side,role=$side_number,ambusher moves 0}
            [/then]
        [/if]
    [/event]

    [event]
        name=moveto
        first_time_only=no

        [filter]
            side=1

            [filter_adjacent]
                side=2,3
                role=ambusher
            [/filter_adjacent]
        [/filter]

        {MODIFY_UNIT (
            side=2,3
            role=ambusher

            [filter_adjacent]
                x,y=$x1,$y1
            [/filter_adjacent]
        ) role not_ambusher}

        [redraw][/redraw]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x,y=12,11
        [/filter]
        [move_unit_fake]
            type=Elvish Archer
            side=1
            x=12,12,11
            y=14,13,13
        [/move_unit_fake]

        {NAMED_LOYAL_UNIT 1 (Elvish Archer) 11 13 (Niodien) ( _ "Niodien")}
        # wmllint: recognize Niodien

        [message]
            speaker=Niodien
            message= _ "Stay on the path! The hills here are not safe!"
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x,y=3,15
        [/filter]
        [move_unit_fake]
            type=Elvish Fighter
            side=1
            x=4,5,5
            y=16,16,15
        [/move_unit_fake]

        {NAMED_LOYAL_UNIT 1 (Elvish Fighter) 5 15 (Loflar) ( _ "Loflar")}
        # wmllint: recognize Loflar

        [message]
            speaker=Loflar
            message= _ "Beware the hills! There are many orcs in hiding, preparing to ambush you!"
        [/message]
    [/event]

    [event]
        name=moveto
        [allow_undo]
        [/allow_undo]
        [filter]
            side=1
            x=16
            y=16
        [/filter]
        [redraw]
        [/redraw]
        [message]
            speaker=narrator
            image="scenery/signpost.png"
            #wmllint: display on
            message= _ "NE - Dan'Tonk
SE - Fort Tahn"
            #wmllint: display off
        [/message]
        [message]
            speaker=Konrad
            message= _ "Dan'Tonk, we are so close to Weldyn."
        [/message]
        [message]
            speaker=Delfador
            message= _ "We dare not confront Asheviere yet. We must retrieve the Scepter of Fire and gather more allies in the north."
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id=Kojun Herolm
        [/filter]
        [endlevel]
            result=victory
            bonus=yes
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

    [event]
        name=victory
        [message]
            speaker=Konrad
            message= _ "Victory is ours, men. Let us proceed northeast!"
        [/message]
    [/event]

    {campaigns/Heir_To_The_Throne/utils/deaths.cfg}
[/scenario]
