#textdomain wesnoth-httt
[scenario]
    id=05b_Isle_of_the_Damned
    next_scenario=06_The_Siege_of_Elensefar
    name= _ "Isle of the Damned"
    map_data="{campaigns/Heir_To_The_Throne/maps/05b_Isle_of_the_Damned.map}"
    {TURNS 28 26 24}

    {DEFAULT_SCHEDULE}

    {SCENARIO_MUSIC "elvish-theme.ogg"}
    {EXTRA_SCENARIO_MUSIC "nunc_dimittis.ogg"}
    {EXTRA_SCENARIO_MUSIC "silvan_sanctuary.ogg"}
    {EXTRA_SCENARIO_MUSIC "weight_of_revenge.ogg"}

    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description= _ "Resist until the end of the turns"
                condition=win
                show_turn_counter=yes
            [/objective]
            {ALTERNATIVE_OBJECTIVE ( _ "Defeat all enemy leaders")}
            [objective]
                description= _ "Death of Konrad"
                condition=lose
            [/objective]

            [gold_carryover]
                carryover_percentage=0
            [/gold_carryover]
        [/objectives]
    [/event]

    # This appoints the Advisor role to our most advanced unit coming out of The Bay of Pearls. This would be
    # the same as the initial Advisor we would appoint if we took the path through Muff Malal's Peninsula, and
    # will be the initial Advisor recalled at the start of The Siege of Elensefar.
    #
    # We store a copy of this Advisor, giving it a new id. This is done in prestart because the recall list will
    # not be available at the point the ship returns to collect Konrad. When the ship comes to collect Konrad,
    # we will unstore this copy and hide it before it speaks its line. This way the ship appears to be selected,
    # but the unit's name, profile image and details are displayed; just as if the unit were inside the ship.
    #
    # This was an old TODO item, now done. That TODO also suggested having the Advisor speak on enemies defeated
    # as well as turns over. So I moved the WML for the line to place it in the macro and re-ordered a bit so it
    # works and still looks the same on time over.
    # GL-2016JUL

    [event]
        name=prestart

        [role]
            role=Advisor
            search_recall_list=only

            type="Elvish Sylph,Great Mage," +
                "Elvish Marshal,Elvish Champion,Elvish Avenger,Elvish Sharpshooter,Elvish Shyde,Elvish Enchantress,Elvish Outrider,Paladin,Grand Knight,Mage of Light,Arch Mage,Silver Mage," +
                "Merman Triton,Merman Hoplite,Merman Javelineer,Merman Entangler,Mermaid Diviner,Mermaid Siren," +
                "Elvish Captain,Elvish Hero,Elvish Ranger,Elvish Marksman,Elvish Druid,Elvish Sorceress,Elvish Rider,Knight,Lancer,White Mage,Red Mage," +
                "Merman Warrior,Merman Spearman,Merman Netcaster,Mermaid Priestess,Mermaid Enchantress," +
                "Elvish Fighter,Elvish Archer,Elvish Shaman,Elvish Scout,Horseman,Mage," +
                "Merman Fighter,Merman Hunter,Mermaid Initiate"
            [else]
                [unit]
                    side=1
                    type=Elvish Fighter
                    role=Advisor
                    x,y=recall,recall
                [/unit]
            [/else]
        [/role]

        [store_unit]
            variable=hidden_advisor
            [filter]
                role=Advisor
            [/filter]
        [/store_unit]

        [set_variable]
            name=hidden_advisor.id
            value=hidden_advisor
        [/set_variable]
    [/event]

    [story]
        [part]
            story= _ "But the voyage did not go as smoothly as had been hoped. A storm blew up and bore down on the ship. Though all hands were on deck working desperately, a sudden gust of wind flung Konrad overboard as he attempted to secure the sails..."
            {HTTT_BIGMAP}
            show_title=no
        [/part]
        [part]
            story= _ "The merfolk finally saved Konrad from the sea, but were unable to get him back to the ship. By dint of great effort they reached a nearby island..."
            {HTTT_BIGMAP}
            show_title=no
        [/part]
    [/story]

    {HTTT_TRACK {JOURNEY_05B_NEW} }

    [side]
        type=Commander
        id=Konrad
        name= _ "Konrad"
        unrenamable=yes
        profile=portraits/konrad-elvish.png
        side=1
        canrecruit=yes
        team_name=elves
        user_team_name=_"Rebels"
        controller=human
        gold=0
#ifdef HARD
        fog=yes
