#textdomain wesnoth-low
[scenario]
    id=19_Costly_Revenge
    name= _ "Costly Revenge"
    victory_when_enemies_defeated=no
    {LOW_MAP Saurgrath.map}
    {WINTER_MASK 19_Costly_Revenge.mask}

    {TURNS 35 30 25}

    {INTRO_AND_SCENARIO_MUSIC revelation.ogg the_deep_path.ogg}
    {EXTRA_SCENARIO_MUSIC vengeful.ogg}
    {EXTRA_SCENARIO_MUSIC casualties_of_war.ogg}
    {EXTRA_SCENARIO_MUSIC the_dangerous_symphony.ogg}
    {EXTRA_SCENARIO_MUSIC into_the_shadows.ogg}
    {EXTRA_SCENARIO_MUSIC weight_of_revenge.ogg}
    {EXTRA_SCENARIO_MUSIC nunc_dimittis.ogg}

    {DEFAULT_SCHEDULE}

    {LOW_PRESTART}

    next_scenario=20_Council_ruling
    [story]
        [part]
            show_title=yes
            story= _ "But Kalenz failed to persuade the dwarves. The dwarves left, and Landar insisted the elves must march on the empire of the Saurians..."
            delay=4000
            {TO_COSTLY_REVENGE}
        [/part]
        [part]
            story={CAPTION ( _ "Cleodil")} + _"Kalenz...the shydes and druids are not happy with this. The saurians are already beaten, and there is too much hate in Landar's heart. Something is not right here."
            background=story/characters/cleodil.png
            scale_background=no
        [/part]
        [part]
            story={CAPTION ( _ "Kalenz")} + _"I am not entirely easy with this myself, Cleodil. But there is something to what Landar says; the wide green world must know there is a price, a heavy price for raiding in the forest of Wesmere."
            background=story/characters/kalenz.png
            scale_background=no
        [/part]
        [part]
            story={CAPTION ( _ "Cleodil")} + _"Then you who walk the earth path and carry steel can collect that price. Those on the faerie path will not be with you. Not this time."
            background=story/characters/cleodil.png
            scale_background=no
        [/part]
        [part]
            story={CAPTION ( _ "Kalenz")} + _"We do as we must."
            background=story/characters/kalenz.png
            scale_background=no
        [/part]
        [part]
            show_title=yes
            {TO_COSTLY_REVENGE_BATTLE}
        [/part]
    [/story]

    #wmllint: validate-off
    [side]
        {KALENZ}
        {GOLD 300 260 220}
        # wmllint: recognize Kalenz
        team_name=player
        user_team_name= _ "Player"
        recruit=Elvish Fighter, Elvish Archer, Elvish Scout
        # TODO no minimum gold here?
        x=3
        y=18
#ifndef MULTIPLAYER
        [unit]
            {LANDAR}
            # wmllint: recognize Landar
            placement=leader
        [/unit]
#endif
        [unit]
            {CLEODIL}
            # wmllint: recognize Cleodil
            placement=leader
        [/unit]
    [/side]
    #wmllint: validate-on
    [event]
        name=prestart

        [kill]
            race=dwarf
        [/kill]
        [disallow_recruit]
            type={DWARVES}, Elvish Shaman, Elvish Druid, Elvish Sorceress
        [/disallow_recruit]
        # all shamans have left with Cleodil
        [store_unit]
            kill=yes
            variable=faeries
            [filter]
                type={SHAMANS}
            [/filter]
        [/store_unit]

        {RECALL_LOYALS}
        # wmllint: recognize Anduilas
    [/event]

    [side]
        side=2
        controller=ai
        type=Saurian Flanker
        id=Spahr
        name=_ "Spahr"
        canrecruit=yes
        x=23
        y=20
        {GOLD 400 600 800}
        {INCOME 4 8 12}
        team_name=Saurians
        user_team_name= _ "Enemies"
        {FLAG_VARIANT undead}
#ifdef EASY
        recruit=Saurian Skirmisher, Saurian Augur
#else
        recruit=Saurian Skirmisher, Saurian Augur, Saurian Ambusher, Saurian Oracle, Saurian Soothsayer, Saurian Flanker
