// TDOD: route me

global Map =
{
	Flag_obj = "FLAG_obj",
	Build_Command_Post = "BUILD_Command_Post",
	Build_Sidegate = "BUILD_Sidegate",
	Build_Tank = "BUILD_Tank",
	Build_Tank_Barrier_1 = "BUILD_Tank_Barrier_1",
	Build_Wooden_Gate = "BUILD_Wooden_Gate",
	Plant_Command_Post = "PLANT_Command_Post",
	Plant_Sidegate = "PLANT_Sidegate",
	Plant_Tank_Barrier_1 = "PLANT_Tank_Barrier_1",
	Plant_Wooden_Gate = "PLANT_Wooden_Gate",
	Mount_337 = "MOUNTMG42_337",
	Repair_337 = "REPAIRMG42_337",
	Mover_tank = "MOVER_tank",

	Suicide = 1,

	Command_Post_Built = function()
	{
		Util.ChangeSpawn(TEAM.ALLIES, 5, 9);

		Util.MapDebugPrint( "Command_Post_Built" );
	},

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

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

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

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

	Command_Post_Destroyed = function()
	{
		Util.ChangeSpawn(TEAM.ALLIES, 0, 9);

		Util.MapDebugPrint( "Command_Post_Destroyed" );
	},

	Sidegate_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Sidegate" );

		Util.MapDebugPrint( "Sidegate_Destroyed" );
	},

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

	Wooden_Gate_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Wooden_Gate" );

		Util.MapDebugPrint( "Wooden_Gate_Destroyed" );
	},

	obj_Taken = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_obj.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_raft.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_aobj.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_araft.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "PLANTMINE_.*" );

		Util.ChangeSpawn(TEAM.AXIS, 1);
		if ( Map.Suicide )
		{
			ETUtil.KillTeam(TEAM.AXIS, 6);
		}
		Util.ChangeSpawn(TEAM.ALLIES, 0, 9);

		Util.MapDebugPrint( "obj_Taken" );
	},

	obj_returned = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_obj.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_raft.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_aobj.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_araft.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANTMINE_cp.*" );

		Util.ChangeSpawn(TEAM.AXIS, 0, 9);
		Util.ChangeSpawn(TEAM.ALLIES, 5, 9);
				//distance check instead?

		Util.MapDebugPrint( "obj_returned" );
	},

	main_gate = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Tank" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_obj.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_aobj.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"MOUNT_tank",
			"ESCORT_tank",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANTMINE_cp.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANTMINE_h.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_bar.*" );
		Util.EnableGoal("PLANT_Wooden_Gate");
		Util.EnableGoal("BUILD_Command_Post");
		Util.EnableGoal("MOUNTMG42.*", TEAM.AXIS);
		Util.EnableGoal("REPAIRMG42.*", TEAM.AXIS);
		SetAvailableMapGoals( TEAM.ALLIES, false, "MOBILEMG42_allies1" );

		Util.DisableGroup( "path", TEAM.AXIS);
		Util.DisableGroup( "2", TEAM.AXIS);
		Util.EnableGoal("FLAG_obj");

		Wp.SetWaypointFlag( "wall1", "closed", false );
		Wp.SetWaypointFlag( "wall2", "closed", false );
		Util.MapDebugPrint( "main_gate" );
	},

	tank_stolen = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_tank.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_atank.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_bar.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"MOBILEMG42_ally1",
			"SNIPE.*",
		});
		Util.DisableGroup( "1", TEAM.AXIS);

		Util.MapDebugPrint( "tank stolen" );
	},

	tank_past_gate =
	{
		Name = "tank_past_gate",
		TriggerOnClass = CLASS.VEHICLE_HVY,
		OnEnter = function(ent)
		{
			Util.EnableGroup( "path", TEAM.AXIS);
			Util.EnableGroup( "2", TEAM.AXIS);
			SetAvailableMapGoals( TEAM.ALLIES, true, "MOBILEMG42_allies1" );
			Util.MapDebugPrint( "tank_past gate" );
		},
	},

	tank_damaged = function()
	{
		Util.SetPositionGoal( Map.Build_Tank, Map.Mover_tank );
		Util.MapDebugPrint( "tank blown" );
	},
};

