#textdomain wesnoth-did

[scenario]
    id=12_Endless_Night
    name= _ "Endless Night"
    map_data="{campaigns/Descent_Into_Darkness/maps/12_Endless_Night.map}"
    turns=unlimited
    next_scenario=12_Endless_Night
    victory_when_enemies_defeated=yes

    {UNDERGROUND}
    [time_area]
        x=27-31,26,21-25
        y=0-5,2-4,0-2
        {DEFAULT_SCHEDULE}
    [/time_area]

    [story]
        [part]
            music=transience.ogg
            story= _ "Years pass. Every summer, by the time the mountainous paths and high passes shed their wintry gowns of snow, the lich sends his soldiers to attack the orcs, removing all human, elven, and dwarven patrols that impede them. Every year, the undead inflict some damage before being repelled."
            {STORYTXT_BACKGROUND end.jpg}
        [/part]
        # a bit of extra text for the first round
        [if]
            {VARIABLE_CONDITIONAL timesForever numerical_equals 0}
            [then]
                [part]
                    story= _ "The lich sometimes wonders if his endeavors are naught but a fruitless crusade, but then again, so what? Life, unlife, death... nothing has ever given his existence meaning. And yet, he still persists on? For what?"
                    {STORYTXT_BACKGROUND end.jpg}
                [/part]
                [part]
                    story= _ "<i>Reason and purpose...</i>"
                    {STORYTXT_BACKGROUND end.jpg}
                [/part]
                [part]
                    story= _ "He needs none. Philosophy only begets misery. Violence and savagery have been the essence of his existence, the forces that once controlled his life, the ones unrelinquished in undeath. Better to simply kill without deliberation, for what use is there to dwell on any alternative? He has never been one for regrets."
                    {STORYTXT_BACKGROUND end.jpg}
                [/part]
            [/then]
        [/if]
        # These if statements are before the prestart event, so are off-by-one compared to the other checks of timesForever
        [if]
            {VARIABLE_CONDITIONAL timesForever numerical_equals 1}
            [then]
                [part]
                    story= _ "Mal Keshar continues to study the book and re-reads the final entry."
                    {STORYTXT_BACKGROUND end.jpg}
                [/part]
                [part]
                    # po: This text comes from the epilogue of Secrets of the Ancients, edited to avoid revealing the name of the campaign or the names of the protagonists
                    story = _"<i>“We prevailed today on the field, but our victory did not please me. I realize now... the world is not ready for our knowledge. They cannot understand that we have conquered that primordial fear: death. Instead, as they look upon us, judgment of our appearance drives them to ignorant terror. I give up on all of them. [...] In some future time, less conservative attitudes may dominate, and our knowledge can be put to good use. I can certainly afford to wait. In the meantime, we are doing what we can to hasten that day.”</i>"
                    {STORYTXT_BACKGROUND book.jpg}
                [/part]
                [part]
                    # po: More text from the epilogue of Secrets of the Ancients
                    story= _ "<i>“As for me, I will make my journal conspicuous on this battlefield. I suspect that most will fear it enough to try to destroy it, but I have placed several wards on my journal to protect it. This way, it should survive long enough to make its way into the hands of someone more open-minded. Tath, in particular, is home to many mages. It only takes one who is willing to learn...”</i>"
                    {STORYTXT_BACKGROUND book.jpg}
                [/part]
            [/then]
        [/if]
        [if]
            {VARIABLE_CONDITIONAL timesForever numerical_equals 2}
            [then]
                [part]
                    # po: This text comes from the epilogue of Secrets of the Ancients, edited to avoid revealing the name of the campaign or the names of the protagonists
                    story = _"<i>“We prevailed today on the field, but our victory did not please me. I realize now... the world is not ready for our knowledge. They cannot understand that we have conquered that primordial fear: death. Instead, as they look upon us, judgment of our appearance drives them to ignorant terror. I give up on all of them. [...] In some future time, less conservative attitudes may dominate, and our knowledge can be put to good use. I can certainly afford to wait. In the meantime, we are doing what we can to hasten that day.”</i>"
                    {STORYTXT_BACKGROUND book.jpg}
                [/part]
                [part]
                    # po: More text from the epilogue of Secrets of the Ancients
                    story= _ "<i>“As for me, I will make my journal conspicuous on this battlefield. I suspect that most will fear it enough to try to destroy it, but I have placed several wards on my journal to protect it. This way, it should survive long enough to make its way into the hands of someone more open-minded. Tath, in particular, is home to many mages. It only takes one who is willing to learn...”</i>"
                    {STORYTXT_BACKGROUND book.jpg}
                [/part]
                [part]
                    story= _ "The final entry gnaws at Mal Keshar. While he had been Darken Volk’s pawn, both of them were being used as pawns by the author of the book. Has his whole existence been nothing more than that of a puppet?"
                    {STORYTXT_BACKGROUND end.jpg}
                [/part]
                [part]
                    story= _ "Still, despite his misgivings about being manipulated, he feels that he can learn something from the book. Orcs had only ever been half of the story — the other had been his own people being unable to accept his use of dark magic. But, if he allowed a foolish hero to take a copy of the book, would others eventually follow in his footsteps? If enough people began to view necromancy as merely another magical art, could it eventually be accepted in society?"
                    {STORYTXT_BACKGROUND end.jpg}
                [/part]
            [/then]
        [/if]
        [if]
            {VARIABLE_CONDITIONAL timesForever greater_than 2}
            [then]
                [part]
                    story= _ "The book still sits on a dusty shelf in Mal Keshar’s keep, untended and untouched, but constantly plaguing the forefront of the lich’s mind."
                    {STORYTXT_BACKGROUND end.jpg}
                [/part]
                [part]
                    story= _ "If he allowed a foolish hero to take a copy of the book, would others eventually follow in his footsteps? Would the author’s plan actually work, or would people continue to view necromancy as only a corrupting power? One voice tells him that being accepted by society should not be of any concern to him. Another says that it would not harm him to try. He does not come to any conclusions, but a slightly embellished copy of the tome sits there in his lair, waiting to be taken."
                    {STORYTXT_BACKGROUND end.jpg}
                [/part]
            [/then]
        [/if]
        [part]
            story= _ "Rumors circulate of a lich who preys on scouting patrols. A hero, gathering his loyal troops to him, decides to put an end to the evil."
            {STORYTXT_BACKGROUND end.jpg}
        [/part]
    [/story]

    {DID_TRACK {JOURNEY_12_NEW}}

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        save_id=Malin Keshar
        recruit=Walking Corpse,Vampire Bat,Ghost,Ghoul,Skeleton Archer,Skeleton,Dark Adept
        {GOLD 220 200 180}
        team_name=good
        village_gold=1
        user_team_name= _ "Mal Keshar"
        {FLAG_VARIANT undead}

        # wmllint: recognize Mal Keshar
        {CHARACTER_STATS_MAL_KESHAR}

        facing=ne
    [/side]
    # wmllint: validate-on

    # Foolish Hero
    [side]
        side=2
        controller=ai
        # Place leader, grant gold, income and recruits later
        no_leader=yes
        gold=0
        {NO_INCOME}
        # Set ai values later
    [/side]

    # Too Foolish Hero
    [side]
        side=3
        controller=ai
        # Place leader, grant gold, income and recruits later
        no_leader=yes
        hidden=yes
        gold=0
        {NO_INCOME}
        # Set ai values later
    [/side]

    {STARTING_VILLAGES 1 15}

    [event]
        name=prestart

        {CLEAR_CORPSE_HORDE}

        {VARIABLE_OP timesForever add 1}
        {VARIABLE second_hero_arrived 0}

        [objectives]
            side=1
            delayed_variable_substitution=yes #so timesForever note works correctly when using debug
            [objective]
                condition=win
                description= _ "Defeat the foolish hero"
                [show_if]
                    {VARIABLE_CONDITIONAL timesForever less_than_equal_to 1}
                [/show_if]
            [/objective]

            [objective]
                condition=win
                description= _ "Defeat another foolish hero"
                [show_if]
                    {VARIABLE_CONDITIONAL timesForever numerical_equals 2}
                [/show_if]
            [/objective]

            [objective]
                condition=win
                description= _ "Defeat yet another foolish hero"
                [show_if]
                    {VARIABLE_CONDITIONAL timesForever greater_than_equal_to 3}
                    [and]
                        {VARIABLE_CONDITIONAL second_hero_arrived numerical_equals 0}
                    [/and]
                [/show_if]
            [/objective]

            [objective]
                condition=win
                description= _ "Defeat both foolish heroes"
                [show_if]
                    {VARIABLE_CONDITIONAL second_hero_arrived numerical_equals 1}
                [/show_if]
            [/objective]

            [objective]
                condition=lose
                description= _ "Destruction of Mal Keshar"
                [show_if]
                    {VARIABLE_CONDITIONAL timesForever less_than_equal_to 2}
                [/show_if]
            [/objective]

            [objective]
                {ALTERNATIVE_OBJECTIVE_CAPTION}
                condition=win
                description= _ "Allow an enemy unit to take the book"
                [show_if]
                    {VARIABLE_CONDITIONAL timesForever greater_than_equal_to 3}
                [/show_if]
            [/objective]

            [objective]
                {ALTERNATIVE_OBJECTIVE_CAPTION}
                condition=win
                description= _ "Destruction of Mal Keshar"
                [show_if]
                    {VARIABLE_CONDITIONAL timesForever greater_than_equal_to 3}
                [/show_if]
            [/objective]

            [gold_carryover]
                carryover_percentage=40
            [/gold_carryover]

            [note]
                description="<b>" + _ "Endless Night $timesForever" + "</b>"
            [/note]

            [note]
                # po: more text copied from Secrets of the Ancients
                description= _ "To turn a necromancer into a lich, right-click on it while it is in a castle."
            [/note]

            {HAS_NO_TURN_LIMIT}

            # No {IS_LAST_SCENARIO}, because the player can win and keep on playing
        [/objectives]

        {MODIFY_UNIT (id=Mal Keshar) profile (portraits/malin_lich-ancient.png)}

        # There is now a menu option to turn necromancers into liches.
        [set_menu_item]
            id=lichify
            description= _ "Transform into a lich"
            image=units/icons/icon-lich.png
            [show_if]
                [have_unit]
                    x=$x1
                    y=$y1
                    side=1
                    type=Necromancer
                [/have_unit]
            [/show_if]
            [command]
                [if]
                    [have_location]
                        x=$x1
                        y=$y1
                        terrain=C*^*,K*^*,*^K*,*^C*  # castles and keeps
                    [/have_location]
                    [then]
                        [fire_event]
                            name=lichify  # See DiD's macros.cfg, or SotA’s sota-utils.cfg
                            [primary_unit]
                                x=$x1
                                y=$y1
                            [/primary_unit]
                        [/fire_event]
                    [/then]
                    [else]
                        [message]
                            speaker=narrator
                            image=misc/makeshift-altar.png
                            message= _ "You can only do this in a castle."
                        [/message]
                    [/else]
                [/if]
            [/command]
        [/set_menu_item]

        [if]
            {VARIABLE_CONDITIONAL timesForever greater_than 1}

            [then]
                {VARIABLE previous_previous_randomHero $previous_randomHero}
                {VARIABLE previous_randomHero $randomHero}
            [/then]

            [else]
                {VARIABLE previous_previous_randomHero -1}
                {VARIABLE previous_randomHero -1}
            [/else]
        [/if]

        # let's pick a random hero type...
        {VARIABLE_OP randomHero rand (human,bandit,elf,dwarf,orc)}

        # and make sure it's not the same as last time
        [while]
            {VARIABLE_CONDITIONAL randomHero equals $previous_randomHero}

            [or]
                {VARIABLE_CONDITIONAL randomHero equals $previous_previous_randomHero}
            [/or]

            [do]
                {VARIABLE_OP randomHero rand (human,bandit,elf,dwarf,orc)}
            [/do]
        [/while]

        [if]
            {VARIABLE_CONDITIONAL timesForever greater_than 4}

            [then]
                [replace_map]
                    map="{campaigns/Descent_Into_Darkness/maps/12a_Endless_Night.map}"
                    expand=yes
                    shrink=yes
                [/replace_map]

                # don't let the two foolish heroes be from the same faction
                {VARIABLE_OP randomHero2 rand (human,bandit,elf,dwarf,orc)}

                [while]
                    {VARIABLE_CONDITIONAL randomHero2 equals $randomHero}

                    [do]
                        {VARIABLE_OP randomHero2 rand (human,bandit,elf,dwarf,orc)}
                    [/do]
                [/while]

                {VARIABLE_OP flankturn rand 5..10}

                [event]
                    name=new turn
                    [filter_condition]
                        [variable]
                            name=turn_number
                            numerical_equals=$flankturn
                        [/variable]
                    [/filter_condition]

                    # the text here is duplicated from below
                    [switch]
                        variable=randomHero2
                        [case]
                            value=human
                            [scroll_to]
                                x,y=2,50
                            [/scroll_to]

                            [move_unit_fake]
                                type="Royal Guard"
                                side=3
                                x= 2, 6, 8
                                y=50,49,46
                            [/move_unit_fake]

                            [unit]
                                side=3
                                type=Royal Guard
                                id=Too Foolish Hero
                                name= _ "Too Foolish Hero"
                                x,y=8,46
                                canrecruit=yes
                                animate=no
                                facing=ne
                            [/unit]

                            [terrain]
                                x,y=8,46
                                terrain=Ke
                            [/terrain]
                            [terrain]
                                x=   7,8-9,10
                                y=46-47,47,45-47
                                terrain=Ce
                            [/terrain]
                            [terrain]
                                x= 9, 5,12, 5
                                y=49,45,46,48
                                terrain=Uu^Vct
                            [/terrain]
                            [redraw][/redraw]

                            [capture_village]
                                side=3
                                x= 9, 5,12, 5
                                y=49,45,46,48
                            [/capture_village]

                            [message]
                                speaker=Too Foolish Hero
                                # po: the text that the "Too Foolish Hero" speaks is identical to that in the start event and can probably be copied over
                                message= _ "Your doom is at hand, lich! It is nigh time you answered for your evil crimes!"
                            [/message]

                            [modify_side]
                                side=3
                                user_team_name= _ "Humans"
                                {FLAG_VARIANT loyalist}
                                recruit=Spearman,Swordsman,Pikeman,Bowman,Longbowman,Heavy Infantryman,Shock Trooper,Mage,Red Mage,White Mage,Horseman,Knight,Lancer
                            [/modify_side]

                            {INCIDENTAL_MUSIC loyalists.ogg}
                        [/case]

                        [case]
                            value=bandit
                            [scroll_to]
                                x,y=2,50
                            [/scroll_to]

                            [move_unit_fake]
                                type=Highwayman
                                side=3
                                x= 2, 6, 8
                                y=50,49,46
                            [/move_unit_fake]

                            [unit]
                                side=3
                                type=Highwayman
                                id=Too Foolish Hero
                                name= _ "Too Foolish Hero"
                                x,y=8,46
                                canrecruit=yes
                                animate=no
                                facing=ne
                            [/unit]

                            [terrain]
                                x,y=8,46
                                terrain=Ke
                            [/terrain]
                            [terrain]
                                x=   7,8-9,10
                                y=46-47,47,45-47
                                terrain=Ce
                            [/terrain]
                            [terrain]
                                x= 9, 5,12, 5
                                y=49,45,46,48
                                terrain=Uu^Vct
                            [/terrain]
                            [redraw][/redraw]

                            [capture_village]
                                side=3
                                x= 9, 5,12, 5
                                y=49,45,46,48
                            [/capture_village]

                            [message]
                                speaker=Too Foolish Hero
                                message= _ "You have preyed on too many of my men. Our territory will be much more secure without your undead pestering us."
                            [/message]

                            [modify_side]
                                side=3
                                user_team_name= _ "Bandits"
                                # default flag
                                recruit=Thug,Bandit,Footpad,Outlaw,Poacher,Trapper,Thief,Rogue
                            [/modify_side]

                            {INCIDENTAL_MUSIC knolls.ogg}
                        [/case]

                        [case]
                            value=elf
                            [scroll_to]
                                x,y=2,50
                            [/scroll_to]

                            [move_unit_fake]
                                type="Elvish Marshal"
                                side=3
                                x= 2, 6, 8
                                y=50,49,46
                            [/move_unit_fake]

                            [unit]
                                side=3
                                type=Elvish Marshal
                                id=Too Foolish Hero
                                name= _ "Too Foolish Hero"
                                x,y=8,46
                                canrecruit=yes
                                animate=no
                                facing=ne
                            [/unit]

                            [terrain]
                                x,y=8,46
                                terrain=Ke
                            [/terrain]
                            [terrain]
                                x=   7,8-9,10
                                y=46-47,47,45-47
                                terrain=Ce
                            [/terrain]
                            [terrain]
                                x= 9, 5,12, 5
                                y=49,45,46,48
                                terrain=Uu^Vct
                            [/terrain]
                            [redraw][/redraw]

                            [capture_village]
                                side=3
                                x= 9, 5,12, 5
                                y=49,45,46,48
                            [/capture_village]

                            [message]
                                speaker=Too Foolish Hero
                                message= _ "We have finally found you, lich! Long have we heard of your abominable deeds, ensnaring the living with your dark sorceries and molding them into your slaves. Your wretched unlife ends here!"
                            [/message]

                            [modify_side]
                                side=3
                                user_team_name= _ "Elves"
                                {FLAG_VARIANT wood-elvish}
                                recruit=Elvish Fighter,Elvish Hero,Elvish Captain,Elvish Archer,Elvish Ranger,Elvish Marksman,Elvish Shaman,Elvish Sorceress,Elvish Druid,Elvish Scout,Elvish Rider,Wose
                            [/modify_side]

                            {INCIDENTAL_MUSIC elvish-theme.ogg}
                        [/case]

                        [case]
                            value=dwarf
                            [scroll_to]
                                x,y=2,50
                            [/scroll_to]

                            [move_unit_fake]
                                type="Dwarvish Lord"
                                side=3
                                x= 2, 6, 8
                                y=50,49,46
                            [/move_unit_fake]

                            [unit]
                                side=3
                                type=Dwarvish Lord
                                id=Too Foolish Hero
                                name= _ "Too Foolish Hero"
                                x,y=8,46
                                canrecruit=yes
                                animate=no
                                facing=ne
                            [/unit]

                            [terrain]
                                x,y=8,46
                                terrain=Ke
                            [/terrain]
                            [terrain]
                                x=   7,8-9,10
                                y=46-47,47,45-47
                                terrain=Ce
                            [/terrain]
                            [terrain]
                                x= 9, 5,12, 5
                                y=49,45,46,48
                                terrain=Uu^Vct
                            [/terrain]
                            [redraw][/redraw]

                            [capture_village]
                                side=3
                                x= 9, 5,12, 5
                                y=49,45,46,48
                            [/capture_village]

                            [message]
                                speaker=Too Foolish Hero
                                # po: written with a dwarvish accent - regular english would be "it's been along time since I've smashed some undead. You've got plenty of bones for my hammer to break"
                                message= _ "Been a long time since I’ve smashed me some undead. Ye gots ye plenty o’ bones for me hammer ta break."
                            [/message]

                            [modify_side]
                                side=3
                                user_team_name= _ "Dwarves"
                                {FLAG_VARIANT knalgan}
                                recruit=Dwarvish Fighter,Dwarvish Steelclad,Dwarvish Thunderer,Dwarvish Thunderguard,Dwarvish Stalwart,Dwarvish Guardsman,Dwarvish Ulfserker,Dwarvish Berserker,Dwarvish Scout,Dwarvish Pathfinder,Gryphon Rider,Gryphon Master
                            [/modify_side]

                            {INCIDENTAL_MUSIC knalgan_theme.ogg}
                        [/case]

                        [case]
                            value=orc
                            [scroll_to]
                                x,y=2,50
                            [/scroll_to]

                            [move_unit_fake]
                                type="Orcish Warlord"
                                side=3
                                x= 2, 6, 8
                                y=50,49,46
                            [/move_unit_fake]

                            [unit]
                                side=3
                                type=Orcish Warlord
                                id=Too Foolish Hero
                                name= _ "Too Foolish Hero"
                                x,y=8,46
                                canrecruit=yes
                                animate=no
                                facing=ne
                            [/unit]

                            [terrain]
                                x,y=8,46
                                terrain=Ke
                            [/terrain]
                            [terrain]
                                x=   7,8-9,10
                                y=46-47,47,45-47
                                terrain=Ce
                            [/terrain]
                            [terrain]
                                x= 9, 5,12, 5
                                y=49,45,46,48
                                terrain=Uu^Vct
                            [/terrain]
                            [redraw][/redraw]

                            [capture_village]
                                side=3
                                x= 9, 5,12, 5
                                y=49,45,46,48
                            [/capture_village]

                            [modify_side]
                                side=3
                                user_team_name= _ "Orcs"
                                {FLAG_VARIANT6 ragged}
                                recruit=Orcish Warrior,Orcish Slayer,Orcish Crossbowman,Troll,Troll Rocklobber
                            [/modify_side]

                            [message]
                                speaker=Too Foolish Hero
                                message= _ "I’ve finally found your lair, lich! You have attacked my tribe and wreaked havoc on our homes for many years. You slew my father and turned his body into one of your nasty creations. With your death, your annoying minions will pester us no longer!"
                            [/message]

                            {INCIDENTAL_MUSIC northerners.ogg}
                        [/case]
                    [/switch]

                    [message]
                        speaker=Mal Keshar
                        message= _ "I almost feel as if the universe is mocking me by sending me this many imbeciles..."
                    [/message]

                    [modify_side]
                        side=3
                        hidden=no
                        team_name=enemies
