#textdomain wesnoth-sof
[scenario]
    name= _ "Caverns of Flame"
    id=9_Caverns_of_Flame
    map_file=9_Caverns_of_Flame.map
    next_scenario=Epilogue
    turns=unlimited
    victory_when_enemies_defeated=no

    {SCENARIO_MUSIC "the_dangerous_symphony.ogg"}
    {EXTRA_SCENARIO_MUSIC "heroes_rite.ogg"}

    #    {UNDERGROUND}
    [time]
        id=underground_SoF_volcano
        name= _ "Underground"
        image=misc/time-schedules/schedule-underground.png~CS(40,-40,-80)
        lawful_bonus=-25
        red=-5
        green=-30
        blue=-65
    [/time]

    [side]
        type=Dwarvish Fighter
        id=Rugnur
        side=1
        canrecruit=yes
        recruit=
        controller=human
        shroud=yes
        {GOLD 180 160 140}
        {QUANTITY recall_cost 1 5 10}
        {INCOME 8 7 6}
        team_name=dwarves
        user_team_name= _ "Dwarves"
        {FLAG_VARIANT knalgan}
    [/side]

    [side]
        no_leader=yes
        side=2
        team_name=elves
        user_team_name= _ "Elves"
        {GOLD 120 140 160}
        {INCOME 4 6 8} # don't want them to be too strong, else it becomes AI vs AI slog
        [ai]
            [goal]
                name=target
                [criteria]
                    side=1
                [/criteria]
                value=5
            [/goal]
            [goal]
                name=target
                [criteria]
                    side=3,4,5
                [/criteria]
                value=0.5
            [/goal]
            grouping=no
            aggression=1.0
        [/ai]
        {FLAG_VARIANT wood-elvish}
    [/side]

    # work-around until better AI control is found
    # Moving this guy to side 4 and adding [micro_ai] type simple_attack works,
    # but there were some difficult to reproduce instances where AI didn't behave as expected
    # and Gathor retreated and got out of reach. It might be worth revisiting in the future.
    # further comment at prestart event
    # the Lua goal is to make sure the guy doesn't hang back
    [side]
        side=3
        no_leader=yes
        hidden=yes
        team_name=orcs
        user_team_name= _ "Orcs"
        color=purple
        [ai]
            [goal]
                name=target
                [criteria]
                    side=1
                [/criteria]
                value=10
            [/goal]
            [goal]
                name=target
                [criteria]
                    side=2,6
                [/criteria]
                value=1
            [/goal]
            [goal]
                name=lua_goal
                engine=lua
                code = <<
                    local turn = wesnoth.current.turn
                    local targets = {}
                    targets[1] = { value = 2, type = 'explicit', loc = { x = 29, y = 7 } }
                    targets[2] = { value = turn * 2 , type = 'explicit', loc = { x = 19, y = 17 } }
                    return targets
                >>
            [/goal]
            grouping=no
            aggression=1.0
            caution=0.0
            simple_targeting=yes
            support_villages=no
            village_value=0
        [/ai]
        [unit]
            id=Gathor
            name= _ "Bar'Gathor"
            type=Orcish Warrior
            profile=portraits/orcs/grunt-3.webp
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_STRONG}
                [object]
                    [effect]
                        apply_to=overlay
                        add="misc/loyal-icon.png~GS()"
                    [/effect]
                [/object]
            [/modifications]
            x,y=41,3
        [/unit]
    [/side]

    [side]
        type=Orcish Warlord
        side=4
        canrecruit=yes
        recruit=Orcish Grunt,Orcish Assassin,Orcish Warrior,Orcish Crossbowman
        {GOLD 120 160 200}
        {INCOME 20 25 30}
        [ai]
            [goal]
                name=target
                [criteria]
                    side=1
                [/criteria]
                value=10
            [/goal]
            [goal]
                name=target
                [criteria]
                    side=2
                [/criteria]
                value=2
            [/goal]
            [goal]
                name=target
                [criteria]
                    side=3
                [/criteria]
                value=0.5
            [/goal]
            [aspect]
                id=recruitment_instructions
                [facet]
                    [value]
                        [limit]
                            type=Orcish Grunt
                            max=2
                        [/limit]
                        [limit]
                            type=Orcish Assassin
                            max=2
                        [/limit]
                        [recruit]
                            importance=0
                        [/recruit]
                    [/value]
                [/facet]
            [/aspect]
        [/ai]
        team_name=orcs
        user_team_name= _ "Orcs"
        [village]
            x,y=32,1
        [/village]
        [village]
            x,y=38,7
        [/village]
        [village]
            x,y=40,1
        [/village]
        [village]
            x,y=42,1
        [/village]
        {FLAG_VARIANT6 ragged}
    [/side]

    [side]
        type=Troll Warrior
        id=Harohk
        name= _ "Harohk"
        side=5
        canrecruit=yes
        recruit=Troll Rocklobber,Troll
        {GOLD 120 160 200}
        {INCOME 6 8 10}
        [ai]
            recruitment_pattern=fighter,fighter,mixed fighter
            [goal]
                name=target
                [criteria]
                    side=1
                [/criteria]
                value=10
            [/goal]
            [goal]
                name=target
                [criteria]
                    side=2
                [/criteria]
                value=1
            [/goal]
            [goal]
                name=target
                [criteria]
                    side=3
                [/criteria]
                value=0.1
            [/goal]
        [/ai]
        team_name=trolls
        user_team_name= _ "Trolls"
        [unit]
            id=Toomak
            name= _ "Toomak"
            type=Troll Hero
            profile=portraits/trolls/troll-hero.webp
            ai_special=guardian
            [modifications]
                [object]
                    [effect]
                        apply_to=overlay
                        add="misc/loyal-icon.png~GS()"
                    [/effect]
                [/object]
            [/modifications]
            x,y=39,22
        [/unit]
    [/side]

    [side]
        no_leader=yes
        side=6
        team_name=wyrms
        user_team_name= _ "Wyrms of Khrakrahs"
        color=green
        [ai]
            [goal]
                name=target
                [criteria]
                    side=1
                [/criteria]
                value=5
            [/goal]
            [goal]
                name=target
                [criteria]
                    side=2,4,5
                [/criteria]
                value=0.5
            [/goal]
            grouping=no
            aggression=0.9
        [/ai]
        [unit]
            type=Cave Wyrmlet
            x,y=9,2
        [/unit]
        [unit]
            type=Red Wyrmlet
            x,y=7,3
        [/unit]
        [unit]
            type=Cave Wyrmlet
            x,y=9,4
        [/unit]
        [unit]
            type=Cave Wyrmlet
            x,y=5,8
        [/unit]
        [unit]
            type=Cave Wyrm
            x,y=2,9
        [/unit]
    [/side]
    [event]
        name=new turn
        first_time_only=no
        [set_variable]
            name=turn_TEMP
            value=$turn_number
        [/set_variable]
        [set_variable]
            name=turn_TEMP
            modulo=3
        [/set_variable]
        [if]
            [variable]
                name=turn_TEMP
                equals=0
            [/variable]
            [then]
                [unit]
                    side=6
                    type=Red Wyrmlet
                    x,y=1,8
                [/unit]
                [unit]
                    side=6
                    type=Red Wyrm
                    x,y=4,1
                [/unit]
            [/then]
            [else]
                [unit]
                    side=6
                    type=Cave Wyrmlet
                    x,y=1,8
                [/unit]
                [unit]
                    side=6
                    type=Cave Wyrm
                    x,y=4,1
                [/unit]
            [/else]
        [/if]
        {CLEAR_VARIABLE turn_TEMP}
    [/event]

    [story]
        [part]
            story= _ "Rugnur and the dwarves fled down the cave path, deeper into the volcano, with the elves and mercenaries close behind. Unfortunately, they began to see litter and wall markings indicating they were plunging into the land of orcs and trolls."
        [/part]
        [part]
            story= _ "The situation looked grim, but the dwarves had faced long odds before. Upon entering a large cavern, lit by pervasive lava pools, Rugnur rallied all his forces for a final push."
        [/part]
    [/story]

    {SOF_TRACK {JOURNEY_09_NEW} }

    {SOF_DEATHS}

    {SOF_RUNIC_EVENTS}

    [event]
        name=prestart

        # micro AI to make sure the orc stays on the front lines
        # need high CA score to keep him from retreating when injured
        # this does not work reliably (1.15.2+dev),
        # so moving Gathor to his own side=3 for now
        # [micro_ai]
        #    side=4
        #    ai_type=simple_attack
        #    action=add
        #    ca_score=300000
        #    [filter]
        #        id=Gathor
        #    [/filter]
        # [/micro_ai]
        # to delay the trolls
        [set_variable]
            name=gathor_tablet
            value=whole
        [/set_variable]
        [store_unit]
            [filter]
                id=Harohk
            [/filter]
            variable=harohk
            kill=yes
        [/store_unit]
        #the glyphs - three pairs
        [item]
            x,y=27,20
            image=scenery/rock-cairn.png
        [/item]
        # set 1
        [item]
            x,y=26,19
            image=scenery/monolith4.png
        [/item]
        [item]
            x,y=28,20
            image=scenery/monolith1.png
        [/item]
        [set_variable]
            name=orcs_dead
            value=0
        [/set_variable]
        [event]
            name=die
            first_time_only=no
            id=tablet_count
            [filter]
                side=3,4
            [/filter]
            [set_variable]
                name=orcs_dead
                add=1
            [/set_variable]
            [if]
                [variable]
                    name=orcs_dead
