#textdomain wesnoth-httt
[scenario]
    id=06_The_Siege_of_Elensefar
    name= _ "The Siege of Elensefar"
    map_file=06_The_Siege_of_Elensefar.map
    {TURNS 40 36 32}

    {DEFAULT_SCHEDULE}

    next_scenario=07_Crossroads

    {SCENARIO_MUSIC "the_city_falls.ogg"}
    {EXTRA_SCENARIO_MUSIC "breaking_the_chains.ogg"}
    {EXTRA_SCENARIO_MUSIC "battle.ogg"}
    {EXTRA_SCENARIO_MUSIC "vengeful.ogg"}
    {EXTRA_SCENARIO_MUSIC "casualties_of_war.ogg"}
    {EXTRA_SCENARIO_MUSIC "legends_of_the_north.ogg"}

    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description= _ "Defeat all enemy leaders"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Konrad"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

            [gold_carryover]
                bonus=yes
                carryover_percentage=40
            [/gold_carryover]
        [/objectives]
    [/event]

    [label]
        x,y=16,28
        text= _ "Elensefar"
    [/label]

    {HTTT_TRACK {JOURNEY_06_NEW} }

    [side]
        type=Commander
        id=Konrad
        name= _ "Konrad"
        unrenamable=yes
        profile=portraits/konrad-elvish.webp
        side=1
        canrecruit=yes
        controller=human
        team_name=elves
        user_team_name=_"Rebels"
        {GOLD 180 150 120}
        {FLAG_VARIANT long}
    [/side]

    # wmllint: recognize Delfador

    [side]
        type=Orcish Warlord
        id=Agadla
        name= _ "Agadla"
        side=2
        canrecruit=yes
        recruit=Orcish Warrior,Orcish Grunt,Orcish Assassin,Orcish Crossbowman,Orcish Archer
        {GOLD 120 160 200}
        team_name=orcs
        user_team_name=_"Evil"

        [ai]
            recruitment_pattern=fighter,fighter,mixed fighter,archer
            leader_value=10.0
            aggression=0.0
            caution=1.0
            grouping=defensive
        [/ai]

        [ai]
            time_of_day=dusk
            aggression=0.6
            grouping=defensive
        [/ai]
        [ai]
            time_of_day=first_watch,second_watch
            aggression=0.7
            caution=0.25
            grouping=offensive
        [/ai]
        {FLAG_VARIANT6 ragged}
    [/side]

#ifndef HARD
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Orcish Warrior" 2}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Orcish Crossbowman" 2}
#endif

    [side]
        type=Dark Sorcerer
        id=Muff Jaanal
        name= _ "Muff Jaanal"
        side=3
        canrecruit=yes

        recruit=Skeleton Archer,Skeleton

        {GOLD 80 120 160}

        team_name=orcs
        user_team_name=_"Evil"

        [ai]
            recruitment_pattern=fighter,fighter,archer
            leader_value=10.0
        [/ai]

        [ai]
            time_of_day=dusk,first_watch,second_watch
            aggression=1.0
            grouping=no
        [/ai]
        {FLAG_VARIANT undead}
    [/side]

    # Start the orcs/undead with most of the villages on the map
#ifdef EASY
    {STARTING_VILLAGES 2 5}
    {STARTING_VILLAGES 3 0}
#endif
#ifdef NORMAL
    {STARTING_VILLAGES 2 10}
    {STARTING_VILLAGES 3 10}
#endif
#ifdef HARD
    {STARTING_VILLAGES 2 10}
    {STARTING_VILLAGES 3 20}
#endif

    [time_area]
        x=  11,  12,  13,  14,  15, 16-22,  23,  24, 25-26
        y= 0-1, 0-2, 0-6, 0-5, 0-6,   0-5, 0-3, 0-1,   0-2
        {UNDERGROUND}
    [/time_area]

