#textdomain wesnoth-did
[scenario]
    id=A_Haunting_in_Winter
    next_scenario=Beginning_of_the_Revenge

    name=_ "A Haunting in Winter"
    map_data="{campaigns/Descent_Into_Darkness/maps/A_haunting_in_winter.map}"
    victory_when_enemies_defeated=yes
    {TURNS 36 34 32}
    {UNDERGROUND}

    {INTRO_AND_SCENARIO_MUSIC the_deep_path.ogg knalgan_theme.ogg}
    {EXTRA_SCENARIO_MUSIC underground.ogg}
    {EXTRA_SCENARIO_MUSIC legends_of_the_north.ogg}

    [story]
        [part]
            story=_ "Malin and Darken Volk spend the summer and fall traveling up and down the lower Northlands. They attack small goblin villages and orc camps when they find them. Malin's power grows considerably under the constant tutelage of the necromancer."
            background=story/travel.jpg
            scale_background=no
        [/part]
        [part]
            show_title=yes
            {TO_A_HAUNTING_IN_WINTER}
        [/part]
    [/story]

    [time_area]
        x=12-24,12-21,12-20,14-18,16-18
        y=19-20,18,17,16,15
        {DEFAULT_SCHEDULE}
    [/time_area]

    [side]
        side=1
        controller=human
        type=Apprentice Mage
        id=Malin Keshar
        name=_ "Malin Keshar"
        unrenamable=yes
        canrecruit=yes
        recruit=Walking Corpse,Vampire Bat,Ghost,Ghoul
        fog=yes
        shroud=yes
        gold=150
        {FLAG_VARIANT undead}
    [/side]

    [side]
        side=2
        controller=ai
        team_name=outlaws
        user_team_name=_"Outlaws"
        type=Dwarvish Steelclad
        id=Dap Horner
        name=_ "Dap Horner"
        canrecruit=yes
        recruit=Dwarvish Guardsman,Dwarvish Fighter,Dwarvish Thunderer
        {GOLD 0 20 40}
        fog=yes
        shroud=no
        [ai]
            aggression=0.6
            grouping=offensive
            recruitment_pattern=mixed fighter,fighter
        [/ai]
    [/side]

    [side]
        side=3
        controller=ai
        team_name=outlaws
        user_team_name=_"Outlaws"
        type=Bandit
        id=Gorak Cole
        name=_ "Gorak Cole"
        canrecruit=yes
        recruit=Footpad,Poacher,Thug,Thief
        {GOLD 60 80 100}
        fog=yes
        shroud=no
        [ai]
            aggression=0.7
        [/ai]
    [/side]

    [side]
        side=4
        controller=ai
        team_name=free undead
        user_team_name=_"Free Undead"
        no_leader=yes
        fog=no
        shroud=no
        [ai]
            aggression=4.0
            caution=0.0
            grouping=no
            simple_targeting=yes
            village_value=0
            [target]
                id=Malin Keshar
                value=100
            [/target]
        [/ai]
    [/side]

    [event]
        name=prestart

        [objectives]
            side=1
            [objective]
                condition=win
                description=_ "Clear the cave of enemies"
            [/objective]
            [objective]
                condition=lose
                description=_ "Death of Malin Keshar"
            [/objective]
            [objective]
                condition=lose
                description=_ "Death of Darken Volk"
            [/objective]
            [objective]
                condition=lose
                description=_ "Time runs out"
            [/objective]

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

        # {SCATTER_IMAGE (terrain=Uu) 5 scenery/rubble.png}

        # Set outlaw villages
        {SET_VILLAGE 2 28 1}
        {SET_VILLAGE 2 23 7}
        {SET_VILLAGE 2 29 8}
        {SET_VILLAGE 2 28 10}

        {SET_VILLAGE 3 12 15}
        {SET_VILLAGE 3 9 18}
        {SET_VILLAGE 3 9 20}
        {SET_VILLAGE 3 10 10}

        # Set dwarf watchman
        {NAMED_LOYAL_UNIT 2 (Dwarvish Guardsman) 14 12 Watchman (_ "Watchman")}

        # Ghost variable
        {VARIABLE ghost_was_freed no}

        # Set ghost leader rebellion turn
        [set_variable]
            name=free_ghost_turn
            random=5..16
        [/set_variable]
    [/event]

    [event]
        name=start
        [recall]
            id=Darken Volk
        [/recall]

        [message]
            speaker=Darken Volk
            message=_ "Winter comes on fast, and we need a sheltered place to spend it. This cave looks promising, but from the tracks in and out several bands of outlaws already inhabit it. You should clear them out so we may use it safely."
        [/message]
    [/event]

    # In-scenario events

    # Warn player about the rebellion
    [event]
        name=recruit
        first_time_only=yes
        [filter]
            type=Ghost
        [/filter]

        [message]
            speaker=Darken Volk
            message=_ "Be careful when imprisoning a soul and use all your might to retain control over it or it might attempt to break free and destroy you!"
        [/message]
        [message]
            speaker=Malin Keshar
            message=_ "I... I will try."
        [/message]
    [/event]

    [event]
        name=sighted
        [filter]
            side=2
        [/filter]
        [filter_second]
            side=1
        [/filter_second]
        [scroll_to]
            x,y=$x1,$y1
        [/scroll_to]
        [delay]
            time=250
        [/delay]

        [message]
            speaker=Malin Keshar
            message=_ "Dwarves! They have often been our allies against the orc hordes. Surely they will allow us to winter with them."
        [/message]

        [scroll_to]
            x,y=$x1,$y1
        [/scroll_to]

        [message]
            speaker=unit
            message=_ "Two necromancers are at the cave entrance! Up yer axes, boys, if ye dinna' want tae be a walking pile o' bones."
        [/message]
        [message]
            speaker=Malin Keshar
            message=_ "Or not. Why do they hate us so much?"
        [/message]
        [message]
            speaker=Darken Volk
            message=_ "People fear that which they don't understand, and death, after all, is the greatest mystery. Those who dare to investigate that mystery are bound to invoke fear and distrust. Worry not, your people will again warm to you once you deal with the orc threat at its source. For now, the cave-dwellers give us no choice."
        [/message]
    [/event]

    [event]
        name=new turn
        first_time_only=no
        [if]
            # Reach or pass ghost turn, and ghost wasn't already freed
            [have_unit]
                type=Ghost
            [/have_unit]
            [variable]
                name=free_ghost_turn
                less_than_equal_to=$turn_number
            [/variable]
            [variable]
                name=ghost_was_freed
                equals=no
            [/variable]
            [then]
                # Set free the ghost event
                [event]
                    name=side turn
                    first_time_only=yes
                    {MODIFY_ONE_UNIT type=Ghost side 4}
                    {MODIFY_ONE_UNIT side=4 id (Tortured Soul)}
                    {MODIFY_ONE_UNIT side=4 name (_ "Tortured Soul")}
                    {MODIFY_ONE_UNIT side=4 canrecruit yes}
                    {VARIABLE ghost_was_freed yes}

                    [message]
                        side=4
                        message=_ "Free! Your foul spells cannot enslave me any longer, Malin the Damned. You shall pay for keeping me from my final rest!"
                    [/message]
                    [message]
                        speaker=Darken Volk
                        message=_ "Fool boy! Your will must be stronger or you will never be able to control your soldiers well enough to face the orcs. Many are the young necromancers who have died when their servants turned on them. He will attack you relentlessly."
                    [/message]
                    [message]
                        speaker=Malin Keshar
                        message=_ "But why are they attacking me? And what should I do?!?"
                    [/message]
                    [message]
                        speaker=Darken Volk
                        message=_ "Destroy the rebel quickly and all will be well. Wait, and he will begin to turn the rest of your forces against you."
                    [/message]
                [/event]
            [/then]
        [/if]
    [/event]

    # When the free ghost leader is around, one random unit per turn is freed
    [event]
        name=new turn
        first_time_only=no
        [if]
            [have_unit]
                side=4
                canrecruit=yes
            [/have_unit]
            [then]
                {MODIFY_ONE_UNIT (race=undead
                side=1) side 4}
            [/then]
        [/if]
    [/event]

    [event]
        name=die
        [filter]
            side=4
            canrecruit=yes
        [/filter]
        # Regain control of "rebel" ghosts
        {MODIFY_UNIT (side=4
        canrecruit=no) side 1}

        [message]
            speaker=Malin Keshar
            message=_ "I think I've got the rest of them under control now. That was a close call."
        [/message]
    [/event]

    # Defeat Conditions
    {MALIN_DEATH}
    {VOLK_DEATH}
    {TIME_OUT_LOSE}

    # Victory Condition
    [event]
        name=enemies defeated
        [endlevel]
            result=victory
            bonus=yes
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

    [event]
        name=victory
        {CLEAR_VARIABLE free_ghost_turn}
        {CLEAR_VARIABLE ghost_was_freed}
    [/event]
[/scenario]
