#textdomain wesnoth-did
# New Macros

# Define starting villages
#define SET_VILLAGE SIDE X Y
    [capture_village]
        x={X}
        y={Y}
        side={SIDE}
    [/capture_village]
#enddef

# Shorthand for messages, useful for lots of short messages
#define SPEAK SPEAKER_STRING MESSAGE_TEXT
    [message]
        speaker={SPEAKER_STRING}
        message={MESSAGE_TEXT}
    [/message]
#enddef

# MODIFY_ONE_UNIT alters a unit variable for a single unit
# Warning: moving the unit will create a copy, since kill is set to no by necessity
#define MODIFY_ONE_UNIT FILTER NAME VALUE
    [store_unit]
        [filter]
            {FILTER}
        [/filter]
        variable=MODIFY_UNIT_store
        kill=no
    [/store_unit]
    [set_variable]
        name=MODIFY_UNIT_store[0].{NAME}
        value={VALUE}
    [/set_variable]
    [unstore_unit]
        variable=MODIFY_UNIT_store[0]
        find_vacant=no
    [/unstore_unit]
    {CLEAR_VARIABLE MODIFY_UNIT_store}
#enddef

# Create a new ghost-type "advisor" if Malin doesn't already have one
#define CREATE_ADVISOR
    [recall]
        # recall an advisor if one already exists
        role=advisor
    [/recall]
    [if]
        # check if that worked, if not make another unit the advisor
        [have_unit]
            role=advisor
        [/have_unit]
        [then]
            # do nothing
        [/then]
        [else]
            [role]
                role=advisor
                type=Spectre,Nightgaunt,Wraith,Shadow,Ghost
            [/role]
            [recall]
                role=advisor
            [/recall]
            [if]
                # If player has no such units on the recall list, make a new ghost
                [have_unit]
                    role=advisor
                [/have_unit]
                [then]
                    # do nothing
                [/then]
                [else]
                    [store_unit]
                        # store to get location
                        [filter]
                            id=Malin Keshar
                        [/filter]
                        kill=no
                        variable=tempStore
                    [/store_unit]
                    [unit]
                        type=Ghost
                        side=1
                        x=$tempStore.x
                        y=$tempStore.y
                        role=advisor
                    [/unit]
                    {CLEAR_VARIABLE tempStore}
                [/else]
            [/if]
        [/else]
    [/if]
#enddef

# Place a door at DOOR_X, DOOR_Y, which is opened by moving a unit of side 1
# next to it. FACING should be one of two values: "sw" OR "se", depending on
# which direction the door should face. This last selects which graphic to use.
# This macro must be used inside an [event]
#define PLACE_DOOR DOOR_X DOOR_Y FACING_STRING
    [terrain]
        x={DOOR_X}
        y={DOOR_Y}
        terrain=xx  # wmllint: ignore
    [/terrain]
    {PLACE_IMAGE (scenery/gate-rusty-{FACING_STRING}.png) {DOOR_X} {DOOR_Y}}
#enddef

# This allows the doors to be opened by moving next to them.
#define DOOR_OPENING_EVENT SIDES
    [event]
        name=moveto
        first_time_only=no

        [filter]
            side={SIDES}

            [filter_location]
                [filter_adjacent_location]
                    terrain=xx
                [/filter_adjacent_location]
            [/filter_location]
        [/filter]

        [store_locations]
            terrain=xx

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

            variable=door_to_open
        [/store_locations]

        [terrain]
            x,y=$door_to_open.x,$door_to_open.y
            terrain=Rr
        [/terrain]

        [removeitem]
            x,y=$door_to_open.x,$door_to_open.y
        [/removeitem]
    [/event]
#enddef

#define DELAY NUMBER
    [delay]
        time={NUMBER}
    [/delay]
#enddef

#define ALLOW_RECRUIT LIST_VALUE
    [allow_recruit]
        side=2
        type={LIST_VALUE}
    [/allow_recruit]
#enddef
