#textdomain wesnoth-tsg
[scenario]
    id=02_Proven_by_the_Sword

    name= _ "Proven by the Sword"
    next_scenario=03_A_Desperate_Errand

    {SCENARIO_MUSIC breaking_the_chains.ogg}
    {EXTRA_SCENARIO_MUSIC the_city_falls.ogg}
    {EXTRA_SCENARIO_MUSIC casualties_of_war.ogg}

    map_data="{campaigns/The_South_Guard/maps/02_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,13
        text=_"Westin"
    [/label]

    {DEFAULT_SCHEDULE_SECOND_WATCH}

    victory_when_enemies_defeated=no
    turns=7

    # Scenario Introduction - Not all is right in Westin.

    {SG_PROVEN_BY_THE_SWORD}
    {TSG_BIGMAP {JOURNEY_02_NEW} }

    # The South Guard

    [side]
        side=1
        type=Horseman Commander
        id=Deoran
        name= _ "Deoran"
        profile=portraits/deoran.png
        unrenamable=yes

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

        {GOLD 80 70 60}

        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

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

        [ai]
            grouping=no
            {NO_SCOUTS}

            {QUANTITY recruitment_pattern (fighter,fighter,scout,fighter)
            (fighter,archer,fighter,fighter)
            (scout,fighter,archer,fighter,fighter)}

            # The units at the beginning should not focus villages:
            village_value=0
            # scout_village_targeting=0
            {MODIFY_AI_DELETE_CANDIDATE_ACTION 2 main_loop villages}
        [/ai]
        {FLAG_VARIANT6 ragged}

        # These units won't, unlike all recruited ones, burn down villages.
        # Instead they capture them, if they move onto one.
#define VILLAGE_USERS
    [+unit]
        role=Criminal
        upkeep=loyal
    [/unit]
#enddef

        {NAMED_GENERIC_UNIT 2 Footpad 24 7 () (_"Criminal")} {VILLAGE_USERS}
        {NAMED_GENERIC_UNIT 2 Thief 22 13 () (_"Criminal")} {VILLAGE_USERS} {GUARDIAN}

#ifdef NORMAL
        {NAMED_GENERIC_UNIT 2 Footpad 26 11 () (_"Criminal")} {VILLAGE_USERS}
#endif

#ifdef HARD
        {NAMED_GENERIC_UNIT 2 Footpad 26 11 () (_"Criminal")} {VILLAGE_USERS}
        {NAMED_GENERIC_UNIT 2 Thief 18 14 () (_"Criminal")} {VILLAGE_USERS} {GUARDIAN}
#endif
    [/side]

    {STARTING_VILLAGES 2 20}

    [event]
        name=turn 4

        # Now is the time that the recruited units may have met Deoran's,
        # and may have the chance to recapture a village.
        [modify_side]
            side=2
            [ai]
                village_value=3
            [/ai]
        [/modify_side]
        {MODIFY_AI_ADD_CANDIDATE_ACTION 2 main_loop {AI_CA_VILLAGES}}
    [/event]

    [event]
        name=prestart

        # Modify the size of the keep of the enemy on 'simple' and 'easy' difficulties.
#ifdef NORMAL
        {MODIFY_TERRAIN Ce 17 26}
#endif
#ifdef HARD
        {MODIFY_TERRAIN Ce 17 26}
        {MODIFY_TERRAIN Ce 19 25}
