# Macros for setting animations.

# These don't rely on any other macros.   Please don't change this.

#define DEFENSE_ANIM REACTION BASEFRAME HITSOUND
# Define a defensive animation moving from a specified BASEFRAME
# to REACTION, with HITSOUND playing only if a hit occurs.
    [defend]
    start_time=-126
        [frame]
            duration=1
            image={BASEFRAME}
        [/frame]
        [frame]
            duration=100
            image={REACTION}
        [/frame]
        [if]
            hits=hit
            [frame]
                duration=150
                image={REACTION}
                sound={HITSOUND}
            [/frame]
        [/if]
        [else]
            hits=miss,kill
            [frame]
                duration=150
                image={REACTION}
            [/frame]
        [/else]
        [frame]
            duration=1
            image={BASEFRAME}
        [/frame]
    [/defend]
#enddef


#define DEFENSE_ANIM_FILTERED REACTION BASEFRAME HITSOUND FILTER
# Define a defensive animation moving from a specified BASEFRAME
# to REACTION, with HITSOUND playing only if a hit occurs.  This
# fires only if FILTER is matched.
    [defend]
    start_time=-126
        {FILTER}
        [frame]
            duration=1
            image={BASEFRAME}
        [/frame]
        [frame]
            duration=100
            image={REACTION}
        [/frame]
        [if]
            hits=hit
            [frame]
                duration=150
                image={REACTION}
                sound={HITSOUND}
            [/frame]
        [/if]
        [else]
            hits=miss,kill
            [frame]
                duration=150
                image={REACTION}
            [/frame]
        [/else]
        [frame]
            duration=1
            image={BASEFRAME}
        [/frame]
    [/defend]
#enddef


#define DEFENSE_ANIM_RANGE REACTION BASEFRAME HITSOUND RANGE
# Define a defensive animation moving from a specified BASEFRAME
# to REACTION, with HITSOUND playing only if a hit occurs.  This
# fires only on the class of attacks specified by RANGE.
    [defend]
    start_time=-126
        [attack_filter]
        range={RANGE}
        [/attack_filter]
        [frame]
            duration=1
            image={BASEFRAME}
        [/frame]
        [frame]
            duration=100
            image={REACTION}
        [/frame]
        [if]
            hits=hit
            [frame]
                duration=150
                image={REACTION}
                sound={HITSOUND}
            [/frame]
        [/if]
        [else]
            hits=miss,kill
            [frame]
                duration=150
                image={REACTION}
            [/frame]
        [/else]
        [frame]
            duration=1
            image={BASEFRAME}
        [/frame]
    [/defend]
#enddef


#define DEFENSE_ANIM_ELVEN_FILTERED REACTION BASEFRAME HITSOUND FILTER
# Define a defensive animation moving from a specified BASEFRAME
# to REACTION, with HITSOUND playing only if a hit occurs and an
# elven halo waxing and waning during the animation.  This fires
# only if FILTER is matched.
	[defend]
		{FILTER}
		[frame]
			begin=-175
			end=-150
			image={BASEFRAME}
			halo=halo/elven/elven-shield-halo-20pct.png
		[/frame]
		[frame]
			begin=-150
			end=-125
			image={BASEFRAME}
			halo=halo/elven/elven-shield-halo-40pct.png
		[/frame]
		[frame]
			begin=-125
			end=-75
			image={REACTION}
			halo=halo/elven/elven-shield-halo-60pct.png
		[/frame]
		[frame]
			begin=-75
			end=-25
			image={REACTION}
			halo=halo/elven/elven-shield-halo-80pct.png
		[/frame]
		[if]
			hits=hit
			[frame]
				begin=-25
				end=75
				image={REACTION}
				sound={HITSOUND}
				halo=halo/elven/elven-shield-halo-100pct.png
			[/frame]
		[/if]
		[else]
			hits=miss,kill
			[frame]
				begin=-25
				end=75
				image={REACTION}
				halo=halo/elven/elven-shield-halo-100pct.png
			[/frame]
		[/else]
		[frame]
			begin=75
			end=125
			image={REACTION}
			halo=halo/elven/elven-shield-halo-80pct.png
		[/frame]
		[frame]
			begin=125
			end=150
			image={BASEFRAME}
			halo=halo/elven/elven-shield-halo-60pct.png
		[/frame]
		[frame]
			begin=150
			end=175
			image={BASEFRAME}
			halo=halo/elven/elven-shield-halo-40pct.png
		[/frame]
		[frame]
			begin=175
			end=200
			image={BASEFRAME}
			halo=halo/elven/elven-shield-halo-20pct.png
		[/frame]
	[/defend]
