#textdomain wesnoth-sotbe
#define BRIDGE_EXPLODE
    [sound]
        name=explosion.ogg
    [/sound]
    [delay]
        time=200
    [/delay]
    [sound]
        name=explosion.ogg
    [/sound]
    [delay]
        time=200
    [/delay]
    [sound]
        name=explosion.ogg
    [/sound]
    [delay]
        time=500
    [/delay]
    [sound]
        name=fire.wav
    [/sound]
    [terrain]
        x=18,18,18,19,19,20,20,20
        y=12,13,14,13,14,12,13,14
        terrain=Ww
    [/terrain]
    [redraw][/redraw]
    [kill]
        x=18,18,18,19,19,20,20,20
        y=12,13,14,13,14,12,13,14
        animate=yes
        fire_event=yes
    [/kill]
    [kill]
        side=1
        x=18,18,18,19,19,20,20,20
        y=12,13,14,13,14,12,13,14
        animate=yes
        fire_event=yes
    [/kill]
    [kill]
        side=1
        x=1-38
        y=15-43
    [/kill]

#enddef

#define CHECK_LIZARD_SAFE
    [store_unit]
        variable="saurians"
        [filter]
            race="lizard"
            x="1-38"
            y="1-12"
        [/filter]
    [/store_unit]
    [set_variable]
        name="i"
        value="0"
    [/set_variable]
    [while]
        [variable]
            less_than="$saurians.length"
            name="i"
        [/variable]
        [do]
            [set_variable]
                add="1"
                name="i"
            [/set_variable]
        [/do]
    [/while]
#enddef

#define ON_THE_BRIDGE DESCRIPTION
    [event]
        first_time_only="no"
        name=moveto
        [filter]
            description={DESCRIPTION}
            x=18,18,18,19,19,20,20,20
            y=12,13,14,13,14,12,13,14
        [/filter]
        {VARIABLE leaders_not_safe T}
        #      [message]
        #         description=Grüü
        #         message= _ "Don't do it now!"
        #      [/message]
    [/event]
#enddef

