#textdomain wesnoth-utbs

# Scenario should work under following assumptions:
# -- Player finds himself on the battlefield between feuding undead.
# -- Undead deploy champions (one each).
# -- Number of tents saved from destruction affects unit cost later in campaign
# -- Character Garak is removed from campaign at this stage.
# -- There is an orc raid in second half.
# -- There is no timeflow, scenario takes place at night.

[scenario]
    id=03_Stirring_in_the_Night
    next_scenario=04_Descending_into_Darkness
    name= _ "A Stirring in the Night"
    {UTBS_MAP 03_A_Stirring_in_the_Night.map}
    {LONGDARK4}
    [+time]
        # po: Use the same translation as for the string in the wesnoth-help textdomain.
        name= _ "The Long Dark"
    [/time]
    # Set initial turns to 12 to give impression that that is how long player needs to
    # survive.
    turns=12
    victory_when_enemies_defeated=no

    {INTRO_AND_SCENARIO_MUSIC "transience.ogg" "the_deep_path.ogg"}
    {EXTRA_SCENARIO_MUSIC "frantic.ogg"}
    {EXTRA_SCENARIO_MUSIC "the_king_is_dead.ogg"}
    {EXTRA_SCENARIO_MUSIC "siege_of_laurelmor.ogg"}

    {STORY_STIRRING_IN_THE_NIGHT}

    # Side 1 elves
    [side]
        side=1
        id=Kaleh
        type=Quenoth Youth
        canrecruit=yes
        controller=human
        recruit=Quenoth Fighter,Tauroch Rider,Quenoth Scout,Quenoth Mystic
        gold=200
        {INCOME 4 2 0}
        {FLAG_VARIANT long}
        user_team_name= _ "team_name^Quenoth Elves"
    [/side]

    # Side 2 undead, starts with pet revenant, Zur
    [side]
        side=2
        id=Azkotep
        name= _ "Azkotep"
        type=Lich
        canrecruit=yes
        controller=ai
        {GOLD 125 150 175}
        {INCOME 15 18 21}

        recruit=Skeleton,Skeleton Archer,Skeleton Rider

        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression 0.9}
            {AI_SIMPLE_ALWAYS_ASPECT caution    0.0}
            {AI_SIMPLE_ALWAYS_ASPECT passive_leader yes}

            {AI_SIMPLE_ALWAYS_ASPECT village_value            0}
            {AI_SIMPLE_ALWAYS_ASPECT scout_village_targeting 0}
            {AI_NO_SCOUTS}
            #!-- Do not target sides 1 and 4, thay are an annoyance not an enemy
            #!-- Unless on HARD of course, death to the living
            [goal]
                value=10
                [criteria]
                    side=3
                [/criteria]
            [/goal]

            [goal]
                value=20
                [criteria]
                    id=Grak
                [/criteria]
            [/goal]

#ifdef HARD
            [goal]
                value=5
                [criteria]
                    side=1
                [/criteria]
            [/goal]

            [goal]
                value=5
                [criteria]
                    side=4
                [/criteria]
            [/goal]
#endif
        [/ai]
        {FLAG_VARIANT undead}
    [/side]

    # Side 3 undead, starts with pet wraith, Grak
    [side]
        side=3
        id=Ystara
        name= _ "Ystara"
        type=Death Knight
        canrecruit=yes
        controller=ai
        {GOLD 125 150 175}
        {INCOME 15 18 21}

        recruit=Vampire Bat,Ghoul,Ghost,Walking Corpse

        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression 0.9}
            {AI_SIMPLE_ALWAYS_ASPECT caution    0.0}
            {AI_SIMPLE_ALWAYS_ASPECT passive_leader yes}
            {AI_SIMPLE_ALWAYS_ASPECT village_value           0}
            {AI_SIMPLE_ALWAYS_ASPECT scout_village_targeting 0}
            {AI_NO_SCOUTS}

            [goal]
                value=10
                [criteria]
                    side=2
                [/criteria]
            [/goal]

            [goal]
                value=20
                [criteria]
                    id=Zur
                [/criteria]
            [/goal]
#ifdef HARD
            [goal]
                value=5
                [criteria]
                    side=1
                [/criteria]
            [/goal]

            [goal]
                value=5
                [criteria]
                    side=4
                [/criteria]
            [/goal]
#endif
        [/ai]
        {FLAG_VARIANT undead}
    [/side]

    # Side 4, Orcish Raiders
    # Raider shouldn’t usually capture the elves' keep, but if they do, they can
    # summon more units.
    [side]
        side=4
        no_leader=yes
        controller=ai

        recruit=Orcish Grunt, Orcish Archer, Goblin Spearman, Orcish Assassin
        shroud=no
        fog=no

        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression 1.0}
            {AI_SIMPLE_ALWAYS_ASPECT caution    0.0}
            {AI_SIMPLE_ALWAYS_ASPECT scout_village_targeting 0}
            {AI_SIMPLE_ALWAYS_ASPECT village_value           0}
        [/ai]
        {FLAG_VARIANT6 ragged}
    [/side]

    {STARTING_VILLAGES 1 30}

#define VILLAGE_CONTROL_OBJECTIVE
    [objective]
        description= _ "You lose control (even temporarily) of more than 6 villages"
        condition=lose
    [/objective]
#enddef
#define DEFEAT_AZKOTEP_OBJECTIVE
    [objective]
        description= _ "Defeat Azkotep"
        condition=win
    [/objective]
#enddef
#define DEFEAT_YSTARA_OBJECTIVE
    [objective]
        description= _ "Defeat Ystara"
        condition=win
    [/objective]
#enddef
#define HERO_DEATH_OBJECTIVE
    [objective]
        description= _ "Death of Kaleh"
        condition=lose
    [/objective]

    [objective]
        description= _ "Death of Nym"
        condition=lose
    [/objective]

    [objective]
        description= _ "Death of Zhul"
        condition=lose
    [/objective]
#enddef

    #! -- setting up objectives,variables and map objects sets
    #! -- variables : $ambush_turn, $sneak_up, $elven_camps,
    #! -- $killed_by_azkotep, $killed_by_ystara, $grak_defeated,
    #! -- $zur_defeated
    [event]
        name=prestart

        # set starting scenario objectives
        [objectives]
            summary= _ "Starting Objectives:"
            [objective]
                description= _ "Survive until dawn"
                condition=win
                show_turn_counter=yes
            [/objective]
            [objective]
                {ALTERNATIVE_OBJECTIVE_CAPTION}
                description= _ "Defeat all undead leaders"
                condition=win
            [/objective]
            {VILLAGE_CONTROL_OBJECTIVE}
            [objective]
                description= _ "Death of Kaleh"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Nym"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Garak"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Zhul"
                condition=lose
            [/objective]

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

        #recall heroes
        [recall]
            id=Nym
        [/recall]

        [recall]
            id=Elyssa
        [/recall]

        [recall]
            id=Zhul
        [/recall]

        [recall]
            id=Garak
        [/recall]

        [recall]
            id=Dust Devil
        [/recall]

        [item]
            x=14
            y=10
            halo=halo/fire-aura.png
        [/item]

        [item]
            x=16
            y=15
            halo=halo/fire-aura.png
        [/item]

        [item]
            x=13
            y=20
            halo=halo/fire-aura.png
        [/item]

        {VARIABLE sneak_up 0}
        {VARIABLE killed_by_azkotep 0}
        {VARIABLE killed_by_ystara 0}
        {VARIABLE grak_defeated 0}
        {VARIABLE zur_defeated 0}
        {VARIABLE defiant_death 0}

        # Time Areas correspond with halos around campfires
        [time_area]
            x=14,16,13
            y=10,15,20
            id=campfires
            radius=2
            {DAWN}
            [+time]
                # po: Use the same translation as for the string in the wesnoth-help textdomain.
                name= _ "The Long Dark"
                image=misc/time-schedules/after-the-fall/15longdark4.png~BLIT(misc/tod-bright.png)
            [/time]
        [/time_area]
    [/event]

    # Start of scenario event. It sets up
    # initial undead units and plays intro dialogue

    [event]
        name=start