#ifdef EASY
                    equals=5
#endif
#ifdef NORMAL
                    equals=8
#endif
#ifdef HARD
                    equals=12
#endif
                [/variable]
                [then]
                    [fire_event]
                        name=gathor_fit
                    [/fire_event]
                [/then]
            [/if]
        [/event]
        [event]
            name=attacker_hits
            id=tablet_hit
            [filter_second]
                id=Gathor
            [/filter_second]
            [fire_event]
                name=gathor_fit
            [/fire_event]
        [/event]
        [event]
            name=last_breath
            id=tablet_last_breath
            [filter]
                id=Gathor
            [/filter]
            [fire_event]
                name=gathor_fit
            [/fire_event]
        [/event]
        [event]
            name=gathor_fit
            [message]
                speaker=Gathor
                message= _ "Argh, this is not good! But I’ve still got a trick up my sleeve..."
            [/message]
            [message]
                speaker=narrator
                message= _ "The angry orc pulled out a stone tile with a glowing rune stamped on one side, and waved it at his foes."
                image=wesnoth-icon.png
            [/message]
            [message]
                speaker=Gathor
                message= _ "Nothing!? Even this magical piece of troll dung lets me down!"
            [/message]
            [message]
                speaker=narrator
                message= _ "The frustrated orc flung the tile against the wall, where it shattered."
                image=wesnoth-icon.png
            [/message]
            [set_variable]
                name=gathor_tablet
                value=broken
            [/set_variable]
            {QUAKE "rumble.ogg"}
            [scroll_to]
                x,y=27,20
            [/scroll_to]
            [remove_item]
                x,y=28,20
            [/remove_item]
            [remove_item]
                x,y=26,19
            [/remove_item]
            [terrain]
                x=24,30
                y=18,21
                terrain=Ql
            [/terrain]
            [terrain]
                x=25,29
                y=19-20,21-20
                terrain=Uh
            [/terrain]
            [terrain]
                x=26,28
                y=19,20
                terrain=Isa
            [/terrain]
            [remove_shroud]
                side=1
                x,y=21-33,16-24
            [/remove_shroud]
            [redraw]
                side=1
            [/redraw]
            [kill]
                [and]
                    x=24,30
                    y=18,21
                    [not]
                        race=gryphon
                    [/not]
                [/and]
                animate=yes
                fire_event=yes
            [/kill]
            [delay]
                time=300
            [/delay]
            [objectives]
                side=1
                [objective]
                    description= _ "Find and destroy the remaining runic tablets"
                    condition=win
                [/objective]
                [objective]
                    description= _ "Death of Rugnur"
                    condition=lose
                [/objective]
                [objective]
                    description= _ "Death of Krawg"
                    condition=lose
                [/objective]
                [objective]
                    description= _ "Death of Thursagan"
                    condition=lose
                [/objective]

                {IS_LAST_SCENARIO}
            [/objectives]
            [remove_event]
                id=tablet_last_breath
            [/remove_event]
            [remove_event]
                id=tablet_hit
            [/remove_event]
            [remove_event]
                id=tablet_count
            [/remove_event]
        [/event]
        # set 2
        [item]
            x,y=28,19
            image=scenery/monolith4.png
        [/item]
        [item]
            x,y=26,20
            image=scenery/monolith1.png
        [/item]
        [event]
            name=last breath
            [filter]
                id=Toomak
            [/filter]
            [message]
                speaker=unit
                message= _ "All these years we stood guard... to protect these tunnels... and it comes to this..."
            [/message]
        [/event]
        [event]
            name=die
            [filter]
                id=Toomak
            [/filter]
            [message]
                speaker=narrator
                message= _ "As the troll collapsed, a stone tile it had been wearing hit the floor and shattered."
                image=wesnoth-icon.png
            [/message]
            {QUAKE "rumble.ogg"}
            [scroll_to]
                x,y=27,20
            [/scroll_to]
            [remove_item]
                x,y=26,20
            [/remove_item]
            [remove_item]
                x,y=28,19
            [/remove_item]
            [terrain]
                x=24,30
                y=21,18
                terrain=Ql
            [/terrain]
            [terrain]
                x=25-26,28,29
                y=21,18,19
                terrain=Uh
            [/terrain]
            [terrain]
                x=26,28
                y=20,19
                terrain=Isa
            [/terrain]
            [remove_shroud]
                side=1
                x,y=21-33,16-24
            [/remove_shroud]
            [redraw]
                side=1
            [/redraw]
            [kill]
                [and]
                    x=24,30
                    y=21,18
                    [not]
                        race=gryphon
                    [/not]
                [/and]
                animate=yes
                fire_event=yes
            [/kill]
            [delay]
                time=300
            [/delay]
            [objectives]
                side=1
                [objective]
                    description= _ "Find and destroy the remaining runic tablets"
                    condition=win
                [/objective]
                [objective]
                    description= _ "Death of Rugnur"
                    condition=lose
                [/objective]
                [objective]
                    description= _ "Death of Krawg"
                    condition=lose
                [/objective]
                [objective]
                    description= _ "Death of Thursagan"
                    condition=lose
                [/objective]

                {IS_LAST_SCENARIO}
            [/objectives]
        [/event]
        # set 3
        # this contains the end-level event
        [item]
            x,y=27,19
            image=scenery/monolith1.png
        [/item]
        [item]
            x,y=27,21
            image=scenery/monolith4.png
        [/item]
        [item]
            x,y=29,31
            image=items/stone-tablet.png
        [/item]
        [event]
            name=moveto
            [filter]
                x,y=29,31
            [/filter]
            [filter_condition]
                [variable]
                    name=gathor_tablet
                    equals=whole
                [/variable]
                [or]
                    [have_unit]
                        id=Toomak
                    [/have_unit]
                [/or]
            [/filter_condition]
            [if]
                # Only flying units can reach this location and the only flying units the player should have access to besides Krawg is the Gryphon Rider line
                [variable]
                    name=unit.id
                    equals=Krawg
                [/variable]
                [then]
                    [message]
                        #wmllint: recognize Krawg
                        speaker=Krawg
                        message= _ "Wha’?"
                    [/message]
                    [message]
                        speaker=narrator
                        message= _ "Krawg puzzled over a stone tile sitting loose on the small mesa. Beneath a spattering of bat guano, there was a glowing rune. Krawg didn’t know what to make of it, so the gryphon left it for now."
                        image=wesnoth-icon.png
                    [/message]
                [/then]
                [else]
                    [message]
                        speaker=$unit.id
                        message= _ "The gryphon rider puzzled over a stone tile sitting loose on the small mesa. Beneath a spattering of bat guano, there was a glowing rune. Neither mount nor rider knew what to make of it, so they left it for now."
                    [/message]
                [/else]
            [/if]
        [/event]
        [event]
            name=moveto
            [filter]
                x,y=29,31
            [/filter]
            [filter_condition]
                [not]
                    [variable]
                        name=gathor_tablet
                        equals=whole
                    [/variable]
                    [or]
                        [have_unit]
                            id=Toomak
                        [/have_unit]
                    [/or]
                [/not]
            [/filter_condition]
            [if]
                [variable]
                    name=unit.id
                    equals=Krawg
                [/variable]
                [then]
                    [message]
                        speaker=Krawg
                        message= _ "Screech!"
                    [/message]
                [/then]
            [/if]
            [if]
                [variable]
                    name=unit.id
                    equals=Krawg
                [/variable]
                [then]
                    [message]
                        speaker=narrator
                        message= _ "Krawg saw that this tablet was like the others held by the orc and troll, and knew that this could remove the last bridge across the fire lake."
                        image=wesnoth-icon.png
                    [/message]
                    [message]
                        #wmllint: recognize Thursagan
                        speaker=Thursagan
                        message= _ "Yes, Krawg, that must be the last rune sealing the volcano. Smash it, like the others!"
                    [/message]
                    [message]
                        speaker=Krawg
                        message= _ "Krawg sad."
                    [/message]
                    [message]
                        speaker=Thursagan
                        message= _ "Just do it, you dumb bird! You can escape, our enemies cannot. We knew that death was likely when we fled here, just go!"
                    [/message]
                    [message]
                        speaker=Rugnur
                        message= _ "Wait! If Krawg can escape, shouldn’t we give him the Sceptre?"
                    [/message]
                    [message]
                        speaker=Thursagan
                        message= _ "No, too risky, even if Krawg drops it in King Haldric’s hand. You’ve seen how the elves have behaved, you’ve seen how your lord behaved. The corrupting emissions from the ruby are nothing compared to the greed already out there, and my crafted gold cage does nothing to contain that."
                    [/message]
                    [message]
                        speaker=Thursagan
                        message= _ "Durstorn and Glildur have both convinced me that the time is not right for the Sceptre of Fire, best that it rests with us for a while. Now, Krawg!"
                    [/message]
                    [message]
                        speaker=Krawg
                        message= _ "Yah! Krah!"
                    [/message]
                [/then]
                [else]
                    [message]
                        speaker=$unit.id
                        message= _ "There’s a tablet with a rune here!"
                    [/message]
                    [message]
                        speaker=Thursagan
                        message= _ "Yes, that must be the last rune sealing the volcano. Smash it, like the others!"
                    [/message]
                    [message]
                        speaker=$unit.id
                        message= _ "The resulting eruption will lead to all of your deaths!"
                    [/message]
                    [message]
                        speaker=Thursagan
                        message= _ "Just do it! You riders have a chance to escape, our enemies cannot. We knew that death was likely when we fled here, just go!"
                    [/message]
                    [message]
                        speaker=Rugnur
                        message= _ "Wait! If the riders can escape, shouldn’t we give them the Sceptre?"
                    [/message]
                    [message]
                        speaker=Thursagan
                        message= _ "No, too risky, even if they drop it in King Haldric’s hand. You’ve seen how the elves have behaved, you’ve seen how your lord behaved. The corrupting emissions from the ruby are nothing compared to the greed already out there, and my crafted gold cage does nothing to contain that."
                    [/message]
                    [message]
                        speaker=Thursagan
                        # po: "smash it" refers to a stone tablet, not the Sceptre.
                        message= _ "Durstorn and Glildur have both convinced me that the time is not right for the Sceptre of Fire, best that it rests with us for a while. Now, smash it!"
                    [/message]
                    [message]
                        speaker=$unit.id
                        message= _ "Alright, there’s no turning back now!"
                    [/message]
                [/else]
            [/if]
            [remove_item]
                x,y=29,31
                image=items/stone-tablet.png
            [/remove_item]
            [floating_text]
                x,y=29,31
                text="<span color='#ff7722'>" +
                    # po: Treat this as if it was a sound-effect in a comic book.
                    _ "Smash!" + "</span>"
            [/floating_text]
            {QUAKE "rumble.ogg"}
            [scroll_to]
                x,y=27,20
            [/scroll_to]
            [remove_item]
                x,y=27,19
            [/remove_item]
            [remove_item]
                x,y=27,21
            [/remove_item]
            [terrain]
                x=27,27
                y=17,23
                terrain=Ql
            [/terrain]
            [terrain]
                x=26-27,27,28
                y=18,22,21
                terrain=Uh
            [/terrain]
            [terrain]
                x=27,27
                y=19,21
                terrain=Isa
            [/terrain]
            [redraw]
                side=1
            [/redraw]
            # Need to check if the player had Gryphon Riders or Gryphon Masters and store it in a variable because they will be killed
            [if]
                [have_unit]
                    type=Gryphon Rider, Gryphon Master
                [/have_unit]
                [then]
                    [set_variable]
                        name=gryphonrider_flag
                        value=yes
                    [/set_variable]
                [/then]
                [else]
                    [set_variable]
                        name=gryphonrider_flag
                        value=no
                    [/set_variable]
                [/else]
            [/if]
            [kill]
                [and]
                    x=27,27
                    y=17,23
                    [not]
                        race=gryphon
                    [/not]
                [/and]
                animate=yes
                fire_event=yes
            [/kill]
            [delay]
                time=300
            [/delay]
            {MOVE_UNIT (id=Krawg) 22 33}
            [store_unit]
                [filter]
                    id=Krawg
                [/filter]
                variable=krawg
                kill=yes
            [/store_unit]
            {QUAKE "rumble.ogg"}
            [scroll_to]
                x,y=27,20
            [/scroll_to]
            [remove_item]
                x,y=27,20
            [/remove_item]
            [terrain]
                x=26-28,26-28,27
                y=19,20,21
                terrain=Qxu
            [/terrain]
            [kill]
                [and]
                    x=26-28,26-28,27
                    y=19,20,21
                [/and]
                animate=no
            [/kill]
            [redraw]
                side=1
            [/redraw]
            [delay]
                time=300
            [/delay]
            [terrain]
                [and]
                    x=22-32
                    y=16-24
                    terrain=Ql
                [/and]
                terrain=Qlf
            [/terrain]
            [terrain]
                x=26-28,26-28,27
                y=19,20,21
                terrain=Ql
            [/terrain]
            [redraw]
                side=1
            [/redraw]
            [delay]
                time=300
            [/delay]
            [terrain]
                [and]
                    terrain=Ql*
                    radius=2
                [/and]
                [not]
                    terrain=Xu*
                [/not]
                terrain=Qlf
            [/terrain]
            [redraw]
                side=1
            [/redraw]
            # fade to red then fade out
            [screen_fade]
                red,green,blue=255,0,0
                alpha=200
                duration=600
            [/screen_fade]
            {SCREEN_FADE_OUT}
            # Check if the player had a Gryphon Rider or Gryphon Master before all units were killed.
            [if]
                [variable]
                    name=gryphonrider_flag
                    boolean_equals=yes
                [/variable]
                [then]
                    [message]
                        speaker=narrator
                        # po: Krawg survives in both variants of this paragraph, but this one has an extra sentence to explain the gryhon riders’ fate. Surrounding events imply that flying units can escape, but the plot requires all dwarves to die.
                        message= _ "Once the magic seal capping the throat of the volcano was removed, lava and toxic gas exploded upward, killing everyone inside and sealing them in a tomb of hot, flowing rock. Krawg and the gryphon riders flew towards a hole in the roof but it was only Krawg who managed to outrun the explosion and emerge as the sole survivor. The Sceptre of Fire would wait, unharmed by the lava, until some day far in the future."
                        image=wesnoth-icon.png
                    [/message]
                [/then]
                [else]
                    [message]
                        speaker=narrator
                        # po: Krawg survives in both variants of this paragraph, this one is shown if the player didn’t have any gryphon riders. Surrounding events imply that flying units can escape, and in this variant Krawg is the only flying unit.
                        message= _ "Once the magic seal capping the throat of the volcano was removed, lava and toxic gas exploded upward, killing everyone inside and sealing them in a tomb of hot, flowing rock. The Sceptre of Fire would wait, unharmed by the lava, until some day far in the future."
                        image=wesnoth-icon.png
                    [/message]
                [/else]
            [/if]
            [endlevel]
                result=victory
                carryover_report=no
                save=no
                linger_mode=no
            [/endlevel]
        [/event]
        [recall]
            id=Thursagan
        [/recall]
        [recall]
            id=Baglur
        [/recall]
        [recall]
            id=Krawg
        [/recall]
        [recall]
            side=1
        [/recall]
        [recall]
            side=1
        [/recall]
        [recall]
            side=1
        [/recall]
        # original version of this scenario recalled everyone at the start, but that makes this a slog.
        # instead, recall cost is reduced, and there are lots of little keeps scattered on the map.
