#textdomain wesnoth-tutorial

[tutorial]
    id=tutorial
    # po: Hello, translators! The tutorial is meant to be a bit funny at the start,
    # po: welcoming new players. Please keep the friendly fun feeling!
    # po: If you have any questions, ask in the forums or in the #wesnoth-dev channel on the Freenode IRC network.
    name= _ "Wesnoth Tutorial — Part I"
    map_data="{campaigns/tutorial/maps/01_Tutorial_part_1.map}"
    next_scenario=2_Tutorial
    victory_when_enemies_defeated=no
    experience_modifier=100

    {DEFAULT_SCHEDULE}

    {SCENARIO_MUSIC       traveling_minstrels.ogg}
    {EXTRA_SCENARIO_MUSIC knolls.ogg}
    {EXTRA_SCENARIO_MUSIC silvan_sanctuary.ogg}
    {EXTRA_SCENARIO_MUSIC loyalists.ogg}

    [side]
        side=1
        controller=human
        gold=100
        save_id=human_player
        persistent=yes
        team_name=player
        user_team_name= _ "team_name^Student"

        type=Fighter
        id=student
        name= _"Konrad"
        unrenamable=yes
        profile=portraits/konrad.png
        canrecruit=yes

        facing=se
    [/side]

    [side]
        side=2
        controller=ai
        no_leader=yes
        hidden=yes
        defeat_condition=never

        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT caution 0}
            {AI_SIMPLE_ALWAYS_ASPECT aggression 1}
            [goal]
                [criteria]
                    id=student
                [/criteria]
                value=10
            [/goal]
            [goal]
                [criteria]
                    id=Delfador
                [/criteria]
                value=.1
            [/goal]
        [/ai]
    [/side]

    [side]
        side=3
        controller=null
        team_name=player
        no_leader=yes
        hidden=yes

        [unit]
            id=Delfador
            name= _ "Delfador"
            type=Elder Mage
            profile=portraits/delfador.png~RIGHT()
            x,y=13,5
            random_traits=no
            facing=nw
            {IS_HERO}
            [modifications]
                {TRAIT_INTELLIGENT}
                [object]
                    [effect]
                        apply_to=new_animation
                        [extra_anim]
                            flag=summon_quintain_raise_staff
                            start_time=0
                            [frame]
                                image="units/human-magi/elder-mage-ranged[1~3].png:100"
                            [/frame]
                        [/extra_anim]
                        [extra_anim]
                            flag=summon_quintain_lower_staff
                            start_time=0
                            [frame]
                                image="units/human-magi/elder-mage-ranged[3~1].png:150"
                            [/frame]
                        [/extra_anim]
                    [/effect]
                [/object]
            [/modifications]
        [/unit]
    [/side]

    [event]
        name=prestart
        [store_unit]
            [filter]
                id=student
            [/filter]
            variable=student_store
            kill=yes
        [/store_unit]

        [objectives]
            side=1
            summary= _ "You will learn the basics of:
