#textdomain wesnoth-dm
[scenario]
    id=06_Swamps_of_Illuven
    name=_ "The Swamps of Illuven"
    {MEMOIRS_MAP 06_The_Swamps_of_Illuven.map}
    next_scenario=07_Night_in_the_Swamp
    {TURNS 32 30 28}
    victory_when_enemies_defeated=no
    {DEFAULT_SCHEDULE}

    {SCENARIO_MUSIC underground.ogg}    # No story part, so no intro music
    {EXTRA_SCENARIO_MUSIC traveling_minstrels.ogg}
    {EXTRA_SCENARIO_MUSIC revelation.ogg}
    {EXTRA_SCENARIO_MUSIC transience.ogg}

    {DM_TRACK {SEARCH_STAGE6}}

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        recruit=Mage,Spearman,Horseman,Bowman,Cavalryman,Heavy Infantryman
        save_id=Player
        team_name=allies
        user_team_name= _ "Loyalists"
        side_name= _ "Delfador"
        {FLAG_VARIANT loyalist}
        [leader]
            {YOUNG_DELFADOR}
        [/leader]
        [unit]
            {LIONEL}
            placement=leader
        [/unit]
        {GOLD 150 125 100}
    [/side]
    [event]
        name=prestart
        {MODIFY_UNIT (side=1) facing ne}
    [/event]
    {STARTING_VILLAGES 1 {ON_DIFFICULTY 6 5 4}}

    [side]
        side=2
        controller=ai
        recruit=Thief,Poacher,Thug
        {GOLD 80 100 120}
        team_name=enemies
        user_team_name= _ "Bandits"
        {FLAG_VARIANT6 ragged}
        [leader]
            id=Garrath
            name= _ "Garrath"
            type=Rogue
            facing=se
        [/leader]
        [ai]
            villages_per_scout=15
        [/ai]
    [/side]
    {STARTING_VILLAGES 2 {ON_DIFFICULTY 2 3 4}}

    [side]
        side=3
        controller=ai
        recruit=Footpad,Poacher,Thug
        {GOLD 80 100 120}
        team_name=enemies
        user_team_name= _ "Bandits"
        {FLAG_VARIANT6 ragged}
        [leader]
            id=Harold
            name=_ "Harold"
            type=Bandit
            facing=sw
        [/leader]
        [ai]
            villages_per_scout=10
        [/ai]
    [/side]
    {STARTING_VILLAGES 3 {ON_DIFFICULTY 2 3 4}}
    # wmllint: validate-on

    # reward for the player who defeats Garrath without paying him
    {PLACE_IMAGE items/chest-plain-closed.png 4 3}

    # location of the signpost
    {MEMOIRS_VICTORY_POSITION 38 3 yes}

    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description=_ "Move Delfador to the signpost in the northeast"
                condition=win
            [/objective]
            [objective]
                description=_ "Death of Delfador"
                condition=lose
            [/objective]
            [objective]
                description=_ "Death of Lionel"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

            [gold_carryover]
                bonus=yes
                carryover_percentage=80
            [/gold_carryover]
        [/objectives]
    [/event]

    [event]
        name=start
        [message]
            speaker=Lionel
            message=_"These are the swamps of Illuven — lesser kin of the Swamp of Dread north of the Great River, but noxious enough in their own fashion. Our way lies west and north across them to the Ford of Abez. The western road around the other edge of the Brown Hills would have been safer, but..."
        [/message]
        [message]
            speaker=Delfador
            message=_"... I insisted on the most direct possible route. I know; let us both hope the choice was not folly. Who made those villages in the swamps? Orcs?"
        [/message]
        [message]
            speaker=Lionel
            message=_"No, men of Wesnoth... but those who dwell here are a lawless lot."
        [/message]

        [store_gold]
            side=1
            variable=fee
        [/store_gold]
        {VARIABLE_OP fee multiply {ON_DIFFICULTY 6 7 8}}
        {VARIABLE_OP fee divide 10}
        {VARIABLE_OP fee round 0}
        {VARIABLE garrath_hostile yes}
        {VARIABLE times_garrath_paid 0}
        [message]
            speaker=Garrath
            message=_"Greetings, strangers! This swamp is dangerous... You wanna cross it, you’ll need protection — cost you only $fee gold!"
            [option]
                label=_"Thanks very much. Here’s the gold..."
                [command]
                    [gold]
                        side=1
                        amount=-$fee
                    [/gold]
                    # take his gold:
                    [remove_item]
                        x=4
                        y=3
                    [/remove_item]
