#textdomain wesnoth-After_the_Storm

#
# Implementation of event-based unit abilities.
#

#define ABILITY_PHYSICAL_ENDURANCE_EVENTS
    [event]
        id=ability_physical_endurance_attacker_hits
        name=attacker hits
        first_time_only=no
        [filter_second]
            ability=physical_endurance
        [/filter_second]
        [filter_attack]
            [not]
                type=arcane,cold,fire
            [/not]
        [/filter_attack]

        [fire_event]
            name=physical endurance handler
            [primary_unit]
                x,y=$x2,$y2
            [/primary_unit]
            [secondary_unit]
                x,y=$x1,$y1
            [/secondary_unit]
        [/fire_event]
    [/event]
    [event]
        id=ability_physical_endurance_defender_hits
        name=defender hits
        first_time_only=no
        [filter]
            ability=physical_endurance
        [/filter]
        [filter_second_attack]
            [not]
                type=arcane,cold,fire
            [/not]
        [/filter_second_attack]

        [fire_event]
            name=physical endurance handler
            [primary_unit]
                x,y=$x1,$y1
            [/primary_unit]
            [secondary_unit]
                x,y=$x2,$y2
            [/secondary_unit]
        [/fire_event]
    [/event]
    [event]
        id=ability_physical_endurance_handler
        name=physical endurance handler
        first_time_only=no

        # Primary unit: physical endurance user
        # Secondary unit: attacker/defender

        [if]
            {VARIABLE_NUMERICAL_GREATER_THAN unit.hitpoints 0}
            [then]
                {VARIABLE_OP temp_PHYSICAL_ENDURANCE_restore_hp to_variable damage_inflicted}
                {VARIABLE_OP temp_PHYSICAL_ENDURANCE_restore_hp divide      2}
                {VARIABLE_OP temp_PHYSICAL_ENDURANCE_restore_hp round       ceil}

                [heal_unit]
                    [filter]
                        x,y=$x1,$y1
                    [/filter]
                    amount=$temp_PHYSICAL_ENDURANCE_restore_hp
                    restore_statuses=no
                [/heal_unit]

                [floating_text]
                    x,y=$x1,$y1
                    text="$heal_amount" # wmllint: ignore
                [/floating_text]

                {CLEAR_VARIABLE temp_PHYSICAL_ENDURANCE_restore_hp}
            [/then]
        [/if]
    [/event]
#enddef

#define ABILITY_ABSCOND_EVENTS
    [event]
        id=ability_abscond_check_attack_1st_unit
        name=attack end
        first_time_only=no
        [filter]
            ability=abscond
        [/filter]
        [filter_condition]
            {VARIABLE_NUMERICAL_LESS_THAN_OR_EQUAL unit.hitpoints 0}
        [/filter_condition]

        [fire_event]
            name=abscond triggered
            [primary_unit]
                x,y=$x1,$y1
            [/primary_unit]
        [/fire_event]
    [/event]

    [event]
        id=ability_abscond_check_attack_2nd_unit
        name=attack end
        first_time_only=no
        [filter_second]
            ability=abscond
        [/filter_second]
        [filter_condition]
            {VARIABLE_NUMERICAL_LESS_THAN_OR_EQUAL second_unit.hitpoints 0}
        [/filter_condition]

        [fire_event]
            name=abscond triggered
            [primary_unit]
                x,y=$x2,$y2
            [/primary_unit]
        [/fire_event]
    [/event]

    [event]
        id=ability_abscond_trigger
        name=abscond triggered
        first_time_only=no
        [filter]
            [not]
                status=absconding
            [/not]
        [/filter]

        {LOG_ATS_DBG "$unit.id ($x1, $y1) absconding!"}

        [set_variables]
            name=unit
            mode=merge
            [value]
                hitpoints="$(min(8, $unit.max_hitpoints))"
                attacks_left=0
                moves="$(max(1, $unit.max_moves - 2))"
                [status]
                    absconding=yes
                [/status]
            [/value]
        [/set_variables]

        [unstore_unit]
            variable=unit
            find_vacant=no
        [/unstore_unit]

        [event]
            name="side $unit.side turn $(2 + $turn_number)"
            delayed_variable_substitution=no

            [store_unit]
                [filter]
                    id=$unit.id
                [/filter]
                variable=abscondee
                kill=no
            [/store_unit]

            {CLEAR_VARIABLE abscondee.status.absconding}

            [unstore_unit]
                variable=abscondee
                find_vacant=no
            [/unstore_unit]

            {CLEAR_VARIABLE abscondee}
        [/event]
    [/event]

    [event]
        id=ability_abscond_cleanup
        name=victory

        [store_unit]
            [filter]
                status=absconding
            [/filter]
            variable=victory_abscondees
            kill=no
        [/store_unit]

        [foreach]
            array=victory_abscondees
            variable=abscondee

            [do]
                {CLEAR_VARIABLE abscondee.status.absconding}

                [unstore_unit]
                    variable=abscondee
                    find_vacant=no
                [/unstore_unit]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE victory_abscondees}
    [/event]
#enddef

#
# Macro used to implement ABILITY_DEMOLITION_AUXILIARY_EVENT
# and some scenario-specific events.
#
# NOTE: if _ADDITIONAL_LOCATION_FILTER contains terrain=, it must be under an
# [and], [or], or [not] block; otherwise, it will cause problems.
#
#define ABILITY_DEMOLITION_AUXILIARY_EVENT_DESTRUCTION_IMPLEMENTATION _X _Y
#arg HANDLE_AS_UNIT_ATTACK
    yes
#endarg
    # Dummy SLF that never matches anything, so that [not] EXCLUDE_SLF [/not]
    # if EXCLUDE_SLF is unspecified doesn't result in excluding the whole map.
#arg EXCLUDE_SLF
    terrain=&&&&
#endarg

    {VARIABLE temp_DEMO_source_is_unit {HANDLE_AS_UNIT_ATTACK}}

    [color_adjust]
        red,green,blue=300,300,300
    [/color_adjust]

    [set_variables]
        name=temp_DEMO_terraform_actions
        mode=replace
        [value]
            [remove_terrain_overlays]
                x={_X}
                y={_Y}
                radius=1

                [not]
                    {EXCLUDE_SLF}
                [/not]

                [filter_radius]
                    [not]
                        terrain=X*,*^X*,Q*,*^Q*,W*,*^W*,S*,*^S*
                    [/not]
                    [not]
                        {EXCLUDE_SLF}
                    [/not]
                [/filter_radius]
            [/remove_terrain_overlays]

            [terrain]
                x={_X}
                y={_Y}
                radius=1
                [and]
                    # Only these terrains can get flattened. The others only
                    # have their overlays removed above.
                    terrain=A*,C*,D*,G*,K*,R*,U*,Y*
                [/and]

                [not]
                    {EXCLUDE_SLF}
                [/not]

                [filter_radius]
                    [not]
                        terrain=X*,*^X*,Q*,*^Q*,W*,*^W*,S*,*^S*
                    [/not]
                    [not]
                        {EXCLUDE_SLF}
                    [/not]
                [/filter_radius]

                terrain=Re^Es
            [/terrain]
        [/value]
    [/set_variables]

    # Execute terraforming commands
    [insert_tag]
        name=command
        variable=temp_DEMO_terraform_actions
    [/insert_tag]

    [harm_unit]
        [filter]
            [filter_location]
                [filter_adjacent_location]
                    x={_X}
                    y={_Y}
                [/filter_adjacent_location]
            [/filter_location]
        [/filter]

        # No harm source unit or weapon given here, on purpose.

        delay=0
        amount=$this_unit.hitpoints
        # No animations played at this point, since they'd delay the sequence too much
        # in the worst case (six adjacent units)
        animate=no
        kill=no
        fire_event=yes
    [/harm_unit]

    {QUAKE "explosion-big.ogg"}

    [redraw][/redraw] # update terrain display

    [color_adjust]
        red,green,blue=0,0,0
    [/color_adjust]

    # Kill all adjacent units that don't have the demolition ability first;
    # we need to take care of those in a separate step to prevent causing
    # an event loop.

    [set_variables]
        name=temp_DEMO_action
        mode=replace
        [value]
            [filter_location]
                [filter_adjacent_location]
                    x={_X}
                    y={_Y}
                [/filter_adjacent_location]
            [/filter_location]
            [not]
                ability=demolition
            [/not]
            [not]
                status=immune_to_demolition
            [/not]
            [not]
                # Shapeshifters are handled by scenario-specific
                # events where they appear, and it might not be
                # a good idea for those to fire at this point.
                [filter_wml]
                    [variables]
                        is_shapeshifter=yes
                    [/variables]
                [/filter_wml]
            [/not]
            [secondary_unit]
                # the demolition unit killed them
                x={_X}
                y={_Y}
            [/secondary_unit]
            animate=yes
            fire_event=yes
        [/value]
    [/set_variables]

    [if]
        {VARIABLE_BOOLEAN_EQUALS temp_DEMO_source_is_unit no}
        [then]
            # Our event wasn't dispatched by a unit attack sequence (hopefully)
            # so we need to fire_event on the source tile kill.
            [set_variables]
                name=temp_DEMO_action.filter_location
                mode=merge
                [value]
                    [or]
                        x={_X}
                        y={_Y}
                    [/or]
                [/value]
            [/set_variables]

            # Avoid triggering a warning about not matching any units in
            # [secondary_unit] on Wesnoth 1.14.
            {CLEAR_VARIABLE temp_DEMO_action.secondary_unit}
        [/then]
    [/if]

    [insert_tag]
        name=kill
        variable=temp_DEMO_action
    [/insert_tag]

    {CLEAR_VARIABLE temp_DEMO_action,temp_DEMO_source_is_unit,temp_DEMO_terraform_actions}

    # Remove this source unit so the target units with demolition don't
    # trigger its death again.

    [kill]
        x={_X}
        y={_Y}
        animate=no
        fire_event=no
    [/kill]

    # Take care of any remaining adjacent units with demolition.

    [kill]
        [filter_location] # SLF, since there's no unit at (_X, _Y) anymore.
            [filter_adjacent_location]
                x={_X}
                y={_Y}
            [/filter_adjacent_location]
        [/filter_location]
        ability=demolition
        # No secondary unit, but we shouldn't need one in this case.
        animate=yes
        fire_event=yes
    [/kill]
#enddef

#define ABILITY_DEMOLITION_EVENTS
    [event]
        id=ability_demolition_die
        name=die
        first_time_only=no
        [filter]
            ability=demolition
        [/filter]

        # Work around Wesnoth 1.14+ rendering the unit visible again because it
        # gets referenced in the event.
        [hide_unit]
            x,y=$x1,$y1
        [/hide_unit]

        {ABILITY_DEMOLITION_AUXILIARY_EVENT_DESTRUCTION_IMPLEMENTATION $x1 $y1}

        [fire_event]
            name=demolition complete
        [/fire_event]
    [/event]
#enddef

#
# Base ability implementation for all aspect Guardians.
#

# Some scenario events can interact with this ability in unexpected ways
# resulting in "failed to auto-store $unit/$second_unit" errors -- most notably
# this caused issues in scenario E3S10 when killing the last Blood Core (see
# <https://github.com/project-ethea/After_the_Storm/issues/75>. This check is
# here to ensure that either the stores are viable or the event handlers that
# rely on them being so are not executed.
#define ABILITY_ASPECT_GUARDIAN_BASE:UNIT_PAIR_EXISTS_PRECONDITION
    [filter_condition]
        {VARIABLE_NUMERICAL_GREATER_THAN unit.length        0}
        {VARIABLE_NUMERICAL_GREATER_THAN second_unit.length 0}
    [/filter_condition]
#enddef

# wmllint: unbalanced-on
#define ABILITY_ASPECT_GUARDIAN_BASE
    #
    # Regeneration
    #
    [regenerate]
        value=8
        id=aspect_guardian_regenerates
        affect_self=yes
        poison=cured
    [/regenerate]

    #
    # Immortality
    #
    [dummy]
        id=aspect_guardian_immortality
    [/dummy]

    # wmlxgettext: [abilities]
[/abilities]

