#textdomain wesnoth-low

#define LOW_MAP NAME
    map_data="{@campaigns/Legend_of_Wesmere/maps/{NAME}}"
#enddef

#define LOW_MASK NAME
    [event]
        name=prestart
        [terrain_mask]
            x=1
            y=1
            mask="{@campaigns/Legend_of_Wesmere/masks/{NAME}}"
        [/terrain_mask]
    [/event]
#enddef

#define WINTER_MASK MASK_NAME
    [event]
        name=prestart
        [terrain_mask]
            x,y=1,1
            mask="{@campaigns/Legend_of_Wesmere/masks/{MASK_NAME}}"
            border=yes

            #seems not to work
            #Windmill
            [rule]
                old=Gg^Wm
                new=Aa
                terrain=Aa^Wm
            [/rule]

            #human Village
            [rule]
                old=Gg^Vh
                new=Aa
                terrain=Aa^Vha
            [/rule]
            #dwarf Village
            [rule]
                old=Hh^Vhh
                new=Aa
                terrain=Ha^Vhha
            [/rule]

            #elvish Village
            [rule]
                old=Gg^Ve
                new=Aa
                terrain=Aa^Vea
            [/rule]
            #flat hut Village
            [rule]
                old=Gg^Vc
                new=Aa
                terrain=Aa^Vca
            [/rule]
            #hill hut Village
            [rule]
                old=Hh^Vc
                new=Aa
                terrain=Ha^Vca
            [/rule]
            #forest
            [rule]
                old=Gs^Fp
                new=Aa
                terrain=Aa^Fpa
            [/rule]
            #hills
            [rule]
                old=Hh
                new=Aa
                terrain=Ha
            [/rule]
            #forested hills
            [rule]
                old=Hh^Fp
                new=Aa
                terrain=Ha^Fpa
            [/rule]
            #deciduous forest
            [rule]
                old=Gs^Fds
                new=Aa
                terrain=Aa^Fda
            [/rule]
            #deciduous forested hills
            [rule]
                old=Hh^Fds
                new=Aa
                terrain=Ha^Fda
            [/rule]

            #water
            #[rule]
            #    old=Ww
            #    new=Aa
            #    terrain=Ai
            #[/rule]

            #River Ford --> ice
            [rule]
                old=Wwf
                new=Aa
                terrain=Ai
            [/rule]

            # that would brake the balance of S19
            #swamp
            #[rule]
            #    old=Ss
            #    new=Aa
            #    terrain=Ai
            #[/rule]
            #castle
            [rule]
                new=Ce,Ke
            [/rule]
            [rule]
                old=Ce,Ke
                new=Aa^Fpa
            [/rule]
            #mountains
            [rule]
                old=Mm
                new=Aa
                terrain=Ms
            [/rule]
            #mountain village
            [rule]
                old=Mm^Vhh
                new=Aa
                terrain=Ms^Vhha
            [/rule]

            #Grass
            [rule]
                old=Gg,Re,Ggf
                new=Aa
                #don't specify terrain and it just uses the new terrain
            [/rule]

            #Savannah
            [rule]
                old=Gs
                new=Aa
                terrain=Aa
            [/rule]

            [rule]
                old=Rd
                new=Aa
                terrain=Aa
            [/rule]

            #Mushroom lichtung
            [rule]
                old=Gs^Uf
                new=Aa
                terrain=Aa
            [/rule]

            #default: Will match everything, since 'old' and 'new' aren't
            #specified. Set 'use_old=yes' to signal no change.
            [rule]
                use_old=yes
            [/rule]
        [/terrain_mask]
    [/event]
#enddef

#define RECALL_LOYALS
    [store_unit]
        variable=loyals
        [filter]
            [filter_wml]
                upkeep="loyal"
            [/filter_wml]
        [/filter]
    [/store_unit]

    {FOREACH loyals loyal_one}
        [recall]
            id=$loyals[$loyal_one].id
        [/recall]
    {NEXT loyal_one}
    {CLEAR_VARIABLE loyals}
#enddef