#endif

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

        [store_unit]
            [filter]
                side=2
                canrecruit=no
                gender=female
            [/filter]
            variable=namechange
        [/store_unit]

        [foreach]
            array=namechange
            [do]
                {VARIABLE this_item.name _"female^Criminal"}
                [unstore_unit]
                    variable=this_item
                    find_vacant=no
                [/unstore_unit]
            [/do]
        [/foreach]
        {CLEAR_VARIABLE namechange}
    [/event]

    [event]
        name=start

        [recall]
            id=Sir Gerrick
        [/recall]

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

        [message]
            speaker=Deoran
            message= _ "Look there! Smoke rises from Westin! The bandits must have already overrun the garrison and are sacking the city!"
        [/message]
        [message]
            speaker=Sir Gerrick
            message= _ "Then we must make haste before they leave the city in ruins and slaughter all who live therein."
        [/message]

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

        [message]
            speaker=Urza Nalmath
            message= _ "What?! Those soldiers come from the northern forts... this can only mean my brother Mathin is dead. Those fiends! They will pay for his death!"
        [/message]

        [objectives]
            side=1
            [objective]
                [show_if]
                    [variable]
                        name=citadel_secured
                        boolean_not_equals=yes
                    [/variable]
                [/show_if]
                description= _ "Bring Deoran to the Citadel of Westin"
                condition=win
            [/objective]
            [objective]
                [show_if]
                    [have_unit]
                        id=Minister Hylas
                    [/have_unit]
                [/show_if]
                description= _ "Defeat 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]
                [show_if]
                    [have_unit]
                        id=Minister Hylas
                    [/have_unit]
                [/show_if]
                description= _ "Death of Minister Hylas"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

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

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

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

        # Check if it is Deoran. If not, tell him to go to Westin.
        [if]
            [have_unit]
                x,y=22,13
                [not]
                    id=Deoran
                [/not]
            [/have_unit]
            [then]
                [message]
                    speaker=unit
                    message= _ "I have reached the citadel!"
                [/message]
                [message]
                    speaker=Sir Gerrick
                    message= _ "Excellent, but the battle is not won yet, and there is still no sign of Sir Loris. Sir Deoran, you should secure the keep."
                [/message]
                [show_objectives][/show_objectives]
            [/then]
        [/if]
    [/event]

    # Deoran arrives at the citadel.

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

        {VARIABLE citadel_secured "yes"}

        [modify_turns]
            {QUANTITY add 17 16 15}
        [/modify_turns]

        [remove_item]
            x,y=22,13
        [/remove_item]

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

        [message]
            speaker=Deoran
            image=portraits/deoran-mad.png
            message= _ "More bandits?! Prepare to die!"
        [/message]
        [message]
            speaker=Minister Hylas
            message= _ "Peace, I am a friend! I am Hylas, advisor to Sir Loris and Chief Minister of the town council. Thanks to your timely arrival, the city is saved!"
        [/message]
        [message]
            speaker=Deoran
            message= _ "Indeed, we have defeated most of the bandits in the city. But where is Sir Loris? And where is the city garrison?"
        [/message]
        [message]
            speaker=Minister Hylas
            message= _ "Alas, Sir Loris fell in battle several days ago. For weeks, we warned him of the new power of these bandits, yet he would never lead his men against them until their strength had become too great for us to handle. I sent a messenger to the king about our plight, but some misfortune must have befallen him, for you are the first reinforcements to arrive here. If only Sir Loris had sent a rider earlier, he might have survived long enough to stand with us here."
        [/message]

        [message]
            speaker=Deoran
            image=portraits/deoran-sad.png
            message= _ "Indeed. Foolish though he may have been, it still grieves me to learn of his death. With him gone, it seems that I must lead the townsfolk against the bandits and drive them from our city."
        [/message]

#ifdef EASY
        {NAMED_LOYAL_UNIT 1 Spearman 18 12 (Ufes) (_"Ufes")}
        {NAMED_LOYAL_UNIT 1 Bowman 18 13 (Joran) (_"Joran")}
        {NAMED_LOYAL_UNIT 1 Peasant 19 15 (Makees) (_"Makees")}
        {NAMED_LOYAL_UNIT 1 Peasant 20 15 (Tyborg) (_"Tyborg")}
#endif
#ifdef NORMAL
        {NAMED_LOYAL_UNIT 1 Spearman 18 12 (Ufes) (_"Ufes")}
        {NAMED_LOYAL_UNIT 1 Peasant 18 13 (Joran) (_"Joran")}
        {NAMED_LOYAL_UNIT 1 Peasant 19 15 (Makees) (_"Makees")}
        {NAMED_LOYAL_UNIT 1 Peasant 20 15 (Tyborg) (_"Tyborg")}
#endif
#ifdef HARD
        {NAMED_LOYAL_UNIT 1 Peasant 18 12 (Ufes) (_"Ufes")}
        {NAMED_LOYAL_UNIT 1 Peasant 18 13 (Joran) (_"Joran")}
        {NAMED_LOYAL_UNIT 1 Peasant 19 15 (Makees) (_"Makees")}
        {NAMED_LOYAL_UNIT 1 Peasant 20 15 (Tyborg) (_"Tyborg")}
