#textdomain wesnoth-dw

# This level is not too hard. Don't go too negative on gold, but
# recruit three or four high-level units. You need mostly leveled
# initiates for their magic ranged attacks. Keshan is a big help, and
# so is the unit with the storm trident. If you decide to go after the
# orc leader, wait until the undead are dispatched. Heal everyone,
# then assemble just to the north of his keep. Don't touch the ships
# or piers though! Wait until day time, then send in all the units
# with magical attacks. Use other units to keep the slurbows
# busy. Hopefully the leader won't kill anyone before your next
# turn. One more round of magical attacks should kill him before his
# recruits start beating you up. Killing the orc leader isn't really
# necessary, but he helps someone level up, and he has a fair bit of
# gold. The next level is much easier with lots of gold.

# A lot of the code here is to activate the orc side if the mermen do
# anything wrong, and keep it passive until then. There is also some
# animation of the orcs coming out to tear down the keep after the
# first turn.

[scenario]
    name= _ "Tirigaz"
    map_data="{campaigns/Dead_Water/maps/Tirigaz.map}"

    id=05_Tirigaz
    next_scenario=06_Uncharted_Islands

    [story]
        [part]
            story= _ "Farther up the coast was the port city of Tirigaz where Kai Laudiss had so soundly beaten the orcs. Bilheld was due west from there. The merfolk felt uneasy, so they took shelter in an abandoned orcish encampment as night fell."
        [/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}
            {NEW_JOURNEY 637 497}
            {NEW_JOURNEY 628 473}
            {NEW_JOURNEY 610 454}
            {NEW_JOURNEY 589 437}
            {NEW_JOURNEY 576 412}
            {NEW_JOURNEY 575 388}
            {NEW_JOURNEY 552 381}
            {NEW_BATTLE 542 361}
        [/part]
    [/story]

    {DUSK}
    {FIRST_WATCH}
    {SECOND_WATCH}
    {DAWN}
    {MORNING}
    {AFTERNOON}

    {TURNS4 18 17 16 16}
    victory_when_enemies_defeated=no

    [side]
        {SIDE_1}
        {INCOME4 8 7 6 6}
        {GOLD4 120 120 100 100}
    [/side]

    [event]
        name=prestart

        [music]
            name=northerners.ogg
        [/music]
        [music]
            name=legends_of_the_north.ogg
            append=yes
        [/music]

        {RECALL_LOYAL_UNITS}

        [objectives]
            side=1
            {HOW_TO_LOSE}
            [objective]
                description= _ "Destroy all the undead"
                condition=win
            [/objective]
            [objective]
                {BONUS_OBJECTIVE_CAPTION}
                description= _ "Also kill Marg-Tonz"+{EARLY_FINISH_BONUS_FOOTNOTE}+{OBJECTIVE_FOOTNOTE _"(you can destroy the undead first)"}
                condition=win
            [/objective]

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

        [set_variable]
            name=orcs_passive
            value=yes
        [/set_variable]

        [item]
            x=27
            y=10
            image="units/transport/transport-galleon.png~RC(magenta>orange)"
        [/item]
        [item]
            x=29
            y=9
            image="units/transport/galleon.png~RC(magenta>purple)"
        [/item]
        [item]
            x=22
            y=5
            image="units/transport/transport-galleon.png~RC(magenta>teal)"
        [/item]
    [/event]

    [side]
        side=2
        controller=ai
        user_team_name= _ "Orcs"
        team_name=neutral

        id=Marg-Tonz
        name= _ "Marg-Tonz"
        canrecruit=yes
        moves=0
        type=Orcish Sovereign
        recruit=Wolf Rider, Goblin Knight, Goblin Pillager, Orcish Archer, Orcish Grunt, Orcish Crossbowman, Orcish Assassin, Orcish Warrior, Orcish Slurbow, Orcish Warlord, Orcish Slayer

        [ai]
            [target]
                side=1
                value=1000
            [/target]
            leader_value=1000
        [/ai]

        gold=0
        income=-10
        {FLAG_VARIANT ragged}
    [/side]
    {STARTING_VILLAGES 2 99}

    [side]
        side=3
        controller=ai
        no_leader=yes
        team_name=bad guys
        user_team_name= _ "Undead"
        [ai]
            aggression=0.8
            [target]
                side=1
                value=1000
            [/target]
            [target]
                side=2
                value=1
            [/target]
            village_value=0
            # Even though they are less attractive targets, the ghosts
            # will attack the orcs if they are in range and the mermen
            # aren't. We will keep the ghosts from attacking the orcs
            # by telling them to avoid the hexes around the guardians.
            [avoid]
                x=14,15,16,  15,16,17,      22,23,24,    24,25,26,         29,30,31,           32,33,34,     31,32,33,        35,36,37
                y=2-3,2-4,2-3,  9-10,8-10,9-10,  2-3,2-4,2-3,  12-13,12-14,12-13,  12-13,11-13,12-13,  7-8,7-9,7-8,  10-11,9-11,10-11,  15-16,14-16,15-16
            [/avoid]
        [/ai]

        gold=0
        {FLAG_VARIANT undead}
    [/side]

    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Orcish Warlord) 3}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Orcish Slurbow) 2}

