#textdomain wesnoth-tsg
[scenario]
    id=2_Proven_By_The_Sword

    name= _ "Proven By The Sword"
    next_scenario=3_A_Desperate_Errand

    {SCENARIO_MUSIC battle.ogg}
    {EXTRA_SCENARIO_MUSIC the_city_falls.ogg}

    map_data="{campaigns/The_South_Guard/maps/2_Proven_By_The_Sword.map}"

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

    [label]
        x,y=22,16
        text=_"Westin"
    [/label]

    {SECOND_WATCH}
    {DAWN}
    {MORNING}
    {AFTERNOON}
    {DUSK}
    {FIRST_WATCH}

    {TURNS 40 32 28}

    # Scenario Introduction - Not all is right in Westin.

    {SG_PROVEN_BY_THE_SWORD}

    # The South Guard

    [side]
        side=1
        type=Horseman Commander
        id=Deoran
        name= _ "Deoran"
        unrenamable=yes

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

        {GOLD 130 100 85}

        canrecruit=yes
        recruit=Bowman, Spearman
    [/side]

    {STARTING_VILLAGES 1 4}

    # The Bandit Armies

    # wmllint: local spelling Nalmath
    [side]
        side=2
        type=Outlaw
        id=Urza Nalmath
        name= _ "Urza Nalmath"

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

        {GOLD 20 30 40}

        canrecruit=yes
        {QUANTITY recruit (Ruffian,Thief,Footpad)
        (Ruffian,Thug,Thief,Poacher)
        (Footpad,Thug,Thief,Poacher,Trapper)}

        [ai]
            # macroified the params here because they'll be reused later in the scenario
#define URZA_NALMATH_AI_PARAMS
    {ATTACK_DEPTH 2 3 4}
    grouping=no
    {NO_SCOUTS}
    village_value=3
#enddef

            {URZA_NALMATH_AI_PARAMS}

            {QUANTITY recruitment_pattern (fighter,fighter,scout,fighter)
            (fighter,archer,fighter,fighter)
            (scout,fighter,archer,fighter,fighter)}
        [/ai]
    [/side]

    {STARTING_VILLAGES 2 21}

    # The Bandit Armies - Hidden Criminals

    [side]
        side=3
        no_leader=yes

        team_name=bandits
        user_team_name=_"Bandits"

#define MAKE_PREVIOUS_AN_AMBUSHER
    [+unit]
        [status]
            ambush=on
        [/status]
    [/unit]
#enddef
        {NAMED_GENERIC_UNIT 2 Footpad 28 13 () (_"Criminal")}
        {MAKE_PREVIOUS_AN_AMBUSHER}
#ifdef NORMAL
        {NAMED_GENERIC_UNIT 2 Footpad 34 14 () (_"Criminal")}
        {MAKE_PREVIOUS_AN_AMBUSHER}
#endif
#ifdef HARD
        {NAMED_GENERIC_UNIT 2 Footpad 34 14 () (_"Criminal")}
        {MAKE_PREVIOUS_AN_AMBUSHER}
        {NAMED_GENERIC_UNIT 2 Thief 22 12 () (_"Criminal")} {GUARDIAN}
#endif
#undef MAKE_PREVIOUS_AN_AMBUSHER

        {NAMED_GENERIC_UNIT 2 Footpad 21 17 () (_"Criminal")} {GUARDIAN}
#ifdef NORMAL
        {NAMED_GENERIC_UNIT 2 Poacher 18 22 () (_"Criminal")} {GUARDIAN}
#endif
#ifdef HARD
        {NAMED_GENERIC_UNIT 2 Thief 18 22 () (_"Criminal")} {GUARDIAN}
#endif
    [/side]

    [event]
        name=prestart

        # Add a useful village on 'trivial' difficulty.
#ifdef EASY
        {MODIFY_TERRAIN Gg^Vh 26 20}
#endif

        # Modify the size of the keep of the enemy on 'simple' and 'easy' difficulties.
