#textdomain wesnoth-ei
[scenario]
    id=11_Captured
    name= _ "Captured"
    next_scenario=12_Evacuation
    map_file=11_Captured.map
    victory_when_enemies_defeated=no
    turns=unlimited
    {UNDERGROUND}
    {SCENARIO_MUSIC underground.ogg}

    # wmllint: local spelling Dra-Nak
    [story]
        [part]
            story= _ "After their surrender, Gweddry, Dacyn, and Owaec were promptly taken before the orcish chieftain, Dra-Nak. The rest were thrown into the prisons to await their turn..."
            music=silence.ogg
        [/part]
    [/story]

    {EI_TRACK {JOURNEY_11_NEW} }

    [side]
        side=1
        canrecruit=yes
        controller=human
        team_name=good
        user_team_name=_"Wesnothians"
        shroud=yes
        gold=0 # see notes in S09_Castle_In_The_Ice
        {FLAG_VARIANT loyalist}
        {CHARACTER_STATS_GWEDDRY}
        defeat_condition=never # since you start without a leader
    [/side]

    #---------------------------
    # DRA-NAK
    #---------------------------
    [side]
        color=white
        type=Orcish Sovereign
        id=Chief Dra-Nak
        name= _ "Chief Dra-Nak"
        profile=portraits/orcs/ruler-2.webp
        [modifications]
            {TRAIT_INTELLIGENT}
            {TRAIT_STRONG}
        [/modifications]
        facing=nw
        side=2
        canrecruit=yes
        controller=ai
        recruit=Orcish Warrior,Orcish Archer,Orcish Assassin
        gold=0
        income=-2
        [ai]
            grouping=no
            aggression=0.4
            leader_value=0
            [avoid] # avoid the villages, or else Dra-Nak tries to claim them
                x=36-99, 0-20
                y= 0-99,20-99
            [/avoid]
            [aspect]
                id=attacks
                [facet]
                    invalidate_on_gamestate_change=yes
                    [filter_enemy]
                        [not]
                            [filter_wml]
                                [variables]
                                    undercover=yes
                                [/variables]
                            [/filter_wml]
                        [/not]
                    [/filter_enemy]
                [/facet]
            [/aspect]
        [/ai]
        team_name=bad
        user_team_name=_"Clan Whitefang"
        {FLAG_VARIANT6 ragged}
    [/side]
    {SILENTLY_LIMIT_LEADER_MOVES 2 2}

    #---------------------------
    # PRISONERS AND BATS
    #---------------------------
    [side]
        color=red
        side=3
        no_leader=yes
        controller=null # so they can't rest-heal
        team_name=good,bad
        user_team_name=_"Prisoners"
        share_vision=none
        hidden=yes
    [/side]
    [side]
        side=4
        no_leader=yes
        controller=ai
        team_name=bats
        user_team_name=_"Bats"
        share_vision=none
        hidden=yes
        [ai]
            aggression=0.99
            [micro_ai]
                ai_type=zone_guardian

                [filter]
                [/filter]

                [filter_location]
                    x,y=7-12,1-4
                [/filter_location]
            [/micro_ai]
        [/ai]
    [/side]

    #---------------------------
    # ORC REINFORCEMENTS
    #---------------------------
    [side]
        color=white
        type=Orcish Warlord
        id=Varrak-Klar
        #po: In S11, an orc with so much gold for recruitment that the player can't beat them, acts as a turn limit.
        name=_"Varrak-Klar" # this guy reappears in S12 Evacuation, if you kill Dra-Nak
        [modifications]
            {TRAIT_RESILIENT}
            {TRAIT_STRONG}
        [/modifications]
        side=5
        controller=ai
        hidden=yes
        facing=sw
        canrecruit=yes
        hidden=yes
        controller=ai
        recruit=Orcish Warrior,Orcish Archer,Orcish Assassin
        gold=0
        income=-2
        team_name=bad
        user_team_name=_"Clan Whitefang"
        {FLAG_VARIANT6 ragged}
    [/side]

    {SILENTLY_LIMIT_LEADER_MOVES 5 0} # don't let them reach the villages and get income
    [side]
        color=white
        type=Orcish Slurbow
        id=Rakkha
        #po: In S11, an orc with so much gold for recruitment that the player can't beat them, acts as a turn limit.
        name=_"Rakkha" # this guy reappears in S12 Evacuation
        [modifications]
            {TRAIT_QUICK}
            {TRAIT_STRONG}
        [/modifications]
        side=6
        controller=ai
        hidden=yes
        facing=sw
        canrecruit=yes
        controller=ai
        recruit=Orcish Grunt,Orcish Crossbowman,Orcish Assassin
        gold=0
        income=-2
        team_name=bad
        user_team_name=_"Clan Whitefang"
        {FLAG_VARIANT6 ragged}
    [/side]
    {SILENTLY_LIMIT_LEADER_MOVES 6 0} # don't let them reach the villages and get income

    # force orc gold to stay 0 before the fighting starts, even if they have vilalges
    [event]
        name=new turn
        first_time_only=no

        [filter_condition]
            [have_unit]
                id=Gweddry
                side=3
            [/have_unit]
        [/filter_condition]

        [modify_side]
            side=2,5,6
            gold=0
        [/modify_side]
    [/event]

    [event]
        name=prestart

        [time_area]
            x= 0-7,  8-12,13-16,17,   18,   19,   20,   21,      39,  39,   40,  40,   41,  41,   42,  42,   43-99
            y=17-99,18-99,20-99,24-99,24-99,25-99,25-99,28-99,   0-13,27-29,0-15,27-29,0-16,27-29,0-16,23-99,0-99
            {WINTER_SCHEDULE}
        [/time_area]

        {PLACE_IMAGE scenery/dwarven-keep-tile.png 30 15}
        {PLACE_IMAGE items/whitefang-flag.png 28 15}
        {PLACE_IMAGE items/whitefang-flag.png 32 15}
        {PLACE_IMAGE items/bones.png 30 17}

        {PLACE_IMAGE items/burial.png 22 13}
        {PLACE_IMAGE items/burial.png 26 11}

        {PLACE_IMAGE items/chest-open.png 33 11}

        {PLACE_IMAGE items/bones.png 12 3}
        {PLACE_IMAGE items/bones.png 9 3}

        {PLACE_IMAGE items/barrel.png 14 15}
        {PLACE_IMAGE items/box.png 15 15}
        {PLACE_IMAGE items/axe.png 15 16}
        {PLACE_IMAGE scenery/trash.png 16 16}
        {PLACE_IMAGE items/dummy.png 16 15}

        {PLACE_IMAGE items/armor.png 15 19}
        {PLACE_IMAGE items/bow.png 15 18}
        {PLACE_IMAGE items/barrel.png 14 18}
        {PLACE_IMAGE "items/barrel.png~FL()" 16 19}
        {PLACE_IMAGE "items/sword.png~FL()" 16 18}
        {PLACE_IMAGE items/barrel.png 17 19}

        {PLACE_IMAGE scenery/trash.png 30 24}

        {MODIFY_UNIT id=Gweddry facing se}

        {RECALL_XY Dacyn 28 13}
        {MODIFY_UNIT id=Dacyn facing se}
