#textdomain wesnoth-dw

# You defeat the lich to try to get the sword, but as soon as the lich
# drops it, Caladon teleports in and picks it up. Now, you need to
# defeat Caladon to get the sword. He grants you time to leave, which
# is actually a turn to remove any very damaged units from the
# vicinity as Caladon is pretty dangerous. You can attack him now, or
# wait a turn for him to get impatient and attack you. When he
# attacks, or you attack him, he summons fire guardians (stolen from
# UtBS). He does not also recruit, because that would just be
# mean. (There is no reason he would have much gold anyway.)

[scenario]
    name= _ "The Flaming Sword"
    map_data="{campaigns/Dead_Water/maps/The_Flaming_Sword.map}"

    id=10_The_Flaming_Sword
    next_scenario=11_Getting_Help

    [story]
        [part]
            story= _ "Caladon led them just a little way up the shore. Despite its name, the swamp was not actually desolate on the outskirts. A hardy population of humans coaxed a living out of the damp soil."
        [/part]

        [part]
            background=dead-water-map.png
            show_title=yes
            {OLD_BATTLE 746 673}
            {OLD_JOURNEY 729 657}
            {OLD_JOURNEY 734 635}
            {OLD_BATTLE 732 615}
            {OLD_JOURNEY 708 612}
            {OLD_JOURNEY 681 607}
            {OLD_JOURNEY 654 600}
            {OLD_JOURNEY 647 573}
            {OLD_JOURNEY 640 546}
            {OLD_BATTLE 650 522}
            {OLD_JOURNEY 637 497}
            {OLD_JOURNEY 628 473}
            {OLD_JOURNEY 610 454}
            {OLD_JOURNEY 589 437}
            {OLD_JOURNEY 576 412}
            {OLD_JOURNEY 575 388}
            {OLD_JOURNEY 552 381}
            {OLD_BATTLE 542 361}
            {OLD_JOURNEY 523 370}
            {OLD_JOURNEY 501 381}
            {OLD_JOURNEY 477 391}
            {OLD_BATTLE 455 401}
            {OLD_JOURNEY 434 414}
            {OLD_JOURNEY 414 428}
            {OLD_BATTLE 395 446}
            {OLD_JOURNEY 402 471}
            {OLD_JOURNEY 396 495}
            {OLD_JOURNEY 387 518}
            {OLD_JOURNEY 369 537}
            {OLD_JOURNEY 344 548}
            {OLD_JOURNEY 319 542}
            {OLD_JOURNEY 307 523}
            {OLD_REST 306 497}
            {OLD_JOURNEY 286 479}
            {OLD_JOURNEY 265 467}
            {OLD_JOURNEY 266 444}
            {OLD_JOURNEY 279 424}
            {OLD_JOURNEY 301 413}
            {OLD_JOURNEY 321 399}
            {OLD_JOURNEY 339 378}
            {OLD_JOURNEY 354 356}
            {OLD_JOURNEY 368 334}
            {OLD_JOURNEY 384 315}
            {OLD_JOURNEY 395 293}
            {OLD_JOURNEY 375 278}
            {OLD_JOURNEY 357 264}
            {OLD_BATTLE 355 242}
            {NEW_JOURNEY 346 222}
            {NEW_JOURNEY 357 203}
            {NEW_JOURNEY 374 191}
            {NEW_JOURNEY 386 175}
            {NEW_BATTLE 373 160}
        [/part]
    [/story]

    {DEFAULT_SCHEDULE}

    {TURNS4 30 28 28 28}
    victory_when_enemies_defeated=no

    # wmllint: validate-off
    [side]
        # wmllint: recognize Kai Krellis
        {SIDE_1}
        fog=yes
        {GOLD4 120 120 120 120}
    [/side]
    # wmllint: validate-on

    {STARTING_VILLAGES 1 6}

    [side]
        side=2
        controller=ai
        type=Lich
        id=Mal-Govon
        name= _ "Mal-Govon"
        canrecruit=yes
        user_team_name= _ "Mal-Govon"
        team_name=bad guys

        # The first turn, I want the lich to recruit fairly weak
        # scouts to get villages. That way he'll have more gold for
        # strong units on the next turns--units to use to
        # attack. There is an event that gives him all the rest of his
        # recruits on a later turn. If I don't do this, he uses all
        # his money for a few Spectres and has no income left. There
        # aren't enough units to beat the player, even though they are
        # strong ones.
        recruit="Blood Bat, Ghost"
        [ai]
            village_value=5
            recruitment_pattern=scout
            scout_village_targeting=5
        [/ai]

        {FLAG_VARIANT undead}
        {INCOME4 30 35 40 45}
        {GOLD4 500 600 700 800}
    [/side]

    {STARTING_VILLAGES 2 5}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Blood Bat) 4}

    [side]
        side=3
        no_leader=yes
        team_name=good guys
        user_team_name= _ "Villagers"
        # I want Howyrth to stay out of the nearby castle so the
        # player will always be able to use it.
        [ai]
            village_value=0
            [avoid]
                x=21,20
                y=18,17
            [/avoid]
        [/ai]
    [/side]

    [side]
        side=4
        no_leader=yes
        id=Caladon
        name= _ "Caladon"
        team_name=Caladon
        user_team_name= _ "Caladon"
        income=-2
        gold=0
        controller=null
    [/side]

    [event]
        name=turn 2

        [allow_recruit]
            side=2