#ifdef __UNUSED__
        [store_unit]
            [filter]
                side=1
                x,y=recall,recall
            [/filter]

            kill=no
            variable=to_be_recalled
        [/store_unit]

        [foreach]
            array=to_be_recalled
            [do]
                [recall]
                    id=$this_item.id
                [/recall]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE to_be_recalled}
#endif
        # items hinting at volcano history
        [item]
            x,y=43,26
            image=items/chest-plain-open.png
        [/item]
        [item]
            x,y=44,25
            image=items/chest-plain-open.png
        [/item]
        [item]
            x,y=44,26
            image=items/chest-plain-open.png
        [/item]
        [event]
            name=moveto
            [filter]
                side=1
                race=dwarf
                x=43,44,44
                y=26,25,26
            [/filter]
            [message]
                speaker=unit
                message= _ "These chests have been forced open. Whatever they once held has been removed."
            [/message]
        [/event]
        [item]
            x,y=44,28
            image=items/barrel.png
        [/item]
        [item]
            x,y=41,29
            image=items/bones.png
        [/item]
        [item]
            x,y=42,30
            image=items/book1.png
        [/item]
        [event]
            name=moveto
            [filter]
                side=1
                race=dwarf
                [filter_location]
                    terrain=Isa*
                [/filter_location]
            [/filter]
            [message]
                speaker=unit
                message= _ "Ah! We aren’t wandering the bowels o’ the earth, this is crafted stone! It’s very old though..."
            [/message]
        [/event]
        [event]
            name=moveto
            [filter]
                side=1
                race=dwarf
                x,y=42,30
            [/filter]
            [message]
                speaker=unit
                message= _ "This is some sort of notebook... I can’t read the text, but there are drawings showing three arcs spanning what must be the volcano. There are three symbols for these arcs... well, it must describe the volcano somehow, but I can’t puzzle it out now."
            [/message]
        [/event]
        [item]
            x,y=37,22
            image=items/burial.png
        [/item]
        [objectives]
            side=1
            [objective]
                description= _ "Explore as much of the cave as possible"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Rugnur"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Krawg"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Thursagan"
                condition=lose
            [/objective]

            {RUNE_MECHANIC_NOTE}

            {IS_LAST_SCENARIO}
        [/objectives]
    [/event]

    [event]
        name=start

        [unit]
            x,y=27,9
            side=5
            type=Troll
            ai_special=guardian
            role=Guardian
            name= _ "Guardian"
        [/unit]
        [unit]
            x,y=22,22
            side=5
            type=Troll Shaman
            ai_special=guardian
            role=Guardian
            name= _ "Guardian"
        [/unit]
        [unit]
            x,y=27,15
            side=5
            type=Troll Shaman
            ai_special=guardian
            role=Guardian
            name= _ "Guardian"
        [/unit]
        [unit]
            x,y=32,22
            side=5
            type=Troll Shaman
            ai_special=guardian
            role=Guardian
            name= _ "Guardian"
        [/unit]
        #messages
        [message]
            speaker=Rugnur
            message= _ "Well, we’ve put some distance between us and the elves, so we have a little time to think. What is this place?"
        [/message]
        [message]
            speaker=Thursagan
            # wmllint: local spelling Khrakrahs
            message= _ "Remember what Khrakrahs said, about this being a volcano? Well, it seems we’re under the crater, sitting on the magma chamber... I think we should try to cause it to erupt."
        [/message]
        [message]
            speaker=Rugnur
            message= _ "Huh, makes sense. It will kill all the elves, and we might be able to find a safe place so the lava doesn’t kill us."
        [/message]
        [message]
            speaker=Baglur
            message= _ "Yes, an interesting plan. How do you propose we do this?"
        [/message]
        [message]
            speaker=Thursagan
            message= _ "Look up! If this were a normal volcano, you’d see stars and sky. Instead, there’s a high ceiling, shaped like a cone. This means that something must be holding back the volcano’s lava flow. This thing, if it exists, could be our chance to trigger an eruption. The first place I would consider investigating would be the center of this chamber."
        [/message]
        [message]
            speaker=Rugnur
            message= _ "I see, yes. Quite a gamble, yet what choice do we have? Let’s explore and hope we find something like what you describe."
        [/message]
        [message]
            speaker=Krawg
            message= _ "Krah!
