#textdomain wesnoth-did

#define GIVE_MALIN_EXPERIENCE EXP
    [store_unit]
        [filter]
            id=Malin Keshar
        [/filter]
        variable=malin
    [/store_unit]

    {VARIABLE experience_gained {EXP}}
    {VARIABLE_OP malin.experience add $experience_gained|}
    [floating_text]
        x,y=$malin.x,$malin.y
        text="<span color='#800080'>" + _ "+$experience_gained| exp" + "</span>"
    [/floating_text]
    {CLEAR_VARIABLE experience_gained}

    [unstore_unit]
        variable=malin
    [/unstore_unit]

    {CLEAR_VARIABLE malin}
#enddef

#define CLEAR_CORPSE_HORDE
    [kill]
        type=Walking Corpse
        [not]
            variation=drake,dwarf,goblin,gryphon,mounted,saurian,spider,swimmer,troll,wose,wolf,bat
        [/not]
        side=1
        [filter_wml]
            experience=0
        [/filter_wml]
    [/kill]
#enddef

# MODIFY_ONE_UNIT alters a unit variable for a single unit
#define MODIFY_ONE_UNIT FILTER WML
    [store_unit]
        [filter]
            {FILTER}
        [/filter]
        variable=MODIFY_UNIT_store
        kill=no
    [/store_unit]

    [modify_unit]
        [filter]
            id=$MODIFY_UNIT_store[0].id
        [/filter]
        {WML}
    [/modify_unit]

    {CLEAR_VARIABLE MODIFY_UNIT_store}
#enddef

# Create a new ghost-type "advisor" if Malin doesn't already have one
#define CREATE_ADVISOR
    [if]
        [have_unit]
            side=1
            role=advisor
            search_recall_list=yes
        [/have_unit]
        [then]
            # Recall an advisor if we have one
            [recall]
                role=advisor
            [/recall]
        [/then]
        [else]
            # Else, make a new advisor from a ghost unit
            [role]
                role=advisor
                side=1
                type=Eidolon,Phantom,Spectral Servant,Spectre,Nightgaunt,Wraith,Shadow,Ghost
                search_recall_list=yes
                [auto_recall][/auto_recall]
                [else]
                    # If that fails too, make a brand new ghost advisor
                    [unit]
                        type=Ghost
                        side=1
                        role=advisor
                        animate=yes
                        placement=leader
                    [/unit]
                [/else]
            [/role]
        [/else]
    [/if]
#enddef

#define MANOR_DOORS ALLOWED_SIDES
    # Triggers when moving next to any door terrain and will replace it
    # with an 'opened' variant.

    [event]
        name=moveto
        first_time_only=no

        [filter]
            side={ALLOWED_SIDES}

            [filter_location]
                [filter_adjacent_location]
                    terrain=*^Pr*
                [/filter_adjacent_location]
            [/filter_location]
            [not]
                [filter_location]
                    [filter_adjacent_location]
                        terrain=*^Pr/o,*^Pr\o,*^Pr|o
                    [/filter_adjacent_location]
                [/filter_location]
            [/not]
        [/filter]

        [store_locations]
            terrain=*^Pr*

            [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="$door_to_open.terrain|o" # Append 'o' to the terrain string to get open variant.
            layer=both
        [/terrain]

        [redraw]
            side=$unit.side
        [/redraw]

        {CLEAR_VARIABLE door_to_open}
    [/event]
#enddef

#define SET_GOT_INSIDE_MANOR
    {MODIFY_UNIT (
        side=1
        {NOT_ON_RECALL_LIST}
        [not]
            id=Malin Keshar

            [or]
                id=Darken Volk
            [/or]
        [/not]
    ) variables.got_inside_manor yes}
#enddef
