global Map =
{
	Ammo_Cabinet_north_ammocabinet = "AMMOCAB_north_ammocabinet",
	Ammo_Cabinet_south_ammocabinet = "AMMOCAB_south_ammocabinet",
	Health_Cabinet_north_healthcabinet = "HEALTHCAB_north_healthcabinet",
	Health_Cabinet_south_healthcabinet = "HEALTHCAB_south_healthcabinet",
	Call_Artillery_125 = "CALLARTILLERY_125",
	Call_Artillery_195 = "CALLARTILLERY_195",
	Call_Artillery_501 = "CALLARTILLERY_501",
	Call_Artillery_ally_artyspot = "CALLARTILLERY_ally_artyspot",
	Call_Artillery_docartyspot = "CALLARTILLERY_docartyspot",
	Call_Artillery_docartyspot2 = "CALLARTILLERY_docartyspot2",
	Call_Artillery_rocket_arty = "CALLARTILLERY_rocket_arty",
	Artillery_D_483 = "ARTILLERY_D_483",
	Artillery_D_docarty = "ARTILLERY_D_docarty",
	Artillery_D_rocketarty = "ARTILLERY_D_rocketarty",
	Artillery_S_262 = "ARTILLERY_S_262",
	Artillery_S_rocketarty = "ARTILLERY_S_rocketarty",
	Checkpoint_forward_spawn = "CHECKPOINT_forward_spawn",
	Flag_keycard = "FLAG_keycard",
	Cappoint_290 = "CAPPOINT_290",
	Build_Command_Post = "BUILD_Command_Post",
	Build_Fence = "BUILD_Fence",
	Plant_Base_Gate = "PLANT_Base_Gate",
	Plant_Command_Post = "PLANT_Command_Post",
	Plant_Fence = "PLANT_Fence",
	Plant_Side_Entrance = "PLANT_Side_Entrance",
	Plant_prototype_rocket = "PLANT_prototype_rocket",
	Mount_9 = "MOUNTMG42_9",
	Repair_9 = "REPAIRMG42_9",
	Snipe_321 = "SNIPE_321",

	Command_Post_Built = function( trigger )
	{
		Util.ChangeSpawn(TEAM.ALLIES, 2, 6);
		Util.MapDebugPrint( "Command_Post_Built" );
	},

	Fence_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "ROUTE_fence1" );
		SetAvailableMapGoals( TEAM.AXIS, false, "MOBILEMG42_st1" );
		Util.MapDebugPrint( "Fence_Built" );
	},

	Base_Gate_Destroyed = function( trigger )
	{
		Groups.EnableAllies(Groups.group3);
		Groups.EnableAxis(Groups.group4);
		Groups.DisableAllies(Groups.group1);
		Groups.DisableAxis(Groups.group2);

		Util.MapDebugPrint( "Base_Gate_Destroyed" );
	},

	Command_Post_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Command_Post_Destroyed" );
	},

	Fence_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "ROUTE_fence1" );
		SetAvailableMapGoals( TEAM.AXIS, true, "MOBILEMG42_st1" );

		rnd = RandInt(1,3);
		if ( rnd == 1 )
		{
			Util.SetGoalPosition( 1173, -1175, 784.125, Map.Plant_prototype_rocket );
		}
		else if ( rnd == 2 )
		{
			Util.SetGoalPosition( 1152, -870.486, 784.125, Map.Plant_prototype_rocket );
		}
		else
		{
			Util.SetGoalPosition( 1067, -757, 784.145, Map.Plant_prototype_rocket );
		}



		Util.MapDebugPrint( "Fence_Destroyed" );
	},

	Side_Entrance_Destroyed = function( trigger )
	{
		Groups.EnableAllies(Groups.group3);
		Groups.EnableAxis(Groups.group4);
		Groups.DisableAllies(Groups.group1);
		Groups.DisableAxis(Groups.group2);

		Util.MapDebugPrint( "Side_Entrance_Destroyed" );
	},

	prototype_rocket_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, ".*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, ".*" );

		Util.MapDebugPrint( "prototype_rocket_Destroyed" );
	},

	keycard_Taken = function( trigger )
	{
		Groups.EnableAllies(Groups.group5);
		Groups.EnableAxis(Groups.group6);
		Groups.DisableAllies(Groups.group3);
		Groups.DisableAxis(Groups.group4);

		Util.MapDebugPrint( "keycard_Taken" );
	},

	keycard_returned = function( trigger )
	{
		Groups.EnableAllies(Groups.group7);
		Groups.EnableAxis(Groups.group8);
		Groups.DisableAllies(Groups.group5);
		Groups.DisableAxis(Groups.group6);

		Util.MapDebugPrint( "keycard_returned" );
	},

	CAPPOINT_290_Captured = function( trigger )
	{
		Groups.EnableAllies(Groups.group9);
		Groups.EnableAxis(Groups.group10);
		Groups.DisableAllies(Groups.group7);
		Groups.DisableAllies(Groups.group5);
		Groups.DisableAxis(Groups.group8);
		Groups.DisableAxis(Groups.group6);

		Util.ChangeSpawn(TEAM.ALLIES, 2, 9);
		Util.EnableGoal("PLANT_Command_Post"); //enables for both teams
		Util.DisableGoal("HEALTHCAB_south_healthcabinet"); //enables for both teams
		Util.DisableGoal("AMMOCAB_south_ammocabinet"); //enables for both teams
		Util.EnableGoal("HEALTHCAB_north_healthcabinet"); //enables for both teams
		Util.EnableGoal("AMMOCAB_north_ammocabinet"); //enables for both teams
		SetAvailableMapGoals( TEAM.AXIS, false, "CAMP_rock*.*" );

		Util.MapDebugPrint( "CAPPOINT_290_Captured" );
	},

	forward_spawn_Axis_Captured = function( trigger )
	{
		Util.MapDebugPrint( "forward_spawn_Axis_Captured" );
	},

	forward_spawn_Allies_Captured = function( trigger )
	{
		Util.ChangeSpawn(TEAM.ALLIES, 2, 4);

		Util.MapDebugPrint( "forward_spawn_Allies_Captured" );
	},

	base_plant = function( trigger )
 	{
 		Util.MapDebugPrint( "base_plant" );
 	},

	base_defused = function( trigger )
 	{
 		Util.MapDebugPrint( "base_defused" );
 	},

	rocket_plant = function( trigger )
 	{

 		Groups.DisableAxis(Groups.group10);
		Groups.EnableAxis(Groups.group11);

 		Util.MapDebugPrint( "planted_at_rocket" );
 	},

	rocket_defused = function( trigger )
 	{
		Groups.DisableAxis(Groups.group11);
		Groups.EnableAxis(Groups.group10);

//~		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_fence3" );



 		Util.MapDebugPrint( "rocket_defused" );
 	},
};

