/*
Updated for new escort goals.
*/


global Map =
{

	Barrierpassed =
 	{
 		Name="Barrierpassed",
 		TriggerOnEntity = GetGoal("MOVER_truck").GetEntity(),
 		OnEnter = function(ent)
 		{
 			//Util.MapDebugPrint(GetEntName(ent) + " BarrierPassed");
			//Map.RideVehicle.truck.Enabled = true;
			SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Truck_Barrier_1" );
			Util.SetGoalPosition( 428.9, 2221.7, 164.125, Map.Plant_Main_Entrance);
 		},
 		OnExit = function(ent)
 		{
			Util.MapDebugPrint(GetEntName(ent) + " exited aabb trigger");
			Util.DisableGroup( "group5");
			Util.DisableGroup( "group4");
			Util.EnableGroup( "group7", TEAM.ALLIES);
			Util.EnableGroup( "group13", TEAM.AXIS);
	//~		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Main_Entrance" );
	//~		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_main.*" );
			Util.MapDebugPrint("barrier1 exit");
 		},

	},

	def =
 	{
 		Name="def",
 		TriggerOnEntity = GetGoal("MOVER_truck").GetEntity(),
 		OnEnter = function(ent)
 		{
 			//Util.MapDebugPrint(GetEntName(ent) + "BarrierPassed");
			//Map.RideVehicle.truck.Enabled = true;

			Util.EnableGroup( "group12", TEAM.AXIS);
			SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Truck_Barrier_2" );
//~			SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Bridge" );
//~			SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_MG42" );

 		},
 		OnExit = function(ent)
 		{
			Util.MapDebugPrint(GetEntName(ent) + "exited aabb trigger");
			Util.DisableGroup( "group13");
		//~	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_main.*" );
			Util.MapDebugPrint("def exit");
 		},
	},

	barrier2 =
 	{
 		Name="barrier2",
 		TriggerOnEntity = GetGoal("MOVER_truck").GetEntity(),
 		OnEnter = function(ent)
 		{
 			//Util.MapDebugPrint(GetEntName(ent) + "BarrierPassed");
			//Map.RideVehicle.truck.Enabled = true;

			SetAvailableMapGoals( TEAM.AXIS, false, {
				"PLANT_Bridge",
				"BUILD_MG42",
				"BUILD_Truck_Barrier_2",
				"MOUNTMG42_Balcony_MG",
			});
			Util.EnableGroup( "group14", TEAM.AXIS);
			Util.DisableGroup( "group15");
			Util.MapDebugPrint("b2 enter");

 		},
 		OnExit = function(ent)
 		{
			Util.DisableGroup( "group9");

			Util.EnableGroup( "group10", TEAM.ALLIES);
			Util.MapDebugPrint(GetEntName(ent) + " exited aabb trigger");
			Util.MapDebugPrint("b2 exit");
 		},
	},

	shift =
 	{
 		Name="shift",
 		TriggerOnEntity = GetGoal("MOVER_truck").GetEntity(),
 		OnEnter = function(ent)
 		{
 			//Util.MapDebugPrint(GetEntName(ent) + " BarrierPassed");
			//Map.RideVehicle.truck.Enabled = true;

			SetAvailableMapGoals( TEAM.AXIS, false, {
				"DEFEND_tp.*",
				"PLANT_Bridge",
			});
			SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Allied_Command_Post" );
			SetAvailableMapGoals( TEAM.AXIS, true, "MOBILEMORTAR_mtr1" );
			Util.DisableGroup( "group12");
			Util.DisableGroup( "group8");
			Util.EnableGroup( "group9", TEAM.ALLIES);
			Util.EnableGroup( "group15", TEAM.AXIS);
			Util.MapDebugPrint("shift enter");
 		},
 		OnExit = function(ent)
 		{
			SetAvailableMapGoals( TEAM.AXIS, false, "MOUNT_Balcony_MG" );
			Util.MapDebugPrint(GetEntName(ent) + " exited aabb trigger");
			Util.MapDebugPrint("shift exit");
 		},
	},

	fix_truck =
 	{
 		Name="fix_truck",
 		TriggerOnEntity = GetGoal("MOVER_truck").GetEntity(),
 		OnEnter = function(ent)
 		{
 			//Util.MapDebugPrint(GetEntName(ent) + "BarrierPassed");
			//Map.RideVehicle.truck.Enabled = true;

//~			Map.EscortVehicle.truck.Enabled = true;
			Util.MapDebugPrint("fix it!");
 		},
 		OnExit = function(ent)
 		{

			Util.MapDebugPrint(GetEntName(ent) + "exited aabb trigger");
			Util.MapDebugPrint("fix exit");
 		},
	},

	Quiet = true,
	Ammo_Cabinet_north_ammocabinet = "AMMOCAB_north_ammocabinet",
	Ammo_Cabinet_south_ammocabinet = "AMMOCAB_south_ammocabinet",
	Ammo_Cabinet_steel_ammocabinet = "AMMOCAB_steel_ammocabinet",
	Health_Cabinet_north_healthcabinet = "HEALTHCAB_north_healthcabinet",
	Health_Cabinet_south_healthcabinet = "HEALTHCAB_south_healthcabinet",
	Health_Cabinet_steel_healthcabinet = "HEALTHCAB_steel_healthcabinet",
	Call_Artillery_153 = "CALLARTILLERY_153",
	Call_Artillery_80 = "CALLARTILLERY_80",
	Artillery_D_119 = "ARTILLERY_D_119",
	Artillery_D_79 = "ARTILLERY_D_79",
	Artillery_S_361 = "ARTILLERY_S_361",
	Artillery_S_79 = "ARTILLERY_S_79",
	Flag_gold_crate = "FLAG_gold_crate",
	Cappoint_53 = "CAPPOINT_53",
	Build_Allied_Command_Post = "BUILD_Allied_Command_Post",
	Build_Axis_Command_Post = "BUILD_Axis_Command_Post",
	Build_Balcony_MG = "BUILD_Balcony_MG",
	Build_Bridge = "BUILD_Bridge",
	Build_Bridge_1 = "BUILD_Bridge_1",
	Build_MG42 = "BUILD_MG42",
	Build_Truck = "BUILD_Truck",
	Build_Truck_Barrier_1 = "BUILD_Truck_Barrier_1",
	Build_Truck_Barrier_2 = "BUILD_Truck_Barrier_2",
	Plant_Allied_Command_Post = "PLANT_Allied_Command_Post",
	Plant_Axis_Command_Post = "PLANT_Axis_Command_Post",
	Plant_Balcony_MG = "PLANT_Balcony_MG",
	Plant_Bridge = "PLANT_Bridge",
	Plant_Bridge_1 = "PLANT_Bridge_1",
	Plant_MG42 = "PLANT_MG42",
	Plant_Main_Entrance = "PLANT_Main_Entrance",
	Plant_Radio_Wall = "PLANT_Radio_Wall",
	Plant_Truck_Barrier_1 = "PLANT_Truck_Barrier_1",
	Plant_Truck_Barrier_2 = "PLANT_Truck_Barrier_2",
	Mount_Balcony_MG = "MOUNTMG42_Balcony_MG",
	Mount_MG42 = "MOUNTMG42_MG42",
	Repair_Balcony_MG = "REPAIRMG42_Balcony_MG",
	Repair_MG42 = "REPAIRMG42_MG42",
	Snipe_354 = "SNIPE_354",
	Snipe_SNIPE_2 = "SNIPE_SNIPE_2",
	Snipe_SNIPE_3 = "SNIPE_SNIPE_3",
	Snipe_SNIPE_9 = "SNIPE_SNIPE_9",
	Mover_truck = "MOVER_truck",

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

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

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

	Bridge_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Bridge" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Bridge_1",
			"BUILD_Allied_Command_Post",
			"ROUTE_in1",
		});
		Util.MapDebugPrint("bridge built");
	},

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

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

	Truck_Built = function( trigger )
	{
		Util.SetMaxUsers( 2, "ESCORT_.*" );
		Util.MapDebugPrint("truck built");
	},

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

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

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

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

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

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

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

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

	Main_Entrance_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Truck_Barrier_2" );
		SetAvailableMapGoals( TEAM.AXIS, true, "MOUNT_Balcony_MG" );
		Util.DisableGroup( "group7");
		Util.EnableGroup( "group8", TEAM.ALLIES);
		Util.MapDebugPrint("gate blown");
	},

	Radio_Wall_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_wall.*" );
		Util.DisableGroup( "group16", TEAM.ALLIES);

		Util.MapDebugPrint("wall blown");
	},

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

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

	gold_crate_Taken = function( trigger )
	{
//~		SetAvailableMapGoals( TEAM.AXIS, true, "ATACK_at.*" );

		Util.DisableGroup("group1");
		Util.DisableGroup("group2");
		Util.EnableGroup( "group3", TEAM.AXIS);
		Util.EnableGroup( "group6", TEAM.ALLIES);
		SetAvailableMapGoals( TEAM.ALLIES, true, "CAPPOINT_53" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_wall.*" );

		Util.MapDebugPrint("gold_crate_Taken");
	},

	CAPPOINT_53_Captured = function( trigger )
	{
		Util.DisableGroup("group3");
		Util.DisableGroup( "group6");
		Util.EnableGroup( "group4", TEAM.ALLIES);
		Util.EnableGroup( "group5", TEAM.AXIS);
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_wall.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Truck_Barrier_1" );

		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Truck_Barrier_1" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Truck",
			"ESCORT_Truck",
		});

