#textdomain wesnoth-trow
[scenario]
    id=04a_The_Swamp_of_Esten
    name= _ "The Swamp of Esten"
    next_scenario=05_The_Oldwood
    bonus=yes
    map_data="{campaigns/The_Rise_Of_Wesnoth/maps/04a_The_Swamp_of_Esten.map}"
    {TURNS 39 36 33}
    {DEFAULT_SCHEDULE}

    {SCENARIO_MUSIC wanderer.ogg}
    {EXTRA_SCENARIO_MUSIC knolls.ogg}

    [story]
        [part]
            # Same as in 04b!
            story= _ "So it came to pass that Prince Haldric was forced from his home, never to return. With the help of his father’s noble sacrifice he has escaped through the southern pass. Haldric has left the lands of his home, and before him stretches the vast expanse of the southern kingdoms of his people."

            background=story/fall_of_eldaric.png
            music=underground.ogg
        [/part]
        [part]
            story= _ "The river road follows the Isle’s greatest river to the southeast. This road leads to the Isle’s second largest city, Clearwater Port. It would likely have been the Isle’s largest city save for the events of the Wesfolk War. The Lich-Lords befouled much of the land around the river during the course of a great battle. Now the swamp is home to a Wesfolk-imitating cult."
            {TROW_GREEN_ISLE_BIGMAP}
        [/part]
    [/story]

    {BIGMAP_04A}

    {TROW_DEATHS}

    [side]
        type=Noble Commander
        id=Prince Haldric
        name= _ "Prince Haldric"
        unrenamable=yes
        side=1
        canrecruit=yes
        gold=100
        controller=human
        team_name=Haldric
        user_team_name=_"Refugees"
        fog=yes
        {FLAG_VARIANT loyalist}
    [/side]

    [side]
        type=Dark Sorcerer
        id=Cleon
        name= _ "Cleon"
        #This is the nearest enemy, make him softer.
        side=2
        canrecruit=yes
        #He's fodder boy
        recruit=Vampire Bat, Walking Corpse, Dark Adept
        [ai]
            {NO_SCOUTS}
            recruitment_pattern=scout,fighter,fighter,fighter,archer
            recruitment_ignore_bad_movement=yes
            {ATTACK_DEPTH 3 4 5}
        [/ai]
        {GOLD 80 120 160}
        team_name=cult
        user_team_name=_"Cultists"
        {FLAG_VARIANT undead}
    [/side]

    [side]
        type=Dark Sorcerer
        id=Lollyra
        name= _ "Lollyra"
        gender=female
        side=3
        canrecruit=yes
        {GOLD 130 170 210}
        [ai]
            {NO_SCOUTS}
            recruitment_ignore_bad_combat=yes
            recruitment_pattern=scout,fighter,fighter,fighter,archer
            {ATTACK_DEPTH 3 4 5}
        [/ai]
#ifdef EASY
        recruit=Dark Adept, Ghoul, Ghost, Skeleton, Skeleton Archer, Vampire Bat, Walking Corpse, Mudcrawler
#endif
#ifdef NORMAL
        recruit=Dark Adept, Necrophage, Ghost, Skeleton, Skeleton Archer, Blood Bat, Soulless, Giant Mudcrawler
#endif
#ifdef HARD
        recruit=Dark Adept, Necrophage, Wraith, Shadow, Revenant, Deathblade, Bone Shooter, Blood Bat, Soulless
#endif
        team_name=cult
        user_team_name=_"Cultists"
        {FLAG_VARIANT undead}
    [/side]

    [side]
        type=Dark Sorcerer
        id=Clurka
        name= _ "Clurka"
        gender=female
        side=4
        canrecruit=yes
        {GOLD 130 170 210}
        [ai]
            {NO_SCOUTS}
            recruitment_ignore_bad_movement=yes
            recruitment_pattern=scout,fighter,fighter,fighter,archer
            {ATTACK_DEPTH 3 4 5}
        [/ai]

#ifdef EASY
        recruit=Dark Adept, Ghoul, Ghost, Skeleton, Skeleton Archer, Vampire Bat, Walking Corpse, Mudcrawler
#endif
#ifdef NORMAL
        recruit=Dark Adept, Necrophage, Ghost, Skeleton, Skeleton Archer, Blood Bat, Soulless, Giant Mudcrawler
#endif
#ifdef HARD
        recruit=Dark Adept, Necrophage, Wraith, Shadow, Revenant, Deathblade, Bone Shooter, Blood Bat, Soulless
