#textdomain wesnoth-anl
[multiplayer]
    id=multiplayer_A_New_Land
    name= _ "4p - A New Land"
    map_data="{multiplayer/maps/4p_A_New_Land.map}"
    # wmllint: local spelling gold=100
    description= _ "This 4p survival scenario allows you to construct buildings and terraform the land. Use map settings. Recommended starting gold=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}
        {ALLOW_RECRUIT 1 "Peasant,Mage"}
        {ALLOW_RECRUIT 2 "Peasant,Mage"}
        {ALLOW_RECRUIT 3 "Peasant,Mage"}
        {ALLOW_RECRUIT 4 "Peasant,Mage"}
    [/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]
            {CONDITION side_number less_than_equal_to 4}
            [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 this_side_workers[$i].status.worked_this_turn}

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

        {CLEAR_VARIABLE this_side_workers}
    [/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]

    [event]
        name=start

        # Restricting movement of AI guardians

        [store_unit]
            [filter]
                role=guardian
            [/filter]

            kill=no
            variable=stored_guardians
        [/store_unit]

        {FOREACH stored_guardians i}
            [object]
                silent=yes
                duration=forever
                [filter]
                    x=$stored_guardians[$i].x
                    y=$stored_guardians[$i].y
                [/filter]
                [effect]
                    apply_to=movement_costs
                    replace=true
                    [movement_costs]
                        flat={UNREACHABLE}
                        sand={UNREACHABLE}
                    [/movement_costs]
                [/effect]
            [/object]
        {NEXT i}

        {CLEAR_VARIABLE stored_guardians}
    [/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}
        {PLAY_SOUND skeleton-die-1.ogg}
        [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}
        {PLAY_SOUND skeleton-die-1.ogg}
        [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}
        {PLAY_SOUND skeleton-die-1.ogg}
        [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}
        {PLAY_SOUND skeleton-die-1.ogg}
        [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 }
        {PLAY_SOUND ("torch.ogg")}
    [/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}
        {PLAY_SOUND ("pincers.ogg")}
    [/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}
        {PLAY_SOUND ("dagger-swish.wav")}
        {PLAY_SOUND ("club.ogg")}
    [/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}
        {PLAY_SOUND ("dagger-swish.wav")}
        {PLAY_SOUND ("club.ogg")}
    [/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}
        {PLAY_SOUND ("dagger-swish.wav")}
        {PLAY_SOUND ("club.ogg")}
    [/event]

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

    # Telling players about spiders

    [event]
        name=turn 3
        [message]
            speaker=narrator
            message= _ "One of your peasants has happened upon some spider's 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 them?"
        [/message]
        {SCROLL_TO 24 12}
        {DELAY 200}
        {SCROLL_TO 36 12}
        {DELAY 200}
        {SCROLL_TO 24 43}
        {DELAY 200}
        {SCROLL_TO 36 43}
        {DELAY 200}
        [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 200}
        {SCROLL_TO 10 30}
        {DELAY 200}
        {SCROLL_TO 50 25}
        {DELAY 200}
        {SCROLL_TO 50 30}
        {DELAY 200}
        [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 5 ("Soulless")}
        {ALLOW_RECRUIT 6 ("Goblin Rouser")}
        {ALLOW_RECRUIT 7 ("Goblin Rouser")}
        {ALLOW_RECRUIT 8 ("Soulless")}
    [/event]

    [event]
        name=turn 9
        {ALLOW_RECRUIT 5 ("Skeleton")}
        {ALLOW_RECRUIT 6 ("Orcish Grunt")}
        {ALLOW_RECRUIT 7 ("Orcish Grunt")}
        {ALLOW_RECRUIT 8 ("Skeleton")}
    [/event]

    [event]
        name=turn 11
        {ALLOW_RECRUIT 5 ("Skeleton Archer")}
        {ALLOW_RECRUIT 6 ("Orcish Archer")}
        {ALLOW_RECRUIT 7 ("Orcish Archer")}
        {ALLOW_RECRUIT 8 ("Skeleton Archer")}
    [/event]

    [event]
        name=turn 13
        {ALLOW_RECRUIT 5 ("Ghoul")}
        {ALLOW_RECRUIT 6 ("Troll Whelp")}
        {ALLOW_RECRUIT 7 ("Troll Whelp")}
        {ALLOW_RECRUIT 8 ("Ghoul")}
        {DISALLOW_RECRUIT 5 "Walking Corpse,Soulless"}
        {DISALLOW_RECRUIT 6 "Goblin Spearman,Goblin Rouser"}
        {DISALLOW_RECRUIT 7 "Goblin Spearman,Goblin Rouser"}
        {DISALLOW_RECRUIT 8 "Walking Corpse,Soulless"}
    [/event]

    [event]
        name=turn 15
        {ALLOW_RECRUIT 5 ("Dark Adept")}
        {ALLOW_RECRUIT 6 ("Orcish Assassin")}
        {ALLOW_RECRUIT 7 ("Orcish Assassin")}
        {ALLOW_RECRUIT 8 ("Dark Adept")}
    [/event]

    [event]
        name=turn 17
        {ADD_GOLD 5 50}
        {ADD_GOLD 6 50}
        {ADD_GOLD 7 50}
        {ADD_GOLD 8 50}
        {ALLOW_RECRUIT 5 ("Necrophage,Bone Shooter,Revenant")}
        {ALLOW_RECRUIT 6 ("Troll,Orcish Crossbowman,Orcish Warrior")}
        {ALLOW_RECRUIT 7 ("Troll,Orcish Crossbowman,Orcish Warrior")}
        {ALLOW_RECRUIT 8 ("Necrophage,Bone Shooter,Revenant")}
    [/event]
[/multiplayer]