global OnMapLoad = function()
{
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Command_Post_Built );
	OnTrigger( "The Fence has been constructed!", Map.Fence_Built );
	OnTrigger( "Allies have destroyed the base gate!", Map.Base_Gate_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Command_Post_Destroyed );
	OnTrigger( "The Fence has been destroyed.", Map.Fence_Destroyed );
	OnTrigger( "Allies have destroyed the side entrance!", Map.Side_Entrance_Destroyed );
	OnTrigger( "Allies have destroyed the prototype rocket!", Map.prototype_rocket_Destroyed );
	OnTrigger( "Allies have stolen the keycard!", Map.keycard_Taken );
	OnTrigger( "Flag returned keycard!", Map.keycard_returned );
	OnTrigger( "Allies have secured the keycard!", Map.CAPPOINT_290_Captured );
	OnTrigger( "MISSING_STRING", Map.forward_spawn_Axis_Captured );
	OnTrigger( "Allies have captured the forward bunker!", Map.forward_spawn_Allies_Captured );
	OnTrigger( "Planted at the Base Gate.", Map.base_plant );
	OnTrigger( "Defused at the Base Gate.", Map.base_defused );

	OnTrigger( "Planted at the prototype rocket.", Map.rocket_plant );
	OnTrigger( "Defused at the prototype rocket.", Map.rocket_defused );

	SetAvailableMapGoals( TEAM.AXIS, false, ".*" );
	SetAvailableMapGoals( TEAM.ALLIES, false, ".*" );
	SetAvailableMapGoals( TEAM.AXIS, true, "CAMP_rock*.*" );

//~ Initial Axis goals
	Groups.EnableAxis(Groups.group2);

