#textdomain wesnoth-trow
[scenario]
    id=22_The_Rise_of_Wesnoth
    name= _ "The Rise of Wesnoth"
    next_scenario=23_Epilogue
    victory_when_enemies_defeated=no
    map_data="{campaigns/The_Rise_Of_Wesnoth/maps/22_The_Rise_of_Wesnoth.map}"

    {TURNS 45 42 39}
    {DEFAULT_SCHEDULE}

    {SCENARIO_MUSIC knalgan_theme.ogg}
    {EXTRA_SCENARIO_MUSIC vengeful.ogg}
    {EXTRA_SCENARIO_MUSIC battle.ogg}
    {EXTRA_SCENARIO_MUSIC the_city_falls.ogg}

    # No story
    {TROW_GC_TRACK {JOURNEY_22_NEW} }

    {TROW_DEATHS}

    [side]
        id=Prince Haldric
        name= _ "Prince Haldric"
        side=1
        type=Noble Commander
        unrenamable=yes
        canrecruit=yes
        gold=200
        controller=human
        team_name=Haldric
        user_team_name=_"Refugees"
        {FLAG_VARIANT loyalist}
    [/side]

    #2 is Jevyan
    #3 is the Sea Castle
    #4 is the Coast Orc
    #5 is the Island Orc
    #6 is the North Orc

    [side]
        type=Ancient Lich
        id=Lich-Lord Jevyan
        name= _ "Lich-Lord Jevyan"
        profile="portraits/jevyan.png"
        side=2
        canrecruit=yes
        recruit=Revenant,Deathblade,Bone Shooter,Skeleton,Skeleton Archer,Vampire Bat,Walking Corpse,Soulless,Vampire Bat,Ghoul,Necrophage
        {GOLD 160 180 210}
        user_team_name=_"Evil"
        team_name=orcs
        [ai]
            {NO_SCOUTS}
            recruitment_pattern=scout,fighter,fighter,archer,scout,fighter,fighter,archer
            passive_leader=yes
            {ATTACK_DEPTH 5 6 6}
        [/ai]
        [ai]
            time_of_day=dusk,first_watch,second_watch
            aggression=0.65
        [/ai]
        [ai]
            [goal]
                name=protect_location
                [criteria]
                    x,y=42,40
                [/criteria]
                protect_radius=8
                value=10
            [/goal]
        [/ai]
        {INCOME 4 6 8}
        {FLAG_VARIANT undead}
    [/side]

    {STARTING_VILLAGES 2 10}

    [side]
        type=Orcish Warlord
        id=Tan-Vragish
        name= _ "Tan-Vragish"
        side=3
        canrecruit=yes
        recruit=Naga Fighter,Vampire Bat
        {GOLD 130 150 180}
        team_name=orcs
        user_team_name=_"Evil"
        [ai]
            {NO_SCOUTS}
            recruitment_pattern=fighter,fighter,scout
            {ATTACK_DEPTH 5 5 6}
        [/ai]
        [ai]
            time_of_day=dusk,first_watch,second_watch
            aggression=0.75
            caution=0.0
            grouping=no
        [/ai]
        {INCOME 1 2 4}
    [/side]

    {STARTING_VILLAGES 3 10}

    [side]
        type=Orcish Warlord
        id="Ut'Tan-Grorag"
        name= _ "Ut’Tan-Grorag"
        profile=portraits/orcs/grunt.png
        side=4
        canrecruit=yes
#ifdef EASY
        recruit=Orcish Archer, Orcish Assassin, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Goblin Pillager, Goblin Knight, Troll Whelp, Goblin Spearman
#endif

#ifdef NORMAL
        recruit=Orcish Archer, Orcish Assassin, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Goblin Pillager, Goblin Knight, Orcish Slayer, Orcish Warrior, Troll Whelp, Troll, Troll Rocklobber, Goblin Spearman
#endif

#ifdef HARD
        recruit=Orcish Archer, Orcish Assassin, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Orcish Warrior, Goblin Knight, Goblin Pillager, Orcish Slayer, Troll Whelp, Troll, Troll Warrior, Troll Rocklobber, Goblin Spearman, Goblin Impaler
#endif
        {GOLD 170 190 220}
        team_name=orcs
        user_team_name=_"Evil"
        [ai]
            #{NO_SCOUTS}
            recruitment_pattern=scout,fighter,fighter,archer,scout,fighter,fighter,archer,mixed fighter
            grouping=defensive
            {ATTACK_DEPTH 5 5 6}
        [/ai]
        [ai]
            time_of_day=dusk,first_watch,second_watch
            aggression=0.65
            grouping=offensive
        [/ai]
        {INCOME 2 4 8}
    [/side]

    {STARTING_VILLAGES 4 10}

    [side]
        type=Orcish Warlord
        id=Tan-Erinak
        name= _ "Tan-Erinak"
        profile=portraits/orcs/grunt-2.png
        side=5
        canrecruit=yes
