//==========================================================================================
//
//	cathedral_te.gm
//
//	Who          	When		What
//------------------------------------------------------------------------------------------
//	^1[UJE]^3Captain	27 May 2015	Initial Script
//
//==========================================================================================
//

global Map =
{
	Command_Post_Dyno = 0,
	Main_Door_Dyno = 0,
	Side_Door_Dyno = 0,
    radarsStolen = 0,
	eastRadarIsSecured = false,
	westRadarIsSecured = false,
	DefendingTeam = TEAM.AXIS,

	Command_Post_Built = function()
	{
        Util.ChangeSpawn( TEAM.ALLIES, 3, 4 );
		Util.MapDebugPrint( "Command_Post_Built" );
	},

	Command_Post_Planted = function()
	{

		Map.Command_Post_Dyno += 1;
		Util.MapDebugPrint( "Command_Post_Planted" );
	},

	Main_Door_Planted = function()
	{

		Map.Main_Door_Dyno += 1;
		Util.MapDebugPrint( "Main_Door_Planted" );
	},

	Side_Door_Planted = function()
	{

		Map.Side_Door_Dyno += 1;
		Util.MapDebugPrint( "Side_Door_Planted" );
	},

	Command_Post_Defused = function()
	{

		Map.Command_Post_Dyno -= 1;
		Util.MapDebugPrint( "Command_Post_Defused" );
	},

	Main_Door_Defused = function()
	{

		Map.Main_Door_Dyno -= 1;
		Util.MapDebugPrint( "Main_Door_Defused" );
	},

	Side_Door_Defused = function()
	{

		Map.Side_Door_Dyno -= 1;
		Util.MapDebugPrint( "Side_Door_Defused" );
	},

	Command_Post_Destroyed = function()
	{

		Map.Command_Post_Dyno = 0;

		Util.MapDebugPrint( "Command_Post_Destroyed" );
	},

	Main_Door_Destroyed = function()
	{

		Map.Main_Door_Dyno = 0;
        SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_Allied_maindoor_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "FLAG_.*" );

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"PLANTMINE_Gazebo_.*",
			"DEFEND_Axis_maindoor_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
		        "PLANTMINE_Sidedoor_.*",
				"PLANTMINE_West_.*",
				"PLANTMINE_Cappoint_.*",
				"DEFEND_West_radar_.*",
				"DEFEND_East_radar_.*",
				"MOBILEMG42_West_radar.*",
			});
		Util.MapDebugPrint( "Main_Door_Destroyed" );
	},

	Side_Door_Destroyed = function()
	{

		Map.Side_Door_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, true, "FLAG_.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"PLANTMINE_Gazebo_.*",
			"DEFEND_Axis_maindoor_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
		        "PLANTMINE_Sidedoor_.*",
				"PLANTMINE_West_.*",
				"PLANTMINE_Cappoint_.*",
				"DEFEND_West_radar_.*",
				"DEFEND_East_radar_.*",
				"MOBILEMG42_West_radar.*",
			});
		Util.MapDebugPrint( "Side_Door_Destroyed" );
	},

	radarbox1_Taken = function()
	{
		Map.radarsStolen += 1;
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_West_radar_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Cappoint_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "CAPPOINT_.*" );
		Util.MapDebugPrint( "radarbox1_Taken" );
	},

	radarbox1_Returned = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_West_radar_.*",
		});
		Map.radarsStolen -= 1;
		if ( Map.radarsStolen < 1 )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Cappoint_.*" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "CAPPOINT_.*" );
		}
		Util.MapDebugPrint( "radarbox1_Returned" );
	},

	radarbox1_Secured = function()
	{
		Map.westRadarIsSecured = true;
		Map.radarsStolen -= 1;
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"PLANTMINE_West_.*",
			"DEFEND_West_radar_.*",
		});
		Util.SetMaxUsers( 3, "FLAG_radarbox2" );
		if ( Map.radarsStolen < 1 )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Cappoint_.*" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "CAPPOINT_Gold.*" );
		}
		Util.MapDebugPrint( "radarbox1_Secured" );
	},

	radarbox2_Taken = function()
	{
		Map.radarsStolen += 1;
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_East_radar_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Cappoint_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "CAPPOINT_.*" );
		Util.MapDebugPrint( "radarbox2_Taken" );
	},

	radarbox2_Returned = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_East_radar_.*",
		});
		Map.radarsStolen -= 1;
		if ( Map.radarsStolen < 1 )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Cappoint.*" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "CAPPOINT_.*" );
		}
		Util.MapDebugPrint( "radarbox2_Returned" );
	},

	radarbox2_Secured = function()
	{
		Map.eastRadarIsSecured = true;
		Map.radarsStolen -= 1;
		if ( Map.radarsStolen < 1 )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, {
				"DEFEND_Cappoint_.*",
				"DEFEND_East_radar_.*",
			});
			SetAvailableMapGoals( TEAM.ALLIES, false, "CAPPOINT_Gold.*" );
		}
		Util.MapDebugPrint( "radarbox2_Secured" );
	},


	oldcityflag_Axis_Captured = function()
	{
        SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "CHECKPOINT.*" );
		Util.MapDebugPrint( "oldcityflag_Axis_Captured" );
	},

	oldcityflag_Allies_Captured = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT.*" );
        SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT.*" );
		Util.MapDebugPrint( "oldcityflag_Allies_Captured" );
	},

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Command_Post_Built );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Command_Post_Destroyed );
	OnTrigger( "Allies have breached the Main Gate", Map.Main_Door_Destroyed );
	OnTrigger( "Planted at Side Door.", Map.Side_Door_Planted );
	OnTrigger( "Allies have blown open the Side Door!", Map.Side_Door_Destroyed );
	OnTrigger( "Allies have stolen West Radar Parts!", Map.radarbox1_Taken );
	OnTrigger( "Flag returned radarbox1!", Map.radarbox1_Returned );
	OnTrigger( "Allies have secured the West Radar Parts!", Map.radarbox1_Secured );
	OnTrigger( "Allies have stolen East Radar Parts!", Map.radarbox2_Taken );
	OnTrigger( "Flag returned radarbox2!", Map.radarbox2_Returned );
	OnTrigger( "Allies have secured the East Radar Parts!", Map.radarbox2_Secured );
	OnTrigger( "Axis reclaim the Cathedral!", Map.oldcityflag_Axis_Captured );
	OnTrigger( "Allies capture the Cathedral!", Map.oldcityflag_Allies_Captured );

	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"PLANTMINE_.*",
		"DEFEND_.*",
		"ATTACK_.*",
		"CAPPOINT_.*",
		"FLAG_.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_Allied_maindoor.*" );
	SetAvailableMapGoals( TEAM.AXIS, false, {
		"ATTACK_.*",
		"DEFEND_.*",
		"PLANTMINE_.*",
		"CAPPOINT_.*",
		"MOBILEMG42_West_radar.*",

	});
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"PLANTMINE_Gazebo_.*",
		"DEFEND_Axis_maindoor.*",
	});

	// Max users per goal
	Util.SetMaxUsers( 1, "ATTACK_.*" );
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "BUILD_.*" );
	Util.SetMaxUsers( 1, "PLANT_.*" );
	Util.SetMaxUsers( 1, "CHECKPOINT.*" );
	Util.SetMaxUsers( 3, "FLAG_radarbox1" );
	Util.SetMaxUsers( 2, "FLAG_radarbox2" );
	Util.SetMaxUsers( 1, "GRENADE_.*" );

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


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

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 150.0;
};
	// Routing
global InitializeRoutes = function()
{
	MapRoutes =
	{
		CHECKPOINT_oldcityflag =
		{
			ROUTE_allied_spawn_1 =
			{
				ROUTE_allied_cave =
				{
				ROUTE_exit_garden_east_1 = {},
				ROUTE_exit_garden_east_2 = {},
				ROUTE_exit_garden_south = {}
		},
		    ROUTE_exit_south =
		    {
		        ROUTE_exit_garden_east_1 = {},
			    ROUTE_exit_garden_east_2 = {},
			    ROUTE_exit_garden_south = {}
		},
		    ROUTE_exit_east =
          {
		        ROUTE_exit_nave_east = {},
		        ROUTE_exit_gazebo_1 = {},
		        ROUTE_exit_gazebo_2 = {},
		        ROUTE_exit_nave_south = {},
		        ROUTE_exit_gazebo = {}

				}
			}
		}
	};
	Util.Routes(MapRoutes);
};