#ifndef EASY
        # Dacyn needs either full HP or low enough hp that the player realizes he needs to flee.
        # with medium HP the player might think they're expected to fight, even if it's not likely/possible
        # 7hp chosen arbitrarily
        {MODIFY_UNIT id=Dacyn hitpoints 7}
#endif

        {RECALL_XY Owaec 26 14}
        {MODIFY_UNIT id=Owaec facing se}

        #------------------
        # SPAWN ESCAPEES
        #------------------
        # escapee leader
        [role]
            side=1
            type=Royal Guard,Halberdier,Great Mage,Master Bowman,Arch Mage,Silver Mage,Mage of Light,Javelineer,Swordsman,Pikeman,Longbowman,Red Mage,White Mage,Mage,Spearman,Bowman,Iron Mauler,Shock Trooper,Heavy Infantryman
            [not]
                id=Dacyn
            [/not]
            role=escapee leader
        [/role]
        [if]
            [not]
                [have_unit]
                    role=escapee leader
                    search_recall_list=yes
                [/have_unit]
            [/not]
            [then]
                {GENERIC_UNIT 1 "Mage" "recall" "recall"}
                [+unit]
                    role=escapee leader
                [/unit]
            [/then]
        [/if]

        [recall]
            x,y=23,4
            role=escapee leader
        [/recall]
        {MODIFY_UNIT (role=escapee leader) facing nw}

        # escapee sidekick 0
        [role]
            side=1
            type=White Mage,Red Mage,Longbowman,Pikeman,Swordsman,Javelineer,Mage,Spearman,Bowman,Mage of Light,Arch Mage,Silver Mage,Master Bowman,Halberdier,Royal Guard,Great Mage,Iron Mauler,Shock Trooper,Heavy Infantryman
            [not]
                id=Dacyn
            [/not]
            [not]
                role=escapee leader
            [/not]
            role=escapee sidekick 0
        [/role]
        [if]
            [not]
                [have_unit]
                    role=escapee sidekick 0
                    search_recall_list=yes
                [/have_unit]
            [/not]
            [then]
                {GENERIC_UNIT 1 "Fencer" "recall" "recall"}
                [+unit]
                    role=escapee sidekick 0
                [/unit]
            [/then]
        [/if]

        [recall]
            x,y=25,4
            role=escapee sidekick 0
        [/recall]

        # escapee sidekick 1
        [role]
            side=1
            type=Longbowman,Pikeman,Swordsman,Javelineer,White Mage,Red Mage,Mage,Spearman,Bowman,Mage of Light,Arch Mage,Silver Mage,Master Bowman,Halberdier,Royal Guard,Great Mage,Iron Mauler,Shock Trooper,Heavy Infantryman
            [not]
                id=Dacyn
            [/not]
            [not]
                role=escapee leader
            [/not]
            [not]
                role=escapee sidekick 0
            [/not]
            role=escapee sidekick 1
        [/role]
        [if]
            [not]
                [have_unit]
                    role=escapee sidekick 1
                    search_recall_list=yes
                [/have_unit]
            [/not]

            [then]
                {GENERIC_UNIT 1 "Spearman" "recall" "recall"}
                [+unit]
                    role=escapee sidekick 1
                [/unit]
            [/then]
        [/if]

        [recall]
            x,y=25,5
            role=escapee sidekick 1
        [/recall]

        # escapee sidekick 2 is a deserter, so don't recall them from the existing list
        {NOTRAIT_UNIT 1 "Bowman" 24 5}
        [+unit]
            role="escapee sidekick 2"
            # Fixing the gender makes translation easier, as it avoids the need for text variants.
            # Our heroes are all male, so let's have the very non-heroic unit be male too.
            gender=male
            [modifications]
                {TRAIT_DESERTER}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        {TEAM_COLOR_OVERRIDE x,y=24,5 darkred} # deserters get a slightly different color

        #------------------
        # PREPARE PRISONERS
        #------------------
        # store lvl2+ units first, so these will get priority for recall
        # then store low level units
        {STORE_RECALLS (level=2-99)        possible_prisoners}   # through 99 in case the user has an add-on with extra advancements
        {STORE_RECALLS (level=1) possible_prisoners}   # no level 0 (even though peasants are possible), because they'd be worthless here

        #------------------
        # SPAWN PRISONERS
        #------------------
        # these 2 drake prisoners are from S09, where they were taken away as tribute
        {NAMED_UNIT 1 (Drake Glider)     29 7 "Ga'all" (_"Ga’all") ()} {FACING ne} {TEAM_COLOR_OVERRIDE x,y=29,7 orange}
        {NAMED_UNIT 1 (Drake Warrior)    30 6 "Verash" (_"Verash") ()} {FACING ne} {TEAM_COLOR_OVERRIDE x,y=30,6 orange}

        # minimum 3 deserters
        {NOTRAIT_UNIT 1 (Javelineer) 15 8}  {TEAM_COLOR_OVERRIDE x,y=15,8 darkred}
        [+unit]
            [modifications]
                {TRAIT_DESERTER}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        {NOTRAIT_UNIT 1 (Poacher)    14 9}  {TEAM_COLOR_OVERRIDE x,y=14,9 darkred}
        [+unit]
            [modifications]
                {TRAIT_DESERTER}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]

        {NOTRAIT_UNIT 1 (Thief)      13 9}  {TEAM_COLOR_OVERRIDE x,y=13,9 darkred}
        [+unit]
            [modifications]
                {TRAIT_DESERTER}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        # fill the rest of the cells with player units (leave some empty spots for appearance's sake)
        # 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 (because the player's recall list was short)
        [store_locations]
            x=14,14,15,15,16,  18,19,19,20,20,21,  28,29,30,31
            y= 7,10, 7,10, 9,   6, 6, 8, 6, 7, 7,   7, 8, 7, 8
            variable=prisoner_locations
        [/store_locations]
        [foreach]
            array=prisoner_locations
            [do]
                [if]
                    {VARIABLE_CONDITIONAL possible_prisoners.length greater_than 0}
                    [then]
                        [recall] # recall player units
                            find_in=possible_prisoners[0]
                            x,y=$this_item.x,$this_item.y
                            show=no
                        [/recall]
                        {CLEAR_VARIABLE possible_prisoners[0]}
                    [/then]

                    [else]
                        # if not enough player recalls, spawn more deserters
                        # include units that are useful in this scenario but bad recalls overall
                        {RANDOM "Heavy Infantryman,Spearman,Javelineer,Bowman,Poacher,Trapper,Thief"}
                        {NOTRAIT_UNIT 1 ($random) $this_item.x $this_item.y}
                        {TEAM_COLOR_OVERRIDE x,y=$this_item.x,$this_item.y darkred} # deserters get a slightly different color
                        [+unit]
                            [modifications]
                                {TRAIT_DESERTER}
                                {TRAIT_RESILIENT}
                            [/modifications]
                        [/unit]
                        # yes, yes, they're all resilient, does it really matter?
                    [/else]
                [/if]
            [/do]
        [/foreach]
        {CLEAR_VARIABLE possible_prisoners,prisoner_locations,new_prisoner}

        #------------------
        # SPAWN GUARDS
        #------------------
        # gweddry/owaec/dacyn guards
        {NOTRAIT_UNIT 2 {ON_DIFFICULTY (Drake Clasher) (Drake Thrasher) (Drake Thrasher)} 23 16}  {TEAM_COLOR_OVERRIDE x,y=23,16 orange } # needed to block disguise movement
        [+unit]
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]
        # can't be quick, so it can't spot human escapees before they spot it
        {GENERIC_UNIT 2 "Orcish Grunt"  24 13} # needed to block disguise movement
        {GENERIC_UNIT 2 "Orcish Grunt"  26 12} # needed to block disguise movement

        # prison guards
