#textdomain wesnoth-thot
[scenario]
    name=_"Invaders"
    id="05_Invaders"
    next_scenario="06_High_Pass"
    victory_when_enemies_defeated=yes
    map_data="{campaigns/The_Hammer_of_Thursagan/maps/invaders.map}"
    {DEFAULT_SCHEDULE}
    turns=40	# BALANCE

    # This scenario is the Attack of the Fuzzy-Wuzzies. The player
    # will be seriously outnumbered, but careful defensive
    # maneuvering and use of veterans can save the day.

    {INTRO_AND_SCENARIO_MUSIC "revelation.ogg" "the_dangerous_symphony.ogg"}
    {EXTRA_SCENARIO_MUSIC "the_city_falls.ogg"}
    {EXTRA_SCENARIO_MUSIC "vengeful.ogg"}

    [label]
        x,y=22,21
        text=_"Ruined Castle"
    [/label]

    [story]
        [part]
            background=maps/wesnoth.png
            story= _ "The Alliance's road ended at the troll bridge. East of it lay only the wildlands."
        [/part]
        [part]
            show_title=yes
            {TO_INVADERS}
        [/part]
    [/story]

    [side]
        type="Dwarvish Fighter"
        id="Aiglondur"
        name=_"Aiglondur"
        canrecruit="1"
        side="1"
        controller="human"
        team_name="northern_alliance"
        user_team_name=_"Alliance"
        {FLAG_VARIANT knalgan}
        fog="no"
        shroud="no"
        recruit="Dwarvish Fighter,Dwarvish Thunderer,Dwarvish Guardsman, Dwarvish Scout"
        {GOLD 100 80 60}	# BALANCE
    [/side]

    [side]
        type=Orcish Warlord
        id=Tan-Malgar
        name= _ "Tan-Malgar"
        profile=portraits/orcs/transparent/grunt-2.png
        side=2
        canrecruit=yes
        recruit=Orcish Archer, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Goblin Pillager, Goblin Spearman

        {GOLD 220 260 300}	# BALANCE
        team_name=orcs
        user_team_name=_"Orcs"
        [ai]
            {NO_SCOUTS}
            recruitment_ignore_bad_movement=yes
            recruitment_pattern=scout,fighter,fighter,archer
            {ATTACK_DEPTH 4 5 5}
        [/ai]
        [ai]
            time_of_day=dusk,first_watch,second_watch
            aggression=0.75
            caution=0.0
            grouping=no
        [/ai]
    [/side]

    [side]
        type=Orcish Warlord
        id=Tan-Grolak
        name= _ "Tan-Grolak"
        profile=portraits/orcs/transparent/grunt-3.png
        side=3
        canrecruit=yes
#ifdef EASY
        recruit=Orcish Archer, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Goblin Pillager, Goblin Spearman
#endif

#ifdef NORMAL
        recruit=Orcish Archer, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Orcish Warrior, Goblin Pillager, Goblin Spearman
#endif

#ifdef HARD
        recruit=Orcish Archer, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Orcish Warrior, Goblin Knight, Goblin Pillager, Orcish Slayer, Goblin Spearman, Goblin Impaler
#endif

        {GOLD 180 220 360}	# BALANCE
        team_name=orcs
        user_team_name=_"Orcs"
        [ai]
            {NO_SCOUTS}
            recruitment_ignore_bad_movement=yes
#ifdef EASY
            recruitment_pattern=scout,fighter,fighter,archer
#endif
#ifdef NORMAL
            recruitment_pattern=scout,fighter,fighter,archer
#endif
#ifdef HARD
            recruitment_pattern=scout,fighter,fighter,mixed fighter,archer
