#textdomain wesnoth-sota

# Ras-Tahban starts in the keep, and the DAs are in castle tiles. It looks better with
# the keep not actually attached to the castle. So, to make the castle tiles function,
# there is an invisible castle overlay on one of the grass tiles in between the two (3,10)
# making the castle continuous. Nothing is supposed to be recruited on the grass tile
# with the overlay, so the loyal kids are both set to start on it to block it. But, the
# kids may be dead. In that case, a dummy unit is used. Its image is an empty .png,
# and has no movement points. It is petrified so it can't be attacked, and It is deleted
# after the first turn (when no more recruits are possible.)

[scenario]
    name= _ "Training Session"
    map_file=09_Training_Session.map

    id=09_Training_Session
    next_scenario=10_Merfolk_Revenge
    victory_when_enemies_defeated=no

    [story]
        [part]
            [background_layer]
                image=portraits/humans/dark-adept.webp
                scale=no
            [/background_layer]
            story= _ "Ras-Tabahn’s offer enticed a large group of youngsters all eager to train as magi. The fact that it was illicit training in the dark arts was unimportant. More important was the escape from the drudgery of a fixed future, planned in advance by their parents. Ras-Tabahn spent a number of days in the forest outside of Carcyn instructing them on how to call on the spirit world and channel a small amount of its power. Soon after they moved on, they came across three farmsteads on the riverbank that had clearly been raided."
        [/part]
        {JOURNEY_PART 9}
    [/story]

    {DEFAULT_SCHEDULE}
    {DEFAULT_MUSIC_PLAYLIST}
    turns=unlimited

    # wmllint: validate-off
    [side]
        {SIDE_1_RAS-TABAHN}
        {RAS-TABAHN_RECRUIT_1}
        gold=0
    [/side]
    # wmllint: validate-on

    [side]
        side=2
        controller=ai
        no_leader=yes
        gold=0
        color=black
        hidden=yes
        [ai]
            aggression=0.6
        [/ai]
    [/side]

    # *************************** MACROS ***************************

    # This macro is the same for all difficulty levels.
#define PLACE_CORPSE_1 X Y
    [unit]
        x,y={X},{Y}
        type=Soulless
        side=2
    [/unit]
#enddef

    # This macro uses a different unit type for EASY difficulty level.
#ifdef EASY
#define PLACE_CORPSE_2 X Y
    [unit]
        x,y={X},{Y}
        type=Walking Corpse
        side=2
    [/unit]
#enddef
#else
#define PLACE_CORPSE_2 X Y
    [unit]
        x,y={X},{Y}
        type=Soulless
        side=2
    [/unit]
#enddef
#endif

    # This uses a different unit type for HARD difficulty level.
#ifdef HARD
#define PLACE_CORPSE_3 X Y
    [unit]
        x,y={X},{Y}
        type=Soulless
        side=2
    [/unit]
#enddef
#else
#define PLACE_CORPSE_3 X Y
    [unit]
        x,y={X},{Y}
        type=Walking Corpse
        side=2
    [/unit]
#enddef
#endif

#define PLACE_DARK_ADEPT X Y TRAIT1 TRAIT2 GENDER
    [unit]
        x={X}
        y={Y}
        type=SotA Dark Adept
        side=1
        moves=0
        gender={GENDER}  # Otherwise, they're all male, and there's no reason for that.
        [modifications]
            {TRAIT_{TRAIT1}}
            {TRAIT_{TRAIT2}}
        [/modifications]
        facing=sw
        role=trainee
    [/unit]