#enddef

# this macro is called on top of every idle animation,
# to provide a standard set of conditions to play the idle animation

#define STANDARD_IDLE_FILTER
# Poisoned units should have no idle animation.  This macro defines a
# filter that excludes them.
[unit_filter]
	[not]
		[wml_filter]
			[status]
				poisoned="yes"
			[/status]
		[/wml_filter]
	[/not]
[/unit_filter]
#enddef

#define FRAME_ON_SLOW CONTENTS
# When a unit is slowed, the slowed sound (slowed.wav) should be
# played by the attack animation. Wrap the [frame] containing
# the sound= key inside this macro, and the sound will not get
# played if the attack misses or the target already is slowed.
	[if]
	    hits=yes
		[secondary_unit_filter]
			[not]
				[wml_filter]
					[status]
						slowed="yes"
					[/status]
				[/wml_filter]
			[/not]
		[/secondary_unit_filter]

		{CONTENTS}
	[/if]
	[else]
		hits=yes
		[secondary_unit_filter]
			[wml_filter]
				[status]
					slowed="yes"
				[/status]
			[/wml_filter]
		[/secondary_unit_filter]

		{CONTENTS}

		[+frame]
			sound=
		[/frame]
	[/else]
	[else]
		hits=no

		{CONTENTS}

		[+frame]
			sound=
		[/frame]
	[/else]
#enddef

#define FRAME_ON_POISON CONTENTS
# When a unit is poisoned, the poison sound (poison.ogg) should
# be played by the attack animation. Wrap the [frame] containing
# the sound= key inside this macro, and the sound will not get
# played if the attack misses or the target already is poisoned.
	[if]
	    hits=yes
		[secondary_unit_filter]
			[not]
				[wml_filter]
					[status]
						poisoned="yes"
					[/status]
				[/wml_filter]
			[/not]
		[/secondary_unit_filter]

		{CONTENTS}
	[/if]
	[else]
		hits=yes
		[secondary_unit_filter]
			[wml_filter]
				[status]
					poisoned="yes"
				[/status]
			[/wml_filter]
		[/secondary_unit_filter]

		{CONTENTS}

		[+frame]
			sound=
		[/frame]
	[/else]
	[else]
		hits=no

		{CONTENTS}

		[+frame]
			sound=
		[/frame]
	[/else]
#enddef

#define HIT_MISS_SOUNDS HITSOUND MISSSOUND CONTENTS
# A more convenient way of wiring in hit and miss sounds to an
# attack animation. Use by wrapping a [frame] inside this macro.
# Then, if the attack misses, HITSOUND will be played and if it
# misses, MISSSOUND will be played instead.
	[if]
	    hits=yes

		{CONTENTS}

		[+frame]
			sound={HITSOUND}
		[/frame]
	[/if]
	[else]
		hits=no

		{CONTENTS}

		[+frame]
			sound={MISSSOUND}
		[/frame]
	[/else]
#enddef

#define MISSILE_FRAME_WAIL
# Animate a projectile for a wail attack.
    [if]
        direction=n,ne,nw

        [missile_frame]
            begin=-300
            end=-230
            image="projectiles/wailprojectile-n-1.png"
            image_diagonal="projectiles/wailprojectile-ne-1.png"
        [/missile_frame]
        [missile_frame]
            begin=-230
            end=-160
            image="projectiles/wailprojectile-n-2.png"
            image_diagonal="projectiles/wailprojectile-ne-2.png"
        [/missile_frame]
        [missile_frame]
            begin=-160
            end=0
            image="projectiles/wailprojectile-n-3.png"
            image_diagonal="projectiles/wailprojectile-ne-3.png"
        [/missile_frame]
        [missile_frame]
            begin=0
            end=40
            image="projectiles/wailprojectile-n-4.png"
            image_diagonal="projectiles/wailprojectile-ne-4.png"
        [/missile_frame]
        [missile_frame]
            begin=40
            end=80
            image="projectiles/wailprojectile-n-5.png"
            image_diagonal="projectiles/wailprojectile-ne-5.png"
        [/missile_frame]
        [missile_frame]
            begin=80
            end=120
            image="projectiles/wailprojectile-n-6.png"
            image_diagonal="projectiles/wailprojectile-ne-6.png"
        [/missile_frame]
    [/if]
    [else]
        direction=s,se,sw
    ### The price of asymmetrical projectiles - here, we use a conditional because the game automatically flips the images for the south frame.  We have a separate set of images for the south part, which are not only flipped vertically, but also have their angle corrected for the sw direction.

        [missile_frame]
            begin=-300
            end=-230
            image="projectiles/wailprojectile-s-1.png"
            image_diagonal="projectiles/wailprojectile-se-1.png"
        [/missile_frame]
        [missile_frame]
            begin=-230
            end=-160
            image="projectiles/wailprojectile-s-2.png"
            image_diagonal="projectiles/wailprojectile-se-2.png"
        [/missile_frame]
        [missile_frame]
            begin=-160
            end=0
            image="projectiles/wailprojectile-s-3.png"
            image_diagonal="projectiles/wailprojectile-se-3.png"
        [/missile_frame]
        [missile_frame]
            begin=0
            end=40
            image="projectiles/wailprojectile-s-4.png"
            image_diagonal="projectiles/wailprojectile-se-4.png"
        [/missile_frame]
        [missile_frame]
            begin=40
            end=80
            image="projectiles/wailprojectile-s-5.png"
            image_diagonal="projectiles/wailprojectile-se-5.png"
        [/missile_frame]
        [missile_frame]
            begin=80
            end=120
            image="projectiles/wailprojectile-s-6.png"
            image_diagonal="projectiles/wailprojectile-se-6.png"
        [/missile_frame]
    [/else]
