//==========================================================================================
//
//	bremen_final.gm
//
//	Who			When		What
//------------------------------------------------------------------------------------------
//	Blindman		2 21 10
//	=F|A=BlackWolf*		15.02.2020	Amended waypoints to support =F|A=Bremen
//	=F|A=BlackWolf*		15.02.2020	Removed camp goal at final barrier due to new wall
//
//==========================================================================================
//

global Map =
{
	Debug = false,

	Checkpoint_flag1_flag = "CHECKPOINT_flag1_flag",
	Flag_keycard_flag = "FLAG_keycard_flag",
	Build_Neutral_Command_Post = "BUILD_Neutral_Command_Post",
	Build_Side_Door = "BUILD_Side_Door",
	Build_Truck = "BUILD_Truck",
	Build_Truck_Barrier_1 = "BUILD_Truck_Barrier_1",
	Build_Truck_Barrier_2 = "BUILD_Truck_Barrier_2",
	Plant_Main_Gate = "PLANT_Main_Gate",
	Plant_Neutral_Command_Post = "PLANT_Neutral_Command_Post",
	Plant_Side_Door = "PLANT_Side_Door",
	Plant_Truck_Barrier_1 = "PLANT_Truck_Barrier_1",
	Plant_Truck_Barrier_2 = "PLANT_Truck_Barrier_2",
	Mover_truck = "MOVER_truck",
	sidedoor_status = 0,
	maindoor_status = 0,
	suicide = true,
	covie = 0,

	TriggerOne =
	{
		Name = "TriggerOne",
		TriggerOnEntity = GetGoal("MOVER_truck").GetEntity(),
		OnEnter = function(ent)
		{
			Util.DisableGroup("axis3", TEAM.AXIS);
			Util.EnableGroup("axis4", TEAM.AXIS);
			Util.DisableGroup("cp");
			Util.DisableGroup("cv", TEAM.AXIS);
			Util.EnableGroup("bar2", TEAM.ALLIES);
			SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Truck_Barrier_1" );
			SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Truck_Barrier_2" );
			Util.MapDebugPrint("TriggerOne");
		},
	},

	TriggerTwo =
	{
		Name = "TriggerTwo",
		TriggerOnEntity = GetGoal("MOVER_truck").GetEntity(),
		OnEnter = function(ent)
		{
			Util.DisableGroup("axis4", TEAM.AXIS);
			Util.EnableGroup("axis5");
			Util.DisableGroup("bar2", TEAM.ALLIES);
			Util.DisableGroup("cv", TEAM.AXIS);
			SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Truck_Barrier_2" );
			Util.MapDebugPrint("TriggerTwo");
		},
	},

	spawntrigger =
	{
		Name = "spawntrigger",
		TriggerOnEntity = GetGoal("MOVER_truck").GetEntity(),
		OnEnter = function(ent)
		{
			Util.ChangeSpawn(TEAM.ALLIES, 2, 9);
			Util.DisableGroup("cv", TEAM.AXIS);
			Util.MapDebugPrint("spawntrigger");
		},
	},

	backspawn =
	{
		Name = "backspawn",
		TriggerOnEntity = GetGoal("MOVER_truck").GetEntity(),
		OnEnter = function(ent)
		{
			Util.ChangeSpawn(TEAM.ALLIES, 1, 9);
			Util.DisableGroup("cv", TEAM.AXIS);
			SetAvailableMapGoals( TEAM.ALLIES, true, "MOBILEMORTAR_backspawn1" );
			Util.MapDebugPrint("backspawn");
		},
	},

	truckmoving =
	{
		Name = "truckmoving",
		TriggerOnEntity = GetGoal("MOVER_truck").GetEntity(),
		OnEnter = function(ent)
		{
			Util.DisableGroup("keydefense", TEAM.AXIS);
			Util.DisableGroup("cv", TEAM.AXIS);
			Util.MapDebugPrint("truckmoving");
		},
	},

	escort =
	{
		Name = "escort",
		TriggerOnEntity = GetGoal("MOVER_truck").GetEntity(),
		OnEnter = function(ent)
		{
			// open up all the offsets
			ETUtil.SetExcludeIndexes("ESCORT_truck");
		},
	},
	covie =
	{
		Name = "covie",
		TriggerOnClass = CLASS.COVERTOPS,
		OnEnter = function(ent)
		{
			if ( GetEntTeam(ent) == TEAM.ALLIES)
			{
				Util.EnableGroup("cv", TEAM.AXIS);
				Util.DisableGroup("axis1", TEAM.AXIS);
				SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT_flag1_flag" );
				Util.ChangeSpawn(TEAM.AXIS, 4, 9);
				Util.MapDebugPrint( "Covie shift" );
			}
		},
	},

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

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

	Truck_Built = function( trigger )
	{
		Util.DisableGroup("axis2", TEAM.AXIS);
		Util.EnableGroup("axis3", TEAM.AXIS);
		Util.DisableGroup("garage", TEAM.ALLIES);
		Util.DisableGroup("cv", TEAM.AXIS);
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Main_Gate" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"BUILD_Truck_Barrier_1",
			"BUILD_Truck_Barrier_2",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, "ESCORT_truck" );
		Map.Truck_Built_FirstTime = true;

		Util.MapDebugPrint( "Truck_Built" );
	},

	Truck_Barrier_1_Built = function( trigger )
	{
		Util.SetPositionGoal( "BUILD_Truck", "MOVER_truck" );
		Util.MapDebugPrint( "Truck_Barrier_1_Built" );
	},

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

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

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

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

	Truck_Barrier_1_Planted = function( trigger )
	{
		Util.DisableGroup("cv", TEAM.AXIS);

		Util.MapDebugPrint( "Truck_Barrier_1_Planted" );
	},

	Truck_Barrier_2_Planted = function( trigger )
	{
		Util.DisableGroup("cv", TEAM.AXIS);

		Util.MapDebugPrint( "Truck_Barrier_2_Planted" );
	},

	Main_Gate_Destroyed = function( trigger )
	{
		Util.EnableGroup("keydefense", TEAM.AXIS );
		Util.DisableGroup("axis1");
		Util.DisableGroup("allies1");
		Util.EnableGroup("allies2", TEAM.ALLIES);
		Util.EnableGroup("cp");
		Util.DisableGroup("cv", TEAM.AXIS);
		SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT_flag1_flag" );
		SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT_flag1_flag" );
		Util.ClearRoleForGoals(Map.Flag_keycard_flag, ROLE.INFILTRATOR);
		Map.maindoor_status = 1;

		Util.MapDebugPrint( "Main_Gate_Destroyed" );
	},

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

	Side_Door_Destroyed = function( trigger )
	{
		Util.EnableGroup("keydefense", TEAM.AXIS );
		Util.DisableGroup("axis1");
		Util.DisableGroup("allies1");
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Main_Gate" );
		Util.EnableGroup("allies2", TEAM.ALLIES);
		Util.EnableGroup("cp");
		Util.SetGoalPosition( -966.9, 1716.4, 88.125, "PLANT_Main_Gate" ) ;
		Util.ClearRoleForGoals(Map.Flag_keycard_flag, ROLE.INFILTRATOR);
		sidedoor_status = 1;

		Util.MapDebugPrint( "Side_Door_Destroyed" );
	},

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

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

	keycard_flag_Taken = function( trigger )
	{
		// check if someone snuck through
		if ( Map.maindoor_status == 0 ) {
			Util.DisableGoal(".*", true); // all but routes
		}

		Util.EnableGroup("allies4", TEAM.ALLIES);
		Util.EnableGroup("keydefense2", TEAM.AXIS);
		Util.DisableGroup("keydefense", TEAM.AXIS);
		Util.DisableGroup("allies2", TEAM.ALLIES);
		Util.DisableGroup("cv", TEAM.AXIS);
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"CAPPOINT_.*",
			"FLAG_.*",
		});

		Util.MapDebugPrint( "keycard_flag_Taken" );
	},

	keycard_flag_Returned = function( trigger )
	{
		// if wall is still intact shift them back to the proper phase
		if ( Map.maindoor_status == 0 ) {
			Util.EnableGroup("keydefense", TEAM.AXIS );
			Util.EnableGroup("axis1");
			Util.EnableGroup("allies1");;
			Util.EnableGroup("cv", TEAM.AXIS);
			SetAvailableMapGoals( TEAM.ALLIES, true, "CHECKPOINT_flag1_flag" );
			SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT_flag1_flag" );
		}
		else {
			Util.EnableGroup("allies2", TEAM.ALLIES);
			Util.EnableGroup("keydefense", TEAM.AXIS);
		}

		Util.DisableGroup("keydefense2", TEAM.AXIS);
		Util.DisableGroup("allies4", TEAM.ALLIES);
		Util.DisableGroup("cv", TEAM.AXIS);

		Util.MapDebugPrint( "keycard_flag_Returned" );
	},

	keycard_flag_Secured = function( trigger )
	{
		Util.DisableGroup("keydefense", TEAM.AXIS );
		Util.DisableGroup("keydefense2", TEAM.AXIS );
		Util.DisableGroup("cv", TEAM.AXIS);
		Util.DisableGroup("allies2", TEAM.ALLIES );
		Util.DisableGroup("allies4", TEAM.ALLIES );
		Util.EnableGroup("allies3", TEAM.ALLIES);
		Util.EnableGroup("garage", TEAM.ALLIES);
		Util.EnableGroup("axis2", TEAM.AXIS);
		Util.DisableGroup("cv", TEAM.AXIS);
		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Truck_Barrier_1" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ATTACK_keypath.*",
			"ATTACK_key11",
			"ATTACK_key12",
			"ATTACK_key13",
			"ATTACK_key14",
		});

		Util.MapDebugPrint( "keycard_flag_Secured" );
	},

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

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

