#textdomain wesnoth-sota

# There is lots of animation here, but nothing complicated.

[scenario]
    name= _ "Mortality"
    map_file=17_Mortality.map
    theme=Cutscene_Minimal

    id=17_Mortality
    next_scenario=18_Abandoned_Outpost
    victory_when_enemies_defeated=no

    [story]
        [part]
            story= _ "6 VI, 23 YW

Not far inside the cave was a ruined castle built in a style I did not recognize. Ras-Tabahn said, “Dwarves.” It is infested with rats, and clearly, no dwarves have lived here for a long time."
        [/part]
        {JOURNEY_PART 17}
    [/story]

    {UNDERGROUND}
    turns=unlimited

    # wmllint: validate-off
    [side]
        {SIDE_1_BOTH}
        shroud=yes
        gold=0
    [/side]
    # wmllint: validate-on

    [side]
        side=2
        controller=ai
        user_team_name= _ "Rats"
        team_name=bad
        no_leader=yes
        gold=0
        hidden=yes
    [/side]

#define PLACE_RAT X Y
    [unit]
        type=Giant Rat
        x={X}
        y={Y}
        side=2
    [/unit]
#enddef
    # *************************** PRESTART ***************************
    [event]
        name=prestart

        {PLACE_RAT 4 4}
        {PLACE_RAT 5 4}
        {PLACE_RAT 14 6}
        {PLACE_RAT 2 7}
        {PLACE_RAT 11 3}
    [/event]

    # This inserts the event that allows units to turn into a lich. (See: sota-utils.cfg)
    {TURN_INTO_A_LICH}

    # *************************** ENDING / OPENING ***************************
#define DELAY
    [delay]
        time=400
    [/delay]
    [redraw][/redraw]
