#textdomain wesnoth-ei

#wmllint: local spelling alswdan

[scenario]
    id=04b_Ill_Humors
    name= _ "Ill Humours"
    map_file=04b_Ill_Humors.map
    turns=22
    next_scenario=05_Northern_Outpost

    {DEFAULT_SCHEDULE_AFTERNOON}

    {SETUP_CAMPFIRES}

    {SCENARIO_MUSIC into_the_shadows.ogg}
    {EXTRA_SCENARIO_MUSIC underground.ogg}

    [story]
        [part]
            story=_ "Pursued by a vengeful Mal-Skraat and his minions, Gweddry and Dacyn were forced eastward out of the Estmarks, into the near reaches of the uncharted Bitter Swamp."
            music=silence.ogg
            {EI_BIGMAP}
        [/part]
    [/story]
    {EI_TRACK {JOURNEY_04B_NEW} }

    #------------------
    # GWEDDRY
    #------------------
    [side]
        side=1
        controller=human
        {GOLD 170 160 150}
        team_name=wesnothians
        user_team_name= _ "Wesnothians"
        {FLAG_VARIANT loyalist}
        fog=yes
        {CHARACTER_STATS_GWEDDRY}
    [/side]

    #------------------
    # MAL-SKRAAT
    #------------------
    [side]
        side=2
        type=Dark Sorcerer
        id=Mal-Skraat
        name= _ "Mal-Skraat"
        gender=male
        canrecruit=yes
        facing=se
        [modifications]
            {TEAM_COLOR_OVERRIDE () darkred}
            {TRAIT_INTELLIGENT}
            {TRAIT_STRONG}
        [/modifications]
        controller=ai
        recruit=Vampire Bat,Blood Bat
        {GOLD 22 22 22} # remember he starts with several non-loyal defenders, so he needs enough gold to get at least 1 vampire/blood bat
        {INCOME 0 6 12}
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        [ai]
            leader_value=0
        [/ai]
    [/side]
    {SILENTLY_LIMIT_LEADER_MOVES 2 1}
    [event]
        name=side 1 turn end
        first_time_only=no
        {RESET_SIDE_AI 2 no 0.8 0.25}
        {VARY_AI_BY_SCHEDULE 2}
    [/event]
    [event] # create ambush guards
        name=prestart
        {NAMED_UNIT 2 {ON_DIFFICULTY "Walking Corpse" "Skeleton Rider" "Bone Knight"   } 1 8 "rider1" "" ()}
        {NAMED_UNIT 2 {ON_DIFFICULTY "Walking Corpse" "Skeleton Rider" "Skeleton Rider"} 1 7 "rider2" "" ()}
        {NAMED_UNIT 2 {ON_DIFFICULTY "Walking Corpse" "Soulless"       "Skeleton Rider"} 2 7 "rider3" "" ()}
        [micro_ai]
            ai_type=zone_guardian
            side=2
            action=add
            id=rider1,rider2,rider3
            station_x=1
            station_y=8
            [filter_location]
                x,y=3,3
                radius=6
            [/filter_location]
        [/micro_ai]
    [/event]

    #------------------
    # SWAMP LURKERS
    #------------------
#define LIZARD_NERF
    [+unit]
        level={ON_DIFFICULTY 1 2 2}
        [modifications]
            [object]
                [effect]
                    apply_to=alignment
                    set=neutral
                [/effect]
                # makes the night less paralyzing. Players didn't enjoy having to afk all night
                [effect]
                    apply_to=attack
                    increase_damage={ON_DIFFICULTY  -6 -2 -0}
                [/effect]

                [effect]
                    apply_to=hitpoints
                    increase_total={ON_DIFFICULTY -20 -5 -0}
                [/effect]

                [effect]
                    apply_to=image_mod
                    add={ON_DIFFICULTY "~SCALE(70,70)" "" ""}
                [/effect]
            [/object]
        [/modifications]
    [/unit]
#enddef
    [side]
        side=3
        controller=ai
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        no_leader=yes
        hidden=yes
        [ai]
            caution=-9
            grouping=no
            leader_value=0
        [/ai]

        {GENERIC_UNIT 3 (Swamp Lizard) 33 9} {LIZARD_NERF} {FACING sw}
    [/side]
    {SILENTLY_LIMIT_MOVES 3 (upkeep=loyal) 3} # keep the guardians from being too aggressive

    [event] # create swamp lizards
        name=side 1 turn 2 # wait until turn 2, so there's no risk of one messing up hahid's cutscene
        [random_placement]
            variable=location
            num_items=6
            min_distance=7
            [filter_location]
                x=19-45, 39-45, 23-39   # the edges of the map
                y= 1-5,   5-25, 22-25
                terrain=Ss,Sm,Sm^Qhu
            [/filter_location]
            [command]
                {GENERIC_UNIT 3 "Swamp Lizard" $location.x $location.y} {LIZARD_NERF} {GUARDIAN}
            [/command]
        [/random_placement]
    [/event]