global OnMapLoad = function()
{
	OnTrigger( "Allied Command post constructed. Charge speed increased.", Map.Neutral_Command_Post_Built );
	OnTrigger( "MISSING_STRING", Map.Side_Door_Built );
	OnTrigger( "The Truck has been repaired!", Map.Truck_Built );
	OnTrigger( "Truck Barrier #1 has been constructed.", Map.Truck_Barrier_1_Built );
	OnTrigger( "Truck Barrier #2 has been constructed.", Map.Truck_Barrier_2_Built );
	OnTrigger( "Planted at the Main Gate.", Map.Main_Gate_Planted );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Neutral_Command_Post_Planted );
	OnTrigger( "Planted at the Side Door.", Map.Side_Door_Planted );
	OnTrigger( "Planted at Truck Barrier #1.", Map.Truck_Barrier_1_Planted );
	OnTrigger( "Planted at Truck Barrier #2.", Map.Truck_Barrier_2_Planted );
	OnTrigger( "The main gate has been destroyed!", Map.Main_Gate_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Neutral_Command_Post_Destroyed );
	OnTrigger( "The side door has been destroyed!", Map.Side_Door_Destroyed );
	OnTrigger( "Truck Barrier #1 has been destroyed.", Map.Truck_Barrier_1_Destroyed );
	OnTrigger( "Truck Barrier #2 has been destroyed.", Map.Truck_Barrier_2_Destroyed );
	OnTrigger( "Allies have stolen the Keycard!", Map.keycard_flag_Taken );
	OnTrigger( "Axis have returned the Keycard!", Map.keycard_flag_Returned );
	OnTrigger( "Allied team has gained access to the truck!", Map.keycard_flag_Secured );
	OnTrigger( "MISSING_STRING", Map.flag1_flag_Axis_Captured );
	OnTrigger( "The Allies have captured the forward bunker!", Map.flag1_flag_Allies_Captured );


	cellar = OnTriggerRegion(AABB(966.809,1068.9,56.505,1259.212,1319.8,153.125), Map.TriggerOne);
	storage = OnTriggerRegion(AABB(-1556.64,206.912,63.274,-1031.68,336.874,144.106), Map.TriggerTwo);
	gate = OnTriggerRegion(AABB(-829.24,1622.1,55.125,-494.425,1999.13,138.544), Map.spawntrigger);
	bs = OnTriggerRegion(AABB(-1882.64,-472.875,66.793,-1834.875,9.407,145.242), Map.backspawn);

	cv1 = OnTriggerRegion(AABB(-956.875,1107.2,95.125,-907.818,1264.874,169.125), Map.covie);