<i>(Looks about the cave, adopts a hostile stance, then glances back at the dwarves.)</i>"
        [/message]
        [message]
            speaker=Thursagan
            message= _ "Indeed, Krawg, we are not alone down here. Orcs and trolls are prowling around."
        [/message]
    [/event]

#define RANDOM_MERCENARY_2 TYPE
    {GENERIC_UNIT 2 {TYPE} 23 1}
#enddef

    [event]
        name=moveto
        [filter]
            id=Rugnur
            [filter_location]
                terrain=K*
            [/filter_location]
        [/filter]
        [message]
            speaker=Rugnur
            message= _ "Friends, brothers, this is a desperate situation, I need your help. Can we negotiate pay after we’re back to safety?"
        [/message]
        [message]
            speaker=narrator
            image=icons/coins_copper.png~XBRZ(4)
            message= _ "Recall costs are reduced for the duration of the scenario."
        [/message]
    [/event]

    #elves come (and orcs fix their bridge)
    [event]
        name=turn 6
        [move_unit_fake]
            type=Elvish Marshal
            side=2
            x=23,23
            y=1,3
        [/move_unit_fake]
        [unit]
            type=Elvish Marshal
            side=2
            id=Glildur
            name= _ "Glildur"
            canrecruit=yes
            x,y=23,3
            {SOF_GLILDUR_PORTRAIT}
            facing=sw
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_INTELLIGENT}
                [object]
                    silent=yes
                    [effect]
                        apply_to=image_mod
                        add=CS(-10,-25,+5)
                    [/effect]
                [/object]
            [/modifications]
            extra_recruit=Elvish Hero, Elvish Ranger
        [/unit]
        [message]
            speaker=Glildur
            message= _ "End of the road, little dwarves! That ruby is as good as ours..."
        [/message]
        {RANDOM_MERCENARY_2 "Dwarvish Lord"}
        {RANDOM_MERCENARY_2 "Dwarvish Lord"}
        {RANDOM_MERCENARY_2 "Dwarvish Lord"}
        {RANDOM_MERCENARY_2 "Dwarvish Lord"}