#endif
        team_name=cult
        user_team_name=_"Cultists"
        {FLAG_VARIANT undead}
    [/side]

    [event]
        name=prestart

        {PLACE_IMAGE (scenery/signpost.png) 15 31}
        {PLACE_IMAGE (scenery/temple1.png) 19 5}
        {PLACE_IMAGE (scenery/temple1.png) 30 10}
        {PLACE_IMAGE (scenery/temple1.png) 34 36}
        {PLACE_IMAGE (scenery/temple1.png) 1 26}
        {PLACE_IMAGE (scenery/temple1.png) 5 12}

        {GUARD_UNIT (Giant Scorpion) () ( _ "Scorpion") 2 26 4}
        {GUARD_UNIT (Giant Scorpion) () ( _ "Scorpion") 3 32 27}
        {GUARD_UNIT (Giant Scorpion) () ( _ "Scorpion") 4 17 35}
#ifdef NORMAL
        {GUARD_UNIT (Giant Scorpion) () ( _ "Scorpion") 2 13 8}
        {GUARD_UNIT (Giant Scorpion) () ( _ "Scorpion") 3 32 31}
        {GUARD_UNIT (Giant Scorpion) () ( _ "Scorpion") 4 9 34}
#endif
#ifdef HARD
        {GUARD_UNIT (Giant Scorpion) () ( _ "Scorpion") 2 13 8}
        {GUARD_UNIT (Giant Scorpion) () ( _ "Scorpion") 2 15 3}
        {GUARD_UNIT (Giant Scorpion) () ( _ "Scorpion") 3 32 31}
        {GUARD_UNIT (Giant Scorpion) () ( _ "Scorpion") 3 33 36}
        {GUARD_UNIT (Giant Scorpion) () ( _ "Scorpion") 4 9 34}
        {GUARD_UNIT (Giant Scorpion) () ( _ "Scorpion") 4 20 32}
#endif
        [recall]
            id=Lady Outlaw
        [/recall]

        [recall]
            id=Burin the Lost
        [/recall]

        [objectives]
            side=1
            [objective]
                description= _ "Defeat all enemy leaders"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Prince Haldric"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

            [gold_carryover]
                bonus=yes
                carryover_percentage=40
            [/gold_carryover]
        [/objectives]
    [/event]

    [event]
        name=start
        [message]
            speaker=narrator
            message= _ "With great trepidation, Prince Haldric leads his refugee band into the Swamp of Esten. In the center of that very swamp a shroud of fog descends over young Prince Haldric."
            image=wesnoth-icon.png
        [/message]

        [message]
            speaker=Prince Haldric
            message= _ "I have a very bad feeling about this. This awful swamp and its crazy cult... Before these troubles started we used to have to clear the swamp every spring and fall."
        [/message]

        [message]
            speaker=Prince Haldric
            message= _ "I suppose with the rampaging bands of murderous orcs roaming about that hasn’t been done in a while."
        [/message]

        [message]
            speaker=Burin the Lost
            message= _ "I miss the orcs... We go all this way, and (<i>sniff</i>) what a lovely smell we have discovered."
            image=portraits/burin-annoyed.png
        [/message]

        [message]
            speaker=Lady Outlaw
            message= _ "This is too quiet. I don’t like this one bit, not one bit at all."
        [/message]

        [message]
            speaker=Prince Haldric
            message= _ "Wait, I think I hear something... To arms!"
        [/message]
    [/event]

    [event]
        name=moveto
        first_time_only=no

        [filter]
            side=1

            [filter_location]
                [and]
                    x,y=13,6

                    [or]
                        x,y=10,25
                    [/or]

                    [or]
                        x,y=28,33
                    [/or]

                    radius=4
                [/and]

                [not]
                    find_in=triggered_scorpion_locs
                    radius=4
                [/not]
            [/filter_location]
        [/filter]

        [store_locations]
            [and]
                x,y=13,6

                [or]
                    x,y=10,25
                [/or]

                [or]
                    x,y=28,33
                [/or]
            [/and]

            [and]
                x,y=$x1,$y1
                radius=4
            [/and]

            [or]
                find_in=triggered_scorpion_locs
            [/or]

            variable=triggered_scorpion_locs
        [/store_locations]

        [event]
            name=new turn
            delayed_variable_substitution=no

            [store_unit]
                [filter]
                    side=1
                [/filter]

                kill=no
                variable=temp
            [/store_unit]

            {VARIABLE i 0}
            [while]
                [variable]
                    name=i
                    less_than=$|temp.length
                [/variable]

                [do]
                    [store_locations]
                        find_in=player_vision_edge

                        [or]
                            x,y=$|temp[$|i].x,$|temp[$|i].y
                            radius="$|($|temp[$|i].max_moves + 1)"

                            [filter_radius]
                                terrain=Wwf,G*,R*
                            [/filter_radius]
                        [/or]

                        variable=player_vision_edge
                    [/store_locations]

                    {VARIABLE_OP i add 1}
                [/do]
            [/while]

            [store_locations]
                find_in=player_vision_edge

                [filter_adjacent_location]
                    terrain=Wwf,G*,R*

                    [not]
                        find_in=player_vision_edge
                    [/not]
                [/filter_adjacent_location]

                variable=player_vision_edge
            [/store_locations]

            {CLEAR_VARIABLE temp}

            {VARIABLE search_radius 5}
            [while]
                [variable]
                    name=possible_scorpion_locs.length
                    less_than=1
                [/variable]

                [variable]
                    name=search_radius
                    less_than=20
                [/variable]

                [do]
                    [store_locations]
                        x,y=$x1,$y1
                        radius=$|search_radius

                        variable=temp
                    [/store_locations]

                    [store_locations]
                        find_in=temp

                        [and]
                            find_in=player_vision_edge
                        [/and]

                        variable=possible_scorpion_locs
                    [/store_locations]

                    [if]
                        [variable]
                            name=possible_scorpion_locs.length
                            greater_than_equal_to=1
                        [/variable]

                        [then]
                            {VARIABLE_OP scorpion_loc_i rand "0..$|($|possible_scorpion_locs.length - 1)"}
                            {VARIABLE spawn_x $|possible_scorpion_locs[$|scorpion_loc_i].x}
                            {VARIABLE spawn_y $|possible_scorpion_locs[$|scorpion_loc_i].y}

                            [scroll_to]
                                x,y=$|spawn_x,$|spawn_y
                            [/scroll_to]

                            {NAMED_LOYAL_UNIT 2 (Giant Scorpion) $|spawn_x $|spawn_y () ( _ "Scorpion")}
                            [+unit]
                                animate=yes
                            [/unit]

                            {CLEAR_VARIABLE scorpion_loc_i,spawn_x,spawn_y}
                        [/then]
                    [/if]

                    {VARIABLE_OP search_radius add 1}
                [/do]
            [/while]

            {CLEAR_VARIABLE player_vision_edge,search_radius,temp,possible_scorpion_locs}
        [/event]
    [/event]