#ifdef HARD
        {GENERIC_UNIT 2 "Drake Glider" 23 10}  {TEAM_COLOR_OVERRIDE x,y=23,10 orange}
#endif
        {GENERIC_UNIT 2 {ON_DIFFICULTY (Drake Burner)  (Fire Drake)    (Fire Drake)   } 19 12}  {TEAM_COLOR_OVERRIDE x,y=19,12 orange}
        {GENERIC_UNIT 2 {ON_DIFFICULTY (Drake Clasher) (Drake Arbiter) (Drake Arbiter)} 26  8}  {TEAM_COLOR_OVERRIDE x,y=26,8  orange} # needed to block disguise movement

        # dra-nak bodyguards
#ifndef EASY
        {LOYAL_UNIT 2 {ON_DIFFICULTY "n/a" "Orcish Assassin" "Orcish Slayer"} 29 16} {GUARDIAN} {FACING nw}
        {LOYAL_UNIT 2 {ON_DIFFICULTY "n/a" "Orcish Assassin" "Orcish Slayer"} 31 15} {GUARDIAN} {FACING nw}
        {SILENTLY_LIMIT_MOVES 2 (type=Orcish Assassin,Orcish Slayer) 3}
#endif

        {GENERIC_UNIT 2 "Drake Glider" 28 18}  {TEAM_COLOR_OVERRIDE x,y=28,18 orange} # needed to block disguise movement (this guy also has a speaking role)
        {NAMED_UNIT 2 (Cave Bear) 31 17 "Boja" (_"Boja") ()} {FACING nw}
        [+unit]
            [modifications]
                {TRAIT_SLOW}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]
        # so gweddry/owaec/dacyn get a chance to run
        # a trained bear must be pretty smart, right?
#ifdef EASY
        [modify_unit]
            [filter]
                id=Boja
            [/filter]

            [object]
                [effect]
                    apply_to=attack
                    increase_damage=-43%
                [/effect]
                # -3/-6
                [effect]
                    apply_to=hitpoints
                    increase_total=-30
                [/effect]
            [/object]
        [/modify_unit]
#endif

        {NOTRAIT_UNIT 2 "Gate" 34 11} # destructible treasury gate (killing Dra-Nak also unlocks the gate)
#ifndef EASY
        {NOTRAIT_UNIT 2 "Orcish Grunt" 34 12} {GUARDIAN} {FACING s} # treasury guard
        [+unit]
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]
#endif

        # cowardly goblin
        {NAMED_UNIT 2 (Goblin Spearman) 31 23 "Cowardly Goblin" _"Cowardly Goblin" ()}
        [+unit]
            max_moves=0
        [/unit]
        {FACING ne}
        {PLACE_ITEM_INVISIBILITY 31 23}
        [event]
            name=moveto

            [filter]
                x,y=31,23
            [/filter]

            [set_achievement]
                content_for=eastern_invasion
                id=ei_S11
            [/set_achievement]
        [/event]

        #------------------
        # IMPRISON PLAYER UNITS
        #------------------
        {MODIFY_UNIT (
            side=1
            [not]
                role=escapee leader
            [/not]
            [not]
                role=escapee sidekick 0
            [/not]
            [not]
                role=escapee sidekick 1
            [/not]
            [not]
                role=escapee sidekick 2
            [/not]
            [not]
                x,y=recall,recall
            [/not]
        ) side 3}

        # dump items in the orcish treasury
        # this is thematic, and also prevents cheese with shield+dacyn and baneblade+gate
#define DROP_ITEM ID PLACE_ITEM
    [if]
        [have_unit]
            trait=TRAIT_{ID}
        [/have_unit]
        [then]
            [remove_trait]
                trait_id=TRAIT_{ID}
            [/remove_trait]
            {PLACE_ITEM}
        [/then]
    [/if]
#enddef
        {DROP_ITEM {ID_HOLY_AMULET_1 } {PLACE_ITEM_HOLY_AMULET {ID_HOLY_AMULET_1} 14 16}}
        {DROP_ITEM {ID_HOLY_AMULET_2 } {PLACE_ITEM_HOLY_AMULET {ID_HOLY_AMULET_2} 16 17}}
        {DROP_ITEM {ID_CRYSTAL_QUIVER} {PLACE_ITEM_CRYSTAL_QUIVER                 17 18}}

        {DROP_ITEM {ID_SENTINEL      } {PLACE_ITEM_SHIELD_OF_THE_SENTINEL 33 11}}
        {DROP_ITEM {ID_BANEBLADE     } {PLACE_ITEM_BANEBLADE              34 11}}
        {DROP_ITEM {ID_PLAGUE_STAFF  } {PLACE_ITEM_PLAGUE_STAFF           34 10}}
