#textdomain wesnoth-tb
[terrain_type]
    #impassable custom magic gate
    symbol_image=../scenery/gate-rusty-se
    id=magic_irongate
    name= _ "Irongate"
    string=Xzga
    aliasof=Xu
[/terrain_type]

{TERRAIN_BASE Xzga flat/road}

[scenario]
    #textdomain wesnoth-tb
    id=03_Guarded_Castle
    name= _ "Guarded Castle"
    map_data="{campaigns/Two_Brothers/maps/03_Guarded_Castle.map}"
#ifdef EASY
    turns=30
#endif
#ifdef HARD
    turns=24
#endif
    next_scenario=04_Return_to_the_Village
    victory_when_enemies_defeated=no

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

    # Place animated brazier in the library
    {ANIMATED_BRAZIER 2 10}

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

    [story]
        [part]
            show_title=yes
            {TO_GUARDED_CASTLE}
        [/part]
        # Diary entries split into two parts until story screens allow vertical scrolling (FR #17492).
        [part]
            # wmllint: local spelling clanless
            story=_"19 IV, 363 YW
Excerpt from the journal of Rotharik the Clanless

The last of Mordak’s servants arrived this morning bearing the news of his death, as well as a bundle so well-bound it was barely recognizable as a man. Mordak was always reckless. This whole desperate scheme was his, and I suppose I could blame him for everything that we have suffered through if it still mattered. It was he who brought the wrath of the orcs down on us, too. But all the same, he managed to accomplish what he set out to do. I still cannot believe the finality of what has happened; until now we had always managed to make it through somehow.

We had hoped to deliver the mage to Tairach in return for our lives. I do not know what the warlord wants with this man, but he matches the description. I suppose that Mordak’s plan would have worked perfectly if not for the appearance of the horse warriors. Now they are coming here, led by a man rumored to be this mage’s brother. If that is true, he will stop at nothing, no more than would I if they held Mordak."
        [/part]
        [part]
            story=_ "19 IV, 363 YW
Excerpt from the journal of Rotharik the Clanless

I have done what I can to fortify this dilapidated castle. The orcs who came with us stand guard at the gates, and I am gathering all of my servants to me in the inner sanctum. But ill fate awaits. Whether I defeat this horse-warrior or no, the orcs will still come for me; they have been scouring the borderlands and raiding the northern farm country in search of us.

Yet for some reason I fear these brothers more. If Mordak were here it would be different, but we are broken... and these two men are whole. In each other, in the ties that bind them, they have strength."
        [/part]
    [/story]

    [side]
#ifdef EASY
        gold=170
#endif
#ifdef HARD
        gold=120
#endif
        type=Knight
        id=Arvith
        name= _ "Arvith"
        unrenamable=yes
        profile="portraits/arvith.png~RIGHT()"
        fog=no
        side=1
        canrecruit=yes
        controller=human
        recruit=Horseman,Bowman,Spearman,Footpad
        team_name=good
        user_team_name=_"Humans"
        shroud=yes
    [/side]

    [side]
#ifdef EASY
        gold=40
#endif
#ifdef HARD
        gold=60
#endif
        type=Dark Sorcerer
        id=Rotharik
        name= _ "Rotharik"
        unrenamable=yes
        experience=0
        side=2
        controller=ai
        canrecruit=yes
#ifdef HARD
        recruit=Skeleton,Skeleton Archer,Vampire Bat,Ghost,Dark Adept,Ghoul,Walking Corpse
#else
        recruit=Skeleton,Skeleton Archer,Vampire Bat,Dark Adept,Ghoul,Walking Corpse
#endif
#ifdef EASY
        income=7
#endif
#ifdef HARD
        income=13
#endif
        team_name=evil
        user_team_name=_"Enemies"
        [unit]
            side=2
            id=Guard_leader
            name= _ "Guard"
            type=Assassin
            x=28
            y=26
        [/unit]
        [unit]
            side=2
            role=Guard
            name= _ "Guard"
            type=Bandit
            x=30
            y=25
        [/unit]
#ifdef HARD
        [unit]
            side=2
            role=Guard
            name= _ "Guard"
            type=Bandit
            x=28
            y=24
        [/unit]
        [unit]
            side=2
            role=Guard
            name= _ "Guard"
            type=Bandit
            x=27
            y=28
        [/unit]
