#textdomain wesnoth-httt
[scenario]
    id=01_The_Elves_Besieged
    name= _ "The Elves Besieged"
    next_scenario=02_Blackwater_Port
    victory_when_enemies_defeated=no
    map_file=01_The_Elves_Besieged.map
    {TURNS 16 14 12}
    {DEFAULT_SCHEDULE}

    {SCENARIO_MUSIC "battle.ogg"}
    {EXTRA_SCENARIO_MUSIC "casualties_of_war.ogg"}
    {EXTRA_SCENARIO_MUSIC "knolls.ogg"}
    {EXTRA_SCENARIO_MUSIC "siege_of_laurelmor.ogg"}
    {EXTRA_SCENARIO_MUSIC "suspense.ogg"}
    {EXTRA_SCENARIO_MUSIC "the_city_falls.ogg"}

    # Chantal can't be killed for storyline reasons.
    # Prevent AIs from getting too close.
#define AVOID_CHANTAL
    [avoid]
        x,y=2-4,22-24
    [/avoid]
#enddef

    [event]
        name=prestart
        {VARIABLE besieged_enemies_killed 0}
        {NEED_DELFADOR (x,y=19,23)}
        [objectives]
            side=1
            [objective]
                description= _ "Move Konrad to the signpost in the northwest"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Konrad"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Delfador"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

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

    {HTTT_INTRO}
    {HTTT_TRACK {JOURNEY_01_NEW} }

    {STARTING_VILLAGES 5 10}
    {STARTING_VILLAGES 6 10}
    {STARTING_VILLAGES 1 3}
    {STARTING_VILLAGES_AREA 6 7 10 6}
    {STARTING_VILLAGES_AREA 5 17 3 1}
    {STARTING_VILLAGES_AREA 6 9 40 10}
    {STARTING_VILLAGES_AREA 5 26 31 5}
    {STARTING_VILLAGES_AREA 5 29 46 1}

    # wmllint: recognize Kalenz

    [side]
        type=Fighter
        id=Konrad
        name= _"Konrad"
        unrenamable=yes
        profile=portraits/konrad-elvish.webp
        side=1
        canrecruit=yes
        controller=human
        recruit=Elvish Scout,Elvish Fighter,Elvish Archer,Elvish Shaman
        {GOLD 140 120 100}
        team_name=elves
        user_team_name=_"Rebels"
        [ai]
            [goal]
                name=target
                [criteria]
                    id=Delfador
                [/criteria]
                value=3.0
            [/goal]
            [goal]
                name=protect_unit
                [criteria]
                    id=Delfador
                [/criteria]
                protect_radius=6
                value=20.0
            [/goal]
            [goal]
                name=protect_unit
                [criteria]
                    id=Konrad
                [/criteria]
                protect_radius=10
                value=20.0
            [/goal]
            [goal]
                name=target
                [criteria]
                    id=Kalenz
                [/criteria]
                value=3.0
            [/goal]
            [goal]
                name=protect_unit
                [criteria]
                    id=Kalenz
                [/criteria]
                protect_radius=4
                value=20.0
            [/goal]

            [avoid]
                x=20-31
                y=1-12
            [/avoid]

            [leader_goal]
                x,y=1,1
            [/leader_goal]
        [/ai]
        {FLAG_VARIANT long}
    [/side]

#ifdef HARD
#define HIGH_PRIORITY_TARGETS

    [goal]
        name=target
        [criteria]
            id=Delfador
        [/criteria]
        value=100
    [/goal]
    [goal]
        name=target
        [criteria]
            id=Konrad
        [/criteria]
        value=100
    [/goal]
#enddef
#endif

    #macro which tells the AI not to start thinking about
    #whether it's a bad idea to send trolls into the forest
    #against elves, and just do it
#define EBESIEGED_RECRUITMENT
    [ai]
        simple_targeting=yes
    [/ai]
#enddef

    [side]
        type=Orcish Warlord
        id=Urug-Telfar
        name= _ "Urug-Telfar"
        side=2
        canrecruit=yes
        profile=portraits/orcs/grunt-2.webp
        recruit=Orcish Warrior,Goblin Knight,Goblin Pillager,Orcish Crossbowman,Orcish Assassin,Troll
        {GOLD 175 250 325}
        [ai]
            recruitment_pattern=scout,fighter,mixed fighter,archer
            {AVOID_CHANTAL}
#ifdef HARD
            {HIGH_PRIORITY_TARGETS}
#endif
        [/ai]
        {EBESIEGED_RECRUITMENT}
        team_name=orcs
        user_team_name=_"Orcs"
        {FLAG_VARIANT6 ragged}
    [/side]

    [side]
        type=Orcish Warlord
        id=Knafa-Tan
        name= _ "Knafa-Tan"
        side=3
        canrecruit=yes
        recruit=Orcish Warrior,Wolf Rider,Orcish Crossbowman,Orcish Assassin,Troll
        {EBESIEGED_RECRUITMENT}
        team_name=orcs
        user_team_name=_"Orcs"
        {GOLD 150 225 300}
        [ai]
            {AVOID_CHANTAL}