#undef DROP_ITEM

        #------------------
        # NO MAINTENANCE COSTS
        #------------------
        # the player's initial units don't cost gold, but other prisoners will
        # it might be smart for the player to avoid freeing some prisoners until just before you escape
        [modify_unit]
            [filter]
                side=1
            [/filter]

            [object]
                duration=scenario
                [effect]
                    apply_to=loyal
                [/effect]
            [/object]
        [/modify_unit]

        #------------------
        # START UNARMED
        #------------------
        [modify_unit]
            [filter]
                side=1,3
                [not]
                    id=Gweddry,Dacyn,Owaec
                [/not]

                [not]
                    x,y=recall,recall
                [/not]
            [/filter]

            [object]
                id=unarmed
                duration=scenario
                [effect]
                    apply_to=remove_attacks

                    [not]
                        name=fire breath
                    [/not]
                [/effect]

                [effect]
                    apply_to=new_attack

                    [filter]
                        [not]
                            trait=strong
                        [/not]
                    [/filter]

                    name=unarmed
                    description= _ "unarmed"
                    icon=attacks/fist-human.png
                    range=melee
                    type=impact
                    damage=4
                    number=3 # same as the merman civilian
                [/effect]

                [effect]
                    apply_to=new_attack

                    [filter]
                        trait=strong
                    [/filter]

                    name=unarmed
                    description= _ "unarmed"
                    icon=attacks/fist-human.png
                    range=melee
                    type=impact
                    range=melee
                    type=impact
                    damage=5
                    number=3 # same as the merman civilian
                [/effect]
            [/object]
        [/modify_unit]

        #------------------
        # STEAL PLAYER'S GOLD
        #------------------
        [store_gold]
            side=1
            variable=gold_amount_S11
        [/store_gold]
        [modify_side]
            side=1
            gold=0
            income=-2
        [/modify_side]
    [/event]

    [event]
        name=start

        [modify_side] # if I do this in the side tag, Dra-Nak doesn't spawn
            side=2
            controller=null
        [/modify_side]

        [message]
            speaker=narrator
            #po: Exactly four units are in this jail cell, identified as "role=escapee ..." in the po hints.
            #po: 3 were in Gweddry's recall list, but escapee sidekick 2 deserted from another Wesnoth commander
            message= _ "Several of Gweddry’s men find themselves locked away in a crude orcish cell."
            image=wesnoth-icon.png
        [/message]
        [message]
            role=escapee sidekick 1
            message= _ "We’ve got to get out of here!"
        [/message]
        [message]
            role=escapee sidekick 2
            #po: Speaker is the male deserter, however the other units don't know his backstory yet
            message= _ "I’m sure your commanders will come and save us!"
        [/message]
        [message]
            role=escapee sidekick 0
            #po: Male speaker talking to male deserter, also the huge enemies changed in 1.17 from trolls to orcs
            message= _ "What? Didn’t you see those huge orcs drag them away? It’s hopeless!"
            #po: Female speaker talking to male deserter, also the huge enemies changed in 1.17 from trolls to orcs
            female_message= _ "female^What? Didn’t you see those huge orcs drag them away? It’s hopeless!"
        [/message]
        [message]
            role=escapee leader
            message= _ "Be quiet, you three! There’s something back here..."
        [/message]
        {MOVE_UNIT role="escapee leader" 22 3}
        [message]
            role=escapee leader
            message= _ "Look! There’s a gap in the wall over here. I think I can slip through if I clear away some of these rocks..."
        [/message]

        [animate_unit]
            [filter]
                role=escapee leader
            [/filter]
            flag=attack
            hits=yes
            [primary_attack]
                range=melee
            [/primary_attack]
            [facing]
                [filter]
                    x,y=21,3
                [/filter]
            [/facing]
        [/animate_unit]

        [sound]
            name=cave-in.ogg
        [/sound]

        {MODIFY_TERRAIN Uu^Dr 21 3}
        [redraw]
        [/redraw]
        [message]
            role=escapee leader
            message= _ "Come on! This way!"
        [/message]
        {MOVE_UNIT (role=escapee leader) 21 3}

        [objectives]
            side=1
            [objective]
                description= _ "Find Gweddry, Dacyn and Owaec"
                condition=win
            [/objective]
            [objective]
                #po: Initially shown with 4 escapees.
                description= _ "Death of the escapees"
                condition=lose
            [/objective]
        [/objectives]
    [/event]

    #------------------
    # HALLWAY EVENTS
    #------------------
    # cell door is locked
    [event]
        name=moveto
        [filter]
            side=1
            x,y=24-25,5
        [/filter]
        [message]
            speaker=unit
            #po: the escapees' cell door
            message= _ "The door won’t open from this side."
        [/message]
    [/event]

    # deserter dialogue
    [event]
        name=enter hex

        [filter]
            side=1
            x,y=16,3-4
        [/filter]

        [event]
            name=new turn
            {STORE_UNIT_VAR (role=escapee sidekick 2) name deserter_name}
            [message]
                role=escapee sidekick 1
                #po: The speaker is male. The deserter, "escapee sidekick 2", will always be male.
                #po: The other escapees, including the speaker, are 3 random units from the player's recall list.
                message= _ "$deserter_name, I don’t recognize you, and you look like you’ve been locked up longer than the rest of us. How did you get here?"
                #po: The speaker is female. The deserter, "escapee sidekick 2", will always be male.
                #po: The other escapees, including the speaker, are 3 random units from the player's recall list.
                female_message= _ "female^$deserter_name, I don’t recognize you, and you look like you’ve been locked up longer than the rest of us. How did you get here?"
            [/message]
            {CLEAR_VARIABLE deserter_name}
            [message]
                role=escapee sidekick 2
                message= _ "When the undead burned Tath, I got... lost. I have family up north, but I didn’t even get across the ford before some orcs captured me. They marched me and many other slaves east along the river, until we arrived here."
            [/message]
            [message]
                role=escapee leader
                #po: The speaker is male
                message= _ "(scowling) A deserter. We should lock you back in your cell."
                #po: The speaker is female
                female_message= _ "female^(scowling) A deserter. We should lock you back in your cell."
            [/message]
            [message]
                role=escapee sidekick 2
                #po: "you" being an audience of three units
                message= _ "No, please, you don’t understand! The undead are everywhere! I didn’t want to die like all my friends..."
            [/message]
        [/event]
    [/event]

    # spawn bats
    [event]
        name=enter hex
        [filter]
            side=1
            x,y=12,4
        [/filter]
        [message]
            speaker=unit
            message= _ "Do you hear something coming from those pits?"
        [/message]

        {GENERIC_UNIT 4 "Vampire Bat" 8 2}
        {GENERIC_UNIT 4 "Vampire Bat" 11 2}
        [message]
            side=4
            race=bats
            message= _ "Neep! Neep!" # wmllint: no spellcheck
        [/message]
        [event]
            name=new turn
            {GENERIC_UNIT 4 "Vampire Bat" 8 2}
        [/event]
    [/event]
    [event]
        name=attack
        [filter]
            race=bats
        [/filter]
        [message]
            speaker=second_unit
            message= _ "Ack! Get away from me!"
        [/message]
    [/event]

    # dead-end tunnel
    [event]
        name=moveto
        [filter]
            side=1
            x,y=1-8,5-8
        [/filter]
        [message]
            speaker=unit
            message= _ "This tunnel seems to go deeper into the caves. We can’t go that way."
        [/message]
    [/event]

    # do the caves go on forever?
    [event]
        name=enter hex

        [filter]
            side=1
            x,y=9,9
        [/filter]

        [event]
            name=new turn
            [message]
                role=escapee sidekick 0
                message= _ "How do we know these caves aren’t all dead ends? We might be stuck wandering until we die of thirst!"
            [/message]
            [message]
                role=escapee leader
                message= _ "You’re welcome to go back to your cell."
            [/message]
        [/event]
    [/event]

    # more wesnoth foreshadowing
    [event]
        name=enter hex

        [filter]
            side=1
            x,y=10-11,14
        [/filter]

        [event]
            name=new turn
            [message]
                role=escapee sidekick 2
                message= _ "Even if we do find your commanders and escape, maybe we should consider staying in the north? It’s tranquil, and quiet.... and there’s no undead..."
            [/message]
            [message]
                role=escapee sidekick 0
                message= _ "I didn’t come all this way just to give up at the words of a deserter!"
            [/message]
            [message]
                role=escapee leader
                message= _ "Let’s focus on escaping the orcs before worrying about the future. Now quiet, I smell something foul up ahead."
            [/message]
        [/event]
    [/event]

    #------------------
    # DON THE DISGUISE
    #------------------
    [event]
        name=moveto

        [filter]
            side=1
            x,y=14-18,13-19
        [/filter]

        [message]
            speaker=unit
            message= _ "Ugh, here’s where that wretched stench is coming from. This must be the orcish storeroom, full of their discarded gear and trash. At least we can find ourselves some proper weapons."
        [/message]
        [remove_object]
            side=1
            object_id=unarmed
        [/remove_object]
        [floating_text]
            x,y=$unit.x,$unit.y
            text= _ "<span color='#00FF00' size='x-small'>weapons restored</span>"
        [/floating_text]
        [sound]
            name=magicmissile.wav
        [/sound]
        [delay]
            time=300
        [/delay]

        [sound]
            name=magicmissile.wav
        [/sound]
        [delay]
            time=300
        [/delay]

        [if]
            {VARIABLE_CONDITIONAL gold_amount_S11 greater_than_equal_to 1}
            [then]
                [message]
                    speaker=unit
                    message= _ "And look, our captured equipment and provisions are here too! I’ve recovered supplies worth $gold_amount_S11 gold."
                [/message]
                [sound]
                    name=gold.ogg
                [/sound]

                [gold]
                    side=1
                    amount=$gold_amount_S11
                [/gold]
            [/then]
        [/if]
    [/event]
    [event]
        name=moveto

        [filter]
            side=1
        [/filter]

        [filter_condition]
            [have_unit]
                race=orc,drake # not goblins or bats!
                [filter_vision]
                    side=1
                [/filter_vision]
            [/have_unit]
        [/filter_condition]

        [redraw]
            side=1
        [/redraw]
        [message]
            speaker=unit
            message= _ "The other prison cells should be to the north of that chamber. If we can get past those guards we could set everyone free."
        [/message]
        [message]
            side=1

            [not]
                x,y=$x1,$y1
            [/not]

            message= _ "But there’s too many of them!"
        [/message]
        [message]
            speaker=unit
            message= _ "Hmm... I have an idea."
        [/message]

        {VARIABLE unit.variables.undercover yes}
        {VARIABLE unit.profile "portraits/disguise.webp"}

        [unstore_unit]
            variable=unit
            find_vacant=no
        [/unstore_unit]

        {MOVE_UNIT id=$unit.id 15 16}
        [sound]
            name=magicmissile.wav
        [/sound]
        [delay]
            time=300
        [/delay]

        [sound]
            name=magicmissile.wav
        [/sound]
        {REMOVE_IMAGE 16 15}
        [redraw]
        [/redraw]
        [delay]
            time=300
        [/delay]

        [sound]
            name=magicmissile.wav
        [/sound]

        [object]
            id=disguise

            [filter]
                id=$unit.id
            [/filter]

            [effect]
                apply_to=image_mod
                add="O(0)~CROP(0,0,72,72)~BLIT(units/orcs/xbowman.png~TC(1,magenta),0,0)"
            [/effect]
        [/object]
        [delay]
            time=300
        [/delay]

        [if]
            [have_unit]
                side=1
                count=2-99
            [/have_unit]

            [then]
                [message]
                    id=$unit.id
                    message= _ "So, how do I look?"
                [/message]
                [message]
                    id=$unit.id
                    message= _ "I’ll try to slip past the guards. You wait here."
                [/message]
            [/then]
        [/if]
    [/event]

    # don't let Chief Dra-Nak rest after Owaec hits him
    [event]
        name=side 2 turn refresh
        first_time_only=no
        {MODIFY_UNIT (id=Chief Dra-Nak) resting no}
    [/event]

    # unshroud the throne room when the disguised character can see it
    [event]
        name=moveto
        [filter]
            side=1
            [filter_location]
                # The disguised character still needs to stay outside the ZoC of all the guards.
                # That leaves two routes to the cells - near the west wall (passing near 23,12),
                # or a loop south and behind the throne (passing near 30,15).
                x=23,30
                y=12,15
                radius=5
            [/filter_location]
        [/filter]
        [remove_shroud]
            side=1
            x=17-36,12-33
            y= 5-18, 7-19
            [and]
                radius=20
            [/and]
            [not]
                terrain=X*
                [filter_adjacent_location]
                    terrain=X*
                    count=6
                [/filter_adjacent_location]
            [/not]
        [/remove_shroud]

        {SCROLL_TO 30 15}
        [message]
            speaker=Chief Dra-Nak
            #po: Gweddry, Dacyn and Owaec are being held by guards in front of Dra-Nak's throne
            message= _ "You’ve been a difficult prize to capture, but well worth the cost! Human corpses may not sell as well as dwarf or drake tribute, but with this many of you, I’ll still fetch a hefty bounty."
        [/message]
        [message]
            speaker=Gweddry
            #po: The nearest guards are orcs, but there are drakes guarding the edge of the room.
            message= _ "Drakes, surely you can see that this orc does not have your best interests at heart? He is bleeding your numbers to fund his empire while your leader stands by and does nothing!"
        [/message]
        [message]
            x,y=28,18 # a drake
            message= _ "I follow the Ways of our Flight.
