//==========================================================================================
//
//  erdenberg_t1.gm
//
//  Who         When            What
//------------------------------------------------------------------------------------------
//  ^4Tardis    30 April 2011   Initial Script
//
//==========================================================================================
//

global Map =
{
    Allied_Command_Post_Built = function()
    {
        Util.MapDebugPrint( "Allied_Command_Post_Built", true );
    },

    Allied_Command_Post_Planted = function()
    {
        Util.MapDebugPrint( "Command_Post_Planted", true );
    },

    Allied_Command_Post_Defused = function()
    {
        Util.MapDebugPrint( "Command_Post_Defused", true );
    },

    Allied_Command_Post_Destroyed = function()
    {
        Util.MapDebugPrint( "Allied_Command_Post_Destroyed", true );
    },

    Axis_Command_Post_Built = function()
    {
        Util.MapDebugPrint( "Axis_Command_Post_Built", true );
    },

    Axis_Command_Post_Planted = function()
    {
        Util.MapDebugPrint( "Command_Post_Planted", true );
    },

    Axis_Command_Post_Defused = function()
    {
        Util.MapDebugPrint( "Command_Post_Defused", true );
    },

    Axis_Command_Post_Destroyed = function()
    {
        Util.MapDebugPrint( "Axis_Command_Post_Destroyed", true );
    },

    East_Flak88_Planted = function()
    {
        Util.MapDebugPrint( "East_Flak88_Planted", true );
    },

    East_Flak88_Defused = function()
    {
        Util.MapDebugPrint( "East_Flak88_Defused", true );
    },

    East_Flak88_Destroyed = function()
    {
        SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_east.*" );
        SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_east.*" );

        Util.MapDebugPrint( "East_Flak88_Destroyed" );
    },

    West_Flak88_Planted = function()
    {
        Util.MapDebugPrint( "West_Flak88_Planted", true );
    },

    West_Flak88_Defused = function()
    {
        Util.MapDebugPrint( "West_Flak88_Defused", true );
    },

    West_Flak88_Destroyed = function()
    {
        SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_west.*" );
        SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_west.*" );

        Util.MapDebugPrint( "West_Flak88_Destroyed" );
    },


    Main_Entrance_Planted = function()
    {
        Util.MapDebugPrint( "Main_Entrance_Planted", true );
    },

    Main_Entrance_Defused = function()
    {
        Util.MapDebugPrint( "Main_Entrance_Defused", true );
    },

    Main_Entrance_Destroyed = function()
    {
        SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_main.*" );
        SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_main.*" );
        SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT_forward_flag" );
        SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT_forward_flag" );
        Util.EnableGoal( ".*Command_Post" );

        // East
        SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_east.*" );
        SetAvailableMapGoals( TEAM.ALLIES, true, {
        	"ATTACK_east.*",
        	"PLANT_East_Flak88",
        });

        // West
        SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_west.*" );
        SetAvailableMapGoals( TEAM.ALLIES, true, {
        	"ATTACK_west.*",
        	"PLANT_West_Flak88",
        });

        Util.MapDebugPrint( "Main_Entrance_Destroyed" );
    },

    forward_flag_Axis_Captured = function()
    {
        Util.MapDebugPrint( "forward_flag_Axis_Captured", true );
    },

    forward_flag_Allies_Captured = function()
    {
        Util.MapDebugPrint( "forward_flag_Allies_Captured", true );
    },
};