#endif

        [ai]
            recruitment_ignore_bad_movement=yes
#ifdef EASY
            recruitment_pattern=scout,scout,healer,scout
#else
            recruitment_pattern=scout,scout,healer,archer,archer,scout
#endif
        [/ai]
    [/side]
    {STARTING_VILLAGES_ALL 2}

    [side]
        side=3
        controller=ai
        type=Saurian Flanker
        id=Hgyr
        name= _ "Hgyr"
        canrecruit=yes
        x=26
        y=2
        {GOLD 300 400 500}
        {INCOME 4 8 12}
        team_name=Saurians
        user_team_name= _ "Enemies"
        {FLAG_VARIANT undead}
#ifdef EASY
        recruit=Saurian Skirmisher, Saurian Augur
#else
        recruit=Saurian Skirmisher, Saurian Augur, Saurian Ambusher, Saurian Flanker, Saurian Oracle, Saurian Soothsayer
#endif

        [ai]
            recruitment_ignore_bad_movement=yes
#ifdef EASY
            recruitment_pattern=scout, healer, scout
#else
            recruitment_pattern=scout, healer, scout, archer
#endif
        [/ai]
    [/side]
    {STARTING_VILLAGES 3 20}

    [side]
        side=4
        persistent=yes
        save_id=Landar
        no_leader=yes
        hidden=yes
    [/side]

    [event]
        name=victory

        # dialog
        [message]
            id=Kalenz
            message= _ "That was the last. A bitter day's work, and no memory to be proud of."
        [/message]
        [message]
            id=Landar
            message={WHISPER _"A shame we missed the opportunity to rid the forests of dwarves, as well."}
        [/message]

        # modify 2/3 of the non-loyal, non-shaman-line units to join Landar
        {MODIFY_UNIT (id=Landar) side 4}
        [store_unit]
            #TODO spellcheck
            variable=steal_wearer
            kill=yes
            [filter]
                side=1
                [not]
                    id=Kalenz
                [/not]
                [not]
                    id=Landar
                [/not]
                [not]
                    {FILTER_LOYALS}
                [/not]
            [/filter]
        [/store_unit]
        {FOREACH steal_wearer u}
            {RANDOM (2,1,2)}
            [if]
                [variable]
                    name=random
                    numerical_equals=1
                [/variable]
                [then]
                    {VARIABLE steal_wearer[$u].role kalenz_loyal}
                    [unstore_unit]
                        variable=steal_wearer[$u]
                    [/unstore_unit]
                [/then]
                [else]
                    {VARIABLE steal_wearer[$u].side 4}
                    {VARIABLE steal_wearer[$u].role landar_loyal}
                    [unstore_unit]
                        variable=steal_wearer[$u]
                    [/unstore_unit]
                [/else]
            [/if]
        {NEXT u}
        {CLEAR_VARIABLE steal_wearer}

        # unstore the shaman-line units to rejoin Kalenz
        # x,y is on recall,recall since they have been stored in prestart
        {FOREACH faeries faery}
            [unstore_unit]
                variable=faeries[$faery]
            [/unstore_unit]
        {NEXT faery}
        {CLEAR_VARIABLE faeries}
    [/event]

    ##### Scenario objectives #####
    [event]
        name=prestart
        [objectives]
            side=0
            [objective]
                description= _ "Defeat all enemy units, and destroy all villages"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Kalenz"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Landar"
                condition=lose
            [/objective]
            [objective]
                description= _ "Turns run out"
                condition=lose
            [/objective]
            note={NO_GOLD_CARRYOVER_NOTE}
        [/objectives]
    [/event]

    [event]
        name=start
        [message]
            side=1
            [not]
                id=Kalenz
            [/not]
            [not]
                id=Landar
            [/not]
            {FILTER_LOYALS}
            message= _ "We have finally reached Saurgrath, their capitol. Remember whose side they have taken in the war against us."
        [/message]
        [message]
            id=Landar
            message= _ "Now is our chance to finish them off..."
        [/message]
        [message]
            id=Kalenz
            message= _ "I fear this will be a bloodbath..."
        [/message]
        [message]
            id=Landar
            message= _ "Destroy them, root and branch. Burn out their homes. Let none remain alive!"
        [/message]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "Kalenz is not able to recruit or recall shamans or any of their advancements in this scenario."
        [/message]
    [/event]

    #TODO update this comment
    # every time one of the saurian gets killed this event checks if it
    # was the last one and if there are any villages left.
