#textdomain wesnoth-sof
[scenario]
    name= _ "Gathering Materials"
    id=4_Gathering_Materials
    map_generation=lua
    next_scenario=4t_The_Jeweler

    [story]
        [part]
            story= _ "Those who had worked the eastern mines were brave indeed. The mines were often infested with trolls and other vile creatures, who thrived in the dark and gloom of the caves."
        [/part]
        [part]
            story= _ "And braver still were Rugnur and his companions, who had to visit those tunnels after years of abandonment."
        [/part]
    [/story]

    {SOF_TRACK {JOURNEY_04_NEW} }

    [generator]
        id="cavegen"
        config_name=_"Sceptre of Fire Mines"
        create_map = << return wesnoth.require("cave_map_generator").generate_map(...) >>

        map_width=45
        map_height=45
        village_density=60

        terrain_wall = "Xu"
        terrain_clear = "Uu"
        terrain_keep = "Kud"
        terrain_castle = "Cud"
        terrain_village = "Uu^Vud"

        #the chamber with the player. Near the south-west corner
        [chamber]
            id=player
            x=10-15
            y=32-38
            size=7
            jagged=40
            [item_location]
                id = 1
                place_castle = yes
            [/item_location]
        [/chamber]

        #the chamber with the coal. Somewhere in the southeast.
        [chamber]
            id=coal1
            x=28-35
            y=28-35
            size=8
            [passage]
                chance=70
                width=1
                windiness=5
                destination=gold
            [/passage]
            [passage]
                chance=50
                width=2
                windiness=5
                destination=coal2
            [/passage]
            [passage]
                chance=50
                width=2
                windiness=5
                destination=gold
            [/passage]
            [passage]
                chance=50
                width=2
                windiness=10
                destination=coal2
            [/passage]
            [item_location]
                id = 2
                place_castle = yes
            [/item_location]
        [/chamber]

        #the northern chamber with only bad guys. Somewhere in the north-east.
        [chamber]
            id=gold
            x=28-35
            y=5-12
            size=8
            jagged=50
            [passage]
                chance=100
                width=2
                windiness=10
                destination=coal1
            [/passage]
            [passage]
                chance=100
                width=2
                windiness=10
                destination=coal2
            [/passage]
            [passage]
                chance=50
                width=1
                windiness=5
                destination=coal1
            [/passage]
            [passage]
                chance=50
                width=1
                windiness=5
                destination=coal2
            [/passage]
            [item_location]
                id = 3
                place_castle = yes
            [/item_location]
        [/chamber]

        #chamber with the second coal mine. Somewhere in the north-west.
        [chamber]
            id=coal2
            x=8-12
            y=8-12
            size=7
            [passage]
                chance=70
                width=1
                windiness=5
                destination=gold
            [/passage]
            [passage]
                chance=50
                width=2
                windiness=5
                destination=coal1
            [/passage]
            [passage]
                chance=50
                width=2
                windiness=5
                destination=gold
            [/passage]
            [passage]
                chance=50
                width=1
                windiness=5
                destination=coal1
            [/passage]
            [item_location]
                id = 4
                place_castle = yes
            [/item_location]
        [/chamber]

        #chamber with gold in it that connects to all the others
        [chamber]
            id=connector
            x=15-20
            y=15-20
            size=4
            #passages to both the troll's chamber and the player’s chamber
            [passage]
                destination=player
                width=2
                windiness=10
            [/passage]
            [passage]
                destination=coal1
                width=2
                windiness=10
            [/passage]
            [passage]
                destination=coal2
                width=2
                windiness=10
            [/passage]
            [passage]
                destination=gold
                width=2
                windiness=10
            [/passage]
        [/chamber]

        [chamber]
            id=exit_tunnel
            x=1
            y=38-43
            size=2
            [passage]
                destination=player
                width=1
                windiness=10
            [/passage]
        [/chamber]
    [/generator]

    [side]
        type=Dwarvish Fighter
        id=Rugnur
        side=1
        canrecruit=yes
        recruit=Dwarvish Fighter,Dwarvish Thunderer,Dwarvish Guardsman,Dwarvish Scout,Dwarvish Miner
        controller=human
        shroud=yes
        {FLAG_VARIANT knalgan}
        team_name=dwarves
        user_team_name= _ "Dwarves"
        {GOLD 210 180 150}
    [/side]
    # these AI sides were set to not be on the same side. Assuming that is intentional, let's give them a little distinction and variety
    [side]
#ifdef HARD
        type="Troll Warrior"