#define ADVISOR
    [role]
        role=Advisor
        [auto_recall][/auto_recall]

        type="Elvish Sylph,Great Mage," +

            "Elvish Marshal,Elvish Champion,Elvish Avenger,Elvish Sharpshooter,Elvish Shyde,Elvish Enchantress,Elvish Outrider," +
            "Paladin,Grand Knight," +
            "Mage of Light,Arch Mage,Silver Mage," +
            "Highwayman,Fugitive,Huntsman,Ranger," +

            "Elvish Captain,Elvish Hero,Elvish Ranger,Elvish Marksman,Elvish Druid,Elvish Sorceress,Elvish Rider," +
            "Knight,Lancer," +
            "White Mage,Red Mage," +
            "Bandit,Outlaw,Trapper," +

            "Elvish Fighter,Elvish Archer,Elvish Shaman,Elvish Scout," +
            "Horseman," +
            "Mage," +
            "Thug,Footpad,Poacher," +

            # Merfolk at the bottom because they are not as useful as the other options with this castle placement.
            "Merman Triton,Merman Hoplite,Merman Javelineer,Merman Entangler,Mermaid Diviner,Mermaid Siren," +
            "Merman Warrior,Merman Spearman,Merman Netcaster,Mermaid Priestess,Mermaid Enchantress," +
            "Merman Fighter,Merman Hunter,Mermaid Initiate"
        [else]
            [unit]
                side=1
                type=Elvish Fighter
                role=Advisor
                placement=leader
            [/unit]
        [/else]
    [/role]