#enddef

    # *************************** PRESTART ***************************
    [event]
        name=prestart

        # Gold is removed now, and will be returned later.
        [store_gold]
            side=1
            variable=rastabahn_gold
        [/store_gold]

        # This is exactly enough to recall five units.
        [modify_side]
            side=1
            gold=100
        [/modify_side]

        [objectives]
            side=1
            [objective]
                description= _ "Destroy all the undead units" + {OBJECTIVE_FOOTNOTE _"(there will be three waves)"}
                condition=win
            [/objective]
            [objective]
                description= _ "Death of all five dark adepts"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Ras-Tabahn"
                condition=lose
            [/objective]

            [gold_carryover]
                bonus=no
            [/gold_carryover]

            {HAS_NO_TURN_LIMIT}
            [note]
                description= _ "You will not earn gold this scenario, but your gold from the previous scenario will be available in the next."
            [/note]
        [/objectives]

        [item]
            x,y=22,3
            image=scenery/village-human-burned4.png
        [/item]
        [item]
            x,y=24,7
            image=scenery/village-human-burned1.png
        [/item]
        [item]
            x,y=21,11
            image=scenery/village-human-burned2.png
        [/item]

        {PLACE_DARK_ADEPT 4 7 QUICK INTELLIGENT male}
        {PLACE_DARK_ADEPT 4 8 STRONG RESILIENT female}
        {PLACE_DARK_ADEPT 4 9 QUICK RESILIENT female}
        {PLACE_DARK_ADEPT 4 10 RESILIENT INTELLIGENT male}
        {PLACE_DARK_ADEPT 4 11 STRONG QUICK female}

        # Only one Shynal will be recalled.
        [recall]
            id=Shynal
            x,y=3,10
            show=no
        [/recall]
        [recall]
            id=Corpse Shynal
            x,y=3,10
            show=no
        [/recall]
        [recall]
            id=Carcyn
            x,y=3,10
            show=no
        [/recall]
        [modify_unit]
            [filter]
                id=Shynal
                [or]
                    id=Corpse Shynal
                [/or]
            [/filter]
            facing=sw
            moves=0
        [/modify_unit]
        [modify_unit]
            [filter]
                id=Carcyn
            [/filter]
            facing=nw
            moves=0
        [/modify_unit]

        [modify_unit]
            [filter]
                id=Ras-Tabahn
            [/filter]
            facing=ne
        [/modify_unit]

        [if]
            [not]
                [have_unit]
                    x,y=3,10
                [/have_unit]
            [/not]
            [then]
                [unit]
                    name=""
                    x,y=3,10
                    side=2  # By default, side 1 gets an orb and 2 doesn't.
                    type=Dummy
                    id=dummy
                [/unit]
                [petrify]
                    id=dummy
                [/petrify]
            [/then]
        [/if]

        {FREEZE_UNIT (Ras-Tabahn)}
    [/event]

    # *************************** PLAY ***************************
    [event]
        name=turn 1 end

        [terrain]
            x,y=3,10
            terrain="^"
            layer=overlay
        [/terrain]
        [modify_side]
            side=1
            gold=0
        [/modify_side]
        [kill]
            id=dummy
        [/kill]

        [event]
            name=turn_refresh
            first_time_only=no
            [modify_side]
                side=1
                gold=0
            [/modify_side]
        [/event]
    [/event]

    [event]
        name=turn 3
        {REPEAT 4 {PLACE_CORPSE_2 24 7}}
        {REPEAT 2 {PLACE_CORPSE_3 24 7}}
    [/event]

    [event]
        name=turn 5
        {REPEAT 4 {PLACE_CORPSE_1 22 3}}
        {REPEAT 3 {PLACE_CORPSE_3 22 3}}

        # The player isn't allowed to win before turn 5, but now they can.
        [event]
            name=die
            first_time_only=no
            [filter]
                side=2
            [/filter]

            # Check for a win.
            [if]
                # If there are no corpses or soulless left...
                [not]
                    [have_unit]
                        side=2
                    [/have_unit]
                [/not]
                [then]
                    # Gold was removed at the beginning, and is returned now.
                    [gold]
                        side=1
                        amount=$rastabahn_gold
                    [/gold]
                    [clear_variable]
                        name=rastabahn_gold
                    [/clear_variable]

                    [endlevel]
                        result=victory
                        bonus=yes
                        {NEW_GOLD_CARRYOVER 100}
                    [/endlevel]
                [/then]
            [/if]
        [/event]
    [/event]

    # *************************** ENDING / OPENING ***************************
    [event]
        name=die
        first_time_only=no
        [filter]
            side=1
        [/filter]

        # Check for a loss.
        [if]
            # If there are none of the *original* DA's left (the kids don't count)...
            [not]
                [have_unit]
                    role=trainee
                [/have_unit]
            [/not]
            [then]
                [endlevel]
                    result=defeat
                [/endlevel]
            [/then]
        [/if]
    [/event]

    [event]
        name=start
        [scroll_to]
            x,y=23,10
        [/scroll_to]
        [delay]
            time=1000
        [/delay]
        [message]
            speaker=Ras-Tabahn
            message= _ "What happened here, I wonder. Well, no matter. What was bad for these families is good for us. I will animate them, and you will attack. Practice both freezing and life force attacks. You may each choose one soldier from our army for protection, and I will call it up for you. After that, I will not help. I intend most of you to survive this battle, so try not to die."
        [/message]

        [if]
            {BOTH_KIDS_LIVE}
            [then]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "plural^You may watch."
                [/message]
                [message]
                    speaker=Shynal
                    message= _ "Can we help?"
                [/message]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "plural^As you wish. (<i>Cough, cough</i>)"
                [/message]
            [/then]
        [/if]

        [if]
            {ONE_KID_LIVES}
            [then]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "You may watch."
                [/message]
                [message]
                    id=Carcyn,Shynal
                    message= _ "Can I help?"
                    female_message= _ "self_female^Can I help?"
                [/message]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "As you wish. (<i>Cough, cough</i>)"
                [/message]
            [/then]
        [/if]

        [message]
            speaker=narrator
            image=logo.png
            message= _ "You can recruit from in front of each dark adept during the first turn only."
        [/message]

        {REPEAT 3 {PLACE_CORPSE_1 21 11}}
        {REPEAT 4 {PLACE_CORPSE_3 21 11}}

        [modify_unit]
            [filter]
                side=1
            [/filter]
            facing=se
        [/modify_unit]
    [/event]

    [event]
        name=time over

        [message]
            speaker=Ras-Tabahn
            message= _ "This has taken too long. We will surely miss our meeting with Ardonna now."
        [/message]
    [/event]

    [event]
        name=scenario end

        {MODIFY_UNIT (role=trainee) role ""}
    [/event]

    {HERO_DEATHS}
    {MAKE_BATS_NORMAL}
    {ZOMBIES}
    {KIDS_ADVANCE}
[/scenario]