//~	cv2 = OnTriggerRegion(AABB(-2342.312,883.321,63.125,-2214.777,1544.874,143.981), Map.covie);
	es = OnTriggerRegion(AABB(2140.201,-539.198,63.125,2427.025,-420.330,137.242),Map.escort);
	t3 = OnTriggerRegion(AABB(-1133.8,1432.8,63.125,-878.6,1694.6,137.125), Map.truckmoving);


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

	// groups
	// cs: these can be removed from script once the goals are saved ...
	Util.SetGroup( "MOBILEMORTAR_spwan1", "allies1");
	Util.SetGroup( "MOBILEMORTAR_spwan2", "allies1");
	Util.SetGroup( "ATTACK_flag.*", "allies1");
	Util.SetGroup( "PLANT_Main_Gate", "allies1");
	Util.SetGroup( "PLANT_Side_Door", "allies1");
	Util.SetGroup( "FLAG_keycard_flag", "allies2");
	Util.SetGroup( "CAPPOINT_.*", "allies2");
	Util.SetGroup( "ATTACK_key.*", "allies2");
	Util.SetGroup( "BUILD_truck", "allies3");
	Util.SetGroup( "PLANT_Truck_Barrier_1", "allies3");
//~	Util.SetGroup( "PLANT_Truck_Barrier_2", "allies3");
	Util.SetGroup( "ATTACK_keypath.*", "allies4");
	Util.SetGroup( "ATTACK_garage.*", "garage");
	Util.SetGroup( "CAMP_tb.*", "bar2");

	Util.SetGroup( "CAMP_key.*", "keydefense");
	Util.SetGroup( "MOBILEMG42_key5", "keydefense");
	Util.SetGroup( "BUILD_Truck_Barrier_1", "keydefense");
	Util.SetGroup( "ATTACK_cappoint.*", "keydefense2");
	Util.SetGroup( "DEFEND_flag.*", "axis1");
	Util.SetGroup( "MOBILEMORTAR_axis", "axis1");
	Util.SetGroup( "CAMP_truck.*", "axis2");
	Util.SetGroup( "BUILD_Truck_Barrier_2", "axis2");
	Util.SetGroup( "CAMP_barrier1_.*", "axis3");
	Util.SetGroup( "CAMP_barrier2_.*", "axis4");
	Util.SetGroup( "CAMP_endgame.*", "axis5");
	Util.SetGroup( "CAMP_covie.*", "cv");
	Util.SetGroup( "MOBILEMG42_covie2", "cv");

	Util.SetGroup( "BUILD_Neutral_Command_Post", "cp");
	Util.SetGroup( "PLANT_Neutral_Command_Post", "cp");

	SetAvailableMapGoals( TEAM.ALLIES, true, "CHECKPOINT_flag1_flag" );
	SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT_flag1_flag" );
	Util.SetRoleForGoals(Map.Flag_keycard_flag, ROLE.INFILTRATOR);
	SetAvailableMapGoals( TEAM.ALLIES, true, Map.Flag_keycard_flag );

	// Max users per goal
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "CAMP_.*" );
	Util.SetMaxUsers( 3, "CHECKPOINT_.*" );
	Util.SetMaxUsers( 1, "PLANT_Side_Door" );
	Util.SetMaxUsers( 3, "FLAG_.*" );
	Util.SetMaxUsers( 3, "ESCORT_.*" );
	//various repositioning
	Util.AddUseWp( "PLANT_Truck_Barrier_2", "plantbarrier2" );
	Util.AddUseWp( "PLANT_Truck_Barrier_1", "plantbarrier1" );
