/********************************************************
Waypoints and Script by >WES< P!NNAN & >WES< GRANNY
********************************************************/

global Map =
{

	Debug = false,
	Talk = true, //set this to false if you wont bots talking ingame
	Quiet = true,

	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_ar_call_al_1 = "CALLARTILLERY_ar_call_al_1",
	Call_Artillery_ar_call_ax_1 = "CALLARTILLERY_ar_call_ax_1",
	Call_Artillery_ar_call_ax_2 = "CALLARTILLERY_ar_call_ax_2",
	Call_Artillery_ar_call_ax_3 = "CALLARTILLERY_ar_call_ax_3",
	Call_Artillery_ar_call_ax_4 = "CALLARTILLERY_ar_call_ax_4",
	Artillery_S_ar_al_1 = "ARTILLERY_S_ar_al_1",
	Artillery_D_ar_ax_1 = "ARTILLERY_D_ar_ax_1",
	Artillery_D_ar_ax_2 = "ARTILLERY_D_ar_ax_2",
	Artillery_D_ar_ax_3 = "ARTILLERY_D_ar_ax_3",
	Build_Command_Post = "BUILD_Command_Post",
	Build_Field_MG42 = "BUILD_Field_MG42",
	Build_Tank = "BUILD_Tank",
	Build_Tank_Barrier_1 = "BUILD_Tank_Barrier_1",
	Build_Tank_Barrier_2 = "BUILD_Tank_Barrier_2",
	Plant_Command_Post = "PLANT_Command_Post",
	Plant_Field_MG42 = "PLANT_Field_MG42",
	Plant_Tank_Barrier_1 = "PLANT_Tank_Barrier_1",
	Plant_Tank_Barrier_2 = "PLANT_Tank_Barrier_2",
	Mount_2326 = "MOUNTMG42_2326",
	Mount_Field_MG42 = "MOUNTMG42_Field_MG42",
	Repair_2326 = "REPAIRMG42_2326",
	Repair_Field_MG42 = "REPAIRMG42_Field_MG42",
	Mobile_MG42_mg_al_1 = "MOBILEMG42_mg_al_1",
	Mobile_MG42_mg_ax_1 = "MOBILEMG42_mg_ax_1",
	Mobile_MG42_mg_ax_2 = "MOBILEMG42_mg_ax_2",
	Mobile_Mortar_mo_al_1 = "MOBILEMORTAR_mo_al_1",
	Mobile_Mortar_mo_al_2 = "MOBILEMORTAR_mo_al_2",
	Mobile_Mortar_mo_ax_1 = "MOBILEMORTAR_mo_ax_1",
	Mobile_Mortar_mo_ax_2 = "MOBILEMORTAR_mo_ax_2",
	Snipe_s_alpart1_1 = "SNIPE_s_alpart1_1",
	Snipe_s_alpart1_2 = "SNIPE_s_alpart1_2",
	Snipe_s_apart1_1 = "SNIPE_s_apart1_1",
	Snipe_s_church_1 = "SNIPE_s_church_1",
	Snipe_s_church_2 = "SNIPE_s_church_2",
	Snipe_s_al_church_1 = "SNIPE_s_al_church_1",
	Snipe_s_al_church_2 = "SNIPE_s_al_church_2",
	Snipe_s_apart3 = "SNIPE_s_apart3",
	Mover_tank = "MOVER_tank",

	//CP
	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_Built = function( trigger )
	{
		Util.MapDebugPrint( "Axis_Command_Post_Built" );
	},

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

	//MG
	Field_MG42_Built = function( trigger )
	{
		Util.MapDebugPrint( "Field_MG42_Built" );
	},

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

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

	Tank_Destroyed = function( trigger )
	{
		Util.SetPositionGoal( "BUILD_Tank", "MOVER_tank" );

		Util.MapDebugPrint( "Tank_Destroyed" );
	},

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

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

		if ( Map.Talk && MAP_TALK )
		{
			foreach ( id and bot in BotTable )
			{
				if ( bot.GetTeam() == TEAM.ALLIES )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.SayVoice(VOICE.PATH_CLEARED);
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.ExecCommand("vsay_team FTAttack");
					}
				}
				if ( bot.GetTeam() == TEAM.AXIS )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.SayVoice(VOICE.REINFORCE_DEF);
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.ExecCommand("vsay_team FTFallBack");
					}
				}
			}
		}

		Util.MapDebugPrint( "change_action_1" );
	},

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

		if ( Map.Talk && MAP_TALK )
		{
			foreach ( id and bot in BotTable )
			{
				if ( bot.GetTeam() == TEAM.ALLIES )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.SayVoice(VOICE.PATH_CLEARED);
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.ExecCommand("vsay_team FTAttack");
					}
				}
				if ( bot.GetTeam() == TEAM.AXIS )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.SayVoice(VOICE.REINFORCE_DEF);
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.ExecCommand("vsay_team FTFallBack");
					}
				}
			}
		}

		Util.MapDebugPrint( "change_action_2" );
	},

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

		if ( Map.Talk && MAP_TALK )
		{
			foreach ( id and bot in BotTable )
			{
				if ( bot.GetTeam() == TEAM.ALLIES )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.SayVoice(VOICE.PATH_CLEARED);
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.ExecCommand("vsay_team FTAttack");
					}
				}
				if ( bot.GetTeam() == TEAM.AXIS )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.SayVoice(VOICE.REINFORCE_DEF);
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.ExecCommand("vsay_team FTFallBack");
					}
				}
			}
		}

		Util.MapDebugPrint( "change_action_3" );
	},

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

		if ( Map.Talk && MAP_TALK )
		{
			foreach ( id and bot in BotTable )
			{
				if ( bot.GetTeam() == TEAM.ALLIES )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.SayVoice(VOICE.PATH_CLEARED);
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.ExecCommand("vsay_team FTAttack");
					}
				}
				if ( bot.GetTeam() == TEAM.AXIS )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.SayVoice(VOICE.REINFORCE_DEF);
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.ExecCommand("vsay_team FTFallBack");
					}
				}
			}
		}

		Util.MapDebugPrint( "change_action_4" );
	},

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

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

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

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

	Allies_Win = function( trigger )
	{
		ETUtil.WinningChat( TEAM.ALLIES );
		ETUtil.LosingChat( TEAM.AXIS );
		Util.MapDebugPrint( "allies_win" );
	},

	tank_at_location = function( trigger )
	{
		switch(Map.VehicleLocation)
		{
			case 1:
			{
				Map.change_action_1();
			}
			case 2:
			{
				Map.change_action_2();
			}
			case 3:
			{
				Map.change_action_3();
			}
			case 4:
			{
				Map.change_action_4();
			}
		}
		Util.MapDebugPrint("tank at location " + Map.VehicleLocation, true);
	},
};