#enddef

    [event]
        name=prestart

        {PLACE_IMAGE scenery/rock1.png 13 12}
        {PLACE_IMAGE scenery/rock2.png 25 28}

        [disallow_recruit]
            side=1
            type=Thief
        [/disallow_recruit]

        {NEED_KALENZ (x,y=recall,recall)}
        {NEED_DELFADOR (x,y=recall,recall)}

        {STORE_DELFADOR}
        {STORE_KALENZ}

        {ADVISOR}
    [/event]

    [event]
        name=start
        [message]
            speaker=narrator
            image="wesnoth-icon.png"
            message= _ "The party arrived at Elensefar at last, but found that the city had already fallen to the savage orcs."
        [/message]
        [message]
            role=Advisor
            message= _ "My lord! It seems the city has already fallen!"
        [/message]
        [message]
            speaker=Konrad
            message= _ "This is terrible news! We must retake the city!"
        [/message]
        [message]
            role=Advisor
            message= _ "There are so many of them. This will not be easy! And look to the north! It seems that the undead are allied with the orcs!"
        [/message]
        [message]
            speaker=Muff Jaanal
            message= _ "Here come the elves! Our newly forged alliance with the orcs will give us the power to crush them with ease!"
        [/message]
        [message]
            speaker=Konrad
            message= _ "We must take the city, and destroy the evil undead before reinforcements arrive!"
        [/message]
    [/event]

    [event]
        name=turn 4

        [move_unit_fake]
            type=Rogue
            side=1
            x=24,24,23
            y=38,39,40
        [/move_unit_fake]

        [unit]
            id=Reglok
            name= _ "Reglok"
            type=Rogue
            side=1
            x=23
            y=40
            gender=male
            facing=sw
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]

        [unit]
            id=Gelgar
            name= _ "Gelgar"
            type=Thief
            side=1
            x=22
            y=39
            gender=male
            facing=sw
            [modifications]
                {TRAIT_LOYAL}
            [/modifications]
        [/unit]
        [unit]
            id=Gamlel
            name= _ "Gamlel"
            type=Thief
            side=1
            x=24
            y=40
            gender=female
            facing=sw
            [modifications]
                {TRAIT_LOYAL}
            [/modifications]
        [/unit]

        [redraw]
        [/redraw]
        [delay]
            time=1250
        [/delay]

        [message]
            speaker=narrator
            image="wesnoth-icon.png"
            message= _ "As night began to fall, three dark figures crept out of the forest."
        [/message]
        [message]
            speaker=Konrad
            {KONRAD_VARIATION_ELF mad}
            message= _ "Halt! Who goes there, friend or foe?"
        [/message]
        [message]
            speaker=Reglok
            message= _ "Greetings, friend. We are from the Elensefar Thieves’ Guild. We would like to help you against the orcs!"
        [/message]
        {ADVISOR}
        [message]
            role=Advisor
            message= _ "Thieves, hmmm? Who says we can trust such as you?"
        [/message]
        [message]
            speaker=Gamlel
            message= _ "We would understand if you didn’t trust us, of course, but it is in our mutual interest to rid the city of the orcs!"
        [/message]
        [message]
            speaker=Konrad
            message= _ "Very well. You may join us."
        [/message]
        [message]
            speaker=Reglok
            message= _ "We will serve you well, for we respect the help you are providing to our city. You shall find that there is honor, even among thieves."
        [/message]
        [message]
            speaker=Konrad
            message= _ "Yes, but where is your fighting force? How can you help us?"
        [/message]
        [message]
            speaker=Gelgar
            message= _ "We survive by stealth. We can help you sneak into the city and surround the orcs. Alternatively, we can lay in wait until you give us a signal then ambush the orcs’ rear."
        [/message]
        [message]
            speaker=Konrad
            message= _ "Hmm... I have to consider this..."
            [option]
                label= _ "Help us infiltrate the city. We can do the rest."
                [command]
                    [message]
                        speaker=Reglok
                        message= _ "Excellent. Two hours past midnight meet us on the west bank of the river, across from Elensefar’s docks."
                    [/message]
                    [set_variable]
                        name=thieves_ford
                        value=yes
                    [/set_variable]
                    {HIGHLIGHT_IMAGE 6 32 items/gohere.png ()}
                    [label]
                        x,y=6,32
                        # po: The party and an ally have agreed to meet at the location identified by this label.
                        text=_ "Meeting point"
                        team_name=elves
                    [/label]
                    # The image will be removed when the ford appears
                [/command]
            [/option]
            [option]
                label= _ "I want you to reinforce us once we break through their line."
                [command]
                    [message]
                        speaker=Reglok
                        message= _ "Very well. When you raise your red banner over any building in the city proper, we will see the sign and attack from the city’s northern gate."
                    [/message]
                    [message]
                        speaker=Konrad
                        message= _ "Agreed. But, will you be able to see our flag if it’s dark?"
                    [/message]
                    [message]
                        speaker=Reglok
                        message= _ "Yes, we will see it. In fact, we prefer to fight at night. I pray you do not lead us into slaughter."
                    [/message]
                    [message]
                        speaker=Konrad
                        message= _ "Do not fear, friends. There will be a slaughter here, but it will be orcish blood staining the streets."
                    [/message]
                    #
                    # Special event - if you chose to have the thieves
                    # ambush the orcs, they appear when you capture
                    # one of the Elensefar villages
                    #
                    [event]
                        name=moveto
                        [filter]
                            side=1
                            [filter_location]
                                terrain=*^V*
                                [and]
                                    x,y=16,26
                                    radius=5
                                [/and]
                            [/filter_location]
                        [/filter]
                        [message]
                            speaker=narrator
                            image="wesnoth-icon.png"
                            message= _ "As the banner was raised, sounds of fighting could be heard from across the city."
                        [/message]

                        #create units

                        [unit]
                            id=Reglok
                            name= _ "Reglok"
                            type=Rogue
                            side=1
                            x=16
                            y=22
                            gender=male
                            facing=sw
                            [modifications]
                                {TRAIT_LOYAL}
                                {TRAIT_INTELLIGENT}
                            [/modifications]
                        [/unit]

                        [unit]
                            id=Gelgar
                            name= _ "Gelgar"
                            type=Thief
                            side=1
                            x=14
                            y=22
                            gender=male
                            facing=se
                            [modifications]
                                {TRAIT_LOYAL}
                            [/modifications]
                        [/unit]
                        [unit]
                            id=Gamlel
                            name= _ "Gamlel"
                            type=Thief
                            side=1
                            x=20
                            y=23
                            gender=female
                            facing=sw
                            [modifications]
                                {TRAIT_LOYAL}
                            [/modifications]
                        [/unit]
                        [unit]
                            id=Darglen
                            name= _ "Darglen"
                            type=Thief
                            side=1
                            x=18
                            y=23
                            facing=sw
                            [modifications]
                                {TRAIT_LOYAL}
                            [/modifications]
                        [/unit]
                        #dialog
                        [message]
                            speaker=Reglok
                            message= _ "Let’s expel these invaders! Today, the city is ours again!"
                        [/message]

                        # Allow the player to cancel attack orders
                        [cancel_action][/cancel_action]
                    [/event]
                [/command]
            [/option]
        [/message]
        [kill]
            type=Thief
        [/kill]
        [kill]
            type=Rogue
        [/kill]
        [allow_recruit]
            side=1
            type=Thief
        [/allow_recruit]
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "You can now recruit Thieves!"
        [/message]
    [/event]

    #
    # Special event - if you chose to have the thieves help you across the river,
    # on turn 6 the ford appears
    #
    [event]
        name=turn 6

        [if]
            [variable]
                name=thieves_ford
                equals=yes
            [/variable]
            [then]
                [remove_item]
                    x,y=6,32
                [/remove_item]
                {REMOVE_LABEL 6 32 EXTRA_WML=team_name=elves}
                [scroll_to]
                    x,y=6,32
                [/scroll_to]
                [message]
                    speaker=narrator
                    image="wesnoth-icon.png"
                    message= _ "On the banks of Elensefar’s port district, three shadowy figures appeared."
                [/message]
                [message]
                    speaker=narrator
                    image="wesnoth-icon.png"
                    message= _ "To Konrad’s surprise, they quickly made their way across the river’s mouth. The turbulent waters hid a nearly invisible ford, wide enough for two soldiers to march shoulder-to-shoulder."
                [/message]
                #create units

                [unit]
                    id=Reglok
                    name= _ "Reglok"
                    type=Rogue
                    side=1
                    x=7
                    y=30
                    gender=male
                    facing=se
                    [modifications]
                        {TRAIT_LOYAL}
                        {TRAIT_INTELLIGENT}
                    [/modifications]
                [/unit]

                [unit]
                    id=Gelgar
                    name= _ "Gelgar"
                    type=Thief
                    side=1
                    x=6
                    y=30
                    gender=male
                    facing=se
                    [modifications]
                        {TRAIT_LOYAL}
                    [/modifications]
                [/unit]

                [unit]
                    id=Gamlel
                    name= _ "Gamlel"
                    type=Thief
                    side=1
                    x=6
                    y=31
                    gender=female
                    facing=se
                    [modifications]
                        {TRAIT_LOYAL}
                    [/modifications]
                [/unit]
                #create terrain
                [terrain]
                    terrain=Wwf # wmllint: ignore
                    x=8,7-8
                    y=30,31-32
                [/terrain]
                #dialog
                [message]
                    speaker=Reglok
                    message= _ "Very few people know that the river can be forded here. The orcs have yet to discover this place. Bring your forces into the city, quickly now, and you can flank them."
                [/message]
            [/then]
        [/if]
    [/event]

    [event]
        name=enemies defeated
        [message]
            speaker=Konrad
            {KONRAD_VARIATION_ELF glad}
            message= _ "Finally, we have retaken the city! Let us rest here, friends."
        [/message]
        [role]
            role=Thief
            type=Assassin,Rogue,Thief
        [/role]
        [message]
            role=Thief
            message= _ "Victory! The thieves of Elensefar will be in your service, my lord."
        [/message]
        [message]
            speaker=narrator
            image="wesnoth-icon.png"
            message= _ "The party rested for three days, after which an old friend returned."
        [/message]

        {VARIABLE delfador_store.profile "portraits/delfador.webp~RIGHT()"}
        {RESTORE_DELFADOR}
        {RESTORE_KALENZ}

        [move_unit_fake]
            type=Elder Mage
            side=1
            x=25,24,24
            y=18,17,16
        [/move_unit_fake]

        [recall]
            id=Delfador
            x,y=24,16
            show=no
        [/recall]

        [recall]
            id=Kalenz
            x,y=22,16
        [/recall]

        [message]
            speaker=Delfador
            message= _ "Greetings, friends. I see that you have rescued the city! I knew that you could do it."
        [/message]

        [message]
            speaker=Konrad
            {KONRAD_VARIATION_ELF glad}
            message= _ "Delfador! So good to see you! Where have you been?"
        [/message]

        [message]
            speaker=Delfador
            message= _ "I have been meeting with the Ka’lian, the Great Council of the Elves. This is Kalenz, a great lord of the Northern Elves who came to the Council to offer us the support of his people."
            # See Legend of Wesmere; Kalenz is the former High Lord of
            # the elves. At this time in 517 YW, he is probably a leader or
            # legate of the elves of the Forest of Lintanir. None of
            # this backstory existed when HttT was first written.
        [/message]

        [message]
            speaker=Kalenz
            message= _ "Greetings, friend."
        [/message]

        [message]
            speaker=Konrad
            message= _ "Delfador, we have captured this city, but surely Asheviere’s men will come and attack us! What should we do?"
        [/message]

        [message]
            speaker=Delfador
            message= _ "The Ka’lian has met and decided: we must capture the Sceptre of Fire."
        [/message]

        [message]
            speaker=Konrad
            message= _ "The Sceptre of Fire? What’s that?"
        [/message]

        [message]
            speaker=Delfador
            {DELFADOR_MENTORING}
            message= _ "The Sceptre of Fire is the most ancient artifact of the realm of Wesnoth. It was forged by the dwarves of Knalga at the request of King Haldric II. It took their finest smiths years to make it, but soon after it was completed, the makers were chased underground, attacked by the elves. None know exactly what occurred, but the Sceptre was lost somewhere in the great caverns. Years have passed, and the fortunes of the dwarves have waxed and waned, but the Sceptre has never been found."
        [/message]

        [message]
            speaker=Konrad
            message= _ "But what has this to do with me?"
        [/message]

        [message]
            speaker=Delfador
            message= _ "When Garard II, your uncle, was deciding upon a successor, he issued an edict that whichever member of the royal family could retrieve the Sceptre of Fire would rule the land."
        [/message]

        [message]
            speaker=Konrad
            message= _ "Oh, and you want me to get this Sceptre?"
        [/message]

        [message]
            speaker=Kalenz
            message= _ "We will help you retrieve it, my lord."
        [/message]

        [message]
            speaker=Delfador
            message= _ "Time is short. We think that Asheviere is also searching for the Sceptre, to help seal her place as ruler. But if you find the Sceptre first, the people will support you as the king."
        [/message]

        [message]
            speaker=Konrad
            message= _ "Me? King?"
        [/message]

        [message]
            speaker=Delfador
            message= _ "Yes, Konrad. I believe you will be king one day. Now let us make haste!"
        [/message]

        [message]
            speaker=Delfador
            message= _ "We cannot go to Wesmere, for Asheviere’s orcs have the approaches ringed about with steel; Kalenz and I barely escaped, and Chantal cannot get out. Until we are stronger, we must go where the orcs are not."
        [/message]

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

    # Konrad's troops reach Muff Jaanal's citadel.

    [event]
        name=enter_hex
        [filter]
            side=1
            x=12-13,16-17
            y=  3-4,  5-6
        [/filter]

        [message]
            speaker=Muff Jaanal
            message= _ "So you endeavor to fight me in my home. Foolish."
        [/message]