#define CITY_GUARD X Y
    [unit]
        type=Orcish Crossbowman
        generate_name=yes
        side=2
        x={X}
        y={Y}
        [modifications]
            {TRAIT_LOYAL}
            {TRAIT_FEARLESS}
        [/modifications]
        moves=0
    [/unit]
#enddef

    [event]
        name=prestart
        {CITY_GUARD 15 3}
        {CITY_GUARD 16 9}
        {CITY_GUARD 23 3}
        {CITY_GUARD 33 8}
        {CITY_GUARD 30 12}
        {CITY_GUARD 25 13}
        {CITY_GUARD 36 15}
    [/event]

#define GHOST X Y
    [unit]
        type=Ghost
        x={X}
        y={Y}
        side=3
    [/unit]
#enddef

#define WRAITH X Y
    [unit]
        type=Wraith
        x={X}
        y={Y}
        side=3
    [/unit]
#enddef

    [event]
        name=start

        [move_unit_fake]
            type=Ghost
            x=14,20
            y=20,18
        [/move_unit_fake]

        [unit]
            type=Ghost
            id=ghost scout
            x=20
            y=18
            side=3
        [/unit]

        [message]
            speaker=ghost scout
            message= _ "Found. Them."
        [/message]

        {GHOST 19 20}
        {GHOST 20 19}
        {GHOST 21 20}
        {GHOST 22 20}
        {WRAITH 19 19}
        {WRAITH 17 19}
        {WRAITH 18 19}
        {WRAITH 17 18}
        {WRAITH 20 20}

#ifdef NORMAL
        [unit]
            type=Spectre
            x=17
            y=18
            side=3
        [/unit]
        [unit]
            type=Spectre
            x=20
            y=20
            side=3
        [/unit]
#endif

#ifdef HARD
        [unit]
            type=Spectre
            x=17
            y=18
            side=3
        [/unit]
        [unit]
            type=Spectre
            x=20
            y=20
            side=3
        [/unit]
        [unit]
            type=Shadow
            x=20
            y=19
            side=3
        [/unit]
        [unit]
            type=Shadow
            x=20
            y=19
            side=3
        [/unit]
#endif

#ifdef NIGHTMARE
        [unit]
            type=Spectre
            x=17
            y=18
            side=3
        [/unit]
        [unit]
            type=Spectre
            x=20
            y=20
            side=3
        [/unit]
        [unit]
            type=Shadow
            x=20
            y=19
            side=3
        [/unit]
        [unit]
            type=Shadow
            x=20
            y=19
            side=3
        [/unit]
        [unit]
            type=Nightgaunt
            x=20
            y=19
            side=3
        [/unit]
        [unit]
            type=Nightgaunt
            x=20
            y=19
            side=3
        [/unit]
