#textdomain wesnoth-ei
[scenario]
    id=10_Lake_Vrug
    name= _ "Lake Vrug"
    map_data="{campaigns/Eastern_Invasion/maps/10_Lake_Vrug.map}"
    turns=30

    {DEFAULT_SCHEDULE_MORNING}

    next_scenario=11_Captured

    {DEFAULT_MUSIC_PLAYLIST}

    {campaigns/Eastern_Invasion/utils/deaths.cfg}

    {BIGMAP_10}

    victory_when_enemies_defeated=no

    [side]
        type=Lieutenant
        id=Gweddry
        name= _ "Gweddry"
        side=1
        canrecruit=yes
        controller=human
        team_name=good
        user_team_name=_"Wesnothians"
        shroud=yes
        gold=200
        {FLAG_VARIANT loyalist}
    [/side]

    [side]
        type=Troll Warrior
        id=Darg
        name= _ "Darg"
        side=2
        canrecruit=yes
#ifdef HARD
        recruit=Troll Rocklobber,Troll,Troll Whelp
#else
        recruit=Troll,Troll Whelp
#endif
        team_name=monster
        user_team_name=_"Monsters"
        {GOLD 200 250 300}
    [/side]

    [side]
        type=Gryphon
        id=Kraagak
        name= _ "Kraagak"
        side=3
        canrecruit=yes
#ifdef EASY
        recruit=Gryphon
#else
        recruit=Gryphon,Sky Drake
