#textdomain wesnoth-tsg
[scenario]
    id=01_Born_to_the_Banner

    name= _ "Born to the Banner"
    next_scenario=02_Proven_by_the_Sword

    {SCENARIO_MUSIC loyalists.ogg}
    {EXTRA_SCENARIO_MUSIC battle.ogg}
    {EXTRA_SCENARIO_MUSIC knolls.ogg}

    map_data="{campaigns/The_South_Guard/maps/01_Born_to_the_Banner.map}"

    {campaigns/The_South_Guard/utils/sg_deaths.cfg}
    {campaigns/The_South_Guard/utils/sg_help.cfg}

    {DEFAULT_SCHEDULE_MORNING}

    victory_when_enemies_defeated=no
    {TURNS 24 20 16}

    # Scenario Introduction - Summer

    {SG_BORN_TO_THE_BANNER}
    {TSG_BIGMAP {JOURNEY_01_NEW} }

    # The South Guard

    [side]  # wmllint: validate-off
        side=1
        {QUANTITY type (Horseman Commander) (Junior Commander) (Junior Commander)}
        id=Deoran
        name= _ "Deoran"
        unrenamable=yes
        profile=portraits/deoran.png
        facing=sw

        team_name=South_Guard
        user_team_name=_"South Guard"
        controller=human
        {CUSTOM_SG_FLAG}

        {GOLD 70 60 50}
        {INCOME 4 2 0}

        canrecruit=yes
        recruit=Peasant
    [/side] # wmllint: validate-on

    {STARTING_VILLAGES 1 5}

    # The Bandit Armies

    [side]
        side=2
        type=Bandit
        id=Urza Mathin
        name= _ "Urza Mathin"

        team_name=bandits
        user_team_name=_"Bandits"
        controller=ai

        {GOLD 20 25 30}
        {INCOME -2 0 2}

        canrecruit=yes
#ifdef EASY
        recruit=Ruffian,Thug
#endif

#ifdef NORMAL
        recruit=Ruffian,Thug,Poacher
#endif

#ifdef HARD
        recruit=Footpad,Thief,Poacher,Thug
#endif
        [ai]
            {ATTACK_DEPTH 1 2 3}
#ifdef EASY
            recruitment_pattern=fighter
#endif
#ifdef NORMAL
            recruitment_pattern=fighter,fighter,archer
#endif
#ifdef HARD
            recruitment_pattern=scout,fighter,archer,archer
#endif
        [/ai]
        {FLAG_VARIANT6 ragged}
    [/side]

    {STARTING_VILLAGES 2 9}

    [label]
        x,y=9,10
        text= _ "The River Fort"
    [/label]

    # Scenario Pre-start

    [event]
        name=prestart

        [objectives]
            side=1
            [objective]
                [show_if]
                    [not]
                        [have_unit]
                            id=Sir Gerrick
                        [/have_unit]
                    [/not]
                [/show_if]
                description= _ "Investigate the river fort"
                condition=win
            [/objective]
            [objective]
                [show_if]
                    [have_unit]
                        id=Urza Mathin
                    [/have_unit]
                [/show_if]
                description= _ "Defeat Urza Mathin"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Deoran"
                condition=lose
            [/objective]
            [objective]
                [show_if]
                    [have_unit]
                        id=Sir Gerrick
                    [/have_unit]
                [/show_if]
                description= _ "Death of Sir Gerrick"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

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

#ifdef EASY
        [set_variable]
            name=leader_attacked
            value=no
        [/set_variable]
#endif

        # Add a useful village on 'trivial' difficulty'.
#ifdef EASY
        {MODIFY_TERRAIN Gg^Vh 10 18}
        [capture_village]
            side=2
            x,y=10,18
        [/capture_village]