#else
        type="Troll"
#endif
        side=2
        canrecruit=yes
        controller=ai
        [ai]
            leader_value=2
            village_value=0.2
            recruitment_pattern=fighter,fighter,mixed fighter

            [goal]
                name=target
                [criteria]
                    side=1
                [/criteria]
                value=2
            [/goal]
        [/ai]
        recruit=Troll Whelp,Young Ogre,Troll Rocklobber
        team_name=trolls1
        user_team_name=_"Resident Trolls"
        {GOLD 90 120 150}
        {INCOME 2 3 4}
    [/side]
    [side]
#ifdef HARD
        type="Troll Warrior"
#else
        type="Troll"
#endif
        side=3
        canrecruit=yes
        controller=ai
        [ai]
            leader_value=2
            village_value=0.2
            recruitment_pattern=fighter

            [goal]
                name=target
                [criteria]
                    side=1
                [/criteria]
                value=2
            [/goal]
        [/ai]
        recruit=Troll Whelp,Young Ogre,Ogre
        team_name=trolls2
        user_team_name=_"Intruding Trolls"
        {GOLD 90 120 150}
        {INCOME 2 3 4}
    [/side]
    # Changing this leader to a rider goblin, because I don't know why a troll could recruit goblins...
    # If the troll does make sense, it can be changed back, but this way also brings some variety
    [side]
#ifdef HARD
        type="Direwolf Rider"
#else
        type="Goblin Pillager"