Mortic is Aspirant.
I serve his will."
        [/message]
        {MOVE_UNIT (id=Chief Dra-Nak) 28 14}
        [animate_unit]
            [filter]
                id=Chief Dra-Nak
            [/filter]

            flag=attack
            hits=yes
            [primary_attack]
                range=melee
            [/primary_attack]
            [facing]
                x,y=27,14
            [/facing]
            [animate]
                [filter]
                    id=Gweddry
                [/filter]

                flag=defend
            [/animate]
        [/animate_unit]
        [message]
            speaker=Chief Dra-Nak
            message= _ "You Wesnothians still don’t get it? These weaklings <i>need</i> me! Before I came, this place was a wasteland, with drake, dwarf, and naga fighting over scraps and bleeding in the snow."
        [/message]
        [message]
            speaker=Chief Dra-Nak
            message= _ "I united them all under my banner, bringing <i>peace</i> and <i>order</i> to these mountains! And once I sell you off, we will have enough money and power to rival even the great tribes of the north. I will usher in a new golden age for my people!"
        [/message]
        [message]
            speaker=Owaec
            message= _ "You murder your allies and call it peace? Bah, this place will only know peace once you are dead!"
        [/message]
        {MOVE_UNIT (id=Owaec) 27 15}
        [animate_unit]
            [filter]
                id=Owaec
            [/filter]

            flag=attack
            hits=yes
            [primary_attack]
                type=impact
            [/primary_attack]
            [facing]
                x,y=28,14
            [/facing]
            [animate]
                [filter]
                    id=Chief Dra-Nak
                [/filter]

                flag=defend
                text="23"
                red=255
            [/animate]
        [/animate_unit]
        [message]
            speaker=Chief Dra-Nak
            #po: Owaec has attacked the orc
            message= _ "Hah, that almost hurt! I’m gonna enjoy shipping you lot down south. Maybe this time, the necromancers will let me watch..."
        [/message]

        {SCROLL_TO 21 16}
        [message]
            speaker=unit
            #po: speaker is the escapee wearing the orc disguise, there are around 10 guards
            message={WHISPER _"Opening the cells should confuse the guards for a moment. But I better not get too close to them..."}
        [/message]

        [objectives]
            side=1
            [objective]
                #po: At least one cell is still locked. There's one with 8 Wesnothians, one with 6 Wesnothians,
                #po: and one containing 4 Wesnothians plus 2 Drakes.
                description= _ "Release the other prisoners"
                condition=win
            [/objective]
            [objective]
                #po: Later shown meaning all of the released prisoners. Some can die, just not all.
                description= _ "Death of the escapees"
                condition=lose
            [/objective]
        [/objectives]
        {TELEPORT_UNIT (id=Chief Dra-Nak) 30 15} {MODIFY_UNIT (id=Chief Dra-Nak) facing nw}
        {TELEPORT_UNIT (id=Owaec)         26 14} {MODIFY_UNIT (id=Owaec)         facing se}
    [/event]

    # expose if you capture a village
    [event]
        name=capture

        [filter]
            side=1
        [/filter]

        [fire_event]
            name=free heroes
        [/fire_event]
    [/event]

    # expose if any undisguised humans get too close to the orcs/drakes
    [event]
        name=enter_hex
        [filter]
            side=1
            x,y=20,17-18
            [filter_wml]
                [not]
                    [variables]
                        undercover=yes
                    [/variables]
                [/not]
            [/filter_wml]
        [/filter]
        [fire_event]
            name=free heroes
        [/fire_event]
    [/event]

    # expose if any unit moves adjacent to an orc/drake
    [event]
        name=moveto
        [filter_condition]
            [have_unit]
                side=1
                [filter_adjacent]
                    race=orc,drake
                [/filter_adjacent]
            [/have_unit]
        [/filter_condition]
        [fire_event]
            name=free heroes
        [/fire_event]
    [/event]

    #------------------
    # LOCK PRISON CELLS
    #------------------
    [event]
        name=explain_upkeep
        [if]
            [have_unit]
                id=Gweddry
                side=3
            [/have_unit]

            [then]
                [message]
                    speaker=unit
                    #po: while the speaker is still in disguise
                    message= _"Here’s one of the prison cells! As soon as I open this, all hell is going to break loose."
                [/message]
            [/then]
        [/if]
        [store_gold]
            side=1
        [/store_gold]
        [if]
            [variable]
                name=gold
                greater_than_equal_to=1
            [/variable]

            [then]
                # if we have gold
                [message]
                    speaker=unit
                    message= _"I’m already well-equipped, but we’ll have to pay upkeep to arm and armor each prisoner I free. I hope we’ll have enough gold left over for the next battle!"
                [/message]
            [/then]
        [/if]
    [/event]

