#textdomain wesnoth-sota

# At the end of this scenario, Ras-Tabahn and his army and gold have to be stored so they
# can be brought back when R-T rejoins Ardonna. There is some dialog about having at
# least 50 gold because that's probably necessary to win Entering_the_Northlands on hard.
# EtN is the next scenario chronologically, but not the next in the game, so having to
# come all the way back to this scenario for more gold would be annoying--hence the tip.
# You get the ability to recruit chocobones when a unit inspects the bones of a
# flightless bird half-buried in the sand. There is one long event for this. Almost the
# same event appears in Mountain_Pass if the player doesn't find the bones here.

[scenario]
    name= _ "Merfolk Revenge"
    map_file=10_Merfolk_Revenge.map

    id=10_Merfolk_Revenge
    next_scenario=11_Battleground

    [story]
        [part]
            [background_layer]
                image=portraits/merfolk/triton.webp
                scale=no
            [/background_layer]
            story= _ "Ras-Tabahn’s party reached the end of the elf road near the Great River where they were to wait for Ardonna. As they arrived, another party did as well."
        [/part]
        {JOURNEY_PART 10}
    [/story]

    {DEFAULT_SCHEDULE}
    {DEFAULT_MUSIC_PLAYLIST}
    {TURNS 25 26 27}

    [side]
        {SIDE_1_RAS-TABAHN}
        {RAS-TABAHN_RECRUIT_2}
        {GOLD 150 130 110}
    [/side]

    {STARTING_VILLAGES 2 5}
    {STARTING_VILLAGES 1 5}

    [side]
        side=2
        controller=ai
        user_team_name= _ "Merfolk"
        type=Merman Triton
        name= _ "Okean"
        id=Okean
        recruit=Merman Netcaster, Merman Fighter, Merman Hunter, Mermaid Initiate
        color=purple
        facing=sw
        {GOLD 210 270 330}
        {FLAG_VARIANT long}
        [ai]
            caution=3
            recruitment_diversity=3.0
        [/ai]
    [/side]

    # *************************** PRESTART ***************************
    [event]
        name=prestart

        [objectives]
            side=1
            [objective]
                description= _ "Defeat the enemy leader"
                condition=win
            [/objective]

            {HOW_TO_LOSE_WITH_RAS-TABAHN}

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

        # Only one Shynal will be recalled.
        [recall]
            id=Shynal
            x,y=8,14
            show=no
        [/recall]
        [recall]
            id=Corpse Shynal
            x,y=8,14
            show=no
        [/recall]
        [recall]
            id=Carcyn
            x,y=8,15
            show=no
        [/recall]

        [set_variable]
            name=bird_bones_found
            value=no
        [/set_variable]
        [item]
            x,y=32,12
            image=items/bird-bones.png
        [/item]
    [/event]

    [event]
        name=start
    [/event]

    # *************************** PLAY ***************************

    # This long event creates a chocobone when a unit moves to where bird bones are
    # buried in the sand.
    # There is a short conversation, but there are many possibilities for which units
    # are involved, so there are a lot of ifs. There is also a lot of animation around
    # the appearance of the chocobone involving a skeleton and a flightless-bird unit.
    [event]
        name=moveto
        [filter]
            x,y=32,12
            side=1
        [/filter]

        [if]
            [variable]
                name=unit.race
                equals=undead
            [/variable]
            [then]
                [message]
                    speaker=$unit.id
                    #po: Bones examined by a ghost, skeleton, ghoul, or corpse.
                    message= _ "Bones. Claws and wings."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=$unit.id
                    #po: Bones examined by a human.
                    message= _ "There are some large bones here. I can see claws and wings."
                [/message]
            [/else]
        [/if]

        # Choose a human for Ras-Tabahn to talk to.
        [store_unit]
            [filter]
                race=human
                {EVERYWHERE}
                [not]
                    id=Ras-Tabahn
                [/not]
            [/filter]
            variable=all_other_humans
        [/store_unit]
        [if]
            [variable]
                name=all_other_humans.length
                greater_than=0
            [/variable]
            [then]
                [set_variable]
                    name=other_human
                    value=$all_other_humans[0].id
                [/set_variable]
            [/then]
            [else]
                [set_variable]
                    name=other_human
                    value=nobody
                [/set_variable]
            [/else]
        [/if]
        [clear_variable]
            name=all_other_humans
        [/clear_variable]

        [if]
            [have_unit]
                id=$other_human
            [/have_unit]
            [then]
                [message]
                    speaker=$other_human
                    message= _ "How odd. I wonder what they are from. A gryphon perhaps?"
                [/message]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "A large flightless bird would be my guess."
                [/message]
                [message]
                    speaker=$other_human
                    message= _ "Well, there is an easy way to find out."
                [/message]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "Indeed. Let us see."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "I wonder what they are from. A large flightless bird perhaps? Let us see."
                [/message]
            [/else]
        [/if]

        # Remove the bones and show a resurrected bird:
        [remove_item]
            # Remove the bones:
            x,y=32,12
        [/remove_item]
        [animate_unit]
            # Fire the recruitment animation (actually an extra_anim):
            [filter]
                id=Ras-Tabahn
            [/filter]
            flag=recruit2
            [facing]
                # The x is 31, not 32, because R-T might be standing on the bones
                # himself, and he should face the location the bird will appear.
                x,y=31,12
            [/facing]
        [/animate_unit]
        [unit]
            # Show the bird fading in. The engine will automatically find an empty
            # location for it.
            x,y=32,12
            id=bird
            type=Bone Bird
            side=1
            facing=se
            animate=yes
        [/unit]
        [store_unit]
            # Store the bird so we can get its location later:
            [filter]
                id=bird
            [/filter]
            variable=bird
        [/store_unit]

        [message]
            speaker=$other_human
            message= _ "Oh, you were right!"
        [/message]

        [message]
            speaker=Ras-Tabahn
            message= _ "I wonder if it could carry someone light. A skeleton maybe."
        [/message]

        # Replace the bird with a Chocobone:
        [modify_unit]
            # We're about to animate a recruit which will most likely appear to
            # Ras-Tabahn's upper left, so we'll face him that direction:
            [filter]
                id=Ras-Tabahn
            [/filter]
            facing=nw
        [/modify_unit]
        [animate_unit]
            # Fire the recruitment animation (actually an extra_anim):
            [filter]
                id=Ras-Tabahn
            [/filter]
            flag=recruit2
        [/animate_unit]
        [unit]
            # Animate a skeleton getting recruited:
            side=1
            animate=yes
            type=Skeleton
            id=rider
            placement=leader
        [/unit]
        [store_unit]
            # Remove the skeleton, but store it so we can get its location:
            [filter]
                id=rider
            [/filter]
            variable=rider
            kill=yes
        [/store_unit]
        [move_unit_fake]
            # Show a skeleton moving from where the skeleton appeared to wherever
            # the bird is:
            type=Skeleton
            side=1
            x=$rider.x, $bird.x
            y=$rider.y, $bird.y
        [/move_unit_fake]
        [kill]
            id=bird
            animate=no
        [/kill]
        [unit]
            # Now we show a joined skeleton and bird:
            x,y=$bird.x, $bird.y
            type=Chocobone
            side=1
            animate=no
            facing=se
        [/unit]

        [message]
            speaker=Ras-Tabahn
            message= _ "Splendid! These birds could be quite useful."
        [/message]
        [allow_recruit]
            side=1
            type=Chocobone
        [/allow_recruit]
        [message]
            speaker=narrator
            image=units/undead-skeletal/chocobone.png~SCALE(93,93)
            message= _ "You can now recruit chocobones!"
        [/message]
        [set_variable]
            # This variable causes the bird bones *not* to appear on Mountain_Pass.
            # It won't be cleared until then.
            name=bird_bones_found
            value=yes
        [/set_variable]
        [clear_variable]
            name=bird, rider, other_human
        [/clear_variable]
    [/event]

    # *************************** ENDING / OPENING ***************************
    [event]
        name=enemies defeated

        # We want to be able to add Ras-Tabahn's gold to the total when the two
        # characters are reunited, but only Ardonna's gold will be carried over
        # from the scenario right before that. We are storing R-T's gold now,
        # but we want to store what it would be after the bonus. We need to
        # calculate the bonus and store it before ending the scenario.
        [store_turns]
            variable=turns
        [/store_turns]
        [store_villages]
            variable=villages
        [/store_villages]
        [store_gold]
            side=1
            variable=gold
        [/store_gold]

        # This is the formula used by the game:
        [set_variable]
            name=rastabahn_gold
            value="$((($turns - $turn_number) * ($villages.length + 2) + ($gold)) * 0.4)"
        [/set_variable]
        [set_variable]
            name=rastabahn_gold
            round=0
        [/set_variable]

        [set_variable]
            name=gold_message
            value= _ "Hopefully this will be enough gold."
        [/set_variable]

        [if]
            [variable]
                name=rastabahn_gold
                less_than=46
            [/variable]
            [then]
                [set_variable]
                    name=gold_message
                    value= _ "We have won, but I am afraid this may not be enough gold."
                [/set_variable]
            [/then]
        [/if]

        [if]
            [variable]
                name=rastabahn_gold
                greater_than=55
            [/variable]
            [then]
                [set_variable]
                    name=gold_message
                    value= _ "Good. We ended with a fair amount of gold."
                [/set_variable]
            [/then]
        [/if]

        # During the next message about gold, the carryover report will not have been
        # shown yet, so the player won't know how much gold R-T is talking about. To
        # fix that, we temporarily set the amount of gold shown at the top of the
        # screen to be equal to the carryover amount. Then we have to set it back to
        # make the carryover report correct.
        [gold]
            side=1
            amount="$(-1 * $gold + $rastabahn_gold)"
        [/gold]
        [message]
            speaker=Ras-Tabahn
            message=$gold_message
        [/message]
        [gold]
            side=1
            amount="$(-1 * $rastabahn_gold + $gold)"
        [/gold]

        # R-T gold should not be negative:
        [if]
            [variable]
                name=rastabahn_gold
                less_than=0
            [/variable]
            [then]
                [set_variable]
                    name=rastabahn_gold
                    value=0
                [/set_variable]
            [/then]
        [/if]

        # We don't need "bonus=yes" etc., but it will cause the carryover report
        # to be generated correctly:
        [endlevel]
            result=victory
            bonus=yes
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
        [clear_variable]
            name=turns, villages, gold, gold_message
        [/clear_variable]
    [/event]

    [event]
        name=start
        [message]
            speaker=Okean
            message= _ "You! You have destroyed the town of Carcyn!"
        [/message]
        [message]
            speaker=Ras-Tabahn
            message= _ "The town is hardly destroyed. I just encouraged a change of leadership."
        [/message]
        [message]
            speaker=Okean
            message= _ "Your words mock us. Those humans were valuable trading partners of ours. We will have justice!"
        [/message]
        [message]
            speaker=Ras-Tabahn
            message= _ "Actually, I expect you will follow them into the ground if you try to harm us."
        [/message]

        [if]
            {BOTH_KIDS_LIVE}
            [then]
                [message]
                    speaker=Ras-Tabahn
                    #po: here "you" means both Carcyn and Shynal
                    message= _ "addressed_plural^This is going to cost us, but I want to keep some gold around for emergencies — I think 50 is about right. You help me collect some. (<i>Cough, cough</i>)"
                [/message]
                [message]
                    speaker=Carcyn
                    message= _ "Right away sir."
                [/message]
                [message]
                    speaker=Shynal
                    message= _ "Are you feeling well?"
                [/message]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "Yes, yes. I’m quite all right."
                [/message]
                [message]
                    speaker=Shynal
                    message= _ "I don’t fancy wading in the water to fight these things."
                [/message]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "No problem. We can lure them onto land."
                [/message]
                [message]
                    speaker=Shynal
                    message= _ "How?"
                [/message]
                [message]
                    speaker=Ras-Tabahn
                    #po: here "you" means both Carcyn and Shynal, translating it as if "you" meant only Shynal is also ok
                    message= _ "addressed_plural^Have you never been fishing before? With bait of course."
                [/message]
            [/then]
        [/if]

        [if]
            {ONE_KID_LIVES}
            [then]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "This is going to cost us, but I want to keep some gold around for emergencies — I think 50 is about right. Help me collect some. (<i>Cough, cough</i>)"
                [/message]
                [message]
                    id=Carcyn,Shynal
                    message= _ "Right away sir. Are you feeling well?"
                [/message]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "Yes, yes. I’m quite all right."
                [/message]
                [message]
                    id=Carcyn,Shynal
                    message= _ "I don’t fancy wading in the water to fight these things."
                    female_message= _ "self_female^I don’t fancy wading in the water to fight these things."
                [/message]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "No problem. We can lure them onto land."
                [/message]
                [message]
                    id=Carcyn,Shynal
                    message= _ "How?"
                [/message]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "Have you never been fishing before? With bait of course."
                [/message]
            [/then]
        [/if]

        [if]
            {NO_KIDS_LIVE}
            [then]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "This is going to cost me, but I want to keep some gold around for emergencies — I think 50 is about right. I’d better send someone to collect some. (<i>Cough, cough</i>) I hope I can lure these fish onto land. Maybe I should recruit some bait."
                [/message]
            [/then]
        [/if]
    [/event]

    [event]
        name=time over

        [message]
            speaker=narrator
            image=logo.png
            message= _ "You have no more time."
        [/message]
    [/event]

    {HERO_DEATHS}
    {MAKE_BATS_NORMAL}
    {ZOMBIES}
    {KIDS_ADVANCE}
[/scenario]
