#textdomain wesnoth-ei
[scenario]
    id=18_Epilogue
    name= _ "Epilogue"
    map_file=Throne_Room.map
    theme=Cutscene_Minimal
    turns=unlimited
    next_scenario=null

    {DEFAULT_SCHEDULE}

    {INTRO_AND_SCENARIO_MUSIC weight_of_revenge.ogg journeys_end.ogg}
    {EXTRA_SCENARIO_MUSIC wanderer.ogg}
    {EXTRA_SCENARIO_MUSIC knolls.ogg}

    [story]
        [part]
            story= _ "When Mal-Ravanal fell, the undead army collapsed like puppets with cut strings. The invading necromancers looked on in horror, unable to comprehend what had happened."
        [/part]
        [part]
            story= _ "Yet even as the lich’s body crumbled, for a moment’s breath, the onlookers saw a vast and louring column of shadow arise like smoke from an unclean fire. It divided fivefold at its height, reaching for the heavens like a clutching hand. Men let weapons fall from nerveless fingers and horses reared in terror as that great dark pall obscured the sun..."
        [/part]
        [part]
            story= _ "... and then it thinned, and paled, and a breeze from the west dissolved it in tatters, and the light of day shone once again undiminished on Weldyn."
            music=knolls.ogg
        [/part]
    [/story]

    [side]
        id=Gweddry # TODO: he respawns even if he died last scenario, so we need to fix that
        side=1
        controller=human
        gold=0
        team_name=good
        user_team_name=_"Wesnothians"
        {FLAG_VARIANT loyalist}
        defeat_condition=never
    [/side]
    [event]
        name=prestart

        [filter_condition]
            {VARIABLE_CONDITIONAL gweddry_dead equals yes}
        [/filter_condition]

        {MODIFY_UNIT id,x,y=Gweddry,recall,recall id not_gweddry}
    [/event]

    [side]
        side=2
        canrecruit=no
        facing=sw
        controller=ai
        team_name=good
        user_team_name=_"Wesnothians"
        {FLAG_VARIANT loyalist}
    [/side]

#define RECALL_OR_CREATE SIDE ID X Y FACING TYPE
    {RECALL_XY {ID} {X} {Y}}
    [if]
        [have_unit]
            x,y={X},{Y}
        [/have_unit]

        [then]
        [/then]

        [else]
            {GENERIC_UNIT {SIDE} ({TYPE}) {X} {Y}}
        [/else]
    [/if]
    {MODIFY_UNIT (x,y={X},{Y}) facing {FACING}}