#ifdef EASY
        recruit=Orcish Archer, Orcish Assassin, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Goblin Pillager, Goblin Knight, Troll Whelp, Goblin Spearman
#endif

#ifdef NORMAL
        recruit=Orcish Archer, Orcish Assassin, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Goblin Pillager, Goblin Knight, Orcish Slayer, Orcish Warrior, Troll Whelp, Troll, Troll Rocklobber, Goblin Spearman
#endif

#ifdef HARD
        recruit=Orcish Archer, Orcish Assassin, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Orcish Warrior, Goblin Knight, Goblin Pillager, Orcish Slayer, Troll Whelp, Troll, Troll Warrior, Troll Rocklobber, Goblin Spearman, Goblin Impaler
#endif
        {GOLD 150 170 200}
        team_name=orcs
        user_team_name=_"Evil"
        [ai]
            #{NO_SCOUTS}
            recruitment_pattern=scout,fighter,fighter,archer,scout,fighter,fighter,archer,mixed fighter
            grouping=defensive
            {ATTACK_DEPTH 5 5 6}
        [/ai]
        [ai]
            time_of_day=dusk,first_watch,second_watch
            aggression=0.65
            grouping=offensive
        [/ai]

        {INCOME 1 2 4}
    [/side]

    {STARTING_VILLAGES 5 10}

    [side]
        type=Orcish Warlord
        id=Tan-Prodash
        name= _ "Tan-Prodash"
        profile=portraits/orcs/grunt-3.png
        side=6
        canrecruit=yes
#ifdef EASY
        recruit=Orcish Archer, Orcish Assassin, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Goblin Pillager, Goblin Knight, Troll Whelp, Goblin Spearman
#endif

#ifdef NORMAL
        recruit=Orcish Archer, Orcish Assassin, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Goblin Pillager, Goblin Knight, Orcish Slayer, Orcish Warrior, Troll Whelp, Troll, Troll Rocklobber, Goblin Spearman
#endif

#ifdef HARD
        recruit=Orcish Archer, Orcish Assassin, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Orcish Warrior, Goblin Knight, Goblin Pillager, Orcish Slayer, Troll Whelp, Troll, Troll Warrior, Troll Rocklobber, Goblin Spearman, Goblin Impaler