#ifdef EASY
                        gold="$(140 + 40 * $timesForever)"
                        income="$(5 + 1 * $timesForever)"
#endif
#ifdef NORMAL
                        gold="$(170 + 50 * $timesForever)"
                        income="$(6 + 2 * $timesForever)"
#endif
#ifdef HARD
                        gold="$(200 + 60 * $timesForever)"
                        income="$(7 + 3 * $timesForever)"
#endif
                        # see comments on lines 822 and 823 regarding aggression
                        [ai]
                            aggression="$(min( [1.0, (0.3 + 0.1 * $timesForever) ] ) )"
                            villages_per_scout=10
                            village_value=0.5
                        [/ai]
                    [/modify_side]

                    {VARIABLE second_hero_arrived 1}

                    [show_objectives]
                        side=1
                    [/show_objectives]
                [/event]
            [/then]
        [/if]

        [switch]
            variable=randomHero
            [case]
                value=human
                [unit]
                    side=2
                    type=Royal Guard
                    id=Foolish Hero
                    name= _ "Foolish Hero"
                    x,y=22,4
                    canrecruit=yes
                    facing=sw
                [/unit]

                [modify_side]
                    side=2
                    user_team_name= _ "Humans"
                    {FLAG_VARIANT loyalist}
                    recruit=Spearman,Swordsman,Pikeman,Bowman,Longbowman,Heavy Infantryman,Shock Trooper,Mage,Red Mage,White Mage,Horseman,Knight,Lancer
                [/modify_side]

                {REPLACE_SCENARIO_MUSIC loyalists.ogg}
            [/case]

            [case]
                value=bandit
                [unit]
                    side=2
                    type=Highwayman
                    id=Foolish Hero
                    name= _ "Foolish Hero"
                    x,y=22,4
                    canrecruit=yes
                    facing=sw
                [/unit]

                [modify_side]
                    side=2
                    user_team_name= _ "Bandits"
                    # default flag
                    recruit=Thug,Bandit,Footpad,Outlaw,Poacher,Trapper,Thief,Rogue
                [/modify_side]

                {REPLACE_SCENARIO_MUSIC knolls.ogg}
            [/case]

            [case]
                value=elf
                [unit]
                    side=2
                    type=Elvish Marshal
                    id=Foolish Hero
                    name= _ "Foolish Hero"
                    x,y=22,4
                    canrecruit=yes
                    facing=sw
                [/unit]

                [modify_side]
                    side=2
                    user_team_name= _ "Elves"
                    {FLAG_VARIANT wood-elvish}
                    recruit=Elvish Fighter,Elvish Hero,Elvish Captain,Elvish Archer,Elvish Ranger,Elvish Marksman,Elvish Shaman,Elvish Sorceress,Elvish Druid,Elvish Scout,Elvish Rider,Wose
                [/modify_side]

                {REPLACE_SCENARIO_MUSIC elvish-theme.ogg}
            [/case]

            [case]
                value=dwarf
                [unit]
                    side=2
                    type=Dwarvish Lord
                    id=Foolish Hero
                    name= _ "Foolish Hero"
                    x,y=22,4
                    canrecruit=yes
                    facing=sw
                [/unit]

                [modify_side]
                    side=2
                    user_team_name= _ "Dwarves"
                    {FLAG_VARIANT knalgan}
                    recruit=Dwarvish Fighter,Dwarvish Steelclad,Dwarvish Thunderer,Dwarvish Thunderguard,Dwarvish Stalwart,Dwarvish Guardsman,Dwarvish Ulfserker,Dwarvish Berserker,Dwarvish Scout,Dwarvish Pathfinder,Gryphon Rider,Gryphon Master
                [/modify_side]

                {REPLACE_SCENARIO_MUSIC knalgan_theme.ogg}
            [/case]

            [case]
                value=orc
                [unit]
                    side=2
                    type=Orcish Warlord
                    id=Foolish Hero
                    name= _ "Foolish Hero"
                    x,y=22,4
                    canrecruit=yes
                    facing=sw
                [/unit]

                [modify_side]
                    side=2
                    user_team_name= _ "Orcs"
                    {FLAG_VARIANT6 ragged}
                    recruit=Orcish Warrior,Orcish Slayer,Orcish Crossbowman,Troll,Troll Rocklobber
                [/modify_side]

                {REPLACE_SCENARIO_MUSIC northerners.ogg}
            [/case]
        [/switch]

        [capture_village]
            side=2
            x=21,19,25,24
            y= 2, 5, 4, 6
        [/capture_village]

        # Give the foolish hero gold & income based on timesForever
        # Set ai aggression, it hits 1.0 at 7 timesForever, ensuring the enemy will attack.
        [modify_side]
            side=2
            team_name=enemies