//~	Util.AddUseWp( "PLANT_Side_Door", "sidedoor" );
//~	Util.AddUseWp( "BUILD_Truck", "buildtruck" );
	Util.SetGoalPosition( -1501.867, 1941.1, 264.125, "PLANT_Side_Door" ) ;
	Util.SetPositionGoal( "BUILD_Truck", "MOVER_truck" );

	// only escort from front until it gets around the corner
	ETUtil.SetExcludeIndexes("ESCORT_truck", { 0, 1, 2, 3, 4, 5 });

	Util.EnableGroup("allies1", TEAM.ALLIES);
	Util.EnableGroup("axis1", TEAM.AXIS);


	MapRoutes =
	{
		PLANT_Truck_Barrier_1 =
		{
			ROUTE_cpspawn  =
			{
				ROUTE_cp2  =
				{
					ROUTE_cp3  =
					{
						ROUTE_cp4  =
						{
							ROUTE_cp5  =
							{
								ROUTE_cp6  =
								{
									ROUTE_cp7  =
									{
										ROUTE_cp8  =
										{
										},
									},
								},
							},
							ROUTE_cp4a  =
							{
								ROUTE_cp4b  =
								{
									ROUTE_cp4c  =
									{
										ROUTE_cp8  =
										{
										},
									},
									ROUTE_cp4d  =
									{
									},
								},
							},
						},
					},
					ROUTE_cp4d  =
					{
					},
				},
			},
		},
	};

	MapRoutes.FLAG_keycard_flag = PLANT_Truck_Barrier_1;
	MapRoutes.ATTACK_key12 = PLANT_Truck_Barrier_1;
	MapRoutes.ATTACK_key11 = PLANT_Truck_Barrier_1;
	MapRoutes.ATTACK_key14 = PLANT_Truck_Barrier_1;
	MapRoutes.ATTACK_key13 = PLANT_Truck_Barrier_1;
	Util.Routes(MapRoutes);

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

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