• <small>Movement</small>
• <small>Attacking</small>
• <small>Healing</small>
• <small>Recruiting</small>"
            [objective]
                description= _ "Destroy a fierce enemy"
                condition=win
            [/objective]
            [objective]
                description= _ "Get yourself killed"
                condition=lose
            [/objective]
        [/objectives]

        # We don't want players ending their turn before the requisite actions have been completed
        # Therefor, we frequently disallow or allow end turn as needed
        [disallow_end_turn][/disallow_end_turn]
    [/event]

    [event]
        name=start

        [message]
            speaker=narrator
            caption= _ "Welcome to Wesnoth!"
            image=wesnoth-icon.png
            message= _ "This is a two-part tutorial intended for people who are new to the game. Part 1 will teach you the basics about movement, attacking, healing, and recruiting. Firstly, you’ll choose a hero (both heroes play the same)." +
                {CONTINUE_MSG}
        [/message]

        [select_character][/select_character]

        {CLEAR_VARIABLE student_store}

        {GENDER (
            [message]
                speaker=narrator
                caption= _ "Welcome to Wesnoth!"
                image=wesnoth-icon.png
                message= _ "For this tutorial, you are playing Konrad. You are standing on the keep, and your mentor Delfador is on the east side of the river. You can move the mouse over a unit to see a summary of its abilities and stats on the right of the screen." +
                    {CONTINUE_MSG}
            [/message]
        ) (
            [message]
                speaker=narrator
                caption= _ "Welcome to Wesnoth!"
                image=wesnoth-icon.png
                message= _ "For this tutorial, you are playing Li’sar. You are standing on the keep, and your mentor Delfador is on the east side of the river. You can move the mouse over a unit to see a summary of its abilities and stats on the right of the screen." +
                    {CONTINUE_MSG}
            [/message]
        )}

        {GENDER (
            {PRINT ( _ "Click on Konrad")}
        ) (
            {PRINT ( _ "Click on Li’sar")}
        )}

        # For undo warning always keep a list of target hexes in target_loc
        # First find Delfador and let "check_undo" event use the hexes around him
        [store_locations]
            [filter]
                side=3
            [/filter]
            variable=target_loc
            radius=1          # hexes next to Delfador
        [/store_locations]

        # Set to 'no' if undo message is to be disabled temporarily
        {VARIABLE enable_undo_messages yes}
    [/event]

    # HP stat tracking
    [event]
        name=side 1 turn,attack_end
        id=hp_stat_tracking
        first_time_only=no

        [lua]
            code= <<
                local unit = wesnoth.get_units({id = "student"})[1]
                local hp_diff = unit.max_hitpoints - unit.hitpoints

                if hp_diff > 7 then hp_diff = 8 end

                wml.variables.student_hp = unit.hitpoints
                wml.variables.student_hp_heal_amount = hp_diff
            >>
        [/lua]
    [/event]

    # Give a warning to undo last step if target is out of reach
    # Check whether at least one of our units can reach any of the target_loc locations
    [event]
        name=moveto
        id=check_undo
        first_time_only=no
        [filter]
            side=1
        [/filter]
        [allow_undo][/allow_undo]

        # Store all our units
        [store_unit]
            [filter]
                side=1
            [/filter]
            variable=student_team
        [/store_unit]

        {VARIABLE within_reach no}
        #{VARIABLE mindist 100} # kept for debugging

        [store_locations]
            [filter]
                side=2
            [/filter]
            radius=1    # hexes around the quintain(s)
            variable=target_enemies
        [/store_locations]

        # Combine the quintains' neighbourhood as targets with the actual quest targets so we don't alert for undo if the player
        # wants to attack instead of following the narrative
        # Resulting array of locations is all_targets
        [lua]
            code= <<
                if wml.variables.target_enemies == nil then
                    wml.variables.all_targets = wml.variables.target_loc
                else
                    local target_loc = wml.array_access.get('target_loc')
                    local targets = wml.array_access.get('target_enemies')
                    for k, v in pairs(target_loc) do
                        table.insert(targets, v)
                    end
                    wml.array_access.set('all_targets', targets)
                end
            >>
        [/lua]

        [if]
            {VARIABLE_CONDITIONAL enable_undo_messages boolean_equals yes}
            [then]
                [foreach]   # Check each unit
                    array=student_team
                    [do]
                        {VARIABLE moves_left $this_item.moves}
                        {VARIABLE student_team_member $this_item.id}

                        # compare their movement points with the movement costs of the valid target locations
                        [foreach]
                            array=all_targets
                            [do]
                                [find_path]
                                    [traveler]
                                        id=$student_team_member
                                    [/traveler]
                                    [destination]
                                        x=$this_item.x
                                        y=$this_item.y
                                    [/destination]
                                    variable=curr_distance
                                    allow_multiple_turns=yes
                                    check_zoc=no
                                [/find_path]

                                # debug: unit distance calculations
                                #[if]
                                #    {VARIABLE_CONDITIONAL curr_distance.movement_cost less_than $mindist}
                                #    [then]
                                #        {VARIABLE mindist $curr_distance.movement_cost}
                                #    [/then]
                                #[/if]

                                [if]
                                    {VARIABLE_CONDITIONAL curr_distance.movement_cost less_than_equal_to $moves_left}
                                    [then]
                                        {VARIABLE within_reach yes}
                                    [/then]
                                [/if]
                            [/do]
                        [/foreach]
                    [/do]
                [/foreach]
            [/then]
        [/if]

        # debug: display resulting shortest path between all units of side 1 and all target_loc hexes
        #[lua]
        #    code= <<
        #        print("Min dist: " .. wml.variables.mindist)
        #    >>
        #[/lua]

        [if]
            {VARIABLE_CONDITIONAL within_reach boolean_equals no}
            {VARIABLE_CONDITIONAL enable_undo_messages boolean_equals yes}
            [then]
                {PRINT (_ "To undo your last move, press <b>u</b> or use the right-click menu.")}
                {VARIABLE undo_displayed yes}
            [/then]
        [/if]

        # Clear undo message only if it is currently displayed and player performs undo
        #  - so normal quest PRINTs are not cleared when the player does an undo on his own
        # (Original message not restored yet after undo.)
        [on_undo]
            [if]
                {VARIABLE_CONDITIONAL undo_displayed boolean_equals yes}
                [then]
                    {CLEAR_PRINT}
                    {VARIABLE undo_displayed no}
                [/then]
            [/if]
        [/on_undo]
    [/event]

    [event]
        name=remove_check_undo
        first_time_only=yes
        [remove_event]
            id=check_undo
        [/remove_event]

        {CLEAR_VARIABLE student_team,moves_left,student_team_member,curr_distance,target_loc,target_unit,all_targets}
        {CLEAR_VARIABLE within_reach,undo_displayed,enable_undo_messages}
    [/event]

    [event]
        name=select
        [filter]
            side=1
        [/filter]

        {CLEAR_PRINT}

        {GENDER (
            [message]
                speaker=narrator
                caption= _ "Movement"
                image=wesnoth-icon.png
                message= _ "When you hover over or select a unit, in this case Konrad, the places he can move to are highlighted. All units have a certain number of <i>movement points</i>, which dictate how many hexes that unit can move per turn. Normally, moving one hex on flat terrain uses one movement point. To move, simply click on Konrad and then your destination. (You can press <b>u</b> to undo a move if you move to the wrong place.)" +
                    {CONTINUE_MSG}
            [/message]
        ) (
            [message]
                speaker=narrator
                caption= _ "Movement"
                image=wesnoth-icon.png
                message= _ "When you hover over or select a unit, in this case Li’sar, the places she can move to are highlighted. All units have a certain number of <i>movement points</i>, which dictate how many hexes that unit can move per turn. Normally, moving one hex on flat terrain uses one movement point. To move, simply click on Li’sar and then your destination. (You can press <b>u</b> to undo a move if you move to the wrong place.)" +
                    {CONTINUE_MSG}
            [/message]
        )}

        # [message]speaker=narrator deselects the unit, so reselect it now
        [select_unit]
            id=student
        [/select_unit]

        {GENDER (
            {PRINT ( _ "Move Konrad next to Delfador")}
        ) (
            {PRINT ( _ "Move Li’sar next to Delfador")}
        )}
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            [filter_adjacent]
                id=Delfador
            [/filter_adjacent]
        [/filter]

        {CLEAR_PRINT}

        [message]
            speaker=student
            message= _ "Good morning, Delfador! Is it time to attack things?"
            female_message= _ "female^Good morning, Delfador! Is it time to attack things?"
        [/message]

        [message]
            speaker=Delfador
            message= _ "Um, well..."
        [/message]

        [message]
            speaker=student
            message= _ "Have you found an orc for me to fight, huh? A troll?"
            female_message= _ "female^Have you found an orc for me to fight, huh? A troll?"
        [/message]

        [message]
            speaker=Delfador
            message= _ "Quiet! I will summon an enemy for you..."
        [/message]

        # Explicitly check if the spot is free. The place where the engine
        # would place the unit (nw of it) is less helpful, because the place
        # where Delfador moves later is then more than 5 moves away.
        [if]
            [not]
                [have_unit]
                    x=14
                    y=4
                [/have_unit]
            [/not]
            [then]
                # Delfador steps 1 hex northeast to a new summoning position
                {MOVE_UNIT (id=Delfador) 14 4}
                {MODIFY_UNIT (id=Delfador) facing sw}
            [/then]
            [else]
                # Delfador steps 1 hex southeast to a new summoning position
                {MOVE_UNIT (id=Delfador) 14 5}
                {MODIFY_UNIT (id=Delfador) facing nw}
            [/else]
        [/if]

        # Adjust Delfador's MP as if he really moved, disabled due to issue #3344
        # {MODIFY_UNIT (id=Delfador) moves 5}

        [scroll_to_unit]
            id=Delfador
        [/scroll_to_unit]

        [animate_unit]
            [filter]
                id=Delfador
            [/filter]
            flag=summon_quintain_raise_staff
        [/animate_unit]

        [color_adjust]
            red=100
            green=100
            blue=100
        [/color_adjust]

        [unit]
            id=Quintain
            type=Quintain
            ai_special=guardian
            x,y=13,5
            side=2
        [/unit]

        [sound]
            name=lightning.ogg
        [/sound]

        [animate_unit]
            [filter]
                id=Delfador
            [/filter]
            flag=summon_quintain_lower_staff
        [/animate_unit]

        [color_adjust]
            red=0
            green=0
            blue=0
        [/color_adjust]

        [message]
            speaker=Delfador
            message= _ "... this quintain!"
        [/message]

        [message]
            speaker=student
            message= _ "A quintain? You want me to fight a dummy?"
            female_message= _ "female^A quintain? You want me to fight a dummy?"
        [/message]

        {GENDER (
            [message]
                speaker=Delfador
                message= _ "Young man, you have $student_hp hitpoints and a sword. I’m fairly sure you’ll win."
            [/message]
        ) (
            [message]
                speaker=Delfador
                message= _ "female^Young lady, you have $student_hp hitpoints and a sword. I’m fairly sure you’ll win."
            [/message]
        )}

        {GENDER (
            [message]
                speaker=narrator
                caption= _"Attacking"
                image=wesnoth-icon.png
                message= _ "To attack the quintain, first select the attacker (Konrad), then the target (the quintain). You will see an attack description. Click <b>Attack</b> when you’re ready."
            [/message]
        ) (
            [message]
                speaker=narrator
                caption= _"Attacking"
                image=wesnoth-icon.png
                message= _"To attack the quintain, first select the attacker (Li’sar), then the target (the quintain). You will see an attack description. Click <b>Attack</b> when you’re ready."
            [/message]
        )}
    [/event]

    # First time the student attacks the quintain
    [event]
        name=attack_end
        first_time_only=yes
        [filter]
            id=student
        [/filter]

        [message]
            speaker=student
            message= _ "Hey! This quintain fights back!"
        [/message]

        [message]
            speaker=Delfador
            message= _ "Hmm, perhaps we should have started with a doll."
        [/message]

        [message]
            speaker=student
            message= _ "Should I retreat?"
            female_message= _ "female^Should I retreat?"
        [/message]

        [message]
            speaker=Delfador
            message= _ "Good idea!"
        [/message]

        {GENDER (
            [message]
                speaker=narrator
                caption= _ "Crowns"
                image=wesnoth-icon.png
                message= _ "The tiny golden crown above your leader (Konrad) indicates he is a side leader. In most scenarios, you will lose if your leader is killed. Be sure to keep him safe!"
            [/message]
        ) (
            [message]
                speaker=narrator
                caption= _ "Crowns"
                image=wesnoth-icon.png
                message= _ "The tiny golden crown above your leader (Li’sar) indicates she is a side leader. In most scenarios, you will lose if your leader is killed. Be sure to keep her safe!"
            [/message]
        )}

        # Check where Delfador is, to set the remaining moves accordingly
        [if]
            [have_unit]
                id=Delfador
                x=14
                y=4
            [/have_unit]
            [then]
                {MOVE_UNIT (id=Delfador) 14 8}
                # Adjust Delfador's MP as if he really moved, disabled due to issue #3344
                # {MODIFY_UNIT (id=Delfador) moves 0}
            [/then]
            [else]
                {MOVE_UNIT (id=Delfador) 14 8}
                # Adjust Delfador's MP as if he really moved, disabled due to issue #3344
                # {MODIFY_UNIT (id=Delfador) moves 2}
            [/else]
        [/if]

        {MODIFY_UNIT (id=Delfador) facing nw}

        [message]
            speaker=Delfador
            message= _ "Unfortunately, you’ve used up your turn attacking the quintain. The quintain now gets to attack."
        [/message]

        [message]
            speaker=student
            message= _ "The <i>dummy</i> gets a turn?"
        [/message]

        [message]
            speaker=Delfador
            message= _ "Yes. It’s a magical quintain! If it hits you, it does 3 damage, and has 5 chances. If it hits every time, you’ll drop from $student_hp to $($student_hp-15) hitpoints. Brace yourself!"
        [/message]

        [allow_end_turn][/allow_end_turn]

        [message]
            speaker=narrator
            caption= _ "Turns"
            image=wesnoth-icon.png
            message= _ "Every turn, each side in a scenario gets a chance to make their move. Once you’ve completed everything you wish to do this turn, click on the <b>End Turn</b> button in the bottom right of the screen. The other teams, whether controlled by the AI or other human players, will then make their move. Some scenarios must be completed in a certain number of turns. You can see what turn it is, and any applicable turn limit, next to the flag icon at the top of the screen."
        [/message]

        {PRINT (_"End your turn")}
    [/event]

    # TURN 2: lesson in healing
    # There is a 1 in 170,000 chance that the quintain will miss on all
    # 10 attacks. Ignoring that.
    [event]
        name=turn 2

        [disallow_end_turn][/disallow_end_turn]

        # works around the situation that the player can't do anything anymore
        # if he disobeys orders - inserts [allow_end_turn][/allow_end_turn]
        {ALLOW_END_TURN_AFTER_ATTACK}

        {CLEAR_PRINT}

        [message]
            speaker=student
            message= _ "Ouch! I need to heal! Only $student_hp hitpoints left!"
            female_message= _ "female^Ouch! I need to heal! Only $student_hp hitpoints left!"
        [/message]

        [message]
            speaker=Delfador
            message= _ "There are two villages within your reach. Visiting villages is a good idea, and ending your turn on one will heal you. To a village!"
        [/message]

        [label]
            immutable=yes
            text= _ "Village"
            visible_in_fog=yes
            visible_in_shroud=no
            x=10,11
            y=3,7
        [/label]

        # Update targets for undo message: villages
        [store_villages]
            variable=target_loc
        [/store_villages]

        {GENDER (
            {PRINT ( _ "Move Konrad to a nearby village")}
        ) (
            {PRINT ( _ "Move Li’sar to a nearby village")}
        )}

        [event]
            name=capture
            [filter]
                side=1
            [/filter]

            {CLEAR_PRINT}

            [message]
                speaker=narrator
                caption= _ "Villages"
                image=wesnoth-icon.png
                message= _"You have captured a village! It now flies your colors and has been added to your total village count (the house icon at the top of the screen shows how many villages you currently control). Villages provide the gold needed to recruit units. Each turn, you gain 2 gold, plus 1 for every village you own."
            [/message]

            [allow_end_turn][/allow_end_turn]

            {PRINT ( _ "End your turn")}
        [/event]
    [/event]

    # TURN 3: lesson in recruiting
    # Use a refresh event so dialog happens post-healing
    [event]
        name=turn 3 refresh

        [disallow_end_turn][/disallow_end_turn]

        {ALLOW_END_TURN_AFTER_ATTACK}

        {CLEAR_PRINT}

        [message]
            speaker=Delfador
            message= _ "Since you started your turn on a village, you regained some health! Villages heal units 8 hitpoints per turn, or enough to top off their health, whichever is less. In your case, you regained $student_hp_heal_amount hitpoints."
        [/message]

        [message]
            speaker=Delfador
            message= _ "Now, it’s time to summon some help against that quintain."
        [/message]

        [message]
            speaker=student
            message= _ "I’ll recruit some elves!"
            female_message= _ "female^I’ll recruit some elves!"
        [/message]

        [message]
            speaker=Delfador
            message= _ "A splendid idea! It’s probably best not to attempt attacking the quintain this turn. Instead, you should return to the keep and recruit two units; you have plenty of gold for that."
        [/message]

        [label]
            immutable=yes
            text= _ "Keep"
            visible_in_fog=yes
            visible_in_shroud=no
            x=9
            y=6
        [/label]

        # Update targets for undo message: keep
        [store_locations]
            variable=target_loc
            x,y=9,6
        [/store_locations]

        {GENDER (
            {PRINT ( _ "Move Konrad to the keep")}
        ) (
            {PRINT ( _ "Move Li’sar to the keep")}
        )}

        [event]
            name=moveto
            [filter]
                x,y=9,6
            [/filter]

            {CLEAR_PRINT}

            [set_recruit]
                recruit=Elvish Fighter
                side=1
            [/set_recruit]

            [message]
                speaker=narrator
                caption= _ "Recruiting"
                image=wesnoth-icon.png
                message= _ "Whenever you’re on a <i>keep</i>, you can <i>recruit</i> units on the castle tiles around it by right-clicking and selecting <b>Recruit</b>. Note that newly recruited units cannot act the turn you recruit them; you will be able to use them next turn. This scenario you have only one type of unit to choose from: the Elvish Fighter."
            [/message]

            {PRINT (_"Recruit two Elvish Fighters")}
        [/event]

        [event]
            name=recruit
            [filter]
                side=1
            [/filter]
            [filter_condition]
                [have_unit]
                    type=Elvish Fighter
                    count=2
                [/have_unit]
            [/filter_condition]

            {CLEAR_PRINT}

            [message]
                speaker=narrator
                caption= _ "Traits"
                image=wesnoth-icon.png
                message= _"Be sure to examine the <i>traits</i> of your new recruits. They are listed under its race in the sidebar. Traits can subtly affect how you use your troops. For example, units with the <i>quick</i> trait can move an extra hex each turn, and units with the <i>intelligent</i> trait require 20% less experience to level up."
            [/message]

            # Allow our hero to move freely until next turn without undo messages now that the recruiting is done
            {VARIABLE enable_undo_messages no}

            [allow_end_turn][/allow_end_turn]

            {PRINT ( _ "End your turn")}
        [/event]

        # Clean up hp tracking. We no longer need it after this point
        {CLEAR_VARIABLE student_hp,student_hp_heal_amount}

        [remove_event]
            id=hp_stat_tracking
        [/remove_event]
    [/event]

    # TURN 4: enemy healing and attacking
    # Optimally, the Quintain will still be alive at this point, but it is possible
    # it will kill itself attacking the student if they attacked it at the end of
    # turn 3. Therefor, only fire this if the Quintain is still alive.
    [event]
        name=turn 4
        [filter_condition]
            [have_unit]
                id=Quintain
            [/have_unit]
        [/filter_condition]

        # Update undo target: quintain and its surrounding hexes
        {VARIABLE enable_undo_messages yes}
        [store_locations]
            [filter]
                side=2
            [/filter]
            variable=target_loc
            radius=1    # hexes next to the first quintain
        [/store_locations]

        [disallow_end_turn][/disallow_end_turn]

        {ALLOW_END_TURN_AFTER_ATTACK}

        {CLEAR_PRINT}

        [message]
            speaker=student
            message= _ "Hey, the quintain just healed 2 hitpoints! I’d better attack it at once!"
            female_message= _ "female^Hey, the quintain just healed 2 hitpoints! I’d better attack it at once!"
        [/message]

        [message]
            speaker=Delfador
            message= _ "Yes, if a unit doesn’t do anything for a turn, it will slowly heal."
        [/message]

        [message]
            speaker=Delfador
            message= _ "Before you send your fighters against the quintain, you should know they have two kinds of attack..."
        [/message]

        [message]
            speaker=student
            message= _ "I’ll tell them to use the one that does more damage!"
            female_message= _ "female^I’ll tell them to use the one that does more damage!"
        [/message]

        [message]
            speaker=Delfador
            message= _ "And which would that be? The sword (5×4; or 5 damage on each hit, with 4 attacks) or the bow (3×3; or 3 damage on each hit, with 3 attacks)? I suppose you’ll find out..."
        [/message]

        {PRINT ( _ "Attack the quintain with your fighters")}

        [event]
            name=select
            id=trying_to_be_a_wise_guy
            [filter]
                id=student
            [/filter]

            [message]
                speaker=Delfador
                message= _ "You wouldn’t do anything stupid like charging that quintain yourself again, now would you? Use the fighters you recruited first; they’ll be a lot of help."
            [/message]
        [/event]

        [event]
            name=attack
            [filter]
                type=Elvish Fighter
            [/filter]

            [remove_event]
                id=trying_to_be_a_wise_guy
            [/remove_event]

            {CLEAR_PRINT}

            # After this, we no longer need to restrict turn endings
            [allow_end_turn][/allow_end_turn]

            # Now our hero is free to wander around without undo warnings - clean up
            [fire_event]
                name=remove_check_undo
            [/fire_event]
        [/event]

        [event]
            name=attack_end
            [filter]
                type=Elvish Fighter
            [/filter]
            [filter_attack]
                name=sword
            [/filter_attack]

            [message]
                speaker=Delfador
                message= _ "Your elf used a sword (5×4; or 5 damage on each hit, with 4 attacks), which is a <i>melee</i> attack. The quintain defended with its melee attack (3×5; or 3 damage on each hit, with 5 attacks). The ranged attack (the bow) would have been safer."
            [/message]
        [/event]

        [event]
            name=attack_end
            [filter_attack]
                name=bow
            [/filter_attack]

            [message]
                speaker=Delfador
                message= _ "Your elf used a bow, which is a <i>ranged</i> attack (3×3; or 3 damage on each hit, with 3 attacks). The quintain has no ranged attack, only a melee attack, so it could not defend itself."
            [/message]
        [/event]
    [/event]

    # TURN 5 onwards: advice
    # There are three lines of dialog in the following events that are only show if
    # the quintain (and as such, Delfador) are still around.
    [event]
        name=turn 5

        {CLEAR_PRINT}

        [message]
            speaker=Delfador
            message= _"Keep attacking with both elves until the quintain is finished!"
            [show_if]
                [have_unit]
                    id=Delfador
                [/have_unit]
            [/show_if]
        [/message]
    [/event]

    # TURN 6: recruit more guys
    [event]
        name=turn 6

        [message]
            speaker=Delfador
            message= _"Maybe you should recruit another elf?"
            [show_if]
                [have_unit]
                    id=Delfador
                [/have_unit]
            [/show_if]
        [/message]

        [message]
            speaker=narrator
            caption= _ "Unit Descriptions"
            image=wesnoth-icon.png
            message= _ "You can right click on a unit to see a detailed <b>Unit Description</b>."
        [/message]
    [/event]

    # TURN 7: protect your troops
    [event]
        name=turn 7

        [message]
            speaker=narrator
            caption= _ "Protect Your Troops"
            image=wesnoth-icon.png
            message= _ "Remember to pull back wounded units into villages and recruit more if needed. Take special care of units with the highest <i>experience points (XP)</i> so they can gain levels and become more powerful."
        [/message]
    [/event]

    # TURN 8: support
    [event]
        name=turn 8

        [message]
            speaker=narrator
            caption= _ "Support"
            image=wesnoth-icon.png
            message= _"Each village you control will <i>support</i> one unit for free. After that, each unit costs you one gold per turn."
        [/message]
    [/event]

    # TURN 9: advancement
    [event]
        name=turn 9

        [message]
            speaker=Delfador
            message= _ "You had really better finish off that quintain."
            [show_if]
                [have_unit]
                    id=Delfador
                [/have_unit]
            [/show_if]
        [/message]

        [message]
            speaker=narrator
            caption= _ "Advancement"
            image=wesnoth-icon.png
            message= _ "When a unit gains enough experience points (the <i>experience bar</i>, if present, is on the <b>right</b> of the <i>hitpoints bar</i>), it will gain a level. Elvish Fighters have two advancement options, and you will be able to choose which one you want. However, second level units cost twice as much to support as first level units."
        [/message]
    [/event]

    # TURN 10: defenses
    [event]
        name=turn 10

        [message]
            speaker=narrator
            caption= _ "Defenses"
            image=wesnoth-icon.png
            # wmllint: local spelling quintains
            message= _ "Whenever one of your units is selected, you’ll see varying percentages as you move the mouse over the map. The higher the percentage, the more <i>defense</i> that unit has in that kind of terrain. For example, most units have good defenses in castles and villages but poor defenses in rivers. Some units, like these quintains, have a <i>magical</i> attack, which always has a 70% chance of hitting no matter what terrain their targets occupy."
        [/message]
    [/event]

    [event]
        name=last_breath
        [filter]
            id=student
        [/filter]

        [message]
            speaker=unit
            message= _ "Agh! This training is too much for me..."
            female_message= _ "female^Agh! This training is too much for me..."
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id=student
        [/filter]

        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    # Death of the first quintain
    [event]
        name=die
        [filter]
            id=Quintain
        [/filter]

        {CLEAR_PRINT}

        # This is for debug purposes, so anyone using console commands doesn't get stuck
        # and unable to end their turn. It should have no affect on normal gameplay.
        [allow_end_turn][/allow_end_turn]

        # Debug or not, from now on our hero is free to wander - don't warn about undo
        # (there is one corner case when it would still be useful)
        [fire_event]
            name=remove_check_undo
        [/fire_event]

        [message]
            speaker=second_unit
            message= _ "The quintain is destroyed, and I have gained more experience!"
        [/message]

        [message]
            speaker=Delfador
            message= _ "Yes, you gain experience through battle, especially by killing an opponent. Gain enough experience and you’ll become more powerful."
        [/message]

        {GENDER (
            [message]
                speaker=Delfador
                message= _ "Now, Konrad, I will leave you with more dummies to practice on! After that, we have real work to do..."
            [/message]
        ) (
            [message]
                speaker=Delfador
                message= _ "Now, Li’sar, I will leave you with more dummies to practice on! After that, we have real work to do..."
            [/message]
        )}

        [scroll_to_unit]
            id=Delfador
        [/scroll_to_unit]

        [animate_unit]
            [filter]
                id=Delfador
            [/filter]
            flag=summon_quintain_raise_staff
        [/animate_unit]

        [color_adjust]
            red=100
            green=100
            blue=100
        [/color_adjust]

        [unit]
            type=Quintain
            ai_special=guardian
            x,y=16,10
            side=2
        [/unit]

        [unit]
            type=Quintain
            ai_special=guardian
            x,y=13,11
            side=2
        [/unit]

        [unit]
            type=Quintain
            ai_special=guardian
            x,y=9,11
            side=2
        [/unit]

        [modify_side]
            side=2
            defeat_condition=no_units_left
        [/modify_side]

        [sound]
            name=lightning.ogg
        [/sound]

        [animate_unit]
            [filter]
                id=Delfador
            [/filter]
            flag=summon_quintain_lower_staff
        [/animate_unit]

        [color_adjust]
            red=0
            green=0
            blue=0
        [/color_adjust]

        {MOVE_UNIT (id=Delfador) (12,8,8,8) (7,9,10,11)}

        [scroll_to_unit]
            type=Quintain
        [/scroll_to_unit]

        [kill]
            id=Delfador
        [/kill]

        [message]
            speaker=narrator
            caption= _ "Note"
            image=wesnoth-icon.png
            message= _ "These dummies only attack if you are a single tile away. With care, you should be able to kill them one at a time."
        [/message]
    [/event]

    [event]
        name=enemies defeated

        [message]
            speaker=student
            message= _ "Well, I think I know the basics. Onwards! Maybe I can fight in a real battle next?"
            female_message= _ "female^Well, I think I know the basics. Onwards! Maybe I can fight in a real battle next?"
        [/message]

        [endlevel]
            result=victory
            carryover_report=no
            carryover_add=yes
            carryover_percentage=0
        [/endlevel]
    [/event]

    [event]
        name=victory

        [message]
            speaker=narrator
            caption= _ "Victory"
            image=wesnoth-icon.png
            message= _ "After your victory notice, the map will be grayed out to indicate that the scenario is over; this is called <i>linger mode</i>. You will still be able to examine the final positions and state of your troops and any surviving enemies. When you’re finished, click the <b>End Scenario</b> button to go on to the next scenario in the campaign."
        [/message]
    [/event]

    [event]
        name=defeat

        {CLEAR_PRINT}
    [/event]
[/tutorial]