#define SPAWN_ON_TURN TURN TYPE SPAWNX SPAWNY
    [event]
        name=side 1 turn {TURN}
        {VARIABLE temp {TYPE}}
        [if]
            {VARIABLE_CONDITIONAL temp not_equals none}
            [then]
                {GENERIC_UNIT 3 ({TYPE}) {SPAWNX} {SPAWNY}} {VARIATION bat}
            [/then]
        [/if]
        {CLEAR_VARIABLE temp}
    [/event]
#enddef
    {SPAWN_ON_TURN  1 ({ON_DIFFICULTY "Dragonfly Naiad" "Dragonfly Naiad" "Dragonfly Naiad"}) 45 25}
    {SPAWN_ON_TURN  1 ({ON_DIFFICULTY "none"            "Dragonfly Naiad" "Dragonfly Naiad"}) 45 25}
    {SPAWN_ON_TURN  1 ({ON_DIFFICULTY "none"            "none"            "Dragonfly Naiad"}) 45 25}

    {SPAWN_ON_TURN  3 ({ON_DIFFICULTY "Dragonfly Naiad" "Dragonfly"       "Dragonfly"      }) 45 19}
    {SPAWN_ON_TURN  3 ({ON_DIFFICULTY "none"            "Dragonfly Naiad" "Dragonfly Naiad"}) 45 19}
    {SPAWN_ON_TURN  3 ({ON_DIFFICULTY "none"            "none"            "Dragonfly Naiad"}) 45 19}

    {SPAWN_ON_TURN  9 ({ON_DIFFICULTY "none"            "Dragonfly Naiad" "Dragonfly Naiad"}) 30 25}
    {SPAWN_ON_TURN  9 ({ON_DIFFICULTY "none"            "none"            "Dragonfly Naiad"}) 30 25}

    {SPAWN_ON_TURN 12 ({ON_DIFFICULTY "Dragonfly Naiad" "Dragonfly"       "Dragonfly"      }) 45  1}
    {SPAWN_ON_TURN 12 ({ON_DIFFICULTY "none"            "Dragonfly Naiad" "Dragonfly"      }) 45  1}
    {SPAWN_ON_TURN 12 ({ON_DIFFICULTY "none"            "none"            "Dragonfly Naiad"}) 45  1}

    {SPAWN_ON_TURN 15 ({ON_DIFFICULTY "none"            "Dragonfly Naiad" "Dragonfly Naiad"}) 34 25}
    {SPAWN_ON_TURN 15 ({ON_DIFFICULTY "none"            "none"            "Dragonfly Naiad"}) 34 25}

    {SPAWN_ON_TURN 17 ({ON_DIFFICULTY "Dragonfly Naiad" "Dragonfly Naiad" "Dragonfly Naiad"}) 30 25}
    {SPAWN_ON_TURN 17 ({ON_DIFFICULTY "none"            "none"            "Dragonfly Naiad"}) 30 25}

    {SPAWN_ON_TURN 19 ({ON_DIFFICULTY "none"            "Dragonfly"       "Dragonfly"      }) 45 13}
    {SPAWN_ON_TURN 19 ({ON_DIFFICULTY "none"            "Dragonfly Naiad" "Dragonfly"      }) 45 13}
    {SPAWN_ON_TURN 19 ({ON_DIFFICULTY "none"            "none"            "Dragonfly Naiad"}) 45 13}
    {SPAWN_ON_TURN 19 ({ON_DIFFICULTY "none"            "none"            "Dragonfly Naiad"}) 45 13}

    {SPAWN_ON_TURN 22 ({ON_DIFFICULTY "Dragonfly Naiad" "Dragonfly Naiad" "Dragonfly"      }) 23  1}
    {SPAWN_ON_TURN 22 ({ON_DIFFICULTY "none"            "Dragonfly Naiad" "Dragonfly"      }) 23  1}

    #------------------
    # DUNEFOLK
    #------------------
    [side]
        side=4
        controller=ai
        team_name=wesnothians
        #po: a group of Dunefolk
        user_team_name= _ "Far Travelers"
        no_leader=yes
        hidden=yes
        fog=yes
        shroud=yes
        share_vision=none # not at first
        gold=0
        income=5 # 0 net income, after maintenance
        [ai]
            aggression=0.1
            caution=0.9
        [/ai]
        {NAMED_NOTRAIT_UNIT 4 (Dune Soldier) 8 24 "Ikriaf" (_"Ikriaf")}
        [+unit]
            [modifications]
                {TRAIT_MERCENARY}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        {AI_ZONE_GUARDIAN 4 "Ikriaf"     8 24  5 25 4}

        {NAMED_NOTRAIT_UNIT 4 (Dune Swordsman) 6 22 "Ragnabair" (_"Ragnabair")}
        [+unit]
            [modifications]
                {TRAIT_MERCENARY}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        {AI_ZONE_GUARDIAN 4 "Ragnabair"  6 22  5 25 4}

        {NAMED_NOTRAIT_UNIT 4 (Dune Soldier) 2 23 "Abman" (_"Abman")}
        [+unit]
            [modifications]
                {TRAIT_MERCENARY}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        {AI_ZONE_GUARDIAN 4 "Abman"      2 23  5 25 4}

        {NAMED_NOTRAIT_UNIT 4 (Dune Rider) 4 22 "Nur al-Nuh" (_"Nur al-Nuh")}
        [+unit]
            [modifications]
                {TRAIT_MERCENARY}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        {AI_ZONE_GUARDIAN 4 "Nur al-Nuh" 4 22  5 25 4}

        {NAMED_NOTRAIT_UNIT 4 (Dune Falconer) 3 25 "Muma" (_"Muma")}
        [+unit]
            [modifications]
                {TRAIT_MERCENARY}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        {AI_ZONE_GUARDIAN 4 "Muma"       3 25  5 25 4}
    [/side]
    [event]
        name=prestart
        # all in one spot, so it's consistent if I change it
        {VARIABLE herbs_needed {ON_DIFFICULTY 4 5 6}}
        {VARIABLE gold_cost 50}
        {VARIABLE gold_extra 150}
    [/event]

    # and a few undead guards
    [side]
        side=5
        color=brown  # same color as the lich in S04c
        no_leader=yes
        hidden=yes
        controller=ai
        team_name=undead
        user_team_name= _ "Undead"
        {NAMED_LOYAL_UNIT 5 ({ON_DIFFICULTY "Walking Corpse"  Skeleton          Revenant     }) 36  6 "guardN" ""}
        {AI_ZONE_GUARDIAN 5 "guardN"     36  6  36  6 3}

        {NAMED_LOYAL_UNIT 5 ({ON_DIFFICULTY "Walking Corpse" "Skeleton Archer" "Bone Shooter"}) 42 15 "guardE" ""}
        {AI_ZONE_GUARDIAN 5 "guardE"     42 15  42 15 3}

        {NAMED_LOYAL_UNIT 5 ({ON_DIFFICULTY "Walking Corpse"  Skeleton          Revenant     }) 35 21 "guardS" ""}
        {AI_ZONE_GUARDIAN 5 "guardS"     35 21  35 21 3}
    [/side]

    #------------------
    # PRESTART
    #------------------
    [event]
        name=prestart

        [objectives]
            side=1
            [objective]
                #po: Mal-Skraat is male
                description= _ "Defeat Mal-Skraat"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Gweddry or Dacyn"
                condition=lose
            [/objective]
            {TURNS_RUN_OUT}
            [gold_carryover]
                bonus=yes
                carryover_percentage=40
            [/gold_carryover]
            [note]
                description= _ "Any unit that begins or ends its turn adjacent to a swamp hex will become poisoned."
            [/note]
        [/objectives]

        {RECALL Dacyn}
    [/event]
    #------------------
    # POISON
    #------------------
    [event]
        name=side 1 turn refresh, side 1 turn end
        first_time_only=no
        {MODIFY_UNIT (
            side=1
            [not]
                status=unpoisonable
            [/not]
            [filter_location]
                terrain=Ss,Sm,Sm^Qhu
                radius=1
            [/filter_location]
        ) status.poisoned yes}
    [/event]

    #------------------
    # OPENING DIALOGUE
    #------------------
    [event]
        name=start
        [message]
            speaker=Gweddry
            message= _ "Ugh, the fumes from this swamp are horrific! I can barely see my nose and some of the men have started collapsing from sickness. I don’t think we can march much deeper."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "We have already marched much too far eastward. We should now head northwest and try to reach Wesnoth’s northern river outpost. Owaec’s soldiers have likely been routed or killed, but the outpost itself will still provide a place to regroup."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "I had hoped to preserve the lives of our men, yet it seems we have no choice but to confront this infernal sorcerer."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "This is a very dangerous place for us to fight. We must stay away from this swamp’s vapours, lest we become poisoned. And we should be cautious when venturing forth; there is no telling what lurks invisible under the water."
        [/message]
    [/event]

    #------------------
    # DUNEFOLK ARRIVE
    #------------------
    [event]
        name=side 1 turn end

        # opening units
        [unit]
            side=4
            x,y=17,21
            name= _ "Safyam"
            id="Safyam"
            gender=female
            type=Dune Burner
            [modifications]
                {TRAIT_MERCENARY}
                {TRAIT_QUICK}
            [/modifications]
            facing=se
            [status]
                poisoned=yes
            [/status]
        [/unit]
        [unit]
            side=4
            x,y=19,21
            name= _ "Hahid al-Ali"
            id="Hahid al-Ali"
            type=Dune Apothecary
            facing=se
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_MERCENARY}
                {HERB_OVERLAY_ONESCENARIO}
            [/modifications]
            [status]
                unpoisonable=yes
            [/status]
        [/unit]
        [item]
            x,y=21,20
            image=items/swamp_herb.png
            visible_in_fog=no
        [/item]

        # voices in the fog
        [message]
            speaker=Dacyn
            message= _ "Quiet, someone approaches..."
        [/message]
        [message]
            #po: Speaker (not the spoken text), but used both for humans in S04b and later for the voices from the amulet
            caption= _ "Unknown"
            image=units/unknown-unit1.png
            #po: male speaker talking to female
            #po: alswdan is a fictional swamp herb
            #po: suggested pronunciation is "ull-su-dahn"
            message= _ "It must be here somewhere! I’m telling you, alswdan only grows in swamps, and this is the grandest one on the continent."
        [/message]
        [message]
            #po: Speaker (not the spoken text), but used both for humans in S04b and later for the voices from the amulet
            caption= _ "Unknown 2"
            image=units/unknown-unit2.png
            #po: female speaker talking to male, but "us" being a group of at least 5
            message= _ "And <i>I’m</i> telling <i>you</i>, you’re going to get us killed wandering around these northlands! I haven’t seen home in years! Your ‘easy money’ expedition has already led us far-too-far astray from the dunes."
        [/message]

        # demonstrating poison immunity
        {SCROLL_TO 18 21}
        [lift_fog]
            [filter_side]
                side=1
            [/filter_side]
            x,y=18,20
            radius=4
        [/lift_fog]
        [message]
            speaker=Gweddry
            #po: speaking to 1 male and 1 female
            message= _ "Hail, strangers! Are you friend or foe? What brings you to this foul swamp?"
        [/message]
        [message]
            speaker=Hahid al-Ali
            #po: speaking to Gweddry
            message= _ "Ah, natives! Perhaps you can help us! I am Hahid al-Ali, herbalist extraordinaire, and this is my assistant Safyam. We’ve journeyed to your lands seeking the rare gwza-alswdan plant."
        [/message]
        [message]
            speaker=Hahid al-Ali
            #po: telling his female companion to harvest a herb
            message= _ "Why, there’s one now! Safyam, if you would."
        [/message]
        {MOVE_UNIT id=Safyam 21 20}
        [lift_fog]
            [filter_side]
                side=1
            [/filter_side]
            x,y=21,20
            radius=4
        [/lift_fog]
        {REMOVE_IMAGE 21 20}
        [sound]
            name=bat-flapping.wav
        [/sound]

        [delay]
            time=250
        [/delay]

        [modify_unit]
            [filter]
                id=Safyam
            [/filter]
            {HERB_OVERLAY_ONESCENARIO}
            [status]
                unpoisonable=yes
            [/status]
        [/modify_unit]
        [delay]
            time=250
        [/delay]

        # negotiations
        [message]
            speaker=Hahid al-Ali
            message= _ "Thanks to my cure made from this marvelous herb, she is now immune to the swamp’s ill humours! With more, I can make an antitoxin strong enough to cure the draught of death itself!"
        [/message]
        [message]
            speaker=Gweddry
            message= _ "If we help you find more of this ‘alswdan’, will you share your cure with us? Our people have been attacked by undead and we must now fight this dark sorcerer to return home."
        [/message]
        [message]
            speaker=Hahid al-Ali
            message= _ "Ho ho, a haggler after my own heart! I don’t see why not. But if these undead are giving you such trouble, why not strike them in their capital? Safyam spotted it not far east of here. I want nothing to do with them of course, but I’m sure you military-minded folk would have no trouble storming their walls."
        [/message]
        [message]
            speaker=Hahid al-Ali
            message= _ "If you can find enough alswdan and pay a small fee, I’d be happy to inoculate all of your men and point you in the direction of the undead fortress."
        [/message]
        {MODIFY_UNIT (id=Hahid al-Ali) side 1}
        {MODIFY_UNIT (id=Safyam) side 1}
        [modify_side]
            side=4
            share_vision=all
            hidden=no
        [/modify_side]
        [redraw]
        [/redraw]