#ifdef EASY
            type="Blood Bat, Ghost, Wraith, Spectre, Shadow, Bone Shooter, Deathblade, Revenant, Ghoul, Necrophage"
#endif

#ifdef NORMAL
            type="Blood Bat, Dread Bat, Ghost, Wraith, Spectre, Shadow, Bone Shooter, Deathblade, Ghoul, Necrophage, Chocobone"
#endif

#ifdef HARD
            type="Blood Bat, Dread Bat, Ghost, Wraith, Spectre, Shadow, Bone Shooter, Banebow, Deathblade, Ghoul, Necrophage, Chocobone"
#endif

#ifdef NIGHTMARE
            type="Blood Bat, Dread Bat, Ghost, Wraith, Spectre, Shadow, Bone Shooter, Banebow, Deathblade, Ghoul, Necrophage, Chocobone"
#endif
        [/allow_recruit]

        [modify_side]
            side=2
            [ai]
                recruitment_pattern=fighter,fighter,archer,scout,scout,scout # The scouts are to get more ghost variants.
                # Ignoring these two makes for a more interesting variety of enemies:
                recruitment_ignore_bad_combat=yes
                recruitment_ignore_bad_movement=yes
                scout_village_targeting=5
                [protect_location]
                    x,y=36,23
                    radius=8
                    value=200
                [/protect_location]
            [/ai]
        [/modify_side]

#ifdef EASY
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Wraith) 4}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Shadow) 4}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Spectre) 1}
#endif
#ifdef NORMAL
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Dread Bat) 2}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Wraith) 4}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Spectre) 1}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Shadow) 4}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Bone Shooter) 3}
#endif
#ifdef HARD
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Dread Bat) 3}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Wraith) 4}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Spectre) 1}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Shadow) 4}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Bone Shooter) 3}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Banebow) 1}
#endif
#ifdef NIGHTMARE
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Dread Bat) 3}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Wraith) 5}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Spectre) 1}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Shadow) 4}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Bone Shooter) 3}
        {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Banebow) 2}
