#textdomain wesnoth-sotbe

#define NOT_SAFE_LOCATIONS
    y=12-43
    [not]
        x,y=19,12
    [/not]
#enddef

[scenario]
    id=10_Saving_Inarix
    name= _ "Saving Inarix"
    map_file=10_Saving_Inarix.map
    turns=16

    {DEFAULT_SCHEDULE_AFTERNOON}

    victory_when_enemies_defeated=no

    next_scenario=11_Clash_of_Armies

    {SCENARIO_MUSIC "vengeful.ogg"}
    {EXTRA_SCENARIO_MUSIC "breaking_the_chains.ogg"}

    [event]
        name=turn 1

        [objectives]
            side=1
            [objective]
                description= _ "Wait for Inarix’s arrival from the south on turn 4"
                condition=win
                [show_if]
                    [variable]
                        name=turn_number
                        less_than=4
                    [/variable]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Destroy the southern part of the bridge"
                condition=win
            [/objective]
            [objective]
                description= _ "In order to recruit saurians later on, bring Inarix and at least four saurians to safety"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Kapou’e"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Grüü"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

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

            [note]
                description= _ "Whoever detonates the bridge will die."
            [/note]
        [/objectives]
    [/event]

    [side]
        side=1
        id="Kapou'e"
        type=Orcish Leader
        controller=human
        team_name=Kapoue
        user_team_name=_ "Kapou’e"
        {GOLD 210 180 150}
        {BLACK_FLAG}
    [/side]

    {STARTING_VILLAGES 1 10}
    {STARTING_VILLAGES_AREA 1 5 5 4}
    {STARTING_VILLAGES_AREA 1 35 5 4}

    [side]
        type=Elvish Champion
        id=Thelarion
        name= _ "Thelarion"
        side=2
        canrecruit=yes
        facing=sw
        [ai]
            aggression=1.0
            villages_per_scout=10
            village_value=0.1
            [goal] # Target Inarix with same value as Kapou'e
                name=target
                [criteria]
                    id=Inarix
                [/criteria]
                value=3
            [/goal]
        [/ai]
        recruit=Elvish Fighter, Elvish Archer, Elvish Shaman, Elvish Scout
        team_name=villains
        user_team_name=_"Villains"
        {GOLD 400 500 600}
        {INCOME 15 20 25}
        {FLAG_VARIANT wood-elvish}
    [/side]

    {STARTING_VILLAGES 2 13}

    [side]
        type=Dwarvish Steelclad
        id=Darstang
        name= _ "Darstang"
        side=3
        canrecruit=yes
        [ai]
            aggression=1.0
            villages_per_scout=10
            village_value=0.1
            [goal] # Target Inarix with same value as Kapou'e
                name=target
                [criteria]
                    id=Inarix
                [/criteria]
                value=3
            [/goal]
        [/ai]
        recruit=Dwarvish Fighter, Dwarvish Thunderer, Dwarvish Scout, Footpad, Bandit
        team_name=villains
        user_team_name=_"Villains"
        {GOLD 400 500 600}
        {INCOME 15 20 25}
        {FLAG_VARIANT knalgan}
    [/side]

    {STARTING_VILLAGES 3 13}

    {SOTBE_TRACK {JOURNEY_10_NEW} }

    [event]
        name=prestart
        {NAMED_LOYAL_UNIT 1 (Orcish Slayer) 20 4 Plonk (_ "Plonk")}
        [+unit]
            random_traits=no
        [/unit]

        {GENERIC_UNIT 2 "Elvish Fighter" 19 11} {GUARDIAN}
        {GENERIC_UNIT 2 "Elvish Fighter" 19 12} {GUARDIAN}
        {GENERIC_UNIT 2 "Elvish Archer" 20 11} {GUARDIAN}
        {GENERIC_UNIT 2 "Elvish Archer" 18 11} {GUARDIAN}

        [unit]
            type=Dwarvish Guardsman
            side=3
            x=17
            y=15
            generate_name=yes
            ai_special=guardian
        [/unit]
        [unit]
            type=Dwarvish Guardsman
            side=3
            x=21
            y=15
            generate_name=yes
            ai_special=guardian
            facing=sw
        [/unit]

        [item]
            x,y=21,13
            image=items/barrel-floating.png
        [/item]
    [/event]

    [event]
        name=start

        [recall]
            id=Grüü
        [/recall]
        [recall]
            id=Jetto
        [/recall]

        [message]
            speaker="Plonk"
            message= _ "Reinforcements, at last! Whoever you are, you are welcome in Prestim! The fortified bridge over the River Bork was taken this morning by a small commando of elves. We have already tried to assault it twice without success."
        [/message]
        [message]
            speaker="Grüü"
            message= _ "Ah! They are no match against my hammer."
        [/message]
        [message]
            speaker="Plonk"
            message= _ "There is worse; our scouts report that our saurian allies led by Inarix are still trapped on the other side of the river some miles away. They won’t be able to cross the river."
        [/message]
        [message]
            speaker="Plonk"
            message= _ "Elves and dwarves have joined humans against us and have set up camp nearby. Humans will arrive soon. We must destroy the southern bridge on the river."
        [/message]
        [message]
            speaker="Kapou'e"
            message= _ "If Inarix falls prey to those humans, then we won’t be able to count on their help in this struggle. We must do something!"
            image=portraits/kapoue-angry.webp
        [/message]
        [message]
            speaker="Grüü"
            message= _ "I know what we must do. Kill elves and help Inarix cross."
        [/message]
        [message]
            speaker="Plonk"
            message= _ "It won’t be that easy! Our enemies are well entrenched."
        [/message]
        [message]
            speaker="Plonk"
            message= _ "We can capture the southern bridge and keep it open for the saurians. When the bulk of them have crossed, someone needs to go and light the barrel of oil we have set up beside the bridge to destroy it. Any warriors trapped on the bridge or on the other side of the river will perish!"
        [/message]

        {HIGHLIGHT_IMAGE 21 13 items/barrel-floating.png ()}

        [message]
            speaker=Thelarion
            message= _ "Hey look, that tribe of orcs that destroyed my enclave in the Silent Forest have reinforced Prestim. It is time to avenge the death of our fallen kin my friends — get them!"
        [/message]
        [message]
            speaker="Kapou'e"
            message= _ "Ahhh, it’s ‘the Prince’ from the Silent Forest. Unfortunately, I don’t think we can deal with him now, we have to focus on saving Inarix."
        [/message]
    [/event]

    [event]
        name=turn 4

        {NAMED_LOYAL_UNIT 1 (Saurian Ambusher) 8 42 Inarix (_ "Inarix")}
        [+unit]
            random_traits=no
            profile=portraits/inarix.webp
            unrenamable=yes
        [/unit]

        {GENERIC_UNIT 1 "Saurian Skirmisher" 8 42}
        {GENERIC_UNIT 1 "Saurian Skirmisher" 8 42}
        {GENERIC_UNIT 1 "Saurian Skirmisher" 8 42}
        {GENERIC_UNIT 1 "Saurian Augur"      8 42}
        {GENERIC_UNIT 1 "Saurian Augur"      8 42}
        {GENERIC_UNIT 1 "Saurian Augur"      8 42}
        {GENERIC_UNIT 1 "Saurian Skirmisher" 8 42}
        {GENERIC_UNIT 1 "Saurian Skirmisher" 8 42}
        {GENERIC_UNIT 1 "Saurian Skirmisher" 8 42}

        [message]
            speaker="Inarix"
            message= _ "Hurry-hurry, friends. Lanbec’h and his kind are right on our tails, we must reach Prestim quickly."
        [/message]
    [/event]

    [event]
        name=bridge explode

        [store_locations]
            y=12-14
            terrain=*^B*

            variable=exploding_hexes
        [/store_locations]

        [remove_item]
            x,y=21,13
        [/remove_item]

        [item]
            x,y=21,13
            halo=projectiles/fire-burst-small-[1~8].png:50,misc/blank-hex.png:1000000
        [/item]

        [kill]
            x,y=21,13
            animate=yes
            fire_event=yes
        [/kill]

        [foreach]
            array=exploding_hexes
            [do]
                [sound]
                    name=explosion.ogg
                [/sound]

                [item]
                    x,y=$this_item.x,$this_item.y
                    halo=projectiles/fire-burst-small-[1~8].png:50,misc/blank-hex.png:1000000
                [/item]

                [kill]
                    x,y=$this_item.x,$this_item.y
                    animate=yes
                    fire_event=yes
                [/kill]

                [terrain]
                    x,y=$this_item.x,$this_item.y
                    terrain=Ww^Es
                [/terrain]

                [sound]
                    name=water-blast.wav
                [/sound]

                [redraw]
                [/redraw]
            [/do]
        [/foreach]

        [kill]
            side=1
            x=1-38
            y=15-43
            animate=no
            fire_event=yes
        [/kill]

        {CLEAR_VARIABLE exploding_hexes}
    [/event]

    [event]
        name=moveto
        first_time_only=no

        [filter]
            x,y=21,13
            id="Kapou'e"
        [/filter]

        [message]
            speaker="Kapou'e"
            message= _ "Bah! I’m not going to blow myself to bits!"
        [/message]

        [allow_undo]
        [/allow_undo]
    [/event]

    [event]
        name=moveto
        first_time_only=no

        [filter]
            x,y=21,13
            id=Grüü
        [/filter]

        [message]
            speaker="Kapou'e"
            message= _ "Grüü, stay away from that thing! I still have a use for you!"
            image=portraits/kapoue-angry.webp
        [/message]

        [message]
            speaker="Grüü"
            message= _ "Uh... Fine, Chief!"
        [/message]

        [allow_undo]
        [/allow_undo]
    [/event]

    [event]
        name=moveto
        first_time_only=no

        [filter]
            x,y=21,13
            id=Inarix
        [/filter]

        [message]
            speaker="Inarix"
            message= _ "I’m not going to do it!"
        [/message]

        [allow_undo]
        [/allow_undo]
    [/event]

    [event]
        name=moveto
        first_time_only=no

        [filter]
            side=1
            x,y=21,13

            [not]
                id="Kapou'e,Grüü,Inarix"
            [/not]
        [/filter]

        [if]
            [have_unit]
                id="Kapou'e"
                {NOT_SAFE_LOCATIONS}
            [/have_unit]

            [then]
                [message]
                    speaker="Kapou'e"
                    message= _ "Get away from there you idiot, I’m still over here!"
                    image=portraits/kapoue-angry.webp
                [/message]
            [/then]
        [/if]

        [if]
            [have_unit]
                id=Grüü
                {NOT_SAFE_LOCATIONS}
            [/have_unit]

            [then]
                [message]
                    speaker="Grüü"
                    message= _ "Hey, don’t light it up, I’m not safe!"
                [/message]
            [/then]
        [/if]

        [if]
            [not]
                [have_unit]
                    id="Kapou'e,Grüü"
                    {NOT_SAFE_LOCATIONS}
                [/have_unit]
            [/not]

            [then]
                [if]
                    [variable]
                        name=turn_number
                        less_than=4
                    [/variable]

                    [then]
                        [message]
                            speaker="Grüü"
                            #po: To "blow up" means "to make something explode".
                            message= _ "Chief, we can’t be blowing up the bridge before Inarix is here, can we?"
                        [/message]
                    [/then]

                    [else]
                        [if]
                            [have_unit]
                                id=Inarix
                                {NOT_SAFE_LOCATIONS}
                            [/have_unit]

                            [then]
                                {VARIABLE unit_detonating_says _"Chief, Inarix hasn’t yet made it across! Are you really sure you want to do this?"}
                            [/then]

                            [else]
                                {VARIABLE unit_detonating_says _"I’m ready, Chief!"}
                            [/else]
                        [/if]

                        [message]
                            speaker=unit
                            message=$unit_detonating_says

                            [option]
                                label= _ "Let her blow!"

                                [command]
                                    [message]
                                        speaker="Grüü"
                                        message= _ "Bye bye, $unit.name|!"
                                    [/message]

                                    [if]
                                        [have_unit]
                                            id=Inarix
                                            {NOT_SAFE_LOCATIONS}
                                        [/have_unit]

                                        [then]
                                            [message]
                                                speaker=Inarix
                                                message= _ "Damn you, Son of the Black-Eye! You’ll pay for this!"
                                            [/message]

                                            {VARIABLE inarix_abandoned yes}
                                            {VARIABLE got_saurians no}
                                        [/then]

                                        [else]
                                            [message]
                                                side=1
                                                {NOT_SAFE_LOCATIONS}
                                                [not]
                                                    x,y=21,13
                                                [/not]
                                                message= _ "No, wait!"
                                            [/message]
                                        [/else]
                                    [/if]

                                    [message]
                                        speaker=unit
                                        message= _ "Aaaaaaaargh!"
                                    [/message]

                                    [fire_event]
                                        name=bridge explode
                                    [/fire_event]

                                    [endlevel]
                                        result=victory
                                        bonus=yes
                                        {NEW_GOLD_CARRYOVER 40}
                                    [/endlevel]
                                [/command]
                            [/option]

                            [option]
                                label= _ "Wait a moment."

                                [command]
                                    [message]
                                        speaker=unit
                                        message= _ "<i>Phew!</i>"
                                    [/message]
                                [/command]
                            [/option]
                        [/message]

                        {CLEAR_VARIABLE unit_detonating_says}
                    [/else]
                [/if]
            [/then]
        [/if]

        [allow_undo]
        [/allow_undo]
    [/event]

    [event]
        name=die
        first_time_only=no

        [filter]
            side=1
            race=lizard

            [not]
                id=Inarix
            [/not]
        [/filter]

        [store_unit]
            [filter]
                side=1
                race=lizard

                [not]
                    id=Inarix
                [/not]
            [/filter]

            kill=no
            variable=stored_saurians
        [/store_unit]

        [if]
            [variable]
                name=stored_saurians.length
                less_than=5
            [/variable]

            [variable]
                name=got_saurians
                not_equals=no
            [/variable]

            [then]
                [message]
                    speaker="Kapou'e"
                    message= _ "Blast it! The saurians have had too many casualties in order for them to be of any real help to us. We won’t be able to recruit them in the future."
                [/message]

                {VARIABLE got_saurians no}
            [/then]
        [/if]

        {CLEAR_VARIABLE stored_saurians}
    [/event]

    [event]
        name=recruit
        first_time_only=no

        [filter]
            side=2,3
        [/filter]

        [store_side]
            side=$unit.side
        [/store_side]

        [if]
            [variable]
                name=side.gold
                {QUANTITY less_than 300 350 400}  # Starting gold is +100 per difficulty level, so this is correct in this order
            [/variable]
            [variable]
                name=turn_number
                less_than=8
            [/variable]
            [then]
                [disallow_recruit]
                    side=$unit.side
                    type=$side.recruit
                [/disallow_recruit]
            [/then]
        [/if]

        {CLEAR_VARIABLE side}
    [/event]

    [event]
        name=side 2 turn 8
        [message]
            speaker=Thelarion
            message= _ "This isn’t working. Mobilize all our troops and send these creatures back to hell."
        [/message]
        [message]
            speaker=Darstang
            message= _ "It won’t be said that Elves were braver than us, everyone attack!"
        [/message]

        [allow_recruit]
            side=2
            type=Elvish Fighter, Elvish Archer, Elvish Shaman, Elvish Scout
        [/allow_recruit]
        [allow_recruit]
            side=3
            type=Dwarvish Fighter, Dwarvish Thunderer, Dwarvish Scout, Footpad, Bandit
        [/allow_recruit]
    [/event]

    [event]
        name=time over

        [unit]
            type="General"
            id="Earl Lanbec'h"
            name= _ "Earl Lanbec’h"
            profile=portraits/lanbech.webp
            side=2
            x=8
            y=42
            random_traits=no
        [/unit]
        {GENERIC_UNIT 2 "Heavy Infantryman" 8 42}
        {GENERIC_UNIT 2 "Heavy Infantryman" 8 42}
        {GENERIC_UNIT 2 "Heavy Infantryman" 8 42}
        {GENERIC_UNIT 2 "Heavy Infantryman" 8 42}
        {GENERIC_UNIT 2 "Heavy Infantryman" 8 42}
        {GENERIC_UNIT 2 "Heavy Infantryman" 8 42}
        {GENERIC_UNIT 2 "Heavy Infantryman" 8 42}
        [message]
            speaker="Earl Lanbec'h"
            message= _ "At them! Rip them to the last!"
        [/message]
        [message]
            speaker="Kapou'e"
            message= _ "It is too late, we are defeated."
        [/message]
    [/event]

    [event]
        name=victory

        [unit]
            type="General"
            id="Earl Lanbec'h"
            name= _ "Earl Lanbec’h"
            profile=portraits/lanbech.webp
            side=2
            x=8
            y=42
            random_traits=no
        [/unit]

        [message]
            speaker="Earl Lanbec'h"
            message= _ "So, the elves and dwarves failed to take the fortress and the beasts were able to muster a defense. No matter. Once the vanguard of my army arrives, I will storm their pitiful fortress myself."
        [/message]

        [if]
            [variable]
                name=got_saurians
                not_equals=no
            [/variable]

            [then]
                [allow_recruit]
                    side=1
                    type=Saurian Skirmisher,Saurian Augur
                [/allow_recruit]
            [/then]
        [/if]

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

            [then]
                [kill]
                    race=lizard
                    fire_event=no
                    animate=no
                [/kill]
            [/then]
        [/if]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Thelarion
        [/filter]
        [message]
            speaker=unit
            message= _ "The green earth will curse you for this..."
        [/message]
        {VARIABLE thelarion_dead yes}
    [/event]

    [event]
        name=last breath
        [filter]
            id=Darstang
        [/filter]
        [message]
            speaker=unit
            message= _ "Curse you, foul orc!"
        [/message]
        {VARIABLE darstang_dead yes}
    [/event]

    {HERO_DEATHS}
[/scenario]