#define HERBS_OBJECTIVE COUNT STRING
    [objective]
        {ALTERNATIVE_OBJECTIVE_CAPTION}
        description={STRING}
        condition=win
        [show_if]
            [have_unit]
                id=Hahid al-Ali
            [/have_unit]
            [variable]
                name=herbs_needed
                equals={COUNT}
            [/variable]
        [/show_if]
    [/objective]
#enddef
#define SHOW_IF_HERBS_OBJECTIVE_ACTIVE
    [show_if]
        [have_unit]
            id=Hahid al-Ali
        [/have_unit]
        [variable]
            name=herbs_needed
            greater_than=0
        [/variable]
    [/show_if]
#enddef
        # alter objectives
        [objectives]
            side=1
            [objective]
                description= _ "To travel west, defeat Mal-Skraat. <i>(normal)</i>"
                condition=win
            [/objective]
            {HERBS_OBJECTIVE 6 (_ "To travel east, collect 6 alswdan herbs and pay Hahid al-Ali $gold_cost gold. <i>(challenging)</i>")}
            {HERBS_OBJECTIVE 5 (_ "To travel east, collect 5 alswdan herbs and pay Hahid al-Ali $gold_cost gold. <i>(challenging)</i>")}
            {HERBS_OBJECTIVE 4 (_ "To travel east, collect 4 alswdan herbs and pay Hahid al-Ali $gold_cost gold. <i>(challenging)</i>")}
            {HERBS_OBJECTIVE 3 (_ "To travel east, collect 3 alswdan herbs and pay Hahid al-Ali $gold_cost gold. <i>(challenging)</i>")}
            {HERBS_OBJECTIVE 2 (_ "To travel east, collect 2 alswdan herbs and pay Hahid al-Ali $gold_cost gold. <i>(challenging)</i>")}
            {HERBS_OBJECTIVE 1 (_ "To travel east, collect 1 alswdan herb and pay Hahid al-Ali $gold_cost gold. <i>(challenging)</i>")}
            [objective]
                description= _ "<i>(herbs are spread in all directions around your starting keep)</i>"
                condition=win
                {SHOW_IF_HERBS_OBJECTIVE_ACTIVE}
            [/objective]
            [objective]
                description= _ "Death of Gweddry or Dacyn"
                condition=lose
            [/objective]
            {TURNS_RUN_OUT}
            [gold_carryover]
                bonus=yes
                carryover_percentage=40
            [/gold_carryover]
            [note]
                description= _ "Any unit that begins or ends its turn adjacent to a swamp hex will become poisoned. Hahid and Safyam are already immune."
                [show_if]
                    [have_unit]
                        id=Hahid al-Ali
                    [/have_unit]
                [/show_if]
            [/note]
            [note]
                description= _ "Any unit that begins or ends its turn adjacent to a swamp hex will become poisoned."
                [show_if]
                    [not]
                        [have_unit]
                            id=Hahid al-Ali
                        [/have_unit]
                    [/not]
                [/show_if]
            [/note]
            [note]
                description= _ "The dunefolk will not follow you to the next scenario."
                {SHOW_IF_HERBS_OBJECTIVE_ACTIVE}
            [/note]
        [/objectives]
        [fire_event]
            name=place_herbs
        [/fire_event]
    [/event]

