#textdomain wesnoth-utbs
# Scenario 3: A Stirring in the Night

# 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 limit 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}
    #don't display snapshot of map in saved games
    snapshot="no"
    #there is no time flow and no turn limit for this scenario
    {LONGDARK4}
    turns="-1"
    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=Desert Fighter
        canrecruit=yes
        controller=human
        recruit=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
        gold=200
        {INCOME 4 2 0}
        shroud=yes
        fog=no
        {FLAG_VARIANT long}
    [/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}
#ifdef HARD
        recruit=Deathblade,Revenant,Bone Shooter,Chocobone,Skeleton Rider
#else
        recruit=Skeleton,Skeleton Archer,Skeleton Rider
#endif
        #
        # AI config
        #
        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression 0.9}
            {AI_SIMPLE_ALWAYS_ASPECT caution    0.0}
            {AI_SIMPLE_ALWAYS_ASPECT passive_leader yes}

            # AI will attack a weak unit with a max of 3,4,5 units
            # depending on the difficulty
            {AI_SIMPLE_ALWAYS_ASPECT attack_depth {ON_DIFFICULTY 3 4 5}}

            #!-- Needed to force AI to recruit non flying units
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_ignore_bad_movement yes}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_ignore_bad_combat   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}
#ifdef HARD
        recruit=Blood Bat,Necrophage,Wraith,Soulless
#else
        recruit=Vampire Bat,Ghoul,Ghost,Walking Corpse
