#textdomain wesnoth-sotbe
#define GRUNT_DEFENDER X Y
    [unit]
        type=Orcish Grunt
        x={X}
        y={Y}
        side=5
        random_traits=yes
        generate_name=yes
    [/unit]
#enddef

#define ARCHER_DEFENDER X Y
    [unit]
        type=Orcish Archer
        x={X}
        y={Y}
        side=5
        random_traits=yes
        generate_name=yes
    [/unit]
#enddef

[scenario]
    id="Black_Flag"
    name= _ "Black Flag"
    map_data="{campaigns/Son_Of_The_Black_Eye/maps/Black_Flag.map}"
    {TURNS 30 28 24}

    {DEFAULT_SCHEDULE}

    next_scenario="Desert_Of_Death"

    {SCENARIO_MUSIC "the_city_falls.ogg"}
    {EXTRA_SCENARIO_MUSIC "breaking_the_chains.ogg"}
    {EXTRA_SCENARIO_MUSIC "siege_of_laurelmor.ogg"}

    [side]
        type=Orcish Leader
        id="Kapou'e"
        name= _ "Kapou'e"
        side=1
        canrecruit=yes
        controller=human
        recruit= Wolf Rider, Orcish Grunt, Troll Whelp, Orcish Archer
        team_name=Kapoue
        user_team_name=_ "Kapou'e"
        gold=100
        {BLACK_FLAG}
    [/side]

    [side]
        type=General
        id=Slowhand
        name= _ "Slowhand"
        side=2
        team_name=Humans
        user_team_name=_"Humans"
        canrecruit=yes
        recruit=Swordsman,Fencer,Mage,Heavy Infantryman,Bowman
        [ai]
            recruitment_pattern=fighter,fighter,archer,mixed fighter
            aggression=0
            village_value=10.0
            leader_value=50.0
        [/ai]
        {GOLD 110 130 150}
    [/side]

    {STARTING_VILLAGES 2 6}

    [side]
        side=3
        no_leader=yes
        team_name=Humans
        user_team_name=_"Humans"

        [ai]
            [avoid]
                x,y=1-10,1-20
            [/avoid]
        [/ai]
    [/side]

    [side]
        type=General
        id=Harman
        name= _ "Harman"
        side=4
        team_name=Humans
        user_team_name=_"Humans"
        canrecruit=yes
        facing=sw
        recruit=Swordsman,Fencer,Mage,Heavy Infantryman,Bowman
        [ai]
            recruitment_pattern=fighter,fighter,archer,mixed fighter
            aggression=0
            village_value=10.0
            leader_value=50.0
        [/ai]
        {GOLD 80 100 150}
    [/side]

    {STARTING_VILLAGES 4 4}

    [side]
        side=5
        team_name=Kapoue
        user_team_name=_ "Kapou'e"
        no_leader=yes
    [/side]

    [story]
        [part]
            show_title=yes
            {TO_BLACK_FLAG}
        [/part]
    [/story]

    [event]
        name=prestart

        {GRUNT_DEFENDER 16 12}
        {ARCHER_DEFENDER 17 12}
        {GRUNT_DEFENDER 20 9}
        {ARCHER_DEFENDER 28 13}
        {GRUNT_DEFENDER 32 23}
        {ARCHER_DEFENDER 31 25}

        [unit]
            side=2
            id="Landing Galleon"
            type=Transport Galleon
            ai_special=guardian
            x=6
            y=9
        [/unit]

        [unit]
            type=Orcish Warrior
            id=Affman
            name= _ "Affman"
            side=5
            x,y=27,20
            random_traits=yes
        [/unit]

        [objectives]
            side=1
            [objective]
                description= _ "Defeat Slowhand and Harman"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Kapou'e"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Grüü"
                condition=lose
            [/objective]
            [objective]
                description= _ "Turns run out"
                condition=lose
            [/objective]

            note={EARLY_FINISH_BONUS_NOTE}+{NEW_GOLD_CARRYOVER_NOTE_40}
        [/objectives]
    [/event]

    [event]
        name=start

        [recall]
            id=Pirk
            x=26
            y=1
        [/recall]
        [recall]
            id=Gork
            x=27
            y=1
        [/recall]
        [recall]
            id=Vraurk
            x=28
            y=1
        [/recall]

        [recall]
            id=Grüü
            x,y=25,2
        [/recall]

        [recall]
            id=Jetto
            x,y=24,1
        [/recall]

        [message]
            speaker="Kapou'e"
            message= _ "So, here is Tirigaz. But what's going on?"
        [/message]
        [message]
            speaker="Pirk"
            message= _ "Looks like humans have attacked here too. You were right, Kapou'e, the humans have declared all-out war on us."
        [/message]
        [message]
            speaker="Kapou'e"
            message= _ "Listen, if we are to meet with the rest of the Great Council, we have to repel this attack. You shamans hide here in the forest until we defeat them. It will be faster and easier for us if we don't have to worry about protecting you."
        [/message]
        [message]
            speaker="Gork"
            message= _ "This is a wise choice. Good luck, son of the Black-Eye."
        [/message]
        [message]
            speaker="Slowhand"
            message= _ "Haha! Our plan is going well, let's surround them on land while our allies attack them from sea!"
        [/message]
        [store_unit]
            [filter]
                id=Pirk
            [/filter]
            variable=Pirk_store
            kill=yes
        [/store_unit]
        [store_unit]
            [filter]
                id=Gork
            [/filter]
            variable=Gork_store
            kill=yes
        [/store_unit]
        [store_unit]
            [filter]
                id=Vraurk
            [/filter]
            variable=Vraurk_store
            kill=yes
        [/store_unit]
    [/event]

    [event]
        name=new turn
        first_time_only=no

        [if]
            [variable]
                name=turn_number
                less_than=5
            [/variable]

            [then]
                {NOTRAIT_UNIT 3 "Transport Galleon" 1 30}
            [/then]
        [/if]
    [/event]

    [event]
        name=turn 2

        [message]
            speaker=Affman
            message= _ "Look, a party of our kind approaches from the North."
        [/message]

        [message]
            speaker="Kapou'e"
            message= _ "Greetings from Kapou'e, Son of the Black-Eye Karun."
        [/message]

        [message]
            speaker=Affman
            message= _ "Son of the great Black-Eye Karun?! You do us honor, Chief."
        [/message]

        [message]
            speaker="Kapou'e"
            message= _ "Do not grovel like humans, just tell me what's going on here."
        [/message]

        [message]
            speaker=Affman
            message= _ "I don't really know, one day all was calm and peaceful and the next a fleet of human ships showed up and began spewing out troops. Did our best to hold them off, but they captured the Northern keep. And then human reinforcements arrived from their settlements to the South."
        [/message]

        [message]
            speaker="Kapou'e"
            message= _ "Are the shamans safe?"
        [/message]

        [message]
            speaker=Affman
            message= _ "When we realized that there was no way we could hold the humans off, we sent them east to a place near the Mourned Hills along with most of our women and children. The rest of us remained here to buy them some time."
        [/message]

        [message]
            speaker="Kapou'e"
            message= _ "Wise decision. We have actually come to speak to the shamans, but while we are here we must help you out of this scrape. Grüü, hold them while I run to the keep and organize our forces to counterattack. We can't defeat them by sea without ships, but we can destroy the foothold they have gained on the land."
        [/message]

        [message]
            speaker="Grüü"
            message= _ "I love this strategy, Chief!"
        [/message]
    [/event]

    [event]
        name=turn 4

        # add a warning about the transport galleon and the landing party here
        #[message]
        #    speaker="Grüü"
        #    message= _ ""
        #[/message]
    [/event]

    [event]
        name=turn refresh
        first_time_only=no

        [if]
            [variable]
                name=side_number
                equals=3
            [/variable]

            [then]
                [store_unit]
                    [filter]
                        type=Transport Galleon
                        side=3

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

                    kill=yes
                    variable=stored_transports
                [/store_unit]

                {FOREACH stored_transports i}
                    [store_locations]
                        x=14-28
                        y=14-29
                        terrain=Ww

                        [filter_adjacent_location]
                            terrain=Ds,*^Bw*
                        [/filter_adjacent_location]

                        [not]
                            find_in=already_picked_transport_destination_surroundings
                        [/not]

                        variable=possible_transport_destinations
                    [/store_locations]

                    {VARIABLE_OP transport_destination_index random "1..$possible_transport_destinations.length"}
                    {VARIABLE_OP transport_destination_index add -1}

                    {VARIABLE stored_transports[$i].variables.destination_x $possible_transport_destinations[$transport_destination_index].x}
                    {VARIABLE stored_transports[$i].variables.destination_y $possible_transport_destinations[$transport_destination_index].y}
                    {VARIABLE stored_transports[$i].variables.destination_set yes}

                    [store_locations]
                        x=$stored_transports[$i].variables.destination_x
                        y=$stored_transports[$i].variables.destination_y
                        radius=2

                        [filter_radius]
                            terrain=Ww,Ds,*^Bw*
                        [/filter_radius]

                        [or]
                            find_in=already_picked_transport_destination_surroundings
                        [/or]

                        variable=already_picked_transport_destination_surroundings
                    [/store_locations]

                    [unstore_unit]
                        variable=stored_transports[$i]
                    [/unstore_unit]
                {NEXT i}

                [store_unit]
                    [filter]
                        type=Transport Galleon
                        side=3

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

                    kill=yes
                    variable=stored_transports
                [/store_unit]

                {FOREACH stored_transports i}
                    {VARIABLE stored_transports[$i].goto_x $stored_transports[$i].variables.destination_x}
                    {VARIABLE stored_transports[$i].goto_y $stored_transports[$i].variables.destination_y}

                    [unstore_unit]
                        variable=stored_transports[$i]
                    [/unstore_unit]
                {NEXT i}

                [store_unit]
                    [filter]
                        type=Transport Galleon
                        side=3

                        [filter_wml]
                            [variables]
                                landed=yes
                            [/variables]
                        [/filter_wml]
                    [/filter]

                    kill=yes
                    variable=stored_transports
                [/store_unit]

                {FOREACH stored_transports i}
                    {VARIABLE stored_transports[$i].moves 0}

                    [unstore_unit]
                        variable=stored_transports[$i]
                    [/unstore_unit]
                {NEXT i}

                {CLEAR_VARIABLE stored_transports}
            [/then]
        [/if]
    [/event]

    [event]
        name=moveto
        first_time_only=no

        [filter]
            type=Transport Galleon

            [not]
                [filter_wml]
                    [variables]
                        landed=yes
                    [/variables]
                [/filter_wml]
            [/not]

            [filter_wml]
                [variables]
                    destination_x=$x1
                    destination_y=$y1
                [/variables]
            [/filter_wml]
        [/filter]

        {VARIABLE unit.variables.landed yes}

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

        {RANDOM 0..2}