#endif
        {FLAG_VARIANT long}
    [/side]

    # Neither enemy leader gets starting villages, in order to slow down their
    # initial rush a bit

    [side]
        id=Haf-Mal
        name= _ "Haf-Mal"
        type=Lich
        side=2
        canrecruit=yes
        team_name=undead
        user_team_name=_"Undead"
        recruit=Skeleton,Vampire Bat,Ghost,Dark Adept,Chocobone
        [ai]
            recruitment_pattern=scout,fighter,fighter,archer
            {ATTACK_DEPTH 1 3 5}
        [/ai]
        {GOLD 80 100 110}
        {FLAG_VARIANT undead}
    [/side]

    [side]
        id=Jarmal-Gorg
        name= _ "Jarmal-Gorg"
        type=Lich
        side=3
        canrecruit=yes
        team_name=undead
        user_team_name=_"Undead"
        recruit=Skeleton,Skeleton Archer,Walking Corpse,Vampire Bat,Ghost,Dark Adept
        [ai]
            recruitment_pattern=scout,fighter,archer,fighter,archer,fighter
            {ATTACK_DEPTH 1 3 5}
        [/ai]
        {GOLD 80 100 110}
        {FLAG_VARIANT undead}
    [/side]

    [event]
        name=prestart
        {VARIABLE via_isle_of_the_damned yes}
        {CLEAR_VARIABLE moremirmu}

        {PLACE_IMAGE scenery/temple1.png 11 13}
        {PLACE_IMAGE scenery/temple1.png 10 17}
        {PLACE_IMAGE scenery/temple1.png 9 15}

        #reset gold held to 100
        [store_side]
            side=1
        [/store_side]
        {VARIABLE isle_damned_starting_gold $side.gold}
        {CLEAR_VARIABLE side}

        [modify_side]
            side=1
            gold=0
        [/modify_side]

        # disallow recruiting of everything except merfolk
        [disallow_recruit]
            side=1
            type=Elvish Fighter,Elvish Archer,Elvish Shaman,Elvish Scout,Mage,Horseman
        [/disallow_recruit]

        [allow_recruit]
            side=1
            type=Thug,Poacher,Footpad
        [/allow_recruit]
        {STORE_DELFADOR}

        # Kill the recall list except for merfolk
        [store_unit]
            variable=iotd_recall_store
            kill=yes
            [filter]
                side=1
                [not]
                    race=merman
                [/not]
                [not]
                    id=Konrad
                [/not]
            [/filter]
        [/store_unit]

        {NAMED_LOYAL_UNIT 1 (Merman Fighter) 27 12 (Kalba) ( _ "Kalba")}
        {NAMED_LOYAL_UNIT 1 (Merman Fighter) 31 14 (Gnaba) ( _ "Gnaba")}
        # wmllint: recognize Kalba
        # wmllint: recognize Gnaba
    [/event]

    [event]
        name=start

        [message]
            speaker=Konrad
            {KONRAD_VARIATION_ELF concerned}
            message= _ "Whew, I survived. But now where am I? Is this island inhabited?"
        [/message]
        [message]
            speaker=Kalba
            message= _ "We have heard only the worst things about this place, my lord. It is said that the legions of the undead have come here in great numbers and devastated the island into an ugly wasteland."
        [/message]
        [message]
            speaker=Konrad
            {KONRAD_VARIATION_ELF concerned}
            message= _ "Let’s hope these rumors are not true! I have none of my men or gold with me! How could I defend myself?"
        [/message]
        [message]
            speaker=Kalba
            message= _ "There are still some bands of humans hiding on the island, my lord. If you recruit some of them to help, we might have some hope of holding off the undead hordes!"
        [/message]

        {NAMED_LOYAL_UNIT 1 (Outlaw) 20 10 (Delurin) ( _ "Delurin")}
        # wmllint: recognize Delurin

        [redraw]
            side=1
        [/redraw]

        {MOVE_UNIT id=Delurin 21 12}

        [redraw]
            side=1
        [/redraw]

        [message]
            speaker=Delurin
            message= _ "Maybe we can make a deal! Help us defeat those evil creatures! You may use our gold reserves to lead us!"
        [/message]

        [modify_side]
            side=1
            gold=100
        [/modify_side]

        [message]
            speaker=narrator
            message= _ "You receive 100 pieces of gold!"
            image=wesnoth-icon.png
        [/message]
    [/event]

    [event]
        name=turn 2
        [message]
            speaker=Konrad
            message= _ "There are some ancient temples to the southwest; I wonder what might be inside them!"
        [/message]
    [/event]