#ifdef EASY
        {NAMED_NOTRAIT_UNIT 2 (Revenant) 20 22 (Zur)  ( _ "Zur") }
        {NAMED_NOTRAIT_UNIT 3 (Wraith)   22  7 (Grak) ( _ "Grak")}

        # On medium and hard change champions type to more menacing
        # and give them some help

#else
        {NOTRAIT_UNIT 2 (Skeleton Rider) 20 23}
        {NOTRAIT_UNIT 2 (Skeleton Rider) 21 23}
        {NOTRAIT_UNIT 3 (Necrophage) 22 6}
        {NOTRAIT_UNIT 3 (Necrophage) 23 7}
#endif

#ifdef NORMAL
        {NAMED_NOTRAIT_UNIT 2 (Deathblade) 20 22 (Zur)  (_"Zur") }
        {NAMED_NOTRAIT_UNIT 3 (Wraith)     22  7 (Grak) (_"Grak")}
#endif

#ifdef HARD
        {NAMED_NOTRAIT_UNIT 2 (Draug)      20 22 (Zur)  (_"Zur") }
        {NAMED_NOTRAIT_UNIT 3 (Spectre) 22  7 (Grak) (_"Grak")}
#endif

        # give the champs an icon so they stand out, but make it gray since they are not loyal
        [modify_unit]
            [filter]
                id=Grak,Zur
            [/filter]
            overlays=misc/loyal-icon.png~GS()
        [/modify_unit]
        [message]
            speaker=Nym
            message= _ "Kaleh, wake up! Sentries report movement in the sands!"
        [/message]
        [message]
            speaker=Kaleh
            message= _ "Orcs?"
        [/message]
        [message]
            speaker=Nym
            message= _ "I don’t..."
        [/message]
        [message]
            speaker=Azkotep
            message= _ "We meet again, Ystara."
        [/message]
        [message]
            speaker=Ystara
            message= _ "You think you can take me, Azkotep?"
        [/message]
        [message]
            speaker=Azkotep
            message= _ "My champion, Zur shall slice you to shreds like the puny adept you once were."
        [/message]
        [message]
            speaker=Ystara
            message= _ "You always were an arrogant little bastard. Grak will swallow your soul, or what’s left of it."
        [/message]
        [message]
            speaker=Azkotep
            message= _ "You spurned me once and I will make you pay. To battle, my minions! Become my wrath!"
        [/message]
        [message]
            speaker=Nym
            message= _ "... think so. You really know how to pick a campsite, Kaleh."
        [/message]
        [message]
            speaker=Kaleh
            message= _ "Where did they come from? I swear those castles weren’t there at sunset."
        [/message]
        [message]
            speaker=Zhul
            message= _ "Many strange things can happen during the long dark. But despite their wraith-like forms, I have no doubt that their cold steel can still bite flesh."
        [/message]
        [message]
            speaker=Elyssa
            message= _ "Like I haven’t killed enough undead recently. Why can’t these guys just stay dead?"
        [/message]
        [message]
            speaker=Garak
            message= _ "Our encampment is out of the direct line of attack, so we should be somewhat safe, at least."
        [/message]
        [message]
            speaker=Zhul
            message= _ "But if the battle spills around our people will be slaughtered by the undead hordes!"
        [/message]
        [message]
            speaker=Kaleh
            message= _ "There’s no way we can escape the battle in time. We must protect the camp from the undead."
        [/message]
        [message]
            speaker=Zhul
            message= _ "I fear that if we lose more than half of the tents we will not have the strength to go on. Garak, wake your men. We must hold off the undead until dawn."
        [/message]
        [message]
            speaker=Kaleh
            message= _ "To arms my people, to arms!"
        [/message]
    [/event]

    # At the end of the initial dialogue Kaleh raises a war cry,
    # some elves will wake up and respond
    # Recall a random number of troops among the tents to make the
    # glorious victory achieveable on harder levels.
    # Internal variables: $tents, $rally_chance, $i

    [event]
        name=turn 1

        [store_villages]
            variable=tents
        [/store_villages]

        {VARIABLE rally_chance {ON_DIFFICULTY 70 50 30}}

        [foreach]
            array=tents
            [do]
                {RANDOM 0..100}
                {VARIABLE_OP random sub $this_item.y}
                [if]
                    [variable]
                        name=random
                        less_than=$rally_chance
                    [/variable]

                    [then]
                        [recall]
                            side=1
                            x=$this_item.x
                            y=$this_item.y
                        [/recall]
                        {VARIABLE_OP rally_chance sub 3}
                    [/then]
                [/if]
            [/do]
        [/foreach]
        {CLEAR_VARIABLE tents}
        {CLEAR_VARIABLE rally_chance}

        # depending on what units rally, and where, player can lose a village to the north champion purely to RNG, this scout can block that without being too wonderful otherwise
#ifndef HARD
        [recall]
            type=Quenoth Scout
            x,y=16,14
            facing=se
        [/recall]
        [if]
            [have_unit]
                x,y=16,14
            [/have_unit]
            [else]
                [unit]
                    type=Quenoth Scout
                    side=1
                    x,y=16,14
                    facing=se
                [/unit]
            [/else]
        [/if]
#endif
    [/event]

    # The first capture of an elven_camp has some speech
    [event]
        name=capture
        first_time_only=yes
        [filter]
            side=2,3
        [/filter]

        [message]
            speaker=Nym
            message= _ "They’re raising the corpses of our fallen! What a horrible fate!"
            image=portraits/nym_moody.png
        [/message]
        [message]
            speaker=Elyssa
            message= _ "Then we shall have to give them a proper cremation."
        [/message]
    [/event]

    # Count destroyed tents, each lost makes future scenarios harder
    # Includes defeat by loss of tents
    # Affects variables : $elven_camps
    # Each tent lost to undead spawns a WC
    [event]
        name=prestart

        [store_villages]
            variable=camps
        [/store_villages]

        # give player villages to protect
        {VARIABLE elven_camps $camps.length}

        #This generates and stores an event for every camp.
        #That way we can avoid to store information about each village
        #by using the first_time_only feature.
        [foreach]
            array=camps
            [do]
                [set_variables]
                    name=camp_event
                    mode=replace
                    [value]
                        name=capture
                        first_time_only=yes
                        [filter]
                            side=2,3,4
                            x=$this_item.x
                            y=$this_item.y
                        [/filter]

                        [if]
                            [variable]
                                name=unit.side
                                equals=2
                            [/variable]
                            [or]
                                [variable]
                                    name=unit.side
                                    equals=3
                                [/variable]
                            [/or]
                            [then]
#ifdef HARD
                                {NOTRAIT_UNIT $|unit.side (Soulless) $|x1 $|y1}
#endif
#ifdef NORMAL
                                {RANDOM (Walking Corpse,Soulless)}
                                {NOTRAIT_UNIT $|unit.side $|random $|x1 $|y1}
#endif
#ifdef EASY
                                {NOTRAIT_UNIT $|unit.side (Walking Corpse) $|x1 $|y1}
#endif
                            [/then]
                        [/if]

                        [gold]
                            amount={ON_DIFFICULTY 10 20 30}
                            side=$|unit.side
                        [/gold]

                        {VARIABLE_OP elven_camps sub 1}

                        [if]
                            [variable]
                                name=elven_camps
                                equals=5
                            [/variable]
                            [then]
                                [message]
                                    speaker=Kaleh
                                    message= _ "Too many of our people have been killed. We will surely be overwhelmed by the undead now. All is lost!"
                                [/message]

                                [endlevel]
                                    result=defeat
                                [/endlevel]
                            [/then]
                        [/if]
                    [/value]
                [/set_variables]
                [insert_tag]
                    name=event
                    variable=camp_event
                [/insert_tag]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE camps}
        {CLEAR_VARIABLE camp_event}
    [/event]

    # Instead with providing AI with higher lvl units on medium
    # and hard give it highly experienced lvl1's