#endif

        # Count the undead because it's more robust than hardcoding
        # their number.
        [store_unit]
            [filter]
                side=3
            [/filter]
            variable=undead
        [/store_unit]
        {FOREACH undead loop}
            [set_variable]
                name=number_of_undead
                add=1
            [/set_variable]
        {NEXT loop}
        [clear_variable]
            name=undead
        [/clear_variable]

        [message]
            speaker=Kai Krellis
            message= _ "I feared this might happen. We tarried too long fighting the saurians, and the undead have caught up with us. The spirits may have trapped us here for the night, but in the morning we will..."
        [/message]

        [message]
            speaker=Marg-Tonz
            message= _ "What’s going on? What are you fish-men doing here? Are we constantly to be pestered by you creatures?"
        [/message]

        [message]
            speaker=Cylanna
            message= _ "He’s one to complain about <i>that</i>..."
        [/message]

        [message]
            speaker=Kai Krellis
            message= _ "We were just passing through."
        [/message]

        [message]
            speaker=Marg-Tonz
            message= _ "Well, finish passing."
        [/message]

        [message]
            speaker=Kai Krellis
            message= _ "Actually, we have some ghosts after us now, and we would like to shelter here for a while."
        [/message]

        [message]
            speaker=Marg-Tonz
            message= _ "Forget about it! We don’t want no trouble, but get off our land! Ghosts who don’t like fish are your problem."
        [/message]

        [message]
            speaker=Kai Krellis
            message= _ "If you give us a few hours to regroup and prepare our soldiers, we will go without causing you trouble."
        [/message]

        [message]
            speaker=Marg-Tonz
            message= _ "You have one hour. After that, we are tearing down that old encampment. You stay in the water if you know what’s good for you. If you set foot...or whatever...on land again, we’ll cut your throats. And stay off our piers. And don’t touch the ships neither!"
        [/message]

        [message]
            speaker=Cylanna
            message= _ "I wonder how he gets customers with manners like that."
        [/message]

        [message]
            speaker=Kai Krellis
            message= _ "One hour will work for us. It will not take all of us to defeat the undead. " + {WHISPER _"We can decide what to do about the orc after that."}
        [/message]

        [message]
            speaker=narrator
            message= _ "You will only be able to use your keep for one turn."
            image=wesnoth-icon.png
        [/message]
    [/event]

#define WAKE_ORCS
    # This variable removes their movement points every turn when it's yes:
    [set_variable]
        name=orcs_passive
        value=no
    [/set_variable]

    [gold]
        side=2
#ifdef EASY
        amount=200
#endif
#ifdef NORMAL
        amount=250
#endif
#ifdef HARD
        amount=300
#endif
#ifdef NIGHTMARE
        amount=350
#endif
    [/gold]

    [modify_side]
        side=2
        income=0
    [/modify_side]