#endif
    [/side]

    [side]
        no_leader=yes
        side=3
        team_name=evil
        user_team_name=_"Enemies"

        #Orcish guards
        [unit]
            side=3
            id=Knago-Brek
            name= _ "Knago-Brek"
            type=Orcish Warrior
            unrenamable=yes
            x=19
            y=17
            ai_special=guardian
        [/unit]
        [unit]
            side=3
            name= _ "Castle Guard"
            type=Orcish Grunt
            x=18
            y=16
            ai_special=guardian
        [/unit]
        [unit]
            side=3
            name= _ "Castle Guard"
            type=Orcish Grunt
            x=20
            y=16
            ai_special=guardian
        [/unit]
#ifdef HARD
        [unit]
            side=3
            name= _ "Castle Guard"
            type=Orcish Warrior
            x=15
            y=17
            ai_special=guardian
        [/unit]
        [unit]
            side=3
            name= _ "Castle Guard"
            type=Orcish Warrior
            x=23
            y=17
            ai_special=guardian
        [/unit]
#endif
    [/side]

    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description= _ "Rescue Baran"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Arvith"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

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

        {VARIABLE Got_Key 0}
        {VARIABLE Trigger_Guards1 0}

        #placing prison gates
        [terrain]
            x=5
            y=5
            terrain=Xzga    # wmllint: ignore
        [/terrain]
        {PLACE_IMAGE scenery/gate-rusty-se.png 5 5}
        [terrain]
            x=6
            y=10
            terrain=Xzga    # wmllint: ignore
        [/terrain]
        {PLACE_IMAGE scenery/gate-rusty-sw.png 6 10}
        #       [terrain]
        #           x=7
        #           y=7
        #           terrain=Xzga
        #       [/terrain]
        #       {PLACE_IMAGE scenery/gate-rusty-se.png 5 5}

        #making it more like a real prison
        {PLACE_IMAGE items/bones.png 5 12}
        {PLACE_IMAGE items/bones.png 9 6}
        {PLACE_IMAGE items/bones.png 2 6}
        {PLACE_IMAGE items/bones.png 9 3}

        # random evil-overlord furniture
        {PLACE_IMAGE "items/dragonstatue.png" 12 2}
        {PLACE_IMAGE "items/dragonstatue.png~FL(horiz)" 26 2}

        # The library
        #{PLACE_IMAGE items/book3.png 2 9}
        #{PLACE_IMAGE items/book4.png 3 9}

        #treasure pile
        {PLACE_IMAGE items/chest-plain-closed.png 34 4}
        #{PLACE_IMAGE items/ball-blue.png 34 5}
        #{PLACE_IMAGE items/ball-green.png 33 4}
        #{PLACE_IMAGE items/ball-magenta.png 35 4}

        #evil altar
        {PLACE_IMAGE items/altar-evil.png 29 3}
        {PLACE_IMAGE items/brazier.png 28 2}
        {PLACE_IMAGE items/brazier.png 30 2}
        {PLACE_IMAGE scenery/rune5.png 30 3}
        {PLACE_IMAGE scenery/rune6.png 28 3}

        # The armory
        #{PLACE_IMAGE items/brazier.png 10 10}
        #{PLACE_IMAGE items/brazier.png 12 11}
        #{PLACE_IMAGE items/axe.png 11 10}
        #{PLACE_IMAGE items/spear-fancy.png 10 11}
        #{PLACE_IMAGE items/buckler.png 10 11}
        #{PLACE_IMAGE items/buckler.png 11 11}
        #{PLACE_IMAGE "items/axe.png~FL(horiz)" 11 12}
        #{PLACE_IMAGE "items/bow.png~FL(horiz)" 10 12}
        #{PLACE_IMAGE items/bow-elven.png 12 10}
        #{PLACE_IMAGE "items/bow-crystal.png~FL(horiz)" 12 10}

        # The supply room
        {PLACE_IMAGE items/brazier.png 26 11}
        {PLACE_IMAGE items/brazier.png 28 10}
        #{PLACE_IMAGE items/barrel.png 28 11}
        #{PLACE_IMAGE items/chest.png 28 12}
        #{PLACE_IMAGE items/box.png 27 12}
        #{PLACE_IMAGE items/box.png 27 11}
        #{PLACE_IMAGE items/potion-green.png 26 10}
    [/event]

    [event]
        name=start
#ifdef EASY
        [recall]
            id=Brena
        [/recall]