global OnMapLoad = function()
{
    // Register callback functions
    OnTrigger( "Planted at the East Flak88.", Map.East_Flak88_Planted );
    OnTrigger( "Planted at the Main Entrance.", Map.Main_Entrance_Planted );
    OnTrigger( "Planted at the West Flak88.", Map.West_Flak88_Planted );
    OnTrigger( "Planted at the Allied Command Post.", Map.Allied_Command_Post_Planted );
    OnTrigger( "Planted at the Axis Command Post.", Map.Axis_Command_Post_Planted );
    OnTrigger( "Defused at the Allied Command Post.", Map.Allied_Command_Post_Defused );
    OnTrigger( "Defused at the Axis Command Post.", Map.Axis_Command_Post_Defused );
    OnTrigger( "Defused at the East Flak88.", Map.East_Flak88_Defused );
    OnTrigger( "Defused at the Main Entrance.", Map.Main_Entrance_Defused );
    OnTrigger( "Defused at the West Flak88.", Map.West_Flak88_Defused );
    OnTrigger( "The East Flak88 has been destroyed!", Map.East_Flak88_Destroyed );
    OnTrigger( "Main Gate has been destroyed!", Map.Main_Entrance_Destroyed );
    OnTrigger( "The West Flak88 has been destroyed!", Map.West_Flak88_Destroyed );
    OnTrigger( "The Axis have reclaimed the forward bunker!", Map.forward_flag_Axis_Captured );
    OnTrigger( "The Allies have captured the forward bunker!", Map.forward_flag_Allies_Captured );

    Util.DisableGoal( ".*", true ); // All but routes
    SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_main.*" );
    SetAvailableMapGoals( TEAM.ALLIES, true, {
    	"ATTACK_main.*",
    	"PLANT_Main_Entrance",
    });
    SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT_forward_flag" );
    SetAvailableMapGoals( TEAM.ALLIES, true, "CHECKPOINT_forward_flag" );
    SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Command_Post" );

    SetGoalPriority( "PLANT_Command_Post.*", 0.49, 0, CLASS.ENGINEER );

    // Max users per goal
    Util.SetMaxUsers( 1, "DEFEND_.*" );
    Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
    Util.SetMaxUsers( 2, "CHECKPOINT.*" );
    Util.SetMaxUsers( 1, "PLANT.*" );
    Util.SetMaxUsers( 1, "BUILD.*" );
    Util.SetMaxUsers( 1, "PLANT_Command_Post" );

    // Camp times
    SetMapGoalProperties( "MOUNTMG42_.*",  { MinCampTime = 15, MaxCampTime = 90 } );

    Util.MapDebugPrint( "Omni-bot map script for " + GetMapName() + " executed." );
};

global OnBotJoin = function( bot )
{
    bot.TargetBreakableDist = 90.0;
};

