#textdomain wesnoth-sotbe

#define OLD_ORCISH_SHAMAN SIDE X Y ID_STRING NAME_STRING
    [unit]
        id={ID_STRING}
        name={NAME_STRING}
        unrenamable=yes
        type=Old Orcish Shaman
        profile=portraits/old_orcish_shaman.png
        side={SIDE}
        x={X}
        y={Y}
        random_traits=no
        {IS_HERO}
        [modifications]
            {TRAIT_LOYAL}
        [/modifications]
    [/unit]
#enddef

#define NOVICE_ORCISH_SHAMAN SIDE X Y ID_STRING NAME_STRING
    [unit]
        id={ID_STRING}
        name={NAME_STRING}
        unrenamable=yes
        type=Novice Orcish Shaman
        profile=portraits/young_orcish_shaman.png
        side={SIDE}
        x={X}
        y={Y}
        random_traits=no
        {IS_HERO}
        [modifications]
            {TRAIT_LOYAL}
        [/modifications]
    [/unit]
#enddef

#define ORCISH_SHAMAN SIDE X Y ID_STRING NAME_STRING
    [unit]
        id={ID_STRING}
        name={NAME_STRING}
        unrenamable=yes
        type=Orcish Shaman
        profile=portraits/orcish_shaman.png
        side={SIDE}
        x={X}
        y={Y}
        random_traits=no
        {IS_HERO}
        [modifications]
            {TRAIT_LOYAL}
        [/modifications]
    [/unit]
#enddef

#define BLACK_FLAG
    flag=flags/black-flag-[1,2,1,3].png:[100,300,100,300]
    flag_icon=flags/black-flag-icon.png
#enddef

#define RENAME_IF_DEAD VAR NAME STRING
    [if]
        [variable]
            name={VAR}
            equals=yes
        [/variable]
        [then]
            {MODIFY_UNIT id={NAME} name {STRING}}
        [/then]
    [/if]
#enddef

#define ALBROCK_SIDE
    type=Orcish Warlord
    id="Al'Brock"
    name= _ "Al’Brock"
    unrenamable=yes
    side=2
    canrecruit=yes
    profile=portraits/albrock.png
    recruit=Wolf Rider, Orcish Grunt, Troll Whelp, Orcish Archer, Orcish Crossbowman, Orcish Warrior
    team_name=Kapoue
    user_team_name=_ "Kapou’e"
    persistent=yes
#enddef

#define FLARTAR_SIDE
    type=Orcish Warlord
    id="Flar'Tar"
    name= _ "Flar’Tar"
    unrenamable=yes
    side=3
    canrecruit=yes
    profile=portraits/flartar.png
    recruit=Wolf Rider, Orcish Grunt, Troll Whelp, Orcish Archer, Orcish Crossbowman, Orcish Warrior
    team_name=Kapoue
    user_team_name=_ "Kapou’e"
    persistent=yes
#enddef

#define GREAT_HORDE_NOTE
    [note]
        description= _ "The Great Horde: upkeep cost of every unit decreased by one."
    [/note]
#enddef

#define GOT_THE_GREAT_HORDE SIDES
    [event]
        name=prerecruit
        first_time_only=no

        [filter]
            side={SIDES}
        [/filter]

        {VARIABLE unit.upkeep $unit.level}
        {VARIABLE_OP unit.upkeep sub 1}
        {VARIABLE unit.variables.great_horde_upkeep_mod_applied yes}

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

    [event]
        name=start

        [store_unit]
            [filter]
                side={SIDES}

                [not]
                    [filter_wml]
                        [modifications]
                            [trait]
                                id=loyal
                            [/trait]
                        [/modifications]
                    [/filter_wml]
                [/not]

                [not]
                    [filter_wml]
                        [variables]
                            great_horde_upkeep_mod_applied=yes
                        [/variables]
                    [/filter_wml]
                [/not]
            [/filter]

            kill=yes
            variable=horde_units
        [/store_unit]

        {FOREACH horde_units i}
            {VARIABLE horde_units[$i].upkeep $horde_units[$i].level}
            {VARIABLE_OP horde_units[$i].upkeep sub 1}
            {VARIABLE horde_units[$i].variables.great_horde_upkeep_mod_applied yes}

            [unstore_unit]
                variable=horde_units[$i]
                find_vacant=no
            [/unstore_unit]
        {NEXT i}

        {CLEAR_VARIABLE horde_units}
    [/event]

    [event]
        name=post_advance
        first_time_only=no

        [filter]
            side={SIDES}

            [not]
                [filter_wml]
                    [modifications]
                        [trait]
                            id=loyal
                        [/trait]
                    [/modifications]
                [/filter_wml]
            [/not]
        [/filter]

        {VARIABLE unit.upkeep $unit.level}
        {VARIABLE_OP unit.upkeep sub 1}
        {VARIABLE unit.variables.great_horde_upkeep_mod_applied yes}

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

#define AI_FORCE_ATTACK_HIGH_XP_UNITS_SETUP
    # Function needed for Micro AI which forces attacks on units 1 XP from leveling
    # Goes directly into scenario toplevel, but only once per scenario
    [event]
        name=preload
        first_time_only=no
        [lua]
            code=<<
                function close_to_advancing(unit)
                    if (unit.experience >= unit.max_experience-1) then
                        return true
                    else
                        return false
                    end
                end
            >>
        [/lua]
    [/event]
#enddef

#define AI_FORCE_ATTACK_HIGH_XP_UNITS SIDE
    # Micro AI which forces attacks on units 1 XP from leveling
    # Goes directly into scenario toplevel, one macro per side
    [event]
        name=prestart
        [micro_ai]
            side={SIDE}
            ai_type=simple_attack
            action=add

            ca_score=100001
            [filter]
                canrecruit=no
            [/filter]
            [filter_second]
                lua_function = "close_to_advancing"
            [/filter_second]
        [/micro_ai]
    [/event]
#enddef
