#textdomain wesnoth-low
[scenario]
    name= _ "Costly Revenge"

    id=19_Costly_Revenge
    victory_when_enemies_defeated=no
    experience_modifier=100

    random_start_time=no
    allow_new_game=yes
    new_game_title= _ "Chapter Five: Civil War"
    force_lock_settings=yes

    {LOW_MAP Saurgrath.map}
    {WINTER_MASK 19_Costly_Revenge.mask}

    {TURNS 40 35 30}

    {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}
    {EXTRA_SCENARIO_MUSIC suspense.ogg}

    {DEFAULT_SCHEDULE_DUSK}

    next_scenario=20_Council_Ruling
    [story]
#ifdef MULTIPLAYER
        [part]
            title= _ "<i>The Legend of Wesmere</i>
Chapter Five"
        [/part]
#endif
        [part]
            title= _ "Chapter Five
<i>Civil War</i>"
        [/part]
        [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..."
            {LOW_BIGMAP}
            {SAURIANS_STAGE1}
        [/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.webp
            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.webp
            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.webp
            scale_background=no
        [/part]
        [part]
            story={CAPTION ( _ "Kalenz")} + _ "We do as we must."
            background=story/characters/kalenz.webp
            scale_background=no
        [/part]
    [/story]
    {LOW_TRACK {SAURIANS_STAGE1_END} }

#define PLAYER_GOLD
    {GOLD 340 300 280}
#enddef
#define MULTIPLAYER_GOLD
    {GOLD 200 175 160}
#enddef

    [side]
        side=1
        {PLAYABLE}
        save_id=Kalenz
        disallow_shuffle=yes

        {KALENZ}
        x=3
        y=18

#ifndef MULTIPLAYER
        {PLAYER_GOLD}
        [unit]
            {LANDAR}
            #TODO place on his keep
            placement=leader
        [/unit]
#else
        {MULTIPLAYER_GOLD}
#endif
    [/side]
    [event]
        name=prestart
#ifdef MULTIPLAYER
        [persistent_carryover_unstore]
            scenario_id = LoW_Chapter_Four
        [/persistent_carryover_unstore]
#endif
#ifndef MULTIPLAYER
        [kill]
            race=dwarf
        [/kill]
#endif

        #TODO see if this recalls units which are not recallable
        {RECALL_LOYALS}
    [/event]

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

        [ai]
#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
        allow_player=no
        type=Saurian Flanker
        id=Hgyr
        name= _ "Hgyr"
        canrecruit=yes
        x=26
        y=2
        {GOLD 250 300 400}
        {INCOME 4 8 12}
        team_name=Saurians
        user_team_name= _ "Enemies"
        {SAURIAN_SETUP}
#ifdef EASY
        recruit=Saurian Skirmisher, Saurian Augur
#else
        recruit=Saurian Skirmisher, Saurian Augur, Saurian Ambusher, Saurian Flanker, Saurian Oracle, Saurian Soothsayer
#endif

        [ai]
#ifdef EASY
            recruitment_pattern=scout, healer, scout
#else
            recruitment_pattern=scout, healer, scout, archer
#endif
        [/ai]
    [/side]

#ifdef MULTIPLAYER
    [side]
        side=4
        {PLAYABLE}

        {MULTIPLAYER_GOLD}
        save_id=Landar
        disallow_shuffle=yes
        no_leader=yes
        [unit]
            {LANDAR}
            x=3
            y=18
        [/unit]
    [/side]
#endif

    {STARTING_VILLAGES 3 20}

    [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]
    [/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]

            {TURNS_RUN_OUT}

            [gold_carryover]
                carryover_percentage=0
            [/gold_carryover]
        [/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 capital. 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 crab
            side=2,3
            [not]
                canrecruit=yes
            [/not]
            message= _ "They even shatter our eggs!"
        [/message]
        [if]
            [have_unit]
                #wmllint: recognize Anduilas
                id=Anduilas
            [/have_unit]
            [then]
                [role]
                    role=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 capital."
        [/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][/redraw]
        {VICTORY_CONDITIONAL}
    [/event]

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

#undef PLAYER_GOLD
#undef MULTIPLAYER_GOLD