#ifndef EASY
    # Change the difficulty increase model from having computer
    # recruit some lvl2 and 3 units outright to advancing or
    # half-advancing recruited lvl 1. At the same time, guarantees
    # broader spectrum of opposing units, as AI advancement is random.
    # Internal variables : $factor
    [event]
        name=recruit
        first_time_only=no
        [filter]
            side=2,3,4
        [/filter]

        {VARIABLE min_experience "$(floor($unit.max_experience * {ON_DIFFICULTY 0 0.5 0.75}))"}
        {RANDOM "$min_experience..$($unit.max_experience - 1)"}
        {VARIABLE unit.experience $random}
        [unstore_unit]
            variable=unit
        [/unstore_unit]
        {CLEAR_VARIABLE min_experience,random}
    [/event]
#endif

    # If opposing champion wasn't attacked by the player yet Garak
    # can issue a challenge. Sffects variables : $grak_defeated,
    # $zur_defeated
    # Inform the player about the possibility of challenge and
    # adjust Garak accordingly. Perform the challenge, set the
    # death events where required. Internal variables :
    # $garak_x, $garak_y, $challenged
    [event]
        name=turn 2
        [message]
            speaker=Garak
            message=_"These champions... I will challenge them. Zhul, bless my weapons with light of Eloh."
        [/message]
        [message]
            speaker=Zhul
            message=_"Garak, but the suns..."
        [/message]
        [message]
            speaker=Kaleh
            message=_"You will not do any such thing, anyone trying to fight these creeps singlehanded will surely die. We need you, we will not make it without you."
        [/message]
        [message]
            speaker=Garak
            message=_"I had dreams this night Kaleh, full of gloom and darkness, my journey will end here one way or another."
        [/message]
        [message]
            speaker=Kaleh
            message=_"No! That’s not true, our future is what we make of it, stay behind for this fight and..."
        [/message]
        [message]
            speaker=Garak
            message=_"And what? You’ll help me become a coward? I lived long, I’m not afraid of the end, just let me give it some meaning."
        [/message]
        [message]
            speaker=Zhul
            message=_"I bless you with the light that will come, I bless you with the memory and the promise. Lay down your shield, champion, and let your blade shine in the dark."
        [/message]
        [object]
            id=Garak_vow
            silent=yes
            [filter]
                id=Garak
            [/filter]
            [effect]
                apply_to=remove_attacks
                range=ranged
            [/effect]
            [effect]
                apply_to=new_ability
                [abilities]
                    {ABILITY_STEADFAST}
                [/abilities]
            [/effect]
            [effect]
                apply_to=attack
                range=melee
                [set_specials]
                    [berserk]
                        id=berserk
                        name= _ "righteous rage"
                        name_inactive=""
                        description= _ "Whether used offensively or defensively, this attack presses the engagement until one of the champions is slain, or 30 rounds of attacks have occurred."
                        value=30
                        [filter_opponent]
                            id=Grak,Zur
                        [/filter_opponent]
                    [/berserk]
#ifndef HARD
                    [chance_to_hit]
                        id=magical
                        name= _ "true strike"
                        name_inactive=""
                        description= _ "This attack always has a 70% chance to hit regardless of the defensive ability of the champion being attacked."
                        value=70
                        cumulative=no
                        [filter_opponent]
                            id=Grak,Zur
                        [/filter_opponent]
                    [/chance_to_hit]