#enddef

    [event]
        name=turn 2

        # If, at the end of turn 2, (actually, beginning of turn 3)
        # the mermen are still ashore, the orcs attack.  The event
        # doesn't need to check for the turn being 3, because that's
        # the only way the mermen could be ashore with the orcs still
        # passive.
        [event]
            name=side turn
            first_time_only=no

            [if]
                [and]
                    [variable]
                        name=side_number
                        equals=2
                    [/variable]
                    [variable]
                        name=orcs_passive
                        equals=yes
                    [/variable]
                    [have_unit]
                        side=1
                        [not]
                            [filter_location]
                                terrain=Ww, Wo, Wwf
                            [/filter_location]
                        [/not]
                    [/have_unit]
                [/and]
                [then]
                    [message]
                        speaker=Marg-Tonz
                        message= _ "You’re still squatting on our land! I warned you."
                    [/message]
                    {WAKE_ORCS}
                [/then]
            [/if]
        [/event]
    [/event]

    # After turn 3, if the mermen touch land, the orcs attack.
    [event]
        name=turn 3

        [event]
            name=moveto
            first_time_only=yes

            [filter]
                side=1
                [not]
                    [filter_location]
                        terrain=Ww, Wo, Wwf
                    [/filter_location]
                [/not]
            [/filter]

            [if]
                [variable]
                    name=orcs_passive
                    equals=yes
                [/variable]

                [then]
                    [message]
                        speaker=Marg-Tonz
                        message= _ "I told you to stay off our land! Now you’re in for it."
                    [/message]
                    {WAKE_ORCS}
                [/then]

                [else]
                    [allow_undo]
                    [/allow_undo]
                [/else]
            [/if]
        [/event]
    [/event]

    # If a merman lands on a ship, the orcs attack.
    [event]
        name=moveto
        first_time_only=yes

        [filter]
            side=1
            #ship locations
            x=27, 29, 22
            y=10, 9, 5
        [/filter]

        [if]
            [variable]
                name=orcs_passive
                equals=yes
            [/variable]

            [then]
                [message]
                    speaker=Marg-Tonz
                    message= _ "I told not to bother the ships! Now you’re in for it."
                [/message]
                {WAKE_ORCS}
            [/then]

            [else]
                [allow_undo]
                [/allow_undo]
            [/else]
        [/if]
    [/event]

    # If a mermen attacks an orc, the orcs can attack back:
    [event]
        name=attack_end
        first_time_only=yes

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

        [if]
            [variable]
                name=orcs_passive
                equals=yes
            [/variable]

            [then]
                [message]
                    speaker=Marg-Tonz
                    message= _ "You crazy fish men are attacking us? After we tried to be nice? That’s it. We’re going to end you once and for all."
                [/message]
                {WAKE_ORCS}
            [/then]

            [else]
                [allow_undo]
                [/allow_undo]
            [/else]
        [/if]
    [/event]

    # Remove the orcs movement points each turn if the mermen have
    # stayed in the water.
    [event]
        name=turn refresh
        first_time_only=no

        [if]
            [variable]
                name=orcs_passive
                equals=yes
            [/variable]

            [then]
                [store_unit]
                    [filter]
                        side=2
                    [/filter]
                    kill=yes
                    variable=orcs
                [/store_unit]
                {FOREACH orcs orc}
                    [set_variable]
                        name=orcs[$orc].moves
                        value=0
                    [/set_variable]
                    [unstore_unit]
                        variable=orcs[$orc]
                    [/unstore_unit]
                {NEXT orc}
                [clear_variable]
                    name=orcs
                [/clear_variable]
            [/then]
        [/if]
    [/event]

    # When a ghost is killed, check to see if it was the last one. If
    # it was, and the orc is gone, the player wins. Otherwise, he gets
    # the option to kill the orc.
    [event]
        name=die
        first_time_only=no

        [filter]
            side=3
        [/filter]

        [set_variable]
            name=number_of_undead
            sub=1
        [/set_variable]

        [if]
            [variable]
                name=number_of_undead
                equals=0
            [/variable]

            [then]
                [if]
                    [not]
                        [have_unit]
                            id=Marg-Tonz
                        [/have_unit]
                    [/not]

                    [then]
                        [message]
                            speaker=Kai Krellis
                            message= _ "Now maybe we can head west undisturbed."
                        [/message]
                        [endlevel]
                            result=victory
                            {NEW_GOLD_CARRYOVER 40}
                        [/endlevel]
                    [/then]

                    [else]
                        [message]
                            speaker=Kai Krellis
                            message= _ "We have destroyed the undead."
                            [option]
                                message= _ "Now maybe we can head west undisturbed."
                                [command]
                                    [endlevel]
                                        result=victory
                                        bonus=no
                                    [/endlevel]
                                [/command]
                            [/option]
                            [option]
                                message= _ "This orc leader has not learned that threatening merfolk is a bad idea. We shall defeat him before we go."
                            [/option]
                        [/message]
                    [/else]
                [/if]
            [/then]
        [/if]
    [/event]

    # If the ghost are gone, then killing Marg-Tonz ends the level. If
    # they are not, it doesn't.
    [event]
        name=die

        [filter]
            id=Marg-Tonz
        [/filter]

        [item]
            x=$x1
            y=$y1
            image=items/chest.png
        [/item]
        [message]
            speaker=second_unit
            message= _ "It seems that orc was rich! He has a chest here with over 100 pieces of gold!"
        [/message]
        [sound]
            name=gold.ogg
        [/sound]
        [gold]
            side=1
            amount=106
        [/gold]

        [if]
            [variable]
                name=number_of_undead
                equals=0
            [/variable]

            [then]
                [endlevel]
                    result=victory
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/then]
        [/if]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Marg-Tonz
        [/filter]

        [message]
            speaker=Marg-Tonz
            message= _ "I hate mermen!"
        [/message]
    [/event]

    # In the next event, orcs come out of a village and stand next to
    # the keep. The keep disappears one hex at a time, and the orcs go
    # back to the village.
