#textdomain wesnoth-did
# New Macros

# Define starting villages
#define SET_VILLAGE SIDE X Y
[capture_village]
	x={X}
	y={Y}
	side={SIDE}
[/capture_village]
#enddef

# Shorthand for messages, useful for lots of short messages
#define SPEAK SPEAKER MESSAGE
[message]
	speaker={SPEAKER}
	message={MESSAGE}
[/message]
#enddef

# MODIFY_ONE_UNIT alters a unit variable for a single unit
# Warning: moving the unit will create a copy, since kill is set to no by necessity
#define MODIFY_ONE_UNIT FILTER VAR VALUE
[store_unit]
	[filter]
		{FILTER}
	[/filter]
	variable=MODIFY_UNIT_store
	kill=no
[/store_unit]
[set_variable]
	name=MODIFY_UNIT_store[0].{VAR}
	value={VALUE}
[/set_variable]
[unstore_unit]
	variable=MODIFY_UNIT_store[0]
	find_vacant=no
[/unstore_unit]
{CLEAR_VARIABLE MODIFY_UNIT_store}
#enddef

# Just like UNIT except use guardian ai special
#define GEN_GUARDIAN TYPE DESCRIPTION UDESCRIPTION SIDE X Y
[unit]
	type={TYPE}
	description={DESCRIPTION}
	user_description={UDESCRIPTION}
	side={SIDE}
	x,y={X},{Y}
	[modifications]
		{TRAIT_LOYAL}
	[/modifications]
	ai_special=guardian
[/unit]
#enddef

# Generates a normal unit except with the guardian attribute
#define GEN_GUARD TYPE SIDE X Y
[unit]
	type={TYPE}
	side={SIDE}
	x={X}
	y={Y}
	generate_description=yes
	random_traits=yes
	upkeep=loyal
	animate=no
	ai_special=guardian
[/unit]
#enddef

# Generate a unit with random name and random traits
#define GEN_UNIT TYPE SIDE X Y
[unit]
	type={TYPE}
	side={SIDE}
	x={X}
	y={Y}
	generate_description=yes
	random_traits=yes
	upkeep=loyal
	animate=no
[/unit]
#enddef

# Ice randomly breaks and kills the unit.  The event should filter out flying units
#define IF_ICE_BREAKS
[set_variable]
	name=ice_random
	random=1,2,3,4
[/set_variable]
[if]
	[variable]
		name=ice_random
		numerical_equals=1
	[/variable]
	[then]
#enddef

#define END_ICE_BREAKS
		[terrain]
			letter=Wo
			x,y=$x1,$y1
		[/terrain]
		[redraw]
			side=1
		[/redraw]
		[kill]
			x,y=$x1,$y1
			animate=yes
			fire_event=yes
		[/kill]
	[/then]
[/if]
{CLEAR_VARIABLE ice_random}
#enddef


# Create a new ghost-type "advisor" if Malin doesn't already have one
#define CREATE_ADVISOR
[recall]
	# recall an advisor if one already exists
	role=advisor
[/recall]
[if]
	# check if that worked, if not make another unit the advisor
	[have_unit]
		role=advisor
	[/have_unit]
	[then]
		# do nothing
	[/then]
	[else]
		[role]
			role=advisor
			type=Spectre,Nightgaunt,Wraith,Shadow,Ghost
		[/role]
		[recall]
			role=advisor
		[/recall]
		[if]
			# If player has no such units on the recall list, make a new ghost
			[have_unit]
				role=advisor
			[/have_unit]
			[then]
				# do nothing
			[/then]
			[else]
				[store_unit]
					# store to get location
					[filter]
						description=Malin Keshar
					[/filter]
					kill=no
					variable=tempStore
				[/store_unit]
				[unit]
					type=Ghost
					side=1
					x=$tempStore.x
					y=$tempStore.y
				[/unit]
				{CLEAR_VARIABLE tempStore}
			[/else]
		[/if]
	[/else]
[/if]
#enddef


# Door-related terrain and macros ########################################
[terrain]
	symbol_image=flat/road
	id=door
	name=_ "Door"
	string=xx
	aliasof=Xu
	no_overlay=false
	recruit_onto=false
	recruit_from=false
[/terrain]
{TERRAIN_BASE xx flat/road}

# Place a door at DOOR_X, DOOR_Y, which is opened by moving a unit of side 1 to location X1,Y1 or X2,Y2.  FACING should be one of two values: "nesw" OR "nwse", depending on which direction the door should face.  This last selects which graphic to use.
# This macro must be used inside an [event]
#define PLACE_DOOR DOOR_X DOOR_Y FACING X1 Y1 X2 Y2
[terrain]
	x={DOOR_X}
	y={DOOR_Y}
	letter=xx	# wmllint: ignore 
[/terrain]
{PLACE_IMAGE (misc/door_{FACING}.png) {DOOR_X} {DOOR_Y}}
[event]
	name=moveto
	first_time_only=yes
	[filter]
		side=1
		x={X1},{X2}
		y={Y1},{Y2}
	[/filter]
	# set new terrain at the door location
	[terrain]
		x={DOOR_X}
		y={DOOR_Y}
		letter=Rr
	[/terrain]
	[removeitem]
		x={DOOR_X}
		y={DOOR_Y}
	[/removeitem]
[/event]
#enddef

#define DELAY TIME
[delay]
	time={TIME}
[/delay]
#enddef

#define IF_UNIT_DEAD DESCRIPTION
[store_unit]
	variable=deathTest
	[filter]
		description={DESCRIPTION}
	[/filter]
	kill=no
[/store_unit]
[if]
	[variable]
		name=deathTest.hitpoints
		less_than_equal_to=0
	[/variable]
	[then]
#enddef

#define END_IF_DEAD
	[/then]
[/if]
{CLEAR_VARIABLE deathTest}
#enddef

#define IF_VAR VARIABLE VALUE
[if]
	[variable]
		name={VARIABLE}
		numerical_equals={VALUE}
	[/variable]
	[then]
#enddef

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

#define ALLOW_RECRUIT LIST
[allow_recruit]
	side=2
	type={LIST}
[/allow_recruit]
#enddef