#endif
                    mode=append
                [/set_specials]
            [/effect]
            [effect]
                apply_to=attack
                range=melee
                # the type=blade is needed in case Garak picked up the holy
                # water in the second scenario - in that case he gets to keep it
                type=blade
                set_type=fire
            [/effect]
        [/object]
    [/event]

    [event]
        name=attack
        first_time_only=no
        [filter]
            id=Garak,Grak,Zur
        [/filter]
        [filter_second]
            id=Garak,Grak,Zur
        [/filter_second]

        # Identify who was challenged
        # could be none if Zur fights Grak
        [if]
            [variable]
                name=unit.id
                equals=Garak
            [/variable]
            [then]
                {VARIABLE challenged $second_unit.id}
            [/then]
            [else]
                [if]
                    [variable]
                        name=second_unit.id
                        equals=Garak
                    [/variable]
                    [then]
                        {VARIABLE challenged $unit.id}
                    [/then]
                [/if]
            [/else]
        [/if]

        # if Zur or Grak is challenged, display appropriate dialog
        [if]
            [variable]
                name=challenged
                equals=Grak
            [/variable]
            [then]
                [message]
                    speaker=Garak
                    message=_"You there! Creep! Stand and face me, shade! I challenge you!"
                [/message]
                [if]
                    [variable]
                        name=zur_defeated
                        equals=0
                    [/variable]
                    [then]
                        [message]
                            speaker=Grak
                            message=_"Foolish mortal... For daring to challenge me, I’ll devour your soul and torment it for all eternity..."
                        [/message]
                    [/then]
                    [else]
                        [message]
                            speaker=Grak
                            message=_"So you destroyed Zur... Come mortal, let’s cross our blades... It’s time for you to take his place..."
                        [/message]
                    [/else]
                [/if]
                [event]
                    name=die
                    [filter]
                        id=Grak
                    [/filter]
                    {VARIABLE grak_defeated 1}
                [/event]
            [/then]
            [else]
                [if]
                    [variable]
                        name=challenged
                        equals=Zur
                    [/variable]
                    [then]
                        [message]
                            speaker=Garak
                            message=_"You there! Pile of bones! I challenge you, stand and face me!"
                        [/message]
                        [if]
                            [variable]
                                name=grak_defeated
                                equals=0
                            [/variable]
                            [then]
                                [message]
                                    speaker=Zur
                                    message=_"Puny elf... Time to die..."
                                [/message]
                            [/then]
                            [else]
                                [message]
                                    speaker=Zur
                                    message=_"Grak was weak... But still you deserve respect... Meet my axe and take his place..."
                                [/message]
                            [/else]
                        [/if]
                        [event]
                            name=die
                            [filter]
                                id=Zur
                            [/filter]
                            {VARIABLE zur_defeated 1}
                        [/event]
                    [/then]
                [/if]
            [/else]
        [/if]

        {CLEAR_VARIABLE challenged}
    [/event]

    [event]
        name=die
        [filter]
            id=Garak
        [/filter]
        [filter_second]
            id=Grak,Zur
        [/filter_second]
        [message]
            speaker=$second_unit.id
            message=_"And so it ends... Your champion is dead, elves... Come join him..."
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id=Garak
        [/filter]
        [filter_second]
            [not]
                id=Grak,Zur
            [/not]
        [/filter_second]
        [message]
            speaker=Kaleh
            message=_"Where is Garak? Has anybody seen him?"
        [/message]
        [message]
            speaker=Zhul
            message=_"I saw him jumping into deep darkness pursuing a group of enemies. Let’s hope nothing happened to him."
        [/message]
    [/event]

    # If challenge didn't happen by turn 12 and bad guy dies, Garak
    # gets possessed. Sets variable : $ElvishGarak, $defiant_death
    # Depends on variables : $grak_defeated, $zur_defeated,
    # $azkotep_casualties[], $ystara_casualties[],
    # $killed_by_azkotep, $killed_by_ystara clears variables :
    # $azkotep_casualties[], $ystara_casualties[],
    # $killed_by_azkotep, $killed_by_ystara

    # Turn 12
    # -- The sun should rise, it won't need dialogue
    # --If both bad guys alive -> kill Garak -> replace with zombie
    #   If champion not killed in a duel else just kill
    # --If one alive && his champion not killed in a duel ->
    #   kill Garak, place fallen one -> else just kill
    # --If both died it will not be invoked
    # Internal variables : $choice_flag, $i
    [event]
        name=turn 12

        {VARIABLE choice_flag 0}

        [if]
            [have_unit]
                id=Azkotep
            [/have_unit]
            [then]
                {VARIABLE_OP choice_flag add 1000}
            [/then]
        [/if]
        [if]
            [have_unit]
                id=Ystara
            [/have_unit]
            [then]
                {VARIABLE_OP choice_flag add 100}
            [/then]
        [/if]
        {VARIABLE_OP grak_defeated multiply 10}
        {VARIABLE_OP choice_flag add $grak_defeated}
        {VARIABLE_OP grak_defeated divide 10}
        {VARIABLE_OP choice_flag add $zur_defeated}

        [message]
            speaker=Nym
            message= _"Look, dawn is nigh, our salvation is almost at hand. Even the long dark can’t last forever, and with the light of the sun the undead power wanes and their dark magics unravel."
        [/message]

        # Garak will die - store him for resurrection dialogs.
        [store_unit]
            [filter]
                id=Garak
            [/filter]
            variable=ElvishGarak
            kill=no
        [/store_unit]

        [if]
            [variable]
                name=choice_flag
                equals=1111
            [/variable]
            [then]
                [message]
                    speaker=Ystara
                    message= _ "No! This contest is not over yet, Azkotep. I shall show you a taste of my true power."
                [/message]

                [kill]
                    id=Ystara
                    animate=yes
                    fire_event=no
                [/kill]
                [kill]
                    id=Garak
                    animate=yes
                    fire_event=no
                [/kill]
                {NAMED_NOTRAIT_UNIT 2 (Corrupted Quenoth Elf) $ElvishGarak.x $ElvishGarak.y (Possessed Garak) ( _ "Possessed Garak")}
                [fire_event]
                    name=garak_resists
                [/fire_event]
                [message]
                    speaker=Azkotep
                    message= _"No! How dare you? I shall have my vengeance upon you for spoiling this contest! Darkness shall reign until I have triumphed!"
                [/message]
                [message]
                    speaker=Nym
                    message= _ "Maybe I spoke too soon. Curse Uria, he has even blotted out the stars, all is darkness. Kaleh, our course is clear, we must destroy that abomination."
                    image=portraits/nym_moody.png
                [/message]
                [objectives]
                    summary= _ "New Objectives:"
                    silent=no
                    {DEFEAT_AZKOTEP_OBJECTIVE}
                    {VILLAGE_CONTROL_OBJECTIVE}
                    {HERO_DEATH_OBJECTIVE}

                    [gold_carryover]
                        carryover_percentage=40
                    [/gold_carryover]
                [/objectives]
                {VARIABLE defiant_death 1}
            [/then]
        [/if]
        [if]
            [variable]
                name=choice_flag
                equals=1110
            [/variable]
            [then]
                [message]
                    speaker=Azkotep
                    message= _ "No, I shall have my revenge. I shall show you that darkness is strongest just before dawn. Death and decay, grant me my vengeance!"
                [/message]
                [message]
                    speaker=Ystara
                    message= _ "In this I shall support you, the darkness will not lift until one of us is victorious."
                [/message]

                [kill]
                    id=Azkotep
                    animate=yes
                    fire_event=no
                [/kill]
                [kill]
                    id=Garak
                    animate=yes
                    fire_event=no
                [/kill]
                [modify_side]
                    side=1
                    shroud=yes
                    reset_maps=yes
                [/modify_side]
                {NAMED_NOTRAIT_UNIT 2 (Corrupted Quenoth Elf) 21 24 (Possessed Garak) ( _ "Possessed Garak")}
                [fire_event]
                    name=create_garak_minions_azkotep
                [/fire_event]
                [fire_event]
                    name=garak_gloats
                [/fire_event]
                [message]
                    speaker=Nym
                    message= _ "Maybe I spoke too soon. Curse Uria, they have even blotted out the stars, all is darkness. Kaleh, our course is clear, we must destroy one of these abominations. Whether it be the thing that has taken our friend, or the spectral evil that remains, one of them must die for this battle to end. We have no choice."
                    image=portraits/nym_moody.png
                [/message]
                [message]
                    speaker=Zhul
                    message= _ "But to kill Garak? How can we?"
                [/message]
                [message]
                    speaker=Kaleh
                    message= _ "That thing is not Garak. This night has lasted long enough, and too many of our people have died. How many more would you sacrifice for Garak’s sake? Just protecting our encampments isn’t enough, darkness and chaos will overwhelm us if we can’t end this battle soon. We must destroy one of those two evils, whatever the cost. I do not intend to let that... thing keep control of the body of our friend."
                [/message]
                [message]
                    speaker=Ystara
                    message= _ "The stench of death is in the air."
                [/message]
                [message]
                    speaker=Possessed Garak
                    message= _ "Yes, let us end this once and for all."
                [/message]
                [objectives]
                    summary= _ "New Objectives:"
                    silent=no
                    [objective]
                        description=_"Defeat Possessed Garak"
                        condition=win
                    [/objective]
                    {DEFEAT_YSTARA_OBJECTIVE}
                    [+objective]
                        {ALTERNATIVE_OBJECTIVE_CAPTION}
                    [/objective]
                    {VILLAGE_CONTROL_OBJECTIVE}
                    {HERO_DEATH_OBJECTIVE}

                    [gold_carryover]
                        carryover_percentage=40
                    [/gold_carryover]
                [/objectives]
            [/then]
        [/if]
        [if]
            [variable]
                name=choice_flag
                equals=1101
            [/variable]
            [or]
                [variable]
                    name=choice_flag
                    equals=1100
                [/variable]
            [/or]
            [then]
                [message]
                    speaker=Ystara
                    message= _ "No, I shall have my revenge. I shall show you that darkness is strongest just before dawn. Death and decay, grant me my vengeance!"
                [/message]
                [message]
                    speaker=Azkotep
                    message= _ "In this I shall support you, the darkness shall not break until one of us is victorious."
                [/message]

                [kill]
                    id=Ystara
                    animate=yes
                    fire_event=no
                [/kill]
                [kill]
                    id=Garak
                    animate=yes
                    fire_event=no
                [/kill]
                [redraw]
                    side=1
                [/redraw]
                [modify_side]
                    side=1
                    shroud=yes
                    reset_maps=yes
                [/modify_side]
                {NAMED_NOTRAIT_UNIT 3 (Corrupted Quenoth Elf) 23 6 (Possessed Garak) ( _ "Possessed Garak")}
                [fire_event]
                    name=create_garak_minions_ystara
                [/fire_event]
                [fire_event]
                    name=garak_gloats
                [/fire_event]
                [message]
                    speaker=Nym
                    message= _ "Maybe I spoke too soon. Curse Uria, they have even blotted out the stars, all is darkness. Kaleh, our course is clear, we must destroy one of these abominations. Whether it be the thing that has taken our friend, or the spectral evil that remains, one of them must die for this battle to end. We have no choice."
                    image=portraits/nym_moody.png
                [/message]
                [message]
                    speaker=Zhul
                    message= _ "But to kill Garak? How can we?"
                [/message]
                [message]
                    speaker=Kaleh
                    message= _ "That thing is not Garak. This night has lasted long enough, and too many of our people have died. How many more would you sacrifice for Garak’s sake? Just protecting our encampments isn’t enough, darkness and chaos will overwhelm us if we can’t end this battle soon. We must destroy one of those two evils, whatever the cost. I do not intend to let that... thing keep control of the body of our friend."
                [/message]
                [message]
                    speaker=Azkotep
                    message= _ "The stench of death is in the air."
                [/message]
                [message]
                    speaker=Possessed Garak
                    message= _ "Yes, let us end this once and for all."
                [/message]
                [objectives]
                    summary= _ "New Objectives:"
                    silent=no
                    [objective]
                        description=_"Defeat Possessed Garak"
                        condition=win
                    [/objective]
                    {DEFEAT_AZKOTEP_OBJECTIVE}
                    [+objective]
                        {ALTERNATIVE_OBJECTIVE_CAPTION}
                    [/objective]
                    {VILLAGE_CONTROL_OBJECTIVE}
                    {HERO_DEATH_OBJECTIVE}

                    [gold_carryover]
                        carryover_percentage=40
                    [/gold_carryover]
                [/objectives]
            [/then]
        [/if]
        [if]
            [variable]
                name=choice_flag
                equals=1010
            [/variable]
            [or]
                [variable]
                    name=choice_flag
                    equals=1011
                [/variable]
            [/or]
            [then]
                [message]
                    speaker=Ystara
                    message= _ "No! This contest is not over yet, Azkotep. I shall show you a taste of my true power."
                [/message]

                [kill]
                    id=Garak
                    animate=yes
                    fire_event=no
                [/kill]
                {NAMED_NOTRAIT_UNIT 2 (Corrupted Quenoth Elf) $ElvishGarak.x $ElvishGarak.y (Possessed Garak) ( _ "Possessed Garak")}
                [fire_event]
                    name=garak_resists
                [/fire_event]
                [message]
                    speaker=Azkotep
                    message= _"No! How dare you! I shall have my vengeance upon you for spoiling this contest! Darkness shall reign until I have triumphed!"
                [/message]
                [message]
                    speaker=Nym
                    message= _ "Maybe I spoke too soon. Curse Uria, he has even blotted out the stars, all is darkness. Kaleh, our course is clear, we must destroy that abomination."
                    image=portraits/nym_moody.png
                [/message]
                [objectives]
                    summary= _ "New Objectives:"
                    silent=no
                    {DEFEAT_AZKOTEP_OBJECTIVE}
                    {VILLAGE_CONTROL_OBJECTIVE}
                    {HERO_DEATH_OBJECTIVE}

                    [gold_carryover]
                        carryover_percentage=40
                    [/gold_carryover]
                [/objectives]
                {VARIABLE defiant_death 1}
            [/then]
        [/if]
        [if]
            [variable]
                name=choice_flag
                equals=1001
            [/variable]
            [or]
                [variable]
                    name=choice_flag
                    equals=1000
                [/variable]
            [/or]
            [then]
                [kill]
                    id=Garak
                    animate=yes
                    fire_event=no
                [/kill]
                [modify_side]
                    side=1
                    shroud=yes
                    reset_maps=yes
                [/modify_side]
                {NAMED_NOTRAIT_UNIT 3 (Corrupted Quenoth Elf) 23 6 (Possessed Garak) ( _ "Possessed Garak")}
                [fire_event]
                    name=create_garak_minions_ystara
                [/fire_event]
                [fire_event]
                    name=garak_gloats
                [/fire_event]
                [message]
                    speaker=Possessed Garak
                    message= _ "I told you, I will be back, you fools! Now I shall have my vengeance upon you all. Darkness shall reign until I have triumphed!"
                [/message]
                [message]
                    speaker=Azkotep
                    message= _ "In this I shall support you, the darkness shall not lift until one of us is victorious."
                [/message]
                [message]
                    speaker=Nym
                    message= _ "Maybe I spoke too soon. Curse Uria, they have even blotted out the stars, all is darkness. Kaleh, our course is clear, we must destroy one of these abominations. Whether it be the thing that has taken our friend, or the spectral evil that remains, one of them must die for this battle to end. We have no choice."
                    image=portraits/nym_moody.png
                [/message]
                [message]
                    speaker=Zhul
                    message= _ "But to kill Garak? How can we?"
                [/message]
                [message]
                    speaker=Kaleh
                    message= _ "That thing is not Garak. This night has lasted long enough, and too many of our people have died. How many more would you sacrifice for Garak’s sake? Just protecting our encampments isn’t enough, darkness and chaos will overwhelm us if we can’t end this battle soon. We must destroy one of those two evils, whatever the cost. I do not intend to let that... thing keep control of the body of our friend."
                [/message]
                [message]
                    speaker=Azkotep
                    message= _ "The stench of death is in the air."
                [/message]
                [message]
                    speaker=Possessed Garak
                    message= _ "Yes, let us end this once and for all."
                [/message]
                [objectives]
                    summary= _ "New Objectives:"
                    silent=no
                    [objective]
                        description=_"Defeat Possessed Garak"
                        condition=win
                    [/objective]
                    {DEFEAT_AZKOTEP_OBJECTIVE}
                    [+objective]
                        {ALTERNATIVE_OBJECTIVE_CAPTION}
                    [/objective]
                    {VILLAGE_CONTROL_OBJECTIVE}
                    {HERO_DEATH_OBJECTIVE}

                    [gold_carryover]
                        carryover_percentage=40
                    [/gold_carryover]
                [/objectives]
            [/then]
        [/if]
        [if]
            [variable]
                name=choice_flag
                equals=101
            [/variable]
            [or]
                [variable]
                    name=choice_flag
                    equals=111
                [/variable]
            [/or]
            [then]
                [message]
                    speaker=Azkotep
                    message= _ "No, I shall have my revenge. I shall show you that darkness is strongest just before dawn. Death and decay, grant me my vengeance!"
                [/message]
                [kill]
                    id=Azkotep
                    animate=yes
                    fire_event=no
                [/kill]
                [kill]
                    id=Garak
                    animate=yes
                    fire_event=no
                [/kill]
                {NAMED_NOTRAIT_UNIT 2 (Corrupted Quenoth Elf) $ElvishGarak.x $ElvishGarak.y (Possessed Garak) ( _ "Possessed Garak")}
                [fire_event]
                    name=garak_resists
                [/fire_event]
                [message]
                    speaker=Ystara
                    message= _"No! How dare you! I shall have my vengeance upon you for spoiling this contest! Darkness shall reign until I have triumphed!"
                [/message]
                [message]
                    speaker=Nym
                    message= _ "Maybe I spoke too soon. Curse Uria, she has even blotted out the stars, all is darkness. Kaleh, our course is clear, we must destroy that abomination."
                    image=portraits/nym_moody.png
                [/message]
                [objectives]
                    summary= _ "New Objectives:"
                    silent=no
                    {DEFEAT_YSTARA_OBJECTIVE}
                    {VILLAGE_CONTROL_OBJECTIVE}
                    {HERO_DEATH_OBJECTIVE}

                    [gold_carryover]
                        carryover_percentage=40
                    [/gold_carryover]
                [/objectives]
                {VARIABLE defiant_death 1}
            [/then]
        [/if]
        [if]
            [variable]
                name=choice_flag
                equals=110
            [/variable]
            [or]
                [variable]
                    name=choice_flag
                    equals=100
                [/variable]
            [/or]
            [then]
                [kill]
                    id=Garak
                    animate=yes
                    fire_event=no
                [/kill]
                [modify_side]
                    side=1
                    shroud=yes
                    reset_maps=yes
                [/modify_side]
                {NAMED_NOTRAIT_UNIT 2 (Corrupted Quenoth Elf) 21 24 (Possessed Garak) ( _ "Possessed Garak")}
                [fire_event]
                    name=create_garak_minions_azkotep
                [/fire_event]
                [fire_event]
                    name=garak_gloats
                [/fire_event]
                [message]
                    speaker=Possessed Garak
                    message= _ "I told you, I will be back, you fools! Now I shall have my vengeance upon you all. Darkness shall reign until I have triumphed!"
                [/message]
                [message]
                    speaker=Ystara
                    message= _ "In this I shall support you, the darkness shall not lift until one of us is victorious."
                [/message]
                [message]
                    speaker=Nym
                    message= _ "Maybe I spoke too soon. Curse Uria, they have even blotted out the stars, all is darkness. Kaleh, our course is clear, we must destroy one of these abominations. Whether it be the thing that has taken our friend, or the spectral evil that remains, one of them must die for this battle to end. We have no choice."
                    image=portraits/nym_moody.png
                [/message]
                [message]
                    speaker=Zhul
                    message= _ "But to kill Garak? How can we?"
                [/message]
                [message]
                    speaker=Kaleh
                    message= _ "That thing is not Garak. This night has lasted long enough, and too many of our people have died. How many more would you sacrifice for Garak’s sake? Just protecting our encampments isn’t enough, darkness and chaos will overwhelm us if we can’t end this battle soon. We must destroy one of those two evils, whatever the cost. I do not intend to let that... thing keep control of the body of our friend."
                [/message]
                [message]
                    speaker=Ystara
                    message= _ "The stench of death is in the air."
                [/message]
                [message]
                    speaker=Possessed Garak
                    message= _ "Yes, let us end this once and for all."
                [/message]
                [objectives]
                    summary= _ "New Objectives:"
                    silent=no
                    [objective]
                        description=_"Defeat Possessed Garak"
                        condition=win
                    [/objective]
                    {DEFEAT_YSTARA_OBJECTIVE}
                    [+objective]
                        {ALTERNATIVE_OBJECTIVE_CAPTION}
                    [/objective]
                    {VILLAGE_CONTROL_OBJECTIVE}
                    {HERO_DEATH_OBJECTIVE}

                    [gold_carryover]
                        carryover_percentage=40
                    [/gold_carryover]
                [/objectives]
            [/then]
        [/if]

        [modify_turns]
            value=-1
        [/modify_turns]
        {CLEAR_VARIABLE choice_flag}