#ifdef NORMAL
        {MODIFY_TERRAIN Ce 18 27}
#endif
#ifdef HARD
        {MODIFY_TERRAIN Ce 18 27}
        {MODIFY_TERRAIN Ce 19 28}
#endif

        #make Urza Nalmath water-phobic
        [object]
            silent=yes
            [filter]
                side=2
                canrecruit=yes
            [/filter]
            [effect]
                apply_to=movement_costs
                replace=true
                [movement_costs]
                    deep_water={UNREACHABLE}
                    shallow_water={UNREACHABLE}
                    swamp_water={UNREACHABLE}
                [/movement_costs]
            [/effect]
        [/object]
    [/event]

    [event]
        name=start

        [recall]
            id=Sir Gerrick
        [/recall]

#ifdef EASY
        [recall]
            type=Royal Guard, Pikeman, Swordsman, Javelineer, Master Bowman, Longbowman
        [/recall]
        [recall]
            type=Royal Guard, Pikeman, Swordsman, Javelineer, Master Bowman, Longbowman
        [/recall]
#endif
#ifdef NORMAL
        [recall]
            type=Royal Guard, Pikeman, Swordsman, Javelineer, Master Bowman, Longbowman
        [/recall]
#endif

        [message]
            speaker=Deoran
            message= _ "Look! There is smoke coming from Westin. That can only mean that bandits have overrun the garrison and are sacking the city!"
        [/message]
        [message]
            speaker=Sir Gerrick
            message= _ "If too much time passes and they are unchecked, they will leave the city in ruins and make a great slaughter of all who live therein. We must act quickly."
        [/message]

        {HIGHLIGHT_IMAGE 22 16 items/gohere.png ()}

        [message]
            speaker=Urza Nalmath
            message= _ "What!? If there are soldiers of Wesnoth coming from the northern forts, then my brother Mathin is surely dead... They will pay for his death, just as Sir Loris paid for his pride!"
        [/message]

        [objectives]
            side=1
            [objective]
                description= _ "Take the Citadel at Westin by the end of the ninth turn"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Deoran"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Sir Gerrick"
                condition=lose
            [/objective]
            [objective]
                description= _ "Time runs out"
                condition=lose
            [/objective]

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

    # Someone from the South Guard reaches the citadel and holds it.

    [event]
        name=moveto
        [filter]
            side=1
            x,y=22,16
        [/filter]

        {VARIABLE citadel_secured "yes"}
        # check if it is Deoran. If not, tell him to go to Westin
        [if]
            [have_unit]
                x,y=22,16
                [not]
                    id=Deoran
                [/not]
            [/have_unit]
            [then]
                [message]
                    speaker=unit
                    message= _ "At last the citadel is secured."
                [/message]
                [message]
                    speaker=Sir Gerrick
                    message= _ "Now, Deoran, take your post of command at the Citadel of Westin."
                [/message]
                [objectives]
                    side=1
                    [objective]
                        description= _ "Bring Deoran to the Citadel of Westin."
                        condition=win
                    [/objective]
                    [objective]
                        description= _ "Death of Deoran"
                        condition=lose
                    [/objective]
                    [objective]
                        description= _ "Death of Sir Gerrick"
                        condition=lose
                    [/objective]
                    [objective]
                        description= _ "Time runs out"
                        condition=lose
                    [/objective]

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

    # Deoran arrives at the citadel

    [event]
        name=moveto
        [filter]
            id=Deoran
            x,y=22,16
        [/filter]

        [removeitem]
            x,y=22,16
        [/removeitem]

        [unit]
            type=White Mage
            id=Minister Hylas
            profile=portraits/hylas.png
            name= _ "Minister Hylas"
            {IS_HERO}
            side=1
            x,y=21,16
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]

        [message]
            speaker=Deoran
            image=portraits/deoran-mad.png
            message= _ "More bandits?! They'll feel the deadly bite of my lance!"
        [/message]
        [message]
            speaker=Minister Hylas
            message= _ "Peace! For I am no enemy. I am Minister Hylas, advisor to Sir Loris! You came just in time! We couldn't have held them off another day..."
        [/message]
        [message]
            speaker=Deoran
            message= _ "Indeed, our arrival was timely. But where is Sir Loris? Where is the garrison of the city? I was sent by Haldric to relieve him and take command of the South Guard, for the King has heard no news from Westin in two months."
        [/message]
        [message]
            speaker=Minister Hylas
            message= _ "Alas, Sir Loris will find no relief now. He is buried northwest of the city where he fell. For weeks we warned him of the new power of these bandits. And yet he would never lead his men against them until their strength had waxed and ours waned."
        [/message]
        [message]
            speaker=Deoran
            image=portraits/deoran-sad.png
            message= _ "It grieves me to learn of his death, foolish though he may have been! Now, though, there are more pressing matters. Rise, men of Wesnoth! We must drive these bandits from our city!"
        [/message]

        {NAMED_LOYAL_UNIT 1 Peasant 18 15 (Ufes) (_"Ufes")}
        {NAMED_LOYAL_UNIT 1 Peasant 18 16 (Joran) (_"Joran")}
        {NAMED_LOYAL_UNIT 1 Peasant 19 18 (Makees) (_"Makees")}
        {NAMED_LOYAL_UNIT 1 Peasant 20 18 (Tyborg) (_"Tyborg")}

        [message]
            speaker=Ufes
            message= _ "We will do our best to hold the city - you lead your men across the river and kill the bandit leader!"
        [/message]

        [objectives]
            side=1
            [objective]
                description= _ "Kill Urza Nalmath, the bandit leader"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Deoran"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Sir Gerrick"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Minister Hylas"
                condition=lose
            [/objective]
            [objective]
                description= _ "Time runs out"
                condition=lose
            [/objective]

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

        [set_recruit]
            side=2
            {QUANTITY recruit (Walking Corpse)
            (Walking Corpse,Skeleton,Vampire Bat)
            (Skeleton,Skeleton Archer,Vampire Bat,Blood Bat)}
        [/set_recruit]

        # update the [ai] params so that the recruitment_pattern matches the new
        # recruits
        [modify_side]
            side=2

            [ai]
                {URZA_NALMATH_AI_PARAMS}

                {QUANTITY recruitment_pattern (fighter)
                (fighter,fighter,scout,fighter)
                (fighter,archer,fighter,archer,scout)}
            [/ai]
        [/modify_side]

        [gold]
            side=2
            {QUANTITY amount 15 30 60}
        [/gold]
    [/event]

    # Deoran is too late.

    [event]
        name=turn 9
        [if]
            [variable]
                name=citadel_secured
                not_equals="yes"
            [/variable]
            [then]
                [message]
                    speaker=Sir Gerrick
                    message= _ "They are almost to the great hall! Hurry, Deoran! You must reach the citadel or all will be lost!"
                [/message]