#define EMPTY_TEMPLE_TRAP X Y
    [event]
        name=moveto
        [filter]
            side=1
            x={X}
            y={Y}
        [/filter]
        [message]
            speaker=unit
            message= _ "The temple seems to be empty."
        [/message]
    [/event]
#enddef

#define MOREMIRMU_TRAP X Y
    [event]
        name=moveto
        [filter]
            side=1
            x={X}
            y={Y}
        [/filter]
        [message]
            speaker=unit
            message= _ "Looks like there is somebody hidden in the temple."
        [/message]
        [unit]
            id=Moremirmu
            name= _ "Moremirmu"
            side=1
            type=White Mage
            x={X}
            y={Y}
            random_traits=no
            profile=portraits/moremirmu.png

            #Moremirmu has a special sword which makes him
            #especially deadly against undead.
            [modifications]
                [object]
                    [effect]
                        apply_to=attack
                        range=melee
                        set_name=holy sword
                        set_description=_ "holy sword"
                        set_icon=attacks/sword-holy.png
                        set_type=arcane
                        increase_damage=1
                        increase_attacks=2
                    [/effect]
                [/object]
                {TRAIT_LOYAL}
            [/modifications]
            {IS_LOYAL}
        [/unit]
        #set the variable to say the Moremirmu is alive
        [set_variable]
            name=moremirmu
            value=1
        [/set_variable]
        [message]
            speaker=Moremirmu
            message= _ "I was hiding in this holy place, planning how to defeat the evil undead. Now with your help, I can destroy them."
        [/message]
        [message]
            speaker=Konrad
            message= _ "Join us, wise one. We welcome your aid!"
        [/message]
        [message]
            speaker=Moremirmu
            message= _ "If we eradicate the undead blight on these islands, I will surely go with you. Otherwise, I plan to finish my task here before moving on."
        [/message]
    [/event]
#enddef

#define XAKAE_TRAP X Y
#ifdef EASY
    {EMPTY_TEMPLE_TRAP {X} {Y}}
#else
    [event]
        name=moveto
        [filter]
            side=1
            x={X}
            y={Y}
        [/filter]
        [message]
            speaker=unit
            message= _ "Looks like there is somebody hidden in the temple."
        [/message]

        [unit]
            type=Revenant
            id=Xakae
            name= _ "Xakae"
            side=2
            x={X}
            y={Y}
            [modifications]
                {TRAIT_LOYAL}
            [/modifications]
            {IS_LOYAL}
        [/unit]

        {LOYAL_UNIT 2 (Walking Corpse) ({X}) ({Y})}
        {LOYAL_UNIT 2 (Walking Corpse) ({X}) ({Y})}
#ifdef HARD
        {LOYAL_UNIT 2 (Walking Corpse) ({X}) ({Y})}
#endif

        [message]
            speaker=Xakae
            message= _ "Surprise! Searching for magi, and all I get is these foul humans!"
        [/message]
    [/event]
#endif
#enddef

    [event]
        name=prestart

        {RANDOM 1..6}
        [switch]
            variable=random
            [case]
                value=6

                {EMPTY_TEMPLE_TRAP 9 15}
                {XAKAE_TRAP 10 17}
                {MOREMIRMU_TRAP 11 13}
            [/case]
            [case]
                value=5

                {XAKAE_TRAP 9 15}
                {EMPTY_TEMPLE_TRAP 10 17}
                {MOREMIRMU_TRAP 11 13}
            [/case]
            [case]
                value=4

                {EMPTY_TEMPLE_TRAP 9 15}
                {MOREMIRMU_TRAP 10 17}
                {XAKAE_TRAP 11 13}
            [/case]
            [case]
                value=3

                {XAKAE_TRAP 9 15}
                {MOREMIRMU_TRAP 10 17}
                {EMPTY_TEMPLE_TRAP 11 13}
            [/case]
            [case]
                value=2

                {MOREMIRMU_TRAP 9 15}
                {EMPTY_TEMPLE_TRAP 10 17}
                {XAKAE_TRAP 11 13}
            [/case]
            [else]
                # value=1 and "can't happen, but just in case" case

                {MOREMIRMU_TRAP 9 15}
                {XAKAE_TRAP 10 17}
                {EMPTY_TEMPLE_TRAP 11 13}
            [/else]
        [/switch]
        {CLEAR_VARIABLE random}
    [/event]

    [event]
        name=last breath
        [filter]
            id=Moremirmu
        [/filter]

        [message]
            speaker=unit
            message= _ "Fight on against the undead without me, friends!"
        [/message]
        [set_variable]
            name=moremirmu
            value=0
        [/set_variable]
    [/event]

