#textdomain wesnoth-utbs

#define KALEH_LEVEL_BONUS
    # We increase damage by one when we increase the level.
    [effect]
        apply_to=attack
        times=per level
        increase_damage=1
    [/effect]
#enddef

#define KALEH_ADVANCEMENT HP_INCREMENT XP_INCREMENT EFFECT_WML VARIATION_NAME
    [advancement]
        max_times=1
        always_display=yes
        [effect]
            apply_to=hitpoints
            increase_total={HP_INCREMENT}
            increase={HP_INCREMENT}
        [/effect]
        [effect]
            apply_to=max_experience
            increase={XP_INCREMENT}
        [/effect]
        [effect]
            apply_to=variation
            name={VARIATION_NAME}
        [/effect]
        {EFFECT_WML}
    [/advancement]
#enddef

# ADVANCEMENTS:
#define KALEH_LEADERSHIP VARIANT_NAME
    {KALEH_ADVANCEMENT 3 8 (
        id=leadership
        description= _ "a leader in battle"
        image=units/elves-desert/kaleh-leading.png
        require_amla=""
        [effect]
            apply_to=new_ability
            [filter]
                level=2
            [/filter]
            [abilities]
                {ABILITY_LEADERSHIP_LEVEL_2}
            [/abilities]
        [/effect]
        [effect]
            apply_to=new_ability
            [filter]
                level=3
            [/filter]
            [abilities]
                {ABILITY_LEADERSHIP_LEVEL_3}
            [/abilities]
        [/effect]
    ) {VARIANT_NAME}}
#enddef

#define KALEH_BOLAS VARIANT_NAME
    {KALEH_ADVANCEMENT 4 6 (
        id=bolas
        description= _ "trained by Nym in using the bolas"
        image=attacks/bolas.png
        require_amla=""
        [effect]
            apply_to=new_attack
            name=bolas
            description= _"bolas"
            type=impact
            range=ranged
            damage=4
            number=2
            [specials]
                {WEAPON_SPECIAL_SLOW}
            [/specials]
            icon=attacks/bolas.png
        [/effect]
        [effect]
            apply_to=attack
            name=bolas
            times=per level
            increase_damage=1
        [/effect]
        [effect]
            apply_to=new_animation
            [attack_anim]
                [filter_attack]
                    name=bolas
                [/filter_attack]
                [missile_frame]
                    begin=-150
                    end=0
                    image=projectiles/bolas-n.png
                    image_diagonal=projectiles/bolas-ne.png
                [/missile_frame]
                [if]
                    hits=yes
                    [frame]
                        begin=-300
                        end=-200
                        image=units/elves-desert/kaleh.png
                        sound=hatchet.wav
                    [/frame]
                [/if]
                [else]
                    hits=no
                    [frame]
                        begin=-300
                        end=-200
                        image=units/elves-desert/kaleh.png
                        sound=hatchet-miss.wav
                    [/frame]
                [/else]
                [frame]
                    begin=-200
                    end=0
                    image=units/elves-desert/kaleh.png
                [/frame]
                {SOUND:SLOW}
            [/attack_anim]
        [/effect]
    ) {VARIANT_NAME}}
#enddef

# Special macro to add the damage bonus per level. Use only once!
#define KALEH_SWORD_FIRST VARIANT_NAME
    {KALEH_ADVANCEMENT 6 4 (
        id=sword
        description= _ "a better swordsman"
        image=attacks/sword-elven.png
        require_amla=""
        [effect]
            apply_to=attack
            range=melee
            increase_damage=2
        [/effect]
        {KALEH_LEVEL_BONUS}
    ) {VARIANT_NAME}}
#enddef

#define KALEH_SWORD VARIANT_NAME
    {KALEH_ADVANCEMENT 6 4 (
        id=sword
        description= _ "a better swordsman"
        image=attacks/sword-elven.png
        require_amla=""
        [effect]
            apply_to=attack
            range=melee
            increase_damage=2
        [/effect]
    ) {VARIANT_NAME}}
#enddef

#define KALEH_SWORD2 VARIANT_NAME
    {KALEH_ADVANCEMENT 6 6 (
        id=sword2
        description= _ "a better swordsman"
        image=attacks/sword-elven.png
        require_amla=sword
        [effect]
            apply_to=attack
            range=melee
            increase_damage=2
        [/effect]
    ) {VARIANT_NAME}}
#enddef