#ifdef EASY
                    [message]
                        speaker=Garrath
                        message=_"You know, you really ought to be more careful before handing over money to suspicious strangers like me. But, since I’m feeling nice at the moment, I think I will actually keep my word and offer you some protection."
                    [/message]
                    [message]
                        speaker=Harold
                        message=_"Hey, what’s your problem, Garrath? I thought we had a deal!"
                    [/message]
                    [message]
                        speaker=Garrath
                        message=_"Yeah, well, I changed my mind."
                    [/message]
                    [modify_side]
                        side=2
                        team_name=allies
                    [/modify_side]
                    {VARIABLE garrath_hostile no}
                    {VARIABLE times_garrath_paid 1}
                    [gold]
                        side=2
                        amount=$fee
                    [/gold]
                    # we are already inside an "ifdef EASY" block, so no need to vary this on difficulty:
                    {CAPTURE_VILLAGES 2 4 3 4}
                    [redraw]
                    [/redraw]
                    [message]
                        speaker=Delfador
                        message=_"...I’m not entirely sure what just happened here, but I guess I should be grateful?"
                    [/message]
                    [message]
                        speaker=Lionel
                        message=_"While it appears fortune favored us this time, I fear for the travelers for whom this man does <i>not</i> keep his word..."
                    [/message]
#else
                    [message]
                        speaker=Garrath
                        message=_"It’s been a pleasure doing business with you... Bye!"
                    [/message]
                    [kill]
                        side=2
                    [/kill]
                    # (the gold-taking that was previously done here is now done above)
                    [delay]
                        time=500
                    [/delay]
                    [message]
                        speaker=Delfador
                        message=_"Where did he go?"
                    [/message]
                    [message]
                        speaker=Harold
                        message=_"Haw haw haw! Fools!"
                    [/message]
                    [message]
                        speaker=Lionel
                        message=_"Well, at least we only have to deal with one of them now..."
                    [/message]
#endif
                    # give the remaining enemy a boost, for balance
                    [gold]
                        side=3
                        amount={ON_DIFFICULTY 32 36 40}
                    [/gold]
                    # (maybe also give them an income, but I can't decide on a good amount)