#endif
        {GOLD 150 170 200}
        team_name=orcs
        user_team_name=_"Evil"
        [ai]
            {NO_SCOUTS}
            recruitment_pattern=scout,fighter,fighter,archer,scout,fighter,fighter,archer,mixed fighter
            {ATTACK_DEPTH 5 5 6}
        [/ai]
        [ai]
            time_of_day=dusk,first_watch,second_watch
            aggression=0.75
            caution=0.0
            grouping=no
        [/ai]
        {INCOME 1 2 4}
    [/side]

    {STARTING_VILLAGES 6 10}

    [event]
        name=prestart

        {PLACE_IMAGE ("units/transport/transport-galleon.png~RC(magenta>green)") 5 38}
        {PLACE_IMAGE ("units/transport/transport-galleon.png~RC(magenta>purple)") 21 35}
        {PLACE_IMAGE ("units/transport/transport-galleon.png~RC(magenta>black)") 38 27}
        {PLACE_IMAGE ("units/transport/transport-galleon.png~RC(magenta>brown)") 6 19}

        {PLACE_IMAGE ("units/transport/transport-galleon.png~RC(magenta>blue)") 21 37}
        {PLACE_IMAGE ("units/transport/transport-galleon.png~RC(magenta>blue)") 22 39}
        {PLACE_IMAGE ("units/transport/transport-galleon.png~RC(magenta>blue)") 23 44}

        [recall]
            id=Lady Jessene
        [/recall]
        [recall]
            id=Burin the Lost
        [/recall]
        [recall]
            id=Sir Ruddry
        [/recall]
        [recall]
            id=Sir Ladoc
        [/recall]
        [recall]
            id=Minister Edren
        [/recall]
        [recall]
            id=Commander Aethyr
        [/recall]

        [unit_overlay]
            id=Commander Aethyr
            image=misc/treaty-icon.png
        [/unit_overlay]

        {LIVING_INTEL (Familiar) (Familiar) ( _ "Familiar") "portraits/familiar.png" 2 40 39}
        # wmllint: whofield clear LIVING_INTEL

        [objectives]
            side=1
            [objective]
                description= _ "Commander Aethyr sacrifices himself to Lich-Lord Jevyan and"
                condition=win
            [/objective]
            [objective]
                description= _ "Destroy Lich-Lord Jevyan and"
                condition=win
            [/objective]
            [objective]
                description= _ "Defeat all enemy leaders except for one"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Prince Haldric"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Lady Jessene"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Commander Aethyr by somebody other than Jevyan"
                condition=lose
            [/objective]
            [objective]
                description= _ "Fail to leave one enemy leader behind"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}
            {IS_LAST_SCENARIO}
        [/objectives]
    [/event]

    [event]
        name=start
        [message]
            speaker=narrator
            message= _ "Haldric approaches the place where Lich-Lord Jevyan has made landfall. The final confrontation looms before him."
            image=wesnoth-icon.png
        [/message]
        [message]
            speaker=Lich-Lord Jevyan
            message= _ "You cannot win. Give me the Ruby of Fire and I will go in peace."
        [/message]
        [message]
            speaker=Prince Haldric
            message= _ "This ends here, Jevyan. Even if I believed your words I couldn’t give you the Ruby of Fire."
        [/message]
        [message]
            speaker=Lich-Lord Jevyan
            message= _ "Bah! Even if you have learned to conceal the power of the Ruby of Fire you will deliver it unto me in death!"
        [/message]
        [message]
            speaker=Lady Jessene
            message= _ "You’re a fool, Jevyan. How do you think we secured our place here? We had to give the elves the Ruby of Fire. We just signed a treaty with the elves ensuring our place here."
        [/message]
        [message]
            speaker=Lich-Lord Jevyan
            message= _ "No! I don’t believe it. Only a fool would give away an artifact of such power."
        [/message]
        [message]
            speaker=Prince Haldric
            message= _ "A fool, or a desperate band of refugees!"
            image=portraits/haldric-mad.png
        [/message]
        [message]
            speaker=Lich-Lord Jevyan
            message= _ "Casting fire is the least of the Ruby’s abilities. You are twice a fool, for having failed to plumb more than its most trivial use and for having given it away."
        [/message]
        [message]
            speaker=Burin the Lost
            message= _ "You shouldn’t give such toys to elves! Bah! It matters little to me. I’m no wizard. All I got is my axe. Heh, heh. It’s all I need — prepare to die, orcish scum!"
        [/message]
        [message]
            speaker=Minister Edren
            message= _ "Ha. Let all of the minions of Darkness be cast down!"
        [/message]
        [message]
            speaker=Prince Haldric
            message= _ "It matters little, because here you fall!"
            image=portraits/haldric-mad.png
        [/message]
        [message]
            speaker=Sir Ruddry
            message= _ "For all of the good people of Clearwater Port!"
        [/message]
        [message]
            speaker=Sir Ladoc
            message= _ "For the honor of Southbay!"
        [/message]
        [message]
            speaker=Commander Aethyr
            message= _ "We don’t need some magic trinket to beat you! Prepare to meet your fate, you decrepit sack of bones! For the honor of all of the people of the west-north!"
        [/message]
        [message]
            speaker=Prince Haldric
            message= _ "Charge!"
            image=portraits/haldric-mad.png
        [/message]
        [message]
            speaker="Ut'Tan-Grorag"
            message= _ "I hate it when my prey gets chatty! Get them, it’s a long boat ride back home!"
        [/message]
        [message]
            speaker=Lich-Lord Jevyan
            message= _ "We shall soon see if you have the Ruby of Fire!"
        [/message]
        [message]
            speaker=Familiar
            message= _ "<i>Clack</i>! <i>Clack!</i>"
        [/message]
        [message]
            speaker=Prince Haldric
            message={WHISPER _"Commander, you remember the plan right?"}
        [/message]
        [message]
            speaker=Commander Aethyr
            message={WHISPER _"Yes, sir. I am ready."}
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            side=1

            [not]
                id=Prince Haldric,Lady Jessene,Commander Aethyr
            [/not]
        [/filter]
        [message]
            speaker=Lady Jessene
            message= _ "He’s raising our dead! Be careful!"
        [/message]
    [/event]

    [event]
        name=die
        first_time_only=no

        [filter]
            side=1

            [not]
                id=Commander Aethyr
            [/not]
        [/filter]

        [filter_second]
            [not]
                #Basically not any type that has plague
                type=Walking Corpse,Soulless
            [/not]
        [/filter_second]

        {RISE_UP_RISE_UP}
    [/event]

    [event]
        name=attack
        [filter]
            id=Commander Aethyr
        [/filter]
        [message]
            speaker=Commander Aethyr
            message= _ "Feel my wrath, Jevyan, I’m coming for you! No piece of paper in my pocket is going to stop me from destroying you. For my family! For the people of Clearwater Port!"
        [/message]
        [message]
            speaker=Lich-Lord Jevyan
            message= _ "All life is finite; you will be made to serve along with the rest."
        [/message]
    [/event]

    [event]
        name=attack
        [filter]
            id=Burin the Lost
        [/filter]
        [message]
            speaker=Burin the Lost
            message= _ "Come on, stay still, just for a second..."
        [/message]
    [/event]

    [event]
        name=attack
        [filter]
            id=Lady Jessene
        [/filter]
        [message]
            speaker=Lady Jessene
            message= _ "For the Wesfolk!"
        [/message]
    [/event]

    [event]
        name=attack
        [filter]
            side=2,3,4,5,6
        [/filter]
        [filter_second]
            id=Commander Aethyr
        [/filter_second]
        [message]
            speaker=Lady Jessene
            message= _ "Be careful, Commander!"
        [/message]
    [/event]

    [event]
        name=attack
        [filter]
            id=Familiar
        [/filter]
        [message]
            speaker=Familiar
            message= _ "<i>Clack</i>! <i>Clack!</i>"
        [/message]
    [/event]