#ifdef HARD
        {CLEAR_VARIABLE azkotep_casualties,ystara_casualties}
#endif
        {CLEAR_VARIABLE killed_by_azkotep}
        {CLEAR_VARIABLE killed_by_ystara}
    [/event]

    [event]
        name=garak_resists

        [message]
            speaker=Zhul
            message= _ "Eloh protect us, what has he done?"
        [/message]
        [message]
            speaker=Possessed Garak
            message= _ "I live again! I can feel!"
        [/message]
        [kill]
            id=Possessed Garak
            animate=no
            fire_event=no
        [/kill]
        [unstore_unit]
            variable=ElvishGarak
            find_vacant=yes
        [/unstore_unit]
        [message]
            speaker=Garak
            message=_"I will... not... yield... I defeated... your... champion... I... will... overcome... you..."
        [/message]
        [kill]
            id=Garak
            animate=no
            fire_event=no
        [/kill]
        {NAMED_NOTRAIT_UNIT 2 (Corrupted Quenoth Elf) $ElvishGarak.x $ElvishGarak.y (Possessed Garak) ( _ "Possessed Garak")}
        [message]
            speaker=Possessed Garak
            message=_"No, fool! Stop!"
        [/message]
        [kill]
            id=Possessed Garak
            animate=no
            fire_event=no
        [/kill]
        [unstore_unit]
            variable=ElvishGarak
            find_vacant=yes
        [/unstore_unit]
        [message]
            speaker=Garak
            message=_"The dark lord... is no more..."
        [/message]

        [message]
            speaker=narrator
            message=_"Garak collapses to the ground with his own blade sticking from his chest."
            image=wesnoth-icon.png
        [/message]
        [kill]
            id=Garak
            animate=yes
            fire_event=no
        [/kill]
    [/event]

    # Count (or store) dying elves and orcs, they will make a host for possessed Garak.
    # Two events per undead side: one to count units as killed by that side and one to
    # create the appropriate number of minions when Garak is possessed by that side.