#define REMOVE_KEEP X Y
    [delay]
        time=200
    [/delay]
    [terrain]
        terrain=Re
        x={X}
        y={Y}
    [/terrain]
    [redraw]
    [/redraw]
#enddef

    [event]
        name=turn 2
        [move_unit_fake]
            type=Orcish Grunt
            side=2
            x=36,35,34,34,34
            y=13,18,18,19,20
        [/move_unit_fake]
        [unit]
            type=Orcish Grunt
            x=34
            y=20
            side=2
        [/unit]

        [move_unit_fake]
            type=Orcish Grunt
            side=2
            x=36,37
            y=13,18
        [/move_unit_fake]
        [unit]
            type=Orcish Grunt
            x=37
            y=18
            side=2
        [/unit]

        [move_unit_fake]
            type=Orcish Grunt
            side=2
            x=36,35
            y=13,18
        [/move_unit_fake]
        [unit]
            type=Orcish Grunt
            x=35
            y=18
            side=2
        [/unit]

        {REMOVE_KEEP 36 20}
        {REMOVE_KEEP 35 20}
        {REMOVE_KEEP 35 19}
        {REMOVE_KEEP 36 18}
        {REMOVE_KEEP 36 19}
        {REMOVE_KEEP 37 19}
        {REMOVE_KEEP 37 20}

        # In the following kill events, we need to be careful with
        # which unit we’re killing, because Kai Krellis could be
        # standing where the grunt was supposed to. In that case, the
        # grunt will be misplaced by a hex.
        [kill]
            type=Orcish Grunt
            [filter_location]
                x=34
                y=20
                radius=1
            [/filter_location]
            animate=no
            fire_event=no
        [/kill]
        [move_unit_fake]
            type=Orcish Grunt
            side=2
            x=34,34,34,35,36
            y=20,19,18,18,13
        [/move_unit_fake]

        [kill]
            type=Orcish Grunt
            [filter_location]
                x=35
                y=18
                radius=1
            [/filter_location]
            animate=no
            fire_event=no
        [/kill]
        [move_unit_fake]
            type=Orcish Grunt
            side=2
            x=35,36
            y=18,13
        [/move_unit_fake]

        [kill]
            type=Orcish Grunt
            [filter_location]
                x=37
                y=18
                radius=1
            [/filter_location]
            animate=no
            fire_event=no
        [/kill]
        [move_unit_fake]
            type=Orcish Grunt
            side=2
            x=37,36
            y=18,13
        [/move_unit_fake]
    [/event]

#undef REMOVE_KEEP
#undef CITY_GUARD
#undef GHOST
#undef WRAITH
#undef WAKE_ORCS
    {HERO_DEATHS}
[/scenario]
