//==========================================================================================
//
//	mummies_lab_beta1.gm
//
//	Who               	When		What
//------------------------------------------------------------------------------------------
//	LightRay@ets-clan.com	04 March 2022	Initial Script
//
//==========================================================================================
//

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

	First_Tank_Build = 0,

	Tank_Built = function( trigger )
	{
		Util.DisableGoal( "CAMP_WAIT_.*" );

		SetAvailableMapGoals( 0, 1, "ESCORT_Tank" );
		SetAvailableMapGoals( 0, 1, "MOUNT_Tank" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "CAMP_ATTACK_S1_.*" );

		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Guard_Tower" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANTMINE_ALLIES_Cave_1" );

		if (Map.First_Tank_Build == 0) {
			Map.First_Tank_Build = 1;
			SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Foot_Bridge" );
		};

		Util.MapDebugPrint( "Tank_Built" );
	},

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

	Foot_Bridge_Built = function( trigger )
	{

		Util.MapDebugPrint( "Foot_Bridge_Built" );
	},

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

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

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

	Axis_MG42_Construction_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Cave_Barrier" );

		Util.MapDebugPrint( "Axis_MG42_Construction_Built" );
	},

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

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

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

	Guard_Tower_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Allied_MG42_Construction" );

		Util.MapDebugPrint( "Guard_Tower_Built" );
	},

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

	Bank_Doors_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Tank", true );

		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"BUILD_Command_Post",
			"MOUNT_Tank",
			"PLANT_Axis_Supply_Room",
			"PLANT_Genesis_Machine",
			"PLANT_Weak_Wall"
		});

		SetAvailableMapGoals( TEAM.ALLIES, 0, {
			"BUILD_Allied_MG42_Construction",
			"BUILD_Foot_Bridge",
			"BUILD_Guard_Tower"
		});

		SetAvailableMapGoals( TEAM.AXIS, 0, "CAMP_DEFEND_S1_.*" );

		Util.MapDebugPrint( "Bank_Doors_Destroyed" );
	},

	Axis_Supply_Room_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Weak_Wall" );

		Util.MapDebugPrint( "Axis_Supply_Room_Destroyed" );
	},

	Weak_Wall_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Genesis_Machine" );

		Util.MapDebugPrint( "Weak_Wall_Destroyed" );
	},

	Genesis_Machine_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Genesis_Machine_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, 0, "BUILD_Command_Post");
				SetAvailableMapGoals(TEAM.AXIS, 1, "PLANT_Command_Post");
			}
			case TEAM.AXIS: {
				Map.CP_Owner = TEAM.AXIS;
				SetAvailableMapGoals(TEAM.AXIS, 0, "BUILD_Command_Post");
				SetAvailableMapGoals(TEAM.AXIS, 0, "PLANT_Command_Post");
				SetAvailableMapGoals(TEAM.ALLIES, 0, "BUILD_Command_Post");
				SetAvailableMapGoals(TEAM.ALLIES, 1, "PLANT_Command_Post");
			}
		}
		Util.MapDebugPrint("CP Owner: " + Map.CP_Owner );
	},
	Allied_CP_Built = function (trigger) {
		Map.Set_CP(TEAM.ALLIES);
		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");
	},

	STAGE1 = function ( trigger ) {
		SetAvailableMapGoals( TEAM.AXIS, 0, "CAMP_DEFEND_S1_.*" );
		SetAvailableMapGoals( TEAM.AXIS, 0, "MOBILEMG42_CAVE_.*" );
	},

	tank_at_location = function( trigger )
	{
		switch(Map.VehicleLocation)
		{
			case 1: // Tank at E3 tunnel entrance
			{
				Map.STAGE1();
			}
		}

		Util.MapDebugPrint("vehicle at location " + Map.VehicleLocation, true);
	},

};

