#textdomain wesnoth-l
[scenario]
    id=04_Unlawful_Orders
    name= _ "Unlawful Orders"
    next_scenario=05_Hide_and_Seek
    victory_when_enemies_defeated=yes
    map_data="{campaigns/Liberty/maps/04_Unlawful_Orders.map}"
    {TURNS 30 22 16}
    {DEFAULT_SCHEDULE}

    {INTRO_AND_SCENARIO_MUSIC "knolls.ogg" "the_city_falls.ogg"}
    {EXTRA_SCENARIO_MUSIC "the_deep_path.ogg"}
    {EXTRA_SCENARIO_MUSIC "legends_of_the_north.ogg"}
    {EXTRA_SCENARIO_MUSIC "vengeful.ogg"}

    [label]
        x,y=16,15
        text= _ "Elensefar"
    [/label]

    [label]
        x,y=8,13
        text= _ "Port of Elensefar"
    [/label]

    {LIBERTY_BIGMAP {JOURNEY_04_NEW} }

    [side]
        type=Bandit
        id=Baldras
        side=1
        canrecruit=yes
        controller=human
        recruit=Thug,Footpad,Poacher
        {GOLD 200 150 100}
        team_name=good_guys
        user_team_name=_"Rebels"
    [/side]

    {AI_CONTROLLER () 1 2 ()}

    # wmllint: directory spelling Maddock
    [side]
        type=General
        id=Lord Maddock
        name= _ "Lord Maddock"
        profile=portraits/maddock.png
        side=2
        canrecruit=yes
        controller=ai
        recruit=Spearman,Horseman,Cavalryman,Heavy Infantryman,Mage,Bowman
        [ai]
            recruitment_pattern=scout,mixed fighter,fighter,archer,fighter
            leader_value=3
            village_value=0.2
        [/ai]
        {GOLD 100 100 70}
        team_name=good_guys
        user_team_name=_"Rebels"
        {FLAG_VARIANT loyalist}
    [/side]

    {STARTING_VILLAGES 2 15}

    [side]
        type=General
        id=Kestrel
        name= _ "Kestrel"
        side=3
        canrecruit=yes
        controller=ai
        recruit=Spearman,Horseman,Cavalryman,Heavy Infantryman,Dark Adept,Bowman
        [ai]
            caution=0.0
            aggression=1.0
            recruitment_pattern=scout,fighter,fighter,archer,archer
            leader_value=20
        [/ai]
        {GOLD 140 180 260}
        user_team_name=_"Asheviere"
        {FLAG_VARIANT loyalist}
    [/side]

    {STARTING_VILLAGES 3 5}

    #
    # Prestart events
    #
    [event]
        name=prestart

        [objectives]
            side=1
            [objective]
                description= _ "Defeat the enemy general"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Baldras"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Harper"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Maddock"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

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

            {AI_CONTROLLER_NOTE}
        [/objectives]

        [store_unit]
            [filter]
                id=Baldras
            [/filter]

            kill=yes
            variable=stored_Baldras
        [/store_unit]

        {VARIABLE stored_Baldras.facing sw}

        {NAMED_LOYAL_UNIT 3 Lieutenant 17 39 Rothel (_ "Rothel")}
        [+unit]
            [modifications]
                {TRAIT_QUICK}
            [/modifications]
        [/unit]
    [/event]

    #
    # Starting conversation and actions
    #
    [event]
        name=start

        [move_unit_fake]
            side=1
            type=Boat
            x=25,23
            y= 9,11
        [/move_unit_fake]

        [item]
            x,y=23,11
            image=units/transport/boat.png~FL(horiz)
        [/item]

        [move_unit_fake]
            side=1
            type=$stored_Baldras.type
            x=23,21
            y=11,11
        [/move_unit_fake]

        [unstore_unit]
            variable=stored_Baldras
        [/unstore_unit]

        [recall]
            id=Harper
        [/recall]
        [role]
            type=Huntsman,Ranger,Fugitive,Highwayman,Outlaw,Trapper,Bandit,Footpad,Poacher,Thug
            role=Advisor
            [auto_recall][/auto_recall]
            [not]
                id=Harper,Baldras
            [/not]
        [/role]

        [message]
            speaker=Lord Maddock
            message= _ "Baldras, your trip here was not wise. The Queen’s patrols have been visiting the local villages and bringing the elders here. Those that swear allegiance to the Queen are allowed to return home. Those that do not—"
        [/message]
        [message]
            speaker=Baldras
            message= _ "— Are dispatched on the spot. I know the price of dissent. But what of you?"
        [/message]
        [message]
            speaker=Lord Maddock
            message= _ "Well, they do not come within the walls of my city. They are actually camped nearby, and the main garrison is further south at Halstead. I know my time will soon come to swear allegiance, but they do not press me. They are afraid I will refuse."
        [/message]
        [message]
            speaker=Baldras
            message= _ "Will you?"
        [/message]
        [message]
            speaker=Lord Maddock
            message= _ "Yes. The Queen ascended to the throne through the vilest of treachery. However, while most of my forces were sent with the King to fight the orcs, we have a strong enough contingent here to make the Queen’s forces think twice about attacking Elensefar outright."
        [/message]
        [message]
            speaker=Lord Maddock
            message= _ "We have an uneasy peace until they are done with the smaller villages and finally come around to obtaining my oath. The treaty between Elensefar and Wesnoth is ancient, but I am not so naïve as to place my full trust in it. Not in these wicked times."
        [/message]
        [message]
            speaker=Harper
            message= _ "What can we do then? We have brought with us many from Annuvin Province who are willing to fight, but our families are still at home. They will not last long if the Queen’s patrols return."
        [/message]
        [message]
            speaker=Lord Maddock
            message= _ "I am unwilling to start a civil war. I believe the Queen will remain preoccupied with order throughout the kingdom and, more importantly, with quelling the Northerner threat. We are a matter she will choose to deal with later rather than sooner, if she can."
        [/message]
        [message]
            speaker=Kestrel
            message= _ "A foolish miscalculation, Lord Maddock. These men with which you consort are outlaws and fugitives. They are a well-organized gang of criminals and murderers. We will kill them and then expect your oath of allegiance to Queen Asheviere."
        [/message]
        [message]
            speaker=Lord Maddock
            message= _ "Men, to arms! The defense of Elensefar has begun!"
        [/message]

        {CLEAR_VARIABLE stored_Baldras}
    [/event]

    #
    # Special event - the human enemies become undead at night
    #

    [event]
        name=turn 4

        [music]
            name="frantic.ogg"
        [/music]

        [message]
            speaker=narrator
            message= _ "As the sun set, a horrific change began to take place to the human adversaries of Baldras and his allies..."
            image="wesnoth-icon.png"
        [/message]
    [/event]

    [event]
        name=prestart

        [set_variables]
            name=undead_transformation

            [value]
                human_type=Spearman
                undead_type=Skeleton
            [/value]
            [value]
                human_type=Swordsman
                undead_type=Deathblade
            [/value]
            [value]
                human_type=Pikeman
                undead_type=Revenant
            [/value]
            [value]
                human_type=Bowman
                undead_type=Skeleton Archer
            [/value]
            [value]
                human_type=Longbowman
                undead_type=Bone Shooter
            [/value]
            [value]
                human_type=Heavy Infantryman
                undead_type=Ghoul
            [/value]
            [value]
                human_type=Shock Trooper
                undead_type=Necrophage
            [/value]
            [value]
                human_type=Cavalryman
                undead_type=Skeleton Rider
            [/value]
            [value]
                human_type=Dragoon
                undead_type=Bone Knight
            [/value]
            [value]
                human_type=Lieutenant
                undead_type=Death Squire
            [/value]
            [value]
                human_type=General
                undead_type=Death Knight
            [/value]
            [value]
                human_type=Horseman
                undead_type=Skeleton Rider
            [/value]
            [value]
                human_type=Knight
                undead_type=Bone Knight
            [/value]
            [value]
                human_type=Lancer
                undead_type=Bone Knight
            [/value]
        [/set_variables]
    [/event]