//~		Map.EscortVehicle.truck.Enabled = true;
		Util.MapDebugPrint("CAPPOINT_53_Captured");
	},

	truck_blasted = function( trigger )
	{
		Util.SetPositionGoal( Map.Build_Truck, Map.Mover_truck );
//~		Map.EscortVehicle.truck.Enabled = false;
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Truck" );
//~		SetAvailableMapGoals( TEAM.ALLIES, false, "ESCORT_Truck" );
		Util.SetMaxUsers( 1, "ESCORT_.*" );
		Util.MapDebugPrint("truck blasted");
	},

	gold_crate_returned = function( trigger )
	{
		Util.EnableGroup( "group1", TEAM.ALLIES);
		Util.EnableGroup( "group2", TEAM.AXIS);
		Util.DisableGroup( "group3");
		Util.DisableGroup( "group6");
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_wall.*" );
		Util.MapDebugPrint("crate returned");
	},

	wall_plant = function( trigger )
	{
		Util.EnableGroup( "group16", TEAM.ALLIES);
		Util.MapDebugPrint("wall  plant");
	},

	wall_defused = function( trigger )
	{
		Util.DisableGroup( "group16");
		Util.MapDebugPrint("wall  defused");
	},
};

global OnMapLoad = function()
{
	OnTrigger( "MISSING_STRING", Map.Allied_Command_Post_Built );
	OnTrigger( "MISSING_STRING", Map.Axis_Command_Post_Built );
	OnTrigger( "MISSING_STRING", Map.Balcony_MG_Built );
	OnTrigger( "Allies have constructed the Bridge!", Map.Bridge_Built );
	OnTrigger( "MISSING_STRING", Map.Bridge_1_Built );
	OnTrigger( "MISSING_STRING", Map.MG42_Built );
	OnTrigger( "The Truck has been repaired!", Map.Truck_Built );
	OnTrigger( "MISSING_STRING", Map.Truck_Barrier_1_Built );
	OnTrigger( "Truck Barrier #2 has been constructed.", Map.Truck_Barrier_2_Built );
	OnTrigger( "MISSING_STRING", Map.Allied_Command_Post_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Axis_Command_Post_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Balcony_MG_Destroyed );
	OnTrigger( "The Bridge has been destroyed!", Map.Bridge_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Bridge_1_Destroyed );
	OnTrigger( "MISSING_STRING", Map.MG42_Destroyed );
	OnTrigger( "the Main Entrance Destroyed.", Map.Main_Entrance_Destroyed );
	OnTrigger( "The Radio Room wall has been destroyed!", Map.Radio_Wall_Destroyed );
	OnTrigger( "Truck Barrier #1 has been destroyed.", Map.Truck_Barrier_1_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Truck_Barrier_2_Destroyed );
	OnTrigger( "Allies have stolen The Radar Parts!", Map.gold_crate_Taken );
	OnTrigger( "Flag returned gold_crate!", Map.gold_crate_returned );
	OnTrigger( "radar_allies_radarw_secured", Map.CAPPOINT_53_Captured );
	OnTrigger( "The Truck has been damaged!", Map.truck_blasted );
	OnTrigger( "Planted at the Radio Wall.", Map.wall_plant );
	OnTrigger( "Defused at the Radio Wall.", Map.wall_defused );

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

	Util.SetPositionGoal( Map.Build_Truck, Map.Mover_truck );
	Util.SetGoalOffset( -28, 0, 0, "PLANT_Main_Entrance" );
	Util.SetGoalPosition( -1462.6, 1353.2, 216.787, "PLANT_Truck_Barrier_1" ) ;
	Util.SetGoalOffset( -55, -75, 0, "PLANT_Truck_Barrier_2" );
	Util.SetGoalPosition( -2188.5, 1307.2, 211.8, "PLANT_Radio_Wall" ) ;
	Util.SetGoalOffset( 0, 0, -220, "PLANT_Bridge" );
//~	Util.SetGoalOffset( -55, -55, 0, "PLANT_Truck_Barrier_1" );
//~	Util.SetGoalOffset( 0, -35, -19, "PLANT_Radio_Wall" );
//~	Util.SetGoalOffset( 0, 0, -220, "PLANT_Bridge_1" );

	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "BUILD_.*" );
	Util.SetMaxUsers( 2, "DEFUSE_.*" );
	Util.SetMaxUsers( 2, "ESCORT_.*" );
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 1, "PLANT_Bridge" );
	Util.SetMaxUsers( 1, "REVIVE_.*" );
	Util.SetMaxUsers( 5, "FLAG_gold_crate" );