[event]
    id=aspect_guardian_immortality_implementation
    name=last breath
    first_time_only=no
    [filter]
        ability=aspect_guardian_immortality
    [/filter]
    [filter_second]
        [not]
            ability=aspect_guardian_immortality
        [/not]
        [not]
            ability=aspect_destroyer
        [/not]
    [/filter_second]

    {VARIABLE unit.hitpoints 1}

    # Deduct the killing XP from the attacker, otherwise it is possible
    # for them to advance very quickly from L1 to their maximum advancement.
    # Things get even messier once the full health AMLA effect kicks in.

    {LOG_ATS_DBG "aspect_guardian_immortality_implementation: triggered, deducting $(max([4, 8 * $unit.level])) XP from $second_unit.id"}

    {VARIABLE_MIN second_unit.experience "$(max([4, 8 * $unit.level]))"}

    [unstore_unit]
        variable=unit
        find_vacant=no
    [/unstore_unit]

    [unstore_unit]
        variable=second_unit
        find_vacant=no
    [/unstore_unit]
[/event]

[event]
    id=aspect_guardian_no_combat_experience_on_attack_implementation
    name=attack end
    first_time_only=no
    [filter_second]
        ability=aspect_guardian_immortality
    [/filter_second]

    {ABILITY_ASPECT_GUARDIAN_BASE:UNIT_PAIR_EXISTS_PRECONDITION}

    [if]
        # Let the last breath event handle things if the target is dying.
        {VARIABLE_NUMERICAL_GREATER_THAN second_unit.hitpoints 0}
        [then]
            {LOG_ATS_DBG "aspect_guardian_no_combat_experience_on_attack_implementation: triggered, deducting $second_unit.level XP from $unit.id"}

            # Deduct the combat XP from the attacker.
            {VARIABLE_MIN unit.experience "$second_unit.level"}

            [unstore_unit]
                variable=unit
                find_vacant=no
            [/unstore_unit]
        [/then]
    [/if]
[/event]

[event]
    id=aspect_guardian_no_combat_experience_on_defense_implementation
    name=attack end
    first_time_only=no
    [filter]
        ability=aspect_guardian_immortality
    [/filter]

    {ABILITY_ASPECT_GUARDIAN_BASE:UNIT_PAIR_EXISTS_PRECONDITION}

    [if]
        # Let the last breath event handle things if the target is dying.
        {VARIABLE_NUMERICAL_GREATER_THAN unit.hitpoints 0}
        [then]
            {LOG_ATS_DBG "aspect_guardian_no_combat_experience_on_defense_implementation: triggered, deducting $unit.level XP from $second_unit.id"}

            # Deduct the combat XP from the attacker.
            {VARIABLE_MIN second_unit.experience "$unit.level"}

            [unstore_unit]
                variable=second_unit
                find_vacant=no
            [/unstore_unit]
        [/then]
    [/if]
[/event]

[+abilities]
    # wmlxgettext: [/abilities]
#enddef
# wmllint: unbalanced-off

#
# UtBS ability events
#

#define ABILITY_DISENGAGE_EVENTS
    [event]
        name=attack end
        first_time_only=no

        [filter]
            ability=disengage

            [not]
                [filter_wml]
                    moves=$this_unit.max_moves
                [/filter_wml]
            [/not]
        [/filter]

        {VARIABLE unit.moves 0}

        [unstore_unit]
            variable=unit
            find_vacant=no
        [/unstore_unit]
    [/event]
#enddef

#define ABILITY_FORMATION_EVENTS
    [event]
        id=ability_formation_event
        name=unit placed
        first_time_only=no

        [filter]
            [not]
                side=1
            [/not]

            [not]
                [filter_wml]
                    [attack]
                        [specials]
                            [chance_to_hit]
                                id=formation_enemy_1
                            [/chance_to_hit]
                        [/specials]
                    [/attack]
                [/filter_wml]
            [/not]
        [/filter]

        [object]
            silent=yes

            [filter]
                id=$unit.id
            [/filter]

            [effect]
                apply_to=attack

                [set_specials]
                    mode=append

                    [chance_to_hit]
                        id=formation_enemy_1
                        name=""
                        description=""
                        sub=10
                        [filter_base_value]
                            greater_than_equal_to=40
                        [/filter_base_value]
                        [filter_opponent]
                            ability=formation

                            [filter_adjacent]
                                ability=formation
                                is_enemy=no
                                count=1-5
                            [/filter_adjacent]
                        [/filter_opponent]
                    [/chance_to_hit]
                    [chance_to_hit]
                        id=formation_enemy_2
                        name=""
                        description=""
                        sub=10
                        [filter_base_value]
                            greater_than_equal_to=50
                        [/filter_base_value]
                        [filter_opponent]
                            ability=formation

                            [filter_adjacent]
                                ability=formation
                                is_enemy=no
                                count=2-5
                            [/filter_adjacent]
                        [/filter_opponent]
                    [/chance_to_hit]
                    [chance_to_hit]
                        id=formation_enemy_3
                        name=""
                        description=""
                        sub=10
                        [filter_base_value]
                            greater_than_equal_to=60
                        [/filter_base_value]
                        [filter_opponent]
                            ability=formation

                            [filter_adjacent]
                                ability=formation
                                is_enemy=no
                                count=3-5
                            [/filter_adjacent]
                        [/filter_opponent]
                    [/chance_to_hit]
                    [chance_to_hit]
                        id=formation_enemy_4
                        name=""
                        description=""
                        sub=10
                        [filter_base_value]
                            greater_than_equal_to=70
                        [/filter_base_value]
                        [filter_opponent]
                            ability=formation

                            [filter_adjacent]
                                ability=formation
                                is_enemy=no
                                count=4-5
                            [/filter_adjacent]
                        [/filter_opponent]
                    [/chance_to_hit]
                    [chance_to_hit]
                        id=formation_enemy_5
                        name=""
                        description=""
                        sub=10
                        [filter_base_value]
                            greater_than_equal_to=80
                        [/filter_base_value]
                        [filter_opponent]
                            ability=formation

                            [filter_adjacent]
                                ability=formation
                                is_enemy=no
                                count=5
                            [/filter_adjacent]
                        [/filter_opponent]
                    [/chance_to_hit]
                [/set_specials]
            [/effect]
        [/object]
    [/event]
#enddef


#textdomain wesnoth-After_the_Storm

#define ABILITY_ABSORB_DAMAGE
    [dummy]
        id=absorb_damage
        name= _ "absorb damage"
        female_name= _ "female^absorb damage"
        description= _ "Units with this ability will not take damage."
        special_note={SPECIAL_NOTE_ABSORB_DAMAGE}
    [/dummy]
#enddef

#define ABILITY_PHYSICAL_ENDURANCE
    [dummy]
        id=physical_endurance
        name= _ "physical endurance"
        female_name= _ "female^physical endurance"
        description= _ "Units with this ability instantly regenerate half of damage dealt to them unless its type is arcane, cold, or fire, or it would count as the killing blow otherwise."
        special_note={SPECIAL_NOTE_PHYSICAL_ENDURANCE}
    [/dummy]

    {ABILITY_EVENTS PHYSICAL_ENDURANCE}
#enddef

#define ABILITY_ABSCOND
    [dummy]
        id=abscond
        name= _ "abscond"
        female_name= _ "female^abscond"
        description= _ "Units with this ability are able to survive one fatal hit every other turn. Upon triggering the ability, the absconding unit is set back to 8 HP and 2 under its maximum movement points, allowing it to retreat to safety."
        special_note={SPECIAL_NOTE_ABSCOND}
        # This is purely a visual aid, although it's not terribly helpful in
        # 1.14 since the ability's name overflows most of the time.
        [filter]
            [not]
                status=absconding
            [/not]
        [/filter]
    [/dummy]
#enddef

#define ABILITY_DEMOLITION_TEXT_ONLY
    [dummy]
        id=demolition
        name= _ "demolition"
        female_name= _ "female_name^demolition"
        description= _ "On death, units with this ability destroy all adjacent hexes and units, and the hex they are standing on."
        special_note={SPECIAL_NOTE_DEMOLITION}
    [/dummy]
#enddef

#define ABILITY_DEMOLITION
    {ABILITY_DEMOLITION_TEXT_ONLY}

    {ABILITY_EVENTS DEMOLITION}
#enddef

#define ABILITY_AQUEOUS
    [resistance]
        id=aqueous
        name= _ "aqueous"
        female_name= _ "female^aqueous"
        description= _ "This unit’s resistances to non-arcane damage are increased to 10% or (if already 10% or higher) tripled up to a maximum of 60%, when defending on water, reef, or swamp terrain. It also regenerates 8 HP at the start of every turn when positioned on those terrains, but it will not remove poison from itself."
        special_note={SPECIAL_NOTE_AQUEOUS}
        [filter]
            [filter_location]
                {ABILITY_AQUEOUS:TERRAIN_FILTER}
            [/filter_location]
        [/filter]
        affect_self=yes
        active_on=defense
        multiply=3
        max_value=60
        apply_to=blade,pierce,impact,fire,cold
        [filter_base_value]
            greater_than=0
            less_than=60
        [/filter_base_value]
    [/resistance]

    [resistance]
        id=aqueous_min_resistance
        [filter]
            [filter_location]
                {ABILITY_AQUEOUS:TERRAIN_FILTER}
            [/filter_location]
        [/filter]
        affect_self=yes
        active_on=defense
        value=10
        max_value=10
        apply_to=blade,pierce,impact,fire,cold
        [filter_base_value]
            less_than=10
        [/filter_base_value]
    [/resistance]

    [regenerate]
        id=aqueous_regenerates
        value=8
        affect_self=yes
        [filter]
            [filter_location]
                {ABILITY_AQUEOUS:TERRAIN_FILTER}
            [/filter_location]
        [/filter]
    [/regenerate]
#enddef

#define ABILITY_AQUEOUS:TERRAIN_FILTER
    # Water, Swamp, Oasis, Merfolk Castle/Keep, Swamp Castle/Keep, Sunken Castle/Keep
    terrain="W*,W*^*,S*,S*^*,*^Do,Cm*,Cm*^*,Km*,Km*^*,Chs*,Chs*^*,Khs*,Khs*^*,Chw*,Chw*^*,Khw*,Khw*^*"
#enddef

#
# GENERAL NOTE ABOUT ASPECT ABILITIES:
#
# These abilities are only appropriate for actual guardians, of which there
# are only three on Irdya before the campaign is over, and none left
# afterwards. You should not really be reusing these abilities for any other
# units.
#
# More generally, aspect guardians stick to the "new powers as the plot
# demands" trope, and the full extent of their powers is intentionally not
# explored in this campaign. Young/recently awakened guardians in particular
# do not have access to their full potential yet.
#

#define ABILITY_ASPECT_OF_DARKNESS
    [dummy]
        id=aspect_of_darkness
        name= _ "aspect of darkness"
        description= _ "This unit is a Guardian of the Aspect of Darkness.

As such, it has access to the following abilities:

 • Obscures: +25 chaotic bonus on adjacent locations
 • Regeneration (+8 HP per turn)
 • Immortality (can only be killed by specific units)
 • Counts as level 0 for XP calculation purposes during combat"
    [/dummy]

    #
    # Implementation details follow.
    #

    {ABILITY_ASPECT_GUARDIAN_BASE}

    [illuminates]
        id=aspect_of_darkness_obscures
        value=-25
        min_value=-25
        cumulative=no
        affect_self=yes
    [/illuminates]
#enddef

#define ABILITY_ASPECT_OF_EARTH
    [dummy]
        id=aspect_of_earth
        name= _ "aspect of earth"
        description= _ "This unit is a Guardian of the Aspect of Earth.

As such, it has access to the following abilities:

 • Sylvan Essence: healing and curing allies (+16 HP per turn), self-concealment on vegetated terrains
 • Regeneration (+8 HP per turn)
 • Immortality (can only be killed by specific units)
 • Counts as level 0 for XP calculation purposes during combat"
    [/dummy]

    #
    # Implementation details follow.
    #

    {ABILITY_ASPECT_GUARDIAN_BASE}

    [heals]
        value=16
        id=aspect_of_earth_sylvan_essence_healing_curing
        affect_allies=yes
        affect_self=no
        poison=cured
        [affect_adjacent]
            adjacent=n,ne,se,s,sw,nw
        [/affect_adjacent]
    [/heals]

    [hides]
        id=aspect_of_earth_sylvan_essence_conceal
        affect_self=yes
        [filter_self]
            [filter_location]
                terrain={VEGETATED_TERRAINS}
            [/filter_location]
        [/filter_self]
    [/hides]