#endif
        side=4
        canrecruit=yes
        controller=ai
        [ai]
            leader_value=2
            village_value=0.2
            recruitment_pattern=fighter

            [goal]
                name=target
                [criteria]
                    side=1
                [/criteria]
                value=2.0
            [/goal]
        [/ai]
        recruit=Goblin Spearman,Goblin Rouser,Goblin Impaler
        team_name=trolls3
        user_team_name=_"Goblin Explorers"
        {GOLD 90 120 150}
        {INCOME 2 3 4}
    [/side]

    {TURNS 44 40 36}
    victory_when_enemies_defeated=no

    {SCENARIO_MUSIC underground.ogg}
    {EXTRA_SCENARIO_MUSIC suspense.ogg}

    {UNDERGROUND}

    {SOF_DEATHS}

    # wmllint: recognize Rugnur

    {STARTING_VILLAGES 1 5}
    {STARTING_VILLAGES 2 8}
    {STARTING_VILLAGES 3 8}
    {STARTING_VILLAGES 4 8}

    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Troll Rocklobber) 1}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 (Ogre) 1}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 (Goblin Rouser) 2}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 (Goblin Impaler) 2}

    {SOF_RUNIC_EVENTS}

    [event]
        name=prestart

        # Alanin and Krawg are taking a break
        # wmllint: recognize Alanin
        # wmllint: recognize Krawg

        [store_unit]
            [filter]
                id=Alanin
            [/filter]

            variable=alanin
            kill=yes
        [/store_unit]
        [store_unit]
            [filter]
                id=Krawg
            [/filter]

            variable=krawg
            kill=yes
        [/store_unit]

        [store_locations]
            [and]
                [filter]
                    side=1
                    canrecruit=yes
                [/filter]

                radius=1

                [filter_radius]
                    terrain=X*
                [/filter_radius]
            [/and]

            [not]
                [filter]
                    side=1
                    canrecruit=yes
                [/filter]
            [/not]

            variable=adjacent_cavewall
        [/store_locations]

        [foreach]
            array=adjacent_cavewall
            [do]
                [terrain]
                    x,y=$this_item.x,$this_item.y
                    terrain=Uu
                [/terrain]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE adjacent_cavewall}

        [store_locations]
            [filter]
                side=1
                canrecruit=yes
            [/filter]

            radius=4

            [filter_radius]
                terrain=Cud,Kud
            [/filter_radius]

            variable=resource_return_locations
        [/store_locations]

        # Here we overlay a mask containing a rather random pattern of
        # suitable terrains on the map, because the map generator itself
        # only places the very basic terrains (floor, walls, etc)
        # also, include tracks overlay in mask

        [terrain_mask]
            x,y=1,1
            mask="{campaigns/Sceptre_of_Fire/maps/4_Gathering_Materials-random.mask}"

            [rule]
                old=Uu
                new=Uu^Ii,Uu^Tf,Tb^Tf,Uh,Ww,Cud
            [/rule]

            [rule]
                old=Xu
                new=*^Br\
                terrain=Uh^Br\
            [/rule]

            [rule]
                old=Xu
                new=*^Br|
                terrain=Uh^Br|
            [/rule]

            [rule]
                old=Xu
                new=*^Br/
                terrain=Uh^Br/
            [/rule]

            [rule]
                old=Xu,Cud,Kud
                use_old=yes
            [/rule]

            [rule]
                new=*^Br\
                use_old=no
                layer=both
                replace_if_failed=yes
                terrain=Uu^Br\
            [/rule]

            [rule]
                new=*^Br|
                use_old=no
                layer=both
                replace_if_failed=yes
                terrain=Uu^Br|
            [/rule]

            [rule]
                new=*^Br/
                use_old=no
                layer=both
                replace_if_failed=yes
                terrain=Uu^Br/
            [/rule]
        [/terrain_mask]

        # Here we need to randomize the coal and gold locations by
        # hand, because the map generator can otherwise sometimes place
        # them inside cavewall.

        # The first coal pile is somewhere near where side 2 starts

        [store_locations]
            [filter]
                side=2
                canrecruit=yes
            [/filter]

            radius=5

            [filter_radius]
                terrain=!,Xu,Qxu,*^V*
            [/filter_radius]

            variable=possible_coal_1_locations
        [/store_locations]

        [store_locations]
            find_in=possible_coal_1_locations
            [not]
                terrain=Kud,Cud,Re,*^Br*
            [/not]
            variable=possible_coal_1_locations
        [/store_locations]

        {RANDOM 1..$possible_coal_1_locations.length}
        {VARIABLE_OP random sub 1}

        {VARIABLE coal_1.x $possible_coal_1_locations[$random].x}
        {VARIABLE coal_1.y $possible_coal_1_locations[$random].y}

        # The second coal pile is somewhere near where side 4 starts

        [store_locations]
            [filter]
                side=4
                canrecruit=yes
            [/filter]

            radius=5

            [filter_radius]
                terrain=!,Xu,Qxu,*^V*
            [/filter_radius]

            variable=possible_coal_2_locations
        [/store_locations]

        [store_locations]
            find_in=possible_coal_2_locations
            [not]
                terrain=Kud,Cud,Re,*^Br*
            [/not]
            variable=possible_coal_2_locations
        [/store_locations]

        {RANDOM 1..$possible_coal_2_locations.length}
        {VARIABLE_OP random sub 1}

        {VARIABLE coal_2.x $possible_coal_2_locations[$random].x}
        {VARIABLE coal_2.y $possible_coal_2_locations[$random].y}

        # And the gold pile is 8-12 hexes away from where side 3 starts

        [store_locations]
            [and]
                [filter]
                    side=3
                    canrecruit=yes
                [/filter]

                radius=12

                [filter_radius]
                    terrain=!,Xu,Qxu,*^V*
                [/filter_radius]
            [/and]

            [not]
                [filter]
                    side=3
                    canrecruit=yes
                [/filter]

                radius=8

                # Not sure if this is really needed
                [filter_radius]
                    terrain=!,Xu,Qxu,*^V*
                [/filter_radius]
            [/not]

            variable=possible_gold_locations
        [/store_locations]

        [store_locations]
            find_in=possible_gold_locations
            [not]
                terrain=Kud,Cud,Re,*^Br*
            [/not]
            variable=possible_gold_locations
        [/store_locations]

        {RANDOM 1..$possible_gold_locations.length}
        {VARIABLE_OP random sub 1}

        {VARIABLE gold_1.x $possible_gold_locations[$random].x}
        {VARIABLE gold_1.y $possible_gold_locations[$random].y}

        [item]
            image=items/gold.png
            x,y=$gold_1.x,$gold_1.y
        [/item]

        [item]
            image=items/coal.png
            x,y=$coal_1.x,$coal_1.y
        [/item]

        [item]
            image=items/coal.png
            x,y=$coal_2.x,$coal_2.y
        [/item]

        {VARIABLE coalin 0}
        {VARIABLE goldin 0}

        {CLEAR_VARIABLE possible_coal_1_locations}
        {CLEAR_VARIABLE possible_coal_2_locations}
        {CLEAR_VARIABLE possible_gold_locations}

        # one cart near the player, another cart randomly further out
        # can probably be better optimized
        [store_locations]
            terrain=*^Br*
            [and]
                [filter]
                    side=1
                    canrecruit=yes
                [/filter]
                radius=7
            [/and]

            variable=possible_cart1_locations
        [/store_locations]

        [store_locations]
            [and]
                terrain=*^Br*
            [/and]

            [not]
                [filter]
                    side=1
                    canrecruit=yes
                [/filter]

                radius=15
            [/not]

            variable=possible_cart2_locations
        [/store_locations]

        {RANDOM 1..$possible_cart1_locations.length}
        {VARIABLE_OP random sub 1}

        {VARIABLE cart_1.x $possible_cart1_locations[$random].x}
        {VARIABLE cart_1.y $possible_cart1_locations[$random].y}

        {RANDOM 1..$possible_cart2_locations.length}
        {VARIABLE_OP random sub 1}

        {VARIABLE cart_2.x $possible_cart2_locations[$random].x}
        {VARIABLE cart_2.y $possible_cart2_locations[$random].y}

        {SOF_MINECART_MENU cart1 $cart_1.x| $cart_1.y|}
        {SOF_MINECART_MENU cart2 $cart_2.x| $cart_2.y|}

        {CLEAR_VARIABLE possible_cart1_locations}
        {CLEAR_VARIABLE possible_cart2_locations}

        [objectives]
            side=1
            [objective]
                description= _ "Bring 1 load of gold and 2 loads of coal to the starting castle"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Rugnur"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Thursagan"
                condition=lose
            [/objective]
            [note]
                description= _ "Dwarvish Miners can pick up and carry gold and coal."
            [/note]

            {RUNE_MECHANIC_NOTE}

            {TURNS_RUN_OUT}

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

        #Add Map Labels for coal and gold.
        [label]
            x,y=$coal_1.x,$coal_1.y
            text= _ "Coal"
        [/label]
        [label]
            x,y=$coal_2.x,$coal_2.y
            text= _ "Coal"
        [/label]
        [label]
            x,y=$gold_1.x,$gold_1.y
            text= _ "Gold"
        [/label]
    [/event]

    [event]
        name=start
        [recall]
            id=Baglur
        [/recall]
        [recall]
            id=Thursagan
        [/recall]
        [recall]
            id=Kinan
        [/recall]
        [recall]
            id=Rynan
        [/recall]
        [message]
            speaker=Rugnur
            message= _ "Well, these are the eastern mines. Trolls and ogres live here, be prepared to fight them; also, be prepared to spend quite some time here — mining can take a while."
        [/message]
        [message]
            speaker=Thursagan
            message= _ "For me to make the artifact Haldric wants, I need a special type of gold. I know not exactly where it can be found, but Baglur said these mines were the source of it."
        [/message]
        [message]
            speaker=Baglur
            message= _ "Also, the only coal that wi’ melt this gold is here."
        [/message]
        [message]
            speaker=Rugnur
            message= _ "So we’re down here to, what, mine this gold and coal? That should be easy enough."
        [/message]
        [message]
            speaker=Thursagan
            message= _ "Yes, although we will have to hire the miners — they don’t work for free. But beware, there are trolls and such down here..."
        [/message]
    [/event]

    # This reminder will be triggered either on the third turn, or when the
    # player is running out of gold for recruitment, whichever happens first.
    # The message will only be displayed once, because it's first_time_only=yes.
    [event]
        name=reminder_to_recruit_miners

        [filter_condition]
            [not]
                [have_unit]
                    type=Dwarvish Miner
                [/have_unit]
            [/not]
        [/filter_condition]

        [message]
            speaker=Thursagan
            message= _ "Don’t forget to recruit the miners. Our warriors can clear the tunnels of trolls and worse, but once we find the gold and coal we need the miners to acquire it."
        [/message]
    [/event]

    [event]
        name=turn 3

        [fire_event]
            name=reminder_to_recruit_miners
        [/fire_event]
    [/event]
    [event]
        name=recruit,recall
        first_time_only=no

        [filter]
            side=1
        [/filter]

        [store_gold]
            side=1
            variable=money_for_recruitment
        [/store_gold]
        [if]
            [variable]
                name=money_for_recruitment
                less_than=65
                # Two miners cost 38, the most expensive recruit is 24, and
                # upkeep will cost a bit, hence warn around about 65.
            [/variable]
            [then]
                [fire_event]
                    name=reminder_to_recruit_miners
                [/fire_event]
            [/then]
        [/if]
        {CLEAR_VARIABLE money_for_recruitment}
        [allow_undo][/allow_undo]
    [/event]

    [event]
        name=moveto

        [filter]
            x,y=$coal_1.x,$coal_1.y

            [or]
                x,y=$coal_2.x,$coal_2.y
            [/or]

            [and]
                side=1

                [not]
                    type=Dwarvish Miner
                [/not]
            [/and]
        [/filter]

        [message]
            speaker=unit
            message= _ "Here is some of the coal that we need! Send a miner here to take it!"
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    [event]
        name=moveto

        [filter]
            x,y=$coal_1.x,$coal_1.y
            side=1
            type=Dwarvish Miner

            [not]
                status=has_coal
            [/not]

            [not]
                status=has_gold
            [/not]
        [/filter]

        [message]
            speaker=unit
            message= _ "I have all the coal I can carry..."
        [/message]
        {VARIABLE unit.status.has_coal yes}
        [unstore_unit]
            variable=unit
            find_vacant=no
        [/unstore_unit]
        [unit_overlay]
            x,y=$x1,$y1
            image=misc/coal-icon.png
            object_id="coal_icon"
        [/unit_overlay]
        [remove_item]
            x,y=$x1,$y1
        [/remove_item]
        {REMOVE_LABEL $coal_1.x $coal_1.y}
        {VARIABLE coal_1.x 0}
        {VARIABLE coal_1.y 0}
    [/event]

    [event]
        name=moveto

        [filter]
            x,y=$coal_2.x,$coal_2.y
            side=1
            type=Dwarvish Miner

            [not]
                status=has_coal
            [/not]

            [not]
                status=has_gold
            [/not]
        [/filter]

        [message]
            speaker=unit
            message= _ "I have all the coal I can carry..."
        [/message]
        {VARIABLE unit.status.has_coal yes}
        [unstore_unit]
            variable=unit
            find_vacant=no
        [/unstore_unit]
        [unit_overlay]
            x,y=$x1,$y1
            image=misc/coal-icon.png
            object_id="coal_icon"
        [/unit_overlay]
        [remove_item]
            x,y=$x1,$y1
        [/remove_item]
        {REMOVE_LABEL $coal_2.x $coal_2.y}
        {VARIABLE coal_2.x 0}
        {VARIABLE coal_2.y 0}
    [/event]

    [event]
        name=moveto

        [filter]
            x,y=$gold_1.x,$gold_1.y
            side=1

            [not]
                type=Dwarvish Miner
            [/not]
        [/filter]

        [message]
            speaker=unit
            message= _ "Here is the mine of precious gold! Send a miner here to take it!"
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    [event]
        name=moveto

        [filter]
            x,y=$gold_1.x,$gold_1.y
            side=1
            type=Dwarvish Miner

            [not]
                status=has_coal
            [/not]

            [not]
                status=has_gold
            [/not]
        [/filter]

        [message]
            speaker=unit
            message= _ "I have all the gold I can carry..."
        [/message]
        {VARIABLE unit.status.has_gold yes}
        [unstore_unit]
            variable=unit
            find_vacant=no
        [/unstore_unit]
        [unit_overlay]
            x,y=$x1,$y1
            image=misc/gold-icon.png
            object_id="gold_icon"
        [/unit_overlay]
        [remove_item]
            x,y=$x1,$y1
        [/remove_item]
        {REMOVE_LABEL $gold_1.x $gold_1.y}
        {VARIABLE gold_1.x 0}
        {VARIABLE gold_1.y 0}
    [/event]

    # If a miner carrying coal dies, we let others pick it up

    [event]
        name=die
        first_time_only=no

        [filter]
            side=1
            type=Dwarvish Miner
            status=has_coal
        [/filter]

        [item]
            x,y=$x1,$y1
            image=items/coal.png
        [/item]

        {VARIABLE hex_$x1|_$y1|_coal yes}
    [/event]

    [event]
        name=moveto
        first_time_only=no

        [filter]
            side=1
            type=Dwarvish Miner

            [not]
                status=has_coal
            [/not]

            [not]
                status=has_gold
            [/not]
        [/filter]

        [if]
            [variable]
                name=hex_$x1|_$y1|_coal
                equals=yes
            [/variable]

            [then]
                [message]
                    speaker=unit
                    message= _ "I have all the coal I can carry..."
                [/message]

                {VARIABLE unit.status.has_coal yes}

                [unstore_unit]
                    variable=unit
                    find_vacant=no
                [/unstore_unit]

                [unit_overlay]
                    x,y=$x1,$y1
                    image=misc/coal-icon.png
                    object_id="coal_icon"
                [/unit_overlay]

                [remove_item]
                    x,y=$x1,$y1
                [/remove_item]

                {CLEAR_VARIABLE hex_$x1|_$y1|_coal}
            [/then]

            [else]
                [allow_undo][/allow_undo]
            [/else]
        [/if]
    [/event]

    # Exactly same as above, but for gold

    [event]
        name=die
        first_time_only=no

        [filter]
            side=1
            type=Dwarvish Miner
            status=has_gold
        [/filter]

        [item]
            x,y=$x1,$y1
            image=items/gold.png
        [/item]

        {VARIABLE hex_$x1|_$y1|_gold yes}
    [/event]

    [event]
        name=moveto
        first_time_only=no

        [filter]
            side=1
            type=Dwarvish Miner

            [not]
                status=has_coal
            [/not]

            [not]
                status=has_gold
            [/not]
        [/filter]

        [if]
            [variable]
                name=hex_$x1|_$y1|_gold
                equals=yes
            [/variable]

            [then]
                [message]
                    speaker=unit
                    message= _ "I have all the gold I can carry..."
                [/message]

                {VARIABLE unit.status.has_gold yes}

                [unstore_unit]
                    variable=unit
                    find_vacant=no
                [/unstore_unit]

                [unit_overlay]
                    x,y=$x1,$y1
                    image=misc/gold-icon.png
                    object_id="gold_icon"
                [/unit_overlay]

                [remove_item]
                    x,y=$x1,$y1
                [/remove_item]

                {CLEAR_VARIABLE hex_$x1|_$y1|_gold}
            [/then]

            [else]
                [allow_undo][/allow_undo]
            [/else]
        [/if]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            type=Dwarvish Miner
            status=has_coal

            [filter_location]
                find_in=resource_return_locations
            [/filter_location]
        [/filter]
        [message]
            speaker=unit
            message= _ "My load of coal is delivered!"
        [/message]

        {VARIABLE unit.status.has_coal no}

        [unstore_unit]
            variable=unit
            find_vacant=no
        [/unstore_unit]

        [remove_object]
            x,y=$x1,$y1
            object_id="coal_icon"
        [/remove_object]

        [set_variable]
            name=coalin
            add=1
        [/set_variable]

        [if]
            [variable]
                name=coalin
                greater_than_equal_to=2
            [/variable]
            [then]
                [message]
                    speaker=unit
                    message= _ "That’s the last load of coal we need."
                [/message]
                [if]
                    [variable]
                        name=goldin
                        greater_than_equal_to=1
                    [/variable]
                    [then]
                        [message]
                            speaker=Thursagan
                            message= _ "This is all we need from these mines. Now we should go back further west, where there are no trolls and ogres, and mine there."
                        [/message]

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

    [event]
        name=moveto
        first_time_only=no
        [filter]
            type=Dwarvish Miner
            status=has_gold

            [filter_location]
                find_in=resource_return_locations
            [/filter_location]
        [/filter]
        [message]
            speaker=unit
            message= _ "Here’s the gold."
        [/message]

        {VARIABLE unit.status.has_gold no}

        [unstore_unit]
            variable=unit
            find_vacant=no
        [/unstore_unit]

        [remove_object]
            x,y=$x1,$y1
            object_id="gold_icon"
        [/remove_object]

        [set_variable]
            name=goldin
            add=1
        [/set_variable]

        [if]
            [variable]
                name=goldin
                greater_than_equal_to=1
            [/variable]
            [then]
                [if]
                    [variable]
                        name=coalin
                        greater_than_equal_to=2
                    [/variable]
                    [then]
                        [message]
                            speaker=Thursagan
                            message= _ "This is all we need from these mines. Now we should go back further west, where there are no trolls and ogres, and mine there."
                        [/message]

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

    [event]
        name=victory

        [unstore_unit]
            variable=alanin
        [/unstore_unit]

        [unstore_unit]
            variable=krawg
        [/unstore_unit]

        {SOF_CLEAR_RUNE_VARS 1}

        {CLEAR_VARIABLE alanin}
        {CLEAR_VARIABLE krawg}

        {CLEAR_VARIABLE coalin}
        {CLEAR_VARIABLE goldin}
        {CLEAR_VARIABLE coal_1}
        {CLEAR_VARIABLE coal_2}
        {CLEAR_VARIABLE gold_1}
        {CLEAR_VARIABLE cart1}
        {CLEAR_VARIABLE cart2}
        {CLEAR_VARIABLE resource_return_locations}

        [kill]
            type=Dwarvish Miner
        [/kill]

        [disallow_recruit]
            side=1
            type=Dwarvish Miner
        [/disallow_recruit]
    [/event]
[/scenario]