#ifdef EASY
                    [event]
                        name=capture
                        first_time_only=no
                        [filter]
                            side=1
                        [/filter]
                        [if]
                            [have_location]
                                x,y=$x1,$y1
                                owner_side=2
                            [/have_location]
                            [or]
                                [variable]
                                    name=owner_side
                                    equals=2
                                [/variable]
                            [/or]
                            [then]
                                [if]
                                    [variable]
                                        name=garrath_hostile
                                        boolean_equals=no
                                    [/variable]
                                    [then]
                                        [if]
                                            [variable]
                                                name=times_garrath_paid
                                                less_than_equal_to=1
                                            [/variable]
                                            [then]
                                                [message]
                                                    speaker=Garrath
                                                    message=_"Hey, that was one of <i>our</i> villages! Deal’s off; we’re no longer protecting you!"
                                                [/message]
                                                # Need to conditionalize here to ensure Garrath's reply makes sense:
                                                [if]
                                                    [have_unit]
                                                        id=Harold
                                                    [/have_unit]
                                                    [then]
                                                        [message]
                                                            speaker=Harold
                                                            message=_"So... does that mean that <i>our</i> deal is back on now, Garrath?"
                                                        [/message]
                                                        [message]
                                                            speaker=Garrath
                                                            message=_"Fine, I guess..."
                                                        [/message]
                                                    [/then]
                                                [/if]
                                                [message]
                                                    speaker=Delfador
                                                    message=_"Wait, I’m sorry! I didn’t realize you were so attached to that village! Please give me a chance to make it up to you!"
                                                [/message]
                                                [message]
                                                    speaker=Garrath
                                                    message=_"Well, I guess a little extra payment could persuade me to forgive you..."
                                                [/message]
                                                [store_gold]
                                                    variable=gold
                                                    side=1
                                                [/store_gold]
                                                [if]
                                                    [variable]
                                                        name=gold
                                                        less_than=20
                                                    [/variable]
                                                    [then]
                                                        [message]
                                                            speaker=Delfador
                                                            # If debugging, feel free to edit the variable $gold into this message to see how much you have left:
                                                            message=_"I’m afraid I don’t have much gold left..."
                                                        [/message]
                                                        [message]
                                                            speaker=Garrath
                                                            message=_"Oh well, too bad for you!"
                                                        [/message]
                                                        [modify_side]
                                                            side=2
                                                            team_name=enemies
                                                        [/modify_side]
                                                        {VARIABLE garrath_hostile yes}
                                                    [/then]
                                                    [else]
                                                        [message]
                                                            speaker=Delfador
                                                            message=_"Well..."
                                                            [option]
                                                                label=_"Here’s 20 more gold."
                                                                [command]
                                                                    [gold]
                                                                        side=1
                                                                        amount=-20
                                                                    [/gold]
                                                                    [gold]
                                                                        side=2
                                                                        amount=20
                                                                    [/gold]
                                                                    {VARIABLE_OP times_garrath_paid add 1}
                                                                    [message]
                                                                        speaker=Garrath
                                                                        message=_"Pleasure doing business with you! Just don’t let it happen again!"
                                                                    [/message]
                                                                    # If Harold is dead, dialogue will still make sense with this omitted:
                                                                    [message]
                                                                        speaker=Harold
                                                                        message=_"Sheesh, Garrath, won’t you make up your mind already?!"
                                                                    [/message]
                                                                    # (nothing else to do; Garrath stays an ally)
                                                                [/command]
                                                            [/option]
                                                            [option]
                                                                label=_"Nope, I’m not giving you any more gold."
                                                                [command]
                                                                    [message]
                                                                        speaker=Garrath
                                                                        message=_"Suit yourself. Men, attack!"
                                                                    [/message]
                                                                    [modify_side]
                                                                        side=2
                                                                        team_name=enemies
                                                                    [/modify_side]
                                                                    {VARIABLE garrath_hostile yes}
                                                                [/command]
                                                            [/option]
                                                        [/message]
                                                    [/else]
                                                [/if] # gold
                                                {CLEAR_VARIABLE gold}
                                            [/then]
                                            [elseif]
                                                [variable]
                                                    name=times_garrath_paid
                                                    # This should be redundant with the previous condition, but I'm writing it like this
                                                    # to be more explicit about what exactly I'm doing, and to leave room for future
                                                    # editors to potentially add more cases in the future:
                                                    greater_than_equal_to=2
                                                [/variable]
                                                [then]
                                                    [message]
                                                        speaker=Garrath
                                                        message=_"Hey! You captured one of my villages again! I thought I told you to stop doing that!"
                                                    [/message]
                                                    [message]
                                                        speaker=Delfador
                                                        message=_"Sorry! It’s a hard habit to break! Perhaps I can pay you again to make up for it?"
                                                        # (possible future direction: actually let him do so, but at a higher price than before. For now, though, we won't.)
                                                    [/message]
                                                    [message]
                                                        speaker=Garrath
                                                        message=_"Nope, I’m through with your games! Men, attack!"
                                                    [/message]
                                                    [modify_side]
                                                        side=2
                                                        team_name=enemies
                                                    [/modify_side]
                                                    {VARIABLE garrath_hostile yes}
                                                    [message]
                                                        speaker=Delfador
                                                        message=_"Oh well, I guess I should have listened when he said not to let it happen again..."
                                                    [/message]
                                                [/then]
                                            [/elseif]
                                        [/if] # times_garrath_paid
                                    [/then]
                                    [else]
                                        # case where he is already hostile:
                                        [message]
                                            speaker=Garrath
                                            message=_"Stop stealing my villages!"
                                        [/message]
                                    [/else]
                                [/if] # garrath_hostile
                            [/then]
                        [/if]
                    [/event]

                    [event]
                        name=side 1 turn refresh
                        first_time_only=no
                        [store_gold]
                            variable=gold
                            side=1
                        [/store_gold]
                        [if]
                            [variable]
                                name=gold
                                less_than=0
                            [/variable]
                            [then]
                                [message]
                                    speaker=Garrath
                                    message=_"Hm, it looks like you don’t have any gold left. We’re not interested in you anymore; bye!"
                                [/message]
                                [kill]
                                    side=2
                                [/kill]
                                [message]
                                    speaker=Harold
                                    message=_"What a fickle one, that Garrath..."
                                [/message]
                            [/then]
                        [/if]
                        {CLEAR_VARIABLE gold}
                    [/event]

                    # A little bit of extra balance to make up for the fact that Harold now has an extra enemy:
                    [event]
                        name=last breath
                        [filter]
                            side=2
                        [/filter]
                        [filter_second]
                            side=3
                        [/filter_second]
                        [message]
                            speaker=Harold
                            message=_"I’ll be taking back that money that your men “borrowed” from me now, Garrath!"
                        [/message]
                    [/event]

                    # Split the actual gold-giving part of this off from the previous one so that it can happen multiple times:
                    [event]
                        name=die
                        first_time_only=no
                        [filter]
                            side=2
                        [/filter]
                        [filter_second]
                            side=3
                        [/filter_second]
                        {RANDOM $unit.level..$unit.cost}
                        [gold]
                            side=3
                            amount=$random
                        [/gold]
                        [floating_text]
                            x,y=$x2,$y2
                            # wmllint: markcheck off
                            text="<span color='#BCB088'>+$random|g</span>"
                            # wmllint: markcheck on
                        [/floating_text]
                    [/event]