#ifdef HARD
        {RANDOM_MERCENARY_2 "Dwarvish Lord"}
#endif
        {RANDOM_MERCENARY_2 "Dwarvish Dragonguard"}
        {RANDOM_MERCENARY_2 "Dwarvish Dragonguard"}
        {RANDOM_MERCENARY_2 "Dwarvish Dragonguard"}
        {RANDOM_MERCENARY_2 "Dwarvish Dragonguard"}
#ifdef HARD
        {RANDOM_MERCENARY_2 "Dwarvish Dragonguard"}
#endif
        {RANDOM_MERCENARY_2 "Elvish Champion"}
        {RANDOM_MERCENARY_2 "Elvish Champion"}
        {RANDOM_MERCENARY_2 "Elvish Champion"}
        {RANDOM_MERCENARY_2 "Elvish Champion"}
#ifdef HARD
        {RANDOM_MERCENARY_2 "Elvish Champion"}
#endif
        {RANDOM_MERCENARY_2 "Elvish Avenger"}
        {RANDOM_MERCENARY_2 "Elvish Avenger"}
        {RANDOM_MERCENARY_2 "Elvish Avenger"}
        {RANDOM_MERCENARY_2 "Elvish Avenger"}
#ifdef HARD
        {RANDOM_MERCENARY_2 "Elvish Avenger"}
