#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 MESSAGE
    [message]
        speaker={SPEAKER}
        message={MESSAGE}
    [/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

# Just like UNIT except use guardian ai special
#define GEN_GUARDIAN TYPE DESCRIPTION USER_DESCRIPTION SIDE X Y
    [unit]
        type={TYPE}
        description={DESCRIPTION}
        user_description={USER_DESCRIPTION}
        side={SIDE}
        x,y={X},{Y}
        [modifications]
            {TRAIT_LOYAL}
        [/modifications]
        ai_special=guardian
    [/unit]
#enddef

# Generates a normal unit except with the guardian attribute
#define GEN_GUARD TYPE SIDE X Y
    [unit]
        type={TYPE}
        side={SIDE}
        x={X}
        y={Y}
        generate_description=yes
        random_traits=yes
        upkeep=loyal
        animate=no
        ai_special=guardian
    [/unit]
#enddef

# Generate a unit with random name and random traits
#define GEN_UNIT TYPE SIDE X Y
    [unit]
        type={TYPE}
        side={SIDE}
        x={X}
        y={Y}
        generate_description=yes
        random_traits=yes
        upkeep=loyal
        animate=no
    [/unit]
#enddef

# Ice randomly breaks and kills the unit (0.25 probability).
# This event should filter out flying units, but doesn't yet.
#define IF_ICE_BREAKS ACTION_WML
    [set_variable]
        name=ice_random
        random=1,2,3,4
    [/set_variable]
    [if]
        [variable]
            name=ice_random
            numerical_equals=1
        [/variable]
        [then]
            {ACTION_WML}
            [terrain]
                terrain=Wo
                x,y=$x1,$y1
            [/terrain]
            [redraw]
                side=1
            [/redraw]
            [kill]
                x,y=$x1,$y1
                animate=yes
                fire_event=yes
            [/kill]
        [/then]
    [/if]
    {CLEAR_VARIABLE ice_random}
#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]
                            description=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

# Door-related terrain and macros ########################################
[terrain]
    symbol_image=flat/road
    id=door
    name=_ "Door"
    string=xx
    aliasof=Xu
    no_overlay=false
    recruit_onto=false
    recruit_from=false
[/terrain]
{TERRAIN_BASE xx flat/road}

# Place a door at DOOR_X, DOOR_Y, which is opened by moving a unit of side 1 to location X1,Y1 or X2,Y2.  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 X1 Y1 X2 Y2
    [terrain]
        x={DOOR_X}
        y={DOOR_Y}
        terrain=xx	# wmllint: ignore
    [/terrain]
    {PLACE_IMAGE (scenery/gate-rusty-{FACING}.png) {DOOR_X} {DOOR_Y}}
    [event]
        name=moveto
        first_time_only=yes
        [filter]
            side=1
            x={X1},{X2}
            y={Y1},{Y2}
        [/filter]
        # set new terrain at the door location
        [terrain]
            x={DOOR_X}
            y={DOOR_Y}
            terrain=Rr
        [/terrain]
        [removeitem]
            x={DOOR_X}
            y={DOOR_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
