//==========================================================================================
//
//	breakout_et_b2.gm
//
//	Who            	When		What
//------------------------------------------------------------------------------------------
//	^1[FL]^7Blind^4man	20 November 2010	Initial Script
//
//==========================================================================================
//

global Map =
{
	Debug = 0, // please set to zero before distributing your script

	Allied_Field_Communications_Dyno = 0,
	Back_Wall_Dyno = 0,
	German_88_Dyno = 0,
	Hotel_De_Ville_Dyno = 0,
	Sewer_Gate_Dyno = 0,
	Suicide = 1,
	Talk = true,
	Plant_Back_Wall = "PLANT_Back_Wall",

	Back_Wall_Built = function( trigger )
	{
		Util.SetRoleForGoals(Map.Plant_Back_Wall, ROLE.INFILTRATOR);

		Util.MapDebugPrint( "Back_Wall_Built" );
	},

	Hotel_De_Ville_Built = function( trigger )
	{
		Util.ChangeSpawn(TEAM.AXIS, 2, 5);

		Util.MapDebugPrint( "Hotel_De_Ville_Built" );
	},

	Allied_cp_Built = function( trigger )
	{
		Util.ChangeSpawn(TEAM.ALLIES, 2, 5);

		Util.MapDebugPrint( "Allied_De_Ville_Built" );
	},

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

	Allied_Field_Communications_Planted = function( trigger )
	{
		Util.DisableGoal("PLANT_Hotel_De_Ville"); //enables for both teams
		Util.DisableGoal("PLANT_Back_Wall"); //enables for both teams
		SetAvailableMapGoals( TEAM.ALLIES, false, "SWITCH_s1" );
		Util.DisableGoal("BUILD_Hotel_De_Ville"); //enables for both teams
		Util.DisableGoal("SNIPE_church"); //enables for both teams
		Util.DisableGoal("SNIPE_hotel.*"); //enables for both teams
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_gun.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_plant.*" );

		foreach ( id and bot in BotTable )
		{
			if ( bot.GetTeam() == TEAM.ALLIES )
			{
				bot.ChangeSpawnPoint( 2 );

				//distance check instead?
				if ( Map.Suicide && bot.GetReinforceTime() < 9 )
				{
					bot.ExecCommand( "kill" );
				}
			}
		}

		Map.Allied_Field_Communications_Dyno += 1;
		Util.MapDebugPrint( "Allied_Field_Communications_Planted" );
	},

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

	German_88_Planted = function( trigger )
	{
		Util.DisableGoal("PLANT_Hotel_De_Ville"); //enables for both teams
		Util.DisableGoal("PLANT_Back_Wall"); //enables for both teams
		Util.DisableGoal("BUILD_Hotel_De_Ville"); //enables for both teams
		SetAvailableMapGoals( TEAM.AXIS, false, "SWITCH_s2" );
		Util.DisableGoal("SNIPE_church"); //enables for both teams
		Util.DisableGoal("SNIPE_hotel.*"); //enables for both teams
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"PLANT_Back_Wall",
			"ATTACK_hq.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_gun.*" );

		foreach ( id and bot in BotTable )
		{
			if ( bot.GetTeam() == TEAM.AXIS )
			{
				bot.ChangeSpawnPoint( 1 );

				//distance check instead?
				if ( Map.Suicide && bot.GetReinforceTime() < 9 )
				{
					bot.ExecCommand( "kill" );
				}
			}
		}

		Map.German_88_Dyno += 1;
		Util.MapDebugPrint( "German_88_Planted" );
	},

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

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

	Allied_Field_Communications_Defused = function( trigger )
	{
		Util.EnableGoal("PLANT_Hotel_De_Ville"); //enables for both teams
		Util.EnableGoal("BUILD_Hotel_De_Ville"); //enables for both teams
		Util.EnableGoal("PLANT_Back_Wall"); //enables for both teams
		Util.EnableGoal("SNIPE_church"); //enables for both teams
		Util.EnableGoal("SNIPE_hotel.*"); //enables for both teams
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_gun.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_plant.*" );

		Map.Allied_Field_Communications_Dyno -= 1;
		Util.MapDebugPrint( "Allied_Field_Communications_Defused" );
	},

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

	German_88_Defused = function( trigger )
	{
		Util.EnableGoal("PLANT_Hotel_De_Ville"); //enables for both teams
		Util.EnableGoal("PLANT_Back_Wall"); //enables for both teams
		Util.EnableGoal("SNIPE_church"); //enables for both teams
		Util.EnableGoal("SNIPE_hotel.*"); //enables for both teams
		Util.EnableGoal("BUILD_Hotel_De_Ville"); //enables for both teams

		SetAvailableMapGoals( TEAM.AXIS, true, {
			"SWITCH_s2",
			"ATTACK_hq.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_gun.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Back_Wall" );

		Map.German_88_Dyno -= 1;
		Util.MapDebugPrint( "German_88_Defused" );
	},

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

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

	Allied_Field_Communications_Destroyed = function( trigger )
	{
		Map.Allied_Field_Communications_Dyno = 0;

		Util.MapDebugPrint( "Allied_Field_Communications_Destroyed" );
	},

	Back_Wall_Destroyed = function( trigger )
	{
		Util.ClearRoleForGoals(Map.Plant_Back_Wall, ROLE.INFILTRATOR);

		Map.Back_Wall_Dyno = 0;

		Util.MapDebugPrint( "Back_Wall_Destroyed" );
	},

	German_88_Destroyed = function( trigger )
	{
		Map.German_88_Dyno = 0;

		Util.MapDebugPrint( "German_88_Destroyed" );
	},

	Hotel_De_Ville_Destroyed = function( trigger )
	{
		Map.Hotel_De_Ville_Dyno = 0;

		Util.MapDebugPrint( "Hotel_De_Ville_Destroyed" );
	},

	Sewer_Gate_Destroyed = function( trigger )
	{
		Map.Sewer_Gate_Dyno = 0;

		Util.MapDebugPrint( "Sewer_Gate_Destroyed" );
	},

	gate_open = function(trigger)
	{
		vel = ToVector(trigger.Action);

		if ( vel.z > 0 )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "SWITCH_s2" );

			Util.MapDebugPrint( "doorOpen", true );
		}
		else if ( vel.z < 0 )
		{
			SetAvailableMapGoals( TEAM.AXIS, true, "SWITCH_s2" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "SWITCH_s1" );

			Util.MapDebugPrint("^1doorClosed", true);
		}
	},
};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "The back alley wall has been rebuilt", Map.Back_Wall_Built );
	OnTrigger( "Axis Command Post constructed in the Hotel De Ville!", Map.Hotel_De_Ville_Built );
	OnTrigger( "Allied Command Post constructed in the Hotel De Ville!", Map.Allied_cp_Built );
	OnTrigger( "The Sewer Gate has been rebuilt", Map.Sewer_Gate_Built );
	OnTrigger( "Planted at The Allied Field Communications.", Map.Allied_Field_Communications_Planted );
	OnTrigger( "Planted at Back Wall.", Map.Back_Wall_Planted );
	OnTrigger( "Planted at The German 88.", Map.German_88_Planted );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Hotel_De_Ville_Planted );
	OnTrigger( "Planted at the Sewer Gate.", Map.Sewer_Gate_Planted );
	OnTrigger( "Defused at The Allied Field Communications.", Map.Allied_Field_Communications_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Back_Wall_Defused );
	OnTrigger( "Defused at The German 88.", Map.German_88_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Hotel_De_Ville_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Sewer_Gate_Defused );
	OnTrigger( "MISSING_STRING", Map.Allied_Field_Communications_Destroyed );
	OnTrigger( "The Axis have breached the back alley wall", Map.Back_Wall_Destroyed );
	OnTrigger( "MISSING_STRING", Map.German_88_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Hotel_De_Ville_Destroyed );
	OnTrigger( "The Allies have breached the Sewer Gate", Map.Sewer_Gate_Destroyed );
	OnTrigger( "sgate_goto", Map.gate_open );

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

	//selective enable---
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"ATTACK_gun.*",
		"PLANT_German_88",
		"PLANT_Sewer_Gate",
	});
	SetAvailableMapGoals( TEAM.ALLIES,true,"MOUNTMG42_111" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_hq.*" );
	SetAvailableMapGoals( TEAM.ALLIES,true,{
		"CALLARTILLERY_a1",
		"ARTILLERY_S_397",
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, "MOBILEMG42_hq" );

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"MOBILEMG42_axis88",
		"MOBILEMG42_axis99",
		"GRENADE_.*",
		"CAMP_.*",
	});
	SetAvailableMapGoals( TEAM.AXIS,true,{
		"MOUNTMG42_396",
		"REPAIRMG42_396",
		"CALLARTILLERY_112",
		"ARTILLERY_D_112",
	});
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"ATTACK_hq.*",
		"DEFEND_88_.*",
		"PLANT_Allied_Field_Communications",
		"PLANT_Back_Wall",
		"SWITCH_s2",
	});

	//universal enable---
	Util.EnableGoal("SNIPE_church"); //enables for both teams
	Util.EnableGoal("SNIPE_hotel.*"); //enables for both teams
	Util.EnableGoal("BUILD_Hotel_De_Ville"); //enables for both teams
	Util.EnableGoal("PLANT_Hotel_De_Ville"); //enables for both teams
	Util.EnableGoal("CALLARTILLERY_s4"); //enables for both teams
	Util.EnableGoal("ARTILLERY_.*"); //enables for both teams
	Util.EnableGoal("AMMOCAB_.*"); //enables for both teams
	Util.EnableGoal("HEALTHCAB_.*"); //enables for both teams

	//resposition some shit---
	Util.SetGoalPosition( -2678.125, 1411.427, 128.125, "PLANT_Back_Wall" ) ;
	Util.SetGoalPosition( 4933, 2432.4, 118.125, "PLANT_German_88" ) ;
	Util.SetGoalPosition( -2999.5, 978.127, 432.125, "PLANT_Allied_Field_Communications" ) ;

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

	Util.SetRoleForGoals(Map.Plant_Back_Wall, ROLE.INFILTRATOR);

	// Camp times
	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=30, MaxCampTime=90} );

	SetGoalPriority( "PLANT_Back_Wall", 0.85, TEAM.AXIS, 0 );
	SetGoalPriority( "MOUNTMG42_.*", 0.05, 0, CLASS.COVERTOPS );
	SetGoalPriority( "PLANT_Allied_Field_Communications", 0.84, TEAM.AXIS, 0 );
	SetGoalPriority( "PLANT_German_88", 0.84, TEAM.ALLIES, 0 );
	SetGoalPriority( "DEFEND_hq.*", 0.52, TEAM.ALLIES, 0 );
	SetGoalPriority( "DEFEND_plant.*", 0.52, TEAM.ALLIES, 0 );
	SetGoalPriority( "DEFEND_88_.*", 0.52, TEAM.AXIS, 0 );
	SetGoalPriority( "BUILD_Hotel_De_Ville", 0.84, 0, 0 );
	SetGoalPriority( "GRENADE_.*", 0.86, TEAM.AXIS );
	SetGoalPriority( "PLANT_Hotel_De_Ville", 0.95, 0, CLASS.COVERTOPS );
	SetGoalPriority( "PLANT_Hotel_De_Ville", 0.0, 0, CLASS.ENGINEER );

	MapRoutes =
	{
		PLANT_German_88 =
		{
			ROUTE_1  =
			{
				ROUTE_112  =
				{
					ROUTE_124  =
					{
						ROUTE_backdoor3  =
						{
							ROUTE_backdoor4  =
							{
								ROUTE_backdoor5  =
								{
									ROUTE_backdoor6  =
									{
										ROUTE_backdoor7  =
										{
											ROUTE_backdoor8  =
											{
												ROUTE_backdoor9  =
												{
													ROUTE_695  =
													{
														ROUTE_699  =
														{
															ROUTE_701  =
															{
																ROUTE_9  =
																{
																	ROUTE_8  =
																	{
																		ROUTE_5  =
																		{
																			ROUTE_4  =
																			{
																				ROUTE_402  =
																				{
																					ROUTE_704  =
																					{
																					},
																				},
																			},
																			ROUTE_602  =
																			{
																				ROUTE_606  =
																				{
																					ROUTE_610  =
																					{
																						ROUTE_704  =
																						{
																						},
																					},
																				},
																			},
																		},
																		ROUTE_14  =
																		{
																			ROUTE_13  =
																			{
																				ROUTE_12  =
																				{
																					ROUTE_386  = {},
																					ROUTE_449  = {},
																				},
																			},
																		},
																	},
																},
															},
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
				ROUTE_99  =
				{
					ROUTE_45  =
					{
						ROUTE_sewer14  =
						{
							ROUTE_sewer13  =
							{
								ROUTE_sewer12  =
								{
									ROUTE_sewer11  =
									{
										ROUTE_sewer10  =
										{
											ROUTE_sewer9  =
											{
												ROUTE_sewer8  =
												{
													ROUTE_sewer7  =
													{
														ROUTE_sewer6  =
														{
															ROUTE_sewer5  =
															{
																ROUTE_sewer4  =
																{
																	ROUTE_sewer3  =
																	{
																		ROUTE_sewer2  =
																		{
																			ROUTE_sewer1  =
																			{
																				ROUTE_6  =
																				{
																					ROUTE_5  =
																					{
																						ROUTE_602  =
																						{
																						},
																					},
																				},
																			},
																		},
																	},
																},
															},
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
				ROUTE_sewer14  =
				{
					ROUTE_sewer13  =
					{
						ROUTE_backdoor13  =
						{
							ROUTE_backdoor12  =
							{
								ROUTE_backdoor11  =
								{
									ROUTE_backdoor10  =
									{
										ROUTE_backdoor9  =
										{
											ROUTE_11  =
											{
												ROUTE_10  =
												{
													ROUTE_9  =
													{
														ROUTE_8  =
														{
															ROUTE_5  =
															{
																ROUTE_602  =
																{
																},
															},
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
			},
		},

		DEFEND_hq2 =
		{
			ROUTE_1  =
			{
				ROUTE_6_1  = {Weight = 2,},
					ROUTE_sewer15  =
					{
						ROUTE_54  =
						{
							ROUTE_900  =
							{
								ROUTE_71  =
								{
									ROUTE_75  =
									{
									},
								},
							},
						},
					},

				ROUTE_sewer15  =
				{
					ROUTE_54  = {Weight = 4,},
						ROUTE_900  =
						{
							ROUTE_71  =
							{
							},
						},

					ROUTE_66  =
					{
						ROUTE_71  =
						{
							ROUTE_75  =
							{
							},
						},
					},
				},
			},
		},

		DEFEND_88_2 =
		{
			ROUTE_2  =
			{
				ROUTE_3  =
				{
				},
				ROUTE_500  =
				{
				},
				ROUTE_530  =
				{
					ROUTE_386  =
					{
						ROUTE_449  =
						{
							ROUTE_3  = {},
						},
					},
				},
			},
		},

		PLANT_Allied_Field_Communications =
		{
			ROUTE_2  =
			{
				ROUTE_3  =
				{
					ROUTE_4  =
					{
						ROUTE_5  =
						{
							ROUTE_9  =
							{
								ROUTE_10  =
								{
									ROUTE_11  =
									{
										ROUTE_backdoor9  =
										{
											ROUTE_backdoor11  =
											{
												ROUTE_backdoor12  =
												{
													ROUTE_backdoor13  =
													{
														ROUTE_sewer13  =
														{
															ROUTE_sewer14  =
															{
																ROUTE_sewer15  =
																{
																	ROUTE_54  =
																	{
																		ROUTE_900  =
																		{
																			ROUTE_71  =
																			{
																				ROUTE_75  =
																				{
																				},
																			},
																		},
																	},
																},
																ROUTE_45  =
																{
																	ROUTE_99  =
																	{
																		ROUTE_sewer15  =
																		{
																			ROUTE_66  =
																			{
																				ROUTE_71  =
																				{
																					ROUTE_75  =
																					{
																					},
																				},
																			},
																		},
																	},
																},
															},
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
				ROUTE_12  =
				{
					ROUTE_13  =
					{
						ROUTE_14  =
						{
							ROUTE_6  =
							{
								ROUTE_7  =
								{
									ROUTE_sewer4  =
									{
										ROUTE_sewer5  =
										{
											ROUTE_sewer6  =
											{
												ROUTE_sewer7  =
												{
													ROUTE_sewer8  =
													{
														ROUTE_sewer9  =
														{
															ROUTE_sewer10  =
															{
																ROUTE_backdoor2  =
																{
																	ROUTE_124  =
																	{
																		ROUTE_112  =
																		{
																			ROUTE_sewer15  =
																			{
																				ROUTE_66  =
																				{
																				},
																			},
																		},
																	},
																},
															},
														},
													},
												},
											},
										},
									},
								},
								ROUTE_9  =
								{
									ROUTE_10  =
									{
										ROUTE_11  =
										{
											ROUTE_backdoor9  =
											{
												ROUTE_backdoor8  =
												{
													ROUTE_backdoor7  =
													{
														ROUTE_backdoor6  =
														{
															ROUTE_backdoor5  =
															{
																ROUTE_backdoor4  =
																{
																	ROUTE_backdoor3  =
																	{
																		ROUTE_124  =
																		{
																			ROUTE_112  =
																			{
																				ROUTE_54  =
																				{
																					ROUTE_900  =
																					{
																						ROUTE_71  =
																						{
																						},
																					},
																				},
																			},
																		},
																	},
																},
															},
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
			},
		},
	};

	MapRoutes.DEFEND_hq1 = MapRoutes.DEFEND_hq2;
	MapRoutes.DEFEND_hq3 = MapRoutes.DEFEND_hq2;
	MapRoutes.DEFEND_plant1 = MapRoutes.DEFEND_hq2;
	MapRoutes.DEFEND_plant2 = MapRoutes.DEFEND_hq2;
	MapRoutes.DEFEND_plant3 = MapRoutes.DEFEND_hq2;
	MapRoutes.DEFEND_plant4 = MapRoutes.DEFEND_hq2;
	MapRoutes.ATTACK_gun1 = MapRoutes.PLANT_German_88;
	MapRoutes.ATTACK_gun2 = MapRoutes.PLANT_German_88;
	MapRoutes.ATTACK_gun3 = MapRoutes.PLANT_German_88;
	MapRoutes.ATTACK_gun4 = MapRoutes.PLANT_German_88;
	MapRoutes.DEFEND_88_1 = MapRoutes.DEFEND_88_2;
	MapRoutes.DEFEND_88_3 = MapRoutes.DEFEND_88_2;
	MapRoutes.DEFEND_88_4 = MapRoutes.DEFEND_88_2;
	MapRoutes.DEFEND_gun1 = MapRoutes.DEFEND_88_2;
	MapRoutes.DEFEND_gun2 = MapRoutes.DEFEND_88_2;
	MapRoutes.DEFEND_gun3 = MapRoutes.DEFEND_88_2;
	MapRoutes.DEFEND_gun4 = MapRoutes.DEFEND_88_2;
	MapRoutes.ATTACK_hq1 = MapRoutes.PLANT_Allied_Field_Communications;
	MapRoutes.ATTACK_hq2 = MapRoutes.PLANT_Allied_Field_Communications;
	MapRoutes.ATTACK_hq3 = MapRoutes.PLANT_Allied_Field_Communications;
	MapRoutes.ATTACK_hq4 = MapRoutes.PLANT_Allied_Field_Communications;
	MapRoutes.CALLARTILLERY_a1 = MapRoutes.PLANT_German_88;
	Util.Routes(MapRoutes);


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

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