#textdomain wesnoth-tutorial
{./utils.cfg}
# Comment this out for a faster (no-commentry) tutorial for testing.
{./2_Speaking.cfg}

#define BADGUY TYPE NAME POSITION
    [unit]
        id={NAME}
        generate_name=yes
        type={TYPE}
        x,y={POSITION}
        moves=0
        side=2
        animate=yes
    [/unit]
    [redraw][/redraw]
#enddef

#define DEFEND_ISLAND
    [if]
        {NUMEQ island_defended 0}
        {NUMEQ dumbo_dead 1}
        [then]
            {VARIABLE island_defended 1}
            {LABEL (_"Patch of forest") 10,14}
            {TALK_ABOUT_LOC 10,14 (_"Now put an unwounded unit, preferably a Fighter, in that patch of forest on the south-east of the island; a nice, defensible spot.")}
            {STUDENT (_"Can one unit survive against all those enemies?")}
            {TEACHER (_"With a little help, yes. If you move your Shaman next to the defending unit, she will heal it 4 hitpoints per turn. Just be careful not to expose the Shaman to attack since she is fairly weak herself.")}
            {PRINT (_"Move a unit (a Fighter if possible) to the patch of forest")}
            [event]
                name=moveto
                [filter]
                    x,y=10,14
                [/filter]
                {UNLABEL 10,14}
                {PRINT (_"Advance other units onto the island or to capture villages, then <b>End Turn</b>")}
                [allow_undo][/allow_undo]
            [/event]
        [/then]
    [/if]
#enddef

#define REFUND_AND_REMOVE_RECRUIT
    [if]
        [variable]
            # is it a recall?
            # FIXME: units could be recalled with 0 xp
            name=recruit.experience
            greater_than=0
        [/variable]
        [then]
            [gold]
                side=1
                amount=20
            [/gold]
            # put the unit back into the recall list
            # ugly trait hack...
            [unit]
                side=$recruit.side
                name=$recruit.name
                type=$recruit.type
                experience=$recruit.experience
                gender=$recruit.gender
                [modifications]
                    [trait]
                        id=$recruit.modifications.trait[0].id
                        name=$recruit.modifications.trait[0].name
                        [effect]
                            apply_to=$recruit.modifications.trait[0].effect[0].apply_to
                            # hitpoints (resilient & quick)
                            increase_total=$recruit.modifications.trait[0].effect[0].increase_total
                            times=$recruit.modifications.trait[0].effect[0].times
                            # damage (strong, dextrous)
                            increase_damage=$recruit.modifications.trait[0].effect[0].increase_damage
                            range=$recruit.modifications.trait[0].effect[0].range
                            # movement (quick), experience (intelligent)
                            increase=$recruit.modifications.trait[0].effect[0].increase
                        [/effect]
                        [effect]
                            apply_to=$recruit.modifications.trait[0].effect[1].apply_to
                            # hitpoints (resilient & quick)
                            increase_total=$recruit.modifications.trait[0].effect[1].increase_total
                            times=$recruit.modifications.trait[0].effect[1].times
                            # damage (strong, dextrous)
                            increase_damage=$recruit.modifications.trait[0].effect[1].increase_damage
                            range=$recruit.modifications.trait[0].effect[1].range
                            # movement (quick), experience (intelligent)
                            increase=$recruit.modifications.trait[0].effect[1].increase
                        [/effect]
                    [/trait]
                    [trait]
                        id=$recruit.modifications.trait[1].id
                        name=$recruit.modifications.trait[1].name
                        [effect]
                            apply_to=$recruit.modifications.trait[1].effect[0].apply_to
                            # hitpoints (resilient & quick)
                            increase_total=$recruit.modifications.trait[1].effect[0].increase_total
                            times=$recruit.modifications.trait[1].effect[0].times
                            # damage (strong, dextrous)
                            increase_damage=$recruit.modifications.trait[1].effect[0].increase_damage
                            range=$recruit.modifications.trait[1].effect[0].range
                            # movement (quick), experience (intelligent)
                            increase=$recruit.modifications.trait[1].effect[0].increase
                        [/effect]
                        [effect]
                            apply_to=$recruit.modifications.trait[1].effect[1].apply_to
                            # hitpoints (resilient & quick)
                            increase_total=$recruit.modifications.trait[1].effect[1].increase_total
                            times=$recruit.modifications.trait[1].effect[1].times
                            # damage (strong, dextrous)
                            increase_damage=$recruit.modifications.trait[1].effect[1].increase_damage
                            range=$recruit.modifications.trait[1].effect[1].range
                            # movement (quick), experience (intelligent)
                            increase=$recruit.modifications.trait[1].effect[1].increase
                        [/effect]
                    [/trait]
                [/modifications]
            [/unit]
        [/then]
        [else]
            # simply use cost to return
            [gold]
                side=1
                amount=$recruit.cost
            [/gold]
        [/else]
    [/if]
#enddef

#define CHECK_INTELLIGENT NAME
    [if]
        [variable]
            # Ignoring single-trait units, as we don't have those during the tutorial
            name={NAME}.modifications.trait.length
            equals=2
        [/variable]
        [then]
            [if]
                [variable]
                    name={NAME}.modifications.trait[0].id
                    equals=intelligent
                [/variable]
                [or]
                    [variable]
                        name={NAME}.modifications.trait[1].id
                        equals=intelligent
                    [/variable]
                [/or]
                [then]
                    {VARIABLE is_intelligent yes}
                [/then]
                [else]
                    {VARIABLE is_intelligent no}
                [/else]
            [/if]
        [/then]
        [else]
            {VARIABLE is_intelligent no}
        [/else]
    [/if]
#enddef

#define IMPORTANT_UNIT NAME
    {CHECK_INTELLIGENT {NAME}}
    [if]
        # Archer needs 44/35(intelligent), Fighter needs 40/32
        [variable]
            name={NAME}.type
            equals=Elvish Archer
        [/variable]
        {BOOLEQ is_intelligent no}
        [variable]
            name={NAME}.experience
            greater_than=35
        [/variable]
        [or]
            [variable]
                name={NAME}.type
                equals=Elvish Archer
            [/variable]
            {BOOLEQ is_intelligent yes}
            [variable]
                name={NAME}.experience
                greater_than=26
            [/variable]
        [/or]
        [or]
            [variable]
                name={NAME}.type
                equals=Elvish Fighter
            [/variable]
            {BOOLEQ is_intelligent no}
            [variable]
                name={NAME}.experience
                greater_than=31
            [/variable]
        [/or]
        [or]
            [variable]
                name={NAME}.type
                equals=Elvish Fighter
            [/variable]
            {BOOLEQ is_intelligent yes}
            [variable]
                name={NAME}.experience
                greater_than=23
            [/variable]
        [/or]
        [then]
            {VARIABLE commented 0}
            {FOREACH galdrad_comments i}
                [if]
                    [variable]
                        name=galdrad_comments[$i].id
                        equals=${NAME}.id
                    [/variable]
                    [then]
                        {VARIABLE commented 1}
                    [/then]
                [/if]
            {NEXT i}
            {CLEAR_VARIABLE i}

            [if]
                {NUMEQ commented 0}
                [then]
                    [store_unit]
                        [filter]
                            id=${NAME}.id
                        [/filter]
                        variable=galdrad_comments
                        mode=append
                    [/store_unit]
                    {TEACHER (_"That unit is about one kill (8 experience points) away from gaining a level! Do not let it die!")}
                [/then]
            [/if]
            {CLEAR_VARIABLE commented}
        [/then]
    [/if]
    {CLEAR_VARIABLE is_intelligent}
