#textdomain wesnoth-ei
[scenario]
    id=11_Captured
    name= _ "Captured"
    next_scenario=12_Evacuation
    map_data="{campaigns/Eastern_Invasion/maps/11_Captured.map}"
    victory_when_enemies_defeated=no
    {TURNS 50 40 30}
    {UNDERGROUND}

    {INTRO_AND_SCENARIO_MUSIC northerners.ogg the_deep_path.ogg}
    {EXTRA_SCENARIO_MUSIC breaking_the_chains.ogg}
    {EXTRA_SCENARIO_MUSIC underground.ogg}

    {campaigns/Eastern_Invasion/utils/deaths.cfg}

    # wmllint: local spelling Dra-Nak
    [story]
        [part]
            story= _ "After reaching what they believed was safety, Gweddry and his men had been captured by northern orcs."
            #       background=story/
        [/part]
        [part]
            story= _ "Informed they were being taken to the orcish king, Dra-Nak, they attempted to escape before that happened..."
            show_title=yes
            #       background=story/
        [/part]
    [/story]

    #######
    #sides#
    #######
    [side]
        type=General
        id=Gweddry
        name= _ "Gweddry"
        side=1
        canrecruit=no
        controller=human
        team_name=good
        user_team_name=_"Wesnothians"
        fog=yes
        shroud=yes
        gold=100
        {FLAG_VARIANT loyalist}
    [/side]

    [side]
        type=Orcish Warlord
        id=King Dra-Nak
        name= _ "King Dra-Nak"
        side=2
        canrecruit=yes
        controller=ai
        recruit=
        {GOLD 40 50 60}
        [ai]
            passive_leader=yes
            grouping=no
            recruitment_ignore_bad_combat=yes
            aggression=0.4
            [avoid]
                x=1-7,7-14,14-21
                y=1-24,21-24,16-24
            [/avoid]
        [/ai]
        team_name=bad
        user_team_name=_"Evil"
        {FLAG_VARIANT ragged}
    [/side]

    [side]
        side=3
        no_leader=yes
        [ai]
            aggression=1.0  # An insanely aggressive guardian :-)
        [/ai]
        team_name=bad
        user_team_name=_"Evil"
    [/side]

    #####################
    #lots of definitions#
    #####################

#define GUARD X Y TYPE
    [unit]
        type={TYPE}
        side=2
        x={X}
        y={Y}
        ai_special=guardian
    [/unit]
#enddef

#define ATTACKER X Y TYPE
    [unit]
        type={TYPE}
        side=2
        x={X}
        y={Y}
    [/unit]
#enddef

#define SIDE3 X Y TYPE
    [unit]
        type={TYPE}
        side=3
        x={X}
        y={Y}
        ai_special=guardian
    [/unit]
#enddef

#define ROLE TYPE ROLE_VALUE X Y
    [role]
        type={TYPE}
        side=1
        role={ROLE_VALUE}
    [/role]
    [recall]
        role={ROLE_VALUE}
        x,y={X},{Y}
    [/recall]