# Special macro to add the damage bonus per level. Use only once!
#define KALEH_BOW_FIRST VARIANT_NAME
    {KALEH_ADVANCEMENT 4 4 (
        id=bow
        description= _ "a better archer"
        image=attacks/bow-elven.png
        require_amla=""
        [effect]
            apply_to=attack
            name=bow
            increase_damage=1
            increase_attacks=1
        [/effect]
        {KALEH_LEVEL_BONUS}
    ) {VARIANT_NAME}}
#enddef

#define KALEH_BOW VARIANT_NAME
    {KALEH_ADVANCEMENT 4 4 (
        id=bow
        description= _ "a better archer"
        image=attacks/bow-elven.png
        require_amla=""
        [effect]
            apply_to=attack
            name=bow
            increase_damage=1
            increase_attacks=1
        [/effect]
    ) {VARIANT_NAME}}
#enddef

#define KALEH_BOW2 VARIANT_NAME
    {KALEH_ADVANCEMENT 4 6 (
        id=bow2
        description= _ "a better archer"
        image=attacks/bow-elven.png
        require_amla=bow
        [effect]
            apply_to=attack
            name=bow
            increase_damage=2
        [/effect]
    ) {VARIANT_NAME}}
#enddef

#define KALEH_BOW3 VARIANT_NAME
    {KALEH_ADVANCEMENT 4 8 (
        id=bow3
        description= _ "a marksman with the bow"
        image=attacks/bow-elven.png
        require_amla=bow2
        [effect]
            apply_to=attack
            name=bow
            increase_damage=1
            [set_specials]
                {WEAPON_SPECIAL_MARKSMAN}
            [/set_specials]
        [/effect]
    ) {VARIANT_NAME}}
#enddef

#define KALEH_SUSTENANCE VARIANT_NAME
    {KALEH_ADVANCEMENT 5 8 (
        id=sustenance
        description= _ "gain +20% resistance under the sun"
        image=attacks/sand-storm.png
        require_amla=bow
        [effect]
            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]
        [/effect]
    ) {VARIANT_NAME}}
#enddef

#define KALEH_ARMOR VARIANT_NAME
    {KALEH_ADVANCEMENT 6 10 (
        id=armor
        description= _ "gain +10% resistance to blade, pierce and impact"
        image=attacks/heater-shield.png
        require_amla="sword,sword2"
        [effect]
            apply_to=new_ability
            [abilities]
                [resistance]
                    id=armor
                    add=10
                    max_value=30
                    apply_to=blade,pierce,impact
                    # don't clutter ability list
                    name= ""
                    description= ""	# wmllint: ignore
                    affect_self=yes
                [/resistance]
            [/abilities]
        [/effect]
    ) {VARIANT_NAME}}
#enddef

#define KALEH_STUN VARIANT_NAME
    {KALEH_ADVANCEMENT 4 10 (
        id=stun
        description= _ "gain a stunning attack that disrupts enemy ZOC"
        image=attacks/scimitar.png
        require_amla="sword"
        [effect]
            apply_to=attack
            name=sword
            [set_specials]
                mode=append
                [chance_to_hit]
                    id=stun
                    name= _ "stun"
                    description= _ "Stun:
This attack puts enormous pressure on the enemy, disrupting his ZOC if a hit is landed. 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. Not active on defense."
                    apply_to=opponent
                    active_on=offense
                    value=60
                    cumulative=yes
                [/chance_to_hit]
            [/set_specials]
        [/effect]
    ) {VARIANT_NAME}}
#enddef

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

Enemy units cannot see this unit while it is in desert dunes, desert mountains, oasis 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, desert mountains and craters, and remain undetected by its enemies.

Enemy units cannot see this unit while it is in desert dunes, desert mountains, oasis 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,Dd^Do
                        [/filter_location]
                    [/filter_self]
                [/hides]
            [/abilities]
        [/effect]
    ) {VARIANT_NAME}}
#enddef

#define KALEH
    id=Kaleh
    race=elf
    name= _ "Kaleh of the Quenoth Elves"
    image=units/elves-desert/kaleh.png
    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
        frozen=3
    [/movement_costs]
    [defense]
        sand=40
        forest=50
    [/defense]
    movement=5
    profile=portraits/kaleh.png
    alignment=lawful
    [leading_anim]
        [frame]
            begin=-150
            end=150
            image=units/elves-desert/kaleh-leading.png
        [/frame]
    [/leading_anim]
    advances_to=null
    cost=14
    usage=fighter
    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]
        [filter_attack]
            name=bow
        [/filter_attack]
        [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]
        [filter_attack]
            name=sword
        [/filter_attack]
        [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]
