#textdomain wesnoth-ei

#define DEFAULT_AMLA_EFFECTS
    [effect]
        apply_to=max_experience
        increase=20%
    [/effect]

    [effect]
        apply_to=hitpoints
        heal_full=yes
    [/effect]

    [effect]
        apply_to=status
        remove=poisoned
    [/effect]

    [effect]
        apply_to=status
        remove=slowed
    [/effect]
#enddef

#define GLOBAL__UNIVERSAL_AMLAS
    #############################
    # EXPLAIN AMLAS
    #############################
    [event]
        name=explain_amlas

        [filter_condition]
            {VARIABLE_CONDITIONAL finished_explaining_amlas not_equals yes}
        [/filter_condition]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message=_"In this campaign, whenever a max-level unit advances, they can select one of several minor bonuses!"
        [/message]
        {VARIABLE finished_explaining_amlas yes}
    [/event]

    #############################
    # IMPLEMENT AMLAS
    #############################
    [event]
        name=pre advance
        first_time_only=no

        [filter]
            [not]
                id=$amla_currently_advancing_id
            [/not]
        [/filter]

        #--------------------
        # SKIP IF NOT MAX-LEVEL
        #--------------------
        {STORE_UNIT_VAR id=$unit.id advances_to amla_candidate_advances_to}
        [if] {VARIABLE_CONDITIONAL amla_candidate_advances_to equals ""}
            [then]
            [/then]

            [else]
                {CLEAR_VARIABLE amla_candidate_advances_to}
                [return]
                [/return]
            [/else]
        [/if]
        {CLEAR_VARIABLE amla_candidate_advances_to}

        #--------------------
        # AVOID RECURSION
        #--------------------
        # modifying a unit re-triggers "pre advance", so avoid infinite recursion
        {VARIABLE amla_currently_advancing_id $unit.id}

        #--------------------
        # EXPLAIN AMLAS
        #--------------------
        [fire_event]
            name=explain_amlas
        [/fire_event]

        #--------------------
        # ADD AMLAS
        #--------------------
        [remove_object]
            object_id=universal_amlas_object
            id=$unit.id
        [/remove_object]
        [modify_unit]
            [filter]
                id=$unit.id
            [/filter]

            [object]
                id=universal_amlas_object
                [effect]
                    apply_to=remove_advancement
                    amlas=amla_default
                [/effect]

                #--------------------
                # HITPOINTS
                #--------------------
                [effect]
                    apply_to=new_advancement
                    [advancement]
                        id=hitpoints_increase
                        description= _ "Gain +8 hitpoints."
                        strict_amla=yes
                        max_times=-1
                        [effect]
                            apply_to=hitpoints
                            increase_total=8
                        [/effect]

                        {DEFAULT_AMLA_EFFECTS}
                    [/advancement]
                    #--------------------
                    # MELEE DAMAGE
                    #--------------------
                    [advancement]
                        id=melee_increase1
                        description= _ "Gain +4 melee damage."
                        strict_amla=yes
                        max_times=-1

                        [filter]
                            [has_attack]
                                range=melee
                                number=1
                            [/has_attack]

                            [not]
                                [has_attack]
                                    range=melee
                                    number=2-99
                                [/has_attack]
                            [/not]
                        [/filter]

                        [effect]
                            apply_to=attack
                            increase_damage=4
                            range=melee
                        [/effect]

                        {DEFAULT_AMLA_EFFECTS}
                    [/advancement]
                    [advancement]
                        id=melee_increase2
                        description= _ "Gain +2 melee damage."
                        strict_amla=yes
                        max_times=-1

                        [filter]
                            [has_attack]
                                range=melee
                                number=2
                            [/has_attack]

                            [not]
                                [has_attack]
                                    range=melee
                                    number=3-99
                                [/has_attack]
                            [/not]
                        [/filter]

                        [effect]
                            apply_to=attack
                            increase_damage=2
                            range=melee
                        [/effect]

                        {DEFAULT_AMLA_EFFECTS}
                    [/advancement]
                    [advancement]
                        id=melee_increase3
                        description= _ "Gain +1 melee damage."
                        strict_amla=yes
                        max_times=-1

                        [filter]
                            [has_attack]
                                range=melee
                                number=3-99
                            [/has_attack]
                        [/filter]

                        [effect]
                            apply_to=attack
                            increase_damage=1
                            range=melee
                        [/effect]

                        {DEFAULT_AMLA_EFFECTS}
                    [/advancement]
                    [advancement]
                        id=ranged_increase1
                        description= _ "Gain +3 ranged damage."
                        strict_amla=yes
                        max_times=-1

                        [filter]
                            [has_attack]
                                range=ranged
                                number=1
                            [/has_attack]

                            [not]
                                [has_attack]
                                    range=ranged
                                    number=2-99
                                [/has_attack]
                            [/not]
                        [/filter]

                        [effect]
                            apply_to=attack
                            increase_damage=3
                            range=ranged
                        [/effect]

                        {DEFAULT_AMLA_EFFECTS}
                    [/advancement]
                    [advancement]
                        id=ranged_increase2
                        description= _ "Gain +2 ranged damage."
                        strict_amla=yes
                        max_times=-1

                        [filter]
                            [has_attack]
                                range=ranged
                                number=2
                            [/has_attack]

                            [not]
                                [has_attack]
                                    range=ranged
                                    number=3-99
                                [/has_attack]
                            [/not]
                        [/filter]

                        [effect]
                            apply_to=attack
                            increase_damage=2
                            range=ranged
                        [/effect]

                        {DEFAULT_AMLA_EFFECTS}
                    [/advancement]
                    [advancement]
                        id=ranged_increase3
                        description= _ "Gain +1 ranged damage."
                        strict_amla=yes
                        max_times=-1

                        [filter]
                            [has_attack]
                                range=ranged
                                number=3-99
                            [/has_attack]
                        [/filter]

                        [effect]
                            apply_to=attack
                            increase_damage=1
                            range=ranged
                        [/effect]

                        {DEFAULT_AMLA_EFFECTS}
                    [/advancement]
                [/effect]
            [/object]
        [/modify_unit]

        #--------------------
        # RESET AMLAS
        #--------------------
        [event]
            name=post advance
            {CLEAR_VARIABLE amla_currently_advancing_id}

            [remove_object]
                object_id=universal_amlas_object
                id=$unit.id
            [/remove_object]
        [/event]
    [/event]
#enddef
