#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=3_Guarded_Castle
    name= _ "Guarded Castle"
    map_data="{campaigns/Two_Brothers/maps/3_Guarded_Castle.map}"
#ifdef EASY
    turns=30
#endif
#ifdef HARD
    turns=24
#endif
    next_scenario=4_Return_To_The_Village
    victory_when_enemies_defeated=no

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

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

    [story]
        [part]
            show_title=yes
            {TO_GUARDED_CASTLE}
        [/part]
    [/story]

    [side]
#ifdef EASY
        gold=170
#endif
#ifdef HARD
        gold=120
#endif
        type=Knight
        id=Arne
        name= _ "Arne"
        unrenamable=yes
        profile="portraits/humans/knight.png"
        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 Bjarn"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Arne"
                condition=lose
            [/objective]
            [objective]
                description= _ "Turns run out"
                condition=lose
            [/objective]

            note={EARLY_FINISH_BONUS_NOTE}+{NEW_GOLD_CARRYOVER_NOTE_40}
        [/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}
        {ITM_GLOWING_BRAZIER 2 10}

        #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= _ "Arne's men arrived at the castle and were immediately challenged by some guards."
        [/message]
        [message]
            speaker=Guard_leader
            message= _ "Halt! Friend or foe? Give the password."
        [/message]

        [message]
            speaker=Arne
            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]
            [/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=Arne
            message= _ "My sword-arm has a say in who will do the dying. Come on, men, let's kill some orcs."
        [/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, triger 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=Arne
                    message= _ "Um, yes. Fine. You can go."
                [/message]
                [message]
                    speaker=Guard2_leader
                    message= _ "Um, you're supposed to give the password."
                [/message]
                [message]
                    speaker=Arne
                    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=Arne
                    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=Arne
                    message= _ "Um, yes. Fine. You can go."
                [/message]
                [message]
                    speaker=Guard2_leader
                    message= _ "Um, you're supposed to give the password."
                [/message]
                [message]
                    speaker=Arne
                    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=Arne
                    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= _ "Nooo! This is the end..."
        [/message]
        [kill]
            id=Rotharik
            animate=yes
        [/kill]
        [message]
            speaker=second_unit
            message= _ "There's a key in his robes."
        [/message]
        [message]
            speaker=Arne
            message= _ "That may well be the key to the cell they're holding Bjarn in! I will take it."
        [/message]
        {VARIABLE Got_Key 1}
        [objectives]
            side=1
            [objective]
                description= _ "Move Arne to the cell with his brother to free him"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Arne"
                condition=lose
            [/objective]
            [objective]
                description= _ "Turns run out"
                condition=lose
            [/objective]

            note={EARLY_FINISH_BONUS_NOTE}+{NEW_GOLD_CARRYOVER_NOTE_40}
        [/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=Bjarn
            name= _ "Bjarn"
            unrenamable=yes
            type=Red Mage
            profile="portraits/humans/mage-red.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
        [/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 Bjarn. He is in this cell."
        [/message]
        [if]
            [variable]
                name=unit.id
                equals="Arne"
            [/variable]
            [then]
                [message]
                    speaker=Bjarn
                    message= _ "Good to see you, Arne. Now can you get me out of this dungeon, please?"
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Bjarn
                    message= _ "You must be one of Arne's men. Please help me get out of this dungeon."
                [/message]
            [/else]
        [/if]
        [message]
            speaker=Bjarn
            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 Arne"
                        condition=lose
                    [/objective]
                    [objective]
                        description= _ "Turns run out"
                        condition=lose
                    [/objective]

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

    [event]
        name=moveto
        first_time_only=no
        [filter]
            x=5,6
            y=6,5
            id=Arne
        [/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=Bjarn
                    message= _ "Thank you for saving me. I had almost given up hope you would free me."
                [/message]
                [message]
                    speaker=Arne
                    message= _ "Oh it was nothing, a few elves, one or two dark sorcerers, a bunch of orcs and some undead. Really just a day's work for us mercenaries."
                [/message]
                [message]
                    speaker=Bjarn
                    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=Arne
        [/filter]
        [message]
            speaker=Arne
            message= _ "Everything is lost now that I am dead..."
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=time over
        [message]
            speaker=Rotharik
            message= _ "You are too late! Your brother is already dead! Muhahahaha..."
        [/message]
        [message]
            speaker=Arne
            message= _ "Argh!!!"
        [/message]
    [/event]
[/scenario]
