#textdomain wesnoth-dm
[scenario]
    id=04_Leollyn
    name=_ "Leollyn"
    {MEMOIRS_MAP 04_Leollyn.map}
    next_scenario=05_Council_in_Weldyn
    {TURNS 26 25 24}
    {DEFAULT_SCHEDULE}

    {SCENARIO_MUSIC loyalists.ogg} # No story text, so no intro music
    {EXTRA_SCENARIO_MUSIC northerners.ogg}
    {EXTRA_SCENARIO_MUSIC knolls.ogg}
    {EXTRA_SCENARIO_MUSIC elvish-theme.ogg}

    {DM_TRACK {SEARCH_STAGE4}}

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        recruit={LOYALISTS}
        save_id=Player
        team_name=allies
        user_team_name= _ "Mages"
        side_name= _ "Delfador"
        {FLAG_VARIANT long}
        [leader]
            {YOUNG_DELFADOR}
        [/leader]
        {GOLD 150 125 100}
    [/side]
    [event]
        name=prestart
        # bowmen said they would "come with you"
        [repeat]
            times=2
            [do]
                [role]
                    role=""
                    search_recall_list=only
                    type=Master Bowman,Longbowman,Bowman
                    [auto_recall][/auto_recall]
                    [else]
                        [unit]
                            placement=leader
                            side=1
                            type=Bowman
                        [/unit]
                    [/else]
                [/role]
            [/do]
        [/repeat]
        {MODIFY_UNIT (side=1) facing sw}
    [/event]

    [side]
        side=2
        controller=ai
        recruit=Wolf Rider, Orcish Assassin, Orcish Archer
        {GOLD 150 200 250}
        team_name=enemies
        user_team_name= _ "Pillagers"
        {FLAG_VARIANT6 ragged}
        [leader]
            id=Hagha-Tan
            name= _ "Hagha-Tan"
            type=Orcish Slayer
            facing=se
        [/leader]
        [ai]
            recruitment_pattern=scout, mixed fighter, mixed fighter, archer
            # there are a lot of close villages
            villages_per_scout=6
            # attack Delfador more heavily than Leollyn
            leader_value={ON_DIFFICULTY 1.8 1.9 2.0}
            [goal]
                name=target
                [criteria]
                    id=Delfador
                [/criteria]
                value={ON_DIFFICULTY 2.2 2.6 3.0}
            [/goal]
        [/ai]
    [/side]

    [side]
        side=3
        controller=ai
        recruit=Red Mage,White Mage
        {GOLD 20 10 0}
        {INCOME 10 9 8}
        team_name=allies
        user_team_name= _ "Loyalists"
        {FLAG_VARIANT loyalist}
        # wmllint: who LEOLLYN is Leollyn
        [leader]
            {LEOLLYN}
            facing=se
        [/leader]
        {UNIT 3 Spearman 2 18 (ai_special=guardian)} {FACING se}
        {UNIT 3 Spearman 4 18 (ai_special=guardian)} {FACING se}
        [ai]
            recruitment_pattern=mixed fighter,mixed fighter,healer
            aggression={ON_DIFFICULTY 0.2 0.1 0.0}
            caution={ON_DIFFICULTY 0.9 0.8 0.7}
            grouping=defensive
            support_villages=yes
        [/ai]
    [/side]
    # wmllint: validate-on

    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description=_ "Defeat Hagha-Tan"
                condition=win
            [/objective]
            [objective]
                description=_ "Death of Delfador"
                condition=lose
            [/objective]
            [objective]
                description=_ "Death of Leollyn"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

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

    [event]
        name=start
        [message]
            speaker=Delfador
            message=_"Methor told me that I could find Leollyn in his tower in the Royal Forest outside the city. It should be near here..."
        [/message]
        [message]
            speaker=Hagha-Tan
            message=_"Ah, another human is approaching... yes... more meat for my war-band..."
        [/message]
        [message]
            speaker=Leollyn
            message=_"Hail, strangers on the road! I crave your aid; hurry, for we are sorely beset!"
        [/message]
        [message]
            speaker=Delfador
            message=_"Well met, Leollyn! My friends and I will roust this barbarian for you. We’re getting used to such work by now — I did not expect to have so much trouble getting here!"
        [/message]
        [message]
            speaker=Leollyn
            message=_"Then you have not heard...? —But there will be time enough for talking. If you can distract those vile creatures, I will try to organize a counterattack."
        [/message]
    [/event]

    # alert player before they face poison
    [event]
        name=attack
        [filter]
            type_adv_tree=Orcish Assassin
        [/filter]
        [filter_second]
            side=1
        [/filter_second]
        [message]
            speaker=Hagha-Tan
            message=_"Yes... yes... slay them, my assassins!"
        [/message]
        [message]
            speaker=second_unit
            message=_"Uh oh... I don’t like the look of this..."
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            type_adv_tree=Orcish Assassin
        [/filter]
        [filter_second]
            side=1
        [/filter_second]
        [message]
            speaker=Delfador
            message=_ "Their blood sheds as readily as any man’s."
        [/message]
        [message]
            speaker=Leollyn
            message=_"You are a brave fighter, young friend."
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            side=1
            [not]
                id=Delfador
            [/not]
        [/filter]
        [filter_second]
            type_adv_tree=Orcish Assassin
        [/filter_second]
        [message]
            speaker=Leollyn
            message=_ "All of you have to be extra careful!"
        [/message]
        [message]
            speaker=Delfador
            message=_"Kill them all! For our slain friend."
        [/message]
    [/event]

    # defeat player if leollyn is killed
    [event]
        name=die
        [filter]
            id=Leollyn
        [/filter]
        [message]
            speaker=Delfador
            message=_"Leollyn is slain! This is terrible... I had best give up and return home."
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=victory
        [message]
            speaker=Leollyn
            message=_"Well now, you arrived just in the nick of time. A fellow mage too, I see. Now what did you say your name was?"
        [/message]
        [if]
            [variable]
                name=methor_alive
                equals=yes
            [/variable]
            [then]
                [message]
                    speaker=Delfador
                    message=_"Delfador, sir. Actually, I came seeking you — you see, I was a student of Methor’s. He said that you might find me employment in Weldyn."
                [/message]
                [message]
                    speaker=Leollyn
                    message=_"Ah, one of Methor’s, eh? Good, good... Well, young Garard certainly needs all the hands he can muster right now. Especially those who know their magic!"
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Delfador
                    message=_"Delfador, sir. But I bring you ill news... Methor, my teacher, is dead."
                [/message]
                [message]
                    speaker=Leollyn
                    message=_"That is ill news indeed... these are dark times. I think you had best return with me to Weldyn. Garard too, must hear your news."
                [/message]
            [/else]
        [/if]
        {CLEAR_VARIABLE methor_alive}
        [message]
            speaker=Delfador
            message=_"Is that Garard, King of Wesnoth, you refer to?!"
        [/message]
        [message]
            speaker=Leollyn
            message=_"Of course — do you know any other kings by that name? I was one of his father’s most trusted advisors until he passed away earlier this year, and I still have the son’s ear, though being young he listens perhaps less well than he should."
        [/message]
    [/event]

    {MEMOIRS_DEATHS}
[/scenario]