#enddef

    [event]
        name=start

        [move_unit]
            id=Ardonna
            to_x=12
            to_y=4
        [/move_unit]
        [remove_shroud]
            x,y=12,4
            radius=4
        [/remove_shroud]
        [move_unit]
            id=Ardonna
            to_x=9
            to_y=6
        [/move_unit]
        [modify_unit]
            [filter]
                id=Ardonna
            [/filter]
            facing=ne
        [/modify_unit]
        # The shroud won't normally be cleared until all the animation is finished,
        # even with [redraw]. We have to do it manually:
        [remove_shroud]
            x,y=9,6
            radius=5
        [/remove_shroud]
        [remove_shroud]
            x,y=5,6
            radius=3
        [/remove_shroud]
        [remove_shroud]
            x,y=8,2
            radius=2
        [/remove_shroud]

        [recall]
            id=Ras-Tabahn
            x,y=16,1
        [/recall]
        [modify_unit]
            [filter]
                id=Ras-Tabahn
            [/filter]
            hitpoints=6
        [/modify_unit]
        [move_unit]
            id=Ras-Tabahn
            to_x=14
            to_y=3
        [/move_unit]
        [message]
            speaker=Ardonna
            message= _ "Just a little farther."
        [/message]
        [move_unit]
            id=Ras-Tabahn
            to_x=11
            to_y=5
        [/move_unit]
        [message]
            speaker=Ras-Tabahn
            message= _ "Ardryn-Na, I’m dying. (<i>Cough, cough</i>) I don’t think... I can stop it."
        [/message]
        [message]
            speaker=Ardonna
            message= _ "Nor should you! You must embrace it. Crelanu said as much. He also said your life force must depart, but he didn’t say it could not come back to you!"
        [/message]
        [message]
            speaker=Ras-Tabahn
            message= _ "What are you... proposing?"
        [/message]
        [message]
            speaker=Ardonna
            message= _ "That you project your will into another object so that it is part of you — your staff for example. If you do this just as your body dies, your whole consciousness should follow the flow of your will, as it will have no other place to go."
        [/message]
        [message]
            speaker=Ras-Tabahn
            message= _ "Well, it could go to the... lands of the dead. But... if I had an altar... the stone would serve to anchor me (<i>cough, cough, cough</i>) to this plane... and stop the downward flow of my soul... for just a moment."
        [/message]
        [message]
            speaker=Ardonna
            message= _ "And a moment is all you need! You only need project your will <i>back</i> into your body, animating it as you would anything else!"
        [/message]
        [message]
            speaker=Ras-Tabahn
            message= _ "You seem... more sure than I, but  (<i>cough, cough</i>) I have no choice."
        [/message]
        [message]
            speaker=Ardonna
            message= _ "Crelanu said he wouldn’t do it. That implies that he <i>could</i>, so he also believed that it would work. And like you said, he should know. For now, you can rest. We’ll have an altar built soon."
        [/message]

        # Skeletons are created, and some rock disappears. ("Collected" by the
        # skeletons.)
        [unit]
            type=Skeleton
            x,y=8,4
            side=1
            animate=yes
            facing=ne
        [/unit]
        [unit]
            type=Skeleton
            x,y=10,5
            side=1
            animate=yes
            facing=nw
        [/unit]
        [terrain]
            x,y=10,4
            terrain=^
            layer=overlay
        [/terrain]
        [terrain]
            x,y=9,4
            terrain=^
            layer=overlay
        [/terrain]
        {DELAY}

        # Skeletons face the eventual location of the altar, and rock appears there.
        [modify_unit]
            [filter]
                x,y=8,4
            [/filter]
            facing=se
        [/modify_unit]
        [modify_unit]
            [filter]
                x,y=10,5
            [/filter]
            facing=nw
        [/modify_unit]
        [terrain]
            x,y=9,5
            terrain=^Dr
            layer=overlay
        [/terrain]
        {DELAY}

        # One skeleton turns around and more rock disappears.
        [modify_unit]
            [filter]
                x,y=10,5
            [/filter]
            facing=se
        [/modify_unit]
        [terrain]
            x,y=11,6
            terrain=^
            layer=overlay
        [/terrain]
        {DELAY}

        # Skeletons face the new pile of rock, and the altar appears.
        [modify_unit]
            [filter]
                x,y=10,5
            [/filter]
            facing=nw
        [/modify_unit]
        [terrain]
            x,y=9,5
            terrain=^
            layer=overlay
        [/terrain]
        [item]
            # So color is the same as the Ras-Tabahn-on-the-altar.
            image=items/altar-sacrifice.png~NO_TOD_SHIFT()
            x,y=9,5
        [/item]
        {DELAY}

        # Ras-Tabahn appears to move to the altar and lie on it.
        [store_unit]
            [filter]
                id=Ras-Tabahn
            [/filter]
            variable=rastabahn_stored
        [/store_unit]
        [hide_unit]
            id=Ras-Tabahn
        [/hide_unit]
        [move_unit_fake]
            type=Necromancer
            side=1
            x=11,10,9
            y=5,  4,  5
        [/move_unit_fake]
        [remove_item]
            x,y=9,5
        [/remove_item]
        # Ras-Tabahn-on-the-altar is a unit so that he can retain his property bars
        # and orb, and be drawn in the correct z-position.
        [unit]
            type=Sacrifice
            x,y=9,5
            side=1
            facing=se
            experience=$rastabahn_stored.experience
            hitpoints=$rastabahn_stored.hitpoints
            max_hitpoints=$rastabahn_stored.max_hitpoints
            ellipse=misc/ellipse-hero
            id=necromancer_on_altar
            name= _ "Ras-Tabahn"
            profile=$rastabahn_stored.profile
            [modifications]
                [insert_tag]
                    name=trait
                    variable=rastabahn_stored.modifications.trait[0]
                [/insert_tag]
                [insert_tag]
                    name=trait
                    variable=rastabahn_stored.modifications.trait[1]
                [/insert_tag]
            [/modifications]
        [/unit]
        [clear_variable]
            name=rastabahn_stored
        [/clear_variable]

        {DELAY}

        [message]
            speaker=Ardonna
            message= _ "No need for you to wait to die. We can have done with it immediately. And although neither of us needs speak the incantations aloud anymore, you should this time, as any mistake would be disastrous."
        [/message]
        [message]
            speaker=necromancer_on_altar
            message= _ "Yes. I’m ready. Do it."
        [/message]

        [unit]
            type=SotA Skeleton
            side=1
            placement=map
            overwrite=yes
            x,y=8,4
            id=skeleton
            facing=se
        [/unit]
        [animate_unit]
            [filter]
                id=skeleton
            [/filter]
            flag=sacrifice
        [/animate_unit]

        # TODO: The skeleton should keep the final animation frame here,
        # rather than flipping back to the standing animation for the fade.

        [screen_fade]
            red,green,blue=0,0,0
            alpha=255
            duration=1000
        [/screen_fade]

        [delay]
            time=2000
        [/delay]

        [fire_event]
            name=lichify  # See: sota-utils.cfg
            [primary_unit]
                id=Ardonna
            [/primary_unit]
        [/fire_event]

        [fire_event]
            name=lichify
            [primary_unit]
                id=Ras-Tabahn
            [/primary_unit]
        [/fire_event]

        # New, lich versions of the two leaders are now on the recall list, so we
        # need to remove the necromancer versions from the game:
        [kill]
            side=1
            # Since we don't want to include units on the recall list:
            x=1-16
            y=1-7
        [/kill]

        [endlevel]
            result=victory
            linger_mode=no
            carryover_report=no
            bonus=no
            replay_save=no
            {NEW_GOLD_CARRYOVER 100}
        [/endlevel]
    [/event]
[/scenario]