#enddef

    ######################
    #/lots of definitions#
    ######################

    [event]
        name=prestart

        # {SCATTER_IMAGE (terrain=Uu) 4 scenery/rubble.png}

        [objectives]
            side=1
            [objective]
                description= _ "Escape through the south-west tunnel"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Gweddry"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Dacyn"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Owaec"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

            [gold_carryover]
                bonus=yes
                carryover_percentage=40
            [/gold_carryover]
        [/objectives]
        ##############################
        #starting units (like guards)#
        ##############################
        #the first guards
        #you cannot go out this way!
        {GUARD 34 17 (Troll Warrior)}
        {GUARD 34 19 (Troll Warrior)}
        {GUARD 31 18 (Troll Warrior)}
        {GUARD 31 20 (Troll Warrior)}
        {GUARD 27 17 (Troll Warrior)}
        {GUARD 27 19 (Troll Warrior)}

        #kings chamber guards
        {GUARD 9 16 (Orcish Warrior)}
        {GUARD 12 14 (Orcish Warrior)}
        {GUARD 15 16 (Orcish Warrior)}
        {GUARD 15 19 (Orcish Warrior)}
        {GUARD 25 11 (Orcish Warrior)}
        {GUARD 12 20 (Orcish Warrior)}
        {GUARD 9 19 (Orcish Warrior)}

        #torture chamber guards
        {GUARD 33 28 (Orcish Slayer)}
        {GUARD 30 26 (Orcish Slayer)}
        {GUARD 27 27 (Orcish Assassin)}
        {GUARD 28 29 (Orcish Assassin)}

        #these are bats that inhabit the side tunnels
        {SIDE3 14 9 (Blood Bat)}
        {SIDE3 19 10 (Vampire Bat)}
        {SIDE3 22 9 (Vampire Bat)}
        {SIDE3 24 7 (Vampire Bat)}
        {SIDE3 33 10 (Vampire Bat)}
    [/event]

    #########################
    #names for all the rooms#
    #########################
    [label]
        x,y=23,25
        text=_"Prison"
    [/label]
    [label]
        x,y=33,28
        text=_"Torture Chamber"
    [/label]
    [label]
        x,y=12,18
        text=_"Throne Room"
    [/label]
    [label]
        x,y=28,32
        text=_"The City"
    [/label]
    [label]
        x,y=19,33
        text=_"The City"
    [/label]
    [label]
        x,y=15,32
        text=_"Exit"
    [/label]

    #############################
    #THE START EVENT BEGINS HERE#
    #############################
    [event]
        name=start
        ################
        #getting people#
        ################
        #getting Dacyn and Owaec
        [recall]
            id=Dacyn
            x,y=28,11
        [/recall]
        [recall]
            id=Owaec
            x,y=28,10
        [/recall]
        #getting the sidekicks
        {ROLE (Red Mage,Longbowman,Master Bowman,Arch Mage,Silver Mage,Great Mage) SIDE1 27 10}
        {ROLE (Swordsman,Pikeman,Javelineer,Royal Guard,Halberdier) SIDE2 29 10}

        ##################
        #huge intro scene#
        ##################

        #some talking
        [message]
            speaker=Gweddry
            message= _ "I think Dacyn and Owaec have escaped already. Now I have to, also... these guards are not being very alert, I may be able to get past them..."
        [/message]
        {MOVE_UNIT id=Gweddry 30 18}

        [redraw]
            side=1
        [/redraw]

        [message]
            speaker=Gweddry
            message= _ "Aha! There is a small crack in the cave wall here."
        [/message]

        {MOVE_UNIT id=Gweddry 29 16}

        [redraw]
            side=1
        [/redraw]

        {MOVE_UNIT id=Gweddry 29 12}

        [redraw]
            side=1
        [/redraw]

        #dialogue
        [message]
            speaker=Dacyn
            message= _ "So, Gweddry, you escaped too? Good. I think they have the rest of our troops captive, along with the peasants following us. We should be able to rescue them."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Where are they? These caves are impossible to navigate!"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Somewhere south of us. We are in a hidden passage in the north. Oh, and some others escaped too, along with Owaec."
        [/message]

        {CLEAR_FOG 1 13 17 6}

        [message]
            speaker=King Dra-Nak
            message= _ "Well, where are the prisoners?"
        [/message]
        [message]
            x,y=15,16
            message= _ "Right here, boss."
        [/message]
        [message]
            speaker=King Dra-Nak
            message= _ "Well, where’s their leader? I don’t see him."
        [/message]
        [message]
            x,y=15,16
            message= _ "Uh... " + {WHISPER _"whisper^I dunno. He escaped, I think."}
        [/message]
        [message]
            speaker=King Dra-Nak
            message= _ "You fool! Well, find him. Bring him to me! Wait, no, just kill him on sight."
        [/message]

        {UNCLEAR_FOG}

        [place_shroud]
            side=1
            x=5-25
            y=5-25
        [/place_shroud]

        #######################
        #event inside an event#
        #######################
        [event]
            name=sighted,moveto
            [filter]
                type=Orcish Grunt,Orcish Warrior
                [filter_vision]
                    viewing_side=1
                [/filter_vision]
            [/filter]
            [message]
                speaker=unit
                message= _ "Look, the escaped prisoners have returned!"
            [/message]
            [message]
                speaker=King Dra-Nak
                message= _ "Kill them."
            [/message]
            #these are prisoners even though the macro is called PRISON

            #first group of prisoners- in the small cell

            # lvl4 units are stored first, then lvl3, then lvl2 and lastly lvl1:
            # this makes it easy to just keep recalling the first unit of the
            # array in order to ensure the prisoners are always the highest lvl
            # units possible

            [store_unit]
                [filter]
                    side=1
                    x,y=recall,recall
                    level=4
                [/filter]

                kill=no
                variable=possible_prisoners
            [/store_unit]

            [store_unit]
                [filter]
                    side=1
                    x,y=recall,recall
                    level=3
                [/filter]

                kill=no
                variable=possible_prisoners
                mode=append
            [/store_unit]

            [store_unit]
                [filter]
                    side=1
                    x,y=recall,recall
                    level=2
                [/filter]

                kill=no
                variable=possible_prisoners
                mode=append
            [/store_unit]

            [store_unit]
                [filter]
                    side=1
                    x,y=recall,recall
                    level=1
                [/filter]

                kill=no
                variable=possible_prisoners
                mode=append
            [/store_unit]

            [set_variables]
                name=prisoner_locations

                [value]
                    x,y=37,27
                [/value]
                [value]
                    x,y=38,27
                [/value]
                [value]
                    x,y=39,28
                [/value]
                [value]
                    x,y=39,29
                [/value]
                [value]
                    x,y=39,30
                [/value]
                [value]
                    x,y=38,30
                [/value]
                [value]
                    x,y=37,31
                [/value]
                [value]
                    x,y=36,31
                [/value]
                [value]
                    x,y=35,31
                [/value]
                [value]
                    x,y=34,30
                [/value]
                [value]
                    x,y=38,29
                [/value]
                [value]
                    x,y=37,30
                [/value]
                [value]
                    x,y=36,30
                [/value]
            [/set_variables]

            # for each prisoner location, we either recall the first unit of the
            # array (and then remove it from the array) or create a new unit if
            # the array is empty (meaning that the recall list had less than 13
            # units

            {FOREACH prisoner_locations i}
                [if]
                    [variable]
                        name=possible_prisoners.length
                        greater_than=0
                    [/variable]

                    [then]
                        {VARIABLE_OP possible_prisoners[0].hitpoints multiply 0.75}

                        [kill]
                            side=1
                            x,y=recall,recall
                            id=$possible_prisoners[0].id
                        [/kill]

                        [unstore_unit]
                            variable=possible_prisoners[0]
                            x,y=$prisoner_locations[$i].x,$prisoner_locations[$i].y
                            find_vacant=yes
                        [/unstore_unit]

                        {CLEAR_VARIABLE possible_prisoners[0]}
                    [/then]

                    [else]
                        [if]
                            [variable]
                                name=have_ogres
                                boolean_equals=yes
                            [/variable]

                            [then]
                                {RANDOM "Young Ogre,Spearman,Cavalryman,Mage,Horseman,Heavy Infantryman"}
                            [/then]

                            [else]
                                {RANDOM "Spearman,Cavalryman,Mage,Horseman,Heavy Infantryman"}
                            [/else]
                        [/if]

                        [unit]
                            side=1
                            type=$random
                            generate_name=yes
                            random_traits=yes
                            x,y=$prisoner_locations[$i].x,$prisoner_locations[$i].y
                            to_variable=new_prisoner
                        [/unit]

                        {VARIABLE_OP new_prisoner.hitpoints multiply 0.75}

                        [unstore_unit]
                            variable=new_prisoner
                        [/unstore_unit]
                    [/else]
                [/if]
            {NEXT i}

            [redraw]
                side=1
            [/redraw]

            #a prisoner says something
            [message]
                x,y=37,27
                message= _ "The guards are distracted! Now is the time to escape!"
            [/message]
            [message]
                x,y=33,28
                message= _ "Huh? Who’s there, who said that?"
            [/message]
            {ATTACKER 24 24 (Orcish Warrior)}
            {ATTACKER 24 25 (Orcish Warrior)}
            {ATTACKER 24 25 (Troll Warrior)}
            {ATTACKER 28 31 (Orcish Warrior)}
            {ATTACKER 29 32 (Orcish Warrior)}
            {ATTACKER 28 32 (Troll Warrior)}
        [/event]
        ########################
        #/event inside an event#
        ########################
    [/event]
    ###########################
    #THE START EVENT ENDS HERE#
    ###########################

    {PICKUPPABLE_ITEM holy_amulet 22 38 side=1 items/ankh-necklace.png
    _"Wearing this amulet will cause every blow you deal to inflict <i>arcane</i> damage!"
    _"holy amulet^Take it"
    _"holy amulet^Leave it"
    _"I am not suited to using this item! Let another take it." (
        [object]
            name= _ "Holy Amulet"
            image=items/ankh-necklace.png
            duration=forever

            [effect]
                apply_to=attack
                range=melee
                set_type=arcane
            [/effect]
            [effect]
                apply_to=attack
                range=ranged
                set_type=arcane
            [/effect]
        [/object]
    )}

    #they start recruiting to chase you at turn 20
    [event]
        name=turn 20
        [allow_recruit]
            side=2
            type=Orcish Warrior,Orcish Crossbowman,Troll
        [/allow_recruit]
    [/event]

    #if you try to leave the way you came, it yells at you
    [event]
        name=moveto
        [filter]
            id=Gweddry
            x=23-31
            y=15-21
        [/filter]
        [message]
            speaker=Gweddry
            message= _ "I see the exit to the tunnel! Onward!"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Wait! We cannot go out that way. There are too many orcs. We must exit through the south-west gates."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Very well. We must go the other way."
        [/message]
    [/event]

    #victory
    #when you exit the caves, you win
    [event]
        name=moveto
        [filter]
            x=1-11
            y=32-40
            id=Gweddry
        [/filter]
        [message]
            speaker=Gweddry
            message= _ "Good! We have escaped these accursed caves!"
        [/message]
        [endlevel]
            result=victory
            bonus=yes
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

    {FOREIGN_DEFEAT}
[/scenario]