#enddef

    [event]
        name=prestart
        {PUT_TO_RECALL_LIST id=Gweddry} # so I can recall him at a specific place

        # if I change this, also change 16_Council
        {PLACE_IMAGE scenery/throne.png 10 5}
        {PLACE_IMAGE items/sceptre-of-fire.png 7 6}
        {PLACE_IMAGE items/ornate2.png 13 6}
        {PLACE_IMAGE items/ornate1.png 14 6}
        {PLACE_IMAGE items/altar-evil-amulet.png 7 6}

        {KILL id=Dacyn} # remove Dacyn to ensure he can't be recalled if, for example, he picked up the plague staff

        # king and high advisor
        [unit]
            side=2
            x,y=10,7
            facing=se
            {CHARACTER_STATS_KING}
            [modifications]
                {KONRAD_UNARMED_SCENARIO}
            [/modifications]
        [/unit]
        [unit]
            id=Aeraeka
            name= _ "Aeraeka"
            type=Arch Mage
            side=2
            x,y=8,8
            facing=se
            gender=female
            [modifications]
                {TEAM_COLOR_OVERRIDE () brown}
            [/modifications]
        [/unit]

        # funeral speaker
        {NAMED_UNIT 2 (White Mage) 12 8 "Renaerawan" (_"Renaerawan") ()} {FACING sw}
        [+unit]
            gender=female
        [/unit]

        # Gweddry and Owaec
        {RECALL_OR_CREATE 2 Gweddry 8 10 se "Swordsman"}
        {RECALL_OR_CREATE 2 Owaec  12 10 sw "Knight"}

        # Addogin, Hahid, or Terraent, and Gaennell
        {RECALL_XY (Addogin) 12 12}
        [if]
            [not]
                [have_unit]
                    x,y=12,12
                [/have_unit]
            [/not]

            [then]
                {RECALL_XY (Terraent) 12 12}
            [/then]
        [/if]
        [if]
            [have_unit]
                x,y=12,12
            [/have_unit]

            [then]
                [recall] # for some reason, RECALL_XY fails here. I don't know why.
                    id=Gaennell
                    x,y=12,14
                [/recall]
                [if]
                    [not]
                        [have_unit]
                            x,y=12,14
                        [/have_unit]
                    [/not]

                    [then]
                        {GENERIC_UNIT 2 (Silver Mage) 12 14}
                    [/then]
                [/if]
                {MODIFY_UNIT x,y=12,14 facing nw}
            [/then]

            [else]
                [recall]
                    id=Gaennell
                    x,y=12,12
                [/recall]
                {GENERIC_UNIT 2 (Silver Mage) 12 14} {FACING nw}
            [/else]
        [/if]

        {RECALL_OR_CREATE 2 (Hahid al-Ali) 12 12 sw "Silver Mage"}

        # Grug or Dolburras
        {RECALL_XY Grug 8 12}
        {RECALL_OR_CREATE 2 Dolburras 8 12 se "Red Mage"}

        # plague staff wielder
        {STORE_UNIT_VAR (
            [not]
                race=undead
            [/not]

            [has_attack]
                special_id=plague
            [/has_attack]
        ) id plague_staff_wielder_id}
        {RECALL_OR_CREATE 2 $plague_staff_wielder_id 8 14 ne "Master at Arms"}

        # guards
        {GENERIC_UNIT 2 (Swordsman)  8 20} {FACING se}
        {GENERIC_UNIT 2 (Pikeman)   12 20} {FACING sw}
        {GENERIC_UNIT 2 (Royal Guard)    6 15} {FACING ne}
        {GENERIC_UNIT 2 (Royal Guard)   14 15} {FACING nw}
    [/event]

    [event]
        name=start
        [message]
            speaker=Renaerawan
            #po: the speaker is a white mage who first appears in this epilogue
            message= _ "We are gathered here today in remembrance of our dear colleague and friend, Dacyn, who fell even as he vanquished the arch-lich Mal-Ravanal."
        [/message]
        [message]
            speaker=Renaerawan
            message= _ "I knew Dacyn as a complicated man: ambitious yet loyal, proud yet wise. But above all, Dacyn sought to act for the good of Wesnoth, and today we honor him for that."
        [/message]

        [message]
            speaker=Konrad
            image=portraits/konrad_II.webp
            message= _ "Today we have won a great victory, yet it comes at great cost."
        [/message]
        [message]
            speaker=Grug
            message= _ "Grug sad! Magic man kind."
        [/message]
        [message]
            speaker=Dolburras
            message= _ "Ay. Too many ha’ died in this war, both my kinsmen at Knalga and yours here."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "So many months of fighting... I feel as though I am awakening from a long nightmare."
        [/message]
        [message]
            speaker=Owaec
            #po: he's alive, this isn't a plaque on a tomb
            message= _ "My duty is done; the Clans have been avenged. At last, I can rest in peace."
        [/message]

        [message]
            speaker=Konrad
            image=portraits/konrad_II.webp
            message= _ "Alas, our work is not yet complete. Mal-Ravanal’s host has been broken, but in its wake, chaos and disorder prevail throughout the countryside. We will be years... decades... recovering from the ill wrought here."
        [/message]
        [message]
            speaker=Aeraeka
            message= _ "Even now we should be sending what’s left of our armies to restore order throughout the land."
        [/message]
        [if]
            [have_unit]
                id=Owaec,Gweddry
            [/have_unit]

            [then]
                [message]
                    speaker=Konrad
                    image=portraits/konrad_II.webp
                    #po: TODO for 1.19? Make clear who this is addressing, and make variations depending on whether it's to one person or two.
                    #po: To Owaec, Gweddry or both; but I only know that because I can see the condition and the alternative line if they're both dead.
                    #po: The "we" could be the royal pronoun (first person singular), but "we" as in "everyone in the Kingdom" fits too.
                    message= _ "It shall be so. But first, know that you have served Us, and Our Kingdom, full well. We are minded to reward you."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=Konrad
                    image=portraits/konrad_II.webp
                    #po: All three heroes are dead.
                    #po: The "we" could be the royal pronoun (first person singular), but "we" as in "everyone in the Kingdom" fits too.
                    message= _ "I had a mind to share this victory with those who made it possible, yet so many of them now lie dead. Lieutenant Gweddry, Lord Owaec, Advisor Dacyn, we thank you for your sacrifice."
                [/message]
            [/else]
        [/if]

        #------------------
        # GRUG AND DOLBURRAS
        #------------------
        [if]
            [have_unit]
                id=Grug
            [/have_unit]

            [then]
                [delay]
                    time=750
                [/delay]

                [if]
                    {VARIABLE_CONDITIONAL plague_staff_wielder_id equals Grug}
                    [then]
                        [message]
                            speaker=Konrad
                            image=portraits/konrad_II.webp
                            #po: the player chose to give Grug the plague staff
                            message= _ "Grug, a necromancer ogre is something wholly new to Us, but know that Wesnoth will never tolerate your kind. You shall surrender that accursed stave to be destroyed, you shall foreswear the practice of all magic on penalty of death, and are hereby exiled from Wesnoth. Be grateful for Our mercy."
                        [/message]
                        [message]
                            speaker=Grug
                            message= _ "Guh... Grug say no magic yes ok."
                        [/message]
                        {CLEAR_VARIABLE plague_staff_wielder_id}
                    [/then]

                    [else]
                        [message]
                            speaker=Konrad
                            image=portraits/konrad_II.webp
                            message= _ "Grug, Gweddry has told me of the help you and your tribe provided his men. We wish to offer you a new home in the Estmark Hills along with Our thanks."
                        [/message]
                        [message]
                            speaker=Grug
                            message= _ "(bowing clumsily) Grug say new home will make thanks with."
                        [/message]
                    [/else]
                [/if]
            [/then]
        [/if]

        [if]
            [have_unit]
                id=Dolburras
            [/have_unit]

            [then]
                [delay]
                    time=750
                [/delay]

                [if]
                    {VARIABLE_CONDITIONAL plague_staff_wielder_id equals Dolburras}
                    [then]
                        [message]
                            speaker=Konrad
                            image=portraits/konrad_II.webp
                            #po: the player chose to give Dolburras the plague staff
                            message= _ "Dwarf, <i>necromancer</i>, know that Wesnoth will never tolerate your kind. You shall surrender that accursed stave to be destroyed, you shall foreswear the practice of all magic on penalty of death, and you are hereby exiled from Wesnoth. Be grateful for Our mercy."
                        [/message]
                        [message]
                            speaker=Dolburras
                            #po: "Yeah, fair enough. I don't think my kinsmen will look kindly upon necromancies either."
                            message= _ "Aye, fair enough. I dinnae think my kinsmen will look kindly upon necromancies either."
                        [/message]
                        {CLEAR_VARIABLE plague_staff_wielder_id}
                    [/then]

                    [else]
                        [message]
                            speaker=Konrad
                            image=portraits/konrad_II.webp
                            message= _ "Dolburras, Owaec has told me of the help you provided his men; both your skill at arms and your tenacious spirit. We wish to offer you this finely crafted shield — an heirloom of my line — and an honor guard as you return to Knalga."
                        [/message]
                        [if]
                            [have_unit]
                                id=Owaec
                            [/have_unit]

                            [then]
                                [message]
                                    speaker=Dolburras
                                    #po: "Aye, I am honored. You have my sincerest thanks, your Majesty."
                                    message= _ "Aye, I be honored. Ye have my sincerest thanks, yer Majesty."
                                [/message]
                            [/then]

                            [else]
                                [message]
                                    speaker=Dolburras
                                    #po: Owaec's dead
                                    message= _ "Aye, I be honored. I only wish he were here to see the Clans avenged."
                                [/message]
                            [/else]
                        [/if]
                    [/else]
                [/if]
            [/then]
        [/if]

        #------------------
        # ADDOGIN, HAHID, AND TERRAENT
        #------------------
        [if]
            [have_unit]
                id=Addogin
            [/have_unit]

            [then]
                [delay]
                    time=750
                [/delay]

                [if]
                    {VARIABLE_CONDITIONAL plague_staff_wielder_id equals Addogin}
                    [then]
                        [message]
                            speaker=Konrad
                            image=portraits/konrad_II.webp
                            #po: the player chose to give Addogin the plague staff
                            message= _ "Mercenary, <i>necromancer</i>, know that Wesnoth will never tolerate your kind. You shall surrender that accursed stave to be destroyed, you shall foreswear the practice of all magic on penalty of death, and you are hereby exiled from Wesnoth. Be grateful for Our mercy."
                        [/message]
                        [message]
                            speaker=Addogin
                            message= _ "Yeah, figures. How did I let myself get caught up in all this anyways? Suppose I can always head north to those farmlands we passed by..."
                        [/message]
                        {CLEAR_VARIABLE plague_staff_wielder_id}
                    [/then]

                    [else]
                        [message]
                            speaker=Konrad
                            image=portraits/konrad_II.webp
                            message= _ "Addogin, mercenary captain from the Estmarks. I have heard the story of how you entered Gweddry’s service against your will, but I have also heard that you honored your word to see this invasion through to its end. The palace could use a warrior of such caliber. We would offer you a position in the Royal Guard."
                        [/message]
                        [message]
                            speaker=Addogin
                            message= _ "Sir, uh, milord, uh, King sir, I’m honored, really am, but I just wanna go home. If it’s alright with you, this old geezer will be haulin’ himself back east, to an overdue retirement."
                        [/message]
                        [message]
                            speaker=Konrad
                            image=portraits/konrad_II.webp
                            message= _ "As you wish. Then take this chest of silver, that you may never again need raise sword for coin."
                        [/message]
                    [/else]
                [/if]
            [/then]
        [/if]

        [if]
            [have_unit]
                id=Hahid al-Ali
            [/have_unit]

            [then]
                [delay]
                    time=750
                [/delay]

                [if]
                    {VARIABLE_CONDITIONAL plague_staff_wielder_id equals "Hahid al-Ali"}
                    [then]
                        [message]
                            speaker=Konrad
                            image=portraits/konrad_II.webp
                            #po: the player chose to give Hahid the plague staff
                            message= _ "Southerner, <i>necromancer</i>, know that Wesnoth will never tolerate your kind. You shall surrender that accursed stave to be destroyed, you shall foreswear the practice of all magic on penalty of death, and you are hereby exiled back to the desert wastes. Be grateful for Our mercy."
                        [/message]
                        [message]
                            speaker=Hahid al-Ali
                            message= _ "Bah, I save you barbarians from an invasion, and this is the thanks I get! What happened to being paid thrice what I’m owed? So much for northerner generosity!"
                        [/message]
                        {CLEAR_VARIABLE plague_staff_wielder_id}
                    [/then]

                    [else]
                        [message]
                            speaker=Konrad
                            image=portraits/konrad_II.webp
                            message= _ "Hahid al-Ali, We know of your far-off people, but great distance has caused little contact between us. May it be thus no longer. If you accept, We would appoint you as ambassador between our two realms."
                        [/message]
                        [message]
                            speaker=Hahid al-Ali
                            message= _ "Me, ambassador to the barbarian kingdoms, what a thought! I am honored, and would be even more honored to learn that the job comes with... excellent pay I hope?"
                        [/message]
                    [/else]
                [/if]
            [/then]
        [/if]

        [if]
            [have_unit]
                id=Terraent
            [/have_unit]

            [then]
                [delay]
                    time=750
                [/delay]

                [message]
                    speaker=Konrad
                    image=portraits/konrad_II.webp
                    message= _ "Sir Terraent, your service to the Crown and your unfailing optimism has been a beacon of light in these dark times. If you accept, we would appoint you to command the River Guard in Estmark."
                [/message]
                [message]
                    speaker=Terraent
                    message= _ "It has been an honor to spread the holy Light in this kingdom, and I humbly accept your commission. May the Light shine ever-bright upon the pious."
                [/message]
            [/then]
        [/if]

        #------------------
        # GAENNELL AND PLAGUE-STAFF-WIELDER
        #------------------
        [if]
            [have_unit]
                id=Gaennell
            [/have_unit]

            [then]
                [delay]
                    time=750
                [/delay]

                [if]
                    {VARIABLE_CONDITIONAL plague_staff_wielder_id equals Gaennell}
                    [then]
                        {CLEAR_VARIABLE plague_staff_wielder_id}
                    [/then]
                [/if]
                [if]
                    [have_unit]
                        id=Terraent
                    [/have_unit]

                    [then]
                        [message]
                            speaker=Konrad
                            image=portraits/konrad_II.webp
                            #po: Gaennell’s previous crimes are held against her, regardless of whether or not she has the plague staff now.
                            #po: Terraent is alive, "speaks well of you" meaning he's asked the King to pardon Gaennell.
                            message= _ "As for you, <i>necromancer</i>. We are not as like as Terraent to show mercy unto evil, but he speaks well of you, and so mercy shall be shown. Go from here a free woman, but know that you are hereby forbidden to practice magic in any form, at penalty of death."
                        [/message]
                    [/then]

                    [else]
                        [message]
                            speaker=Konrad
                            image=portraits/konrad_II.webp
                            #po: Gaennell’s previous crimes are held against her, regardless of whether or not she has the plague staff now.
                            #po: Terraent is dead.
                            message= _ "As for you, <i>necromancer</i>. We are not as like as Terraent to show mercy unto evil, but in honor of his sacrifice We will show it now. Go from here a free woman, but know that you are hereby forbidden to practice magic in any form, at penalty of death."
                        [/message]
                    [/else]
                [/if]
                [message]
                    speaker=Gaennell
                    message= _ "<i>Forbidden to-</i>"
                [/message]
                [message]
                    speaker=Gaennell
                    message= _ "... as an adept I’d dreamt of one day standing in this palace, though under... different circumstances. Well, better that I get to keep my head, I guess. I am grateful for Your leniency."
                [/message]
            [/then]
        [/if]

        [if]
            [have_unit]
                id=$plague_staff_wielder_id
            [/have_unit]

            [then]
                [delay]
                    time=750
                [/delay]

                [if]
                    [have_unit]
                        id=Gaennell
                    [/have_unit]

                    [then]
                        [message]
                            speaker=Konrad
                            image=portraits/konrad_II.webp
                            #po: a unit has the plague staff, but they're not one of the loyals. This version of the line is used if Gaennell is here.
                            message= _ "And the same goes for you, wielder of that accursed stave. You shall surrender it to be destroyed, and leave here forbidden to practice magic. Be grateful for Our mercy."
                        [/message]
                    [/then]

                    [else]
                        [message]
                            speaker=Konrad
                            image=portraits/konrad_II.webp
                            #po: a unit has the plague staff, but they're not one of the loyals, and the player doesn't have Gaennell
                            message= _ "As for you, <i>necromancer</i>. You shall surrender that accursed stave to be destroyed, and are hereby forbidden to practice magic in any form, at penalty of death. Be grateful for Our mercy."
                        [/message]
                    [/else]
                [/if]
                [message]
                    speaker=$plague_staff_wielder_id
                    message= _ "As you command, your Majesty."
                [/message]
            [/then]
        [/if]

        #------------------
        # OWAEC AND GWEDDRY
        #------------------
        [if]
            [have_unit]
                id=Owaec
            [/have_unit]

            [then]
                [delay]
                    time=750
                [/delay]

                [message]
                    speaker=Konrad
                    image=portraits/konrad_II.webp
                    message= _ "Owaec, last Prince of the Plains. You and your people have suffered much."
                [/message]
                [message]
                    speaker=Owaec
                    message= _ "My Lord, the Clansmen gladly gave their lives for Wesnoth, and know that I would do the same without hesitation."
                [/message]
                [message]
                    speaker=Konrad
                    image=portraits/konrad_II.webp
                    message= _ "The true test is not to die for one’s King, but to live for Him... Kneel, Owaec."
                [/message]
                [message]
                    speaker=Konrad
                    image=portraits/konrad_II.webp
                    message= _ "And arise, Sir Owaec, High Lord of the Horse Clans! Your people have been shattered, but We trust none more than you to make them whole again. Ride from here, and recover in peace."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=Konrad
                    image=portraits/konrad_II.webp
                    #po: Owaec is dead too
                    message= _ "But alas, what of the Clansmen? Their horses have been scattered, their Lords were broken, and now the last prince has fallen defending the walls of Weldyn. I fear that the Horse Clans will never again return to their former glory."
                [/message]
            [/else]
        [/if]

        [if]
            [have_unit]
                id=Gweddry
            [/have_unit]

            [then]
                [delay]
                    time=750
                [/delay]

                [message]
                    speaker=Konrad
                    image=portraits/konrad_II.webp
                    message= _ "And now what of the humble Gweddry; still but a lieutenant. It seems you are long-overdue for a promotion."
                [/message]
                [message]
                    speaker=Gweddry
                    message= _ "Sire, I but did my duty."
                [/message]
                [message]
                    speaker=Konrad
                    image=portraits/konrad_II.webp
                    message= _ "Quite. Now do not interrupt while I am doing mine... Kneel, Gweddry, lieutenant."
                [/message]
                [message]
                    speaker=Konrad
                    image=portraits/konrad_II.webp
                    message= _ "And arise, Gweddry, Earl of Estmark! The land for which you shed your blood shall be put under your hand to be made green again. May you ever prosper."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=Konrad
                    image=portraits/konrad_II.webp
                    message= _ "And what of Gweddry... He had survived long, sacrificed much, only to meet his end here at the last. I wish he could have lived to see the peace he has wrought."
                [/message]
            [/else]
        [/if]

        [delay]
            time=2000
        [/delay]

        [message]
            speaker=Konrad
            image=portraits/konrad_II.webp
            message= _ "Wesnoth is bowed, but thanks to the efforts of many heroes we stand yet unbroken. And now, at long last, the time has come to rebuild."
        [/message]
        [message]
            speaker=Konrad
            image=portraits/konrad_II.webp
            message= _ "To each of you, take as Our first command to you your own wish! Go from here; secure our borders. Show all that the might of Wesnoth will endure!"
        [/message]

        [if]
            [variable]
                name=dra_nak_dead
                not_equals=yes
            [/variable]
            [variable]
                name=mortic_dead
                not_equals=yes
            [/variable]
            [variable]
                name=fork_18b
                equals=yes
            [/variable]
            [then]
                [endlevel] # bonus scenario
                    result=victory
                    next_scenario=99_Empire
                    carryover_percentage=0
                    carryover_report=no
                    replay_save=no
                    linger_mode=no
                [/endlevel]
            [/then]
            [else]
                [endlevel] # end campaign
                    result=victory
                    carryover_report=no
                    replay_save=no
                    linger_mode=no
                [/endlevel]
            [/else]
        [/if]
    [/event]
[/scenario]