#define JEVGOLD
#ifdef EASY
    [gold]
        side=2
        amount=40
    [/gold]
#endif

#ifdef NORMAL
    [gold]
        side=2
        amount=80
    [/gold]
#endif

#ifdef HARD
    [gold]
        side=2
        amount=120
    [/gold]
#endif
#enddef

    # If Jevyan dies while Aethyr is still alive, player loses.
    [event]
        name=die

        [filter]
            id=Lich-Lord Jevyan
        [/filter]

        [filter_condition]
            [have_unit]
                id=Commander Aethyr
                side=1
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=Commander Aethyr
            message= _ "You deny me my honorable death? Our foes are not yet convinced that the elves have the ruby."
        [/message]

        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    # When Jevyan dies and there's more than one orcish leader left, have them
    # taunt the player.
    [event]
        name=die

        [filter]
            id=Lich-Lord Jevyan
        [/filter]

        [filter_condition]
            [have_unit]
                side=3,4,5,6
                canrecruit=yes
                count=2-4
            [/have_unit]
            [not]
                [have_unit]
                    id=Commander Aethyr
                [/have_unit]
            [/not]
        [/filter_condition]

        [message]
            speaker=Tan-Vragish
            message= _ "Da old bag o’ bones is gone, but you haven’t beat us yet!"  # wmllint: no spellcheck
        [/message]
        [message]
            speaker="Ut'Tan-Grorag"
            message= _ "We took yer home, now we’ll take yer lives!"
        [/message]
        [message]
            speaker=Tan-Erinak
            message= _ "The elfses have da fire ruby, and you have nothing!"    # wmllint: no spellcheck
        [/message]
        [message]
            speaker=Tan-Prodash
            message= _ "We will suck the marrow from your bones human!"
        [/message]
    [/event]

    # When only Jevyan and one orcish leader remains, have some dialogue.
    [event]
        name=die

        [filter]
            side=3,4,5,6
            canrecruit=yes
        [/filter]

        [filter_condition]
            [have_unit]
                side=3,4,5,6
                canrecruit=yes
                [not]
                    x,y=$x1,$y1
                [/not]
                count=1
            [/have_unit]

            [have_unit]
                id=Lich-Lord Jevyan
            [/have_unit]
        [/filter_condition]

        # Needed to prevent the dying leader from speaking
        [kill]
            x,y=$x1,$y1
        [/kill]

        [message]
            speaker=Tan-Vragish
            message= _ "The battle is going against us!"
        [/message]
        [message]
            speaker="Ut'Tan-Grorag"
            message= _ "Our forces are being routed! We should flee back to the Green Isle!"
        [/message]
        [message]
            speaker=Tan-Erinak
            message= _ "It goes poorly for us!"
        [/message]
        [message]
            speaker=Tan-Prodash
            message= _ "Defeated, by humans?"
        [/message]
        [message]
            speaker=Lich-Lord Jevyan
            message= _ "Fight on, you cowardly orcish worms!"
        [/message]
    [/event]

    # When only one orcish leader remains, player wins.
    [event]
        name=die
        first_time_only=no

        [filter]
            side=2,3,4,5,6
            canrecruit=yes
        [/filter]

        [filter_condition]
            [have_unit]
                side=3,4,5,6
                canrecruit=yes
                [not]
                    x,y=$x1,$y1
                [/not]
                count=1
            [/have_unit]

            [not]
                [have_unit]
                    id=Lich-Lord Jevyan
                [/have_unit]
            [/not]
            [not]
                [have_unit]
                    id=Commander Aethyr
                [/have_unit]
            [/not]
        [/filter_condition]

        [store_unit]
            [filter]
                side=3,4,5,6
                canrecruit=yes
                [not]
                    x,y=$x1,$y1
                [/not]
            [/filter]

            kill=no
            variable=last_orc_leader
        [/store_unit]

        [switch]
            variable=last_orc_leader.side

            [case]
                value=3

                [message]
                    speaker=Tan-Vragish
                    message= _ "Da old bag of bones has been crushed, and our cause is lost. We know da elfses have da fire ruby. Retreat!" # wmllint: no spellcheck
                [/message]

                [set_variables]
                    name=escape_boat

                    [value]
                        x1,y1=5,38
                        x2,y2=1,38
                    [/value]
                [/set_variables]
            [/case]

            [case]
                value=4

                [message]
                    speaker="Ut'Tan-Grorag"
                    message= _ "Da elfses have the fire ruby, we must flee. To da ships!"   # wmllint: no spellcheck
                [/message]

                [set_variables]
                    name=escape_boat

                    [value]
                        x1,y1=21,35
                        x2,y2=14,42
                    [/value]
                [/set_variables]
            [/case]

            [case]
                value=5

                [message]
                    speaker=Tan-Erinak
                    message= _ "We have many kinsmen on the Green Isle— we will return for the Ruby of Fire!"
                [/message]

                [set_variables]
                    name=escape_boat

                    [value]
                        x1,y1=38,27
                        x2,y2=12,27
                    [/value]
                [/set_variables]
            [/case]

            [case]
                value=6

                [message]
                    speaker=Tan-Prodash
                    message= _ "We must get back to the Green Isle. The elfses have the Ruby of Fire and our assault has been stopped." # wmllint: no spellcheck
                [/message]

                [set_variables]
                    name=escape_boat

                    [value]
                        x1,y1=6,19
                        x2,y2=1,24
                    [/value]
                [/set_variables]
            [/case]
        [/switch]

        [hide_unit]
            side=$last_orc_leader.side
            canrecruit=yes
        [/hide_unit]

        [move_unit_fake]
            side=$last_orc_leader.side
            type=$last_orc_leader.type
            x=$last_orc_leader.x,$escape_boat.x1
            y=$last_orc_leader.y,$escape_boat.y1
        [/move_unit_fake]

        [remove_item]
            x=$escape_boat.x1
            y=$escape_boat.y1
        [/remove_item]

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

        [move_unit_fake]
            side=$last_orc_leader.side
            type=Transport Galleon
            x=$escape_boat.x1,$escape_boat.x2
            y=$escape_boat.y1,$escape_boat.y2
        [/move_unit_fake]

        [endlevel]
            result=victory
            carryover_report=no
            linger_mode=no
            save=no
        [/endlevel]
    [/event]

    # If the player kills all orcish leaders, they lose.
    [event]
        name=die
        first_time_only=no

        [filter]
            side=3,4,5,6
            canrecruit=yes
        [/filter]

        [filter_condition]
            [have_unit]
                side=3,4,5,6
                canrecruit=yes
                [not]
                    x,y=$x1,$y1
                [/not]
                count=0
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=Prince Haldric
            message= _ "The plan revolved around some orcs making it back to the Green Isle to tell their kin that the elves have the Ruby of Fire so we wouldn’t have to bear the brunt of the next invasion."
            image=portraits/haldric-surprised.png
        [/message]
        [message]
            speaker=Prince Haldric
            message= _ "What have we done?"
            image=portraits/haldric-surprised.png
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=die

        [filter]
            side=3,4,5,6
            canrecruit=yes
        [/filter]

        {JEVGOLD}
    [/event]

    [event]
        name=last breath

        [filter]
            id=Commander Aethyr
        [/filter]

        [filter_second]
            [not]
                id=Lich-Lord Jevyan
            [/not]
        [/filter_second]

        # wmllint: local spelling soo
        # The idea is that he's dying and cannot finish the word
        [message]
            speaker=Commander Aethyr
            message= _ "My love, my family, I’ll be there soo—"
        [/message]

        [message]
            speaker=Prince Haldric
            message= _ "Aethyr! No! He was critical for convincing Jevyan that the elves have the Ruby of Fire."
            image=portraits/haldric-mad.png
        [/message]

        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=last breath

        [filter]
            id=Commander Aethyr
        [/filter]

        [filter_second]
            id=Lich-Lord Jevyan
        [/filter_second]

        [message]
            speaker=Commander Aethyr
            message= _ "Jevyan— I spit upon thee. Your end awaits. My love, my family, I’ll be there soo—"
        [/message]
    [/event]

    [event]
        name=die

        [filter]
            id=Commander Aethyr
        [/filter]

        [filter_second]
            id=Lich-Lord Jevyan
        [/filter_second]

        [message]
            speaker=Lich-Lord Jevyan
            message= _ "Fool. You are no match for my power. What! What’s this? A treaty. That’s elf script."
        [/message]

        [message]
            speaker=Lich-Lord Jevyan
            message= _ "No. Why? You fools, you gave the Ruby of Fire to the elves. But that won’t save you from me. I will destroy you, then I will deal with the elves."
        [/message]

        [message]
            speaker=Prince Haldric
            message= _ "We’ll see about that. For the honor of Commander Aethyr, forward!"
            image=portraits/haldric-mad.png
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Lich-Lord Jevyan
        [/filter]
        [message]
            speaker=Lich-Lord Jevyan
            message= _ "I am fallen before my plans have reached fruition. A curse upon you Haldric, may you and your descendants know nothing but strife!"
        [/message]
    [/event]

    [event]
        name=new turn
        first_time_only=no

        # Each [if] here determines whether one of the three bridges will be
        # destroyed on this turn start. If there's a player unit within 8 hexes
        # of the bridge, but no player within 2 hexes or any unit on the bridge
        # itself, a cuttle fish will appear and destroy it.
        [if]
            [have_location]
                x,y=23,23
                terrain=*^B*
            [/have_location]

            [have_unit]
                side=1

                [filter_location]
                    x=23,23
                    y=22,23
                    radius=8
                [/filter_location]
            [/have_unit]

            [not]
                [have_unit]
                    side=1

                    [filter_location]
                        x=23,23
                        y=22,23
                        radius=2
                    [/filter_location]
                [/have_unit]
            [/not]

            [not]
                [have_unit]
                    x=23,23
                    y=22,23
                [/have_unit]
            [/not]

            [then]
                [move_unit_fake]
                    type=Cuttle Fish
                    side=2
                    x=15,22
                    y=26,23
                [/move_unit_fake]

                [unit]
                    id=Squiddy
                    name= _ "Squiddy"
                    type=Cuttle Fish
                    side=2
                    x=22
                    y=23
                    facing=ne
                    [modifications]
                        {TRAIT_LOYAL}
                    [/modifications]
                    {IS_LOYAL}
                [/unit]

                [message]
                    side=1
                    [filter_location]
                        x,y=23,23
                        radius=8
                    [/filter_location]
                    message= _ "Ack. One of those monsters is destroying the bridge."
                [/message]

                [scroll_to_unit]
                    id=Squiddy
                [/scroll_to_unit]

                [animate_unit]
                    flag=attack

                    [filter]
                        id=Squiddy
                    [/filter]

                    [primary_attack]
                        range=melee
                    [/primary_attack]

                    [facing]
                        [filter_adjacent_location]
                            adjacent=sw
                            [filter]
                                id=Squiddy
                            [/filter]
                        [/filter_adjacent_location]
                    [/facing]

                    hits=yes
                [/animate_unit]

                [animate_unit]
                    flag=attack

                    [filter]
                        id=Squiddy
                    [/filter]

                    [primary_attack]
                        range=melee
                    [/primary_attack]

                    [facing]
                        [filter_adjacent_location]
                            adjacent=sw
                            [filter]
                                id=Squiddy
                            [/filter]
                        [/filter_adjacent_location]
                    [/facing]

                    hits=yes
                [/animate_unit]

                [sound]
                    name=cave-in.ogg
                [/sound]

                [sound]
                    name=water-blast.wav
                [/sound]

                [terrain]
                    x=23,23
                    y=22,23
                    terrain=Ww^Es
                [/terrain]

                [redraw]
                [/redraw]

                [delay]
                    time=500
                [/delay]
            [/then]
        [/if]

        [if]
            [have_location]
                x,y=43,17
                terrain=*^B*
            [/have_location]

            [have_unit]
                side=1

                [filter_location]
                    x=43,43
                    y=17,18
                    radius=8
                [/filter_location]
            [/have_unit]

            [not]
                [have_unit]
                    side=1

                    [filter_location]
                        x=43,43
                        y=17,18
                        radius=2
                    [/filter_location]
                [/have_unit]
            [/not]

            [not]
                [have_unit]
                    x=43,43
                    y=17,18
                [/have_unit]
            [/not]

            [then]
                [move_unit_fake]
                    type=Cuttle Fish
                    side=2
                    x=47,44
                    y=17,17
                [/move_unit_fake]

                [unit]
                    id=Inky
                    name= _ "Inky"
                    type=Cuttle Fish
                    side=2
                    x=44
                    y=17
                    facing=nw
                    [modifications]
                        {TRAIT_LOYAL}
                    [/modifications]
                    {IS_LOYAL}
                [/unit]

                [message]
                    side=1
                    [filter_location]
                        x,y=43,17
                        radius=8
                    [/filter_location]
                    message= _ "The bridge!"
                [/message]

                [scroll_to_unit]
                    id=Inky
                [/scroll_to_unit]

                [animate_unit]
                    flag=attack

                    [filter]
                        id=Inky
                    [/filter]

                    [primary_attack]
                        range=melee
                    [/primary_attack]

                    hits=yes
                [/animate_unit]

                [animate_unit]
                    flag=attack

                    [filter]
                        id=Inky
                    [/filter]

                    [primary_attack]
                        range=melee
                    [/primary_attack]

                    hits=yes
                [/animate_unit]

                [sound]
                    name=cave-in.ogg
                [/sound]

                [sound]
                    name=water-blast.wav
                [/sound]

                [terrain]
                    x=43,43
                    y=17,18
                    terrain=Ww^Es
                [/terrain]

                [redraw]
                [/redraw]

                [delay]
                    time=500
                [/delay]
            [/then]
        [/if]

        [if]
            [have_location]
                x,y=42,30
                terrain=*^B*
            [/have_location]

            [have_unit]
                side=1

                [filter_location]
                    x=42,41
                    y=30,31
                    radius=8
                [/filter_location]
            [/have_unit]

            [not]
                [have_unit]
                    side=1

                    [filter_location]
                        x=42,41
                        y=30,31
                        radius=2
                    [/filter_location]
                [/have_unit]
            [/not]

            [not]
                [have_unit]
                    x=42,41
                    y=30,31
                [/have_unit]
            [/not]

            [then]
                [move_unit_fake]
                    type=Cuttle Fish
                    side=2
                    x=47,42
                    y=32,31
                [/move_unit_fake]

                [unit]
                    id=Beaky
                    name= _ "Beaky"
                    type=Cuttle Fish
                    side=2
                    x=42
                    y=31
                    facing=nw
                    [modifications]
                        {TRAIT_LOYAL}
                    [/modifications]
                    {IS_LOYAL}
                [/unit]

                [scroll_to_unit]
                    id=Beaky
                [/scroll_to_unit]

                [animate_unit]
                    flag=attack

                    [filter]
                        id=Beaky
                    [/filter]

                    [primary_attack]
                        range=melee
                    [/primary_attack]

                    hits=yes
                [/animate_unit]

                [animate_unit]
                    flag=attack

                    [filter]
                        id=Beaky
                    [/filter]

                    [primary_attack]
                        range=melee
                    [/primary_attack]

                    hits=yes
                [/animate_unit]

                [sound]
                    name=cave-in.ogg
                [/sound]

                [sound]
                    name=water-blast.wav
                [/sound]

                [terrain]
                    x=42,41
                    y=30,31
                    terrain=Ww^Es
                [/terrain]

                [redraw]
                [/redraw]

                [message]
                    side=1
                    [filter_location]
                        x,y=42,30
                        radius=8
                    [/filter_location]
                    message= _ "Our advance is thwarted, that monster has destroyed the bridge!"
                [/message]

                [delay]
                    time=500
                [/delay]
            [/then]
        [/if]
    [/event]

    [event]
        name=turn 10
        [move_unit_fake]
            type=Naga Warrior
            side=2
            x=1,4
            y=35,34
        [/move_unit_fake]

        {NAMED_LOYAL_UNIT 2 (Naga Warrior) 4 34 (Abraxas) ( _ "Abraxas")}

        [scroll_to_unit]
            id=Abraxas
        [/scroll_to_unit]

        [message]
            speaker=Abraxas
            message= _ "It’s the Prince Haldric! Jevyan, you never said you came to destroy this monster. We will help you."
        [/message]

        {LOYAL_UNIT 3 (Naga Fighter) 3 34}
        {LOYAL_UNIT 2 (Naga Fighter) 3 35}

