#textdomain wesnoth-ai

[test]
    id=messenger_escort
    name= _ "Messenger Escort"
    next_scenario=micro_ai_test

    map_file=ai/micro_ais/maps/messenger_escort.map

    {DEFAULT_SCHEDULE}
    turns=unlimited
    victory_when_enemies_defeated=no

    [side]
        side=1
        controller=human
        suppress_end_turn_confirmation=yes
        name= _ "Vanak"
        id=Vanak
        type=Orcish Ruler
        persistent=no

        team_name=Vanak
        user_team_name=_"Orcs"
        recruit=Orcish Grunt,Orcish Archer,Orcish Assassin,Wolf Rider

        gold=100
    [/side]

    [side]
        side=2
        controller=ai
        no_leader=yes
        persistent=no

        team_name=messenger
        user_team_name= _ "Messenger"

        gold=0
        income=-2
    [/side]

    [side]  # This side is only here because we need one persistent side for the game to go on
        side=3
        controller=null
        persistent=yes
        save_id=Grnk
        hidden=yes
    [/side]

    # Prestart actions
    [event]
        name=prestart

        {VARIABLE scenario_name messenger_escort}

        [micro_ai]
            side=2
            ai_type=messenger_escort
            action=add

            [filter]
                id=messenger
            [/filter]
            waypoint_x=31,24,27,28
            waypoint_y=20,14,7,1
        [/micro_ai]

        # Put the messenger side units out there
        [unit]
            type=Dragoon
            id=messenger
            name= _ "Messenger"
            side=2
            x,y=30,27
            random_traits=no
            [modifications]
                {TRAIT_LOYAL_HERO}
            [/modifications]
        [/unit]
        {NOTRAIT_UNIT 2 Dragoon 30 26}
        [unit]
            type=Cavalryman
            side=2
            x,y=29,27
            [modifications]
                {TRAIT_QUICK}
            [/modifications]
        [/unit]
        [unit]
            type=Cavalryman
            side=2
            x,y=31,27
            [modifications]
                {TRAIT_QUICK}
            [/modifications]
        [/unit]
        [unit]
            type=Cavalryman
            side=2
            x,y=29,28
            [modifications]
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        # And the orcs
        {NOTRAIT_UNIT 1 (Orcish Grunt) 14 18}
        {NOTRAIT_UNIT 1 (Orcish Archer) 15 19}
        {NOTRAIT_UNIT 1 (Orcish Grunt) 14 17}

        {NOTRAIT_UNIT 1 (Orcish Archer) 12 19}
        {NOTRAIT_UNIT 1 (Orcish Archer) 12 20}
        [unit]
            type=Wolf Rider
            side=1
            x,y=10,20
            [modifications]
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        # waypoints for AI
        {PLACE_IMAGE "scenery/signpost.png" 31 20}
        {SET_LABEL 31 20 _"Messenger Waypoint 1"}
        {PLACE_IMAGE "scenery/signpost.png" 24 14}
        {SET_LABEL 24 14 _"Messenger Waypoint 2"}
        {PLACE_IMAGE "scenery/signpost.png" 27 7}
        {SET_LABEL 27 7 _"Messenger Waypoint 3"}
        # Goal signpost for AI
        {PLACE_IMAGE "scenery/signpost.png" 28 1}
        {SET_LABEL 28 1 _"AI moves Messenger here"}
    [/event]

    [event]
        name=start

        {STORE_UNIT_VAR id=Vanak profile profile}
        [message]
            speaker=Vanak
            image=$profile~FL()~RIGHT()
            # po: This is orcish speech, deliberately omitting the "are" part of "They're"
            message= _ "They there! We them get!"
        [/message]
        {CLEAR_VARIABLE profile}
        [message]
            speaker=messenger
            message= _ "Men, I need to get to that signpost in the north, to get the message to our leader. Let’s head up there as quickly as we can."
        [/message]
        # wmllint: unbalanced-on
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            caption= _ "Notes"
            message= _ "The Messenger Escort AI will try to move the dragoon messenger to the signpost in the north, while protecting him as well as possible with the other units. Vanak’s orcs need to stop him.

Note that the messenger route is set up through a series of waypoints here simply to demonstrate how to use waypoints. On this map, using only a single waypoint at the end of the route would work just as well (or probably even better).

Also note that the messenger does not have to get exactly to each signpost (except for the last one), getting close is good enough.

The Messenger Escort AI is coded as a Micro AI. A Micro AI can be added and adapted to the need of a scenario easily using only WML and the [micro_ai] tag. Check out the <span color='#00A000'>Micro AI wiki page</span> at https://wiki.wesnoth.org/Micro_AIs for more information."
        [/message]
        # wmllint: unbalanced-off

        [objectives]
            side=1
            [objective]
                description= _ "Defeat the messenger"
                condition=win
            [/objective]
            [objective]
                description= _ "Messenger gets to the signpost"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Vanak"
                condition=lose
            [/objective]
        [/objectives]
    [/event]

    # When Messenger makes it to the signpost: defeat
    [event]
        name=moveto
        [filter]
            id=messenger
            x,y=28,1
        [/filter]

        [message]
            speaker=messenger
            message= _ "I made it! Now our people will be safe."
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    # When Messenger dies: victory
    [event]
        name=last breath
        [filter]
            id=messenger
        [/filter]
        [message]
            speaker=messenger
            message= _ "Nooo! All is lost. We will never stop the orcs now!"
        [/message]

        # So that game goes on to next scenario
        [modify_side]
            side=3
            controller=human
        [/modify_side]

        [endlevel]
            result=victory
            bonus=no
            carryover_percentage=0
            carryover_report=no
            linger_mode=no
        [/endlevel]
    [/event]
[/test]