#endif
            {ATTACK_DEPTH 4 5 5}
        [/ai]
        [ai]
            time_of_day=dusk,first_watch,second_watch
            aggression=0.75
            caution=0.0
            grouping=no
        [/ai]
        {INCOME 4 8 12}
    [/side]

    [side]
        type=Orcish Warlord
        id="Tan-Uthkar"
        name= _ "Tan-Uthkar"
        profile=portraits/orcs/transparent/warlord.png
        side=4
        canrecruit=yes
        recruit=Orcish Archer, Orcish Grunt, Wolf Rider, Orcish Warrior, Goblin Spearman
        {GOLD 180 220 360}	# BALANCE
        team_name=orcs
        user_team_name=_"Orcs"
        [ai]
            {NO_SCOUTS}
            recruitment_ignore_bad_movement=yes
            recruitment_pattern=scout,fighter,fighter,archer
            {ATTACK_DEPTH 4 5 5}
        [/ai]
        [ai]
            time_of_day=dusk,first_watch,second_watch
            aggression=0.75
            caution=0.0
            grouping=no
        [/ai]
    [/side]

    {campaigns/The_Hammer_of_Thursagan/utils/herodeaths.cfg}

    [side]
        # The bandit indigenes
        side=5
        no_leader=yes
        [ai]
            grouping=offensive
            village_value=4
        [/ai]
    [/side]

    # Here is the code for popping up random bandits on village
    # captures.
    #
    # Note: If the AI moves an unit onto a village spawning
    # villagers this unit will not attack even it is level 2
    # (vs. level 1), has 60% defense and will be healed the next
    # turn. Instead the AI will use other units to attack the spawned
    # units. This was reported as bug #12839 on the Wesnoth tracker
    #
    # Unfortunately, it appears this can't be fixed in a safe way.
    # The AI is not designed to deal with quite this dynamic an  environment
    [event]
        name=capture
        first_time_only=no
        [if]
            [variable]
                name=unit.side
                numerical_equals=5
            [/variable]
            [then]
                {CLEAR_VARIABLE cleared_$x1|_$y1|_village}
            [/then]
            [else]
                [if]
                    [variable]
                        name=cleared_$x1|_$y1|_village
                        not_equals=yes
                    [/variable]
                    [then]
                        [set_variable]
                            name=cleared_$x1|_$y1|_village
                            value=yes
                        [/set_variable]
                        # Compute the number of indigs that will pop up
                        [if]
                            [variable]
                                name=unit.side
                                numerical_equals=1
                            [/variable]
                            [then]
                                # The bandit villagers hate dwarves...
                                [set_variable]
                                    name=indigs
                                    random=0..2
                                [/set_variable]
                            [/then]
                            [else]
                                # ...but they hate orcs much worse.
                                [set_variable]
                                    name=indigs
                                    random=2..5
                                [/set_variable]
                            [/else]
                        [/if]
                        # Now place the indigs
                        [set_variable]
                            name=indig_countdown
                            value=$indigs
                        [/set_variable]
                        [while]
                            [variable]
                                name=indig_countdown
                                greater_than=0
                            [/variable]
                            [do]
                                [store_locations]
                                    [filter_adjacent_location]
                                        x,y=$x1,$y1
                                    [/filter_adjacent_location]

                                    [not]
                                        [filter]
                                        [/filter]
                                    [/not]

                                    variable=possible_indig_locations
                                [/store_locations]

                                [if]
                                    [variable]
                                        name=possible_indig_locations.length
                                        greater_than=0
                                    [/variable]
                                    [then]
                                        {VARIABLE_OP random_location_index random 1..$possible_indig_locations.length}
                                        [set_variable]
                                            name=random_location_index
                                            add=-1
                                        [/set_variable]
                                        {RANDOM (Footpad,Thief,Thug)}
                                        [unit]
                                            type=$random
                                            side=5
                                            x,y=$possible_indig_locations[$random_location_index].x,$possible_indig_locations[$random_location_index].y
                                            generate_name=yes
                                            random_traits=yes
                                        [/unit]
                                    [/then]
                                [/if]
                                [set_variable]
                                    name=indig_countdown
                                    add=-1
                                [/set_variable]
                            [/do]
                        [/while]
                        {CLEAR_VARIABLE indigs_countdown}
                        # Perform appropriate notifications
                        [if]
                            [variable]
                                name=indigs
                                greater_than=0
                            [/variable]
                            [then]
                                [message]
                                    speaker=unit
                                    message= _ "The villagers are attacking us!"
                                [/message]
                                [if]
                                    [variable]
                                        name=indigs_sighted
                                        equals=0
                                    [/variable]
                                    [then]
                                        [message]
                                            speaker=Aiglondur
                                            message= _ "Aye, it's still bandit country, right enough."
                                        [/message]
                                    [/then]
                                [/if]
                                [set_variable]
                                    name=indigs_sighted
                                    add=1
                                [/set_variable]
                            [/then]
                            [else]
                                [if]
                                    [variable]
                                        name=indigs_sighted
                                        greater_than=0
                                    [/variable]
                                    [then]
                                        [message]
                                            speaker=unit
                                            message= _ "No bandits in this village."
                                        [/message]
                                    [/then]
                                [/if]
                            [/else]
                        [/if]
                        {CLEAR_VARIABLE possible_indig_locations}
                        {CLEAR_VARIABLE indigs}
                    [/then]
                [/if]
            [/else]
        [/if]
    [/event]

    [event]
        name="prestart"
        [role]
            type=Dwarvish Steelclad,Dwarvish Thunderguard,Dwarvish Fighter,Dwarvish Thunderer
            [not]
                id=Aiglondur
            [/not]
            role=Scout
        [/role]

        [recall]
            id="Angarthing"
        [/recall]

        [recall]
            role=Scout
        [/recall]

        [set_variable]
            name=indigs_sighted
            value=0
        [/set_variable]

        [objectives]
            side="1"
            [objective]
                description=_"Defeat all enemies"
                condition="win"
            [/objective]
            [objective]
                description=_"Death of Aiglondur"
                condition="lose"
            [/objective]
            [objective]
                description=_"Death of Angarthing"
                condition="lose"
            [/objective]
            [objective]
                description=_"Time runs out"
                condition="lose"
            [/objective]

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

    [event]
        name="start"
        [message]
            speaker="Aiglondur"
            message=_"Stay alert, everyone, and keep together. This is bandit country...more than likely where Gothras and his gang came from."
        [/message]
        [message]
            role="Scout"
            #po: "muckle" = Scottish/archaic English meaning "great" or "large"
            message=_"Nae sign o' bandits I can see, captain -- but there are three muckle hosts of orcs off to our east."
        [/message]
        [message]
            speaker="Aiglondur"
            message=_"What's this? Large orcish war-bands so close to the Alliance's border? That can only mean trouble."
        [/message]
        [message]
            speaker="Tan-Malgar"
            message=_"Well, boys, we were planning to invade the Northern Alliance anyway...these dwarves should make a tasty appetizer."
        [/message]
        [message]
            speaker="Tan-Grolak"
            message=_"Yeah, boss. Anything to get away from those masked ones..."
        [/message]
        [message]
            speaker="Tan-Malgar"
            message=_"Be silent. We are orc warriors; we do not flee foes."
        [/message]
        [message]
            speaker="Tan-Uthkar"
            message=_"But, given a choice, we fight the weaker foe first."
        [/message]
    [/event]

    [event]
        name=enemies defeated

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