#textdomain wesnoth-tsg
[scenario]
    id=07b_Pebbles_in_the_Flood

    name= _ "Pebbles in the Flood"
    next_scenario=08b_The_Tides_of_War

    {SCENARIO_MUSIC heroes_rite.ogg}
    {EXTRA_SCENARIO_MUSIC the_king_is_dead.ogg}
    {EXTRA_SCENARIO_MUSIC nunc_dimittis.ogg}

    map_data="{campaigns/The_South_Guard/maps/07b_Pebbles_in_the_Flood.map}"

    {campaigns/The_South_Guard/utils/sg_help.cfg}

    {DEFAULT_SCHEDULE}

    {SG_PEBBLES_IN_THE_FLOOD}
    {TSG_BIGMAP {JOURNEY_07B_NEW} }

    turns=unlimited
    victory_when_enemies_defeated=no
    disallow_recall=yes

    # The South Guard

    [side]
        side=1
        type=Horseman Commander
        id=Deoran
        name= _ "Deoran"
        profile=portraits/deoran.png
        unrenamable=yes

        team_name=South_Guard
        user_team_name=_"South Guard"
        controller=human
        {CUSTOM_SG_FLAG}

        gold=0
        {INCOME 4 2 0}

        canrecruit=yes
        recruit=Bowman, Spearman, Cavalryman, Footpad, Thug
    [/side]

    {STARTING_VILLAGES 1 15}

    # The Undead Hordes

    [side]
        side=2
        type=Ancient Lich
        id="Mal M'Brin"
        name= _ "Mal M’Brin"
        profile=portraits/mal-mbrin.png
        facing=sw

        team_name=The_Undead_Hordes
        user_team_name=_"Undead"
        controller=ai

        {GOLD 180 250 320}
        {INCOME 10 13 16}

        canrecruit=yes
        [ai]
            passive_leader=yes # So he can't attack or be pinned away from his keep
            recruitment_pattern=scout, fighter, fighter, archer, scout, fighter, archer
            aggression=1.0
            caution=0.0
            [goal]
                [criteria]
                    id=Sir Gerrick
                [/criteria]
                value=10.0
            [/goal]
        [/ai]
        recruit=Deathblade, Revenant, Draug, Bone Shooter, Blood Bat, Chocobone
        {FLAG_VARIANT undead}
    [/side]

    [side]
        side=3
        type=Lich
        id=Mal Tera
        name= _ "Mal Tera"

        team_name=The_Undead_Hordes
        user_team_name=_"Undead"
        controller=ai

        {GOLD 120 160 200}
        {INCOME 9 12 15}

        canrecruit=yes
        [ai]
            recruitment_pattern=fighter
            aggression=0.95
        [/ai]
#ifdef EASY
        recruit=Walking Corpse, Soulless, Ghoul, Vampire Bat
#endif
#ifdef NORMAL
        recruit=Walking Corpse, Soulless, Ghoul, Blood Bat
#endif
#ifdef HARD
        recruit=Walking Corpse, Soulless, Ghoul, Blood Bat, Necrophage