#ifdef EASY
            gold="$(200 + 40 * $timesForever)"
            income="$(5 + 5 * $timesForever)"
#endif
#ifdef NORMAL
            gold="$(230 + 50 * $timesForever)"
            income="$(6 + 6 * $timesForever)"
#endif
#ifdef HARD
            gold="$(260 + 60 * $timesForever)"
            income="$(7 + 7 * $timesForever)"
#endif
            [ai]
                aggression="$(min( [1.0, (0.3 + 0.1 * $timesForever) ] ) )"
                villages_per_scout=10
                village_value=0.5
            [/ai]
        [/modify_side]

        # play only sad music after a few repetitions
        [if]
            {VARIABLE_CONDITIONAL timesForever greater_than_equal_to 3}
            [then]
                [music]
                    name=the_king_is_dead.ogg
                    append=yes
                [/music]
                [music]
                    name=weight_of_revenge.ogg
                    append=yes
                [/music]
                [music]
                    name=nunc_dimittis.ogg
                    append=yes
                [/music]
            [/then]
            [else]
                [music]
                    name=battle.ogg
                    append=yes
                [/music]
                [music]
                    name=casualties_of_war.ogg
                    append=yes
                [/music]
            [/else]
        [/if]

        [recall]
            type=Skeletal Dragon
            x,y=28,19
        [/recall]
    [/event]

    [event]
        name=start

        # Additional dialog depending on how many times the scenario has been played
        [switch]
            variable=timesForever
            [case]
                value=1
                # no additional dialog
            [/case]
            [case]
                value=2
                [message]
                    speaker=Mal Keshar
                    message= _ "I will destroy you like the last foolish hero who challenged me."
                [/message]
            [/case]
            [case]
                value=3
                [message]
                    speaker=Mal Keshar
                    message= _ "Another foolish hero? Seriously?"
                [/message]
            [/case]
            [case]
                value=4
                [message]
                    speaker=Mal Keshar
                    message= _ "Is there an endless supply of foolish heroes with death wishes? Honestly, where do you all come from?"
                [/message]
            [/case]
            [else]
                # 5 and up
                {RANDOM 1..4}
                [switch]
                    variable=random
                    [case]
                        value=1
                        [message]
                            speaker=Mal Keshar
                            message= _ "Am I doomed to fight foolish heroes forever?"
                        [/message]
                    [/case]
                    [case]
                        value=2
                        [message]
                            speaker=Mal Keshar
                            message= _ "How long is this going to keep happening?"
                        [/message]
                    [/case]
                    [case]
                        value=3
                        [message]
                            speaker=Mal Keshar
                            message= _ "..."
                        [/message]
                    [/case]
                    [else]
                        [message]
                            speaker=Mal Keshar
                            message= _ "At this point, I would be more surprised if these foolish heroes stopped showing up."
                        [/message]
                    [/else]
                [/switch]
                {CLEAR_VARIABLE random}
            [/else]
        [/switch]

        [switch]
            variable=randomHero
            [case]
                value=human
                [message]
                    speaker=Foolish Hero
                    message= _ "Your doom is at hand, lich! It is nigh time you answered for your crimes against humanity!"
                [/message]

                [message]
                    speaker=Mal Keshar
                    # po: cityfolk - just a person from the city, e.g. Weldyn
                    message= _ "Narrow-minded and obtuse, as one would expect of cityfolk. Go back to your manors and taverns before I decide to kill you."
                [/message]
            [/case]

            [case]
                value=bandit
                [message]
                    speaker=Foolish Hero
                    message= _ "You have preyed on too many of my men. Our territory will be much more secure without your undead pestering us."
                [/message]

                [message]
                    speaker=Mal Keshar
                    message= _ "Not even real soldiers. How meaningless."
                [/message]
            [/case]

            [case]
                value=elf
                [message]
                    speaker=Foolish Hero
                    message= _ "We have finally found you, lich! Long have we heard of your abominable deeds, ensnaring the living with your dark sorceries and molding them into your slaves. Your wretched unlife ends here!"
                [/message]

                [message]
                    speaker=Mal Keshar
                    message= _ "Life or death, it is all the same. There are always those who try to kill me. Ever do they fail."
                [/message]
            [/case]

            [case]
                value=dwarf
                [message]
                    speaker=Foolish Hero
                    # po: written with a dwarvish accent - regular english would be "it's been along time since I've smashed some undead. You've got plenty of bones for my hammer to break"
                    message= _ "Been a long time since I’ve smashed me some undead. Ye gots ye plenty o’ bones for me hammer ta break."
                [/message]

                [message]
                    speaker=Mal Keshar
                    message= _ "And it has been some time since I’ve had a supply of dwarven corpses to work with. I suppose I can put your hammers to good use in the mines."
                [/message]
            [/case]

            [case]
                value=orc
                [message]
                    speaker=Foolish Hero
                    message= _ "I’ve finally found your lair, lich! You have attacked my tribe and wreaked havoc on our homes for many years. You slew my father and turned his body into one of your nasty creations. With your death, your annoying minions will pester us no longer!"
                [/message]

                [message]
                    speaker=Mal Keshar
                    message= _ "The Whitefang Orcs! It is you who despoiled my motherland and razed my home. It is you who forced me to resort to necromancy to protect myself. It is you who ended my mortal life and forced me to become a lich. And you desire vengeance? Hah! The irony of this would be hysterical if I could still feel such an emotion."
                [/message]
            [/case]
        [/switch]

        # this event is after the prestart event, so it will happen on the first iteration
        [if]
            {VARIABLE_CONDITIONAL timesForever numerical_equals 1}
            [then]
                [message]
                    speaker=narrator
                    image=misc/makeshift-altar.png
                    message= _ "Mal Keshar has had time to study the book, learning how his apprentices can become liches with less reliance on luck than Malin’s own transformation."
                [/message]
            [/then]
        [/if]

        # Place the book, and add a victory event if the foolish hero's army
        # takes it. Should the unit have to make its way back to the enemy
        # keep? Probably not, Mal Keshar is going to let it go anyway; maybe
        # he should have to kill the first unit that picks it up and let a
        # second enemy pick it up, to make it more convincing for the foolish
        # hero.
        #
        # The dialog would be wrong if the hero picked up the book themselves,
        # but that's unlikely to happen, the hero is likely to stay on the keep
        # to recruit.
        [if]
            {VARIABLE_CONDITIONAL timesForever greater_than_equal_to 3}
            [then]
                {PLACE_IMAGE (items/book5.png) 17 27}

                [event]
                    name=moveto
                    first_time_only=yes
                    [filter]
                        x,y=17,27
                        side=2,3
                    [/filter]

                    [remove_item]
                        x,y=$x1,$y1
                        image="items/book5.png"
                    [/remove_item]

                    [if]
                        [have_unit]
                            x,y=$x1,$y1
                            side=2
                        [/have_unit]
                        [then]
                            [role]
                                id=Foolish Hero
                                role=speakinghero
                            [/role]
                            {VARIABLE hero_type $randomHero}
                        [/then]
                        [else]
                            [role]
                                id=Too Foolish Hero
                                role=speakinghero
                            [/role]
                            {VARIABLE hero_type $randomHero2}
                        [/else]
                    [/if]
                    [switch]
                        variable=hero_type
                        [case]
                            value=human
                            [message]
                                speaker=unit
                                message= _ "That’s an evil grimoire!"
                            [/message]

                            [message]
                                role=speakinghero
                                message= _ "It might be linked to the lich’s power! Try burning it."
                            [/message]

                            [message]
                                speaker=Mal Keshar
                                message= _ "<small>(faking pain)</small> Aaargh!"
                            [/message]

                            [message]
                                role=unit
                                message= _ "It’s not catching fire!"
                            [/message]

                            [message]
                                role=speakinghero
                                message= _ "Still, it seems to be hurting the lich. Let us retreat and bring it with us. The mages may be able to destroy this and put an end to this lich."
                            [/message]
                        [/case]

                        [case]
                            value=bandit
                            [message]
                                speaker=unit
                                message= _ "That’s an evil grimoire!"
                            [/message]

                            [message]
                                role=speakinghero
                                message= _ "It might be linked to the lich’s power! Try burning it."
                            [/message]

                            [message]
                                speaker=Mal Keshar
                                message= _ "<small>(faking pain)</small> Aaargh!"
                            [/message]

                            [message]
                                role=unit
                                message= _ "It’s not catching fire!"
                            [/message]

                            [message]
                                role=speakinghero
                                message= _ "Still, it seems to be hurting the lich. Let us retreat and bring it with us. We may yet find another way to destroy it and put an end to this lich."
                            [/message]
                        [/case]

                        [case]
                            value=elf
                            [message]
                                speaker=unit
                                message= _ "That’s an evil grimoire!"
                            [/message]

                            [message]
                                role=speakinghero
                                # po: "faerie fire" as in the elvish sylph's attack
                                message= _ "It must be connected to the lich’s power. Perhaps if we burn it with faerie fire, the lich will be destroyed. Let us take it and retreat."
                            [/message]
                        [/case]

                        [case]
                            value=dwarf
                            [message]
                                speaker=unit
                                # po: regular english: That's an evil grimoire!
                                message= _ "That be an evil grimoire!"
                            [/message]

                            [message]
                                role=speakinghero
                                # po: regular english: Try destroying the darned thing.
                                message= _ "Try destroyin’ the blasted thing."
                            [/message]

                            [message]
                                speaker=Mal Keshar
                                message= _ "<small>(faking pain)</small> Aaargh!"
                            [/message]

                            [message]
                                speaker=unit
                                # po: regular english: My axe can't cut the paper. It's protected by magic!
                                message= _ "Me axe kinna cut tha paper. It be protected by magic!"
                            [/message]

                            [message]
                                role=speakinghero
                                # po: regular english: Yes, but the lich still seems to be hurt. Let's take it and retreat. Maybe the forge can destroy it.
                                message= _ "Aye, but the lich still seems ta be hurtin’. Let’s take it ’n retreat. Maybe tha forge ken destroy it."
                            [/message]
                        [/case]

                        [case]
                            value=orc
                            [message]
                                speaker=unit
                                # po: this orc has bad grammar on purpose
                                message= _ "Me like skull on book. It look good."
                            [/message]

                            [message]
                                role=speakinghero
                                message= _ "Idiot."
                            [/message]

                            [message]
                                speaker=Mal Keshar
                                message= _ "<small>(faking pain)</small> Aaargh!"
                            [/message]

                            [message]
                                speaker=unit
                                # po: still the same orc, still has bad grammar. Uuuuuh is a whine-like sound, indicating disappointment.
                                message= _ "Uuuuuh, I can’t pull skull off book, but lich scream."
                            [/message]

                            [message]
                                speaker=Mal Keshar
                                message= _ "Defend the book, my minions! Aaargh!"
                            [/message]

                            [message]
                                role=speakinghero
                                message= _ "The book must be connected to the lich’s power! Take it and retreat. Once we smash that book, the lich should be destroyed."
                            [/message]
                        [/case]
                    [/switch]

                    [story]
                        title= _ "Epilogue"
                        [part]
                            story= _ "The foolish hero was tricked, and left believing both that the book could be destroyed, and that the lich might be weakened by doing so."
                            {STORYTXT_BACKGROUND end.jpg}
                        [/part]
                        [part]
                            story= _ "Retreating outside the cave, the foolish hero tried to destroy the book. None of the attempts left so much as a single dent or char, yet each one caused another scream to echo from the cave mouth. Eventually, the cave entrance collapsed, and everything was still. Satisfied, and slightly intrigued, the foolish hero left the ruined lair behind, book stowed away safely — and secretly — in his pack."
                            {STORYTXT_BACKGROUND end.jpg}
                        [/part]
                        [part]
                            story= _ "Years pass. Every summer, by the time the mountainous paths and high passes shed their wintry gowns of snow, humans, elves and dwarves patrol to resist orcish raiders. Undead no longer trouble the watches and memories of the lich fade to mere legend."
                            {STORYTXT_BACKGROUND end.jpg}
                        [/part]
                        [part]
                            story= _ "Rumors circulate about a spirit of good fortune that protects these guards. It is said that that when attacked by orcs at night, the darkness itself descends to repel the assailants."
                            {STORYTXT_BACKGROUND end.jpg}
                        [/part]
                    [/story]

                    [endlevel]
                        next_scenario=null
                        carryover_report=no
                        save=no
                        linger_mode=no
                    [/endlevel]
                [/event]
            [/then]
        [/if]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Mal Keshar
        [/filter]

        [if]
            {VARIABLE_CONDITIONAL timesForever greater_than_equal_to 3}

            # after a few repetitions, we'll let the campaign really end
            # when Malin dies
            [then]
                [if]
                    [have_unit]
                        x,y=$x2,$y2
                        side=2
                    [/have_unit]
                    [then]
                        [role]
                            id=Foolish Hero
                            role=speakinghero
                        [/role]
                        [role]
                            side=2
                            [not]
                                canrecruit=yes
                            [/not]
                            role=second
                        [/role]
                        {VARIABLE hero_type $randomHero}
                    [/then]
                    [else]
                        [role]
                            id=Too Foolish Hero
                            role=speakinghero
                        [/role]
                        [role]
                            side=3
                            [not]
                                canrecruit=yes
                            [/not]
                            role=second
                        [/role]
                        {VARIABLE hero_type $randomHero2}
                    [/else]
                [/if]

                [music]
                    name=journeys_end.ogg
                    immediate=yes
                    append=no
                [/music]

                [switch]
                    variable=hero_type
                    [case]
                        value=human
                        [message]
                            speaker=Mal Keshar
                            message= _ "Slain by those who were once my countrymen..."
                        [/message]

                        [kill]
                            id=Mal Keshar
                            animate=yes
                        [/kill]

                        [message]
                            role=speakinghero
                            message= _ "His evil deeds have come to an end."
                        [/message]

                        [message]
                            role=second
                            message= _ "Who do you think he was before he was corrupted by the darkness?"
                        [/message]

                        [message]
                            role=speakinghero
                            message= _ "It matters not. He embraced death over life, and thus relinquished his right to our mercy. Let us return home; the town will need us to help defend against the orcish raids."
                        [/message]

                        [message]
                            role=second
                            message= _ "Yes, sir."
                        [/message]
                    [/case]

                    [case]
                        value=bandit
                        [message]
                            speaker=Mal Keshar
                            message= _ "Darkness descends... and I..."
                        [/message]

                        [kill]
                            id=Mal Keshar
                            animate=yes
                        [/kill]

                        [message]
                            role=speakinghero
                            message= _ "It is done. He will trouble us no more."
                        [/message]

                        [message]
                            role=second
                            message= _ "Who do you think he was before becoming a lich?"
                        [/message]

                        [message]
                            role=speakinghero
                            message= _ "Likely one of those arrogant mages who think themselves superior to everyone else. He probably learned necromancy just to subjugate people like us."
                        [/message]

                        [message]
                            role=second
                            message= _ "So he was an evil tyrant. How dreadful."
                        [/message]

                        [message]
                            role=speakinghero
                            message= _ "Probably. Anyway, there is no use in dwelling upon one so wicked. Let us go."
                        [/message]
                    [/case]

                    [case]
                        value=elf
                        [message]
                            speaker=Mal Keshar
                            message= _ "Darkness descends... and I..."
                        [/message]

                        [kill]
                            id=Mal Keshar
                            animate=yes
                        [/kill]

                        [message]
                            role=speakinghero
                            message= _ "Well, that is the end of his evil ways."
                        [/message]

                        [message]
                            role=second
                            message= _ "I wonder who this lich was in life before he turned to the evil that is undeath."
                        [/message]

                        [message]
                            role=speakinghero
                            message= _ "A selfish human, only greedy for power while utterly indifferent to anything but himself. A necromancer’s only purpose is to work for their own gain, nothing else."
                        [/message]

                        [message]
                            role=second
                            message= _ "Pure evil, that is what they are."
                        [/message]

                        [message]
                            role=speakinghero
                            message= _ "Indeed. We need not afford this one any compassion. Let us leave this miserable place."
                        [/message]
                    [/case]

                    [case]
                        value=dwarf
                        [message]
                            speaker=Mal Keshar
                            message= _ "Darkness descends... and I..."
                        [/message]

                        [kill]
                            id=Mal Keshar
                            animate=yes
                        [/kill]

                        [message]
                            role=speakinghero
                            # po: regular english - the lich is nothing but a pile of bones now
                            message= _ "Tha lich be nae but a pile o’ bones now."
                        [/message]

                        [message]
                            role=second
                            # po: regular english - I wonder what kind of human he was in life
                            message= _ "I wonder what kind o’ human he did be in life."
                        [/message]

                        [message]
                            role=speakinghero
                            # po: regular english - I guess he was some crazy mage who wanted to make other humans his slaves. Why else do you think he would turn to dark magic?
                            message= _ "Me guess be that he be some loonie mage who wanted ta make other humans inta ’is slaves. Why else d’ye think tha lad woul’ turn ta dark magic?"
                        [/message]

                        [message]
                            role=second
                            # po: regular english - I don't know. You think the lich's castle can be useful
                            message= _ "I dinna know. Ye think tha lich’s castle ken be useful?"
                        [/message]

                        [message]
                            role=speakinghero
                            # po: regular english - Yes. Let's get to work.
                            message= _ "Aye. Let’s git to workin’."
                        [/message]
                    [/case]

                    [case]
                        value=orc
                        [message]
                            speaker=Mal Keshar
                            message= _ "Felled by an orc... so it ends... like this..."
                        [/message]

                        [kill]
                            id=Mal Keshar
                            animate=yes
                        [/kill]

                        [message]
                            role=speakinghero
                            message= _ "The lich is dead! I have finally avenged my father."
                        [/message]

                        [message]
                            role=second
                            message= _ "Who you think he was, boss?"
                        [/message]

                        [message]
                            role=speakinghero
                            message= _ "Just some angst-ridden mage who turned to dark magic when he swore some stupid quest for revenge upon us. Amusing that he was more bothersome in death than in life. Annoying that it took so long to kill him."
                        [/message]

                        # easter egg text
                        [if]
                            [variable]
                                name=x1
                                numerical_equals=17
                            [/variable]
                            [and]
                                [variable]
                                    name=y1
                                    numerical_equals=27
                                [/variable]
                            [/and]
                            [and]
                                [variable]
                                    name=timesForever
                                    greater_than=5
                                [/variable]
                            [/and]
                            [then]
                                [message]
                                    role=second
                                    message= _ "Boss, look! The lich dropped a shiny book!"
                                [/message]

                                [message]
                                    role=speakinghero
                                    message= _ "Well, what is it?"
                                [/message]

                                [message]
                                    role=second
                                    message= _ "I don’t know, but it looks like someone wrote something inside! It says:"
                                [/message]

                                [message]
                                    speaker=narrator
                                    image=items/book2.png
                                    # po: hahaha is Zephrin laughing
                                    # po: this line sounds very "modern-day" but that's intentional because it's an easter egg, not meant to be taken strictly at face value
                                    message= _ "<i>That stupid memory came back to bother me again today. It was that time at the Academy when Zephrin and I were arguing about orcs. I still remember that hoarse voice of his telling me, ‘Fun story, Malin, but you really should put a disclaimer. You know, to make sure everyone understands no orcs were harmed in the making of this story, hahaha.’

I can still hear his infernal cackling ringing in my head. Sure thing, Zephrin, right... like my whole life was some sort of work of fiction!</i>"
                                [/message]

                                [message]
                                    role=speakinghero
                                    # po: Bah is an exclamation of disgust or irritation
                                    message= _ "Bah! Do these people believe that we are fools? They must think we are all actors in a poorly written drama! I’ve had enough of this. I’m going home."
                                [/message]
                            [/then]
                            [else]
                                [message]
                                    role=speakinghero
                                    message= _ "Anyway, round up the wolves. I’m going home."
                                [/message]
                            [/else]
                        [/if]
                    [/case]
                [/switch]

                [endlevel]
                    next_scenario=null
                    carryover_report=no
                    save=no
                    linger_mode=no
                [/endlevel]
            [/then]

            # Normal defeat condition before sufficient repetitions
            # putting the HERODEATH_MALIN_LICH macro here doesn't seem to work
            [else]
                [message]
                    speaker=unit
                    message= _ "... Then my battle against the orcs is lost!"
                [/message]

                [endlevel]
                    result=defeat
                [/endlevel]
            [/else]
        [/if]
    [/event]

    [event]
        name=enemies defeated

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

    {TURN_INTO_A_LICH}
[/scenario]