#define PLACE_HERB I
    [item]
        x,y=$herb_locations[{I}].x, $herb_locations[{I}].y
        image=items/swamp_herb.png
        visible_in_fog=no
    [/item]
    [event]
        name=moveto
        [filter]
            side=1
            x,y=$herb_locations[{I}].x, $herb_locations[{I}].y
        [/filter]
        [modify_unit]
            [filter]
                id=$unit.id
            [/filter]
            {HERB_OVERLAY_ONESCENARIO}
            [status]
                unpoisonable=yes
            [/status]
        [/modify_unit]

        [if]
            [have_unit]
                id=Hahid al-Ali
            [/have_unit]

            [and]
                {VARIABLE_CONDITIONAL herbs_needed greater_than 0}
            [/and]

            [then]
                {VARIABLE_OP herbs_needed sub 1}
                [if]
                    {VARIABLE_CONDITIONAL herbs_needed less_than_equal_to 0}
                    [then]
                        {REMOVE_IMAGE $herb_locations[{I}].x, $herb_locations[{I}].y}
                        [fire_event]
                            name=herbs_collected
                        [/fire_event]
                    [/then]

                    [else]
                        [message]
                            speaker=unit
                            #po: TODO for 1.19: make this the male message, and add a separate female one
                            message= _ "I’ve found a sprig of alswdan and am now immune to the swamp’s poison! We’ll need $herbs_needed more (and $gold_cost gold) to travel east."
                        [/message]
                    [/else]
                [/if]
            [/then]

            [else]
                [message]
                    speaker=unit
                    #po: TODO for 1.19: make this the male message, and add a separate female one
                    message= _ "I’ve found a sprig of alswdan and am now immune to the swamp’s poison!"
                [/message]
            [/else]
        [/if]

        {REMOVE_IMAGE $herb_locations[{I}].x, $herb_locations[{I}].y}
    [/event]