#enddef

#define MISSILE_FRAME_FIRE_BREATH N_OFFSET S_OFFSET N_DIAGONAL_OFFSET S_DIAGONAL_OFFSET
# Animate a projectile for a fire-breath attack.
    [if]
        direction=n

        [missile_frame]
            begin=-400
            end=100
            halo=projectiles/fire-breath-n-1.png:80,projectiles/fire-breath-n-2.png:80,projectiles/fire-breath-n-3.png:80,projectiles/fire-breath-n-4.png:80,projectiles/fire-breath-n-5.png:80
            halo_x,halo_y={N_OFFSET}
        [/missile_frame]
    [/if]
    [else]
        direction=s

        [missile_frame]
            begin=-400
            end=100
            halo=projectiles/fire-breath-s-1.png:80,projectiles/fire-breath-s-2.png:80,projectiles/fire-breath-s-3.png:80,projectiles/fire-breath-s-4.png:80,projectiles/fire-breath-s-5.png:80
            halo_x,halo_y={S_OFFSET}
        [/missile_frame]
    [/else]
    [else]
        direction=ne,nw

        [missile_frame]
            begin=-400
            end=100
            halo=projectiles/fire-breath-ne-1.png:80,projectiles/fire-breath-ne-2.png:80,projectiles/fire-breath-ne-3.png:80,projectiles/fire-breath-ne-4.png:80,projectiles/fire-breath-ne-5.png:80
            halo_x,halo_y={N_DIAGONAL_OFFSET}
        [/missile_frame]
    [/else]
    [else]
        direction=se,sw

        [missile_frame]
            begin=-400
            end=100
            halo=projectiles/fire-breath-se-1.png:80,projectiles/fire-breath-se-2.png:80,projectiles/fire-breath-se-3.png:80,projectiles/fire-breath-se-4.png:80,projectiles/fire-breath-se-5.png:80
            halo_x,halo_y={S_DIAGONAL_OFFSET}
        [/missile_frame]
    [/else]
#enddef