global OnMapLoad = function()
{
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Command_Post_Built );
	OnTrigger( "MISSING_STRING", Map.Sidegate_Built );
	OnTrigger( "MISSING_STRING", Map.Tank_Built );
	OnTrigger( "MISSING_STRING", Map.Tank_Barrier_1_Built );
	OnTrigger( "MISSING_STRING", Map.Wooden_Gate_Built );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Command_Post_Destroyed );
	OnTrigger( "The Sidegate has been destroyed!", Map.Sidegate_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Tank_Barrier_1_Destroyed );
	OnTrigger( "The Wooden Gate has been destroyed!", Map.Wooden_Gate_Destroyed );
	OnTrigger( "Allies have stolen the Secret Documents!", Map.obj_Taken );
	OnTrigger( "Flag returned obj!", Map.obj_returned );
	OnTrigger( "The tank has been damaged", Map.tank_damaged );
	OnTrigger( "Allied team has destroyed the Main Gate!", Map.main_gate );
	OnTrigger( "Allied team has stolen the Tank!", Map.tank_stolen );

	OnTriggerRegion(AABB(90.309,165.550,575.125,556.621,251.8,649.125), Map.tank_past_gate);
	SetGoalGroup( "ARTILLERY_D_tank", "1");
	SetGoalGroup( "ARTILLERY_S_tank", "1");
	SetGoalGroup( "CALLARTILLERY_tank1", "1");
	SetGoalGroup( "CALLARTILLERY_tank_b", "2");
	SetGoalGroup( "ARTILLERY_S_tank2", "2");

	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"DEFEND_.*",
		"ATTACK_aobj.*",
		"ATTACK_araft.*",
		"PLANTMINE_.*",
	});
	SetAvailableMapGoals( TEAM.AXIS, false, {
		"ATTACK_.*",
		"DEFEND_bar.*",
		"DEFEND_path.*",
		"DEFEND_obj.*",
		"DEFEND_raft.*",
		"MOBILEMG42_ally1",
		"MOBILEMG42_allies1",
		"SNIPE.*",
		"PLANTMINE_.*",
	});

	Wp.SetWaypointFlag( "wall1", "closed", true );
	Wp.SetWaypointFlag( "wall2", "closed", true );

	Util.SetGoalPosition( 1860, -428.6, 600.125, "PLANT_Sidegate" ) ;
	Util.SetGoalPosition( 1786, 1487, 611.825, "PLANT_Tank_Barrier_1" ) ;
	Util.SetGoalPosition( 297.35, 4913, 819, "PLANT_Wooden_Gate" ) ;


	SetMapGoalProperties( "DEFEND_.*", {MinCampTime=30, MaxCampTime=90} );
	SetMapGoalProperties( "DEFEND_start.*", {MinCampTime=60, MaxCampTime=90} );
	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=30, MaxCampTime=90} );
	SetMapGoalProperties( "ATTACK_.*", {MinCampTime=25, MaxCampTime=60} );
//~	SetMapGoalProperties( "SNIPE_.*", {MinCampTime=40, MaxCampTime=60} );

	Util.DisableGoal("BUILD_Command_Post");
	Util.DisableGoal("MOUNTMG42.*");
	Util.DisableGoal("MOVER_plane");
	Util.DisableGoal("MOVER_lighthouse_light");
	Util.DisableGoal("REPAIRMG42.*");
	Util.DisableGoal("PLANT_Wooden_Gate");
	Util.DisableGoal("FLAG_obj");
	Util.DisableGoal("MOBILEMG42_allies1");
	Util.DisableGroup( "1", TEAM.ALLIES);
	Util.DisableGroup( "2", TEAM.ALLIES);
	Util.DisableGroup( "2", TEAM.AXIS);

	SetGoalPriority( "PLANT_Wooden_Gate", 0.99, TEAM.ALLIES, CLASS.COVERTOPS );

	Util.SetMaxUsers( 2, "CHECKPOINT_.*" );
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 2, "BUILD_.*" );
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 1, "ESCORT_tank" );
	Util.SetMaxUsers( 1, "PLANT_Command_Post" );
	Util.SetMaxUsers( 1, "BUILD_.*" );
	Util.SetMaxUsers( 3, "MOUNT_tank" );




	MapRoutes =
	{
		FLAG_obj =
		{
			ROUTE_spawn0  =
			{
				ROUTE_spawn1  =
				{
					ROUTE_spawn2  =
					{
						ROUTE_spawn3  =
						{
							ROUTE_spawn9  =
							{
								ROUTE_spawn8  =
								{
									ROUTE_spawn13  =
									{
									},
								},
							},
						},
					},
				},
				ROUTE_spawn12  =
				{
					ROUTE_spawn13  =
					{
					},
				},
			},
		},
	};

	BUILD_Command_Post =
		{
			ROUTE_spawn0  =
			{
				ROUTE_spawn1  =
				{
					ROUTE_spawn2  =
					{
						ROUTE_spawn3  =
						{
							ROUTE_spawn4  =
							{
								ROUTE_spawn5  =
								{
								},
							},
						},
					},
				},
				ROUTE_spawn12  =
				{
					ROUTE_spawn11  =
					{
						ROUTE_spawn10  =
						{
							ROUTE_spawn9  =
							{
								ROUTE_spawn6  =
								{
									ROUTE_spawn5  =
									{
									},
								},
							},
						},
					},
				},
			},
		};


	MapRoutes.PLANT_Command_Post = MapRoutes.BUILD_Command_Post;
	MapRoutes.PLANT_Wooden_Gate = MapRoutes.Flag_obj;
	Util.Routes(MapRoutes);
};

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