[scenario]
    id="Saving_Inarix"
    name= _ "Saving Inarix"
    map_data="{campaigns/Son_Of_The_Black_Eye/maps/Prestim.map}"
    turns=16

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

    next_scenario="Clash_of_armies"
    {SCENARIO_MUSIC "loyalists.ogg"}
    {VICTORY_AND_DEFEAT_MUSIC}

    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description= _ "In order to recruit saurians later on, bring Inarix and at least four saurians to the fort on River Gork"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Kapou'e"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Grüü"
                condition=lose
            [/objective]
        [/objectives]
    [/event]

    [side]
        type=Orcish Leader
        description="Kapou'e"
        user_description= _ "Kapou'e"
        side=1
        canrecruit=yes
        controller=human
        recruit= Wolf Rider, Orcish Grunt, Troll Whelp, Orcish Archer
        team_name=Kapoue
        gold=100
        {BLACK_FLAG}

        [village]
            x=11
            y=1
        [/village]

        [village]
            x=10
            y=3
        [/village]

        [village]
            x=14
            y=1
        [/village]

        [village]
            x=12
            y=5
        [/village]

        [village]
            x=14
            y=4
        [/village]

        [village]
            x=15
            y=4
        [/village]

        [village]
            x=22
            y=1
        [/village]

        [village]
            x=24
            y=5
        [/village]

        [village]
            x=25
            y=2
        [/village]

        [village]
            x=26
            y=4
        [/village]

        [village]
            x=27
            y=5
        [/village]

        [village]
            x=28
            y=1
        [/village]
    [/side]

    [side]
        type=Elvish Champion
        description=Thelarion
        user_description= _ "Thelarion"
        side=2
        canrecruit=yes
        [ai]
            aggression=1.0
            recruitment_pattern=scout, scout, fighter, fighter, fighter, healer, archer
            [target]
                type=Saurian
                value=50
            [/target]
        [/ai]
        recruit=Elvish Fighter, Elvish Archer, Elvish Shaman, Elvish Scout
        team_name=vilains
        {GOLD 100 150 200}
        {INCOME 15 30 45}
    [/side]

    [side]
        type=Dwarvish Steelclad
        description=Darstang
        user_description= _ "Darstang"
        side=3
        canrecruit=yes
        [ai]
            recruitment_pattern=scout, fighter, fighter, fighter, mixed fighter, archer
            aggression=1.0
            villages_per_scout=10
            [target]
                type=Saurian
                value=50
            [/target]
        [/ai]
        recruit=Dwarvish Fighter, Dwarvish Thunderer, Footpad, Bandit
        team_name=vilains
        {GOLD 100 150 200}
        {INCOME 15 30 45}
    [/side]

    [story]
        [part]
            background=sotbe3.png
            show_title=yes
            {DOT 463 171}
            {DOT 469 193}
            {DOT 467 217}
            {DOT 458 241}
            {DOT 438 270}
            {DOT 407 297}
            {DOT 372 309}
            {DOT 344 314}
            {DOT 319 324}
            {DOT 318 350}
            {CROSS 318 378}
        [/part]
    [/story]

    [event]
        name=prestart
        [unit]
            type="Orcish Slayer"
            description="Plonk"
            user_description= _ "Plonk"
            x=20
            y=4
        [/unit]
        {RECALL Grüü}
        # wmllint: recognize Grüü
        {WATCH_TOWER 30 5 (Eastern Tower)}
        {WATCH_TOWER 10 4 (Western Tower)}
        {WATCH_TOWER 19 5 (Southern Tower)}
        {ELVISH_FIGHTER_G 19 11}
        {ELVISH_FIGHTER_G 19 12}
        {ELVISH_ARCHER_G 20 11}
        {ELVISH_ARCHER_G 18 11}
        [unit]
            type=Orcish Archer
            side=1
            x=20
            y=6
        [/unit]

        [unit]
            type=Dwarvish Guardsman
            side=3
            x=18
            y=15
            ai_special=guardian
        [/unit]
        [unit]
            type=Dwarvish Guardsman
            side=3
            x=20
            y=15
            ai_special=guardian
        [/unit]

        {VARIABLE elvish_casualties 0}
        {VARIABLE leaders_not_safe F}
    [/event]

    #  Don't blow up the bridge while Grüü or Kapou'e are there.
    {ON_THE_BRIDGE (Grüü)}
    {ON_THE_BRIDGE (Kapou'e)}

    [event]
        name=start
        [message]
            description="Plonk"
            message= _ "Reinforcements, at last! Whoever you are, you are welcome in Prestim! The fortified bridge over the Gork river was taken this morning by a small commando of elves, we have already tried to assault it twice without success."
        [/message]
        [message]
            description="Grüü"
            message= _ "Ah! They are no match against my hammer."
        [/message]
        [message]
            description="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]
            description="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]
            description="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!"
        [/message]
        [message]
            description="Grüü"
            message= _ "I know what we must do. Kill elves and help Inarix cross."
        [/message]
        [message]
            description="Plonk"
            message= _ "It won't be that easy! Our enemies are well entrenched."
        [/message]
        [message]
            description="Plonk"
            message= _ "We will sabotage the southern bridge when the bulk of the Saurian army has crossed. Any warriors trapped on the bridge or on the other side of the river will perish!"
        [/message]
        {VARIABLE saurians_safe 0}

        [message]
            description=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]
            description="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]

        [object]
            silent=yes
            [filter]
                description=Grüü
            [/filter]

            [effect]
                apply_to=status
                remove=poisoned
                duration=level
            [/effect]
        [/object]
    [/event]

    [event]
        name=turn 4

        [unit]
            type=Saurian Ambusher
            description=Inarix
            user_description= _ "Inarix"
            side=1
            random_traits=no
            x=8
            y=42
            [modifications]
                {TRAIT_LOYAL}
            [/modifications]
        [/unit]

        {SAURIAN 8 42}
        {SAURIAN 8 42}
        {SAURIAN 8 42}
        {SAURIAN_HEALER 8 42}
        {SAURIAN_HEALER 8 42}
        {SAURIAN_HEALER 8 42}
        {SAURIAN 8 42}
        {SAURIAN 8 42}
        {SAURIAN 8 42}
        [message]
            description="Inarix"
            message= _ "Here we are, my friends. Earl Lanbec'h and his kind is on our tails, we must hurry up."
        [/message]
    [/event]

    [event]
        first_time_only="no"
        name="new turn"
        [if]
            [variable]
                equals="1"
                name="saurians_safe"
            [/variable]
            [variable]
                equals="F"
                name="leaders_not_safe"
            [/variable]
            [then]
                [role]
                    type=Orcish Slayer, Orcish Assassin, Orcish Warlord, Orcish Warrior, Orcish Grunt, Orcish Crossbowman, Orcish Archer
                    role=engineer
                [/role]

                [message]
                    role=engineer
                    message= _ "The Saurians are safe, Chief, should we blow the bridge?"
                [/message]

                [message]
                    description="Kapou'e"
                    message= _ "Ah...."

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

                        [command]
                            {BRIDGE_EXPLODE}
                            {CLEAR_VARIABLE leaders_not_safe}
                            {CLEAR_VARIABLE saurians_safe}
                            [endlevel]
                                result=victory
                                bonus=yes
                            [/endlevel]
                        [/command]
                    [/option]

                    [option]
                        message= _ "Just wait a sec."
                        [command]
                            [message]
                                role=engineer
                                message= _ "Argh! Hurry up, let's get a move on this!"
                            [/message]

                            [message]
                                description="Kapou'e"
                                message= _ "Shut up, I'm in charge here not you!"
                            [/message]
                        [/command]
                    [/option]
                [/message]
            [/then]
        [/if]
        {CHECK_LIZARD_SAFE}
        [if]
            [variable]
                greater_than="4"
                name="i"
            [/variable]
            [then]
                [message]
                    description="Kapou'e"
                    message= _ "Hurry up! The southern bridge is going to explode! Retreat! "
                [/message]
                {VARIABLE saurians_safe 1}
            [/then]
        [/if]

        [if]
            [variable]
                equals="T"
                name="leaders_not_safe"
            [/variable]
            [then]
                {VARIABLE leaders_not_safe F}
                [message]
                    description=Grüü
                    message= _ "I hurry up!"
                [/message]
            [/then]
        [/if]
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            type=Saurian Skirmisher, Saurian Ambusher, Saurian Flanker, Saurian Augur, Saurian Oricle, Saurian Soothsayer
        [/filter]
        [command]
            [set_variable]
                name=saurian_casualties
                add=1
            [/set_variable]
        [/command]
        [command]
            [if]
                [variable]
                    name=saurian_casualties
                    numerical_equals=6
                [/variable]
                [then]
                    [message]
                        description="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]

                    [set_variable]
                        name=no_saurians
                        value=1
                    [/set_variable]

                    [set_variable]
                        name="i"
                        value="0"
                    [/set_variable]
                    [while]
                        [variable]
                            less_than="$saurians.length"
                            name="i"
                        [/variable]
                        [do]
                            [set_variable]
                                add="1"
                                name="i"
                            [/set_variable]
                        [/do]
                    [/while]
                [/then]
            [/if]
        [/command]
    [/event]

    [event]
        name=turn 8
        [message]
            description=Thelarion
            message= _ "This has taken too much time, we should send all of our troops and send these creatures back to hell."
        [/message]
        [message]
            description=Darstang
            message= _ "It won't be said that Elves were braver than us, everyone attack!"
        [/message]
        [modify_side]
            side=2
            income=100
        [/modify_side]
        [modify_side]
            side=3
            income=100
        [/modify_side]
    [/event]

    [event]
        name=time over
        {CHECK_LIZARD_SAFE}
        [if]
            [variable]
                greater_than="4"
                name="i"
            [/variable]
            [variable]
                equals="F"
                name="leaders_not_safe"
            [/variable]
            [then]
                {BRIDGE_EXPLODE}
                {CLEAR_VARIABLE leaders_not_safe}
                {CLEAR_VARIABLE saurians_safe}
                [endlevel]
                    result=victory
                [/endlevel]
            [/then]
            [else]
                [unit]
                    type="General"
                    description="Earl Lanbec'h"
                    user_description= _ "Earl Lanbec'h"
                    side=2
                    x=8
                    y=42
                [/unit]
                {HEAVY_INFANTRYMAN 8 42}
                {HEAVY_INFANTRYMAN 8 42}
                {HEAVY_INFANTRYMAN 8 42}
                {HEAVY_INFANTRYMAN 8 42}
                {HEAVY_INFANTRYMAN 8 42}
                {HEAVY_INFANTRYMAN 8 42}
                {HEAVY_INFANTRYMAN 8 42}
                [message]
                    speaker="Earl Lanbec'h"
                    message= _ "At the saurians! Rip them to the last!"
                [/message]
                [message]
                    speaker="Kapou'e"
                    message= _ "It is too late, we are defeated."
                [/message]
            [/else]
        [/if]
        {CLEAR_VARIABLE leaders_not_safe}
        {CLEAR_VARIABLE saurians_safe}
    [/event]

    [event]
        name=victory
        [kill]
            description=Eastern Tower
        [/kill]
        [kill]
            description=Western Tower
        [/kill]
        [kill]
            description=Southern Tower
        [/kill]

        [if]
            [variable]
                name=no_saurians
                numerical_equals=0
            [/variable]

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

        {CLEAR_VARIABLE no_saurians}
    [/event]

    {@campaigns/Son_Of_The_Black_Eye/utils/deaths.cfg}
[/scenario]
