//==========================================================================================
//
//	crevasse_pe.gm
//
//	Who			When		What
//------------------------------------------------------------------------------------------
//	^1[FL]^7Blind^4man	3 8 10
//
//==========================================================================================
//

global Map =
{
	Build_Anti_Tank_Gun = "BUILD_Anti_Tank_Gun",
	Flag_keycard_flag = "FLAG_keycard_flag",

	keytrigger =
	{
		Name = "keytrigger",
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
			if ( GetEntTeam(ent) == TEAM.ALLIES)
			{

			SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_key.*" );
			SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_cap.*" );
			SetAvailableMapGoals( TEAM.AXIS, false, "CAMP_key.*" );
			SetAvailableMapGoals( TEAM.AXIS, true, "CAMP_cap.*" );

			}
		},
		OnExit = function(ent)
		{
		Util.MapDebugPrint( "key taken" );
		},
	},


	Debug = 0,

	Allied_CP_Dyno = 0,
	Anti_Tank_Gun_Dyno = 0,
	Suicide = 1,
//	DontDispenseAmmo = true,
//	DontDispenseHealth = true,

	Allied_CP_Built = function( trigger )
	{
		Util.ChangeSpawn(TEAM.ALLIES, 0);
		if ( Map.Suicide )
		{
			ETUtil.KillTeam(TEAM.ALLIES, 5);
		}
		Util.MapDebugPrint( "Allied_CP_Built" );
	},

	Anti_Tank_Gun_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "SWITCH_.*" );
		Util.MapDebugPrint( "Anti_Tank_Gun_Built" );
	},

	Allied_CP_Planted = function( trigger )
	{
		Map.Allied_CP_Dyno += 1;
		Util.MapDebugPrint( "Allied_CP_Planted" );
	},

	Anti_Tank_Gun_Planted = function( trigger )
	{
		Map.Anti_Tank_Gun_Dyno += 1;
		Util.MapDebugPrint( "Anti_Tank_Gun_Planted" );
	},

	Allied_CP_Defused = function( trigger )
	{
		Map.Allied_CP_Dyno -= 1;
		Util.MapDebugPrint( "Allied_CP_Defused" );
	},

	Anti_Tank_Gun_Defused = function( trigger )
	{
		Map.Anti_Tank_Gun_Dyno -= 1;
		Util.MapDebugPrint( "Anti_Tank_Gun_Defused" );
	},

	Allied_CP_Destroyed = function( trigger )
	{
		Map.Allied_CP_Dyno = 0;

		Util.MapDebugPrint( "Allied_CP_Destroyed" );
	},

	Anti_Tank_Gun_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "SWITCH_.*" );
		Map.Anti_Tank_Gun_Dyno = 0;

		Util.MapDebugPrint( "Anti_Tank_Gun_Destroyed" );
	},

	documents_Taken = function( trigger )
	{

			SetAvailableMapGoals( TEAM.AXIS, true, "CAMP_trans.*" );
			SetAvailableMapGoals( TEAM.AXIS, false, "CAMP_docs.*" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_docs.*" );
			SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_trans.*" );
			SetAvailableMapGoals( TEAM.AXIS, false, "PLANTMINE_.*" );

		Util.MapDebugPrint( "documents_Taken" );
	},

	keycard_flag_Taken = function( trigger )
	{
		rnd = RandInt(1,3);
		if ( rnd == 1 )
		{
			Util.SetGoalPosition( -988.4, -1821.674, -987.875, Map.Build_Anti_Tank_Gun );
		}
		else if ( rnd == 2 )
		{
			Util.SetGoalPosition( -831.271, -1813.465, -1005.875, Map.Build_Anti_Tank_Gun);
		}
		else
		{
			Util.SetGoalPosition( -826.432, -1875.653, -1005.875, Map.Build_Anti_Tank_Gun);
		}

		Util.MapDebugPrint( "keycard_flag_Taken" );
	},

	documents_Returned = function( trigger )
	{
			SetAvailableMapGoals( TEAM.AXIS, true, "CAMP_docs.*" );
			SetAvailableMapGoals( TEAM.AXIS, false, "CAMP_trans.*" );
			SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_docs.*" );
			SetAvailableMapGoals( TEAM.AXIS, true, "PLANTMINE_.*" );

		Util.MapDebugPrint( "documents_Returned" );
	},

	keycard_flag_Returned = function( trigger )
	{
			SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_key.*" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_cap.*" );
			SetAvailableMapGoals( TEAM.AXIS, true, "CAMP_key.*" );
			SetAvailableMapGoals( TEAM.AXIS, false, "CAMP_cap.*" );

		Util.MapDebugPrint( "keycard_flag_Returned" );
	},

	documents_Secured = function( trigger )
	{
		Util.MapDebugPrint( "game over" );
	},

	keycard_flag_Secured = function( trigger )
	{

		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_cap.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Allied_CP",
			"BUILD_Anti_Tank_Gun",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ATTACK_key.*",
			"CAPPOINT_139",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_gun.*" );

		SetAvailableMapGoals( TEAM.AXIS, false, "CAMP_key.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"CAMP_gun.*",
			"CAMP_switch.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, "CAMP_cap.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"PLANT_Anti_Tank_Gun",
			"PLANTMINE_.*",
		});

		Util.ChangeSpawn(TEAM.AXIS, 0);
		if ( Map.Suicide )
		{
			ETUtil.KillTeam(TEAM.AXIS, 7);
		}

		Util.MapDebugPrint( "keycard_flag_Secured" );
	},

	gun_fired = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"SWITCH_.*",
			"ATTACK_gun.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"FLAG_documents",
			"CAPPOINT_transmitter",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, "CAMP_gun.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "CAMP_docs.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_docs.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "CAMP_switch.*" );
		Util.DisableGoal( "PLANT_.*", true );
		Util.DisableGoal( "BUILD_.*", true );
		Util.MapDebugPrint( "^qAT gun Fired" );
	},

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Allied_CP_Built );
	OnTrigger( "Allies have repaired the Anti-Tank Gun!", Map.Anti_Tank_Gun_Built );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Allied_CP_Planted );
	OnTrigger( "Planted at Anti_Tank Gun.", Map.Anti_Tank_Gun_Planted );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Allied_CP_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Anti_Tank_Gun_Defused );
	OnTrigger( "MISSING_STRING", Map.Allied_CP_Destroyed );
	OnTrigger( "Axis have disabled the Anti-tank Gun!", Map.Anti_Tank_Gun_Destroyed );
	OnTrigger( "Allies have stolen the Documents!", Map.documents_Taken );
	OnTrigger( "Allies have stolen the Keycard!", Map.keycard_flag_Taken );
	OnTrigger( "Flag returned documents!", Map.documents_Returned );
	OnTrigger( "Flag returned keycard_flag!", Map.keycard_flag_Returned );
	OnTrigger( "MISSING_STRING", Map.documents_Secured );
	OnTrigger( "Allied team has used the Keycard!", Map.keycard_flag_Secured );
	OnTrigger( "The allies have broken into the secure room!", Map.gun_fired );

	SetAvailableMapGoals( TEAM.ALLIES, false, ".*" );
	SetAvailableMapGoals( TEAM.AXIS, false, ".*" );
	Util.EnableGoal( "HEALTHCAB_.*", true );
	Util.EnableGoal( "AMMOCAB_.*", true );
	Util.EnableGoal( "ROUTE_.*", true );
	Util.SetGoalPosition( -998.054, -1829.160, -987.875, "PLANT_Anti_Tank_Gun");

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"Flag_keycard_flag",
		"CAPPOINT_139",
		"ATTACK_key.*",
	});
	SetAvailableMapGoals( TEAM.AXIS, true, "CAMP_key.*" );
	SetGoalPriority( "ROUTE_15", 1.0 );

	// Max users per goal
	Util.SetMaxUsers( 1, "CAMP_.*" );
	Util.SetMaxUsers( 3, "FLAG_keycard_flag" );
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "GRENADE_.*" );
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );

	k1 = OnTriggerRegion(AABB(1124.853,2183.944,-152.875,1162.853,2221.944,-78.875),Map.keytrigger);
	// Camp times