#endif
        #
        # AI config
        #
        {ai/aliases/stable_singleplayer.cfg}
        [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}
            {AI_SIMPLE_ALWAYS_ASPECT attack_depth {ON_DIFFICULTY 3 4 5}}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_ignore_bad_movement yes}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_ignore_bad_combat   yes}

            [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 config
        #
        {ai/aliases/stable_singleplayer.cfg}
        [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}

            {ATTACK_DEPTH 3 4 5}
        [/ai]
        {FLAG_VARIANT 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_challenged,
    #! -- $zur_challenged
    [event]
        name=prestart

        # set starting scenario objectives
        [objectives]
            summary= _ "Starting Objectives:"
            [objective]
                description= _ "Survive Until Dawn (or)"
                condition=win
                show_turn_counter=yes
            [/objective]
            [objective]
                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
        [unit]
            {NYM}
            placement=leader
        [/unit]

        [recall]
            id=Elyssa
        [/recall]

        [unit]
            {ZHUL}
            placement=leader
        [/unit]

        # wmllint: recognize Garak
        [unit]
            {GARAK}
            placement=leader
        [/unit]

        [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]

        [remove_shroud]
            x=1-60
            y=1-60
            side=1
        [/remove_shroud]

#ifdef EASY
        {RANDOM 7..9}
#endif
#ifdef NORMAL
        {RANDOM 6..8}
#endif
#ifdef HARD
        {RANDOM 6..8}
#endif

        {VARIABLE ambush_turn $random}

        {VARIABLE sneak_up 0}
        {VARIABLE killed_by_azkotep 0}
        {VARIABLE killed_by_ystara 0}
        {VARIABLE grak_challenged 0}
        {VARIABLE zur_challenged 0}
        {VARIABLE defiant_death 0}
        {VARIABLE azkotep_casaulties.length 0}
        {VARIABLE ystara_casaulties.length 0}

        #Time Areas correspond with halo around campfires
        #North campfire
        [time_area]
            x=14
            y=10
            radius=2
            {DUSK}
        [/time_area]

        #Central campfire
        [time_area]
            x=16
            y=15
            radius=2
            {DUSK}
        [/time_area]

        #South Campfire
        [time_area]
            x=13
            y=20
            radius=2
            {DUSK}
        [/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

        [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]

#ifdef EASY
        {VARIABLE rally_chance 70}
#endif

#ifdef NORMAL
        {VARIABLE rally_chance 50}
#endif

#ifdef HARD
        {VARIABLE rally_chance 30}
#endif

        {VARIABLE i 0}

        {FOREACH tents i}
            {RANDOM 0..100}
            {VARIABLE_OP random sub tents[i].y}
            [if]
                [variable]
                    name=random
                    less_than=$rally_chance
                [/variable]

                [then]
                    [recall]
                        side=1
                        x=$tents[$i].x
                        y=$tents[$i].y
                    [/recall]
                    {VARIABLE_OP rally_chance sub 3}
                [/then]
            [/if]
        {NEXT i}
        {CLEAR_VARIABLE tents}
        {CLEAR_VARIABLE i}
        {CLEAR_VARIABLE rally_chance}
    [/event]

    # Count (or store) dying elves and orcs, they will make a host
    # for posessed Garak sets variables : $azkotep_casaulties,
    # $ystara_casaulties affects variables : $killed_by_ystara,
    # $killed_by_azkotep

    # This event is pretty simple, with intention of giving Garak a
    # number of walking corpses equal to number of lost
    # units. Point to consider is to actualy zombify the killed by
    # storing them and unstoring as a recruit list when Garak is
    # posessed.
    [event]
        name=die
        first_time_only=no
        [filter]
            side=1,4
        [/filter]

        [if]
            [variable]
                name=second_unit.side
                equals=2
            [/variable]
            [variable]
                name=turn_number
                less_than=13
            [/variable]
            [then]
#ifdef HARD
                {VARIABLE_OP azkotep_casaulties.length add 1}
                [store_unit]
                    [filter]
                        x,y=$x1,$y1
                    [/filter]
                    variable=azkotep_casaulties[$killed_by_azkotep].unit
                    kill=no
                [/store_unit]
                {VARIABLE azkotep_casaulties[$killed_by_azkotep].unit.side 2}
                {VARIABLE azkotep_casaulties[$killed_by_azkotep].unit.hitpoints $azkotep_casaulties[$killed_by_azkotep].unit.max_hitpoints}
                {VARIABLE azkotep_casaulties[$killed_by_azkotep].unit.status.poisoned "no"}
#endif
                {VARIABLE_OP killed_by_azkotep add 1}
            [/then]
        [/if]
        [if]
            [variable]
                name=second_unit.side
                equals=3
            [/variable]
            [variable]
                name=turn_number
                less_than=13
            [/variable]
            [then]
#ifdef HARD
                {VARIABLE_OP ystara_casaulties.length add 1}
                [store_unit]
                    [filter]
                        id=$unit.id
                    [/filter]
                    variable=ystara_casaulties[$killed_by_ystara].unit
                    kill=no
                [/store_unit]
                {VARIABLE ystara_casaulties[$killed_by_ystara].unit.side 3}
                {VARIABLE ystara_casaulties[$killed_by_ystara].unit.hitpoints $ystara_casaulties[$killed_by_ystara].unit.max_hitpoints}
                {VARIABLE ystara_casaulties[$killed_by_ystara].unit.status.poisoned "no"}
#endif
                {VARIABLE_OP killed_by_ystara add 1}
            [/then]
        [/if]
    [/event]

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

        [message]
            speaker=Nym
            message= _ "They’re raising the corpses of our fallen! What a horrible fate!"
        [/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 camps camp}
            [set_variables]
                name=camp_event
                mode=replace
                [value]
                    name=capture
                    first_time_only=yes
                    [filter]
                        side=2,3,4
                        x=$camps[$camp].x
                        y=$camps[$camp].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 0..100}
                            [if]
                                [variable]
                                    name=random
                                    less_than=51
                                [/variable]
                                [then]
                                    {NOTRAIT_UNIT $|unit.side (Walking Corpse) $|x1 $|y1}
                                [/then]
                                [else]
                                    {NOTRAIT_UNIT $|unit.side (Soulless) $|x1 $|y1}
                                [/else]
                            [/if]
#endif
#ifdef EASY
                            {NOTRAIT_UNIT $|unit.side (Walking Corpse) $|x1 $|y1}
#endif
                        [/then]
                    [/if]

                    [gold]
#ifdef EASY
                        amount=10
#endif
#ifdef NORMAL
                        amount=20
#endif
#ifdef HARD
                        amount=30
#endif
                        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]
        {NEXT camp}
        {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
            x=$x1
            y=$y1
        [/filter]

#ifdef NORMAL
        {VARIABLE factor $unit.max_experience}
        {VARIABLE_OP factor multiply 0.5}
        {RANDOM $factor..$unit.max_experience}
        {VARIABLE unit.experience $random}
#endif
        [unstore_unit]
            variable=unit
            x=$x1
            y=$y1
        [/unstore_unit]
        {CLEAR_VARIABLE factor}
    [/event]
#endif

    # If opposing champion wasn't attacked by the player yet Garak
    # can issue a challenge. Sffects variables : $grak_challenged,
    # $zur_challenged
    # Inform the player about the possibility of challenge and
    # adjust Garak accordingly. Perform the challenge, set the
    # death events where required. Internal variables :
    # $garak_duel, $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 champion with the light that will come, I bless you with the memory and the promise. Lay down your bow, champion, and let your sword 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]
            #textdomain wesnoth-help
            [effect]
                apply_to=attack
                range=melee
                [set_specials]
                    [berserk]
                        id=berserk
                        name= _ "berserk"
                        name_inactive=""
                        description= _ "Berserk:
Whether used offensively or defensively, this attack presses the engagement until one of the combatants is slain, or 30 rounds of attacks have occurred."
                        value=30
                        [filter_opponent]
                            id=Zur
                            [or]
                                id=Grak
                            [/or]
                        [/filter_opponent]
                    [/berserk]
#ifdef HARD
#else
                    [chance_to_hit]
                        id=magical
                        name= _ "magical"
                        name_inactive=""
                        description= _ "Magical:
This attack always has a 70% chance to hit regardless of the defensive ability of the unit being attacked."
                        value=70
                        cumulative=no
                        [filter_opponent]
                            id=Zur
                            [or]
                                id=Grak
                            [/or]
                        [/filter_opponent]
                    [/chance_to_hit]
                    [firststrike]
                        id=firststrike
                        name= _ "firststrike"
                        name_inactive=""
                        description= _ "First Strike:
This unit always strikes first with this attack, even if they are defending."
                        [filter_opponent]
                            id=Zur
                            [or]
                                id=Grak
                            [/or]
                        [/filter_opponent]
                    [/firststrike]
#endif
                    mode=append
                [/set_specials]
            [/effect]
            #textdomain wesnoth-utbs
            [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
            [or]
                id=Grak
            [/or]
            [or]
                id=Zur
            [/or]
        [/filter]
        [filter_second]
            id=Garak
            [or]
                id=Grak
            [/or]
            [or]
                id=Zur
            [/or]
        [/filter_second]
        [if]
            [and]
                [variable]
                    name=second_unit.id
                    equals=Grak
                [/variable]
                [or]
                    [variable]
                        name=second_unit.id
                        equals=Zur
                    [/variable]
                [/or]
            [/and]
            [and]
                [variable]
                    name=unit.id
                    equals=Garak
                [/variable]
            [/and]
            [then]
                {VARIABLE challenged $second_unit.id}
                [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_challenged
                                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]
                    [/then]
                    [else]
                        [message]
                            speaker=Garak
                            message=_"You there! Pile of bones! I challenge you, stand and face me!"
                        [/message]
                        [if]
                            [variable]
                                name=grak_challenged
                                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]
                    [/else]
                [/if]
                [event]
                    name=die
                    [filter]
                        id=Garak
                    [/filter]
                    [filter_second]
                        id=Zur
                        [or]
                            id=Grak
                        [/or]
                    [/filter_second]
                    [message]
                        speaker=$challenged
                        message=_"And so it ends... Your champion is dead, elves... Come join him..."
                    [/message]
                [/event]
                [event]
                    name=die
                    [filter]
                        id=$challenged
                    [/filter]
                    [if]
                        [variable]
                            name=second_unit.id
                            equals=Grak
                        [/variable]
                        [then]
                            {VARIABLE grak_challenged 1}
                        [/then]
                        [else]
                            {VARIABLE zur_challenged 1}
                        [/else]
                    [/if]
                    {CLEAR_VARIABLE challenged}
                [/event]
            [/then]
        [/if]
        [if]
            [and]
                [variable]
                    name=unit.id
                    equals=Grak
                [/variable]
                [or]
                    [variable]
                        name=unit.id
                        equals=Zur
                    [/variable]
                [/or]
            [/and]
            [and]
                [variable]
                    name=second_unit.id
                    equals=Garak
                [/variable]
            [/and]
            [then]
                {VARIABLE challenged $unit.id}
                [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_challenged
                                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 us cross our blades... It’s time for you to take his place..."
                                [/message]
                            [/else]
                        [/if]
                    [/then]
                    [else]
                        [message]
                            speaker=Garak
                            message=_"You there! Pile of bones! I challenge you, stand and face me!"
                        [/message]
                        [if]
                            [variable]
                                name=grak_challenged
                                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]
                    [/else]
                [/if]
                [event]
                    name=die
                    [filter]
                        id=Garak
                    [/filter]
                    [filter_second]
                        id=Zur
                        [or]
                            id=Grak
                        [/or]
                    [/filter_second]
                    [message]
                        speaker=$challenged
                        message=_"And so it ends... Your champion is dead, elves... Come join him..."
                    [/message]
                [/event]
                [event]
                    name=die
                    [filter]
                        id=$challenged
                    [/filter]
                    [if]
                        [variable]
                            name=second_unit.id
                            equals=Grak
                        [/variable]
                        [then]
                            {VARIABLE grak_challenged 1}
                        [/then]
                        [else]
                            {VARIABLE zur_challenged 1}
                        [/else]
                    [/if]
                    {CLEAR_VARIABLE challenged}
                [/event]
            [/then]
        [/if]
    [/event]

    [event]
        name=die
        [filter]
            id=Garak
        [/filter]
        [filter_second]
            [not]
                id=Grak
            [/not]
            [not]
                id=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_challenged, $zur_challenged,
    # $azkotep_casaulties[], $ystara_casaulties[],
    # $killed_by_azkotep, $killed_by_ystara clears variables :
    # $azkotep_casaulties[], $ystara_casaulties[],
    # $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, $coords
    # wmllint: recognize Possessed Garak
    [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_challenged multiply 10}
        {VARIABLE_OP choice_flag add $grak_challenged}
        {VARIABLE_OP grak_challenged divide 10}
        {VARIABLE_OP zur_challenged multiply 1}
        {VARIABLE_OP choice_flag add $zur_challenged}

        [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]

        [if]
            [variable]
                name=choice_flag
                greater_than=99
            [/variable]
            [then]
                [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]
                        [if]
                            [have_unit]
                                id=Garak
                            [/have_unit]
                            [then]
                                [store_locations]
                                    [filter]
                                        id=Garak
                                    [/filter]
                                    variable=coords
                                [/store_locations]
                                [store_unit]
                                    [filter]
                                        id=Garak
                                    [/filter]
                                    variable=ElvishGarak
                                    kill=no
                                [/store_unit]
                                [kill]
                                    id=Garak
                                    animate=yes
                                    fire_event=no
                                [/kill]
                            [/then]
                        [/if]
                        [kill]
                            id=Ystara
                            animate=yes
                            fire_event=no
                        [/kill]
                        {NAMED_NOTRAIT_UNIT 2 (Corrupted Elf)  $coords.x $coords.y (Possessed Garak) ( _ "Possessed Garak")}
                        [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
                            x=$coords.x
                            y=$coords.y
                            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 Elf)  $coords.x $coords.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
                            x=$coords.x
                            y=$coords.y
                            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]
                        [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."
                        [/message]
                        [objectives]
                            summary= _ "New Objectives:"
                            show=yes
                            {DEFEAT_AZKOTEP_OBJECTIVE}
                            {VILLAGE_CONTROL_OBJECTIVE}
                            {HERO_DEATH_OBJECTIVE}

                            [gold_carryover]
                                bonus=yes
                                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]

                        [if]
                            [have_unit]
                                id=Garak
                            [/have_unit]
                            [then]
                                [store_locations]
                                    [filter]
                                        id=Garak
                                    [/filter]
                                    variable=coords
                                [/store_locations]
                                [store_unit]
                                    [filter]
                                        id=Garak
                                    [/filter]
                                    variable=ElvishGarak
                                    kill=no
                                [/store_unit]
                                [kill]
                                    id=Garak
                                    animate=yes
                                    fire_event=no
                                [/kill]
                            [/then]
                        [/if]
                        [kill]
                            id=Azkotep
                            animate=yes
                            fire_event=no
                        [/kill]
                        [place_shroud]
                            side=1
                            x=1-60
                            y=1-60
                        [/place_shroud]
                        {NAMED_NOTRAIT_UNIT 2 (Corrupted Elf) 21 24 (Possessed Garak) ( _ "Possessed Garak")}
                        {VARIABLE i 0}
#ifdef HARD
                        {FOREACH azkotep_casaulties i}
                            {VARIABLE azkotep_casaulties[$i].unit.side 2}
                            [unstore_unit]
                                variable=azkotep_casaulties[$i].unit
                                x=21
                                y=24
                                find_vacant=yes
                            [/unstore_unit]
                        {NEXT i}
#else
                        [while]
                            [not]
                                [variable]
                                    name=i
                                    equals=$killed_by_azkotep
                                [/variable]
                            [/not]
                            [do]
#ifdef NORMAL
                                {RANDOM 0..100}
                                [if]
                                    [variable]
                                        name=random
                                        less_than=51
                                    [/variable]
                                    [then]
                                        {NOTRAIT_UNIT 2 (Walking Corpse) 21 24}
                                    [/then]
                                    [else]
                                        {NOTRAIT_UNIT 2 (Soulless) 21 24}
                                    [/else]
                                [/if]
#endif
#ifdef EASY
                                {NOTRAIT_UNIT 2 (Walking Corpse) 21 24}
#endif
                                {VARIABLE_OP i add 1}
                            [/do]
                        [/while]
#endif
                        [message]
                            speaker=Possessed Garak
                            message=_"Hahaha...!"
                        [/message]
                        [message]
                            speaker=Zhul
                            message= _ "Eloh protect us, what has he done?"
                        [/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 on the slaughter!"
                        [/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."
                        [/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:"
                            show=yes
                            [objective]
                                description=_"Defeat Possessed Garak (or)"
                                condition=win
                            [/objective]
                            {DEFEAT_YSTARA_OBJECTIVE}
                            {VILLAGE_CONTROL_OBJECTIVE}
                            {HERO_DEATH_OBJECTIVE}

                            [gold_carryover]
                                bonus=yes
                                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]
                        [if]
                            [have_unit]
                                id=Garak
                            [/have_unit]
                            [then]
                                [store_locations]
                                    [filter]
                                        id=Garak
                                    [/filter]
                                    variable=coords
                                [/store_locations]
                                [store_unit]
                                    [filter]
                                        id=Garak
                                    [/filter]
                                    variable=ElvishGarak
                                    kill=no
                                [/store_unit]
                                [kill]
                                    id=Garak
                                    animate=yes
                                    fire_event=no
                                [/kill]
                            [/then]
                        [/if]
                        [kill]
                            id=Ystara
                            animate=yes
                            fire_event=no
                        [/kill]
                        [redraw]
                            side=1
                        [/redraw]
                        [place_shroud]
                            side=1
                            x=1-60
                            y=1-60
                        [/place_shroud]
                        {NAMED_NOTRAIT_UNIT 3 (Corrupted Elf) 23 6 (Possessed Garak) ( _ "Possessed Garak")}
                        {VARIABLE i 0}
#ifdef HARD
                        {FOREACH ystara_casaulties i}
                            {VARIABLE ystara_casaulties[$i].side 3}
                            [unstore_unit]
                                variable=ystara_casaulties[$i].unit
                                x=23
                                y=6
                                find_vacant=yes
                            [/unstore_unit]
                        {NEXT i}
#else
                        [while]
                            [not]
                                [variable]
                                    name=i
                                    equals=$killed_by_ystara
                                [/variable]
                            [/not]
                            [do]
#ifdef NORMAL
                                {RANDOM 0..100}
                                [if]
                                    [variable]
                                        name=random
                                        less_than=51
                                    [/variable]
                                    [then]
                                        {NOTRAIT_UNIT 3 (Walking Corpse) 23 6}
                                    [/then]
                                    [else]
                                        {NOTRAIT_UNIT 3 (Soulless) 23 6}
                                    [/else]
                                [/if]
#endif
#ifdef EASY
                                {NOTRAIT_UNIT 3 (Walking Corpse) 23 6}
#endif
                                {VARIABLE_OP i add 1}
                            [/do]
                        [/while]
#endif
                        [message]
                            speaker=Possessed Garak
                            message=_"Hahaha...!"
                        [/message]
                        [message]
                            speaker=Zhul
                            message= _ "Eloh protect us, what has she done?"
                        [/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 on the slaughter!"
                        [/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."
                        [/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:"
                            show=yes
                            [objective]
                                description=_"Defeat Possessed Garak (or)"
                                condition=win
                            [/objective]
                            {DEFEAT_AZKOTEP_OBJECTIVE}
                            {VILLAGE_CONTROL_OBJECTIVE}
                            {HERO_DEATH_OBJECTIVE}

                            [gold_carryover]
                                bonus=yes
                                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]
                        [if]
                            [have_unit]
                                id=Garak
                            [/have_unit]
                            [then]
                                [store_locations]
                                    [filter]
                                        id=Garak
                                    [/filter]
                                    variable=coords
                                [/store_locations]
                                [store_unit]
                                    [filter]
                                        id=Garak
                                    [/filter]
                                    variable=ElvishGarak
                                    kill=no
                                [/store_unit]
                                [kill]
                                    id=Garak
                                    animate=yes
                                    fire_event=no
                                [/kill]
                            [/then]
                        [/if]
                        {NAMED_NOTRAIT_UNIT 2 (Corrupted Elf)  $coords.x $coords.y (Possessed Garak) ( _ "Possessed Garak")}
                        [message]
                            speaker=Zhul
                            message= _ "Eloh protect us, what has she 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
                            x=$coords.x
                            y=$coords.y
                            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 Elf) $coords.x $coords.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
                            x=$coords.x
                            y=$coords.y
                            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]
                        [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."
                        [/message]
                        [objectives]
                            summary= _ "New Objectives:"
                            show=yes
                            {DEFEAT_AZKOTEP_OBJECTIVE}
                            {VILLAGE_CONTROL_OBJECTIVE}
                            {HERO_DEATH_OBJECTIVE}

                            [gold_carryover]
                                bonus=yes
                                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]
                        [if]
                            [have_unit]
                                id=Garak
                            [/have_unit]
                            [then]
                                [store_locations]
                                    [filter]
                                        id=Garak
                                    [/filter]
                                    variable=coords
                                [/store_locations]
                                [store_unit]
                                    [filter]
                                        id=Garak
                                    [/filter]
                                    variable=ElvishGarak
                                    kill=no
                                [/store_unit]
                                [kill]
                                    id=Garak
                                    animate=yes
                                    fire_event=no
                                [/kill]
                            [/then]
                        [/if]
                        [place_shroud]
                            side=1
                            x=1-60
                            y=1-60
                        [/place_shroud]
                        {NAMED_NOTRAIT_UNIT 3 (Corrupted Elf) 23 6 (Possessed Garak) ( _ "Possessed Garak")}
                        {VARIABLE i 0}
#ifdef HARD
                        {FOREACH ystara_casaulties i}
                            {VARIABLE ystara_casaulties[$i].unit.side 3}
                            [unstore_unit]
                                variable=ystara_casaulties[$i].unit
                                x=23
                                y=6
                                find_vacant=yes
                            [/unstore_unit]
                        {NEXT i}
#else
                        [while]
                            [not]
                                [variable]
                                    name=i
                                    equals=$killed_by_ystara
                                [/variable]
                            [/not]
                            [do]
#ifdef NORMAL
                                {RANDOM 0..100}
                                [if]
                                    [variable]
                                        name=random
                                        less_than=51
                                    [/variable]
                                    [then]
                                        {NOTRAIT_UNIT 3 (Walking Corpse) 23 6}
                                    [/then]
                                    [else]
                                        {NOTRAIT_UNIT 3 (Soulless) 23 6}
                                    [/else]
                                [/if]
#endif
#ifdef EASY
                                {NOTRAIT_UNIT 3 (Walking Corpse) 23 6}
#endif
                                {VARIABLE_OP i add 1}
                            [/do]
                        [/while]
#endif
                        [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]
                        [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."
                        [/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:"
                            show=yes
                            [objective]
                                description=_"Defeat Possessed Garak (or)"
                                condition=win
                            [/objective]
                            {DEFEAT_AZKOTEP_OBJECTIVE}
                            {VILLAGE_CONTROL_OBJECTIVE}
                            {HERO_DEATH_OBJECTIVE}

                            [gold_carryover]
                                bonus=yes
                                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]
                        [if]
                            [have_unit]
                                id=Garak
                            [/have_unit]
                            [then]
                                [store_locations]
                                    [filter]
                                        id=Garak
                                    [/filter]
                                    variable=coords
                                [/store_locations]
                                [store_unit]
                                    [filter]
                                        id=Garak
                                    [/filter]
                                    variable=ElvishGarak
                                    kill=no
                                [/store_unit]
                                [kill]
                                    id=Garak
                                    animate=yes
                                    fire_event=no
                                [/kill]
                            [/then]
                        [/if]
                        [kill]
                            id=Azkotep
                            animate=yes
                            fire_event=no
                        [/kill]
                        {NAMED_NOTRAIT_UNIT 2 (Corrupted Elf) $coords.x $coords.y (Possessed Garak) ( _ "Possessed Garak")}
                        [message]
                            speaker=Zhul
                            message= _ "Eloh protect us, what is happening?"
                        [/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
                            x=$coords.x
                            y=$coords.y
                            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 Elf) $coords.x $coords.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
                            x=$coords.x
                            y=$coords.y
                            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]
                        [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."
                        [/message]
                        [objectives]
                            summary= _ "New Objectives:"
                            show=yes
                            {DEFEAT_YSTARA_OBJECTIVE}
                            {VILLAGE_CONTROL_OBJECTIVE}
                            {HERO_DEATH_OBJECTIVE}

                            [gold_carryover]
                                bonus=yes
                                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]
                        [if]
                            [have_unit]
                                id=Garak
                            [/have_unit]
                            [then]
                                [store_locations]
                                    [filter]
                                        id=Garak
                                    [/filter]
                                    variable=coords
                                [/store_locations]
                                [store_unit]
                                    [filter]
                                        id=Garak
                                    [/filter]
                                    variable=ElvishGarak
                                    kill=no
                                [/store_unit]
                                [kill]
                                    id=Garak
                                    animate=yes
                                    fire_event=no
                                [/kill]
                            [/then]
                        [/if]
                        [place_shroud]
                            side=1
                            x=1-60
                            y=1-60
                        [/place_shroud]
                        {NAMED_NOTRAIT_UNIT 2 (Corrupted Elf) 21 24 (Possessed Garak) ( _ "Possessed Garak")}
                        {VARIABLE i 0}
#ifdef HARD
                        {FOREACH azkotep_casaulties i}
                            {VARIABLE azkotep_casaulties[$i].unit.side 2}
                            [unstore_unit]
                                variable=azkotep_casaulties[$i].unit
                                x=21
                                y=24
                                find_vacant=yes
                            [/unstore_unit]
                        {NEXT i}
#else
                        [while]
                            [not]
                                [variable]
                                    name=i
                                    equals=$killed_by_azkotep
                                [/variable]
                            [/not]
                            [do]
#ifdef NORMAL
                                {RANDOM 0..100}
                                [if]
                                    [variable]
                                        name=random
                                        less_than=51
                                    [/variable]
                                    [then]
                                        {NOTRAIT_UNIT 2 (Walking Corpse) 21 24}
                                    [/then]
                                    [else]
                                        {NOTRAIT_UNIT 2 (Soulless) 21 24}
                                    [/else]
                                [/if]
#endif
#ifdef EASY
                                {NOTRAIT_UNIT 2 (Walking Corpse) 21 24}
#endif
                                {VARIABLE_OP i add 1}
                            [/do]
                        [/while]
#endif
                        [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]
                        [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."
                        [/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:"
                            show=yes
                            [objective]
                                description=_"Defeat Possessed Garak (or)"
                                condition=win
                            [/objective]
                            {DEFEAT_YSTARA_OBJECTIVE}
                            {VILLAGE_CONTROL_OBJECTIVE}
                            {HERO_DEATH_OBJECTIVE}

                            [gold_carryover]
                                bonus=yes
                                carryover_percentage=40
                            [/gold_carryover]
                        [/objectives]
                    [/then]
                [/if]
            [/then]
        [/if]
        {CLEAR_VARIABLE choice_flag}
        {CLEAR_VARIABLE i}
        {CLEAR_VARIABLE coords}
        {CLEAR_VARIABLE azkotep_casaulties}
        {CLEAR_VARIABLE ystara_casaulties}
        {CLEAR_VARIABLE killed_by_azkotep}
        {CLEAR_VARIABLE killed_by_ystara}
    [/event]

    # Somewhere around turn 8 an orc raiding party makes an entrance.
    # Affects variables : $sneak_up
    # Depends on variables : $ambush_turn
    # Clears variables : $ambush_turn
    # Creates warning about incoming orcs two turns before they show up
    # Creates orcs themselvs on random turn around turn 8
    # Creates die event for orcish boss and reward for killing him
    # Internal variables : $orc_warning, $parchment_x, $parchment_y
    [event]
        name=new turn
        first_time_only="no"
        {VARIABLE orc_warning $ambush_turn}
        {VARIABLE_OP orc_warning sub 2}

        [if]
            [variable]
                name=turn_number
                equals=$orc_warning
            [/variable]
            [then]
                {NAMED_UNIT 1 (Desert 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]
            [/then]
        [/if]
        {CLEAR_VARIABLE orc_warning}
    [/event]

    [event]
        name=new turn
        first_time_only="no"
        [if]
            [variable]
                name=turn_number
                numerical_equals=$ambush_turn
            [/variable]
            [then]
                [unit]
#ifdef EASY
                    type=Orcish Leader
#else
                    type=Orcish Ruler
#endif
                    id=Ganthos
                    name= _ "Ganthos"
                    upkeep=free
                    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]
                {CLEAR_VARIABLE ambush_turn}
            [/then]
        [/if]
    [/event]

    [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]
        {VARIABLE parchment_x $x1}
        {VARIABLE parchment_y $y1}
        [event]
            name=moveto
            [filter]
                x=$parchment_x
                y=$parchment_y
            [/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=$parchment_x
                y=$parchment_y
            [/remove_item]
            {CLEAR_VARIABLE parchment_x}
            {CLEAR_VARIABLE parchment_y}
        [/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, $elven_camps
    # Clears variables : $ElvishGarak, $grak_challenged, $zur_challenged,
    #    $defiant_death, $elven_camps
    # Internal variables : $other_creep
    [event]
        name=last breath
        first_time_only=no
        [filter]
            id=Azkotep
            [or]
                id=Ystara
            [/or]
        [/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]
            [have_unit]
                id=Possessed Garak
            [/have_unit]
            [or]
                [variable]
                    name=turn_number
                    greater_than=11
                [/variable]
            [/or]
            [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]
                        [kill]
                            id=Possessed Garak
                            animate=no
                            fire_event=no
                        [/kill]
                        [unstore_unit]
                            variable=ElvishGarak
                            find_vacant=yes
                        [/unstore_unit]
                        [message]
                            speaker=Zhul
                            message= _ "He’s... he’s still breathing!"
                        [/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]
                            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]
                [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."
                [/message]
                [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 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 the cost of all units by 1
                                        {INCREASE_RECRUIT_COSTS_BY_ONE}
                                    [/then]
                                    [else]
                                        [message]
                                            speaker=Nym
                                            message= _ "We have suffered grievous losses, but we 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 the cost of all units by 2
                                        {INCREASE_RECRUIT_COSTS_BY_ONE}
                                        {INCREASE_RECRUIT_COSTS_BY_ONE}
                                    [/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]
                {CLEAR_VARIABLE elven_camps}
                {CLEAR_VARIABLE defiant_death}
                {CLEAR_VARIABLE zur_challenged}
                {CLEAR_VARIABLE grak_challenged}
                {CLEAR_VARIABLE ElvishGarak}
                {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]
                            speaker=Ystara
                            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]
                            speaker=Ystara
                            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]
                [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."
                [/message]

                {CLEAR_VARIABLE elven_camps}
                {CLEAR_VARIABLE defiant_death}
                {CLEAR_VARIABLE zur_challenged}
                {CLEAR_VARIABLE grak_challenged}
                {CLEAR_VARIABLE ElvishGarak}
                {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]
        [kill]
            id=Possessed Garak
            animate=no
            fire_event=no
        [/kill]
        [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]
        [unstore_unit]
            variable=ElvishGarak
            find_vacant=yes
        [/unstore_unit]
        [message]
            speaker=Zhul
            message= _ "He’s... he’s still breathing!"
        [/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]
        [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."
        [/message]

        [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 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 the cost of all units by 1
                                {INCREASE_RECRUIT_COSTS_BY_ONE}
                            [/then]
                            [else]
                                [message]
                                    speaker=Nym
                                    message= _ "We have suffered grievous losses, but we 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 the cost of all units by 2
                                {INCREASE_RECRUIT_COSTS_BY_ONE}
                                {INCREASE_RECRUIT_COSTS_BY_ONE}
                            [/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]
        {CLEAR_VARIABLE elven_camps}
        {CLEAR_VARIABLE defiant_death}
        {CLEAR_VARIABLE zur_challenged}
        {CLEAR_VARIABLE grak_challenged}
        {CLEAR_VARIABLE ElvishGarak}
        [endlevel]
            result=victory
            bonus=yes
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

    {UTBS_INCLUDE utils/kaleh-abilities.cfg}
    {UTBS_INCLUDE utils/deaths.cfg}
[/scenario]