#ifdef HARD
            {HIGH_PRIORITY_TARGETS}
#endif
        [/ai]
        {FLAG_VARIANT6 ragged}
    [/side]

    [side]
        type=Orcish Warlord
        id=Maga-Knafa
        name= _ "Maga-Knafa"
        side=4
        canrecruit=yes
        recruit=Orcish Warrior,Wolf Rider,Orcish Crossbowman,Troll Warrior,Orcish Slayer
        {EBESIEGED_RECRUITMENT}
        team_name=orcs
        user_team_name=_"Orcs"
        {GOLD 150 225 300}
        [ai]
            {AVOID_CHANTAL}
#ifdef HARD
            {HIGH_PRIORITY_TARGETS}
#endif
        [/ai]
        {FLAG_VARIANT6 ragged}
    [/side]

    #allies of Konrad
    [side]
        type=Elvish Champion
        id=Galdrad
        name= _ "Galdrad"
        side=5
        canrecruit=yes
        recruit=Elvish Fighter,Elvish Archer,Elvish Ranger
        [ai]
            recruitment_pattern=fighter,archer,mixed fighter
        [/ai]
        {GOLD 225 200 175}
        team_name=elves
        user_team_name=_"Rebels"
        {FLAG_VARIANT wood-elvish}
    [/side]

    [side]
        type=Elvish Shyde
        id=Chantal
        name= _ "Chantal"
        profile=portraits/chantal-shyde.webp
        side=6
        canrecruit=yes
        recruit=Elvish Shaman,Elvish Archer,Elvish Fighter
        [ai]
            passive_leader="yes"
            passive_leader_shares_keep="yes"
            recruitment_pattern=archer,archer,fighter,fighter,healer
        [/ai]
        {GOLD 275 250 225}
        team_name=elves
        user_team_name=_"Rebels"
        {FLAG_VARIANT wood-elvish}
    [/side]

    [event]
        name=start

        [message]
            speaker=narrator
            image="wesnoth-icon.png"
            message= _ "Twenty years into her rule, Asheviere turned her attention to the wood elves living in the great forest southwest of Wesnoth, whom she despised. Orcish mercenaries were hired and dispatched to bring about their ruin."
        [/message]
        [message]
            speaker=Konrad
            message= _ "Master Delfador! Look, there are orcs coming from all directions! What shall we do?"
        [/message]
        [message]
            speaker=Delfador
            message= _ "There are too many to fight, far too many. We must escape!"
        [/message]
        [message]
            speaker=Konrad
            {KONRAD_VARIATION_ELF concerned}
            message= _ "But to where? This is the only home we have! What about the elves?"
        [/message]
        [message]
            speaker=Galdrad
            message= _ "We will fight them, but you must escape, Konrad. It is imperative that you escape!"
        [/message]
        [message]
            speaker=Delfador
            message= _ "We will go north. Perhaps we can reach the Isle of Alduin. If we can make it there, surely we will be safe. Konrad, we must recruit some elves to help us, and then you must make it to the sign post in the northwest. I will protect you!"
        [/message]
        [message]
            speaker=Konrad
            message= _ "Very well, let us hurry!"
        [/message]
        [message]
            speaker=Urug-Telfar
            message= _ "Attack the elves, my grunts, and take their villages. Let us claim this land for the Queen!"
        [/message]

        #on hard level, the enemies will specifically target Delfador and Konrad
#ifdef HARD
        [message]
            speaker=Knafa-Tan
            message= _ "Remember, it is rumored that the filthy mage and one that he protects are in these parts. They are the ones we want!"
        [/message]
#else
        [message]
            speaker=Knafa-Tan
            message= _ "Ha ha! We will rip the filthy elves to pieces!"
        [/message]