#endif
    [/event]

    # Scenario Start

    [event]
        name=start
        [message]
            speaker=narrator
            {NARRATOR: _"Upon arrival, Deoran found the land completely overrun by bandits."}
            image=wesnoth-icon.png
        [/message]

        [move_unit_fake]
            {QUANTITY type Pikeman Spearman Spearman}
            side=1
            x=13,13,13,14
            y=8,7,6,5
        [/move_unit_fake]

        [unit]
            {QUANTITY type Pikeman Spearman Spearman}
            id=Moreth
            name= _ "Moreth"
            unrenamable=yes
            side=1
            x,y=14,5
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_RESILIENT}
            [/modifications]
            {IS_LOYAL}
        [/unit]

        [message]
            speaker=Moreth
            message= _ "You will never take this village! I have watched too many of your kind ransack our homes and kill the townsfolk! I’ll defend them to the death if I must!"
        [/message]

        [message]
            speaker=Deoran
            image=portraits/deoran-mad.png
            message= _ "My kind? I am a knight of Wesnoth and a messenger appointed by the King himself! What do you mean, <i>“my kind”</i>? And where is the South Guard?"
        [/message]

        [message]
            speaker=Moreth
            message= _ "My deepest apologies, sir! Bandits have been pillaging the villages and killing the peasants — we tried our utmost to resist and expel them, but their numbers were too great. Alas, Sir Gerrick and I are now the last two who remain. The South Guard is no more."
        [/message]

        [message]
            speaker=Deoran
            message= _ "What? I was sent here merely to question Sir Loris, but it seems that the circumstances here are more dire than I had thought. We must arm the villagers and drive off the bandits before they can do any more harm!"
        [/message]

        [message]
            speaker=Moreth
            message= _ "Then we must head to the river fort! Sir Gerrick is guarding the armory there!"
        [/message]

        {HIGHLIGHT_IMAGE 9 10 items/gohere.png ()}

#ifdef EASY
        [message]
            speaker=narrator
            image=items/gohere.png
            {TUTOR: _"Whenever you see a target that looks like this, you should move your leader (or whatever unit the dialog just suggested) onto the hex that contains it."}
        [/message]
#endif

        [message]
            speaker=Urza Mathin
            message= _ "Ha! This new commander is merely a boy. What kind of fool sent him here to stop us? This sniveling child will soon share the fate of that swine Loris!"
        [/message]
    [/event]

    # The River Fort - You find Sir Gerrick defending the citadel.

    [event]
        name=moveto

        [filter]
            side=1
            x,y=9,10
        [/filter]

        [remove_item]
            x,y=9,10
        [/remove_item]

        [unit]
            side=1
            type=Infantry Lieutenant
            id=Sir Gerrick
            name= _ "Sir Gerrick"
            unrenamable=yes
            profile=portraits/sir-gerrick.png
            {IS_HERO}
            x,y=10,9
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [message]
            speaker=Sir Gerrick
            message= _ "At last, reinforcements! Sir Knight, bandits have overrun the whole countryside, killing and pillaging without regard or mercy. My men and I tried to fight them off, but we were unfortunately routed and most of my men were slain. I have barely managed to defend this fort, but the South Guard has fallen and I do not know how much longer I can hold..."
        [/message]

        [message]
            speaker=Deoran
            message= _ "Do not despair! I am sure we can drive off these brigands if we rally the villagers and re-man the posts. Are there any weapons left in the citadel’s armory?"
        [/message]

        [message]
            speaker=Sir Gerrick
            message= _ "A small supply of spears and bows still remains. I will distribute them to the peasants if that is your wish, commander."
        [/message]

        [message]
            speaker=Deoran
            message= _ "<i>So he has decided that I am to take command? Very well, I have never been one to back down from a challenge.</i> Yes, we should assemble what troops we can at my encampment and organize a front against the bandits. I shall raise the white and red banners and lead us against them. The South Guard fights again!"
        [/message]

        [allow_recruit]
            side=1
            type=Spearman, Bowman
        [/allow_recruit]

#ifdef EASY
        [message]
            speaker=narrator
            image="units/infantry-commander.png~RC(magenta>red)"
            {TUTOR: _"As a senior infantry officer, Sir Gerrick is both a powerful warrior and capable leader, raising the fighting spirit of less experienced troops near him and causing their attacks to deal more damage."}
        [/message]

        [message]
            speaker=narrator
            image="misc/hero-icon.png"
            {TUTOR: _"Units that have a <i>hero</i> marker are vital to your campaign. If any of them die, you will lose the scenario, so guard them carefully!"}
        [/message]
#endif

        [if]
            [have_unit]
                id=Urza Mathin
            [/have_unit]
            [then]
                [show_objectives][/show_objectives]