#define LOCK_CELL X Y TERRAIN PRISONER_FILTER FREED_MESSAGE WML
    [event]
        name=moveto
        first_time_only=no

        [filter]
            side=1
            [filter_location]
                x,y={X},{Y}
                radius=1
            [/filter_location]
        [/filter]

        [filter_condition]
            [have_unit]
                {PRISONER_FILTER}
            [/have_unit]
        [/filter_condition]

        [fire_event]
            name=explain_upkeep
            [primary_unit]
                id=$unit.id
            [/primary_unit]
        [/fire_event]
        [message]
            speaker=unit
            #po: prompt to the player
            message= _ "Open the cell?"
            [option]
                #po: choice when prompted "open the cell?"
                label= _ "Yes! <i>(freed units will incur upkeep)</i>"
                [command]
                    [sound]
                        name=open-chest.wav
                    [/sound]

                    {MODIFY_TERRAIN {TERRAIN} {X} {Y}}
                    [redraw]
                    [/redraw]
                    [message]
                        {PRISONER_FILTER}

                        [not]
                            race=drake
                        [/not]

                        message={FREED_MESSAGE}
                    [/message]
                    {MODIFY_UNIT {PRISONER_FILTER} side 1}
                    [remove_object]
                        side=1
                        object_id=unarmed
                    [/remove_object]
                    {WML}
                    [fire_event]
                        name=free heroes
                    [/fire_event]
                [/command]
            [/option]
            [option]
                #po: choice when prompted "open the cell?"
                label= _ "Not yet..."
                [command]
                [/command]
            [/option]
        [/message]
    [/event]