#define UTBS_COUNT_DEATHS_AND_CREATE_MINIONS FOR_VILLAIN SIDE
    [event]
        name=die
        first_time_only=no
        [filter]
            side=1,4
        [/filter]
        [filter_second]
            side={SIDE}
        [/filter_second]
        [filter_condition]
            [variable]
                name=turn_number
                less_than=12
            [/variable]
        [/filter_condition]

#ifdef HARD
        [store_unit]
            [filter]
                x,y=$x1,$y1
            [/filter]
            mode=append
            variable={FOR_VILLAIN}_casualties
            kill=no
        [/store_unit]
        {VARIABLE {FOR_VILLAIN}_casualties[$killed_by_{FOR_VILLAIN}].side {SIDE}}
        {VARIABLE {FOR_VILLAIN}_casualties[$killed_by_{FOR_VILLAIN}].hitpoints ${FOR_VILLAIN}_casualties[$killed_by_{FOR_VILLAIN}].max_hitpoints}
        {VARIABLE {FOR_VILLAIN}_casualties[$killed_by_{FOR_VILLAIN}].status.poisoned "no"}
#endif
        {VARIABLE_OP killed_by_{FOR_VILLAIN} add 1}
    [/event]

    [event]
        name=create_garak_minions_{FOR_VILLAIN}

        [store_locations]
            [filter]
                id=Possessed Garak
            [/filter]
            variable=coords
        [/store_locations]

        {VARIABLE i 0}
        [while]
            [variable]
                name=i
                less_than=$killed_by_{FOR_VILLAIN}
            [/variable]
            [do]
#ifdef HARD
                {VARIABLE {FOR_VILLAIN}_casualties[$i].side {SIDE}}
                [unstore_unit]
                    variable={FOR_VILLAIN}_casualties[$i]
                    x=$coords.x
                    y=$coords.y
                    find_vacant=yes
                [/unstore_unit]
#endif
#ifdef NORMAL
                {RANDOM (Walking Corpse,Soulless)}
                {NOTRAIT_UNIT {SIDE} $random $coords.x $coords.y}
#endif
#ifdef EASY
                {NOTRAIT_UNIT {SIDE} (Walking Corpse) $coords.x $coords.y}
#endif
                [set_variable]
                    name=i
                    add=1
                [/set_variable]
            [/do]
        [/while]
        {CLEAR_VARIABLE i}
        {CLEAR_VARIABLE coords}
    [/event]
#enddef

    {UTBS_COUNT_DEATHS_AND_CREATE_MINIONS azkotep 2}
    {UTBS_COUNT_DEATHS_AND_CREATE_MINIONS ystara 3}
#undef UTBS_COUNT_DEATHS_AND_CREATE_MINIONS

    [event]
        name=garak_gloats

        [message]
            speaker=Possessed Garak
            message=_"Hahaha...!"
        [/message]
        [message]
            speaker=Zhul
            message= _ "Eloh protect us, what is happening?"
        [/message]
        [redraw]
            side=1
        [/redraw]
        [message]
            speaker=Possessed Garak
            message= _ "I live again! I can feel!"
        [/message]
        [message]
            speaker=Kaleh
            message= _ "Garak?"
        [/message]
        [message]
            speaker=Possessed Garak
            message= _ "Hahaha! Your puny friend is no more. With his body I shall crush you all. Arise again my minions and feast in the slaughter!"
        [/message]
    [/event]

    # Somewhere around turn 8 an orc raiding party makes an entrance.
    # Internal variables: $ambush_turn
    # Creates orcs on random turn around turn 8
    # Creates warning about incoming orcs two turns before they show up
    [event]
        name=prestart
#ifdef EASY
        {VARIABLE_OP ambush_turn rand 7..9}
#endif
#ifdef NORMAL
        {VARIABLE_OP ambush_turn rand 6..8}
#endif
#ifdef HARD
        {VARIABLE_OP ambush_turn rand 6..8}
#endif

        [event]
            name=turn_$ambush_turn
            delayed_variable_substitution=no

            [unit]
#ifdef EASY
                type=Orcish Leader
#else
                type=Orcish Ruler
#endif
                id=Ganthos
                name= _ "Ganthos"
                canrecruit=yes
                side=4
                x=3
                y=4
            [/unit]
#ifdef HARD
            {GENERIC_UNIT 4 (Goblin Pillager) 2 4}
            {GENERIC_UNIT 4 (Goblin Pillager) 3 3}
#else
            {GENERIC_UNIT 4 (Wolf Rider) 2 4}
            {GENERIC_UNIT 4 (Wolf Rider) 3 3}
#endif
#ifdef HARD
            {GENERIC_UNIT 4 (Orcish Crossbowman) 1 5}
            {GENERIC_UNIT 4 (Orcish Crossbowman) 3 2}
#else
            {GENERIC_UNIT 4 (Orcish Archer) 1 5}
            {GENERIC_UNIT 4 (Orcish Archer) 3 2}
#endif
#ifdef NORMAL
            {GENERIC_UNIT 4 (Orcish Assassin) 2 5}
            {GENERIC_UNIT 4 (Orcish Assassin) 4 2}
#endif
#ifdef HARD
            {GENERIC_UNIT 4 (Orcish Slayer) 2 5}
            {GENERIC_UNIT 4 (Orcish Slayer) 4 2}
