#textdomain wesnoth-low

#TODO Add the ogre cage idea.
#TODO give a reward for saving some of the Kalian gold.
#TODO add the water sound effects.
#TODO try to tune the troll ai to not start a suicide run against the wood border.

[scenario]
    random_start_time=no
    allow_new_game=no
    force_lock_settings=yes

    id=07_Elves_Last_Stand

    experience_modifier=100
    next_scenario=08_Council_of_Hard_Choices
    name= _ "Elves’ Last Stand"

    ### Story ###
    [story]
        [part]
            story= _ "The journey back to Wesmere was surprisingly uneventful, the orcs having apparently withdrawn to regroup after their defeats. Kalenz and his band returned just in time..."
        [/part]
    [/story]
    {LOW_TRACK ( {FLIGHT_COMPLETE} {TREASURY_STAGE4} ) }
    ### /Story ###

    ### Music playlist ###
    {INTRO_AND_SCENARIO_MUSIC elf-land.ogg elvish-theme.ogg}
    {EXTRA_SCENARIO_MUSIC the_city_falls.ogg}
    {EXTRA_SCENARIO_MUSIC silvan_sanctuary.ogg}
    {EXTRA_SCENARIO_MUSIC wanderer.ogg}
    {EXTRA_SCENARIO_MUSIC siege_of_laurelmor.ogg}
    {EXTRA_SCENARIO_MUSIC heroes_rite.ogg}
    {EXTRA_SCENARIO_MUSIC casualties_of_war.ogg}
    ### /Music playlist ###

    ### Map setup ###
    {TURNS 30 25 20}

    {DEFAULT_SCHEDULE_AFTERNOON}

    {LOW_MAP  Kalian.map}
    {LOW_MASK 07_Elves_Last_Stand.mask 1 1}
    {campaigns/Legend_of_Wesmere/maps/Kalian_map.cfg}

    ### /Map Setup ###

#define PLAYER_GOLD
    {GOLD 700 600 500}
    income=-2
#enddef
#define MULTIPLAYER_GOLD
    {GOLD 250 215 190}
    income=-2
#enddef

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

        {KALENZ}
        x=46
        y=21

#ifndef MULTIPLAYER
        {PLAYER_GOLD}
        [unit]
            {LANDAR}
            x=45
            y=35
        [/unit]
        [unit]
            {CLEODIL}
            x=47
            y=28
        [/unit]
#else
        {MULTIPLAYER_GOLD}
#endif
    [/side]

    #TODO enable the extended recruit list and give a hint to the player about it
    #        [event]
    #            name=prestart
    #            [allow_recruit]
    #                side=1
    #                type={ELVES}
    #            [/allow_recruit]
    #        [/event]

    [event]
        name=prestart
        # the usual suspects
        {RECALL_LOYALS}
    [/event]

    # wmllint: skip-side
    {MP_SIDE 2 (
        no_leader=yes
        {PLAYABLE}
        save_id=Landar
        disallow_shuffle=yes
        {MULTIPLAYER_GOLD}

        [unit]
            {LANDAR}
            x=45
            y=35
        [/unit]
    )}

    # wmllint: skip-side
    {MP_SIDE 3 (
        no_leader=yes
        {PLAYABLE}
        save_id=Cleodil
        disallow_shuffle=yes
        {MULTIPLAYER_GOLD}

        [unit]
            {CLEODIL}
            x=47
            y=28
        [/unit]
    )}

    ### Allies ####
    [side]
        side=4
        {PLAYABLE}
        no_leader=yes
        save_id=Galtrid
        disallow_shuffle=yes
#ifndef MULTIPLAYER
        {GOLD 400 300 200}
#else
        {GOLD 160 130 100}
        previous_save_id=Kalenz
#endif

        [unit]
            # wmllint: recognize Galtrid
            {GALTRID}
            x=33
            y=32
        [/unit]

#ifndef MULTIPLAYER
        [unit]
            # wmllint: recognize El_Isomithir
            {EL_ISOMITHIR}
            x=29
            y=32
        [/unit]
        [unit]
            # wmllint: recognize Eradion
            {ERADION}
            x=7
            y=36
        [/unit]
#endif
    [/side]

    # wmllint: skip-side
    {MP_SIDE 5 (
        {PLAYABLE}
        {EL_ISOMITHIR}
        save_id=El_Isomithir
        disallow_shuffle=yes
        previous_save_id=Landar
        x=29
        y=32
        {GOLD 160 130 100}
    )}

    # wmllint: skip-side
    {MP_SIDE 6 (
        {PLAYABLE}
        {ERADION}
        save_id=Eradion
        disallow_shuffle=yes
        previous_save_id=Cleodil
        x=7
        y=36
        {GOLD 160 130 100}
    )}