//~	SetGoalPriority( "MOBILEMORTAR_.*", 0.85, 0, CLASS.SOLDIER );
//~	SetGoalPriority( "PLANT_Command_Post", 0.89, 0, CLASS.COVERTOPS );
//~	SetGoalPriority( "PLANT_Command_Post", 0.0, 0, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Radio_Wall", 0.86, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "BUILD_Truck", 0.98, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "ATTACK_k.*", 0.0, TEAM.ALLIES, CLASS.ENGINEER );

	Util.LimitToClass("PLANT_Command_Post", 0, CLASS.COVERTOPS);
	Util.LimitToClass("PLANT_Bridge", TEAM.AXIS, CLASS.COVERTOPS);

	Wp.SetWaypointFlag( "ass1", "closed", true );
	Wp.SetWaypointFlag( "ass2", "closed", false );
	Wp.SetWaypointFlag( "ass3", "closed", false );
	Wp.SetWaypointFlag( "ass4", "closed", false );

	SetMapGoalProperties( "DEFEND_.*", {MinCampTime=30, MaxCampTime=90} );
	SetMapGoalProperties( "MOUNT_.*", {MinCampTime=30, MaxCampTime=90} );
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=30, MaxCampTime=90} );
	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=30, MaxCampTime=90} );
	SetMapGoalProperties( "ATTACK_.*", {MinCampTime=30, MaxCampTime=90} );

	OnTriggerRegion(AABB(-1532,1472.5,148.6,-1108,1710,249), Map.Barrierpassed);
	OnTriggerRegion(AABB(25.5,1960.6,137,88.7,2428,213), Map.def);
	OnTriggerRegion(AABB(1654.5,-1438,-0.875,1811,-882,75.125), Map.barrier2);
	OnTriggerRegion(AABB(456.8,97.3,21.9,885.5,203.6,110.8), Map.shift);
	OnTriggerRegion(AABB(-1489.5,1120.5,205,-1109,1196.8,288.8), Map.fix_truck);

	Util.EnableGroup( "group1", TEAM.ALLIES);
	Util.EnableGroup( "group2", TEAM.AXIS);
	Util.EnableGroup( "group17"); // routes
	Util.EnableGoal("AMMOCAB_.*"); //enables for both teams
	Util.EnableGoal("HEALTHCAB_.*"); //enables for both teams

	SetAvailableMapGoals( TEAM.ALLIES, false, "ROUTE_in1" );

	MapRoutes =
	{
		CAPPOINT_53 =
		{
			ROUTE_obj  =
			{
				ROUTE_obj2  =
				{
					ROUTE_obj1  =
					{
						ROUTE_obj4  =
						{
							ROUTE_obj5  =
							{
								ROUTE_tunnel1  =
								{
									ROUTE_tunnel2  =
									{
									},
								},
							},
							ROUTE_tunnel3  =
							{
							},
						},
					},
				},
			},
		},

		FLAG_gold_crate =
		{
			ROUTE_spawn3  =
			{
				ROUTE_in1  =
				{
					ROUTE_in2  =
					{
						ROUTE_in3  =
						{
							ROUTE_in4  =
							{
								ROUTE_in5  =
								{
									ROUTE_in6  =
									{
										ROUTE_in7  =
										{
										},
									},
								},
							},
						},
					},
				},
			},
			ROUTE_spawn1  =
			{
				ROUTE_fs50  =
				{
					ROUTE_fs51  =
					{
						ROUTE_fs52  =
						{
							ROUTE_fs53  =
							{
								ROUTE_obj1  =
								{
								},
							},
						},
					},
					ROUTE_tunnel2  =
					{
						ROUTE_tunnel1  =
						{
							ROUTE_obj4  =
							{
								ROUTE_obj1  =
								{
								},
							},
						},
					},
				},
			},
		},

	};
	MapRoutes.ATTACK_p1 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_p2 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_p3 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_p5 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_p6 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_k1 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_k2 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_k3 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_k4 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_m1 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_m2 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_m3 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_m4 = MapRoutes.FLAG_gold_crate;
	MapRoutes.PLANT_Radio_Wall = MapRoutes.FLAG_gold_crate;
	MapRoutes.PLANT_Truck_Barrier_1 = MapRoutes.FLAG_gold_crate;
	Util.Routes(MapRoutes);

	Util.FixMoverPos("truck", Vec3(-1646.500, -1791.000, 200.500), Vec3(-1792.000, -1788.000, 142.000));

	Util.MapDebugPrint("OnMapLoad");
};

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