#textdomain wesnoth-utbs
#define ENABLE_AMLA REQUISITE TYPE HP_RAISE DAMAGE XP
    [advancement]
        require_amla={REQUISITE}
        [effect]
        [/effect]
        [effect]
            apply_to=attack
            increase_damage={DAMAGE}
        [/effect]
        [effect]
            apply_to=hitpoints
            increase_total={HP_RAISE}
            increase={HP_RAISE}
        [/effect]
        [effect]
            apply_to=variation
            name={TYPE}
        [/effect]
        [effect]
            apply_to=max_experience
            increase={XP}
        [/effect]
        [effect]
            apply_to=hitpoints
            heal_full=yes
        [/effect]
    [/advancement]
#enddef

#define CHANGE_AMLA TYPE HP_RAISE DAMAGE XP
    [advancement]
        [effect]
        [/effect]
        [effect]
            apply_to=attack
            increase_damage={DAMAGE}
        [/effect]
        [effect]
            apply_to=hitpoints
            increase_total={HP_RAISE}
            increase={HP_RAISE}
            heal_full=yes
        [/effect]
        [effect]
            apply_to=variation
            name={TYPE}
        [/effect]
        [effect]
            apply_to=max_experience
            increase={XP}
        [/effect]
        [effect]
            apply_to=hitpoints
            heal_full=yes
        [/effect]
    [/advancement]
#enddef

#define KALEH_ADVANCEMENT TIMES ID DESCRIPTION IMAGE REQUISITE HP_RAISE XP EFFECT
    [advancement]
        id={ID}
        description= {DESCRIPTION}
        image={IMAGE}
        max_times={TIMES}
        require_amla={REQUISITE}
        [effect]
            {EFFECT}
        [/effect]
        [effect]
            apply_to=attack
            increase_damage=1
        [/effect]
        [effect]
            apply_to=hitpoints
            increase_total={HP_RAISE}
            increase={HP_RAISE}
        [/effect]
        [effect]
            apply_to=variation
            name=Fighter
        [/effect]
        [effect]
            apply_to=max_experience
            increase={XP}
        [/effect]
        [effect]
            apply_to=hitpoints
            heal_full=yes
        [/effect]
    [/advancement]
#enddef