#endif
        [message]
            speaker=Galdrad
            message= _ "Let them come. We will fight them with all we have!"
        [/message]
        [message]
            speaker=Chantal
            message= _ "Be careful, Konrad! Guard him well, Delfador!"
        [/message]
        [message]
            speaker=Delfador
            message= _ "Do not spend your life here, Chantal. Someone must warn the Northern Elves that the war we so long feared has begun."
        [/message]

        {HIGHLIGHT_IMAGE 1 1 scenery/signpost.png ()}

        [scroll_to_unit]
            id=Konrad
        [/scroll_to_unit]
    [/event]

    [event]
        name=moveto
        [filter]
            x=1
            y=1
            id=Konrad
        [/filter]
        [message]
            speaker=Konrad
            message= _ "Very well, we have made it this far! But where do we go next?"
        [/message]
        [message]
            speaker=Delfador
            message= _ "We must travel north, and try to make it to the Isle of Alduin. Hopefully we will find refuge there."
        [/message]
        [message]
            speaker=Konrad
            message= _ "Of course you are right, Delfador. But what will become of the elves here?"
        [/message]
        [message]
            speaker=Delfador
            message= _ "The elves will fight. They may even prevail. But I fear things do not bode well for them. Let us not speak of it now. Onward!"
        [/message]
        [message]
            speaker=Chantal
            message= _ "Good luck, Konrad! Don’t worry about us, we will fight as best we can!"
        [/message]
        [endlevel]
            result=victory
            bonus=yes
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Konrad
        [/filter]
        [message]
            speaker=Konrad
            {KONRAD_VARIATION_ELF concerned}
            message= _ "I... I don’t think I can make it anymore."
        [/message]
        [message]
            speaker=Delfador
            message= _ "Prince... you must keep fighting! Nooooooo!"
        [/message]
        [message]
            speaker=Konrad
            {KONRAD_VARIATION_ELF concerned}
            message= _ "It is over. I am doomed..."
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Delfador
        [/filter]
        [message]
            speaker=Delfador
            message= _ "I have... have failed in my duty to protect the Prince! I am defeated."
        [/message]
        [message]
            speaker=Konrad
            {KONRAD_VARIATION_ELF concerned}
            message= _ "Don’t die, Delfador! Please, you have to stay alive!"
        [/message]
        [message]
            speaker=Delfador
            message= _ "Ugh!"
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=time over
        [message]
            speaker=Delfador
            message= _ "Oh, no! We have run out of time, they have arrived with reinforcements..."
        [/message]
    [/event]

    [event]
        name=die
        [filter_second]
            id=Konrad
        [/filter_second]
        [message]
            speaker=second_unit
            message= _ "Die, villain, die!"
            {KONRAD_VARIATION_ELF mad}
        [/message]
    [/event]

    [event]
        name=die
        [filter_second]
            id=Delfador
        [/filter_second]
        [message]
            speaker=Delfador
            message= _ "Only the foolish oppose me!"
        [/message]
    [/event]

    [event]
        name=attack
        [filter_second]
            id=Galdrad
        [/filter_second]
        [message]
            speaker=Galdrad
            message= _ "I am Galdrad. You will have to fight me to get any further!"
        [/message]
    [/event]

    [event]
        name=attack
        [filter_second]
            id=Delfador
        [/filter_second]
        [message]
            speaker=Delfador
            {DELFADOR_VARIATION_ELF mad}
            message= _ "Only a fool would dare to attack me!"
        [/message]
    [/event]

    [event]
        name=attack
        [filter]
            id=Delfador
        [/filter]
        [message]
            speaker=Delfador
            {DELFADOR_VARIATION_ELF mad}
            message= _ "I am Delfador the Great. Prepare to die!"
        [/message]
    [/event]

    [event]
        name=attack
        [filter]
            id=Konrad
        [/filter]
        [message]
            speaker=Konrad
            {KONRAD_VARIATION_ELF mad}
            message= _ "Let me through, you rogue!"
        [/message]
    [/event]

    #when a Goblin Knight moves onto one of the villages
    #that Delfador and Konrad start near
    [event]
        name=moveto
        [filter]
            side=2,3,4
            x,y=20,25
        [/filter]
        [scroll_to]
            x,y=20,25
        [/scroll_to]
        [terrain]
            x,y=20,25
            radius=1
            terrain=Rb
        [/terrain]
        [terrain]
            x,y=20,24
            terrain=Rb^Dr
        [/terrain]
        [item]
            x,y=20,25
            image=scenery/village-human-burned2.png
        [/item]
        [sound]
            name=torch.ogg
        [/sound]
        [delay]
            time=500
        [/delay]
        [fire_event]
            name=home destroyed
        [/fire_event]
    [/event]

    [event]
        name=moveto
        [filter]
            side=2,3,4
            x,y=17,23
        [/filter]
        [scroll_to]
            x,y=17,23
        [/scroll_to]
        [terrain]
            x,y=17,23
            radius=1
            terrain=Rb
        [/terrain]
        [terrain]
            x=18,18
            y=22,23
            terrain=Rb^Dr
        [/terrain]
        [item]
            x,y=17,23
            image=scenery/village-human-burned4.png
        [/item]
        [sound]
            name=torch.ogg
        [/sound]
        [delay]
            time=500
        [/delay]
        [fire_event]
            name=home destroyed
        [/fire_event]
    [/event]

    [event]
        name=home destroyed
        [message]
            speaker=Konrad
            {KONRAD_VARIATION_ELF concerned}
            message= _ "Oh no! They are destroying our home!"
        [/message]
        [message]
            speaker=Delfador
            message= _ "There can be no looking back. We must go quickly!"
        [/message]
    [/event]

    [event]
        name=die
        first_time_only=no

        [filter]
            side=2,3,4
            canrecruit=yes
        [/filter]

        [set_variable]
            name=besieged_enemies_killed
            add=1
        [/set_variable]
    [/event]
[/scenario]

#undef AVOID_CHANTAL
#undef HIGH_PRIORITY_TARGETS
#undef EBESIEGED_RECRUITMENT