#ifndef MULTIPLAYER
    {STARTING_VILLAGES_ALL 4}
#endif
    ### /ALLIES ###

    ### ENEMIES ###
    [side]
        side=7
        no_leader=yes

        allow_player=no
        controller=ai
        team_name=orcs
        user_team_name= _ "Enemies"
        {ORC_SETUP}

        {GOLD 1200 1720 2260}
        {INCOME 50 80 120}

        [unit]
            type=Naga Myrmidon
            id=Mordrum
            name= _ "Mordrum"
            canrecruit=yes
            x=6
            y=4
#ifdef HARD
            extra_recruit=Naga Fighter, Naga Warrior, Naga Myrmidon, Water Serpent
#endif
#ifdef NORMAL
            extra_recruit=Naga Fighter, Naga Warrior, Naga Myrmidon, Water Serpent
#endif
#ifdef EASY
            extra_recruit=Naga Fighter, Naga Warrior
#endif
        [/unit]

        [unit]
            type=Orcish Warlord
            id=Urug-Pir
            name=_ "Urug-Pir"
            profile=portraits/orcs/grunt-2.webp
            canrecruit=yes
            x=6
            y=23
#ifdef HARD
            extra_recruit=Orcish Archer, Orcish Crossbowman, Orcish Slurbow, Orcish Assassin, Orcish Slayer, Orcish Nightblade, Orcish Grunt, Orcish Warrior, Orcish Warlord, Goblin Spearman, Goblin Impaler, Goblin Rouser, Wolf Rider, Goblin Knight, Goblin Pillager, Direwolf Rider
#endif
#ifdef NORMAL
            extra_recruit=Orcish Archer, Orcish Crossbowman, Orcish Assassin, Orcish Slayer, Orcish Grunt, Orcish Warrior, Goblin Spearman, Goblin Impaler, Goblin Rouser, Wolf Rider, Goblin Knight, Goblin Pillager, Direwolf Rider
#endif
#ifdef EASY
            extra_recruit=Orcish Archer, Orcish Crossbowman, Orcish Assassin, Orcish Grunt, Orcish Warrior, Goblin Spearman, Wolf Rider, Goblin Knight, Goblin Pillager
#endif
        [/unit]

        [unit]
            type=Great Troll
            id=Truugl
            name= _ "Truugl"
            canrecruit=yes
            x=26
            y=7
#ifdef EASY
            extra_recruit=Troll Whelp
#endif
#ifdef NORMAL
            extra_recruit=Troll Whelp, Troll, Troll Rocklobber, Troll Shaman
#endif
#ifdef HARD
            extra_recruit=Troll Whelp, Troll, Troll Rocklobber, Troll Shaman, Troll Warrior, Troll Hero
#endif
        [/unit]

        [ai]
            {AI_SIMPLE_NIGHT_ASPECT aggression 0.75}
            {AI_SIMPLE_NIGHT_ASPECT caution 0.0}
            [recruitment_instructions]
                [recruit]
                    importance=0
                [/recruit]
                [pattern]
                    importance=1
                    leader_id=Truugl
#ifdef EASY
                    type="fighter"
#else
                    type="fighter, mixed fighter, fighter, mixed fighter, fighter"
#endif
                [/pattern]
                [pattern]
                    importance=1
                    leader_id=Urug-Pir
                    type="scout,fighter,fighter,archer,mixed fighter"
                [/pattern]
            [/recruitment_instructions]
        [/ai]
    [/side]

    ### /ENEMIES ####

    #### Objectives and corresponding events ####
#define OBJECTIVES
    side=0
    [objective]
        #TODO reconsider the formulation
        #TODO format?
        description= _ "You must own the field and be capable of overwhelming your opponents. (Player(s) own more than 25 units while the foes’ numbers fall below 15.)"
        condition=win
    [/objective]
    [objective]
        description= _ "Defeat all enemy leaders."
        condition=win
    [/objective]
    [objective]
        description= _ "Death of Kalenz"
        condition=lose
    [/objective]
    [objective]
        description= _ "Death of Landar"
        condition=lose
    [/objective]
    [objective]
        description= _ "Death of Cleodil"
        condition=lose
    [/objective]
    [objective]
        description= _ "Death of Galtrid"
        condition=lose
    [/objective]

    {TURNS_RUN_OUT}

    [gold_carryover]
        carryover_percentage=0
    [/gold_carryover]