[unit]
    id=Kaleh
    race=elf
    name= _ "Kaleh of the Quenoth Elves"
    image=units/elves-desert/kaleh.png
    [attack_anim]
        apply_to=attack
        start_time=-150
        [frame]
            duration=300
            image=units/elves-desert/kaleh-ranged.png
        [/frame]
        [attack_filter]
            range=ranged
        [/attack_filter]
    [/attack_anim]
    hitpoints=28
    movement_type=woodland
    #desert elves move fast across the sands, but are not used to forests
    #they are also a bit faster in caves
    [movement_costs]
        sand=1
        forest=2
        cave=2
        tundra=3
    [/movement_costs]
    [defense]
        sand=40
        forest=50
    [/defense]
    movement=5
    experience=22
    level=1
    profile=portraits/kaleh.png
    alignment=lawful
    image_leading=units/elves-desert/kaleh-leading.png
    advanceto=null
    cost=14
    usage=fighter

    [variation]
        variation_name=Youth
        inherit=yes
        name= _ "Desert Youth"
    [/variation]

    [variation]
        variation_name=Fighter
        inherit=yes
        name= _ "Desert Fighter"
        # leadership
        {ENABLE_AMLA "" Captain 5 1 4}
        # swordskill 1
        {CHANGE_AMLA Hero 7 1 0}
        # swordskill 2
        {CHANGE_AMLA Hero 7 1 0}
        # bowskill 1
        {CHANGE_AMLA Hero 5 1 0}
        # bowskill 2
        {CHANGE_AMLA Hero 5 1 2}
        # bowskill 3
        {CHANGE_AMLA Hero 4 1 4}
        # bola
        {CHANGE_AMLA Hero 7 1 0}
        # camouflage
        {CHANGE_AMLA Hero 8 1 2}
        # sustenance
        {CHANGE_AMLA Hero 8 1 5}
        # armor-clad
        {CHANGE_AMLA Hero 8 1 6}
        # charisma
        {CHANGE_AMLA Hero 3 1 8}
        # stun
        {CHANGE_AMLA Hero 5 1 5}
    [/variation]

    [variation]
        variation_name=Captain
        inherit=yes
        level=2
        experience=40
        name= _ "Desert Captain"
        # leadership - moot
        {CHANGE_AMLA Captain2 5 0 0}
        # swordskill 1
        {CHANGE_AMLA Captain2 6 0 5}
        # swordskill 2
        {CHANGE_AMLA Captain2 6 0 8}
        # bowskill 1
        {CHANGE_AMLA Captain2 6 0 2}
        # bowskill 2
        {CHANGE_AMLA Captain2 6 0 4}
        # bowskill 3
        {CHANGE_AMLA Captain2 5 0 8}
        # bola
        {CHANGE_AMLA Captain2 6 0 0}
        # camouflage
        {CHANGE_AMLA Captain2 8 0 4}
        # sustenance
        {ENABLE_AMLA "bow,bolas" Captain2 8 0 8}
        # armor-clad
        {ENABLE_AMLA "sword" Captain2 8 0 10}
        # charisma
        {CHANGE_AMLA Captain2 3 0 12}
        # stun
        {ENABLE_AMLA "sword,sword" Captain2 5 0 8}
    [/variation]
    [variation]
        variation_name=Captain2
        inherit=yes
        level=2
        experience=40
        name= _ "Desert Captain"
        # leadership - moot
        {CHANGE_AMLA Marshal 5 1 0}
        # swordskill 1
        {CHANGE_AMLA Marshal 7 1 0}
        # swordskill 2
        {ENABLE_AMLA "sword" Marshal 6 1 8}
        # bowskill 1
        {CHANGE_AMLA Marshal 6 1 0}
        # bowskill 2
        {CHANGE_AMLA Marshal 6 1 3}
        # bowskill 3
        {CHANGE_AMLA Marshal 5 1 8}
        # bola
        {ENABLE_AMLA "not available" Marshal 6 1 0}
        # camouflage
        {CHANGE_AMLA Marshal 8 1 2}
        # sustenance
        {ENABLE_AMLA "bolas" Marshal 8 1 12}
        # armor-clad
        {ENABLE_AMLA "" Marshal 8 1 12}
        # charisma
        {ENABLE_AMLA "" Marshal 3 1 16}
        # stun - already enabled
        {ENABLE_AMLA "sword" Marshal 5 1 8}
    [/variation]

    [variation]
        variation_name=Hero
        inherit=yes
        level=2
        experience=40
        name= _ "Desert Hero"
        # leadership
        {ENABLE_AMLA "" Captain2 5 0 5}
        # swordskill 1
        {CHANGE_AMLA Hero2 8 0 5}
        # swordskill 2
        {ENABLE_AMLA "sword" Hero2 8 0 8}
        # bowskill 1
        {CHANGE_AMLA Hero2 7 0 0}
        # bowskill 2
        {CHANGE_AMLA Hero2 6 0 4}
        # bowskill 3
        {CHANGE_AMLA Hero2 5 0 8}
        # bola
        {CHANGE_AMLA Hero2 8 0 0}
        # camouflage
        {CHANGE_AMLA Hero2 9 0 4}
        # sustenance
        {ENABLE_AMLA "bolas" Hero2 9 0 8}
        # armor-clad
        {ENABLE_AMLA "sword,sword" Hero2 9 0 10}
        # charisma
        {CHANGE_AMLA Hero2 5 0 14}
        # stun
        {ENABLE_AMLA "sword" Hero2 6 0 8}
    [/variation]
    [variation]
        variation_name=Hero2
        inherit=yes
        level=2
        experience=40
        name= _ "Desert Hero"
        # leadership - already enabled
        {ENABLE_AMLA "" Marshal 5 2 4}
        # swordskill 1
        {CHANGE_AMLA Champion 8 1 0}
        # swordskill 2
        {ENABLE_AMLA "sword" Champion 8 1 8}
        # bowskill 1
        {CHANGE_AMLA Champion 7 1 0}
        # bowskill 2
        {CHANGE_AMLA Champion 6 1 2}
        # bowskill 3
        {CHANGE_AMLA Champion 5 1 8}
        # bola
        {ENABLE_AMLA "not available" Champion 8 1 0}
        # camouflage
        {CHANGE_AMLA Champion 9 1 2}
        # sustenance
        {ENABLE_AMLA "" Champion 9 1 12}
        # armor-clad
        {ENABLE_AMLA "" Champion 9 1 12}
        # charisma
        {CHANGE_AMLA Champion 5 1 16}
        # stun - already enabled
        {ENABLE_AMLA "sword" Champion 6 1 8}
    [/variation]

    [variation]
        variation_name=Champion
        inherit=yes
        level=3
        experience=100
        name= _ "Desert Champion"
        # leadership - disable
        {ENABLE_AMLA "non-existant" Marshal 2 0 50}
        # swordskill 1
        {CHANGE_AMLA Champion 4 0 50}
        # swordskill 2
        {ENABLE_AMLA "sword" Champion 4 0 50}
        # bowskill 1
        {CHANGE_AMLA Champion 2 0 50}
        # bowskill 2
        {CHANGE_AMLA Champion 2 0 50}
        # bowskill 3
        {CHANGE_AMLA Champion 2 0 50}
        # bola
        {ENABLE_AMLA "not available" Champion 4 0 50}
        # camouflage
        {CHANGE_AMLA Champion 4 0 50}
        # sustenance
        {ENABLE_AMLA "" Champion 4 0 50}
        # armor-clad
        {ENABLE_AMLA "sword" Champion 4 0 50}
        # charisma
        {CHANGE_AMLA Champion 2 0 50}
        # stun - already enabled
        {ENABLE_AMLA "sword" Champion 2 0 50}
    [/variation]
    [variation]
        variation_name=Marshal
        inherit=yes
        level=3
        experience=100
        name= _ "Desert Marshal"
        # leadership - disable
        {ENABLE_AMLA "non-existant" Marshal 3 0 24}
        # swordskill 1
        {CHANGE_AMLA Marshal 4 0 20}
        # swordskill 2
        {ENABLE_AMLA "sword" Marshal 4 0 20}
        # bowskill 1
        {CHANGE_AMLA Marshal 2 0 20}
        # bowskill 2
        {CHANGE_AMLA Marshal 2 0 24}
        # bowskill 3
        {CHANGE_AMLA Marshal 1 0 28}
        # bola
        {ENABLE_AMLA "not available" Marshal 4 0 50}
        # camouflage
        {CHANGE_AMLA Marshal 4 0 24}
        # sustenance
        {ENABLE_AMLA "" Marshal 3 0 30}
        # armor-clad
        {ENABLE_AMLA "" Marshal 3 0 34}
        # charisma
        {CHANGE_AMLA Marshal 3 0 36}
        # stun - already enabled
        {ENABLE_AMLA "sword" Marshal 2 0 30}
    [/variation]

    # ADVANCEMENTS:

    # I - LEADERSHIP
    {KALEH_ADVANCEMENT 1 leadership (_ "a leader in battle") units/elves-desert/kaleh-leading.png not-allowed 3 4 (apply_to=new_ability
    [abilities]
        {ABILITY_LEADERSHIP_LEVEL_2}
    [/abilities]
    )}

    # II - SWORDSKILL 1
    {KALEH_ADVANCEMENT 1 sword (_ "a better swordsman") attacks/sword-elven.png "" 6 6 (apply_to=attack
    range=melee
    increase_damage=2
    )}

    # III - SWORDSKILL 2
    {KALEH_ADVANCEMENT 1 sword2 (_ "a better swordsman") attacks/sword-elven.png "not_allowed" 6 5 (apply_to=attack
    range=melee
    increase_damage=2
    )}

    # IV - BOWSKILL 1
    {KALEH_ADVANCEMENT 1 bow (_ "a better archer") attacks/bow-elven.png "" 4 2 (apply_to=attack
    name=bow
    increase_damage=1
    increase_attacks=1
    )}

    # V - BOWSKILL 2
    {KALEH_ADVANCEMENT 1 bow2 (_ "a better archer") attacks/bow-elven.png bow 4 4 (apply_to=attack
    name=bow
    increase_damage=2
    )}

    # VI - BOWSKILL 3
    {KALEH_ADVANCEMENT 1 bow3 (_ "a marksman with the bow") attacks/bow-elven.png bow2 4 6 (apply_to=attack
    name=bow
    increase_damage=1
    [set_specials]
        {WEAPON_SPECIAL_MARKSMAN}
    [/set_specials]
    )}

    # VII - BOLA
    {KALEH_ADVANCEMENT 1 bolas (_ "trained by Nym in using the bolas") attacks/bolas.png "" 6 4 (apply_to=new_attack
    name=bola
    description= _"bolas"
    type=impact
    range=ranged
    damage=4
    number=2
    [specials]
        {WEAPON_SPECIAL_SLOW}
    [/specials]
    icon=attacks/bolas.png
    )}

    # VIII - CAMOUFLAGE
    {KALEH_ADVANCEMENT 1 camouflage (_ "skilled in surviving the desert") units/elves-desert/kaleh-defend.png "" 7 5 (apply_to=new_ability
    [abilities]
        [hides]
            id=camouflage
            name= _ "camouflage"
            name_inactive= _ "camouflage"
            description= _ "Camouflage:
This unit can hide in desert dunes and desert mountains and craters, and remain undetected by its enemies.

Enemy units cannot see this unit while it is in desert dunes, desert mountains and craters, except if they have units next to it. Any enemy unit that first discovers this unit immediately loses all its remaining movement."
            description_inactive= _ "Camouflage:
This unit can hide in desert dunes and desert mountains and craters, and remain undetected by its enemies.

Enemy units cannot see this unit while it is in desert dunes and desert mountains and craters, except if they have units next to it. Any enemy unit that first discovers this unit immediately loses all its remaining movement."
            affect_self=yes
            [filter_self]
                [filter_location]
                    terrain=Hd,Md,Dd^Dc
                [/filter_location]
            [/filter_self]
        [/hides]
    [/abilities]
    )}

    # IX - SUSTENANCE
    {KALEH_ADVANCEMENT 1 sustenance (_ "gain +20% resistance under the sun") attacks/sand-storm.png "bow,bolas" 3 5 (apply_to=new_ability
    [abilities]
        [resistance]
            id=sustenance
            add=20
            max_value=30
            apply_to=blade,pierce,impact,fire,cold,arcane
            [filter_base_value]
                greater_than=-1
            [/filter_base_value]
            [filter_self]
                [filter_location]
                    time_of_day=lawful
                [/filter_location]
            [/filter_self]
            name= _ "sustenance"
            description= _ "Sustenance:
This unit's resistances are increased by 20% in daylight, on defense and attack. Vulnerabilities are not affected."
            affect_self=yes
        [/resistance]
    [/abilities]
    )}

    # X - ARMOR-CLAD
    {KALEH_ADVANCEMENT 1 armor (_ "gain +10% resistance to blade, pierce and impact") attacks/heater-shield.png "non_existant" 3 5 (apply_to=new_ability
    [abilities]
        [resistance]
            id=sustenance
            add=10
            max_value=30
            apply_to=blade,pierce,impact
            [filter_self]
                [filter_location]
                    time_of_day=lawful
                [/filter_location]
            [/filter_self]
            # don't clutter ability list
            name= ""
            description= ""
            affect_self=yes
        [/resistance]
    [/abilities]
    )}

    # XI - CHARISMA
    {KALEH_ADVANCEMENT 1 charisma (_ "a charismatic leader - all adjacent units pay no upkeep") attacks/glowing-fist.png "non_existant" 3 5 (apply_to=new_ability
    [abilities]
        [resistance]
            id=charisma
            max_value=-60
            apply_to=none
            [filter_base_value]
                greater_than=100
            [/filter_base_value]
            name= _ "charisma"
            description= _ "Charisma:
Adjacent units will be treated loyal and not pay upkeep."
            affect_self=yes
        [/resistance]
    [/abilities]
    )}

    # XII - STUN
    {KALEH_ADVANCEMENT 1 stun (_ "gain a stunning attack that disrupts enemy ZOC") attacks/scimitar.png "non_existant" 3 5 (apply_to=new_attack
    name=sword_rush
    description= _ "sword"
    type=blade
    icon=attacks/sword-elven.png
    damage=5
    number=4
    range=melee
    defense_weight=0
    [specials]
        [chance_to_hit]
            id=fierce
            name= _ "stun"
            description= _ "Stun:
This attack puts enormous pressure on the enemy, disrupting his ZOC if a hit is landed. The attacker is exposing himself to attack and will be slowed as a result of the effort. Not active on defense."
            name_inactive= _ "stun"
            description_inactive= _ "Stun:
This attack puts enormous pressure on the enemy, disrupting his ZOC if a hit is landed. The attacker is exposing himself to attack and will be slowed as a result of the effort. Not active on defense."
            apply_to=opponent
            value=60
            cumulative=yes
        [/chance_to_hit]
    [/specials]
    )}

    unit_description= _ "Kaleh is still a young Elf of the Quenoth, on the verge of adulthood. He trained with his father with the bow and sword, joining him in lighter expeditions and raids. When his father was lost, Kaleh became more serious and solemn than is usual for those who walk under the two suns. He turned inwards for answers and guidance, not knowing how much his people would look towards him for guidance in times to come."+{SPECIAL_NOTES}+{SPECIAL_NOTES_LEADERSHIP}+{SPECIAL_NOTES_MARKSMAN}+{SPECIAL_NOTES_SLOW}
    die_sound={SOUND_LIST:ELF_HIT}
    {DEFENSE_ANIM_RANGE "units/elves-desert/kaleh-defend.png" units/elves-desert/kaleh.png {SOUND_LIST:ELF_HIT} melee}
    {DEFENSE_ANIM_RANGE "units/elves-desert/kaleh-ranged-defend.png" units/elves-desert/kaleh-ranged.png {SOUND_LIST:ELF_HIT} ranged}
    # Melee damage increased by 1, ranged damage decreased by 1
    [attack]
        name=sword
        description= _"sword"
        type=blade
        range=melee
        damage=5
        number=4
        icon=attacks/sword-elven.png
    [/attack]
    [attack]
        name=bow
        description= _"bow"
        type=pierce
        range=ranged
        damage=2
        number=3
        icon=attacks/bow-elven.png
    [/attack]
    [attack_anim]
        [attack_filter]
            name=bow
        [/attack_filter]
        [missile_frame]
            begin=-100
            end=0
            image=projectiles/missile-n.png
            image_diagonal=projectiles/missile-ne.png
        [/missile_frame]
        [frame]
            begin=-445
            end=-380
            image="units/elves-desert/kaleh-ranged.png"
        [/frame]
        [if]
            hits=yes
            [frame]
                begin=-380
                end=-305
                image="units/elves-desert/kaleh-ranged-1.png"
                sound=bow.ogg
            [/frame]
        [/if]
        [else]
            hits=no
            [frame]
                begin=-380
                end=-305
                image="units/elves-desert/kaleh-ranged-1.png"
                sound=bow-miss.ogg
            [/frame]
        [/else]
        [frame]
            begin=-305
            end=-230
            image="units/elves-desert/kaleh-ranged-2.png"
        [/frame]
        [frame]
            begin=-230
            end=-130
            image="units/elves-desert/kaleh-ranged-3.png"
        [/frame]
        [frame]
            begin=-130
            end=-100
            image="units/elves-desert/kaleh-ranged-4.png"
        [/frame]
        [frame]
            begin=-100
            end=0
            image="units/elves-desert/kaleh-ranged-4.png"
        [/frame]
        [frame]
            begin=0
            end=65
            image="units/elves-desert/kaleh-ranged.png"
        [/frame]
    [/attack_anim]
    [attack_anim]
        [attack_filter]
            name=sword
        [/attack_filter]
        [frame]
            begin=-200
            end=-100
            image=units/elves-desert/kaleh-melee-1.png
        [/frame]
        [if]
            hits=yes
            [frame]
                begin=-100
                end=100
                image=units/elves-desert/kaleh-melee-2.png
                sound={SOUND_LIST:SWORD_SWISH}
            [/frame]
        [/if]
        [else]
            hits=no
            [frame]
                begin=-100
                end=100
                image=units/elves-desert/kaleh-melee-2.png
                sound={SOUND_LIST:MISS}
            [/frame]
        [/else]
        [frame]
            begin=100
            end=200
            image=units/elves-desert/kaleh.png
        [/frame]
    [/attack_anim]
[/unit]
