#textdomain wesnoth
# Utility macros for manipulating map terrain and overlays.

# These don't depend on any other macros.  Please don't change this.
# ! in comments is used in generating HTML documentation, ignore it otherwise.

#define MODIFY_TERRAIN TERRAIN X_SPAN Y_SPAN
    # Changes the terrain at a given list of coordinates
    #
    # For example, we could make 14,15 and 14,16 grassland:
    #! {MODIFY_TERRAIN Gg (14,14) (15,16)}
    [terrain]
        terrain={TERRAIN}
        x={X_SPAN}
        y={Y_SPAN}
    [/terrain]
#enddef

#define MODIFY_TERRAIN_MASK X Y MASK_VALUE RULES_WML
    # Changes the terrain for a given area
    [terrain_mask]
        x={X}
        y={Y}
        mask={MASK_VALUE}
        {RULES_WML}
    [/terrain_mask]
#enddef

#define SCATTER_IMAGE FILTER NUMBER IMAGE
    # Place NUMBER copies of the IMAGE on map hexes matching FILTER.
    # Does not check for collisions.
    #
    # This call will scatter 20 copies of a pine-tree graphic over grassland:
    #! {SCATTER_IMAGE (terrain=Gg) 20 scenery/pine1.png}
    [store_locations]
        {FILTER}
        variable=random_placement_locations
    [/store_locations]

    {VARIABLE_OP random_string format "0..$random_placement_locations.length"}

    {VARIABLE REPEAT_i 0}

    [while]
        [variable]
            name=REPEAT_i
            less_than={NUMBER}
        [/variable]

        [do]
            [set_variable]
                name=random_subscript
                rand=$random_string
            [/set_variable]

            {VARIABLE_OP random_placement_x format "$random_placement_locations[$random_subscript].x"}
            {VARIABLE_OP random_placement_y format "$random_placement_locations[$random_subscript].y"}

            [item]
                image={IMAGE}
                x,y=$random_placement_x,$random_placement_y
            [/item]

            {VARIABLE_OP REPEAT_i add 1}
        [/do]
    [/while]

    {CLEAR_VARIABLE REPEAT_i}
    {CLEAR_VARIABLE random_subscript}
    {CLEAR_VARIABLE random_placement_locations}
#enddef
