#textdomain wesnoth-multiplayer

[multiplayer]
    id=2p_Dark_Forecast
    name= _ "2p - Dark Forecast (Survival)"
    description= _ "Dark Forecast is a survival scenario for solitaire or two-player teambased play against randomly AI spawned units. Victory is achieved by surviving all enemy waves.  During the course of gameplay, the terrain will change based on random weather effects."
    turns="45"
    experience_modifier="100"
    map_data="{multiplayer/maps/Dark_Forecast.map}"
    victory_when_enemies_defeated=no

#define RANDOMIZE NUMBER
    {VARIABLE_OP random rand 1..{NUMBER}}
#enddef

#define RANDOMIZE_INDEX NUMBER
    {VARIABLE ran_max {NUMBER}}
    {VARIABLE_OP ran_max add -1}
    {VARIABLE_OP ran_range format "0..$ran_max"}
    {VARIABLE_OP random rand $ran_range}
#enddef

#define PLACE_SPAWN_GROUP X Y
    {VARIABLE spawn_x {X}}
    {VARIABLE spawn_y {Y}}
    [if]
        [variable]
            name=spawn_x
            equals="random"
        [/variable]
        [then]
            {RANDOMIZE $location}
            {VARIABLE x $spawn_place[$random].x}
            {VARIABLE y $spawn_place[$random].y}
            [store_locations]
                variable=locs
                x=$x
                y=$y
                radius=1
            [/store_locations]
            {RANDOMIZE_INDEX $locs.length}
            {VARIABLE spawn_x $locs[$random].x}
            {VARIABLE spawn_y $locs[$random].y}
        [/then]
    [/if]
    [store_unit]
        variable=spawns
        kill=yes
        [filter]
            canrecruit=no
            side=1,2
            [not]
                x=1-15
                y=8-22
            [/not]
        [/filter]
    [/store_unit]
    {FOREACH spawns id}
    {VARIABLE movement $spawns[$id].max_moves}
    {VARIABLE_OP movement multiply 0.33}
    {VARIABLE_OP movement add 1}
    {VARIABLE unit_name $spawns[$id].user_description}
    [unit]
        side=$timid_ai_side
        type=$spawns[$id].type
        x=$spawns[$id].x
        y=$spawns[$id].y
        generate_description=yes
        random_traits=no
        [modifications]
            [object]
                [effect]
                    apply_to=movement
                    set=$movement
                [/effect]
                [effect]
                    apply_to=movement_costs
                    replace=true
                    [movement_costs]
                        grassland=1
                        sand=2
                        forest=2
                        cavewall=3
                        canyon=3
                        deep_water=3
                    [/movement_costs]
                [/effect]
            [/object]
        [/modifications]
        [status]
            poisoned="no"
            slowed="on"
        [/status]
    [/unit]
    {NEXT id}
    {CLEAR_VARIABLE spawns}
    [store_unit]
        variable=spawns
        kill=yes
        [filter]
            canrecruit=no
            side=1,2
            [not]
                x=1-15
                y=8-22
            [/not]
        [/filter]
    [/store_unit]
    {VARIABLE msg "Spawning: "}
    {FOREACH spawns id}
    {VARIABLE spawns[$id].x $spawn_x}
    {VARIABLE spawns[$id].y $spawn_y}
    {RANDOMIZE 3}
    {VARIABLE position "se"}
    [if]
        [variable]
            name=random
            numerical_equals=1
        [/variable]
        [then]
            {VARIABLE position "sw"}
        [/then]
    [/if]
    {VARIABLE spawns[$id].facing $position}
    {VARIABLE_OP msg format "$msg
    $spawns[$id].type"}
    [if]
        [variable]
            name=unit_name
            equals="none"
        [/variable]
        [else]
            {VARIABLE spawns[$id].user_description $unit_name}
        [/else]
    [/if]
    [unstore_unit]
        variable=spawns[$id]
        find_vacant=yes
        animate=yes
    [/unstore_unit]
    {NEXT id}
    {CLEAR_VARIABLE spawns}
    ### DEBUG
    #{VARIABLE_OP msg format "$msg
    #
    #total cost: $total_cost"}
    #[message]
    #  speaker=narrator
    #  message=$msg
    #[/message]
#enddef

    # copies the units over from SIDE1 to SIDE2
    # and removes all objects
#define ADJUST_AGGRESSION SIDE1 SIDE2
    [if]
        [have_unit]
            side={SIDE1}
        [/have_unit]
        [then]
            [store_unit]
                variable=ai_unit
                kill=yes
                [filter]
                    side={SIDE1}
                [/filter]
            [/store_unit]
            {FOREACH ai_unit id}
            {VARIABLE name $ai_unit[$id].user_description}
            {VARIABLE type $ai_unit[$id].type}
            {VARIABLE hitpoints $ai_unit[$id].hitpoints}
            {VARIABLE max_hp $ai_unit[$i].max_hitpoints}
            {VARIABLE facing $ai_unit[$id].facing}
            {VARIABLE gender $ai_unit[$id].gender}
            {VARIABLE experience $ai_unit[$id].experience}
            {VARIABLE poisoned $ai_unit[$id].status.poisoned}
            {VARIABLE slowed $ai_unit[$id].status.slowed}
            {VARIABLE hides $ai_unit[$id].status.hides}
            {VARIABLE x $ai_unit[$id].x}
            {VARIABLE y $ai_unit[$id].y}
            [if]
                [variable]
                    name=ai_unit[$id].race
                    equals="undead"
                [/variable]
                [then]
                    {VARIABLE name ""}
                [/then]
            [/if]
            [unit]
                type=$type
                side={SIDE2}
                x=$x
                y=$y
                experience=$experience
                facing=$facing
                gender=$gender
                user_description=$name
                random_traits=yes
                [status]
                    hides=$hides
                    slowed=$slowed
                    poisoned=$poisoned
                [/status]
            [/unit]
            # set hp now to adjust for trait bonuses
            [store_unit]
                variable=last_spawn
                kill=no
                [filter]
                    side={SIDE2}
                    x,y = $x,$y
                [/filter]
            [/store_unit]
            {VARIABLE hp_add $last_spawn.max_hitpoints}
            {VARIABLE_OP hp_add add -$max_hp}
            {VARIABLE_OP $last_spawn.hitpoints add $hp_add}
            [unstore_unit]
                variable=last_spawn
            [/unstore_unit]

            {NEXT id}
            {CLEAR_VARIABLE ai_unit}
            {CLEAR_VARIABLE type}
            {CLEAR_VARIABLE name}
            {CLEAR_VARIABLE hitpoints}
            {CLEAR_VARIABLE facing}
            {CLEAR_VARIABLE gender}
            {CLEAR_VARIABLE experience}
            {CLEAR_VARIABLE poisoned}
            {CLEAR_VARIABLE hides}
            {CLEAR_VARIABLE slowed}
            {CLEAR_VARIABLE hp_add}
            {CLEAR_VARIABLE max_hp}
        [/then]
    [/if]
#enddef

#define SPAWN_UNIT SIDE TYPE ID TIER NUMBER
    {VARIABLE uside {SIDE}}
    {VARIABLE utype {TYPE}}
    {VARIABLE y 10}
    {VARIABLE number -{NUMBER}}
    {VARIABLE_OP number add 11}
    {VARIABLE_OP y add $number}
    {VARIABLE x 18}
    {VARIABLE this_tier {TIER}}
    [if]
        [variable]
            name=this_tier
            greater_than=1
        [/variable]
        [then]
            {VARIABLE x 19}
        [/then]
    [/if]
    [unit]
        type={TYPE}
        side={SIDE}
        x=$x
        y=$y
        role=new_unit{TIER}
        random_traits=no
        user_description="none"
    [/unit]
    [store_unit]
        kill=no
        variable=new_unit
        [filter]
            side={SIDE}
            role=new_unit{TIER}
        [/filter]
    [/store_unit]
    {VARIABLE_OP gold add -$new_unit.cost}
    ### DEBUG
    {VARIABLE_OP total_cost add $new_unit.cost}
    [if]
        [variable]
            name=min_cost
            greater_than=$new_unit.cost
        [/variable]
        [then]
            {VARIABLE min_cost $new_unit.cost}
        [/then]
    [/if]
    {VARIABLE_OP max_units add -1}
    {VARIABLE new_unit.spawn_id {ID}}
    {VARIABLE new_unit.role new_spawn{TIER}}
    [unstore_unit]
        variable=new_unit
    [/unstore_unit]
    {CLEAR_VARIABLE new_unit}
#enddef

#define ADJUST_UNIT_LEVEL SIDE TIER_NUMBER
    {VARIABLE next_tier {TIER_NUMBER}}
    {VARIABLE tier {TIER_NUMBER}}
    {VARIABLE side {SIDE}}
    {VARIABLE_OP next_tier add 1}
    {VARIABLE_OP next_role format "new_spawn$next_tier"}
    [store_unit]
        kill=yes
        variable=new_spawn
        [filter]
            side={SIDE}
            role=new_spawn{TIER_NUMBER}
        [/filter]
    [/store_unit]
    {FOREACH new_spawn unit_id}
    {VARIABLE spawn_id $new_spawn[$unit_id].spawn_id}
    {VARIABLE previous_cost $new_spawn.cost}
    {VARIABLE upgrade_var main_spawns[$group_id].spawn_type[$spawn_id].up{TIER_NUMBER}}
    {VARIABLE_OP advanceto to_variable $upgrade_var}
    [if]
        [variable]
            name=advanceto
            not_equals=null
        [/variable]
        [variable]
            name=advanceto
            not_equals=none
        [/variable]
        [then]
            {VARIABLE yind $new_spawn[$unit_id].y}
            [if]
                [variable]
                    name=advanceto
                    equals=more
                [/variable]
                [then]
                    {VARIABLE upgrade_cost $new_spawn[$unit_id].cost}
                    # add 2 gold to cost
                    {VARIABLE_OP upgrade_cost add 2}
                    {VARIABLE advanceto $new_spawn[$unit_id].type}
                    [if]
                        [variable]
                            name=gold
                            greater_than_equal_to=$upgrade_cost
                        [/variable]
                        [then]
                            {VARIABLE_OP gold add -$upgrade_cost}
                            ### DEBUG
                            {VARIABLE_OP total_cost add $upgrade_cost}
                            {SPAWN_UNIT {SIDE} $advanceto $spawn_id $next_role $max_units}
                            {VARIABLE new_spawn[$unit_id].role $next_role}
                        [/then]
                    [/if]
                [/then]
                [else]
                    [unit]
                        side={SIDE}
                        type=$advanceto
                        random_traits=no
                        user_description="none"
                        x=20
                        y=22
                    [/unit]
                    [store_unit]
                        variable=advancement
                        kill=yes
                        [filter]
                            x=20
                            y=22
                            side={SIDE}
                        [/filter]
                    [/store_unit]
                    {VARIABLE upgrade_cost $advancement.cost}
                    {VARIABLE_OP upgrade_cost add -$previous_cost}
                    # 25% surcharge
                    {VARIABLE_OP upgrade_cost multiply 1.25}
                    {CLEAR_VARIABLE advancement}
                    [if]
                        [variable]
                            name=gold
                            greater_than_equal_to=$upgrade_cost
                        [/variable]
                        [then]
                            {VARIABLE_OP gold add -$upgrade_cost}
                            ### DEBUG
                            {VARIABLE_OP total_cost add $upgrade_cost}
                            {VARIABLE new_spawn[$unit_id].type $advanceto}
                            {VARIABLE new_spawn[$unit_id].role $next_role}
                        [/then]
                    [/if]
                [/else]
            [/if]
        [/then]
    [/if]
    [unstore_unit]
        variable=new_spawn[$unit_id]
        find_vacant=yes
    [/unstore_unit]
    {NEXT unit_id}
    {CLEAR_VARIABLE new_spawn}
#enddef

#define CLEAR_SPAWN_GROUP NUMBER
    {CLEAR_VARIABLE main_spawns[{NUMBER}]}
#enddef

#define REMOVE_SPAWN_GROUP NUMBER
    {VARIABLE index {NUMBER}}
    [while]
        [variable]
            name=index
            less_than=$main_group
        [/variable]
        [do]
            {VARIABLE from $index}
            {VARIABLE_OP from add 1}
            # clear the array at index
            {CLEAR_VARIABLE main_spawns[$index].spawn_type}
            #{CLEAR_VARIABLE main_spawns[$index].spawn_up1}
            #{CLEAR_VARIABLE main_spawns[$index].spawn_up2}
            #{CLEAR_VARIABLE main_spawns[$index].spawn_up3}
            # copy values 'from' to 'index'
            {VARIABLE main_spawns[$index].x $main_spawns[$from].x}
            {VARIABLE main_spawns[$index].y $main_spawns[$from].y}
            {VARIABLE spawn_number $main_spawns[$from].spawn_number}
            {VARIABLE main_spawns[$index].spawn_number $spawn_number}
            {VARIABLE spawn_id 1}
            [while]
                [variable]
                    name=spawn_id
                    less_than_equal_to=$spawn_number
                [/variable]
                [do]
                    {VARIABLE main_spawns[$index].spawn_type[$spawn_id].type $main_spawns[$from].spawn_type[$spawn_id].type}
                    {VARIABLE main_spawns[$index].spawn_type[$spawn_id].up1 $main_spawns[$from].spawn_type[$spawn_id].up1}
                    {VARIABLE main_spawns[$index].spawn_type[$spawn_id].up2 $main_spawns[$from].spawn_type[$spawn_id].up2}
                    {VARIABLE main_spawns[$index].spawn_type[$spawn_id].up3 $main_spawns[$from].spawn_type[$spawn_id].up3}
                    {VARIABLE_OP spawn_id add 1}
                [/do]
            [/while]
            {VARIABLE_OP index add 1}
        [/do]
    [/while]
    {VARIABLE_OP spawn_id format main_spawns[$main_group]}
    {CLEAR_VARIABLE $spawn_id}
    {VARIABLE_OP main_group add -1}
#enddef

#define VICTORY_CHECK_FROM_TURN TURN
    [event]
        name=die
        first_time_only=no
        [filter]
            side=1
        [/filter]
        [if]
            [variable]
                name=turn_number
                greater_than={TURN}
            [/variable]
            [then]
                [if]
                    [not]
                        [have_unit]
                            side=1
                            x=1-15
                            y=8-22
                        [/have_unit]
                    [/not]
                    [then]
                        [music]
                            name=victory.ogg
                            play_once=yes
                            immediate=yes
                        [/music]
                        [message]
                            speaker=narrator
                            message= _"The screams and pleas for mercy are finally silenced, as you remove your blood soaked blade from the last of the rebels. There will be no more resistance from the local scum. Your reign has finally earned stability."
                            image=wesnoth-icon.png
                        [/message]
                        [endlevel]
                            result=victory
                        [/endlevel]
                    [/then]
                [/if]
            [/then]
        [/if]
    [/event]
#enddef

#define FINAL_SPAWN
    [if]
        [variable]
            name=fixed_groups_left
            greater_than=0
        [/variable]
        [then]
            {RANDOMIZE $fixed_group}
            {VARIABLE fixed_id $random}
            {VARIABLE size $fixed_spawns[$fixed_id].spawn_number}
            [while]
                [variable]
                    name=size
                    less_than=1
                [/variable]
                [do]
                    {VARIABLE_OP fixed_id add 1}
                    [if]
                        [variable]
                            name=fixed_id
                            greater_than=$fixed_group
                        [/variable]
                        [then]
                            {VARIABLE fixed_id 1}
                        [/then]
                    [/if]
                    {VARIABLE size $fixed_spawns[$fixed_id].spawn_number}
                [/do]
            [/while]
            {VARIABLE id 1}
            {VARIABLE y 9}
            [while]
                [variable]
                    name=id
                    less_than_equal_to=$size
                [/variable]
                [do]
                    {VARIABLE type $fixed_spawns[$fixed_id].spawn_type[$id].type}
                    [unit]
                        type=$type
                        side=2
                        x=18
                        y=$y
                        random_traits=no
                        user_description="none"
                    [/unit]
                    {VARIABLE_OP y add 1}
                    {VARIABLE_OP id add 1}
                [/do]
            [/while]
            {VARIABLE fixed_x $fixed_spawns[$fixed_id].x}
            {VARIABLE fixed_y $fixed_spawns[$fixed_id].y}
            {PLACE_SPAWN_GROUP $fixed_x $fixed_y}
            {VARIABLE fixed_spawns[$fixed_id].spawn_number 0}
            {VARIABLE_OP fixed_groups_left add -1}
        [/then]
    [/if]
#enddef

#define REGULAR_RANDOM_SPAWNS SIDE INTERVAL SPAWN_NUM BASE_GOLD GOLD_INCREMENT UNITS GOLD_PER_UNIT
    {VARIABLE spawn_id 0}
    [while]
        [variable]
            name=spawn_id
            less_than=$main_group
        [/variable]
        [do]
            {VARIABLE turns $spawn_id}
            {VARIABLE_OP turns multiply {INTERVAL}}
            {VARIABLE_OP turns add 3}
            {VARIABLE_OP spawn_id add 1}
            {VARIABLE gold {BASE_GOLD}}
            {VARIABLE gold_turns $turns}
            {VARIABLE_OP gold_turns add -3}
            {VARIABLE_OP gold_turns multiply {GOLD_INCREMENT}}
            {VARIABLE_OP gold add $gold_turns}
            [if]
                [variable]
                    name=spawn_id
                    less_than={SPAWN_NUM}
                [/variable]
                [then]
                    # regular spawns
                    [if]
                        [variable]
                            name=spawn_id
                            greater_than=1
                        [/variable]
                        [then]
                            {VARIABLE units $gold_turns}
                            # add a random amount of the basic gold
                            {RANDOMIZE {BASE_GOLD}}
                            {VARIABLE gold1 $random}
                            {RANDOMIZE {BASE_GOLD}}
                            [if]
                                [variable]
                                    name=gold1
                                    less_than=random
                                [/variable]
                                [then]
                                    {VARIABLE random $gold1}
                                [/then]
                            [/if]
                            {CLEAR_VARIABLE gold1}
                            {VARIABLE_OP units add $random}
                            {VARIABLE unit_increment {GOLD_PER_UNIT}}
                            {VARIABLE unit_turns $turns}
                            {VARIABLE_OP unit_turns divide 1.5}
                            {VARIABLE_OP unit_increment add $unit_turns}
                            {VARIABLE_OP units divide $unit_increment}
                            ### DEBUG
                            {VARIABLE unit_increment $units}
                            ### END DEBUG
                            {VARIABLE_OP units add {UNITS}}
                            {RANDOMIZE 4}
                            {VARIABLE_OP random add -2}
                            {VARIABLE_OP units add $random}
                            {RANDOMIZE 5}
                            [if]
                                [variable]
                                    name=random
                                    numerical_equals=1
                                [/variable]
                                [then]
                                    {VARIABLE_OP units add -1}
                                [/then]
                            [/if]
                            {RANDOMIZE 3}
                            {VARIABLE_OP random add -2}
                            {VARIABLE_OP turns add $random}
                        [/then]
                        [else]
                            {VARIABLE units {UNITS}}
                            {VARIABLE_OP units add 1}
                            ### DEBUG
                            {VARIABLE unit_increment 0}
                            ### END DEBUG
                        [/else]
                    [/if]
                    {VARIABLE timed_spawn[$spawn_id].units $units}
                    {VARIABLE timed_spawn[$spawn_id].turn $turns}
                    {VARIABLE timed_spawn[$spawn_id].gold $gold}
                    ### DEBUG
                    {VARIABLE timed_spawn[$spawn_id].units_added $unit_increment}
                    ### END DEBUG
                [/then]
            [/if]
        [/do]
    [/while]
    {CLEAR_VARIABLE num}
    {VARIABLE triggered_spawns {SPAWN_NUM}}
    {VARIABLE_OP triggered_spawns add -1}
    {VARIABLE final_turns $timed_spawn[$triggered_spawns].turn}
    {CLEAR_VARIABLE triggered_spawns}
    {VARIABLE_OP final_turns add 40}
    {VARIABLE_OP final_turns divide 2}
    {VARIABLE fixed_groups_left $fixed_group}
    {VARIABLE trigger_index 1}
    {VARIABLE previous_spawn "no"}
    # reduce gold and units for spawns
    # after the final spawn
    {VARIABLE spawn_id 0}
    {VARIABLE num 0}
    [while]
        [variable]
            name=spawn_id
            less_than=$main_group
        [/variable]
        [do]
            {VARIABLE turn $timed_spawn[$spawn_id].turn}
            {VARIABLE end_spawn 0}
            [if]
                [variable]
                    name=turn
                    greater_than_equal_to=$final_turns
                [/variable]
                [then]
                    {VARIABLE diff_div 3}
                    {VARIABLE_OP diff_div add $end_spawn}
                    {VARIABLE_OP timed_spawn[$spawn_id].gold divide $diff_div}
                    {VARIABLE_OP diff_div add 1}
                    {VARIABLE_OP timed_spawn[$spawn_id].units divide $diff_div}
                    [if]
                        # two spawns added to the final
                        [variable]
                            name=end_spawn
                            greater_than=1
                        [/variable]
                        [then]
                            {VARIABLE timed_spawn[$spawn_id].turn -1}
                        [/then]
                        [else]
                            {VARIABLE_OP end_spawn add 1}
                        [/else]
                    [/if]
                [/then]
            [/if]
            {VARIABLE_OP spawn_id add 1}
        [/do]
    [/while]
    {VICTORY_CHECK_FROM_TURN $final_turns}
    [event]
        name=new turn
        first_time_only=no
        {VARIABLE spawn_now "no"}
        [if]
            [variable]
                name=turn_number
                greater_than=2
            [/variable]
            [then]
                {VARIABLE trigger_turn $timed_spawn[$trigger_index].turn}
                [if]
                    [variable]
                        name=turn_number
                        numerical_equals=$trigger_turn
                    [/variable]
                    [then]
                        # normal spawn
                        {VARIABLE gold $timed_spawn[$trigger_index].gold}
                        {VARIABLE max_units $timed_spawn[$trigger_index].units}
                        {VARIABLE min_cost 100}
                        {VARIABLE_OP trigger_index add 1}
                        {VARIABLE spawn_now "yes"}
                        {RANDOMIZE_INDEX 2}
                        {VARIABLE previous_spawn "yes"}
                    [/then]
                [/if]
            [/then]
        [/if]
        [if]
            [variable]
                name=spawn_now
                equals="yes"
            [/variable]
            [then]
                ### DEBUG
                {VARIABLE total_cost 0}
                {VARIABLE size $main_group}
                {RANDOMIZE $size}
                {VARIABLE group_id $random}
                {VARIABLE size $main_spawns[$group_id].spawn_number}
                [while]
                    [variable]
                        name=gold
                        greater_than=0
                    [/variable]
                    [variable]
                        name=max_units
                        greater_than=0
                    [/variable]
                    [do]
                        {RANDOMIZE $size}
                        [if]
                            [variable]
                                name=random
                                greater_than=0
                            [/variable]
                            [then]
                                {VARIABLE type $main_spawns[$group_id].spawn_type[$random].type}
                                {SPAWN_UNIT {SIDE} $type $random 1 $max_units}
                            [/then]
                            [else]
                                # fallback for invalid/cleared spawn groups
                                {VARIABLE gold 0}
                            [/else]
                        [/if]
                    [/do]
                [/while]
                {ADJUST_UNIT_LEVEL {SIDE} 1}
                {ADJUST_UNIT_LEVEL {SIDE} 2}
                {ADJUST_UNIT_LEVEL {SIDE} 3}
                # spend remainder
                {VARIABLE extra_units 3}
                [while]
                    [variable]
                        name=gold
                        greater_than_equal_to=$min_cost
                    [/variable]
                    [variable]
                        name=extra_units
                        greater_than=0
                    [/variable]
                    [do]
                        {RANDOMIZE $size}
                        [if]
                            [variable]
                                name=random
                                greater_than=0
                            [/variable]
                            [then]
                                {VARIABLE type $main_spawns[$group_id].spawn_type[$random].type}
                                {SPAWN_UNIT {SIDE} $type $random 5 $max_units}
                                {VARIABLE_OP extra_units add -1}
                            [/then]
                            [else]
                                # fallback for invalid/cleared spawn groups
                                {VARIABLE gold 0}
                            [/else]
                        [/if]
                    [/do]
                [/while]
                {VARIABLE spawn_x $main_spawns[$group_id].x}
                {VARIABLE spawn_y $main_spawns[$group_id].y}
                {PLACE_SPAWN_GROUP $spawn_x $spawn_y}
                {REMOVE_SPAWN_GROUP $group_id}
                [music]
                    name=frantic.ogg
                    ms_before=300
                    play_once=yes
                    immediate=yes
                [/music]
            [/then]
        [/if]
    [/event]

    # the event extending the turn limit
    # and firing final spawns
    [event]
        name=new turn
        first_time_only="no"
        {VARIABLE next_turn $turn_number}
        {VARIABLE_OP next_turn add 1}
        [if]
            [variable]
                name=turn_number
                equals=$final_turns
            [/variable]
            [then]
                [music]
                    name=battle.ogg
                    ms_before=200
                    immediate=yes
                    append=yes
                [/music]
                {FINAL_SPAWN}
                {VARIABLE new_limit 12}
                {VARIABLE_OP new_limit add $turn_number}
                {VARIABLE_OP new_limit add -45}
                [modify_turns]
                    add=$new_limit
                [/modify_turns]
                {VARIABLE next_final_spawn $turn_number}
                {RANDOMIZE_INDEX 2}
                {VARIABLE_OP next_final_spawn add $random}
                [message]
                    side=3,4
                    canrecruit=yes
                    message= _ "The last and most powerful of these creatures are almost upon us. I feel that if we can finish them off in time, we shall be victorious."
                [/message]
            [/then]
            [else]
                [if]
                    [variable]
                        name=turn_number
                        greater_than=43
                    [/variable]
                    [variable]
                        name=next_final_spawn
                        equals=99
                    [/variable]
                    [then]
                        [modify_turns]
                            add=1
                        [/modify_turns]
                    [/then]
                    [else]
                        [if]
                            [variable]
                                name=turn_number
                                greater_than=$next_final_spawn
                            [/variable]
                            [then]
                                {FINAL_SPAWN}
                                {RANDOMIZE 2}
                                {VARIABLE_OP next_final_spawn add $random}
                            [/then]
                        [/if]
                    [/else]
                [/if]
            [/else]
        [/if]
    [/event]
#enddef

# XX is either an X coordinate (for fixed spawn position)
# or "random" for a random location
# chosen from the spawn_place array
# set in DEFINE_SPAWN_LOCATION
# (in the latter case YY is ignored)
#define DEFINE_MAIN_GROUP XX YY
    {VARIABLE spawn_id 0}
    {VARIABLE_OP main_group add 1}
    {VARIABLE main_spawns[$main_group].x {XX}}
    {VARIABLE main_spawns[$main_group].y {YY}}
#enddef

#define ADD_MAIN_SPAWN TYPE UP1 UP2 UP3
    {VARIABLE_OP spawn_id add 1}
    {VARIABLE main_spawns[$main_group].spawn_type[$spawn_id].type {TYPE}}
    {VARIABLE main_spawns[$main_group].spawn_type[$spawn_id].up1 {UP1}}
    {VARIABLE main_spawns[$main_group].spawn_type[$spawn_id].up2 {UP2}}
    {VARIABLE main_spawns[$main_group].spawn_type[$spawn_id].up3 {UP3}}
    {VARIABLE main_spawns[$main_group].spawn_number $spawn_id}
#enddef

#define DEFINE_SPAWN_LOCATION X_SPAN Y_SPAN
    {VARIABLE_OP location add 1}
    {VARIABLE spawn_place[$location].x {X_SPAN}}
    {VARIABLE spawn_place[$location].y {Y_SPAN}}
#enddef

#define DEFINE_FIXED_GROUP X Y
    {VARIABLE spawn_id 0}
    {VARIABLE_OP fixed_group add 1}
    {VARIABLE fixed_spawns[$fixed_group].x {X}}
    {VARIABLE fixed_spawns[$fixed_group].y {Y}}
#enddef

#define ADD_FIXED_SPAWN TYPE
    {VARIABLE_OP spawn_id add 1}
    {VARIABLE fixed_spawns[$fixed_group].spawn_type[$spawn_id].type {TYPE}}
    {VARIABLE fixed_spawns[$fixed_group].spawn_number $spawn_id}
#enddef

#define SET_TIMID_AI_AND_BOLD_AI TIMID BOLD
    {VARIABLE timid_ai_side {TIMID}}
    {VARIABLE bold_ai_side {BOLD}}
    [event]
        name=side turn
        first_time_only=no
        [if]
            [variable]
                name=side_number
                greater_than=$timid_ai_side
            [/variable]
            [then]
                {ADJUST_AGGRESSION $timid_ai_side $bold_ai_side}
            [/then]
        [/if]
    [/event]
#enddef

#define WEATHER_EVENT_AT TURN WEATHER
    {VARIABLE_OP weather_events add 1}
    {VARIABLE weather_event[$weather_events].turn {TURN}}
    {VARIABLE weather_event[$weather_events].weather {WEATHER}}
    {RANDOMIZE 2}
    {VARIABLE_OP turn add $random}
    {VARIABLE_OP weather[{WEATHER}].turns add -$random}
    {VARIABLE max_turns 2}
    {VARIABLE w_id {WEATHER}}
    [if]
        [variable]
            name=w_id
            numerical_equals=0
        [/variable]
        [then]
            {VARIABLE max_turns 1}
        [/then]
    [/if]
    [while]
        [variable]
            name=max_turns
            greater_than=0
        [/variable]
        [variable]
            name=weather[{WEATHER}].turns
            greater_than=1
        [/variable]
        [do]
            {RANDOMIZE 3}
            {VARIABLE_OP random add -1}
            [if]
                [variable]
                    name=random
                    less_than=2
                [/variable]
                [then]
                    {VARIABLE_OP turn add $random}
                    {VARIABLE_OP max_turns add -$random}
                    {VARIABLE_OP weather[{WEATHER}].turns add -$random}
                [/then]
                [else]
                    # stop incrementing
                    {VARIABLE max_turns 0}
                [/else]
            [/if]
        [/do]
    [/while]
    {CLEAR_VARIABLE w_id}
#enddef

#define WEATHER_MAP NAME
    [terrain_mask]
        mask={NAME}
        x=1
        y=1
    [/terrain_mask]
#enddef

#define WEATHER_ALERT TEXT RED GREEN BLUE
    [print]
        text= {TEXT}
        duration=120
        size=26
        red={RED}
        green={GREEN}
        blue={BLUE}
    [/print]
#enddef

#define ADJUST_WEATHER
    {VARIABLE weather $weather_event[$next_weather].weather}
    [if]
        [variable]
            name=weather_change
            numerical_equals=4
        [/variable]
        [then]
            # second snow
            {WEATHER_MAP "{multiplayer/maps/Dark_Forecast_secondsnow.mask}"}
            [sound]
                name=wolf-die.wav
            [/sound]
            {WEATHER_ALERT _"Heavy Snowfall" 224 255 251}
        [/then]
        [else]
            [if]
                [variable]
                    name=weather_change
                    numerical_equals=3
                [/variable]
                [then]
                    # first snow
                    {WEATHER_MAP "{multiplayer/maps/Dark_Forecast_firstsnow.mask}"}
                    [sound]
                        name=wail.wav
                    [/sound]
                    {WEATHER_ALERT _"Snowfall" 229 243 241}
                [/then]
                [else]
                    [if]
                        [variable]
                            name=weather_change
                            numerical_equals=2
                        [/variable]
                        [then]
                            # heavy rains
                            {WEATHER_MAP "{multiplayer/maps/Dark_Forecast_rain.mask}"}
                            [sound]
                                name=magic-faeriefire-miss.ogg
                            [/sound]
                            [delay]
                                time=250
                            [/delay]
                            [sound]
                                name=ambient/ship.ogg
                            [/sound]
                            {WEATHER_ALERT _"Heavy Rains" 174 220 255}
                        [/then]
                        [else]
                            [if]
                                [variable]
                                    name=weather_change
                                    numerical_equals=1
                                [/variable]
                                [then]
                                    # drought
                                    {WEATHER_MAP "{multiplayer/maps/Dark_Forecast_drought.mask}"}
                                    [sound]
                                        name=gryphon-shriek-1.ogg
                                    [/sound]
                                    {WEATHER_ALERT _"Drought" 251 231 171}
                                [/then]
                                [else]
                                    # clear weather
                                    {WEATHER_MAP "{multiplayer/maps/Dark_Forecast_basic.mask}"}
                                    [sound]
                                        name=magic-holy-miss-2.ogg
                                    [/sound]
                                    {WEATHER_ALERT _"Clear Weather" 221 253 171}
                                [/else]
                            [/if]
                        [/else]
                    [/if]
                [/else]
            [/if]
        [/else]
    [/if]
#enddef

#define INIT_WEATHER
    {VARIABLE turn 5}
    {RANDOMIZE 3}
    {VARIABLE_OP random add -2}
    {VARIABLE_OP turn add $random}
    {VARIABLE weather[0].turns 22}
    {VARIABLE weather[0].name "Clear"}
    {VARIABLE weather[1].turns 10}
    {VARIABLE weather[1].name "Drought"}
    {VARIABLE weather[2].turns 12}
    {VARIABLE weather[2].name "Heavy Rain"}
    {VARIABLE weather[3].turns 9}
    {VARIABLE weather[3].name "Snowfall"}
    {VARIABLE weather[4].turns 6}
    {VARIABLE weather[4].name "Heavy Snowfall"}
    {VARIABLE next_weather 1}
    {VARIABLE weather_events 0}
    [while]
        [variable]
            name=turn
            less_than=55
        [/variable]
        [do]
            {RANDOMIZE 3}
            {VARIABLE check 3}
            [while]
                [variable]
                    name=weather[$random].turns
                    less_than=1
                [/variable]
                [variable]
                    name=check
                    greater_than=0
                [/variable]
                [do]
                    {VARIABLE_OP random add 1}
                    [if]
                        [variable]
                            name=random
                            greater_than=3
                        [/variable]
                        [then]
                            {VARIABLE random 1}
                        [/then]
                    [/if]
                    {VARIABLE_OP check add -1}
                [/do]
            [/while]
            {VARIABLE id $random}
            {WEATHER_EVENT_AT $turn $id}
            # check for second snow
            [if]
                [variable]
                    name=id
                    numerical_equals=3
                [/variable]
                [then]
                    {RANDOMIZE 2}
                    {VARIABLE check $weather[4].turns}
                    [if]
                        [variable]
                            name=random
                            equals=1
                        [/variable]
                        [variable]
                            name=check
                            greater_than=0
                        [/variable]
                        [then]
                            {WEATHER_EVENT_AT $turn 4}
                        [/then]
                    [/if]
                [/then]
            [/if]
            {WEATHER_EVENT_AT $turn 0}
        [/do]
    [/while]
    [event]
        name=side turn
        first_time_only=no
        {VARIABLE turn_for_weather $weather_event[$next_weather].turn}
        [if]
            [variable]
                name=weather_change
                greater_than=-1
            [/variable]
            [variable]
                name=side_number
                numerical_equals=3
            [/variable]
            [then]
                {ADJUST_WEATHER}
            [/then]
        [/if]
    [/event]
    [event]
        name=new turn
        first_time_only=no
        {VARIABLE turn_weather $weather_event[$next_weather].turn}
        [if]
            [variable]
                name=turn_number
                greater_than_equal_to=$turn_weather
            [/variable]
            [then]
                {VARIABLE weather_change $weather_event[$next_weather].weather}
                {VARIABLE_OP next_weather add 1}
            [/then]
            [else]
                {VARIABLE weather_change -1}
            [/else]
        [/if]
    [/event]
#enddef

    {DAWN}
    {MORNING}
    {AFTERNOON}
    {DUSK}
    {FIRST_WATCH}
    {SECOND_WATCH}

    [side]
        side=1
        canrecruit=yes
        team_name="revolt"
        allow_player=no
        disallow_observers=yes
        no_leader=yes
        controller="ai"
        village_gold=1
        [unit]
            type=Ancient Lich
            canrecruit=yes
            x=8
            y=6
            ai_special=guardian
            [modifications]
                [object]
                    [effect]
                        apply_to=movement_costs
                        replace=true
                        [movement_costs]
                            tundra=99
                        [/movement_costs]
                    [/effect]
                [/object]
            [/modifications]
        [/unit]
    [/side]

    [side]
        side=2
        colour=red
        canrecruit=yes
        team_name="revolt"
        allow_player=no
        disallow_observers=yes
        no_leader=yes
        controller="ai"
        village_gold=1
        [ai]
            aggression=-4.0
            caution=0.99
            grouping=defensive
            village_value=12
            attack_depth=1
        [/ai]
    [/side]

    [side]
        side=3
        canrecruit=yes
        team_name="human"
        controller="human"
        save_id="Player1"
        village_gold=1
        gold=75
        income=0
        gold_lock="true"
        income_lock="true"
        team_lock="true"
        fog="yes"
    [/side]

    [side]
        side=4
        canrecruit=yes
        team_name="human"
        controller="human"
        save_id="Player2"
        village_gold=1
        gold=75
        income=0
        gold_lock="true"
        income_lock="true"
        team_lock="true"
        fog="yes"
    [/side]

    [event]
        name=prestart
        {SET_TIMID_AI_AND_BOLD_AI 2 1}
        {VARIABLE location 0}
        {VARIABLE turn_limit 40}
        {DEFINE_SPAWN_LOCATION "3-14" "22"} #south
        {DEFINE_SPAWN_LOCATION "1" "11-20"} #west
        {DEFINE_SPAWN_LOCATION "2-13" "9"} #north
        {DEFINE_SPAWN_LOCATION "1" "9-22"} #west

        {VARIABLE main_group 0}

        # this is used as spacer for the final spawns
        {VARIABLE next_final_spawn 99}

        {DEFINE_MAIN_GROUP random 1}
        {ADD_MAIN_SPAWN "Heavy Infantryman" "Shock Trooper" "Iron Mauler" "none"}
        {ADD_MAIN_SPAWN "Elvish Fighter" "Elvish Hero" "more" "Elvish Champion"}
        {ADD_MAIN_SPAWN "Goblin Spearman" "more" "more" "more"}
        {ADD_MAIN_SPAWN "Goblin Spearman" "Goblin Rouser" "none" "none"}
        {ADD_MAIN_SPAWN "Elvish Fighter" "Elvish Captain" "Elvish Marshal" "none"}

        {DEFINE_MAIN_GROUP random 2}
        {ADD_MAIN_SPAWN "Mage" "Red Mage" "Silver Mage" "none"}
        {ADD_MAIN_SPAWN "Footpad" "Outlaw" "more" "none"}
        {ADD_MAIN_SPAWN "Drake Fighter" "Drake Warrior" "Drake Blademaster" "none"}
        {ADD_MAIN_SPAWN "Walking Corpse" "more" "more" "more"}

        {DEFINE_MAIN_GROUP random 3}
        {ADD_MAIN_SPAWN "Merman Hunter" "Merman Spearman" "Merman Entangler" "none"}
        {ADD_MAIN_SPAWN "Naga Fighter" "Naga Warrior" "Naga Myrmidon" "none"}
        {ADD_MAIN_SPAWN "Spearman" "Pikeman" "none" "Halberdier"}

        {DEFINE_MAIN_GROUP random 4}
        {ADD_MAIN_SPAWN "Elvish Shaman" "Elvish Druid" "Elvish Shyde" "Elvish Sylph"}
        {ADD_MAIN_SPAWN "Drake Burner" "Fire Drake" "Inferno Drake" "Armageddon Drake"}
        {ADD_MAIN_SPAWN "Skeleton" "Revenant" "more" "Draug"}

        {DEFINE_MAIN_GROUP random 5}
        {ADD_MAIN_SPAWN "Giant Mudcrawler" "Sea Serpent" "none" "none"}
        {ADD_MAIN_SPAWN "Mudcrawler" "more" "Giant Mudcrawler" "more"}

        {DEFINE_MAIN_GROUP random 6}
        {ADD_MAIN_SPAWN "Ghoul" "Necrophage" "more" "none"}
        {ADD_MAIN_SPAWN "Elvish Archer" "Elvish Marksman" "none" "Elvish Sharpshooter"}
        {ADD_MAIN_SPAWN "Elvish Archer" "Elvish Ranger" "Elvish Avenger" "none"}
        {ADD_MAIN_SPAWN "Drake Clasher" "Drake Gladiator" "more" "Drake Enforcer"}

        {DEFINE_MAIN_GROUP random 7}
        {ADD_MAIN_SPAWN "Skeleton Archer" "Bone Shooter" "more" "Banebow"}
        {ADD_MAIN_SPAWN "Fencer" "Duelist" "none" "Master at Arms"}
        {ADD_MAIN_SPAWN "Drake Glider" "Sky Drake" "Hurricane Drake" "none"}

        {DEFINE_MAIN_GROUP random 8}
        {ADD_MAIN_SPAWN "Merman Fighter" "Merman Warrior" "more" "Merman Triton"}
        {ADD_MAIN_SPAWN "Dark Adept" "Dark Sorcerer" "Necromancer" "none"}
        {ADD_MAIN_SPAWN "Elvish Scout" "Elvish Rider" "more" "none"}

        {DEFINE_MAIN_GROUP random 9}
        {ADD_MAIN_SPAWN "Wose" "Elder Wose" "Ancient Wose" "none"}
        {ADD_MAIN_SPAWN "Orcish Archer" "Orcish Crossbowman" "Orcish Slurbow" "none"}
        {ADD_MAIN_SPAWN "Saurian Skirmisher" "more" "Saurian Ambusher" "more"}

        {DEFINE_MAIN_GROUP random 10}
        {ADD_MAIN_SPAWN "Orcish Grunt" "Orcish Warrior" "more" "none"}
        {ADD_MAIN_SPAWN "Vampire Bat" "Blood Bat" "more" "none"}
        {ADD_MAIN_SPAWN "Dwarvish Thunderer" "Dwarvish Thunderguard" "none" "none"}
        {ADD_MAIN_SPAWN "Peasant" "more" "more" "more"}
        {ADD_MAIN_SPAWN "Woodsman" "more" "Sergeant" "Orcish Ruler"}

        {DEFINE_MAIN_GROUP random 11}
        {ADD_MAIN_SPAWN "Dwarvish Guardsman" "Dwarvish Stalwart" "none" "none"}
        {ADD_MAIN_SPAWN "Bowman" "Longbowman" "more" "Master Bowman"}
        {ADD_MAIN_SPAWN "Troll Whelp" "Troll" "Troll Warrior" "none"}

        {DEFINE_MAIN_GROUP random 12}
        {ADD_MAIN_SPAWN "Orcish Assassin" "Orcish Slayer" "more" "none"}
        {ADD_MAIN_SPAWN "Cavalryman" "Dragoon" "more" "Cavalier"}
        {ADD_MAIN_SPAWN "Saurian Augur" "Saurian Soothsayer" "none" "none"}

        {DEFINE_MAIN_GROUP random 13}
        {ADD_MAIN_SPAWN "Wolf Rider" "Goblin Pillager" "more" "none"}
        {ADD_MAIN_SPAWN "Ghost" "Shadow" "more" "more"}
        {ADD_MAIN_SPAWN "Sergeant" "Lieutenant" "General" "Grand Marshal"}

        {DEFINE_MAIN_GROUP random 14}
        {ADD_MAIN_SPAWN "Gryphon Rider" "none" "more" "none"}
        {ADD_MAIN_SPAWN "Thief" "Rogue" "more" "Assassin"}

        {DEFINE_MAIN_GROUP random 15}
        {ADD_MAIN_SPAWN "Dwarvish Fighter" "Dwarvish Steelclad" "more" "Dwarvish Lord"}
        {ADD_MAIN_SPAWN "Poacher" "Trapper" "more" "none"}
        {ADD_MAIN_SPAWN "Cuttle Fish" "more" "more" "none"}

        {DEFINE_MAIN_GROUP random 16}
        {ADD_MAIN_SPAWN "Walking Corpse" "more" "more" "more"}
        {ADD_MAIN_SPAWN "Mage" "White Mage" "Mage of Light" "none"}
        {ADD_MAIN_SPAWN "Thug" "Bandit" "more" "none"}

        {VARIABLE fixed_group 0}

        {DEFINE_FIXED_GROUP 1 22}
        {ADD_FIXED_SPAWN "Fire Dragon"}
        {ADD_FIXED_SPAWN "Gryphon Master"}
        {ADD_FIXED_SPAWN "Hurricane Drake"}

        {DEFINE_FIXED_GROUP 5 8}
        {ADD_FIXED_SPAWN "Yeti"}
        {ADD_FIXED_SPAWN "Elvish Druid"}
        {ADD_FIXED_SPAWN "Elvish Druid"}

        {DEFINE_FIXED_GROUP 1 14}
        {ADD_FIXED_SPAWN "Lich"}
        {ADD_FIXED_SPAWN "Walking Corpse"}
        {ADD_FIXED_SPAWN "Walking Corpse"}
        {ADD_FIXED_SPAWN "Walking Corpse"}
        {ADD_FIXED_SPAWN "Ghoul"}
        {ADD_FIXED_SPAWN "Soulless"}
        {ADD_FIXED_SPAWN "Walking Corpse"}
        {ADD_FIXED_SPAWN "Walking Corpse"}
        {ADD_FIXED_SPAWN "Walking Corpse"}

        {DEFINE_FIXED_GROUP 11 22}
        {ADD_FIXED_SPAWN "Elvish Champion"}
        {ADD_FIXED_SPAWN "Dwarvish Stalwart"}
        {ADD_FIXED_SPAWN "Dwarvish Stalwart"}
        {ADD_FIXED_SPAWN "Orcish Slayer"}

        [store_unit]
            variable=leader
            [filter]
                side=3,4
            [/filter]
            kill=no
        [/store_unit]
        [if]
            [variable]
                name=leader.length
                less_than=2
            [/variable]
            [then]
                {VARIABLE notes ( _"Single player mode - uses the reduced strength spawns.")}
            [/then]
            [else]
                {VARIABLE notes ( _"Two player mode - uses the full strength spawns.")}
            [/else]
        [/if]

        [music]
            name=wanderer.ogg
            ms_before=2000
        [/music]
        [music]
            name=battle.ogg
            ms_before=2000
            append=yes
        [/music]
        [music]
            name=breaking_the_chains.ogg
            play_once=yes
            immediate=yes
        [/music]

        [objectives]
            summary= _ "Survive and defeat the waves of opposition."
            [objective]
                description= _ "Defeat all waves"
                condition=win
            [/objective]
            [objective]
                description= _ "Lose all your team's leaders"
                condition=lose
            [/objective]
            note=$notes
        [/objectives]
        {CLEAR_VARIABLE notes}
    [/event]

    [event]
        name=start
        [message]
            caption= _"Dark Forecast - a random survival scenario"
            speaker=narrator
            image=misc/schedule-dawn.png
            message= _ "Your aim is to survive the spawning waves and defeat the final arch-enemies.
       
The spawning waves are generated randomly and will different each time Dark Forecast is played.


They appear along the north, south and west map edges - though they are most likely to spawn on the west edge. The spawn waves appear at somewhat regular intervals.


The weather will also change randomly, affecting the layout of the map.



#Dark Forecast was made by:

@jb
- map design, spawn groups and scenario concept

@Rhuvaen
- WML implementation"
        [/message]
        [message]
            side=3
            message= _"So this is the accursed valley - a land ours for the taking."
        [/message]
        [message]
            side=4
            message= _"The inhabitants are rumored to be a strange alliance of man and beast, and our claim is not going to be unopposed. We must be prepared for the surprises of this land."
        [/message]
        [message]
            side=3
            message= _"Then let us discover what lies in waiting and teach them not to oppose our claim."
        [/message]
    [/event]

    [event]
        name=turn 2
        {INIT_WEATHER}
        [if]
            [variable]
                name=leader.length
                less_than=2
            [/variable]
            [then]
                {REGULAR_RANDOM_SPAWNS 2 5 12 50 5 4 21}
            [/then]
            [else]
                {REGULAR_RANDOM_SPAWNS 2 4 12 90 4 5 23}
            [/else]
        [/if]
        {CLEAR_VARIABLE leader}
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            side=3,4
            canrecruit=yes
        [/filter]
        [if]
            [have_unit]
                side=3,4
                canrecruit=yes
            [/have_unit]
            [then]
                [message]
                    speaker=unit
                    message= _"Ugh!  How can this be?  Defeated by mere barbarians! My gods have forsaken me..."
                [/message]
            [/then]
            [else]
                [music]
                    name=defeat.ogg
                    play_once=yes
                    immediate=yes
                [/music]
                [sound]
                    name=dwarf-laugh.wav
                [/sound]
                [message]
                    speaker=second_unit
                    message= _"Cheers of your enemy are the last thing you hear as you slip into death...their joy fills your last moments with pure hate."
                [/message]
                [endlevel]
                    result=defeat
                [/endlevel]
            [/else]
        [/if]
    [/event]

    [event]
        name=time over
        [music]
            name=defeat.ogg
            play_once=yes
            immediate=yes
        [/music]
        [sound]
            name=dwarf-laugh.wav
        [/sound]
        [message]
            side=1,2
            canrecruit=yes
            message= _ "The enemy cheers as a dark mist rises from the land, engulfing you. As ghostly wisps drain away your will, you realize that your time in this land is over."
        [/message]
    [/event]

    #undef RANDOMIZE
    #undef RANDOMIZE_INDEX
    #undef PLACE_SPAWN_GROUP
    #undef ADJUST_AGGRESSION
    #undef SPAWN_UNIT
    #undef ADJUST_UNIT_LEVEL
    #undef CLEAR_SPAWN_GROUP
    #undef REMOVE_SPAWN_GROUP
    #undef VICTORY_CHECK_FROM_TURN
    #undef FINAL_SPAWN
    #undef REGULAR_RANDOM_SPAWNS
    #undef DEFINE_MAIN_GROUP
    #undef ADD_MAIN_SPAWN
    #undef DEFINE_SPAWN_LOCATION
    #undef DEFINE_FIXED_GROUP
    #undef ADD_FIXED_SPAWN
    #undef SET_TIMID_AI_AND_BOLD_AI
    #undef WEATHER_EVENT_AT
    #undef WEATHER_MAP
    #undef WEATHER_ALERT
    #undef ADJUST_WEATHER
    #undef INIT_WEATHER
[/multiplayer]
