#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}"
    {SCENARIO_MUSIC "revelation.ogg"}
    {EXTRA_SCENARIO_MUSIC "wanderer.ogg"}
    {EXTRA_SCENARIO_MUSIC "nunc_dimittis.ogg"}
    {TURNS 28 26 24}

    {DEFAULT_SCHEDULE}

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

            note= _ "No gold carried over to the next scenario."
        [/objectives]
    [/event]

    {BIGMAP_ISLE_OF_THE_DAMNED_1}

    [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..."
            background=story/story9.png
            show_title=no
        [/part]
        [part]
            story= _ "The mermen 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..."
            background="maps/wesnoth.png"
            show_title=no
        [/part]
    [/story]

    {BIGMAP_ISLE_OF_THE_DAMNED_2}

    [side]
        type=Commander
        id=Konrad
        name= _ "Konrad"
        unrenamable=yes
        profile=portraits/konrad.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

        {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 mermen
        [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]

        # 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]
    [/event]

    [event]
        name=start

        {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

        [message]
            speaker=Konrad
            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
            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]

    # TODO: randomize temples properly, and make Moremirmu appear at the end of
    # scenario if the player never found him

#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

            #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_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
    [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_UNDEAD}
                {TRAIT_LOYAL}
            [/modifications]
            {IS_LOYAL}
        [/unit]

        {LOYAL_UNDEAD_UNIT 2 (Walking Corpse) ({X}) ({Y})}
        {LOYAL_UNDEAD_UNIT 2 (Walking Corpse) ({X}) ({Y})}
#ifdef HARD
        {LOYAL_UNDEAD_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]
#enddef

    [event]
        name=start

        #
        # Determine the contents of the temples:
        # - on easy, Moremirmu shows up in 1 close temple and the others are empty
        # - on normal, Moremirmu shows up in 1 close temple and the far one has the revenant
        # - on hard, Moremirmu and the revenant show up in the 2 close temples (far one is empty)
        #
        {RANDOM 1..2}
        [if]
            [variable]
                name=random
                numerical_equals=1
            [/variable]
#ifdef EASY
            [then]
                {MOREMIRMU_TRAP 11 13}
                {EMPTY_TEMPLE_TRAP 10 17}
                {EMPTY_TEMPLE_TRAP 9 15}
            [/then]
            [else]
                {MOREMIRMU_TRAP 10 17}
                {EMPTY_TEMPLE_TRAP 11 13}
                {EMPTY_TEMPLE_TRAP 9 15}
            [/else]
#endif
#ifdef NORMAL
            [then]
                {MOREMIRMU_TRAP 11 13}
                {EMPTY_TEMPLE_TRAP 10 17}
                {XAKAE_TRAP 9 15}
            [/then]
            [else]
                {MOREMIRMU_TRAP 10 17}
                {EMPTY_TEMPLE_TRAP 11 13}
                {XAKAE_TRAP 9 15}
            [/else]
#endif
#ifdef HARD
            [then]
                {MOREMIRMU_TRAP 11 13}
                {XAKAE_TRAP 10 17}
                {EMPTY_TEMPLE_TRAP 9 15}
            [/then]
            [else]
                {MOREMIRMU_TRAP 10 17}
                {XAKAE_TRAP 11 13}
                {EMPTY_TEMPLE_TRAP 9 15}
            [/else]
#endif
        [/if]
    [/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]

    [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)" 27 8}
#enddef

#define RESTORE_RECALL_LIST
    {FOREACH iotd_recall_store i}
        [unstore_unit]
            variable=iotd_recall_store[$i]
        [/unstore_unit]
    {NEXT i}
    {CLEAR_VARIABLE iotd_recall_store}
#enddef

    [event]
        name=enemies defeated
        [message]
            speaker=Konrad
            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}
        {RESTORE_RECALL_LIST}

        [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]

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

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

        [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]

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

    [event]
        name=time over
        {ISLE_GALLEON_ARRIVE}
        {RESTORE_RECALL_LIST}

        # TODO: use an existing unit as the speaker, and maybe add the message
        # to the enemies defeated event too
        [message]
            speaker=narrator
            image=units/elves-wood/fighter.png
            message= _ "Thank goodness we have found you, sir! Come aboard quickly, we shall take you away from this horrible island!"
        [/message]
        [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]
                [kill]
                    id=Moremirmu
                [/kill]
            [/then]
        [/if]

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

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

        [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]

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

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