#ifdef EASY
        [gold]
            side=3
            amount=20
        [/gold]
#else
        [gold]
            side=3
            amount=40
        [/gold]
#endif

        [terrain]
            x=13
            y=2
            terrain=Uu
        [/terrain]
        [sound]
            name=skeleton-big-die.ogg
        [/sound]
#ifdef EASY
        {LOYAL_UNIT 3 (Skeleton) 13 2}
#else
        {LOYAL_UNIT 3 (Revenant) 13 2}
#endif
        [scroll_to_unit]
            x=13
            y=2
        [/scroll_to_unit]

        [terrain]
            x=22
            y=2
            terrain=Uu
        [/terrain]
        [sound]
            name=skeleton-big-die.ogg
        [/sound]
#ifdef HARD
        {LOYAL_UNIT 3 (Revenant) 22 2}
#else
        {LOYAL_UNIT 3 (Skeleton) 22 2}
#endif
        [scroll_to_unit]
            x=22
            y=2
        [/scroll_to_unit]

        # Allow the player to cancel attack orders
        [cancel_action][/cancel_action]
    [/event]

    {campaigns/Heir_To_The_Throne/utils/deaths.cfg}

    [event]
        name=victory

        {CLEAR_VARIABLE thieves_ford}

        [allow_recruit]
            side=1
            type=Thief
        [/allow_recruit]

        {RESTORE_DELFADOR}
        {RESTORE_KALENZ}
    [/event]
[/scenario]

#undef ADVISOR