#endif
        {RANDOM_MERCENARY_2 "Elvish Outrider"}
        {RANDOM_MERCENARY_2 "Elvish Outrider"}
        {RANDOM_MERCENARY_2 "Elvish Outrider"}
        {RANDOM_MERCENARY_2 "Elvish Outrider"}
#ifdef HARD
        {RANDOM_MERCENARY_2 "Elvish Outrider"}
#endif
        [message]
            speaker=Rugnur
            message= _ "Thursagan! The elves are right on our tail! What should we do?"
        [/message]
        [message]
            speaker=Thursagan
            message= _ "We should try to set off the volcano as soon as possible. Draw the elves further into the caves, so they can’t escape when it does erupt."
        [/message]
        [terrain]
            terrain=Qxu^Bp/
            x=34,34,35
            y=4,5,6
        [/terrain]
        [unstore_unit]
            variable=harohk
            find_vacant=no
        [/unstore_unit]
        {CLEAR_VARIABLE harohk}
    [/event]

    [event]
        name=last_breath
        [filter]
            id=Glildur
        [/filter]
        [message]
            speaker=Glildur
            message= _ "Damnation! I almost had it... but now I join Landar..."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            race=dwarf
            x=22-31
            y=17-23
        [/filter]
        [message]
            speaker=unit
            message= _ "This must be the center of the volcano! The lava is blocked just as you surmised, Thursagan! It’s plugged up with this... enchanted courtyard?"
        [/message]
        [message]
            speaker=Thursagan
            message= _ "Aye, it is enchanted; I can tell by those runes. We need to break the enchantment somehow."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            race=dwarf
            x=24,24,27,27,30,30
            y=18,21,17,23,18,21
        [/filter]
        [message]
            speaker=unit
            message= _ "It’s very hot here, above the lava. This bridge also seems rather delicate — I’d better not loiter here."
        [/message]
    [/event]

    [event]
        name=attack_end
        [filter]
            side=1
            [or]
                type=Troll Shaman
            [/or]
        [/filter]
        [filter_second]
            side=1
            [or]
                type=Troll Shaman
            [/or]
        [/filter_second]
        [message]
            speaker=Rugnur
            message= _ "These trolls are not like others I’ve seen, and they seem to be guarding this chamber."
        [/message]
        [message]
            [and]
                type=Troll Shaman
                [and]
                    id=$unit.id
                    [or]
                        id=$second_unit.id
                    [/or]
                [/and]
            [/and]
            message= _ "Yes, we tend and preserve this volcano, protecting it from those like you."
        [/message]
        [message]
            speaker=Rugnur
            message= _ "Us? We’re nice, not like the elves chasing us."
        [/message]
        [message]
            speaker=Baglur
            message= _ "Aye, but it’s no use, Rugnur. There’s no peace between dwarves and trolls, never has been."
        [/message]
    [/event]

    #when the elves lose troops, the orcs gain them
    [event]
        name=die
        first_time_only=no
        [filter]
            side=2
        [/filter]
        [gold]
            side=4
            amount=50
        [/gold]
        [gold]
            side=5
            amount=50
        [/gold]
    [/event]

    # the orcs are held back
    [event]
        name=enter_hex
        [filter]
            side=1
            x,y=30-32,3-8
        [/filter]
        [filter_condition]
            [variable]
                name=turn_number
                less_than=6
            [/variable]
        [/filter_condition]
        {MOVE_UNIT (id=Gathor) 36 5}
        [remove_shroud]
            side=1
            x,y=32-43,3-9
        [/remove_shroud]
        [redraw]
            side=1
        [/redraw]
        [message]
            speaker=Gathor
            message= _ "Ah ha! I knew it, there are intruders! And yet our damned bridge is broken, it was built by idiots. Come, come, bring planks, we’ve got to get across!"
        [/message]
        [message]
            speaker=Rugnur
            message= _ "Huh. Well, let’s not stay here too long."
        [/message]
        [message]
            speaker=Thursagan
            message= _ "Right, if we can get both the orcs and the elves behind us, maybe they’ll fight each other."
        [/message]
    [/event]
[/scenario]

#undef RANDOM_MERCENARY_2
