// No defend or route goals on waypoints but added into the script

global Map =
{
	Debug = 1,
	DefendingTeam = TEAM.ALLIES,
	ElevatorPos = "bottom",
	Main_Doors_Blown = 0,


	Tank_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Tank" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"ESCORT_Tank",
			"MOUNT_Tank",
		});
		SetAvailableMapGoals( TEAM.AXIS, 1, {
			"MOUNT_Tank",
		});
		Util.MapDebugPrint( "Tank_Built" );
	},
	Tank_Damaged = function( trigger )
	{
		if (!Map.Main_Doors_Blown)
		{
			SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Tank" );
			SetAvailableMapGoals( TEAM.ALLIES, 0, "ESCORT_Tank" );
		}
		Util.MapDebugPrint( "Tank_Damaged" );
	},

	Bridge_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Bridge" );
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Bridge" );
		Util.MapDebugPrint( "thebridge_Built" );
	},
	Bridge_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Bridge" );
		Util.MapDebugPrint( "Bridge_Planted" );
	},
	Bridge_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Bridge" );
		Util.MapDebugPrint( "Bridge_Destroyed" );
	},
	Bridge_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Bridge" );
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Bridge" );
		Util.MapDebugPrint( "Bridge_Destroyed" );
	},

	Generator_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 0, "BUILD_generator" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_generator" );
		Util.MapDebugPrint( "Generator_Built" );
	},
	Generator_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_generator" );
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_generator" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Gun_Controls" );
		Util.MapDebugPrint( "Generator_Destroyed" );
	},

	side_entrance_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_side_entrance" );
		Util.MapDebugPrint( "side_entrance_Planted" );
	},
	side_entrance_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_side_entrance" );
		Util.MapDebugPrint( "side_entrance_Defused" );
	},
	side_entrance_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_side_entrance" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_generator" );
		Util.MapDebugPrint( "side_entrance_Destroyed" );
	},

	Main_Doors_Destroyed = function( trigger )
	{
		Map.Main_Doors_Blown = 1;
		sleep(2);
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_generator" );
		SetAvailableMapGoals( TEAM.ALLIES, 0, {
			"BUILD_Tank",
			"MOUNT_Tank",
			"ESCORT_Tank",
			"CAMP_Main_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, 0, {
			"MOUNT_Tank",
			"CAMP_Main_.*",
			"CAMP_r1_.*",
		});
		SetAvailableMapGoals( 0, 1, "CAMP_Gun_.*" );
		Util.MapDebugPrint( "Main_Doors_Destroyed" );
	},


	//end game
	Gun_Controls_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Gun_Controls_Destroyed" );
	},


	// Neutral Command Post
	CP_Owner = 0,
	CP_Dyno = 0,

	Set_CP = function(_p) // p = TEAM.ALLIES or TEAM.AXIS or 0 (unbuilt)
	{
		switch(_p)
		{
			case 0:
			{
				Map.CP_Owner = 0;
				SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Command_Post" );
			}
			case TEAM.ALLIES:
			{
				Map.CP_Owner = TEAM.ALLIES;
				SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "BUILD_Command_Post" );
			}
			case TEAM.AXIS:
			{
				Map.CP_Owner = TEAM.AXIS;
				SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "BUILD_Command_Post" );
			}
		}
		//Util.MapDebugPrint("CP Owner: " + Map.CP_Owner );
	},
	Allied_CP_Built = function( trigger )
	{
		Map.Set_CP(TEAM.ALLIES);

		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Bridge" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"PLANT_generator",
			"PLANT_Gun_Controls",
			"PLANT_side_entrance",
		});

		SetAvailableMapGoals( 0, 1, "CAMP_Gun_.*" );

		Util.EnableGoal(".*CAB.*");

		Util.MapDebugPrint( "Allied_CP_Built" );
	},
	Allied_CP_Destroyed = function( trigger )
	{
		Map.CP_Dyno = 0;
		Map.Set_CP(0);
		Util.MapDebugPrint( "Allied_CP_Destroyed" );
	},
	Axis_CP_Built = function( trigger )
	{
		Map.Set_CP(TEAM.AXIS);
		Util.MapDebugPrint( "Axis_CP_Built" );
	},
	Axis_CP_Destroyed = function( trigger )
	{
		Map.CP_Dyno = 0;
		Map.Set_CP(0);
		Util.MapDebugPrint( "Axis_CP_Destroyed" );
	},
	CP_Planted = function( trigger )
	{
		Map.CP_Dyno += 1;
		Util.MapDebugPrint( "CP_Planted" );
	},
	CP_Defused = function( trigger )
	{
		Map.CP_Dyno -= 1;
		Util.MapDebugPrint( "CP_Defused" );
	},

	vehicle_at_location = function( trigger )
	{
		switch(Map.VehicleLocation)
		{
			case 1: // tank over bridge
			{
				SetAvailableMapGoals( TEAM.ALLIES, 0, "CAMP_b1_.*" );
				SetAvailableMapGoals( TEAM.ALLIES, 1, "CAMP_Main_.*" );
			}
		}
		Util.MapDebugPrint("vehicle at location " + Map.VehicleLocation, true);
	},

};

