#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]

        {VARIABLE sound no}
        {FOREACH researchers i}
            {VARIABLE_OP temp_x format "$researchers[$i].x"}
            {VARIABLE_OP temp_y format "$researchers[$i].y"}

            {VARIABLE_OP credited_side format $researchers[$i].side}
            {VARIABLE_OP amount format $researchers.level}
            {ADDING_TO_CURRENT_RESEARCH_FIELD $credited_side| $amount}

            {VARIABLE sound yes}
            {SCROLL_TO $temp_x $temp_y}

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

        [if]
            {CONDITION sound equals yes}
            [then]
                {PLAY_SOUND ("magic-holy-miss-3.ogg")}
                {DELAY 200}
            [/then]
        [/if]

        {CLEAR_VARIABLE sound}
        {CLEAR_VARIABLE researchers}
        {CLEAR_VARIABLE amount}
        {CLEAR_VARIABLE credited_side}
        {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]

        {VARIABLE sound no}
        {FOREACH harvesters i}
            {VARIABLE_OP temp_x format "$harvesters[$i].x"}
            {VARIABLE_OP temp_y format "$harvesters[$i].y"}

            {VARIABLE_OP credited_side format $harvesters[$i].side}
            {VARIABLE_OP amount format $player_$credited_side|.farming.gold}

            # auto-harvest
            {ADD_GOLD $credited_side $amount}
            {MODIFY_TERRAIN "Re" $temp_x $temp_y}
            {REMOVE_ITEM $temp_x $temp_y}
            {VARIABLE sound yes}
            {SCROLL_TO $temp_x $temp_y}

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

        [if]
            {CONDITION sound equals yes}
            [then]
                {PLAY_SOUND ("gold.ogg")}
                {DELAY 200}
            [/then]
        [/if]

        {VARIABLE sound no}
        {FOREACH planters i}
            {VARIABLE_OP temp_x format "$planters[$i].x"}
            {VARIABLE_OP temp_y format "$planters[$i].y"}

            # auto-plant
            {MODIFY_TERRAIN "Re^Gvs" $temp_x $temp_y }
            {REMOVE_ITEM $temp_x $temp_y}
            {PLACE_IMAGE "items/flower4.png" $temp_x $temp_y}
            {VARIABLE sound yes}

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

        [if]
            {CONDITION sound equals yes}
            [then]
                {PLAY_SOUND ("entangle.wav")}
                {DELAY 200}
            [/then]
        [/if]

        {CLEAR_VARIABLE sound}
        {CLEAR_VARIABLE harvesters}
        {CLEAR_VARIABLE planters}
        {CLEAR_VARIABLE amount}
        {CLEAR_VARIABLE credited_side}

        {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]

        {VARIABLE sound no}
        {FOREACH miners i}
            {VARIABLE_OP temp_x format "$miners[$i].x"}
            {VARIABLE_OP temp_y format "$miners[$i].y"}

            {VARIABLE_OP credited_side format $miners[$i].side}
            {VARIABLE_OP amount format $player_$credited_side|.mining.gold}

            # auto-mine
            {ADD_GOLD $credited_side $amount}
            {SCROLL_TO $temp_x $temp_y}
            {VARIABLE sound yes}

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

        [if]
            {CONDITION sound equals yes}
            [then]
                {PLAY_SOUND ("gold.ogg")}
                {DELAY 200}
            [/then]
        [/if]

        {CLEAR_VARIABLE sound}
        {CLEAR_VARIABLE miners}
        {CLEAR_VARIABLE amount}
        {CLEAR_VARIABLE credited_side}

        {REDRAW}
    [/event]
#enddef