#enddef

    [event]
        name=prestart
        [objectives]
            {OBJECTIVES}
        [/objectives]
    [/event]

    [event]
        name=enemies defeated
        [endlevel]
            save=no
            result=victory
            bonus=no
            carryover_percentage=0
        [/endlevel]
    [/event]

    #Let the orcs flee if their numbers go low and the elves go high
    [event]
        name=side 7 turn
        first_time_only=no

        [filter_condition]
            [variable]
                name=turn_number
                greater_than=1
            [/variable]
        [/filter_condition]

        [if]
            [have_unit]
                side=7
                count=1-15
            [/have_unit]
            [have_unit]
                side=1,2,3,4
                count=25-infinity
            [/have_unit]
            [then]
                [message]
                    canrecruit=yes
                    race=orc,troll
                    message= _ "Flee! They have broken us!"
                [/message]
                [message]
                    id=Landar
                    message= _ "Hunt them down and kill every single one of them!"
                [/message]
                [message]
                    id=Cleodil
                    message= _ "It is not wise to put a wounded foe in a desperate situation; they will but fight harder for it. Break their will and let them flee, so they will spread fear of us among their kind."
                [/message]
                [message]
                    id=Galtrid
                    message= _ "She is right. Don’t let them lure you away from the Ka’lian, preparations for when more of them arrive must be made."
                [/message]
                [fire_event]
                    name=enemies defeated
                [/fire_event]
            [/then]
        [/if]
    [/event]

    [event]
        name=time over
        [message]
            id=Kalenz
            message= _ "The orcs are not defeated, and our troops and supplies are exhausted. This is the end!"
        [/message]
    [/event]
    #### /Objectives and corresponding events ####

    #### INTRO ####
    [event]
        name=start

        [message]
            id=Kalenz
            message= _ "The orcs have pushed us back to the Ka’lian. There is no way out. We must win here!"
        [/message]
        [message]
            id=Galtrid
            message= _ "This is our final stand. If they take the Ka’lian, all is lost!"
        [/message]
        [message]
            id=Landar
            # wmllint: local spelling Elvenkind
            message= _ "Galtrid, speak not of defeat. Elvenkind shall rise! Our enemies shall perish in blood and fire!"
        [/message]
        [message]
            id=Cleodil
            message= _ "It is a dark day indeed when elves must steel themselves with dreams of slaughter."
        [/message]
        [message]
            id=Urug-Pir
            # wmllint: local spelling da
            message= _ "We’ll crush those weak elves and I’ll get da stone!"
        [/message]
        [message]
            id=El_Isomithir
            message= _ "These are hardened orc and troll veterans. Men, prepare for a long, difficult fight..."
        [/message]
    [/event]
    ### /INTRO ####

    ### OLURF ###
    [event]
        name=turn 7

        # Hint to the player that the dwarves aren't going to turn up until the end
        [message]
            id=Landar
            message= _ "Those dwarves must still be protecting our gold — on their land."
        [/message]
        [message]
            id=Kalenz
            message= _ "Yes, it seems we must defend the Kalian alone."
        [/message]
    [/event]

    [event]
        name=olurf

        [unit]
#ifndef MULTIPLAYER
            side=1
#else
            side=8
#endif
            {OLURF}
            canrecruit=yes
            x=$olurf_entry.x
            y=$olurf_entry.y
        [/unit]

#ifndef MULTIPLAYER
        {OLURF_PARTY 1}
#else
        {OLURF_PARTY 8}