#endif
#ifdef EASY
            {GENERIC_UNIT 4 (Orcish Grunt) 3 6}
            {GENERIC_UNIT 4 (Orcish Grunt) 5 3}
#else
            {GENERIC_UNIT 4 (Orcish Warrior) 3 6}
            {GENERIC_UNIT 4 (Orcish Warrior) 5 3}
#endif
            #give orcs an income, if they ever capture a keep to use it
            [modify_side]
                side=4
                {INCOME 20 25 30}
                {GOLD 75 100 125}
            [/modify_side]
            [message]
                speaker=Ganthos
                # wmllint: local spelling Stinkin'
                message= _ "What’s this on our borders? Stinkin’ elves and more undead? We’ll teach them a lesson they won’t soon forget. Attack!"
            [/message]
            [message]
                speaker=Kaleh
                message= _ "If those raiders capture any of our encampments, I fear our people’s fate will be just as bad as if it was captured by the undead."
            [/message]
        [/event]

        {VARIABLE_OP ambush_turn sub 2}

        [event]
            name=turn_$ambush_turn
            delayed_variable_substitution=no

            {NAMED_UNIT 1 (Quenoth Scout) 1 1 (Elven Scout) ( _ "Wounded Elven Scout") (upkeep=free)}
            [message]
                speaker=Elven Scout
                message=_"Orcs... Not far behind me... From the hills..."
            [/message]
            [kill]
                id=Elven Scout
                animate=yes
                fire_event=no
            [/kill]
        [/event]

        {CLEAR_VARIABLE ambush_turn}
    [/event]

    # Die event for orcish boss and reward for killing him
    # Affects variables: $sneak_up
    [event]
        name=last breath
        [filter]
            id=Ganthos
        [/filter]
        [if]
            [variable]
                name=second_unit.side
                equals=1
            [/variable]
            [then]
                [message]
                    speaker=Ganthos
                    message=_"You got me, elf... But you won’t be so lucky with the tribes of the hills... (<i>Cough</i>)"
                [/message]
                [message]
                    speaker=Ganthos
                    message=_"I deeply regret... I won’t be able to see that..."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Ganthos
                    message=_"Killed by a dead creep... (<i>Cough</i>)"
                [/message]
            [/else]
        [/if]
        [item]
            x,y=$x1,$y1
            image="items/parchment.png"
        [/item]
        [message]
            speaker=Nym
            message=_"Look, he dropped something! I wonder what it is..."
        [/message]

        [event]
            name=moveto
            delayed_variable_substitution=no

            [filter]
                x=$x1
                y=$y1
            [/filter]
            [if]
                [variable]
                    name=unit.side
                    equals=1
                [/variable]
                [then]
                    [message]
                        speaker=unit
                        message=_"It’s some sort of a map. I think I recognize some of those hills ahead on it."
                    [/message]
                    [message]
                        speaker=Nym
                        message=_"And these look like camps and patrol routes. A lot of camps and patrol routes. Kaleh, do you think we could sneak up between them?"
                    [/message]
                    [message]
                        speaker=Kaleh
                        message=_"Difficult, but worth a try I guess. But first we must try to survive this mess."
                    [/message]
                    [message]
                        speaker=Nym
                        message=_"Right, sorry. Damn creeps."
                    [/message]
                    {VARIABLE sneak_up 1}
                [/then]
                [else]
                    [message]
                        speaker=Nym
                        message=_"And now we’ll never know what was on that parchment. Shame."
                    [/message]
                [/else]
            [/if]
            [remove_item]
                x=$x1
                y=$y1
            [/remove_item]
        [/event]
#ifdef EASY
        [if]
            [have_unit]
                race=orc
            [/have_unit]
            [then]
                [message]
                    race=orc
                    message=_"Chief has fallen! Flee!"
                [/message]
            [/then]
            [else]
                # The wolf rider line are wolves, so must include both
                # goblins (for recruited spearmen) and wolves
                [message]
                    race=goblin,wolf
                    message=_"Boss dead! Run!"
                [/message]
            [/else]
        [/if]
        [kill]
            side=4
            animate=no
            fire_event=no
        [/kill]