#endif
        team_name=monster
        user_team_name=_"Monsters"
        {GOLD 200 250 300}
        [ai]
            aggression=0.9
            grouping=no
        [/ai]
    [/side]

    [event]
        name=prestart

        # {SCATTER_IMAGE (terrain=Ww) 1 scenery/icepack-1.png}

        [objectives]
            side=1
            [objective]
                description= _ "Defeat the enemy leaders"
                condition=win
                [show_if]
                    [variable]
                        name=enemies_defeated
                        boolean_equals=false
                    [/variable]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Move Dacyn to the stronghold"
                condition=win
                [show_if]
                    [variable]
                        name=Dacyn_researching
                        boolean_equals=false
                    [/variable]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Gweddry"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Dacyn"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Owaec"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

            [gold_carryover]
                bonus=yes
                carryover_percentage=40
            [/gold_carryover]
        [/objectives]

        [set_variable]
            name=enemies_defeated
            value=false
        [/set_variable]

        [set_variable]
            name=Dacyn_researching
            value=false
        [/set_variable]
    [/event]

    [event]
        name=start
        [recall]
            id=Dacyn
        [/recall]
        [recall]
            id=Owaec
        [/recall]
        [recall]
            id=Grug
        [/recall]
        [recall]
            id=Terraent
        [/recall]
        [message]
            speaker=Dacyn
            message= _ "The trail stops soon. We have almost reached Lake Vrug. There is a small island off the coast ahead that was once home to a great school of magic. I pray that the library is still intact."
        [/message]
        [message]
            speaker=Owaec
            message= _ "But what happened to the people living on it?"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Few enough remained before the trolls and gryphons took up residence in the mountains. But now the school is deserted, and has been for decades."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Very well, we will take care of the trolls and gryphons. Search the library and may you find us an answer. Onward!"
        [/message]
    [/event]

    #give the player a hint about mountainous terrain
    [event]
        name=recall
        [filter]
            type=Paladin,Lancer,Knight,Grand Knight,Horseman,Cavalier,Dragoon,Cavalryman,Heavy Infantryman,Iron Mauler,Shock Trooper
        [/filter]
        [fire_event]
            name=movement_warning
        [/fire_event]
    [/event]

    [event]
        name=recruit
        [filter]
            type=Horseman,Cavalryman,Heavy Infantryman
        [/filter]
        [fire_event]
            name=movement_warning
        [/fire_event]
    [/event]

    [event]
        name=movement_warning
        [message]
            speaker=Dacyn
            message= _ "The island ahead is mountainous; it would be wise to select troops that do well on such terrain."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            [not]
                id=Dacyn
            [/not]
            [filter_location]
                x,y=12,4
                radius=3
            [/filter_location]
        [/filter]
        [filter_condition]
            [variable]
                name=Dacyn_researching
                boolean_equals=false
            [/variable]
        [/filter_condition]
        [message]
            speaker=unit
            message= _ "This must be the academy Dacyn mentioned."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "It still looks quite defensible. We should be able to hold there while Dacyn is working."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Very well. Let us rally there after the trolls and gryphons are defeated."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            x,y=12,4
            side=1
        [/filter]
        [sound]
            name=gold.ogg
        [/sound]
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "You find 100 gold in the fortress!"
        [/message]
        [gold]
            side=1
            amount=100
        [/gold]
    [/event]

    [event]
        name=moveto
        [filter]
            x,y=12,4
            id=Dacyn
        [/filter]

        [message]
            speaker=Dacyn
            message= _ "Excellent; I’ll start my research."
        [/message]

        [store_unit]
            [filter]
                id=Dacyn
            [/filter]

            kill=yes
            variable=stored_Dacyn
        [/store_unit]

        [set_variable]
            name=Dacyn_researching
            value=true
        [/set_variable]

        # If we've already defeated all enemies, end the scenario now
        [if]
            [variable]
                name=enemies_defeated
                boolean_equals=true
            [/variable]
            [then]
                [delay]
                    time=3000
                [/delay]

                [message]
                    speaker=narrator
                    message= _ "Some time later..."
                [/message]

                [endlevel]
                    result=victory
                    bonus=yes
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/then]
            [else]
                [show_objectives][/show_objectives]
            [/else]
        [/if]
    [/event]

    [event]
        name=enemies defeated

        [message]
            speaker=Gweddry
            message= _ "Alright, now we should be safe while Dacyn is researching."
        [/message]

        [set_variable]
            name=enemies_defeated
            value=true
        [/set_variable]
    [/event]

    # Check each turn if the victory conditions have been met
    [event]
        name=turn end
        first_time_only=no
        [filter_condition]
            [variable]
                name=enemies_defeated
                boolean_equals=true
            [/variable]
            [variable]
                name=Dacyn_researching
                boolean_equals=true
            [/variable]
        [/filter_condition]

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

    [event]
        name=victory

        [unstore_unit]
            variable=stored_Dacyn
            find_vacant=yes
        [/unstore_unit]

        {CLEAR_VARIABLE stored_Dacyn}
        {CLEAR_VARIABLE enemies_defeated}
        {CLEAR_VARIABLE Dacyn_researching}

        [store_unit]
            [filter]
                id=Gweddry
            [/filter]
            variable=temp
        [/store_unit]
        [message]
            speaker=Dacyn
            message= _ "I have found an answer! We must return to Wesnoth immediately! ..."
        [/message]
        [unit]
            type=Troll Warrior
            side=3
            x=$temp.x
            y=$temp.y
        [/unit]
        [unit]
            type=Troll Warrior
            id=Groog
            name= _ "Groog"
            side=3
            x=$temp.x
            y=$temp.y
        [/unit]
        [unit]
            type=Troll Warrior
            side=3
            x=$temp.x
            y=$temp.y
        [/unit]
        [unit]
            type=Troll Warrior
            side=3
            x=$temp.x
            y=$temp.y
        [/unit]
        [unit]
            type=Troll Warrior
            side=3
            x=$temp.x
            y=$temp.y
        [/unit]
        [unit]
            type=Troll Warrior
            side=3
            x=$temp.x
            y=$temp.y
        [/unit]
        [message]
            speaker=Groog
            # wmllint: local spelling wid
            message= _ "Be not going too fast. You gonna come wid us."
        [/message]
        [delay]
            time=100
        [/delay]

        {CLEAR_VARIABLE temp}
    [/event]

    {FOREIGN_DEFEAT}
[/scenario]