//	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=15, MaxCampTime=90} );
//	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=10, MaxCampTime=60} );

	MapRoutes =
	{
		FLAG_keycard_flag =
		{
			ROUTE_1  =
			{
				ROUTE_8  =
				{
					ROUTE_589  =
					{
						ROUTE_22  =
						{
							ROUTE_56  =
							{
								ROUTE_346  = {},


							},
						},
					},
					ROUTE_11  =
					{
						ROUTE_15  =
						{
							ROUTE_19  =
							{
								ROUTE_22  =
								{
									ROUTE_113  =
									{
										ROUTE_643  =
										{
											ROUTE_69  =
											{
												ROUTE_71  =
												{
												},
											},
										},
									},
								},
								ROUTE_27  =
								{
									ROUTE_62  =
									{
										ROUTE_60  =
										{
											ROUTE_346  =
											{
											},
										},
									},
									ROUTE_319  =
									{
										ROUTE_33  =
										{
											ROUTE_36  =
											{
												ROUTE_303  =
												{
													ROUTE_321  =
													{
														ROUTE_113  =
														{
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
			},
		},

		CAPPOINT_transmitter =
		{
			ROUTE_285  =
			{
				ROUTE_451  =
				{
					ROUTE_453  =
					{
						ROUTE_210  =
						{
							ROUTE_207  =
							{
								ROUTE_206  =
								{
									ROUTE_200  =
									{
										ROUTE_180  =
										{
											ROUTE_560  =
											{
												ROUTE_642  =
												{
												},
											},
										},
									},
								},
							},
						},
					},
				},
				ROUTE_570  =
				{
					ROUTE_600  =
					{
						ROUTE_609  =
						{
							ROUTE_235  =
							{
								ROUTE_556  =
								{
									ROUTE_642  =
									{
									},
								},
							},
						},
					},
				},
				ROUTE_276  =
				{
					ROUTE_272  =
					{
						ROUTE_640  =
						{
							ROUTE_269  =
							{
							},
						},
					},
				},
			},
		},

		CAPPOINT_139 =
		{
			ROUTE_330  =
			{
				ROUTE_60  =
				{
					ROUTE_62  =
					{
						ROUTE_308  =
						{
							ROUTE_319  =
							{
								ROUTE_33  =
								{
									ROUTE_303  =
									{
									},
								},
							},
						},
					},
				},
				ROUTE_346  =
				{
					ROUTE_56  =
					{
						ROUTE_113  =
						{
							ROUTE_321  =
							{
								ROUTE_303  =
								{
									ROUTE_133  =
									{
									},
								},
							},
						},
					},
				},
				ROUTE_71  =
				{
					ROUTE_341  =
					{
						ROUTE_107  =
						{
							ROUTE_321  =
							{
								ROUTE_303  =
								{
									ROUTE_133  =
									{
									},
								},
							},
						},
					},
				},
			},
		},

		ATTACK_gun1 =
		{
			ROUTE_cp  =
			{
				ROUTE_cp1  =
				{
					ROUTE_cp8  =
					{
						ROUTE_cp9  =
						{
							ROUTE_cp10  =
							{
								ROUTE_cp13  =
								{
								},
								ROUTE_cp11  =
								{
									ROUTE_cp12  =
									{
									},
								},
							},
						},
					},
					ROUTE_cp2  =
					{
						ROUTE_206  =
						{
							ROUTE_200  =
							{
							},
						},
					},
					ROUTE_cp3  =
					{
						ROUTE_cp4  =
						{
							ROUTE_cp5  =
							{
								ROUTE_cp6  =
								{
									ROUTE_cp7  =
									{
										ROUTE_cp13a  =
										{
											ROUTE_cp13b  =
											{
												ROUTE_cp13c  =
												{
													ROUTE_cp13d  =
													{
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
			},
		},

	};

	MapRoutes.ATTACK_key1 = MapRoutes.FLAG_keycard_flag;
	MapRoutes.ATTACK_key2 = MapRoutes.FLAG_keycard_flag;
	MapRoutes.ATTACK_key3 = MapRoutes.FLAG_keycard_flag;
	MapRoutes.ATTACK_key4 = MapRoutes.FLAG_keycard_flag;
	MapRoutes.ATTACK_key5 = MapRoutes.FLAG_keycard_flag;
	MapRoutes.ATTACK_trans1 = MapRoutes.CAPPOINT_transmitter;
	MapRoutes.ATTACK_trans2 = MapRoutes.CAPPOINT_transmitter;
	MapRoutes.ATTACK_trans3 = MapRoutes.CAPPOINT_transmitter;
	MapRoutes.ATTACK_trans4 = MapRoutes.CAPPOINT_transmitter;
	MapRoutes.ATTACK_cap1 = MapRoutes.CAPPOINT_139;
	MapRoutes.ATTACK_cap2 = MapRoutes.CAPPOINT_139;
	MapRoutes.ATTACK_cap3 = MapRoutes.CAPPOINT_139;
	MapRoutes.ATTACK_cap4 = MapRoutes.CAPPOINT_139;

	MapRoutes.ATTACK_gun2 = MapRoutes.ATTACK_gun1;
	MapRoutes.ATTACK_gun3 = MapRoutes.ATTACK_gun1;
	MapRoutes.ATTACK_gun4 = MapRoutes.ATTACK_gun1;
	MapRoutes.Build_Anti_Tank_Gun = MapRoutes.ATTACK_gun1;
	Util.Routes(MapRoutes);

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

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