#enddef

# NOTE: This ability is intentionally not completely implemented and broken.
# The only unit which possesses this ability in this campaign only appears
# in a cutscene. The ability is provided mostly for the sake of having
# something to show in the sidebar should the fullscreen UI theme fail to
# work on some build/platform/version. Consider it a 'stub' ability.
#define ABILITY_ASPECT_OF_LIFE
    [dummy]
        id=aspect_of_life
        name= _ "aspect of life"
        description= _ "This unit is a Guardian of the Aspect of Life.

As such, it has access to the following abilities:

 • Healing and curing allies (+8 HP per turn)
 • Regeneration (+16 HP per turn)
 • Life stealing (+32 HP regenerated per unit killed)
 • Immortality (can only be killed by specific units)
 • Counts as level 0 for XP calculation purposes during combat"
    [/dummy]

    #
    # Implementation details follow.
    #

    {ABILITY_ASPECT_GUARDIAN_BASE}

    [heals]
        value=8
        id=aspect_of_life_healing_curing
        affect_allies=yes
        affect_self=no
        poison=cured
        [affect_adjacent]
            adjacent=n,ne,se,s,sw,nw
        [/affect_adjacent]
    [/heals]
#enddef

#define ABILITY_ASPECT_DESTROYER
    [dummy]
        #
        # This silent ability deliberately lacks UI text.
        #
        id=aspect_destroyer
    [/dummy]
#enddef

#
# UtBS abilities
#

#textdomain wesnoth-utbs

#define ABILITY_FORMATION
    [dummy]
        id=formation
        name= _ "formation"
        female_name= _ "female^formation"
        description= _ "This unit gains a +10% bonus to defense when another unit with the same ability is adjacent to it. However, this cannot raise the unit’s defense above 70%."
        special_note={SPECIAL_NOTE_FORMATION}
    [/dummy]

    {ABILITY_EVENTS FORMATION}
#enddef

#define ABILITY_DISENGAGE
    [dummy]
        id=disengage
        name= _ "disengage"
        female_name= _ "female^disengage"
        description= _ "If this unit doesn’t move before attacking, it will retain its movement points after the attack."
        special_note={SPECIAL_NOTE_DISENGAGE}
    [/dummy]

    {ABILITY_EVENTS DISENGAGE}
#enddef

# kate: indent-mode normal; encoding utf-8; space-indent on;


#textdomain wesnoth-After_the_Storm

#
# STRENGTH UPGRADES
#
# Req.: none
#

#define AMLA_ANYA_STRENGTH_L1
    {CHARACTER_AMLA
    amla_anya_strength_l1
    ()
    attacks/touch-faerie.png ( _ "Strength I: melee damage +1")
    (
        [effect]
            apply_to=attack
            range=melee
            increase_damage=1
        [/effect]
    )}
#enddef

#define AMLA_ANYA_STRENGTH_L2
    {CHARACTER_AMLA
    amla_anya_strength_l2
    amla_anya_strength_l1
    attacks/touch-faerie.png ( _ "Strength II: hitpoints +4, melee damage +1")
    (
        [effect]
            apply_to=hitpoints
            increase=4
            increase_total=4
        [/effect]
        [effect]
            apply_to=attack
            range=melee
            increase_damage=1
        [/effect]
    )}
#enddef

#define AMLA_ANYA_STRENGTH_L3
    {CHARACTER_AMLA
    amla_anya_strength_l3
    amla_anya_strength_l2
    attacks/touch-faerie.png ( _ "Strength III: hitpoints +4, melee strikes +1")
    (
        [effect]
            apply_to=hitpoints
            increase=4
            increase_total=4
        [/effect]
        [effect]
            apply_to=attack
            range=melee
            increase_attacks=1
        [/effect]
    )}
#enddef

#define AMLA_ANYA_STRENGTH_L4
    {CHARACTER_AMLA
    amla_anya_strength_l4
    amla_anya_strength_l3
    attacks/touch-faerie.png ( _ "Strength IV: melee drains special")
    (
        [effect]
            apply_to=attack
            range=melee
            [set_specials]
                mode=append
                {WEAPON_SPECIAL_DRAIN}
            [/set_specials]
        [/effect]
    )}
#enddef

#
# FOCUS UPGRADES
#
# Req.: none
#

#define AMLA_ANYA_FOCUS_L1
    {CHARACTER_AMLA
    amla_anya_focus_l1
    ()
    attacks/forest-chill.png ( _ "Focus I: noctum damage +1")
    (
        [effect]
            apply_to=attack
            name=noctum
            increase_damage=1
        [/effect]
    )}
#enddef

#define AMLA_ANYA_FOCUS_L2
    {CHARACTER_AMLA
    amla_anya_focus_l2
    amla_anya_focus_l1
    attacks/forest-chill.png ( _ "Focus II: chill damage +1, daze weapon special")
    (
        [effect]
            apply_to=attack
            name=forest chill
            increase_damage=1
            [set_specials]
                mode=append
                {WEAPON_SPECIAL_DAZE}
            [/set_specials]
        [/effect]
    )}
#enddef

#define AMLA_ANYA_FOCUS_L3
    {CHARACTER_AMLA
    amla_anya_focus_l3
    amla_anya_focus_l2
    attacks/forest-chill.png ( _ "Focus III: chill strikes +1")
    (
        [effect]
            apply_to=attack
            name=forest chill
            increase_attacks=1
        [/effect]
    )}
#enddef

#define AMLA_ANYA_FOCUS_L4
    {CHARACTER_AMLA
    amla_anya_focus_l4
    amla_anya_focus_l3
    attacks/forest-chill.png ( _ "Focus IV: noctum damage +1")
    (
        [effect]
            apply_to=attack
            name=noctum
            increase_damage=1
        [/effect]
    )}
#enddef

#define AMLA_ANYA_FOCUS_L5
    {CHARACTER_AMLA
    amla_anya_focus_l5
    amla_anya_focus_l4,amla_anya_strength_l4
    attacks/forest-chill.png ( _ "Focus V: noctum damage +1, strikes +1")
    (
        [effect]
            apply_to=attack
            name=noctum
            increase_damage=1
            increase_attacks=1
        [/effect]
    )}
#enddef

#
# SHIELDING UPGRADES
#
# Req.: none
#

#define AMLA_ANYA_SHIELDING_L1
    {CHARACTER_AMLA
    amla_anya_shielding_l1
    ()
    attacks/magic-missile.png ( _ "Shielding I: fire resistance +10%")
    (
        [effect]
            apply_to=resistance
            replace=no
            [resistance]
                fire=-10
            [/resistance]
        [/effect]
    )}
#enddef

#define AMLA_ANYA_SHIELDING_L2
    {CHARACTER_AMLA
    amla_anya_shielding_l2
    amla_anya_shielding_l1
    attacks/magic-missile.png ( _ "Shielding II: fire resistance +10%, cold resistance +10%")
    (
        [effect]
            apply_to=resistance
            replace=no
            [resistance]
                fire=-10
                cold=-10
            [/resistance]
        [/effect]
    )}
#enddef

#define AMLA_ANYA_SHIELDING_L3
    {CHARACTER_AMLA
    amla_anya_shielding_l3
    amla_anya_shielding_l2
    attacks/magic-missile.png ( _ "Shielding III: arcane resistance +10%")
    (
        [effect]
            apply_to=resistance
            replace=no
            [resistance]
                arcane=-10
            [/resistance]
        [/effect]
    )}
#enddef

#
# ABSCOND ABILITY
#
# Req.: Strength II, Focus II
#
# NOTE: As this ability is essentially foreshadowing a reveal in E3, it's
#       intentionally restricted to said episode even though the requirements
#       can be fulfilled in E2.
#

#define AMLA_ANYA_EVASION
    {CHARACTER_AMLA
    amla_anya_evasion
    amla_anya_strength_l2,amla_anya_focus_l2
    icons/abscond.png ( _ "Evasion: abscond ability")
    (
        [effect]
            apply_to=new_ability
            [abilities]
                {ABILITY_ABSCOND}
            [/abilities]
        [/effect]
    )}
#enddef

#define AMLA_TREE:ANYA_EPISODE_2
    {AMLA_ANYA_STRENGTH_L1}
    {AMLA_ANYA_STRENGTH_L2}
    {AMLA_ANYA_FOCUS_L1}
    {AMLA_ANYA_FOCUS_L2}
    {AMLA_ANYA_SHIELDING_L1}
    {AMLA_ANYA_SHIELDING_L2}
#ifdef CAMPAIGN_AFTER_THE_STORM_EPISODE_II
    {AMLA_TREE_LOCK amla_anya_strength_l2,amla_anya_focus_l2,amla_anya_shielding_l2}
#endif
#enddef

#define AMLA_TREE:ANYA_EPISODE_3
    {AMLA_ANYA_STRENGTH_L3}
    {AMLA_ANYA_STRENGTH_L4}
    {AMLA_ANYA_FOCUS_L3}
    {AMLA_ANYA_FOCUS_L4}
    {AMLA_ANYA_FOCUS_L5}
    {AMLA_ANYA_SHIELDING_L3}
    {AMLA_ANYA_EVASION}
#enddef


#textdomain wesnoth-After_the_Storm

#
# STRENGTH UPGRADES
#
# Req.: none
# Note: These are lifted directly from IftU with different ids. Weapon effects
#       go by weapon range instead of name so they can carry into Episode III
#       transparently once she loses her staff. This is intentional.
#