#define VICTORY_CONDITIONAL
    [if]
        [not]
            [have_unit]
                side=2
                [or]
                    side=3
                [/or]
            [/have_unit]
        [/not]
        [not]
            [have_location]
                terrain=*^V*
            [/have_location]
        [/not]
        [then]
            [endlevel]
                result=victory
                bonus=no
                save=no
                carryover_percentage=0
            [/endlevel]
        [/then]
    [/if]
#enddef

    [event]
        name=die
        first_time_only=no
        [filter]
            race=lizard
        [/filter]
        {VICTORY_CONDITIONAL}
    [/event]

    [event]
        name=capture
        first_time_only=yes
        [filter]
            side=1
            [not]
                id=Landar
            [/not]
        [/filter]
        #TODO check ingame if the dialogue works.
        [message]
            x=$x1
            y=$y1
            message= _ "These are but eggs and hatchlings."
        [/message]
        [message]
            id=Landar
            message= _ "Do not spare them. They will only foul our forests anew when they get their growth."
        [/message]
        [message]
            #TODO The nearest saurian
            #formula=TODO get it from crap
            side=2,3
            [not]
                canrecruit=yes
            [/not]
            message= _ "They even shatter our eggs!"
        [/message]
        [if]
            [have_unit]
                id=Anduilas
            [/have_unit]
            [then]
                [role]
                    role=Anduilas
                    # wmllint: recognize Anduilas
                    id=Anduilas
                [/role]
            [/then]
            [else]
                [role]
                    role=Anduilas
                    side=1
                    [not]
                        id=Kalenz
                    [/not]
                    [not]
                        id=Landar
                    [/not]
                    [not]
                        id=$unit.id
                    [/not]
                [/role]
            [/else]
        [/if]
        [message]
            role=Anduilas
            message= _ "But...to kill their young? Are we to go that far?"
        [/message]
        [message]
            id=Kalenz
            message= _ "Stay. You need not have the blood of children on your hands, and I shall not."
        [/message]
        [message]
            id=Landar
            message= _ "Perhaps you are too tender-minded to do what must be done, but many of us are not."
        [/message]
        [message]
            id=Kalenz
            message= _ "I will not set elf against elf. But, Landar, I fear you are storing up a dreadful price for yourself."
        [/message]
        [message]
            id=Landar
            message= _ "Stand aside. I will do what is needful."
        [/message]
        [message]
            side=2,3
            [not]
                canrecruit=yes
            [/not]
            message= _ "Their revenge is terrible! I fear for our kind."
        [/message]
        [message]
            side=2,3
            canrecruit=yes
            message= _ "Don't flee. We cannot abandon our capitol."
        [/message]
        [scroll_to]
            x=$x1
            y=$y1
        [/scroll_to]
    [/event]

    # capture event lifted from IftU.
    [event]
        name=moveto
        first_time_only=no
        [filter]
            [filter_location]
                terrain=*^V*
            [/filter_location]
            side=1
            [not]
                id=Kalenz
            [/not]
            [not]
                role=Anduilas
            [/not]
        [/filter]
        [sound]
            name=hiss-die.wav
        [/sound]
        #TODO need a delay here?
        [sound]
            name=torch.ogg
        [/sound]
        [delay]
            time=200
        [/delay]
        [sound]
            name=wose-die.ogg
        [/sound]
        [terrain]
            x=$x1
            y=$y1
            terrain=Dd^Dr
            layer=overlay
        [/terrain]
        {REDRAW}
        {VICTORY_CONDITIONAL}
    [/event]

    {campaigns/Legend_of_Wesmere/utils/deaths.cfg}
[/scenario]