#ifdef EASY
                [if]
                    [not]
                        [have_unit]
                            x,y=15,5
                            id=Deoran
                        [/have_unit]
                    [/not]
                    [then]
                        {HIGHLIGHT_IMAGE 15 5 items/gohere.png ()}

                        [message]
                            speaker=narrator
                            image=items/gohere.png
                            {TUTOR: _"Head back to the encampment where you started and recruit some troops!"}
                        [/message]

                        [event]
                            name=moveto
                            [filter]
                                x,y=15,5
                                id=Deoran
                            [/filter]

                            [fire_event]
                                name=encamped
                            [/fire_event]
                        [/event]
                    [/then]
                    [else]
                        [fire_event]
                            name=encamped
                        [/fire_event]
                    [/else]
                [/if]
#endif
            [/then]
            [else]
                [fire_event]
                    name=victory dance
                [/fire_event]
            [/else]
        [/if]

        # Activate side 2 a little late so they don't send everything at you before dawn breaks
        [gold]
            side=2
            amount={ON_DIFFICULTY 30 35 40}
        [/gold]
    [/event]

    # You return to the encampment and recruit troops.

#ifdef EASY
    [event]
        name=encamped

        [remove_item]
            x,y=15,5
        [/remove_item]

        [scroll_to]
            x,y=15,5
        [/scroll_to]

        [message]
            speaker=narrator
            {TUTOR: _"While you are in your camp, you can recruit more units. Build an army to use against the bandits that Urza Mathin recruits."}
            image=wesnoth-icon.png
        [/message]
        [message]
            speaker=narrator
            image="units/human-loyalists/bowman.png~RC(magenta>red)"
            {TUTOR: _"Bowmen have a strong ranged attack and are very effective against units that lack a ranged attack, like Thieves and Thugs. They also carry a sword and can defend themselves against melee attacks."}
        [/message]
        [message]
            speaker=narrator
            image="units/human-loyalists/spearman.png~RC(magenta>red)"
            {TUTOR: _"Spearmen have a strong melee attack and are effective against most units. They also have a weak ranged attack. They form the backbone of the South Guard."}
        [/message]
        [message]
            speaker=narrator
            {TUTOR: _"The best army will have a mix of units to deal with the different enemies that you will encounter. For now, concentrate on creating a small corps of experienced Bowmen."}
            image=wesnoth-icon.png
        [/message]
    [/event]
#endif

    # Merfolk - You find merfolk who will become allies and protect your waterways.

    [event]
        name=moveto
        [filter]
            side=1
            x,y=4,10
        [/filter]
        [unit]
            side=1
#ifdef EASY
            type=Merman Warrior
#endif
#ifdef NORMAL
            type=Merman Warrior
#endif
#ifdef HARD
            type=Merman Fighter
#endif
            id=Myssh
            name= _ "Myssh"
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_INTELLIGENT}
            [/modifications]
            x,y=5,11
            {IS_LOYAL}
        [/unit]
        [unit]
            side=1
#ifdef EASY
            type=Merman Spearman
#endif
#ifdef NORMAL
            type=Merman Hunter
#endif
#ifdef HARD
            type=Merman Hunter
#endif
            id=Ylla
            name= _ "Ylla"
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_QUICK}
            [/modifications]
            x,y=5,10
            {IS_LOYAL}
        [/unit]

        [message]
            speaker=Myssh
            message= _ "Your people have been our allies ever since the days of Lord Typhon. We will help you drive these bandits from your lands if you allow us to continue living here in peace."
        [/message]

        [message]
            speaker=Deoran
            message= _ "We welcome your aid! The rivers of this land will remain yours when we are victorious."
        [/message]

#ifdef EASY
        [message]
            speaker=narrator
            image="units/merfolk/hunter.png~RC(magenta>red)"
            {TUTOR: _"You may now recruit Merman Hunters. Merfolk are aquatic creatures and fight best in rivers and swamps. They are much less effective on dry land."}
        [/message]
#endif

        [allow_recruit]
            side=1
            type=Merman Hunter
        [/allow_recruit]
        {VARIABLE has_merfolk "yes"}
    [/event]

    # Dusk - Sir Gerrick suggests that you should hold the north banks of the river.

#ifdef EASY
    [event]
        name=turn 3

        [if]
            [have_unit]
                id=Sir Gerrick
            [/have_unit]
            [then]
                [message]
                    speaker=Sir Gerrick
                    message= _ "Bandits are most dangerous at night, Sir Deoran. Let us hold the north bank of the river until dawn and press our attack in the morning!"
                [/message]

                [message]
                    speaker=narrator
                    image=misc/time-schedules/default/schedule-firstwatch.png
                    {TUTOR: _"All of your units are <i>lawful</i>. This means that they receive a combat bonus during the day and a penalty at night. Urza Mathin’s units are all <i>chaotic</i>, which means that they receive a bonus at night and a penalty during the day. You will be much more effective fighting during the day."}
                [/message]
            [/then]
        [/if]
    [/event]
