# I'm putting The South Guard's common balancing macros in here.
# This should make my WML a little more sane.  Most of these
# I've shamlessly pillaged from The Rise of Wesnoth, The Useful WML Fragments Wiki,
# and the generous advice of the collected fora.

#define CUSTOM_SG_FLAG
	flag=flag/SGflag-1.png:200,flag/SGflag-2.png:125,flag/SGflag-3.png:400,flag/SGflag-2.png:200
#enddef

#define DOT X Y
[image]
x,y={X},{Y}
file=misc/dot.png
delay=500
[/image]
#enddef

#define CROSS X Y
[image]
x,y={X},{Y}
file=misc/cross.png
delay=500
[/image]
#enddef

#define SG_IF VAR
	[if]
		[variable]
			name={VAR}
			equals=true
		[/variable]
	[then]
#enddef

#define SG_END_IF
	[/then]
	[/if]
#enddef


#define SG_CHANGE_TERRAIN X Y LETTER
	[terrain]
		x={X}
		y={Y}
		letter={LETTER}
	[/terrain]
#enddef

#define PUT_IMG IMG X Y
	[item]
		x={X}
		y={Y}
		image={IMG}
	[/item]
#enddef

#define MOVE_EXISTING_UNIT FILTER X Y
{_MOVE_EXISTING_UNIT ({FILTER}) ({X}) ({Y}) ( )}
#enddef

#This is in case you need to make another unit type to display moving.
#For example, if the movement has to go through deep water or cavewall,
#you could make a unit whose id was the original's with "Fake " at the beginning,
#which would have a [movement costs] tag with cavewall=1.  Skirmisher ability is also useful to give here.
#HINT: undeadfly movetype takes only 1 move through anything except cavewall.
#define MOVE_EXISTING_UNIT_WITH_FAKE_VERSION FILTER X Y
{_MOVE_EXISTING_UNIT ({FILTER}) ({X}) ({Y}) ([set_variable]
name=mover_type
format="Fake $mover_type"
[/set_variable])}
#enddef

#don't use this directly, unless you really need to
#define _MOVE_EXISTING_UNIT FILTER X Y EXTRA_COMMANDS
        [store_unit]
                [filter]
                {FILTER}
                [/filter]
        variable=mover_store
        [/store_unit]
        {VARIABLE_OP temp_x1 to_variable mover_store.x}
        {VARIABLE_OP temp_y1 to_variable mover_store.y}
        #if it's really a unit on the map, never mind whether it has HP<=0
        #(in which case [have_unit] wouldn't detect it)
        [if]
        [variable]
        name=temp_x1
        greater_than=0
        [/variable]
        [variable]
        name=temp_y1
        greater_than=0
        [/variable]
                [then]
                #kill the original
                [kill]
                x=$temp_x1
                y=$temp_y1
                [/kill]
                [unit]
                type=Invisible
                x={X}
                y={Y}
                side=1
                role=temp_location_tester
                [/unit]
                [store_unit]
                        [filter]
                        role=temp_location_tester
                        [/filter]
                kill=yes
                variable=temp_store
                [/store_unit]
                {VARIABLE_OP temp_x2 to_variable temp_store.x}
                {VARIABLE_OP temp_y2 to_variable temp_store.y}
                {VARIABLE_OP mover_store.x to_variable temp_x2}
                {VARIABLE_OP mover_store.y to_variable temp_y2}
                #make it face the right direction
                #this may be unnecessary/bad; I don't think it's totally reliable
                #if a unit goes a long way around
                [if]
                [variable]
                name=temp_x1
                greater_than=$temp_x2
                [/variable]
                        [then]
                        {VARIABLE mover_store.facing reverse}
                        [/then]
                [/if]
                [if]
                [variable]
                name=temp_x2
                greater_than=$temp_x1
                [/variable]
                        [then]
                        {VARIABLE mover_store.facing normal}
                        [/then]
                [/if]
                #don't move to the same place!
                #it would go one hex away and back
                [if]
                [or]
                [variable]
                name=temp_x1
                not_equals=$temp_x2
                [/variable]
                [/or]
                [or]
                [variable]
                name=temp_y1
                not_equals=$temp_y2
                [/variable]
                [/or]
                        [then]
                        {VARIABLE_OP mover_type to_variable mover_store.type}
                        {VARIABLE_OP mover_side to_variable mover_store.side}
                        {VARIABLE_OP mover_gender to_variable mover_store.side}
                        {VARIABLE_OP movement_x format (|$temp_x1|,$temp_x2)}
                        {VARIABLE_OP movement_y format (|$temp_y1|,$temp_y2)}
                        {EXTRA_COMMANDS}
                        [move_unit_fake]
                                type=$mover_type
                                side=$mover_side
                                gender=$mover_gender
                                x=$movement_x
                                y=$movement_y
                        [/move_unit_fake]
                        [unstore_unit]
                        variable=mover_store
                        [/unstore_unit]
                        [redraw]
                        [/redraw]
                        {CLEAR_VARIABLE mover_type}
                        {CLEAR_VARIABLE mover_side}
                        {CLEAR_VARIABLE mover_gender}
                        {CLEAR_VARIABLE movement_y}
                        {CLEAR_VARIABLE movement_x}
                        [/then]
                        [else]
                        [unstore_unit]
                        variable=mover_store
                        [/unstore_unit]
                        [redraw]
                        [/redraw]
                        [/else]
                [/if]
                {CLEAR_VARIABLE temp_x2}
                {CLEAR_VARIABLE temp_y2}
                {CLEAR_VARIABLE temp_store}
                [/then]
        [/if]
        {CLEAR_VARIABLE temp_x1}
        {CLEAR_VARIABLE temp_y1}
        {CLEAR_VARIABLE mover_store}
 #enddef