#enddef
[unit_type]
    {KALEH}
    hitpoints=28
    experience=22
    level=1
    [variation]
        {KALEH}
        variation_name=Youth
        inherit=no
        level=1
        hitpoints=28
        experience=22
        name= _ "Desert Youth"
        # Special macros to add the damage bonus per level. Use only once!
        {KALEH_SWORD_FIRST  Fighter}
        {KALEH_BOW_FIRST    Fighter}
    [/variation]
    # Generic Fighter variation tree.
#define KALEH_FIGHTER VARIANT_NAME
    {KALEH_BOLAS        {VARIANT_NAME}}
    {KALEH_SWORD        {VARIANT_NAME}}
    {KALEH_BOW          {VARIANT_NAME}}
    {KALEH_BOW2         {VARIANT_NAME}}
    {KALEH_BOW3         {VARIANT_NAME}}
    {KALEH_CAMOUFLAGE   {VARIANT_NAME}}
    {KALEH_SUSTENANCE   {VARIANT_NAME}}
    {KALEH_ARMOR        {VARIANT_NAME}}
    {KALEH_STUN         {VARIANT_NAME}}
#enddef
    [variation]
        {KALEH}
        variation_name=Fighter
        inherit=no
        level=1
        hitpoints=28
        experience=28
        name= _ "Desert Fighter"
        {KALEH_LEADERSHIP   Captain }
        {KALEH_SWORD2       Hero    }
        {KALEH_FIGHTER      Fighter1}
    [/variation]
    [variation]
        {KALEH}
        variation_name=Fighter1
        inherit=no
        level=2
        hitpoints=28
        experience=40
        name= _ "Desert Fighter"
        {KALEH_LEADERSHIP   Captain2}
        {KALEH_SWORD2       Hero2   }
        {KALEH_FIGHTER      Fighter2}
    [/variation]
    [variation]
        {KALEH}
        variation_name=Fighter2
        inherit=no
        level=2
        hitpoints=28
        experience=50
        name= _ "Desert Fighter"
        {KALEH_LEADERSHIP   Captain3}
        {KALEH_SWORD2       Hero3   }
        {KALEH_FIGHTER      Fighter3}
    [/variation]
    [variation]
        {KALEH}
        variation_name=Fighter3
        inherit=no
        level=3
        hitpoints=28
        experience=80
        name= _ "Desert Fighter"
        {KALEH_LEADERSHIP   Captain3}
        {KALEH_SWORD2       Hero3   }
        {KALEH_FIGHTER      Fighter3}
    [/variation]
    # Captain variation tree - reached when leadership is chosen
    # disables sword2 and thus armor
    # reduces XP requirements by 3 per variation
#define KALEH_CAPTAIN VARIANT_NAME
    {KALEH_LEADERSHIP {VARIANT_NAME}}
    {KALEH_FIGHTER    {VARIANT_NAME}}
#enddef
    [variation]
        {KALEH}
        variation_name=Captain
        inherit=no
        level=2
        hitpoints=28
        experience=37
        name= _ "Desert Captain"
        {KALEH_CAPTAIN Captain2}
    [/variation]
    [variation]
        {KALEH}
        variation_name=Captain2
        inherit=no
        level=2
        hitpoints=28
        experience=44
        name= _ "Desert Captain"
        {KALEH_CAPTAIN Captain3}
    [/variation]
    [variation]
        {KALEH}
        variation_name=Captain3
        inherit=no
        level=3
        hitpoints=28
        experience=71
        name= _ "Desert Marshal"
        {KALEH_CAPTAIN Captain3}
    [/variation]
    # Hero variation tree - reached when sword2 is chosen
    # disables leadership
    # gives +3 HP per variation
#define KALEH_HERO VARIANT_NAME
    {KALEH_SWORD2  {VARIANT_NAME}}
    {KALEH_FIGHTER {VARIANT_NAME}}
#enddef
    [variation]
        {KALEH}
        variation_name=Hero
        inherit=no
        level=2
        hitpoints=31
        experience=40
        name= _ "Desert Hero"
        {KALEH_HERO Hero2}
    [/variation]
    [variation]
        {KALEH}
        variation_name=Hero2
        inherit=no
        level=2
        hitpoints=34
        experience=50
        name= _ "Desert Hero"
        {KALEH_HERO Hero3}
    [/variation]
    [variation]
        {KALEH}
        variation_name=Hero3
        inherit=no
        level=3
        hitpoints=37
        experience=80
        name= _ "Desert Champion"
        {KALEH_HERO Hero3}
    [/variation]
[/unit_type]