#define LOOT AMOUNT SIDE
    {VARIABLE amount_gold {AMOUNT}}
    [message]
        speaker=narrator
        message= _ "You retrieve $amount_gold pieces of gold."
        image=wesnoth-icon.png
    [/message]
    {CLEAR_VARIABLE amount_gold}

    [sound]
        name=gold.ogg
    [/sound]

    [gold]
        side={SIDE}
        amount={AMOUNT}
    [/gold]
#enddef

#define SET_GOLD SIDE FACTOR_EASY FACTOR_NORMAL FACTOR_HARD
    [event]
        name=prestart

        [store_gold]
            side=1
        [/store_gold]

#ifdef EASY
        {VARIABLE_OP gold multiply {FACTOR_EASY}}
#endif

#ifdef NORMAL
        {VARIABLE_OP gold multiply {FACTOR_NORMAL}}
#endif

#ifdef HARD
        {VARIABLE_OP gold multiply {FACTOR_HARD}}
#endif

        [modify_side]
            side={SIDE}
            gold=$gold
        [/modify_side]

        [wml_message]
            message="gold of side {SIDE} set to $gold"	# wmllint: ignore no spellcheck
            logger=warn
        [/wml_message]

        {CLEAR_VARIABLE gold}
    [/event]
#enddef

#define ELVES
Elvish Fighter,Elvish Archer,Elvish Scout,Elvish Shaman#enddef

#define DWARVES
Dwarvish Fighter,Dwarvish Thunderer,Dwarvish Ulfserker, Dwarvish Berserker, Dwarvish Guardsman#enddef

#define ORCS1
Orcish Archer, Orcish Assassin, Orcish Grunt, Wolf Rider, Goblin Spearman#enddef

#define VILLAGE_SIDE SIDE X Y
    [event]
        name=prestart

        [command]
            [capture_village]
                side={SIDE}
                x={X}
                y={Y}
            [/capture_village]
        [/command]

        [message_debug]
            logger=warn
            message="village at {X}, {Y} to side {SIDE}"	# wmllint: ignore no spellcheck
        [/message_debug]
    [/event]
#enddef

#define STARTING_VILLAGES_DWARF SIDE
    [event]
        name=prestart

        #{CAPTURE_VILLAGES_OF_TYPE (*^Vhh) {SIDE} 1 1 {INFINITY}}
        {CAPTURE_FILTERED_VILLAGES {SIDE} (terrain=*^Vhh*)}
    [/event]
#enddef

#define STARTING_VILLAGES_ELF SIDE
    [event]
        name=prestart

        {CAPTURE_FILTERED_VILLAGES {SIDE} (terrain=*^Ve*)}
    [/event]
#enddef

#define STARTING_VILLAGES_HUMAN SIDE
    [event]
        name=prestart

        {CAPTURE_FILTERED_VILLAGES {SIDE} (terrain=*^Vh,*^Vha)}
    [/event]
#enddef

#define STARTING_VILLAGES_TROLL SIDE
    [event]
        name=prestart

        {CAPTURE_FILTERED_VILLAGES {SIDE} (terrain=*^Vc*)}
    [/event]
#enddef

#define VILLAGE_KALENZ X Y
    {VILLAGE_SIDE 1 {X} {Y}}
#enddef

# Thanks to Shadow Master for this macro
# !***Macro to random place unit within area***
#define RANDOM_PLACEMENT _X _Y _RADIUS _WML
    [store_locations]
        x,y={_X},{_Y}
        radius={_RADIUS}
        variable=random_placement_locations
    [/store_locations]

    {VARIABLE_OP random_string format "0..$random_placement_locations.length"}

    {RANDOM $random_string}

    {VARIABLE_OP random_placement_x format "$random_placement_locations[$random].x"}
    {VARIABLE_OP random_placement_y format "$random_placement_locations[$random].y"}

    {CLEAR_VARIABLE random_placement_locations}

    {_WML}

    [+unit]
        x,y=$random_placement_x,$random_placement_y
    [/unit]

    {CLEAR_VARIABLE random_placement_x}
    {CLEAR_VARIABLE random_placement_y}
#enddef
