#textdomain wesnoth-sotbe

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

#define NOVICE_ORCISH_SHAMAN SIDE X Y ID_STRING NAME_STRING
    [unit]
        id={ID_STRING}
        name={NAME_STRING}
        unrenamable=yes
        type=Orcish Shaman
        variation=adolescent
        profile=portraits/young_orcish_shaman.webp
        side={SIDE}
        x={X}
        y={Y}
        random_traits=no
        [modifications]
            {TRAIT_LOYAL_HERO}
        [/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.webp
        side={SIDE}
        x={X}
        y={Y}
        random_traits=no
        [modifications]
            {TRAIT_LOYAL_HERO}
        [/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.webp
    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.webp
    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]
            array=horde_units
            [do]
                {VARIABLE this_item.upkeep $this_item.level}
                {VARIABLE_OP this_item.upkeep sub 1}
                {VARIABLE this_item.variables.great_horde_upkeep_mod_applied yes}

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

        {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 ENABLE_AI_COMMAND_CA_TRANSPORT_S6
    [lua]
        code = <<
function wesnoth.custom_synced_commands.ship_unload(cfg)

	local unit = wesnoth.units.get(cfg.x, cfg.y)
	unit.variables.landed = 'yes'
	unit.variables.destination_x = 1
	unit.variables.destination_y = 30

	local locs = wml.child_array(cfg, "dst")

	local l2_type = mathx.random_choice('Swordsman,Javelineer,Pikeman')
	wesnoth.units.to_map({ side = wesnoth.current.side, type = l2_type, moves = 2 }, locs[1].x, locs[1].y)
	wesnoth.add_known_unit(l2_type)

	for i = 2, #locs do
		local l1_type = mathx.random_choice('Fencer,Mage,Cavalryman,Bowman,Spearman')
		wesnoth.units.to_map({ side = wesnoth.current.side, type = l1_type, moves = 2 }, locs[i].x, locs[i].y)
		wesnoth.add_known_unit(l1_type)
	end
end

>>
    [/lua]
#enddef