#endif

    # Dawn - Sir Gerrick suggests that you should attack now!

    [event]
        name=turn 6

        [if]
            [have_unit]
                id=Sir Gerrick
            [/have_unit]
            [then]
                [message]
                    speaker=Sir Gerrick
                    message= _ "The dawn breaks — now is the time for us to attack and drive these bandits from our lands. To me, men of the South Guard!"
                [/message]
            [/then]
        [/if]
        [message]
            speaker=Urza Mathin
            message= _ "Curses! They actually managed to survive the night! I must hold out until my brothers send more men my way."
        [/message]

#ifdef EASY
        [message]
            speaker=narrator
            image=misc/time-schedules/default/schedule-dawn.png
            {TUTOR: _"During the day, your units will deal more damage and the bandits will deal less. The more of Urza Mathin’s troops you can defeat during the day, the better."}
        [/message]
#endif
    [/event]

    # Village Ambush - You find something unexpected in one of the villages.

    [event]
        name=moveto
        [filter]
            side=1
            x,y=11,12
        [/filter]

#ifdef EASY
        [unit]
            side=1
            type=Longbowman
            id=Aleron
            name= _ "Aleron"
            x,y=12,12
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_QUICK}
            [/modifications]
            {IS_LOYAL}
        [/unit]

        [message]
            speaker=unit
            message= _ "Who goes there? Show yourself!"
        [/message]
        [message]
            speaker=Aleron
            message= _ "Stay your hand! It is I, Aleron! The villagers hid me from the bandits when the town was overrun. They tended to my wounds while I was gravely wounded."
        [/message]
        [message]
            speaker=Sir Gerrick
            message= _ "Thank the light! I am glad to find you alive, Aleron. We feared the worst when you did not return after the battle."
        [/message]
        [message]
            speaker=Aleron
            message= _ "No matter, I am healed now and ready to fight. Let us punish these bandits for their crimes and murders!"
        [/message]
        [message]
            speaker=narrator
            {TUTOR: _"Aleron is a Longbowman, stronger and better trained than regular bowmen. His arrows are deadly to enemies without a ranged attack."}
            image="units/human-loyalists/longbowman.png~RC(magenta>red)"
        [/message]
#endif

#ifdef NORMAL
        [unit]
            side=1
            type=Peasant
            id=Aleron
            name= _ "Aleron"
            x,y=12,12
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_STRONG}
            [/modifications]
            {IS_LOYAL}
        [/unit]

        [message]
            speaker=Aleron
            message= _ "More bandits? Begone, we have nothing left for you."
        [/message]
        [message]
            speaker=unit
            message= _ "We fight under the banner of the South Guard <i>against</i> the bandits! Join us if you wish to drive these brigands from your land!"
        [/message]
        [message]
            speaker=Aleron
            message= _ "The South Guard has risen again? I would be proud to fight alongside you!"
        [/message]
#endif

#ifdef HARD
        [unit]
            side=2
            type=Footpad
            random_traits=yes
            id=Glasar
            name= _ "Glasar"
            x,y=12,12
        [/unit]

        [message]
            speaker=Glasar
            message= _ "This village is ours to plunder! Leave now or perish!"
        [/message]
        [message]
            speaker=unit
            message= _ "Do you not see the banners we bear? The South Guard has risen again! Flee while you can, or you will meet a swift death at our hand!"
        [/message]
#endif
    [/event]

    # If the player doesn't find Sir Gerrick in five turns, prompt him again.

