//==========================================================================================
//
//	secrets.gm
//
//	Who                  	When		What
//------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com	04 December 2017	Initial Script
//	palota	13 July 2025
//==========================================================================================
//

global Map =
{
	//Obj states 1 = intact/built
	side_entrance_of_the_mine = 1,
	Tower_Entrance = 1,
	Tower_Gate = 0,
	Underground_Defense = 0,

	Navigation =
	{
		rope = {
			navigate = function()
			{
				this.AddAimRequest(Priority.High, "facing", Vec3(0, 0.422, 0.906));
				for(i=0; i<30; ++i)
				{
					pos = this.Bot.GetPosition();
					if(Abs(pos.x - 2500) > 60 || Abs(pos.y + 1150 ) > 60){ break; }
					sleep(0.5);
				}
			}
		},
	},

	Allied_Front_Gate_Destroyed = function()
	{
		Wp.CheckBlockable();
		SetAvailableMapGoals(TEAM.AXIS, 1, "PLANT_Forward_Gate");
		Util.MapDebugPrint("Allied_Front_Gate_Destroyed");
	},

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

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

	Sneek_Ramp_Built = function()
	{
		Util.EnableGoal("ROUTE_Sneek_Ramp");
		Util.MapDebugPrint("Sneek_Ramp_Built");
	},
	Sneek_Ramp_Destroyed = function()
	{
		Util.DisableGoal("ROUTE_Sneek_Ramp");
		Util.MapDebugPrint("Sneek_Ramp_Destroyed");
	},

	//Axis access door to Allies tower. Not rebuildable.
	Tower_Entrance_Destroyed = function()
	{
		Map.Tower_Entrance = 0;
		Wp.CheckBlockable();
		SetAvailableMapGoals(TEAM.ALLIES, 1, {
			".*mg42_bank",
		});
		SetAvailableMapGoals(TEAM.AXIS, 1, "PLANT_Tower_Gate");
		if (!Map.Tower_Gate){
			SetAvailableMapGoals(TEAM.AXIS, 1, "FLAG_documents");
		}
		Util.SetMaxUsersInProgress(4, "FLAG_documents");
		Util.MapDebugPrint("Tower_Entrance_Destroyed");
	},

	Tower_Gate_Built = function()
	{
		Map.Tower_Gate = 1;
		Util.MapDebugPrint("Tower_Gate_Built");
	},
	Tower_Gate_Destroyed = function()
	{
		Map.Tower_Gate = 0;
		Wp.CheckBlockable();
		SetAvailableMapGoals(TEAM.AXIS, 1, "FLAG_documents");
		Util.MapDebugPrint("Tower_Gate_Destroyed");
	},

	Underground_Defense_Built = function()
	{
		Map.Underground_Defense = 1;
		Util.DisableGoal("ROUTE_defense");
		Util.MapDebugPrint("Underground_Defense_Built");
	},
	Underground_Defense_Destroyed = function()
	{
		Map.Underground_Defense = 0;
		Wp.CheckBlockable();
		Util.EnableGoal("ROUTE_defense");
		SetAvailableMapGoals(TEAM.AXIS, 1, "FLAG_documents");
		Util.MapDebugPrint("Underground_Defense_Destroyed");
	},

	side_entrance_of_the_mine_Destroyed = function()
	{
		Map.side_entrance_of_the_mine = 0;
		Wp.CheckBlockable();
		SetAvailableMapGoals(TEAM.AXIS, 1, "PLANT_Underground_Defense");
		Util.MapDebugPrint("side_entrance_of_the_mine_Destroyed");
	},

	documents_Taken = function()
	{
		SetAvailableMapGoals(TEAM.AXIS, 1, {
			"BUILD_Sneek_Ramp",
			"BUILD_Radio_Tower_Raft",
		});
		Util.MapDebugPrint("documents_Taken");
	},
	documents_Returned = function()
	{
		Util.MapDebugPrint("documents_Returned");
	},
	documents_Secured = function()
	{
		ETUtil.WinningChat(TEAM.AXIS);
		ETUtil.LosingChat(TEAM.ALLIES);
		Util.MapDebugPrint("documents_Secured");
	},

	forward_spawn_Axis_Captured = function()
	{
		SetAvailableMapGoals(TEAM.AXIS, 1, {
			"PLANT_Tower_Entrance",
			"PLANT_Allied_Front_Gate",
		}, true);
		Util.MapDebugPrint("forward_spawn_Axis_Captured");
	},

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

};