#ifdef NORMAL
        {LOYAL_UNIT 3 (Naga Fighter) 2 33}
        {LOYAL_UNIT 2 (Naga Fighter) 2 35}
#endif
#ifdef HARD

        {LOYAL_UNIT 3 (Naga Fighter) 2 33}
        {LOYAL_UNIT 2 (Naga Fighter) 2 35}
        {LOYAL_UNIT 3 (Naga Fighter) 1 34}
        {LOYAL_UNIT 2 (Naga Fighter) 1 35}
#endif

        [allow_recruit]
            type=Naga Fighter
            side=3
        [/allow_recruit]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Familiar
        [/filter]
        [message]
            speaker=Familiar
            message= _ "<i>Clack</i>! <i>Splat</i>!"   # wmllint: no spellcheck
        [/message]
    [/event]

    [event]
        name=die

        [filter]
            id=Familiar
        [/filter]

        [message]
            speaker=second_unit
            message= _ "Ahh... That almost makes it all worth while!"
        [/message]

        [if]
            [have_unit]
                id=Lich-Lord Jevyan
            [/have_unit]

            [then]
                [message]
                    speaker=Lich-Lord Jevyan
                    message= _ "You’ll pay for that!"
                [/message]
                {JEVGOLD}

                [fire_event]
                    name=spawn corpses
                [/fire_event]

                [fire_event]
                    name=spawn skeletons
                [/fire_event]

                [message]
                    speaker=Lich-Lord Jevyan
                    message= _ "Strike down these fools."
                [/message]
            [/then]
        [/if]
    [/event]

    # This event spawns corpses in the swamps around Jevyan's castle.
    [event]
        name=spawn corpses
        first_time_only=no

        [message]
            speaker=Lich-Lord Jevyan
            message= _ "Rise, rise from the ground!"
        [/message]
        [random_placement]
            variable=wc_loc
            allow_less=yes
            num_items={ON_DIFFICULTY 3 6 9}
            [filter_location]
                terrain=S*

                [and]
                    x,y=42,40
                    radius=14
                [/and]

                [not]
                    [filter]
                    [/filter]
                [/not]
            [/filter_location]
            [command]
                [sound]
                    name={SOUND_LIST:ZOMBIE_HIT}
                [/sound]

                {LOYAL_UNIT 2 (Walking Corpse) $wc_loc.x $wc_loc.y}
                [+unit]
                    animate=yes
                [/unit]
            [/command]
        [/random_placement]

        {CLEAR_VARIABLE wc_loc}
    [/event]

    # This event spawns skeletons to shallow water bordering deep water.
    [event]
        name=spawn skeletons
        first_time_only=no

        [message]
            speaker=Lich-Lord Jevyan
            message= _ "Come in from the deep my loyal soldiers!"
        [/message]
        [random_placement]
            variable=skele_loc
            allow_less=yes
            num_items={ON_DIFFICULTY 3 4 5}
            [filter_location]
                terrain=Ww

                [not]
                    [filter]
                    [/filter]
                [/not]

                [not]
                    [filter]
                        side=1
                    [/filter]

                    radius=1
                [/not]

                [filter_adjacent_location]
                    terrain=Wo
                    adjacent=nw,sw

                    [not]
                        [filter]
                        [/filter]
                    [/not]

                    [not]
                        [filter]
                            side=1
                        [/filter]

                        radius=1
                    [/not]
                [/filter_adjacent_location]
            [/filter_location]
            [command]
                [store_locations]
                    terrain=Wo

                    [not]
                        [filter]
                        [/filter]
                    [/not]

                    [not]
                        [filter]
                            side=1
                        [/filter]

                        radius=1
                    [/not]

                    [filter_adjacent_location]
                        x,y=$skele_loc.x,$skele_loc.y
                    [/filter_adjacent_location]

                    variable=skele_from
                [/store_locations]

                # This makes the type alternate between Skeleton and Skeleton Archer
                [switch]
                    variable=skele_type

                    [case]
                        value="Skeleton"

                        {VARIABLE skele_type "Skeleton Archer"}
                    [/case]

                    [case]
                        value="Skeleton Archer"

                        {VARIABLE skele_type "Skeleton"}
                    [/case]

                    [else]
                        {VARIABLE skele_type "Skeleton"}
                    [/else]
                [/switch]

                [scroll_to]
                    x=$skele_loc.x
                    y=$skele_loc.y
                [/scroll_to]

                [sound]
                    name=water-blast.wav
                [/sound]

                # Note: this doesn't actually get drawn because
                # of submerge, but it doesn't hurt either; if
                # at some point it becomes possible to make this
                # show up again, please do so
                [move_unit_fake]
                    side=2
                    type=$skele_type
                    x=$skele_from.x,$skele_loc.x
                    y=$skele_from.y,$skele_loc.y
                [/move_unit_fake]

                {LOYAL_UNIT 2 $skele_type $skele_loc.x $skele_loc.y}
            [/command]
        [/random_placement]
        {CLEAR_VARIABLE (skele_loc,skele_from,skele_type)}
    [/event]

    # This triggers on turns 2,9,16,23,... and sets the next corpse spawn turn
    # to be one of the next 5 turns, like this:
    # 1 2 (3 4 5 6 7) 8 9 (10 11 12 13 14) 15 16 (17 18 19 20 21) 22 23 (24 ...
    [event]
        name=turn 2,turn 9,turn 16,turn 23,turn 30,turn 37,turn 44
        first_time_only=no

        {VARIABLE_OP next_corpse_spawn_turn rand "$($turn_number + 1)..$($turn_number + 5)"}
        #{DEBUG_MSG "setting next corpse spawn to trigger on turn $next_corpse_spawn_turn"}
    [/event]

    # This triggers the corpse spawn on the turn determined by the above event.
    [event]
        name=new turn
        first_time_only=no

        [filter_condition]
            [variable]
                name=turn_number
                numerical_equals=$next_corpse_spawn_turn
            [/variable]

            [have_unit]
                id=Lich-Lord Jevyan
            [/have_unit]
        [/filter_condition]

        [fire_event]
            name=spawn corpses
        [/fire_event]

        {CLEAR_VARIABLE next_corpse_spawn_turn}
    [/event]

    # This triggers on turns 6,16,26,36,... and sets the next skeleton spawn turn
    # to be one of the next 4 turns, like this:
    # 1 2 3 4 5 6 (7 8 9 10) 11 12 13 14 15 16 (17 18 19 20) 21...
    [event]
        name=turn 6,turn 16,turn 26,turn 36
        first_time_only=no

        {VARIABLE_OP next_skeleton_spawn_turn rand "$($turn_number + 1)..$($turn_number + 4)"}
        #{DEBUG_MSG "setting next skeleton spawn to trigger on turn $next_skeleton_spawn_turn"}
    [/event]

    # This triggers the skeleton spawn on the turn determined by the above event.
    [event]
        name=new turn
        first_time_only=no

        [filter_condition]
            [variable]
                name=turn_number
                numerical_equals=$next_skeleton_spawn_turn
            [/variable]

            [have_unit]
                id=Lich-Lord Jevyan
            [/have_unit]
        [/filter_condition]

        [fire_event]
            name=spawn skeletons
        [/fire_event]

        {CLEAR_VARIABLE next_skeleton_spawn_turn}
    [/event]

    [event]
        name=victory

        [message]
            speaker=Lady Jessene
            message= _ "We did it! We won!"
        [/message]
        [message]
            speaker=Prince Haldric
            message= _ "Jevyan is destroyed, but at a terrible price. Let’s put Commander Aethyr to rest and discuss what is to come in the following days."
        [/message]
    [/event]

    [event]
        name=time over
        [message]
            speaker=Prince Haldric
            message= _ "Our strength is waning, and our foes grow stronger by the hour. The battle is lost!"
            image=portraits/haldric-surprised.png
        [/message]
    [/event]
[/scenario]

#undef JEVGOLD