#endif

        ####ifndef MULTIPLAYER
        ####        {MODIFY_UNIT (side=8) side 1}
        ####        {TRANSFER_VILLAGE_OWNERSHIP 8 1}
        ######endif

        [message]
            id=Olurf
            message= _ "Did ye think we’d let you have all the fun wi’ the orcs by yerselves?"
        [/message]
        [message]
            id=Landar
            message= _ "You did, we’ve already driven them from the forest. You barely caught up in time to chase them into the hills."
        [/message]

        [message]
            id=Kalenz
            message= _ "Diplomacy, Landar. We do need to pursue the orcs into the mountains, and an army of dwarves will be welcome companions."
        [/message]
        [message]
            id=Landar
            message= _ "It’s not much of an army he is bringing with him, though."
        [/message]
        [message]
            id=Olurf
            message= _ "Not much of an army? These are dwarves with mighty axes, each worth three of you and your silly plinking bows!"
        [/message]
        [message]
            id=Kalenz
            message= _ "Olurf, is that all the dwarves you could find? Was the gold not enough?"
        [/message]
        [message]
            id=Olurf
            message= _ "They are no’ fighting for gold, they’re here for the fun. I’d ha’ brought a lot more if my men ha’ all kept quiet about helping elves! But the rest o’ my clan should join us in a few days."
        [/message]
        [message]
            id=Landar
            message= _ "In a few days? That’s too late! We want our gold back!"
        [/message]
        [message]
            id=Olurf
            message= _ "Sure, minus expenses."
        [/message]
        [message]
            id=Landar
            message= _ "What expenses?"
        [/message]
        [message]
            id=Olurf
            message= _ "It’s an ancient dwarvish custom to buy the warriors a few drinks before the battle... So minus expenses that’s about even."
        [/message]
        [message]
            id=Landar
            message= _ "That explains why they are so reckless in battle..."
        [/message]
    [/event]

    [event]
        name=scenario_end
        [filter_condition]
            [proceed_to_next_scenario]
            [/proceed_to_next_scenario]
        [/filter_condition]
        {VARIABLE olurf_entry.x 40}
        {VARIABLE olurf_entry.y 5}
        [fire_event]
            name=olurf
        [/fire_event]
    [/event]
    ### /OLURF ###

    [event]
        name=scenario_end
        [filter_condition]
            [proceed_to_next_scenario]
            [/proceed_to_next_scenario]
        [/filter_condition]
        [message]
            id=Galtrid
            message= _ "At last! The orcs are defeated."
        [/message]

        [unit]
            type=Orcish Warrior
            id=Pirorr
            name= _ "Pirorr"
            side=7
            x=1
            y=43
            facing=ne
            profile=portraits/orcs/grunt-2.webp
        [/unit]
        {MOVE_UNIT id=Pirorr 1 41}

        [message]
            id=Pirorr
            message= _ "The elves have beaten us and they did not use da stone. Maybe they don’t have it? Great Chief will not like bad news!"
        [/message]
        [kill]
            id=Pirorr
            animate=no
        [/kill]

        [message]
            id=Galtrid
            message= _ "Kalenz, we are again in your debt. You returned just in time."
        [/message]
        [message]
            id=Kalenz
            message= _ "And we have what’s left of the elvish treasury with us!"
        [/message]
        [message]
            id=Landar
            message= _ "Perhaps the gold will give our words more weight with the Council."
        [/message]
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            side_for=1
            message= _ "Kalenz" + _ " has returned any remaining gold into the elvish treasury. You will start the next scenario with a preset amount."
        [/message]
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            side_for=2
            message= _ "Landar" + _ " has returned any remaining gold into the elvish treasury. You will start the next scenario with a preset amount."
        [/message]
    [/event]

    ###DEATH EVENTS###
    [event]
        name=last breath
        [filter]
            id=Truugl
        [/filter]
        [message]
            id=Truugl
            message= _ "Aargh! I should have stayed in the mountains instead of joining the orcs!"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Mordrum
        [/filter]
        [message]
            id=Kalenz
            message= _ "Orcs, death is all you will find in this forest!"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Urug-Pir
        [/filter]
        [message]
            speaker=unit
            message= _ "I die without getting da stone?"
        [/message]
    [/event]

    #Eradion death is split in two events.
    #The first part is spoken after deadly wounded but still speaking
    [event]
        name=last breath
        [filter]
            id="Eradion"
        [/filter]
        {INCIDENTAL_MUSIC sad.ogg}
        [message]
            speaker=second_unit
            message= _ "Be grateful, tree-shagger, for I have spared you the pain of seeing your precious citadel burned and razed."
        [/message]
        [message]
            speaker=unit
            message= _ "Galtrid, my friend. Do not let my death be in vain. Destroy these foul orcs, and sing for me in the green woods when we have won."
        [/message]
        [message]
            id=Galtrid
            message= _ "We shall avenge you tenfold!"
        [/message]
        [scroll_to_unit]
            id="Eradion"
        [/scroll_to_unit]
    [/event]
    [event]
        name=die
        [filter]
            id="Eradion"
        [/filter]
        [message]
            speaker=second_unit
            message= _ "Dead he is. Too quick. His screams were sweet."
        [/message]
        [message]
            side=4,5,6
            [not]
                id=Galtrid
            [/not]
            [not]
                id="Eradion"
            [/not]
            message= _ "Let us pursue the orc who murdered $unit.name|!"
        [/message]
        [message]
            id=Galtrid
            message= _ "No, don’t leave your formation. An elf was slain by beast. What does it matter which beast it was? We must kill them all."
        [/message]
    [/event]

    # There is a story-only scenario remaining in this chapter,
    # but that doesn't have any fighting, and it doesn't have all
    # of the mp sides active in it.
    [event]
        name=scenario_end
        [filter_condition]
            [proceed_to_next_scenario]
            [/proceed_to_next_scenario]
        [/filter_condition]

        [persistent_carryover_store]
            scenario_id = LoW_Chapter_Two
        [/persistent_carryover_store]
    [/event]

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

#undef PLAYER_GOLD
#undef MULTIPLAYER_GOLD