#endif
    [/event]

    # Handles evil guys deaths and victory events, lots of dialogue.
    # Includes both normal and glorious victory.
    # Depends on variables : $ElvishGarak, $defiant_death
    # Internal variables : $other_creep
    [event]
        name=last breath
        first_time_only=no
        [filter]
            id=Azkotep,Ystara
        [/filter]
        [if]
            [variable]
                name=unit.id
                equals=Azkotep
            [/variable]
            [then]
                {VARIABLE other_creep "Ystara"}
            [/then]
            [else]
                {VARIABLE other_creep "Azkotep"}
            [/else]
        [/if]
        [if]
            [have_unit]
                id=$other_creep
            [/have_unit]
            [then]
                [message]
                    speaker=$unit.id
                    message= _ "You think you have defeated me, don’t you? Foolish boy, I shall assume a new form more powerful and horrible than you could ever imagine!"
                [/message]
                [message]
                    speaker=$other_creep
                    message= _ "How dare you interfere in our contest! I did not need your help. I shall teach you not to cross a lord of darkness."
                [/message]
            [/then]
        [/if]
        [if]
            [variable]
                name=turn_number
                greater_than=11
            [/variable]
            [then]
                [message]
                    speaker=Kaleh
                    message= _ "Finally. It is over."
                [/message]
                [if]
                    [have_unit]
                        id=Possessed Garak
                    [/have_unit]
                    [then]
                        [message]
                            speaker=Possessed Garak
                            message= _ "See, I told you I was more powerful. This game is over, now I can leave this shell of a body."
                        [/message]
                        [store_unit]
                            [filter]
                                id=Possessed Garak
                            [/filter]
                            variable=PossGarak
                            kill=no
                        [/store_unit]
                        [unit]
                            side=$unit.side
                            type=Defeated Corrupted Quenoth Elf
                            name= _ "Garak"
                            hitpoints=1
                            id=Garak_defeated
                            x,y=$PossGarak.x,$PossGarak.y
                            overwrite=yes
                        [/unit]
                        {CLEAR_VARIABLE PossGarak}
                        [message]
                            speaker=Zhul
                            message= _ "He’s... he’s still breathing!"
                        [/message]
                        [message]
                            speaker=Garak_defeated
                            message= _ "Protect the boy for me Zhul, (<i>cough</i>) I go to a better place."
                        [/message]
                        [kill]
                            id=Garak_defeated
                            animate=yes
                            fire_event=no
                        [/kill]
                    [/then]
                    [else]
                        [message]
                            speaker=Nym
                            message=_"What about Garak?"
                        [/message]
                        [if]
                            [variable]
                                name=defiant_death
                                equals=0
                            [/variable]
                            [then]
                                [message]
                                    speaker=Kaleh
                                    message=_"I’ve asked and looked around, there is no sign of him or his body"
                                [/message]
                                [message]
                                    speaker=Zhul
                                    message=_"He’s probably dead, then, but he died as a warrior. Let’s respect his wishes and remember him for that."
                                [/message]
                            [/then]
                            [else]
                                [message]
                                    speaker=Zhul
                                    message=_"He died as a hero. Remember that and tell the tale, for it’s worth it."
                                [/message]
                            [/else]
                        [/if]
                    [/else]
                [/if]

                [fire_event]
                    name=garak_eulogy
                [/fire_event]

                [fire_event]
                    name=count_final_camps
                [/fire_event]

                {CLEAR_VARIABLE other_creep}
                [endlevel]
                    result=victory
                    bonus=yes
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/then]
        [/if]
        [if]
            [not]
                [have_unit]
                    id=$other_creep
                [/have_unit]
            [/not]
            [variable]
                name=turn_number
                less_than=12
            [/variable]
            [then]
                [message]
                    speaker=Kaleh
                    message= _ "The undead lords are defeated at last."
                [/message]
                [message]
                    speaker=Ganthos
                    message= _ "There’s too many of them and the night is almost gone. Pull back you wretches, pull back!"
                [/message]
                [message]
                    speaker=Nym
                    message= _ "I can see the first rays of Naia shining over the horizon. She never looked so beautiful. The undead forces have crumbled into dust and the remaining orcs are retreating with the dawn."
                [/message]
                [message]
                    speaker=Zhul
                    message= _ "That was a very brave thing you did, Kaleh, defeating both of those Undead Lords. It took great courage and strength. Because of your daring attack, we did not have to wait for the dawn to save us. You were our savior. And many fewer of our people died than would have if we had had to wait out the long night."
                [/message]
                [message]
                    speaker=Nym
                    message= _ "Though we saved almost all our people this time, we won’t always be so lucky. While elves who have fought with you in the past will gladly return, if the numbers of our people dwindle, it’s going to become more and more costly to recruit new warriors. It would be wise to stockpile gold against this eventuality."
                [/message]
                [message]
                    speaker=Ystara
                    message= _ "You have triumphed for the moment, but think not that the dark lords can be so easily vanquished. We shall return, and shall rule long after your bones have crumbled to dust. This is our land, and none shall leave it unscathed."
                [/message]
                [message]
                    speaker=Azkotep
                    message= _ "You fought so hard to protect your precious people, young elf. No great deed should go unpunished."
                [/message]
                [if]
                    [have_unit]
                        id=Garak
                    [/have_unit]
                    [then]
                        [message]
                            id=Ystara,Azkotep
                            message= _ "A token to remember us by..."
                        [/message]
                        [message]
                            speaker=Garak
                            message= _ "Aauugghh!"
                        [/message]
                        [message]
                            speaker=Zhul
                            message= _ "He just collapsed!"
                        [/message]
                        [message]
                            speaker=Garak
                            message= _ "Protect the boy for me Zhul, (<i>cough</i>) I go to a better place."
                        [/message]
                        [kill]
                            id=Garak
                            animate=yes
                            fire_event=no
                        [/kill]
                    [/then]
                    [else]
                        [message]
                            id=Ystara,Azkotep
                            message=_"You will never see your champion again. And we will torment his soul for the rest of the eternity."
                        [/message]
                        [message]
                            speaker=Zhul
                            message=_"Don’t listen to them, they are powerless in their defeat. Even if Garak fell in battle his soul went to a better place and they can’t reach him there."
                        [/message]
                    [/else]
                [/if]

                [fire_event]
                    name=garak_eulogy
                [/fire_event]

                {CLEAR_VARIABLE other_creep}
                [endlevel]
                    result=victory
                    bonus=yes
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/then]
        [/if]
    [/event]

    [event]
        name=die
        [filter]
            id=Possessed Garak
        [/filter]
        [if]
            [have_unit]
                id=Azkotep
            [/have_unit]
            [then]
                [message]
                    speaker=Azkotep
                    message= _ "Hah, now you have learned the flesh is always weaker than the powers of the undead."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Ystara
                    message= _ "My undead zombies shall always defeat the living."
                [/message]
            [/else]
        [/if]
        [message]
            speaker=Kaleh
            message= _ "Finally. It is over."
        [/message]
        [unit]
            side=$unit.side
            type=Defeated Corrupted Quenoth Elf
            name= _ "Garak"
            hitpoints=1
            id=Garak_defeated
            x,y=$unit.x,$unit.y
            overwrite=yes
        [/unit]
        [message]
            speaker=Zhul
            message= _ "He’s... he’s still breathing!"
        [/message]
        [message]
            speaker=Garak_defeated
            message= _ "Protect the boy for me Zhul, (<i>cough</i>) I go to a better place."
        [/message]
        [kill]
            id=Garak_defeated
            animate=yes
            fire_event=no
        [/kill]

        [fire_event]
            name=garak_eulogy
        [/fire_event]

        [fire_event]
            name=count_final_camps
        [/fire_event]

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

    [event]
        name=garak_eulogy

        [message]
            speaker=Kaleh
            message= _ "From the sands he came, to the sands he will return. We remember and honor his sacrifice, and I vow that his death will not be in vain."
        [/message]
        [message]
            speaker=Zhul
            message= _ "Goodbye, old friend. May Eloh shine her light eternal upon you."
        [/message]
        [message]
            speaker=Elyssa
            message= _ "He was as brave and valiant a fighter as I have ever seen in my travels."
        [/message]
        [message]
            speaker=Nym
            message= _ "He was a bastard at times... But... but why did he have to die? It... it just doesn’t make sense."
            image=portraits/nym_moody.png
        [/message]
    [/event]

    # Final dialog concerning survival of camps
    # Depends on variables : $elven_camps
    [event]
        name=count_final_camps
        [if]
            [variable]
                name=elven_camps
                equals=12
            [/variable]
            [then]
                [message]
                    speaker=Zhul
                    message= _ "Miraculously, all of our encampments survived the night."
                [/message]
                [message]
                    speaker=Nym
                    message= _ "Though we saved almost all our people this time, we won’t always be so lucky. While elves who have fought with you in the past will gladly return, if the numbers of our people dwindle, it’s going to become more and more costly to recruit new warriors. It would be wise to stockpile gold against this eventuality."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Zhul
                    message= _ "Well, only $elven_camps encampments remain, but we will survive."
                [/message]
                [message]
                    speaker=Kaleh
                    message= _ "Yes, but at what cost?"
                [/message]
                [if]
                    [variable]
                        name=elven_camps
                        greater_than=8
                    [/variable]
                    [then]
                        [message]
                            speaker=Nym
                            message= _ "Though we saved almost all our people this time, we won’t always be so lucky. While elves who have fought with you in the past will gladly return, as the numbers of our people dwindle, it’s going to become more and more costly to recruit new warriors. It would be wise to stockpile gold against this eventuality."
                        [/message]
                    [/then]
                    [else]
                        [if]
                            [variable]
                                name=elven_camps
                                greater_than=6
                            [/variable]
                            [then]
                                [message]
                                    speaker=Nym
                                    message= _ "We have suffered losses, but we are not broken yet. We have saved most of our people tonight. But while elves who have fought with you in the past will gladly return, as the numbers of our people dwindle, it’s going to become more and more costly to recruit new warriors. It would be wise to stockpile gold against this eventuality."
                                [/message]

                                {INCREASE_RECRUIT_COSTS 1}
                            [/then]
                            [else]
                                [message]
                                    speaker=Nym
                                    message= _ "We have suffered grievous losses, but we are not broken yet. Long will this slaughter be remembered by our people. Where was Eloh during the darkness? And I’m afraid that while elves who have fought with you in the past will gladly return, as the numbers of our people dwindle, it’s going to become more and more costly to recruit new warriors. It would be wise to stockpile gold against this eventuality."
                                [/message]

                                {INCREASE_RECRUIT_COSTS 2}
                            [/else]
                        [/if]
                    [/else]
                [/if]
            [/else]
        [/if]

        [message]
            speaker=Kaleh
            message= _ "All this death and destruction. What were those shades arguing over? Was this all just some sort of demented game?"
        [/message]
        [message]
            speaker=Zhul
            message= _ "The lords of the dead are powerful and twisted indeed. Only Eloh knows the truth of what happened tonight."
        [/message]
        [message]
            speaker=Nym
            message= _ "I don’t want to be here tomorrow night to find out. The hills to the north are close. Let’s be far away before another nightfall."
        [/message]
    [/event]

    # victory
    # clear all variables potentially not cleared
    [event]
        name=scenario_end
        {CLEAR_VARIABLE defiant_death}
        {CLEAR_VARIABLE zur_defeated}
        {CLEAR_VARIABLE grak_defeated}
        {CLEAR_VARIABLE ElvishGarak}
        {CLEAR_VARIABLE elven_camps}
#ifdef HARD
        {CLEAR_VARIABLE azkotep_casualties,ystara_casualties}
#endif
        {CLEAR_VARIABLE killed_by_azkotep}
        {CLEAR_VARIABLE killed_by_ystara}
    [/event]

#define UTBS_GARAK_MUST_LIVE
#enddef
    {UTBS_INCLUDE utils/deaths.cfg}
#undef UTBS_GARAK_MUST_LIVE
[/scenario]