#ifdef EASY
                [message]
                    speaker=narrator
                    message= _ "You must move Deoran here by the end of the next turn, or Westin will fall and you will be defeated!"
                    image=wesnoth-icon.png
                [/message]
#endif
            [/then]
        [/if]
    [/event]

    [event]
        name=turn 10
        [if]
            [variable]
                name=citadel_secured
                not_equals="yes"
            [/variable]
            [then]
                [message]
                    speaker=Sir Gerrick
                    message= _ "We're too late! They're burning the city..."
                [/message]
                [message]
                    speaker=Deoran
                    image=portraits/deoran-sad.png
                    message= _ "Westin has fallen! This is a problem too great for me to handle - I must return to Haldric and tell him of our loss..."
                [/message]

                [endlevel]
                    result=defeat
                [/endlevel]
            [/then]
        [/if]
    [/event]

    # The undead attack

    [event]
        name=side turn
        first_time_only=no

        [if]
            [variable]
                name=undead_spotted
                not_equals=yes
            [/variable]

            [have_unit]
                race=undead
            [/have_unit]

            [then]
                [scroll_to_unit]
                    race=undead
                [/scroll_to_unit]

                [message]
                    speaker=Urza Nalmath
                    message= _ "Now the Guard will feel the wrath of my new friends! It is time for the dead to wage war! Rise, warriors!"
                [/message]

                [message]
                    speaker=Sir Gerrick
                    message= _ "What devilry is this?! Those are no living men that fight for him!"
                [/message]
                [message]
                    speaker=Minister Hylas
                    message= _ "He has made some pact with the undead. How could a mere brigand have gained such great powers?"
                [/message]
                [message]
                    speaker=Deoran
                    message= _ "However he has done this fell thing, we must defeat him!"
                [/message]

