#textdomain wesnoth-anl

#define COMPLETE_ACTION GOLD_NUMBER
    [set_variable]
        name=finished
        value=yes
    [/set_variable]

    [set_variable]
        name=unit.status.worked_this_turn
        value=yes
    [/set_variable]
    [set_variable]
        name=unit.moves
        value=0
    [/set_variable]

    [unstore_unit]
        variable=unit
    [/unstore_unit]

    [gold]
        amount={GOLD_NUMBER}
        side=$side_number
    [/gold]
#enddef

#define ANL_SHOW_IF TYPE TERRAINLIST
    [show_if]
        [have_unit]
            side=$side_number
            x,y=$x1,$y1
            type={TYPE}
            [filter_location]
                terrain={TERRAINLIST}
            [/filter_location]
        [/have_unit]
    [/show_if]
#enddef

#define SET_NAMES SIDE
    [if]
        [have_unit]
            side={SIDE}
            canrecruit=yes
        [/have_unit]
        [then]
            [store_unit]
                [filter]
                    side={SIDE}
                    canrecruit=yes
                [/filter]
                variable=leader
            [/store_unit]

            [set_variable]
                name=player_{SIDE}.name
                value=$leader.name
            [/set_variable]

            [unstore_unit]
                variable=leader
            [/unstore_unit]
        [/then]
    [/if]
#enddef

#define SET_SIDE_VARIABLES SIDE
    [set_variables]
        name=player_{SIDE}

        [value]
            [farming]
                progress=0
                target=4
                gold=3
            [/farming]

            [mining]
                progress=0
                target=5
                gold=4
            [/mining]

            [warfare]
                progress=0
                target=4
                troop_available=0
            [/warfare]

            troop_1=no
            troop_2=no
            troop_3=no
            troop_4=no
            troop_5=no
            troop_6=no
            troop_7=no
            troops=0

            [research]
                current_target=agriculture
                target_language_name= _ "agriculture" # wmllint: ignore
            [/research]

            [leader_option_1]
                progress=0
                target=4
            [/leader_option_1]

            ally_1=no
            ally_2=no
            ally_3=no
            ally_4=no

            [leader_option_2]
                progress=0
                target=4
            [/leader_option_2]

            ally_5=no
            ally_6=no
            ally_7=no
            ally_8=no
        [/value]
    [/set_variables]
#enddef

#define PICK_RECRUIT_OPTION UNIT_IMAGE UNIT_TYPE_STRING UNIT_TYPE_NAME_STRING VAR
    [option]
        message={MENU_IMG_TXT {UNIT_IMAGE} {UNIT_TYPE_NAME_STRING}}
        [show_if]
            [variable]
                name=player_$side_number|.{VAR}
                equals=no
            [/variable]
        [/show_if]
        [command]
            [set_variable]
                name=player_$side_number|.{VAR}
                value=yes
            [/set_variable]

            [set_variable]
                name=player_$side_number|.troops
                add=1
            [/set_variable]

            [allow_recruit]
                type={UNIT_TYPE_STRING}
                side=$side_number
            [/allow_recruit]
        [/command]
    [/option]
#enddef

#define ADDING_TO_CURRENT_RESEARCH_FIELD SIDE NUMBER
    [switch]
        variable=player_{SIDE}.research.current_target
        [case]
            value="agriculture"

            [set_variable]
                name=player_{SIDE}.farming.progress
                add={NUMBER}
            [/set_variable]
        [/case]
        [case]
            value="mining"

            [set_variable]
                name=player_{SIDE}.mining.progress
                add={NUMBER}
            [/set_variable]
        [/case]
        [case]
            value="warfare"

            [set_variable]
                name=player_{SIDE}.warfare.progress
                add={NUMBER}
            [/set_variable]
        [/case]
    [/switch]
#enddef

#define ANL_RESCUE_TRAPPED_UNIT MOVETO_X MOVETO_Y UNIT_X UNIT_Y
    [event]
        name=moveto
        [filter]
            side=1,2,3,4
            x={MOVETO_X}
            y={MOVETO_Y}
        [/filter]

        [message]
            speaker=unit
            message= _ "Let’s cut you free!"
        [/message]
        [message]
            speaker=narrator
            message= _ "You release the creature from the web and it agrees to help you."
            image=wesnoth-icon.png
        [/message]

        [store_unit]
            [filter]
                x={UNIT_X}
                y={UNIT_Y}
            [/filter]
            variable=critter
            kill=no
        [/store_unit]

        [set_variable]
            name=critter.side
            value=$side_number
        [/set_variable]
        [clear_variable]
            name=critter.overlays
        [/clear_variable]

        [unstore_unit]
            variable=critter
        [/unstore_unit]
    [/event]
#enddef

#define ANL_PLACE_UNIT SIDE TYPE X Y
    [unit]
        side={SIDE}
        type={TYPE}
        generate_name=yes
        ai_special=guardian
        random_traits=no
        x={X}
        y={Y}
    [/unit]
#enddef

#define ANL_PLACE_GUARDIAN SIDE TYPE X Y
    [unit]
        side={SIDE}
        type={TYPE}
        generate_name=yes
        ai_special=guardian
        random_traits=no
        role=guardian
        x={X}
        y={Y}
        [modifications]
            [object]
                silent=yes
                duration=forever
                [effect]
                    apply_to=movement_costs
                    replace=true
                    [movement_costs]
                        flat={UNREACHABLE}
                        sand={UNREACHABLE}
                        shallow_water={UNREACHABLE}
                    [/movement_costs]
                [/effect]
            [/object]
        [/modifications]
    [/unit]
#enddef

#define ANL_PLACE_WOUNDED_UNIT SIDE TYPE X Y HITPOINTS_AMOUNT
    [unit]
        side={SIDE}
        type={TYPE}
        generate_name=yes
        hitpoints={HITPOINTS_AMOUNT}
        ai_special=guardian
        random_traits=no
        x={X}
        y={Y}
    [/unit]
#enddef

#define ANL_PLACE_TRAPPED_UNIT SIDE TYPE X Y
    [unit]
        side={SIDE}
        type={TYPE}
        generate_name=yes
        ai_special=guardian
        random_traits=no
        overlays=projectiles/web.png
        x={X}
        y={Y}
    [/unit]
#enddef

#define BUILD_SOUND_1
    [sound]
        name=miss-1.ogg
    [/sound]
    [delay]
        time=120
    [/delay]
    [sound]
        name=bite.ogg
    [/sound]
    [delay]
        time=220
    [/delay]
    [sound]
        name=dart.wav
    [/sound]
    [delay]
        time=180
    [/delay]
    [sound]
        name=dart.wav
    [/sound]
#enddef

#define BUILD_SOUND_2
    [sound]
        name=staff.wav
    [/sound]
    [delay]
        time=100
    [/delay]
    [sound]
        name=pincers.ogg
    [/sound]
    [delay]
        time=160
    [/delay]
    [sound]
        name=sling.ogg
    [/sound]
#enddef

#define BUILD_SOUND_3
    [sound]
        name=bite.ogg
    [/sound]
    [delay]
        time=280
    [/delay]
    [sound]
        name=staff.wav
    [/sound]
    [delay]
        time=100
    [/delay]
    [sound]
        name=dart.wav
    [/sound]
    [delay]
        name=180
    [/delay]
    [sound]
        name=dart.wav
    [/sound]
#enddef