#endif
                [/command]
            [/option]
            [option]
                label=_"No thanks — we’ll manage by ourselves..."
                [command]
                    [message]
                        speaker=Garrath
                        message=_"You’ll regret it!"
                    [/message]
                    [message]
                        speaker=Harold
                        message=_"They certainly will! Haw haw haw!"
                    [/message]

                    [event]
                        name=moveto
                        [filter]
                            x,y=4,3
                            side=1
                        [/filter]

                        [sound]
                            name=open-chest.wav
                        [/sound]
                        {REMOVE_IMAGE 4 3}
                        {PLACE_IMAGE items/chest-plain-open.png 4 3}
                        [sound]
                            name=gold.ogg
                        [/sound]
                        [gold]
                            side=1
                            amount={ON_DIFFICULTY 120 110 100}
                        [/gold]
                        [message]
                            speaker=unit
                            message=_"This chest contains all the money that rogue has taken from unwary travelers!"
                        [/message]
                    [/event]
                [/command]
            [/option]
        [/message]
        {CLEAR_VARIABLE fee}
    [/event]

    [event]
        name=victory
        # need to clear these out here instead of in the previous event so that they can be used in inner events:
        {CLEAR_VARIABLE garrath_hostile}
        {CLEAR_VARIABLE times_garrath_paid}
    [/event]
    {MEMOIRS_DEATHS}
[/scenario]
