#textdomain wesnoth-anl

# ------------------------------------------------------
# Automatic Studying
# ------------------------------------------------------

#define AUTO_STUDYING TYPES
    [event]
        name=side turn
        first_time_only=no

        [store_unit]
            [filter]
                type={TYPES}
                side=$side_number
                canrecruit=no
                [filter_location]
                    terrain="Gg^Ve,Gg^Vea"
                [/filter_location]
            [/filter]
            variable=researchers
            kill=no
        [/store_unit]

        [set_variable]
            name=sound
            value=no
        [/set_variable]

        {FOREACH researchers i}
            [set_variable]
                name=temp_x
                value=$researchers[$i].x
            [/set_variable]
            [set_variable]
                name=temp_y
                value=$researchers[$i].y
            [/set_variable]

            [set_variable]
                name=credited_side
                value=$researchers[$i].side
            [/set_variable]
            [set_variable]
                name=amount
                value=$researchers[$i].level
            [/set_variable]

            {ADDING_TO_CURRENT_RESEARCH_FIELD $credited_side| $amount}

            [set_variable]
                name=sound
                value=yes
            [/set_variable]

            [scroll_to]
                x,y=$temp_x,$temp_y
            [/scroll_to]

            [unstore_unit]
                variable=researchers[$i]
                text=$amount
                {COLOR_WHITE}
            [/unstore_unit]
        {NEXT i}

        [if]
            [variable]
                name=sound
                equals=yes
            [/variable]

            [then]
                [sound]
                    name=magic-holy-miss-3.ogg
                [/sound]

                [delay]
                    time=200
                [/delay]
            [/then]
        [/if]

        [clear_variable]
            name=sound,researchers,amount,credited_side
        [/clear_variable]

        [redraw]
        [/redraw]
    [/event]
#enddef

# ------------------------------------------------------
# Automatic Farming
# ------------------------------------------------------

#define AUTO_FARMING TYPES
    [event]
        name=side turn
        first_time_only=no

        [store_unit]
            [filter]
                type={TYPES}
                side=$side_number
                [filter_location]
                    terrain=Re^Gvs
                [/filter_location]
            [/filter]
            variable=harvesters
            kill=no
        [/store_unit]

        [store_unit]
            [filter]
                type={TYPES}
                side=$side_number
                [filter_location]
                    terrain=Re
                [/filter_location]
            [/filter]
            variable=planters
            kill=no
        [/store_unit]

        [set_variable]
            name=sound
            value=no
        [/set_variable]
        {FOREACH harvesters i}
            [set_variable]
                name=temp_x
                value=$harvesters[$i].x
            [/set_variable]
            [set_variable]
                name=temp_y
                value=$harvesters[$i].y
            [/set_variable]

            [set_variable]
                name=credited_side
                value=$harvesters[$i].side
            [/set_variable]
            [set_variable]
                name=amount
                value=$player_$credited_side|.farming.gold
            [/set_variable]

            # auto-harvest
            [gold]
                side=$credited_side
                amount=$amount
            [/gold]

            {MODIFY_TERRAIN "Re" $temp_x $temp_y}
            [remove_item]
                x,y=$temp_x,$temp_y
            [/remove_item]

            [set_variable]
                name=sound
                value=yes
            [/set_variable]

            [scroll_to]
                x,y=$temp_x,$temp_y
            [/scroll_to]

            [unstore_unit]
                variable=harvesters[$i]
                text=$amount
                red,green,blue=204,204,51
            [/unstore_unit]
        {NEXT i}

        [if]
            [variable]
                name=sound
                equals=yes
            [/variable]

            [then]
                [sound]
                    name=gold.ogg
                [/sound]

                [delay]
                    time=200
                [/delay]
            [/then]
        [/if]

        [set_variable]
            name=sound
            value=no
        [/set_variable]
        {FOREACH planters i}
            [set_variable]
                name=temp_x
                value=$planters[$i].x
            [/set_variable]
            [set_variable]
                name=temp_y
                value=$planters[$i].y
            [/set_variable]

            # auto-plant
            {MODIFY_TERRAIN "Re^Gvs" $temp_x $temp_y }

            [remove_item]
                x,y=$temp_x,$temp_y
            [/remove_item]
            [item]
                x,y=$temp_x,$temp_y
                image=items/flower4.png
            [/item]

            [set_variable]
                name=sound
                value=yes
            [/set_variable]

            [unstore_unit]
                variable=planters[$i]
            [/unstore_unit]
        {NEXT i}

        [if]
            [variable]
                name=sound
                equals=yes
            [/variable]

            [then]
                [sound]
                    name=entangle.wav
                [/sound]

                [delay]
                    time=200
                [/delay]
            [/then]
        [/if]

        [clear_variable]
            name=sound,harvesters,planters,amount,credited_side
        [/clear_variable]

        [redraw]
        [/redraw]
    [/event]
#enddef

# ------------------------------------------------------
# Automatic Mining
# ------------------------------------------------------

#define AUTO_MINING TYPES
    [event]
        name=side turn
        first_time_only=no

        [store_unit]
            [filter]
                type={TYPES}
                side="$side_number"
                [filter_location]
                    terrain=Hh^Vhh,Ha^Vhha,Mm^Vhh
                [/filter_location]
            [/filter]
            variable=miners
            kill=no
        [/store_unit]

        [set_variable]
            name=sound
            value=no
        [/set_variable]
        {FOREACH miners i}
            [set_variable]
                name=temp_x
                value=$miners[$i].x
            [/set_variable]
            [set_variable]
                name=temp_y
                value=$miners[$i].y
            [/set_variable]

            [set_variable]
                name=credited_side
                value=$miners[$i].side
            [/set_variable]
            [set_variable]
                name=amount
                value=$player_$credited_side|.mining.gold
            [/set_variable]

            # auto-mine
            [gold]
                side=$credited_side
                amount=$amount
            [/gold]

            [scroll_to]
                x,y=$temp_x,$temp_y
            [/scroll_to]

            [set_variable]
                name=sound
                value=yes
            [/set_variable]

            [unstore_unit]
                variable=miners[$i]
                text=$amount
                red,green,blue=204,204,51
            [/unstore_unit]
        {NEXT i}

        [if]
            [variable]
                name=sound
                equals=yes
            [/variable]

            [then]
                [sound]
                    name=gold.ogg
                [/sound]

                [delay]
                    time=200
                [/delay]
            [/then]
        [/if]

        [clear_variable]
            name=sound,miners,amount,credited_side
        [/clear_variable]

        [redraw]
        [/redraw]
    [/event]
#enddef