#define MISSILE_FRAME_FAERIE_FIRE
# Animate a projectile for a faerie-fire attack.
    [missile_frame]
        begin=-500
        end=-350
        image="projectiles/icemissile-n-1.png"
        image_diagonal="projectiles/icemissile-ne-1.png"
        halo=halo/elven/ice-halo1.png:100,halo/elven/ice-halo2.png:100,halo/elven/ice-halo3.png:25
        halo_x,halo_y=0,0
    [/missile_frame]
    [missile_frame]
        begin=-350
        end=-200
        image="projectiles/icemissile-n-2.png"
        image_diagonal="projectiles/icemissile-ne-2.png"
        halo=halo/elven/ice-halo3.png:75,halo/elven/ice-halo4.png:75
        halo_x,halo_y=0,0
    [/missile_frame]
    [missile_frame]
        begin=-200
        end=-50
        image="projectiles/icemissile-n-3.png"
        image_diagonal="projectiles/icemissile-ne-3.png"
        halo=halo/elven/ice-halo5.png:100,halo/elven/ice-halo1.png:100,halo/elven/ice-halo2.png:50
        halo_x,halo_y=0,0
    [/missile_frame]
    [missile_frame]
        begin=-50
        end=0
        image="projectiles/icemissile-n-4.png"
        image_diagonal="projectiles/icemissile-ne-4.png"
        halo=halo/elven/ice-halo6.png
        halo_x,halo_y=0,0
    [/missile_frame]
    [missile_frame]
        begin=25
        end=75
        image="projectiles/icemissile-n-5.png"
        image_diagonal="projectiles/icemissile-ne-5.png"
        halo=halo/elven/ice-halo7.png
        halo_x,halo_y=0,0
    [/missile_frame]
    [missile_frame]
        begin=75
        end=125
        image="projectiles/icemissile-n-6.png"
        image_diagonal="projectiles/icemissile-ne-6.png"
        halo=halo/elven/ice-halo8.png
        halo_x,halo_y=0,0
    [/missile_frame]
    [missile_frame]
        begin=125
        end=175
        image="projectiles/icemissile-n-7.png"
        image_diagonal="projectiles/icemissile-ne-7.png"
        halo=halo/elven/ice-halo9.png
        halo_x,halo_y=0,0
    [/missile_frame]
#enddef

#define MISSILE_FRAME_FIREBALL
# Animate a projectile for a fireball attack.
    [missile_frame]
        begin=-220
        end=-100
        image="projectiles/fireball-n-2.png"
        image_diagonal="projectiles/fireball-nw-2.png"
    [/missile_frame]
    [missile_frame]
        begin=-100
        end=25
        image="projectiles/fireball-n.png"
        image_diagonal="projectiles/fireball-nw.png"
    [/missile_frame]
    [missile_frame]
        begin=25
        end=80
        image="projectiles/fireball-n-2.png"
        image_diagonal="projectiles/fireball-nw-2.png"
    [/missile_frame]
#enddef

#define MISSILE_FRAME_HATCHET
# Animate a projectile for a thrown-hatchet attack.
	[missile_frame]
		begin=-200
		end=-150
		image="projectiles/hatchet-2.png"
		image_diagonal="projectiles/hatchet-2.png"
	[/missile_frame]
	[missile_frame]
		begin=-150
		end=-100
		image="projectiles/hatchet-3.png"
		image_diagonal="projectiles/hatchet-3.png"
	[/missile_frame]
	[missile_frame]
		begin=-100
		end=-50
		image="projectiles/hatchet-4.png"
		image_diagonal="projectiles/hatchet-4.png"
	[/missile_frame]
	[missile_frame]
		begin=-50
		end=0
		image="projectiles/hatchet-1.png"
		image_diagonal="projectiles/hatchet-1.png"
	[/missile_frame]
#enddef

#define FIRE_BURST_SMALL
	[missile_frame]
		begin=0
		end=75
		image="projectiles/fire-burst-small-1.png"
		image_diagonal="projectiles/fire-burst-small-1.png"
		offset=0.8
	[/missile_frame]
	[missile_frame]
		begin=75
		end=150
		image="projectiles/fire-burst-small-2.png"
		image_diagonal="projectiles/fire-burst-small-2.png"
		offset=0.83
	[/missile_frame]
	[missile_frame]
		begin=150
		end=225
		image="projectiles/fire-burst-small-3.png"
		image_diagonal="projectiles/fire-burst-small-3.png"
		offset=0.86
	[/missile_frame]
	[missile_frame]
		begin=225
		end=300
		image="projectiles/fire-burst-small-4.png"
		image_diagonal="projectiles/fire-burst-small-4.png"
		offset=0.89
	[/missile_frame]
	[missile_frame]
		begin=300
		end=375
		image="projectiles/fire-burst-small-5.png"
		image_diagonal="projectiles/fire-burst-small-5.png"
		offset=0.92
	[/missile_frame]
	[missile_frame]
		begin=375
		end=450
		image="projectiles/fire-burst-small-6.png"
		image_diagonal="projectiles/fire-burst-small-6.png"
		offset=0.95
	[/missile_frame]
	[missile_frame]
		begin=450
		end=525
		image="projectiles/fire-burst-small-7.png"
		image_diagonal="projectiles/fire-burst-small-7.png"
		offset=0.98
	[/missile_frame]
	[missile_frame]
		begin=525
		end=600
		image="projectiles/fire-burst-small-8.png"
		image_diagonal="projectiles/fire-burst-small-8.png"
		offset=1.0
	[/missile_frame]
#enddef
