#textdomain wesnoth-anl
[multiplayer]
    id=multiplayer_A_New_Land
    name= _ "4p — A New Land"
    map_data="{multiplayer/maps/4p_A_New_Land.map}"
    description= _ "This 4p survival scenario allows you to construct buildings and terraform the land. Use map settings. The recommended starting gold is 100."
    experience_modifier=70%
    turns=unlimited

    {DEFAULT_SCHEDULE}
    {DEFAULT_MUSIC_PLAYLIST}
    # ------------------------------------------------------
    # Include ANL macros
    # ------------------------------------------------------
    {multiplayer/scenarios/ANL_utils}

    # ------------------------------------------------------
    # Story & Objectives
    # ------------------------------------------------------

    [story]
        [part]
            show_title=yes
            story= _ "In the aftermath of the great war the remnants of humanity fled to an obscure secluded glen. Though they knew they could not hide from the mighty armies that had crushed their homeland, the leaders of the resistance hoped only for enough time to rebuild their forces."
        [/part]
    [/story]

    [event]
        name="start"
        [objectives]
            side=0
            summary="<small>" + _ "Right-click on your leader during your turn for help" + "</small>" # wmllint: no spellcheck
            [objective]
                description= _ "You must survive until turn 25."
                condition=win
            [/objective]
        [/objectives]
    [/event]

    # ------------------------------------------------------
    # Side Definitions
    # ------------------------------------------------------

    # Players

    [side]
        side=1
        canrecruit=yes
        controller=human
        team_name=1
        user_team_name= _ "teamname^Team 1"
        team_lock=yes
        income_lock=yes
        village_gold=2
        shroud=no
        fog=yes
        recruit=Peasant,Mage
        faction_from_recruit=yes
    [/side]

    [side]
        side=2
        canrecruit=yes
        controller=human
        team_name=1
        user_team_name= _ "teamname^Team 1"
        team_lock=yes
        income_lock=yes
        village_gold=2
        shroud=no
        fog=yes
        recruit=Peasant,Mage
        faction_from_recruit=yes
    [/side]

    [side]
        side=3
        canrecruit=yes
        controller=human
        team_name=1
        user_team_name= _ "teamname^Team 1"
        team_lock=yes
        income_lock=yes
        village_gold=2
        shroud=no
        fog=yes
        recruit=Peasant,Mage
        faction_from_recruit=yes
    [/side]

    [side]
        side=4
        canrecruit=yes
        controller=human
        team_name=1
        user_team_name= _ "teamname^Team 1"
        team_lock=yes
        income_lock=yes
        village_gold=2
        shroud=no
        fog=yes
        recruit=Peasant,Mage
        faction_from_recruit=yes
    [/side]

    # AI

    [side]
        side=5
        canrecruit=yes
        controller=ai
        allow_player=no
        team_name=2
        user_team_name= _ "teamname^Team 2"
        gold=25
        recruit=Walking Corpse
        income=20
        village_gold=2
        team_lock=yes
        income_lock=yes
        type=Death Knight
        allow_player=no
        [modifications]
            {MOVEMENT_RESTRICTION flat shallow_water}
        [/modifications]
        [ai]
            aggression=1.0
            recruitment_pattern=fighter
        [/ai]
        [village]
            x,y=10,25
        [/village]
    [/side]

    [side]
        side=6
        canrecruit=yes
        controller=ai
        allow_player=no
        team_name=2
        user_team_name= _ "teamname^Team 2"
        gold=25
        recruit=Goblin Spearman
        income=20
        village_gold=2
        team_lock=yes
        income_lock=yes
        type=Orcish Sovereign
        allow_player=no
        [modifications]
            {MOVEMENT_RESTRICTION flat shallow_water}
        [/modifications]
        [ai]
            aggression=1.0
            recruitment_pattern=fighter
        [/ai]
        [village]
            x,y=50,25
        [/village]
    [/side]

    [side]
        side=7
        canrecruit=yes
        controller=ai
        allow_player=no
        team_name=2
        user_team_name= _ "teamname^Team 2"
        gold=25
        recruit=Goblin Spearman
        income=20
        village_gold=2
        team_lock=yes
        income_lock=yes
        type=Orcish Sovereign
        allow_player=no
        [modifications]
            {MOVEMENT_RESTRICTION flat shallow_water}
        [/modifications]
        [ai]
            aggression=1.0
            recruitment_pattern=fighter
        [/ai]
        [village]
            x,y=10,30
        [/village]
    [/side]

    [side]
        side=8
        canrecruit=yes
        controller=ai
        allow_player=no
        team_name=2
        user_team_name= _ "teamname^Team 2"
        gold=25
        recruit=Walking Corpse
        income=20
        village_gold=2
        team_lock=yes
        income_lock=yes
        type=Death Knight
        allow_player=no
        [modifications]
            {MOVEMENT_RESTRICTION flat shallow_water}
        [/modifications]
        [ai]
            aggression=1.0
            recruitment_pattern=fighter
        [/ai]
        [village]
            x,y=50,30
        [/village]
    [/side]

    # This side is for trapped units. It is allied to the AI so they don't attack it.

    [side]
        side=9
        canrecruit=no
        controller=null
        allow_player=no
        no_leader=yes
        team_name=2
        income=0
        village_gold=0
        team_lock=yes
        gold_lock=yes
        income_lock=yes
        allow_player=no
        [ai]
            ai_algorithm=idle_ai
        [/ai]
    [/side]

    # ------------------------------------------------------
    # ANL Building Logic
    # ------------------------------------------------------

    [event]
        name=prestart

        # Players
        {SET_SIDE_VARIABLES 1}
        {SET_SIDE_VARIABLES 2}
        {SET_SIDE_VARIABLES 3}
        {SET_SIDE_VARIABLES 4}

        {ANL_HELP}
        {WORKER_OPTIONS "Peasant"}
        {RESEARCH_OPTIONS "Mage,Red Mage,White Mage,Mage of Light,Silver Mage,Arch Mage,Great Mage"}
        {LEADER_OPTIONS}
    [/event]

    # Auto-studying

    {AUTO_STUDYING "Mage,Red Mage,White Mage,Mage of Light,Silver Mage,Arch Mage,Great Mage"}

    # Research complete messages

    [event]
        name=side turn
        first_time_only=no
        [if]
            [variable]
                name=side_number
                less_than_equal_to=4
            [/variable]

            [then]
                {FARMING_RESEARCH_COMPLETE}
                {MINING_RESEARCH_COMPLETE}
                {WARFARE_RESEARCH_COMPLETE}
            [/then]
        [/if]
    [/event]

    # Remove working status from any working units when starting a turn

    [event]
        name=side turn
        first_time_only=no

        [store_unit]
            [filter]
                side=$side_number

                [filter_wml]
                    [status]
                        worked_this_turn=yes
                    [/status]
                [/filter_wml]
            [/filter]

            kill=yes
            variable=this_side_workers
        [/store_unit]

        {FOREACH this_side_workers i}
            [clear_variable]
                name=this_side_workers[$i].status.worked_this_turn
            [/clear_variable]

            [unstore_unit]
                variable=this_side_workers[$i]
            [/unstore_unit]
        {NEXT i}

        [clear_variable]
            name=this_side_workers
        [/clear_variable]
    [/event]

    # Auto-working

    {AUTO_FARMING "Peasant"}
    {AUTO_MINING "Peasant"}

    # ------------------------------------------------------
    # Scenario Events
    # ------------------------------------------------------

    [event]
        name=prestart

        # Placing trapped creatures
        {ANL_PLACE_TRAPPED_UNIT 9 Gryphon 24 12}
        {ANL_PLACE_TRAPPED_UNIT 9 "Fire Drake" 36 12}
        {ANL_PLACE_TRAPPED_UNIT 9 Ogre 24 43}
        {ANL_PLACE_TRAPPED_UNIT 9 "Elder Wose" 36 43}

        # Placing spiders
        {ANL_PLACE_WOUNDED_UNIT 5 "Giant Spider" 29 13 4}
        {ANL_PLACE_WOUNDED_UNIT 6 "Giant Spider" 31 13 4}
        {ANL_PLACE_WOUNDED_UNIT 7 "Giant Spider" 29 43 4}
        {ANL_PLACE_WOUNDED_UNIT 8 "Giant Spider" 31 43 4}

        # Initial AI units - Side 5
        {ANL_PLACE_UNIT 5 "Walking Corpse" 10 25}
        {ANL_PLACE_UNIT 5 "Walking Corpse" 10 25}
        {ANL_PLACE_UNIT 5 "Walking Corpse" 10 25}
        {ANL_PLACE_GUARDIAN 5 "Revenant" 26 18}
        {ANL_PLACE_GUARDIAN 5 "Revenant" 45 32}
        {ANL_PLACE_GUARDIAN 5 "Walking Corpse" 13 27}
        # Initial AI units - Side 6
        {ANL_PLACE_UNIT 6 "Goblin Spearman" 50 25}
        {ANL_PLACE_UNIT 6 "Goblin Spearman" 50 25}
        {ANL_PLACE_UNIT 6 "Goblin Spearman" 50 25}
        {ANL_PLACE_GUARDIAN 6 "Orcish Warrior" 34 18}
        {ANL_PLACE_GUARDIAN 6 "Orcish Warrior" 45 24}
        {ANL_PLACE_GUARDIAN 6 "Goblin Spearman" 47 27}
        # Initial AI units - Side 7
        {ANL_PLACE_UNIT 7 "Goblin Spearman" 10 30}
        {ANL_PLACE_UNIT 7 "Goblin Spearman" 10 30}
        {ANL_PLACE_UNIT 7 "Goblin Spearman" 10 30}
        {ANL_PLACE_GUARDIAN 7 "Orcish Warrior" 15 32}
        {ANL_PLACE_GUARDIAN 7 "Orcish Warrior" 26 37}
        {ANL_PLACE_GUARDIAN 7 "Goblin Spearman" 13 29}
        # Initial AI units - Side 8
        {ANL_PLACE_UNIT 8 "Walking Corpse" 50 30}
        {ANL_PLACE_UNIT 8 "Walking Corpse" 50 30}
        {ANL_PLACE_UNIT 8 "Walking Corpse" 50 30}
        {ANL_PLACE_GUARDIAN 8 "Revenant" 15 24}
        {ANL_PLACE_GUARDIAN 8 "Revenant" 34 37}
        {ANL_PLACE_GUARDIAN 8 "Walking Corpse" 47 29}
    [/event]

    # Setting leader names

    [event]
        name=new turn
        first_time_only=no
        {SET_NAMES 1}
        {SET_NAMES 2}
        {SET_NAMES 3}
        {SET_NAMES 4}
    [/event]

    # Rescuing trapped units

    {ANL_RESCUE_TRAPPED_UNIT 25 13 24 12}
    {ANL_RESCUE_TRAPPED_UNIT 35 13 36 12}
    {ANL_RESCUE_TRAPPED_UNIT 25 43 24 43}
    {ANL_RESCUE_TRAPPED_UNIT 35 43 36 43}

    # Destroying mushroom mines

    [event]
        name=moveto
        [filter]
            x=10
            y=25
            side=1,2,3,4
        [/filter]

        [modify_side]
            side=5
            income=10
        [/modify_side]
        {MODIFY_TERRAIN Uh $x1 $y1}
        [sound]
            name=skeleton-die-1.ogg
        [/sound]
        [message]
            speaker=narrator
            image=terrain/village/cave-tile.png
            message= _ "You destroy the mushroom mine. The northwest undead now have 10 less income."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            x=50
            y=25
            side=1,2,3,4
        [/filter]

        [modify_side]
            side=6
            income=10
        [/modify_side]
        {MODIFY_TERRAIN Uh $x1 $y1}
        [sound]
            name=skeleton-die-1.ogg
        [/sound]
        [message]
            speaker=narrator
            image=terrain/village/cave-tile.png
            message= _ "You destroy the mushroom mine. The northeast orcs now have 10 less income."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            x=10
            y=30
            side=1,2,3,4
        [/filter]

        [modify_side]
            side=7
            income=10
        [/modify_side]
        {MODIFY_TERRAIN Uh $x1 $y1}
        [sound]
            name=skeleton-die-1.ogg
        [/sound]
        [message]
            speaker=narrator
            image=terrain/village/cave-tile.png
            message= _ "You destroy the mushroom mine. The southwest orcs now have 10 less income."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            x=50
            y=30
            side=1,2,3,4
        [/filter]

        [modify_side]
            side=8
            income=10
        [/modify_side]
        {MODIFY_TERRAIN Uh $x1 $y1}
        [sound]
            name=skeleton-die-1.ogg
        [/sound]
        [message]
            speaker=narrator
            image=terrain/village/cave-tile.png
            message= _ "You destroy the mushroom mine. The southeast undead now have 10 less income."
        [/message]
    [/event]

    # Make AI units destroy player’s buildings

    # Villages
    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=5,6,7,8
            [filter_location]
                terrain=Gg^Vh
            [/filter_location]
        [/filter]
        {MODIFY_TERRAIN "Rd" $x1 $y1}
        {PLACE_IMAGE "scenery/village-human-burned2.png" $x1 $y1 }
        [sound]
            name=torch.ogg
        [/sound]
    [/event]

    # Farms
    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=5,6,7,8
            [filter_location]
                terrain=Re^Gvs
            [/filter_location]
        [/filter]
        {MODIFY_TERRAIN "Rd" $x1 $y1}
        {PLACE_IMAGE "scenery/castle-ruins.png" $x1 $y1}
        [sound]
            name=pincers.ogg
        [/sound]
    [/event]

    # Universities & Castles
    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=5,6,7,8
            [filter_location]
                terrain=Gg^Ve,Gg^Vea,Ch,Ce,Cv,Chr,Chw,Chs,Ke,Kv,Kh,Khr
            [/filter_location]
        [/filter]
        {MODIFY_TERRAIN "Rd" $x1 $y1}
        {PLACE_IMAGE "scenery/rubble.png" $x1 $y1}
        [sound]
            name=dagger-swish.wav
        [/sound]
        [sound]
            name=club.ogg
        [/sound]
    [/event]

    # Hill mines
    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=5,6,7,8
            [filter_location]
                terrain=Hh^Vhh
            [/filter_location]
        [/filter]
        {MODIFY_TERRAIN "Hh" $x1 $y1}
        [sound]
            name=dagger-swish.wav
        [/sound]
        [sound]
            name=club.ogg
        [/sound]
    [/event]

    # Mountain mines
    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=5,6,7,8
            [filter_location]
                terrain=Mm^Vhh
            [/filter_location]
        [/filter]
        {MODIFY_TERRAIN "Mm" $x1 $y1}
        [sound]
            name=dagger-swish.wav
        [/sound]
        [sound]
            name=club.ogg
        [/sound]
    [/event]

    # ------------------------------------------------------
    # Messages
    # ------------------------------------------------------

    # Telling players about spiders

    [event]
        name=turn 3

        [message]
            speaker=narrator
            message= _ "One of your peasants has happened upon some spiders’ nests in the north and south."
            image=wesnoth-icon.png
        [/message]
        [message]
            side=1,2,3,4
            type=Peasant
            message= _ "I swear I saw somebody trapped in the spider’s web. Maybe we should rescue him?"
        [/message]

        {SCROLL_TO 24 12}
        [delay]
            time=200
        [/delay]
        {SCROLL_TO 36 12}
        [delay]
            time=200
        [/delay]
        {SCROLL_TO 24 43}
        [delay]
            time=200
        [/delay]
        {SCROLL_TO 36 43}
        [delay]
            time=200
        [/delay]

        [message]
            speaker=narrator
            message= _ "Move any unit next to these captives and they will join your side. The spiders guarding each captive are currently wounded, the sooner you get there the better chance you have of killing them."
            image=wesnoth-icon.png
        [/message]
    [/event]

    # Telling players about mushroom mines

    [event]
        name=turn 5

        [message]
            speaker=narrator
            message= _ "Your men report strange sounds coming from some caves to the east and west."
            image=wesnoth-icon.png
        [/message]
        [message]
            canrecruit=yes
            side=1,2,3,4
            message= _ "It would seem the enemy has built some underground mushroom mines nearby — it must be where the mainstay of their resources are produced. If we could destroy them our chances wouldn’t nearly be so slim."
        [/message]

        {SCROLL_TO 10 25}
        [delay]
            time=200
        [/delay]
        {SCROLL_TO 10 30}
        [delay]
            time=200
        [/delay]
        {SCROLL_TO 50 25}
        [delay]
            time=200
        [/delay]
        {SCROLL_TO 50 30}
        [delay]
            time=200
        [/delay]

        [message]
            speaker=narrator
            message= _ "Move any unit onto these villages to destroy the mine. Each one you destroy will reduce the enemy’s income by 10."
            image=wesnoth-icon.png
        [/message]
    [/event]

    # Almost there...

    [event]
        name=turn 23

        [message]
            side=1,2,3,4
            canrecruit=yes
            message= _ "This battle is nearly at an end. Victory is close at hand!"
        [/message]
    [/event]

    # Victory!

    [event]
        name=turn 25

        [message]
            side=1,2,3,4
            canrecruit=yes
            message= _ "We have survived the onslaught! The tide of the battle has turned, victory cannot elude us now!"
        [/message]
        [message]
            speaker=narrator
            message= _ "You have won the game, but you may continue if you wish..."
            image=wesnoth-icon.png
        [/message]
    [/event]

    # Deaths

    [event]
        name=last breath
        [filter]
            canrecruit=yes
            side=1
        [/filter]

        [message]
            speaker=unit
            message= _ "I have fallen, but all is not lost!"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            canrecruit=yes
            side=2
        [/filter]

        [message]
            speaker=unit
            message= _ "I am done for, but we have yet to lose this battle!"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            canrecruit=yes
            side=3
        [/filter]

        [message]
            speaker=unit
            message= _ "Comrades, avenge me!"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            canrecruit=yes
            side=4
        [/filter]

        [message]
            speaker=unit
            message= _ "Do not fear, there is hope for us still!"
        [/message]
    [/event]

    # ------------------------------------------------------
    # AI Recruitment Pattern
    # ------------------------------------------------------

    [event]
        name=turn 7

        [allow_recruit]
            side=6,7
            type=Goblin Rouser
        [/allow_recruit]

        [allow_recruit]
            side=5,8
            type=Soulless
        [/allow_recruit]
    [/event]

    [event]
        name=turn 9

        [allow_recruit]
            side=6,7
            type=Orcish Grunt
        [/allow_recruit]

        [allow_recruit]
            side=5,8
            type=Skeleton
        [/allow_recruit]
    [/event]

    [event]
        name=turn 11

        [allow_recruit]
            side=6,7
            type=Orcish Archer
        [/allow_recruit]

        [allow_recruit]
            side=5,8
            type=Skeleton Archer
        [/allow_recruit]
    [/event]

    [event]
        name=turn 13

        [allow_recruit]
            side=6,7
            type=Troll Whelp
        [/allow_recruit]

        [allow_recruit]
            side=5,8
            type=Ghoul
        [/allow_recruit]

        [disallow_recruit]
            side=6,7
            type=Goblin Spearman,Goblin Rouser
        [/disallow_recruit]

        [disallow_recruit]
            side=5,8
            type=Walking Corpse,Soulless
        [/disallow_recruit]
    [/event]

    [event]
        name=turn 15

        [allow_recruit]
            side=6,7
            type=Orcish Assassin
        [/allow_recruit]

        [allow_recruit]
            side=5,8
            type=Dark Adept
        [/allow_recruit]
    [/event]

    [event]
        name=turn 17

        [gold]
            side=5,6,7,8
            amount=50
        [/gold]

        [allow_recruit]
            side=6,7
            type=Troll,Orcish Crossbowman,Orcish Warrior
        [/allow_recruit]

        [allow_recruit]
            side=5,8
            type=Necrophage,Bone Shooter,Revenant
        [/allow_recruit]
    [/event]
[/multiplayer]
