#textdomain wesnoth-httt
[scenario]
    id=23_Test_of_the_Clans
    name= _ "Test of the Clan"
    map_data="{campaigns/Heir_To_The_Throne/maps/23_Test_of_the_Clans.map}"
    {SCENARIO_MUSIC "knolls.ogg"}
    {EXTRA_SCENARIO_MUSIC "the_city_falls.ogg"}
    {EXTRA_SCENARIO_MUSIC "battle.ogg"}
    {TURNS 53 50 47}

    {DEFAULT_SCHEDULE}

    next_scenario=24_Battle_for_Wesnoth

    # wmllint: local spelling Bayer
    [event]
        name=prestart
#ifdef EASY
        {VARIABLE units_to_slay 25}
#endif
#ifdef NORMAL
        {VARIABLE units_to_slay 35}
#endif
#ifdef HARD
        {VARIABLE units_to_slay 50}
#endif
        [recall]
            id=Delfador
        [/recall]
        [recall]
            id=Kalenz
        [/recall]
        [recall]
            id="Li'sar"
        [/recall]
        [objectives]
            side=1
            [objective]
                description= _ "Defeat $units_to_slay enemy units"
                condition=win
            [/objective]
            [objective]
                description= _ "<span color='white'>Bonus objective:</span>
<span color='green'>Defeat all enemy leaders</span>"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Konrad"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Delfador"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Li'sar"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Kalenz"
                condition=lose
            [/objective]
            [objective]
                description= _ "Turns run out"
                condition=lose
            [/objective]

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

    {BIGMAP_TEST_OF_THE_CLANS}

    [side]
        team_name=elves
        user_team_name=_"Rebels"
        type=Commander
        id=Konrad
        name= _ "Konrad"
        unrenamable=yes
        profile=portraits/konrad.png
        side=1
        canrecruit=yes
        controller=human
        gold=400
    [/side]

    {STARTING_VILLAGES 1 7}

    [side]
        team_name=clan
        user_team_name=_"Plainsmen"
        type=Grand Knight
        id=Sir Alric
        name= _ "Sir Alric"
        side=2
        canrecruit=yes
        recruit=Horseman,Knight,Bowman,Lancer
        [ai]
            recruitment_pattern=fighter,fighter,archer
            {ATTACK_DEPTH 5 5 6}
        [/ai]
        [ai]
            time_of_day=morning,afternoon
            grouping=offensive
            aggression=0.6
        [/ai]
        [ai]
            time_of_day=first_watch,second_watch
            aggression=0.4
            grouping=defensive
        [/ai]
        {GOLD 120 150 180}
        {INCOME 2 4 8}
    [/side]

    {STARTING_VILLAGES 2 7}

    [side]
        team_name=clan
        user_team_name=_"Plainsmen"
        type=Grand Knight
        id=Sir Ruga
        name= _ "Sir Ruga"
        side=3
        canrecruit=yes
        recruit=Horseman,Knight,Bowman,Lancer
        [ai]
            recruitment_pattern=fighter,fighter,archer
            {ATTACK_DEPTH 5 5 6}
        [/ai]
        [ai]
            time_of_day=morning,afternoon
            grouping=offensive
            aggression=0.6
        [/ai]
        [ai]
            time_of_day=first_watch,second_watch
            aggression=0.4
            grouping=defensive
        [/ai]
        {GOLD 120 150 180}
        {INCOME 2 4 8}
    [/side]

    {STARTING_VILLAGES 3 7}

    [side]
        team_name=clan
        user_team_name=_"Plainsmen"
        type=Grand Knight
        id=Sir Daryn
        name= _ "Sir Daryn"
        side=4
        canrecruit=yes
        recruit=Horseman,Knight,Bowman,Lancer
        [ai]
            recruitment_pattern=fighter,fighter,archer
            {ATTACK_DEPTH 5 5 6}
        [/ai]
        [ai]
            time_of_day=morning,afternoon
            grouping=offensive
            aggression=0.6
        [/ai]
        [ai]
            time_of_day=first_watch,second_watch
            aggression=0.4
            grouping=defensive
        [/ai]
        {GOLD 120 150 180}
        {INCOME 2 4 8}
    [/side]

    {STARTING_VILLAGES 4 7}

    [side]
        team_name=clan
        user_team_name=_"Plainsmen"
        type=Grand Knight
        id=Bayar
        name= _ "Lord Bayar"
        side=5
        canrecruit=yes
        recruit=Knight,Longbowman
        [ai]
            recruitment_pattern=fighter,fighter,archer
            {ATTACK_DEPTH 5 5 6}
        [/ai]
        [ai]
            time_of_day=morning,afternoon
            grouping=offensive
            aggression=0.6
        [/ai]
        [ai]
            time_of_day=first_watch,second_watch
            aggression=0.4
            grouping=defensive
        [/ai]
        {GOLD 140 170 200}
        {INCOME 4 8 12}
    [/side]

    {STARTING_VILLAGES 5 7}

    [event]
        name=start

        # {SCATTER_IMAGE (terrain=Gg) 22 scenery/pine2.png}

        [message]
            speaker=Konrad
            message= _ "Greetings, men of the plains."
        [/message]
        [message]
            speaker=Sir Daryn
            message= _ "What do these intruders want? We did not invite them here, that is certain."
        [/message]
        [message]
            speaker=Delfador
            message= _ "We come in peace! We wish for you to aid us in our struggle against Asheviere, the evil Queen."
        [/message]
        [message]
            speaker=Sir Alric
            message= _ "We will not join you. You who are led by these youths and this old man."
        [/message]
        [message]
            speaker=Delfador
            message= _ "You are for us or against us. If you do not join us to overthrow the evil Queen, we will strip you of your power, once the throne is rightfully reclaimed."
        [/message]
        [message]
            speaker=Bayar
            message= _ "Hah! You think you can seize the throne? Defeat us in battle and we will join you, or leave now and never return!"
        [/message]
        [message]
            speaker=Kalenz
            message= _ "Very well. We will fight you."
        [/message]
        [message]
            speaker=Bayar
            message= _ "Fools! We will run you down like dogs!"
        [/message]
        [message]
            speaker=Sir Alric
            message= _ "There is no turning back for you now. This is a fight to the death!"
        [/message]
        [music]
            name="battle.ogg"
            immediate=yes
        [/music]
    [/event]

    [event]
        name=turn 3
        [message]
            speaker=Konrad
            message= _ "Delfador, this is sheer madness. We cannot afford to play games when we should be marching against the Queen."
        [/message]
        [message]
            speaker=Konrad
            message= _ "Lord Bayar, halt this folly! I challenge you to a personal combat."
        [/message]
        [message]
            speaker=Bayar
            message= _ "Ho! You have amused me, young heir. Ho, ho, challenge indeed."
        [/message]
        [message]
            speaker=Konrad
            message= _ "Young heir? Then you assent to my claim?"
        [/message]
        [message]
            speaker=Bayar
            message= _ "Impudence. Bah! Do you see orcs on our plains? Did we not grant you a test of your strength?"
        [/message]
        [message]
            speaker=Konrad
            message= _ "I fail to see the purpose of this exercise. It only weakens us."
        [/message]
        [message]
            speaker=Bayar
            message= _ "No, whelp. You may be weakened, but the horse clans are eternal. I will promise you this, however. If you can defeat me personally, I myself will join your siege of Weldyn."
        [/message]
        [message]
            speaker=Sir Ruga
            message= _ "Aye."
        [/message]
        [message]
            speaker=Sir Daryn
            message= _ "Aye."
        [/message]
        [message]
            speaker=Sir Alric
            message= _ "Aye."
        [/message]
    [/event]

    #
    # Lord Bayar dies - you get a bonus
    #
    [event]
        name=last breath
        [filter]
            id=Bayar
        [/filter]

        {VARIABLE clan_bayar 1}

        [if]
            [variable]
                name=units_to_slay
                greater_than=1
            [/variable]
            [then]
                [message]
                    speaker=Bayar
                    message= _ "I cannot believe this! You have defeated me! You are now my liege, and I leave the battlefield in shame. But the Clan shall fight on!"
                [/message]
                [message]
                    speaker=Delfador
                    message= _ "Their leader has fallen but still they fight!"
                [/message]
            [/then]
        [/if]
    [/event]
    #
    # Sir Daryn dies - you get a bonus
    #
    [event]
        name=last breath
        [filter]
            id=Sir Daryn
        [/filter]

        {VARIABLE clan_daryn 1}

        [if]
            [variable]
                name=units_to_slay
                greater_than=1
            [/variable]
            [then]
                [message]
                    speaker=Sir Daryn
                    message= _ "You can defeat me, but the Clan will never fall. Our numbers are endless!"
                [/message]
            [/then]
        [/if]
    [/event]
    #
    # Sir Ruga dies - you get a bonus
    #
    [event]
        name=last breath
        [filter]
            id=Sir Ruga
        [/filter]

        {VARIABLE clan_ruga 1}

        [if]
            [variable]
                name=units_to_slay
                greater_than=1
            [/variable]
            [then]
                [message]
                    speaker=Sir Ruga
                    message= _ "Even as I pledge my lance to your service, my Clan fights on!"
                [/message]
            [/then]
        [/if]
    [/event]
    #
    # Sir Alric dies - you get a bonus
    #
    [event]
        name=last breath
        [filter]
            id=Sir Alric
        [/filter]

        {VARIABLE clan_alric 1}

        [if]
            [variable]
                name=units_to_slay
                greater_than=1
            [/variable]
            [then]
                [message]
                    speaker=Sir Alric
                    message= _ "A humiliating defeat, yet you are no match for the might of the Clan!"
                [/message]
            [/then]
        [/if]
    [/event]