#ifdef EASY
                [message]
                    speaker=narrator
                    image="units/human-magi/white-mage-magic-1.png~RC(magenta>red)"
                    message= _ "Not only will Minister Hylas's arcane attack melt undead bones, but he can also heal wounded units near him."
                [/message]
#endif

                [scroll_to_unit]
                    race=undead
                [/scroll_to_unit]

                {VARIABLE undead_spotted yes}
            [/then]
        [/if]
    [/event]

    # Pillaging and burning the villages near Westin

    [event]
        name=capture
        [filter]
            side=2
            race=human
        [/filter]

        [message]
            speaker=Urza Nalmath
            message= _ "Leave nothing standing! Burn their villages down and kill them all!"
        [/message]
        [message]
            speaker=unit
            message= _ "We will avenge your brother's death!"
        [/message]
        [message]
            speaker=Sir Gerrick
            message= _ "They are burning our villages! We must stop them!"
        [/message]
    [/event]

    [event]
        name=capture
        first_time_only=no
        [filter]
            side=2
            race=human
        [/filter]

        [sound]
            name=torch.ogg
        [/sound]

        {VARIABLE_OP random_string format "scenery/village-human-burned1.png,scenery/village-human-burned2.png,scenery/village-human-burned3.png,scenery/village-human-burned4.png"}
        {RANDOM $random_string}

        {PLACE_IMAGE $random $x1 $y1}

        {MODIFY_TERRAIN Gg $x1 $y1}

        [gold]
            side=2
            amount=10
        [/gold]
    [/event]

    # Victory

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

        [message]
            speaker=unit
            message= _ "My brother has died unavenged! What have we done!?"
        [/message]

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

        [if]
            [have_unit]
                id=Minister Hylas
                x,y=$x2,$y2
            [/have_unit]

            [then]
                [message]
                    speaker=Deoran
                    message= _ "How can a bandit have summoned undead?"
                [/message]
            [/then]

            [else]
                [message]
                    speaker=second_unit
                    message= _ "How can a bandit have summoned undead?"
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Minister Hylas
            message= _ "Just before the bandit raids began, an ambassador came to Sir Loris from the elves of the Aethenwood west of here. He asked that a knight be sent to discuss a new threat to Wesnoth."
        [/message]

        [message]
            speaker=Deoran
            message= _ "And did Sir Loris go to the elves?"
        [/message]

        [message]
            speaker=Minister Hylas
            message= _ "No. He suspected the elves of some trickery and made no reply to them. Perhaps they know the origin of these dead warriors we now face."
        [/message]

        [message]
            speaker=Deoran
            message= _ "My men have been trained to fight the living. I do not know that we can protect the city from foes so dark as these. I shall go meet the elves and see if they can be of any aid!"
        [/message]

        [message]
            speaker=Minister Hylas
            message= _ "I will accompany you, my lord. I have studied the arts of holy magic and my skill may be of some use against the dark ones."
        [/message]

        [message]
            speaker=narrator
            message= _ "Deoran sent a rider to request mounted reinforcements and set out at once towards the Aethenwood..."
            image=wesnoth-icon.png
        [/message]

        {CLEAR_VARIABLE citadel_secured}

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