//==========================================================================================
//
//	document_raid_final.gm
//
//	Who             When			What
//------------------------------------------------------------------------------------------
//	Scabs		Jan 2011		Waypoints
//	MickyP		Jan 2011		Initial Script
//
//==========================================================================================
//

global Map =
{
	Debug = 0,
	TB_Built = false,
	Tank_At_TB = false,
	Bridge_Built = false,

	Allied_Command_Post_Built = function( trigger )
	{
		Util.MapDebugPrint( "Allied_Command_Post_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" );
	},

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

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

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

	Back_Wall_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Back_Wall" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"CHECKPOINT_forward_flag",
			"PLANT_Back_Gate",
		});

		Util.MapDebugPrint( "Back_Wall_Destroyed" );
	},

	Back_Gate_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Back_Gate" );
		Util.EnableGoal( "ROUTE_Back_Gate" );

		Util.MapDebugPrint( "Back_Gate_Destroyed" );
	},

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

	Tank_Escaping = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_Tank.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_Hill.*" );

		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Tank_Start.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Barrier.*" );

		Util.MapDebugPrint( "Tank_Escaping" );
	},

	Tank_Barrier_Built = function( trigger )
	{
		Map.TB_Built = true;
		Wp.SetWaypointFlag( "Barrier", "closed", true );
		if ( Map.Tank_At_TB == true )

			{
			SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Tank" );
			}

		Util.MapDebugPrint( "Tank_Barrier_Built" );
	},

	Tank_Barrier_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Tank" );
		Map.TB_Built = false;
		Wp.SetWaypointFlag( "Barrier", "closed", false );
		Util.MapDebugPrint( "Tank_Barrier_Destroyed" );
	},

	Tank_At_Barrier = function( trigger )
	{
		Map.Tank_At_TB = true;
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_Hill.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_Barrier.*" );
		if (  Map.TB_Built == true )
			{
			SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Tank" );
			}

		Util.MapDebugPrint( "Tank_At_Barrier" );
	},

	Tank_Past_Barrier = function( trigger )
	{
		Map.Tank_At_TB = false;
		SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Tank_Barrier" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Tank_Barrier" );

		Util.MapDebugPrint( "Tank_Past_Barrier" );
	},

	Tank_past_Gate = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_Barrier.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Bridge" );

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_Barrier.*",
			"PLANT_Allied_Command_Post",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_Bridge.*",
			"PLANT_Bridge",
		});

		Util.MapDebugPrint( "Tank_past_Gate" );
	},

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

	Bridge_Built = function( trigger )
	{
		Map.Bridge_Built = true;

		Util.MapDebugPrint( "Bridge_Built" );
	},

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

	Tank_Over_Bridge_1 = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Bridge" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Axis_Command_Post" );

		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Barrier.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"BUILD_Fence",
			"BUILD_Axis_Command_Post",
			"DEFEND_Gun.*",
		});

		Util.MapDebugPrint( "Tank_Over_Bridge_1" );
	},

	Tank_At_Gun = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Bridge.*" );

		Util.MapDebugPrint( "Tank_At_Gun" );
	},

	Tank_Past_Gun = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Gun.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Corner.*" );

		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_Corner.*" );

		Util.MapDebugPrint( "Tank_Past_Gun" );
	},

	Tank_Rear_gun = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Wall.*" );

		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_Wall.*" );

		Util.MapDebugPrint( "Tank_Rear_gun" );
	},

	Tank_Near_Power = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Corner.*" );

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

		Util.MapDebugPrint( "Tank_Rear_gun" );
	},

	Fence_Built = function( trigger )
	{
		Util.DisableGoal( "ROUTE_Fence" );
		Util.MapDebugPrint( "Fence_Built" );
	},

	Fence_Destroyed = function( trigger )
	{
		Util.EnableGoal( "ROUTE_Fence" );
		Util.MapDebugPrint( "Fence_Destroyed" );
	},

	document_door_open = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"FLAG_Documents",
			"CAPPOINT_Tank",
			"PLANT_Fence",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"BUILD_Tank",
			"MOUNT_Tank",
			"ATTACK_Wall.*",
		});

		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Wall.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_Obj.*",
			"DEFEND_Area.*",
		});

		Util.BotChat(TEAM.AXIS, "vsay", VOICE.REINFORCE_DEF, 1);

		Util.MapDebugPrint( "document_door_open" );
	},

	Documents_Taken = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_Obj.*",
			"DEFEND_Area.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Tank_Cappoint.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Tank_Cappoint.*" );

		Util.MapDebugPrint( "Documents_Taken" );
	},

	Documents_Returned = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Tank_Cappoint.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Tank_Cappoint.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_Obj.*",
			"DEFEND_Area.*",
		});
		Util.MapDebugPrint( "Documents_Returned" );
	},

	Documents_Secured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Tank",
			"MOUNT_Tank",
			"BUILD_Bridge",
		});

		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"PLANT_Fence",
			"FLAG_Documents",
			"CAPPOINT_Tank",
		});

		SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Fence" );


		Util.MapDebugPrint( "Documents_Secured" );
	},

	Tank_At_Bridge_2 = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Tank_Cappoint.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Tank_Cappoint.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Bridge.*" );

		Util.MapDebugPrint( "Tank_At_Bridge_2" );
	},

	Tank_Over_Bridge_2 = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Bridge" );

		Util.MapDebugPrint( "Tank_Over_Bridge_2" );
	},

	vehicle_at_location = function( trigger )
	{
		switch(Map.VehicleLocation)
		{
			case 1:
			{
				// Tank top of hill
				Map.Tank_Escaping();
			}
			case 2:
			{
				// Tank at barrier
				Map.Tank_At_Barrier();
			}
			case 3:
			{
				// Tank past barrier
				Map.Tank_Past_Barrier();

			}
			case 4:
			{
				// tank at bridge
				Map.Tank_At_Bridge_1();
			}
			case 5:
			{
				//tank over bridge
				Map.Tank_Over_Bridge_1();

			}
			case 6:
			{
				// tank at Gun
				Map.Tank_At_Gun();

			}
			case 7:
			{
				//tank past Gun
				Map.Tank_Past_Gun();
			}
			case 8:
			{
				//tank at 3rd corner
				Map.Tank_Rear_gun();

			}
			case 9:
			{
				////tank at 4th corner
				Map.Tank_Near_Power();

			}
			case 10:
			{
				//tank at bridge
				Map.Tank_At_Bridge_2();

			}
			case 11:
			{
				//tank over bridge
				Map.Tank_Over_Bridge_2();

			}
		}
		Util.MapDebugPrint("vehicle at location " + Map.VehicleLocation, true);
	},
};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Allied_Command_Post_Built );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Axis_Command_Post_Built );
	OnTrigger( "The Bridge has been constructed.", Map.Bridge_Built );
	OnTrigger( "The Fence has been constructed.", Map.Fence_Built );
	OnTrigger( "The tank has been repaired!", Map.Tank_Built );
	OnTrigger( "The Tank Barrier has been constructed.", Map.Tank_Barrier_Built );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Allied_Command_Post_Destroyed );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Axis_Command_Post_Destroyed );
	OnTrigger( "The Allies have destroyed the back gate!", Map.Back_Gate_Destroyed );
	OnTrigger( "The Allies have destroyed the back wall!", Map.Back_Wall_Destroyed );
	OnTrigger( "The Bridge has been destroyed.", Map.Bridge_Destroyed );
	OnTrigger( "The Fence has been destroyed.", Map.Fence_Destroyed );
	OnTrigger( "The Tank Barrier has been destroyed.", Map.Tank_Barrier_Destroyed );
	OnTrigger( "Allies have stolen Documents!", Map.Documents_Taken );
	OnTrigger( "Flag returned Documents!", Map.Documents_Returned );
	OnTrigger( "Allied team has stolen The Gun Documents", Map.Documents_Secured );
	OnTrigger( "Axis have reclaim the Forward Bunker!", Map.forward_flag_Axis_Captured );
	OnTrigger( "Allies have captured the Forward Bunker!", Map.forward_flag_Allies_Captured );
	OnTrigger( "The Door To Document Room Has Opened!", Map.document_door_open );
	OnTrigger( "The tank is past the gate!", Map.Tank_past_Gate );

	OnTrigger( "tank at location", Map.vehicle_at_location );

	Trigger1 = OnTriggerRegion(AABB(-2779.208,1045.598,9.125,-2538.053,1097.765,83.125),		RegionTrigger.VehicleTrigger);
	Trigger2 = OnTriggerRegion(AABB(-1937.408,1205.201,9.125,-1892.468,1400.117,87.922),		RegionTrigger.VehicleTrigger);
	Trigger3 = OnTriggerRegion(AABB(-1849.507,1174.101,9.125,-1797.215,1395.793,83.125),		RegionTrigger.VehicleTrigger);
	Trigger4 = OnTriggerRegion(AABB(-948.146,-328.014,-34.580,-749.332,-267.036,45.526),		RegionTrigger.VehicleTrigger);
	Trigger5 = OnTriggerRegion(AABB(-1115.433,-1313.749,97.125,-1061.420,-1065.551,181.499),	RegionTrigger.VehicleTrigger);
	Trigger6 = OnTriggerRegion(AABB(-1958.542,-1442.700,122.352,-1653.952,-1385.657,198.925),	RegionTrigger.VehicleTrigger);
	Trigger7 = OnTriggerRegion(AABB(-1708.133,-2530.968,238.360,-1669.798,-2243.689,346.047),	RegionTrigger.VehicleTrigger);
	Trigger8  = OnTriggerRegion(AABB(-812.307,-2538.263,244.443,-748.342,-2260.133,346.974),	RegionTrigger.VehicleTrigger);
	Trigger9 = OnTriggerRegion(AABB(-986.253,-595.799,9.591,-736.392,-549.651,84.693),		RegionTrigger.VehicleTrigger);

	Util.DisableGoal( ".*", true ); // all but routes
	Util.EnableGoal( "AMMOCAB_first_ammocabinet" );
	Util.EnableGoal( "HEALTHCAB_first_healthcabinet" );

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"BUILD_Tank",
		"BUILD_Allied_Command_Post",
		"MOUNT_Tank",
		"PLANT_Back_Wall",
		"PLANT_Tank_Barrier",
		"ATTACK_Tank.*",
	});

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"BUILD_Tank_Barrier",
		"CHECKPOINT_forward_flag",
		"DEFEND_Tank_Start.*",
		"PLANT_Allied_Command_Post",
	});

	Util.DisableGoal( "ROUTE_Back_Gate" );
	Wp.SetWaypointFlag( "Barrier", "closed", false );

	SetGoalPriority( "BUILD_Bridge", 0.91 );
	SetGoalPriority( "BUILD_Fence", 0.91 );
	SetGoalPriority( "PLANT_Axis_Command_Post", 0.8 );

	// Max users per goal
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "GRENADE_.*" );
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 1, "CHECKPOINT_forward_flag" );
	Util.SetMaxUsers( 2, "PLANT_.*" );

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


	if ( Map.Debug > 1 )
		{ Util.ShowActiveGoals(); }

	print( "Omni-bot map script for " + GetMapName() + " executed." );

	MapRoutes =
	{
		BUILD_Tank =
		{
			ROUTE_Allied_Spawn  =
			{
				ROUTE_Allied_Lower_Exit  =
				{
					ROUTE_Barrier  =
					{
					},
				},
				ROUTE_Allied_Upper_Exit  =
				{
					ROUTE_CP_Outside  =
					{
						ROUTE_Hill_Top  =
						{
						},
					},
					ROUTE_Command_Post  =
					{
						ROUTE_Hill_Top  =
						{
						},
					},
				},
			},
			ROUTE_Flag_Spawn  =
			{
				ROUTE_Barrier_Bridge_Exit  =
				{
				},
				ROUTE_Back_Gate  =
				{
				},
				ROUTE_Flag_Stairs  =
				{
					ROUTE_Barrier_Bridge_Exit  =
					{
					},
				},
			},
		},
		DEFEND_Tank_Start_1 =
		{
			ROUTE_Flag_Spawn  =
			{
				ROUTE_Flag_Stairs  =
				{
					ROUTE_Barrier_Bridge_Exit  =
					{
					},
				},
				ROUTE_Drop_Point  =
				{
					ROUTE_Tank_Ramp  =
					{
					},
				},
			},
		},
		PLANT_Tank_Barrier =
		{
			ROUTE_Allied_Spawn  =
			{
				ROUTE_Allied_Upper_Exit  =
				{
				},
				ROUTE_Allied_Lower_Exit  =
				{
				},
			},
		},
		FLAG_Documents =
		{
			ROUTE_Flag_Spawn  =
			{
				ROUTE_Back_Gate  =
				{
					ROUTE_Docs_Main_Entry  =
					{
						ROUTE_Docs_1  =
						{
						},
						ROUTE_Docs_2  =
						{
						},
						ROUTE_Docs_3  =
						{
						},
						ROUTE_Docs_4  =
						{
						},
					},
					ROUTE_Tree_Right  =
					{
						ROUTE_Fence  =
						{
						},
					},
					ROUTE_Tree_Left  =
					{
						ROUTE_Fence  =
						{
						},
					},
				},
				ROUTE_Flag_Stairs  =
				{
					ROUTE_Barrier_Bridge_Exit  =
					{
						ROUTE_Fence  =
						{
						},
						ROUTE_Docs_Main_Entry  =
						{
							ROUTE_Docs_1  =
							{
							},
							ROUTE_Docs_2  =
							{
							},
							ROUTE_Docs_3  =
							{
							},
							ROUTE_Docs_4  =
							{
							},
						},
					},
				},
			},
		},
		DEFEND_Bridge_1 =
		{
			ROUTE_Axis_Spawn  =
			{
				ROUTE_Axis_Low_Exit  =
				{
					ROUTE_Axis_Bridge  =
					{
					},
				},
				ROUTE_Axis_Middle_Exit  =
				{
					ROUTE_Gun_Front  =
					{
					},
				},
			},
		},
		DEFEND_Obj_1 =
		{
			ROUTE_Axis_Spawn  =
			{
				ROUTE_Axis_Upper_Exit  =
				{
				},
				ROUTE_Axis_Low_Exit  =
				{
				},
				ROUTE_Axis_Middle_Exit  =
				{
				},
			},
		},
		DEFEND_Gun_1 =
		{
			ROUTE_Axis_Spawn  =
			{
				ROUTE_Axis_Middle_Exit  =
				{
				},
				ROUTE_Axis_Low_Exit  =
				{
				},
				ROUTE_Axis_Upper_Exit  =
				{
				},
			},
		},
		DEFEND_Tank_Cappoint_1 =
		{
			ROUTE_Axis_Spawn  =
			{
				ROUTE_Axis_Low_Exit  =
				{
					ROUTE_Gun_Front  =
					{
					},
				},
				ROUTE_Axis_Middle_Exit  =
				{
					ROUTE_Gun_Front  =
					{
					},
					ROUTE_Gun_Rear  =
					{
					},
				},
				ROUTE_Axis_Upper_Exit  =
				{
					ROUTE_Gun_Rear  =
					{
					},
				},
			},
			ROUTE_Flag_Spawn  =
			{
				ROUTE_Flag_Stairs  =
				{
					ROUTE_Barrier_Bridge_Exit  =
					{
					},
				},
				ROUTE_Back_Gate  =
				{
					ROUTE_Tree_Left  =
					{
					},
					ROUTE_Tree_Right  =
					{
					},
				},
			},
		},
	};

	MapRoutes.MOUNT_Tank = MapRoutes.BUILD_Tank;
	MapRoutes.ATTACK_Tank_1 = MapRoutes.BUILD_Tank;
	MapRoutes.ATTACK_Tank_2 = MapRoutes.BUILD_Tank;
	MapRoutes.ATTACK_Tank_3 = MapRoutes.BUILD_Tank;
	MapRoutes.ATTACK_Tank_4 = MapRoutes.BUILD_Tank;
	MapRoutes.ATTACK_Tank_5 = MapRoutes.BUILD_Tank;
	MapRoutes.ATTACK_Hill_1 = MapRoutes.BUILD_Tank;
	MapRoutes.ATTACK_Hill_2 = MapRoutes.BUILD_Tank;
	MapRoutes.ATTACK_Hill_3 = MapRoutes.BUILD_Tank;
	MapRoutes.ATTACK_Hill_4 = MapRoutes.BUILD_Tank;
	MapRoutes.ATTACK_Hill_5 = MapRoutes.BUILD_Tank;

	MapRoutes.ATTACK_Barrier_1 = MapRoutes.PLANT_Tank_Barrier;
	MapRoutes.ATTACK_Barrier_2 = MapRoutes.PLANT_Tank_Barrier;
	MapRoutes.ATTACK_Barrier_3 = MapRoutes.PLANT_Tank_Barrier;
	MapRoutes.ATTACK_Barrier_4 = MapRoutes.PLANT_Tank_Barrier;
	MapRoutes.ATTACK_Barrier_5 = MapRoutes.PLANT_Tank_Barrier;

	MapRoutes.DEFEND_Tank_Start_2 = MapRoutes.DEFEND_Tank_Start_1;
	MapRoutes.DEFEND_Tank_Start_3 = MapRoutes.DEFEND_Tank_Start_1;
	MapRoutes.DEFEND_Tank_Start_4 = MapRoutes.DEFEND_Tank_Start_1;
	MapRoutes.DEFEND_Tank_Start_5 = MapRoutes.DEFEND_Tank_Start_1;
	MapRoutes.DEFEND_Tank_Start_6 = MapRoutes.DEFEND_Tank_Start_1;
	MapRoutes.DEFEND_Tank_Start_7 = MapRoutes.DEFEND_Tank_Start_1;
	MapRoutes.DEFEND_Tank_Start_8 = MapRoutes.DEFEND_Tank_Start_1;

	MapRoutes.DEFEND_Obj_2 = MapRoutes.DEFEND_Obj_1;
	MapRoutes.DEFEND_Obj_3 = MapRoutes.DEFEND_Obj_1;
	MapRoutes.DEFEND_Area_1 = MapRoutes.DEFEND_Obj_1;
	MapRoutes.DEFEND_Area_2 = MapRoutes.DEFEND_Obj_1;
	MapRoutes.DEFEND_Area_3 = MapRoutes.DEFEND_Obj_1;



	Util.Routes(MapRoutes);

};