//~ Initial Allied Goals
	Groups.EnableAllies(Groups.group1);

	Util.SetMaxUsersInProgress( 1, "DEFEND_.*" );
	Util.SetMaxUsersInProgress( 1, "ATTACK_.*" );
	Util.SetMaxUsersInProgress( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsersInProgress( 1, "PLANT_Base_Gate" );
	Util.SetMaxUsersInProgress( 1, "PLANT_Side_Entrance" );
	Util.SetMaxUsersInProgress( 1, "BUILD.*" );
	Util.SetMaxUsersInProgress( 1, "CAMP.*" );

	SetGoalPriority( "MOBILEMORTAR_.*", 0.99, TEAM.ALLIES, CLASS.SOLDIER );
	SetGoalPriority( "PLANT_Fence", 0.99, 0, CLASS.COVERTOPS );
	SetMapGoalProperties( "DEFEND_.*", {MinCampTime=30, MaxCampTime=90} );
	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=15, MaxCampTime=40} );

	SetMapGoalProperties( "ATTACK_.*", {MinCampTime=60, MaxCampTime=120});
	Util.SetGoalPosition( 2635.9, 2262, 964.125, "PLANT_Fence");
	Util.LimitToClass("PLANT_Fence", TEAM.ALLIES, CLASS.COVERTOPS);
	Util.LimitToClass("PLANT_Command_Post", 0, CLASS.COVERTOPS);
	Util.EnableGoal("ROUTE_.*"); //enables for both teams
	SetAvailableMapGoals( TEAM.ALLIES, false, "ROUTE_fence1" );

	Util.EnableGoal("HEALTHCAB_south_healthcabinet"); //enables for both teams
	Util.EnableGoal("AMMOCAB_south_ammocabinet"); //enables for both teams
	Util.EnableGoal("BUILD_Command_Post"); //enables for both teams

	MapRoutes =
	{
		DEFEND_ROCKET_1 =
		{
			ROUTE_axis1 =
			{
				ROUTE_defuse1 =
				{
					ROUTE_defuse2 = {},
					ROUTE_defuse3 = {},
				},
			},
		},
		PLANT_prototype_rocket =
		{
			ROUTE_fs  =
			{
				ROUTE_hall  =
				{
					ROUTE_hall2  =
					{
						ROUTE_hall3  =
						{
							ROUTE_dyno1  =
							{
								ROUTE_dyno3  =
								{
								},
								ROUTE_dyno2  =
								{
									ROUTE_defuse1  =
									{
										ROUTE_defuse3  =
										{
											ROUTE_defuse4  =
											{
											},
										},
										ROUTE_defuse2  =
										{
											ROUTE_defuse5  =
											{
											},
										},
									},
								},
							},
						},
					},
				},
			},
			ROUTE_route2  =
			{
				ROUTE_dyno1  =
				{
					ROUTE_dyno2  =
					{
						ROUTE_defuse1  =
						{
							ROUTE_defuse2  =
							{
								ROUTE_defuse5  =
								{
								},
							},
							ROUTE_defuse3  =
							{
								ROUTE_defuse4  =
								{
								},
							},
						},
					},
				},
				ROUTE_d2  =
				{
					ROUTE_fence1  =
					{
						ROUTE_fence2  =
						{
						},
					},
				},
			},
			ROUTE_axis35  =
			{
				ROUTE_hall2  =
				{
					ROUTE_hall3  =
					{
						ROUTE_dyno1  =
						{
							ROUTE_dyno3  =
							{
							},
							ROUTE_dyno2  =
							{
								ROUTE_defuse1  =
								{
									ROUTE_defuse3  =
									{
										ROUTE_defuse4  =
										{
										},
									},
									ROUTE_defuse2  =
									{
										ROUTE_defuse5  =
										{
										},
									},
								},
							},
						},
					},
				},
			},
		},
		DEFEND_docs2 =
		{
			ROUTE_axis1 =
			{
				ROUTE_d1= {},

				Weight = 3,
				ROUTE_d2 = {},
			},
		},
		CAPPOINT_290 =
		{
			ROUTE_keycard  =
			{
				ROUTE_fs  =
				{
					ROUTE_fs2  =
					{
						ROUTE_fs99  =
						{
						},
					},
					ROUTE_fs1  =
					{
						ROUTE_fs99  =
						{
						},
					},
				},
				ROUTE_hall2  =
				{
					ROUTE_hall3  =
					{
					},
					ROUTE_fs100  =
					{
						ROUTE_fs101  =
						{
						},
					},
				},
			},
		},
	};

	MapRoutes.DEFEND_ROCKET_2 = MapRoutes.DEFEND_ROCKET_1;
	MapRoutes.DEFEND_ROCKET_3 = MapRoutes.DEFEND_ROCKET_1;
	MapRoutes.DEFEND_ROCKET_4 = MapRoutes.DEFEND_ROCKET_1;
	MapRoutes.ATTACK_ROCKET_5 = MapRoutes.PLANT_prototype_rocket;

	MapRoutes.ATTACK_ar1 = MapRoutes.PLANT_prototype_rocket;
	MapRoutes.ATTACK_ar2 = MapRoutes.PLANT_prototype_rocket;
	MapRoutes.ATTACK_ar3 = MapRoutes.PLANT_prototype_rocket;
	MapRoutes.ATTACK_ar4 = MapRoutes.PLANT_prototype_rocket;
	MapRoutes.ATTACK_ar5 = MapRoutes.PLANT_prototype_rocket;
	Util.Routes(MapRoutes);

	Util.MapDebugPrint( "OnMapLoad" );
};