#define TEMPLE_HELP X Y
    [event]
        name=moveto
        [filter]
            side=1
            x={X}
            y={Y}
        [/filter]
        [message]
            speaker=Prince Haldric
            message= _ "Careful, you don’t know what’s lurking in there!"
        [/message]
        [unit]
            side=1
            type=White Mage
            id=Minister Edren
            name= _ "Minister Edren"
            profile="portraits/edmond.png"
            x={X}
            y={Y}
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_STRONG}
            [/modifications]
            {IS_LOYAL}
        [/unit]
        [message]
            speaker=Minister Edren
            message= _ "Back you vile— Oh, sorry I thought you were undead. When are those goofs in Clearwater Port going to clear the swamp again?"
        [/message]
        [message]
            speaker=Prince Haldric
            message= _ "Maybe they’ll clear it some time after the APOCALYPSE is OVER!"
            image=portraits/haldric-mad.png
        [/message]
        [message]
            speaker=Minister Edren
            message= _ "Oooh! I take it you wouldn’t mind if I helped out?"
        [/message]
    [/event]
#enddef

#define TEMPLE_TRAP X Y
    [event]
        name=moveto
        [filter]
            side=1
            x={X}
            y={Y}
        [/filter]
        [message]
            speaker=unit
            message= _ "Hey, there’s somebody hidden in the temple. Ack! Hold there!"
        [/message]
        {LOYAL_UNIT 2 (Vampire Bat) ({X}) ({Y})}
        {LOYAL_UNDEAD_UNIT 3 (Walking Corpse) ({X}) ({Y})}
        {LOYAL_UNDEAD_UNIT 4 (Walking Corpse) ({X}) ({Y})}

#ifdef HARD
        {LOYAL_UNDEAD_UNIT 2 (Ghost) ({X}) ({Y})}
#endif
    [/event]
#enddef

#define TEMPLE_LOOT X Y
    [event]
        name=moveto
        [filter]
            side=1
            x={X}
            y={Y}
        [/filter]

        {LOOT 50 1}
    [/event]
