global Map =
{
	Switches =
	{
		TrackSwitch =
		{
			AimPosition = Vector3(2454,1105,946),
			Enabled = false,
			Priority = 0.8,
			WaypointName = "trackswitch",
			LimitTeam = (1<<TEAM.AXIS),
			LimitClass = Util.AllClasses,
			ExitConditions =
			{
				immediate = function()
				{
					// Map.Switches.TrackSwitch.Enabled = false;
					return true;
				},
			},
		},
	},

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

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

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

	Tank_Destroyed = function( trigger )
	{
		Util.SetPositionGoal( "BUILD_Tank", "MOVER_tank" );
		Util.MapDebugPrint( "Tank_Destroyed" );
	},

	TankAtFirstCorner = function( trigger )
	{
		Util.SetMaxUsersInProgress( 2, "BUILD_Tank_Barrier_1" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"DEFEND_.*",
			"MOBILEMG42_.*",
			"ATTACK_.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"SNIPE_allies_phase2.*",
			"DEFEND_allies_phase2.*",
			"MOBILEMG42_allies_phase2.*",
		});
		Util.MapDebugPrint( "TankAtFirstCorner" );
	},

	Tank_Barrier_1_Built = function( trigger )
	{
		// Reposition plant goal
		rand = RandInt(1,4);
		if ( rand == 1 )
		{
			Util.SetGoalPosition( -630, -1400, 950, "PLANT_Tank_Barrier_1" );
		}
		else if ( rand == 2 )
		{
			Util.SetGoalPosition( -703, -1370, 950, "PLANT_Tank_Barrier_1" );
		}
		else if ( rand == 3 )
		{
			Util.SetGoalPosition( -758, -1290, 950, "PLANT_Tank_Barrier_1" );
		}
		else
		{
			Util.SetGoalPosition( -715, -1107, 950, "PLANT_Tank_Barrier_1" );
		}

		Util.MapDebugPrint( "Tank_Barrier_1_Built" );
	},

	Tank_Barrier_2_Built = function( trigger )
	{
		// Reposition plant goal
		rand = RandInt(1,2);
		if ( rand == 1 )
		{
			Util.SetGoalPosition( 1475, -2348, 820, "PLANT_Tank_Barrier_2" );
		}
		else
		{
			Util.SetGoalPosition( 1276, -2300, 820, "PLANT_Tank_Barrier_2" );
		}

		Util.MapDebugPrint( "Tank_Barrier_2_Built" );
	},

	Tank_Ramp_Built = function( trigger )
	{
		Wp.SetWaypointFlag( "ramp1", "closed", false );
		Util.MapDebugPrint( "Tank_Ramp_Built" );
	},

	Tank_Ramp_Destroyed = function( trigger )
	{
		Wp.SetWaypointFlag( "ramp1", "closed", true );
		Util.MapDebugPrint( "Tank_Ramp_Destroyed" );
	},

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

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

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

	TankPastBarrier1 = function( trigger )
	{
		Util.SetMaxUsersInProgress( 2, "BUILD_Tank_Barrier_2" );
		SetGoalPriority( "BUILD_Tank_Barrier_2", 0.9 );
		SetGoalPriority( "PLANT_Tank_Barrier_2", 0.9 );
		SetAvailableMapGoals( TEAM.ALLIES, true, "TRIPMINE_allies_barrier2.*" );
		Util.MapDebugPrint( "TankPastBarrier1" );
	},

	TankAtSecondCorner = function( trigger )
	{
		SetGoalPriority( "BUILD_Tank_Ramp", 0.7 );
		SetGoalPriority( "PLANT_Tank_Ramp", 0.7 );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"DEFEND_.*",
			"MOBILEMG42_.*",
			"ATTACK_.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"SNIPE_allies_phase4.*",
			"DEFEND_allies_phase4.*",
			"MOBILEMG42_allies_phase4.*",
		});
		Util.MapDebugPrint( "TankAtSecondCorner" );
	},

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

	TankPastBarrier2 = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"DEFEND_.*",
			"MOBILEMG42_.*",
			"ATTACK_.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"SNIPE_allies_phase5.*",
			"DEFEND_allies_phase5.*",
			"MOBILEMG42_allies_phase5.*",
		});
		SetGoalPriority( "PLANT_Tank_Ramp", 0.85 );
		SetGoalPriority( "BUILD_Tank_Ramp", 0.9 );
		Util.MapDebugPrint( "TankPastBarrier2" );
	},

	TankLoaded = function( trigger )
	{
		if ( trigger.Action == "axis_complete" )
		{
			Map.Switches.TrackSwitch.Enabled = true;
			Util.MapDebugPrint("TankLoaded");
		}
		SetAvailableMapGoals( TEAM.AXIS, false, "MOUNT_tank" );
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_axis_phase6.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"PLANT_Tank_Ramp",
			"DEFEND_.*",
			"MOBILEMG42_.*",
			"ATTACK_.*",
			"TRIPMINE_allies_barrier2.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"TRIPMINE_allies_switch.*",
			"SNIPE_allies_phase6.*",
			"DEFEND_allies_phase6.*",
			"MOBILEMG42_allies_phase6.*",
		});

		foreach ( gameId and bot in BotTable )
		{
			bot.IgnoreTarget( GetGoal("MOVER_tank").GetEntity(), 9999 );
		}
	},

	Tank_At_Location = function( trigger )
	{
		switch(Map.VehicleLocation)
		{
			case 1:
			{
				ETUtil.SetExcludeIndexes("BUILD_Tank");
				ETUtil.SetExcludeIndexes("MOUNT_tank");
			}
			case 2:
			{
				Map.TankAtFirstCorner();
			}
			case 3:
			{
				Map.TankAtSecondCorner();
			}
		}

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

	AmmoLoaded = function( trigger )
	{
		if ( trigger.Action == "axis_complete" )
		{
			SetGoalPriority( "BUILD_Tank_Barrier_2", 0.6 );
			SetAvailableMapGoals( TEAM.ALLIES, false, {
				"DEFEND_.*",
				"MOBILEMG42_.*",
				"ATTACK_.*",
				"PLANT_Ammo_Elevator_Control",
			});
			SetAvailableMapGoals( TEAM.ALLIES, true, {
				"SNIPE_allies_phase3.*",
				"DEFEND_allies_phase3.*",
				"MOBILEMG42_allies_phase3.*",
			});
			Util.MapDebugPrint("AmmoLoaded");
		}
	},

	TrackSwitch = function( trigger )
	{
		vel = ToVector(trigger.Action);

		if ( vel.z > 0 )
			{ Map.Switches.TrackSwitch.Enabled = false; }
		else
			{ Map.Switches.TrackSwitch.Enabled = true; }
	},

};

