#textdomain wesnoth-sof
[scenario]
    name= _ "Closing the Gates"
    id=2_Closing_the_Gates
    turns=15
    map_data="{campaigns/Sceptre_of_Fire/maps/2_Closing_the_Gates.map}"
    next_scenario=2t_In_the_Dwarven_City
    victory_when_enemies_defeated=no

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

    {DEFAULT_SCHEDULE}

    [side]
        type=Dwarvish Fighter
        id=Rugnur
        side=1
        canrecruit=yes
        shroud=yes
        controller=human
        recruit=Dwarvish Fighter,Dwarvish Thunderer,Dwarvish Guardsman,Dwarvish Scout
    [/side]

    # Give Rugnur control of all the non-boneyard villages inside the cave.
    # Trolls are going to take a couple of these fairly quickly.
    {STARTING_VILLAGES_AREA 1 14 11 3}
    {STARTING_VILLAGES_AREA 1 26 11 6}

    [side]
        type=Elvish Captain
        id=Glindur
        name= _ "Glindur"
        side=2
        canrecruit=yes
        {RECRUIT (Elvish Fighter,Elvish Scout,Elvish Archer,Elvish Shaman) (Elvish Fighter,Elvish Hero,Elvish Scout,Elvish Archer,Elvish Shaman) (Elvish Fighter,Elvish Hero,Elvish Scout,Elvish Archer,Elvish Ranger,Elvish Shaman)}
        {GOLD 200 250 300}
        [ai]
            grouping=offensive
        [/ai]
    [/side]

    [side]
        no_leader=yes
        side=3
    [/side]

    [story]
        [part]
            story= _ "Next in our story, Rugnur retreated into the caves of Knalga. But the elves pressed on, and would enter the caves shortly."
        [/part]
        [part]
            show_title=yes
            {TO_CLOSING_THE_GATES}
        [/part]
    [/story]

    {SOF_DEATHS}

    [event]
        name=prestart

        # {SCATTER_IMAGE (terrain=Gg) 1 scenery/snowbits.png}

        [objectives]
            side=1
            [objective]
                description= _ "Place someone on each of the six magic glyphs in order to close the dwarvish gates"
                condition=win
            [/objective]
            [objective]
                description= _ "Kill all elves in the caves after the gates are closed"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Rugnur"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Baglur"
                condition=lose
            [/objective]
            [objective]
                description= _ "Time runs out"
                condition=lose
            [/objective]

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

        [kill]
            side=1
            type=Caravan
        [/kill]
        [remove_shroud]
            x= 1-3,   4, 5-6, 7-14,15-16,   17,   18,   19,   20,21-22,   23,   24,12-32
            y=5-28,7-28,9-28,13-28,18-28,19-28,20-28,21-28,22-28,23-28,25-28,26-28, 9-13
        [/remove_shroud]

        {GENERIC_UNIT 3 "Troll Whelp" 6 3}
        {GENERIC_UNIT 3 "Troll Whelp" 6 3}
        {GENERIC_UNIT 3 "Troll Whelp" 6 3}

        {GENERIC_UNIT 3 "Troll Whelp" 30 25}
        {GENERIC_UNIT 3 "Troll Whelp" 30 25}
        {GENERIC_UNIT 3 "Troll Whelp" 30 25}

#ifdef HARD
        {GENERIC_UNIT 3 "Troll Whelp" 30 25}
#endif
#ifdef NORMAL
        {GENERIC_UNIT 3 "Troll Whelp" 30 25}