#define ISLE_GALLEON_ARRIVE

    [sound]
        name=ambient/ship.ogg
    [/sound]

    [lift_fog]
        x=33,32,31,30,29,28,27
        y=7,7,8,7,7,7,8
        radius=3
    [/lift_fog]

    [move_unit_fake]
        type=Galleon
        side=1
        x=33,32,31,30,29,28,27
        y=7,7,8,7,7,7,8
    [/move_unit_fake]

    {PLACE_IMAGE "units/transport/galleon.png~RC(magenta>red)~FL()" 27 8}

    [unstore_unit]
        variable=hidden_advisor
        x,y=27,8
    [/unstore_unit]

    [hide_unit]
        id=hidden_advisor
    [/hide_unit]

    [message]
        speaker=hidden_advisor
        message= _ "Thank goodness we have found you, sir! Come aboard quickly, we shall take you away from this horrible island!"
    [/message]

    [kill]
        id=hidden_advisor
    [/kill]
#enddef

#define RESTORE_RECALL_LIST
    [foreach]
        array=iotd_recall_store
        [do]
            [unstore_unit]
                variable=this_item
            [/unstore_unit]
        [/do]
    [/foreach]
    {CLEAR_VARIABLE iotd_recall_store}
#enddef

    [event]
        name=enemies defeated
        [message]
            speaker=Konrad
            {KONRAD_VARIATION_ELF glad}
            message= _ "We have wrested control of the island from the evil undead! Now all we have to do is wait for the ship to arrive, so we can make our way to Elensefar!"
        [/message]

        {ISLE_GALLEON_ARRIVE}

        [if]
            [variable]
                name=moremirmu
                equals=1
            [/variable]
            [then]
                [message]
                    speaker=Moremirmu
                    message= _ "Together we have vanquished the foul undead! Come, I will join you on your noble quest."
                [/message]
                [set_variable]
                    name=moremirmu
                    value=2
                [/set_variable]
            [/then]
        [/if]

        [fire_event]
            name=victory dance
        [/fire_event]
    [/event]

    [event]
        name=time over
        {ISLE_GALLEON_ARRIVE}

        [message]
            speaker=Konrad
            message= _ "It’s a shame complete victory could not be ours, but thank goodness I am rescued! On to Elensefar!"
        [/message]
        [if]
            [variable]
                name=moremirmu
                equals=1
            [/variable]
            [then]
                [message]
                    speaker=Moremirmu
                    message= _ "Thank you for your assistance here, brothers. I will stay to continue resisting the foul undead. May fate be with you in your noble quest, and may we meet again some day!"
                [/message]
            [/then]
        [/if]

        [fire_event]
            name=victory dance
        [/fire_event]
    [/event]

    [event]
        name=victory dance

        [message]
            speaker=narrator
            message= _ "You regain your lost troops and $isle_damned_starting_gold gold!"
            image=wesnoth-icon.png
        [/message]

        [endlevel]
            result=victory
            bonus=no
            carryover_add=yes
            carryover_percentage=100
        [/endlevel]
    [/event]

    [event]
        name=victory

        {CLEAR_VARIABLE hidden_advisor}

        {RESTORE_RECALL_LIST}

        [if]
            [variable]
                name=moremirmu
                equals=1
            [/variable]
            [then]
                [kill]
                    id=Moremirmu
                [/kill]
            [/then]
        [/if]

        [modify_side]
            side=1
            gold=$isle_damned_starting_gold
        [/modify_side]

        {CLEAR_VARIABLE isle_damned_starting_gold}

        [allow_recruit]
            side=1
            type=Elvish Fighter,Elvish Archer,Elvish Shaman,Elvish Scout,Mage,Horseman
        [/allow_recruit]

        [disallow_recruit]
            side=1
            type=Thug,Poacher,Footpad
        [/disallow_recruit]

        {RESTORE_DELFADOR}
    [/event]

    {campaigns/Heir_To_The_Throne/utils/deaths.cfg}
[/scenario]

#undef EMPTY_TEMPLE_TRAP
#undef MOREMIRMU_TRAP
#undef XAKAE_TRAP
#undef ISLE_GALLEON_ARRIVE
#undef RESTORE_RECALL_LIST