#define AMLA_ELYNIA_STRENGTH_L1
    {CHARACTER_AMLA
    amla_elynia_strength_l1
    ()
    attacks/staff-niryone.png ( _ "Strength I: hitpoints +4, melee damage +1")
    (
        [effect]
            apply_to=hitpoints
            increase=4
            increase_total=4
        [/effect]
        [effect]
            apply_to=attack
            range=melee
            increase_damage=1
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_STRENGTH_L2
    {CHARACTER_AMLA
    amla_elynia_strength_l2
    amla_elynia_strength_l1
    attacks/staff-niryone.png ( _ "Strength II: hitpoints +4, melee strikes +1")
    (
        [effect]
            apply_to=hitpoints
            increase=4
            increase_total=4
        [/effect]
        [effect]
            apply_to=attack
            range=melee
            increase_attacks=1
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_STRENGTH_L3
    {CHARACTER_AMLA
    amla_elynia_strength_l3
    amla_elynia_strength_l2
    attacks/staff-niryone.png ( _ "Strength III: hitpoints +5")
    (
        [effect]
            apply_to=hitpoints
            increase=5
            increase_total=5
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_STRENGTH_L4
    {CHARACTER_AMLA
    amla_elynia_strength_l4
    amla_elynia_strength_l3
    attacks/staff-niryone.png ( _ "Strength IV: hitpoints +5, melee damage +1")
    (
        [effect]
            apply_to=hitpoints
            increase=5
            increase_total=5
        [/effect]
        [effect]
            apply_to=attack
            range=melee
            increase_damage=1
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_STRENGTH_L5
    {CHARACTER_AMLA
    amla_elynia_strength_l5
    amla_elynia_strength_l4
    attacks/staff-niryone.png ( _ "Strength V: hitpoints +7")
    (
        [effect]
            apply_to=hitpoints
            increase=7
            increase_total=7
        [/effect]
    )}
#enddef

#
# FOCUS UPGRADES
#
# Req.: none
#

#define AMLA_ELYNIA_FOCUS_L1
    {CHARACTER_AMLA
    amla_elynia_focus_l1
    ()
    attacks/entangle.png ( _ "Focus I: ensnare strikes +1")
    (
        [effect]
            apply_to=attack
            name=ensnare
            increase_attacks=1
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_FOCUS_L2
    {CHARACTER_AMLA
    amla_elynia_focus_l2
    amla_elynia_focus_l1
    attacks/entangle.png ( _ "Focus II: ensnare damage +1, strikes +1")
    (
        [effect]
            apply_to=attack
            name=ensnare
            increase_damage=1
            increase_attacks=1
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_FOCUS_L3
    {CHARACTER_AMLA
    amla_elynia_focus_l3
    amla_elynia_focus_l2
    attacks/entangle.png ( _ "Focus III: ensnare damage +1")
    (
        [effect]
            apply_to=attack
            name=ensnare
            increase_damage=1
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_FOCUS_L4
    {CHARACTER_AMLA
    amla_elynia_focus_l4
    amla_elynia_focus_l3
    attacks/entangle.png ( _ "Focus IV: ensnare damage +1, stun weapon special")
    (
        [effect]
            apply_to=attack
            name=ensnare
            increase_damage=1
            [set_specials]
                mode=append
                {WEAPON_SPECIAL_STUN}
            [/set_specials]
        [/effect]
    )}
#enddef

#
# SHIELDING UPGRADES
#
# Req.: Focus I
#

#define AMLA_ELYNIA_SHIELDING_L1
    {CHARACTER_AMLA
    amla_elynia_shielding_l1
    amla_elynia_focus_l1
    attacks/magic-missile.png ( _ "Shielding I: arcane resistance +10%")
    (
        [effect]
            apply_to=resistance
            replace=no
            [resistance]
                arcane=-10
            [/resistance]
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_SHIELDING_L2
    {CHARACTER_AMLA
    amla_elynia_shielding_l2
    amla_elynia_shielding_l1
    attacks/magic-missile.png ( _ "Shielding II: impact resistance +10%")
    (
        [effect]
            apply_to=resistance
            replace=no
            [resistance]
                impact=-10
            [/resistance]
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_SHIELDING_L3
    {CHARACTER_AMLA
    amla_elynia_shielding_l3
    amla_elynia_shielding_l2
    attacks/magic-missile.png ( _ "Shielding III: cold resistance +10%, sylvan essence regeneration +1")
    (
        [effect]
            apply_to=resistance
            replace=no
            [resistance]
                cold=-10
            [/resistance]
        [/effect]
        [effect]
            apply_to=remove_ability
            [abilities]
                [regenerate]
                    id=sylvan_essence_selfheal_L0
                [/regenerate]
            [/abilities]
        [/effect]
        [effect]
            apply_to=new_ability
            [abilities]
                [regenerate]
                    id=sylvan_essence_selfheal_L1
                    value=4
                    affect_self=yes
                    [filter_self]
                        [filter_location]
                            terrain={VEGETATED_TERRAINS}
                        [/filter_location]
                    [/filter_self]
                [/regenerate]
            [/abilities]
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_SHIELDING_L4
    {CHARACTER_AMLA
    amla_elynia_shielding_l4
    amla_elynia_shielding_l3
    attacks/magic-missile.png ( _ "Shielding IV: fire resistance +10%")
    (
        [effect]
            apply_to=resistance
            replace=no
            [resistance]
                fire=-10
            [/resistance]
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_SHIELDING_L5
    {CHARACTER_AMLA
    amla_elynia_shielding_l5
    amla_elynia_shielding_l4
    attacks/magic-missile.png ( _ "Shielding V: protection ability")
    (
        [effect]
            apply_to=new_ability
            [abilities]
                {ABILITY_PROTECTION}
            [/abilities]
        [/effect]
    )}
#enddef

#
# THORNS UPGRADES
#

#define AMLA_ELYNIA_THORNS_L1
    {CHARACTER_AMLA
    amla_elynia_thorns_l1
    ()
    attacks/thorns.png ( _ "Thorns I: damage +2")
    (
        [effect]
            apply_to=attack
            name=thorns
            increase_damage=2
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_THORNS_L2
    {CHARACTER_AMLA
    amla_elynia_thorns_l2
    amla_elynia_thorns_l1
    attacks/thorns.png
    ( _ "Thorns II: damage +2, drains weapon special")
    (
        [effect]
            apply_to=attack
            name=thorns
            increase_damage=2
            [set_specials]
                mode=append
                {WEAPON_SPECIAL_DRAIN}
            [/set_specials]
        [/effect]
    )}
#enddef

#
# FAERIE FIRE UPGRADES
#
# Req.: Focus II, Strength II
# Req. for level IV: Focus III, Shielding III, Strength III
# Req. for level V: Focus IV, Shielding IV, Strength IV
#
# NOTE:
#
# The lvl 1 AMLA can be forcefully unlocked by a plot event in AtS E2S7. Since
# it would be cheap to allow people to unlock all subsequent upgrades without
# investing in the prerequisites at all, the lvl 2 AMLA has the same
# requirements and isn't unlocked by any plot events.
#

#define AMLA_ELYNIA_FAERIE_FIRE_L1
    {CHARACTER_AMLA
    amla_elynia_faerie_fire_l1
    amla_elynia_focus_l2,amla_elynia_strength_l2
    attacks/faerie-fire.png ( _ "Faerie Fire I: replaces mystic fire (ranged/arcane 9×3, magical)")
    (
        [effect]
            apply_to=remove_attacks
            name=mystic fire
        [/effect]
        [effect]
            apply_to=new_attack
            name=faerie fire
            description={TSTR_ATTACK_NAME_FAERIE_FIRE}
            type=arcane
            [specials]
                {WEAPON_SPECIAL_MAGICAL}
            [/specials]
            damage,number=9,3
            range=ranged
            icon=attacks/faerie-fire.png
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_FAERIE_FIRE_L2
    {CHARACTER_AMLA
    amla_elynia_faerie_fire_l2
    amla_elynia_faerie_fire_l1,amla_elynia_focus_l2,amla_elynia_strength_l2
    attacks/faerie-fire.png ( _ "Faerie Fire II: damage +1")
    (
        [effect]
            apply_to=attack
            name=faerie fire
            increase_damage=1
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_FAERIE_FIRE_L3
    {CHARACTER_AMLA
    amla_elynia_faerie_fire_l3
    amla_elynia_faerie_fire_l2
    attacks/faerie-fire.png ( _ "Faerie Fire III: strikes +1")
    (
        [effect]
            apply_to=attack
            name=faerie fire
            increase_attacks=1
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_FAERIE_FIRE_L4
    {CHARACTER_AMLA
    amla_elynia_faerie_fire_l4
    amla_elynia_faerie_fire_l3,amla_elynia_focus_l3,amla_elynia_shielding_l3,amla_elynia_strength_l3
    attacks/faerie-fire.png ( _ "Faerie Fire IV: damage +1")
    (
        [effect]
            apply_to=attack
            name=faerie fire
            increase_damage=1
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_FAERIE_FIRE_L5
    {CHARACTER_AMLA
    amla_elynia_faerie_fire_l5
    amla_elynia_faerie_fire_l4,amla_elynia_focus_l4,amla_elynia_shielding_l4,amla_elynia_strength_l4
    attacks/faerie-fire.png ( _ "Faerie Fire V: damage +1")
    (
        [effect]
            apply_to=attack
            name=faerie fire
            increase_damage=1
        [/effect]
    )}
#enddef

#
# AMLA sets
#

#define AMLA_TREE:ELYNIA_EPISODE_1
    {AMLA_ELYNIA_STRENGTH_L1}
    {AMLA_ELYNIA_STRENGTH_L2}
    {AMLA_ELYNIA_STRENGTH_L3}
    {AMLA_ELYNIA_FOCUS_L1}
    {AMLA_ELYNIA_FOCUS_L2}
    {AMLA_ELYNIA_SHIELDING_L1}
    {AMLA_ELYNIA_SHIELDING_L2}
    {AMLA_ELYNIA_FAERIE_FIRE_L1}
    {AMLA_ELYNIA_THORNS_L1}
    {AMLA_ELYNIA_THORNS_L2}
#ifdef CAMPAIGN_AFTER_THE_STORM_EPISODE_I
    {AMLA_TREE_LOCK amla_elynia_strength_l3,amla_elynia_focus_l2,amla_elynia_shielding_l2,amla_elynia_faerie_fire_l1,amla_elynia_thorns_l2}
#endif
#enddef

#define AMLA_TREE:ELYNIA_EPISODE_2
    {AMLA_ELYNIA_STRENGTH_L4}
    {AMLA_ELYNIA_STRENGTH_L5}
    {AMLA_ELYNIA_FOCUS_L3}
    {AMLA_ELYNIA_FOCUS_L4}
    {AMLA_ELYNIA_SHIELDING_L3}
    {AMLA_ELYNIA_FAERIE_FIRE_L2}
    {AMLA_ELYNIA_FAERIE_FIRE_L3}
#ifdef CAMPAIGN_AFTER_THE_STORM_EPISODE_II
    {AMLA_TREE_LOCK amla_elynia_strength_l5,amla_elynia_focus_l4,amla_elynia_shielding_l3,amla_elynia_faerie_fire_l3}
#endif
#enddef

#define AMLA_TREE:ELYNIA_EPISODE_3
    {AMLA_ELYNIA_SHIELDING_L4}
    {AMLA_ELYNIA_SHIELDING_L5}
    {AMLA_ELYNIA_FAERIE_FIRE_L4}
    {AMLA_ELYNIA_FAERIE_FIRE_L5}
#enddef


#textdomain wesnoth-After_the_Storm

#ifdef CAMPAIGN_AFTER_THE_STORM_EPISODE_III

#
# If you are not a maintainer of this campaign then you have no business being
# here.
#
# Turn back and forget you ever found this file.
#
#
#
# ...
#
#
#
# Are you still there?
#
#
#
# ...
#
#
#
# ...
#
#
#
# ...
#
#
#
# Look.
#
# I know lurking around for secrets is fun and all but you should know by now
# that only SPOILERS await those who have a look under the hood of story-based
# campaigns. You have one more chance to leave.
#
#
#
# ...
#
#
#
# ...
#
#
#
# ...
#
#
#
# Very well then.
#
# Don't say I didn't warn you.
#

#######################################################################
#                                                                     #
#           AMLA ABILITY AND WEAPON SPECIAL IMPLEMENTATIONS           #
#                                                                     #
#######################################################################

#
# Area of Effect damage weapon specials
#

#define NO_CROWD_CONTROL
    [+unit]
        [status]
            immune_to_cc=yes
        [/status]
    [/unit]
#enddef

#define NOT_IMMUNE_TO_CROWD_CONTROL
    [not]
        canrecruit=yes
        [or]
            type=Shaxthal Turret,Verlissh Matrix Flow System,Verlissh Matrix Core,Shaxthal Custodian Drone,Shaxthal Demolisher Drone,Shaxthal Deathbringer,Shaxthal Deathbringer Alpha,Magnum Suit,Blood Core,Angel of Blood
        [/or]
        [or]
            ability=absorb_damage
        [/or]
        [or]
            status=immune_to_cc
        [/or]
    [/not]
#enddef

#define WEAPON_SPECIAL_ABATTOIR
    [dummy]
        id=abattoir
        name= _ "abattoir"
        description= _ "On every hit, this attack deals 50% splash damage to all non-leader enemy units adjacent to the target. The exact amount of damage dealt will vary for each affected unit according to their resistances.

Note: Other units may be exempt from the effects of this weapon special."
    [/dummy]
#enddef

#define ENEMY_UNITS_ADJACENT_TO_UNIT_1
    [filter_adjacent]
        x,y=$x1,$y1
    [/filter_adjacent]

    [filter_side]
        [enemy_of]
            side=$unit.side
        [/enemy_of]
    [/filter_side]

    [not]
        x,y=$x2,$y2
    [/not]
#enddef

#define ENEMY_UNITS_ADJACENT_TO_UNIT_2
    [filter_adjacent]
        x,y=$x2,$y2
    [/filter_adjacent]

    [filter_side]
        [enemy_of]
            side=$unit.side
        [/enemy_of]
    [/filter_side]
#enddef

# NOTE: This macro is only intended to be used with [harm_unit]-based splash
#       damage abilities. If you decide to use it yourself, you're pretty much
#       required to read all my babbling below if you don't want things to
#       break or yield disappointing results.
#define UNIT_1_IS_FULLY_QUALIFIED_ATTACK_SOURCE
    # Credit the attack source in any events that may be fired if the harmed
    # unit dies (that being the only situation that fires events in 1.14, see
    # further below for more info).

    [filter_second]
        x,y=$x1,$y1
    [/filter_second]

    kill=yes
    fire_event=yes

    # [primary_attack] and [secondary_attack] are only relevant in 1.14 if
    # animations are enabled, since they aren't propagated to dispatched
    # events. We disable animations for this in practice to avoid attack
    # sequences becoming utterly clunky, so these are essentially a no-op at
    # the moment. But this may change in the future.

    [insert_tag]
        name=primary_attack
        variable="weapon"
    [/insert_tag]

    [insert_tag]
        name=secondary_attack
        variable="second_weapon"
    [/insert_tag]

    # Unfortunately, as of Wesnoth 1.14 [harm_unit] is implemented using an
    # all-or-nothing approach: either nobody gains XP, or both the attacker and
    # the targets do, once per command execution (and the command is going to
    # be executed multiple times during a single attack round!).
    #
    # More importantly, allowing Elynia and Elyssa's targets to gain XP from
    # being splash damaged means that the Guardian's XP gain control mechanism
    # doesn't trigger (fire_event above only concerns deaths in 1.14) and this
    # would potentially allow splash targets to gain levels mid-combat and make
    # everything messier.

    experience=no

    damage_type=$weapon.type
    alignment=$unit.alignment
#enddef

#define GU_SPECIAL_ATTACK_SEQ _SPECIAL_ID
    [event]
        id="gu_"+{_SPECIAL_ID}+":attacker_hits_1st" # wmllint: ignore
        name=attacker hits
        first_time_only=no
        [filter_attack]
            special={_SPECIAL_ID}
        [/filter_attack]

        {EVENT_FORWARD_DISPATCH ({_SPECIAL_ID}+" hits")}
    [/event]

    [event]
        id="gu_"+{_SPECIAL_ID}+":attacker_hits_2nd" # wmllint: ignore
        name=defender hits
        first_time_only=no
        [filter_second_attack]
            special={_SPECIAL_ID}
        [/filter_second_attack]

        {EVENT_INVERSE_DISPATCH ({_SPECIAL_ID}+" hits")}
    [/event]
#enddef

#define WEAPON_SPECIAL_ABATTOIR_EVENTS
    {GU_SPECIAL_ATTACK_SEQ abattoir}

    [event]
        id=gu_abattoir:main
        name=abattoir hits
        first_time_only=no
        [filter_condition]
            [have_unit]
                {ENEMY_UNITS_ADJACENT_TO_UNIT_2}

                {NOT_IMMUNE_TO_CROWD_CONTROL}
            [/have_unit]
        [/filter_condition]

        [harm_multiple_units]
            [filter]
                {ENEMY_UNITS_ADJACENT_TO_UNIT_2}

                {NOT_IMMUNE_TO_CROWD_CONTROL}
            [/filter]

            {UNIT_1_IS_FULLY_QUALIFIED_ATTACK_SOURCE}

            amount="$($weapon.damage * 0.5)"
        [/harm_multiple_units]
    [/event]
#enddef

#define WEAPON_SPECIAL_SHOCKWAVE
    [dummy]
        id=shockwave
        name= _ "shockwave"
        description= _ "On every hit, this attack deals 25% splash damage to all non-leader enemy units adjacent to the attacker. The exact amount of damage dealt will vary for each affected unit according to their resistances.

Note: Other units may be exempt from the effects of this weapon special."
    [/dummy]
#enddef

#define WEAPON_SPECIAL_SHOCKWAVE_EVENTS
    {GU_SPECIAL_ATTACK_SEQ shockwave}

    [event]
        id=gu_shockwave:main
        name=shockwave hits
        first_time_only=no
        [filter_condition]
            [have_unit]
                {ENEMY_UNITS_ADJACENT_TO_UNIT_1}

                {NOT_IMMUNE_TO_CROWD_CONTROL}
            [/have_unit]
        [/filter_condition]

        [harm_multiple_units]
            [filter]
                {ENEMY_UNITS_ADJACENT_TO_UNIT_1}

                {NOT_IMMUNE_TO_CROWD_CONTROL}
            [/filter]

            {UNIT_1_IS_FULLY_QUALIFIED_ATTACK_SOURCE}

            amount="$($weapon.damage * 0.25)"
        [/harm_multiple_units]
    [/event]
#enddef

#define UMBRA_TELEPORT_SOURCE_SLF
    terrain=*^V*
    [filter_owner]
        [allied_with]
            side=$teleport_unit.side
        [/allied_with]
    [/filter_owner]

    [not]
        [filter]
            [not]
                id=$teleport_unit.id
            [/not]
        [/filter]
    [/not]
#enddef

#define UMBRA_TELEPORT_TARGET_SLF
    [not]
        [filter]
        [/filter]
    [/not]
#enddef

#define ABILITY_UMBRA
    [dummy]
        id=umbra
        name= _ "umbra"
        description= _ "Using one of its moves, this unit may teleport between any two empty villages owned by its side or an ally, or from one such village to any vacant tiles adjacent to an allied leader."
    [/dummy]

    # TODO: merge both teleport setups together for performance?

    [teleport]
        id=umbra_super_teleport
        [tunnel]
            id=umbra_1
            [source]
                {UMBRA_TELEPORT_SOURCE_SLF}
            [/source]

            [target]
                {UMBRA_TELEPORT_TARGET_SLF}

                [and]
                    terrain=*^V*
                    [filter_owner]
                        [allied_with]
                            side=$teleport_unit.side
                        [/allied_with]
                    [/filter_owner]

                    [or]
                        [filter_adjacent_location]
                            [filter]
                                canrecruit=yes
                                [filter_side]
                                    [allied_with]
                                        side=$teleport_unit.side
                                    [/allied_with]
                                [/filter_side]
                            [/filter]
                        [/filter_adjacent_location]
                    [/or]
                [/and]
            [/target]

            [filter]
                ability=umbra_super_teleport
            [/filter]
        [/tunnel]
    [/teleport]
#enddef

#define FINALE_AMLA_EVENTS
    {WEAPON_SPECIAL_ABATTOIR_EVENTS}

    {WEAPON_SPECIAL_SHOCKWAVE_EVENTS}
#enddef

#######################################################################
#                                                                     #
#                   ELYNIA GoE AMLA DEFINITIONS                       #
#                                                                     #
#######################################################################

#define AMLA_ELYNIA_STRENGTH_X
    {CHARACTER_AMLA
    amla_elynia_strength_l10
    ()
    attacks/touch-faerie.png ( _ "Strength X: hitpoints +10, melee strikes +1")
    (
        [effect]
            apply_to=hitpoints
            increase=10
            increase_total=10
        [/effect]
        [effect]
            apply_to=attack
            range=melee
            increase_attacks=1
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_STRENGTH_XI
    {CHARACTER_AMLA
    amla_elynia_strength_l11
    amla_elynia_strength_l10
    attacks/touch-faerie.png ( _ "Strength XI: hitpoints +10, melee damage +1")
    (
        [effect]
            apply_to=hitpoints
            increase=10
            increase_total=10
        [/effect]
        [effect]
            apply_to=attack
            range=melee
            increase_damage=1
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_STRENGTH_XII
    {CHARACTER_AMLA
    amla_elynia_strength_l12
    amla_elynia_strength_l11
    attacks/touch-faerie.png ( _ "Strength XII: hitpoints +11, melee damage +1")
    (
        [effect]
            apply_to=hitpoints
            increase=11
            increase_total=11
        [/effect]
        [effect]
            apply_to=attack
            range=melee
            increase_damage=1
        [/effect]
    )}
#enddef

# The Earth sigil
#define AMLA_ELYNIA_FOCUS_X_ICON
icons/original-ten-sigils.png~CROP(180, 0, 60, 60)#enddef

#define AMLA_ELYNIA_FOCUS_X
    {CHARACTER_AMLA
    amla_elynia_focus_l10
    ()
    {AMLA_ELYNIA_FOCUS_X_ICON} ( _ "Focus X: arcane rage damage +1")
    (
        [effect]
            apply_to=attack
            name=arcane rage
            increase_damage=1
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_FOCUS_XI
    {CHARACTER_AMLA
    amla_elynia_focus_l11
    amla_elynia_focus_l10
    {AMLA_ELYNIA_FOCUS_X_ICON} ( _ "Focus XI: ensnare damage +1")
    (
        [effect]
            apply_to=attack
            name=ensnare
            increase_damage=1
            [set_specials]
                mode=append
            [/set_specials]
        [/effect]
    )}
#enddef

#define AMLA_ELYNIA_FOCUS_XII
    {CHARACTER_AMLA
    amla_elynia_focus_l12
    amla_elynia_focus_l11
    {AMLA_ELYNIA_FOCUS_X_ICON} ( _ "Focus XII: arcane rage strikes +1")
    (
        [effect]
            apply_to=attack
            name=arcane rage
            increase_attacks=1
        [/effect]
    )}
#enddef

# Gate Nature's Wrath behind Focus X to force Elynia to lag behind Elyssa
# stats-wise for just a little bit.
#define AMLA_ELYNIA_NATURES_WRATH
    {CHARACTER_AMLA
    amla_elynia_natures_wrath
    amla_elynia_focus_l10
    attacks/arcane-rage.png ( _ "Nature’s Wrath: arcane rage shockwave special")
    (
        [effect]
            apply_to=attack
            name=arcane rage
            [set_specials]
                mode=append
                {WEAPON_SPECIAL_SHOCKWAVE}
            [/set_specials]
        [/effect]
    )}
#enddef

#######################################################################
#                                                                     #
#                   ELYSSA GoD AMLA DEFINITIONS                       #
#                                                                     #
#######################################################################

#define AMLA_DELETE
    [advancement]
        __remove=yes
    [/advancement]
#enddef

#define AMLA_ELYSSA_STRENGTH_X
    {CHARACTER_AMLA
    amla_elyssa_strength_l10
    ()
    attacks/fist-human.png ( _ "Strength ?: hitpoints +12")
    (
        [effect]
            apply_to=hitpoints
            increase=12
            increase_total=12
        [/effect]
    )}
#enddef

#define AMLA_ELYSSA_STRENGTH_XI
    {CHARACTER_AMLA
    amla_elyssa_strength_l11
    amla_elyssa_strength_l10
    attacks/fist-human.png ( _ "Strength ?: hitpoints +10, melee damage +1")
    (
        [effect]
            apply_to=hitpoints
            increase=10
            increase_total=10
        [/effect]
        [effect]
            apply_to=attack
            range=melee
            increase_damage=1
        [/effect]
    )}
#enddef

#define AMLA_ELYSSA_STRENGTH_XII
    {CHARACTER_AMLA
    amla_elyssa_strength_l12
    amla_elyssa_strength_l11
    attacks/fist-human.png ( _ "Strength ?: hitpoints +16, melee damage +1")
    (
        [effect]
            apply_to=hitpoints
            increase=16
            increase_total=16
        [/effect]
        [effect]
            apply_to=attack
            range=melee
            increase_damage=1
        [/effect]
    )}
#enddef

#define AMLA_ELYSSA_STRENGTH_XIII
    {CHARACTER_AMLA
    amla_elyssa_strength_l13
    amla_elyssa_strength_l12
    attacks/fist-human.png ( _ "Strength ?: melee strikes +1")
    (
        [effect]
            apply_to=attack
            range=melee
            increase_attacks=1
        [/effect]
    )}
#enddef

# The Darkness sigil
#define AMLA_ELYSSA_FOCUS_X_ICON
icons/original-ten-sigils.png~CROP(0,60,60,60)#enddef

#define AMLA_ELYSSA_FOCUS_X
    {CHARACTER_AMLA
    amla_elyssa_focus_l10
    ()
    {AMLA_ELYSSA_FOCUS_X_ICON} ( _ "Focus ?: pyranoctum strikes +1")
    (
        [effect]
            apply_to=attack
            name=pyranoctum
            increase_attacks=1
        [/effect]
    )}
#enddef

#define AMLA_ELYSSA_FOCUS_XI
    {CHARACTER_AMLA
    amla_elyssa_focus_l11
    amla_elyssa_focus_l10
    {AMLA_ELYSSA_FOCUS_X_ICON} ( _ "Focus ?: noctum damage +1, pyranoctum damage +2")
    (
        [effect]
            apply_to=attack
            name=noctum
            increase_damage=1
        [/effect]
        [effect]
            apply_to=attack
            name=pyranoctum
            increase_damage=2
        [/effect]
    )}
#enddef

#define AMLA_ELYSSA_ARGANS_LAMENT
    {CHARACTER_AMLA
    amla_elyssa_argans_lament
    ()
    attacks/gaze.png ( _ "Argan’s Lament: terror ability")
    (
        [effect]
            apply_to=new_ability
            [abilities]
                {ABILITY_TERROR}
            [/abilities]
        [/effect]
    )}
#enddef

# This is a very intentional clone of Galas' Initiative AMLA
# FIXME: placeholder icon
#define AMLA_ELYSSA_INITIATIVE
    {CHARACTER_AMLA
    amla_elyssa_strength_initiative
    ()
    attacks/staff-elven-star.png ( _ "Initiative: claw of urvatha first strike weapon special")
    (
        [effect]
            apply_to=attack
            name=claw of urvatha
            [set_specials]
                mode=append
                {WEAPON_SPECIAL_FIRSTSTRIKE}
            [/set_specials]
        [/effect]
    )}
#enddef

#define AMLA_ELYSSA_SOUL_EATER
    {CHARACTER_AMLA
    amla_elyssa_soul_eater
    ()
    icons/soul-eater.png ( _ "Soul Eater: claw of urvatha drains special")
    (
        [effect]
            apply_to=attack
            name=claw of urvatha
            [set_specials]
                mode=append
                {WEAPON_SPECIAL_DRAIN}
            [/set_specials]
        [/effect]
    )}
#enddef

#define AMLA_ELYSSA_SCORCHED_EARTH
    {CHARACTER_AMLA
    amla_elyssa_scorched_earth
    ()
    attacks/fire-blast.png ( _ "Scorched Earth: pyranoctum abattoir special")
    (
        [effect]
            apply_to=attack
            name=pyranoctum
            [set_specials]
                mode=append
                {WEAPON_SPECIAL_ABATTOIR}
            [/set_specials]
        [/effect]
    )}
#enddef

#define AMLA_ELYSSA_MERTHIAALS_DESPAIR
    {CHARACTER_AMLA
    amla_elyssa_merthiaals_despair
    ()
    attacks/fire-blast.png ( _ "Merthiaal’s Despair: noctum shockwave special")
    (
        [effect]
            apply_to=attack
            name=noctum
            [set_specials]
                mode=append
                {WEAPON_SPECIAL_SHOCKWAVE}
            [/set_specials]
        [/effect]
    )}
#enddef

#######################################################################
#                                                                     #
#                    ANYA GoD AMLA DEFINITIONS                        #
#                                                                     #
#######################################################################

# Anya's AMLAs are more limited in comparison to the other two since she's only
# playable for one scenario and doesn't face any enemies able to kill her. The
# player also has bigger numbers on their side than Elynia and Elyssa.

#define AMLA_ANYA_STRENGTH_X
    {CHARACTER_AMLA
    amla_anya_strength_l10
    ()
    attacks/touch-faerie.png ( _ "Strength X: hitpoints +10, melee strikes +1")
    (
        [effect]
            apply_to=hitpoints
            increase=10
            increase_total=10
        [/effect]
        [effect]
            apply_to=attack
            range=melee
            increase_attacks=1
        [/effect]
    )}
#enddef

#define AMLA_ANYA_STRENGTH_XI
    {CHARACTER_AMLA
    amla_anya_strength_l11
    amla_anya_strength_l10
    attacks/fist-human.png ( _ "Strength XI: hitpoints +12")
    (
        [effect]
            apply_to=hitpoints
            increase=12
            increase_total=12
        [/effect]
    )}
#enddef

#define AMLA_ANYA_SHIELDING_X
    {CHARACTER_AMLA
    amla_anya_shielding_l10
    ()
    attacks/magic-missile.png ( _ "Shielding X: impact resistance +10%, fire resistance +10%")
    (
        [effect]
            apply_to=resistance
            replace=no
            [resistance]
                impact=-10
                fire=-10
            [/resistance]
        [/effect]
    )}
#enddef

#define AMLA_ANYA_SHADOW_ANGEL
    {CHARACTER_AMLA
    amla_anya_shadow_angel
    ()
    icons/umbra.png ( _ "Shadow Angel: umbra teleport ability")
    (
        [effect]
            apply_to=remove_ability
            [abilities]
                {ABILITY_TELEPORT}
            [/abilities]
        [/effect]
        [effect]
            apply_to=new_ability
            [abilities]
                {ABILITY_UMBRA}
            [/abilities]
        [/effect]
    )}
#enddef

#######################################################################
#                                                                     #
#                         AMLA TREE MACROS                            #
#                                                                     #
#######################################################################

#define AMLA_TREE:ELYNIA_GUARDIAN
    {AMLA_ELYNIA_STRENGTH_X}
    {AMLA_ELYNIA_STRENGTH_XI}
    {AMLA_ELYNIA_STRENGTH_XII}
    {AMLA_ELYNIA_FOCUS_X}
    {AMLA_ELYNIA_FOCUS_XI}
    {AMLA_ELYNIA_FOCUS_XII}
    {AMLA_ELYNIA_NATURES_WRATH}
#enddef

#define AMLA_TREE:ELYSSA_GUARDIAN
    # 11 AMLAs total
    {AMLA_ELYSSA_STRENGTH_X}
    {AMLA_ELYSSA_STRENGTH_XI}
    {AMLA_ELYSSA_STRENGTH_XII}
    {AMLA_ELYSSA_STRENGTH_XIII}
    {AMLA_ELYSSA_FOCUS_X}
    {AMLA_ELYSSA_FOCUS_XI}
    {AMLA_ELYSSA_ARGANS_LAMENT}
    {AMLA_ELYSSA_INITIATIVE}
    {AMLA_ELYSSA_SOUL_EATER}
    {AMLA_ELYSSA_SCORCHED_EARTH}
    {AMLA_ELYSSA_MERTHIAALS_DESPAIR}
#enddef

#define AMLA_TREE:ELYSSA_GUARDIAN:DELETE
    {AMLA_DELETE}
    {AMLA_DELETE}
    {AMLA_DELETE}
    {AMLA_DELETE}
    {AMLA_DELETE}
    {AMLA_DELETE}
    {AMLA_DELETE}
    {AMLA_DELETE}
    {AMLA_DELETE}
    {AMLA_DELETE}
    {AMLA_DELETE}
#enddef

#define AMLA_TREE:ANYA_GUARDIAN
    {AMLA_ANYA_STRENGTH_X}
    {AMLA_ANYA_STRENGTH_XI}
    {AMLA_ANYA_SHIELDING_X}
    # GLITCHES WHEN UNIT STOPS BEING ON THE MAP, DO NOT USE
    #{AMLA_ANYA_SHADOW_ANGEL}
#enddef

#endif


#textdomain wesnoth-After_the_Storm

#
# ABILITY UPGRADES
#
# Req.: none
#

#define AMLA_GALAS_STEALTH
    {CHARACTER_AMLA
    amla_galas_stealth
    ()
    icons/cloak_leather_brown.png ( _ "Stealth: ambush ability")
    (
        [effect]
            apply_to=new_ability
            [abilities]
                {ABILITY_AMBUSH}
            [/abilities]
        [/effect]
    )}
#enddef

#define AMLA_GALAS_HUNTER_I
    {CHARACTER_AMLA
    amla_galas_hunter_l1
    ()
    attacks/bolas.png ( _ "Hunter I: new attack (ranged/impact 9×2, slows)")
    (
        [effect]
            apply_to=new_attack
            name=bolas
            description= _"bolas"
            type=impact
            range=ranged
            damage=9
            number=2
            [specials]
                {WEAPON_SPECIAL_SLOW}
            [/specials]
        [/effect]
    )}
#enddef

#define AMLA_GALAS_HUNTER_II
    {CHARACTER_AMLA
    amla_galas_hunter_l2
    amla_galas_hunter_l1
    attacks/bolas.png ( _ "Hunter II: bolas strikes +1")
    (
        [effect]
            apply_to=attack
            name=bolas
            increase_attacks=1
        [/effect]
    )}
#enddef

#
# STRENGTH UPGRADES
#
# Req.: none
#

#define AMLA_GALAS_STRENGTH_L1
    {CHARACTER_AMLA
    amla_galas_strength_l1
    ()
    attacks/sword-elven.png ( _ "Strength I: melee damage +1")
    (
        [effect]
            apply_to=attack
            range=melee
            increase_damage=1
        [/effect]
    )}
#enddef

#define AMLA_GALAS_STRENGTH_L2
    {CHARACTER_AMLA
    amla_galas_strength_l2
    amla_galas_strength_l1
    attacks/sword-elven.png ( _ "Strength II: hitpoints +4, melee strikes +1")
    (
        [effect]
            apply_to=hitpoints
            increase=4
            increase_total=4
        [/effect]
        [effect]
            apply_to=attack
            range=melee
            increase_attacks=1
        [/effect]
    )}
#enddef

#define AMLA_GALAS_STRENGTH_L3
    {CHARACTER_AMLA
    amla_galas_strength_l3
    amla_galas_strength_l2
    attacks/sword-elven.png ( _ "Strength III: hitpoints +5")
    (
        [effect]
            apply_to=hitpoints
            increase=5
            increase_total=5
        [/effect]
    )}
#enddef

#define AMLA_GALAS_STRENGTH_FURY
    {CHARACTER_AMLA
    amla_galas_strength_fury
    amla_galas_strength_l2
    attacks/frenzy.png ( _ "Fury: berserker weapon special (melee only)")
    (
        [effect]
            apply_to=attack
            range=melee
            [set_specials]
                mode=append
                {WEAPON_SPECIAL_BERSERK}
            [/set_specials]
        [/effect]
    )}
    {DISABLE_AMLA_WITH amla_galas_strength_initiative}
#enddef

#define AMLA_GALAS_STRENGTH_INITIATIVE
    {CHARACTER_AMLA
    amla_galas_strength_initiative
    amla_galas_strength_l2
    icons/hat-huntsman.png ( _ "Initiative: first strike weapon special (melee only)")
    (
        [effect]
            apply_to=attack
            range=melee
            [set_specials]
                mode=append
                {WEAPON_SPECIAL_FIRSTSTRIKE}
            [/set_specials]
        [/effect]
    )}
    {DISABLE_AMLA_WITH amla_galas_strength_fury}
#enddef

#
# ARMOUR UPGRADES
#
# Req.: none
#

#define AMLA_GALAS_ARMOR_L1
    {CHARACTER_AMLA
    amla_galas_armor_l1
    ()
    icons/armor-chain.png ( _ "Armor I: blade and pierce resistance +10%")
    (
        [effect]
            apply_to=resistance
            replace=no
            [resistance]
                blade=-10
                pierce=-10
            [/resistance]
        [/effect]
    )}
#enddef

#define AMLA_GALAS_ARMOR_L2
    {CHARACTER_AMLA
    amla_galas_armor_l2
    amla_galas_armor_l1
    icons/armor-chain.png ( _ "Armor II: impact resistance +10%")
    (
        [effect]
            apply_to=resistance
            replace=no
            [resistance]
                impact=-10
            [/resistance]
        [/effect]
    )}
#enddef

#define AMLA_GALAS_ARMOR_L3
    {CHARACTER_AMLA
    amla_galas_armor_l3
    amla_galas_armor_l2
    icons/armor-chain.png ( _ "Armor III: blade resistance +10%")
    (
        [effect]
            apply_to=resistance
            replace=no
            [resistance]
                blade=-10
            [/resistance]
        [/effect]
    )}
#enddef

#define AMLA_TREE:GALAS_EPISODE_1
    {AMLA_GALAS_STRENGTH_L1}
    {AMLA_GALAS_STRENGTH_L2}
    {AMLA_GALAS_STRENGTH_L3}
    {AMLA_GALAS_STRENGTH_FURY}
    {AMLA_GALAS_STRENGTH_INITIATIVE}
    {AMLA_GALAS_ARMOR_L1}
    {AMLA_GALAS_ARMOR_L2}
    {AMLA_GALAS_ARMOR_L3}
    {AMLA_GALAS_STEALTH}
    {AMLA_GALAS_HUNTER_I}
    {AMLA_GALAS_HUNTER_II}
    # NOTE:
    # We can't list fury or initiative here because it's not normally possible
    # to obtain both and there's no way to have an OR match in require_amla
    {AMLA_TREE_LOCK amla_galas_strength_l3,amla_galas_stealth,amla_galas_armor_l3,amla_galas_hunter_l2}
#enddef


#textdomain wesnoth-After_the_Storm

# wmllint: local spelling ‹max

# This is a fake AMLA displayed when the character's full AMLA tree is not
# available yet but all the episode-specific AMLAs have already been acquired.
# It doesn't have any effects other than causing the level-up prompt to display
# again until the player selects a different option.
#
# NOTE: Naia's implementation of [amla_list] has special knowledge of the id of
# this AMLA and uses it for influence the UI display. If you change the AMLA id
# here, you need to update Naia as well.
#define AMLA_TREE_LOCK _REQUIRED_AMLAS
    [advancement]
        id=amla_tree_lock_ui
        description= _ "‹No more advancements available yet›"
        image="misc/blank-hex.png~SCALE(60,60)"
        max_times=1
        # Unfortunately there's no way for us to require "all available AMLAs except amla_vitality", so
        # we require users to tell us the full list of unlocks for the current state here
        require_amla={_REQUIRED_AMLAS}
        [effect]
            apply_to=status
            add=amla_tree_lock_ui
        [/effect]
    [/advancement]
#enddef

#define AMLA_UI_HANDLER
    [event]
        id=amla_ui_handler_event
        name=post advance
        first_time_only=no
        [filter]
            status=amla_tree_lock_ui
        [/filter]

        # Revert dummy AMLA and set the unit's XP to maximum to return to the
        # level-up UI after we're done.

        {CLEAR_VARIABLE unit.status.amla_tree_lock_ui}
        {VARIABLE unit.experience $unit.max_experience}

        # We need to excise the AMLA by hand. Using wesnoth.remove_modifications
        # on Wesnoth 1.14.9 (and presumably earlier versions as well) can cause
        # unexpected recalculation of the unit's stats based on how traits and
        # objects would interact with AMLAs, when they normally *do not*. This
        # causes, e.g. Elynia's faerie fire addition to be boosted by the first
        # call to wesnoth.remove_modifications.

        {VARIABLE cleared_amla no}

        [for]
            array=unit.modifications.advancement
            reverse=yes
            [do]
                [if]
                    {VARIABLE_LEXICAL_EQUALS unit.modifications.advancement[$i].id amla_tree_lock_ui}
                    [then]
                        {CLEAR_VARIABLE unit.modifications.advancement[$i]}

                        {VARIABLE cleared_amla yes}

                        [break][/break]
                    [/then]
                [/if]
            [/do]
        [/for]

        {BUG_ON ({VARIABLE_BOOLEAN_NOT_EQUALS cleared_amla yes}) ()}

        {CLEAR_VARIABLE cleared_amla}

        {LOG_ATS ("[AMLA_TREE_LOCK_UI] Dummy advancement triggered and reverted")}

        [transient_message]
            caption= _ "Advancements Locked"
            message= _ "You have not unlocked all advancements for this unit yet. Continue playing the campaign to unlock more advancements."
        [/transient_message]

        # NOTE: The event handler may become recursive here if the player selects the
        #       dummy AMLA again.

        [unstore_unit]
            variable=unit
            find_vacant=no
        [/unstore_unit]
    [/event]
#enddef

#define AMLA_DEBUG_UI
    [set_menu_item]
        id=amla_debug
        description="I Hate Fun" # wmllint: ignore

        [filter_location]
            [filter]
                side=1
            [/filter]
        [/filter_location]

        [command]
            [store_unit]
                [filter]
                    x,y=$x1,$y1
                [/filter]
                variable=u
            [/store_unit]

            {VARIABLE u.experience $u.max_experience}

            [unstore_unit]
                variable=u
                find_vacant=no
            [/unstore_unit]

            {CLEAR_VARIABLE u}

            [unit]
                side=1
                x,y=recall,recall
                type=Yeti
            [/unit]
        [/command]
    [/set_menu_item]
#enddef

#
# Cap a unit's maximum XP to a certain value at the start of an episode.
#
# If the unit's XP pool is greater than the specified amount, then it's
# forcefully capped with a hidden modification. Otherwise, it's left intact.
#
#define AMLA_XP_CAP _ID _MAX_XP
    [store_unit]
        [filter]
            id={_ID}
        [/filter]
        variable=temp_AXC.u
        kill=no
    [/store_unit]

    {VARIABLE_FROM_STRLEN temp_AXC.can_advance $temp_AXC.u.advances_to}

    [if]
        {VARIABLE_NUMERICAL_EQUALS temp_AXC.can_advance 0}
        [then]
            {VARIABLE temp_AXC.diff "$( {_MAX_XP} - $temp_AXC.u.max_experience )"}

            [if]
                {VARIABLE_NUMERICAL_LESS_THAN temp_AXC.diff 0}
                [then]
                    [object]
                        [filter]
                            id={_ID}
                        [/filter]

                        [effect]
                            apply_to=max_experience
                            increase=$temp_AXC.diff
                        [/effect]
                    [/object]
                [/then]
            [/if]
        [/then]
    [/if]

    #
    # Scale current XP to match the old status. We do this regardless of whether the
    # unit has unit type advancements or not (Durvan).
    #

    [if]
        {VARIABLE_NUMERICAL_NOT_EQUALS temp_AXC.u.variables.amla_xp_cap_old_ratio 0}
        [then]
            # Need to use [store_unit] to properly clear off the ratio attribute
            [store_unit]
                [filter]
                    id={_ID}
                [/filter]
                variable=temp_AXC.v
            [/store_unit]

            # Cap to max XP minus one to avoid awkward appearances of the
            # level up dialog, e.g. during cutscenes.
            {VARIABLE temp_AXC.v.experience "$(
                min(xp_pool - 1, round(xp_ratio * xp_pool)) where
                    xp_ratio = $temp_AXC.u.variables.amla_xp_cap_old_ratio,
                    xp_pool = $temp_AXC.v.max_experience
            )"}
            {CLEAR_VARIABLE temp_AXC.v.variables.amla_xp_cap_old_ratio}

            [unstore_unit]
                variable=temp_AXC.v
                find_vacant=no
            [/unstore_unit]
        [/then]
    [/if]

    {CLEAR_VARIABLE temp_AXC}
#enddef

#define AMLA_XP_CAP_TIER_2 _ID
    {AMLA_XP_CAP {_ID} {DIFF 125 150 175}}
#enddef

#define AMLA_XP_CAP_TIER_3 _ID
    {AMLA_XP_CAP {_ID} {DIFF 175 200 225}}
#enddef


#textdomain wesnoth-After_the_Storm

#define FLAME_BLAST_FRAME _NUM _START_TIME _X _Y
    flame_blast_{_NUM}_start_time={_START_TIME}
    flame_blast_{_NUM}_auto_vflip=no
    flame_blast_{_NUM}_offset=1.0
    [flame_blast_{_NUM}_frame]
        halo="halo/flame-burst-[1~8].png:50"
        halo_x={_X}
        halo_y={_Y}
    [/flame_blast_{_NUM}_frame]
#enddef

#define FLAME_BLAST_ANIMATION
    offset=0.0

    flame_sound_start_time=-400
    [flame_sound_frame]
        duration=100
        sound=fire.wav
    [/flame_sound_frame]

    {FLAME_BLAST_FRAME 1 -400 -22   0}

    {FLAME_BLAST_FRAME 2 -350 -14   9}

    {FLAME_BLAST_FRAME 3 -300   0  12}

    {FLAME_BLAST_FRAME 4 -250  14   9}

    {FLAME_BLAST_FRAME 5 -200  22   0}
#enddef

#define FLAME_BLAST_AFFECTS_SELF
    flame_blast_1_offset=0.0
    flame_blast_2_offset=0.0
    flame_blast_3_offset=0.0
    flame_blast_4_offset=0.0
    flame_blast_5_offset=0.0
#enddef

#define STORMKIND_ATTACK_HALO
    halo1_start_time=-400
    halo1_auto_vflip=false
    [halo1_frame]
        halo="halo/saurian-magic-halo-[1~7].png:100"
        halo_y=-15
    [/halo1_frame]

    halo2_start_time=-450
    halo2_auto_vflip=false
    [halo2_frame]
        halo="halo/saurian-magic-halo-[7~1].png:100"
        halo_y=0
    [/halo2_frame]

    halo3_start_time=-400
    halo3_auto_vflip=false
    [halo3_frame]
        halo="halo/saurian-magic-halo-[1~7].png:100"
        halo_y=15
    [/halo3_frame]
#enddef

#define NOCTUM_FIRE_ANIMATION
    {FLAME_BLAST_ANIMATION}

    flame_blast_1_halo_mod="~B(120)"
    flame_blast_2_halo_mod="~B(120)"
    flame_blast_3_halo_mod="~B(120)"
    flame_blast_4_halo_mod="~B(120)"
    flame_blast_5_halo_mod="~B(120)"
#enddef

#define NOCTUM_BOLT_ANIMATION _N1 _N2
    bolt1_auto_vflip=no
    bolt1_start_time=-175
    bolt1_offset=1.0
    bolt1_halo_y=-125
    bolt1_halo_mod="~R(120)"

    [bolt1_frame]
        halo="halo/lightning-bolt-"+{_N1}+"-3.png:100,halo/lightning-bolt-"+{_N1}+"-4.png:100"
    [/bolt1_frame]

    bolt2_auto_vflip=no
    bolt2_start_time=-100
    bolt2_offset=1.0
    bolt2_halo_y=-125
    bolt2_halo_mod="~R(120)"

    [bolt2_frame]
        halo="halo/lightning-bolt-"+{_N2}+"-4.png:100,halo/lightning-bolt-"+{_N2}+"-4.png~O(0.5):100"
    [/bolt2_frame]

    {SOUND:HIT_AND_MISS lightning.ogg lightning-miss.ogg -175}
#enddef

#define BLOOD_BOLT_ANIMATION _N1 _N2
    {NOCTUM_BOLT_ANIMATION ({_N1}) ({_N2})}

    #bolt1_halo_mod="~CS(120,-64,-64)" purple
    #bolt2_halo_mod="~CS(120,-64,-64)" purple

    bolt1_halo_mod="~CS(255,-32,-32)"
    bolt2_halo_mod="~CS(255,-32,-32)"
#enddef

#define GUARDIAN_DEFENSE_ANIM R G B REACTION_IMAGE BASE_IMAGE HIT_SOUND
    [defend]
        start_time=-175
        [frame]
            duration=25
            image={BASE_IMAGE}
            halo="halo/guardian-defense-halo.png"
            halo_mod="~CS({R},{G},{B})~O(0.2)"
        [/frame]
        [frame]
            duration=25
            image={BASE_IMAGE}
            halo="halo/guardian-defense-halo.png"
            halo_mod="~CS({R},{G},{B})~O(0.4)"
        [/frame]
        [frame]
            duration=50
            image={REACTION_IMAGE}
            halo="halo/guardian-defense-halo.png"
            halo_mod="~CS({R},{G},{B})~O(0.6)"
        [/frame]
        [frame]
            duration=50
            image={REACTION_IMAGE}
            halo="halo/guardian-defense-halo.png"
            halo_mod="~CS({R},{G},{B})~O(0.8)"
        [/frame]
        [if]
            hits=hit
            [frame]
                duration=100
                image={REACTION_IMAGE}
                sound={HIT_SOUND}
                halo="halo/guardian-defense-halo.png"
                halo_mod="~CS({R},{G},{B})"
            [/frame]
        [/if]
        [else]
            hits=miss,kill
            [frame]
                duration=100
                image={REACTION_IMAGE}
                halo="halo/guardian-defense-halo.png"
                halo_mod="~CS({R},{G},{B})"
            [/frame]
        [/else]
        [frame]
            duration=50
            image={REACTION_IMAGE}
            halo="halo/guardian-defense-halo.png"
            halo_mod="~CS({R},{G},{B})~O(0.8)"
        [/frame]
        [frame]
            duration=25
            image={BASE_IMAGE}
            halo="halo/guardian-defense-halo.png"
            halo_mod="~CS({R},{G},{B})~O(0.6)"
        [/frame]
        [frame]
            duration=25
            image={BASE_IMAGE}
            halo="halo/guardian-defense-halo.png"
            halo_mod="~CS({R},{G},{B})~O(0.4)"
        [/frame]
        [frame]
            duration=25
            image={BASE_IMAGE}
            halo="halo/guardian-defense-halo.png"
            halo_mod="~CS({R},{G},{B})~O(0.2)"
        [/frame]
    [/defend]
#enddef

#define BLOOD_LASER_BEAM
    laser_start_time=-245

    [if]
        direction=se,sw,ne,nw
        [laser_frame]
            halo="halo/blood-laser-ne-[1~7,6~1].png:[30*6,130,70*6]"
            halo_x,halo_y=20,-10
        [/laser_frame]
    [/if]
    [else]
        direction=n,s
        [laser_frame]
            halo="halo/blood-laser-n-[1~7,6~1].png:[30*6,130,70*6]"
            halo_x,halo_y=20,-10
        [/laser_frame]
    [/else]
#enddef

#define BLOOD_STORM_ANIMATION _BOLT_N1 _BOLT_N2
    [attack_anim]
        [filter_attack]
            name=blood storm
        [/filter_attack]
        start_time=-400
        offset=0.0

        {BLOOD_BOLT_ANIMATION {_BOLT_N1} {_BOLT_N2} }

        [frame]
            duration=600
        [/frame]
    [/attack_anim]
#enddef

#define SOUL_SPEAR_ANIMATION
    [attack_anim]
        [filter_attack]
            name=soul spear
        [/filter_attack]
        [frame]
            begin=-250
            end=-125
        [/frame]
        [if]
            hits=yes
            [frame]
                begin=-125
                end=-100
                sound=magic-dark.ogg
            [/frame]
            [frame]
                begin=-100
                end=100
                sound=spear.ogg
            [/frame]
        [/if]
        [else]
            hits=no
            [frame]
                begin=-125
                end=-100
            [/frame]
            [frame]
                begin=-100
                end=100
                sound=spear-miss.ogg
            [/frame]
        [/else]
        [frame]
            begin=100
            end=175
        [/frame]
    [/attack_anim]
#enddef

#
# UtBS Quenoth elf animation macros
#

#define QUENOTH_FLAME_INTERNAL X Y Y2
misc/blank-hex.png~BLIT(units/elves-quenoth/fire/flame-color.png,{X},{Y2})~MASK(units/elves-quenoth/fire/flame-mask.png,{X},{Y}):75#enddef

#define QUENOTH_FLAME_POS X Y
    {QUENOTH_FLAME_INTERNAL {X} {Y} 15},
    {QUENOTH_FLAME_INTERNAL {X} {Y} 14},
    {QUENOTH_FLAME_INTERNAL {X} {Y} 13},
    {QUENOTH_FLAME_INTERNAL {X} {Y} 12},
    {QUENOTH_FLAME_INTERNAL {X} {Y} 11},
    {QUENOTH_FLAME_INTERNAL {X} {Y} 10},
    {QUENOTH_FLAME_INTERNAL {X} {Y} 9},
    {QUENOTH_FLAME_INTERNAL {X} {Y} 8},
    {QUENOTH_FLAME_INTERNAL {X} {Y} 7},
    {QUENOTH_FLAME_INTERNAL {X} {Y} 6},
    {QUENOTH_FLAME_INTERNAL {X} {Y} 5},
{QUENOTH_FLAME_INTERNAL {X} {Y} 4}#enddef

# not all unwalkable, but still supposed to provide some visual cue that movement is different.  may need revision.
#define QUENOTH_UNWALKABLE_TERRAINS
!,Wwf*^*,Kme*^*,*^B*,!,A*^*,Uu*^*,Uh*^*,*^Uf*,W*^*,S*^*,Chs*^*,Chw*^*,Cm*^*,Km*^*,Q*^*,Mv*^*,*^Qov,*^Vm#enddef


#textdomain wesnoth-After_the_Storm

#define BOSS_ABSORB_FULL_DAMAGE _STANDARD_UNIT_FILTER
    [store_unit]
        [filter]
            {_STANDARD_UNIT_FILTER}
        [/filter]
        variable=temp_BOSS_ABSORB_DAMAGE_store
    [/store_unit]

    # Emulate a blinking effect using timing and unit clobbering
    [object]
        [filter]
            id=$temp_BOSS_ABSORB_DAMAGE_store.id
        [/filter]

        [effect]
            apply_to=image_mod
            add="BLEND(255,170,0,0.25)"
        [/effect]
    [/object]

    {VARIABLE temp_BOSS_ABSORB_DAMAGE_store.hitpoints $temp_BOSS_ABSORB_DAMAGE_store.max_hitpoints}

    # FIXME: Clearing statuses on attack/defender hits is impossible in 1.14
    #        because their flags are set *after* handling the event
#ifdef 0
    [if]
        # Don't use VARIABLE_BOOLEAN_NOT_EQUALS, the variable may not exist
        {VARIABLE_BOOLEAN_EQUALS temp_BOSS_ABSORB_DAMAGE_store.status.slowed_by_api yes}
        [else]
            {CLEAR_VARIABLE temp_BOSS_ABSORB_DAMAGE_store.status.slowed}
        [/else]
    [/if]

    {CLEAR_VARIABLE ("
        temp_BOSS_ABSORB_DAMAGE_store.status.poisoned,
        temp_BOSS_ABSORB_DAMAGE_store.status.petrified,
        temp_BOSS_ABSORB_DAMAGE_store.status.stunned,
        temp_BOSS_ABSORB_DAMAGE_store.status.dazed
    ")}
#endif

    [delay]
        time=90
    [/delay]

    [unstore_unit]
        find_vacant=no
        variable=temp_BOSS_ABSORB_DAMAGE_store
        text="<span font_weight='bold' size='larger'>×</span>"
        color="255,170,0"
    [/unstore_unit]

    {CLEAR_VARIABLE temp_BOSS_ABSORB_DAMAGE_store}
#enddef


#textdomain wesnoth-After_the_Storm

#define HERO_DEFEAT
    [endlevel]
        result=defeat
        music="sad.ogg,defeat.ogg,defeat2.ogg"
    [/endlevel]
#enddef

#define HERO_DEATH_BASE _ID _PRE _POST
    [event]
        name=last breath
        [filter]
            id={_ID}
        [/filter]
        {_PRE}
    [/event]
    [event]
        name=die
        [filter]
            id={_ID}
        [/filter]
        {_POST}
        {HERO_DEFEAT}
    [/event]
#enddef

#define HERO_DEATH_SIMPLE _ID _POST
    [event]
        name=die
        [filter]
            id={_ID}
        [/filter]
        {_POST}
        {HERO_DEFEAT}
    [/event]
#enddef

#define MINOR_DEATH_EVENT _ID _PRE _POST
    [event]
        name=last breath
        [filter]
            id={_ID}
        [/filter]

        {INCIDENTAL_MUSIC sad.ogg}

        {_PRE}
    [/event]
    [event]
        name=die
        [filter]
            id={_ID}
        [/filter]

        {_POST}
    [/event]
#enddef

# kate: indent-mode normal; encoding utf-8; space-indent on;


#textdomain wesnoth-After_the_Storm

# Unlike the rest, Galas' canrecruit and unrenamable
# attributes are included in his own macro. This is
# intentional as he's only used in [side] declarations.
#define CHARACTER_STATS_GALAS
    id=Galas
    name= _ "Galas"
    type=Elvish Wayfarer
    profile="portraits/galas.png"
    canrecruit=yes
    unrenamable=yes
    [modifications]
        {TRAIT_RESILIENT}
        {TRAIT_QUICK}
        [object]
            [effect]
                apply_to=image_mod
                add=RC(magenta>brown)
            [/effect]
        [/object]
    [/modifications]
#enddef

#define CHARACTER_STATS_MAL_KESHAR
    id=Mal Keshar
    name= _ "Mal Keshar"
    type=Ancient Lich
    profile="portraits/mal-keshar.png"
    {IS_HERO}
    unrenamable=yes
    [modifications]
        {TRAIT_UNDEAD}
        {TRAIT_DETERIORATED}
        {MOD_LOYAL_HERO}
    [/modifications]
#enddef

#define CHARACTER_STATS_ELYSSA
    id=Elyssa
    name= _ "Elyssa"
    type=Shaxthal Warlord Elyssa
    profile="portraits/elyssa.png"
    unrenamable=yes
    [modifications]
        {TRAIT_BIOMECHANICAL}
        {TRAIT_INTELLIGENT}
    [/modifications]
#enddef

#define CHARACTER_STATS_MAL_KENDRIA
    id=Mal Kendria
    name= _ "Mal Kendria"
    type=Necromancer
    #profile="portraits/mal-kendria.png"
    gender=female
    level=4
    unrenamable=yes
    [modifications]
        {TRAIT_RESILIENT}
        {TRAIT_QUICK}
    [/modifications]
#enddef

#define CHARACTER_STATS_NAR_HAMOTH
    id=Nar-hamoth
    name= _ "Nar-hamoth"
    type=Shaxthal Warlord Narhamoth
    #profile="portraits/nar-hamoth.png"
    unrenamable=yes
    [modifications]
        {TRAIT_BIOMECHANICAL}
        {TRAIT_ARMORED}
    [/modifications]
#enddef

#define CHARACTER_STATS_MAL_HEKUBA
    id=Mal Hekuba
    name= _ "Mal Hekuba"
    type=Chaos Cardinal
    profile="portraits/mal-hekuba.png"
    unrenamable=yes
    [modifications]
        {TRAIT_UNDEAD}
        {TEAM_COLOR_OVERRIDE () purple}
    [/modifications]
#enddef

#define CHARACTER_STATS_TORANCYN
    id=Torancyn
    name= _ "Torancyn"
    type=Aragwaith Swordsmaster
    #profile="portraits/torancyn.png"
    unrenamable=yes
    [modifications]
        {TRAIT_STRONG}
        {TRAIT_RESILIENT}
    [/modifications]
#enddef

#define CHARACTER_STATS_VALEN
    id=Valen
    name= _ "Valen"
    type=Aragwaith Seer
    profile="portraits/valen.png"
    unrenamable=yes
    [modifications]
        {TRAIT_INTELLIGENT}
        {TRAIT_QUICK}
    [/modifications]
#enddef

#define CHARACTER_STATS_ARNESIUS
    id=Arnesius
    name= _ "Arnesius"
    type=Arch Mage
    gender=male
    #profile="portraits/arnesius.png"
    unrenamable=yes
    [modifications]
        {TRAIT_INTELLIGENT}
        {TRAIT_STRONG}
    [/modifications]
#enddef

# Intentionally unused. This is here for reference purposes only.
#define CHARACTER_STATS_IGOR
    id=Igor
    name= _ "Igor"
    profile="portraits/igor.png"
    type=Wolf Rider
    {IS_LOYAL}
    unrenamable=yes
    [modifications]
        {TRAIT_LOYAL}
        {TRAIT_STRONG}
    [/modifications]
#enddef

#define RECALL_CHARACTER _STATS
    [unit]
        {_STATS}
        side=1
        placement=leader
    [/unit]
#enddef

#define RECALL_CHARACTER_AT _STATS _X _Y
    [unit]
        {_STATS}
        side=1
        placement=map
        x={_X}
        y={_Y}
    [/unit]
#enddef

# Igor is an optional unit, so we use [recall] for him without creating him as
# a fallback path.

#define RECALL_IGOR
    [recall]
        id=Igor
    [/recall]
#enddef

#define RECALL_IGOR_AT_LOCATION _X _Y
    [recall]
        id=Igor
        x={_X}
        y={_Y}
    [/recall]
#enddef

# kate: indent-mode normal; encoding utf-8; space-indent on;