#define FALLBACK
    [if]
        [variable]
            name=type_to_turn_into
            equals=$null
        [/variable]
        [then]
            [wml_message]
                logger=error
                message=_"Could not convert a $stored_changers[$i].type, please report!"
            [/wml_message]
            {VARIABLE type_to_turn_into $stored_changers[$i].type}
        [/then]
    [/if]
#enddef
    [event]
        name=new turn
        first_time_only=no

        {VARIABLE temp $turn_number}
        {VARIABLE_OP temp add 2}
        {VARIABLE_OP temp modulo 6}

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

            [variable]
                name=turn_number
                greater_than_equal_to=4
            [/variable]

            [then]
                [color_adjust]
                    red=255
                    green=100
                    blue=100
                [/color_adjust]
                [delay]
                    time=10
                [/delay]
                [color_adjust]
                    red=0
                    green=0
                    blue=0
                [/color_adjust]
                [redraw]
                [/redraw]

                [disallow_recruit]
                    side=3
                    type=Spearman,Horseman,Cavalryman,Heavy Infantryman,Dark Adept,Bowman
                [/disallow_recruit]
                [allow_recruit]
                    side=3
                    type=Skeleton,Skeleton Rider,Dark Adept,Skeleton Archer
                [/allow_recruit]

                [store_unit]
                    [filter]
                        side=3

                        [not]
                            type=Dark Adept,Dark Sorcerer
                        [/not]
                    [/filter]

                    kill=yes
                    variable=stored_changers
                [/store_unit]

                [for]
                    array=stored_changers
                    variable=i
                    [do]
                        [for]
                            array=undead_transformation
                            variable=j
                            [do]
                                [if]
                                    [variable]
                                        name=stored_changers[$i].type
                                        equals=$undead_transformation[$j].human_type
                                    [/variable]

                                    [then]
                                        {VARIABLE type_to_turn_into $undead_transformation[$j].undead_type}
                                        {VARIABLE j 999}
                                    [/then]
                                [/if]
                            [/do]
                        [/for]

                        {FALLBACK}
                        [unit]
                            type=$type_to_turn_into
                            side=3
                            x,y=$stored_changers[$i].x,$stored_changers[$i].y
                            id=$stored_changers[$i].id
                            name=$stored_changers[$i].name
                            experience=$stored_changers[$i].experience
                            hitpoints=$stored_changers[$i].hitpoints
                            canrecruit=$stored_changers[$i].canrecruit
                            [variables]
                                [insert_tag]
                                    name=stored_trait
                                    variable=stored_changers[$i].modifications.trait
                                [/insert_tag]

                                turned_to_undead_at_least_once=yes
                            [/variables]
                            to_variable=changer
                        [/unit]
                        {CLEAR_VARIABLE type_to_turn_into}

                        [if]
                            [variable]
                                name=changer.hitpoints
                                greater_than=$changer.max_hitpoints
                            [/variable]

                            [then]
                                {VARIABLE changer.hitpoints $changer.max_hitpoints}
                            [/then]
                        [/if]

                        [unstore_unit]
                            variable=changer
                        [/unstore_unit]
                    [/do]
                [/for]

                {CLEAR_VARIABLE stored_changers,changer}
            [/then]
        [/if]
    [/event]

    [event]
        name=new turn
        first_time_only=no

        {VARIABLE temp $turn_number}
        {VARIABLE_OP temp modulo 6}

        [if]
            [variable]
                name=temp
                equals=1
            [/variable]

            [variable]
                name=turn_number
                greater_than_equal_to=4
            [/variable]

            [then]
                [color_adjust]
                    red=255
                    green=255
                    blue=100
                [/color_adjust]
                [delay]
                    time=10
                [/delay]
                [color_adjust]
                    red=0
                    green=0
                    blue=0
                [/color_adjust]
                [redraw]
                [/redraw]

                [disallow_recruit]
                    side=3
                    type=Skeleton,Skeleton Rider,Dark Adept,Skeleton Archer
                [/disallow_recruit]
                [allow_recruit]
                    side=3
                    type=Spearman,Horseman,Cavalryman,Heavy Infantryman,Dark Adept,Bowman
                [/allow_recruit]

                [store_unit]
                    [filter]
                        side=3

                        [not]
                            type=Dark Adept,Dark Sorcerer
                        [/not]
                    [/filter]

                    kill=yes
                    variable=stored_changers
                [/store_unit]

                [for]
                    array=stored_changers
                    [do]
                        [for]
                            array=undead_transformation
                            variable=j
                            [do]
                                [if]
                                    [variable]
                                        name=stored_changers[$i].type
                                        equals=$undead_transformation[$j].undead_type
                                    [/variable]

                                    [then]
                                        {VARIABLE type_to_turn_into $undead_transformation[$j].human_type}
                                        [break][/break]
                                    [/then]
                                [/if]
                            [/do]
                        [/for]

                        {FALLBACK}
                        [if]
                            [variable]
                                name=stored_changers[$i].variables.turned_to_undead_at_least_once
                                equals=yes
                            [/variable]

                            [then]
                                [unit]
                                    type=$type_to_turn_into
                                    side=3
                                    x,y=$stored_changers[$i].x,$stored_changers[$i].y
                                    id=$stored_changers[$i].id
                                    name=$stored_changers[$i].name
                                    experience=$stored_changers[$i].experience
                                    hitpoints=$stored_changers[$i].hitpoints
                                    canrecruit=$stored_changers[$i].canrecruit
                                    [modifications]
                                        [insert_tag]
                                            name=trait
                                            variable=stored_changers[$i].variables.stored_trait
                                        [/insert_tag]
                                    [/modifications]
                                    [variables]
                                        turned_to_undead_at_least_once=yes
                                    [/variables]
                                    to_variable=changer
                                [/unit]
                            [/then]

                            [else]
                                [unit]
                                    type=$type_to_turn_into
                                    side=3
                                    x,y=$stored_changers[$i].x,$stored_changers[$i].y
                                    experience=$stored_changers[$i].experience
                                    hitpoints=$stored_changers[$i].hitpoints
                                    canrecruit=$stored_changers[$i].canrecruit
                                    random_traits=yes
                                    generate_name=yes
                                    to_variable=changer
                                [/unit]
                            [/else]
                        [/if]
                        {CLEAR_VARIABLE type_to_turn_into}

                        [if]
                            [variable]
                                name=changer.hitpoints
                                greater_than=$changer.max_hitpoints
                            [/variable]

                            [then]
                                {VARIABLE changer.hitpoints $changer.max_hitpoints}
                            [/then]
                        [/if]

                        [unstore_unit]
                            variable=changer
                        [/unstore_unit]
                    [/do]
                [/for]

                {CLEAR_VARIABLE stored_changers,changer}
            [/then]
        [/if]
    [/event]