global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 100.0;
	bot.MaxViewDistance = 2400.0;
};

global Groups =
{
	//Allied part 1
	group1 =
	{
		"ATTACK_dyno.*",
		"PLANT_Base_Gate" ,
		"PLANT_Side_Entrance" ,
		"MOBILEMORTAR_mrt1" ,
	},

	//Axis part 1
	group2 =
	{
		"DEFEND_stage1.*" ,
		"BUILD_Fence",
		"CHECKPOINT_forward_spawn" ,
	},

	//Allied part 2
	group3 =
	{
		"CHECKPOINT_forward_spawn" ,
		"FLAG_keycard" ,
		"MOBILEMORTAR_mrt23" ,
		"PLANT_Fence" ,
		"ATTACK_ad.*" ,
		"ARTILLERY_D_docarty",
		"CALLARTILLERY_call33",
		"SMOKEBOMB_al1",
	},

	//Axis part 2
	group4 =
	{
		"DEFEND_fence3" ,
		"DEFEND_docs.*" ,
		"MOBILEMG42_mg1" ,
		"ARTILLERY_D_docarty",
		"CALLARTILLERY_call22",
	},

	//Allied part 3 key taken
	group5 =
	{
		"ATTACK_obj_10" ,
		"CAPPOINT_290" ,
		"CAMP_.*" ,
		"MOBILEMORTAR_mrt23" ,
		"ARTILLERY_D_docarty",
		"CALLARTILLERY_call33",
	},

	//Axis part 3 key taken
	group6 =
	{
		"DEFEND_card.*" ,
		"ARTILLERY_D_docarty",
		"CALLARTILLERY_call22",
	},

	//Allied part 4 key returned
	group7 =
	{
		"ATTACK_ad.*" ,
		"FLAG_keycard" ,
		"CAPPOINT_290" ,
		"MOBILEMORTAR_mrt23" ,
		"SMOKEBOMB_al1",
	},

	//Axis part4 key returned
	group8 =
	{
		"MOBILEMG42_mg1" ,
		"DEFEND_docs.*" ,
	},

	//Allied key secured
	group9 =
	{
		"ATTACK_ROCKET_5" ,
		"ATTACK_ar.*" ,
		"DEFEND_ROCKET_1" ,
		"PLANT_prototype_rocket" ,
		"ATTACK_r1" ,
		"PLANT_Fence",
		"PLANT_Command_Post",
		"BUILD_Command_Post",
		"ARTILLERY_D_rocketarty",
		"ARTILLERY_S_rocketarty",
		"CALLARTILLERY_call99",
		"CALLARTILLERY_call55",
	},
	// Axis key secured
	group10 =
	{
		"DEFEND_ROCKET_.*" ,
		"ATTACK_ROCKET_5" ,
		"DEFEND_fence3" ,
		"BUILD_Fence",
		"MOBILEMG42_rocketmg",
		"ARTILLERY_D_rocketarty",
		"ARTILLERY_S_rocketarty",
		"CALLARTILLERY_call99",
		"CALLARTILLERY_rocket_arty",
		"MOBILEMG42_axis99",
	},

	// Axis rocket plant
	group11 =
	{
		"DEFEND_ROCKET_.*" ,
		"ATTACK_ROCKET_5" ,
		"ARTILLERY_D_rocketarty",
		"ARTILLERY_S_rocketarty",
		"CALLARTILLERY_call99",
		"CALLARTILLERY_rocket_arty",
	},

	EnableAllies = function(group)
	{
		foreach (id and goal in group)
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, goal );
			Util.MapDebugPrint("EnableAllies: enabling " + goal, true);
		}
	},

	EnableAxis = function(group)
	{
		foreach (id and goal in group)
		{
			SetAvailableMapGoals( TEAM.AXIS, true, goal );
			Util.MapDebugPrint("EnableAxis: enabling " + goal, true);
		}
	},

	DisableAllies = function(group)
	{
		foreach (id and goal in group)
		{
			SetAvailableMapGoals( TEAM.ALLIES, false, goal );
			Util.MapDebugPrint("DisableAllies: disabling " + goal, true);
		}
	},

	DisableAxis = function(group)
	{
		foreach (id and goal in group)
		{
			SetAvailableMapGoals( TEAM.AXIS, false, goal );
			Util.MapDebugPrint("DisableAxis: disabling " + goal, true);
		}
	},
};