#endif

        [message]
            speaker=narrator
            image="wesnoth-icon.png"
            message= _ "Arvith and his men halt outside of the castle, gazing for a moment at the hulking mass of stone looming in the fog. There is movement in the mist."
        [/message]
        [message]
            speaker=Guard_leader
            message= _ "Halt! Friend or foe? Give the password."
        [/message]

        [message]
            speaker=Arvith
            message= _ "The password is"
            [option]
                message= _ "$first_password_1|!"
                [command]
                    {VARIABLE first_password_picked "$first_password_1"}
                [/command]
            [/option]
            [option]
                message= _ "$first_password_2|!"
                [command]
                    {VARIABLE first_password_picked "$first_password_2"}
                [/command]
            [/option]
            [option]
                message= _ "$first_password_3|!"
                [command]
                    {VARIABLE first_password_picked "$first_password_3"}
                [/command]
            [/option]
            [option]
                message= _ "$first_password_4|!"
                [command]
                    {VARIABLE first_password_picked "$first_password_4"}
                [/command]
            [/option]
        [/message]

        [if]
            [variable]
                name=first_password_picked
                equals=$first_password_$first_password_number
            [/variable]

            [then]
                [message]
                    speaker=Guard_leader
                    message= _ "Pass, friend."
                [/message]
                [kill]
                    role=Guard
                [/kill]
                [kill]
                    id=Guard_leader
                [/kill]
                [remove_shroud]
                    side=1
                    x=0-38
                    y=20-32
                [/remove_shroud]
                [message]
                    speaker=Arvith
                    message= _ "The adept didn’t lead us astray after all. I’ll keep my word, distasteful as it may be; cut him loose, and let’s be rid of him."
                [/message]
                # Perhaps the Adept is so grateful for Arvith's mercy that he
                # offers to stay with the player's force. In this case the
                # player could choose to keep him as a loyal unit but lose
                # some other loyal unit who leaves in disgust, or dismiss him.
            [/then]

            [else]
                [message]
                    speaker=Guard_leader
                    message= _ "Wrong! Die!"
                [/message]
                {VARIABLE Trigger_Guards1 1}
            [/else]
        [/if]
    [/event]

    [event]
        name=sighted
        [filter]
            side=3
        [/filter]
        [message]
            speaker=Knago-Brek
            message= _ "Haha! We not kill people for long time. Weapon wants blood. We now kill humans!!"
        [/message]
        [message]
            speaker=Arvith
            message= _ "My sword-arm has a say in who will do the dying. Come on, men, let’s kill some orcs."
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id=Knago-Brek
        [/filter]
        [message]
            speaker=Arvith
            message= _ "One less braggart orc in the world."
        [/message]
        [message]
            side=1
            [not]
                # wmllint: recognize Baran
                id=Arvith,Baran
            [/not]
            message= _ "Captain, what are <i>orcs</i> doing this far south?"
        [/message]
        [message]
            speaker=Arvith
            message= _ "Good question. Perhaps my brother will have found out."
        [/message]
    [/event]

    # Trigger 2nd guards at turn3 only if you did not attack the first
    # ones in turn 1, if they are attacked in turn 1, trigger this
    # event in turn 6
    [event]
        name=turn 3
        [if]
            [variable]
                name=Trigger_Guards1
                numerical_equals=0
            [/variable]
            [then]
                [unit]
                    side=2
                    id=Guard2_leader
                    name= _ "Guard"
                    type=Rogue
                    x=16
                    y=24
                [/unit]
                [unit]
                    side=2
                    role=Guard2
                    name= _ "Guard"
                    type=Bandit
                    x=17
                    y=24
                [/unit]
                [unit]
                    side=2
                    role=Guard2
                    name= _ "Guard"
                    type=Bandit
                    x=16
                    y=24
                [/unit]
#ifdef HARD
                [unit]
                    side=2
                    role=Guard2
                    name= _ "Guard"
                    type=Bandit
                    x=17
                    y=23
                [/unit]