#enddef

#define DEFENDER_INJURED NAME
    [if]
        {NUMEQ {NAME}.side 1}
        [variable]
            name={NAME}.hitpoints
            less_than=19
        [/variable]
        [variable]
            name={NAME}.hitpoints
            greater_than=0
        [/variable]
        [then]
            {VARIABLE complained 0}

            # FIXME: If same unit gets attacked twice in same turn, this
            # does not seem to find it the second time. Some internal bug?

            {FOREACH unit_complained i}
                [if]
                    [variable]
                        name=unit_complained[$i].id
                        equals=${NAME}.id
                    [/variable]
                    [then]
                        {VARIABLE complained 1}
                    [/then]
                [/if]
            {NEXT i}

            [if]
                {NUMEQ complained 0}
                [then]
                    [store_unit]
                        [filter]
                            id=${NAME}.id
                        [/filter]
                        variable=unit_complained
                        mode=append
                    [/store_unit]
                    [if]
                        {NUMEQ complain_msg 2}
                        [then]
                            [message]
                                speaker=second_unit
                                message= _"I hope I have a chance to retreat after this!"
                            [/message]
                            {VARIABLE_OP complain_msg add 1}
                        [/then]
                    [/if]

                    [if]
                        {NUMEQ complain_msg 1}
                        [then]
                            [message]
                                speaker=second_unit
                                message= _"One lucky attack by an Orcish Grunt, and I’m done for!"
                            [/message]
                            {VARIABLE_OP complain_msg add 1}
                        [/then]
                    [/if]

                    [if]
                        {NUMEQ complain_msg 0}
                        [then]
                            [message]
                                speaker=second_unit
                                message= _"Ouch! I could make use of some healing in a village."
                            [/message]
                            {VARIABLE_OP complain_msg add 1}
                        [/then]
                    [/if]
                [/then]
            [/if]
            {CLEAR_VARIABLE i}
            {CLEAR_VARIABLE complained}
            {IMPORTANT_UNIT {NAME}}
        [/then]
    [/if]
#enddef

#define CHECK_INCOME
    [if]
        {NUMEQ income_exceeded 0}
        [then]
            [store_side]
            [/store_side]
            [if]
                [variable]
                    name=side.gold
                    greater_than=13
                [/variable]
                [then]
                    {VARIABLE income_exceeded 1}
                    {STUDENT (_"I have $side.gold gold; enough to recruit!")}
                    {TALK_ABOUT_LOC 9,15 (_"Yes, keep recruiting more units: I think you might need them!")}
                [/then]
            [/if]
            {CLEAR_VARIABLE side}
        [/then]
    [/if]
#enddef

[tutorial]
    id=2_Tutorial
    name= _"Wesnoth Tutorial Part II"
    map_data="{campaigns/tutorial/maps/2_Tutorial.map}"
    turns=26

    {DEFAULT_SCHEDULE}

    [side]
        type=Fighter
        id=student
        name= _"Konrad"
        save_id=human_player
        persistent=yes
        canrecruit=yes
        side=1
        gold=123
        controller=human
        recruit=Elvish Fighter,Elvish Archer,Elvish Shaman
    [/side]

    [side]
        type=Orcish Warrior
        id=Thrag
        name= _"Thrag"
        side=2
        canrecruit=yes
        recruit=Orcish Grunt,Wolf Rider,Orcish Archer
        gold=0
        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            [aspect]
                id=aggression
                [facet]
                    # When we unleash you, you *will* attack.
                    value=1.0
                    turns=1-6
                [/facet]
            [/aspect]
        [/ai]
    [/side]

    [side]
        no_leader=yes
        side=3
        team_name=1
        controller=null
    [/side]

    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description= _"Defeat the Orc Leader"
                condition=win
            [/objective]
            [objective]
                description= _"Death of Konrad"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}
        [/objectives]

        [if]
            [variable]
                name=gender
                equals=female
            [/variable]
            [then]
                [store_unit]
                    [filter]
                        id=student
                    [/filter]
                    kill=yes
                    variable=student_save
                [/store_unit]
                {VARIABLE student_x $student_save.x}
                {VARIABLE student_y $student_save.y}
                [unit]
                    type=Fighteress
                    side=1
                    x,y=$student_x,$student_y
                    id=student
                    profile=portraits/lisar.png
                    name= _"Li’sar"
                    canrecruit=yes
                [/unit]
                [objectives]
                    side=1
                    [objective]
                        description= _"Defeat the Orc Leader"
                        condition=win
                    [/objective]
                    [objective]
                        description= _"Death of Li’sar"
                        condition=lose
                    [/objective]

                    {TURNS_RUN_OUT}
                [/objectives]
            [/then]
        [/if]

        [unit]
            id=Galdrad
            name= _"Galdrad"
            type=Elvish Captain
            x,y=12,2
            side=3
        [/unit]

        [unit]
            id=Dumbo
            generate_name=yes
            type=Orcish Grunt
            x,y=8,13
            side=2
            # Make sure the two archers can't take him out!
            [modifications]
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]
    [/event]

    [event]
        name=start

        {VARIABLE dumbo_dead 0}
        {VARIABLE villages_around_keep 0}
        {VARIABLE village_warn 0}
        {VARIABLE recruit_num 1}
        {VARIABLE income_exceeded 0}
        {STUDENT (_"Ho, Galdrad! Has Delfador conjured something else to beat me with? A flock of scarecrows, perhaps?")}
# wmlindent: start ignoring
        {GENDER ({TEACHER (_"This is no game, Konrad! " +
            _"Orcs have encamped across the river. This is elven country; they are fools to enter here. We Elves are fast and hard to hit in forests. You must defeat their leader so they never threaten us again. I will advise you.")}) ({TEACHER (_"This is no game, Li’sar! " +
            _"Orcs have encamped across the river. This is elven country; they are fools to enter here. We Elves are fast and hard to hit in forests. You must defeat their leader so they never threaten us again. I will advise you.")})}