global OnMapLoad = function()
{
	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 MG42 has been constructed.", Map.Field_MG42_Built );
	OnTrigger( "The Tank has been repaired!", Map.Tank_Built );
	OnTrigger( "Tank Barrier #1 has been constructed.", Map.Tank_Barrier_1_Built );
	OnTrigger( "Tank Barrier #2 has been constructed.", Map.Tank_Barrier_2_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 Bridge MG42 has been destroyed.", Map.Field_MG42_Destroyed );
	OnTrigger( "Tank Barrier #1 has been destroyed.", Map.Tank_Barrier_1_Destroyed );
	OnTrigger( "Tank Barrier #2 has been destroyed.", Map.Tank_Barrier_2_Destroyed );
	OnTrigger( "The Tank has been damaged!", Map.Tank_Destroyed );
	OnTrigger( "Allied team has destroyed the Bank Doors!", Map.Blow_Doors );
	OnTrigger( "Allied team escaped with the tank from the City!", Map.Allies_Win );
	OnTrigger( "tank at location", Map.tank_at_location );

	//set up a positional trigger for the tank
	l1 = OnTriggerRegion(AABB(366.670,1006.629,102.234,486.693,1368.145,206.406), RegionTrigger.VehicleTrigger);
	l2 = OnTriggerRegion(AABB(2169.280,-1005.954,86.425,2654.859,-778.670,198.846), RegionTrigger.VehicleTrigger);
	l3 = OnTriggerRegion(AABB(-141.152,-1696.302,157.812,63.152,-1352.807,253.125), RegionTrigger.VehicleTrigger);
	l4 = OnTriggerRegion(AABB(-3104.703,-1591.178,125.056,-2730.967,-1368.898,223.321), RegionTrigger.VehicleTrigger);

	//set offset for better reachable
	Util.SetGoalOffset( 40, 0, 0, "PLANT_Tank_Barrier_1" );
	//Util.SetGoalOffset( 0, 0, 0, "" );

	//set max users for goals
	Util.SetMaxUsersInProgress( 2, "BUILD.*" );
	Util.SetMaxUsersInProgress( 2, "PLANT.*" );
	Util.SetMaxUsersInProgress( 1, "DEFEND_.*" );
	Util.SetMaxUsersInProgress( 1, "ATTACK_.*" );
	Util.SetMaxUsersInProgress( 1, "MOUNTMG42.*" );

	//Set min/max camptime
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=120, MaxCampTime=120});
	SetMapGoalProperties( "SNIPE_.*", {MinCampTime=60, MaxCampTime=120});
	SetMapGoalProperties( "ATTACK_.*", {MinCampTime=30, MaxCampTime=60});
	SetMapGoalProperties( "DEFEND_.*", {MinCampTime=60, MaxCampTime=120});

	SetGoalPriority( "DEFUSE_Tank_Barrier_2_.*", 1.10, TEAM.AXIS, CLASS.ENGINEER, true );
	SetGoalPriority( "DEFUSE_Tank_Barrier_1_.*", 1.15, TEAM.AXIS, CLASS.ENGINEER, true );

	//clear all goals
	SetAvailableMapGoals( TEAM.AXIS, false, ".*" );
	SetAvailableMapGoals( TEAM.ALLIES, false, ".*" );

	Util.EnableGoal("ROUTE.*"); //enable routing for both teams

	//enable part 1 goals
	Groups.EnableAllies(Groups.group1);
	Groups.EnableAxis(Groups.group2);

	//Routes
	MapRoutes =
	{
		ATTACK_a_start_1 =
		{
			ROUTE_r_allied_spawn_1 =
			{
				ROUTE_r_al_spawn1_exit =
				{
					ROUTE_r_split_1 =
					{
						ROUTE_r_right_tunnel = { ROUTE_r_right_tunnel_exit = {}, },
						ROUTE_r_left_tunnel =
						{
							ROUTE_r_left_tunnel_split =
							{
								ROUTE_r_left_tunnel_exit = {},
								ROUTE_r_left_building = { ROUTE_r_left_window = {}, },
							},
						},
					},
				},
			},
		},
	};
	//copying some routes
	MapRoutes.ATTACK_a_start_2 = MapRoutes.ATTACK_a_start_1;
	MapRoutes.ATTACK_a_start_3 = MapRoutes.ATTACK_a_start_1;
	MapRoutes.ATTACK_a_start_4 = MapRoutes.ATTACK_a_start_1;
	MapRoutes.ATTACK_a_start_5 = MapRoutes.ATTACK_a_start_1;
	MapRoutes.ATTACK_a_start_6 = MapRoutes.ATTACK_a_start_1;

	Util.Routes(MapRoutes);
	Util.MapDebugPrint( "OnMapLoad" );
};

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