#endif
    [/event]

    [event]
        name=prestart

        [music]
            name=the_city_falls.ogg
        [/music]

        {RECALL_LOYAL_UNITS}
        # wmllint: recognize Cylanna

        [objectives]
            side=1
            [objective]
                description= _ "Pry the flaming sword from the dead hand of its owner"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Kai Krellis"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Cylanna"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Caladon"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

            [gold_carryover]
                bonus=yes
                carryover_percentage=40
            [/gold_carryover]
        [/objectives]

        [role]
            side=1
            race=merman
            [filter_wml]
                upkeep=full
            [/filter_wml]
            type=Mermaid Siren,Mermaid Diviner,Merman Entangler,Mermaid Enchantress,Mermaid Priestess,Merman Netcaster,Merman Brawler,Mermaid Initiate,Merman Javelineer,Merman Spearman,Merman Hunter,Merman Citizen
            role=spy
        [/role]
        [recall]
            role=spy
        [/recall]
        [store_unit]
            [filter]
                role=spy
            [/filter]
            variable=spy_unit
        [/store_unit]
        [modify_side]
            side=1
            income=$spy_unit.level # Since you have little gold, and maybe didn't plan to recall this unit, it is free. You're welcome.
        [/modify_side]

        {VARIABLE sword_x 999}
        {VARIABLE sword_y 999}

        # This is where the lich starts, so he will pick up this
        # object immediately:
        {FLAMING_SWORD 37 3 flaming-sword1}

        [recall]
            id=Caladon
            x,y=8,27
        [/recall]
    [/event]

    [event]
        name=start
        # The player gets gold more slowly without Siddry and friends, so we'll
        # compensate a little:
        [if]
            [variable]
                name=Siddry_stored
                equals=no
            [/variable]
            [then]
                [gold]
                    amount=20
                    side=1
                [/gold]
            [/then]
        [/if]

        [message]
            speaker=$spy_unit.id
            message= {WHISPER ( _ "(whisper) Kai, I heard Caladon muttering about the sword. I think he may try to take it for himself.")}
        [/message]
        [message]
            speaker=Kai Krellis
            message= {WHISPER ( _ "Thank you, $spy_unit.name|. I will keep that in mind, but it may be hard for us to stop him with that teleporting trick he has.")}
        [/message]

        [clear_variable]
            name=spy_unit
        [/clear_variable]

        [message]
            speaker=Caladon
            message= _ "Here we are. There’s a castle up ahead in the fog. That’s where Agnovon has the sword."
        [/message]
        [message]
            speaker=Kai Krellis
            message= _ "The lich is Agnovon?"
        [/message]
        [message]
            speaker=Caladon
            message= _ "Well, he calls himself Mal-Govon now, but yes. He called this land the KINGDOM of Agnovon. He was its first king. And its last, and every one in between, too! He kept getting older and older, but he never died. Well, NOW he’s dead of course. He still putters around in that castle over there, but he hasn’t really cared about keeping his kingdom under control for a good long while. I bet I can wake him up, though. Watch THIS!"
        [/message]
        [message]
            speaker=narrator
            message= _ "Suddenly, Caladon’s strident voice shrieked out louder than seemed possible, as if there were dozens of men shouting at once."
            image=wesnoth-icon.png
        [/message]
        [message]
            speaker=Caladon
            message= _ "AGNOVON, I’VE COME FOR YOUR SWORD! TODAY YOU WILL REMEMBER FEAR! Heh heh. Nice trick, huh?"
        [/message]

        [message]
            speaker=narrator
            message= _ "A voice came back like wind moaning through dry leaves. Though it was only whispered, all heard it better than they wanted."
            image=wesnoth-icon.png
        [/message]
        [message]
            speaker=Mal-Govon
            message= _ "What I remember, you old fool, is you leaving behind the smoldering bodies of the orcs you had hired to steal my sword. Now, you bring mermen. When they lay expiring like gasping fish on the shore, will you not flee again? Do not speak to <i>me</i> of fear."
        [/message]
        [message]
            speaker=Kai Krellis
            message= _ "We are here of our own accord, and we will take that sword."
        [/message]
        [message]
            speaker=Mal-Govon
            message= _ "The merman speaks. Tell it to go away, Caladon, if it doesn’t want to get hurt."
        [/message]
        [message]
            speaker=Kai Krellis
            message= _ "That does it. Attack!"
        [/message]
    [/event]

    [event]
        name=turn 2

        [message]
            speaker=Caladon
            message= _ "A word of warning, young Kai. I carry a staff of righteous FLAME. If you let me die, I will take YOU all with me!"
        [/message]
    [/event]

    [event]
        name=moveto

        [filter]
            [filter_location]
                x=17
                y=19
                radius=3
            [/filter_location]
            side=1
        [/filter]

        [unit]
            type=Outlaw
            side=3
            x=18
            y=18
            id=Howyrth
            name= _ "Howyrth"
            unrenamable=yes
            ai_special=guardian
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]
        [delay]
            time=500
        [/delay]

        [message]
            speaker=Howyrth
            message= _ "Hello there! Who are you? Were you the ones shouting about taking a sword?"
        [/message]

        [message]
            speaker=Kai Krellis
            message= _ "I am Kai Krellis of Jotha. I am attempting to defeat Mal-Govon and take his sword. Will you to join us in battle against a common enemy?"
        [/message]

        [message]
            speaker=Howyrth
            message= _ "I don’t know if that creature really is our enemy. He has never bothered us, and I should stay at my post anyway. However, I’m sure many townsfolk would welcome the extra income if you want to hire them. I guess we would be happy to get rid of the monster just in case."
        [/message]
        [message]
            speaker=narrator
            message= _ "You can now recruit human villagers, but you will not be able to recall them in future scenarios."
            image=wesnoth-icon.png
        [/message]

        [allow_recruit]
            type=Trapper, Bandit, Poacher, Thug, Footpad, Peasant, Woodsman, Ruffian
            side=1
        [/allow_recruit]

        [if]
            [variable]
                name=Siddry_stored
                not_equals=no
            [/variable]
            [then]
                [move_unit_fake]
                    type=$Siddry_stored.type
                    side=1
                    x=23,19
                    y=14,19
                [/move_unit_fake]
                [set_variable]
                    name=Siddry_stored.x
                    value=19
                [/set_variable]
                [set_variable]
                    name=Siddry_stored.y
                    value=19
                [/set_variable]
                # Siddry may have been stored low on hitpoints, and
                # after he had moved or attacked, so we'll fix all
                # that now:
                [set_variable]
                    name=Siddry_stored.hitpoints
                    value=37    #Hard coded because he is resillient so max_hitpoints is too low
                [/set_variable]
                [set_variable]
                    name=Siddry_stored.moves
                    value=$Siddry_stored.max_moves
                [/set_variable]
                [set_variable]
                    name=Siddry_stored.attacks_left
                    value=$Siddry_stored.max_attacks
                [/set_variable]
                [unstore_unit]
                    variable=Siddry_stored
                [/unstore_unit]
                [message]
                    speaker=Siddry
                    message= _ "Kai Krellis! What are you doing here? I thought you were traveling south when I met you."
                [/message]
                [message]
                    speaker=Kai Krellis
                    message= _ "Friend Siddry!"
                [/message]
                [message]
                    speaker=Howyrth
                    message= _ "You know each other?!"
                [/message]
                [message]
                    speaker=Siddry
                    message= _ "Kai Krellis is the one who saved me from slavery, Howyrth. I told him I would repay him if I could, and here is my chance. My friends and I will join you in your fight, Kai Krellis. We are yours to command, and we refuse to be paid."
                [/message]
                [unit]
                    type=Footpad
                    x=18
                    y=18
                    side=1
                    gender=female
                    id=Lyllan
                    name=Lyllan
                    [modifications]
                        {TRAIT_LOYAL}
                        {TRAIT_DEXTROUS}
                    [/modifications]
                    overlays=overlays/loyal-icon.png
                [/unit]
                [unit]
                    type=Thug
                    x=18
                    y=18
                    side=1
                    id=Trudd
                    name=Trudd
                    [modifications]
                        {TRAIT_LOYAL}
                        {TRAIT_RESILIENT}
                    [/modifications]
                    overlays=overlays/loyal-icon.png
                [/unit]
                [unit]
                    type=Thug
                    x=20
                    y=18
                    side=1
                    id=Dorcyn
                    name=Dorcyn
                    [modifications]
                        {TRAIT_LOYAL}
                        {TRAIT_QUICK}
                    [/modifications]
                    overlays=overlays/loyal-icon.png
                [/unit]

                {CLEAR_VARIABLE Siddry_stored}
            [/then]
            [else]
                [unit]
                    type=Footpad
                    x=18
                    y=18
                    side=1
                    gender=male
                    id=Dorcyn
                    name=Dorcyn
                    [modifications]
                        {TRAIT_RESILIENT}
                        {TRAIT_DEXTROUS}
                    [/modifications]
                [/unit]
                [message]
                    speaker=Dorcyn
                    message= _ "I’ll join you right now! That monster is just unnatural."
                [/message]
            [/else]
        [/if]
    [/event]

    # The variable "Caladon_leader_status" can be one of several values:
    # <empty>:   Caladon is not a leader. He is still a unit on side 1
    #
    # "passive": His side still has "controller=null" set. (He is
    # giving the mermen time to leave before attacking them.)
    #
    # "impatient": Caladon’s side now has "controller=ai" set. (He's
    # tired of waiting for the mermen to leave.) This is actually
    # *set* on the players turn, because Caladon’s side doesn't *get*
    # a turn until it is set. On his first turn after "impatient" is
    # set, he will say something and summon fire guardians.
    #
    # "angry": Player attacked Caladon. (...and Caladon summoned the
    # first fire guardians immediately, so he no longer has to on his
    # turn.)
    #
    # "leader": He is a normal leader now. He has started his turns,
    # and is summoning two fire guardians per turn.
    #
    # "dead":     Keeps any of the other events from happening.