# wmlindent: stop ignoring
        {STUDENT (_"What should I do?")}

        # Now we’re into it... start music.
        {DEFAULT_MUSIC_PLAYLIST}

        {TALK_ABOUT Dumbo (_"First, we will have to deal with the Orcish Grunt stationed in the middle of the river. He should be little trouble.")}
        {TALK_ABOUT Thrag (_"By then, their leader will have recruited more units to send against us and the real fight will begin.")}
        {LABEL (_"Shallow") 19,16}
        {LABEL (_"Shallow") 18,16}
        {LABEL (_"Shallow") 18,14}
        {LABEL (_"Shallow") 19,15}
        {LABEL (_"Shallow") 20,14}
        {LABEL (_"Deep water") 14,14}
        {LABEL (_"Deep water") 20,16}
        {LABEL (_"Deep water") 4,14}

        {TALK_ABOUT_LOC 19,14 (_"See this dark blue water? It’s too deep for either side to cross. The orcs could slowly wade through that narrow band of shallow lighter-blue water in the east; but we could stand on the shore and force them to fight us from the water, where they are exposed and we are protected by the forest.")}
        {UNLABEL 19,16}
        {UNLABEL 18,16}
        {UNLABEL 18,14}
        {UNLABEL 19,15}
        {UNLABEL 20,14}
        {UNLABEL 14,14}
        {UNLABEL 20,16}
        {UNLABEL 4,14}
        {LABEL (_"Village") 11,14}
        {TALK_ABOUT_LOC 9,14 (_"The more likely attack, then, is across the bridge. That middle island is the key: it has a village for healing injured units and forests in which we fight so well.")}
        {UNLABEL 11,14}