#undef FALLBACK

    [event]
        name=turn 4
        [message]
            speaker=Harper
            message= _ "I cannot believe what my eyes are seeing! The flesh runs from their bones... these are not human warriors we fight. They are evil spirits masquerading as human!"
        [/message]
    [/event]

    [event]
        name=turn 7
        [music]
            name="knolls.ogg"
        [/music]
        [message]
            speaker=Lord Maddock
            message= _ "Their human aspect is returning! This is an evil manner of sorcery we face, but one that we may yet overcome. CHARGE!"
        [/message]
    [/event]

    #
    # Victory
    #
    [event]
        name=last breath
        [filter]
            id=Kestrel
        [/filter]
        [message]
            speaker=second_unit
            message= _ "Who are you? What are you?"
        [/message]
        [message]
            speaker=Kestrel
            message= _ "We are accursed. We were once under the command of Prince Eldred, the King’s son and betrayer. The price for our treason is this hellish existence. We know not who or what inflicted this curse upon us, but our mortal deaths may be only the beginning of the penance we are doomed to pay."
        [/message]

        [kill]
            id=Kestrel
            animate=yes
            fire_event=no
        [/kill]

        [message]
            speaker=Baldras
            message= _ "Lord Maddock, now that we are victorious, will you help us?"
        [/message]
        [message]
            speaker=Lord Maddock
            message= _ "I will not. Unless you want me to round up the city’s thieves to fight for you, I do not have the troops to spare. However, I am not the only one who commands men in this corner of Wesnoth."
        [/message]
        [message]
            speaker=Baldras
            message= _ "I don’t understand. There are no other noble lords in this area."
        [/message]
        [message]
            speaker=Lord Maddock
            message= _ "Southeast of here there is a town, and there you may find assistance of the type I cannot give."
        [/message]
        [message]
            speaker=Baldras
            message= _ "Wish us well. If we are to resist the Wesnoth army a second time, we’re going to need more than clubs and slings against steel."
        [/message]

        {CLEAR_VARIABLE undead_transformation}
        {CLEAR_VARIABLE temp}

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

    #
    # Loss conditions - turns run out
    #
    [event]
        name=time over
        [message]
            speaker=Baldras
            message= _ "Look, more riders come from the southeast. We cannot survive another assault. We are finished!"
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=defeat

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message=_ "Indeed, Asheviere’s armies had mustered and struck before the nascent rebellion could even be planned. Her power and ruthlessness — and their toll of death — would only grow greater with time."
        [/message]
    [/event]

    {LIBERTY_DEATHS}
[/scenario]