#enddef

    [event]
        name=start
        {RANDOM 1..3}
        [if]
            [variable]
                name=random
                numerical_equals=1
            [/variable]
            [then]
                {TEMPLE_HELP 5 12}
                {TEMPLE_TRAP 34 36}
                {TEMPLE_TRAP 19 5}
                {TEMPLE_LOOT 1 26}
                {TEMPLE_LOOT 30 10}
            [/then]
        [/if]
        [if]
            [variable]
                name=random
                numerical_equals=2
            [/variable]
            [then]
                {TEMPLE_HELP 1 26}
                {TEMPLE_TRAP 34 36}
                {TEMPLE_TRAP 5 12}
                {TEMPLE_LOOT 19 5}
                {TEMPLE_LOOT 30 10}
            [/then]
        [/if]
        [if]
            [variable]
                name=random
                numerical_equals=3
            [/variable]
            [then]
                {TEMPLE_HELP 19 5}
                {TEMPLE_TRAP 34 36}
                {TEMPLE_TRAP 1 26}
                {TEMPLE_LOOT 5 12}
                {TEMPLE_LOOT 30 10}
            [/then]
        [/if]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x=15
            y=31
        [/filter]

        [redraw]
        [/redraw]

        [message]
            speaker=narrator
            # wmllint: local spelling SW
            #wmllint: display on
            message= _ "SW — The Oldwood Forest.
Enter at Your Own Risk!"
            #wmllint: display off
            image=scenery/signpost.png
        [/message]
        [allow_undo]
        [/allow_undo]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Lollyra
        [/filter]
        [message]
            speaker=Lollyra
            # wmllint: local spelling Un-death
            message= _ "May I live forever in Un-death!"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Clurka
        [/filter]
        [message]
            speaker=Clurka
            message= _ "Ohh! To be risen again!"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Cleon
        [/filter]
        [message]
            speaker=Cleon
            message= _ "A prayer for life immortal!"
        [/message]
    [/event]

    [event]
        name=enemies defeated

        [sound]
            name=horse-canter.wav
        [/sound]

        [unit]
            side=1
            type=Knight
            id=Sir Ruddry
            name= _ "Sir Ruddry"
            profile="portraits/ruddry.png"
            x=35
            y=35
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_RESILIENT}
            [/modifications]
            {IS_LOYAL}
        [/unit]

        [redraw]
            side=1
        [/redraw]

        {MOVE_UNIT (id=Sir Ruddry) 30 33}

        [message]
            speaker=Sir Ruddry
            message= _ "I don’t know who you are, but you can’t continue down this road! There is a horde of those orcs bigger than any army I’ve ever seen just down the road!"
        [/message]

        [message]
            speaker=Prince Haldric
            message= _ "I’m Haldric; my father was King Eldaric IV in the lands northwest of here. Soldier, have you deserted your post?"
        [/message]

        [message]
            speaker=Sir Ruddry
            message= _ "No, Sir! I’m the sole survivor of the Clearwater Port expeditionary force. Trust me, you can’t continue down this road, Sir. Especially with the refugees, you’ll be slaughtered."
        [/message]

        [message]
            speaker=Prince Haldric
            message= _ "Tell me, does Clearwater Port still stand? Is the port free?"
        [/message]

        [message]
            speaker=Sir Ruddry
            message= _ "As far as I know, Sir. We have a large army, and they were pressing all able bodied men and boys into service when I left. That orcish army is huge, but they haven’t met the main body of our forces yet."
        [/message]

        [message]
            speaker=Prince Haldric
            message= _ "Well, we can’t go back, and the road ahead is blocked. I guess we’ll have to risk it and go through the Oldwood forest, then make a break for Clearwater Port or Southbay."
        [/message]

        [message]
            speaker=Burin the Lost
            message= _ "Oh great, now a forest... I should have stayed at home and took my chances with the orcs!"
            image=portraits/burin-annoyed.png
        [/message]

        [message]
            speaker=Sir Ruddry
            message= _ "Sir, if you don’t mind, I’ll go with you."
        [/message]

        [message]
            speaker=Lady Outlaw
            message= _ "On we go..."
        [/message]
        [set_variable]
            name=last_done
            value="River"
        [/set_variable]

        {CLEAR_VARIABLE random}
        {CLEAR_VARIABLE triggered_scorpion_locs}

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

    [event]
        name=time over
        [message]
            speaker=Prince Haldric
            message= _ "We have run out of time... We’ll be trapped in this swamp when winter arrives!"
        [/message]
    [/event]
[/scenario]