# wmlindent: start ignoring
        {TEACHER (_"To start, we will need some units:
two Elvish Fighters
two Elvish Archers
one Elvish Shaman")}
# wmlindent: stop ignoring

        # See if there are two fighters worth recalling
        [store_unit]
            variable=recall
            [filter]
                x,y=recall,recall
            [/filter]
        [/store_unit]

        # Higher Level units should come first.
        {VARIABLE recall_xp1 0}
        {VARIABLE recall_xp2 0}
        {FOREACH recall i}
            {VARIABLE temp_xp $recall[$i].experience}
            {VARIABLE_OP temp_xp add $recall[$i].variables.previous_xp}
            [if]
                [variable]
                    name=temp_xp
                    greater_than=$recall_xp1
                [/variable]
                [then]
                    # Move anything from slot 1 to slot 2
                    [if]
                        [variable]
                            name=recall_xp1
                            greater_than=0
                        [/variable]
                        [then]
                            {VARIABLE_OP recall_i2 value $recall_i1}
                            {VARIABLE_OP recall_xp2 value $recall_xp1}
                        [/then]
                    [/if]

                    {VARIABLE_OP recall_i1 value $i}
                    {VARIABLE_OP recall_xp1 value $temp_xp}
                [/then]
                [else]
                    [if]
                        [variable]
                            name=temp_xp
                            greater_than=$recall_xp2
                        [/variable]
                        [then]
                            {VARIABLE_OP recall_i2 value $i}
                            {VARIABLE_OP recall_xp2 value $temp_xp}
                        [/then]
                    [/if]
                [/else]
            [/if]
        {NEXT i}
        {CLEAR_VARIABLE i}

        [if]
            [variable]
                name=recall_xp1
                greater_than=0
            [/variable]
            [then]
                {VARIABLE_OP recall_name1 value $recall[$recall_i1].name}
                [if]
                    [variable]
                        name=recall_xp2
                        greater_than=0
                    [/variable]
                    [then]
                        {VARIABLE_OP recall_name2 value $recall[$recall_i2].name}
                        # We have two worth recalling.
                        [if]
                            [variable]
                                name=recall_xp1
                                equals=$recall_xp2
                            [/variable]
                            [then]
                                {TEACHER (_"During your tutorial, both $recall_name1 and $recall_name2 gained $recall_xp1 experience points. You should <i>recall</i> them now so they can gain more experience, rather than recruiting new Fighters.")}
                            [/then]
                            [else]
                                {TEACHER (_"During your tutorial, $recall_name1 gained $recall_xp1 experience points, and $recall_name2 gained $recall_xp2. You should <i>recall</i> them now so they can gain more experience, rather than recruiting new Fighters.")}
                            [/else]
                        [/if]
                    [/then]
                    [else]
                        # We have one worth recalling.
                        {TEACHER (_"During your tutorial, $recall_name1 gained $recall_xp1 experience points. You should recall that unit now, and recruit a second one (which is cheaper than recalling, anyway).")}
                    [/else]
                [/if]
                {LABEL (_"RECALL $recall_name1") 11,3}
                {PRINT (_"Right click on the tile north-east of you and <i>recall</i> $recall_name1")}
            [/then]
            [else]
                [if]
                    [variable]
                        name=recall.length
                        greater_than=0
                    [/variable]
                    [then]
                        {TEACHER (_"If any Elvish Fighters from your last battle had experience, we would <i>recall</i> them to the current battlefield. However, your veterans gained no experience so it’s cheaper to recruit new units instead. Recruit an Elvish Fighter.")}
                    [/then]
                    [else]
                        {TEACHER (_"If you had any experienced units alive from your last battle we would <i>recall</i> them. Instead we must recruit some new Elvish Fighters.")}
                    [/else]
                [/if]
                {LABEL (_"Elvish Fighter") 11,3}
                {PRINT (_"Right click on the tile north-east of you and recruit an Elvish Fighter")}
            [/else]
        [/if]
    [/event]

    # Check they recall/recruit correctly in their first turn.
    [event]
        name=recruit,recall
        first_time_only=no
        [filter]
            side=1
        [/filter]

        [if]
            [variable]
                name=recruit_num
                less_than=6
            [/variable]
            [then]
                # What did they recruit?
                [store_unit]
                    variable=recruit
                    kill=yes
                    [filter]
                        x,y=$x1,$y1
                    [/filter]
                [/store_unit]
            [/then]
        [/if]

        [if]
            {NUMEQ recruit_num 5}
            [then]
                [if]
                    [variable]
                        name=recruit.type
                        not_equals=Elvish Shaman
                    [/variable]
                    [then]
                        {REFUND_AND_REMOVE_RECRUIT}
                        {TEACHER (_"No! I said recruit an Elvish <i>Shaman</i>! Now try again...")}
                    [/then]
                    [else]
                        [unstore_unit]
                            variable=recruit
                        [/unstore_unit]
                        {VARIABLE_OP recruit_num add 1}
                        {UNLABEL 10,2}
                        {CLEAR_PRINT}
                        {TEACHER (_"The Shaman is a fairly weak unit, but she has the ability to <i>heal</i> friendly units around her. She also has a special attack which <i>slows</i> enemies, halving the damage they do.")}
                        {STUDENT (_"So, should I end my turn now?")}
                        # FIXME: If any level 2 units, costs will be higher.
                        {TEACHER (_"While none of your recruited units can move, you still can. Your five units cost you 5 gold in upkeep, leaving you 3 gold poorer per turn. You need more income.")}
# wmlindent: start ignoring
                        {GENDER ({PRINT (_"Move Konrad to capture a village")})
                                ({PRINT (_"Move Li’sar to capture a village")})}
# wmlindent: stop ignoring
                    [/else]
                [/if]
            [/then]
        [/if]

        [if]
            {NUMEQ recruit_num 4}
            [then]
                [if]
                    [variable]
                        name=recruit.type
                        not_equals=Elvish Archer
                    [/variable]
                    [then]
                        {REFUND_AND_REMOVE_RECRUIT}
                        {TEACHER (_"No! I said recruit an Elvish <i>Archer</i>! Now try again...")}
                    [/then]
                    [else]
                        {VARIABLE_OP recruit_num add 1}
                        [unit]
                            id=Eowynial
                            name= _"Eowynial"
                            type=Elvish Archer
                            x,y=$x1,$y1
                            side=1
                            gender=female
                            upkeep=full
                            moves=0
                            [modifications]
                                {TRAIT_QUICK}
                                {TRAIT_RESILIENT}
                            [/modifications]
                        [/unit]
                        {EXPLAIN_QUICK_RESILIENT (_"Eowynial")}

                        {UNLABEL 9,4}
                        {UNLABEL 9,3}
                        {LABEL (_"Shaman") 10,2}
                        {PRINT (_"Recruit an Elvish Shaman to your north")}
                    [/else]
                [/if]
            [/then]
        [/if]

        [if]
            {NUMEQ recruit_num 3}
            [then]
                [if]
                    [variable]
                        name=recruit.type
                        not_equals=Elvish Archer
                    [/variable]
                    [then]
                        {REFUND_AND_REMOVE_RECRUIT}
                        {TEACHER (_"No! I said recruit an Elvish <i>Archer</i>! Now try again...")}
                    [/then]
                    [else]
                        {VARIABLE_OP recruit_num add 1}
                        [unit]
                            id=Elriend
                            name= _"Elriend"
                            type=Elvish Archer
                            x,y=$x1,$y1
                            side=1
                            upkeep=full
                            moves=0
                            [modifications]
                                {TRAIT_STRONG}
                                {TRAIT_INTELLIGENT}
                            [/modifications]
                        [/unit]
                        {EXPLAIN_STRONG_INTELLIGENT (_"Elriend")}
                    [/else]
                [/if]
            [/then]
        [/if]

        [if]
            {NUMEQ recruit_num 2}
            [then]
                [if]
                    [variable]
                        name=recall_xp2
                        greater_than=0
                    [/variable]
                    [then]
                        # You were supposed to recall $recall_name2.
                        [if]
                            [variable]
                                name=recruit.name
                                not_equals=$recall_name2
                            [/variable]
                            [then]
                                {REFUND_AND_REMOVE_RECRUIT}
                                {TEACHER (_"No! I said <i>recall</i> $recall_name2|! Now try again...")}
                            [/then]
                            [else]
                                {VARIABLE_OP recruit_num add 1}
                                [unstore_unit]
                                    variable=recruit
                                [/unstore_unit]
                                {UNLABEL 12,3}
# wmlindent: start ignoring
                                {LABEL (_"Archer #1") 9,4}
                                {LABEL (_"Archer #2") 9,3}
# wmlindent: stop ignoring
                                {PRINT (_"Recruit two Elvish Archers in the tiles to your west")}
                            [/else]
                        [/if]
                    [/then]
                    [else]
                        # You were supposed to recruit a Fighter.
                        [if]
                            [variable]
                                name=recruit.type
                                not_equals=Elvish Fighter
                            [/variable]
                            [then]
                                {REFUND_AND_REMOVE_RECRUIT}
                                {TEACHER (_"No! I said recruit an Elvish <i>Fighter</i>! Now try again...")}
                            [/then]
                            [else]
                                {VARIABLE_OP recruit_num add 1}
                                [unit]
                                    id=Golir
                                    name= _"Golir"
                                    type=Elvish Fighter
                                    x,y=$x1,$y1
                                    side=1
                                    upkeep=full
                                    moves=0
                                    [modifications]
                                        {TRAIT_QUICK}
                                        {TRAIT_RESILIENT}
                                    [/modifications]
                                [/unit]
                                {EXPLAIN_QUICK_RESILIENT (_"Golir")}

                                {UNLABEL 12,3}
# wmlindent: start ignoring
                                {LABEL (_"Archer #1") 9,4}
                                {LABEL (_"Archer #2") 9,3}
# wmlindent: stop ignoring
                                {PRINT (_"Recruit two Elvish Archers in the tiles to your west")}
                            [/else]
                        [/if]
                    [/else]
                [/if]
            [/then]
        [/if]

        [if]
            {NUMEQ recruit_num 1}
            [then]
                [if]
                    [variable]
                        name=recall_xp1
                        greater_than=0
                    [/variable]
                    [then]
                        # You were supposed to recall $recall_name1.
                        [if]
                            [variable]
                                name=recruit.name
                                not_equals=$recall_name1
                            [/variable]
                            [then]
                                [if]
                                    [variable]
                                        name=recruit.name
                                        equals=$recall_name2
                                    [/variable]
                                    [then]
                                        {REFUND_AND_REMOVE_RECRUIT}
                                        {TEACHER (_"No! I said recall $recall_name1, not $recall_name2|! Now try again...")}
                                    [/then]
                                    [else]
                                        {REFUND_AND_REMOVE_RECRUIT}
                                        {TEACHER (_"No! I said <i>recall</i> $recall_name1 from the last battle, not recruit a new $recruit.language_name|! Now try again...")}
                                    [/else]
                                [/if]
                            [/then]
                            [else]
                                {VARIABLE_OP recruit_num add 1}
                                {UNLABEL 11,3}
                                [unstore_unit]
                                    variable=recruit
                                [/unstore_unit]
                                [if]
                                    [variable]
                                        name=recall_xp2
                                        greater_than=0
                                    [/variable]
                                    [then]
                                        {PRINT (_"Right click on the tile east of you and recall $recall_name2")}
                                        {LABEL (_"RECALL $recall_name2") 12,3}
                                    [/then]
                                    [else]
                                        {LABEL (_"Elvish Fighter") 12,3}
                                        {PRINT (_"Right click on the tile east of you and recruit an Elvish Fighter")}
                                    [/else]
                                [/if]
                            [/else]
                        [/if]
                    [/then]
                    [else]
                        # You were supposed to recruit a new fighter.
                        # FIXME: How do we tell if they recalled instead?
                        [if]
                            [variable]
                                name=recruit.type
                                not_equals=Elvish Fighter
                            [/variable]
                            [or]
                                [variable]
                                    # FIXME: not a perfect indicator of recall
                                    name=recruit.experience
                                    greater_than=0
                                [/variable]
                            [/or]
                            [then]
                                {REFUND_AND_REMOVE_RECRUIT}
                                {TEACHER (_"$recruit.language_name|? I said <i>recruit</i> a new <i>Elvish Fighter</i>. Now try again...")}
                            [/then]
                            [else]
                                {UNLABEL 11,3}
                                {VARIABLE_OP recruit_num add 1}
                                [unit]
                                    id=Elindel
                                    name= _"Elindel"
                                    type=Elvish Fighter
                                    x,y=$x1,$y1
                                    side=1
                                    upkeep=full
                                    moves=0
                                    [modifications]
                                        {TRAIT_STRONG}
                                        {TRAIT_INTELLIGENT}
                                    [/modifications]
                                [/unit]
                                {EXPLAIN_STRONG_INTELLIGENT (_"Elindel")}
                                {LABEL (_"Elvish Fighter") 12,3}
                                {PRINT (_"Right click on the tile east of you and recruit an Elvish Fighter")}
                            [/else]
                        [/if]
                    [/else]
                [/if]
            [/then]
        [/if]
        {CLEAR_VARIABLE recruit}
    [/event]

    [event]
        name=capture
        [filter]
            x=7,9,13
            y=4,2,3
            id=student
        [/filter]
        first_time_only=no

        [allow_undo][/allow_undo]
        # FIXME: If they somehow capture a village near keep, count could be wrong.
        {VARIABLE_OP villages_around_keep add 1}
        [if]
            {NUMEQ villages_around_keep 1}
            [then]
# wmlindent: start ignoring
                # FIXME: Level 2 units change costs.
        {GENDER ({TEACHER (_"You’ve learned well, Konrad! " +
                  _"The village supports one unit and pays 1 gold per turn. You’re only losing 1 gold per turn now.")})
                ({TEACHER (_"You’ve learned well, Li’sar! " +
                  _"The village supports one unit and pays 1 gold per turn. You’re only losing 1 gold per turn now.")})}
# wmlindent: stop ignoring
                {PRINT (_"End your turn")}
            [/then]
        [/if]
        [if]
            {NUMEQ villages_around_keep 3}
            [then]
                {TEACHER (_"You’ve captured all the villages around the keep, but stay near so you can recruit more units.")}
            [/then]
        [/if]
    [/event]

    [event]
        name=capture
        [filter]
            x=7,9,13
            y=4,2,3
            side=1
            [not]
                id=student
            [/not]
        [/filter]
        {GENDER ({TEACHER (_"You should leave the villages near your keep for Konrad to capture. He needs to stay nearby to recruit more units anyway.")})
        ({TEACHER (_"You should leave the villages near your keep for Li’sar to capture. She needs to stay nearby to recruit more units anyway.")})}
        {UNDO_REMINDER}
    [/event]

    [event]
        name=turn 2
        {TALK_ABOUT Dumbo (_"Orcish Grunts have no ranged attacks, so use your archers against them.")}

        {PRINT (_"Attack the orc with an Archer")}
        {NARRATOR ("<span color='#bcb088'><b>" + _"<big>Unit Summaries</big>" + "</b></span>" + "<span size='5120'>
 </span>" + _"
To review the capabilities of any unit—including an enemy—hover the mouse over it, and you will see a unit summary on the right of the screen")}

        [event]
            name=moveto
            [filter]
                x=8,10
                y=8,8
            [/filter]
            {TEACHER (_"Excellent. Elves are well-protected in the forest. There’s only a 30% chance of hitting an Elvish Archer in that tile.")}
        [/event]
        [event]
            name=moveto
            [filter]
                x,y=9,8
                side=1
            [/filter]
            [allow_undo][/allow_undo]
            {TEACHER (_"It’s very dangerous to stand in water when there are enemies about! Your unit will have an 80% chance of being hit when the enemy counter-attacks! Cancel!")}
            {UNDO_REMINDER}
        [/event]

        [event]
            name=attack_end
            {PRINT (_"Attack the orc with the other Archer")}

            # FIXME: Can't nest events of same type: they both fire 8(
            # So set up this event on next attack.
            [event]
                name=attack

                [event]
                    name=attack_end

                    {CLEAR_PRINT}
                    {UNLABEL 14,3}
                    {LABEL (_"Fighter to HERE") 19,5}
                    {TALK_ABOUT_LOC 19,5 (_"Your other units cannot reach the orc this turn. Send a Fighter to the village in the far east of the map. It will take two turns to reach it.")}
                    {NARRATOR ("<span color='#bcb088'><b>" + _"<big>Long-distance Movement</big>" + "</b></span>" + "<span size='5120'>
 </span>"  + _"
You can order a unit to move for multiple turns by selecting the unit and clicking on the destination. A number will indicate how many turns it will take to get there.")}
                    {PRINT (_"Tell a Fighter to move to the far east village")}

                    [event]
                        name=moveto
                        [filter]
                            x,y=19,5
                        [/filter]
                        {UNLABEL 19,5}
                    [/event]
                    [event]
                        name=moveto
                        [filter]
                            x=15-19
                            y=1-6
                        [/filter]

                        {UNLABEL 19,5}
                        {LABEL (_"Keep") 10,3}
                        {TEACHER (_"Send the other Fighter and the Shaman south so they can attack next turn, then return to the keep to recruit more units!")}
                        {GENDER ({PRINT (_"Move your Fighter and Shaman south, then return Konrad to the keep")})
                        ({PRINT (_"Move your Fighter and Shaman south, then return Li’sar to the keep")})}
                    [/event]

                    [event]
                        name=moveto
                        [filter]
                            side=1
                            x,y=10,3
                        [/filter]
                        {UNLABEL 10,3}
                        {PRINT (_"Recruit another Archer and a Fighter")}
                        {VARIABLE num_recruited 0}
                    [/event]

                    [event]
                        name=recruit
                        first_time_only=no
                        [filter]
                            side=1
                        [/filter]
                        {UNLABEL 11,3}
                        {VARIABLE_OP num_recruited add 1}
                        [if]
                            {NUMEQ num_recruited 2}
                            [then]
                                {STUDENT (_"I have no more money to recruit!")}
                                {TEACHER (_"That is often a problem, which is why owning villages is important.")}
                                {GENDER ({PRINT (_"Move Konrad to another (unowned) village")})
                                ({PRINT (_"Move Li’sar to another (unowned) village")})}
                            [/then]
                        [/if]
                    [/event]
                    [event]
                        name=moveto
                        [filter]
                            x=7,9,13
                            y=4,2,3
                            id=student
                        [/filter]
                        {PRINT (_"End your turn")}
                    [/event]
                [/event]
            [/event]
        [/event]
    [/event]

    [event]
        name=turn 3

        {UNLABEL 11,3}
        {UNLABEL 12,3}

        # Explain: Zone of Control
        {TALK_ABOUT Dumbo (_"That Grunt is blocking the bridge! We must occupy that island before the Wolf Riders reach it.")}
        {STUDENT (_"Can’t our units just move around him?")}

        # All around Dumbo (9,14)
        {LABEL (_"ZoC") 10,14}
        {LABEL (_"ZoC") 8,14}
        {LABEL (_"ZoC") 9,13}
        {LABEL (_"ZoC") 9,15}
        {LABEL (_"ZoC") 10,13}
        {LABEL (_"ZoC") 8,13}
        # FIXME: Figure out best unit choice.
        {TALK_ABOUT Dumbo (_"No. Once you move close to an enemy unit, you are in its <i>Zone of Control</i> and cannot move further that turn.
To move your troops onto that island without wading slowly through the water, you’ll have to kill the Grunt.")}
        {PRINT (_"Attack the orc with an Archer")}
        {UNLABEL 10,14}
        {UNLABEL 8,14}
        {UNLABEL 9,15}
        {UNLABEL 9,13}
        {UNLABEL 10,13}
        {UNLABEL 8,13}

        [event]
            name=attack_end

            [filter_second]
                id=Dumbo
            [/filter_second]

            {CLEAR_PRINT}
            [store_unit]
                variable=dumbo
                kill=no
                [filter]
                    id=Dumbo
                [/filter]
            [/store_unit]
            # This happens before kill event, so we must do this the hard way.
            [if]
                [variable]
                    name=dumbo.hitpoints
                    less_than=1
                [/variable]
                [then]
                    {PRINT (_"Advance other units and capture villages, then <b>End Turn</b>")}
                [/then]
                [else]
                    [if]
                        [variable]
                            name=unit.gender
                            equals=male
                        [/variable]
                        [then]
                            #po: The unit with unit type $unit.language_name is male.
                            {STUDENT (_"No other units can reach that orc. I hope my $unit.language_name survives its counter-attack! I’d better grab more villages and move everyone closer for next turn.")}
                        [/then]
                        [else]
                            #po: The unit with unit type $unit.language_name is female.
                            {STUDENT (_"female^No other units can reach that orc. I hope my $unit.language_name survives its counter-attack! I’d better grab more villages and move everyone closer for next turn.")}
                        [/else]
                    [/if]
                    {TEACHER (_"Yes. If your Shaman stands just behind that unit on the bridge, she will heal it at the beginning of the next turn.")}
                    {PRINT (_"Move your Shaman onto the bridge to stand behind your other unit")}
                    [event]
                        name=moveto
                        [filter]
                            type=Elvish Shaman
                        [/filter]
                        {PRINT (_"Advance other units and capture villages, then <b>End Turn</b>")}
                    [/event]
                [/else]
            [/if]
            {CLEAR_VARIABLE dumbo}
        [/event]
    [/event]

    [event]
        name=die
        [filter]
            id=Dumbo
        [/filter]
        {VARIABLE dumbo_dead 1}
        # Only tell them to defend island if not turn 3.
        [if]
            [variable]
                name=turn_number
                greater_than=3
            [/variable]
            [then]
                {DEFEND_ISLAND}
            [/then]
        [/if]

        [event]
            name=moveto
            [filter]
                x=9,9,9
                y=15,16,17
                side=1
            [/filter]

            [allow_undo][/allow_undo]
            [if]
                [variable]
                    name=turn_number
                    less_than=8
                [/variable]
                [then]
                    {TALK_NO_MOVE (_"Be careful: if you stand on the bridge you are exposed to attack from multiple directions!")}
                    {UNDO_REMINDER}
                [/then]
            [/if]
        [/event]

        [event]
            name=moveto
            [filter]
                x=8,10,18,19,20,11
                y=14,15,14,15,14,15
                side=1
            [/filter]
            {TEACHER (_"It’s very dangerous to stand in water when there are enemies about! Your unit will have an 80% chance of being hit! Cancel, and wait for them to attack you!")}
            {UNDO_REMINDER}
            [allow_undo][/allow_undo]
        [/event]
    [/event]

    [event]
        name=turn 4

        {CLEAR_PRINT}
        {TALK_ABOUT_LOC 19,5 (_"Don’t forget about your Fighter in the east; you can move him south to that last village near the channel.")}
        [allow_undo][/allow_undo]
        [if]
            {NUMEQ dumbo_dead 0}
            [then]
                {TALK_ABOUT Dumbo (_"We need to occupy that village, otherwise they will take it next turn! Move a unit into the village to stop the orcs capturing it. Whichever unit you choose will benefit from the village’s healing, too.")}
            [/then]
            [else]
                {DEFEND_ISLAND}
            [/else]
        [/if]
    [/event]

    [event]
        name=turn 5

        {DEFEND_ISLAND}
        {TALK_ABOUT_LOC 11,14 (_"Careful! It is now nighttime. Orcs are <i>chaotic</i>, which means their attacks are now 25% stronger. By day, their attacks are 25% weaker, which is a noticeable difference. You are <i>lawful</i>: stronger by day and weaker at night. Your elvish warriors are <i>neutral</i>: unaffected by the time of day.")}
        {NARRATOR ("<span color='#bcb088'><b>" + _"<big>Time of Day</big>" + "</b></span>" + "<span size='5120'>
 </span>"  + _"
After this dialog, hold the mouse over the landscape image below the minimap on the right. This brings up a description of the time of day, showing who has the advantage.")}
    [/event]

    [event]
        name=turn 6

        {CHECK_INCOME}
        {TALK_ABOUT_LOC 9,15 (_"Remember to retreat your wounded units to villages. Healers can only heal 4 hitpoints at a time, while villages can heal 8 (the maximum healing for any unit).")}
    [/event]

    [event]
        name=turn 7

        {CHECK_INCOME}
        {LABEL (_"Defend here") 19,14}
        {TALK_ABOUT_LOC 19,16 (_"Beware of those orcs crossing the river! If they get into the forest they’ll be hard to dislodge!")}
    [/event]

    [event]
        name=turn 9
        {UNLABEL 19,14}
        {NARRATOR ("<span color='#bcb088'><b>" + _"<big>Tracking Unused Units</big>" + "</b></span>" + "<span size='5120'>
 </span>"  + _"
You can ensure you use all your troops by pressing <b>n</b> to step from one unit to the next. If you press <b>space</b>, you can mark the currently selected unit as having finished its turn, which stops you moving it by accident later on. When <b>n</b> no longer selects a new unit, it’s safe to end your turn.")}
    [/event]

    [event]
        name=turn 10
        {NARRATOR ("<span color='#bcb088'><b>" + _"<big>Victory Conditions</big>" + "</b></span>" + "<span size='5120'>
 </span>"  + _"
In this scenario, you only need to defeat the orc leader to win. (Victory conditions for a scenario are given under <b>Scenario Objectives</b> in the <b>Main Menu</b>).")}
    [/event]

    [event]
        name=turn 12
        {NARRATOR ("<span color='#bcb088'><b>" + _"<big>Recruit the Right Unit Types</big>" + "</b></span>" + "<span size='5120'>
 </span>"  + _"
Remember to recruit troops useful for the situation. Archers are particularly effective against Grunts, Wolf Riders and the orcish leader.")}
    [/event]

    # Remind them to keep back
    [event]
        name=moveto
        [filter]
            id=student
            x=1-20
            y=6-20
        [/filter]

        [if]
            [variable]
                name=turn_number
                less_than=8
            [/variable]
            [then]
                {TEACHER (_"Stay near the keep! You need to be on a keep to recruit more units, and I doubt the orc leader will let you use his!")}
            [/then]
        [/if]
        [allow_undo][/allow_undo]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Thrag
            x=5,14,19
            y=19,19,23
        [/filter]

        {TALK_ABOUT Thrag (_"Their leader has moved into that village! He’s not as stupid as I thought. The village heals him each turn and provides good defense.")}
    [/event]

    [event]
        name=moveto
        [filter]
            side=2
            x=11,6,11
            y=14,10,10
        [/filter]

        {TALK_ABOUT_LOC ($x1,$y1) (_"That unit has captured our village! You’d better get him out; it heals him each turn and provides good defense.")}
    [/event]

    # Warn about using shaman to attack.
    [event]
        name=attack
        [filter]
            type=Elvish Shaman
        [/filter]

        [message]
            speaker=unit
            message= _"Using me to attack is risky! I can slow the opponent with my ranged attack, but I hope you have a plan if I miss!"
        [/message]
    [/event]

    [event]
        name=attack_end
        first_time_only=no

        [store_unit]
            variable=attacker
            [filter]
                x,y=$x1,$y1
            [/filter]
        [/store_unit]
        [store_unit]
            variable=defender
            [filter]
                x,y=$x2,$y2
            [/filter]
        [/store_unit]

        {DEFENDER_INJURED defender}
        {IMPORTANT_UNIT attacker}

        [if]
            [variable]
                name=attacker.id
                equals=Thrag
            [/variable]
            [variable]
                name=attacker.hitpoints
                less_than=21
            [/variable]
            {NUMEQ talk_about_killing_thrag 0}
            [then]
                {VARIABLE talk_about_killing_thrag 1}
                {TALK_ABOUT Thrag (_"You are close to killing their leader! The unit who finishes him will gain 16 experience points because he is second level. Choose your attacking unit carefully!")}
            [/then]
        [/if]

        [if]
            [variable]
                name=defender.id
                equals=Thrag
            [/variable]
            [variable]
                name=defender.hitpoints
                less_than=21
            [/variable]
            {NUMEQ talk_about_killing_thrag 0}
            [then]
                {VARIABLE talk_about_killing_thrag 1}
                {TALK_ABOUT Thrag (_"You are close to killing their leader! The unit who finishes him will gain 16 experience points because he is second level. Choose your attacking unit carefully!")}
            [/then]
        [/if]
        {CLEAR_VARIABLE attacker}
        {CLEAR_VARIABLE defender}
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            side=1

            [not]
                id=student
            [/not]
        [/filter]

        [store_unit]
            variable=deadguy
            [filter]
                x,y=$x1,$y1
            [/filter]
        [/store_unit]

        [if]
            [variable]
                name=deadguy.type
                equals=Elvish Fighter
            [/variable]
            [or]
                [variable]
                    name=deadguy.type
                    equals=Elvish Archer
                [/variable]
            [/or]
            [then]
                [if]
                    [variable]
                        name=deadguy.experience
                        greater_than=20
                    [/variable]
                    [then]
                        [if]
                            [variable]
                                name=deadguy.gender
                                equals=male
                            [/variable]
                            [then]
                                {TEACHER (_"We will miss $deadguy.name| because he had $deadguy.experience experience points. He would have advanced to second level soon.")}
                            [/then]
                            [else]
                                {TEACHER (_"We will miss $deadguy.name| because she had $deadguy.experience experience points. She would have advanced to second level soon.")}
                            [/else]
                        [/if]
                    [/then]
                    [else]
                        [if]
                            [variable]
                                name=deadguy.experience
                                less_than=8
                            [/variable]
                            [then]
                                [if]
                                    [variable]
                                        name=deadguy.gender
                                        equals=male
                                    [/variable]
                                    [then]
                                        {TEACHER (_"We will miss $deadguy.name|, but at least he was not one of our experienced troops!")}
                                    [/then]
                                    [else]
                                        {TEACHER (_"We will miss $deadguy.name|, but at least she was not one of our experienced troops!")}
                                    [/else]
                                [/if]
                            [/then]
                        [/if]
                    [/else]
                [/if]
            [/then]
            [else]
                [if]
                    [variable]
                        name=deadguy.type
                        equals=Elvish Shaman
                    [/variable]
                    [then]
                        {TEACHER (_"Losing a healer hurts all the troops! Keep them out of the enemy’s reach!")}
                        {NARRATOR ("<span color='#bcb088'><b>" + _"<big>Tracking Enemy Movement</big>" + "</b></span>" + "<span size='5120'>
 </span>"  + _"
You can see where an enemy can reach by moving the mouse over them. You can see all possible enemy moves at once with the <b>Show Enemy Moves</b> command from the <b>Actions</b> menu.")}
                    [/then]
                    [else]
                        # Must be level 2 unit.
                        {TEACHER (_"Second level units are powerful, but not invulnerable! Goodbye, $deadguy.name|.")}
                    [/else]
                [/if]
            [/else]
        [/if]
        {CLEAR_VARIABLE deadguy}
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x=1-13
            y=18-21
        [/filter]
        {TALK_ABOUT Thrag (_"Beware of the orc leader: he can do 36 hitpoints of damage at night! Attack with many units at once during the day.")}
    [/event]

    # What if they level the Shaman?
    [event]
        name=post_advance
        [filter]
            side=1
            type=Elvish Marksman
        [/filter]
        # FIXME: Abilities.
        [if]
            [variable]
                name=unit.gender
                equals=male
            [/variable]
            [then]
                [message]
                    speaker=unit
                    #wmllint: display on
                    message= _"Advancing a level has fully healed me!
I always have a 60% chance of hitting with my <i>Marksman</i> ability, and I deal 9 damage each for 4 attacks. Use me to dislodge hard-to-hit units."
                    #wmllint: display off
                [/message]
            [/then]
            [else]
                [message]
                    speaker=unit
                    #wmllint: display on
                    message= _"female^Advancing a level has fully healed me!
I always have a 60% chance of hitting with my <i>Marksman</i> ability, and I deal 9 damage each for 4 attacks. Use me to dislodge hard-to-hit units."
                    #wmllint: display off
                [/message]
            [/else]
        [/if]
    [/event]
    [event]
        name=post_advance
        [filter]
            side=1
            type=Elvish Ranger
        [/filter]
        [message]
            speaker=unit
            #wmllint: display on
            message= _"Advancing a level has fully healed me!
I am good with both bow and sword, and I have a special ability: <i>Ambush</i>. I can hide in forests where enemies can only see me if they are right next to me."
            #wmllint: display off
        [/message]
    [/event]
    [event]
        name=post_advance
        [filter]
            side=1
            type=Elvish Captain
        [/filter]
        [message]
            speaker=unit
            #wmllint: display on
            message= _"Advancing a level has fully healed me!
I am good with both bow and sword, and I have a special ability: <i>Leadership</i>. First level units around me do 25% more damage, so position me carefully."
            #wmllint: display off
        [/message]
    [/event]
    [event]
        name=post_advance
        [filter]
            side=1
            type=Elvish Hero
        [/filter]
        # FIXME: Abilities
        [message]
            speaker=unit
            #wmllint: display on
            message= _"Advancing a level has fully healed me!
I am particularly good with the sword, dealing 8 damage in 4 attacks."
            #wmllint: display off
        [/message]
    [/event]

    # WE control the AI! Bwahahaha!
    [event]
        name=side 2 turn refresh
        first_time_only=no
        {CLEAR_PRINT}
        [if]
            {NUMEQ turn_number 1}
            [then]
                # Advance sacrificial orc.
                {MOVE Dumbo 8 13 9 9}
                [scroll_to_unit]
                    id=Thrag
                [/scroll_to_unit]
                {BADGUY (Wolf Rider) Scout1 17,24}
                {BADGUY (Wolf Rider) Scout2 18,23}
                {BADGUY (Wolf Rider) Scout3 19,24}
                {BADGUY (Wolf Rider) Scout4 17,25}
                {BADGUY (Wolf Rider) Scout5 18,25}
                # Leader moves to take village
                {MOVE Thrag 18 24 19 23}
                [capture_village]
                    side=2
                    x,y=19,23
                [/capture_village]
            [/then]
        [/if]
        [if]
            {NUMEQ turn_number 2}
            [then]
                # Orc runs away.
                {MOVE Dumbo 9 9 9 14}
                # Riders advance
                [scroll_to_unit]
                    id=Thrag
                [/scroll_to_unit]
                {MOVE Scout1 17 24 13 20}
                {MOVE Scout2 18 23 12 19}
                {MOVE Scout3 19 24 14 20}
                {MOVE Scout4 17 25 10 24}
                {MOVE Scout5 18 25 14 19}
                [capture_village]
                    side=2
                    x,y=14,19
                [/capture_village]
                # Leader move to keep, recruits & advances
                {MOVE Thrag 19 23 18 24}
                {BADGUY (Orcish Grunt) Grunt1 18,23}
                {BADGUY (Orcish Grunt) Grunt2 17,24}
                {BADGUY (Orcish Archer) Archer1 19,24}
                {MOVE Thrag 18 24 16 20}
            [/then]
        [/if]
        [if]
            {NUMEQ turn_number 3}
            [then]
                {MOVE Scout1 13 20 8 18}
                {MOVE Scout2 12 19 7 18}
                {MOVE Scout3 14 20 9 18}
                {MOVE Scout4 10 24 9 26}
                [capture_village]
                    side=2
                    x,y=9,26
                [/capture_village]
                {MOVE Scout5 14 19 9 17}
                {MOVE Thrag 16 20 11 19}
                {MOVE Grunt1 18 23 15 20}
                {MOVE Archer1 19 24 16 20}
                {MOVE Grunt2 17 24 16 21}
            [/then]
        [/if]

        [if]
            {NUMEQ turn_number 4}
            [then]
                # Leave Scout1 and Scout2 to attack
                {MOVE Scout3 9 18 11 16}
                {MOVE Scout5 9 17 10 16}
                {MOVE Scout4 9 26 6 20}
                {MOVE Thrag 11 19 9 19}
                {MOVE Grunt1 15 20 11 19}
                {MOVE Archer1 16 20 18 17}
                {MOVE Grunt2 16 21 18 18}
            [/then]
        [/if]

        # From now on, we only control these two, down channel
        [if]
            {NUMEQ turn_number 5}
            [then]
                {MOVE Archer1 18 17 18 16}
                {MOVE Grunt2 18 18 18 17}
                # Leaders stays here, to shorten the scenario 8)
                {MOVE Thrag 9 19 9 19}
            [/then]
        [/if]

        [if]
            {NUMEQ turn_number 6}
            [then]
                {MOVE Archer1 18 16 19 16}
                {MOVE Grunt2 18 17 18 16}
                {MOVE Thrag 9 19 9 19}
            [/then]
        [/if]

        [if]
            {NUMEQ turn_number 7}
            [then]
                # Force grunt to advance if poss.
                [if]
                    [not]
                        [have_unit]
                            x,y=19,16
                        [/have_unit]
                    [/not]
                    [then]
                        {MOVE Grunt2 18 16 19 16}
                    [/then]
                    [else]
                        {MOVE Grunt2 18 16 18 16}
                    [/else]
                [/if]
                {MOVE Thrag 9 19 9 19}
            [/then]
        [/if]

        [if]
            {NUMEQ turn_number 8}
            [then]
                # Force grunt to advance if poss.
                [if]
                    [not]
                        [have_unit]
                            x,y=19,16
                        [/have_unit]
                    [/not]
                    [then]
                        {MOVE Grunt2 18 16 19 16}
                    [/then]
                    [else]
                        {MOVE Grunt2 18 16 18 16}
                    [/else]
                [/if]

                # We can now leader move IF they are on bridge
                [if]
                    [not]
                        [have_unit]
                            side=1
                            x=7-11
                            y=16-21
                        [/have_unit]
                    [/not]
                    [then]
                        {MOVE Thrag 9 19 9 19}
                    [/then]
                [/if]
            [/then]
        [/if]
    [/event]

    [event]
        name=time over
        {TEACHER (_"You took too long! We’ll never be rid of these orcs!")}
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=die
        [filter]
            id=student
        [/filter]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=defeat
        {CLEAR_PRINT}
    [/event]

    [event]
        name=victory
        {TEACHER (_"You have beaten the orcs! You may want to try some novice-level campaigns next, such as: <i>The South Guard</i>, <i>An Orcish Incursion</i>, <i>A Tale of Two Brothers</i>, or <i>Heir to the Throne</i>. <i>The South Guard</i> was specifically designed as a beginner’s campaign. Konrad, Li’sar and Delfador are characters from <i>Heir to the Throne</i>.")}
    [/event]
[/tutorial]