#endif
        {FLAG_VARIANT undead}
    [/side]

    #prestart
    [event]
        name=prestart

        [store_side]
            side=1
            variable=stored_side_1
        [/store_side]
        {VARIABLE pebbles_starting_gold $stored_side_1.gold}

        [modify_side]
            side=1
            {GOLD 150 125 100}
        [/modify_side]

        # Sgt. Finde's Section

        {NAMED_LOYAL_UNIT 1 Sergeant 2 9 (Finde) (_"Finde")}
        {NAMED_LOYAL_UNIT 1 Peasant 3 9 (Maelvas) (_"Maelvas")}
        {NAMED_LOYAL_UNIT 1 Spearman 4 9 (Orome) (_"Orome")}
        {NAMED_LOYAL_UNIT 1 Peasant 2 8 (Mitche) (_"Mitche")}

        # Lt. Illan's Section

        {NAMED_LOYAL_UNIT 1 (Lieutenant) 11 10 (Illan) (_"Illan")}
        {NAMED_LOYAL_UNIT 1 (Heavy Infantryman) 11 11 (Rheban) (_"Rheban")}
        {NAMED_LOYAL_UNIT 1 (Bowman) 10 10 (Jul) (_"Jul")}

        # Lt. Meris' Section

        {NAMED_LOYAL_UNIT 1 (Lieutenant) 21 10 (Meris) (_"Meris")}
        {NAMED_LOYAL_UNIT 1 (Heavy Infantryman) 21 11 (Findlas) (_"Findlas")}
        {NAMED_LOYAL_UNIT 1 (Heavy Infantryman) 22 10 (Chumet) (_"Chumet")}

        # Sgt. Cadry's Section

        {NAMED_LOYAL_UNIT 1 Sergeant 29 10 (Cadry) (_"Cadry")}
        {NAMED_LOYAL_UNIT 1 (Peasant) 30 9 (Seran) (_"Seran")}
        {NAMED_LOYAL_UNIT 1 (Bowman) 29 9 (Eera) (_"Eera")}
        {NAMED_LOYAL_UNIT 1 (Peasant) 31 9 (Cinry) (_"Cinry")}

        # Ancient Lich's Guards

        {NAMED_LOYAL_UNIT 2 Draug 22 17 () (_"Death Guard")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Draug 25 17 () (_"Death Guard")} {GUARDIAN}

        # Advancing Undead

#ifdef EASY
        {LOYAL_UNDEAD_UNIT 2 Chocobone 18 14}
        {LOYAL_UNDEAD_UNIT 2 Skeleton 4 12}
        {LOYAL_UNDEAD_UNIT 2 Skeleton 21 13}
        {LOYAL_UNDEAD_UNIT 2 Skeleton 29 16}
        {LOYAL_UNIT 2 (Vampire Bat) 2 14}
        {LOYAL_UNIT 2 (Vampire Bat) 9 13}
        {LOYAL_UNIT 2 (Vampire Bat) 23 16}
        {LOYAL_UNIT 2 (Vampire Bat) 32 10}
#endif
#ifdef NORMAL
        {LOYAL_UNDEAD_UNIT 2 Chocobone 18 14}
        {LOYAL_UNDEAD_UNIT 2 Skeleton 4 12}
        {LOYAL_UNDEAD_UNIT 2 Skeleton 21 13}
        {LOYAL_UNDEAD_UNIT 2 Revenant 29 16}
        {LOYAL_UNIT 2 (Vampire Bat) 2 14}
        {LOYAL_UNIT 2 (Blood Bat) 9 13}
        {LOYAL_UNIT 2 (Vampire Bat) 23 16}
        {LOYAL_UNIT 2 (Blood Bat) 32 10}
#endif
#ifdef HARD
        {LOYAL_UNDEAD_UNIT 2 Chocobone 18 14}
        {LOYAL_UNDEAD_UNIT 2 Revenant 4 12}
        {LOYAL_UNDEAD_UNIT 2 Deathblade 21 13}
        {LOYAL_UNDEAD_UNIT 2 Revenant 29 16}
        {LOYAL_UNIT 2 (Blood Bat) 2 14}
        {LOYAL_UNIT 2 (Blood Bat) 9 13}
        {LOYAL_UNIT 2 (Blood Bat) 23 16}
        {LOYAL_UNIT 2 (Blood Bat) 32 10}