#endif
                [message]
                    speaker=Guard2_leader
                    message= _ "Are you our relief arriving? Does this mean we get to leave here now?"
                [/message]
                [message]
                    speaker=Arvith
                    message= _ "Um, yes. Fine. You can go."
                [/message]
                [message]
                    speaker=Guard2_leader
                    message= _ "Um, you’re supposed to give the password."
                [/message]
                [message]
                    speaker=Arvith
                    message= _ "Oh, of course. I had nearly forgotten."
                    [option]
                        message= _ "$second_password_1|!"
                        [command]
                            {VARIABLE second_password_picked "$second_password_1"}
                        [/command]
                    [/option]
                    [option]
                        message= _ "$second_password_2|!"
                        [command]
                            {VARIABLE second_password_picked "$second_password_2"}
                        [/command]
                    [/option]
                    [option]
                        message= _ "$second_password_3|!"
                        [command]
                            {VARIABLE second_password_picked "$second_password_3"}
                        [/command]
                    [/option]
                    [option]
                        message= _ "$second_password_4|!"
                        [command]
                            {VARIABLE second_password_picked "$second_password_4"}
                        [/command]
                    [/option]
                [/message]
                [if]
                    [variable]
                        name=second_password_picked
                        equals=$second_password_$second_password_number
                    [/variable]

                    [then]
                        [message]
                            speaker=Guard2_leader
                            message= _ "Thanks! Irritating little formality, isn’t it?"
                        [/message]
                        [kill]
                            role=Guard2
                        [/kill]
                        [kill]
                            id=Guard2_leader
                        [/kill]
                    [/then]

                    [else]
                        [message]
                            speaker=Guard2_leader
                            message= _ "That’s the wrong password! These aren’t our relief! Get them!"
                        [/message]
                    [/else]
                [/if]
                [message]
                    speaker=Arvith
                    message= _ "I think I should better support my men at the front to make sure we can free my brother."
                [/message]
            [/then]
        [/if]
    [/event]

    [event]
        name=turn 6
        [if]
            [variable]
                name=Trigger_Guards1
                numerical_equals=1
            [/variable]
            [then]
                [unit]
                    side=2
                    id=Guard2_leader
                    name= _ "Guard"
                    type=Rogue
                    x=16
                    y=24
                [/unit]
                [unit]
                    side=2
                    role=Guard2
                    name= _ "Guard"
                    type=Bandit
                    x=17
                    y=24
                [/unit]
                [unit]
                    side=2
                    role=Guard2
                    name= _ "Guard"
                    type=Bandit
                    x=16
                    y=24
                [/unit]
#ifdef HARD
                [unit]
                    side=2
                    role=Guard2
                    name= _ "Guard"
                    type=Bandit
                    x=17
                    y=23
                [/unit]
#endif
                [message]
                    speaker=Guard2_leader
                    message= _ "Are you our relief arriving? Does this mean we get to leave here now?"
                [/message]
                [message]
                    speaker=Arvith
                    message= _ "Um, yes. Fine. You can go."
                [/message]
                [message]
                    speaker=Guard2_leader
                    message= _ "Um, you’re supposed to give the password."
                [/message]
                [message]
                    speaker=Arvith
                    message= _ "Oh, of course. I had nearly forgotten."
                    [option]
                        message= _ "$second_password_1|!"
                        [command]
                            {VARIABLE second_password_picked "$second_password_1"}
                        [/command]
                    [/option]
                    [option]
                        message= _ "$second_password_2|!"
                        [command]
                            {VARIABLE second_password_picked "$second_password_2"}
                        [/command]
                    [/option]
                    [option]
                        message= _ "$second_password_3|!"
                        [command]
                            {VARIABLE second_password_picked "$second_password_3"}
                        [/command]
                    [/option]
                    [option]
                        message= _ "$second_password_4|!"
                        [command]
                            {VARIABLE second_password_picked "$second_password_4"}
                        [/command]
                    [/option]
                [/message]
                [if]
                    [variable]
                        name=second_password_picked
                        equals=$second_password_$second_password_number
                    [/variable]

                    [then]
                        [message]
                            speaker=Guard2_leader
                            message= _ "Thanks! Irritating little formality, isn’t it?"
                        [/message]
                        [kill]
                            role=Guard2
                        [/kill]
                        [kill]
                            id=Guard2_leader
                        [/kill]
                    [/then]

                    [else]
                        [message]
                            speaker=Guard2_leader
                            message= _ "That’s the wrong password! These aren’t our relief! Get them!"
                        [/message]
                    [/else]
                [/if]
                [message]
                    speaker=Arvith
                    message= _ "I think I should better support my men at the front to make sure we can free my brother."
                [/message]
            [/then]
        [/if]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Rotharik
        [/filter]
        [message]
            speaker=unit
            message= _ "Your hand or Tairach’s, death is still death... (argh)"
        [/message]
        [kill]
            id=Rotharik
            animate=yes
        [/kill]
        [message]
            speaker=Arvith
            message= _ "‘Tairach’? Who or what is Tairach?"
        [/message]
        [message]
            speaker=second_unit
            message= _ "There’s a key in his robes."
        [/message]
        [message]
            speaker=Arvith
            message= _ "That may well be the key to the cell they’re holding Baran in! I will take it."
        [/message]
        {VARIABLE Got_Key 1}
        [objectives]
            side=1
            [objective]
                description= _ "Move Arvith to the cell with his brother to free him"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Arvith"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

            [gold_carryover]
                bonus=yes
                carryover_percentage=40
            [/gold_carryover]
        [/objectives]
        [modify_turns]
            add=6
        [/modify_turns]
    [/event]

    [event]
        name=moveto
        [filter]
            x=34
            y=4
            side=1
        [/filter]
