#textdomain wesnoth-utbs
# The file contains useful macros I use within the campaign

#define RANDOM_PLACEMENT_AREA X Y RADIUS
    # set a placement area for subsequent random placement of units
    [store_locations]
        x,y={X},{Y}
        radius={RADIUS}
        variable=random_placement_locations
    [/store_locations]
#enddef

#define PLACE_UNITS_RANDOMLY NUMBER SIDE TYPE ROLE_STRING NAME_STRING TRAIT_WML
    {VARIABLE i 0}
    [while]
        [variable]
            name=i
            less_than={NUMBER}
        [/variable]
        [do]
            {RANDOM "0..$($random_placement_locations.length - 1)"}
            {VARIABLE random_placement_x $random_placement_locations[$random].x}
            {VARIABLE random_placement_y $random_placement_locations[$random].y}

            [unit]
                side={SIDE}
                type={TYPE}
                x=$random_placement_x
                y=$random_placement_y
                role={ROLE_STRING}
                name={NAME_STRING}
                animate=yes
                {TRAIT_WML}
            [/unit]
            {VARIABLE_OP i add 1}
        [/do]
    [/while]
#enddef

#define CLEAR_PLACEMENT_AREA
    {CLEAR_VARIABLE random_placement_x}
    {CLEAR_VARIABLE random_placement_y}
    {CLEAR_VARIABLE random_placement_locations}
#enddef

# The amount of extra recruit cost is kept in $recruit_cost_extra; when this
# macro is called for the first time, it'll disallow recruitment of
# "Desert Fighter" and then allow recruitment of "Desert FighterX". The second
# call then disallows recruitment of "Desert FighterY" and allows recruitment of
# "Desert Fighter(X+Y)", and so on. After $recruit_cost_extra has reached 10,
# nothing will happen anymore.

#define INCREASE_RECRUIT_COSTS X
    {VARIABLE num $recruit_cost_extra}
    {VARIABLE_OP recruit_cost_extra add {X}}
    [if]
        [variable]
            name=recruit_cost_extra
            greater_than=10
        [/variable]
        [then]
            {VARIABLE recruit_cost_extra 10}
        [/then]
    [/if]

    #{DEBUG_MSG "disallowing: Desert Fighter$num,Desert Archer$num,Desert Hunter$num,Desert Shaman$num,Desert Scout$num"}
    [disallow_recruit]
        type=Desert Fighter$num,Desert Archer$num,Desert Hunter$num,Desert Shaman$num,Desert Scout$num
        side=1
    [/disallow_recruit]

    {VARIABLE num $recruit_cost_extra}
    #{DEBUG_MSG "allowing: Desert Fighter$num,Desert Archer$num,Desert Hunter$num,Desert Shaman$num,Desert Scout$num"}
    [allow_recruit]
        type=Desert Fighter$num,Desert Archer$num,Desert Hunter$num,Desert Shaman$num,Desert Scout$num
        side=1
    [/allow_recruit]

    {CLEAR_VARIABLE num}
#enddef

#define UTBS_SHAKE_SCREEN
    [scroll]
        x=20
    [/scroll]
    [scroll]
        x=-20
    [/scroll]
    [scroll]
        x=20
    [/scroll]
    [scroll]
        x=-20
    [/scroll]
#enddef