#define BONUS_VICTORY
    [if]
        [have_unit]
            id=Bayar
            side=5
        [/have_unit]
        [then]
            [role]
                type=Grand Knight
                side=5
                role=clanboss
            [/role]
        [/then]
        [else]
            [role]
                type=Grand Knight
                side=5,4,3,2
                role=clanboss
            [/role]
        [/else]
    [/if]
    [message]
        role=clanboss
        message= _ "Stop! I cannot believe this! You have defeated us! Indeed, you are worthy, worthy even to claim the throne. The clans will help you. We will fight with you against the Queen."
    [/message]
    [message]
        speaker=Konrad
        message= _ "So you admit defeat! You will serve me in fighting the evil queen?"
    [/message]
    [message]
        role=clanboss
        message= _ "We will serve you, my lord. You will make a worthy king."
    [/message]

    [message]
        speaker=narrator
        image="wesnoth-icon.png"
        message= _ "The mighty riders of the eastern plains, the Knights of the Clans, are now yours to command!"
    [/message]
    [allow_recruit]
        type=Knight
    [/allow_recruit]

    [message]
        speaker="Li'sar"
        message= _ "I think you are mistaken! You will help me be queen."
    [/message]
    [message]
        role=clanboss
        message= _ "Who then is your leader? Who do we serve?"
    [/message]
    [message]
        speaker=Delfador
        message= _ "You will serve us. You will protect our flanks while we make way straight for the queen. With you on either flank, we can surely overcome her."
    [/message]
    [message]
        speaker=Kalenz
        message= _ "Delfador, don't you think it is time we settled this?"
    [/message]
    [message]
        speaker=Delfador
        message= _ "Yes, it is time. It is time for the truth to be told. I had hoped to take this secret to my grave, but it isn't to be. You elves live too long, and though I have tried hard to understand, your wisdom is foreign to me."
    [/message]
    [message]
        speaker=Konrad
        message= _ "Secret? What secret Delfador? What are you talking about?"
    [/message]
    [message]
        speaker=Delfador
        # wmllint: local spelling Elnar
        message= _ "We should not speak of it now. Instead come with me, Konrad and Li'sar, to the top of mount Elnar. To look at Weldyn. To make plans for the battle, and to talk."
    [/message]
    {CLEAR_VARIABLE units_to_slay}
    [endlevel]
        result=victory
        bonus=yes
        {NEW_GOLD_CARRYOVER 40}
    [/endlevel]
#enddef

    [event]
        name=last breath
        first_time_only=no
        [filter]
            side=2,3,4,5
        [/filter]

        {VARIABLE_OP units_to_slay add -1}

        [if]
            [variable]
                name=units_to_slay
                numerical_equals=0
            [/variable]

            [then]
                [message]
                    speaker=Delfador
                    message= _ "We are routing their forces! Let's see if the Clan has had enough. Their help in guarding our flanks will be invaluable."
                [/message]
                {BONUS_VICTORY}
            [/then]
            [else]
                [print]
                    text= _ "Still $units_to_slay clan members to defeat!"
                    size=18
                    red,green,blue=255,255,255
                [/print]
            [/else]
        [/if]
    [/event]

    [event]
        name=enemies defeated
        [if]
            [variable]
                name=units_to_slay
                greater_than=0
            [/variable]
            [then]
                # Re-create Lord Bayar so he can talk. He's not dead;
                # he's just out of commission.
                {NAMED_LOYAL_UNIT 5 (Grand Knight) 8 54 (Lord Bayar) (_ "Lord Bayar")}
                {BONUS_VICTORY}
            [/then]
        [/if]
    [/event]

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