#ifdef EASY
        [sound]
            name=gold.ogg
        [/sound]
        [message]
            speaker=unit
            message= _ "Look what I have found in here! I can count a hundred pieces of gold."
        [/message]
        [gold]
            side=1
            amount=100
        [/gold]
#endif
#ifdef HARD
        [sound]
            name=gold.ogg
        [/sound]
        [message]
            speaker=unit
            message= _ "Look what I have found in here! I can count fifty pieces of gold."
        [/message]
        [gold]
            side=1
            amount=50
        [/gold]
#endif
        {REMOVE_IMAGE 34 4}
        {PLACE_IMAGE items/chest-plain-open.png 34 4}
    [/event]

    [event]
        name=moveto
        [filter]
            x=1-8
            y=1-11
            side=1
        [/filter]
        [unit]
            side=1
            id=Baran
            name= _ "Baran"
            unrenamable=yes
            type=Red Mage
            profile=portraits/baran.png
            {IS_HERO}
            x=3
            y=3
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]
        [remove_shroud]
            x=1-8,9-10,5
            y=1-12,1-7,13
            side=1
        [/remove_shroud]
    [/event]

    [event]
        name=moveto
        [filter]
            x=4-8,7,8
            y=5-8,4,4
            side=1
        [/filter]
        [message]
            speaker=unit
            message= _"I found Baran. He is in this cell."
        [/message]
        [if]
            [variable]
                name=unit.id
                equals="Arvith"
            [/variable]
            [then]
                [message]
                    speaker=Baran
                    message= _ "It’s good to see you, Arvith."
                [/message]
                [message]
                    speaker=Arvith
                    message= _ "And you too, brother."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Baran
                    message= _ "You must be one of Arvith’s men. Please help me get out of this dungeon."
                [/message]
            [/else]
        [/if]
        [message]
            speaker=Baran
            message= _ "The accursed dark sorcerer Rotharik has imprisoned me behind this magically enhanced iron gate. It can only be opened with the correct key. You must get it from him to free me."
        [/message]
        [if]
            [variable]
                name=Got_Key
                numerical_equals=0
            [/variable]
            [then]
                [objectives]
                    side=1
                    [objective]
                        description= _ "Kill the dark sorcerer to get the cell key"
                        condition=win
                    [/objective]
                    [objective]
                        description= _ "Death of Arvith"
                        condition=lose
                    [/objective]

                    {TURNS_RUN_OUT}

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

    [event]
        name=moveto
        first_time_only=no
        [filter]
            x=5,6
            y=6,5
            id=Arvith
        [/filter]
        [if]
            [variable]
                name=Got_Key
                numerical_equals=1
            [/variable]
            [then]
                {INCIDENTAL_MUSIC breaking_the_chains.ogg}
                [terrain]
                    x=5
                    y=5
                    terrain=Rr
                [/terrain]
                [message]
                    speaker=Baran
                    message= _ "Thank you for saving me. I... was not certain you would come."
                [/message]
                [message]
                    speaker=Arvith
                    message= _ "Have you no faith in your brother, Baran?"
                [/message]
                [message]
                    speaker=Baran
                    message= _ "It’s not that. Perhaps I deserved to rot here. I failed you. I failed you again."
                [/message]
                [message]
                    speaker=Arvith
                    message= _ "That is as may be. But you are my brother still. And... I never doubted you would have come for me."
                [/message]
                [message]
                    speaker=Arvith
                    message= _ "It was no great trial, after all. A few elves, one or two dark sorcerers, a gang of orcs and some undead. Really just a day’s work for the company."
                [/message]
                [message]
                    speaker=Baran
                    message= _ "Thank you for coming to my aid. Let us return to the village."
                [/message]
                [endlevel]
                    result=victory
                    bonus=yes
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/then]
            [else]
                [allow_undo][/allow_undo]
            [/else]
        [/if]
    [/event]

    [event]
        name=victory
        {CLEAR_VARIABLE Got_Key}
    [/event]

    [event]
        name=last breath
        [filter]
            id=Arvith
        [/filter]
        [message]
            speaker=Arvith
            message= _ "Everything is lost now that I am dead..."
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=time over
        [message]
            # wmllint: local spelling Muahahaha
            speaker=Rotharik
            message= _ "You are too late! Your brother is already dead! Muahahaha...!"
        [/message]
        [message]
            speaker=Arvith
            message= _ "Argh!!"
        [/message]
    [/event]
[/scenario]