#endif

        {MODIFY_UNIT x,y=16-33,1-25 facing sw}

        {CLEAR_VARIABLE stored_side_1}

        # Make it impossible for the player to kill the enemy leaders, no matter how lucky.
        [modify_unit]
            [filter]
                id="Mal M'Brin"
            [/filter]
            [status]
                invulnerable=yes
            [/status]
        [/modify_unit]
        [modify_unit]
            [filter]
                id="Mal Tera"
            [/filter]
            [status]
                invulnerable=yes
            [/status]
        [/modify_unit]
    [/event]

    #start
    [event]
        name=start
        [recall]
            id=Sir Gerrick
            x,y=16,8
        [/recall]
        [recall]
            id=Urza Afalas
            x,y=15,8
        [/recall]

        [object]
            [filter]
                id=Urza Afalas
            [/filter]
            duration=forever
            silent=yes
            [effect]
                apply_to=overlay
                replace="misc/loyal-icon.png"
            [/effect]
        [/object]

        [recall]
            id=Minister Hylas
            x,y=16,7
        [/recall]

        [message]
            speaker=Deoran
            message= _ "We are finally back in Kerlath, but look! The undead have almost caught up to us!"
        [/message]
        [message]
            speaker=Sir Gerrick
            message= _ "These forts are ill-equipped for holding back so many undead. I am certain we will be slaughtered if we try to fight them here!"
        [/message]
        [message]
            speaker=Deoran
            message= _ "But we cannot flee like this forever... the horses are tired, and the men are tired, and I am tired as well. The undead can march day and night without rest, but we cannot. They will certainly overtake us before we reach Westin."
        [/message]
        [message]
            speaker=Sir Gerrick
            message= _ "Then we have only one course of action to take. Deoran, you must hasten back to Westin to prepare a defense against them. I will command the defense of the border forts. Leave me a few men, and we will hold back the undead as long as we can."
        [/message]
        [message]
            speaker=Deoran
            message= _ "But such a thing will mean certain death!"
        [/message]
        [message]
            speaker=Sir Gerrick
            message= _ "Deoran, you are still young and have many things to learn. In dire times, sacrifices must always be made one way or another. If we flee with you, the undead will surely run us down and make short work of the city-folk. Then everything we have fought for will be lost!"
        [/message]
        [message]
            speaker=Deoran
            message= _ "Even so..."
        [/message]
        [message]
            speaker=Urza Afalas
            message= _ "I will stand here with you, Sir Gerrick. You will need my help to slow down the undead, and I have a debt to repay to you for sparing my life."
        [/message]
        [message]
            speaker=Sir Gerrick
            message= _ "Those are brave words that I would not have expected from you, Afalas."
        [/message]
        [message]
            speaker=Urza Afalas
            message= _ "All things end one way or another. Alas, I would have liked to see my home in Westin one more time, but I am too tired. Tired of running, and tired of fleeing from these undead, who corrupted and consumed my brothers. You may think us criminals and outlaws, but we are still human and we still know loyalty and gratitude."
        [/message]
        [message]
            speaker=Sir Gerrick
            message= _ "You will not change our minds, Deoran. Go!"
        [/message]
        [message]
            speaker=Deoran
            message= _ "I... I understand. Minister Hylas, come ride with me to Westin. You must summon the city council while I prepare the defenses. Sir Gerrick, Afalas, we shall return as soon as we can and relieve you."
        [/message]
        [message]
            speaker=Sir Gerrick
            message= _ "You know what the outcome of our battle here will be. I trust you to protect our home from the undead and only ask you to remember those who fell defending our land. Farewell, Sir Deoran!"
        [/message]
        [message]
            speaker=Minister Hylas
            message= _ "The light shines upon your souls, brave warriors."
        [/message]

        {MOVE_UNIT id=Deoran 16 5}

        [message]
            speaker=Deoran
            message= _ "We will never forget your sacrifice here. Thank you, my friend."
        [/message]

        {MOVE_UNIT id=Deoran 15 1}

        [store_unit]
            [filter]
                id=Deoran
            [/filter]

            variable=stored_Deoran
        [/store_unit]
        [kill]
            id=Deoran
        [/kill]

        {MOVE_UNIT id="Minister Hylas" 15 1}

        [store_unit]
            [filter]
                id=Minister Hylas
            [/filter]

            variable=stored_Hylas
        [/store_unit]
        [kill]
            id=Minister Hylas
        [/kill]

        {MODIFY_UNIT (id=Sir Gerrick) overlays ""}
        {MODIFY_UNIT (id=Sir Gerrick) canrecruit yes}
        {MODIFY_UNIT (id=Sir Gerrick) ellipse ""}

        {MODIFY_UNIT (id=Urza Afalas) overlays "misc/loyal-icon.png"}
        {MODIFY_UNIT (id=Urza Afalas) ellipse ""}

        [message]
            speaker=Illan
            message= _ "We are yours to command, Sir Gerrick. We will hold back the undead until the bitter end!"
        [/message]

        [objectives]
            side=1
            [objective]
                description= _ "Hold the line: keep Sir Gerrick alive as long as possible"
                condition=win
            [/objective]

            [gold_carryover]
                carryover_percentage=0
            [/gold_carryover]
            {HAS_NO_TURN_LIMIT}
            [note]
                description= _ "Starting with turn 6, each additional turn you survive strengthens the defenses of Westin."
            [/note]
        [/objectives]

        [message]
            speaker=narrator
            {TUTOR: _"Hold off the undead hordes and keep Sir Gerrick alive as long as you can. Starting on turn 6, every turn that passes strengthens the defenses of Westin."}
            image=wesnoth-icon.png
        [/message]
    [/event]

    [event]
        name=die
        first_time_only=no

        [filter]
            side=1
        [/filter]
        [gold]
            side=2,3