global OnMapLoad = function()
{
	//Register callbacks

	OnTrigger( "The Tank has been repaired!", Map.Tank_Built );
	OnTrigger( "The Tank has been damaged!", Map.Tank_Damaged );

	OnTrigger( "Allied team has reinforced the Bridge!", Map.Bridge_Built );
	OnTrigger( "Planted at the Bridge.", Map.Bridge_Planted );
	OnTrigger( "Defused at the Bridge.", Map.Bridge_Defused );
	OnTrigger( "Axis team has destroyed the Bridge!", Map.Bridge_Destroyed );

	OnTrigger( "Axis have constructed the Door Controls Generator!", Map.Generator_Built );
	OnTrigger( "Allies have destroyed the Door Controls Generator!", Map.Generator_Destroyed );

	OnTrigger( "Allied team has destroyed the Bunker Doors!", Map.Main_Doors_Destroyed );

	OnTrigger( "Planted at the side entrance.", Map.side_entrance_Planted );
	OnTrigger( "Defused at the side entrance.", Map.side_entrance_Defused );
	OnTrigger( "Allies have breached the side entrance!", Map.side_entrance_Destroyed );

	OnTrigger( "Allied team has destroyed the Gun Controls!", Map.Gun_Controls_Destroyed );

	OnTrigger( "Allied Command Post constructed. Charge speed increased!",  Map.Allied_CP_Built );
	OnTrigger( "Axis team has destroyed the Allied Command Post!",          Map.Allied_CP_Destroyed );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!",    Map.Axis_CP_Built );
	OnTrigger( "Allied team has destroyed the Axis Command Post!",          Map.Axis_CP_Destroyed );
	OnTrigger( "Planted at the Command Post.",                              Map.CP_Planted  );
	OnTrigger( "Defused at the Command Post.",                              Map.CP_Defused  );

	OnTrigger( "tank at location", Map.vehicle_at_location );
	triggerbridge = OnTriggerRegion(AABB(-1174.109,-25.200,-68.074,-902.509,151.414,16.193), RegionTrigger.VehicleTrigger);

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

	//Util.EnableGoal(".*CAB.*");
	//Util.SetCabinets(); wait until cp built

	Util.AddUsePoint( "PLANT_side_entrance", Vec3(78,1291,-517) );
	Util.SetGoalOffset( 0, 0, 150, "PLANT_Bridge" );
	Util.LimitToClass("PLANT_Command_Post", 0, 5);
	Util.LimitToClass("PLANT_generator", 2, 5);

	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		"CAMP_b1_.*",
		"BUILD_Tank",
		"ESCORT_Tank",
		"BUILD_Bridge",
	});

	SetAvailableMapGoals( TEAM.AXIS, 1, {
		"CAMP_r1_.*",
		"BUILD_Command_Post",
	});

	SetGoalPriority( "BUILD_Tank", 0.92 );

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

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


global OnBotJoin = function( bot )
{
	// Uncomment for shootable breakables
	bot.TargetBreakableDist = 100.0;

	// Only set MaxViewDistance on maps with limited sight (e.g. fog)
	//~bot.MaxViewDistance = 2400;

};

global InitializeRoutes = function()
{
	print("Configuring Routes");

	MapRoutes =
	{

		PLANT_generator = {},
		PLANT_side_Entrance = {},

		BUILD_Command_Post =
		{
			ROUTE_Tank_Start =
			{
				ROUTE_Cave_Path_1 =
				{
					ROUTE_CP_X = {},
				},
			},
		},

		PLANT_Gun_Controls =
		{
			ROUTE_AlSpawn =
			{
				ROUTE_Bridge_1 =
				{
					ROUTE_Main_Doors =
					{
						ROUTE_Gun_X = {},
					},
				},
			},
		},
	};

/*
		BUILD_Command_Post =
		{
		},
		PLANT_Command_Post =
		{
		},
		BUILD_Tank =
		{
		},
		PLANT_Gun_Controls =
		{
		},
		BUILD_generator =
		{
		},
		PLANT_generator =
		{
		},
		PLANT_side_entrance =
		{
		},
		BUILD_Bridge =
		{
		},
		PLANT_Bridge =
		{
		},
		PLANT_Gun_Controls_1 =
		{
		},
		PLANT_Gun_Controls_2 =
		{
		},
*/
	Util.Routes(MapRoutes);

};