#enddef
#define RANDOM_HERB I X Y
    [random_placement]
        variable=location
        num_items=1
        [filter_location]
            x,y={X},{Y}
            terrain=Ss,Sm,Sm^Qhu
        [/filter_location]
        [command]
            {VARIABLE herb_locations[{I}].x $location.x}
            {VARIABLE herb_locations[{I}].y $location.y}
            {PLACE_HERB {I}}
        [/command]
    [/random_placement]
#enddef

    [event]
        name=place_herbs
        {RANDOM_HERB 1  37-45  1-4 } # top right corner (hard)
        {RANDOM_HERB 2  34-42  5-10} # upper- middle right (medium)
        {RANDOM_HERB 3  34-42 11-16} # middle-middle right (medium)
        {RANDOM_HERB 4  34-42 17-22} # lower- middle right (medium)
        {RANDOM_HERB 5  37-45 23-25} # bottom right corner (hard)

        {RANDOM_HERB 6   6-11 11-15} # near the mountains (hard)
        {RANDOM_HERB 7   8-18 15-24} # near the dunefolk (easy)

        {RANDOM_HERB 8  28-33 17-22} # southeast of Gweddry (easy)
        {RANDOM_HERB 9  33-35  8-11} # northeast of Gweddry (easy)
        {RANDOM_HERB 10 18-29  1-3 } # north of Gweddry (medium)
        {RANDOM_HERB 11 18-29  5-8 } # north of Gweddry (medium)
    [/event]

    #------------------
    # HAHID DIES
    #------------------
    [event]
        name=last breath
        [filter]
            id=Hahid al-Ali
        [/filter]

        [message]
            speaker=Hahid al-Ali
            message=_ "Alas, my long, storied, and exceedingly profitable career has come to an end! Perhaps Safyam was right about the dangers of this place..."
        [/message]
        {KILL (id=Hahid al-Ali) ANIMATE=yes}
        [message] # Safyam may be dead here
            speaker=Safyam
            message=_ "My master has perished! It has been too many years since any of us have seen our homeland; we will return to mourn his passing."
        [/message]
        [fire_event]
            name=dunefolk_leave
        [/fire_event]
    [/event]