global OnMapLoad = function () {
	// Register callback functions
	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( "The Tank has been repaired!", Map.Tank_Built );
	OnTrigger( "The Tank has been damaged!", Map.Tank_Damaged );

	OnTrigger( "Allied Team have built the MG42 nest!!", Map.Allied_MG42_Construction_Built );
	OnTrigger( "Axis have destroyed the MG42 Nest!!", Map.Allied_MG42_Construction_Destroyed );

	OnTrigger( "Axis Team have built the MG42 nest!!", Map.Axis_MG42_Construction_Built );
	OnTrigger( "Allies have destroyed the MG42 Nest!!", Map.Axis_MG42_Construction_Destroyed );

	OnTrigger( "Axis team has constructed the Cave Barrier!", Map.Cave_Barrier_Built );
	OnTrigger( "Allied team has destroyed the cave barrier!", Map.Cave_Barrier_Destroyed );

	OnTrigger( "The Allied team has constructed the Foot Bridge!", Map.Foot_Bridge_Built );
	OnTrigger( "The axis team has destroyed the foot bridge!", Map.Foot_Bridge_Destroyed );

	OnTrigger( "Allied team has constructed the Guard Tower!", Map.Guard_Tower_Built );
	OnTrigger( "Axis team has destroyed the Guard Tower!", Map.Guard_Tower_Destroyed );

	OnTrigger( "Allied team has destroyed the Bank Doors!", Map.Bank_Doors_Destroyed );
	OnTrigger( "The Allies have lessened the Axis supply stock!  Axis Respawn time increased by +5 seconds!", Map.Axis_Supply_Room_Destroyed );

	OnTrigger( "The Allies have destroyed the weak wall!", Map.Weak_Wall_Destroyed );

	OnTrigger( "The Allied team has disabled the Genesis Device!", Map.Genesis_Machine_Destroyed );

	TruckPath1	= OnTriggerRegion(AABB(714.000,737.008,5.792,890.066,1063.563,101.438),	RegionTrigger.VehicleTrigger);
	OnTrigger( "tank at location", Map.tank_at_location );

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

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"CAMP_DEFEND_S1_.*",
		"BUILD_Axis_MG42_Construction",
		"MOBILEMG42_CAVE_.*"
	});

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"CAMP_WAIT_.*",
		"BUILD_Tank"
	});

	Util.ExcludeClass("MOUNTMG42_.*", 0, CLASS.ENGINEER);
	Util.ExcludeClass("MOUNT_Tank", 0, CLASS.ENGINEER);
	Util.ExcludeClass("ESCORT_.*", 0, CLASS.MEDIC, CLASS.ENGINEER);

	Util.LimitToClass("PLANT_Command_Post", 0, CLASS.COVERTOPS);
	Util.LimitToClass("BUILD_Tank", TEAM.ALLIES, CLASS.ENGINEER);

	SetGoalPriority( "BUILD_Tank", 0.95 );
	SetGoalPriority( "MOUNTMG42_.*", 0.0, 0, CLASS.ENGINEER, true );

	// Max users per goal
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 2, "MOBILEMG42_.*" );

	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=300, MaxCampTime=999} );
	SetMapGoalProperties( "CAMP_.*", {MinCampTime=300, MaxCampTime=999} );

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

global OnBotJoin = function( bot )
{
	// Uncomment for shootable breakables
	bot.TargetBreakableDist = 90.0;
	//Only set MaxViewDistance on maps with limited sight (e.g. fog)
	//bot.MaxViewDistance = 2400;
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		PLANT_Weak_Wall =
		{
		},
		PLANT_Genesis_Machine =
		{
		},
		BUILD_Command_Post =
		{
		},
		PLANT_Command_Post =
		{
		},
		BUILD_Guard_Tower =
		{
		},
		PLANT_Guard_Tower =
		{
		},
		BUILD_Cave_Barrier =
		{
		},
		PLANT_Cave_Barrier =
		{
		},
		BUILD_Foot_Bridge =
		{
		},
		PLANT_Foot_Bridge =
		{
		},
		BUILD_Tank =
		{
		},
		PLANT_Axis_Supply_Room =
		{
		},
		BUILD_Allied_MG42_Construction =
		{
		},
		PLANT_Allied_MG42_Construction =
		{
		},
		BUILD_Axis_MG42_Construction =
		{
		},
		PLANT_Axis_MG42_Construction =
		{
		},
	};
	Util.Routes(MapRoutes);
};