#define ACTIVATE_CALADON
    [modify_side]
        side=4
        controller=ai
    [/modify_side]
#enddef

#define SUMMON_FIRE_GUARDIANS NUMBER
    [store_unit]
        [filter]
            id=Caladon
        [/filter]
        variable=Caladon_stored
    [/store_unit]

    {REPEAT {NUMBER} (
        [unit]
            type=Fire Guardian
            # The guardians are summoned on Caladon’s position, so they
            # will surround him or surround his attackers if there are
            # any:
            x=$Caladon_stored.x
            y=$Caladon_stored.y
            side=4
            animate=yes
            generate_name=yes
        [/unit]
    )}
#enddef

    [event]
        name=die
        [filter]
            id=Mal-Govon
        [/filter]

        # It seems strange to have to kill him in a "die" event, but
        # he's only *mostly* dead otherwise, and Caladon can't
        # teleport to his location:
        [kill]
            id=Mal-Govon
        [/kill]

        {PLACE_IMAGE items/flame-sword.png $x1 $y1}

        [message]
            speaker=narrator
            message= _ "The mermen clapped their hands over their ears as a terrible wail echoed off the castle walls."
            image=wesnoth-icon.png
        [/message]

        [delay]
            time=600
            # Gives you half a second to see the sword before the
            # message (probably) covers it up.
        [/delay]

        [if]
            [variable]
                name=second_unit.id
                equals=Kai Krellis
            [/variable]
            [then]
                {VARIABLE staff_tip_off Cylanna}
            [/then]
            [else]
                {VARIABLE staff_tip_off second_unit}
            [/else]
        [/if]

        [message]
            speaker=second_unit
            message= _ "Now we have the sword!"
        [/message]

        [message]
            speaker=Caladon
            message= _ "Correction. Now I have the sword!"
        [/message]

        [store_unit]
            [filter]
                id=Caladon
            [/filter]
            variable=Caladon_stored
        [/store_unit]

        [remove_unit_overlay]
            x=$Caladon_stored.x
            y=$Caladon_stored.y
            image=misc/hero-icon.png
        [/remove_unit_overlay]

        [store_unit]
            [filter]
                id=Caladon
            [/filter]
            kill=yes
            variable=Caladon_stored
        [/store_unit]

        {VARIABLE Caladon_stored.side 4}
        {VARIABLE Caladon_stored.canrecruit yes}
        # He is not going to recruit, but summon guardians each
        # turn. Still, he needs this variable set to get a crown icon,
        # and to show up in the status table.

        [unstore_unit]
            variable=Caladon_stored
        [/unstore_unit]

        [animate_unit]
            flag=pre_teleport
        [/animate_unit]

        [teleport]
            [filter]
                id=Caladon
            [/filter]
            x=$x1
            y=$y1
        [/teleport]

        [animate_unit]
            flag=post_teleport
        [/animate_unit]

        # Remove the death of Caladon from a the loss conditions, but
        # we probably don't need to make a point of it, so silent=yes.
        [objectives]
            silent=yes
            side=1
            [objective]
                description= _ "Pry the flaming sword from the dead hand of its owner"
                condition=win
            [/objective]
            {HOW_TO_LOSE}
        [/objectives]

        [delay]
            time=700
            # Gives you time to see that Caladon teleported to the
            # sword before the message (probably) covers him up
            # (because he will be near the top of the screen).
        [/delay]

        {FLAMING_SWORD $x1 $y1 flaming-sword2}
        [object]
            id=drop_staff
            silent=yes
            [filter]
                x=$x1
                y=$y1
            [/filter]
            [effect]
                apply_to=remove_attacks
                name=staff
            [/effect]
        [/object]

        [message]
            speaker=Caladon
            message= _ "It’s MINE! The Flaming Sword of Agnovon IS ALL MINE! I can feel warmth SPREADING through me!"
        [/message]

        [object]
            id=healer
            silent=yes
            [filter]
                x=$x1
                y=$y1
            [/filter]
            [effect]
                apply_to=hitpoints
                heal_full=yes
            [/effect]
        [/object]
        [sound]
            name=heal.wav
        [/sound]
        [delay]
            time=400
            # Wait for the sound to play (mostly) until scrolling to Kai Krellis
        [/delay]

        [message]
            speaker=Kai Krellis
            message= _ "What? We won that sword!"
        [/message]

        [message]
            speaker=Caladon
            message= _ "Well, it’s true that you helped, so I won’t kill you. But I don’t trust you, so leave my realm. Go on. I will grant you some time. The benevolence of Caladon will be LEGENDARY! Heh heh, HA!"
        [/message]

        [message]
            speaker=$staff_tip_off
            message= {WHISPER ( _ "Kai! He dropped his staff! We can attack him whenever we want now!")}
        [/message]
        [message]
            speaker=Cylanna
            message= {WHISPER ( _ "We can pretend we are going to leave though. That would buy me some time to heal the wounded.")}
        [/message]
        {VARIABLE Caladon_leader_status passive}
        # see note above on this variable

        [clear_variable]
            name=staff_tip_off
        [/clear_variable]
    [/event]

    [event]
        name=attack
        first_time_only=no

        [filter]
            side=1
        [/filter]
        [filter_second]
            side=4
        [/filter_second]

        [if]
            [variable]
                name=Caladon_leader_status  # see note above
                equals=passive
            [/variable]
            [or]
                [variable]
                    name=Caladon_leader_status
                    equals=impatient
                [/variable]
            [/or]
            [then]
                {ACTIVATE_CALADON}
                [message]
                    speaker=Caladon
                    message= _ "You DARE attack ME! You will regret that. Witness the POWER of the Flaming Sword of Caladon! I call on the ELEMENT OF FIRE to DO MY BIDDING!"
                [/message]
                {SUMMON_FIRE_GUARDIANS 6}
                {VARIABLE Caladon_leader_status leader}
            [/then]
        [/if]
    [/event]

    [event]
        name=side turn
        first_time_only=no

        [if]
            [variable]
                name=side_number
                equals=1
            [/variable]
            [and]
                [variable]
                    name=Caladon_leader_status  # see note above
                    equals=passive
                [/variable]
            [/and]

            [then]
                {ACTIVATE_CALADON}
                {VARIABLE Caladon_leader_status impatient}
            [/then]
        [/if]
    [/event]

    [event]
        name=side turn
        first_time_only=no

        [if]
            [variable]
                name=side_number
                equals=4
            [/variable]
            [and]
                [variable]
                    name=Caladon_leader_status  # see note above
                    not_equals=dead
                [/variable]
            [/and]
            [then]
                [if]
                    [variable]
                        name=Caladon_leader_status
                        equals=leader
                    [/variable]

                    [then]
                        {SUMMON_FIRE_GUARDIANS 2}
                    [/then]
                [/if]

                [if]
                    [variable]
                        name=Caladon_leader_status
                        equals=impatient
                    [/variable]

                    [then]
                        [message]
                            speaker=Caladon
                            message= _ "You haven’t left yet? My patience is at an END! Witness the POWER of the Flaming Sword of Caladon! I call on the ELEMENT OF FIRE to DO MY BIDDING!"
                        [/message]
                        {SUMMON_FIRE_GUARDIANS 6}
                        {VARIABLE Caladon_leader_status leader}
                    [/then]
                [/if]
            [/then]
        [/if]
    [/event]

    [event]
        name=die
        [filter]
            id=Caladon
            side=1
        [/filter]

        [sound]
            name=lightning.ogg
        [/sound]
        [sound]
            name=rumble.ogg
        [/sound]

        [kill]
            [filter]
            [/filter]
        [/kill]

        {VARIABLE color 250}
        {VARIABLE delta 8}
        {REPEAT 14 (
            [set_variable]
                name=delta
                sub=3
            [/set_variable]

            [set_variable]
                name=color
                add=$delta
            [/set_variable]

            [color_adjust]
                red,green,blue=$color|,$color|,$color
            [/color_adjust]

            [delay]
                time=100
            [/delay]
        )}

        [color_adjust]
            red,green,blue=0,0,0
        [/color_adjust]
    [/event]

    [event]
        name=die
        [filter]
            id=Caladon
            side=4
        [/filter]

        [set_variable]
            name=sword_x
            value=$x1
        [/set_variable]
        [set_variable]
            name=sword_y
            value=$y1
        [/set_variable]

        {PLACE_IMAGE items/flame-sword.png $sword_x $sword_y}
        [delay]
            time=600
            # Gives you half a second to see the sword before the
            # message (probably) covers it up (because it will be near
            # the top of the screen).
        [/delay]

        [message]
            speaker=Kai Krellis
            message= _ "Now we can finally grab that sword."
        [/message]
    [/event]

    [event]
        name=moveto
        first_time_only=yes

        [allow_undo][/allow_undo]
        [filter]
            x=$sword_x
            y=$sword_y
            side=1
            race=human
        [/filter]

        [message]
            speaker=unit
            message= _ "I am not going with you. One of your people should take the sword."
        [/message]
    [/event]

    # The first_time_only moveto causes the sword's attacks to be
    # explained. The moved unit gets the option to take it.
    # If the unit takes it, a sword *object* is put on the hex, and
    # the unit gets it because he is standing there already.
    # If the unit does not take it, another moveto event is
    # added. This one is *not* first_time_only, but it does the same
    # thing without the explanation.  If a unit does not take the
    # sword, an [allow_undo] is added to the event.
    [event]
        name=moveto
        first_time_only=yes

        [filter]
            x=$sword_x
            y=$sword_y
            side=1
            [not]
                race=human
            [/not]
        [/filter]

        [message]
            speaker=narrator
            message= _ "This sword is 8-4, magical, with <i>fire</i> damage."
            image=wesnoth-icon.png
        [/message]

        [message]
            speaker=unit
            [option]
                message= _ "I’ll carry this sword and destroy undead with blasts of flame."
                [command]
                    [set_variable]
                        name=get_sword
                        value=yes
                    [/set_variable]
                [/command]
            [/option]
            [option]
                message= _ "This sword is not right for me. Let someone else have it."
            [/option]
        [/message]

        [if]
            [variable]
                name=get_sword
                equals=yes
            [/variable]
            [then]
                {FLAMING_SWORD $sword_x $sword_y flaming-sword3}
                {CLEAR_VARIABLE get_sword}
                {CLEAR_VARIABLE sword_x}
                {CLEAR_VARIABLE sword_y}
                [endlevel]
                    result=victory
                    bonus=yes
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/then]
            [else]
                [allow_undo][/allow_undo]
                [event]
                    name=moveto
                    first_time_only=no

                    [filter]
                        x=$sword_x
                        y=$sword_y
                        side=1
                    [/filter]

                    [message]
                        speaker=unit
                        [option]
                            message= _ "I’ll carry the sword."
                            [command]
                                [set_variable]
                                    name=get_sword
                                    value=yes
                                [/set_variable]
                            [/command]
                        [/option]
                        [option]
                            message= _ "Let someone else have it."
                        [/option]
                    [/message]
                    [if]
                        [variable]
                            name=get_sword
                            equals=yes
                        [/variable]
                        [then]
                            {FLAMING_SWORD $sword_x $sword_y flaming-sword3}
                            {CLEAR_VARIABLE get_sword}
                            {CLEAR_VARIABLE sword_x}
                            {CLEAR_VARIABLE sword_y}
                            [endlevel]
                                result=victory
                                bonus=yes
                                {NEW_GOLD_CARRYOVER 40}
                            [/endlevel]
                        [/then]
                        [else]
                            [allow_undo][/allow_undo]
                        [/else]
                    [/if]
                [/event]
            [/else]
        [/if]
    [/event]

    [event]
        name=victory
        [if]
            [have_unit]
                race=human
                side=1
            [/have_unit]
            [then]
                [message]
                    speaker=Kai Krellis
                    message= _ "We thank all you humans for your help, and release you from any farther obligations. Where we are going, you cannot easily follow."
                [/message]
                [kill]
                    race=human
                    side=1
                [/kill]
            [/then]
        [/if]

        [disallow_recruit]
            type=Trapper, Bandit, Poacher, Thug, Footpad, Peasant, Woodsman, Ruffian
            side=1
        [/disallow_recruit]

        {CLEAR_VARIABLE Caladon_stored}
        {CLEAR_VARIABLE sword_x}
        {CLEAR_VARIABLE sword_y}
        {CLEAR_VARIABLE Caladon_leader_status}
    [/event]

    [event]
        name=die
        [filter]
            id=Cylanna
        [/filter]
        [message]
            speaker=Kai Krellis
            message= _ "Cylanna! I need you!"
        [/message]
        [message]
            speaker=Kai Krellis
            message= _ "Tyegëa will never forgive me. We are lost."
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=die
        [filter]
            id=Kai Krellis
        [/filter]
        [message]
            speaker=Cylanna
            message= _ "We are lost without our king!"
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Caladon
            side=4
        [/filter]

        [message]
            speaker=Caladon
            message= _ "CURSE you mermen!"
        [/message]

        {VARIABLE Caladon_leader_status dead}
    [/event]

    [event]
        name=last breath
        [filter]
            id=Caladon
            side=1
        [/filter]

        [message]
            speaker=Caladon
            message= _ "Aghh! Die!"
        [/message]

        [message]
            speaker=Kai Krellis
            message= _ "He has that staff of..."
        [/message]
    [/event]
[/scenario]
