//==========================================================================================
//
//  erdenberg_ga.gm
//
//  Who             When                    What
//------------------------------------------------------------------------------------------
//  Pinn            11 January 2024         Initial Script
//
//==========================================================================================
//

global Map =
{
	Allied_Command_Post_Planted = function()
	{
		Util.MapDebugPrint( "Allied_Command_Post_Planted", true );
	},

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

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

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

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

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

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

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

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

	East_Flak88_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_east.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ATTACK_east.*",
			"PLANT_East_Flak88"
		});

		Util.MapDebugPrint( "East_Flak88_Destroyed" );
	},

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

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

	West_Flak88_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_west.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ATTACK_west.*",
			"PLANT_West_Flak88"
		});

		Util.MapDebugPrint( "West_Flak88_Destroyed" );
	},


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

	Main_Entrance_Defused = function()
	{
		//SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Command_Post" );
		Util.MapDebugPrint( "Main_Entrance_Defused", true );
	},

	Main_Entrance_Destroyed = function()
	{
		sleep( .1 );
		Wp.CheckBlockable();

		Util.DisableGoal( "CHECKPOINT_forward_flag" );
		Util.EnableGoal( { ".*Command_Post", "CHECKPOINT_westflak_flag" } );

		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_main.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ATTACK_main.*",
			"MOUNTMG42_6",
			"REPAIRMG42_6"
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"BUILD_Forward_Door",
			"DEFEND_east.*",
			"DEFEND_west.*",
			"MOUNTMG42_axis_mg",
			"REPAIRMG42_axis_mg"
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"ATTACK_east.*",
			"ATTACK_west.*",
			"PLANT_Forward_Door",
			"PLANT_.*_Flak88"
		});

		SetGoalPriority( "PLANT_.*_Flak88", 1.0, TEAM.ALLIES, CLASS.ENGINEER );

		Util.MapDebugPrint( "Main_Entrance_Destroyed" );
	},

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

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

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Planted at the East Flak88.", Map.East_Flak88_Planted );
	OnTrigger( "Planted at The Main Entrance.", Map.Main_Entrance_Planted );
	OnTrigger( "Planted at the West Flak88.", Map.West_Flak88_Planted );
	OnTrigger( "Planted at the Allied Command Post.", Map.Allied_Command_Post_Planted );
	OnTrigger( "Planted at the Axis Command Post.", Map.Axis_Command_Post_Planted );
	OnTrigger( "Defused at the Allied Command Post.", Map.Allied_Command_Post_Defused );
	OnTrigger( "the Forward Door has been destroyed.", Map.Forward_Door_Destroyed );
	OnTrigger( "Defused at the Axis Command Post.", Map.Axis_Command_Post_Defused );
	OnTrigger( "Defused at the East Flak88.", Map.East_Flak88_Defused );
	OnTrigger( "Defused at the Main Entrance.", Map.Main_Entrance_Defused );
	OnTrigger( "Defused at the West Flak88.", Map.West_Flak88_Defused );
	OnTrigger( "The East Flak88 has been destroyed!", Map.East_Flak88_Destroyed );
	OnTrigger( "Main Gate has been destroyed!", Map.Main_Entrance_Destroyed );
	OnTrigger( "The West Flak88 has been destroyed!", Map.West_Flak88_Destroyed );
	OnTrigger( "The Axis have reclaimed the forward bunker!", Map.forward_flag_Axis_Captured );
	OnTrigger( "The Allies have captured the forward bunker!", Map.forward_flag_Allies_Captured );
	OnTrigger( "The Axis have captured the West Flag", Map.westflak_flag_Axis_Captured );
	OnTrigger( "The Allies have captured the West Flag", Map.westflak_flag_Allies_Captured );

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

	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_main.*" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_main.*" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Main_Entrance" );
	SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT_forward_flag" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "CHECKPOINT_forward_flag" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "MOUNTMG42_6" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "REPAIRMG42_6" );
	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Command_Post" );

	SetGoalPriority( "CHECKPOINT_westflak_flag.*", 1.10, 0, CLASS.ENGINEER );
	SetGoalPriority( "BUILD_Command_Post.*", 0.51, 0, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Forward_Door.*", 0.75, 0, CLASS.COVERTOPS );
	SetGoalPriority( "PLANT_Command_Post.*", 0.75, 0, CLASS.COVERTOPS );
	SetGoalPriority( "BUILD_Forward_Door.*", 1.10, 0, CLASS.ENGINEER );

	// Max users per goal
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 2, "CHECKPOINT.*" );
	Util.SetMaxUsers( 1, "PLANT.*" );
	Util.SetMaxUsers( 1, "BUILD.*" );
	Util.SetMaxUsers( 1, "PLANT_Command_Post" );
	Util.SetMaxUsers( 1, "PLANT_Forward_Door" );
	Util.SetMaxUsers( 1, "BUILD_Forward_Door" );
	Util.SetMaxUsers( 2, "PLANT_Main_Entrance" );
	Util.SetMaxUsers( 1, "CHECKPOINT_westflak_flag" );
	Util.SetMaxUsers( 2, "PLANT_East_Flak88" );
	Util.SetMaxUsers( 2, "PLANT_West_Flak88" );

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

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

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 200.0;
	//default 90 but not breaking things
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		CHECKPOINT_forward_flag =
		{
			ROUTE_alliedSP =
			{
				ROUTE_tunnel =
				{
					ROUTE_tunnelsp =
					{
						ROUTE_tunnelB =
						{
							ROUTE_main_2 =
							{
								ROUTE_main_3 =
								{
									ROUTE_main_4 =
									{
										ROUTE_SPFlag = {},
									},
								},
							},
						},
						ROUTE_tunnelA =
						{
							ROUTE_SPFlag = {},
						},
					},
				},
				ROUTE_main =
				{
					ROUTE_main_1 =
					{
						ROUTE_main_2 =
						{
							ROUTE_main_3 =
							{
								ROUTE_main_4 =
								{
									ROUTE_SPFlag = {},
								},
							},
						},
					},
				},
				ROUTE_ramp =
				{
					ROUTE_ramp_1 =
					{
						ROUTE_ramp_2 =
						{
							ROUTE_ramp_3 =
							{
								ROUTE_ramp_4 =
								{
									ROUTE_SPFlag = {},
								},
							},
						},
					},
				},
			},
		},

		PLANT_Main_Entrance =
		{
			ROUTE_alliedSP =
			{
				ROUTE_tunnel =
				{
					ROUTE_tunnelsp =
					{
						ROUTE_tunnelB =
						{
							ROUTE_main_2 =
							{
								ROUTE_main_3 =
								{
									ROUTE_main_4 = {},
								},
							},
						},
						ROUTE_tunnelA =
						{
							ROUTE_main_4 = {},
						},
					},
				},
				ROUTE_ramp =
				{
					ROUTE_ramp_1 =
					{
						ROUTE_ramp_2 =
						{
							ROUTE_ramp_3 =
							{
								ROUTE_ramp_4 =
								{
									ROUTE_main_4 = {},
								},
							},
						},
					},
				},
				ROUTE_main =
				{
					ROUTE_main_1 =
					{
						ROUTE_main_2 =
						{
							ROUTE_main_3 =
							{
								ROUTE_main_4 = {},
							},
						},
					},
				},
			},
		},

		PLANT_East_Flak88 =
		{
			ROUTE_SPFlag =
			{
				ROUTE_east =
				{
					ROUTE_east_1 =
					{
						ROUTE_east_2 =
						{
							ROUTE_east_3 =
							{
								ROUTE_east_4 =
								{
									ROUTE_east_5 =
									{
										ROUTE_east_6 =
										{
											ROUTE_east_7 =
											{
												ROUTE_eastgun = {},
											},
										},
										ROUTE_westST =
										{
											ROUTE_westST_1 =
											{
												ROUTE_westST_2 =
												{
													ROUTE_eastST_2 =
													{
														ROUTE_eastST_3 =
														{
															ROUTE_eastgun = {},
														},
													},
												},
											},
										},
									},
									ROUTE_east_new_1 =
									{
										ROUTE_east_new_2 =
										{
											ROUTE_east_new_3 =
											{
												ROUTE_eastST_3 =
												{
													ROUTE_eastgun = {},
												},
												ROUTE_east_new_4 =
												{
													ROUTE_east_new_5 =
													{
														ROUTE_east_new_6 =
														{
															ROUTE_east_5 =
															{
																ROUTE_east_6 =
																{
																	ROUTE_east_7 =
																	{
																		ROUTE_eastgun = {},
																	},
																},
															},
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
				ROUTE_west =
				{
					ROUTE_west_1_2 =
					{
						ROUTE_west_1 =
						{
							ROUTE_west_2 =
							{
								ROUTE_west_3 =
								{
									ROUTE_west_4 =
									{
										ROUTE_west_5 =
										{
											ROUTE_westeast =
											{
												ROUTE_eastST =
												{
													ROUTE_eastST_1 =
													{
														ROUTE_eastST_2 =
														{
															ROUTE_eastST_3 =
															{
																ROUTE_eastgun = {},
															},
														},
													},
													ROUTE_westeast_1 =
													{
														ROUTE_westeast_2 =
														{
															ROUTE_eastgun = {},
														},
														ROUTE_eastgun = {},
													},
												},
											},
										},
									},
								},
							},
						 },
					},
				},
				ROUTE_west_2_1 =
				{
					ROUTE_west_2_2 =
					{
						ROUTE_west_2_3 =
						{
							ROUTE_west_4 =
							{
								ROUTE_west_5 =
								{
									ROUTE_westeast =
									{
										ROUTE_eastST =
										{
											ROUTE_eastST_1 =
											{
												ROUTE_eastST_2 =
												{
													ROUTE_eastST_3 =
													{
														ROUTE_eastgun = {},
													},
												},
											},
											ROUTE_westeast_1 =
											{
												ROUTE_westeast_2 =
												{
													ROUTE_eastgun = {},
												},
												ROUTE_eastgun = {},
											},
										},
									},
								},
							},
						},
					},
				},
			},
		},

		PLANT_West_Flak88 =
		{
			ROUTE_SPFlag =
			{
				ROUTE_east =
				{
					ROUTE_eastHO =
					{
						ROUTE_eastHO_1 =
						{
							ROUTE_eastHO_2 =
							{
								ROUTE_eastHO_3 =
								{
									ROUTE_westgun = {},
								},
							},
						},
					},
				},
				ROUTE_west =
				{
					ROUTE_west_1_2 =
					{
						ROUTE_west_1 =
						{
							ROUTE_west_2 =
							{
								ROUTE_west_3 =
								{
									ROUTE_west_4 =
									{
										ROUTE_westgun = {},
										ROUTE_west_5 =
										{
											ROUTE_eastHO_3 =
											{
												ROUTE_westgun = {},
											}  ,
										},
									},
								},
							},
						},
						ROUTE_west_2_1 =
						{
							ROUTE_west_2_2 =
							{
								ROUTE_west_2_3 =
								{
									ROUTE_west_4 =
									{
										ROUTE_westgun = {},
										ROUTE_west_5 =
										{
											ROUTE_eastHO_3 =
											{
												ROUTE_westgun = {},
											} ,
										},
									},
								},
							},
						},
					},
				},
			},
		},

		PLANT_Forward_Door =
		{
			ROUTE_west =
			{
				ROUTE_west_1_2 =
				{
					ROUTE_west_2_2 = {}
				},
			},
		},

		BUILD_Forward_Door =
		{
			ROUTE_west =
			{
				ROUTE_west_1_2 =
				{
					ROUTE_west_2_2 = {}
				},
			},
			ROUTE_AxisSP =
			{
				ROUTE_west_2_3 =
				{
					ROUTE_west_2_2 = {}
				},
			},
		},

		PLANT_East_Flak88 =
		{
			ROUTE_AxisSP =
			{
				ROUTE_AxisA =
				{
					ROUTE_westgun = {},
				},
				ROUTE_AxisB =
				{
					ROUTE_westgun = {},
				},
				ROUTE_AxisC =
				{
					ROUTE_westgun = {},
				},
			},
		},

		PLANT_West_Flak88 =
		{
			ROUTE_AxisSP =
			{
				ROUTE_AxisA =
				{
					ROUTE_westgun = {},
				},
				ROUTE_AxisB =
				{
					ROUTE_westgun = {},
				},
				ROUTE_AxisC =
				{
					ROUTE_westgun = {},
				},
			},
		},
	};

	// Copy some routes
	MapRoutes.DEFEND_main   = MapRoutes.CHECKPOINT_forward_flag;
	MapRoutes.DEFEND_main_1 = MapRoutes.CHECKPOINT_forward_flag;
	MapRoutes.DEFEND_main_2 = MapRoutes.CHECKPOINT_forward_flag;
	MapRoutes.DEFEND_main_3 = MapRoutes.CHECKPOINT_forward_flag;
	MapRoutes.DEFEND_main_4 = MapRoutes.CHECKPOINT_forward_flag;
	MapRoutes.DEFEND_main_5 = MapRoutes.CHECKPOINT_forward_flag;

	MapRoutes.DEFEND_west   = MapRoutes.PLANT_West_Flak88;
	MapRoutes.DEFEND_west_1 = MapRoutes.PLANT_West_Flak88;
	MapRoutes.DEFEND_west_2 = MapRoutes.PLANT_West_Flak88;
	MapRoutes.DEFEND_west_3 = MapRoutes.PLANT_West_Flak88;
	MapRoutes.DEFEND_west_4 = MapRoutes.PLANT_West_Flak88;
	MapRoutes.DEFEND_west_5 = MapRoutes.PLANT_West_Flak88;
	MapRoutes.DEFEND_west_6 = MapRoutes.PLANT_West_Flak88;

	MapRoutes.DEFEND_east   = MapRoutes.PLANT_East_Flak88;
	MapRoutes.DEFEND_east_1 = MapRoutes.PLANT_East_Flak88;
	MapRoutes.DEFEND_east_2 = MapRoutes.PLANT_East_Flak88;
	MapRoutes.DEFEND_east_3 = MapRoutes.PLANT_East_Flak88;
	MapRoutes.DEFEND_east_4 = MapRoutes.PLANT_East_Flak88;

	MapRoutes.ATTACK_main   = MapRoutes.CHECKPOINT_forward_flag;
	MapRoutes.ATTACK_main_1 = MapRoutes.CHECKPOINT_forward_flag;
	MapRoutes.ATTACK_main_2 = MapRoutes.CHECKPOINT_forward_flag;
	MapRoutes.ATTACK_main_3 = MapRoutes.CHECKPOINT_forward_flag;
	MapRoutes.ATTACK_main_4 = MapRoutes.CHECKPOINT_forward_flag;

	MapRoutes.ATTACK_west   = MapRoutes.PLANT_West_Flak88;
	MapRoutes.ATTACK_west_1 = MapRoutes.PLANT_West_Flak88;
	MapRoutes.ATTACK_west_2 = MapRoutes.PLANT_West_Flak88;
	MapRoutes.ATTACK_west_3 = MapRoutes.PLANT_West_Flak88;
	MapRoutes.ATTACK_west_4 = MapRoutes.PLANT_West_Flak88;
	MapRoutes.ATTACK_west_5 = MapRoutes.PLANT_West_Flak88;

	MapRoutes.ATTACK_east   = MapRoutes.PLANT_East_Flak88;
	MapRoutes.ATTACK_east_1 = MapRoutes.PLANT_East_Flak88;
	MapRoutes.ATTACK_east_2 = MapRoutes.PLANT_East_Flak88;
	MapRoutes.ATTACK_east_3 = MapRoutes.PLANT_East_Flak88;
	MapRoutes.ATTACK_east_4 = MapRoutes.PLANT_East_Flak88;
	MapRoutes.ATTACK_east_5 = MapRoutes.PLANT_East_Flak88;

	Util.Routes( MapRoutes );
};