global OnMapLoad = function()
{
	OnTrigger("Axis have blown up the Allied Front Gate", Map.Allied_Front_Gate_Destroyed);
	OnTrigger("Allied team has built the Forward Gate!", Map.Forward_Gate_Built);
	OnTrigger("Axis team has destroyed the Forward Gate!", Map.Forward_Gate_Destroyed);

	OnTrigger("Axis team has built the Radio Tower Ramp!", Map.Radio_Tower_Raft_Built);
	OnTrigger("Allied team has destroyed the Radio Tower Ramp!", Map.Radio_Tower_Raft_Destroyed);

	OnTrigger("Axis team has built the Sneek Ramp!", Map.Sneek_Ramp_Built);
	OnTrigger("Allied team has destroyed the Sneek Ramp!", Map.Sneek_Ramp_Destroyed);

	OnTrigger("Allied team has built the Tower Security Gate!", Map.Tower_Gate_Built);
	OnTrigger("Allied team has destroyed the Tower Security Gate!", Map.Tower_Gate_Destroyed);

	OnTrigger("Allied team has built an Underground Defense!", Map.Underground_Defense_Built);
	OnTrigger("Axis team has destroyed the Allies Underground Defense!", Map.Underground_Defense_Destroyed);

	OnTrigger("Axis have blown up the tower gate", Map.Tower_Entrance_Destroyed);

	OnTrigger("Axis have blown up the side mine gate", Map.side_entrance_of_the_mine_Destroyed);

	OnTrigger("Axis have stolen the precious documents!!", Map.documents_Taken);
	OnTrigger("Flag returned documents!", Map.documents_Returned);
	OnTrigger("Axis have transmitted the precious documents at the Radio Room!", Map.documents_Secured);

	OnTrigger("Axis capture the forward bunker!", Map.forward_spawn_Axis_Captured);
	OnTrigger("axis_capture_forward_spawn", Map.forward_spawn_Axis_Captured);
	OnTrigger("Allies capture the forward bunker!", Map.forward_spawn_Allies_Captured);

	OnTriggerRegion(AABB(2976.774,-4408.714,-3169.875,3641.111,-3417.645,-2643.005), RegionTrigger.DisableCombatMovement); //sneak ramp
	OnTriggerRegion(AABB(2952.755,-3155.381,-3350.875,3964.630,-2344.585,-3128.002), RegionTrigger.DisableCombatMovement); //barbed wires

	Util.DisableGoal(".*", true);
	Util.DisableGoal("ROUTE_Sneek_Ramp");
	Util.EnableGoal({
		"CHECKPOINT_.*",
		"AMMO.*",
		"HEALTH.*",
	});

	//Allies
	SetAvailableMapGoals(TEAM.ALLIES, 1, {
		"DEFEND_flag.*",
		"BUILD_Tower_Gate",
		"BUILD_Underground_Defense",
		"BUILD_Forward_Gate",
		"PLANT_Radio_Tower_Raft",
		"PLANT_Sneek_Ramp",
		".*_mg42_bridge.*",
		"PLANTMINE_.*",
		"SNIPE_Flag.*",
	});

	//Axis
	SetAvailableMapGoals(TEAM.AXIS, 1, {
		"ATTACK_.*",
		"PLANT_side_entrance_of_the_mine",
		"CAPPOINT.*",
		".*MG42_ship",
		"GRENADE_wood",
	});
	// wait until docs taken BUILD_Sneek_Ramp

	SetGoalPriority("MOUNTMG42_mg42_bridge.*", 0.5);
	SetGoalPriority("BUILD_Forward_Gate", 0.81);
	SetGoalPriority("BUILD_Radio_Tower_Raft", 0.81);
	SetGoalPriority("GRENADE_wood", 0.9);
	SetGoalPriority("DEFUSE_side_entrance.*", 0, 0, 0, true);
	SetGoalPriority("DEFUSE_Underground.*", 0, 0, 0, true);
	SetGoalPriority("DEFUSE_Radio.*", 0, 0, 0, true);

	Util.AddUsePoint("PLANT_Forward_Gate", {Vec3(5057, -986, -3327), Vec3(4875, -977, -3327)});
	Util.AddUsePoint("PLANT_Underground_Defense", {Vec3(2331,-2102,-4297), Vec3(2326, -1926, -4297)});

	Util.SetMaxUsers(1, {
		"MOUNTMG42.*",
		"BUILD.*",
		"PLANT.*",
	});
	Util.SetMaxUsersInProgress(2, "FLAG_documents");

	Util.MapDebugPrint("Omni-bot map script for " + GetMapName() + " by maker@bigsighstudios.com.");
};

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

global InitializeRoutes = function()
{
	MapRoutes =
	{
		CHECKPOINT_forward_spawn = {
			ROUTE_AxSp = {
				ROUTE_flag1 = {},
				ROUTE_flag2 = {Weight=3},
			}
		},
		CAPPOINT_Docs = {
			ROUTE_doc = {
				ROUTE_north_east = {},
				ROUTE_ship = { ROUTE_axis = {}},
				ROUTE_defense = { Weight=2,
					ROUTE_axis = {
						ROUTE_Sneek_Ramp = {Weight=9},
						ROUTE_south_east = {}
					}
				},
			}
		},
	};
	Util.Routes(MapRoutes);
};