#endif

        [item]
            x,y=12,12
            image=scenery/rubble.png
        [/item]
        [item]
            x,y=13,13
            image=scenery/rubble.png
        [/item]
        [item]
            x,y=14,13
            image=scenery/rubble.png
        [/item]
    [/event]

    [event]
        name=start
        {MOVE_UNIT id=Rugnur 22 12}
        [recall]
            id=Alanin
        [/recall]
        [redraw]
            side=1
        [/redraw]
        [message]
            speaker=Rugnur
            message= _ "These elves are right behind me! We have to go warn the council of this attack!..."
        [/message]
        [message]
            speaker=Alanin
            message= _ "Here - I'll go warn the council. You stay here and fight."
        [/message]
        [message]
            speaker=Rugnur
            message= _ "Yes, that sounds good. I'll stay here and try to defend the gates..."
        [/message]
        {MOVE_UNIT id=Alanin 32 12}
        [store_unit]
            [filter]
                id=Alanin
            [/filter]
            variable=changealanin
            kill=yes
        [/store_unit]
        [message]
            speaker=Glindur
            message= _ "I see you have sent a messenger to the city. Good idea, but will it really help? We have more troops and more provisions, and we are going to enter those caves and kill you!"
        [/message]
        [message]
            speaker=Rugnur
            message= _ " *gulp*"
        [/message]
        [message]
            speaker=Glindur
            message= _ "Ha! I thought as much. Well then, surrender!"
        [/message]
        [message]
            speaker=Rugnur
            message= _ "Um... on what terms?"
        [/message]
        [message]
            speaker=Glindur
            message= _ "Unconditional."
        [/message]

        {GENERIC_UNIT 1 "Dwarvish Guardsman" 10 13}
        {GENERIC_UNIT 1 "Dwarvish Guardsman" 14 15}
        {GENERIC_UNIT 1 "Dwarvish Guardsman" 12 11}
        {GENERIC_UNIT 1 "Dwarvish Guardsman" 15 13}

#ifdef EASY
        {GENERIC_UNIT 1 "Dwarvish Guardsman" 12 14}
