# The file contains useful macros I use within the campaign

#create a loop that runs X times
#define LOOP VAR
[set_variable]
name={VAR}
multiply=-1
[/set_variable]

[while]
	[variable]
	name={VAR}
	less_than=0
	[/variable]
	[do]
#enddef

# used to add images/items to hexes
#define PUT_IMG IMG X Y
	[item]
		x={X}
		y={Y}
		image={IMG}
	[/item]
#enddef

# create a unit with full upkeep
#define UNIT_ TYPE DESC USERDESC SIDE X Y
	[unit]
		type={TYPE}
		description={DESC}
		user_description={USERDESC}
		side={SIDE}
		upkeep=full
		x={X}
		y={Y}
	[/unit]
#enddef

# create a unit with no upkeep
#define FREE_UNIT TYPE DESC USERDESC SIDE X Y
	[unit]
		type={TYPE}
		description={DESC}
		user_description={USERDESC}
		side={SIDE}
		upkeep=free
		x={X}
		y={Y}
	[/unit]
#enddef

# create a unit with full upkeep and random traits

#define UNIT_T TYPE DESC USERDESC SIDE X Y
[unit]
	side={SIDE}
	type={TYPE}
	description={DESC}
	user_description={USERDESC}
	upkeep=full
	x={X}
	y={Y}
	random_traits="yes"
[/unit]
#enddef


# UNIT_OVERLAY adds an overlay to a unit, taking in a standard filter
#
# Example that gives all spearmen a book:
# {UNIT_OVERLAY type=Spearman items/book1.png}

#define UNIT_OVERLAY FILTER IMG
    [store_unit]
        [filter]
            {FILTER}
        [/filter]
        variable=UNIT_OVERLAY_store
        kill=no
    [/store_unit]
    {FOREACH UNIT_OVERLAY_store UNIT_OVERLAY_i}
	{VARIABLE_OP UNIT_OVERLAY_tempx format
$UNIT_OVERLAY_store[$UNIT_OVERLAY_i].x}
	{VARIABLE_OP UNIT_OVERLAY_tempy format
$UNIT_OVERLAY_store[$UNIT_OVERLAY_i].y}
        [unit_overlay]
            x=$UNIT_OVERLAY_tempx
            y=$UNIT_OVERLAY_tempy
		image={IMG}
        [/unit_overlay]
    {NEXT UNIT_OVERLAY_i}
    {CLEAR_VARIABLE UNIT_OVERLAY_store}
#enddef

#define REMOVE_UNIT_OVERLAY FILTER IMG
    [store_unit]
        [filter]
            {FILTER}
        [/filter]
        variable=UNIT_OVERLAY_store
        kill=no
    [/store_unit]
    {FOREACH UNIT_OVERLAY_store UNIT_OVERLAY_i}
	{VARIABLE_OP UNIT_OVERLAY_tempx format
$UNIT_OVERLAY_store[$UNIT_OVERLAY_i].x}
	{VARIABLE_OP UNIT_OVERLAY_tempy format
$UNIT_OVERLAY_store[$UNIT_OVERLAY_i].y}
        [remove_unit_overlay]
            x=$UNIT_OVERLAY_tempx
            y=$UNIT_OVERLAY_tempy
		image={IMG}
        [/remove_unit_overlay]
    {NEXT UNIT_OVERLAY_i}
    {CLEAR_VARIABLE UNIT_OVERLAY_store}
#enddef

