//==========================================================================================
//
//	uk-boat_b2.gm
//
//	Who 	When		What
//------------------------------------------------------------------------------------------
//	^1Loffy	18 November 2018	ARTILLERY, ATTACK_gate
//	palota	2 June 2025	script, routes, ladders, ATTACK_boat, DEFEND_boat, MOUNTMG42
//
//==========================================================================================
//

global Map =
{
	Debug = 0,

	vehicle_at_location = function()
	{
		switch(Map.VehicleLocation)
		{
			case 1: // tank at barrier
			{
				SetAvailableMapGoals(TEAM.ALLIES, false, "ESCORT_tank");
				SetGoalPriority("PLANT_Tank_Barrier", 0.95);
				SetGoalPriority("DEFEND_gate.*", 0.5);
				ETUtil.SetStartIndex("BUILD_Tank", 1);
				Util.MapDebugPrint("Tank at barrier");
			}
			case 2: // tank passed barrier
			{
				SetAvailableMapGoals(TEAM.ALLIES, false, {
					"ATTACK.*",
					"CALLARTILLERY_al_art.*",
					"ARTILLERY_S_al_art_.*",
				});
				SetAvailableMapGoals(TEAM.ALLIES, true, {
					"ESCORT_tank",
					"BUILD_Allied_Construction",
					"ATTACK_gate.*",
					"ARTILLERY_S_al_left.*",
					"ARTILLERY_S_al_ramp.*",
					"CALLARTILLERY_al_left.*",
					"CALLARTILLERY_al_ramp.*",
				});

				SetAvailableMapGoals(TEAM.AXIS, true, {
					".*MG42_gate",
				});
				SetGoalPriority("DEFEND_gate.*", 0.55);

				Util.MapDebugPrint("Tank passed barrier");
			}
		}
	},

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

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

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

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

	Main_entrance_destroyed = function()
	{
		if (Map.entrance) { return; }
		Map.entrance = 1;

		Util.DisableGoal(".*", true);
		sleep(1.3);
		Wp.CheckBlockable();

		Util.EnableGoal("MOUNTMG42_boat");

		SetAvailableMapGoals(TEAM.ALLIES, true, {
			"PLANT_Boat",
			"PLANT_Wooden_Barricade",
			"ATTACK_boat.*",
		});
		SetAvailableMapGoals(TEAM.AXIS, true, {
			"BUILD_Wooden_Barricade",
			"DEFEND_boat.*",
			"REPAIRMG42_boat",
		});

		Util.MapDebugPrint("Main_entrance_destroyed");
	},

	Wooden_Barricade_Built = function()
	{
		Util.DisableGoal("ROUTE_wood");
		Util.MapDebugPrint("Wooden_Barricade_Built");
	},

	Wooden_Barricade_Destroyed = function()
	{
		Util.EnableGoal("ROUTE_wood");
		Util.MapDebugPrint("Wooden_Barricade_Destroyed");
	},

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

global OnMapLoad = function()
{
	OnTrigger("The Tank Barrier has been constructed.", Map.Tank_Barrier_Built);
	OnTrigger("The Tank Barrier has been destroyed.", Map.Tank_Barrier_Destroyed);
	OnTrigger("tank_turret_stop", Map.Main_entrance_destroyed);
	OnTrigger("Allied Team have built the Assaultramp!", Map.Allied_Construction_Built);
	OnTrigger("Axis have destroyed the Assaultramp!", Map.Allied_Construction_Destroyed);
	OnTrigger("Axis Team have built the Wooden Barricade!", Map.Wooden_Barricade_Built);
	OnTrigger("Allies have destroyed the Wooden Barricade!", Map.Wooden_Barricade_Destroyed);
	OnTrigger("The Allies have destroyed the U-BOAT!", Map.Boat_Destroyed);

	OnTrigger("tank at location", Map.vehicle_at_location);
	OnTriggerRegion(AABB(-130.308,884.873,1.129,-24.820,1124.079,175.816), RegionTrigger.VehicleTrigger);
	OnTriggerRegion(AABB(249.190,844.704,1.132,419.048,1074.763,109.459), RegionTrigger.VehicleTrigger);

	OnTriggerRegion(AABB(-1470.4,1588.8,-596.2,660.1,3087.4,-322.9), RegionTrigger.DisableCombatMovement); //above boat

	Util.DisableGoal(".*", true);

	SetAvailableMapGoals(TEAM.ALLIES, true, {
		"BUILD_Tank",
		"MOUNT_tank",
		"ESCORT_tank",
		"PLANT_Tank_Barrier",
		"ATTACK_..",
		"CALLARTILLERY_al_art.*",
		"ARTILLERY_S_al_art_.*",
	});

	SetAvailableMapGoals(TEAM.AXIS, true, {
		"BUILD_Tank_Barrier",
		"PLANT_Allied_Construction",
		"DEFEND_barrier.*",
		"DEFEND_gate.*",
	});

	SetGoalPriority("PLANT_Wooden_Barricade", 0.75);
	SetGoalPriority("BUILD_Wooden_Barricade", 0.5);
	SetGoalPriority("PLANT_Allied_Construction", 0.7);
	SetGoalPriority("DEFEND_gate.*", 0.4);
	SetGoalPriority("MOUNTMG42_boat", 0.5);
	SetGoalPriority("DEFUSE_Allied_Construction.*", 0, TEAM.ALLIES, CLASS.ENGINEER, true);

	Util.SetMaxUsers(1, "DEFEND.*");
	Util.SetMaxUsers(1, "MOUNTMG42.*");
	Util.SetMaxUsers(1, "BUILD_Allied_Construction");
	Util.SetMaxUsers(1, "BUILD_Wooden_Barricade");
	Util.SetMaxUsers(1, "PLANT_Allied_Construction");

	Util.AddUsePoint("PLANT_Tank_Barrier", Vec3(100,1109,24));
	Util.AddUsePoint("PLANT_Boat", {Vec3(-1287.5, 3107.8, -731.8), Vec3(-1346.0, 2798.6, -731.8), Vec3(-1407.0, 3158.6, -731.8) });
	Util.AddUsePoint("PLANT_Wooden_Barricade", { Vec3(532,1795,-791), Vec3(380,1783,-791) });

	SetMapGoalProperties("DEFEND.*", {MinCampTime=15, MaxCampTime=30});

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

global InitializeRoutes = function()
{
	MapRoutes =
	{
		PLANT_Tank_Barrier = {
			ROUTE_allied = {
				ROUTE_east = {},
				ROUTE_west = {},
				ROUTE_center = {},
			}
		},
		PLANT_Boat = {
			ROUTE_spawn1 = {
				ROUTE_stairs1 = {Weight=0.5},
				ROUTE_stairs2 = {},
				ROUTE_stairs3 = {},
				ROUTE_stairs4 = {},
				ROUTE_wood = {},
			}
		},
	};
	MapRoutes["ATTACK_gate.*"] = MapRoutes.PLANT_Tank_Barrier;
	MapRoutes["ATTACK_.."] = MapRoutes.PLANT_Tank_Barrier;
	MapRoutes["ATTACK_boat.*"] = MapRoutes.PLANT_Boat;
	Util.Routes(MapRoutes);
};