#define OPTION_FULL
    [option]
        label= _ "Give Hahid $gold_cost gold; assault the undead fortress. <i>(challenging)</i>"
        [command]
            [fire_event]
                name=give_full_gold
            [/fire_event]
        [/command]
    [/option]
#enddef
#define OPTION_NONE
    [option]
        label= _ "Give Hahid nothing; return westward towards Wesnoth. <i>(normal)</i>"
        [command]
            [fire_event]
                name=give_no_gold
            [/fire_event]
        [/command]
    [/option]
#enddef
#define OPTION_EXTRA
    [option]
        label= _ "Give Hahid $gold_extra gold."
        [command]
            [fire_event]
                name=give_extra_gold
            [/fire_event]
        [/command]
    [/option]
#enddef

    #------------------
    # HERBS ALL COLLECTED
    #------------------
    # this event only triggers if Hahid is still alive
    [event]
        name=herbs_collected
        [message]
            speaker=Hahid al-Ali
            message= _ "Ho ho, that’s all the herbs I need! Now if you’ll give me those $gold_cost gold pieces you promised, I’d be happy to point you in the direction of that undead fortress."
        [/message]
        [message]
            speaker=Dacyn
            #po: speaking to Gweddry, although the previous message was spoken by Hahid
            message= _ "Even if we do manage to find them, how do you expect us to defeat the undead in the very heart of their territory? I have already told you that this foe is far beyond anything we can face alone. Confronting this menace with the few soldiers we have would be foolish."
        [/message]
        [message]
            speaker=Gweddry
            message=
            {OPTION_FULL}
            {OPTION_NONE}
            {OPTION_EXTRA}
        [/message]
    [/event]

    #------------------
    # GIVE HAHID FULL
    #------------------
    [event]
        name=give_full_gold
        first_time_only=no
        [store_gold]
            side=1
        [/store_gold]
        [if]
            [variable]
                name=gold
                less_than=$gold_cost
            [/variable]

            # not enough gold
            [then]
                [message]
                    speaker=Hahid al-Ali
                    message= _ "I’m afraid you don’t have the $gold_cost gold to pay for my information, so I must be off. Best of luck with that ‘Mal-Skraat’ you’re fighting!"
                [/message]
                [fire_event]
                    name=dunefolk_leave
                [/fire_event]
            [/then]
            # enough gold
            [else]
                [gold]
                    side=1
                    amount=-50
                [/gold]
                [sound]
                    name=gold.ogg
                [/sound]

                {MODIFY_UNIT (id=Hahid al-Ali) side 4}
                {MODIFY_UNIT (id=Safyam) side 4}
                [message]
                    speaker=Gweddry
                    #po: to Dacyn
                    message= _ "If the threat is as grave as you say, I believe we must take advantage of our position behind the undead lines. Even outnumbered, we may still be able to disrupt their plans and cause some mischief within their city."
                [/message]
                [message]
                    speaker=Dacyn
                    message= _ "...so the great Gweddry intends to do what all of Wesnoth cannot. Very well. I cannot return to Wesnoth on my own, so it seems I have little choice but to join you in your folly."
                [/message]
                {VARIABLE fork_04c yes}
                [endlevel]
                    result=victory
                    bonus=yes
                    next_scenario=04c_Mal-Ravanals_Capital
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/else]
        [/if]
    [/event]

    #------------------
    # GIVE HAHID NONE
    #------------------
    [event]
        name=give_no_gold
        first_time_only=no
        [message]
            speaker=Gweddry
            message= _ "I heed Dacyn’s advice on this. Our armies are not strong enough to travel east."
        [/message]
        [message]
            speaker=Hahid al-Ali
            message= _ "Suit yourself! Now that I have what I need, it’s high time my friends and I returned to the Ashland."
        [/message]
        [fire_event]
            name=dunefolk_leave
        [/fire_event]
        [modify_turns]
            add=10
        [/modify_turns]
    [/event]

    #------------------
    # GIVE HAHID EXTRA
    #------------------
    [event]
        name=give_extra_gold
        first_time_only=no
        [store_gold]
            side=1
        [/store_gold]
        [if]
            [variable]
                name=gold
                less_than=$gold_extra
            [/variable]

            # not enough gold
            [then]
                [message]
                    speaker=Hahid al-Ali
                    #po: offering Hahid extra gold, but not having enough gold
                    message= _ "Ho ho, very funny, for a moment I thought you meant it! But really now, do you want my information or not?"
                [/message]
                [message]
                    speaker=Gweddry
                    message=
                    {OPTION_FULL}
                    {OPTION_NONE}
                [/message]
            [/then]
            # enough gold
            [else]
                [gold]
                    side=1
                    amount=-150
                [/gold]
                [sound]
                    name=gold.ogg
                [/sound]

                [message]
                    speaker=Hahid al-Ali
                    #po: offering Hahid extra gold
                    message= _ "What the-? You’re serious!? Well, forget herbalism, I need to find out more about this mystical land where men pay thrice what they owe!"
                [/message]
                [message]
                    speaker=Hahid al-Ali
                    message= _ "Friends, come, let us join these ‘Wesnothians’ and travel west towards the rest of their kind!"
                [/message]
                [message]
                    speaker=Gweddry
                    message= _ "What about journeying east towards the undead fortress?"
                [/message]
                [message]
                    speaker=Hahid al-Ali
                    message= _ "Oh please, I knew you wouldn’t fall for that! I just wanted something to keep those skeletons busy while we left."
                [/message]
                [set_achievement]
                    content_for=eastern_invasion
                    id=ei_S04b
                [/set_achievement]

                {MODIFY_UNIT side=4 side 1}
                [delay]
                    time=1000
                [/delay]

                [modify_turns]
                    add=10
                [/modify_turns]
                [message]
                    speaker=narrator
                    image=wesnoth-icon.png
                    message= _ "(The Dunefolk have joined you! You must now defeat Mal-Skraat and travel west. 10 turns have been added to the limit.)"
                [/message]
                [show_objectives]
                [/show_objectives]
            [/else]
        [/if]
    [/event]

    [event]
        name=dunefolk_leave
        {MODIFY_UNIT (id=Hahid al-Ali) side 4}
        {MODIFY_UNIT (id=Safyam) side 4}

        {MOVE_UNIT (id=Hahid al-Ali) 2 25}  {KILL (id=Hahid al-Ali)}
        {MOVE_UNIT (id=Safyam)       2 25}  {KILL (id=Safyam)}
        {MOVE_UNIT (id=Ikriaf)       2 25}  {KILL (id=Ikriaf)}
        {MOVE_UNIT (id=Ragnabair)    2 25}  {KILL (id=Ragnabair)}
        {MOVE_UNIT (id=Abman)        2 25}  {KILL (id=Abman)}
        {MOVE_UNIT (id=Nur al-Nuh)   2 25}  {KILL (id=Nur al-Nuh)}
        {MOVE_UNIT (id=Muma)         2 25}  {KILL (id=Muma)}
        [redraw]
            clear_shroud=yes
        [/redraw]
        [message]
            speaker=Gweddry
            message=_ "The dunefolk are leaving and without their aid we have no chance of even finding the undead capital. We must defeat Mal-Skraat and proceed westward."
        [/message]
        [show_objectives]
        [/show_objectives]
    [/event]

    #------------------
    # MAL-SKRAAT DIES
    #------------------
    [event]
        name=last breath
        [filter]
            id=Mal-Skraat
        [/filter]

        [message]
            speaker=Mal-Skraat
            message=_ "No, it can’t end like this! My sister has died unavenged..."
        [/message]
        {KILL id=Mal-Skraat ANIMATE=yes}
        [message]
            speaker=Dacyn
            message= _ "Good, now we should be able to reach what’s left of the northern outpost."
        [/message]
        [if]
            {VARIABLE_CONDITIONAL herbs_needed greater_than 0}
            [then]
                {MODIFY_UNIT (id=Hahid al-Ali) side 4}
                {MODIFY_UNIT (id=Safyam) side 4}
                [message]
                    speaker=Hahid al-Ali
                    message= _ "Thanks for nothing! What happened to helping me gather my herbs?"
                [/message]
            [/then]
        [/if]

        {VARIABLE skraat_dead yes}
        {VARIABLE fork_04c no}
        [endlevel]
            result=victory
            bonus=yes
            next_scenario=05_Northern_Outpost
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

    [event]
        name=victory
        # because for some reason this doesn't get cleared when the objects are removed,
        # even back when I had it as part of the object and not a separate effect
        [modify_unit]
            [filter]
                side=1
            [/filter]

            [status]
                unpoisonable=no
            [/status]
        [/modify_unit]

        {CLEAR_VARIABLE gold,gold_cost,herbs_needed,herb_locations}
    [/event]

    [event]
        name=time over
        [message]
            speaker=Gweddry
            message= _ "...urhggg, I don’t feel so good..."
        [/message]
        {MODIFY_UNIT id=Gweddry status.poisoned yes}
        [sound]
            name=poison.ogg
        [/sound]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Dacyn
            message= _ "The swamp’s vapors are overwhelming us... despite our precautions..."
        [/message]
        {MODIFY_UNIT id=Dacyn status.poisoned yes}
        [sound]
            name=poison.ogg
        [/sound]

        [delay]
            time=1000
        [/delay]

        {KILL id=Dacyn ANIMATE=yes}
        [delay]
            time=1000
        [/delay]

        {KILL id=Gweddry ANIMATE=yes}
        [delay]
            time=1000
        [/delay]
    [/event]

    {FOREIGN_DEFEAT}

    {HERODEATH_GWEDDRY}
    {HERODEATH_DACYN}
[/scenario]

#undef SPAWN_ON_TURN