global OnMapLoad = function()
{
	OnTrigger( "Tank Barrier #1 has been constructed.", Map.Tank_Barrier_1_Built );
	OnTrigger( "Tank Barrier #1 has been destroyed.", Map.Tank_Barrier_1_Destroyed );
	OnTrigger( "Tank Barrier #2 has been constructed.", Map.Tank_Barrier_2_Built );
	OnTrigger( "Tank Barrier #2 has been destroyed.", Map.Tank_Barrier_2_Destroyed );
	OnTrigger( "The Tank Ramp has been constructed.", Map.Tank_Ramp_Built );
	OnTrigger( "The Tank Ramp has been destroyed.", Map.Tank_Ramp_Destroyed );
	OnTrigger( "pa_axis_tank_barrier1", Map.TankPastBarrier1 );
	OnTrigger( "pa_axis_tank_barrier2", Map.TankPastBarrier2 );
	OnTrigger( "tank", Map.TankLoaded );
	OnTrigger( "signal_button_start", Map.TrackSwitch );
	OnTrigger( "crane", Map.AmmoLoaded );
	OnTrigger( "MISSING_STRING", Map.Ammo_Elevator_Control_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Command_Post_Built );
	OnTrigger( "MISSING_STRING", Map.Command_Post_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Tank_Built );
	OnTrigger( "The Tank has been damaged!", Map.Tank_Destroyed );
	OnTrigger( "tank at location", Map.Tank_At_Location );

	SetAvailableMapGoals( TEAM.AXIS, false, {
		"REPAIRMG42_.*",
		"MOUNTMG42_.*",
		"SNIPE_.*",
		"DEFEND_.*",
		"MOBILEMG42_.*",
		"ATTACK_.*",
		"TRIPMINE_.*",
	});

	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"TRIPMINE_.*",
		"MOUNTMG42_.*",
		"REPAIRMG42_.*",
		"SNIPE_.*",
		"DEFEND_.*",
		"MOBILEMG42_.*",
		"ATTACK_.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"SNIPE_allies_phase1.*",
		"DEFEND_allies_phase1.*",
		"MOBILEMG42_allies_phase1.*",
	});

	// Priority settings
	SetGoalPriority( "BUILD_Tank_Barrier_1", 0.9 );
	SetGoalPriority( "BUILD_Tank_Barrier_2", 0.5 );
	SetGoalPriority( "BUILD_Command_Post", 0.75 );
	SetGoalPriority( "PLANT_Command_Post", 0.75 );
	SetGoalPriority( "PLANT_Tank_Barrier_1", 0.85 );
	SetGoalPriority( "PLANT_Tank_Barrier_2", 0.7 );
	SetGoalPriority( "BUILD_Tank_Ramp", 0.0 );
	SetGoalPriority( "PLANT_Tank_Ramp", 0.0 );
	SetGoalPriority( "DEFEND._", 0.6 );

	// Set max users for some goals
	Util.SetMaxUsersInProgress( 1, "PLANT_.*" );
	Util.SetMaxUsersInProgress( 1, "BUILD_Command_Post" );
	Util.SetMaxUsersInProgress( 1, "BUILD_Tank_Barrier_1" );
	Util.SetMaxUsersInProgress( 1, "BUILD_Tank_Barrier_2" );
	Util.SetMaxUsersInProgress( 1, "DEFEND_.*" );
	Util.SetMaxUsersInProgress( 1, "ATTACK_.*" );

	// Set map goal properties (camp time)
	SetMapGoalProperties( "ATTACK_.*", {MinCampTime=1, MaxCampTime=15} );
	SetMapGoalProperties( "DEFEND_.*", {MinCampTime=3, MaxCampTime=35} );
	SetMapGoalProperties( "SNIPE_.*", {MinCampTime=6, MaxCampTime=35} );

	// Flag one waypoint at the ramp closed (ramp not built initially)
	Wp.SetWaypointFlag( "ramp1", "closed", true);

	// Set up some positional triggers
	l1 = OnTriggerRegion( AABB(-1315,-2618,920, -1237,-2280,993), RegionTrigger.VehicleTrigger );
	l2 = OnTriggerRegion( AABB(-3240,-2176,919, -2687,-2003,993), RegionTrigger.VehicleTrigger );
	l3 = OnTriggerRegion( AABB(1180,-1495,788, 1345,-1220,862), RegionTrigger.VehicleTrigger );

	// Usable offset indexes for vehicle goals
	ETUtil.SetExcludeIndexes( "BUILD_Tank", { 2,4 } );
	ETUtil.SetExcludeIndexes( "MOUNT_tank", { 2,4 } );

	// Remove the train as a goal
	Util.RemoveGoal( "MOVER_train" );

	// only disguised covert ops can reach it
	SetGoalRole( "PLANT_Ammo_Elevator_Control", ROLE.INFILTRATOR );

	/*** ROUTES ***/
	MapRoutes =
	{
		PLANT_Command_Post =
		{
			ROUTE_axis_spawn =
			{
				ROUTE_ladder = {},
				ROUTE_door = {},
				ROUTE_underground = { ROUTE_ladder2 = {} },
				ROUTE_underground2 = {}
			},
			ROUTE_allied_spawn =
			{
				ROUTE_maindoor = {},
				ROUTE_backdoor = {}
			}
		},
	};
	MapRoutes.BUILD_Command_Post = MapRoutes.PLANT_Command_Post;
	MapRoutes.BUILD_Tank_Barrier_2 = MapRoutes.PLANT_Command_Post;
	MapRoutes.BUILD_Tank_Barrier_1 = MapRoutes.PLANT_Command_Post;
	MapRoutes.ATTACK_axis_phase6_3 = MapRoutes.PLANT_Command_Post;
	MapRoutes.ATTACK_axis_phase6_2 = MapRoutes.PLANT_Command_Post;
	MapRoutes.ATTACK_axis_phase6_1 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase1_2 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase1_3 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase1_4 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase1_5 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase1_6 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase1_7 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase1_8 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase1_9 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase1_10 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase2_1 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase2_4 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase2_5 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase2_6 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase2_8 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase2_9 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase2_10 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase2_11 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase2_12 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase2_13 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase2_13 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase2_14 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase2_15 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase2_16 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase2_17 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase3_1 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase3_2 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase3_3 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase3_4 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase3_5 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase3_6 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase3_7 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase3_8 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase3_9 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase3_10 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase4_1 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase4_2 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase4_3 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase4_4 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase4_5 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase4_6 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase4_7 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase4_8 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase4_9 = MapRoutes.PLANT_Command_Post;
	MapRoutes.DEFEND_allies_phase4_10 = MapRoutes.PLANT_Command_Post;
	MapRoutes.SNIPE_allies_phase2_1 = MapRoutes.PLANT_Command_Post;
	MapRoutes.SNIPE_allies_phase2_2 = MapRoutes.PLANT_Command_Post;
	MapRoutes.SNIPE_allies_phase2_3 = MapRoutes.PLANT_Command_Post;
	MapRoutes.SNIPE_allies_phase2_4 = MapRoutes.PLANT_Command_Post;
	MapRoutes.SNIPE_allies_phase2_6 = MapRoutes.PLANT_Command_Post;

	Util.Routes( MapRoutes );
	Util.UpdateSwitchData();
	Util.MapDebugPrint( "OnMapLoad" );
};

global OnBotJoin = function( bot )
{
	bot.MaxViewDistance = 2200.0;
	bot.TargetBreakableDist = 80.0;
};