#define HUMAN_PILLAGER TYPE X Y
    [unit]
        side=3
        type={TYPE}
        x,y={X},{Y}
        random_traits=yes
        generate_name=yes
        moves=0
    [/unit]
#enddef

        [switch]
            variable=random

            [case]
                value=0

                {HUMAN_PILLAGER Fencer $x1 $y1}
                {HUMAN_PILLAGER Swordsman $x1 $y1}
                {HUMAN_PILLAGER Mage $x1 $y1}
            [/case]

            [case]
                value=1

                {HUMAN_PILLAGER Cavalryman $x1 $y1}
                {HUMAN_PILLAGER Javelineer $x1 $y1}
                {HUMAN_PILLAGER Bowman $x1 $y1}
            [/case]

            [case]
                value=2

                {HUMAN_PILLAGER Pikeman $x1 $y1}
                {HUMAN_PILLAGER Bowman $x1 $y1}
                {HUMAN_PILLAGER Fencer $x1 $y1}
            [/case]
        [/switch]

        [message]
            side=3
            [filter_adjacent]
                x,y=$x1,$y1
            [/filter_adjacent]
            message= _ "Pillage! Let's plunder these orcs!"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Slowhand
        [/filter]
        [message]
            speaker=unit
            message= _ "Aaaargh! I die!"
        [/message]
        [message]
            speaker="Kapou'e"
            message= _ "Finally, you pay for what you did to my orc brothers!"
            image=portraits/kapoue-angry.png
        [/message]
    [/event]

    [event]
        name=enemies defeated

        [message]
            speaker="Kapou'e"
            message= _ "We are victorious at last. Someone go tell the shamans that they can come out now."
        [/message]

        [unstore_unit]
            variable=Pirk_store
            find_vacant=yes
        [/unstore_unit]
        [unstore_unit]
            variable=Gork_store
            find_vacant=yes
        [/unstore_unit]
        [unstore_unit]
            variable=Vraurk_store
            find_vacant=yes
        [/unstore_unit]

        {CLEAR_VARIABLE Pirk_store}
        {CLEAR_VARIABLE Gork_store}
        {CLEAR_VARIABLE Vraurk_store}

        [message]
            speaker=Gork
            message= _ "Congratulations on your victory, Kapou'e. You do honor to the memory of your father."
        [/message]
        [message]
            speaker="Kapou'e"
            message= _ "Thanks, but I have news. Since the forces here were certain they were going to be defeated, they sent the shamans to the Mourned Hills. If we want to meet them, we must go after them."
        [/message]
        [message]
            speaker=Pirk
            message= _ "Oh, great. That means we have to cross the Desert of Death which is full of poisonous giant scorpions and human outlaws. And bypassing it would take too long! Not to mention after this desert, we'll have to cross the Silent Forest!"
        [/message]
        [message]
            speaker=Grüü
            message= _ "Well, we have no choice ... I've never tasted scorpions but I am sure they are good. This journey will be fun."
        [/message]

        {CLEAR_VARIABLE possible_transport_destinations,already_picked_transport_destination_surroundings}

        [endlevel]
            result=victory
            bonus=yes
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

    {campaigns/Son_Of_The_Black_Eye/utils/deaths.cfg}
[/scenario]