#enddef
    {LOCK_CELL 16 10 (Re^Pr/o) (side,x,y=3,13-16,7-10) _"Huzzah, we’re free at last!" ()} # west cell
    {LOCK_CELL 21 8  (Re^Pr/o) (side,x,y=3,18-22,6-8)  _"Hooray, we’re rescued!" ()} # middle cell
    {LOCK_CELL 28 8  (Re^Pr\o) (side,x,y=3,28-31,6-8) _"Yes! Get us out of here!" (
        # east cell
        [message]
            speaker=Ga'all
            #po: Ga'all and Verash are drakes from S10
            message= _ "I am free!
Never again shall I be prisoner!"
        [/message]
        [message]
            speaker=Verash
            #po: Ga'all and Verash are drakes from S10, this is followed by Verash killing Ga'all
            message= _ "You disobey the Aspirant.
For your treachery,
Your punishment is death."
        [/message]
        {MODIFY_UNIT (id=Verash) side 2}
        [animate_unit]
            [filter]
                id=Verash
            [/filter]
            flag=attack
            hits=yes
            [primary_attack]
                range=melee
            [/primary_attack]
            [facing]
                [filter]
                    x,y=29,7
                [/filter]
            [/facing]
        [/animate_unit]

        {KILL id=Ga'all ANIMATE=yes}
    )}
    [event] # empty cell
        name=moveto

        [filter]
            side=1
            [filter_location]
                x=25,26
                y=7,6
            [/filter_location]
        [/filter]

        [sound]
            name=open-chest.wav
        [/sound]

        {MODIFY_TERRAIN (Re^Pr/o) 25 6}
        [redraw]
        [/redraw]
        [fire_event]
            name=free heroes
        [/fire_event]
    [/event]

    #------------------
    # BATTLE BEGINS
    #------------------
    [event]
        name=free heroes
        [fire_event]
            name=remove disguise
            [primary_unit]
                side=1
                [filter_wml]
                    [variables]
                        undercover=yes
                    [/variables]
                [/filter_wml]
            [/primary_unit]
        [/fire_event]
        {MODIFY_UNIT (id=Gweddry,Dacyn,Owaec) side 1}
        [redraw]
        [/redraw]
        [message]
            speaker=Owaec
            message= _ "The guards are distracted! Let us make our daring escape!"
        [/message]
        [objectives]
            side=1
            [objective]
                description= _ "Move Gweddry, Dacyn, or Owaec to the south-west exit"
                condition=win
            [/objective]
            [objective]
                description= _ "Release the remaining prisoners"
                condition=win
                {BONUS_OBJECTIVE_CAPTION}
                [show_if]
                    [have_unit]
                        side=3
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Gweddry, Dacyn, or Owaec"
                condition=lose
            [/objective]

            [gold_carryover]
                carryover_percentage=100
            [/gold_carryover]
            [note]
                description= _ "Save as much gold as possible for the next scenario!"
            [/note]
        [/objectives]

        [modify_side]
            side=2
            recruit=Orcish Grunt,Orcish Archer
            gold={ON_DIFFICULTY 0 30 60}
        [/modify_side]

        [event]
            name=new turn

            # give gold to the eastern orcs, so they start recruiting
            [modify_side]
                side=5,6
                gold={ON_DIFFICULTY 20 60 100}
                income={ON_DIFFICULTY 3 13 23}
            [/modify_side]
            [event]
                name=new turn
                [event]
                    name=new turn
                    [event]
                        name=new turn
                        [event]
                            name=new turn
                            [event]
                                name=new turn
                                [modify_side] # eventually, give infinite gold to the eastern orcs. It's not supposed to be possible to kill them
                                    side=5,6
                                    gold=99999
                                    recruit=Orcish Warlord,Orcish Slurbow,Orcish Nightblade
                                [/modify_side]
                            [/event]
                        [/event]
                    [/event]
                [/event]
            [/event]

            # show the player that there's orcs in the east
            [event]
                name=new turn

                [message]
                    speaker=Chief Dra-Nak
                    #po: shouted to the two leaders who are positioned outside the orcs' caves, happens 2 turns after the main escape starts
                    #po: combined with removing shroud to reveal that those two leaders recruited last turn (and have full castles on normal or hard)
                    message= _ "The prisoners are escaping! Get in here and stop them!"
                [/message]
                [remove_shroud]
                    side=1
                    x,y=46,11
                    radius=2
                [/remove_shroud]
                [remove_shroud]
                    side=1
                    x,y=46,25
                    radius=2
                [/remove_shroud]
                [message]
                    speaker=Rakkha
                    #po: orc leader who was guarding against external threats sends troops into the orcs' throneroom
                    message= _ "Protect the Chief!"
                [/message]
                [message]
                    speaker=Varrak-Klar
                    #po: orc leader who was guarding against external threats sends troops into the orcs' throneroom
                    message= _ "Into the caves!"
                [/message]
                [if]
                    [have_unit]
                        id=Addogin
                    [/have_unit]

                    [then]
                        [message]
                            speaker=Addogin
                            message= _ "Guess we’re on the run again! My mercenary boys back home woulda made short work o’ these Whitefang punks... I sure am missin’ the Estmarks right about now."
                        [/message]
                    [/then]

                    [else]
                        [message]
                            speaker=Gweddry
                            message= _ "Everyone hurry, we have to get out of here!"
                        [/message]
                    [/else]
                [/if]

                [place_shroud]
                    side=1
                    x,y=46,11
                    radius=2
                [/place_shroud]
                [place_shroud]
                    side=1
                    x,y=46,25
                    radius=2
                [/place_shroud]

                [event]
                    name=new turn
                    [event]
                        name=side 1 turn end
                        [message]
                            speaker=Owaec
                            #po: 3 turns after the main escape starts
                            message= _ "Such carnage in this dark confined cave... how I long to once again gaze upon the rolling plains of my homeland. These lands are cold, but the thought of my fellow Clansmen is as a fire burning in my breast."
                        [/message]
                        [message]
                            speaker=Gweddry
                            #po: "there" being the Horse Clans' plains
                            message= _ "Wesnoth’s best horses and much of Weldyn’s food is come from there. I’m sure it’s well-defended, despite never having visited there myself."
                        [/message]
                        [message]
                            speaker=Owaec
                            #po: "them" being the Horse Clans' plains
                            message= _ "There is naught that I can speak that would truly do them justice! You will have to see the plains yourself to appreciate their majesty."
                        [/message]
                        [message]
                            speaker=Gweddry
                            #po: "them" being the Horse Clans' plains
                            message= _ "Then let us return quickly to Wesnoth to aid in their defense!"
                        [/message]
                    [/event]
                [/event]
            [/event]
        [/event]
    [/event]

    # This event should be fired with the disguised unit as the primary unit, even
    # if indirectly triggered by a name=exposed event on another unit.
    [event]
        name=remove disguise
        [message]
            speaker=Chief Dra-Nak
            #po: Boja is the name of the cave bear
            message= _ "Hey, who are you? Boja, sic ’em!"
        [/message]
        [message]
            speaker=$unit.id
            message= _ "Uh oh!"
        [/message]

        {REPLACE_SCENARIO_MUSIC frantic.ogg}
        {VARIABLE unit.variables.undercover was}
        {CLEAR_VARIABLE unit.profile}

        [foreach]
            array=unit.modifications.object
            [do]
                [if]
                    [variable]
                        name=this_item.id
                        equals=disguise
                    [/variable]
                    [then]
                        {CLEAR_VARIABLE this_item}
                    [/then]
                [/if]
            [/do]
        [/foreach]
        [unstore_unit]
            variable=unit
            find_vacant=no
        [/unstore_unit]

        [modify_side]
            side=2
            controller=ai
        [/modify_side]
    [/event]

    # orcish treasury gold, so even if you didn't save anything, you may still be able to start S12 with a little bit
#define TREASURY_GOLD X Y IMAGE AMOUNT LABEL_TEXT MESSAGE
    {PLACE_IMAGE {IMAGE} {X} {Y}}
    {SET_LABEL {X} {Y} {LABEL_TEXT}}
    [event]
        name=moveto

        [filter]
            side=1
            x,y={X},{Y}
        [/filter]

        {REMOVE_IMAGE $unit.x $unit.y}
        {REMOVE_LABEL $unit.x $unit.y}
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            sound=gold.ogg
            message={MESSAGE}
        [/message]
        [gold]
            side=1
            amount={AMOUNT}
        [/gold]
    [/event]
#enddef
    {TREASURY_GOLD 34 10 "items/gold-coins-small.png" 70 (_"70 gold") (_"You’ve pillaged 70 orcish gold pieces!")}
    {TREASURY_GOLD 35 11 "items/gold-coins-medium.png" 115 (_"115 gold") (_"You’ve pillaged 115 orcish gold pieces!")}

    # this gold pile draws the player's attention to this hex, which is also a great place to hide Dacyn
#ifndef HARD
    {TREASURY_GOLD 30 10 "items/gold-coins-small.png" 20 (_"20 gold") (_"These orcs have a pile of 20 gold pieces!")}
#endif

    #---------------------------
    # RING OF INVISIBILITY
    #---------------------------
    [event]
        name=sighted

        [filter]
            id=Cowardly Goblin
        [/filter]

        {SCROLL_TO 31 21}
        [message]
            speaker=unit
            #po: goblin with a ring of invisibility
            message= _ "Oooh so shiny, my precious... what a great gift from the Chief..."
        [/message]
        [message]
            speaker=unit
            #po: goblin with a ring of invisibility (although not enough sense to wear it when running away)
            message= _ "Aaah! Humans! Run away run away!"
        [/message]
        {MOVE_UNIT (id=Cowardly Goblin) 34 28}
        {KILL (id=Cowardly Goblin)}
        [message]
            speaker=second_unit
            #po: unit who discovered the goblin with a ring of invisibility
            message= _ "Hmm, looks like he dropped something."
        [/message]
    [/event]

    #---------------------------
    # ESCAPE
    #---------------------------
    [event]
        name=moveto
        [filter]
            side=1
            x= 0-7,  8-12,13-16,17,   18,   19,   20,   21,      39,  39,   40,  40,   41,  41,   42,  42,   43-99
            y=17-99,18-99,20-99,24-99,24-99,25-99,25-99,28-99,   0-13,27-29,0-15,27-29,0-16,27-29,0-16,23-99,0-99
            [filter_wml]
                [variables]
                    undercover=yes
                [/variables]
            [/filter_wml]
        [/filter]
        [message]
            speaker=unit
            #po: if the disguised unit runs out of the caves alone, without rescuing any other prisoners
            message= _ "Phew! I made it."
        [/message]
        [message]
            side=1

            [not]
                x,y=$x1,$y1
            [/not]

            #po: if the disguised unit runs out of the caves alone, without rescuing any other prisoners
            message= _ "Where are you going?! Come back!"
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            id=Gweddry,Dacyn,Owaec
            x= 0-7,  8-12,13-16,17,   18,   19,   20,   21,      39,  39,   40,  40,   41,  41,   42,  42,   43-99
            y=17-99,18-99,20-99,24-99,24-99,25-99,25-99,28-99,   0-13,27-29,0-15,27-29,0-16,27-29,0-16,23-99,0-99
        [/filter]
        [message]
            speaker=unit
            #po: One of the main heroes gets outside, triggering the victory condition
            message= _ "I’ve reached the exit! We’ll have to make a run for it!"
        [/message]
        [message]
            side=3
            #po: The player didn’t open all the cells before moving a hero to the exit and triggering the victory event
            message= _ "Wait, you can’t leave us behind!"
        [/message]

        {CLEAR_VARIABLE deserter_name}
        [endlevel]
            result=victory
            bonus=yes
            {NEW_GOLD_CARRYOVER 100}
        [/endlevel]
    [/event]

    {FOREIGN_DEFEAT}

    #---------------------------
    # BOJA AND DRA-NAK DEATHS
    #---------------------------
    [event]
        name=die

        [filter]
            id=Boja
        [/filter]

        [message]
            speaker="Chief Dra-Nak"
            #po: immediate response to Boja's death
            message= _ "You killed my bear, you filthy humans! You’ll pay for that!"
        [/message]

        [event]
            name=side 2 turn refresh # set gold on the refresh, because he'll be losing tons of gold from the auto-spawning reinforcements
            [modify_side]
                side=2
                gold={ON_DIFFICULTY 0 25 50}
            [/modify_side]
        [/event]
        [event]
            name=side 2 turn end
            {MODIFY_UNIT side=2 status.guardian no} # so they charge in
            [modify_unit]
                [filter]
                    id=Chief Dra-Nak
                [/filter]
                canrecruit=no # so he charges in
                [object]
                    [effect]
                        apply_to=overlay
                        add=misc/leader-crown.png
                    [/effect]
                [/object]
            [/modify_unit]
        [/event]
    [/event]
    [event]
        name=last breath

        [filter]
            id=Chief Dra-Nak
        [/filter]

        [message]
            speaker="Chief Dra-Nak"
            #po: last breath event for Chief Dra-Nak
            message= _ "Curse you all! Why couldn’t you have just died as tribute like everyone else? Now my glorious golden Empire will never be..."
        [/message]
        {VARIABLE dra_nak_dead yes}
    [/event]
    [event]
        name=die

        [filter]
            id=Chief Dra-Nak
        [/filter]

        [filter_condition]
            [have_unit]
                type=Gate
                x,y=34,11
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=Gweddry
            #po: die event for Chief Dra-Nak
            message= _ "Look, he was carrying the key to their treasury!"
        [/message]
        {SCROLL_TO 34 11}
        {KILL type,x,y=Gate,34,11} # no animation
        [sound]
            name=gate-fall.ogg
        [/sound]

        {MODIFY_TERRAIN (Isa^Pr|o) 34 11} # show the gate being open, instead of destroyed
        [redraw]
        [/redraw]
    [/event]

    {HERODEATH_GWEDDRY}
    {HERODEATH_DACYN}
    {HERODEATH_OWAEC}
    {HERODEATH_TERRAENT}
    {HERODEATH_DOLBURRAS}
    {HERODEATH_GRUG}
    {HERODEATH_HAHID}
[/scenario]
