#textdomain wesnoth-dm
[scenario]
    id=07_Night_in_the_Swamp
    name=_ "Night in the Swamp"
    {MEMOIRS_MAP 07_Night_in_the_Swamp.map}
    next_scenario=08_Ur-Thorodor
    turns=12
    victory_when_enemies_defeated=no

    # There is one less turn than times, so time over displays on morning
    {DUSK}
    {FIRST_WATCH}
    {FIRST_WATCH}
    {FIRST_WATCH}
    {FIRST_WATCH}
    {FIRST_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {SECOND_WATCH}
    {DAWN}
    {MORNING}

    {SCENARIO_MUSIC underground.ogg} # No story part, so no intro music
    {EXTRA_SCENARIO_MUSIC frantic.ogg}
    {EXTRA_SCENARIO_MUSIC vengeful.ogg}
    {EXTRA_SCENARIO_MUSIC siege_of_laurelmor.ogg}

    {DM_TRACK {SEARCH_STAGE7}}

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        recruit=Mage,Spearman,Horseman,Bowman,Cavalryman,Heavy Infantryman
        save_id=Player
        team_name=allies
        user_team_name= _ "Loyalists"
        side_name= _ "Delfador"
        {FLAG_VARIANT loyalist}
        [leader]
            {YOUNG_DELFADOR}
        [/leader]
        [unit]
            {LIONEL}
            placement=leader
        [/unit]
        {GOLD 120 110 100}
    [/side]

    [side]
        side=2
        controller=ai
        team_name=enemies
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        no_leader=yes
    [/side]
    # wmllint: validate-on

#define MEMOIRS_GENERATOR_SKELETON X Y
    # set the generator's terrain
    [event]
        name=prestart
        [item]
            x,y={X},{Y}
            image=scenery/monolith2.png
        [/item]
    [/event]

    # generate a unit each turn
    [event]
        id=generator_{X}_{Y}
        name=new turn
        first_time_only=no

        [scroll_to]
            x,y={X},{Y}
        [/scroll_to]
        [sound]
            name=magic-dark.ogg
        [/sound]
        {RANDOM (Skeleton,Skeleton Archer)}
        [unit]
            type=$random
            side=2
            x,y={X},{Y}
            animate=yes
        [/unit]
        {CLEAR_VARIABLE random}
    [/event]

    # if someone capable of destroying the generator moves there
    [event]
        name=moveto
        [filter]
            side=1
            x,y={X},{Y}
            type_adv_tree=Mage,Journeyman Mage,Paladin
        [/filter]

        [message]
            speaker=unit
            message=_"I call upon all that is holy to break the power of this evil stone!"
        [/message]
        {FLASH_LIGHTNING ()}
        [remove_event]
            id=generator_{X}_{Y}
        [/remove_event]
        [set_variable]
            name=generators_destroyed
            add=1
        [/set_variable]
        [if]
            [variable]
                name=generators_destroyed
                equals={ON_DIFFICULTY 2 2 3}
            [/variable]
            [then]
                [if]
                    [not]
                        [have_unit]
                            side=2
                        [/have_unit]
                    [/not]
                    [then]
                        [message]
                            speaker=Delfador
                            message=_"I think that’s all of them! Let’s move on — the less time we spend in this swamp the better."
                        [/message]
                        {CLEAR_VARIABLE generators_destroyed}
                        [endlevel]
                            result=victory
                            bonus=yes
                        [/endlevel]
                    [/then]
                    [else]
                        [objectives]
                            side=1
                            [objective]
                                description=_ "Survive until daybreak"
                                condition=win
                                show_turn_counter=yes
                            [/objective]
                            [objective]
                                {ALTERNATIVE_OBJECTIVE_CAPTION}
                                description=_ "Defeat remaining enemy units"
                                condition=win
                            [/objective]
                            [objective]
                                description=_ "Death of Delfador"
                                condition=lose
                            [/objective]
                            [objective]
                                description=_ "Death of Lionel"
                                condition=lose
                            [/objective]

                            [gold_carryover]
                                bonus=yes
                                carryover_percentage=80
                            [/gold_carryover]
                        [/objectives]
                        # if the player manages to destroy all generators he then has to kill remaining enemy units. an unlikely outcome unless we are on EASY. the following child event is spawned from this condition.
                        [event]
                            name=die
                            first_time_only=no
                            [filter]
                                side=2
                            [/filter]
                            [if]
                                [not]
                                    [have_unit]
                                        side=2
                                    [/have_unit]
                                [/not]
                                [then]
                                    [message]
                                        speaker=Delfador
                                        message=_"I think that’s all of them! Let’s move on — the less time we spend in this swamp the better."
                                    [/message]
                                    {CLEAR_VARIABLE generators_destroyed}
                                    [endlevel]
                                        result=victory
                                        bonus=yes
                                    [/endlevel]
                                [/then]
                            [/if]
                        [/event]
                    [/else]
                [/if]
            [/then]
        [/if]
    [/event]

    # if someone who can't destroy the generator moves there
    [event]
        name=moveto
        [filter]
            x,y={X},{Y}
            side=1
            [not]
                type_adv_tree=Mage,Journeyman Mage,Paladin
            [/not]
        [/filter]

        [message]
            speaker=unit
            message=_"Evil emanates from this stone, but I have not the power to destroy it."
        [/message]
    [/event]
#enddef

#ifdef EASY
    {MEMOIRS_GENERATOR_SKELETON 18 3}
    {MEMOIRS_GENERATOR_SKELETON 10 16}
#else
    {MEMOIRS_GENERATOR_SKELETON 7 5}
    {MEMOIRS_GENERATOR_SKELETON 11 19}
#endif
#ifdef HARD
    {MEMOIRS_GENERATOR_SKELETON 18 3}
#endif

    [event]
        name=prestart
        {MODIFY_UNIT (id=Delfador) facing nw}
        {MODIFY_UNIT (id=Lionel) facing se}
        {VARIABLE generators_destroyed 0}
        [objectives]
            side=1
            [objective]
                description=_ "Survive until daybreak"
                condition=win
                show_turn_counter=yes
            [/objective]
            [objective]
                {ALTERNATIVE_OBJECTIVE_CAPTION}
                description=_ "Destroy the stones and defeat all enemies"
                condition=win
            [/objective]
            [objective]
                description=_ "Death of Delfador"
                condition=lose
            [/objective]
            [objective]
                description=_ "Death of Lionel"
                condition=lose
            [/objective]

            [gold_carryover]
                bonus=yes
                carryover_percentage=80
            [/gold_carryover]

            [note]
                description=_ "Mages and Paladins are capable of destroying the stones"
            [/note]
        [/objectives]
    [/event]

    [event]
        name=start
        [message]
            speaker=Delfador
            message=_"These swamps seem to go on forever!"
        [/message]
        [message]
            speaker=Lionel
            message=_"One more day’s travel, I think. We should camp for the night now — we should be out of it by tomorrow evening."
        [/message]
    [/event]

    [event]
        name=new turn
        [message]
            speaker=Delfador
            message=_"Those standing stones — they summon evil creatures!"
        [/message]
        [message]
            speaker=Lionel
            message=_"I saw this kind of thing in the north... These abominations are not much affected by swords, but they fear the light of day. We must hold them off as best we can."
        [/message]
        [message]
            speaker=Delfador
            message=_"Hmmm... if I could get nearer to the stones, I could perhaps break their power..."
        [/message]
    [/event]

    # encourage the player who takes the hint about "swords"
    [event]
        name=attack
        [filter]
            type_adv_tree=Heavy Infantryman
        [/filter]
        [filter_second]
            type_adv_tree=Skeleton,Skeleton Archer
        [/filter_second]
        [message]
            speaker=unit
            message=_"This’ll splinter your bones, you vile monstrosity!"
        [/message]
    [/event]

    [event]
        name=time over
        [if]
            [have_unit]
                side=2
            [/have_unit]
            [then]
                [message]
                    speaker=Delfador
                    message=_"At last, morning is here... And the skeletons are disappearing!"
                [/message]
                [kill]
                    side=2
                [/kill]
                [redraw]
                [/redraw]
            [/then]
            [else]
                [message]
                    speaker=Delfador
                    message=_"At last, morning is here!"
                [/message]
            [/else]
        [/if]
        [message]
            speaker=Lionel
            message=_"I hope I never see another night like that! Let’s leave this evil place as quickly as possible — I want to get us out of Illuven before dusk."
        [/message]
        {CLEAR_VARIABLE generators_destroyed}
        [endlevel]
            result=victory
            bonus=no
        [/endlevel]
    [/event]

    {MEMOIRS_DEATHS}
[/scenario]