#endif
        [unit]
            x,y=22,11
            type=Dwarvish Stalwart
            side=1
            id=Baglur
            name= _ "Baglur"
            {IS_HERO}
            profile=portraits/baglur.png
            facing=sw
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]
        [message]
            speaker=Baglur
            message= _ "Wait! Rugnur, dinna' they tell you <i>anything</i> when you took command here?!?"
        [/message]
        [message]
            speaker=Rugnur
            message= _ "Not really. This was supposedly a time of peace. Who are you?"
        [/message]
        [message]
            speaker=Baglur
            message= _ "Argh! I'm a retired warrior... it looks like I'll ha' to come out and help you, else we'll be overrun by the damn elves... argh again. Well, listen here. This entrance to the city can be closed. There's a gate. If we can close it, the elves will no' be able to enter. And you elves; begone from here!"
        [/message]
        [message]
            speaker=Glindur
            message= _ "Cease your meddling, old dwarf! Rugnur is in charge here, and it is he who will bargain with us."
        [/message]
        [message]
            speaker=Rugnur
            message= _ "Baglur, how do you close the gates?"
        [/message]
        [message]
            speaker=Baglur
            message= _ "Och, well that's the difficulty. It's a magic gate. Indestructible. But that means it can only be closed by magic. Ye need to position a warrior on each of the six glyphs. When all are occupied, the gates wi' close. Then the elves will be shut out of the caves forever, at least through this entrance."
        [/message]
        [message]
            speaker=Rugnur
            message= _ "Don't we have troops positioned near these glyphs, to unlock them?"
        [/message]
        [message]
            speaker=Baglur
            message= _ "Och, well, no. Lately trolls have been more in charge of those caves where the glyphs are than we dwarves have."
        [/message]
        [message]
            speaker=Rugnur
            message= _ "Well, where are they located?"
        [/message]
        [message]
            speaker=Baglur
            message= _ "Two are down a side passage in the northwest, another two are in a similar location in the southeast, and two are right next to the front gate."
        [/message]
        [message]
            speaker=Glindur
            message= _ "Have you made up your mind yet about surrendering?! If you will not give up, prepare for battle!"
        [/message]
        [message]
            speaker=Rugnur
            # wmllint: local spelling stonecraft
            message= _ "You may be more powerful than us, but I doubt even you can blast through dwarf-made stonecraft. We refuse - now let's close these gates!"
        [/message]
        [item]
            x,y=9,11
            image=scenery/rune1.png
        [/item]
        [item]
            x,y=14,3
            image=scenery/rune2.png
        [/item]
        [item]
            x,y=30,19
            image=scenery/rune3.png
        [/item]
        [item]
            x,y=17,15
            image=scenery/rune4.png
        [/item]
        [item]
            x,y=3,5
            image=scenery/rune1.png
        [/item]
        [item]
            x,y=23,24
            image=scenery/rune2.png
        [/item]

        [scroll_to]
            x,y=13,13
        [/scroll_to]

        {REPEAT 3 (
            [removeitem]
                x,y=12,12
            [/removeitem]
            [removeitem]
                x,y=13,13
            [/removeitem]
            [removeitem]
                x,y=14,13
            [/removeitem]

            [terrain]
                x=12,13,14
                y=12,13,13
                terrain=Xu
            [/terrain]

            [redraw][/redraw]
            [delay]
                time=200
            [/delay]

            [terrain]
                x=12,14
                y=12,13
                terrain=Uu
            [/terrain]
            [terrain]
                x=13
                y=13
                terrain=Rp
            [/terrain]

            [item]
                x,y=12,12
                image=scenery/rubble.png
            [/item]
            [item]
                x,y=13,13
                image=scenery/rubble.png
            [/item]
            [item]
                x,y=14,13
                image=scenery/rubble.png
            [/item]

            [redraw][/redraw]
            [delay]
                time=200
            [/delay]
        )}
    [/event]

    # We reach the northern side entrance

    [event]
        name=moveto
        [filter]
            x,y=3,5
            side=1
        [/filter]
        [message]
            speaker=unit
            message= _ "But what about this entrance? The elves can come through it just as easily as the main gate, and it cannot be closed!"
        [/message]
        [message]
            speaker=Baglur
            message= _ "I think it can be sealed up somehow... Yes, look, activating that glyph seems to have closed up the gap."
        [/message]
        [terrain]
            x,y=2,6
            terrain=Xu
        [/terrain]
    [/event]

    # We reach the southern side entrance

    [event]
        name=moveto
        [filter]
            x,y=23,24
            side=1
        [/filter]
        [message]
            speaker=unit
            message= _ "But what about this entrance? The elves can come through it just as easily as the main gate, and it cannot be closed!"
        [/message]
        [message]
            speaker=Baglur
            message= _ "I think it can be sealed up somehow... Yes, look, activating that glyph seems to have closed up the gap."
        [/message]
        [terrain]
            x,y=21,24
            terrain=Xu
        [/terrain]
    [/event]

    # Check for all glyph activators in place

    [event]
        name=moveto
        first_time_only=no
        [filter]
            x=9,14,30,17,3,23
            y=11,3,19,15,5,24
            side=1
        [/filter]
        [if]
            [variable]
                name=gate_closed
                not_equals=yes
            [/variable]
            [have_unit]
                x,y=9,11
                side=1
            [/have_unit]
            [have_unit]
                x,y=14,3
                side=1
            [/have_unit]
            [have_unit]
                x,y=30,19
                side=1
            [/have_unit]
            [have_unit]
                x,y=17,15
                side=1
            [/have_unit]
            [have_unit]
                x,y=3,5
                side=1
            [/have_unit]
            [have_unit]
                x,y=23,24
                side=1
            [/have_unit]
            [then]
                {VARIABLE gate_closed yes}

                [message]
                    speaker=Rugnur
                    message= _ "We have everyone positioned on the glyphs! What do we do now?"
                [/message]
                [message]
                    speaker=Baglur
                    message= _ "Just watch. The gates wi' close very soon. Then the elves outside - and, unfortunately, our dwarves who are still out there - wi' become irrelevant."
                [/message]
                [scroll_to]
                    x,y=13,13
                [/scroll_to]

                [delay]
                    time=400
                [/delay]
                [sound]
                    name=explosion.ogg
                [/sound]
                [kill]
                    x,y=12,12
                    animate=yes
                    fire_event=yes
                [/kill]
                [removeitem]
                    x,y=12,12
                [/removeitem]
                [terrain]
                    x=12
                    y=12
                    terrain=Xu
                [/terrain]
                [redraw]
                [/redraw]

                [delay]
                    time=400
                [/delay]
                [sound]
                    name=explosion.ogg
                [/sound]
                [kill]
                    x,y=13,13
                    animate=yes
                    fire_event=yes
                [/kill]
                [removeitem]
                    x,y=13,13
                [/removeitem]
                [terrain]
                    x=13
                    y=13
                    terrain=Xu
                [/terrain]
                [redraw]
                [/redraw]

                [delay]
                    time=400
                [/delay]
                [sound]
                    name=explosion.ogg
                [/sound]
                [kill]
                    x,y=14,13
                    animate=yes
                    fire_event=yes
                [/kill]
                [removeitem]
                    x,y=14,13
                [/removeitem]
                [terrain]
                    x=14
                    y=13
                    terrain=Xu
                [/terrain]
                [redraw]
                [/redraw]

                [message]
                    speaker=Glindur
                    message= _ "Agh! Well, you have defeated me for now, but eventually you will have to exit these caves, to give Haldric back his jewel. And when you do, we will be ready for you."
                [/message]
                [message]
                    speaker=Baglur
                    message= _ "If that is what ye choose to do, fine, but be prepared to wait for many years."
                [/message]

                [kill]
                    x=   1,   2,   3,   4,    5,    6,  7-8,    9,10-12,13-14,15-16,   17,   18,   19,   20,21-22
                    y=7-28,7-28,8-28,9-28,10-28,12-28,13-28,14-28,13-28,14-28,18-28,19-28,20-28,21-28,22-28,26-28
                    side=1
                    fire_event=yes
                    animate=yes
                [/kill]

                [kill]
                    x=   1,   2,   3,   4,    5,    6,  7-8,    9,10-12,13-14,15-16,   17,   18,   19,   20,21-22
                    y=7-28,7-28,8-28,9-28,10-28,12-28,13-28,14-28,13-28,14-28,18-28,19-28,20-28,21-28,22-28,26-28
                    side=2,3
                    fire_event=no
                [/kill]

                [place_shroud]
                    x=   1,   2,   3,   4,    5,    6,  7-8,    9,10-12,13-14,15-16,   17,   18,   19,   20,21-22
                    y=7-28,7-28,8-28,9-28,10-28,12-28,13-28,14-28,13-28,14-28,18-28,19-28,20-28,21-28,22-28,26-28
                [/place_shroud]
                [if]
                    [have_unit]
                        side=2
                    [/have_unit]
                    [then]
                        [message]
                            speaker=Rugnur
                            message= _ "There are still some elves left in here. We have to eliminate them, too, unless they surrender."
                        [/message]
                        [role]
                            role=elf
                            side=2
                        [/role]
                        [message]
                            role=elf
                            message= _ "You would have us be cowards! We do not surrender."
                        [/message]
                        [objectives]
                            side=1
                            [objective]
                                description= _ "Kill all elves in the caves"
                                condition=win
                            [/objective]
                            [objective]
                                description= _ "Death of Rugnur"
                                condition=lose
                            [/objective]
                            [objective]
                                description= _ "Death of Baglur"
                                condition=lose
                            [/objective]
                            [objective]
                                description= _ "Time runs out"
                                condition=lose
                            [/objective]

                            note={EARLY_FINISH_BONUS_NOTE}+{NEW_GOLD_CARRYOVER_NOTE_40}
                        [/objectives]
                        [event]
                            name=die
                            first_time_only=no
                            [filter]
                                side=2
                            [/filter]
                            [if]
                                [have_unit]
                                    side=2

                                    [not]
                                        x,y=$x1,$y1
                                    [/not]
                                [/have_unit]
                                [then]
                                [/then]
                                [else]
                                    [message]
                                        speaker=Rugnur
                                        message= _ "That's all of the elves. Now I should go down to the city and report. I'm late already..."
                                    [/message]
                                    [endlevel]
                                        result=victory
                                        bonus=yes
                                        {NEW_GOLD_CARRYOVER 40}
                                    [/endlevel]
                                [/else]
                            [/if]
                        [/event]
                    [/then]
                    [else]
                        [message]
                            speaker=Rugnur
                            message= _ "Well, now I should go down to the city and report. I'm late already..."
                        [/message]
                        [endlevel]
                            result=victory
                            bonus=yes
                            {NEW_GOLD_CARRYOVER 40}
                        [/endlevel]
                    [/else]
                [/if]
            [/then]
            [else]
                [message]
                    speaker=unit
                    message= _ "My glyph is on."
                [/message]

                [allow_undo]
                [/allow_undo]
            [/else]
        [/if]
    [/event]

    [event]
        name=enemies defeated

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

    [event]
        name=die
        [filter]
            id=Baglur
        [/filter]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]
[/scenario]
