#textdomain wesnoth-nr
[scenario]
    id=05b_Compelled
    name= _ "Compelled"
    {SCENARIO_MUSIC "underground.ogg"}

    [story]
        [part]
            story= _ "Note: The work on this branch of the campaign is in progress."
        [/part]

        [part]
            story= _ "Thus, compelled by some strange and irresistible force, Tallin — eyes glazed and mind unthinking — did the will of his new master."
            music=sad.ogg
        [/part]

        [part]
            # wmllint: local spelling grimoires
            story= _ "He was first stripped of his weapons and armor and then cast into solitary confinement. He remained there for months, never being allowed to see the light of day, being fed only enough food to keep him alive. During this time he was forced to study the most dark and forbidden arts, lashed with whips when he could not recite lessons drawn from grimoires no human should ever have opened. His body grew feeble and emaciated and his mind plunged ever deeper into night. And day by day the magical controls Malifor had fastened about Tallin’s will grew stronger."
        [/part]

        [part]
            story= _ "Tallin never knew exactly how much time passed, but eventually Malifor’s lich-servants declared him fit for service and he was summoned before their dread Master. Through a hideous blood ritual, Malifor gave him the power to animate corpses. He was then sent to a distant network of tunnels to clear out a group of trolls who had taken up residence there."
        [/part]
    [/story]

    map_data="{campaigns/Northern_Rebirth/maps/05b_Compelled.map}"

    {TURNS 39 35 31}

    {UNDERGROUND}

    next_scenario=06b_Slave_of_the_Undead

    [side]
        type=Peasant
        id=Tallin
        canrecruit=yes
        side=1
        controller=human
        gold=200
        recruit=Walking Corpse
        team_name=mob
        user_team_name=_"Minions"
        shroud=yes
    [/side]

    [side]
        type=Troll
        id=Franik
        name= _ "Franik"
        canrecruit=yes
        side=2
        {GOLD 30 35 40}
        recruit=Troll Whelp
        team_name=trolls
        user_team_name=_"Trolls"
        {NOTRAIT_UNIT 2 "Giant Spider" 19 9} {GUARDIAN}
    [/side]

    [side]
        type=Troll
        id=Henie
        name= _ "Henie"
        canrecruit=yes
        side=3
        {GOLD 30 35 40}
        recruit=Troll Whelp
        team_name=trolls
        user_team_name=_"Trolls"
        {NOTRAIT_UNIT 3 "Giant Spider" 20 3} {GUARDIAN}
    [/side]

    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                condition=win
                description=_ "Kill the Troll Leaders"
            [/objective]
            [objective]
                condition=lose
                description=_ "Death of Tallin"
            [/objective]

            {TURNS_RUN_OUT}

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

        [lua]
            code = <<
                local u = wesnoth.get_units({ id = 'Tallin' })[1]
                if u.level <= 1 then
                    u:transform('Dark Adept')
                elseif u.level == 2 then
                    u:transform('Dark Sorcerer')
                else
                    u:transform('Necromancer')
                    -- his portrait does not fit for a lich
                    -- however, he can advance one it if he has a lower level
                    -- u:transform('Lich')
                    -- u.moves = u.max_moves
                end
                u.hitpoints = u.max_hitpoints
                u.experience = 0
            >>
        [/lua]

        # It's questionable whether we should do this here...
        [modify_unit]
            [filter]
                id=Tallin
            [/filter]
            [object]
                duration=scenario
                [effect]
                    apply_to=ellipse
                    # The engine detects that this is a leader unit, and automatically
                    # changes the ellipse. To override it, a custom image is used
                    ellipse=ellipse/unprivileged
                [/effect]
            [/object]
        [/modify_unit]

        # Workaround (as of 1.14.1), manually reset the ellipse as the engine does do it for expiring objects
        [event]
            name=victory
            [modify_unit]
                [filter]
                    id=Tallin
                [/filter]
                [effect]
                    apply_to=ellipse
                    ellipse=
                [/effect]
            [/modify_unit]
        [/event]

        # Debug mode help: ensure there is not more gold available, and clear the recruits
        [modify_side]
            side=1
            gold=200
            recruit=Walking Corpse
        [/modify_side]

        [store_unit]
            [filter]
                role=Supporter
            [/filter]
            variable=betrayed_friend
        [/store_unit]

        [kill]
            side=1
            [not]
                id=Tallin
            [/not]
        [/kill]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Tallin
        [/filter]

        [message]
            speaker=Tallin
            image=portraits/Tallin-Evil.png
            message= _ "Argh! I have failed my master."
        [/message]

        [endlevel]
            result=defeat
        [/endlevel]
    [/event]
[/scenario]