#ifdef EASY
            amount=9
#endif
#ifdef NORMAL
            amount=12
#endif
#ifdef HARD
            amount=15
#endif
        [/gold]

        [fire_event]
            name=allied_unit_death
        [/fire_event]
    [/event]

    [event]
        name=allied_unit_death

        [message]
            speaker=Sir Gerrick
            message= _ "Alas, for each casualty we suffer, the ranks of the undead grow. We must hold fast and survive as long as we can!"
        [/message]
    [/event]

    [event]
        name=turn 3

        [modify_side]
            side=2
            {INCOME 15 20 25}
        [/modify_side]
        [modify_side]
            side=3
            {INCOME 10 15 20}
        [/modify_side]
    [/event]
    [event]
        name=turn 6

        [modify_side]
            side=2
            {INCOME 20 25 30}
        [/modify_side]
        [modify_side]
            side=3
            {INCOME 15 20 25}
        [/modify_side]
    [/event]
    [event]
        name=turn 9

        [modify_side]
            side=2
            {INCOME 25 30 35}
        [/modify_side]
        [modify_side]
            side=3
            {INCOME 20 25 30}
        [/modify_side]
    [/event]
    [event]
        name=turn 12

        [modify_side]
            side=2
            {INCOME 30 35 40}
        [/modify_side]
        [modify_side]
            side=3
            {INCOME 25 30 35}
        [/modify_side]
    [/event]
    [event]
        name=turn 15

        [modify_side]
            side=2
            {INCOME 40 45 50}
        [/modify_side]
        [modify_side]
            side=3
            {INCOME 35 40 45}
        [/modify_side]
    [/event]
    [event]
        name=turn 18

        [modify_side]
            side=2
            {INCOME 50 55 60}
        [/modify_side]
        [modify_side]
            side=3
            {INCOME 45 50 55}
        [/modify_side]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Urza Afalas
        [/filter]

        [message]
            speaker=Urza Afalas
            message= _ "So this is how it ends... I am coming to you, my brothers..."
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Sir Gerrick
        [/filter]

        [message]
            speaker=Sir Gerrick
            message= _ "I only hope... we have bought enough time... for Deoran..."
        [/message]
        [kill]
            x,y=$x1,$y1
            animate=yes
        [/kill]
        [message]
            speaker="Mal M'Brin"
            message= _ "Pesky little humans! You have only delayed the inevitable. We will sweep through your cities and raze them to the ground! March onward, my skeletons! We go to destroy Westin!"
        [/message]

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

    [event]
        name=victory

        {VARIABLE pebbles_defense_length $turn_number}

        [kill]
            side=1
            {NOT_ON_RECALL_LIST}
            fire_event=no
            animate=no
        [/kill]

        {VARIABLE stored_Deoran.x recall}
        {VARIABLE stored_Deoran.y recall}
        {VARIABLE stored_Hylas.x recall}
        {VARIABLE stored_Hylas.y recall}

        [unstore_unit]
            variable=stored_Deoran
        [/unstore_unit]
        [unstore_unit]
            variable=stored_Hylas
        [/unstore_unit]

        # Set the amount of gold that the player has to what it was before Pebbles.
        [modify_side]
            side=1
            gold=$pebbles_starting_gold
        [/modify_side]
        {CLEAR_VARIABLE pebbles_starting_gold}
        {CLEAR_VARIABLE stored_Deoran}
        {CLEAR_VARIABLE stored_Hylas}

        # In case that matters if played as MP Campaign, make him vulnerable again
        [modify_unit]
            [filter]
                id="Mal M'Brin","Mal Tera"
            [/filter]
            [status]
                invulnerable=no
            [/status]
        [/modify_unit]
    [/event]
[/scenario]