#ifdef EASY

    [event]
        name=turn 4
        [if]
            [not]
                [have_unit]
                    id=Sir Gerrick
                [/have_unit]
            [/not]
            [then]
                {HIGHLIGHT_IMAGE 9 10 items/gohere.png ()}

                [message]
                    speaker=narrator
                    image=items/gohere.png
                    {TUTOR: _"Remember, Moreth told you that you should go meet Sir Gerrick at the river fort. Move Deoran there and find out what Sir Gerrick has to say!"}
                [/message]
            [/then]
        [/if]
    [/event]

    # Nothing happens for a while: remind the player of the objective.

    [event]
        name=attack
        [filter_second]
            id=Urza Mathin
        [/filter_second]
        [set_variable]
            name=leader_attacked
            value=yes
        [/set_variable]
    [/event]

    [event]
        name=turn 12
        [if]
            [variable]
                name=leader_attacked
                boolean_not_equals=yes
            [/variable]
            [then]
                [scroll_to_unit]
                    id=Urza Mathin
                [/scroll_to_unit]
                [message]
                    speaker=narrator
                    image="units/human-outlaws/bandit.png~RC(magenta>red)"
                    {TUTOR: _"Remember, your job is to defeat Urza Mathin. He should be your main target. Archers will be especially effective against him because he has no ranged attack."}
                [/message]
            [/then]
        [/if]
    [/event]

    [event]
        name=victory

        {CLEAR_VARIABLE leader_attacked}
    [/event]
#endif

    [event]
        name=time over

        {GENERIC_UNIT 2 (Thug) 14 18}
        {GENERIC_UNIT 2 (Footpad) 15 20}
        {GENERIC_UNIT 2 (Thug) 14 19}
        {GENERIC_UNIT 2 (Poacher) 16 18}

        [message]
            speaker=Urza Mathin
            message= _ "Reinforcements from my brothers! Excellent. Let us go and crush this vermin boy who fancies himself a knight. These lands belong to the brothers Urza!"
        [/message]
        [message]
            speaker=Deoran
            message= _ "There are too many of them! I have no choice but to abandon the villagers here and retreat..."
        [/message]
    [/event]

    # Victory - The bandits are defeated.

    [event]
        name=last breath
        [filter]
            id=Urza Mathin
        [/filter]

        [message]
            speaker=Urza Mathin
            message= _ "My days of pillage and plunder are over! Avenge me, my brothers..."
        [/message]

        [kill]
            x,y=$x1,$y1
            animate=yes
        [/kill]

        [if]
            [have_unit]
                id=Sir Gerrick
            [/have_unit]
            [then]
                [fire_event]
                    name=victory dance
                [/fire_event]
            [/then]
            [else]
                [show_objectives][/show_objectives]
            [/else]
        [/if]
    [/event]

    [event]
        name=victory dance

        [message]
            speaker=Sir Gerrick
            message= _ "Urza Mathin is dead! Congratulations, commander, though I am surprised that the King sent only you to help us. Did Sir Loris not send word of our plight?"
        [/message]

        [message]
            speaker=Deoran
            message= _ "No. I was originally sent by King Haldric to investigate, as he had not heard word from you in weeks. I was prepared to take command of the South Guard if necessary, but not to fight so many bandits with so few men!"
        [/message]

        [message]
            speaker=Sir Gerrick
            message= _ "Aye, you could not have known if Sir Loris did not report of our predicament. I do wish that the King had sent more reinforcements, though you seem to be quite a capable commander despite your age."
        [/message]

        [message]
            speaker=Deoran
            message= _ "I have trained with the best, and perhaps that will make up for any inexperience I may have. At least, we must pray that my being here is enough to remedy these harrowing circumstances. How long have you been fighting against these bandits anyway?"
        [/message]

        [message]
            speaker=Sir Gerrick
            message= _ "Almost two months! I know not why, but one night, Sir Loris took several of our patrols along the Westin road and never returned. The very next evening, these ruffians struck and killed eight of my men. We defended the citadel and held out, hoping for reinforcements, but they never came. Something must have happened in Westin, else Sir Loris would have relieved us by now."
        [/message]

        [message]
            speaker=Deoran
            message= _ "Your story is indeed most peculiar, but we will not accomplish anything by staying here. We will have to seek out Sir Loris in Westin for answers. Come, men, let us ride to the city!"
        [/message]

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

    # this is present so that if you skip the scenario with debug, you will still have Sir Gerrick
    [event]
        name=victory

        [if]
            [not]
                [have_unit]
                    id=Sir Gerrick
                [/have_unit]
            [/not]
            [then]
                [unit]
                    side=1
                    type=Infantry Lieutenant
                    id=Sir Gerrick
                    name= _ "Sir Gerrick"
                    unrenamable=yes
                    profile=portraits/sir-gerrick.png
                    {IS_HERO}
                    x,y=10,9
                    [modifications]
                        {TRAIT_LOYAL}
                        {TRAIT_RESILIENT}
                    [/modifications]
                [/unit]
            [/then]
        [/if]
    [/event]
[/scenario]