global InitializeRoutes = function()
{
    MapRoutes =
    {
        CHECKPOINT_forward_flag =
        {
            ROUTE_alliedSP =
            {
                ROUTE_tunnel =
                {
                    ROUTE_tunnelsp =
                    {
                        ROUTE_tunnelB =
                        {
                            ROUTE_main_2 =
                            {
                                ROUTE_main_3 =
                                {
                                    ROUTE_main_4 =
                                    {
                                        ROUTE_SPFlag = {},
                                    },
                                },
                            },
                        },
                        ROUTE_tunnelA =
                        {
                            ROUTE_SPFlag = {},
                        },
                    },
                },
                ROUTE_main =
                {
                    ROUTE_main_1 =
                    {
                        ROUTE_main_2 =
                        {
                            ROUTE_main_3 =
                            {
                                ROUTE_main_4 =
                                {
                                    ROUTE_SPFlag = {},
                                },
                            },
                        },
                    },
                },
                ROUTE_ramp =
                {
                    ROUTE_ramp_1 =
                    {
                        ROUTE_ramp_2 =
                        {
                            ROUTE_ramp_3 =
                            {
                                ROUTE_ramp_4 =
                                {
                                    ROUTE_SPFlag = {},
                                },
                            },
                        },
                    },
                },
            },
        },

        PLANT_Main_Entrance =
        {
            ROUTE_alliedSP =
            {
                ROUTE_tunnel =
                {
                    ROUTE_tunnelsp =
                    {
                        ROUTE_tunnelB =
                        {
                            ROUTE_main_2 =
                            {
                                ROUTE_main_3 =
                                {
                                    ROUTE_main_4 = {},
                                },
                            },
                        },
                        ROUTE_tunnelA =
                        {
                            ROUTE_main_4 = {},
                        },
                    },
                },
                ROUTE_ramp =
                {
                    ROUTE_ramp_1 =
                    {
                        ROUTE_ramp_2 =
                        {
                            ROUTE_ramp_3 =
                            {
                                ROUTE_ramp_4 =
                                {
                                    ROUTE_main_4 = {},
                                },
                            },
                        },
                    },
                },
                ROUTE_main =
                {
                    ROUTE_main_1 =
                    {
                        ROUTE_main_2 =
                        {
                            ROUTE_main_3 =
                            {
                                ROUTE_main_4 = {},
                            },
                        },
                    },
                },
            },
        },

        PLANT_East_Flak88 =
        {
            ROUTE_SPFlag =
            {
                ROUTE_east =
                {
                    ROUTE_east_1 =
                    {
                        ROUTE_east_2 =
                        {
                            ROUTE_east_3 =
                            {
                                ROUTE_east_4 =
                                {
                                    ROUTE_east_5 =
                                    {
                                        ROUTE_east_6 =
                                        {
                                            ROUTE_east_7 =
                                            {
                                                ROUTE_eastgun = {},
                                            },
                                        },
                                        ROUTE_westST =
                                        {
                                            ROUTE_westST_1 =
                                            {
                                                ROUTE_westST_2 =
                                                {
                                                    ROUTE_eastST_2 =
                                                    {
                                                        ROUTE_eastST_3 =
                                                        {
                                                            ROUTE_eastgun = {},
                                                        },
                                                    },
                                                },
                                            },
                                        },
                                    },
                                },
                            },
                        },
                    },
                },
                ROUTE_west =
                {
                    ROUTE_west_1 =
                    {
                        ROUTE_west_2 =
                        {
                            ROUTE_west_3 =
                            {
                                ROUTE_west_4 =
                                {
                                    ROUTE_west_5 =
                                    {
                                        ROUTE_westeast =
                                        {
                                            ROUTE_eastST =
                                            {
                                                ROUTE_eastST_1 =
                                                {
                                                    ROUTE_eastST_2 =
                                                    {
                                                        ROUTE_eastST_3 =
                                                        {
                                                            ROUTE_eastgun = {},
                                                        },
                                                    },
                                                },
                                            },
                                            ROUTE_westeast_1 =
                                            {
                                                ROUTE_westeast_2 =
                                                {
                                                    ROUTE_eastgun = {},
                                                },
                                                ROUTE_eastgun = {},
                                            },
                                        },
                                    },
                                },
                            },
                        },
                    },
                },
            },
        },

        PLANT_West_Flak88 =
        {
            ROUTE_SPFlag =
            {
                ROUTE_east =
                {
                    ROUTE_eastHO =
                    {
                        ROUTE_eastHO_1 =
                        {
                            ROUTE_eastHO_2 =
                            {
                                ROUTE_eastHO_3 =
                                {
                                    ROUTE_westgun = {},
                                },
                            },
                        },
                    },
                },
                ROUTE_west =
                {
                    ROUTE_west_1 =
                    {
                        ROUTE_west_2 =
                        {
                            ROUTE_west_3 =
                            {
                                ROUTE_west_4 =
                                {
                                    ROUTE_westgun = {},
                                    ROUTE_west_5 =
                                    {
                                        ROUTE_eastHO_3 =
                                        {
                                            ROUTE_westgun = {},
                                        },
                                    },
                                },
                            },
                        },
                    },
                },
            },
        },

        PLANT_East_Flak88 =
        {
            ROUTE_AxisSP =
            {
                ROUTE_AxisA =
                {
                    ROUTE_westgun = {},
                },
                ROUTE_AxisB =
                {
                    ROUTE_westgun = {},
                },
                ROUTE_AxisC =
                {
                    ROUTE_westgun = {},
                },
            },
        },

        PLANT_West_Flak88 =
        {
            ROUTE_AxisSP =
            {
                ROUTE_AxisA =
                {
                    ROUTE_westgun = {},
                },
                ROUTE_AxisB =
                {
                    ROUTE_westgun = {},
                },
                ROUTE_AxisC =
                {
                    ROUTE_westgun = {},
                },
            },
        },
    };

    // Copy some routes
    MapRoutes.DEFEND_main   = MapRoutes.CHECKPOINT_forward_flag;
    MapRoutes.DEFEND_main_1 = MapRoutes.CHECKPOINT_forward_flag;
    MapRoutes.DEFEND_main_2 = MapRoutes.CHECKPOINT_forward_flag;
    MapRoutes.DEFEND_main_3 = MapRoutes.CHECKPOINT_forward_flag;
    MapRoutes.DEFEND_main_4 = MapRoutes.CHECKPOINT_forward_flag;
    MapRoutes.DEFEND_main_5 = MapRoutes.CHECKPOINT_forward_flag;

    MapRoutes.DEFEND_west   = MapRoutes.PLANT_West_Flak88;
    MapRoutes.DEFEND_west_1 = MapRoutes.PLANT_West_Flak88;
    MapRoutes.DEFEND_west_2 = MapRoutes.PLANT_West_Flak88;
    MapRoutes.DEFEND_west_3 = MapRoutes.PLANT_West_Flak88;
    MapRoutes.DEFEND_west_4 = MapRoutes.PLANT_West_Flak88;
    MapRoutes.DEFEND_west_5 = MapRoutes.PLANT_West_Flak88;
    MapRoutes.DEFEND_west_6 = MapRoutes.PLANT_West_Flak88;

    MapRoutes.DEFEND_east   = MapRoutes.PLANT_East_Flak88;
    MapRoutes.DEFEND_east_1 = MapRoutes.PLANT_East_Flak88;
    MapRoutes.DEFEND_east_2 = MapRoutes.PLANT_East_Flak88;
    MapRoutes.DEFEND_east_3 = MapRoutes.PLANT_East_Flak88;
    MapRoutes.DEFEND_east_4 = MapRoutes.PLANT_East_Flak88;

    MapRoutes.ATTACK_main   = MapRoutes.CHECKPOINT_forward_flag;
    MapRoutes.ATTACK_main_1 = MapRoutes.CHECKPOINT_forward_flag;
    MapRoutes.ATTACK_main_2 = MapRoutes.CHECKPOINT_forward_flag;
    MapRoutes.ATTACK_main_3 = MapRoutes.CHECKPOINT_forward_flag;
    MapRoutes.ATTACK_main_4 = MapRoutes.CHECKPOINT_forward_flag;

    MapRoutes.ATTACK_west   = MapRoutes.PLANT_West_Flak88;
    MapRoutes.ATTACK_west_1 = MapRoutes.PLANT_West_Flak88;
    MapRoutes.ATTACK_west_2 = MapRoutes.PLANT_West_Flak88;
    MapRoutes.ATTACK_west_3 = MapRoutes.PLANT_West_Flak88;
    MapRoutes.ATTACK_west_4 = MapRoutes.PLANT_West_Flak88;
    MapRoutes.ATTACK_west_5 = MapRoutes.PLANT_West_Flak88;

    MapRoutes.ATTACK_east   = MapRoutes.PLANT_East_Flak88;
    MapRoutes.ATTACK_east_1 = MapRoutes.PLANT_East_Flak88;
    MapRoutes.ATTACK_east_2 = MapRoutes.PLANT_East_Flak88;
    MapRoutes.ATTACK_east_3 = MapRoutes.PLANT_East_Flak88;
    MapRoutes.ATTACK_east_4 = MapRoutes.PLANT_East_Flak88;
    MapRoutes.ATTACK_east_5 = MapRoutes.PLANT_East_Flak88;

    Util.Routes( MapRoutes );
};