global Groups =
{
	//Allied part 1
	group1 =
	{
		Map.Build_Tank,
		Map.Mobile_MG42_mg_al_1,
		"MOUNT_tank",
		Map.Plant_Tank_Barrier_1,
		"ATTACK_a_start.*",
		"MOBILEMORTAR_mo_al_1.*",
	},

	//Axis part 1
	group2 =
	{
		Map.Build_Tank_Barrier_1,
		Map.Mobile_MG42_mg_ax_1,
		Map.Mobile_MG42_mg_ax_2,
		Map.Mount_2326,
		Map.Repair_2326,
		"DEFEND_d_start.*",
		"MOBILEMORTAR_mo_ax_1.*",
	},

	//Allied part 2
	group3 =
	{
		Map.Build_Field_MG42,
		Map.Build_Tank,
		Map.Mount_Field_MG42,
		"MOUNT_tank",
		Map.Repair_Field_MG42,
		Map.Snipe_s_al_church_1,
		Map.Snipe_s_al_church_2,
		"ATTACK_a_church.*",
		"MOBILEMORTAR_mo_al_2.*",
	},

	//Axis part 2
	group4 =
	{
		Map.Artillery_D_ar_ax_1,
		Map.Build_Command_Post,
		Map.Call_Artillery_ar_call_ax_1,
		Map.Plant_Field_MG42,
		Map.Snipe_s_church_1,
		Map.Snipe_s_church_2,
		"DEFEND_d_church.*",
		"MOBILEMORTAR_mo_ax_2.*",
	},

	//Allies part 3
	group5 =
	{
		Map.Build_Command_Post,
		Map.Build_Tank,
		"MOUNT_tank",
		Map.Plant_Command_Post,
		"ATTACK_a_wall.*"
	},

	//Axis part 3
	group6 =
	{
		Map.Artillery_D_ar_ax_2,
		Map.Build_Tank_Barrier_2,
		Map.Call_Artillery_ar_call_ax_1,
		Map.Call_Artillery_ar_call_ax_2,
		"DEFEND_d_wall.*",
	},

	//Allies part 4
	group7 =
	{
		Map.Build_Command_Post,
		Map.Build_Tank,
		"MOUNT_tank",
		Map.Plant_Command_Post,
		Map.Plant_Tank_Barrier_2,
		"ATTACK_a_barrier.*"
	},

	//Axis part 4
	group8 =
	{
		Map.Artillery_D_ar_ax_2,
		Map.Build_Tank_Barrier_2,
		Map.Call_Artillery_ar_call_ax_1,
		Map.Call_Artillery_ar_call_ax_2,
		"DEFEND_d_barrier.*",
	},

	//Allies part 5
	group9 =
	{
		Map.Build_Command_Post,
		Map.Build_Tank,
		"MOUNT_tank",
		Map.Plant_Command_Post,
		Map.Plant_Tank_Barrier_2,
		"ATTACK_a_end.*"
	},

	//Axis part 5
	group10 =
	{
		Map.Artillery_D_ar_ax_3,
		// Map.Call_Artillery_ar_call_ax_3, // cs: no targets
		// Map.Call_Artillery_ar_call_ax_4, // cs: no targets
		"DEFEND_d_end.*",
	},

	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);
		}
	},
};