#endif

        [message]
            speaker=Ufes
            message= _ "We stand with you, Sir Deoran! We will hold the city while you lead your men across the river and defeat the bandit leader!"
        [/message]

        [show_objectives][/show_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]
                {QUANTITY recruitment_pattern (fighter)
                (fighter,fighter,scout,fighter)
                (fighter,archer,fighter,archer,scout)}
            [/ai]
        [/modify_side]

        [gold]
            side=2
            {QUANTITY amount 40 50 60}
        [/gold]
    [/event]

    # Deoran is too late.

    [event]
        name=turn 6
        [if]
            [variable]
                name=citadel_secured
                boolean_not_equals="yes"
            [/variable]
            [then]
                [message]
                    speaker=Sir Gerrick
                    message= _ "They are almost to the great hall! Hurry, Deoran! We must reach the citadel before it is stormed by the bandits!"
                [/message]

#ifdef EASY
                {HIGHLIGHT_IMAGE 22 13 items/gohere.png ()}

                [message]
                    speaker=narrator
                    {TUTOR: _"You must move someone 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=side 1 turn 7 end
        [if]
            [variable]
                name=citadel_secured
                boolean_not_equals="yes"
            [/variable]
            [then]
                [message]
                    speaker=Sir Gerrick
                    message= _ "We’re too late! They have burned the whole city..."
                [/message]
                [message]
                    speaker=Deoran
                    image=portraits/deoran-sad.png
                    message= _ "Alas, Westin has fallen! There is nothing else I can do here — I can only return to the King and report our loss here..."
                [/message]

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

    # you can get some merfolk reinforcements if you go on the village here
    # it will replay the event from the first scenario if you didn't get them there

    [event]
        name=moveto
        [filter]
            side=1
            x,y=14,20
        [/filter]

        [if]
            [variable]
                name=has_merfolk
                equals="yes"
            [/variable]
            [then]
                [unit]
                    side=1
                    type=Merman Fighter
                    id=Absu
                    name= _ "Absu"
                    [modifications]
                        {TRAIT_LOYAL}
                        {TRAIT_STRONG}
                    [/modifications]
                    x,y=14,21
                    {IS_LOYAL}
                [/unit]

                [message]
                    speaker=Absu
                    message= _ "The red and white banners of the South Guard! This is a welcome change from the bandits who have been trying to ransack my home."
                [/message]
                [message]
                    speaker=Deoran
                    message= _ "Indeed, we have come to drive off these vile brigands. Would you like to join us in our battle to restore peace to Westin?"
                [/message]
                [message]
                    speaker=Absu
                    message= _ "It would be an honor to fight alongside you, Sir Knight."
                [/message]
            [/then]
            [else]
                [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=14,21
                    {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=15,21
                    {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"}
            [/else]
        [/if]
    [/event]

    # The undead attack!

    [event]
        name=prerecruit

        [filter]
            side=2
            race=undead
        [/filter]

        [message]
            speaker=Urza Nalmath
            message= _ "Now, the South Guard will feel the wrath of my new allies! Rise again, my undead warriors!"
        [/message]

        [event]
            name=side turn

            [scroll_to_unit]
                race=undead
            [/scroll_to_unit]

            [message]
                speaker=Sir Gerrick
                message= _ "What devilry is this?! Those are no living men that fight for him!"
                scroll=no
            [/message]
            [message]
                speaker=Minister Hylas
                message= _ "This development is troubling to me as well. He must have made some pact with the undead, but how could a mere brigand gain such powers?"
                scroll=no
            [/message]
            [message]
                speaker=Deoran
                message= _ "It matters not. No matter how he has done this fell thing, we must defeat him!"
                scroll=no
            [/message]

#ifdef EASY
            [message]
                speaker=narrator
                image="units/human-magi/white-mage-magic-1.png~RC(magenta>red)"
                {TUTOR: _"Minister Hylas can heal allied units near him and his <i>arcane</i> attack deals bonus damage to undead foes."}
                scroll=no
            [/message]
#endif
        [/event]
    [/event]

    # Pillaging and burning the villages near Westin.

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

        [message]
            speaker=Urza Nalmath
            message= _ "Leave nothing standing! Raze their villages 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 homes! We must stop them!"
        [/message]
    [/event]

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

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

        {VARIABLE_OP random_string value "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}
        {CLEAR_VARIABLE random,random_string}

        {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! I have failed!"
        [/message]

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

        [message]
            speaker=Deoran
            message= _ "The bandits are scattering! We have saved Westin!"
        [/message]

        [message]
            speaker=Sir Gerrick
            message= _ "Indeed. Still, this victory is troubling. How can a mere outlaw have summoned undead?"
        [/message]

        [fire_event]
            name=victory dance
        [/fire_event]
    [/event]

    [event]
        name=time over

        [unit]
            type=Death Knight
            side=2
            id=Ixlathal
            name= _ "Ixlathal"
            animate=yes
            x,y=18,24
        [/unit]

        [message]
            speaker=Ixlathal
            message= _ "The master sends his regards. The command is to raze the city."
        [/message]
        [message]
            speaker=Urza Nalmath
            message= _ "I am trying, but their resistance is strong..."
        [/message]
        [message]
            speaker=Ixlathal
            message= _ "Then step aside, living one. I will make use of the fresh corpses from this battle."
        [/message]

        [animate_unit]
            [filter]
                id=Ixlathal
            [/filter]
            flag=leading
        [/animate_unit]
        [delay]
            time=500
        [/delay]
        [animate_unit]
            [filter]
                id=Ixlathal
            [/filter]
            flag=leading
        [/animate_unit]
        [delay]
            time=500
        [/delay]
        [animate_unit]
            [filter]
                id=Ixlathal
            [/filter]
            flag=leading
        [/animate_unit]

        [unit]
            type=Walking Corpse
            side=2
            animate=no
            x,y=19,13
        [/unit]
        [unit]
            type=Skeleton
            side=2
            animate=yes
            x,y=19,14
        [/unit]
        [unit]
            type=Skeleton
            side=2
            animate=yes
            x,y=21,16
        [/unit]
        [unit]
            type=Walking Corpse
            side=2
            animate=no
            x,y=19,16
        [/unit]
        [unit]
            type=Walking Corpse
            side=2
            animate=no
            x,y=17,14
        [/unit]
        [unit]
            type=Walking Corpse
            side=2
            animate=no
            x,y=16,21
        [/unit]
        [unit]
            type=Walking Corpse
            side=2
            animate=no
            x,y=16,19
        [/unit]
        [unit]
            type=Walking Corpse
            side=2
            animate=no
            x,y=18,19
        [/unit]
        [unit]
            type=Deathblade
            side=2
            animate=yes
            x,y=15,21
        [/unit]
        [unit]
            type=Revenant
            side=2
            animate=yes
            x,y=21,22
        [/unit]

        [message]
            speaker=Deoran
            message= _ "More undead! Alas, we cannot hold against a force so great. We will have to abandon Westin and let them sack the city..."
        [/message]
    [/event]

    [event]
        name=victory dance

        [message]
            speaker=Minister Hylas
            message= _ "I do not know, but just before the bandit raids began, an ambassador came to Sir Loris from the elves of the Aethenwood. 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. I believe that they may 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 as unnatural as these by ourselves. It is probably best that I meet the elves in hope that their counsel will be of some aid."
        [/message]

        [message]
            speaker=Minister Hylas
            message= _ "I will accompany you, Sir Deoran. I have studied sacred arts and my skills may be of some use against the dark ones."
        [/message]

        [message]
            speaker=Deoran
            message= _ "Very well. Although it will probably take too long to send word to the King for reinforcements, I remember there being a small outpost within a couple days’ ride of here. I will send a message to them asking for a few riders, then we should make haste toward the Aethenwood to find the elves."
        [/message]

        {CLEAR_VARIABLE citadel_secured,has_merfolk}

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

    [event]
        name=victory

        [disallow_recruit]
            type=Peasant
            side=1
        [/disallow_recruit]
    [/event]
[/scenario]

#undef VILLAGE_USERS
